系统生成子系统代码优化

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>
<script>
import ConstConfig from '@/scripts/ConstConfig';
import {createMapSubSystem, updateSubSystem, generateMapSystem} from '@/api/trainingPlatform';
import { ProjectList} from '@/scripts/ProjectConfig';
import Cookies from 'js-cookie';
export default {
name: 'CreateSubSystem',
props: {
title: { type:String, required:true },
operateType:{ type:String, required:true },
mapList:{
required:true,
type:Array
@ -29,6 +28,9 @@ export default {
disabled:null,
productList:[],
typeList:[],
title:'',
isAdd:true,
isGernerate:false,
formModel:{
customized:'',
mapId:'',
@ -48,7 +50,8 @@ export default {
},
form() {
let form = {};
if (this.operateType == 'add') {
if (this.isAdd) {
//
form = {
labelWidth: '150px',
items: [
@ -59,7 +62,16 @@ export default {
{ 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 {
//
form = {
labelWidth: '150px',
items: [
@ -71,32 +83,23 @@ export default {
},
rules() {
let crules = {};
if (this.operateType == 'add') {
crules = {customized:[
{ required: true, message: this.$t('systemGenerate.selectProject'), trigger: 'change'}
],
mapId:[
{ required: true, message: this.$t('systemGenerate.selectMap'), trigger: 'change'}
],
name: [
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'blur' },
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'change' }
],
type:[
{ required: true, message: this.$t('systemGenerate.selectType'), trigger: 'change'}
],
prdType:[
{ 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' }
]
};
}
crules = {customized:[
{ required: true, message: this.$t('systemGenerate.selectProject'), trigger: 'change'}
],
mapId:[
{ required: true, message: this.$t('systemGenerate.selectMap'), trigger: 'change'}
],
name: [
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'blur' },
{ required: true, message: this.$t('systemGenerate.inputName'), trigger: 'change' }
],
type:[
{ required: true, message: this.$t('systemGenerate.selectType'), trigger: 'change'}
],
prdType:[
{ required: true, message: this.$t('rules.productTypeInput'), trigger: 'change'}
]
};
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.label }; });
},
doShow(data) {
if (data) {
this.formModel.name = data.name;
this.formModel.id = data.id;
doShow({type, row}) {
if (row) {
this.title = this.$t('systemGenerate.modifySubSystem');
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.$nextTick(()=>{
this.$refs.dataform.clearValidate();
});
},
doCreate() {
const self = this;
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();
});
},
doClose() {
this.$refs.dataform.resetForm();
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>
<el-card>
<QueryListPage ref="subSystemListPage" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" />
<once-generate ref="generate" :map-list="mapList" @create="generateMapSystem" />
<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" />
<mapSystemOperate ref="mapSystemOperate" :map-list="mapList" @reloadTable="reloadTable" />
</el-card>
</template>
<script>
import Cookies from 'js-cookie';
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 OnceGenerate from './generate';
import createMapSystem from './create';
import mapSystemOperate from './create';
export default {
name: 'SystemGenerate',
components: {
OnceGenerate,
createMapSystem
mapSystemOperate
},
data() {
return {
@ -121,11 +117,7 @@ export default {
},
methods: {
updateData(index, row) {
getSubSystemInfo(row.id).then(response => {
this.$refs.modifyMapSystem.doShow(response.data);
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.getSubSystemInfoFail'));
});
this.$refs.mapSystemOperate.doShow({type:'update', row:row});
},
deleteData(index, row) {
this.$confirm(this.$t('systemGenerate.deleteMapSystemTip'), this.$t('global.tips'), {
@ -141,26 +133,8 @@ export default {
});
}).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() {
this.$refs.createMapSystem.doShow();
this.$refs.mapSystemOperate.doShow({type:'add'});
},
reloadTable() {
if (this.queryList && this.queryList.reload) {
@ -194,15 +168,7 @@ export default {
}
},
generate() {
this.$refs.generate.doShow();
},
generateMapSystem(data) {
generateMapSystem(data.mapId).then(response => {
this.reloadTable();
this.$message.success(this.$t('systemGenerate.generateSuccess'));
}).catch(() => {
this.$messageBox(this.$t('systemGenerate.generateFail'));
});
this.$refs.mapSystemOperate.doShow({type:'generate'});
},
queryFunction(params) {
return getMapSystemPageList(params);