diff --git a/src/resources/api/framework/integration/integration.js b/src/resources/api/framework/integration/integration.js index 9c18c73f7a317985c2919de51b5d83b23fabce72..0a2f5b6203e3b77a1f317da9e1a5384409ce9ef0 100644 --- a/src/resources/api/framework/integration/integration.js +++ b/src/resources/api/framework/integration/integration.js @@ -48,9 +48,6 @@ const integration = { getIntegrationColumnList(params) { return axios.post('/api/rest/integration/table/column/list', params); }, - getIntegrationColumnSearch(params) { - return axios.post('/api/rest/integration/column/data/search', params); - }, getIntegrationTableSearch(params) { return axios.post('/api/rest/integration/table/data/search', params); }, @@ -62,7 +59,6 @@ const integration = { // 查看集成调用记录内容 return axios.post('/api/rest/integration/audit/detail/get', params); } - }; export default integration; diff --git a/src/resources/components/ProcessTaskSearcher/custom-panel.vue b/src/resources/components/ProcessTaskSearcher/custom-panel.vue index 3ab0548e954467ac78f29f13899d49b0db0019c6..8f31ed5dad28c922e5f78ec880c5a5a37fff44ba 100644 --- a/src/resources/components/ProcessTaskSearcher/custom-panel.vue +++ b/src/resources/components/ProcessTaskSearcher/custom-panel.vue @@ -32,6 +32,8 @@ mode="custom" :condition="getConditionConfigByConditionData(conditionGroup, conditionData)" :conditionData="conditionData" + :isCustomValue="true" + :isCustomPanel="true" @change=" (conditionConfig, val, textStr) => { change(conditionData, 'valueList', val); diff --git a/src/resources/components/ProcessTaskSearcher/handlers/channelselect.vue b/src/resources/components/ProcessTaskSearcher/handlers/channelselect.vue index 28231912a66e5706aa7322b9c56c418d0ba25a07..14fdbfdf09c7e989c5f1dcdcc96ccd6c5f0b5554 100644 --- a/src/resources/components/ProcessTaskSearcher/handlers/channelselect.vue +++ b/src/resources/components/ProcessTaskSearcher/handlers/channelselect.vue @@ -44,6 +44,8 @@ mode="simple" :condition="getFormConditionByName(formcondition.name)" :workcenterConditionData="workcenterConditionData" + :isCustomValue="isCustomValue" + :isCustomPanel="true" @change="changeFromCondition" > @@ -65,7 +67,12 @@ export default { mode: { type: String, default: 'simple' }, conditionData: { type: Object }, //当前组件在工单中心配置中的数据 condition: { type: Object }, - workcenterConditionData: { type: Object } //工单中心所有条件数据 + workcenterConditionData: { type: Object }, //工单中心所有条件数据 + isCustomValue: { + // 是否自定义值,单个字符串(value:1)可以自定义返回{text:1,value:1},数组[1]可以自定义返回[{text:1,value:1}] + type: Boolean, + default: false + } }, data() { return { diff --git a/src/resources/components/ProcessTaskSearcher/handlers/checkbox.vue b/src/resources/components/ProcessTaskSearcher/handlers/checkbox.vue index b0b27ae51bd1bb2719bf8aa7b501b324967491e4..517ce1cbf5d7500e7dc0d86965b03f5e9cd2c7b5 100644 --- a/src/resources/components/ProcessTaskSearcher/handlers/checkbox.vue +++ b/src/resources/components/ProcessTaskSearcher/handlers/checkbox.vue @@ -6,6 +6,7 @@ className="block-span" :value="conditionData && conditionData.valueList" :validateList="[{ name: 'required', message: ' ' }]" + :isCustomValue="isCustomValue" @on-change="change" > diff --git a/src/resources/components/ProcessTaskSearcher/handlers/matrixMinxis.js b/src/resources/components/ProcessTaskSearcher/handlers/matrixMinxis.js index b1ff2e027028e5ff513037a65db88374d5568945..633bdfa9a1ad4ee21a300b82fa74317c65e8d1d9 100644 --- a/src/resources/components/ProcessTaskSearcher/handlers/matrixMinxis.js +++ b/src/resources/components/ProcessTaskSearcher/handlers/matrixMinxis.js @@ -1,4 +1,11 @@ export default { + props: { + isCustomValue: { + // 是否自定义值,单个字符串(value:1)可以自定义返回{text:1,value:1},数组[1]可以自定义返回[{text:1,value:1}] + type: Boolean, + default: false + } + }, methods: { dealDataByUrl(nodeList) { //处理返回的数据结构为tsFormSelect需要的数据结构 @@ -9,13 +16,13 @@ export default { if (this.config.mapping.value != this.config.mapping.text) { columlist.push({ text: co[this.config.mapping.text].text, - value: co[this.config.mapping.value].value + '&=&' + co[this.config.mapping.text].text, + value: co[this.config.mapping.value].value, html: co[this.config.mapping.text].text + "(" + co[this.config.mapping.value].text + ')' }); } else { columlist.push({ text: co[this.config.mapping.text].text, - value: co[this.config.mapping.value].value + '&=&' + co[this.config.mapping.text].text, + value: co[this.config.mapping.value].value, html: co[this.config.mapping.text].text }); } diff --git a/src/resources/components/ProcessTaskSearcher/handlers/radio.vue b/src/resources/components/ProcessTaskSearcher/handlers/radio.vue index 5eda272a9d3233abee7177cf6097f978e8d47a58..76af010db1c94a23a080ba69f470deaf66a1e7dd 100644 --- a/src/resources/components/ProcessTaskSearcher/handlers/radio.vue +++ b/src/resources/components/ProcessTaskSearcher/handlers/radio.vue @@ -6,6 +6,7 @@ className="block-span" :value="conditionData && conditionData.valueList" :validateList="[{ name: 'required', message: ' ' }]" + :isCustomValue="isCustomValue" @on-change="change" > diff --git a/src/resources/components/ProcessTaskSearcher/handlers/select.vue b/src/resources/components/ProcessTaskSearcher/handlers/select.vue index 13954ea9839f34bd6e07b2d1e9ffa4aaf8221227..624e787e88adeb6c79534f07e9ae73074abbf437 100644 --- a/src/resources/components/ProcessTaskSearcher/handlers/select.vue +++ b/src/resources/components/ProcessTaskSearcher/handlers/select.vue @@ -14,6 +14,7 @@ border="border" :value="conditionData && conditionData.valueList" :validateList="[{ name: 'required', message: ' ' }]" + :isCustomValue="isCustomValue" @change="change" > @@ -31,10 +32,14 @@ export default { default: 'simple' }, condition: { type: Object }, - conditionData: {type: Object}//当前组件在工单中心配置中的数据 + conditionData: {type: Object}, //当前组件在工单中心配置中的数据 + isCustomValue: { + // 是否自定义值,单个字符串(value:1)可以自定义返回{text:1,value:1},数组[1]可以自定义返回[{text:1,value:1}] + type: Boolean, + default: false + } }, data() { - const _this = this; return { config: this.condition.config, matrixConfig: { @@ -46,8 +51,7 @@ export default { beforeCreate() {}, created() { this.mergeMatrixConfig(); }, beforeMount() {}, - mounted() { - }, + mounted() {}, beforeUpdate() {}, updated() {}, activated() {}, diff --git a/src/resources/components/ProcessTaskSearcher/search-inputer.vue b/src/resources/components/ProcessTaskSearcher/search-inputer.vue index 1e34d41a7b4573cdfe3878bee928bdcf8c71283f..b9980abcf77764b72dc1866e03f5e21f3cbc5d10 100644 --- a/src/resources/components/ProcessTaskSearcher/search-inputer.vue +++ b/src/resources/components/ProcessTaskSearcher/search-inputer.vue @@ -8,6 +8,7 @@ :workcenterConditionData="workcenterConditionData" :conditionData="getWorkcenterConditionData(condition.handler)" :mode="mode" + :isCustomValue="isCustomValue" @change="change" @changeWithCondition="changeWithCondition" > @@ -19,6 +20,7 @@ :condition="condition" :conditionData="conditionData || getWorkcenterConditionData(condition.handler)" :mode="mode" + :isCustomValue="isCustomPanel && isCustomValue" @change="change" > @@ -50,7 +52,16 @@ export default { mode: { type: String, default: 'simple' }, workcenterConditionData: { type: Object }, //全量的工单中心条件数据,主要提供给channelselect.vue使用,其他组件不需要用的此数据 condition: { type: Object }, //默认条件 - conditionData: { type: Object } //工单中心组件条件数据 + conditionData: { type: Object }, //工单中心组件条件数据 + isCustomValue: { + // 是否自定义值,单个字符串(value:1)可以自定义返回{text:1,value:1},数组[1]可以自定义返回[{text:1,value:1}] + type: Boolean, + default: false + }, + isCustomPanel: { // 用于简单模式下,表单过滤属性按钮打开之后,表单属性下拉框需要是{text:1,value:1}或者[{text:1,value:1}] + type: Boolean, + default: false + } }, data() { return { diff --git a/src/resources/components/ProcessTaskSearcher/simple-panel.vue b/src/resources/components/ProcessTaskSearcher/simple-panel.vue index de5efc007c69b1cc773afb562dfe63d9720b9b9f..add9f35e8e02c7b8b6de2dcefcda0ea527deb481 100644 --- a/src/resources/components/ProcessTaskSearcher/simple-panel.vue +++ b/src/resources/components/ProcessTaskSearcher/simple-panel.vue @@ -7,6 +7,7 @@ mode="simple" :condition="condition" :workcenterConditionData="workcenterConditionDataLocal" + :isCustomValue="true" @change="change" > diff --git a/src/resources/mixins/formMixins.js b/src/resources/mixins/formMixins.js index 2cf753ae5960d802069605f802c0e2d229723e1a..a2be9bc9cbef571d9b490aea371c49bc458ab296 100644 --- a/src/resources/mixins/formMixins.js +++ b/src/resources/mixins/formMixins.js @@ -45,6 +45,11 @@ export default { // 是否清空回显失败默认值 type: Boolean, default: false + }, + isCustomValue: { + // 是否自定义值,单个字符串(value:1)可以自定义返回{text:1,value:1},数组[1]可以自定义返回[{text:1,value:1}] + type: Boolean, + default: false } }, methods: { @@ -111,7 +116,12 @@ export default { let valueList = []; value.forEach(v => { if (v != false && !this.$utils.isEmpty(v)) { - valueList.push(v); + if (this.isCustomValue && v[this.valueName]) { + // 数组对象类型 + valueList.push(v?.[this.valueName]); + } else { + valueList.push(v); + } } }); value = valueList; @@ -223,6 +233,30 @@ export default { className = 'text-warning'; } return className; + }, + handleCurrentValue(currentValue) { + let value; + return currentValue => { + if (this.multiple || this.$options.name == 'TsFormCheckbox') { + if (this.$utils.isEmpty(currentValue)) { + value = []; + } else { + if (this.isCustomValue) { + // 返回的是对象处理需要处理成['value1', 'value2'] + value = currentValue instanceof Array ? currentValue.filter(item => item?.[this.valueName]).map(item => item[this.valueName]) : []; + } else { + value = [].concat(currentValue); + } + } + } else { + if (this.isCustomValue && currentValue && typeof currentValue === 'object' && currentValue[this.valueName]) { + value = currentValue[this.valueName]; + } else { + value = currentValue; + } + } + return value; + }; } }, diff --git a/src/resources/mixins/sheetCompontMixins.js b/src/resources/mixins/sheetCompontMixins.js index db647b0a8f6d53d5a03fe8b09f52ccadc41d317e..6184f6acccdf4a40661e86178da89514193b8aab 100644 --- a/src/resources/mixins/sheetCompontMixins.js +++ b/src/resources/mixins/sheetCompontMixins.js @@ -24,13 +24,13 @@ export default { if (config.mapping.value != config.mapping.text) { columlist.push({ text: co[config.mapping.text].text, - value: co[config.mapping.value].value + '&=&' + co[config.mapping.text].text, + value: co[config.mapping.value].value, html: co[config.mapping.text].text + "(" + co[config.mapping.value].text + ')' }); } else { columlist.push({ text: co[config.mapping.text].text, - value: co[config.mapping.value].value + '&=&' + co[config.mapping.text].text, + value: co[config.mapping.value].value, html: co[config.mapping.text].text }); } diff --git a/src/resources/plugins/TsForm/TsFormCheckbox.vue b/src/resources/plugins/TsForm/TsFormCheckbox.vue index f74a3d0832ba9c57bfa49bfe24673f1f3350ae61..7de82df51821ab156377fc8a94261a421dd2482d 100755 --- a/src/resources/plugins/TsForm/TsFormCheckbox.vue +++ b/src/resources/plugins/TsForm/TsFormCheckbox.vue @@ -3,12 +3,12 @@ @@ -114,13 +114,14 @@ export default { }, data() { return { - currentValue: this.value || [], + currentValue: [], validMesage: this.errorMessage || '', nodeList: this.url ? [] : this.dataList, currentValidList: this.filterValid(this.validateList) || [] }; }, created() { + this.currentValue = this.handleCurrentValue(this.value) || []; this.setSelectList(); this.initDataListByUrl(); }, @@ -186,7 +187,7 @@ export default { }, onChangeValue(val, item) { let isSame = JSON.stringify(this.value) == JSON.stringify(this.currentValue); - let value = JSON.parse(JSON.stringify(this.currentValue)); + let value = this.$utils.deepClone(this.currentValue); //20210129_zqp_新增支持on-change方法第二个参数获取选中的选项的完整数据 let selectedItem = []; let label = []; @@ -197,6 +198,9 @@ export default { return true; } }); + if (this.isCustomValue) { + value = selectedItem; + } } this.$emit('update:value', value); this.$emit('change', value, selectedItem); @@ -249,17 +253,16 @@ export default { return reslutClass; }, getText() { - let _this = this; - return function(val) { - let node = _this.nodeList.find(item => item[_this.valueName] == val); - return node && node[_this.textName] ? node[_this.textName] : '-'; + return (val) => { + let node = this.nodeList.find(item => item[this.valueName] == val); + return node && node[this.textName] ? node[this.textName] : '-'; }; } }, watch: { value(newValue, oldValue) { if (JSON.stringify(newValue) != JSON.stringify(this.currentValue)) { - this.currentValue = JSON.parse(JSON.stringify(newValue || [])); + this.currentValue = this.handleCurrentValue(this.$utils.deepClone(newValue)) || []; this.validMesage = ''; this.setSelectList(); } diff --git a/src/resources/plugins/TsForm/TsFormRadio.vue b/src/resources/plugins/TsForm/TsFormRadio.vue index da570a86071adc2c0b4ef1ec30639077e03ff678..026cb58a78164344a8d70a3e948081dcf169abc2 100755 --- a/src/resources/plugins/TsForm/TsFormRadio.vue +++ b/src/resources/plugins/TsForm/TsFormRadio.vue @@ -15,7 +15,7 @@ :label="data[valueName]" :disabled="disabled || data.disabled || readonly" :class="{ 'tsform-radio-readonly': readonly }" - @click.native="cancelRadio(data[valueName])" + @click.native="cancelRadio(data[valueName], data.disabled)" > {{ data[textName] || '-' }} @@ -80,7 +80,7 @@ export default { default: 'text' }, value: { - type: [String, Number, Boolean], + type: [String, Number, Boolean, Object], default: '' }, url: { @@ -121,13 +121,14 @@ export default { }, data() { return { - currentValue: this.value, + currentValue: '', validMesage: this.errorMessage || '', nodeList: this.url ? [] : this.dataList, currentValidList: this.filterValid(this.validateList) || [] }; }, created() { + this.currentValue = this.handleCurrentValue(this.value); this.setSelectList(); this.initDataListByUrl(); }, @@ -198,6 +199,9 @@ export default { return n[this.valueName] === value; }); } + if (this.isCustomValue) { + value = selectedItem || {}; + } this.$emit('update:value', value); this.$emit('change', value, selectedItem || null); if (!(!this.isChangeWrite && isSame)) { @@ -229,7 +233,11 @@ export default { }, 100); } }, - cancelRadio(label) { //取消勾选 + cancelRadio(label, disabled) { //取消勾选 + if (disabled || this.disabled) { + // 禁用之后按钮不可点击 + return false; + } if (this.allowToggle && this.currentValue == label) { this.currentValue = null; this.$emit('update:value', this.currentValue); @@ -245,14 +253,14 @@ export default { return reslutClass; }, getText() { - let node = this.nodeList.find(item => item[this.valueName] == this.value); + let node = this.nodeList.find(item => item[this.valueName] == this.currentValue); return node && node[this.textName] ? node[this.textName] : '-'; } }, watch: { value(newValue, oldValue) { if (newValue != this.currentValue) { - this.currentValue = newValue; + this.currentValue = this.handleCurrentValue(newValue); this.validMesage = ''; this.setSelectList(); this.handleEchoFailedDefaultValue(); diff --git a/src/resources/plugins/TsForm/TsFormSelect.vue b/src/resources/plugins/TsForm/TsFormSelect.vue index a390680711b62c6ed13f2be652d13f0f983a95ad..375659ae44f2fa5451a34cc2c47c118e2e39c068 100755 --- a/src/resources/plugins/TsForm/TsFormSelect.vue +++ b/src/resources/plugins/TsForm/TsFormSelect.vue @@ -314,7 +314,7 @@ export default { mode: { type: String, default: 'normal' }, //normal或group,group代表分组下拉框 value: { //默认值 - type: [String, Number, Array], + type: [String, Number, Array, Object], default: function() { if (this.multiple == true) { return new Array(); @@ -511,10 +511,10 @@ export default { focussing: false, //是否处于焦点中 focusIndex: -1, //通过键盘选中列表 searchKeyWord: '', //搜索对应可以word - currentValue: this.multiple ? (this.$utils.isEmpty(this.value) ? [] : [].concat(this.value)) : this.value, + currentValue: null, isVisible: false, //下拉选项显示 selectedList: [], //选中的集合{text:"",value:""} - nodeList: this.url ? [] : JSON.parse(JSON.stringify(this.dataList || [])), + nodeList: this.url ? [] : this.$utils.deepClone(this.dataList || []), loading: !!this.dynamicUrl, validMesage: this.errorMessage || '', currentValidList: this.filterValid(this.validateList) || [], @@ -535,6 +535,7 @@ export default { }, beforeCreate() {}, created() { + this.currentValue = this.handleCurrentValue(this.value); this.initDataListByUrl(false); }, mounted() {}, @@ -593,7 +594,7 @@ export default { // 暂无数据 return (this.nodeList.length <= 0 || this.hiddenLength == this.nodeList.length) && !this.allowCreate; }, - handleOpen: function() { + handleOpen() { if (this.disabled || this.readonly) { return; } @@ -621,7 +622,7 @@ export default { // 取消上次请求的接口 // let ajaxArr = { method: this.ajaxType, url: url, cancelAxios: this[cancel].token}; let needdataLi = ['post', 'put']; - ArrIndexOf(needdataLi, this.ajaxType) < 0 ? Object.assign(ajaxArr, { params: params }) : Object.assign(ajaxArr, { data: params }); + !needdataLi.includes(this.ajaxType) ? Object.assign(ajaxArr, { params: params }) : Object.assign(ajaxArr, { data: params }); let res = await this.$https(ajaxArr); let nodeList = []; if (res && res.Status == 'OK') { @@ -673,7 +674,6 @@ export default { initDataListByUrl(isSearch) { //isSearch: Boolean 如果是value 改变时,不需要从新通过url来获取nodelist //初始化数据 - let _this = this; this.hiddenLength = 0; if (this.url && !isSearch) { //url @@ -682,12 +682,12 @@ export default { this.isSingel = !!(this.isSquare && this.currentSearch); // 解决文本占位符显示不出来问题 this.getDataByAjax(params, this.url, 'cancelAxios1').then(res => { - _this.nodeList = res; - _this.nodeList && _this.nodeList.length > 20 && _this.search === null ? (_this.currentSearch = true) : (_this.currentSearch = _this.search); //当search参数值不存在时 如果长度大于20增加搜索功能, - _this.setDefaultValue(); //默认选中第一个 - _this.initValueByNodeList(); + this.nodeList = res; + this.nodeList && this.nodeList.length > 20 && this.search === null ? (this.currentSearch = true) : (this.currentSearch = this.search); //当search参数值不存在时 如果长度大于20增加搜索功能, + this.setDefaultValue(); //默认选中第一个 + this.initValueByNodeList(); }); - } else if (_this.dynamicUrl) { + } else if (this.dynamicUrl) { //dynamicUrl this.currentSearch = true; if (!this.$utils.isEmpty(this.value)) { @@ -715,23 +715,22 @@ export default { }, initValueByNodeList() { //通过nodeList,初始化selectedList - let _this = this; this.selectedList = []; if (this.$utils.isEmpty(this.currentValue)) { this.searchKeyWord = ''; return; } - let ary = this.multiple ? this.currentValue : [this.currentValue]; + let valueList = this.multiple ? this.currentValue : this.currentValue instanceof Array ? this.currentValue : [this.currentValue]; let selectedList = []; if (this.mode == 'normal') { - _this.nodeList.forEach(function(item) { - ArrIndexOf(ary, item[_this.valueName]) >= 0 && selectedList.push(item); + this.nodeList.forEach((item) => { + this.ArrIndexOf(valueList, item[this.valueName]) >= 0 && selectedList.push(item); }); } else if (this.mode == 'group') { this.nodeList.forEach(pitem => { if (pitem[this.childrenName] && pitem[this.childrenName].length > 0) { pitem[this.childrenName].forEach(item => { - ArrIndexOf(ary, item[this.valueName]) >= 0 && selectedList.push(item); + this.ArrIndexOf(valueList, item[this.valueName]) >= 0 && selectedList.push(item); }); } }); @@ -741,7 +740,7 @@ export default { if (selectedList.length > 1) { this.currentValue instanceof Array && this.currentValue.forEach(item => { - let findSelect = selectedList.find(sel => sel[this.valueName] == item); + let findSelect = selectedList.find(sel => sel[this.valueName] == item || sel[this.valueName] == item[this.valueName]); findSelect && list.push(findSelect); }); } else { @@ -750,7 +749,7 @@ export default { this.selectedList = list; if (!this.multiple) { //单选时需要给searchKeyword赋值 - if (ary.length > _this.selectedList.length && this.allowCreate) { + if (valueList.length > this.selectedList.length && this.allowCreate) { //如果不是通过接口调用写死的单独做一次性回显的,在下次初始化时把值回显回去 this.searchKeyWord = this.currentValue; //在下拉列表里面添加用户手动创建的数据,主要是为了回显 @@ -772,7 +771,6 @@ export default { this.openOption(); } if (this.dynamicUrl) { - let _this = this; this.setTimeoutDynaic && clearTimeout(this.setTimeoutDynaic); this.setTimeoutDynaic = setTimeout(() => { this.currentPage = 1; @@ -798,7 +796,7 @@ export default { this.selectedList.splice(ind, 1); if (this.currentValue instanceof Array) { // 解决单选时,当前值不是数组时,splice报错问题 - this.currentValue.splice(ArrIndexOf(this.currentValue, value), 1); + this.currentValue.splice(this.ArrIndexOf(this.currentValue, value), 1); } this.$refs.input && this.$refs.input.focus(); this.onChangeValue(); @@ -818,9 +816,8 @@ export default { }, filterNodeList(query) { //nodeList进行搜索过滤 - let _this = this; this.hiddenLength = 0; - _this.liHtml = _this.showName ? _this.showName : _this.textName; + this.liHtml = this.showName ? this.showName : this.textName; this.nodeList.forEach(item => { if (this.mode == 'normal') { if (item) { @@ -836,11 +833,10 @@ export default { } } }); - _this.updatePosition(); + this.updatePosition(); }, selectMatchItem(query, item) { - const _this = this; - let searchNameList = _this.$utils.isEmpty(_this.filterName) ? [_this.textName, _this.valueName] : typeof _this.filterName == 'string' ? [_this.filterName] : _this.filterName; + let searchNameList = this.$utils.isEmpty(this.filterName) ? [this.textName, this.valueName] : typeof this.filterName == 'string' ? [this.filterName] : this.filterName; let filterNode = searchNameList.find(search => { if ( !query || @@ -854,28 +850,27 @@ export default { } }); if (filterNode) { - _this.$set(item, '_isHidden', false); + this.$set(item, '_isHidden', false); if (query) { - let newtext = item[_this.liHtml].replace(new RegExp('(' + query + ')', 'ig'), '$1'); - _this.$set(item, 'showtxt', newtext); + let newtext = item[this.liHtml].replace(new RegExp('(' + query + ')', 'ig'), '$1'); + this.$set(item, 'showtxt', newtext); } else { - _this.$set(item, 'showtxt', item[_this.liHtml]); + this.$set(item, 'showtxt', item[this.liHtml]); } } else { - _this.$set(item, '_isHidden', true); - _this.$set(item, 'showtxt', item[_this.liHtml]); + this.$set(item, '_isHidden', true); + this.$set(item, 'showtxt', item[this.liHtml]); this.hiddenLength++; } }, dynamicInit() { //通过dynamicurl初始化数据 - let _this = this; this.hiddenLength = 0; //不用掉接口初始化text值 if (this.isEqualValue) { this.selectedList = []; - let ary = this.currentValue instanceof Array ? this.currentValue : [this.currentValue]; - ary.forEach(item => { + let valueList = this.currentValue instanceof Array ? this.currentValue : [this.currentValue]; + valueList.forEach(item => { let obj = {}; obj[this.valueName] = obj[this.textName] = item; this.selectedList.push(obj); @@ -887,7 +882,7 @@ export default { this.getDataByAjax(params, this.dynamicUrl, 'cancelAxios1').then(res => { if (((this.multiple && this.currentValue.length) || (!this.multiple && (this.currentValue || ['boolean', 'number'].includes(typeof this.currentValue)))) && res.length) { let selectedList = res.filter(r => { - return _this.multiple ? ArrIndexOf(this.currentValue, r[_this.valueName]) > -1 : this.currentValue == r[_this.valueName]; + return this.multiple ? this.ArrIndexOf(this.currentValue, r[this.valueName]) > -1 : this.handleObjectValue(r[this.valueName]); }); //进行排序,主要是为了显示的text的顺序和value值顺序一样 ,因为接口的数据顺序可能不会根据value来 let list = []; @@ -898,48 +893,59 @@ export default { findSelect && list.push(findSelect); }); } - this.selectedList = selectedList.length > 1 ? list : selectedList; + this.selectedList = selectedList.length > 1 && !this.$utils.isEmpty(list) ? list : selectedList; this.handleEchoFailedDefaultValue(); } else { - _this.selectedList = []; + this.selectedList = []; this.handleEchoFailedDefaultValue(); } - if (!_this.multiple) { + if (!this.multiple) { //是单选,进行赋值处理 - _this.searchKeyWord = ''; - _this.isSingel = !!(this.isSquare && this.currentSearch); + this.searchKeyWord = ''; + this.isSingel = !!(this.isSquare && this.currentSearch); } - if (_this.needCallback) { + if (this.needCallback) { //成功回调设置为false - _this.$emit('update:needCallback', false); - _this.$emit('searchCallback'); + this.$emit('update:needCallback', false); + this.$emit('searchCallback'); } }); }, + handleObjectValue(valueName) { + if (!this.isCustomValue) { + return this.currentValue == valueName; + } + if (this.currentValue instanceof Array) { + return this.currentValue.find((item) => item[this.valueName] == valueName); + } else if (typeof this.currentValue == 'string') { + return this.currentValue == valueName; + } else if (typeof this.currentValue == 'object' && this.currentValue) { + return this.currentValue[this.valueName]; + } + }, handleEchoFailedDefaultValue() { // 处理回显失败默认值,回显失败清空默认值 - if (this.isClearEchoFailedDefaultValue && !this.$utils.isEmpty(this.selectedList)) { - let selectedList = []; - let valueList = this.multiple ? this.currentValue : this.currentValue instanceof Array ? this.currentValue : [this.currentValue]; - valueList.forEach((item, index) => { - if (item && !this.selectedList.find((n) => n[this.valueName] == item)) { - selectedList.push(item[this.valueName]); - if (this.currentValue instanceof Array) { - this.currentValue.splice(index, 1); - } else if (this.currentValue) { - this.currentValue = null; - } - } - }); - if (!this.$utils.isEmpty(selectedList)) { - this.onChangeValue(); - } - } + // if (this.isClearEchoFailedDefaultValue && !this.$utils.isEmpty(this.selectedList)) { + // let selectedList = []; + // let valueList = this.multiple ? this.currentValue : this.currentValue instanceof Array ? this.currentValue : [this.currentValue]; + // valueList.forEach((item, index) => { + // if (item && !this.selectedList.find((n) => n[this.valueName] == item)) { + // selectedList.push(item[this.valueName]); + // if (this.currentValue instanceof Array) { + // this.currentValue.splice(index, 1); + // } else if (this.currentValue) { + // this.currentValue = null; + // } + // } + // }); + // if (!this.$utils.isEmpty(selectedList)) { + // this.onChangeValue(); + // } + // } }, dynamicSearch(query, isFirst) { //query:搜索的关键字,isFirst 是否第一次初始化下拉值,主要为了必填时只有一个下拉值时默认填充 - let _this = this; this.hiddenLength = 0; this.loading = true; if (isFirst) { @@ -951,41 +957,41 @@ export default { params[this.keyword] = query ? query.trim() : ''; this.getDataByAjax(params, this.dynamicUrl, 'cancelAxios') .then(res => { - if (_this.isReachBottomSearch && this.currentPage > 1 && !this.$utils.isSame(this.nodeList, res)) { + if (this.isReachBottomSearch && this.currentPage > 1 && !this.$utils.isSame(this.nodeList, res)) { if (res && res.length > 0) { for (let i = 0; i < res.length; i++) { - _this.nodeList.push(res[i]); + this.nodeList.push(res[i]); } - _this.delMoreSearchTip(); - if (_this.pageCount > 1) { - _this.nodeList.push(_this.moreSearchTip); + this.delMoreSearchTip(); + if (this.pageCount > 1) { + this.nodeList.push(this.moreSearchTip); } } - _this.nodeList = _this.$utils.uniqueByField(_this.nodeList, _this.valueName); // 去重 + this.nodeList = this.$utils.uniqueByField(this.nodeList, this.valueName); // 去重 } else { - _this.nodeList = []; - _this.nodeList = res; // 有传递的时候,拿到所有的值 + this.nodeList = []; + this.nodeList = res; // 有传递的时候,拿到所有的值 } - _this.creatNewItem(query); - _this.nodeList.splice(0, {}); - _this.updatePosition(); - _this.$nextTick(() => { - _this.hasLoadMore = this.hasScrollbar(); + this.creatNewItem(query); + this.nodeList.splice(0, {}); + this.updatePosition(); + this.$nextTick(() => { + this.hasLoadMore = this.hasScrollbar(); }); if (isFirst) { //如果必填或者默认选中第一个,而且下拉值只有一个则默认选中第一个 - _this.setDefaultValue(); + this.setDefaultValue(); } - _this.loading = false; - if (_this.needCallback) { + this.loading = false; + if (this.needCallback) { //成功回调设置为false - _this.$emit('update:needCallback', false); - _this.$emit('searchCallback'); + this.$emit('update:needCallback', false); + this.$emit('searchCallback'); } }) .finally(() => { - _this.loading = false; + this.loading = false; }); }, delMoreSearchTip() { @@ -1012,14 +1018,21 @@ export default { }, onChangeValue() { let isSame = false; - let valueObject = this.selectedList.map(item => { + let selectedList = this.selectedList.map(item => { return { value: item[this.valueName], text: item[this.textName] }; }); - valueObject = this.multiple ? valueObject : valueObject[0] || {}; + let valueObject = this.multiple ? selectedList : selectedList[0] || {}; let toValue = this.currentValue; //额外赋值主要是为了避免引用数据导致值的联动 if (this.multiple) { isSame = JSON.stringify(this.value) == JSON.stringify(this.currentValue); - toValue = this.currentValue.concat([]); + if (this.isCustomValue) { + toValue = this.$utils.deepClone(this.selectedList); + } else { + toValue = this.currentValue.concat([]); + } + } else if (this.isCustomValue) { + isSame = this.$utils.isSame(this.value, this.currentValue); + toValue = valueObject; } else if (this.value == this.currentValue) { isSame = true; } @@ -1040,15 +1053,15 @@ export default { this.isValidPass = true; } }, - onSelectFocus: function() { + onSelectFocus() { typeof this.onFocus == 'function' && this.onFocus(); this.$emit('on-focus'); }, - // onFirst: function() { + // onFirst() { // typeof this.onFirst == 'function' && this.onFirst(); // this.$emit('on-first'); // }, - onSelectBlur: function() { + onSelectBlur() { typeof this.onBlur == 'function' && this.onBlur(); this.$emit('on-blur'); }, @@ -1058,11 +1071,14 @@ export default { return; } let value = item[this.valueName]; - let index = ArrIndexOf(this.currentValue, value); + let index = this.ArrIndexOf(this.currentValue, value); + if (this.multiple && this.$utils.isEmpty(this.currentValue)) { + this.currentValue = []; + } if (index < 0) { //选中 this.multiple ? this.selectedList.push(item) : (this.selectedList = [item]); - this.multiple ? this.currentValue.push(value) : (this.currentValue = value); + this.multiple && value ? this.currentValue.push(value) : (this.currentValue = value); } else if (this.isRequired && !this.multiple) { //取消选中 如果必填且单选,则不能取消选中 return; @@ -1078,6 +1094,7 @@ export default { } this.multiple ? (this.searchKeyWord = '') : this.hideOption(); this.isSingel = !!(this.isSquare && this.currentSearch); + this.onChangeValue(); this.scrollTop(); }, @@ -1114,7 +1131,6 @@ export default { } }, hideOption(isEnterSearch) { - var _this = this; this.isVisible = false; if (!isEnterSearch) { !this.multiple ? (this.searchKeyWord = '') : (this.searchKeyWord = ''); @@ -1123,7 +1139,7 @@ export default { //如果是单选实时搜索在收起元素时,然后下拉里面的值为当前选中项 setTimeout(() => { // this.dynamicSearch('search', this.selectedList[0][this.textName]); - this.selectedList.length > 0 && _this.nodeList && (_this.nodeList = _this.nodeList.filter(item => item[_this.valueName] == _this.selectedList[0][_this.valueName])); + this.selectedList.length > 0 && this.nodeList && (this.nodeList = this.nodeList.filter(item => item[this.valueName] == this.selectedList[0][this.valueName])); }); } }, @@ -1131,7 +1147,6 @@ export default { this.isVisible = true; }, handleKeydown(e) { - let _this = this; if ((this.nodeList && this.nodeList.length > 0) || e.keyCode == 13) { let maxLength = this.nodeList.length; let minLength = this.allowCreate ? 0 : 1; @@ -1150,7 +1165,6 @@ export default { let focusItem = this.setFocusItem(minLength, maxLength, 'down'); } else if (keyCode == '13') { // enter - let _this = this; e.preventDefault(); if (!this.isVisible) { //显示下拉框 @@ -1171,32 +1185,32 @@ export default { selectData && this.toggleSelect(selectData); //键盘回车,如果val与当前下拉某一个一样的就是选中当前一个,如果是回车新加的继续新加逻辑 let isExist = false; - let keyval = _this.addItem ? _this.addItem[_this.textName] || this.searchKeyWord : this.searchKeyWord; - if (keyval && _this.nodeList && _this.nodeList.length > 0) { - _this.nodeList.find(no => { - if (this.$utils.equalStr(no[_this.valueName], keyval) || this.$utils.equalStr(no[_this.textName], keyval)) { + let keyval = this.addItem ? this.addItem[this.textName] || this.searchKeyWord : this.searchKeyWord; + if (keyval && this.nodeList && this.nodeList.length > 0) { + this.nodeList.find(no => { + if (this.$utils.equalStr(no[this.valueName], keyval) || this.$utils.equalStr(no[this.textName], keyval)) { isExist = true; } return isExist; }); } - if (!_this.allowCreate || (_this.allowCreate && isExist)) { - _this.$set(_this, 'addItem', null); + if (!this.allowCreate || (this.allowCreate && isExist)) { + this.$set(this, 'addItem', null); return; } else { - _this.nodeList.unshift(_this.addItem); - if (_this.$listeners && _this.$listeners['on-create']) { - _this.$emit('on-create', keyval); + this.nodeList.unshift(this.addItem); + if (this.$listeners && this.$listeners['on-create']) { + this.$emit('on-create', keyval); } - _this.toggleSelect(_this.nodeList[0]); - _this.$set(_this, 'addItem', null); + this.toggleSelect(this.nodeList[0]); + this.$set(this, 'addItem', null); } } else if (keyCode == '8') { if (this.multiple && !this.searchKeyWord && this.selectedList.length > 0) { let lastLi = this.selectedList.length - 1; let lastval = this.selectedList[lastLi][this.valueName]; - this.currentValue.splice(ArrIndexOf(this.currentValue, lastval), 1); + this.currentValue.splice(this.ArrIndexOf(this.currentValue, lastval), 1); this.selectedList.splice(lastLi, 1); this.onChangeValue(); } @@ -1206,14 +1220,13 @@ export default { setFocusItem(maxLength, minLength, type) { //利用键盘,选中的元素样色 let length = 0; - let _this = this; let selectData = null; this.nodeList.forEach((item, iindex) => { - if (iindex + 1 === _this.focusIndex) { - _this.$set(item, '_focusSelect', true); + if (iindex + 1 === this.focusIndex) { + this.$set(item, '_focusSelect', true); selectData = item; } else { - _this.$set(item, '_focusSelect', false); + this.$set(item, '_focusSelect', false); } }); @@ -1221,10 +1234,10 @@ export default { this.focusIndex = this.focusIndex == maxLength ? minLength : this.focusIndex + (type == 'up' ? -1 : 1); selectData = this.setFocusItem(maxLength, minLength, type); } else { - this.$nextTick(function() { + this.$nextTick(() => { //内容的滚动 - if (_this.$refs.dropdown) { - let $scrollContain = _this.$refs.dropdown.$el.parentNode; + if (this.$refs.dropdown) { + let $scrollContain = this.$refs.dropdown.$el.parentNode; let $selected = $scrollContain.querySelector(' .select-li.hover'); if ($selected) { $scrollContain.scrollTop = $selected.offsetTop - 100; @@ -1238,11 +1251,10 @@ export default { checkExist(str) { //校验某个字符串是否存在下拉列表里 let isExist = false; - let _this = this; - if (str && _this.nodeList && _this.nodeList.length > 0) { - _this.nodeList.forEach(no => { - let textStr = no[_this.textName].toString(); - let valueStr = no[_this.valueName].toString(); + if (str && this.nodeList && this.nodeList.length > 0) { + this.nodeList.forEach(no => { + let textStr = no[this.textName].toString(); + let valueStr = no[this.valueName].toString(); if (textStr === str.toString() || valueStr === str.toString()) { isExist = true; } @@ -1259,12 +1271,11 @@ export default { } }, watchChange(isChange) { - let _this = this; - this.initSettime && clearTimeout(_this.initSettime); + this.initSettime && clearTimeout(this.initSettime); this.initSettime = setTimeout(() => { - _this.initSettime = null; - _this.loading = !!_this.dynamicUrl; - _this.initDataListByUrl(isChange); + this.initSettime = null; + this.loading = !!this.dynamicUrl; + this.initDataListByUrl(isChange); }, 10); }, getSelectedList() { @@ -1276,7 +1287,7 @@ export default { }, scrollTop() { if (this.nowrapHead) { - this.$nextTick(function() { + this.$nextTick(() => { this.$refs.topHead && (this.$refs.topHead.scrollLeft = this.$refs.topHead.scrollWidth); }); } @@ -1298,7 +1309,7 @@ export default { return 0; } }, - handleReachBottom: function() { + handleReachBottom() { // 触底滚动加载 return new Promise(resolve => { setTimeout(() => { @@ -1324,6 +1335,19 @@ export default { hasScrollbar = dropdownContain.$el.clientHeight > 200; } return hasScrollbar; + }, + ArrIndexOf(arr, str) { + //重写 数组的indexof功能 主要是为了实现 1 = '1' 的情况 + let index = -1; + if (arr instanceof Array) { + arr.find((item, i) => { + utils.equalStr(this.isCustomValue && item[this.valueName] ? item[this.valueName] : item, str) && (index = i); + return index >= 0; + }); + } else { + utils.equalStr(arr, str) && (index = 0); + } + return index; } }, computed: { @@ -1338,10 +1362,9 @@ export default { if (this.nowrapHead && this.multiple) { classStr += ' nowrap'; } - return classStr; }, - getPlaceholder: function() { + getPlaceholder() { if ((this.selectedList && this.selectedList.length > 0) || this.disabled) { return ''; } @@ -1353,14 +1376,13 @@ export default { return this.$t('form.placeholder.pleaseselect', { target: '' }); } }, - getClearable: function() { - let _this = this; - let clearable = _this.clearable; + getClearable() { + let clearable = this.clearable; !clearable && - _this.validateList && - _this.validateList.forEach(item => { - typeof item == 'string' && item == 'required' && !_this.multiple && (clearable = false); - typeof item == 'object' && item.name == 'required' && !_this.multiple && (clearable = false); + this.validateList && + this.validateList.forEach(item => { + typeof item == 'string' && item == 'required' && !this.multiple && (clearable = false); + typeof item == 'object' && item.name == 'required' && !this.multiple && (clearable = false); }); if (this.disabled || this.readonly || this.selectedList.length == 0) { clearable = false; @@ -1380,15 +1402,14 @@ export default { return classNameList; }, setLiClass() { - return function(node, index) { - let _this = this; + return (node, index) => { let classtxt = 'select-li ivu-dropdown-item overflow'; - if (this.multiple && this.currentValue && ArrIndexOf(this.currentValue, node[_this.valueName]) > -1) { + if (this.multiple && this.currentValue && this.ArrIndexOf(this.currentValue, node[this.valueName]) > -1) { classtxt = classtxt + ' selected'; - } else if (!this.multiple && this.$utils.equalStr(this.currentValue, node[_this.valueName])) { + } else if (!this.multiple && (this.$utils.equalStr(this.currentValue, node[this.valueName]) || this.handleObjectValue(node[this.valueName]))) { classtxt = classtxt + ' selected'; } - if (index + 1 == _this.focusIndex || node['_focusSelect']) { + if (index + 1 == this.focusIndex || node['_focusSelect']) { classtxt = classtxt + ' hover'; } if (node['_disabled']) { @@ -1398,17 +1419,16 @@ export default { }; }, setInputwidth() { - let _this = this; - return function(keyword) { + return (keyword) => { let style = {}; - if (!_this.multiple) { - if (keyword || _this.getPlaceholder || (_this.isSingel && _this.selectedList.length > 0) || (!_this.multiple && _this.currentSearch && !_this.isSquare)) { - Object.assign(style, { maxWidth: '100%', minWidth: '14px', width: _this.calculateInputWidth(keyword) * 14 + 14 + 'px' }); + if (!this.multiple) { + if (keyword || this.getPlaceholder || (this.isSingel && this.selectedList.length > 0) || (!this.multiple && this.currentSearch && !this.isSquare)) { + Object.assign(style, { maxWidth: '100%', minWidth: '14px', width: this.calculateInputWidth(keyword) * 14 + 14 + 'px' }); } else { style.width = '100%'; } } else if (keyword || this.getPlaceholder) { - Object.assign(style, { maxWidth: '100%', minWidth: '14px', width: _this.calculateInputWidth(keyword) * 14 + 14 + 'px' }); + Object.assign(style, { maxWidth: '100%', minWidth: '14px', width: this.calculateInputWidth(keyword) * 14 + 14 + 'px' }); } else if (this.currentValue && this.currentValue.length > 0) { style.width = '14px'; // 将原有的30像素改成14像素,解决输入框宽度过长,导致换行问题 } @@ -1430,7 +1450,7 @@ export default { // isSame = true; // } if (!isSame) { - this.currentValue = this.multiple ? (this.$utils.isEmpty(newValue) ? [] : [].concat(newValue)) : newValue; + this.currentValue = this.handleCurrentValue(newValue); this.validMesage = ''; this.isValidPass = true; this.watchChange(!!this.url); @@ -1441,7 +1461,7 @@ export default { dataList: { handler: function(newValue, oldValue) { if (!this.url) { - this.nodeList = JSON.parse(JSON.stringify(this.dataList || [])); + this.nodeList = this.$utils.deepClone(this.dataList) || []; this.nodeList && this.nodeList.length > 20 && this.search === null ? (this.currentSearch = true) : (this.currentSearch = this.search); //当search参数值不存在时 如果长度大于20增加搜索功能, this.watchChange(true); } @@ -1449,10 +1469,10 @@ export default { deep: true }, url(newValue, oldValue) { - newValue ? this.watchChange(false) : (this.nodeList = JSON.parse(JSON.stringify(this.dataList || []))); + newValue ? this.watchChange(false) : (this.nodeList = this.$utils.deepClone(this.dataList || [])); }, dynamicUrl(newValue, oldValue) { - newValue ? this.watchChange(false) : (this.nodeList = JSON.parse(JSON.stringify(this.dataList || []))); + newValue ? this.watchChange(false) : (this.nodeList = this.$utils.deepClone(this.dataList || [])); }, params: { handler(newValue, oldValue) { @@ -1463,11 +1483,10 @@ export default { }, deep: true }, - isVisible: function(val) { - let _this = this; + isVisible(val) { if (val) { - this.$nextTick(function() { - _this.updatePosition(); + this.$nextTick(() => { + this.updatePosition(); }); typeof this.onOpenChange == 'function' && this.onOpenChange(val); this.firstOutside = false; @@ -1479,15 +1498,15 @@ export default { } } } - if (!val && _this.nodeList.length > 0) { - _this.nodeList.forEach(no => { + if (!val && this.nodeList.length > 0) { + this.nodeList.forEach(no => { no['_focusSelect'] = false; }); - _this.focusIndex = -1; + this.focusIndex = -1; } this.$emit('on-open-change', val); }, - multiple: function(val) { + multiple(val) { if (this.multiple == true && typeof this.currentValue == 'string') { this.currentValue = [this.currentValue]; } else if (this.multiple == false && typeof this.currentValue == 'object') { @@ -1522,20 +1541,6 @@ function setWidth($contain, $target, transfer) { // } } } - -function ArrIndexOf(arr, str) { - //重写 数组的indexof功能 主要是为了实现 1 = '1' 的情况 - let index = -1; - if (arr instanceof Array) { - arr.find((item, i) => { - utils.equalStr(item, str) && (index = i); - return index >= 0; - }); - } else { - utils.equalStr(arr, str) && (index = 0); - } - return index; -}