import request from 'submodule/dx-element-ui/src/tools/request'; import {isTypeof, isJsonString, createUUID, axiosReqParams, responseNodeParseList, responseKeyToValue, responseToResult, isArrayInnerValue, mergeRequestParams} from 'submodule/dx-element-ui/src/tools/utils'; //初始化input值 export function initInputData(_this) { let item = _this.inputItem, inputType = _this.inputType ? _this.inputType : 'show'; // 字段优先级使用 _this.inputPriField = item[inputType].field ? item[inputType].field : item.field if(item[inputType]){ _this.inputItem[inputType].hideName = _this.inputItem[inputType].hasOwnProperty('hideName') ? _this.inputItem[inputType].hideName : (inputType == 'search' ? true : false); if (item[inputType].type == 'text-tag') { _this.$set(_this.dynamicTags, item.field, (_this.rowData[item.field] ? (isTypeof(_this.rowData[item.field]) == 'string' ? _this.rowData[item.field].split(',') : _this.rowData[item.field]) : [])); } else if (item[inputType].type == 'dynamic' || item[inputType].type == 'tree') { dynamicInitData(_this, item, item); } else if (item[inputType].type == 'file') { let val = item[inputType].parent ? (_this.rowData[item[inputType].parent] && _this.rowData[item[inputType].parent][item.field] ? _this.rowData[item[inputType].parent][item.field] : (_this.rowData[item.field] ? _this.rowData[item.field] : [])) : (_this.rowData[item.field] ? _this.rowData[item.field] : []); if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = val; } else { _this.$set(_this.rowData, item.field, val); } if(Array.isArray(_this.rowData[item.field])) { if(_this.rowData[item.field] && _this.rowData[item.field].length > 0) { _this.rowData[item.field].forEach(row => { for(let [fk, fv] of Object.entries(item[inputType].props)) { if(!row.hasOwnProperty(fk)){ row[fk] = row[fv]; } } }) } } else { let tmpVal = [_this.rowData[item.field]] if (item[inputType].iType === 'string') { tmpVal = _this.rowData[item.field].split(item[inputType].sign || ',') } _this.rowData[item.field] = [] // 重新赋值 tmpVal.forEach(itemVal => { _this.rowData[item.field].push({url: itemVal, name: itemVal}) }) } } else if (item[inputType].type == 'key-val' || item[inputType].type == 'dialog' || item[inputType].type == 'task' || item[inputType].type == 'map') { if (_this.dynamicStatus.hasOwnProperty(item.field)) { _this.dynamicStatus[item.field] = false; } else { _this.$set(_this.dynamicStatus, item.field, false); } if(item[inputType].type == 'map') { initMulFieldValue(_this); } } else if (item[inputType].type == 'select' && !item[inputType].mulField) { if(_this.rowData[item.field]) { if (item.stype == 'mapping') { let mappingItem = { label: _this.rowData[item.mapping], value: _this.rowData[item.field] }; if (mappingItem.label && !isArrayInnerValue(_this.selectList[item[inputType].obj], mappingItem, 'value')) { _this.selectList[item[inputType].obj].unshift(mappingItem); } } if (item[inputType].multiple && item[inputType].iType == 'string') { _this.rowData[item.field] = isTypeof(_this.rowData[item.field]) == 'string' ? _this.rowData[item.field].split(item[inputType].sign) : _this.rowData[item.field]; } } else { if (!_this.rowData.hasOwnProperty(item.field)) { let val = isTypeof(item[inputType].value) === 'undefined' ? (_this.rowData.hasOwnProperty(item.field) ? _this.rowData[item.field] : '') : (isTypeof(item[inputType].value) === 'function' ? eval('(' + item[inputType].value + ')')(_this.rowData) : item[inputType].value); _this.$set(_this.rowData, item.field, val); } } if (item[inputType].hasOwnProperty('subField')) { let currSubFieldValue = ''; if (isTypeof(_this.selectList[item[inputType].obj]) === 'array') { for (let i = 0; i < _this.selectList[item[inputType].obj].length; i++) { if (_this.rowData[item.field] === _this.selectList[item[inputType].obj][i].value) { currSubFieldValue = _this.selectList[item[inputType].obj][i].label; break; } } } if (_this.rowData.hasOwnProperty(item[inputType].subField)) { _this.rowData[item[inputType].subField] = currSubFieldValue; } else { _this.$set(_this.rowData, item[inputType].subField, currSubFieldValue); } } } else if ((item[inputType].type == 'select' || item[inputType].type == 'cascader' || item[inputType].type == 'date-picker' || item[inputType].type == 'time-picker') && isTypeof(item[inputType].mulField) === 'object') { initMulFieldValue(_this); } else if (item[inputType].type == 'checkbox-group' || item[inputType].type == 'input-range') { let val = isTypeof(item[inputType].value) === 'undefined' ? (_this.rowData.hasOwnProperty(item.field) ? _this.rowData[item.field] : '') : (isTypeof(item[inputType].value) === 'function' ? eval('(' + item[inputType].value + ')')(_this.rowData) : item[inputType].value); let tmpVal = val ? (isTypeof(val) === 'array' ? val : (isTypeof(val) === 'string' ? (val.split(item.sign || ',')) : [])) : [] if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = tmpVal; } else { _this.$set(_this.rowData, item.field, tmpVal); } } else { // 优先使用item[inputType].value的值 let val = isTypeof(item[inputType].value) === 'undefined' ? (_this.rowData.hasOwnProperty(item.field) ? _this.rowData[item.field] : '') : (isTypeof(item[inputType].value) === 'function' ? eval('(' + item[inputType].value + ')')(_this.rowData) : item[inputType].value); // 设置值 if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = val } else { _this.$set(_this.rowData, item.field, val) } // 以下逻辑破坏了rowData属性的数据类型,暂时注释掉 // if (_this.rowData.hasOwnProperty(item.field)) { // const tmpRValue = _this.rowData[item.field] ? (isTypeof(_this.rowData[item.field]) === 'number' ? (_this.rowData[item.field] + '') : _this.rowData[item.field]) : (isTypeof(val) === 'number' ? (val + '') : val) // _this.rowData[item.field] = tmpRValue; // } else { // isTypeof(_this.rowData) === 'object' && _this.$set(_this.rowData, item.field, (isTypeof(val) === 'number' ? (val + '') : val)); // } } } //名字前增加必填的标识 iShowRequiredStatus(item, inputType); } //名字前增加必填的标识 export function iShowRequiredStatus(item, inputType) { const tmpRules = [] item.required = false; // 全局的rules控制 if (item.rules && Array.isArray(item.rules)) { const ruleStatus = item.hasOwnProperty(inputType) ? (item[inputType].hasOwnProperty('rule') ? item[inputType].rule : true) : true if (ruleStatus) { tmpRules.push(...new Set(item.rules)) } } // 自己inputType中的rules if(item[inputType] && item[inputType].rules && Array.isArray(item[inputType].rules)) { tmpRules.push(...new Set(item[inputType].rules)) } for(let i = 0; i < tmpRules.length; i++) { // required必填项 if(tmpRules[i].hasOwnProperty('required') && tmpRules[i].required) { item.required = true break; } // 多字段至少一个必填 if (tmpRules[i].hasOwnProperty('validator') && tmpRules[i].validator === 'validateMultipleFieldLeast') { item.required = true break; } } } // init mulField value export function initMulFieldValue(_this) { let tmpValue = [], flagValue = false, tmpLastValue = null, item = _this.inputItem, currFieldValue = _this.rowData[item.field], inputType = _this.inputType ? _this.inputType : 'show'; // 遍历对象数据 Object.keys(item[inputType].mulField).forEach(kk => { if(_this.rowData[kk]) flagValue = true; _this.rowData[kk] && tmpValue.push(_this.rowData[kk]); }) // 重置值 tmpLastValue = item[inputType].type == 'cascader' ? (item[inputType].props && item[inputType].props.multiple ? [tmpValue] : tmpValue) : (flagValue ? (item[inputType].iType == 'string' ? tmpValue.join(item[inputType].sign ? item[inputType].sign : '#0') : tmpValue) : ''); if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = item[inputType].type == 'select' ? (item[inputType].multiple ? (tmpLastValue || currFieldValue || []) : (tmpLastValue || currFieldValue || '')) : tmpLastValue; } else { isTypeof(_this.rowData) === 'object' && _this.$set(_this.rowData, item.field, tmpLastValue); } if(item[inputType].type == 'select' && tmpLastValue) { var tmpMap = { label: tmpValue.join(' / '), value: _this.rowData[item.field] }; if (!isArrayInnerValue(_this.selectList[item[inputType].obj], tmpMap, 'value')) { _this.selectList[item[inputType].obj].unshift(tmpMap); } } } //鼠标进入时,column的parseType:1 export function parseDynamicDataFun1(item, inputType, value){ let res = [], keyVals = {}; if(item[inputType].type == 'dynamic'){ keyVals = { key: item[inputType].list && item[inputType].list[0] && item[inputType].list[0].field, value: item[inputType].list && item[inputType].list[1] && item[inputType].list[1].field } } if(value && value.length > 0){ if(typeof(value) === 'string'){ let splits = value.split('&&'), mapKey = splits[0].split(','), mapVals = splits[1].split(','); for(let i = 0; i < mapKey.length; i++){ let tmpItem = {}; tmpItem[keyVals.key] = mapKey[i]; tmpItem[keyVals.value] = mapVals[i]; res.push(tmpItem); } }else{ value.forEach(iList => { res.push(iList); }); } }else{ let tmpItem = {}; tmpItem[keyVals.key] = ''; tmpItem[keyVals.value] = ''; res.push(tmpItem); } return res; } //鼠标进入时,column的parseType:2 export function parseDynamicDataFun2(item, inputType, value){ let res = [], keyVals = {}; if(item[inputType].type == 'dynamic'){ keyVals = { key: item[inputType].list && item[inputType].list[0] && item[inputType].list[0].field, value: item[inputType].list && item[inputType].list[1] && item[inputType].list[1].field } } if(value && value.length > 0){ let jsonList = JSON.parse(value); if(isTypeof(jsonList) == 'array'){ jsonList.length > 0 && jsonList.forEach(iList => { let tmpItem = {}; for(let [k, v] of Object.entries(iList)){ tmpItem[keyVals.key] = k; tmpItem[keyVals.value] = v; } res.push(tmpItem); }); }else if(isTypeof(jsonList) == 'object'){ for(let [k, v] of Object.entries(jsonList)){ let tmpItem = {}; tmpItem[keyVals.key] = k; tmpItem[keyVals.value] = isTypeof(v) === 'string' ? v : JSON.stringify(v); res.push(tmpItem); }; } }else{ let tmpItem = {}; tmpItem[keyVals.key] = ''; tmpItem[keyVals.value] = ''; res.push(tmpItem); } return res; } export function parseDynamicDataFun3(item, inputType, value) { let res = [], keyVals = item[inputType].props; if(value && value.length > 0){ let jsonList = isTypeof(value) === 'string' ? JSON.parse(value) : '', cTree = function (vals, resData) { if(isTypeof(vals) == 'array'){ vals.length > 0 && vals.forEach((node, index) => { if(isTypeof(node) == 'string'){ let tmpItem = {}; tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = index; tmpItem[keyVals.value] = node; tmpItem[keyVals.children] = []; resData.push(tmpItem); }else{ cTree(node, resData); } }); }else if(isTypeof(vals) == 'object'){ for(let [k, v] of Object.entries(vals)){ if(isTypeof(v) == 'array'){ let tmpItem = {}; tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = k; tmpItem[keyVals.value] = ''; tmpItem[keyVals.children] = []; v.length > 0 && v.forEach((node, index) => { cTree(node, tmpItem[keyVals.children]); }); resData.push(tmpItem); }else if(isTypeof(v) == 'object'){ let tmpItem = {}; tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = k; tmpItem[keyVals.value] = ''; tmpItem[keyVals.children] = []; cTree(v, tmpItem[keyVals.children]); resData.push(tmpItem); }else{ let tmpItem = {}; tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = k; tmpItem[keyVals.value] = v; tmpItem[keyVals.children] = []; resData.push(tmpItem); } } }else if(isTypeof(vals) == 'string'){ let tmpItem = Object.create(null); tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = vals; tmpItem[keyVals.value] = vals; tmpItem[keyVals.children] = []; resData.push(tmpItem); } }; cTree(jsonList, res); }else{ let tmpItem = {}; tmpItem[item[inputType].key] = createUUID(); tmpItem[keyVals.label] = ''; tmpItem[keyVals.value] = ''; tmpItem[keyVals.children] = []; res.push(tmpItem); } return res; } export function createTreeRoot(_this, data) { let newChild = { id: createUUID(), key: '', children: [] }; data.push(newChild); } export function appendTreeChildren(_this, data) { let newChild = { id: createUUID(), key: '', children: [] }; if (!data.children) { _this.$set(data, 'children', []); } data.children.push(newChild); } export function removeTreeNode(node, data) { let parent = node.parent, children = parent.data.children || parent.data, index = children.findIndex(d => d.id === data.id); children.splice(index, 1); } //根据parseType跳转不同的函数 export function parseDynamicData(_this, item, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show'; if(inputItem[inputType].hasOwnProperty('parseType')){ let parseRes = null; switch(inputItem[inputType].parseType){ case 1: parseRes = parseDynamicDataFun1(inputItem, inputType, _this.rowData[inputItem.field]); break; case 2: parseRes = parseDynamicDataFun2(inputItem, inputType, _this.rowData[inputItem.field]); break; case 3: parseRes = parseDynamicDataFun3(inputItem, inputType, _this.rowData[inputItem.field]); break; } return isTypeof(parseRes) === 'array' ? parseRes : []; }else{ if(isTypeof(_this.rowData[inputItem.field]) === 'array'){ return _this.rowData[inputItem.field]; }else{ throw new Error("dynamic的input值不是数组。"); } } } //初始化弹出框,可以自定义函数或通过parseType跳转 export function dynamicInitData(_this, item, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show'; if(inputItem[inputType].type != 'dynamic' && inputItem[inputType].type != 'tree') return false; let tmpValue = isTypeof(item[inputType].callback) === 'function' ? item[inputType].callback(item, _this.rowData[inputItem.field]) : parseDynamicData(_this, item, inputItem); if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = tmpValue; } else { _this.$set(_this.rowData, item.field, tmpValue); } } //动态组中有多个字段,遍历出所有节点 export function dynamicEvent(_this, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show'; if(inputItem[inputType].hasOwnProperty('column')){ inputItem[inputType].column && inputItem[inputType].column.forEach(item => { if(item[inputType].type == 'dynamic' || item[inputType].type == 'tree'){ if (_this.rowData.hasOwnProperty(item.field)) { _this.rowData[item.field] = _this.rowData[inputItem.field]; } else { _this.$set(_this.rowData, item.field, _this.rowData[inputItem.field]); } dynamicInitData(_this, item, inputItem); } }); } } //鼠标focus入口函数 export function dynamicKeyToValEvent(_this, inputItem){ if(!_this.dynamicStatus[inputItem.field]){ dynamicEvent(_this, inputItem); _this.dynamicStatus[inputItem.field] = true; } } //确认输入内容提交回显到输入框中的值,column的parseType:1 export function parseDynamicBackDataFun1(_this, item, inputItem){ let keys = [], vals = [], keyNames = {}, result = '', inputType = _this.inputType ? _this.inputType : 'show'; keyNames.key = item[inputType].list[0].field; keyNames.val = item[inputType].list[1].field; if(isTypeof(_this.rowData[item.field]) === 'array'){ _this.rowData[item.field] && _this.rowData[item.field].forEach(dyItem => { keys.push(dyItem[keyNames.key]); vals.push(dyItem[keyNames.val]); }); } if(keys && keys.join()){ result = keys.join() + '&&' + vals.join(); } return result; } //确认输入内容提交回显到输入框中的值,column的parseType:2 export function parseDynamicBackDataFun2(_this, item, inputItem){ let keyNames = {}, result = '', inputType = _this.inputType ? _this.inputType : 'show'; keyNames.key = item[inputType].list[0].field; keyNames.val = item[inputType].list[1].field; if(isTypeof(_this.rowData[item.field]) == 'array'){ let tmpObj = {}, resData = []; _this.rowData[item.field].forEach(item => { if(item[keyNames.key]){ tmpObj[item[keyNames.key]] = isJsonString(item[keyNames.val]) ? JSON.parse(item[keyNames.val]) : item[keyNames.val]; } }); if(Object.keys(tmpObj).length > 1 || (Object.keys(tmpObj).length == 1 && Object.keys(tmpObj)[0])){ result = JSON.stringify(tmpObj); } } return result; } //确认输入内容提交回显到输入框中的值,树形结构column的parseType:3 export function parseDynamicBackDataFun3(_this, item, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show', keyNames = item[inputType].props, result = '', parseTree = function (tree, resTree) { tree.forEach(item => { let tmpMap = {}; if(item.children && item.children.length > 0){ resTree[item[keyNames.label]] = []; parseTree(item.children, resTree[item[keyNames.label]]); tmpMap[item[keyNames.label]] = resTree[item[keyNames.label]]; }else{ tmpMap[item[keyNames.label]] = item[keyNames.value]; } resTree.push(tmpMap); }); }; if(isTypeof(_this.rowData[item.field]) == 'array'){ let resData = []; parseTree(_this.rowData[item.field], resData) if(resData.length > 0 && (resData.length > 1 || (Object.keys(resData[0]).length > 1 || (Object.keys(resData[0]).length == 1 && Object.keys(resData[0])[0])))){ result = JSON.stringify(resData); } } return result; } //系统内部自带解释函数 export function parseDynamicBackData(_this, item, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show'; if(item[inputType].hasOwnProperty('parseType')){ let parseRes = null; switch(item[inputType].parseType){ case 1: parseRes = parseDynamicBackDataFun1(_this, item, inputItem); break; case 2: parseRes = parseDynamicBackDataFun2(_this, item, inputItem); break; case 3: parseRes = parseDynamicBackDataFun3(_this, item, inputItem); break; } //回显值 if(_this.rowData.hasOwnProperty(inputItem.field)){ _this.rowData[inputItem.field] = parseRes; }else{ _this.$set(_this.rowData, inputItem.field, parseRes); } } } //任务规则组件 export function tranEventBackData(_this, inputItem){ let data = {}, inputType = _this.inputType ? _this.inputType : 'show'; data['jobType'] = _this.rowData['taskType']; if(_this.rowData['taskType'] == 7){ data[_this.rowData['taskunit']] = _this.rowData['tasktime']; data['scheduleStartTime'] = _this.rowData['scheduleStartTime']; }else{ data['month'] = _this.rowData['month']; data['day'] = _this.rowData['day']; data['hour'] = _this.rowData['hours']; data['minute'] = _this.rowData['minutes']; data['second'] = _this.rowData['seconds']; } let param = Object.assign({}, inputItem[inputType].queryUrl); param['_axios'] = _this.axios; createCronExpression(param, mergeRequestParams(data, _this.publicParams), _this.options).then(response => { let taskValue = response; if(response.hasOwnProperty('code') && response.code != 200){ taskValue = ''; } if(_this.rowData.hasOwnProperty(inputItem.field)){ _this.rowData[inputItem.field] = taskValue; }else{ _this.$set(_this.rowData, inputItem.field, taskValue); } }); } //确认、取消按钮的条用 export function parseDataEvent(_this, type, inputItem){ let inputType = _this.inputType ? _this.inputType : 'show'; _this.dynamicStatus[inputItem.field] = false;//隐藏弹出层 if(type === 'clear') return false; if(inputItem[inputType].hasOwnProperty('column')){ if(inputItem[inputType] && inputItem[inputType].type == 'task'){ tranEventBackData(_this, inputItem); }else{ inputItem[inputType].column && inputItem[inputType].column.forEach(item => { if(item[inputType] && (item[inputType].type == 'dynamic' || item[inputType].type == 'tree')){ if(isTypeof(item[inputType].dataCallback) === 'function'){ item[inputType].dataCallback(item, inputItem); }else{ parseDynamicBackData(_this, item, inputItem); } } }); } } } //删除文件 export function handleFileRemove(_this, item, file, fileList) { let inputType = _this.inputType ? _this.inputType : 'show'; /* let num = 0, field = item.field; _this.rowData[field].forEach((fileItem, fileIndex) => { if (fileItem.url == file.url) { num = fileIndex; } }); _this.rowData[field].splice(num, 1); */ // 成功后,提交请求 if (item[inputType].deleteAxios) { const tmpParams = {}; const deleteAxios = item[inputType].deleteAxios; // headers参数增加 if (deleteAxios.axios) { deleteAxios.axios.headers = deleteAxios.axios.headers ? deleteAxios.axios.headers : item[inputType].headers } else { deleteAxios.axios = _this.axios } for (let [k, v] of Object.entries(deleteAxios.params)) { if (isTypeof(v) === 'object') { let tmpValue = null; if (v.type === 'value') { tmpValue = v.value; } else if (v.type === 'row') { tmpValue = _this.rowData[v.value]; } else { tmpValue = file[v.value]; } tmpParams[k] = isTypeof(v.dataType) === 'array' ? [tmpValue] : tmpValue; } else { tmpParams[k] = file[v]; } } request(axiosReqParams(deleteAxios.base, mergeRequestParams(tmpParams, _this.publicParams), deleteAxios.axios, _this.options)).then((response) => {}).catch((err) => {}); } } //文件上传成功 export function handleFileSucess(_this, item, response, file, fileList) { var files = {}, inputType = _this.inputType ? _this.inputType : 'show', fileRes = responseNodeParseList(response, item[inputType].node), obj = item[inputType] && item[inputType].success ? item[inputType].success : { key: 'errno', value: 0, filename: 'file' }; obj.keyType = 'result'; if (responseKeyToValue(response, _this, _this, obj)) { files.url = fileRes[responseToResult(_this, 'filename', obj)]; files.name = file.name; // 增加提交参数 for ( let [k, v] of Object.entries(item[inputType].params)) { if (isTypeof(v) === 'object') { if (v.type === 'value') { files[k] = v.value; } else { files[k] = ''; } } else { files[k] = k == 'url' ? (item[inputType].fileHost ? item[inputType].fileHost : '') + fileRes[v] : fileRes[v]; } } if (isTypeof(_this.rowData[item.field]) == 'array') { _this.rowData[item.field].push(files); } else { _this.rowData[item.field] = [files]; } // 成功后,提交请求 if (item[inputType].successAxios) { const tmpParams = {}; const successAxios = item[inputType].successAxios; // headers参数增加 if (successAxios.axios) { successAxios.axios.headers = successAxios.axios.headers ? successAxios.axios.headers : item[inputType].headers } else { successAxios.axios = _this.axios } for ( let [k, v] of Object.entries(successAxios.params)) { if (isTypeof(v) === 'object') { let tmpValue = null; if (v.type === 'value') { tmpValue = v.value; } else if (v.type === 'row') { tmpValue = _this.rowData[v.value]; } else { tmpValue = fileRes[v.value]; } tmpParams[k] = isTypeof(v.dataType) === 'array' ? [tmpValue] : tmpValue; } else { tmpParams[k] = k == 'url' ? (item[inputType].fileHost ? item[inputType].fileHost : '') + fileRes[v] : fileRes[v]; } } request(axiosReqParams(successAxios.base, mergeRequestParams(tmpParams, _this.publicParams), successAxios.axios, _this.options)).then((response) => {}).catch((err) => {}); } } } //文件上传失败 export function handleFileError(_this, item, response, file, fileList){ var inputType = _this.inputType ? _this.inputType : 'show', fileRes = item[inputType].errnode ? (responseNodeParseList(response, item[inputType].errnode) || response) : response, obj = item[inputType] && item[inputType].success ? item[inputType].success : { key: 'errno', value: 0, message: 'message' }; _this.$message({type: 'error', message: fileRes[responseToResult(_this, 'message', obj)]}); } export function editBtnClickEvent(_this, field) { _this.datas[field].forEach((data, index) => { if(_this.subEditTableIndex == index) { _this.selectList[field].forEach(item => { if(item.field != 'useropts'){ data[item.field] = item.value; item.value = ''; } }); _this.subTableStatus = false; _this.subEditTableIndex = 0; } }); } export function addBtnClickEvent(_this, field) { let result = {}; _this.selectList[field].forEach(item =>{ if(item.field != 'useropts'){ result[item.field] = item.value; item.value = ''; } }); _this.datas[field].push(result); _this.rowData[field] = _this.datas[field]; } export function validateSubDiff(_this, field) { var difflag = false, flag = false; //是否为空记录,true为不空 _this.selectList[field].forEach(item => { if(field == 'mac'){ if(item.field == 'mac'){ if(item.value == ''){ flag = false; }else{ flag = true; } } }else{ if(item['value'] != ''){ flag = true; } } }); //是否相同记录,true为相同记录 _this.datas[field].forEach((data, index) => { if(!difflag){ var lineflag = true; _this.selectList[field].forEach(item => { if(field == 'mac'){ if(item.field == 'mac'){ if(item['value'] != data.mac){ lineflag = false; } } }else{ if(item['value'] != data[item.field]){ lineflag = false; } } }); difflag = lineflag; } }); return !difflag && flag; } export function addSubTable(_this, field) { //1.判断是否是修改;如果修改验证是否存在相同记录;如果为增加验证记录是否唯一 if(validateSubDiff(_this, field)){ if(_this.subTableStatus){ editBtnClickEvent(_this, field); }else{ addBtnClickEvent(_this, field); } }else{ _this.$message({ type: 'error', message: '数据为空或者有相同记录!' }); } } export function pageBtnClickEvent(_this, item) { let axios = item.axios || {}, queryData = item.param ? item.param : {}; request(axiosReqParams(item, mergeRequestParams(queryData, _this.publicParams), axios, _this.options)).then((response) => { responseKeyToValue(response, _this, _this, item.success); }).catch((err) => {}); } export async function inputRemoteEvent(_this, item) { let queryData = item.param ? item.param : {}; const result = await request(axiosReqParams(item, mergeRequestParams(queryData, _this.publicParams), item._axios, _this.options)).then((response) => { let next = { keyType: 'result' }; let tmpData = [] if (responseKeyToValue(response, _this, _this, next)) { tmpData = responseNodeParseList(response, item.parse) || [] } return tmpData }).catch((err) => {}); return result } export function createCronExpression(param, queryData, options) { return request(axiosReqParams(param, queryData, param._axios, options)); }