| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- <template>
- <span>
- <template v-if="widget.type == 'blank'">
- <div :style="{width: isTable ? '100%' : widget.options.width}">
- <slot :name="widget.model" :model="dataModels"></slot>
- </div>
-
- </template>
- <template v-if="widget.type == 'component'">
- <div :style="{width: isTable ? '100%' : widget.options.width}">
- <component :is="`component-${widget.key}-${key}`" :key="key" v-model="dataModel"></component>
- </div>
- </template>
- <template v-if="widget.type == 'custom'">
- <div :style="{width: isTable ? '100%' : widget.options.width}">
- <component
- :is="widget.el"
- v-model="dataModel"
- :width="widget.options.width"
- :height="widget.options.height"
- :placeholder="widget.options.placeholder"
- :readonly="widget.options.readonly"
- :disabled="!edit || widget.options.disabled"
- :editable="widget.options.editable"
- :clearable="widget.options.clearable"
- ></component>
- </div>
- </template>
- <template v-if="widget.type == 'input'" >
- <el-input
- v-if="widget.options.dataType == 'number' || widget.options.dataType == 'integer' || widget.options.dataType == 'float'"
- type="number"
- v-model.number="dataModel"
- :disabled="!edit || widget.options.disabled"
- :placeholder="widget.options.placeholder"
- :show-password="widget.options.showPassword"
- :style="{width: isTable ? '100%' : widget.options.width}"
- ></el-input>
- <el-input
- v-else
- :type="widget.options.dataType"
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :placeholder="widget.options.placeholder"
- :show-password="widget.options.showPassword"
- :style="{width: isTable ? '100%' : widget.options.width}"
- ></el-input>
- </template>
- <template v-if="widget.type == 'textarea'">
- <el-input type="textarea" :rows="5"
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :placeholder="widget.options.placeholder"
- :style="{width: isTable ? '100%' : widget.options.width}"
- ></el-input>
- </template>
- <template v-if="widget.type == 'number'">
- <el-input-number
- v-model="dataModel"
- :style="{width: isTable ? '100%' : widget.options.width}"
- :step="widget.options.step"
- controls-position="right"
- :disabled="!edit || widget.options.disabled"
- :min="widget.options.min"
- :max="widget.options.max"
- ></el-input-number>
- </template>
- <template v-if="widget.type == 'radio'">
- <el-radio-group v-model="dataModel"
- :style="{width: isTable ? '100%' : widget.options.width}"
- :disabled="!edit || widget.options.disabled"
- >
- <el-radio
- :style="{display: widget.options.inline ? 'inline-block' : 'block'}"
- :label="item.value" v-for="(item, index) in (widget.options.remote ? remoteOptions : widget.options.options)" :key="index"
- >
- <template v-if="widget.options.remote">{{item.label}}</template>
- <template v-else>{{widget.options.showLabel ? item.label : item.value}}</template>
- </el-radio>
- </el-radio-group>
- </template>
- <template v-if="widget.type == 'checkbox'">
- <el-checkbox-group v-model="dataModel"
- :style="{width: isTable ? '100%' : widget.options.width}"
- :disabled="!edit || widget.options.disabled"
- >
- <el-checkbox
-
- :style="{display: widget.options.inline ? 'inline-block' : 'block'}"
- :label="item.value" v-for="(item, index) in (widget.options.remote ? remoteOptions : widget.options.options)" :key="index"
- >
- <template v-if="widget.options.remote">{{item.label}}</template>
- <template v-else>{{widget.options.showLabel ? item.label : item.value}}</template>
- </el-checkbox>
- </el-checkbox-group>
- </template>
- <template v-if="widget.type == 'time'">
- <el-time-picker
- v-model="dataModel"
- :is-range="widget.options.isRange"
- :placeholder="widget.options.placeholder"
- :start-placeholder="widget.options.startPlaceholder"
- :end-placeholder="widget.options.endPlaceholder"
- :readonly="widget.options.readonly"
- :disabled="!edit || widget.options.disabled"
- :editable="widget.options.editable"
- :clearable="widget.options.clearable"
- :arrowControl="widget.options.arrowControl"
- :value-format="widget.options.format"
- :style="{width: isTable ? '100%' : widget.options.width}"
- >
- </el-time-picker>
- </template>
- <template v-if="widget.type=='date'">
- <el-date-picker
- v-model="dataModel"
- :type="widget.options.type"
- :placeholder="widget.options.placeholder"
- :start-placeholder="widget.options.startPlaceholder"
- :end-placeholder="widget.options.endPlaceholder"
- :readonly="widget.options.readonly"
- :disabled="!edit || widget.options.disabled"
- :editable="widget.options.editable"
- :clearable="widget.options.clearable"
- :value-format="widget.options.timestamp ? 'timestamp' : widget.options.format"
- :format="widget.options.format"
- :style="{width: isTable ? '100%' : widget.options.width}"
- >
- </el-date-picker>
- </template>
- <template v-if="widget.type =='rate'">
- <el-rate v-model="dataModel"
- :max="widget.options.max"
- :disabled="!edit || widget.options.disabled"
- :allow-half="widget.options.allowHalf"
- :show-score="widget.options.showScore"
- ></el-rate>
- </template>
- <template v-if="widget.type == 'color'">
- <el-color-picker
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :show-alpha="widget.options.showAlpha"
- ></el-color-picker>
- </template>
- <template v-if="widget.type == 'select'">
- <el-select
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :multiple="widget.options.multiple"
- :clearable="widget.options.clearable"
- :placeholder="widget.options.placeholder"
- :style="{width: isTable ? '100%' : widget.options.width}"
- :filterable="widget.options.filterable"
- >
- <el-option v-for="item in (widget.options.remote ? remoteOptions : widget.options.options)" :key="item.value" :value="item.value" :label="widget.options.showLabel || widget.options.remote?item.label:item.value"></el-option>
- </el-select>
- </template>
- <template v-if="widget.type=='switch'">
- <el-switch
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- >
- </el-switch>
- </template>
- <template v-if="widget.type=='slider'">
- <el-slider
- v-model="dataModel"
- :min="widget.options.min"
- :max="widget.options.max"
- :disabled="!edit || widget.options.disabled"
- :step="widget.options.step"
- :show-input="widget.options.showInput"
- :range="widget.options.range"
- :style="{width: isTable ? '100%' : widget.options.width}"
- ></el-slider>
- </template>
- <template v-if="widget.type=='imgupload'">
- <fm-upload
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :readonly="widget.options.readonly"
- :style="{'width': isTable ? '100%' : widget.options.width}"
- :width="widget.options.size.width"
- :height="widget.options.size.height"
- :token="widget.options.token"
- :domain="widget.options.domain"
- :multiple="widget.options.multiple"
- :limit="widget.options.limit"
- :is-qiniu="widget.options.isQiniu"
- :is-delete="widget.options.isDelete"
- :min="widget.options.min"
- :is-edit="widget.options.isEdit"
- :action="widget.options.action"
- :headers="widget.options.headers || []"
- >
- </fm-upload>
- </template>
- <template v-if="widget.type == 'editor'">
- <fm-editor
- v-model="dataModel"
- :sty="{width: isTable ? '100%' : widget.options.width, cursor: (!edit || widget.options.disabled) ? 'no-drop' : '', backgroundColor: (!edit || widget.options.disabled) ? '#F5F7FA' : ''}"
- :toolbar="widget.options.customToolbar"
- :disabled="!edit || widget.options.disabled"
- >
- </fm-editor>
- </template>
- <template v-if="widget.type == 'cascader'">
- <el-cascader
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :clearable="widget.options.clearable"
- :placeholder="widget.options.placeholder"
- :style="{width: isTable ? '100%' : widget.options.width}"
- :options="remoteOptions"
- >
- </el-cascader>
- </template>
- <template v-if="widget.type == 'text'">
- <span>{{dataModel}}</span>
- </template>
- <template v-if="widget.type == 'html'">
- <span v-html="dataModel"></span>
- </template>
- <template v-if="widget.type == 'table'">
- <fm-form-table
- :value="dataModel"
- :columns="widget.tableColumns"
- :models="dataModels"
- :remote="remote"
- :blanks="blanks"
- :disabled="!edit || widget.options.disabled"
- :rules="rules"
- :name="widget.model"
- :remote-option="remoteOption"
- >
- <template v-slot:[blank.name]="scope" v-for="blank in blanks">
- <slot :name="blank.name" :model="scope.model"></slot>
- </template>
- </fm-form-table>
- </template>
- <template v-if="widget.type == 'fileupload'">
- <fm-file-upload
- v-model="dataModel"
- :disabled="!edit || widget.options.disabled"
- :style="{'width': isTable ? '100%' : widget.options.width}"
- :token="widget.options.token"
- :domain="widget.options.domain"
- :multiple="widget.options.multiple"
- :limit="widget.options.limit"
- :is-qiniu="widget.options.isQiniu"
- :min="widget.options.min"
- :action="widget.options.action"
- :tip="widget.options.tip"
- :headers="widget.options.headers || []"
- >
- </fm-file-upload>
- </template>
- </span>
- </template>
- <script>
- import FmUpload from './Upload'
- import FmFormTable from './FormTable'
- import FmFileUpload from './Upload/file'
- import FmEditor from './Editor'
- import Vue from 'vue'
- export default {
- name: 'generate-element-item',
- components: {
- FmUpload,
- FmFormTable,
- FmFileUpload,
- FmEditor
- },
- props: ['widget', 'value', 'models', 'remote', 'isTable', 'blanks', 'disabled', 'edit', 'remoteOption', 'rules'],
- data () {
- return {
- dataModel: this.value,
- dataModels: {...this.models},
- remoteOptions: [],
- key: new Date().getTime()
- }
- },
- created () {
- this.remoteOptions = []
- if (this.widget.options.remote
- && (Object.keys(this.widget.options).indexOf('remoteType') >= 0 ? this.widget.options.remoteType == 'func' : true)
- && this.remote[this.widget.options.remoteFunc]) {
- this.remote[this.widget.options.remoteFunc]((data) => {
- this.loadOptions(data)
- })
- }
- if (this.widget.options.remote
- && this.widget.options.remoteType == 'option'
- && this.remoteOption[this.widget.options.remoteOption]) {
-
- this.loadOptions(this.remoteOption[this.widget.options.remoteOption])
- }
- if ((this.widget.type === 'imgupload' || this.widget.type === 'fileupload') && this.widget.options.isQiniu) {
-
- !this.widget.options.token && this.remote[this.widget.options.tokenFunc]((data) => {
- this.widget.options.token = data
- })
- }
- if (this.widget.type == 'component') {
- Vue.component(`component-${this.widget.key}-${this.key}`, {
- template: `<span>${this.widget.options.template}</span>`,
- props: ['value'],
- data: () => ({
- dataModel: this.value
- }),
- watch: {
- dataModel (val) {
- if (this.ui == 'antd') {
- EventBus.$emit('on-field-change', this.$attrs.id, val)
- } else {
- this.$emit('input', val)
- }
- },
- value (val) {
- this.dataModel = val
- }
- }
- })
- }
- },
- methods: {
- loadOptions (data) {
- this.remoteOptions = data.map(item => {
-
- if (this.widget.options.props.children && this.widget.options.props.children.length && Object.keys(item).includes(this.widget.options.props.children)) {
- return {
- value: item[this.widget.options.props.value],
- label: item[this.widget.options.props.label],
- children: this.processRemoteProps(item[this.widget.options.props.children], this.widget.options.props)
- }
- } else {
- return {
- value: item[this.widget.options.props.value],
- label: item[this.widget.options.props.label]
- }
- }
-
- })
- },
- processRemoteProps (children, props) {
- if (children && children.length) {
- return children.map(item => {
- if (this.processRemoteProps(item[props.children], props).length) {
- return {
- value: item[props.value],
- label: item[props.label],
- children: this.processRemoteProps(item[props.children], props)
- }
- } else{
- return {
- value: item[props.value],
- label: item[props.label],
- }
- }
- })
- } else {
- return []
- }
- }
- },
- watch: {
- value (val) {
- this.dataModel = val
- },
- models: {
- deep: true,
- handler (val) {
- this.dataModels = {...val}
- }
- },
- dataModel (val) {
- this.$emit('input', val)
- },
- dataModels: {
- deep: true,
- handler (val) {
- this.$emit('input', val[this.widget.model])
- }
- },
- 'remoteOption': {
- deep: 'true',
- handler: function (val) {
-
- if (Object.keys(this.remoteOption).indexOf(this.widget.options.remoteOption) >= 0
- && this.widget.options.remote
- && this.widget.options.remoteType == 'option'
- ) {
- this.loadOptions(this.remoteOption[this.widget.options.remoteOption])
- }
- }
- }
- }
- }
- </script>
|