onlineFormMixins.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. import { mapMutations } from 'vuex';
  2. import * as StaticDict from '@/staticDict';
  3. import { getToken } from '@/utils';
  4. import rules from '@/utils/validate.js';
  5. import { getOperationPermCode } from '../utils/index.js';
  6. import OnlineForm from '@/views/onlineForm/index.vue';
  7. import {
  8. OnlineFormController
  9. } from '@/api/onlineController.js';
  10. import axios from 'axios';
  11. import { uploadMixin } from '@/core/mixins';
  12. const OnlineFormMixins = {
  13. props: {
  14. formId: {
  15. type: String,
  16. required: true
  17. },
  18. readOnly: {
  19. type: Boolean,
  20. default: false
  21. },
  22. closeVisible: {
  23. type: String,
  24. default: '0'
  25. },
  26. params: {
  27. type: Object
  28. }
  29. },
  30. mixins: [uploadMixin],
  31. data () {
  32. return {
  33. isLoading: true,
  34. formData: {},
  35. rules: {},
  36. components_json: {},
  37. blueunit: [],
  38. redunit: [],
  39. center: [],
  40. satellite: [],
  41. component_movementjson: {},
  42. formConfig: {
  43. formType: undefined,
  44. formKind: undefined,
  45. gutter: 20,
  46. labelPosition: 'right',
  47. labelWidth: 120,
  48. width: undefined,
  49. height: undefined,
  50. formWidgetList: [],
  51. formQueryTable: undefined
  52. },
  53. masterTable: undefined,
  54. errorMessage: [],
  55. tableWidgetList: [],
  56. dropdownWidgetList: [],
  57. richEditWidgetList: [],
  58. datasourceMap: new Map(),
  59. relationMap: new Map(),
  60. tableMap: new Map(),
  61. columnMap: new Map(),
  62. dictMap: new Map(),
  63. linkageMap: new Map()
  64. }
  65. },
  66. methods: {
  67. getFormData () {
  68. return this.formData;
  69. },
  70. getPermCode (widget, operation) {
  71. return getOperationPermCode(widget, operation);
  72. },
  73. loadOnlineFormData () {
  74. return new Promise((resolve, reject) => {
  75. OnlineFormController.render(this, {
  76. formId: this.formId
  77. }).then(res => {
  78. let onlineForm = res.data.onlineForm;
  79. let formConfigData = JSON.parse(onlineForm.widgetJson);
  80. let formConfig = {
  81. formName: onlineForm.formName,
  82. formType: onlineForm.formType,
  83. formKind: onlineForm.formKind,
  84. masterTableId: onlineForm.masterTableId,
  85. labelWidth: formConfigData.formConfig.labelWidth,
  86. labelPosition: formConfigData.formConfig.labelPosition,
  87. gutter: formConfigData.formConfig.gutter,
  88. height: formConfigData.formConfig.height,
  89. width: formConfigData.formConfig.width,
  90. formWidgetList: formConfigData.widgetList,
  91. formQueryTable: formConfigData.formConfig.tableWidget
  92. }
  93. onlineForm = null;
  94. res.data.onlineForm = null;
  95. // 字典
  96. if (Array.isArray(res.data.onlineDictList)) {
  97. res.data.onlineDictList.forEach(dict => {
  98. this.dictMap.set(dict.dictId, dict);
  99. });
  100. }
  101. res.data.onlineDictList = null;
  102. // 数据表
  103. if (Array.isArray(res.data.onlineTableList)) {
  104. res.data.onlineTableList.forEach(table => {
  105. this.tableMap.set(table.tableId, table);
  106. });
  107. }
  108. res.data.onlineTableList = null;
  109. // 字段
  110. if (Array.isArray(res.data.onlineColumnList)) {
  111. res.data.onlineColumnList.forEach(column => {
  112. if (column.dictId != null) {
  113. column.dictInfo = this.dictMap.get(column.dictId);
  114. }
  115. let table = this.tableMap.get(column.tableId);
  116. if (table) {
  117. if (!Array.isArray(table.columnList)) table.columnList = [];
  118. table.columnList.push(column);
  119. }
  120. this.columnMap.set(column.columnId, column);
  121. });
  122. }
  123. res.data.onlineColumnList = null;
  124. // 虚拟字段
  125. if (Array.isArray(res.data.onlineVirtualColumnList)) {
  126. res.data.onlineVirtualColumnList.forEach(column => {
  127. column.columnId = column.virtualColumnId;
  128. column.columnComment = column.columnPrompt;
  129. column.columnName = column.objectFieldName;
  130. column.primaryKey = false;
  131. column.isVirtualColumn = true;
  132. this.columnMap.set(column.columnId, column);
  133. });
  134. }
  135. res.data.onlineVirtualColumnList = null;
  136. // 数据源
  137. if (Array.isArray(res.data.onlineDatasourceList)) {
  138. res.data.onlineDatasourceList.forEach(datasource => {
  139. datasource.masterTable = this.tableMap.get(datasource.masterTableId);
  140. if (datasource.masterTable) datasource.masterTable.datasource = datasource;
  141. this.datasourceMap.set(datasource.datasourceId, datasource);
  142. });
  143. }
  144. res.data.onlineDatasourceList = null;
  145. // 关联
  146. if (Array.isArray(res.data.onlineDatasourceRelationList)) {
  147. res.data.onlineDatasourceRelationList.forEach(relation => {
  148. let datasource = this.datasourceMap.get(relation.datasourceId);
  149. if (datasource) {
  150. if (!Array.isArray(datasource.relationList)) datasource.relationList = [];
  151. datasource.relationList.push(relation);
  152. }
  153. relation.masterColumn = this.columnMap.get(relation.masterColumnId);
  154. relation.slaveTable = this.tableMap.get(relation.slaveTableId);
  155. if (relation.slaveTable) {
  156. relation.slaveTable.relation = relation;
  157. relation.slaveTable.datasource = datasource;
  158. }
  159. relation.slaveColumn = this.columnMap.get(relation.slaveColumnId);
  160. this.relationMap.set(relation.relationId, relation);
  161. });
  162. }
  163. res.data.onlineDatasourceRelationList = null;
  164. // 校验规则
  165. if (Array.isArray(res.data.onlineColumnRuleList)) {
  166. res.data.onlineColumnRuleList.forEach(rule => {
  167. let column = this.columnMap.get(rule.columnId);
  168. if (column) {
  169. if (!Array.isArray(column.ruleList)) column.ruleList = [];
  170. column.ruleList.push(rule);
  171. }
  172. });
  173. }
  174. res.data.onlineColumnRuleList = null;
  175. this.initFormData(formConfig);
  176. this.formConfig = formConfig;
  177. resolve();
  178. }).catch(e => {
  179. reject(e);
  180. });
  181. });
  182. },
  183. initWidget (widget, formConfig) {
  184. if (widget != null) {
  185. if (widget.datasourceId) widget.datasource = this.datasourceMap.get(widget.datasourceId);
  186. if (widget.relationId) {
  187. widget.relation = this.relationMap.get(widget.relationId);
  188. if (widget.datasource == null && widget.relation != null) {
  189. widget.datasource = this.datasourceMap.get(widget.relation.datasourceId);
  190. }
  191. }
  192. if (widget.datasource == null) {
  193. widget.datasource = {
  194. masterTable: {}
  195. }
  196. widget.column = {}
  197. }
  198. if (widget.tableId) widget.table = this.tableMap.get(widget.tableId);
  199. if (widget.columnId) widget.column = this.columnMap.get(widget.columnId);
  200. if (widget.widgetType === this.SysCustomWidgetType.RichEditor) {
  201. this.richEditWidgetList.push(widget);
  202. }
  203. // 初始化组件下拉字典参数
  204. if (Array.isArray(widget.dictParamList)) {
  205. widget.dictParamList.forEach(param => {
  206. if (param.dictValueType === this.SysOnlineParamValueType.STATIC_DICT) {
  207. let errorItem = null;
  208. if (Array.isArray(param.dictValue) && param.dictValue.length === 2) {
  209. let staticDict = StaticDict[param.dictValue[0]];
  210. if (staticDict == null) {
  211. errorItem = {
  212. widget: widget,
  213. message: '组件字典参数' + param.dictParamName + '绑定的静态字典 [' + param.dictValue[0] + '] 并不存在!'
  214. }
  215. } else {
  216. if (staticDict.getValue(param.dictValue[1]) == null) {
  217. errorItem = {
  218. widget: widget,
  219. message: '组件字典参数' + param.dictParamName + '绑定的静态字典值并不属于静态字段 [' + param.dictValue[0] + '] !'
  220. }
  221. }
  222. }
  223. } else {
  224. errorItem = {
  225. widget: widget,
  226. message: '组件字典参数' + param.dictParamName + '绑定的静态字典错误!'
  227. }
  228. }
  229. if (errorItem != null) this.errorMessage.push(errorItem);
  230. }
  231. });
  232. }
  233. if (widget.column && widget.column.dictInfo != null) {
  234. this.dropdownWidgetList.push(widget);
  235. }
  236. // 初始化表格列
  237. if (widget.widgetType === this.SysCustomWidgetType.Table) {
  238. // 寻找表格主键
  239. widget.primaryColumnName = undefined;
  240. if (widget.table && Array.isArray(widget.table.columnList)) {
  241. for (let i = 0; i < widget.table.columnList.length; i++) {
  242. if (widget.table.columnList[i].primaryKey) {
  243. widget.primaryColumnName = widget.table.columnList[i].columnName;
  244. break;
  245. }
  246. }
  247. }
  248. if (Array.isArray(widget.tableColumnList)) {
  249. widget.tableColumnList.forEach(tableColumn => {
  250. tableColumn.table = this.tableMap.get(tableColumn.tableId);
  251. tableColumn.column = this.columnMap.get(tableColumn.columnId);
  252. tableColumn.relation = this.relationMap.get(tableColumn.relationId);
  253. if (tableColumn.table == null || tableColumn.column == null) {
  254. this.errorMessage.push({
  255. widget: widget,
  256. message: '表格列 [' + tableColumn.showName + '] 绑定的字段不存在!'
  257. });
  258. }
  259. });
  260. }
  261. if (Array.isArray(widget.queryParamList)) {
  262. widget.queryParamList.forEach(param => {
  263. param.table = this.tableMap.get(param.tableId);
  264. param.column = this.columnMap.get(param.columnId);
  265. param.relation = this.relationMap.get(param.relationId);
  266. if (param.table == null || param.column == null) {
  267. this.errorMessage.push({
  268. widget: widget,
  269. message: '表格查询参数不存在!'
  270. });
  271. }
  272. });
  273. }
  274. this.tableWidgetList.push(widget);
  275. }
  276. while (widget.datasourceId != null || widget.relationId != null) {
  277. if (widget.datasourceId == null && widget.relation == null) {
  278. let errorItem = {
  279. widget: widget,
  280. message: '组件绑定字段所属' + (widget.datasourceId ? '数据源' : '关联') + '不存在!'
  281. }
  282. this.errorMessage.push(errorItem);
  283. break;
  284. }
  285. if (widget.table == null) {
  286. let errorItem = {
  287. widget: widget,
  288. messagre: '组件绑定字段所属数据表不存在!'
  289. }
  290. this.errorMessage.push(errorItem);
  291. break;
  292. }
  293. if (widget.column == null && widget.columnId != null) {
  294. let errorItem = {
  295. widget: widget,
  296. messagre: '组件绑定字段不存在!'
  297. }
  298. this.errorMessage.push(errorItem);
  299. break;
  300. }
  301. if (widget.column) {
  302. let table = this.tableMap.get(widget.tableId);
  303. if (table.tableId !== widget.table.tableId) {
  304. let errorItem = {
  305. widget: widget,
  306. messagre: '组件绑定字段不属于选张的数据表!'
  307. }
  308. this.errorMessage.push(errorItem);
  309. break;
  310. }
  311. }
  312. break;
  313. }
  314. if (Array.isArray(widget.childWidgetList)) {
  315. widget.childWidgetList.forEach(subWidget => {
  316. if (formConfig.formType === this.SysOnlineFormType.FLOW && this.formReadOnly) {
  317. subWidget.readOnly = true;
  318. }
  319. this.initWidget(subWidget, formConfig);
  320. })
  321. }
  322. if (widget.column && widget.column.dictInfo) {
  323. if (Array.isArray(widget.dictParamList)) {
  324. widget.dictParamList.forEach(dictParam => {
  325. if (dictParam.dictValueType === this.SysOnlineParamValueType.TABLE_COLUMN) {
  326. let linkageItem = this.linkageMap.get(dictParam.dictValue);
  327. if (linkageItem == null) {
  328. linkageItem = [];
  329. this.linkageMap.set(dictParam.dictValue, linkageItem);
  330. }
  331. linkageItem.push(widget);
  332. }
  333. });
  334. }
  335. }
  336. }
  337. },
  338. initFormWidgetList (formConfig) {
  339. this.errorMessage = [];
  340. if (Array.isArray(formConfig.formWidgetList)) {
  341. formConfig.formWidgetList.forEach(widget => {
  342. if (formConfig.formType === this.SysOnlineFormType.FLOW && this.formReadOnly) {
  343. widget.readOnly = true;
  344. }
  345. this.initWidget(widget, formConfig);
  346. });
  347. }
  348. if (this.errorMessage.length > 0) {
  349. console.error(this.errorMessage);
  350. }
  351. },
  352. buildRuleItem (widget, rule) {
  353. if (rule.propDataJson) rule.data = JSON.parse(rule.propDataJson);
  354. if (widget != null && rule != null) {
  355. switch (rule.onlineRule.ruleType) {
  356. case this.SysOnlineRuleType.INTEGER_ONLY:
  357. return { type: 'integer', message: rule.data.message, trigger: 'blur', transform: (value) => Number(value) };
  358. case this.SysOnlineRuleType.DIGITAL_ONLY:
  359. return { type: 'number', message: rule.data.message, trigger: 'blur', transform: (value) => Number(value) };
  360. case this.SysOnlineRuleType.LETTER_ONLY:
  361. return { type: 'string', pattern: rules.pattern.english, message: rule.data.message, trigger: 'blur' };
  362. case this.SysOnlineRuleType.EMAIL:
  363. return { type: 'email', message: rule.data.message, trigger: 'blur' };
  364. case this.SysOnlineRuleType.MOBILE:
  365. return { type: 'string', pattern: rules.pattern.mobie, message: rule.data.message, trigger: 'blur' };
  366. case this.SysOnlineRuleType.RANGE:
  367. if (widget.column) {
  368. let isNumber = ['Boolean', 'Date', 'String'].indexOf(widget.column.objectFieldType) === -1;
  369. return { type: isNumber ? 'number' : 'string', min: rule.data.min, max: rule.data.max, message: rule.data.message, trigger: 'blur' };
  370. }
  371. break;
  372. case this.SysOnlineRuleType.CUSTOM:
  373. return { type: 'string', pattern: new RegExp(rule.data.pattern), message: rule.data.message, trigger: 'blur' };
  374. }
  375. }
  376. },
  377. buildWidgetRule (widget, rules) {
  378. if (widget != null && widget.column != null) {
  379. let widgetRuleKey = (widget.relation ? widget.relation.variableName + '__' : '') + widget.column.columnName;
  380. // 必填字段以及设置了验证规则的字段
  381. if (!widget.column.nullable || Array.isArray(widget.column.ruleList)) {
  382. rules[widgetRuleKey] = [];
  383. // 必填验证
  384. if (!widget.column.nullable) {
  385. rules[widgetRuleKey].push(
  386. { required: true, message: widget.showName + '不能为空!', trigger: 'true' }
  387. )
  388. }
  389. // 其他验证
  390. if (Array.isArray(widget.column.ruleList)) {
  391. widget.column.ruleList.forEach(rule => {
  392. let ruleItem = this.buildRuleItem(widget, rule);
  393. if (ruleItem) rules[widgetRuleKey].push(ruleItem);
  394. });
  395. }
  396. }
  397. }
  398. },
  399. initWidgetRule (formConfig) {
  400. if (Array.isArray(formConfig.formWidgetList)) {
  401. let rules = {};
  402. formConfig.formWidgetList.forEach(widget => {
  403. this.buildWidgetRule(widget, rules);
  404. });
  405. this.$set(this, 'rules', rules);
  406. this.$nextTick(() => {
  407. if (this.$refs.form) this.$refs.form.clearValidate();
  408. });
  409. }
  410. },
  411. initFormDatasourceData (formConfig) {
  412. let that = this;
  413. function addFormDataByColumn (retObj, column, relation) {
  414. let fieldName = (relation ? relation.variableName + '__' : '') + column.columnName;
  415. if (retObj == null) retObj = {};
  416. if (formConfig.formType === that.SysOnlineFormType.QUERY) {
  417. if (retObj.formFilter == null) retObj.formFilter = {};
  418. if (retObj.formFilterCopy == null) retObj.formFilterCopy = {};
  419. retObj.formFilter[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
  420. retObj.formFilterCopy[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
  421. } else {
  422. retObj[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
  423. }
  424. return retObj;
  425. }
  426. // 设置数据源数据
  427. let datasourceFormData = {};
  428. if (this.masterTable) {
  429. // 添加表单主表的数据
  430. this.masterTable.columnList.forEach(column => {
  431. datasourceFormData = addFormDataByColumn(datasourceFormData, column, this.masterTable.relation);
  432. });
  433. // 如果表单主表是数据源主表,添加关联数据
  434. if (this.masterTable.relation == null) {
  435. let datasource = this.masterTable.datasource;
  436. if (datasource != null && Array.isArray(datasource.relationList)) {
  437. datasource.relationList.forEach(relation => {
  438. // 一对一关联从表数据
  439. if (relation.relationType === this.SysOnlineRelationType.ONE_TO_ONE) {
  440. let slaveTable = this.tableMap.get(relation.slaveTableId);
  441. if (slaveTable && Array.isArray(slaveTable.columnList)) {
  442. slaveTable.columnList.forEach(column => {
  443. datasourceFormData = addFormDataByColumn(datasourceFormData, column, relation);
  444. });
  445. }
  446. }
  447. });
  448. }
  449. }
  450. }
  451. this.$set(this, 'formData', datasourceFormData);
  452. },
  453. initWidgetLinkage (formConfig) {
  454. this.linkageMap.forEach((widgetList, key) => {
  455. let column = this.columnMap.get(key);
  456. let watchKey = null;
  457. if (formConfig.formType === this.SysOnlineFormType.QUERY) {
  458. watchKey = 'formData.formFilter.' + column.columnName;
  459. } else {
  460. watchKey = 'formData.' + column.columnName;
  461. }
  462. this.$watch(watchKey, (newValue) => {
  463. if (Array.isArray(widgetList)) {
  464. widgetList.forEach(widget => {
  465. if (Array.isArray(this.$refs[widget.variableName])) {
  466. this.$refs[widget.variableName].forEach(ref => {
  467. ref.reset();
  468. });
  469. } else {
  470. this.$refs[widget.variableName].reset();
  471. }
  472. });
  473. }
  474. });
  475. });
  476. },
  477. initFormData (formConfig) {
  478. this.masterTable = this.tableMap.get(formConfig.masterTableId);
  479. // 初始化表单数据
  480. this.initFormDatasourceData(formConfig);
  481. // 初始化表单组件
  482. this.initWidget(formConfig.formQueryTable, formConfig);
  483. this.initFormWidgetList(formConfig);
  484. // 初始化校验信息
  485. this.initWidgetRule(formConfig);
  486. },
  487. getParamValue (valueType, valueData) {
  488. switch (valueType) {
  489. case this.SysOnlineParamValueType.FORM_PARAM:
  490. return this.params ? this.params[valueData] : undefined;
  491. case this.SysOnlineParamValueType.TABLE_COLUMN:
  492. {
  493. let column = this.columnMap.get(valueData);
  494. let columnValue = null;
  495. if (this.formConfig.formType === this.SysOnlineFormType.QUERY) {
  496. columnValue = this.formData.formFilterCopy[column.columnName];
  497. } else {
  498. columnValue = this.formData[column.columnName];
  499. }
  500. if (column == null || columnValue == null || columnValue === '') {
  501. return null;
  502. } else {
  503. return columnValue;
  504. }
  505. }
  506. case this.SysOnlineParamValueType.STATIC_DICT:
  507. return Array.isArray(valueData) ? valueData[1] : undefined;
  508. case this.SysOnlineParamValueType.INPUT_VALUE:
  509. return valueData;
  510. }
  511. },
  512. getParamValueObj (paramName, valueType, valueData, retObj) {
  513. try {
  514. if (retObj == null) retObj = {};
  515. retObj[paramName] = this.getParamValue(valueType, valueData);
  516. if (retObj[paramName] == null) return null;
  517. return retObj;
  518. } catch (e) {
  519. console.log(e);
  520. }
  521. },
  522. clean () {
  523. this.datasourceMap = null;
  524. this.relationMap = null;
  525. this.tableMap = null;
  526. this.columnMap = null;
  527. this.dictMap = null;
  528. },
  529. loadAllDropdownData () {
  530. if (Array.isArray(this.dropdownWidgetList)) {
  531. this.dropdownWidgetList.forEach(dropdownWidget => {
  532. let dropdownWidgetImpl = this.$refs[dropdownWidget.variableName][0];
  533. if (dropdownWidgetImpl) {
  534. dropdownWidgetImpl.onVisibleChange();
  535. }
  536. });
  537. }
  538. },
  539. reload () {
  540. this.loadOnlineFormData().then(res => {
  541. this.isLoading = false;
  542. if (this.formConfig.formType === this.SysOnlineFormType.FORM) {
  543. if (Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.EDIT && this.saveOnClose === '1') {
  544. // 编辑操作页面,初始化页面数据
  545. let httpCall = null;
  546. if (this.saveOnClose === '0') {
  547. httpCall = Promise.resolve({
  548. data: this.params
  549. });
  550. } else {
  551. let params = {
  552. datasourceId: (this.masterTable.datasource || {}).datasourceId,
  553. relationId: (this.masterTable.relation || {}).relationId
  554. }
  555. for (let i = 0; i < this.masterTable.columnList.length; i++) {
  556. let column = this.masterTable.columnList[i];
  557. if (column.primaryKey) {
  558. params.dataId = this.params[column.columnName];
  559. break;
  560. }
  561. }
  562. if (params.relationId) {
  563. httpCall = this.doUrl('/admin/online/onlineOperation/viewByOneToManyRelationId/' + (this.masterTable.datasource || {}).variableName, 'get', params);
  564. } else {
  565. httpCall = this.doUrl('/admin/online/onlineOperation/viewByDatasourceId/' + (this.masterTable.datasource || {}).variableName, 'get', params);
  566. }
  567. }
  568. httpCall.then(res => {
  569. this.formData = {
  570. ...this.formData,
  571. ...res.data
  572. }
  573. this.loadAllDropdownData();
  574. // 初始化组件联动
  575. this.initWidgetLinkage(this.formConfig);
  576. }).catch(e => { });
  577. return;
  578. } else {
  579. if (this.rowData != null) {
  580. this.formData = {
  581. ...this.rowData
  582. }
  583. }
  584. }
  585. this.loadAllDropdownData();
  586. }
  587. setTimeout(() => {
  588. if (this.formConfig.formType === this.SysOnlineFormType.FLOW) {
  589. this.loadAllDropdownData();
  590. }
  591. // 初始化组件联动
  592. this.initWidgetLinkage(this.formConfig);
  593. this.onResume();
  594. this.$emit('ready');
  595. }, 30);
  596. }).catch(e => {
  597. console.log(e);
  598. });
  599. },
  600. onResume () { },
  601. getPrimaryKeyColumnParam (table, row) {
  602. if (table && Array.isArray(table.columnList)) {
  603. return table.columnList.reduce((retObj, column) => {
  604. let fieldName = (table.relation ? table.relation.variableName + '__' : '') + column.columnName;
  605. if (column.primaryKey) {
  606. retObj[column.columnName] = row ? row[fieldName] : undefined;
  607. }
  608. return retObj;
  609. }, {});
  610. }
  611. return null;
  612. },
  613. buildSubFormParams (operation, subFormInfo, row) {
  614. let subFormMasterTable = this.tableMap.get(subFormInfo.masterTableId);
  615. if (subFormMasterTable == null) return null;
  616. if (subFormMasterTable.relation == null) {
  617. // 下级表单操作的是主表数据的编辑
  618. if (operation.type === this.SysCustomWidgetOperationType.EDIT) {
  619. return this.getPrimaryKeyColumnParam(this.masterTable, row);
  620. } else {
  621. return null;
  622. }
  623. } else {
  624. // 下级表单操作的是从表
  625. if (subFormInfo.formType === this.SysOnlineFormType.QUERY) {
  626. // 从表的查询页面,参数为主表主键
  627. return this.getPrimaryKeyColumnParam(this.masterTable, row);
  628. } else {
  629. if (operation.type === this.SysCustomWidgetOperationType.EDIT) {
  630. // 从表的编辑页面
  631. if (this.formConfig.formType === this.SysOnlineFormType.FORM &&
  632. Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD) {
  633. return {
  634. ...row
  635. }
  636. } else {
  637. return this.getPrimaryKeyColumnParam(subFormMasterTable, row);
  638. }
  639. } else {
  640. // 从表的添加页面
  641. return {
  642. ...this.params
  643. }
  644. }
  645. }
  646. }
  647. },
  648. async handlerOperation (operation, row, widget) {
  649. if (this.preview()) return;
  650. if (operation.formId != null) {
  651. OnlineFormController.view(this, {
  652. formId: operation.formId
  653. }).then(res => {
  654. let formInfo = res.data;
  655. if (formInfo != null) {
  656. let params = this.buildSubFormParams(operation, formInfo, row);
  657. if (formInfo.formKind === this.SysOnlineFormKind.DIALOG) {
  658. let formJsonData = JSON.parse(formInfo.widgetJson);
  659. let area = (formInfo.height != null) ? [(formJsonData.formConfig.width || 800) + 'px', formJsonData.formConfig.height + 'px'] : (formJsonData.formConfig.width || 800) + 'px';
  660. this.$dialog.show(operation.name, OnlineForm, {
  661. area: area,
  662. offset: '100px'
  663. }, {
  664. flowData: this.flowData,
  665. formId: formInfo.formId,
  666. formType: formInfo.formType,
  667. operationType: operation.type,
  668. params,
  669. saveOnClose: (
  670. formInfo.formType === this.SysOnlineFormType.FLOW || this.formConfig.formType === this.SysOnlineFormType.FLOW ||
  671. (
  672. formInfo.formType === this.SysOnlineFormType.FORM &&
  673. Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD
  674. )
  675. ) ? '0' : '1',
  676. rowData: row
  677. }).then(res => {
  678. let widgetObj = this.$refs[widget.variableName];
  679. if (Array.isArray(widgetObj)) {
  680. widgetObj.forEach(item => {
  681. item.refresh(res, operation.type);
  682. });
  683. } else {
  684. widgetObj.refresh(res, operation.type);
  685. }
  686. }).catch(e => {
  687. });
  688. } else {
  689. if (this.formConfig.formType === this.SysOnlineFormType.QUERY) {
  690. let tableWidget = this.$refs[this.formConfig.formQueryTable.variableName].getTableWidget();
  691. this.addOnlineFormCache({
  692. key: this.$route.fullPath,
  693. value: {
  694. formFilter: { ...this.formData.formFilter },
  695. formFilterCopy: { ...this.formData.formFilterCopy },
  696. tableImpl: {
  697. totalCount: tableWidget.totalCount,
  698. currentPage: tableWidget.currentPage,
  699. pageSize: tableWidget.pageSize
  700. }
  701. }
  702. });
  703. }
  704. this.$router.push({
  705. name: 'onlineForm',
  706. query: {
  707. flowData: this.flowData,
  708. formId: formInfo.formId,
  709. formType: formInfo.formType,
  710. closeVisible: '1',
  711. operationType: operation.type,
  712. params,
  713. saveOnClose: (
  714. formInfo.formType === this.SysOnlineFormType.FLOW || this.formConfig.formType === this.SysOnlineFormType.FLOW ||
  715. (
  716. formInfo.formType === this.SysOnlineFormType.FORM &&
  717. Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD
  718. )
  719. ) ? '0' : '1',
  720. rowData: row
  721. }
  722. })
  723. }
  724. }
  725. }).catch(e => { });
  726. } else {
  727. if (operation.type === this.SysCustomWidgetOperationType.DELETE) {
  728. this.$confirm('是否删除当前数据?').then(res => {
  729. if (this.formConfig.formType !== this.SysOnlineFormType.FLOW &&
  730. (this.formConfig.formType !== this.SysOnlineFormType.FORM || Number.parseInt(this.operationType) !== this.SysCustomWidgetOperationType.ADD)) {
  731. let params = {
  732. datasourceId: (widget.table.datasource || {}).datasourceId,
  733. relationId: (widget.table.relation || {}).relationId
  734. }
  735. for (let i = 0; i < widget.table.columnList.length; i++) {
  736. let column = widget.table.columnList[i];
  737. if (column.primaryKey) {
  738. let fieldName = (widget.table.relation ? widget.table.relation.variableName + '__' : '') + column.columnName;
  739. params.dataId = row[fieldName];
  740. break;
  741. }
  742. }
  743. let httpCall = null;
  744. if (params.relationId) {
  745. httpCall = this.doUrl('/admin/online/onlineOperation/deleteOneToManyRelation/' + widget.datasource.variableName, 'post', params);
  746. } else {
  747. httpCall = this.doUrl('/admin/online/onlineOperation/deleteDatasource/' + widget.datasource.variableName, 'post', params);
  748. }
  749. httpCall.then(res => {
  750. this.$message.success('删除成功!');
  751. let widgetObj = this.$refs[widget.variableName];
  752. if (Array.isArray(widgetObj)) {
  753. widgetObj.forEach(item => {
  754. item.refresh(res, operation.type);
  755. });
  756. } else {
  757. widgetObj.refresh(res, operation.type);
  758. }
  759. }).catch(e => {
  760. });
  761. } else {
  762. let widgetObj = this.$refs[widget.variableName];
  763. if (Array.isArray(widgetObj)) {
  764. widgetObj.forEach(item => {
  765. item.refresh(row, operation.type);
  766. });
  767. } else {
  768. widgetObj.refresh(row, operation.type);
  769. }
  770. }
  771. }).catch(e => { });
  772. } else if (operation.type === this.SysCustomWidgetOperationType.EXPORT) {
  773. console.log('this.formId :>> ', this.formId);
  774. if (this.formId == 1657932361767063552) {
  775. let fileInfoStr = row.component_movementjson;
  776. if (fileInfoStr != undefined) {
  777. let fileInfoArr = JSON.parse(fileInfoStr);
  778. let fileInfo = fileInfoArr[0]; // 假设只有一个文件
  779. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/mainUnit', {
  780. params: {
  781. datasourceId: '1657931215497334784',
  782. fieldName: 'component_movementjson',
  783. asImage: false,
  784. dataId: row.id,
  785. filename: fileInfo.filename,
  786. Authorization: getToken(),
  787. MenuId: '1657932967709773824'
  788. }
  789. })
  790. .then(response => {
  791. // 处理成功的响应
  792. this.component_movementjson = response.data;
  793. })
  794. .catch(error => {
  795. // 处理错误
  796. console.error(error);
  797. });
  798. }
  799. fileInfoStr = row.components_json;
  800. let fileInfoArr1 = JSON.parse(fileInfoStr);
  801. let fileInfo1 = fileInfoArr1[0]; // 假设只有一个文件
  802. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/mainUnit', {
  803. params: {
  804. datasourceId: '1657931215497334784',
  805. fieldName: 'components_json',
  806. asImage: false,
  807. dataId: row.id,
  808. filename: fileInfo1.filename,
  809. Authorization: getToken(),
  810. MenuId: '1657932967709773824'
  811. }
  812. })
  813. .then(response => {
  814. // 处理成功的响应
  815. this.components_json = response.data;
  816. })
  817. .catch(error => {
  818. // 处理错误
  819. console.error(error);
  820. });
  821. const data = {
  822. id: row.id,
  823. name: row.name,
  824. type: row.type,
  825. creator: row.creator,
  826. createtime: row.createtime,
  827. belong: row.belong,
  828. health: row.health,
  829. target: row.target,
  830. team: row.team,
  831. task: row.task,
  832. pos: {
  833. lat: row.lat,
  834. lon: row.lon,
  835. height: row.height
  836. },
  837. component_movementid: row.component_movementid,
  838. component_movementjson: this.component_movementjson,
  839. components_cnt: row.components_cnt,
  840. components_ids: row.components_ids,
  841. components_json: this.components_json
  842. };
  843. const jsonData = JSON.stringify(data);
  844. const blob = new Blob([jsonData], { type: 'application/json' });
  845. const url = URL.createObjectURL(blob);
  846. const link = document.createElement('a');
  847. link.href = url;
  848. link.download = data.name + '.json';
  849. document.body.appendChild(link);
  850. link.click();
  851. document.body.removeChild(link);
  852. } else if (this.formId == 1675055217952952320) {
  853. console.log('row :>> ', row);
  854. let number = row.number
  855. const data = {};
  856. data[number] = {
  857. type: row.type,
  858. properties: {
  859. id: row.id,
  860. lon: row.lon,
  861. lat: row.lat,
  862. h: row.h,
  863. picture: row.picture
  864. }
  865. }
  866. const jsonData = JSON.stringify(data);
  867. const blob = new Blob([jsonData], { type: 'application/json' });
  868. const url = URL.createObjectURL(blob);
  869. const link = document.createElement('a');
  870. link.href = url;
  871. link.download = '指挥中心-' + row.number + '.json';
  872. document.body.appendChild(link);
  873. link.click();
  874. document.body.removeChild(link);
  875. } else if (this.formId == 1675055674104483840) {
  876. console.log('row :>> ', row);
  877. let name = row.name
  878. const data = {};
  879. data[name] = {
  880. id: row.id,
  881. name: row.name,
  882. BW: row.BW,
  883. PW: row.PW,
  884. fc: row.fc,
  885. fs: row.fs,
  886. h: row.h,
  887. lat: row.lat,
  888. lon: row.lon,
  889. modulation: row.modulation,
  890. prf: row.prf,
  891. prf_mode: row.prf_mode,
  892. type: row.type,
  893. style: row.style,
  894. url: row.url,
  895. picture: row.picture
  896. }
  897. const jsonData = JSON.stringify(data);
  898. const blob = new Blob([jsonData], { type: 'application/json' });
  899. const url = URL.createObjectURL(blob);
  900. const link = document.createElement('a');
  901. link.href = url;
  902. link.download = '末端拦截-' + row.name + '.json';
  903. document.body.appendChild(link);
  904. link.click();
  905. document.body.removeChild(link);
  906. } else if (this.formId == 1675056214280507392) {
  907. let number = row.number
  908. const data = {};
  909. data[number] = {
  910. type: row.type,
  911. properties: {
  912. id: row.id,
  913. CSV_starttime: row.CSV_starttime,
  914. CSV_endtime: row.CSV_endtime,
  915. CSV_path: row.CSV_path,
  916. CSV_sampletime: row.CSV_sampletime,
  917. TLE_Propagator: row.TLE_Propagator,
  918. common_RAAN: row.common_RAAN,
  919. common_argofperiapsis: row.common_argofperiapsis,
  920. common_eccentricity: row.common_eccentricity,
  921. common_inclination: row.common_inclination,
  922. common_semiMajorAxis: row.common_semiMajorAxis,
  923. common_trueanomaly: row.common_trueanomaly,
  924. config_type: row.config_type,
  925. mark: row.mark,
  926. picture: row.picture
  927. }
  928. }
  929. const jsonData = JSON.stringify(data);
  930. const blob = new Blob([jsonData], { type: 'application/json' });
  931. const url = URL.createObjectURL(blob);
  932. const link = document.createElement('a');
  933. link.href = url;
  934. link.download = '预警卫星-' + row.number + '.json';
  935. document.body.appendChild(link);
  936. link.click();
  937. document.body.removeChild(link);
  938. } else if (this.formId == 1675048581024714752) {
  939. console.log('row :>> ', row);
  940. let number = row.number
  941. const data = {};
  942. data[number] = {
  943. type: row.type,
  944. properties: {
  945. id: row.id,
  946. launch_lon: row.launch_lon,
  947. launch_lat: row.launch_lat,
  948. launch_h: row.launch_h,
  949. target_lon: row.target_lon,
  950. target_lat: row.target_lat,
  951. target_h: row.target_h,
  952. apogee_height: row.apogee_height,
  953. fly_time: row.fly_time,
  954. filepath: row.filepath,
  955. acceleration: row.acceleration
  956. }
  957. }
  958. const jsonData = JSON.stringify(data);
  959. const blob = new Blob([jsonData], { type: 'application/json' });
  960. const url = URL.createObjectURL(blob);
  961. const link = document.createElement('a');
  962. link.href = url;
  963. link.download = '弹道导弹-' + row.number + '.json';
  964. document.body.appendChild(link);
  965. link.click();
  966. document.body.removeChild(link);
  967. } else if (this.formId == 1674960384441716736) {
  968. let number = row.number
  969. const data = {};
  970. data[number] = {
  971. type: row.type,
  972. properties: {
  973. id: row.id,
  974. N: row.N,
  975. f0: row.fo,
  976. number: row.number,
  977. tau: row.tau,
  978. tr: row.tr,
  979. ts: row.ts,
  980. url: row.url,
  981. method: row.method
  982. }
  983. }
  984. const jsonData = JSON.stringify(data);
  985. const blob = new Blob([jsonData], { type: 'application/json' });
  986. const url = URL.createObjectURL(blob);
  987. const link = document.createElement('a');
  988. link.href = url;
  989. link.download = '干扰雷达-' + row.number + '.json';
  990. document.body.appendChild(link);
  991. link.click();
  992. document.body.removeChild(link);
  993. } else if (this.formId == 1674971627114205184) {
  994. console.log('row :>> ', row);
  995. let number = row.number
  996. const data = {};
  997. data[number] = {
  998. type: row.type,
  999. creator: row.creator,
  1000. properties: {
  1001. id: row.id,
  1002. f0: row.fo,
  1003. number: row.number,
  1004. tau: row.tau,
  1005. k: row.k,
  1006. time: row.time,
  1007. tr: row.tr,
  1008. t_r: row.t_r,
  1009. ts: row.ts,
  1010. url: row.url,
  1011. method: row.method
  1012. }
  1013. }
  1014. const jsonData = JSON.stringify(data);
  1015. const blob = new Blob([jsonData], { type: 'application/json' });
  1016. const url = URL.createObjectURL(blob);
  1017. const link = document.createElement('a');
  1018. link.href = url;
  1019. link.download = '诱饵雷达-' + row.number + '.json';
  1020. document.body.appendChild(link);
  1021. link.click();
  1022. document.body.removeChild(link);
  1023. } else {
  1024. // todo 场景想定json导出
  1025. let fileInfoStr = row.blueunit;
  1026. let fileInfoArr = JSON.parse(fileInfoStr);
  1027. let fileInfo = fileInfoArr[0]; // 假设只有一个文件
  1028. for (let i = 0; i < fileInfoArr.length; i++) {
  1029. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
  1030. params: {
  1031. datasourceId: '1656243335922192384',
  1032. fieldName: 'blueunit',
  1033. asImage: false,
  1034. dataId: row.id,
  1035. filename: fileInfoArr[i].filename,
  1036. Authorization: getToken(),
  1037. MenuId: '1656244747347431424'
  1038. }
  1039. })
  1040. .then(response => {
  1041. // 处理成功的响应
  1042. this.blueunit.push(response.data);
  1043. })
  1044. .catch(error => {
  1045. // 处理错误
  1046. console.error(error);
  1047. });
  1048. }
  1049. fileInfoStr = row.redunit;
  1050. fileInfoArr = JSON.parse(fileInfoStr);
  1051. for (let i = 0; i < fileInfoArr.length; i++) {
  1052. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
  1053. params: {
  1054. datasourceId: '1656243335922192384',
  1055. fieldName: 'redunit',
  1056. asImage: false,
  1057. dataId: row.id,
  1058. filename: fileInfoArr[i].filename,
  1059. Authorization: getToken(),
  1060. MenuId: '1656244747347431424'
  1061. }
  1062. })
  1063. .then(response => {
  1064. // 处理成功的响应
  1065. this.redunit.push(response.data);
  1066. })
  1067. .catch(error => {
  1068. // 处理错误
  1069. console.error(error);
  1070. });
  1071. }
  1072. fileInfoStr = row.center;
  1073. fileInfoArr = JSON.parse(fileInfoStr);
  1074. for (let i = 0; i < fileInfoArr.length; i++) {
  1075. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
  1076. params: {
  1077. datasourceId: '1656243335922192384',
  1078. fieldName: 'center',
  1079. asImage: false,
  1080. dataId: row.id,
  1081. filename: fileInfoArr[i].filename,
  1082. Authorization: getToken(),
  1083. MenuId: '1656244747347431424'
  1084. }
  1085. })
  1086. .then(response => {
  1087. // 处理成功的响应
  1088. this.center.push(response.data);
  1089. })
  1090. .catch(error => {
  1091. // 处理错误
  1092. console.error(error);
  1093. });
  1094. }
  1095. fileInfoStr = row.satellite;
  1096. fileInfoArr = JSON.parse(fileInfoStr);
  1097. for (let i = 0; i < fileInfoArr.length; i++) {
  1098. await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
  1099. params: {
  1100. datasourceId: '1656243335922192384',
  1101. fieldName: 'satellite',
  1102. asImage: false,
  1103. dataId: row.id,
  1104. filename: fileInfoArr[i].filename,
  1105. Authorization: getToken(),
  1106. MenuId: '1656244747347431424'
  1107. }
  1108. })
  1109. .then(response => {
  1110. // 处理成功的响应
  1111. this.satellite.push(response.data);
  1112. })
  1113. .catch(error => {
  1114. // 处理错误
  1115. console.error(error);
  1116. });
  1117. }
  1118. const data = {
  1119. id: row.id,
  1120. xdname: row.xdname,
  1121. type: row.type,
  1122. creator: row.creator,
  1123. createtime: row.createtime,
  1124. bluecnt: row.bluecnt,
  1125. target: row.target,
  1126. starttime: row.starttime,
  1127. steptime: row.steptime,
  1128. blueunit: this.blueunit,
  1129. redunit: this.redunit,
  1130. satellite: this.satellite,
  1131. center: this.center
  1132. };
  1133. const jsonData = JSON.stringify(data);
  1134. const blob = new Blob([jsonData], { type: 'application/json' });
  1135. const url = URL.createObjectURL(blob);
  1136. const link = document.createElement('a');
  1137. link.href = url;
  1138. link.download = data.xdname + '.json';
  1139. document.body.appendChild(link);
  1140. link.click();
  1141. document.body.removeChild(link);
  1142. }
  1143. }
  1144. httpCall.then(res => {
  1145. this.formData = {
  1146. ...this.formData,
  1147. ...res.data
  1148. }
  1149. })
  1150. }
  1151. },
  1152. getRelationTableData (tableWidget) {
  1153. if (tableWidget.widgetType === this.SysCustomWidgetType.Table) {
  1154. let table = tableWidget.table;
  1155. let temp = this.$refs[tableWidget.variableName];
  1156. if (table != null && table.relation != null && Array.isArray(table.columnList) && temp != null) {
  1157. let tableWidgetImpl = temp[0] || temp;
  1158. return tableWidgetImpl.getTableWidget().dataList.map(data => {
  1159. return table.columnList.reduce((retObj, column) => {
  1160. let fieldName = (table.relation ? table.relation.variableName + '__' : '') + column.columnName;
  1161. retObj[column.columnName] = data[fieldName];
  1162. return retObj
  1163. }, {});
  1164. });
  1165. }
  1166. }
  1167. return null;
  1168. },
  1169. getWidgetPrimaryColumnId (widget) {
  1170. let columnList = null;
  1171. if (widget.relationId == null) {
  1172. columnList = widget.datasource.masterTable.columnList;
  1173. } else {
  1174. columnList = widget.relation.slaveTable.columnList;
  1175. }
  1176. if (Array.isArray(columnList)) {
  1177. for (let i = 0; i < columnList.length; i++) {
  1178. let column = columnList[i];
  1179. if (column.primaryKey) {
  1180. let columnName = column.columnName;
  1181. if (widget.relation != null) columnName = widget.relation.variableName + '__' + columnName;
  1182. return this.formData[columnName];
  1183. }
  1184. }
  1185. }
  1186. },
  1187. ...mapMutations(['addOnlineFormCache'])
  1188. },
  1189. created () {
  1190. this.reload();
  1191. },
  1192. destoryed () {
  1193. this.clean();
  1194. },
  1195. watch: {
  1196. formId: {
  1197. handler (newValue) {
  1198. this.reload();
  1199. }
  1200. }
  1201. }
  1202. }
  1203. export {
  1204. OnlineFormMixins
  1205. }