123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233 |
- import { mapMutations } from 'vuex';
- import * as StaticDict from '@/staticDict';
- import { getToken } from '@/utils';
- import rules from '@/utils/validate.js';
- import { getOperationPermCode } from '../utils/index.js';
- import OnlineForm from '@/views/onlineForm/index.vue';
- import {
- OnlineFormController
- } from '@/api/onlineController.js';
- import axios from 'axios';
- import { uploadMixin } from '@/core/mixins';
- const OnlineFormMixins = {
- props: {
- formId: {
- type: String,
- required: true
- },
- readOnly: {
- type: Boolean,
- default: false
- },
- closeVisible: {
- type: String,
- default: '0'
- },
- params: {
- type: Object
- }
- },
- mixins: [uploadMixin],
- data () {
- return {
- isLoading: true,
- formData: {},
- rules: {},
- components_json: {},
- blueunit: [],
- redunit: [],
- center: [],
- satellite: [],
- component_movementjson: {},
- formConfig: {
- formType: undefined,
- formKind: undefined,
- gutter: 20,
- labelPosition: 'right',
- labelWidth: 120,
- width: undefined,
- height: undefined,
- formWidgetList: [],
- formQueryTable: undefined
- },
- masterTable: undefined,
- errorMessage: [],
- tableWidgetList: [],
- dropdownWidgetList: [],
- richEditWidgetList: [],
- datasourceMap: new Map(),
- relationMap: new Map(),
- tableMap: new Map(),
- columnMap: new Map(),
- dictMap: new Map(),
- linkageMap: new Map()
- }
- },
- methods: {
- getFormData () {
- return this.formData;
- },
- getPermCode (widget, operation) {
- return getOperationPermCode(widget, operation);
- },
- loadOnlineFormData () {
- return new Promise((resolve, reject) => {
- OnlineFormController.render(this, {
- formId: this.formId
- }).then(res => {
- let onlineForm = res.data.onlineForm;
- let formConfigData = JSON.parse(onlineForm.widgetJson);
- let formConfig = {
- formName: onlineForm.formName,
- formType: onlineForm.formType,
- formKind: onlineForm.formKind,
- masterTableId: onlineForm.masterTableId,
- labelWidth: formConfigData.formConfig.labelWidth,
- labelPosition: formConfigData.formConfig.labelPosition,
- gutter: formConfigData.formConfig.gutter,
- height: formConfigData.formConfig.height,
- width: formConfigData.formConfig.width,
- formWidgetList: formConfigData.widgetList,
- formQueryTable: formConfigData.formConfig.tableWidget
- }
- onlineForm = null;
- res.data.onlineForm = null;
- // 字典
- if (Array.isArray(res.data.onlineDictList)) {
- res.data.onlineDictList.forEach(dict => {
- this.dictMap.set(dict.dictId, dict);
- });
- }
- res.data.onlineDictList = null;
- // 数据表
- if (Array.isArray(res.data.onlineTableList)) {
- res.data.onlineTableList.forEach(table => {
- this.tableMap.set(table.tableId, table);
- });
- }
- res.data.onlineTableList = null;
- // 字段
- if (Array.isArray(res.data.onlineColumnList)) {
- res.data.onlineColumnList.forEach(column => {
- if (column.dictId != null) {
- column.dictInfo = this.dictMap.get(column.dictId);
- }
- let table = this.tableMap.get(column.tableId);
- if (table) {
- if (!Array.isArray(table.columnList)) table.columnList = [];
- table.columnList.push(column);
- }
- this.columnMap.set(column.columnId, column);
- });
- }
- res.data.onlineColumnList = null;
- // 虚拟字段
- if (Array.isArray(res.data.onlineVirtualColumnList)) {
- res.data.onlineVirtualColumnList.forEach(column => {
- column.columnId = column.virtualColumnId;
- column.columnComment = column.columnPrompt;
- column.columnName = column.objectFieldName;
- column.primaryKey = false;
- column.isVirtualColumn = true;
- this.columnMap.set(column.columnId, column);
- });
- }
- res.data.onlineVirtualColumnList = null;
- // 数据源
- if (Array.isArray(res.data.onlineDatasourceList)) {
- res.data.onlineDatasourceList.forEach(datasource => {
- datasource.masterTable = this.tableMap.get(datasource.masterTableId);
- if (datasource.masterTable) datasource.masterTable.datasource = datasource;
- this.datasourceMap.set(datasource.datasourceId, datasource);
- });
- }
- res.data.onlineDatasourceList = null;
- // 关联
- if (Array.isArray(res.data.onlineDatasourceRelationList)) {
- res.data.onlineDatasourceRelationList.forEach(relation => {
- let datasource = this.datasourceMap.get(relation.datasourceId);
- if (datasource) {
- if (!Array.isArray(datasource.relationList)) datasource.relationList = [];
- datasource.relationList.push(relation);
- }
- relation.masterColumn = this.columnMap.get(relation.masterColumnId);
- relation.slaveTable = this.tableMap.get(relation.slaveTableId);
- if (relation.slaveTable) {
- relation.slaveTable.relation = relation;
- relation.slaveTable.datasource = datasource;
- }
- relation.slaveColumn = this.columnMap.get(relation.slaveColumnId);
- this.relationMap.set(relation.relationId, relation);
- });
- }
- res.data.onlineDatasourceRelationList = null;
- // 校验规则
- if (Array.isArray(res.data.onlineColumnRuleList)) {
- res.data.onlineColumnRuleList.forEach(rule => {
- let column = this.columnMap.get(rule.columnId);
- if (column) {
- if (!Array.isArray(column.ruleList)) column.ruleList = [];
- column.ruleList.push(rule);
- }
- });
- }
- res.data.onlineColumnRuleList = null;
- this.initFormData(formConfig);
- this.formConfig = formConfig;
- resolve();
- }).catch(e => {
- reject(e);
- });
- });
- },
- initWidget (widget, formConfig) {
- if (widget != null) {
- if (widget.datasourceId) widget.datasource = this.datasourceMap.get(widget.datasourceId);
- if (widget.relationId) {
- widget.relation = this.relationMap.get(widget.relationId);
- if (widget.datasource == null && widget.relation != null) {
- widget.datasource = this.datasourceMap.get(widget.relation.datasourceId);
- }
- }
- if (widget.datasource == null) {
- widget.datasource = {
- masterTable: {}
- }
- widget.column = {}
- }
- if (widget.tableId) widget.table = this.tableMap.get(widget.tableId);
- if (widget.columnId) widget.column = this.columnMap.get(widget.columnId);
- if (widget.widgetType === this.SysCustomWidgetType.RichEditor) {
- this.richEditWidgetList.push(widget);
- }
- // 初始化组件下拉字典参数
- if (Array.isArray(widget.dictParamList)) {
- widget.dictParamList.forEach(param => {
- if (param.dictValueType === this.SysOnlineParamValueType.STATIC_DICT) {
- let errorItem = null;
- if (Array.isArray(param.dictValue) && param.dictValue.length === 2) {
- let staticDict = StaticDict[param.dictValue[0]];
- if (staticDict == null) {
- errorItem = {
- widget: widget,
- message: '组件字典参数' + param.dictParamName + '绑定的静态字典 [' + param.dictValue[0] + '] 并不存在!'
- }
- } else {
- if (staticDict.getValue(param.dictValue[1]) == null) {
- errorItem = {
- widget: widget,
- message: '组件字典参数' + param.dictParamName + '绑定的静态字典值并不属于静态字段 [' + param.dictValue[0] + '] !'
- }
- }
- }
- } else {
- errorItem = {
- widget: widget,
- message: '组件字典参数' + param.dictParamName + '绑定的静态字典错误!'
- }
- }
- if (errorItem != null) this.errorMessage.push(errorItem);
- }
- });
- }
- if (widget.column && widget.column.dictInfo != null) {
- this.dropdownWidgetList.push(widget);
- }
- // 初始化表格列
- if (widget.widgetType === this.SysCustomWidgetType.Table) {
- // 寻找表格主键
- widget.primaryColumnName = undefined;
- if (widget.table && Array.isArray(widget.table.columnList)) {
- for (let i = 0; i < widget.table.columnList.length; i++) {
- if (widget.table.columnList[i].primaryKey) {
- widget.primaryColumnName = widget.table.columnList[i].columnName;
- break;
- }
- }
- }
- if (Array.isArray(widget.tableColumnList)) {
- widget.tableColumnList.forEach(tableColumn => {
- tableColumn.table = this.tableMap.get(tableColumn.tableId);
- tableColumn.column = this.columnMap.get(tableColumn.columnId);
- tableColumn.relation = this.relationMap.get(tableColumn.relationId);
- if (tableColumn.table == null || tableColumn.column == null) {
- this.errorMessage.push({
- widget: widget,
- message: '表格列 [' + tableColumn.showName + '] 绑定的字段不存在!'
- });
- }
- });
- }
- if (Array.isArray(widget.queryParamList)) {
- widget.queryParamList.forEach(param => {
- param.table = this.tableMap.get(param.tableId);
- param.column = this.columnMap.get(param.columnId);
- param.relation = this.relationMap.get(param.relationId);
- if (param.table == null || param.column == null) {
- this.errorMessage.push({
- widget: widget,
- message: '表格查询参数不存在!'
- });
- }
- });
- }
- this.tableWidgetList.push(widget);
- }
- while (widget.datasourceId != null || widget.relationId != null) {
- if (widget.datasourceId == null && widget.relation == null) {
- let errorItem = {
- widget: widget,
- message: '组件绑定字段所属' + (widget.datasourceId ? '数据源' : '关联') + '不存在!'
- }
- this.errorMessage.push(errorItem);
- break;
- }
- if (widget.table == null) {
- let errorItem = {
- widget: widget,
- messagre: '组件绑定字段所属数据表不存在!'
- }
- this.errorMessage.push(errorItem);
- break;
- }
- if (widget.column == null && widget.columnId != null) {
- let errorItem = {
- widget: widget,
- messagre: '组件绑定字段不存在!'
- }
- this.errorMessage.push(errorItem);
- break;
- }
- if (widget.column) {
- let table = this.tableMap.get(widget.tableId);
- if (table.tableId !== widget.table.tableId) {
- let errorItem = {
- widget: widget,
- messagre: '组件绑定字段不属于选张的数据表!'
- }
- this.errorMessage.push(errorItem);
- break;
- }
- }
- break;
- }
- if (Array.isArray(widget.childWidgetList)) {
- widget.childWidgetList.forEach(subWidget => {
- if (formConfig.formType === this.SysOnlineFormType.FLOW && this.formReadOnly) {
- subWidget.readOnly = true;
- }
- this.initWidget(subWidget, formConfig);
- })
- }
- if (widget.column && widget.column.dictInfo) {
- if (Array.isArray(widget.dictParamList)) {
- widget.dictParamList.forEach(dictParam => {
- if (dictParam.dictValueType === this.SysOnlineParamValueType.TABLE_COLUMN) {
- let linkageItem = this.linkageMap.get(dictParam.dictValue);
- if (linkageItem == null) {
- linkageItem = [];
- this.linkageMap.set(dictParam.dictValue, linkageItem);
- }
- linkageItem.push(widget);
- }
- });
- }
- }
- }
- },
- initFormWidgetList (formConfig) {
- this.errorMessage = [];
- if (Array.isArray(formConfig.formWidgetList)) {
- formConfig.formWidgetList.forEach(widget => {
- if (formConfig.formType === this.SysOnlineFormType.FLOW && this.formReadOnly) {
- widget.readOnly = true;
- }
- this.initWidget(widget, formConfig);
- });
- }
- if (this.errorMessage.length > 0) {
- console.error(this.errorMessage);
- }
- },
- buildRuleItem (widget, rule) {
- if (rule.propDataJson) rule.data = JSON.parse(rule.propDataJson);
- if (widget != null && rule != null) {
- switch (rule.onlineRule.ruleType) {
- case this.SysOnlineRuleType.INTEGER_ONLY:
- return { type: 'integer', message: rule.data.message, trigger: 'blur', transform: (value) => Number(value) };
- case this.SysOnlineRuleType.DIGITAL_ONLY:
- return { type: 'number', message: rule.data.message, trigger: 'blur', transform: (value) => Number(value) };
- case this.SysOnlineRuleType.LETTER_ONLY:
- return { type: 'string', pattern: rules.pattern.english, message: rule.data.message, trigger: 'blur' };
- case this.SysOnlineRuleType.EMAIL:
- return { type: 'email', message: rule.data.message, trigger: 'blur' };
- case this.SysOnlineRuleType.MOBILE:
- return { type: 'string', pattern: rules.pattern.mobie, message: rule.data.message, trigger: 'blur' };
- case this.SysOnlineRuleType.RANGE:
- if (widget.column) {
- let isNumber = ['Boolean', 'Date', 'String'].indexOf(widget.column.objectFieldType) === -1;
- return { type: isNumber ? 'number' : 'string', min: rule.data.min, max: rule.data.max, message: rule.data.message, trigger: 'blur' };
- }
- break;
- case this.SysOnlineRuleType.CUSTOM:
- return { type: 'string', pattern: new RegExp(rule.data.pattern), message: rule.data.message, trigger: 'blur' };
- }
- }
- },
- buildWidgetRule (widget, rules) {
- if (widget != null && widget.column != null) {
- let widgetRuleKey = (widget.relation ? widget.relation.variableName + '__' : '') + widget.column.columnName;
- // 必填字段以及设置了验证规则的字段
- if (!widget.column.nullable || Array.isArray(widget.column.ruleList)) {
- rules[widgetRuleKey] = [];
- // 必填验证
- if (!widget.column.nullable) {
- rules[widgetRuleKey].push(
- { required: true, message: widget.showName + '不能为空!', trigger: 'true' }
- )
- }
- // 其他验证
- if (Array.isArray(widget.column.ruleList)) {
- widget.column.ruleList.forEach(rule => {
- let ruleItem = this.buildRuleItem(widget, rule);
- if (ruleItem) rules[widgetRuleKey].push(ruleItem);
- });
- }
- }
- }
- },
- initWidgetRule (formConfig) {
- if (Array.isArray(formConfig.formWidgetList)) {
- let rules = {};
- formConfig.formWidgetList.forEach(widget => {
- this.buildWidgetRule(widget, rules);
- });
- this.$set(this, 'rules', rules);
- this.$nextTick(() => {
- if (this.$refs.form) this.$refs.form.clearValidate();
- });
- }
- },
- initFormDatasourceData (formConfig) {
- let that = this;
- function addFormDataByColumn (retObj, column, relation) {
- let fieldName = (relation ? relation.variableName + '__' : '') + column.columnName;
- if (retObj == null) retObj = {};
- if (formConfig.formType === that.SysOnlineFormType.QUERY) {
- if (retObj.formFilter == null) retObj.formFilter = {};
- if (retObj.formFilterCopy == null) retObj.formFilterCopy = {};
- retObj.formFilter[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
- retObj.formFilterCopy[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
- } else {
- retObj[fieldName] = column.objectFieldType === 'Boolean' ? false : undefined;
- }
- return retObj;
- }
- // 设置数据源数据
- let datasourceFormData = {};
- if (this.masterTable) {
- // 添加表单主表的数据
- this.masterTable.columnList.forEach(column => {
- datasourceFormData = addFormDataByColumn(datasourceFormData, column, this.masterTable.relation);
- });
- // 如果表单主表是数据源主表,添加关联数据
- if (this.masterTable.relation == null) {
- let datasource = this.masterTable.datasource;
- if (datasource != null && Array.isArray(datasource.relationList)) {
- datasource.relationList.forEach(relation => {
- // 一对一关联从表数据
- if (relation.relationType === this.SysOnlineRelationType.ONE_TO_ONE) {
- let slaveTable = this.tableMap.get(relation.slaveTableId);
- if (slaveTable && Array.isArray(slaveTable.columnList)) {
- slaveTable.columnList.forEach(column => {
- datasourceFormData = addFormDataByColumn(datasourceFormData, column, relation);
- });
- }
- }
- });
- }
- }
- }
- this.$set(this, 'formData', datasourceFormData);
- },
- initWidgetLinkage (formConfig) {
- this.linkageMap.forEach((widgetList, key) => {
- let column = this.columnMap.get(key);
- let watchKey = null;
- if (formConfig.formType === this.SysOnlineFormType.QUERY) {
- watchKey = 'formData.formFilter.' + column.columnName;
- } else {
- watchKey = 'formData.' + column.columnName;
- }
- this.$watch(watchKey, (newValue) => {
- if (Array.isArray(widgetList)) {
- widgetList.forEach(widget => {
- if (Array.isArray(this.$refs[widget.variableName])) {
- this.$refs[widget.variableName].forEach(ref => {
- ref.reset();
- });
- } else {
- this.$refs[widget.variableName].reset();
- }
- });
- }
- });
- });
- },
- initFormData (formConfig) {
- this.masterTable = this.tableMap.get(formConfig.masterTableId);
- // 初始化表单数据
- this.initFormDatasourceData(formConfig);
- // 初始化表单组件
- this.initWidget(formConfig.formQueryTable, formConfig);
- this.initFormWidgetList(formConfig);
- // 初始化校验信息
- this.initWidgetRule(formConfig);
- },
- getParamValue (valueType, valueData) {
- switch (valueType) {
- case this.SysOnlineParamValueType.FORM_PARAM:
- return this.params ? this.params[valueData] : undefined;
- case this.SysOnlineParamValueType.TABLE_COLUMN:
- {
- let column = this.columnMap.get(valueData);
- let columnValue = null;
- if (this.formConfig.formType === this.SysOnlineFormType.QUERY) {
- columnValue = this.formData.formFilterCopy[column.columnName];
- } else {
- columnValue = this.formData[column.columnName];
- }
- if (column == null || columnValue == null || columnValue === '') {
- return null;
- } else {
- return columnValue;
- }
- }
- case this.SysOnlineParamValueType.STATIC_DICT:
- return Array.isArray(valueData) ? valueData[1] : undefined;
- case this.SysOnlineParamValueType.INPUT_VALUE:
- return valueData;
- }
- },
- getParamValueObj (paramName, valueType, valueData, retObj) {
- try {
- if (retObj == null) retObj = {};
- retObj[paramName] = this.getParamValue(valueType, valueData);
- if (retObj[paramName] == null) return null;
- return retObj;
- } catch (e) {
- console.log(e);
- }
- },
- clean () {
- this.datasourceMap = null;
- this.relationMap = null;
- this.tableMap = null;
- this.columnMap = null;
- this.dictMap = null;
- },
- loadAllDropdownData () {
- if (Array.isArray(this.dropdownWidgetList)) {
- this.dropdownWidgetList.forEach(dropdownWidget => {
- let dropdownWidgetImpl = this.$refs[dropdownWidget.variableName][0];
- if (dropdownWidgetImpl) {
- dropdownWidgetImpl.onVisibleChange();
- }
- });
- }
- },
- reload () {
- this.loadOnlineFormData().then(res => {
- this.isLoading = false;
- if (this.formConfig.formType === this.SysOnlineFormType.FORM) {
- if (Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.EDIT && this.saveOnClose === '1') {
- // 编辑操作页面,初始化页面数据
- let httpCall = null;
- if (this.saveOnClose === '0') {
- httpCall = Promise.resolve({
- data: this.params
- });
- } else {
- let params = {
- datasourceId: (this.masterTable.datasource || {}).datasourceId,
- relationId: (this.masterTable.relation || {}).relationId
- }
- for (let i = 0; i < this.masterTable.columnList.length; i++) {
- let column = this.masterTable.columnList[i];
- if (column.primaryKey) {
- params.dataId = this.params[column.columnName];
- break;
- }
- }
- if (params.relationId) {
- httpCall = this.doUrl('/admin/online/onlineOperation/viewByOneToManyRelationId/' + (this.masterTable.datasource || {}).variableName, 'get', params);
- } else {
- httpCall = this.doUrl('/admin/online/onlineOperation/viewByDatasourceId/' + (this.masterTable.datasource || {}).variableName, 'get', params);
- }
- }
- httpCall.then(res => {
- this.formData = {
- ...this.formData,
- ...res.data
- }
- this.loadAllDropdownData();
- // 初始化组件联动
- this.initWidgetLinkage(this.formConfig);
- }).catch(e => { });
- return;
- } else {
- if (this.rowData != null) {
- this.formData = {
- ...this.rowData
- }
- }
- }
- this.loadAllDropdownData();
- }
- setTimeout(() => {
- if (this.formConfig.formType === this.SysOnlineFormType.FLOW) {
- this.loadAllDropdownData();
- }
- // 初始化组件联动
- this.initWidgetLinkage(this.formConfig);
- this.onResume();
- this.$emit('ready');
- }, 30);
- }).catch(e => {
- console.log(e);
- });
- },
- onResume () { },
- getPrimaryKeyColumnParam (table, row) {
- if (table && Array.isArray(table.columnList)) {
- return table.columnList.reduce((retObj, column) => {
- let fieldName = (table.relation ? table.relation.variableName + '__' : '') + column.columnName;
- if (column.primaryKey) {
- retObj[column.columnName] = row ? row[fieldName] : undefined;
- }
- return retObj;
- }, {});
- }
- return null;
- },
- buildSubFormParams (operation, subFormInfo, row) {
- let subFormMasterTable = this.tableMap.get(subFormInfo.masterTableId);
- if (subFormMasterTable == null) return null;
- if (subFormMasterTable.relation == null) {
- // 下级表单操作的是主表数据的编辑
- if (operation.type === this.SysCustomWidgetOperationType.EDIT) {
- return this.getPrimaryKeyColumnParam(this.masterTable, row);
- } else {
- return null;
- }
- } else {
- // 下级表单操作的是从表
- if (subFormInfo.formType === this.SysOnlineFormType.QUERY) {
- // 从表的查询页面,参数为主表主键
- return this.getPrimaryKeyColumnParam(this.masterTable, row);
- } else {
- if (operation.type === this.SysCustomWidgetOperationType.EDIT) {
- // 从表的编辑页面
- if (this.formConfig.formType === this.SysOnlineFormType.FORM &&
- Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD) {
- return {
- ...row
- }
- } else {
- return this.getPrimaryKeyColumnParam(subFormMasterTable, row);
- }
- } else {
- // 从表的添加页面
- return {
- ...this.params
- }
- }
- }
- }
- },
- async handlerOperation (operation, row, widget) {
- if (this.preview()) return;
- if (operation.formId != null) {
- OnlineFormController.view(this, {
- formId: operation.formId
- }).then(res => {
- let formInfo = res.data;
- if (formInfo != null) {
- let params = this.buildSubFormParams(operation, formInfo, row);
- if (formInfo.formKind === this.SysOnlineFormKind.DIALOG) {
- let formJsonData = JSON.parse(formInfo.widgetJson);
- let area = (formInfo.height != null) ? [(formJsonData.formConfig.width || 800) + 'px', formJsonData.formConfig.height + 'px'] : (formJsonData.formConfig.width || 800) + 'px';
- this.$dialog.show(operation.name, OnlineForm, {
- area: area,
- offset: '100px'
- }, {
- flowData: this.flowData,
- formId: formInfo.formId,
- formType: formInfo.formType,
- operationType: operation.type,
- params,
- saveOnClose: (
- formInfo.formType === this.SysOnlineFormType.FLOW || this.formConfig.formType === this.SysOnlineFormType.FLOW ||
- (
- formInfo.formType === this.SysOnlineFormType.FORM &&
- Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD
- )
- ) ? '0' : '1',
- rowData: row
- }).then(res => {
- let widgetObj = this.$refs[widget.variableName];
- if (Array.isArray(widgetObj)) {
- widgetObj.forEach(item => {
- item.refresh(res, operation.type);
- });
- } else {
- widgetObj.refresh(res, operation.type);
- }
- }).catch(e => {
- });
- } else {
- if (this.formConfig.formType === this.SysOnlineFormType.QUERY) {
- let tableWidget = this.$refs[this.formConfig.formQueryTable.variableName].getTableWidget();
- this.addOnlineFormCache({
- key: this.$route.fullPath,
- value: {
- formFilter: { ...this.formData.formFilter },
- formFilterCopy: { ...this.formData.formFilterCopy },
- tableImpl: {
- totalCount: tableWidget.totalCount,
- currentPage: tableWidget.currentPage,
- pageSize: tableWidget.pageSize
- }
- }
- });
- }
- this.$router.push({
- name: 'onlineForm',
- query: {
- flowData: this.flowData,
- formId: formInfo.formId,
- formType: formInfo.formType,
- closeVisible: '1',
- operationType: operation.type,
- params,
- saveOnClose: (
- formInfo.formType === this.SysOnlineFormType.FLOW || this.formConfig.formType === this.SysOnlineFormType.FLOW ||
- (
- formInfo.formType === this.SysOnlineFormType.FORM &&
- Number.parseInt(this.operationType) === this.SysCustomWidgetOperationType.ADD
- )
- ) ? '0' : '1',
- rowData: row
- }
- })
- }
- }
- }).catch(e => { });
- } else {
- if (operation.type === this.SysCustomWidgetOperationType.DELETE) {
- this.$confirm('是否删除当前数据?').then(res => {
- if (this.formConfig.formType !== this.SysOnlineFormType.FLOW &&
- (this.formConfig.formType !== this.SysOnlineFormType.FORM || Number.parseInt(this.operationType) !== this.SysCustomWidgetOperationType.ADD)) {
- let params = {
- datasourceId: (widget.table.datasource || {}).datasourceId,
- relationId: (widget.table.relation || {}).relationId
- }
- for (let i = 0; i < widget.table.columnList.length; i++) {
- let column = widget.table.columnList[i];
- if (column.primaryKey) {
- let fieldName = (widget.table.relation ? widget.table.relation.variableName + '__' : '') + column.columnName;
- params.dataId = row[fieldName];
- break;
- }
- }
- let httpCall = null;
- if (params.relationId) {
- httpCall = this.doUrl('/admin/online/onlineOperation/deleteOneToManyRelation/' + widget.datasource.variableName, 'post', params);
- } else {
- httpCall = this.doUrl('/admin/online/onlineOperation/deleteDatasource/' + widget.datasource.variableName, 'post', params);
- }
- httpCall.then(res => {
- this.$message.success('删除成功!');
- let widgetObj = this.$refs[widget.variableName];
- if (Array.isArray(widgetObj)) {
- widgetObj.forEach(item => {
- item.refresh(res, operation.type);
- });
- } else {
- widgetObj.refresh(res, operation.type);
- }
- }).catch(e => {
- });
- } else {
- let widgetObj = this.$refs[widget.variableName];
- if (Array.isArray(widgetObj)) {
- widgetObj.forEach(item => {
- item.refresh(row, operation.type);
- });
- } else {
- widgetObj.refresh(row, operation.type);
- }
- }
- }).catch(e => { });
- } else if (operation.type === this.SysCustomWidgetOperationType.EXPORT) {
- console.log('this.formId :>> ', this.formId);
- if (this.formId == 1657932361767063552) {
- let fileInfoStr = row.component_movementjson;
-
- if (fileInfoStr != undefined) {
- let fileInfoArr = JSON.parse(fileInfoStr);
- let fileInfo = fileInfoArr[0]; // 假设只有一个文件
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/mainUnit', {
- params: {
- datasourceId: '1657931215497334784',
- fieldName: 'component_movementjson',
- asImage: false,
- dataId: row.id,
- filename: fileInfo.filename,
- Authorization: getToken(),
- MenuId: '1657932967709773824'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.component_movementjson = response.data;
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- }
- fileInfoStr = row.components_json;
- let fileInfoArr1 = JSON.parse(fileInfoStr);
- let fileInfo1 = fileInfoArr1[0]; // 假设只有一个文件
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/mainUnit', {
- params: {
- datasourceId: '1657931215497334784',
- fieldName: 'components_json',
- asImage: false,
- dataId: row.id,
- filename: fileInfo1.filename,
- Authorization: getToken(),
- MenuId: '1657932967709773824'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.components_json = response.data;
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- const data = {
- id: row.id,
- name: row.name,
- type: row.type,
- creator: row.creator,
- createtime: row.createtime,
- belong: row.belong,
- health: row.health,
- target: row.target,
- team: row.team,
- task: row.task,
- pos: {
- lat: row.lat,
- lon: row.lon,
- height: row.height
- },
- component_movementid: row.component_movementid,
- component_movementjson: this.component_movementjson,
- components_cnt: row.components_cnt,
- components_ids: row.components_ids,
- components_json: this.components_json
- };
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = data.name + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1675055217952952320) {
- console.log('row :>> ', row);
- let number = row.number
- const data = {};
- data[number] = {
- type: row.type,
- properties: {
- id: row.id,
- lon: row.lon,
- lat: row.lat,
- h: row.h,
- picture: row.picture
- }
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '指挥中心-' + row.number + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1675055674104483840) {
- console.log('row :>> ', row);
- let name = row.name
- const data = {};
- data[name] = {
- id: row.id,
- name: row.name,
- BW: row.BW,
- PW: row.PW,
- fc: row.fc,
- fs: row.fs,
- h: row.h,
- lat: row.lat,
- lon: row.lon,
- modulation: row.modulation,
- prf: row.prf,
- prf_mode: row.prf_mode,
- type: row.type,
- style: row.style,
- url: row.url,
- picture: row.picture
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '末端拦截-' + row.name + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1675056214280507392) {
- let number = row.number
- const data = {};
- data[number] = {
- type: row.type,
- properties: {
- id: row.id,
- CSV_starttime: row.CSV_starttime,
- CSV_endtime: row.CSV_endtime,
- CSV_path: row.CSV_path,
- CSV_sampletime: row.CSV_sampletime,
- TLE_Propagator: row.TLE_Propagator,
- common_RAAN: row.common_RAAN,
- common_argofperiapsis: row.common_argofperiapsis,
- common_eccentricity: row.common_eccentricity,
- common_inclination: row.common_inclination,
- common_semiMajorAxis: row.common_semiMajorAxis,
- common_trueanomaly: row.common_trueanomaly,
- config_type: row.config_type,
- mark: row.mark,
- picture: row.picture
- }
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '预警卫星-' + row.number + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1675048581024714752) {
- console.log('row :>> ', row);
- let number = row.number
- const data = {};
- data[number] = {
- type: row.type,
- properties: {
- id: row.id,
- launch_lon: row.launch_lon,
- launch_lat: row.launch_lat,
- launch_h: row.launch_h,
- target_lon: row.target_lon,
- target_lat: row.target_lat,
- target_h: row.target_h,
- apogee_height: row.apogee_height,
- fly_time: row.fly_time,
- filepath: row.filepath,
- acceleration: row.acceleration
- }
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '弹道导弹-' + row.number + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1674960384441716736) {
- let number = row.number
- const data = {};
- data[number] = {
- type: row.type,
- properties: {
- id: row.id,
- N: row.N,
- f0: row.fo,
- number: row.number,
- tau: row.tau,
- tr: row.tr,
- ts: row.ts,
- url: row.url,
- method: row.method
- }
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '干扰雷达-' + row.number + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else if (this.formId == 1674971627114205184) {
- console.log('row :>> ', row);
- let number = row.number
- const data = {};
- data[number] = {
- type: row.type,
- creator: row.creator,
- properties: {
- id: row.id,
- f0: row.fo,
- number: row.number,
- tau: row.tau,
- k: row.k,
- time: row.time,
- tr: row.tr,
- t_r: row.t_r,
- ts: row.ts,
- url: row.url,
- method: row.method
- }
- }
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = '诱饵雷达-' + row.number + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else {
- // todo 场景想定json导出
- let fileInfoStr = row.blueunit;
- let fileInfoArr = JSON.parse(fileInfoStr);
-
- let fileInfo = fileInfoArr[0]; // 假设只有一个文件
- for (let i = 0; i < fileInfoArr.length; i++) {
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
- params: {
- datasourceId: '1656243335922192384',
- fieldName: 'blueunit',
- asImage: false,
- dataId: row.id,
- filename: fileInfoArr[i].filename,
- Authorization: getToken(),
- MenuId: '1656244747347431424'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.blueunit.push(response.data);
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- }
- fileInfoStr = row.redunit;
- fileInfoArr = JSON.parse(fileInfoStr);
-
- for (let i = 0; i < fileInfoArr.length; i++) {
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
- params: {
- datasourceId: '1656243335922192384',
- fieldName: 'redunit',
- asImage: false,
- dataId: row.id,
- filename: fileInfoArr[i].filename,
- Authorization: getToken(),
- MenuId: '1656244747347431424'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.redunit.push(response.data);
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- }
- fileInfoStr = row.center;
- fileInfoArr = JSON.parse(fileInfoStr);
-
- for (let i = 0; i < fileInfoArr.length; i++) {
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
- params: {
- datasourceId: '1656243335922192384',
- fieldName: 'center',
- asImage: false,
- dataId: row.id,
- filename: fileInfoArr[i].filename,
- Authorization: getToken(),
- MenuId: '1656244747347431424'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.center.push(response.data);
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- }
- fileInfoStr = row.satellite;
- fileInfoArr = JSON.parse(fileInfoStr);
-
- for (let i = 0; i < fileInfoArr.length; i++) {
- await axios.get('http://localhost:8084/admin/online/onlineOperation/downloadDatasource/main', {
- params: {
- datasourceId: '1656243335922192384',
- fieldName: 'satellite',
- asImage: false,
- dataId: row.id,
- filename: fileInfoArr[i].filename,
- Authorization: getToken(),
- MenuId: '1656244747347431424'
- }
- })
- .then(response => {
- // 处理成功的响应
- this.satellite.push(response.data);
- })
- .catch(error => {
- // 处理错误
- console.error(error);
- });
- }
- const data = {
- id: row.id,
- xdname: row.xdname,
- type: row.type,
- creator: row.creator,
- createtime: row.createtime,
- bluecnt: row.bluecnt,
- target: row.target,
- starttime: row.starttime,
- steptime: row.steptime,
- blueunit: this.blueunit,
- redunit: this.redunit,
- satellite: this.satellite,
- center: this.center
- };
- const jsonData = JSON.stringify(data);
- const blob = new Blob([jsonData], { type: 'application/json' });
- const url = URL.createObjectURL(blob);
- const link = document.createElement('a');
- link.href = url;
- link.download = data.xdname + '.json';
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- }
- }
- httpCall.then(res => {
- this.formData = {
- ...this.formData,
- ...res.data
- }
- })
- }
- },
- getRelationTableData (tableWidget) {
- if (tableWidget.widgetType === this.SysCustomWidgetType.Table) {
- let table = tableWidget.table;
- let temp = this.$refs[tableWidget.variableName];
- if (table != null && table.relation != null && Array.isArray(table.columnList) && temp != null) {
- let tableWidgetImpl = temp[0] || temp;
- return tableWidgetImpl.getTableWidget().dataList.map(data => {
- return table.columnList.reduce((retObj, column) => {
- let fieldName = (table.relation ? table.relation.variableName + '__' : '') + column.columnName;
- retObj[column.columnName] = data[fieldName];
- return retObj
- }, {});
- });
- }
- }
- return null;
- },
- getWidgetPrimaryColumnId (widget) {
- let columnList = null;
- if (widget.relationId == null) {
- columnList = widget.datasource.masterTable.columnList;
- } else {
- columnList = widget.relation.slaveTable.columnList;
- }
- if (Array.isArray(columnList)) {
- for (let i = 0; i < columnList.length; i++) {
- let column = columnList[i];
- if (column.primaryKey) {
- let columnName = column.columnName;
- if (widget.relation != null) columnName = widget.relation.variableName + '__' + columnName;
- return this.formData[columnName];
- }
- }
- }
- },
- ...mapMutations(['addOnlineFormCache'])
- },
- created () {
- this.reload();
- },
- destoryed () {
- this.clean();
- },
- watch: {
- formId: {
- handler (newValue) {
- this.reload();
- }
- }
- }
- }
- export {
- OnlineFormMixins
- }
|