فهرست منبع

下拉树搜索功能调整

cfort 2 سال پیش
والد
کامیت
03c84895c9

+ 110 - 96
src/business/platform/cat/type/select.vue

@@ -1,23 +1,25 @@
 <template>
-  <div>
-    <template v-if="!readonly">
-      <ibps-tree-select
-        v-if="treeData"
-        v-model="selectData"
-        :data="treeData"
-        :props="props"
-        :node-key="nodeKey"
-        :placeholder="placeholder"
-        :empty-text="emptyText"
-        :clearable="clearable"
-      />
-    </template>
-    <template v-else>
-      <el-tag v-if="$utils.isNotEmpty(value)">
-        {{ value|optionsFilter(treeDataOptions,'label') }}
-      </el-tag>
-    </template>
-  </div>
+    <div>
+        <template v-if="!readonly">
+            <ibps-tree-select
+                v-if="treeData"
+                v-model="selectData"
+                :data="treeData"
+                :props="props"
+                :node-key="nodeKey"
+                :placeholder="placeholder"
+                :empty-text="emptyText"
+                :clearable="clearable"
+                :filterable="filterable"
+                :filter-method="filterMethod"
+            />
+        </template>
+        <template v-else>
+            <el-tag v-if="$utils.isNotEmpty(value)">
+                {{ value|optionsFilter(treeDataOptions,'label') }}
+            </el-tag>
+        </template>
+    </div>
 </template>
 <script>
 import { findTreeData } from '@/api/platform/cat/type'
@@ -26,88 +28,100 @@ import TreeUtils from '@/utils/tree'
 import IbpsTreeSelect from '@/components/ibps-tree-select'
 
 export default {
-  components: {
-    IbpsTreeSelect
-  },
-  props: {
-    value: {
-      type: [String, Number, Array, Object],
-      default: ''
+    components: {
+        IbpsTreeSelect
     },
-    data: {
-      type: Array
-    },
-    placeholder: {
-      type: String,
-      default: '请选择'
-    },
-    emptyText: {
-      type: String,
-      default: '暂无分类'
-    },
-    readonly: { // 是否只读
-      type: Boolean,
-      default: false
-    },
-    clearable: {
-      type: Boolean,
-      default: true
-    },
-    categoryKey: {
-      type: String
+    props: {
+        value: {
+            type: [String, Number, Array, Object],
+            default: ''
+        },
+        data: {
+            type: Array
+        },
+        placeholder: {
+            type: String,
+            default: '请选择'
+        },
+        emptyText: {
+            type: String,
+            default: '暂无分类'
+        },
+        readonly: { // 是否只读
+            type: Boolean,
+            default: false
+        },
+        clearable: {
+            type: Boolean,
+            default: true
+        },
+        categoryKey: {
+            type: String
+        },
+        nodeKey: {
+            type: String
+        },
+        filterable: {
+            type: Boolean,
+            default: false
+        },
+        filterLabel: {
+            type: String,
+            default: ''
+        }
     },
-    nodeKey: {
-      type: String
-    }
-  },
-  data: function() {
-    return {
-      props: {
-        children: 'children',
-        label: 'name'
-      },
-      selectData: this.value,
-      treeData: [],
-      treeDataOptions: []
-    }
-  },
-  watch: {
-    categoryKey: {
-      handler(val, oldVal) {
-        if (this.$utils.isEmpty(this.data)) {
-          this.loadTreeData()
-        } else {
-          this.treeData = JSON.parse(JSON.stringify(this.data)) || []
+    data: function () {
+        return {
+            props: {
+                children: 'children',
+                label: 'name'
+            },
+            selectData: this.value,
+            treeData: [],
+            treeDataOptions: []
         }
-      },
-      immediate: true
     },
-    selectData(val, oldVal) {
-      this.$emit('input', val)
+    watch: {
+        categoryKey: {
+            handler (val, oldVal) {
+                if (this.$utils.isEmpty(this.data)) {
+                    this.loadTreeData()
+                } else {
+                    this.treeData = JSON.parse(JSON.stringify(this.data)) || []
+                }
+            },
+            immediate: true
+        },
+        selectData (val, oldVal) {
+            this.$emit('input', val)
+        },
+        value: {
+            handler (val, oldVal) {
+                this.selectData = val
+            },
+            immediate: true
+        }
     },
-    value: {
-      handler(val, oldVal) {
-        this.selectData = val
-      },
-      immediate: true
-    }
-  },
-  methods: {
-    loadTreeData(categoryKey = this.categoryKey) {
-      findTreeData({ categoryKey: categoryKey }).then(response => {
-        const treeData = response.data.filter((d) => {
-          return d.parentId !== '-1'
-        })
-        this.treeData = TreeUtils.transformToTreeFormat(treeData)
-        this.treeDataOptions = treeData.map(item => {
-          return {
-            value: item.id,
-            label: item.name
-          }
-        })
-      }).catch(() => {
-      })
+    methods: {
+        loadTreeData (categoryKey = this.categoryKey) {
+            findTreeData({ categoryKey: categoryKey }).then(response => {
+                const treeData = response.data.filter((d) => {
+                    return d.parentId !== '-1'
+                })
+                this.treeData = TreeUtils.transformToTreeFormat(treeData)
+                this.treeDataOptions = treeData.map(item => {
+                    return {
+                        value: item.id,
+                        label: item.name
+                    }
+                })
+            }).catch(() => {
+            })
+        },
+        filterMethod (value, data) {
+            if (!value || !this.filterLabel) return true
+            return data[this.filterLabel].indexOf(value) !== -1
+        }
     }
-  }
 }
 </script>

+ 613 - 613
src/components/ibps-tree-select/index.vue

@@ -1,144 +1,144 @@
 <template>
-  <div
-    v-if="editable"
-    v-clickoutside="handleClose"
-    class="el-tree-select"
-    @click="toggleTree"
-  >
     <div
-      v-if="multiple"
-      ref="tags"
-      :style="{ 'max-width': inputWidth - 32 + 'px' }"
-      class="el-tree-select__tags"
+        v-if="editable"
+        v-clickoutside="handleClose"
+        class="el-tree-select"
+        @click="toggleTree"
     >
-      <transition-group @after-leave="resetInputHeight">
-        <template v-for="(item,i) in selected">
-          <el-tag
-            :key="item.value+i"
-            :closable="!selectDisabled"
-            :size="collapseTagSize"
-            type="info"
-            disable-transitions
-            @close.stop="deleteTag(item)"
-          >
-            <span class="el-tree-select__tags-text">{{ displayMode==="name"? item.label:item.path }}</span>
-          </el-tag>
-        </template>
-      </transition-group>
-      <input
-        v-if="filterable"
-        ref="input"
-        v-model="query"
-        :disabled="selectDisabled"
-        :placeholder="currentPlaceholder"
-        :autocomplete="false"
-        :style="{ width: inputLength + 'px'}"
-        type="text"
-        class="el-tree-select__input"
-        @focus="handleFocus"
-        @keydown.esc.stop.prevent="visible = false"
-        @keydown.delete="deletePrevTag"
-        @input="e => handleQueryChange(e.target.value)"
-      >
-    </div>
-    <el-input
-      ref="reference"
-      v-model="selectedLabel"
-      :disabled="selectDisabled"
-      :readonly="selectReadonly"
-      :validate-event="false"
-      :size="selectSize"
-      :class="{ 'is-focus': visible }"
-      :placeholder="currentPlaceholder"
-      type="text"
-      @focus="handleFocus"
-      @keyup.native="onInputChange"
-      @mouseenter.native="inputHovering = true"
-      @mouseleave.native="inputHovering = false"
-    >
-      <template v-if="$slots.prefix" slot="prefix">
-        <slot name="prefix" />
-      </template>
-      <i
-        slot="suffix"
-        :class="suffixIconClass"
-        @click="handleIconClick"
-      />
-    </el-input>
-    <transition name="el-zoom-in-top">
-      <div
-        v-show="visible"
-        ref="popper"
-        :style="{minWidth: inputWidth + 'px'}"
-        class="el-tree-select-dropdown el-popper"
-      >
-        <el-scrollbar
-          wrap-class="el-tree-select-dropdown__wrap"
+        <div
+            v-if="multiple"
+            ref="tags"
+            :style="{ 'max-width': inputWidth - 32 + 'px' }"
+            class="el-tree-select__tags"
+        >
+            <transition-group @after-leave="resetInputHeight">
+                <template v-for="(item,i) in selected">
+                    <el-tag
+                        :key="item.value+i"
+                        :closable="!selectDisabled"
+                        :size="collapseTagSize"
+                        type="info"
+                        disable-transitions
+                        @close.stop="deleteTag(item)"
+                    >
+                        <span class="el-tree-select__tags-text">{{ displayMode==="name"? item.label:item.path }}</span>
+                    </el-tag>
+                </template>
+            </transition-group>
+            <input
+                v-if="filterable"
+                ref="input"
+                v-model="query"
+                :disabled="selectDisabled"
+                :placeholder="currentPlaceholder"
+                :autocomplete="false"
+                :style="{ width: inputLength + 'px'}"
+                type="text"
+                class="el-tree-select__input"
+                @focus="handleFocus"
+                @keydown.esc.stop.prevent="visible = false"
+                @keydown.delete="deletePrevTag"
+                @input="e => handleQueryChange(e.target.value)"
+            >
+        </div>
+        <el-input
+            ref="reference"
+            v-model="selectedLabel"
+            :disabled="selectDisabled"
+            :readonly="selectReadonly"
+            :validate-event="false"
+            :size="selectSize"
+            :class="{ 'is-focus': visible }"
+            :placeholder="currentPlaceholder"
+            type="text"
+            @focus="handleFocus"
+            @keyup.native="onInputChange"
+            @mouseenter.native="inputHovering = true"
+            @mouseleave.native="inputHovering = false"
         >
-          <el-tree
-            ref="tree"
-            :data="data"
-            :lazy="lazy"
-            :load="load"
-            :check-on-click-node="checkOnClickNode"
-            :props="treeProps"
-            :show-checkbox="showCheckbox"
-            :expand-on-click-node="false"
-            :check-strictly="checkStrictly"
-            :filter-node-method="filterNodeMethod"
-            :default-checked-keys="checkedKeys"
-            :node-key="nodeKey"
-            :empty-text="emptyText"
-            :current-node-key="currentNodeKey"
-            default-expand-all
-            highlight-current
-            @check="handleCheck"
-            @node-click="handleNodeClick"
-          >
-            <template v-slot="scope">
-              <span class="el-tree-node__label">
-                <i v-if="icon" :class="icon(scope.data)" /> {{ scope.node.label }}
-              </span>
+            <template v-if="$slots.prefix" slot="prefix">
+                <slot name="prefix" />
             </template>
-          </el-tree>
-        </el-scrollbar>
-      </div>
-    </transition>
-  </div>
+            <i
+                slot="suffix"
+                :class="suffixIconClass"
+                @click="handleIconClick"
+            />
+        </el-input>
+        <transition name="el-zoom-in-top">
+            <div
+                v-show="visible"
+                ref="popper"
+                :style="{minWidth: inputWidth + 'px'}"
+                class="el-tree-select-dropdown el-popper"
+            >
+                <el-scrollbar
+                    wrap-class="el-tree-select-dropdown__wrap"
+                >
+                    <el-tree
+                        ref="tree"
+                        :data="data"
+                        :lazy="lazy"
+                        :load="load"
+                        :check-on-click-node="checkOnClickNode"
+                        :props="treeProps"
+                        :show-checkbox="showCheckbox"
+                        :expand-on-click-node="false"
+                        :check-strictly="checkStrictly"
+                        :filter-node-method="filterNodeMethod"
+                        :default-checked-keys="checkedKeys"
+                        :node-key="nodeKey"
+                        :empty-text="emptyText"
+                        :current-node-key="currentNodeKey"
+                        default-expand-all
+                        highlight-current
+                        @check="handleCheck"
+                        @node-click="handleNodeClick"
+                    >
+                        <template v-slot="scope">
+                            <span class="el-tree-node__label">
+                                <i v-if="icon" :class="icon(scope.data)" /> {{ scope.node.label }}
+                            </span>
+                        </template>
+                    </el-tree>
+                </el-scrollbar>
+            </div>
+        </transition>
+    </div>
 
-  <!--只读 文本样式-->
-  <div v-else class="el-tree-select">
-    <template v-if="$utils.isNotEmpty(selected)">
-      <div
-        v-if="multiple"
-        class="el-tree-select__tags_readonly"
-      >
-        <template v-for="(item,i) in selected">
-          <el-tag
-            v-if="$utils.isNotEmpty(item.value)"
-            :key="item.value+i"
-            type="info"
-            disable-transitions
-            class="el-tree-select__tags-text ibps-mr-5 "
-          >
-            <template v-if="displayMode === 'name'">
-              {{ item.label }}
-            </template>
-            <template v-else>
-              {{ item.path }}
-            </template>
-          </el-tag>
+    <!--只读 文本样式-->
+    <div v-else class="el-tree-select">
+        <template v-if="$utils.isNotEmpty(selected)">
+            <div
+                v-if="multiple"
+                class="el-tree-select__tags_readonly"
+            >
+                <template v-for="(item,i) in selected">
+                    <el-tag
+                        v-if="$utils.isNotEmpty(item.value)"
+                        :key="item.value+i"
+                        type="info"
+                        disable-transitions
+                        class="el-tree-select__tags-text ibps-mr-5 "
+                    >
+                        <template v-if="displayMode === 'name'">
+                            {{ item.label }}
+                        </template>
+                        <template v-else>
+                            {{ item.path }}
+                        </template>
+                    </el-tag>
+                </template>
+            </div>
+            <el-tag
+                v-else
+                type="info"
+                disable-transitions
+            >
+                {{ selectedLabel }}
+            </el-tag>
         </template>
-      </div>
-      <el-tag
-        v-else
-        type="info"
-        disable-transitions
-      >
-        {{ selectedLabel }}
-      </el-tag>
-    </template>
-  </div>
+    </div>
 </template>
 
 <script>
@@ -157,517 +157,517 @@ import PopupManager from '@/utils/popup'
 
 // TODO: 等 vue-popper 合并后,这里还需要做出调整
 const popperMixin = {
-  props: {
-    placement: {
-      type: String,
-      default: 'bottom-start'
+    props: {
+        placement: {
+            type: String,
+            default: 'bottom-start'
+        },
+        appendToBody: false,
+        arrowOffset: Popper.props.arrowOffset,
+        offset: Popper.props.offset,
+        boundariesPadding: Popper.props.boundariesPadding,
+        popperOptions: Popper.props.popperOptions,
+        visibleArrow: {
+            type: Boolean,
+            default: true
+        }
     },
-    appendToBody: false,
-    arrowOffset: Popper.props.arrowOffset,
-    offset: Popper.props.offset,
-    boundariesPadding: Popper.props.boundariesPadding,
-    popperOptions: Popper.props.popperOptions,
-    visibleArrow: {
-      type: Boolean,
-      default: true
-    }
-  },
-  methods: Popper.methods,
-  data: Popper.data,
-  beforeDestroy: Popper.beforeDestroy
+    methods: Popper.methods,
+    data: Popper.data,
+    beforeDestroy: Popper.beforeDestroy
 }
 const sizeMap = {
-  'medium': 36,
-  'small': 32,
-  'mini': 28
+    'medium': 36,
+    'small': 32,
+    'mini': 28
 }
 
 export default {
-  name: 'ibps-tree-select',
-  // components: {
-  //   ElInput,
-  //   ElTree
-  // },
-  directives: { Clickoutside },
-  mixins: [popperMixin, emitter],
-  provide() {
-    return {
-      elTreeSelect: this
-    }
-  },
-  inject: {
-    elForm: {
-      default: ''
-    },
-    elFormItem: {
-      default: ''
-    }
-  },
-  props: {
-    data: {
-      type: Array,
-      required: true
-    },
-    value: {
-      type: [String, Number, Array, Object],
-      default: ''
-    },
-    multiple: Boolean,
-    disabled: Boolean,
-    readonly: {
-      type: Boolean,
-      default: false
-    },
-    readonlyText: { // 只读样式 【text ,original】
-      type: String,
-      default: 'original',
-      validator(val) {
-        return ['original', 'text'].indexOf(val) > -1
-      }
-    },
-    clearable: Boolean,
-    size: {
-      type: String,
-      validator(val) {
-        return ['medium', 'small', 'mini'].indexOf(val) > -1
-      }
+    name: 'ibps-tree-select',
+    // components: {
+    //   ElInput,
+    //   ElTree
+    // },
+    directives: { Clickoutside },
+    mixins: [popperMixin, emitter],
+    provide () {
+        return {
+            elTreeSelect: this
+        }
     },
-    nodeKey: {
-      type: String,
-      default: 'id'
+    inject: {
+        elForm: {
+            default: ''
+        },
+        elFormItem: {
+            default: ''
+        }
     },
+    props: {
+        data: {
+            type: Array,
+            required: true
+        },
+        value: {
+            type: [String, Number, Array, Object],
+            default: ''
+        },
+        multiple: Boolean,
+        disabled: Boolean,
+        readonly: {
+            type: Boolean,
+            default: false
+        },
+        readonlyText: { // 只读样式 【text ,original】
+            type: String,
+            default: 'original',
+            validator (val) {
+                return ['original', 'text'].indexOf(val) > -1
+            }
+        },
+        clearable: Boolean,
+        size: {
+            type: String,
+            validator (val) {
+                return ['medium', 'small', 'mini'].indexOf(val) > -1
+            }
+        },
+        nodeKey: {
+            type: String,
+            default: 'id'
+        },
 
-    props: Object,
-    placeholder: {
-      type: String,
-      default() {
-        return '请选择'
-      }
-    },
-    selectMode: { // 选值模式 leaf、any
-      type: String,
-      default: 'any',
-      validator: function(value) {
-        return ['any', 'leaf'].indexOf(value) !== -1
-      }
-    },
-    displayMode: { // 显示模式 path 、name
-      type: String,
-      default: 'name',
-      validator: function(value) {
-        return ['name', 'path'].indexOf(value) !== -1
-      }
-    },
-    separator: { // 树形选项分隔符
-      type: String,
-      default: '/'
-    },
-    warningText: {
-      type: String,
-      default: '请选择叶子节点'
-    },
-    allowSelection: Function, // 允许的节点
-    lazy: Boolean,
-    load: Function,
-    showCheckbox: Boolean,
-    checkStrictly: Boolean,
-    filterable: Boolean,
-    filterMethod: Function,
-    emptyText: String,
-    showCheckedStrategy: { // 显示多选按钮
-      type: String,
-      default: 'child',
-      validator(val) {
-        return ['all', 'parent', 'child'].indexOf(val) > -1
-      }
+        props: Object,
+        placeholder: {
+            type: String,
+            default () {
+                return '请选择'
+            }
+        },
+        selectMode: { // 选值模式 leaf、any
+            type: String,
+            default: 'any',
+            validator: function (value) {
+                return ['any', 'leaf'].indexOf(value) !== -1
+            }
+        },
+        displayMode: { // 显示模式 path 、name
+            type: String,
+            default: 'name',
+            validator: function (value) {
+                return ['name', 'path'].indexOf(value) !== -1
+            }
+        },
+        separator: { // 树形选项分隔符
+            type: String,
+            default: '/'
+        },
+        warningText: {
+            type: String,
+            default: '请选择叶子节点'
+        },
+        allowSelection: Function, // 允许的节点
+        lazy: Boolean,
+        load: Function,
+        showCheckbox: Boolean,
+        checkStrictly: Boolean,
+        filterable: Boolean,
+        filterMethod: Function,
+        emptyText: String,
+        showCheckedStrategy: { // 显示多选按钮
+            type: String,
+            default: 'child',
+            validator (val) {
+                return ['all', 'parent', 'child'].indexOf(val) > -1
+            }
+        },
+        icon: Function
+    },
+    data () {
+        return {
+            query: '',
+            selectedLabel: '',
+            inputLength: 0,
+            visible: false,
+            inputWidth: 0,
+            inputHovering: false,
+            treeVisibleOnFocus: false,
+            selected: this.multiple ? [] : {},
+            checkOnClickNode: false,
+            treeProps: {
+                label: 'name',
+                children: 'children'
+            }
+        }
     },
-    icon: Function
-  },
-  data() {
-    return {
-      query: '',
-      selectedLabel: '',
-      inputLength: 0,
-      visible: false,
-      inputWidth: 0,
-      inputHovering: false,
-      treeVisibleOnFocus: false,
-      selected: this.multiple ? [] : {},
-      checkOnClickNode: false,
-      treeProps: {
-        label: 'name',
-        children: 'children'
-      }
-    }
-  },
-  computed: {
-    suffixIconClass() {
-      let classes = ['el-tree-select__caret', 'el-input__icon']
-      const criteria = this.clearable &&
+    computed: {
+        suffixIconClass () {
+            let classes = ['el-tree-select__caret', 'el-input__icon']
+            const criteria = this.clearable &&
           !this.selectDisabled &&
           this.inputHovering &&
           !this.multiple &&
           this.value !== undefined &&
           this.value !== null &&
           this.value !== ''
-      if (criteria) {
-        classes = [...classes, 'el-icon-circle-close', 'is-show-close']
-      } else {
-        classes.push('el-icon-arrow-down')
-        if (this.visible) {
-          classes.push('is-reverse')
+            if (criteria) {
+                classes = [...classes, 'el-icon-circle-close', 'is-show-close']
+            } else {
+                classes.push('el-icon-arrow-down')
+                if (this.visible) {
+                    classes.push('is-reverse')
+                }
+            }
+            return classes
+        },
+        selectDisabled () {
+            return this.disabled || (this.elForm || {}).disabled
+        },
+        selectSize () {
+            return this.size || (this.elFormItem || {}).elFormItemSize || (this.$ELEMENT || {}).size
+        },
+        collapseTagSize () {
+            return ['small', 'mini'].indexOf(this.selectSize) > -1
+                ? 'mini'
+                : 'small'
+        },
+        editable () {
+            return !this.readonly || (this.readonly && this.readonlyText === 'original')
+        },
+        selectReadonly () {
+            const isIE = !this.$isServer && !isNaN(Number(document.documentMode))
+            return this.readonly || !this.filterable || this.multiple || (!isIE && !this.visible)
+        },
+        checkedKeys () {
+            if (this.multiple && this.showCheckbox) {
+                return this.value || []
+            } else {
+                return []
+            }
+        },
+        currentNodeKey () {
+            if (this.multiple) {
+                return this.value && this.value.length > 0 ? this.value[0].value : ''
+            } else {
+                if (this.value && Array.isArray(this.value)) {
+                    return this.value[0] || ''
+                } else {
+                    return this.value || ''
+                }
+            }
+        },
+        currentPlaceholder () {
+            if (this.$utils.isEmpty(this.value)) {
+                return this.placeholder
+            } else {
+                return ''
+            }
+        },
+        labelKey () {
+            return this.treeProps['label'] || 'name'
         }
-      }
-      return classes
-    },
-    selectDisabled() {
-      return this.disabled || (this.elForm || {}).disabled
-    },
-    selectSize() {
-      return this.size || (this.elFormItem || {}).elFormItemSize || (this.$ELEMENT || {}).size
-    },
-    collapseTagSize() {
-      return ['small', 'mini'].indexOf(this.selectSize) > -1
-        ? 'mini'
-        : 'small'
-    },
-    editable() {
-      return !this.readonly || (this.readonly && this.readonlyText === 'original')
-    },
-    selectReadonly() {
-      const isIE = !this.$isServer && !isNaN(Number(document.documentMode))
-      return this.readonly || !this.filterable || this.multiple || (!isIE && !this.visible)
     },
-    checkedKeys() {
-      if (this.multiple && this.showCheckbox) {
-        return this.value || []
-      } else {
-        return []
-      }
-    },
-    currentNodeKey() {
-      if (this.multiple) {
-        return this.value && this.value.length > 0 ? this.value[0].value : ''
-      } else {
-        if (this.value && Array.isArray(this.value)) {
-          return this.value[0] || ''
-        } else {
-          return this.value || ''
+    watch: {
+        visible (val) {
+            if (val) {
+                this.updatePopper()
+                if (this.multiple && this.filterable) {
+                    this.$refs.input && this.$refs.input.focus()
+                }
+                this.$emit('focus', this)
+                if (!this.multiple && this.filterable) {
+                    this.broadcast('ElInput', 'inputSelect')
+                }
+            } else {
+                this.destroyPopper()
+                this.$refs.input && this.$refs.input.blur()
+                this.$emit('blur', this)
+                if (!this.multiple) {
+                    this.setSelected()
+                }
+                if (this.filterable) {
+                    setTimeout(() => {
+                        this.handleQueryChange('')
+                    }, 100)
+                }
+            }
+        },
+        value (val, oldVal) {
+            if (this.multiple) {
+                this.resetInputHeight()
+            }
+            this.setSelected()
+            if (!valueEquals(val, oldVal)) {
+                this.dispatch('ElFormItem', 'el.form.change', val)
+            }
+        },
+        data () {
+            this.setSelected()
+        },
+        props: {
+            handler (val, oldVal) {
+                this.treeProps = val
+            },
+            deep: true,
+            immediate: true
         }
-      }
-    },
-    currentPlaceholder() {
-      if (this.$utils.isEmpty(this.value)) {
-        return this.placeholder
-      } else {
-        return ''
-      }
     },
-    labelKey() {
-      return this.treeProps['label'] || 'name'
-    }
-  },
-  watch: {
-    visible(val) {
-      if (val) {
-        this.updatePopper()
-        if (this.multiple && this.filterable) {
-          this.$refs.input && this.$refs.input.focus()
+    mounted () {
+        if (this.multiple && this.showCheckbox) {
+            this.checkOnClickNode = true
         }
-        this.$emit('focus', this)
-        if (!this.multiple && this.filterable) {
-          this.broadcast('ElInput', 'inputSelect')
+        if (this.editable) {
+            this.referenceElm = this.$refs.reference.$el
+            this.popperElm = this.$refs.popper
+            this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width
+            addResizeListener(this.$el, this.handleResize)
+            this.setSelected()
+            this.fixZIndex()
         }
-      } else {
-        this.destroyPopper()
-        this.$refs.input && this.$refs.input.blur()
-        this.$emit('blur', this)
-        if (!this.multiple) {
-          this.setSelected()
-        }
-        if (this.filterable) {
-          setTimeout(() => {
-            this.handleQueryChange('')
-          }, 100)
-        }
-      }
     },
-    value(val, oldVal) {
-      if (this.multiple) {
-        this.resetInputHeight()
-      }
-      this.setSelected()
-      if (!valueEquals(val, oldVal)) {
-        this.dispatch('ElFormItem', 'el.form.change', val)
-      }
-    },
-    data() {
-      this.setSelected()
+    beforeDestroy () {
+        if (this.editable) {
+            removeResizeListener(this.$el, this.handleResize)
+        }
     },
-    props: {
-      handler(val, oldVal) {
-        this.treeProps = val
-      },
-      deep: true,
-      immediate: true
-    }
-  },
-  mounted() {
-    if (this.multiple && this.showCheckbox) {
-      this.checkOnClickNode = true
-    }
-    if (this.editable) {
-      this.referenceElm = this.$refs.reference.$el
-      this.popperElm = this.$refs.popper
-      this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width
-      addResizeListener(this.$el, this.handleResize)
-      this.setSelected()
-      this.fixZIndex()
-    }
-  },
-  beforeDestroy() {
-    if (this.editable) {
-      removeResizeListener(this.$el, this.handleResize)
-    }
-  },
-  methods: {
+    methods: {
     /**
      * zxh 修复zindex 不是最高的被遮住
      */
-    fixZIndex() {
-      PopupManager.getZIndex()
-    },
-    handleFocus(event) {
-      this.treeVisibleOnFocus = true
-      this.visible = true
-      this.$emit('focus', event)
-    },
-    handleClose() {
-      this.visible = false
-    },
-    toggleTree() {
-      if (this.selectDisabled) return
-      if (this.treeVisibleOnFocus) {
-        this.treeVisibleOnFocus = false
-      } else {
-        this.visible = !this.visible
-      }
-    },
-    handleIconClick(event) {
-      if (this.suffixIconClass.indexOf('el-icon-circle-close') > -1) {
-        event.stopPropagation()
-        this.visible = false
-        this.$emit('input', '')
-        this.emitChange('')
-        this.$emit('clear')
-        this.selected = {}
-        this.selectedLabel = ''
-      }
-    },
-    emitChange(val) {
-      if (!valueEquals(this.value, val)) {
-        this.$emit('change', val, this.getNodeData(val))
-      }
-    },
-    handleQueryChange(val) {
-      this.$refs.tree && this.$refs.tree.filter(val)
-    },
-    handleNodeClick(data, node, tree) {
-      if (this.showCheckbox) return
-      if (typeof this.allowSelection === 'function' && !this.allowSelection(data, node, tree)) {
-        return false
-      }
-      if ((this.selectMode === 'leaf' && !node.isLeaf) || (this.selectMode === 'leaf' && node.data.isLeaf === false)) {
-        this.$message.warning(this.warningText)
-        return false
-      }
-      this.setSelectedNode(data, node, tree)
-    },
-    setSelectedNode(data, node, tree) {
-      const value = data[this.nodeKey]
-      if (this.multiple) {
-        const valueCopy = this.value.slice()
-        const index = this.getValueIndex(valueCopy, value)
-        if (index > -1) {
-          valueCopy.splice(index, 1)
-        } else {
-          valueCopy.push(value)
-        }
-        this.$refs.input && this.$refs.input.focus()
-        this.$emit('input', valueCopy)
-        this.emitChange(valueCopy)
-      } else {
-        // if (value === this.value) {
-        //   value = ''
-        // }
-        this.$emit('input', value)
-        this.emitChange(value)
-        this.visible = false
-      }
-    },
-    handleCheck(data, info) {
-      const { checkedNodes } = info
-      let nodes = []
-      switch (this.showCheckedStrategy) {
-        case 'parent':
-          nodes = this.getTreeCheckedParentNodes()
-          break
-        case 'child':
-          nodes = checkedNodes.filter(({ children }) => !(children && children.length))
-          break
-        default:
-          nodes = checkedNodes
-          break
-      }
-      const values = nodes.map((node) => node[this.nodeKey])
-      if (this.filterable) this.$refs.input && this.$refs.input.focus()
-      this.$emit('input', values)
-      this.emitChange(values)
-    },
-    getTreeCheckedParentNodes() {
-      const checkedNodes = []
-      const traverse = (node) => {
-        const childNodes = node.root ? node.root.childNodes : node.childNodes
-        childNodes.forEach(child => {
-          if (child.checked && !child.isLeaf) {
-            checkedNodes.push({
-              label: child.data.label,
-              value: child.data.value
+        fixZIndex () {
+            PopupManager.getZIndex()
+        },
+        handleFocus (event) {
+            this.treeVisibleOnFocus = true
+            this.visible = true
+            this.$emit('focus', event)
+        },
+        handleClose () {
+            this.visible = false
+        },
+        toggleTree () {
+            if (this.selectDisabled) return
+            if (this.treeVisibleOnFocus) {
+                this.treeVisibleOnFocus = false
+            } else {
+                this.visible = !this.visible
+            }
+        },
+        handleIconClick (event) {
+            if (this.suffixIconClass.indexOf('el-icon-circle-close') > -1) {
+                event.stopPropagation()
+                this.visible = false
+                this.$emit('input', '')
+                this.emitChange('')
+                this.$emit('clear')
+                this.selected = {}
+                this.selectedLabel = ''
+            }
+        },
+        emitChange (val) {
+            if (!valueEquals(this.value, val)) {
+                this.$emit('change', val, this.getNodeData(val))
+            }
+        },
+        handleQueryChange (val) {
+            this.$refs.tree && this.$refs.tree.filter(val)
+        },
+        handleNodeClick (data, node, tree) {
+            if (this.showCheckbox) return
+            if (typeof this.allowSelection === 'function' && !this.allowSelection(data, node, tree)) {
+                return false
+            }
+            if ((this.selectMode === 'leaf' && !node.isLeaf) || (this.selectMode === 'leaf' && node.data.isLeaf === false)) {
+                this.$message.warning(this.warningText)
+                return false
+            }
+            this.setSelectedNode(data, node, tree)
+        },
+        setSelectedNode (data, node, tree) {
+            const value = data[this.nodeKey]
+            if (this.multiple) {
+                const valueCopy = this.value.slice()
+                const index = this.getValueIndex(valueCopy, value)
+                if (index > -1) {
+                    valueCopy.splice(index, 1)
+                } else {
+                    valueCopy.push(value)
+                }
+                this.$refs.input && this.$refs.input.focus()
+                this.$emit('input', valueCopy)
+                this.emitChange(valueCopy)
+            } else {
+                // if (value === this.value) {
+                //   value = ''
+                // }
+                this.$emit('input', value)
+                this.emitChange(value)
+                this.visible = false
+            }
+        },
+        handleCheck (data, info) {
+            const { checkedNodes } = info
+            let nodes = []
+            switch (this.showCheckedStrategy) {
+                case 'parent':
+                    nodes = this.getTreeCheckedParentNodes()
+                    break
+                case 'child':
+                    nodes = checkedNodes.filter(({ children }) => !(children && children.length))
+                    break
+                default:
+                    nodes = checkedNodes
+                    break
+            }
+            const values = nodes.map((node) => node[this.nodeKey])
+            if (this.filterable) this.$refs.input && this.$refs.input.focus()
+            this.$emit('input', values)
+            this.emitChange(values)
+        },
+        getTreeCheckedParentNodes () {
+            const checkedNodes = []
+            const traverse = (node) => {
+                const childNodes = node.root ? node.root.childNodes : node.childNodes
+                childNodes.forEach(child => {
+                    if (child.checked && !child.isLeaf) {
+                        checkedNodes.push({
+                            label: child.data.label,
+                            value: child.data.value
+                        })
+                    } else {
+                        traverse(child)
+                    }
+                })
+            }
+            traverse(this.$refs.tree.store)
+            return checkedNodes
+        },
+        getNodeData (value) {
+            let node = null
+            if (Array.isArray(this.data)) {
+                const traverse = (arr, lablePrefix = []) => {
+                    for (let i = 0; i < arr.length; i++) {
+                        const child = arr[i]
+                        let labelData = child[this.labelKey]
+                        if (typeof this.labelKey !== 'string') {
+                            labelData = this.labelKey(child)
+                        }
+                        if (child[this.nodeKey] === value) {
+                            node = {
+                                label: labelData,
+                                value: child[this.nodeKey],
+                                path: [...lablePrefix, labelData].join(this.separator),
+                                data: child
+                            }
+                            break
+                        } else if (child.children && child.children.length > 0) {
+                            traverse(child.children, [...lablePrefix, labelData])
+                        }
+                    }
+                }
+                traverse(this.data)
+            }
+            return node
+        },
+        onInputChange () {
+            if (this.filterable && this.query !== this.selectedLabel) {
+                this.query = this.selectedLabel
+                this.handleQueryChange(this.query)
+            }
+        },
+        filterNodeMethod (value, data) {
+            if (!value) return true
+            this.$nextTick(this.updatePopper)
+            if (typeof this.filterMethod === 'function') {
+                return this.filterMethod(value, data)
+            } else {
+                if (data[this.labelKey]) {
+                    return data[this.labelKey].indexOf(value) !== -1
+                } else {
+                    if (data.label) {
+                        return data.label.indexOf(value) !== -1
+                    } else {
+                        return true
+                    }
+                }
+            }
+        },
+        resetInputHeight () {
+            this.$nextTick(() => {
+                if (!this.$refs.reference || !this.$refs.tags) return
+                const inputEl = this.$refs.reference.$refs.input
+                const tags = this.$refs.tags
+                let height = sizeMap[this.selectSize] || 40
+                if (this.selected.length !== 0) {
+                    height = Math.max((tags.clientHeight + (tags.clientHeight > height ? 6 : 0)), height)
+                }
+                inputEl.style.height = `${height}px`
+                if (this.visible) {
+                    this.updatePopper()
+                }
             })
-          } else {
-            traverse(child)
-          }
-        })
-      }
-      traverse(this.$refs.tree.store)
-      return checkedNodes
-    },
-    getNodeData(value) {
-      let node = null
-      if (Array.isArray(this.data)) {
-        const traverse = (arr, lablePrefix = []) => {
-          for (let i = 0; i < arr.length; i++) {
-            const child = arr[i]
-            let labelData = child[this.labelKey]
-            if (typeof this.labelKey !== 'string') {
-              labelData = this.labelKey(child)
+        },
+        getValueIndex (arr = [], value) {
+            let index = -1
+            arr.some((item, i) => {
+                if (item === value) {
+                    index = i
+                    return true
+                } else {
+                    return false
+                }
+            })
+            return index
+        },
+        deletePrevTag (e) {
+            if (e.target.value.length <= 0) {
+                this.selected.splice(-1, 1)
+                const values = this.selected.map(({ value }) => value)
+                this.$emit('input', values)
+                this.emitChange(values)
             }
-            if (child[this.nodeKey] === value) {
-              node = {
-                label: labelData,
-                value: child[this.nodeKey],
-                path: [...lablePrefix, labelData].join(this.separator),
-                data: child
-              }
-              break
-            } else if (child.children && child.children.length > 0) {
-              traverse(child.children, [...lablePrefix, labelData])
+        },
+        deleteTag (item) {
+            this.selected = this.selected.filter(selectItem => selectItem !== item)
+            const values = this.selected.map(({ value }) => value)
+            this.$emit('input', values)
+            this.emitChange(values)
+        },
+        resetInputWidth () {
+            this.inputWidth = this.$refs.reference && this.$refs.reference ? this.$refs.reference.$el.getBoundingClientRect().width : 0
+        },
+        handleResize () {
+            this.resetInputWidth()
+            if (this.multiple) this.resetInputHeight()
+        },
+        setSelected () {
+            if (this.multiple) {
+                const result = []
+                if (Array.isArray(this.value)) {
+                    this.value.forEach(value => {
+                        const node = this.getNodeData(value)
+                        if (node) result.push(node)
+                    })
+                }
+                this.selected = result
+                if (result.length === 0) {
+                    this.selectedLabel = ''
+                }
+                this.$nextTick(this.resetInputHeight)
+            } else {
+                const node = this.getNodeData(this.value)
+                if (node) {
+                    this.selected = node
+                    this.selectedLabel = this.displayMode === 'name' ? node.label : node.path
+                    if (this.filterable) this.query = this.selectedLabel
+                } else {
+                    this.selected = {}
+                    this.selectedLabel = ''
+                    if (this.filterable) this.query = ''
+                }
             }
-          }
-        }
-        traverse(this.data)
-      }
-      return node
-    },
-    onInputChange() {
-      if (this.filterable && this.query !== this.selectedLabel) {
-        this.query = this.selectedLabel
-        this.handleQueryChange(this.query)
-      }
-    },
-    filterNodeMethod(value, data) {
-      if (!value) return true
-      this.$nextTick(this.updatePopper)
-      if (typeof this.filterMethod === 'function') {
-        return this.filterMethod(value, data)
-      } else {
-        if (data[this.labelKey]) {
-          return data[this.labelKey].indexOf(value) !== -1
-        } else {
-          if (data.label) {
-            return data.label.indexOf(value) !== -1
-          } else {
-            return true
-          }
-        }
-      }
-    },
-    resetInputHeight() {
-      this.$nextTick(() => {
-        if (!this.$refs.reference || !this.$refs.tags) return
-        const inputEl = this.$refs.reference.$refs.input
-        const tags = this.$refs.tags
-        let height = sizeMap[this.selectSize] || 40
-        if (this.selected.length !== 0) {
-          height = Math.max((tags.clientHeight + (tags.clientHeight > height ? 6 : 0)), height)
-        }
-        inputEl.style.height = `${height}px`
-        if (this.visible) {
-          this.updatePopper()
-        }
-      })
-    },
-    getValueIndex(arr = [], value) {
-      let index = -1
-      arr.some((item, i) => {
-        if (item === value) {
-          index = i
-          return true
-        } else {
-          return false
-        }
-      })
-      return index
-    },
-    deletePrevTag(e) {
-      if (e.target.value.length <= 0) {
-        this.selected.splice(-1, 1)
-        const values = this.selected.map(({ value }) => value)
-        this.$emit('input', values)
-        this.emitChange(values)
-      }
-    },
-    deleteTag(item) {
-      this.selected = this.selected.filter(selectItem => selectItem !== item)
-      const values = this.selected.map(({ value }) => value)
-      this.$emit('input', values)
-      this.emitChange(values)
-    },
-    resetInputWidth() {
-      this.inputWidth = this.$refs.reference && this.$refs.reference ? this.$refs.reference.$el.getBoundingClientRect().width : 0
-    },
-    handleResize() {
-      this.resetInputWidth()
-      if (this.multiple) this.resetInputHeight()
-    },
-    setSelected() {
-      if (this.multiple) {
-        const result = []
-        if (Array.isArray(this.value)) {
-          this.value.forEach(value => {
-            const node = this.getNodeData(value)
-            if (node) result.push(node)
-          })
-        }
-        this.selected = result
-        if (result.length === 0) {
-          this.selectedLabel = ''
-        }
-        this.$nextTick(this.resetInputHeight)
-      } else {
-        const node = this.getNodeData(this.value)
-        if (node) {
-          this.selected = node
-          this.selectedLabel = this.displayMode === 'name' ? node.label : node.path
-          if (this.filterable) this.query = this.selectedLabel
-        } else {
-          this.selected = {}
-          this.selectedLabel = ''
-          if (this.filterable) this.query = ''
         }
-      }
     }
-  }
 }
 </script>
 <style lang="scss">

+ 363 - 362
src/views/platform/data/dataTemplate/create.vue

@@ -1,122 +1,124 @@
 <template>
-  <el-dialog
-    :visible.sync="dialogVisible"
-    :close-on-click-modal="false"
-    :close-on-press-escape="false"
-    append-to-body
-    :title="title"
-    class="dialog dataTemplate-create-dialog"
-    @open="getFormData"
-    @close="closeDialog"
-  >
-    <el-form
-      ref="dataTemplateForm"
-      v-loading="dialogLoading"
-      :element-loading-text="$t('common.loading')"
-      :model="dataTemplate"
-      :rules="rules"
-      :label-width="formLabelWidth"
-      @submit.native.prevent
+    <el-dialog
+        :visible.sync="dialogVisible"
+        :close-on-click-modal="false"
+        :close-on-press-escape="false"
+        append-to-body
+        :title="title"
+        class="dialog dataTemplate-create-dialog"
+        @open="getFormData"
+        @close="closeDialog"
     >
-      <el-form-item label="模版名称:" prop="name">
-        <el-input v-model="dataTemplate.name" v-pinyin="{vm:dataTemplate}" />
-      </el-form-item>
-      <el-form-item label="模版Key:" prop="key">
-        <el-input v-model="dataTemplate.key" />
-      </el-form-item>
-      <el-form-item label="分类:" prop="typeId">
-        <ibps-type-select
-          ref="typeSelect"
-          v-model="dataTemplate.typeId"
-          category-key="BO_TYPE"
-          clearable
-        />
-      </el-form-item>
-      <el-form-item label="模版类型:" prop="type">
-        <el-select v-model="dataTemplate.type" style="width:100%;">
-          <el-option
-            v-for="option in templateTypeOptions"
-            :key="option.value"
-            :value="option.value"
-            :label="option.label"
-          />
-        </el-select>
-      </el-form-item>
-      <el-form-item v-if="dataTemplate.type !== 'valueSource'" label="展示形式:" prop="showType">
-        <el-select v-model="dataTemplate.showType" style="width:100%;">
-          <el-option
-            v-for="option in showTypeOptions"
-            :key="option.value"
-            :value="option.value"
-            :label="option.label"
-          />
-        </el-select>
-      </el-form-item>
+        <el-form
+            ref="dataTemplateForm"
+            v-loading="dialogLoading"
+            :element-loading-text="$t('common.loading')"
+            :model="dataTemplate"
+            :rules="rules"
+            :label-width="formLabelWidth"
+            @submit.native.prevent
+        >
+            <el-form-item label="模版名称:" prop="name">
+                <el-input v-model="dataTemplate.name" v-pinyin="{vm:dataTemplate}" />
+            </el-form-item>
+            <el-form-item label="模版Key:" prop="key">
+                <el-input v-model="dataTemplate.key" />
+            </el-form-item>
+            <el-form-item label="分类:" prop="typeId">
+                <ibps-type-select
+                    ref="typeSelect"
+                    v-model="dataTemplate.typeId"
+                    category-key="BO_TYPE"
+                    clearable
+                    filter-label="name"
+                    :filterable="true"
+                />
+            </el-form-item>
+            <el-form-item label="模版类型:" prop="type">
+                <el-select v-model="dataTemplate.type" style="width:100%;">
+                    <el-option
+                        v-for="option in templateTypeOptions"
+                        :key="option.value"
+                        :value="option.value"
+                        :label="option.label"
+                    />
+                </el-select>
+            </el-form-item>
+            <el-form-item v-if="dataTemplate.type !== 'valueSource'" label="展示形式:" prop="showType">
+                <el-select v-model="dataTemplate.showType" style="width:100%;">
+                    <el-option
+                        v-for="option in showTypeOptions"
+                        :key="option.value"
+                        :value="option.value"
+                        :label="option.label"
+                    />
+                </el-select>
+            </el-form-item>
 
-      <el-form-item v-if="dataTemplate.type !== 'valueSource' && dataTemplate.showType === 'compose'" label="组合形式:" prop="composeType">
-        <el-select v-model="dataTemplate.composeType" style="width:100%;">
-          <el-option
-            v-for="option in composeTypeOptions"
-            :key="option.value"
-            :value="option.value"
-            :label="option.label"
-          />
-        </el-select>
-      </el-form-item>
-      <el-form-item v-if="dataTemplate.showType !== 'compose'||dataTemplate.composeType==='treeForm'" prop="datasetKey">
-        <span slot="label">
-          <label>数据集</label>
-          <el-tooltip
-            v-if="!readonly"
-            class="item"
-            effect="light"
-            content="左树右表单需选择有树形结构的表数据"
-            placement="bottom"
-          >
-            <ibps-icon name="help" style="color:#dd5b44;" />
-          </el-tooltip>:
-        </span>
-        <dataset-selector
-          v-model="dataTemplate.datasetKey"
-          value-key="key"
-          @change="changeDataset"
-        />
-      </el-form-item>
-    </el-form>
-    <div slot="footer" class="el-dialog--center">
-      <ibps-toolbar
-        :actions="toolbars"
-        @action-event="handleActionEvent"
-      />
-    </div>
+            <el-form-item v-if="dataTemplate.type !== 'valueSource' && dataTemplate.showType === 'compose'" label="组合形式:" prop="composeType">
+                <el-select v-model="dataTemplate.composeType" style="width:100%;">
+                    <el-option
+                        v-for="option in composeTypeOptions"
+                        :key="option.value"
+                        :value="option.value"
+                        :label="option.label"
+                    />
+                </el-select>
+            </el-form-item>
+            <el-form-item v-if="dataTemplate.showType !== 'compose'||dataTemplate.composeType==='treeForm'" prop="datasetKey">
+                <span slot="label">
+                    <label>数据集</label>
+                    <el-tooltip
+                        v-if="!readonly"
+                        class="item"
+                        effect="light"
+                        content="左树右表单需选择有树形结构的表数据"
+                        placement="bottom"
+                    >
+                        <ibps-icon name="help" style="color:#dd5b44;" />
+                    </el-tooltip>:
+                </span>
+                <dataset-selector
+                    v-model="dataTemplate.datasetKey"
+                    value-key="key"
+                    @change="changeDataset"
+                />
+            </el-form-item>
+        </el-form>
+        <div slot="footer" class="el-dialog--center">
+            <ibps-toolbar
+                :actions="toolbars"
+                @action-event="handleActionEvent"
+            />
+        </div>
 
-    <!--字段设置-->
-    <setting-field
-      :visible="settingFieldDialogVisible"
-      :dataset-key="dataTemplate.datasetKey"
-      :dataset-type="dataTemplate.datasetType"
-      :width="dataTemplate.datasetType==='thirdparty'?'60%':'60%'"
-      :top="dataTemplate.datasetType==='thirdparty'?'0vh':'5vh'"
-      type="next"
-      @callback="handleSettingField"
-      @close="visible => settingFieldDialogVisible = visible"
-    />
-    <thirdparty-config
-      :visible="thirdpartyConfigDialogVisible"
-      :datasets="dataTemplate.datasets"
-      type="next"
-      @callback="handleSettingField"
-      @close="visible => settingFieldDialogVisible = visible"
-    />
+        <!--字段设置-->
+        <setting-field
+            :visible="settingFieldDialogVisible"
+            :dataset-key="dataTemplate.datasetKey"
+            :dataset-type="dataTemplate.datasetType"
+            :width="dataTemplate.datasetType==='thirdparty'?'60%':'60%'"
+            :top="dataTemplate.datasetType==='thirdparty'?'0vh':'5vh'"
+            type="next"
+            @callback="handleSettingField"
+            @close="visible => settingFieldDialogVisible = visible"
+        />
+        <thirdparty-config
+            :visible="thirdpartyConfigDialogVisible"
+            :datasets="dataTemplate.datasets"
+            type="next"
+            @callback="handleSettingField"
+            @close="visible => settingFieldDialogVisible = visible"
+        />
 
-    <!--数据模版设置-->
-    <template-builder
-      :visible="templatebuilderDialogVisible"
-      :data="dataTemplate"
-      @callback="$emit('callback')"
-      @close="visible => templatebuilderDialogVisible = visible"
-    />
-  </el-dialog>
+        <!--数据模版设置-->
+        <template-builder
+            :visible="templatebuilderDialogVisible"
+            :data="dataTemplate"
+            @callback="$emit('callback')"
+            @close="visible => templatebuilderDialogVisible = visible"
+        />
+    </el-dialog>
 </template>
 
 <script>
@@ -135,278 +137,277 @@ import { testKey } from '@/utils/validate'
 import i18n from '@/utils/i18n'
 
 const validateFormKey = (rule, dataTemplateKey, callback) => {
-  if (!testKey(dataTemplateKey)) {
-    callback(new Error(i18n.t('validate.key')))
-  } else {
-    isKeyExists({
-      dataTemplateKey: dataTemplateKey
-    }).then(response => {
-      if (response.data === true) {
-        callback(new Error(`数据模版key已经存在`))
-        return
-      }
-      callback()
-    }).catch((err) => {
-      callback(new Error(err))
-    })
-  }
+    if (!testKey(dataTemplateKey)) {
+        callback(new Error(i18n.t('validate.key')))
+    } else {
+        isKeyExists({
+            dataTemplateKey: dataTemplateKey
+        }).then(response => {
+            if (response.data === true) {
+                callback(new Error(`数据模版key已经存在`))
+                return
+            }
+            callback()
+        }).catch((err) => {
+            callback(new Error(err))
+        })
+    }
 }
 
 export default {
-  components: {
-    IbpsTypeSelect,
-    DatasetSelector,
-    SettingField,
-    ThirdpartyConfig,
-    TemplateBuilder
-  },
-  props: {
-    visible: {
-      type: Boolean,
-      default: false
+    components: {
+        IbpsTypeSelect,
+        DatasetSelector,
+        SettingField,
+        ThirdpartyConfig,
+        TemplateBuilder
     },
-    readonly: {
-      type: Boolean,
-      default: false
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        readonly: {
+            type: Boolean,
+            default: false
+        },
+        id: String,
+        title: String,
+        typeId: String
     },
-    id: String,
-    title: String,
-    typeId: String
-  },
-  data() {
-    return {
-      formName: 'dataTemplateForm',
-      formLabelWidth: '120px',
-      dialogVisible: this.visible,
-      dialogLoading: false,
-      templatebuilderDialogVisible: false,
-      templateTypeOptions,
-      showTypeOptions,
-      composeTypeOptions,
+    data () {
+        return {
+            formName: 'dataTemplateForm',
+            formLabelWidth: '120px',
+            dialogVisible: this.visible,
+            dialogLoading: false,
+            templatebuilderDialogVisible: false,
+            templateTypeOptions,
+            showTypeOptions,
+            composeTypeOptions,
 
-      settingFieldDialogVisible: false,
-      thirdpartyConfigDialogVisible: false,
+            settingFieldDialogVisible: false,
+            thirdpartyConfigDialogVisible: false,
 
-      defaultForm: {},
-      dataTemplate: {
-        name: '',
-        key: '',
-        typeId: '',
-        type: 'default',
-        showType: 'list',
-        composeType: 'treeList',
-        datasetKey: '',
-        datasetType: 'table',
-        unique: ''
-      },
-      rules: {
-        name: [{ required: true, message: this.$t('validate.required') }],
-        key: [{ required: true, message: this.$t('validate.required') },
-          { validator: validateFormKey, trigger: 'change' }],
-        type: [{ required: true, message: this.$t('validate.required') }],
-        composeType: [{ required: false, message: this.$t('validate.required') }],
-        showType: [{ required: true, message: this.$t('validate.required') }],
-        datasetKey: [{ required: true, message: this.$t('validate.required') }]
-      },
-      toolbars: [
-        { key: 'next', icon: 'ibps-icon-arrow-circle-right', label: '下一步' },
-        { key: 'cancel' }
-      ]
-    }
-  },
-  computed: {
-    formId() {
-      return this.id
-    }
-  },
-  watch: {
-    visible: {
-      handler: function(val, oldVal) {
-        this.dialogVisible = this.visible
-      },
-      immediate: true
-    },
-    'dataTemplate.showType': {
-      handler: function(val, oldVal) {
-        if (val === 'compose') {
-          this.formValidate()
+            defaultForm: {},
+            dataTemplate: {
+                name: '',
+                key: '',
+                typeId: '',
+                type: 'default',
+                showType: 'list',
+                composeType: 'treeList',
+                datasetKey: '',
+                datasetType: 'table',
+                unique: ''
+            },
+            rules: {
+                name: [{ required: true, message: this.$t('validate.required') }],
+                key: [{ required: true, message: this.$t('validate.required') },
+                    { validator: validateFormKey, trigger: 'change' }],
+                type: [{ required: true, message: this.$t('validate.required') }],
+                composeType: [{ required: false, message: this.$t('validate.required') }],
+                showType: [{ required: true, message: this.$t('validate.required') }],
+                datasetKey: [{ required: true, message: this.$t('validate.required') }]
+            },
+            toolbars: [
+                { key: 'next', icon: 'ibps-icon-arrow-circle-right', label: '下一步' },
+                { key: 'cancel' }
+            ]
         }
-      },
-      immediate: true
-    }
-  },
-  created() {
-    this.defaultForm = JSON.parse(JSON.stringify(this.dataTemplate))
-  },
-  methods: {
-    changeDataset(data) {
-      this.dataTemplate.datasetType = data.type
     },
-    handleActionEvent({ key }) {
-      switch (key) {
-        case 'next':
-          this.handleNext()
-          break
-        case 'cancel':
-          this.closeDialog()
-          break
-        default:
-          break
-      }
+    computed: {
+        formId () {
+            return this.id
+        }
     },
-    // 设置字段
-    handleNext() {
-      this.$refs[this.formName].validate(valid => {
-        if (valid) {
-          // if (this.dataTemplate.datasetType === 'thirdparty') {
-          //   if (!(this.dataTemplate.type === 'dialog' || this.dataTemplate.type === 'valueSource')) {
-          //     ActionUtils.warning('第三方服务数据集只支持"对话框、值来源"模版类型!')
-          //     return
-          //   }
-          // }
-          if (this.dataTemplate.showType !== 'compose') {
-            this.settingFieldDialogVisible = true
-            this.closeDialog()
-          } else {
-            this.templatebuilderDialogVisible = true
-            this.closeDialog()
-          }
-        } else {
-          ActionUtils.saveErrorMessage()
+    watch: {
+        visible: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+            },
+            immediate: true
+        },
+        'dataTemplate.showType': {
+            handler: function (val, oldVal) {
+                if (val === 'compose') {
+                    this.formValidate()
+                }
+            },
+            immediate: true
         }
-      })
     },
-    handleSettingField(data) {
-      //  如果是第三方服务,需要解析数据字段columns
-      if (this.dataTemplate.datasetType === 'thirdparty') {
-        this.dataTemplate.thirdparty = data
+    created () {
+        this.defaultForm = JSON.parse(JSON.stringify(this.dataTemplate))
+    },
+    methods: {
+        changeDataset (data) {
+            this.dataTemplate.datasetType = data.type
+        },
+        handleActionEvent ({ key }) {
+            switch (key) {
+                case 'next':
+                    this.handleNext()
+                    break
+                case 'cancel':
+                    this.closeDialog()
+                    break
+                default:
+                    break
+            }
+        },
+        // 设置字段
+        handleNext () {
+            this.$refs[this.formName].validate(valid => {
+                if (valid) {
+                    // if (this.dataTemplate.datasetType === 'thirdparty') {
+                    //   if (!(this.dataTemplate.type === 'dialog' || this.dataTemplate.type === 'valueSource')) {
+                    //     ActionUtils.warning('第三方服务数据集只支持"对话框、值来源"模版类型!')
+                    //     return
+                    //   }
+                    // }
+                    if (this.dataTemplate.showType !== 'compose') {
+                        this.settingFieldDialogVisible = true
+                        this.closeDialog()
+                    } else {
+                        this.templatebuilderDialogVisible = true
+                        this.closeDialog()
+                    }
+                } else {
+                    ActionUtils.saveErrorMessage()
+                }
+            })
+        },
+        handleSettingField (data) {
+            //  如果是第三方服务,需要解析数据字段columns
+            if (this.dataTemplate.datasetType === 'thirdparty') {
+                this.dataTemplate.thirdparty = data
 
-        // const queryColumnsAll = Utils.getFieldsByType('query')
-        // console.log('queryColumnsAll', queryColumnsAll)
+                // const queryColumnsAll = Utils.getFieldsByType('query')
+                // console.log('queryColumnsAll', queryColumnsAll)
 
-        // 1.1解析第三方服务字段-接口参数
-        // const queryColumns = []
-        // const requestData = data.requestData// array
-        // if (this.$utils.isNotEmpty(requestData.bodyData)) {
-        //   requestData.bodyData.forEach(item => {
-        //     // 找到参数配置
-        //     this.forEachColumnArray('queryRootColumn', item, queryColumns)
-        //   })
-        //   console.log('queryColumns', queryColumns)
-        //   this.dataTemplate.queryColumns = queryColumns
-        // }
+                // 1.1解析第三方服务字段-接口参数
+                // const queryColumns = []
+                // const requestData = data.requestData// array
+                // if (this.$utils.isNotEmpty(requestData.bodyData)) {
+                //   requestData.bodyData.forEach(item => {
+                //     // 找到参数配置
+                //     this.forEachColumnArray('queryRootColumn', item, queryColumns)
+                //   })
+                //   console.log('queryColumns', queryColumns)
+                //   this.dataTemplate.queryColumns = queryColumns
+                // }
 
-        // TODO 1.2解析第三方服务字段-接口参数-分页
+                // TODO 1.2解析第三方服务字段-接口参数-分页
 
-        // 2.1解析第三方服务字段-接口返回
-        const dataColumns = []
-        // const responseData = data.responseData// array
-        // responseData.forEach(item => {
-        //   // 找到数据配置
-        //   this.forEachColumnArray('dataRootClumn', item, dataColumns)
-        // })
-        // console.log('dataColumns', dataColumns)
-        this.dataTemplate.datasets = dataColumns
+                // 2.1解析第三方服务字段-接口返回
+                const dataColumns = []
+                // const responseData = data.responseData// array
+                // responseData.forEach(item => {
+                //   // 找到数据配置
+                //   this.forEachColumnArray('dataRootClumn', item, dataColumns)
+                // })
+                // console.log('dataColumns', dataColumns)
+                this.dataTemplate.datasets = dataColumns
 
-        // TODO 2.2解析第三方服务字段-接口返回-分页
-      } else {
-        this.dataTemplate.datasets = data
-      }
-      this.templatebuilderDialogVisible = true
-      this.settingFieldDialogVisible = false
-    },
-    forEachColumnArray(bind, item, columns) {
-      if (item.bindType.includes(bind)) {
-        if (item.dataType === 'array') {
-          const primaryItem = item.children[0]
-          if (primaryItem.dataType === 'object') {
-            const primaryObject = primaryItem.children
-            const rootId = this.$utils.guid()
-            const rootColumn = {
-              'id': rootId,
-              'label': primaryItem.desc,
-              'name': primaryItem.name,
-              'parentId': '0',
-              'type': 'table',
-              'attrType': 'table',
-              'objName': primaryItem.name,
-              'isPk': 'N',
-              'icon': 'table'
+                // TODO 2.2解析第三方服务字段-接口返回-分页
+            } else {
+                this.dataTemplate.datasets = data
             }
-            columns.push(rootColumn)
-            primaryObject.forEach(item2 => {
-              if (item2.dataType === 'array' || item2.dataType === 'object') {
-                console.log('暂不支持子表字段解析')
-              } else {
-                // ibps-icon-table ibps-icon-varchar ibps-icon-number ibps-icon-date
-                // id bindType name dataType children desc
-                const type_ = (item2.dataType === 'string' ? 'varchar' : item2.dataType)
-                const column = {
-                  'id': item2.id,
-                  'label': item2.desc,
-                  'name': item2.name,
-                  'parentId': rootId,
-                  'type': type_,
-                  'attrType': 'column',
-                  'objName': item2.name,
-                  'isPk': 'N',
-                  'icon': type_
+            this.templatebuilderDialogVisible = true
+            this.settingFieldDialogVisible = false
+        },
+        forEachColumnArray (bind, item, columns) {
+            if (item.bindType.includes(bind)) {
+                if (item.dataType === 'array') {
+                    const primaryItem = item.children[0]
+                    if (primaryItem.dataType === 'object') {
+                        const primaryObject = primaryItem.children
+                        const rootId = this.$utils.guid()
+                        const rootColumn = {
+                            'id': rootId,
+                            'label': primaryItem.desc,
+                            'name': primaryItem.name,
+                            'parentId': '0',
+                            'type': 'table',
+                            'attrType': 'table',
+                            'objName': primaryItem.name,
+                            'isPk': 'N',
+                            'icon': 'table'
+                        }
+                        columns.push(rootColumn)
+                        primaryObject.forEach(item2 => {
+                            if (item2.dataType === 'array' || item2.dataType === 'object') {
+                                console.log('暂不支持子表字段解析')
+                            } else {
+                                // ibps-icon-table ibps-icon-varchar ibps-icon-number ibps-icon-date
+                                // id bindType name dataType children desc
+                                const type_ = (item2.dataType === 'string' ? 'varchar' : item2.dataType)
+                                const column = {
+                                    'id': item2.id,
+                                    'label': item2.desc,
+                                    'name': item2.name,
+                                    'parentId': rootId,
+                                    'type': type_,
+                                    'attrType': 'column',
+                                    'objName': item2.name,
+                                    'isPk': 'N',
+                                    'icon': type_
+                                }
+                                columns.push(column)
+                            }
+                        })
+                    } else {
+                        // 暂不支持
+                        ActionUtils.warning('返回数据体类型不支持非对象类型!')
+                        return
+                    }
+                } else {
+                    // 暂不支持
+                    ActionUtils.warning('返回数据根类型不支持非数组数据!')
+                    return
                 }
-                columns.push(column)
-              }
+            }
+
+            if (item.dataType === 'object' || item.dataType === 'array') {
+                item.children.forEach(item2 => {
+                    this.forEachColumnArray(bind, item2, columns)
+                })
+            }
+        },
+        // 关闭当前窗口
+        closeDialog () {
+            this.$emit('close', false)
+        },
+        /**
+         * 表单验证
+         */
+        formValidate () {
+            if (this.readonly) return
+            this.$nextTick(() => {
+                this.$refs[this.formName].validate(() => {})
+            })
+        },
+        /**
+         * 获取表单数据
+         */
+        getFormData () {
+            // 重置表单
+            this.dataTemplate = JSON.parse(JSON.stringify(this.defaultForm))
+            this.dataTemplate.typeId = this.typeId
+            this.formValidate()
+            this.$nextTick(() => {
+                this.$refs['typeSelect'].loadTreeData()
             })
-          } else {
-            // 暂不支持
-            ActionUtils.warning('返回数据体类型不支持非对象类型!')
-            return
-          }
-        } else {
-          // 暂不支持
-          ActionUtils.warning('返回数据根类型不支持非数组数据!')
-          return
         }
-      }
-
-      if (item.dataType === 'object' || item.dataType === 'array') {
-        item.children.forEach(item2 => {
-          this.forEachColumnArray(bind, item2, columns)
-        })
-      }
-    },
-    // 关闭当前窗口
-    closeDialog() {
-      this.$emit('close', false)
-    },
-    /**
-     * 表单验证
-     */
-    formValidate() {
-      if (this.readonly) return
-      this.$nextTick(() => {
-        this.$refs[this.formName].validate(() => {})
-      })
-    },
-    /**
-     * 获取表单数据
-     */
-    getFormData() {
-      // 重置表单
-      this.dataTemplate = JSON.parse(JSON.stringify(this.defaultForm))
-      this.dataTemplate.typeId = this.typeId
-      this.formValidate()
-      this.$nextTick(() => {
-        this.$refs['typeSelect'].loadTreeData()
-      })
     }
-  }
 
 }
 </script>
 <style lang="scss">
-.dataTemplate-create-dialog{
-  .el-dialog__body{
-    height:  calc(70vh - 120px) !important;
-  }
-}
-
+    .dataTemplate-create-dialog{
+        .el-dialog__body{
+            height: calc(70vh - 120px) !important;
+        }
+    }
 </style>

+ 406 - 404
src/views/platform/data/dataset/edit.vue

@@ -1,184 +1,186 @@
 <template>
-  <el-dialog
-    :title="title"
-    :visible.sync="dialogVisible"
-    :close-on-click-modal="false"
-    :close-on-press-escape="false"
-    append-to-body
-    top="15vh"
-    class="dataset-dialog"
-    width="70%"
-    @open="getFormData"
-    @close="closeDialog"
-  >
-    <el-form
-      ref="form"
-      v-loading="dialogLoading"
-      :element-loading-text="$t('common.loading')"
-      :model="form"
-      :rules="rules"
-      :label-width="formLabelWidth"
-      @submit.native.prevent
+    <el-dialog
+        :title="title"
+        :visible.sync="dialogVisible"
+        :close-on-click-modal="false"
+        :close-on-press-escape="false"
+        append-to-body
+        top="15vh"
+        class="dataset-dialog"
+        width="70%"
+        @open="getFormData"
+        @close="closeDialog"
     >
-      <el-row>
-        <el-col :span="span">
-          <el-form-item label="名称:" prop="name">
-            <el-input v-if="!readonly" v-model="form.name" v-pinyin="{vm:form}" />
-            <span v-else>{{ form.name }}</span>
-          </el-form-item>
-        </el-col>
-        <el-col :span="span">
-          <el-form-item label="数据集key:" prop="key">
-            <el-input v-if="!readonly" v-model="form.key" :disabled="disabled" />
-            <span v-else>{{ form.key }}</span>
-          </el-form-item>
-        </el-col>
-        <el-col v-if="!readonly" :span="span">
-          <el-form-item key="typeId" label="分类:" prop="typeId">
-            <ibps-type
-              ref="ibpsType"
-              v-model="form.typeId"
-              :readonly="readonly"
-              category-key="BO_TYPE"
-              class="type"
-            />
-          </el-form-item>
-        </el-col>
-        <!-- <el-col :span="12">
-          <el-form-item label="外部数据:" prop="external">
-            <el-switch
-              v-if="!readonly"
-              v-model="form.external"
-              :active-value="'Y'"
-              :inactive-value="'N'"
-              active-text="是"
-              inactive-text="否"
-            />
-            <el-tag v-else :type="form.external|optionsFilter(externalOptions,'type')">
-              {{ form.external|optionsFilter(externalOptions,'label') }}
-            </el-tag>
-          </el-form-item>
-        </el-col> -->
-        <el-col v-if="form.external==='Y'" :span="12" style="height:50px;">
-          <el-form-item label="数据源:" prop="dsAlias">
-            <el-select
-              v-if="!readonly"
-              v-model="form.dsAlias"
-              clearable
-              placeholder="请选择"
-              style="width:100%;"
-            >
-              <el-option
-                v-for="item in dsAliasOptions"
-                :key="item.value"
-                :label="item.label"
-                :value="item.value"
-              />
-            </el-select>
-            <el-tag v-else :type="form.dsAlias|optionsFilter(externalOptions,'type')">
-              {{ form.dsAlias|optionsFilter(externalOptions,'label') }}
-            </el-tag>
-          </el-form-item>
-        </el-col>
-        <el-col :span="span">
-          <el-form-item label="类型:" prop="type">
+        <el-form
+            ref="form"
+            v-loading="dialogLoading"
+            :element-loading-text="$t('common.loading')"
+            :model="form"
+            :rules="rules"
+            :label-width="formLabelWidth"
+            @submit.native.prevent
+        >
             <el-row>
-              <el-col :span="5">
-                <el-select
-                  v-if="!readonly"
-                  v-model="form.type"
-                  placeholder="请选择"
-                  style="width:100%;"
-                  @change="changeType"
-                >
-                  <el-option
-                    v-for="item in datasetTypeOptions"
-                    :key="item.value"
-                    :label="item.label"
-                    :value="item.value"
-                  />
-                </el-select>
-                <el-tag v-else :type="form.type|optionsFilter(datasetTypeOptions,'type')">{{ form.type|optionsFilter(datasetTypeOptions,'label') }}</el-tag>
-              </el-col>
-              <el-col :span="19">
-                <el-form-item v-if="!readonly" prop="from" class="from">
-                  <el-select v-if="form.type!=='thirdparty'" v-model="form.from" filterable placeholder="请选择或者搜索关键字后选择" style="width:100%">
-                    <el-option
-                      v-for="item in fromOptions"
-                      :key="item.value"
-                      :label="item.label"
-                      :value="item.value"
-                    />
-                  </el-select>
-                  <ibps-tree-select
-                    v-else
-                    v-model="form.from"
-                    :data="treeData"
-                    :props="props"
-                    :icon="handleIcon"
-                    :multiple="false"
-                    :allow-selection="handleAllowSelection"
-                    node-key="key"
-                    empty-text="暂无第三方服务"
-                    clearable
-                    filterable
-                  />
-                </el-form-item>
-              </el-col>
+                <el-col :span="span">
+                    <el-form-item label="名称:" prop="name">
+                        <el-input v-if="!readonly" v-model="form.name" v-pinyin="{vm:form}" />
+                        <span v-else>{{ form.name }}</span>
+                    </el-form-item>
+                </el-col>
+                <el-col :span="span">
+                    <el-form-item label="数据集key:" prop="key">
+                        <el-input v-if="!readonly" v-model="form.key" :disabled="disabled" />
+                        <span v-else>{{ form.key }}</span>
+                    </el-form-item>
+                </el-col>
+                <el-col v-if="!readonly" :span="span">
+                    <el-form-item key="typeId" label="分类:" prop="typeId">
+                        <ibps-type
+                            ref="ibpsType"
+                            v-model="form.typeId"
+                            :readonly="readonly"
+                            category-key="BO_TYPE"
+                            class="type"
+                            filter-label="name"
+                            :filterable="true"
+                        />
+                    </el-form-item>
+                </el-col>
+                <!-- <el-col :span="12">
+                    <el-form-item label="外部数据:" prop="external">
+                        <el-switch
+                            v-if="!readonly"
+                            v-model="form.external"
+                            :active-value="'Y'"
+                            :inactive-value="'N'"
+                            active-text="是"
+                            inactive-text="否"
+                        />
+                        <el-tag v-else :type="form.external|optionsFilter(externalOptions,'type')">
+                            {{ form.external|optionsFilter(externalOptions,'label') }}
+                        </el-tag>
+                    </el-form-item>
+                </el-col> -->
+                <el-col v-if="form.external==='Y'" :span="12" style="height:50px;">
+                    <el-form-item label="数据源:" prop="dsAlias">
+                        <el-select
+                            v-if="!readonly"
+                            v-model="form.dsAlias"
+                            clearable
+                            placeholder="请选择"
+                            style="width:100%;"
+                        >
+                            <el-option
+                                v-for="item in dsAliasOptions"
+                                :key="item.value"
+                                :label="item.label"
+                                :value="item.value"
+                            />
+                        </el-select>
+                        <el-tag v-else :type="form.dsAlias|optionsFilter(externalOptions,'type')">
+                            {{ form.dsAlias|optionsFilter(externalOptions,'label') }}
+                        </el-tag>
+                    </el-form-item>
+                </el-col>
+                <el-col :span="span">
+                    <el-form-item label="类型:" prop="type">
+                        <el-row>
+                            <el-col :span="5">
+                                <el-select
+                                    v-if="!readonly"
+                                    v-model="form.type"
+                                    placeholder="请选择"
+                                    style="width:100%;"
+                                    @change="changeType"
+                                >
+                                    <el-option
+                                        v-for="item in datasetTypeOptions"
+                                        :key="item.value"
+                                        :label="item.label"
+                                        :value="item.value"
+                                    />
+                                </el-select>
+                                <el-tag v-else :type="form.type|optionsFilter(datasetTypeOptions,'type')">{{ form.type|optionsFilter(datasetTypeOptions,'label') }}</el-tag>
+                            </el-col>
+                            <el-col :span="19">
+                                <el-form-item v-if="!readonly" prop="from" class="from">
+                                    <el-select v-if="form.type!=='thirdparty'" v-model="form.from" filterable placeholder="请选择或者搜索关键字后选择" style="width:100%">
+                                        <el-option
+                                            v-for="item in fromOptions"
+                                            :key="item.value"
+                                            :label="item.label"
+                                            :value="item.value"
+                                        />
+                                    </el-select>
+                                    <ibps-tree-select
+                                        v-else
+                                        v-model="form.from"
+                                        :data="treeData"
+                                        :props="props"
+                                        :icon="handleIcon"
+                                        :multiple="false"
+                                        :allow-selection="handleAllowSelection"
+                                        node-key="key"
+                                        empty-text="暂无第三方服务"
+                                        clearable
+                                        filterable
+                                    />
+                                </el-form-item>
+                            </el-col>
+                        </el-row>
+                        <p v-if="!readonly&&form.type==='thirdparty'" class="ibps-m-0"><i class="el-icon-warning" style="font-size:12px;color:#E6A23C" /> <span style="font-size:12px;color:#E6A23C">带图标</span> <i class="ibps-icon ibps-icon-list" /> <span style="font-size:12px;color:#E6A23C">数据为目录不能用作第三方服务类型参数</span> </p>
+                    </el-form-item>
+                </el-col>
+                <template v-if="readonly">
+                    <el-col :span="span">
+                        <el-form-item key="from" label="来源:">
+                            <span>{{ form.from }}</span>
+                        </el-form-item>
+                    </el-col>
+                    <!-- <el-col :span="span">
+                        <el-form-item key="isTree" label="是否树型:">
+                            <span>{{ form.isTree|optionsFilter(externalOptions,'label') }}</span>
+                        </el-form-item>
+                    </el-col> -->
+                    <el-col :span="span">
+                        <el-form-item key="createBy" label="创建人:">
+                            <ibps-employee-selector
+                                :value="form.createBy"
+                                :disabled="true"
+                                class="dataset-readonly-selector"
+                            />
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="span">
+                        <el-form-item key="createTime" label="创建时间:">
+                            <span>{{ form.createTime }}</span>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="span">
+                        <el-form-item key="updateBy" label="更新人:">
+                            <ibps-employee-selector
+                                :value="form.updateBy"
+                                :disabled="true"
+                                class="dataset-readonly-selector"
+                            />
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="span">
+                        <el-form-item key="updateTime" label="更新时间:">
+                            <span>{{ form.updateTime }}</span>
+                        </el-form-item>
+                    </el-col>
+                </template>
             </el-row>
-            <p v-if="!readonly&&form.type==='thirdparty'" class="ibps-m-0"><i class="el-icon-warning" style="font-size:12px;color:#E6A23C" /> <span style="font-size:12px;color:#E6A23C">带图标</span> <i class="ibps-icon ibps-icon-list" /> <span style="font-size:12px;color:#E6A23C">数据为目录不能用作第三方服务类型参数</span> </p>
-          </el-form-item>
-        </el-col>
-        <template v-if="readonly">
-          <el-col :span="span">
-            <el-form-item key="from" label="来源:">
-              <span>{{ form.from }}</span>
-            </el-form-item>
-          </el-col>
-          <!-- <el-col :span="span">
-            <el-form-item key="isTree" label="是否树型:">
-              <span>{{ form.isTree|optionsFilter(externalOptions,'label') }}</span>
-            </el-form-item>
-          </el-col> -->
-          <el-col :span="span">
-            <el-form-item key="createBy" label="创建人:">
-              <ibps-employee-selector
-                :value="form.createBy"
-                :disabled="true"
-                class="dataset-readonly-selector"
-              />
-            </el-form-item>
-          </el-col>
-          <el-col :span="span">
-            <el-form-item key="createTime" label="创建时间:">
-              <span>{{ form.createTime }}</span>
-            </el-form-item>
-          </el-col>
-          <el-col :span="span">
-            <el-form-item key="updateBy" label="更新人:">
-              <ibps-employee-selector
-                :value="form.updateBy"
-                :disabled="true"
-                class="dataset-readonly-selector"
-              />
-            </el-form-item>
-          </el-col>
-          <el-col :span="span">
-            <el-form-item key="updateTime" label="更新时间:">
-              <span>{{ form.updateTime }}</span>
-            </el-form-item>
-          </el-col>
-        </template>
-      </el-row>
 
-    </el-form>
-    <div slot="footer" class="el-dialog--center">
-      <ibps-toolbar
-        :actions="toolbars"
-        @action-event="handleActionEvent"
-      />
-    </div>
-  </el-dialog>
+        </el-form>
+        <div slot="footer" class="el-dialog--center">
+            <ibps-toolbar
+                :actions="toolbars"
+                @action-event="handleActionEvent"
+            />
+        </div>
+    </el-dialog>
 </template>
 
 <script>
@@ -197,248 +199,248 @@ import TreeUtils from '@/utils/tree'
 import IbpsTreeSelect from '@/components/ibps-tree-select'
 
 export default {
-  components: {
-    IbpsType,
-    IbpsTreeSelect,
-    IbpsEmployeeSelector
-  },
-  props: {
-    visible: {
-      type: Boolean,
-      default: false
+    components: {
+        IbpsType,
+        IbpsTreeSelect,
+        IbpsEmployeeSelector
     },
-    readonly: {
-      type: Boolean,
-      default: false
-    },
-    id: String,
-    title: String,
-    typeId: String
-  },
-  data() {
-    return {
-      formName: 'form',
-      formLabelWidth: '120px',
-      span: 24,
-      dialogVisible: this.visible,
-      dialogLoading: false,
-      dsAlias: false,
-      disabled: false,
-      datasetTypeOptions,
-      externalOptions: externalOptions,
-      dsAliasOptions: dsAliasOptions,
-      fromOptions: [],
-      defaultForm: {},
-      props: {
-        children: 'children',
-        label: 'name'
-      },
-      treeData: [],
-      form: {
-        key: '',
-        name: '',
-        typeId: '',
-        external: 'N',
-        type: 'table',
-        isTree: 'N',
-        from: '',
-        dsAlias: 'dataSource_default'
-      },
-      rules: {
-        key: [{ required: true, validator: validateKey },
-          { min: 1, max: 64, message: '长度不能超过64个字符', trigger: 'blur' }],
-        name: [{ required: true, message: this.$t('validate.required') },
-          { min: 1, max: 64, message: '长度不能超过64个字符', trigger: 'blur' }],
-        from: [{ required: true, message: this.$t('validate.required') }],
-        external: [{ required: true, message: this.$t('validate.required') }],
-        type: [{ required: true, message: this.$t('validate.required') }]
-      },
-      toolbars: [
-        { key: 'save', hidden: () => { return this.readonly } },
-        { key: 'cancel' }
-      ]
-    }
-  },
-  computed: {
-    formId() {
-      return this.id
-    }
-  },
-  watch: {
-    visible: {
-      handler: function(val, oldVal) {
-        this.dialogVisible = this.visible
-      },
-      immediate: true
-    }
-  },
-  created() {
-    this.defaultForm = JSON.parse(JSON.stringify(this.form))
-  },
-  methods: {
-    handleActionEvent({ key }) {
-      switch (key) {
-        case 'save':
-          this.handleSave()
-          break
-        case 'cancel':
-          this.closeDialog()
-          break
-        default:
-          break
-      }
+    props: {
+        visible: {
+            type: Boolean,
+            default: false
+        },
+        readonly: {
+            type: Boolean,
+            default: false
+        },
+        id: String,
+        title: String,
+        typeId: String
     },
-    // 保存数据
-    handleSave() {
-      this.$refs[this.formName].validate(valid => {
-        if (valid) {
-          this.saveData()
-        } else {
-          ActionUtils.saveErrorMessage()
+    data () {
+        return {
+            formName: 'form',
+            formLabelWidth: '120px',
+            span: 24,
+            dialogVisible: this.visible,
+            dialogLoading: false,
+            dsAlias: false,
+            disabled: false,
+            datasetTypeOptions,
+            externalOptions: externalOptions,
+            dsAliasOptions: dsAliasOptions,
+            fromOptions: [],
+            defaultForm: {},
+            props: {
+                children: 'children',
+                label: 'name'
+            },
+            treeData: [],
+            form: {
+                key: '',
+                name: '',
+                typeId: '',
+                external: 'N',
+                type: 'table',
+                isTree: 'N',
+                from: '',
+                dsAlias: 'dataSource_default'
+            },
+            rules: {
+                key: [{ required: true, validator: validateKey },
+                    { min: 1, max: 64, message: '长度不能超过64个字符', trigger: 'blur' }],
+                name: [{ required: true, message: this.$t('validate.required') },
+                    { min: 1, max: 64, message: '长度不能超过64个字符', trigger: 'blur' }],
+                from: [{ required: true, message: this.$t('validate.required') }],
+                external: [{ required: true, message: this.$t('validate.required') }],
+                type: [{ required: true, message: this.$t('validate.required') }]
+            },
+            toolbars: [
+                { key: 'save', hidden: () => { return this.readonly } },
+                { key: 'cancel' }
+            ]
         }
-      })
-    },
-    // 提交保存数据
-    saveData() {
-      const data = JSON.parse(JSON.stringify(this.form))
-      save(data).then(response => {
-        this.$emit('callback', this)
-        ActionUtils.saveSuccessMessage(response.message, (rtn) => {
-          if (this.$utils.isEmpty(this.formId)) {
-            this.$refs[this.formName].resetFields()
-          }
-          if (rtn) {
-            this.closeDialog()
-          } else {
-            this.formValidate()
-          }
-        })
-      }).catch((err) => {
-        console.error(err)
-      })
     },
-    // 关闭当前窗口
-    closeDialog() {
-      this.$emit('close', false)
-      this.$refs[this.formName].resetFields()
+    computed: {
+        formId () {
+            return this.id
+        }
     },
-    /**
-     * 表单验证
-     */
-    formValidate() {
-      if (this.readonly) return
-      this.$nextTick(() => {
-        this.$refs[this.formName].validate(() => {})
-      })
+    watch: {
+        visible: {
+            handler: function (val, oldVal) {
+                this.dialogVisible = this.visible
+            },
+            immediate: true
+        }
     },
-    changeType(type) {
-      this.form.from = ''
-      this.fromOptions = []
-      this.loadDataTableOrView(type)
+    created () {
+        this.defaultForm = JSON.parse(JSON.stringify(this.form))
     },
-    // 子集Key数据获取
-    loadDataTableOrView(type = 'table') {
-      if (this.$utils.isEmpty(this.formId)) {
-        this.form.from = ''
-        this.fromOptions = []
-      }
-      if (type !== 'thirdparty') {
-        getTableOrViewList({
-          from: '',
-          external: this.form.external,
-          dsAlias: this.form.dsAlias || 'dataSource_default',
-          type: type
-        }).then(response => {
-          const data = response.data
-          this.fromOptions = data.map(item => {
-            return {
-              value: item.id,
-              label: item.text + '【' + item.comment + '】'
+    methods: {
+        handleActionEvent ({ key }) {
+            switch (key) {
+                case 'save':
+                    this.handleSave()
+                    break
+                case 'cancel':
+                    this.closeDialog()
+                    break
+                default:
+                    break
+            }
+        },
+        // 保存数据
+        handleSave () {
+            this.$refs[this.formName].validate(valid => {
+                if (valid) {
+                    this.saveData()
+                } else {
+                    ActionUtils.saveErrorMessage()
+                }
+            })
+        },
+        // 提交保存数据
+        saveData () {
+            const data = JSON.parse(JSON.stringify(this.form))
+            save(data).then(response => {
+                this.$emit('callback', this)
+                ActionUtils.saveSuccessMessage(response.message, (rtn) => {
+                    if (this.$utils.isEmpty(this.formId)) {
+                        this.$refs[this.formName].resetFields()
+                    }
+                    if (rtn) {
+                        this.closeDialog()
+                    } else {
+                        this.formValidate()
+                    }
+                })
+            }).catch((err) => {
+                console.error(err)
+            })
+        },
+        // 关闭当前窗口
+        closeDialog () {
+            this.$emit('close', false)
+            this.$refs[this.formName].resetFields()
+        },
+        /**
+         * 表单验证
+         */
+        formValidate () {
+            if (this.readonly) return
+            this.$nextTick(() => {
+                this.$refs[this.formName].validate(() => {})
+            })
+        },
+        changeType (type) {
+            this.form.from = ''
+            this.fromOptions = []
+            this.loadDataTableOrView(type)
+        },
+        // 子集Key数据获取
+        loadDataTableOrView (type = 'table') {
+            if (this.$utils.isEmpty(this.formId)) {
+                this.form.from = ''
+                this.fromOptions = []
             }
-          })
-        }).catch(() => {})
-      } else {
-        findTreeData().then(response => {
-          const data = response.data
-          const treeData = []
-          data.forEach(d => {
-            if (d.parentId !== '-1') {
-              if (d.isDir === 'Y') {
-                d.disabled = true
-              }
-              treeData.push(d)
+            if (type !== 'thirdparty') {
+                getTableOrViewList({
+                    from: '',
+                    external: this.form.external,
+                    dsAlias: this.form.dsAlias || 'dataSource_default',
+                    type: type
+                }).then(response => {
+                    const data = response.data
+                    this.fromOptions = data.map(item => {
+                        return {
+                            value: item.id,
+                            label: item.text + '【' + item.comment + '】'
+                        }
+                    })
+                }).catch(() => {})
+            } else {
+                findTreeData().then(response => {
+                    const data = response.data
+                    const treeData = []
+                    data.forEach(d => {
+                        if (d.parentId !== '-1') {
+                            if (d.isDir === 'Y') {
+                                d.disabled = true
+                            }
+                            treeData.push(d)
+                        }
+                    })
+                    this.treeData = TreeUtils.transformToTreeFormat(treeData)
+                })
             }
-          })
-          this.treeData = TreeUtils.transformToTreeFormat(treeData)
-        })
-      }
-    },
-    handleIcon(data) {
-      let icon = ''
-      if (data.isDir === 'Y') {
-        icon = 'ibps-icon ibps-icon-list'
-      }
-      return icon
-    },
-    handleAllowSelection(data) {
-      if (data.isDir === 'Y') {
-        this.$message.warning('数据为目录不能用作第三方服务参数,请重新选择!')
-        return false
-      }
-      return true
-    },
-    /**
-     * 获取表单数据
-     */
-    getFormData() {
-      this.$nextTick(() => {
-        if (this.$refs['ibpsType']) {
-          this.$refs['ibpsType'].loadTreeData()
-        }
-      })
-      if (this.$utils.isEmpty(this.formId)) {
-        // 重置表单
-        this.disabled = false
-        this.form = JSON.parse(JSON.stringify(this.defaultForm))
-        this.form.typeId = this.typeId
-        this.span = 24
-        this.loadDataTableOrView()
-        this.formValidate()
-        return
-      }
-      this.dialogLoading = true
-      get({
-        datasetId: this.formId
-      }).then(response => {
-        this.span = 24
-        if (this.readonly) {
-          this.span = 12
-          this.dsAlias = false
+        },
+        handleIcon (data) {
+            let icon = ''
+            if (data.isDir === 'Y') {
+                icon = 'ibps-icon ibps-icon-list'
+            }
+            return icon
+        },
+        handleAllowSelection (data) {
+            if (data.isDir === 'Y') {
+                this.$message.warning('数据为目录不能用作第三方服务参数,请重新选择!')
+                return false
+            }
+            return true
+        },
+        /**
+         * 获取表单数据
+         */
+        getFormData () {
+            this.$nextTick(() => {
+                if (this.$refs['ibpsType']) {
+                    this.$refs['ibpsType'].loadTreeData()
+                }
+            })
+            if (this.$utils.isEmpty(this.formId)) {
+                // 重置表单
+                this.disabled = false
+                this.form = JSON.parse(JSON.stringify(this.defaultForm))
+                this.form.typeId = this.typeId
+                this.span = 24
+                this.loadDataTableOrView()
+                this.formValidate()
+                return
+            }
+            this.dialogLoading = true
+            get({
+                datasetId: this.formId
+            }).then(response => {
+                this.span = 24
+                if (this.readonly) {
+                    this.span = 12
+                    this.dsAlias = false
+                }
+                this.loadDataTableOrView(response.data.type)
+                this.disabled = true
+                this.form = response.data
+                this.formValidate()
+                this.dialogLoading = false
+            }).catch(() => {
+                this.dialogLoading = false
+            })
         }
-        this.loadDataTableOrView(response.data.type)
-        this.disabled = true
-        this.form = response.data
-        this.formValidate()
-        this.dialogLoading = false
-      }).catch(() => {
-        this.dialogLoading = false
-      })
     }
-  }
 
 }
 </script>
 <style lang="scss">
-.dataset-dialog{
-  .el-tree-select{
-    line-height: 28px;
-  }
-  .dataset-readonly-selector{
-    .is-disabled{
-      input{
-        display:none;
-      }
+    .dataset-dialog{
+        .el-tree-select{
+            line-height: 28px;
+        }
+        .dataset-readonly-selector{
+            .is-disabled{
+                input{
+                    display:none;
+                }
+            }
+        }
     }
-  }
-}
 </style>