tool-input.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. import request from 'submodule/dx-element-ui/src/tools/request';
  2. import {isTypeof, isJsonString, createUUID, axiosReqParams, responseNodeParseList, responseKeyToValue, responseToResult, isArrayInnerValue, mergeRequestParams} from 'submodule/dx-element-ui/src/tools/utils';
  3. //初始化input值
  4. export function initInputData(_this) {
  5. let item = _this.inputItem,
  6. inputType = _this.inputType ? _this.inputType : 'show';
  7. // 字段优先级使用
  8. _this.inputPriField = item[inputType].field ? item[inputType].field : item.field
  9. if(item[inputType]){
  10. _this.inputItem[inputType].hideName = _this.inputItem[inputType].hasOwnProperty('hideName') ? _this.inputItem[inputType].hideName : (inputType == 'search' ? true : false);
  11. if (item[inputType].type == 'text-tag') {
  12. _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]) : []));
  13. } else if (item[inputType].type == 'dynamic' || item[inputType].type == 'tree') {
  14. dynamicInitData(_this, item, item);
  15. } else if (item[inputType].type == 'file') {
  16. 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] : []);
  17. if (_this.rowData.hasOwnProperty(item.field)) {
  18. _this.rowData[item.field] = val;
  19. } else {
  20. _this.$set(_this.rowData, item.field, val);
  21. }
  22. if(Array.isArray(_this.rowData[item.field])) {
  23. if(_this.rowData[item.field] && _this.rowData[item.field].length > 0) {
  24. _this.rowData[item.field].forEach(row => {
  25. for(let [fk, fv] of Object.entries(item[inputType].props)) {
  26. if(!row.hasOwnProperty(fk)){
  27. row[fk] = row[fv];
  28. }
  29. }
  30. })
  31. }
  32. } else {
  33. let tmpVal = [_this.rowData[item.field]]
  34. if (item[inputType].iType === 'string') {
  35. tmpVal = _this.rowData[item.field].split(item[inputType].sign || ',')
  36. }
  37. _this.rowData[item.field] = []
  38. // 重新赋值
  39. tmpVal.forEach(itemVal => {
  40. _this.rowData[item.field].push({url: itemVal, name: itemVal})
  41. })
  42. }
  43. } else if (item[inputType].type == 'key-val' || item[inputType].type == 'dialog' || item[inputType].type == 'task' || item[inputType].type == 'map') {
  44. if (_this.dynamicStatus.hasOwnProperty(item.field)) {
  45. _this.dynamicStatus[item.field] = false;
  46. } else {
  47. _this.$set(_this.dynamicStatus, item.field, false);
  48. }
  49. if(item[inputType].type == 'map') {
  50. initMulFieldValue(_this);
  51. }
  52. } else if (item[inputType].type == 'select' && !item[inputType].mulField) {
  53. if(_this.rowData[item.field]) {
  54. if (item.stype == 'mapping') {
  55. let mappingItem = {
  56. label: _this.rowData[item.mapping],
  57. value: _this.rowData[item.field]
  58. };
  59. if (mappingItem.label && !isArrayInnerValue(_this.selectList[item[inputType].obj], mappingItem, 'value')) {
  60. _this.selectList[item[inputType].obj].unshift(mappingItem);
  61. }
  62. }
  63. if (item[inputType].multiple && item[inputType].iType == 'string') {
  64. _this.rowData[item.field] = isTypeof(_this.rowData[item.field]) == 'string' ? _this.rowData[item.field].split(item[inputType].sign) : _this.rowData[item.field];
  65. }
  66. } else {
  67. if (!_this.rowData.hasOwnProperty(item.field)) {
  68. 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);
  69. _this.$set(_this.rowData, item.field, val);
  70. }
  71. }
  72. if (item[inputType].hasOwnProperty('subField')) {
  73. let currSubFieldValue = '';
  74. if (isTypeof(_this.selectList[item[inputType].obj]) === 'array') {
  75. for (let i = 0; i < _this.selectList[item[inputType].obj].length; i++) {
  76. if (_this.rowData[item.field] === _this.selectList[item[inputType].obj][i].value) {
  77. currSubFieldValue = _this.selectList[item[inputType].obj][i].label;
  78. break;
  79. }
  80. }
  81. }
  82. if (_this.rowData.hasOwnProperty(item[inputType].subField)) {
  83. _this.rowData[item[inputType].subField] = currSubFieldValue;
  84. } else {
  85. _this.$set(_this.rowData, item[inputType].subField, currSubFieldValue);
  86. }
  87. }
  88. } 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') {
  89. initMulFieldValue(_this);
  90. } else if (item[inputType].type == 'checkbox-group' || item[inputType].type == 'input-range') {
  91. 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);
  92. let tmpVal = val ? (isTypeof(val) === 'array' ? val : (isTypeof(val) === 'string' ? (val.split(item.sign || ',')) : [])) : []
  93. if (_this.rowData.hasOwnProperty(item.field)) {
  94. _this.rowData[item.field] = tmpVal;
  95. } else {
  96. _this.$set(_this.rowData, item.field, tmpVal);
  97. }
  98. } else {
  99. // 优先使用item[inputType].value的值
  100. 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);
  101. // 设置值
  102. if (_this.rowData.hasOwnProperty(item.field)) {
  103. _this.rowData[item.field] = val
  104. } else {
  105. _this.$set(_this.rowData, item.field, val)
  106. }
  107. // 以下逻辑破坏了rowData属性的数据类型,暂时注释掉
  108. // if (_this.rowData.hasOwnProperty(item.field)) {
  109. // 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)
  110. // _this.rowData[item.field] = tmpRValue;
  111. // } else {
  112. // isTypeof(_this.rowData) === 'object' && _this.$set(_this.rowData, item.field, (isTypeof(val) === 'number' ? (val + '') : val));
  113. // }
  114. }
  115. }
  116. //名字前增加必填的标识
  117. iShowRequiredStatus(item, inputType);
  118. }
  119. //名字前增加必填的标识
  120. export function iShowRequiredStatus(item, inputType) {
  121. const tmpRules = []
  122. item.required = false;
  123. // 全局的rules控制
  124. if (item.rules && Array.isArray(item.rules)) {
  125. const ruleStatus = item.hasOwnProperty(inputType) ? (item[inputType].hasOwnProperty('rule') ? item[inputType].rule : true) : true
  126. if (ruleStatus) {
  127. tmpRules.push(...new Set(item.rules))
  128. }
  129. }
  130. // 自己inputType中的rules
  131. if(item[inputType] && item[inputType].rules && Array.isArray(item[inputType].rules)) {
  132. tmpRules.push(...new Set(item[inputType].rules))
  133. }
  134. for(let i = 0; i < tmpRules.length; i++) {
  135. // required必填项
  136. if(tmpRules[i].hasOwnProperty('required') && tmpRules[i].required) {
  137. item.required = true
  138. break;
  139. }
  140. // 多字段至少一个必填
  141. if (tmpRules[i].hasOwnProperty('validator') && tmpRules[i].validator === 'validateMultipleFieldLeast') {
  142. item.required = true
  143. break;
  144. }
  145. }
  146. }
  147. // init mulField value
  148. export function initMulFieldValue(_this) {
  149. let tmpValue = [],
  150. flagValue = false,
  151. tmpLastValue = null,
  152. item = _this.inputItem,
  153. currFieldValue = _this.rowData[item.field],
  154. inputType = _this.inputType ? _this.inputType : 'show';
  155. // 遍历对象数据
  156. Object.keys(item[inputType].mulField).forEach(kk => {
  157. if(_this.rowData[kk]) flagValue = true;
  158. _this.rowData[kk] && tmpValue.push(_this.rowData[kk]);
  159. })
  160. // 重置值
  161. 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) : '');
  162. if (_this.rowData.hasOwnProperty(item.field)) {
  163. _this.rowData[item.field] = item[inputType].type == 'select' ? (item[inputType].multiple ? (tmpLastValue || currFieldValue || []) : (tmpLastValue || currFieldValue || '')) : tmpLastValue;
  164. } else {
  165. isTypeof(_this.rowData) === 'object' && _this.$set(_this.rowData, item.field, tmpLastValue);
  166. }
  167. if(item[inputType].type == 'select' && tmpLastValue) {
  168. var tmpMap = {
  169. label: tmpValue.join(' / '),
  170. value: _this.rowData[item.field]
  171. };
  172. if (!isArrayInnerValue(_this.selectList[item[inputType].obj], tmpMap, 'value')) {
  173. _this.selectList[item[inputType].obj].unshift(tmpMap);
  174. }
  175. }
  176. }
  177. //鼠标进入时,column的parseType:1
  178. export function parseDynamicDataFun1(item, inputType, value){
  179. let res = [],
  180. keyVals = {};
  181. if(item[inputType].type == 'dynamic'){
  182. keyVals = {
  183. key: item[inputType].list && item[inputType].list[0] && item[inputType].list[0].field,
  184. value: item[inputType].list && item[inputType].list[1] && item[inputType].list[1].field
  185. }
  186. }
  187. if(value && value.length > 0){
  188. if(typeof(value) === 'string'){
  189. let splits = value.split('&&'),
  190. mapKey = splits[0].split(','),
  191. mapVals = splits[1].split(',');
  192. for(let i = 0; i < mapKey.length; i++){
  193. let tmpItem = {};
  194. tmpItem[keyVals.key] = mapKey[i];
  195. tmpItem[keyVals.value] = mapVals[i];
  196. res.push(tmpItem);
  197. }
  198. }else{
  199. value.forEach(iList => {
  200. res.push(iList);
  201. });
  202. }
  203. }else{
  204. let tmpItem = {};
  205. tmpItem[keyVals.key] = '';
  206. tmpItem[keyVals.value] = '';
  207. res.push(tmpItem);
  208. }
  209. return res;
  210. }
  211. //鼠标进入时,column的parseType:2
  212. export function parseDynamicDataFun2(item, inputType, value){
  213. let res = [],
  214. keyVals = {};
  215. if(item[inputType].type == 'dynamic'){
  216. keyVals = {
  217. key: item[inputType].list && item[inputType].list[0] && item[inputType].list[0].field,
  218. value: item[inputType].list && item[inputType].list[1] && item[inputType].list[1].field
  219. }
  220. }
  221. if(value && value.length > 0){
  222. let jsonList = JSON.parse(value);
  223. if(isTypeof(jsonList) == 'array'){
  224. jsonList.length > 0 && jsonList.forEach(iList => {
  225. let tmpItem = {};
  226. for(let [k, v] of Object.entries(iList)){
  227. tmpItem[keyVals.key] = k;
  228. tmpItem[keyVals.value] = v;
  229. }
  230. res.push(tmpItem);
  231. });
  232. }else if(isTypeof(jsonList) == 'object'){
  233. for(let [k, v] of Object.entries(jsonList)){
  234. let tmpItem = {};
  235. tmpItem[keyVals.key] = k;
  236. tmpItem[keyVals.value] = isTypeof(v) === 'string' ? v : JSON.stringify(v);
  237. res.push(tmpItem);
  238. };
  239. }
  240. }else{
  241. let tmpItem = {};
  242. tmpItem[keyVals.key] = '';
  243. tmpItem[keyVals.value] = '';
  244. res.push(tmpItem);
  245. }
  246. return res;
  247. }
  248. export function parseDynamicDataFun3(item, inputType, value) {
  249. let res = [],
  250. keyVals = item[inputType].props;
  251. if(value && value.length > 0){
  252. let jsonList = isTypeof(value) === 'string' ? JSON.parse(value) : '',
  253. cTree = function (vals, resData) {
  254. if(isTypeof(vals) == 'array'){
  255. vals.length > 0 && vals.forEach((node, index) => {
  256. if(isTypeof(node) == 'string'){
  257. let tmpItem = {};
  258. tmpItem[item[inputType].key] = createUUID();
  259. tmpItem[keyVals.label] = index;
  260. tmpItem[keyVals.value] = node;
  261. tmpItem[keyVals.children] = [];
  262. resData.push(tmpItem);
  263. }else{
  264. cTree(node, resData);
  265. }
  266. });
  267. }else if(isTypeof(vals) == 'object'){
  268. for(let [k, v] of Object.entries(vals)){
  269. if(isTypeof(v) == 'array'){
  270. let tmpItem = {};
  271. tmpItem[item[inputType].key] = createUUID();
  272. tmpItem[keyVals.label] = k;
  273. tmpItem[keyVals.value] = '';
  274. tmpItem[keyVals.children] = [];
  275. v.length > 0 && v.forEach((node, index) => {
  276. cTree(node, tmpItem[keyVals.children]);
  277. });
  278. resData.push(tmpItem);
  279. }else if(isTypeof(v) == 'object'){
  280. let tmpItem = {};
  281. tmpItem[item[inputType].key] = createUUID();
  282. tmpItem[keyVals.label] = k;
  283. tmpItem[keyVals.value] = '';
  284. tmpItem[keyVals.children] = [];
  285. cTree(v, tmpItem[keyVals.children]);
  286. resData.push(tmpItem);
  287. }else{
  288. let tmpItem = {};
  289. tmpItem[item[inputType].key] = createUUID();
  290. tmpItem[keyVals.label] = k;
  291. tmpItem[keyVals.value] = v;
  292. tmpItem[keyVals.children] = [];
  293. resData.push(tmpItem);
  294. }
  295. }
  296. }else if(isTypeof(vals) == 'string'){
  297. let tmpItem = Object.create(null);
  298. tmpItem[item[inputType].key] = createUUID();
  299. tmpItem[keyVals.label] = vals;
  300. tmpItem[keyVals.value] = vals;
  301. tmpItem[keyVals.children] = [];
  302. resData.push(tmpItem);
  303. }
  304. };
  305. cTree(jsonList, res);
  306. }else{
  307. let tmpItem = {};
  308. tmpItem[item[inputType].key] = createUUID();
  309. tmpItem[keyVals.label] = '';
  310. tmpItem[keyVals.value] = '';
  311. tmpItem[keyVals.children] = [];
  312. res.push(tmpItem);
  313. }
  314. return res;
  315. }
  316. export function createTreeRoot(_this, data) {
  317. let newChild = { id: createUUID(), key: '', children: [] };
  318. data.push(newChild);
  319. }
  320. export function appendTreeChildren(_this, data) {
  321. let newChild = { id: createUUID(), key: '', children: [] };
  322. if (!data.children) {
  323. _this.$set(data, 'children', []);
  324. }
  325. data.children.push(newChild);
  326. }
  327. export function removeTreeNode(node, data) {
  328. let parent = node.parent,
  329. children = parent.data.children || parent.data,
  330. index = children.findIndex(d => d.id === data.id);
  331. children.splice(index, 1);
  332. }
  333. //根据parseType跳转不同的函数
  334. export function parseDynamicData(_this, item, inputItem){
  335. let inputType = _this.inputType ? _this.inputType : 'show';
  336. if(inputItem[inputType].hasOwnProperty('parseType')){
  337. let parseRes = null;
  338. switch(inputItem[inputType].parseType){
  339. case 1:
  340. parseRes = parseDynamicDataFun1(inputItem, inputType, _this.rowData[inputItem.field]);
  341. break;
  342. case 2:
  343. parseRes = parseDynamicDataFun2(inputItem, inputType, _this.rowData[inputItem.field]);
  344. break;
  345. case 3:
  346. parseRes = parseDynamicDataFun3(inputItem, inputType, _this.rowData[inputItem.field]);
  347. break;
  348. }
  349. return isTypeof(parseRes) === 'array' ? parseRes : [];
  350. }else{
  351. if(isTypeof(_this.rowData[inputItem.field]) === 'array'){
  352. return _this.rowData[inputItem.field];
  353. }else{
  354. throw new Error("dynamic的input值不是数组。");
  355. }
  356. }
  357. }
  358. //初始化弹出框,可以自定义函数或通过parseType跳转
  359. export function dynamicInitData(_this, item, inputItem){
  360. let inputType = _this.inputType ? _this.inputType : 'show';
  361. if(inputItem[inputType].type != 'dynamic' && inputItem[inputType].type != 'tree') return false;
  362. let tmpValue = isTypeof(item[inputType].callback) === 'function'
  363. ? item[inputType].callback(item, _this.rowData[inputItem.field])
  364. : parseDynamicData(_this, item, inputItem);
  365. if (_this.rowData.hasOwnProperty(item.field)) {
  366. _this.rowData[item.field] = tmpValue;
  367. } else {
  368. _this.$set(_this.rowData, item.field, tmpValue);
  369. }
  370. }
  371. //动态组中有多个字段,遍历出所有节点
  372. export function dynamicEvent(_this, inputItem){
  373. let inputType = _this.inputType ? _this.inputType : 'show';
  374. if(inputItem[inputType].hasOwnProperty('column')){
  375. inputItem[inputType].column && inputItem[inputType].column.forEach(item => {
  376. if(item[inputType].type == 'dynamic' || item[inputType].type == 'tree'){
  377. if (_this.rowData.hasOwnProperty(item.field)) {
  378. _this.rowData[item.field] = _this.rowData[inputItem.field];
  379. } else {
  380. _this.$set(_this.rowData, item.field, _this.rowData[inputItem.field]);
  381. }
  382. dynamicInitData(_this, item, inputItem);
  383. }
  384. });
  385. }
  386. }
  387. //鼠标focus入口函数
  388. export function dynamicKeyToValEvent(_this, inputItem){
  389. if(!_this.dynamicStatus[inputItem.field]){
  390. dynamicEvent(_this, inputItem);
  391. _this.dynamicStatus[inputItem.field] = true;
  392. }
  393. }
  394. //确认输入内容提交回显到输入框中的值,column的parseType:1
  395. export function parseDynamicBackDataFun1(_this, item, inputItem){
  396. let keys = [], vals = [], keyNames = {}, result = '',
  397. inputType = _this.inputType ? _this.inputType : 'show';
  398. keyNames.key = item[inputType].list[0].field;
  399. keyNames.val = item[inputType].list[1].field;
  400. if(isTypeof(_this.rowData[item.field]) === 'array'){
  401. _this.rowData[item.field] && _this.rowData[item.field].forEach(dyItem => {
  402. keys.push(dyItem[keyNames.key]);
  403. vals.push(dyItem[keyNames.val]);
  404. });
  405. }
  406. if(keys && keys.join()){
  407. result = keys.join() + '&&' + vals.join();
  408. }
  409. return result;
  410. }
  411. //确认输入内容提交回显到输入框中的值,column的parseType:2
  412. export function parseDynamicBackDataFun2(_this, item, inputItem){
  413. let keyNames = {}, result = '',
  414. inputType = _this.inputType ? _this.inputType : 'show';
  415. keyNames.key = item[inputType].list[0].field;
  416. keyNames.val = item[inputType].list[1].field;
  417. if(isTypeof(_this.rowData[item.field]) == 'array'){
  418. let tmpObj = {}, resData = [];
  419. _this.rowData[item.field].forEach(item => {
  420. if(item[keyNames.key]){
  421. tmpObj[item[keyNames.key]] = isJsonString(item[keyNames.val]) ? JSON.parse(item[keyNames.val]) : item[keyNames.val];
  422. }
  423. });
  424. if(Object.keys(tmpObj).length > 1 || (Object.keys(tmpObj).length == 1 && Object.keys(tmpObj)[0])){
  425. result = JSON.stringify(tmpObj);
  426. }
  427. }
  428. return result;
  429. }
  430. //确认输入内容提交回显到输入框中的值,树形结构column的parseType:3
  431. export function parseDynamicBackDataFun3(_this, item, inputItem){
  432. let inputType = _this.inputType ? _this.inputType : 'show',
  433. keyNames = item[inputType].props,
  434. result = '',
  435. parseTree = function (tree, resTree) {
  436. tree.forEach(item => {
  437. let tmpMap = {};
  438. if(item.children && item.children.length > 0){
  439. resTree[item[keyNames.label]] = [];
  440. parseTree(item.children, resTree[item[keyNames.label]]);
  441. tmpMap[item[keyNames.label]] = resTree[item[keyNames.label]];
  442. }else{
  443. tmpMap[item[keyNames.label]] = item[keyNames.value];
  444. }
  445. resTree.push(tmpMap);
  446. });
  447. };
  448. if(isTypeof(_this.rowData[item.field]) == 'array'){
  449. let resData = [];
  450. parseTree(_this.rowData[item.field], resData)
  451. if(resData.length > 0 && (resData.length > 1 || (Object.keys(resData[0]).length > 1 || (Object.keys(resData[0]).length == 1 && Object.keys(resData[0])[0])))){
  452. result = JSON.stringify(resData);
  453. }
  454. }
  455. return result;
  456. }
  457. //系统内部自带解释函数
  458. export function parseDynamicBackData(_this, item, inputItem){
  459. let inputType = _this.inputType ? _this.inputType : 'show';
  460. if(item[inputType].hasOwnProperty('parseType')){
  461. let parseRes = null;
  462. switch(item[inputType].parseType){
  463. case 1:
  464. parseRes = parseDynamicBackDataFun1(_this, item, inputItem);
  465. break;
  466. case 2:
  467. parseRes = parseDynamicBackDataFun2(_this, item, inputItem);
  468. break;
  469. case 3:
  470. parseRes = parseDynamicBackDataFun3(_this, item, inputItem);
  471. break;
  472. }
  473. //回显值
  474. if(_this.rowData.hasOwnProperty(inputItem.field)){
  475. _this.rowData[inputItem.field] = parseRes;
  476. }else{
  477. _this.$set(_this.rowData, inputItem.field, parseRes);
  478. }
  479. }
  480. }
  481. //任务规则组件
  482. export function tranEventBackData(_this, inputItem){
  483. let data = {},
  484. inputType = _this.inputType ? _this.inputType : 'show';
  485. data['jobType'] = _this.rowData['taskType'];
  486. if(_this.rowData['taskType'] == 7){
  487. data[_this.rowData['taskunit']] = _this.rowData['tasktime'];
  488. data['scheduleStartTime'] = _this.rowData['scheduleStartTime'];
  489. }else{
  490. data['month'] = _this.rowData['month'];
  491. data['day'] = _this.rowData['day'];
  492. data['hour'] = _this.rowData['hours'];
  493. data['minute'] = _this.rowData['minutes'];
  494. data['second'] = _this.rowData['seconds'];
  495. }
  496. let param = Object.assign({}, inputItem[inputType].queryUrl);
  497. param['_axios'] = _this.axios;
  498. createCronExpression(param, mergeRequestParams(data, _this.publicParams), _this.options).then(response => {
  499. let taskValue = response;
  500. if(response.hasOwnProperty('code') && response.code != 200){
  501. taskValue = '';
  502. }
  503. if(_this.rowData.hasOwnProperty(inputItem.field)){
  504. _this.rowData[inputItem.field] = taskValue;
  505. }else{
  506. _this.$set(_this.rowData, inputItem.field, taskValue);
  507. }
  508. });
  509. }
  510. //确认、取消按钮的条用
  511. export function parseDataEvent(_this, type, inputItem){
  512. let inputType = _this.inputType ? _this.inputType : 'show';
  513. _this.dynamicStatus[inputItem.field] = false;//隐藏弹出层
  514. if(type === 'clear') return false;
  515. if(inputItem[inputType].hasOwnProperty('column')){
  516. if(inputItem[inputType] && inputItem[inputType].type == 'task'){
  517. tranEventBackData(_this, inputItem);
  518. }else{
  519. inputItem[inputType].column && inputItem[inputType].column.forEach(item => {
  520. if(item[inputType] && (item[inputType].type == 'dynamic' || item[inputType].type == 'tree')){
  521. if(isTypeof(item[inputType].dataCallback) === 'function'){
  522. item[inputType].dataCallback(item, inputItem);
  523. }else{
  524. parseDynamicBackData(_this, item, inputItem);
  525. }
  526. }
  527. });
  528. }
  529. }
  530. }
  531. //删除文件
  532. export function handleFileRemove(_this, item, file, fileList) {
  533. let inputType = _this.inputType ? _this.inputType : 'show';
  534. /* let num = 0, field = item.field;
  535. _this.rowData[field].forEach((fileItem, fileIndex) => {
  536. if (fileItem.url == file.url) {
  537. num = fileIndex;
  538. }
  539. });
  540. _this.rowData[field].splice(num, 1); */
  541. // 成功后,提交请求
  542. if (item[inputType].deleteAxios) {
  543. const tmpParams = {};
  544. const deleteAxios = item[inputType].deleteAxios;
  545. // headers参数增加
  546. if (deleteAxios.axios) {
  547. deleteAxios.axios.headers = deleteAxios.axios.headers ? deleteAxios.axios.headers : item[inputType].headers
  548. } else {
  549. deleteAxios.axios = _this.axios
  550. }
  551. for (let [k, v] of Object.entries(deleteAxios.params)) {
  552. if (isTypeof(v) === 'object') {
  553. let tmpValue = null;
  554. if (v.type === 'value') {
  555. tmpValue = v.value;
  556. } else if (v.type === 'row') {
  557. tmpValue = _this.rowData[v.value];
  558. } else {
  559. tmpValue = file[v.value];
  560. }
  561. tmpParams[k] = isTypeof(v.dataType) === 'array' ? [tmpValue] : tmpValue;
  562. } else {
  563. tmpParams[k] = file[v];
  564. }
  565. }
  566. request(axiosReqParams(deleteAxios.base, mergeRequestParams(tmpParams, _this.publicParams), deleteAxios.axios, _this.options)).then((response) => {}).catch((err) => {});
  567. }
  568. }
  569. //文件上传成功
  570. export function handleFileSucess(_this, item, response, file, fileList) {
  571. var files = {},
  572. inputType = _this.inputType ? _this.inputType : 'show',
  573. fileRes = responseNodeParseList(response, item[inputType].node),
  574. obj = item[inputType] && item[inputType].success ? item[inputType].success : {
  575. key: 'errno',
  576. value: 0,
  577. filename: 'file'
  578. };
  579. obj.keyType = 'result';
  580. if (responseKeyToValue(response, _this, _this, obj)) {
  581. files.url = fileRes[responseToResult(_this, 'filename', obj)];
  582. files.name = file.name;
  583. // 增加提交参数
  584. for ( let [k, v] of Object.entries(item[inputType].params)) {
  585. if (isTypeof(v) === 'object') {
  586. if (v.type === 'value') {
  587. files[k] = v.value;
  588. } else {
  589. files[k] = '';
  590. }
  591. } else {
  592. files[k] = k == 'url' ? (item[inputType].fileHost ? item[inputType].fileHost : '') + fileRes[v] : fileRes[v];
  593. }
  594. }
  595. if (isTypeof(_this.rowData[item.field]) == 'array') {
  596. _this.rowData[item.field].push(files);
  597. } else {
  598. _this.rowData[item.field] = [files];
  599. }
  600. // 成功后,提交请求
  601. if (item[inputType].successAxios) {
  602. const tmpParams = {};
  603. const successAxios = item[inputType].successAxios;
  604. // headers参数增加
  605. if (successAxios.axios) {
  606. successAxios.axios.headers = successAxios.axios.headers ? successAxios.axios.headers : item[inputType].headers
  607. } else {
  608. successAxios.axios = _this.axios
  609. }
  610. for ( let [k, v] of Object.entries(successAxios.params)) {
  611. if (isTypeof(v) === 'object') {
  612. let tmpValue = null;
  613. if (v.type === 'value') {
  614. tmpValue = v.value;
  615. } else if (v.type === 'row') {
  616. tmpValue = _this.rowData[v.value];
  617. } else {
  618. tmpValue = fileRes[v.value];
  619. }
  620. tmpParams[k] = isTypeof(v.dataType) === 'array' ? [tmpValue] : tmpValue;
  621. } else {
  622. tmpParams[k] = k == 'url' ? (item[inputType].fileHost ? item[inputType].fileHost : '') + fileRes[v] : fileRes[v];
  623. }
  624. }
  625. request(axiosReqParams(successAxios.base, mergeRequestParams(tmpParams, _this.publicParams), successAxios.axios, _this.options)).then((response) => {}).catch((err) => {});
  626. }
  627. }
  628. }
  629. //文件上传失败
  630. export function handleFileError(_this, item, response, file, fileList){
  631. var inputType = _this.inputType ? _this.inputType : 'show',
  632. fileRes = item[inputType].errnode ? (responseNodeParseList(response, item[inputType].errnode) || response) : response,
  633. obj = item[inputType] && item[inputType].success ? item[inputType].success : {
  634. key: 'errno',
  635. value: 0,
  636. message: 'message'
  637. };
  638. _this.$message({type: 'error', message: fileRes[responseToResult(_this, 'message', obj)]});
  639. }
  640. export function editBtnClickEvent(_this, field) {
  641. _this.datas[field].forEach((data, index) => {
  642. if(_this.subEditTableIndex == index) {
  643. _this.selectList[field].forEach(item => {
  644. if(item.field != 'useropts'){
  645. data[item.field] = item.value;
  646. item.value = '';
  647. }
  648. });
  649. _this.subTableStatus = false;
  650. _this.subEditTableIndex = 0;
  651. }
  652. });
  653. }
  654. export function addBtnClickEvent(_this, field) {
  655. let result = {};
  656. _this.selectList[field].forEach(item =>{
  657. if(item.field != 'useropts'){
  658. result[item.field] = item.value;
  659. item.value = '';
  660. }
  661. });
  662. _this.datas[field].push(result);
  663. _this.rowData[field] = _this.datas[field];
  664. }
  665. export function validateSubDiff(_this, field) {
  666. var difflag = false, flag = false;
  667. //是否为空记录,true为不空
  668. _this.selectList[field].forEach(item => {
  669. if(field == 'mac'){
  670. if(item.field == 'mac'){
  671. if(item.value == ''){
  672. flag = false;
  673. }else{
  674. flag = true;
  675. }
  676. }
  677. }else{
  678. if(item['value'] != ''){
  679. flag = true;
  680. }
  681. }
  682. });
  683. //是否相同记录,true为相同记录
  684. _this.datas[field].forEach((data, index) => {
  685. if(!difflag){
  686. var lineflag = true;
  687. _this.selectList[field].forEach(item => {
  688. if(field == 'mac'){
  689. if(item.field == 'mac'){
  690. if(item['value'] != data.mac){
  691. lineflag = false;
  692. }
  693. }
  694. }else{
  695. if(item['value'] != data[item.field]){
  696. lineflag = false;
  697. }
  698. }
  699. });
  700. difflag = lineflag;
  701. }
  702. });
  703. return !difflag && flag;
  704. }
  705. export function addSubTable(_this, field) {
  706. //1.判断是否是修改;如果修改验证是否存在相同记录;如果为增加验证记录是否唯一
  707. if(validateSubDiff(_this, field)){
  708. if(_this.subTableStatus){
  709. editBtnClickEvent(_this, field);
  710. }else{
  711. addBtnClickEvent(_this, field);
  712. }
  713. }else{
  714. _this.$message({ type: 'error', message: '数据为空或者有相同记录!' });
  715. }
  716. }
  717. export function pageBtnClickEvent(_this, item) {
  718. let axios = item.axios || {},
  719. queryData = item.param ? item.param : {};
  720. request(axiosReqParams(item, mergeRequestParams(queryData, _this.publicParams), axios, _this.options)).then((response) => {
  721. responseKeyToValue(response, _this, _this, item.success);
  722. }).catch((err) => {});
  723. }
  724. export async function inputRemoteEvent(_this, item) {
  725. let queryData = item.param ? item.param : {};
  726. const result = await request(axiosReqParams(item, mergeRequestParams(queryData, _this.publicParams), item._axios, _this.options)).then((response) => {
  727. let next = { keyType: 'result' };
  728. let tmpData = []
  729. if (responseKeyToValue(response, _this, _this, next)) {
  730. tmpData = responseNodeParseList(response, item.parse) || []
  731. }
  732. return tmpData
  733. }).catch((err) => {});
  734. return result
  735. }
  736. export function createCronExpression(param, queryData, options) {
  737. return request(axiosReqParams(param, queryData, param._axios, options));
  738. }