rt-sim-training-client/src/views/permissionManage/create.vue

213 lines
7.3 KiB
Vue
Raw Normal View History

2022-10-21 15:21:15 +08:00
<template>
<el-dialog v-dialogDrag :title="isEdit ? $t('orderAuthor.modifyPermissions') : $t('orderAuthor.createPermission')" :visible.sync="dialogShow" width="420px" :before-close="handleClose">
<div>
<el-form ref="form" label-position="right" :model="editModel" label-width="80px" :rules="editRules" size="mini" @submit.native.prevent>
<el-form-item :label="$t('orderAuthor.permissionName')" prop="name">
<el-input v-model="editModel.name" />
</el-form-item>
<el-form-item :label="$t('orderAuthor.describtion')">
<el-input v-model="editModel.des" />
</el-form-item>
2022-10-31 18:24:47 +08:00
<el-form-item :label="$t('orderAuthor.permissionType')" prop="permissionType">
<el-select v-model="editModel.permissionType" :placeholder="$t('map.pleaseSelect')">
<el-option
v-for="item in permissionTypeList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item v-if="editModel.permissionType === 0" label="项目" prop="projectCode">
<el-select v-model="editModel.projectCode" :placeholder="$t('map.pleaseSelect')">
<el-option
v-for="item in projectList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item v-if="editModel.permissionType === 1 || editModel.permissionType === 2" label="线路" prop="mapId">
<el-select v-model="editModel.mapId" :placeholder="$t('map.pleaseSelect')" @change="mapIdChange">
<el-option
v-for="item in mapList"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item v-if="editModel.permissionType === 2" :label="$t('orderAuthor.ability')" prop="abilityIds">
2022-10-21 15:21:15 +08:00
<el-select v-model="editModel.abilityIds" multiple :placeholder="$t('map.pleaseSelect')">
<el-option
2022-10-31 18:24:47 +08:00
v-for="item in filterAbilityList"
2022-10-21 15:21:15 +08:00
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogShow = false">{{ $t('map.cancel') }}</el-button>
<el-button type="primary" :loading="loading" @click="saveAs">{{ $t('map.confirm') }}</el-button>
</span>
</el-dialog>
</template>
<script>
import { createPermission, updatePermission } from '@/api/permissionManage';
export default {
name: 'MapSaveAs',
props: {
2022-10-31 18:24:47 +08:00
abilityList: {
required:true,
type:Array
},
permissionTypeList: {
required:true,
type:Array
},
mapList: {
required:true,
type:Array
},
projectList: {
2022-10-21 15:21:15 +08:00
required:true,
type:Array
}
},
data() {
return {
dialogShow: false,
loading: false,
isEdit: false,
editModel: {
name: '',
des: '',
2022-10-31 18:24:47 +08:00
permissionType: '',
projectCode: '',
mapId: '',
2022-10-21 15:21:15 +08:00
abilityIds: []
},
editRules: {
name: [
{ required: true, message: this.$t('rules.enterPermissionName'), trigger: 'blur' }
2022-10-31 18:24:47 +08:00
],
permissionType: [
{ required: true, message: '请选择权限类型!', trigger: 'blur' }
],
projectCode: [
{ required: true, message: '请选择项目!', trigger: 'blur' }
],
mapId: [
{ required: true, message: '请选择线路!', trigger: 'blur' }
],
abilityIds: [
{ required: true, message: '请选择功能!', trigger: 'blur' },
{ validator: this.validateLimit, trigger: 'blur' }
2022-10-21 15:21:15 +08:00
]
}
};
},
2022-10-31 18:24:47 +08:00
computed: {
mapName() {
let name = '';
const findObj = this.mapList.find(item => {
return item.value == this.editModel.mapId;
});
if (findObj && this.editModel.mapId) {
name = findObj.label;
}
return name;
},
filterAbilityList() {
return this.abilityList.filter(item => {
return item.mapName == this.mapName;
});
}
},
2022-10-21 15:21:15 +08:00
methods: {
2022-10-31 18:24:47 +08:00
mapIdChange() {
this.editModel.abilityIds = [];
},
validateLimit(rule, value, callback) {
const num = value.length;
if (num >= 1) {
callback();
} else {
callback(new Error('请选择功能!'));
}
},
2022-10-21 15:21:15 +08:00
doShow(data) {
if (data) {
this.isEdit = true;
const abilityIds = [];
data.abilityVOList && data.abilityVOList.forEach(item => {
abilityIds.push(item.id);
});
this.editModel = {
2022-10-31 18:24:47 +08:00
...data,
mapId: data.mapId ? String(data.mapId) : '',
2022-10-21 15:21:15 +08:00
abilityIds: abilityIds
};
} else {
this.isEdit = false;
this.initData();
}
this.dialogShow = true;
},
initData() {
this.editModel = {
name: '',
des: '',
2022-10-31 18:24:47 +08:00
permissionType: '',
projectCode: '',
mapId: '',
2022-10-21 15:21:15 +08:00
abilityIds: []
};
},
close() {
this.initData();
this.dialogShow = false;
},
handleClose() {
this.close();
},
saveAs() {
this.$refs['form'].validate((valid) => {
if (!valid) { return; }
this.loading = true;
let apiFn = createPermission;
if (this.isEdit) {
apiFn = updatePermission;
}
2022-10-31 18:24:47 +08:00
const cpData = Object.assign({}, this.editModel);
if (this.editModel.permissionType === 0) {
delete cpData.mapId;
cpData.abilityIds = [];
} else if (this.editModel.permissionType === 1) {
delete cpData.projectCode;
cpData.abilityIds = [];
} else if (this.editModel.permissionType === 2) {
delete cpData.projectCode;
}
apiFn(cpData).then((res) => {
2022-10-21 15:21:15 +08:00
this.loading = false;
this.$message.success(`${this.isEdit ? '编辑' : '新建'}成功!`);
this.$emit('refresh');
this.close();
}).catch((err) => {
console.log('err', err);
this.loading = false;
2022-10-27 11:29:27 +08:00
this.$message.error(`${this.isEdit ? '编辑' : '新建'}失败!,${err.message}`);
2022-10-21 15:21:15 +08:00
});
});
}
}
};
</script>