系统生成子系统代码优化

This commit is contained in:
joylink_cuiweidong 2020-11-13 11:31:05 +08:00
parent 34db1f439f
commit 720c527683
3 changed files with 86 additions and 147 deletions

View File

@ -11,13 +11,12 @@
</template> </template>
<script> <script>
import ConstConfig from '@/scripts/ConstConfig'; import ConstConfig from '@/scripts/ConstConfig';
import {createMapSubSystem, updateSubSystem, generateMapSystem} from '@/api/trainingPlatform';
import { ProjectList} from '@/scripts/ProjectConfig'; import { ProjectList} from '@/scripts/ProjectConfig';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
export default { export default {
name: 'CreateSubSystem', name: 'CreateSubSystem',
props: { props: {
title: { type:String, required:true },
operateType:{ type:String, required:true },
mapList:{ mapList:{
required:true, required:true,
type:Array type:Array
@ -29,6 +28,9 @@ export default {
disabled:null, disabled:null,
productList:[], productList:[],
typeList:[], typeList:[],
title:'',
isAdd:true,
isGernerate:false,
formModel:{ formModel:{
customized:'', customized:'',
mapId:'', mapId:'',
@ -48,7 +50,8 @@ export default {
}, },
form() { form() {
let form = {}; let form = {};
if (this.operateType == 'add') { if (this.isAdd) {
//
form = { form = {
labelWidth: '150px', labelWidth: '150px',
items: [ items: [
@ -59,7 +62,16 @@ export default {
{ prop: 'type', label: this.$t('systemGenerate.type'), type: 'select', required: true, options: this.typeList} { prop: 'type', label: this.$t('systemGenerate.type'), type: 'select', required: true, options: this.typeList}
] ]
}; };
} else if (this.isGernerate) {
//
form = {
labelWidth: '150px',
items: [
{ prop: 'mapId', label: this.$t('systemGenerate.mapName'), type: 'select', required: true, options: this.mapList}
]
};
} else { } else {
//
form = { form = {
labelWidth: '150px', labelWidth: '150px',
items: [ items: [
@ -71,32 +83,23 @@ export default {
}, },
rules() { rules() {
let crules = {}; let crules = {};
if (this.operateType == 'add') { crules = {customized:[
crules = {customized:[ { required: true, message: this.$t('systemGenerate.selectProject'), trigger: 'change'}
{ required: true, message: this.$t('systemGenerate.selectProject'), trigger: 'change'} ],
], mapId:[
mapId:[ { required: true, message: this.$t('systemGenerate.selectMap'), trigger: 'change'}
{ required: true, message: this.$t('systemGenerate.selectMap'), trigger: 'change'} ],
], name: [
name: [ { required: true, message: this.$t('systemGenerate.inputName'), trigger: 'blur' },
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'blur' }, { required: true, message: this.$t('systemGenerate.inputName'), trigger: 'change' }
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'change' } ],
], type:[
type:[ { required: true, message: this.$t('systemGenerate.selectType'), trigger: 'change'}
{ required: true, message: this.$t('systemGenerate.selectType'), trigger: 'change'} ],
], prdType:[
prdType:[ { required: true, message: this.$t('rules.productTypeInput'), trigger: 'change'}
{ required: true, message: this.$t('rules.productTypeInput'), trigger: 'change'} ]
] };
};
} else {
crules = {
name: [
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'blur' },
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'change' }
]
};
}
return crules; return crules;
} }
}, },
@ -110,22 +113,63 @@ export default {
? customeredProductType.map(elem => { return { value: elem.value, label: elem.enlabel }; }) ? customeredProductType.map(elem => { return { value: elem.value, label: elem.enlabel }; })
: customeredProductType.map(elem => { return { value: elem.value, label: elem.label }; }); : customeredProductType.map(elem => { return { value: elem.value, label: elem.label }; });
}, },
doShow(data) { doShow({type, row}) {
if (data) { if (row) {
this.formModel.name = data.name; this.title = this.$t('systemGenerate.modifySubSystem');
this.formModel.id = data.id; this.isAdd = false;
this.isGernerate = false;
this.formModel.name = row.name;
this.formModel.id = row.id;
} else {
if (type == 'add') {
this.title = this.$t('systemGenerate.createSubSystem');
this.isAdd = true;
this.isGernerate = false;
this.formModel.mapId = '';
this.formModel.name = '';
} else {
this.title = this.$t('systemGenerate.generation');
this.isAdd = false;
this.isGernerate = true;
this.formModel.mapId = '';
}
} }
this.dialogVisible = true; this.dialogVisible = true;
this.$nextTick(()=>{
this.$refs.dataform.clearValidate();
});
}, },
doCreate() { doCreate() {
const self = this; const self = this;
this.$refs.dataform.validateForm(() => { this.$refs.dataform.validateForm(() => {
self.$emit('create', Object.assign({}, this.formModel)); if (this.isAdd) {
delete this.formModel.id;
createMapSubSystem(this.formModel).then(response => {
this.$message.success(this.$t('systemGenerate.createMapSystemSuccess'));
self.$emit('reloadTable');
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.createMapSystemFail'));
});
} else if (this.isGernerate) {
generateMapSystem(this.formModel.mapId).then(response => {
this.$message.success(this.$t('systemGenerate.generateSuccess'));
self.$emit('reloadTable');
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.generateFail'));
});
} else {
const datainfo = {'name': this.formModel.name};
updateSubSystem(this.formModel.id, datainfo).then(response => {
this.$message.success(this.$t('systemGenerate.updateMapSystemSuccess'));
self.$emit('reloadTable');
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.updateMapSystemFail'));
});
}
self.doClose(); self.doClose();
}); });
}, },
doClose() { doClose() {
this.$refs.dataform.resetForm();
this.dialogVisible = false; this.dialogVisible = false;
} }
} }

View File

@ -1,71 +0,0 @@
<template>
<div>
<el-dialog :title="title" :visible.sync="dialogVisible" width="500px" :before-close="doClose" center>
<data-form ref="dataform" :form="form" :form-model="formModel" :rules="rules" />
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="doCreate">{{ $t('global.confirm') }}</el-button>
<el-button @click="doClose">{{ $t('global.cancel') }}</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'OnceGenerate',
props:{
mapList:{
required:true,
type:Array
}
},
data() {
return {
dialogVisible: false,
formModel:{
mapId:''
},
title: this.$t('systemGenerate.generation')
};
},
computed: {
form() {
const form = {
labelWidth: '150px',
items: [
{ prop: 'mapId', label: this.$t('systemGenerate.mapName'), type: 'select', required: true, options: this.mapList}
]
};
return form;
},
rules() {
const crules = {
mapId:[
{ required: true, message: this.$t('systemGenerate.selectMap'), trigger: 'change'}
]
};
return crules;
}
},
methods: {
doShow() {
this.dialogVisible = true;
},
doCreate() {
const self = this;
this.$refs.dataform.validateForm(() => {
self.$emit('create', Object.assign({}, this.formModel));
self.doClose();
});
},
doClose() {
this.$refs.dataform.resetForm();
this.dialogVisible = false;
}
}
};
</script>
<style lang="scss" scoped>
/deep/ .el-dialog--center .el-dialog__body{
padding: 25px 55px 20px 30px;
}
</style>

View File

@ -1,25 +1,21 @@
<template> <template>
<el-card> <el-card>
<QueryListPage ref="subSystemListPage" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" /> <QueryListPage ref="subSystemListPage" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" />
<once-generate ref="generate" :map-list="mapList" @create="generateMapSystem" /> <mapSystemOperate ref="mapSystemOperate" :map-list="mapList" @reloadTable="reloadTable" />
<createMapSystem ref="createMapSystem" :map-list="mapList" :title="$t('systemGenerate.createSubSystem')" operate-type="add" @create="handleCreate" />
<createMapSystem ref="modifyMapSystem" :map-list="mapList" :title="$t('systemGenerate.modifySubSystem')" operate-type="modify" @create="handleModify" />
</el-card> </el-card>
</template> </template>
<script> <script>
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { getPublishMapListOnline } from '@/api/jmap/map'; import { getPublishMapListOnline } from '@/api/jmap/map';
import { generateMapSystem, getMapSystemPageList, createMapSubSystem, getSubSystemInfo, updateSubSystem, deleteSubSystem} from '@/api/trainingPlatform'; import { getMapSystemPageList, deleteSubSystem} from '@/api/trainingPlatform';
import ConstConfig from '@/scripts/ConstConfig'; import ConstConfig from '@/scripts/ConstConfig';
import OnceGenerate from './generate'; import mapSystemOperate from './create';
import createMapSystem from './create';
export default { export default {
name: 'SystemGenerate', name: 'SystemGenerate',
components: { components: {
OnceGenerate, mapSystemOperate
createMapSystem
}, },
data() { data() {
return { return {
@ -121,11 +117,7 @@ export default {
}, },
methods: { methods: {
updateData(index, row) { updateData(index, row) {
getSubSystemInfo(row.id).then(response => { this.$refs.mapSystemOperate.doShow({type:'update', row:row});
this.$refs.modifyMapSystem.doShow(response.data);
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.getSubSystemInfoFail'));
});
}, },
deleteData(index, row) { deleteData(index, row) {
this.$confirm(this.$t('systemGenerate.deleteMapSystemTip'), this.$t('global.tips'), { this.$confirm(this.$t('systemGenerate.deleteMapSystemTip'), this.$t('global.tips'), {
@ -141,26 +133,8 @@ export default {
}); });
}).catch(() => { }); }).catch(() => { });
}, },
handleCreate(data) {
delete data.id;
createMapSubSystem(data).then(response => {
this.$message.success(this.$t('systemGenerate.createMapSystemSuccess'));
this.reloadTable();
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.createMapSystemFail'));
});
},
handleModify(data) {
const datainfo = {'name': data.name};
updateSubSystem(data.id, datainfo).then(response => {
this.$message.success(this.$t('systemGenerate.updateMapSystemSuccess'));
this.reloadTable();
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.updateMapSystemFail'));
});
},
handleAdd() { handleAdd() {
this.$refs.createMapSystem.doShow(); this.$refs.mapSystemOperate.doShow({type:'add'});
}, },
reloadTable() { reloadTable() {
if (this.queryList && this.queryList.reload) { if (this.queryList && this.queryList.reload) {
@ -194,15 +168,7 @@ export default {
} }
}, },
generate() { generate() {
this.$refs.generate.doShow(); this.$refs.mapSystemOperate.doShow({type:'generate'});
},
generateMapSystem(data) {
generateMapSystem(data.mapId).then(response => {
this.reloadTable();
this.$message.success(this.$t('systemGenerate.generateSuccess'));
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.generateFail'));
});
}, },
queryFunction(params) { queryFunction(params) {
return getMapSystemPageList(params); return getMapSystemPageList(params);