|
@@ -1,295 +0,0 @@
|
|
|
-<template>
|
|
|
- <div class="system-dept-dialog-container">
|
|
|
- <el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="769px">
|
|
|
- <el-form ref="deptDialogFormRef" :model="state.ruleForm" size="default" label-width="90px">
|
|
|
- <el-row :gutter="35">
|
|
|
- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
- <el-form-item label="权限名称">
|
|
|
- <el-input v-model="state.ruleForm.name" placeholder="请输入权限名称" clearable></el-input>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
-
|
|
|
- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
- <el-form-item label="备注说明">
|
|
|
- <el-input v-model="state.ruleForm.remark" placeholder="请输入备注说明" clearable></el-input>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
-
|
|
|
- <!-- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
- <el-form-item label="角色状态">
|
|
|
- <el-switch v-model="state.status" inline-prompt active-text="启用" inactive-text="禁用"></el-switch>
|
|
|
- </el-form-item>
|
|
|
- </el-col> -->
|
|
|
-
|
|
|
- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
|
|
- <el-form-item label="权限状态" :rules="[{ required: true, message: '权限状态不能为空' }]">
|
|
|
- <el-radio-group v-model="state.ruleForm.valid">
|
|
|
- <el-radio :label="1">启用</el-radio>
|
|
|
- <el-radio :label="0">禁用</el-radio>
|
|
|
- </el-radio-group>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
-
|
|
|
- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
|
|
|
- <el-form-item label="菜单权限">
|
|
|
- <!-- :default-expanded-keys="state.ruleForm.codes" -->
|
|
|
- <el-tree
|
|
|
- show-checkbox
|
|
|
- ref="treeRef"
|
|
|
- node-key="id"
|
|
|
- :data="state.role_list"
|
|
|
- :props="state.menuProps"
|
|
|
- :default-checked-keys="state.ruleForm.code"
|
|
|
- @check-change="getCheckedNodes()"
|
|
|
- class="menu-data-tree"
|
|
|
- />
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
- </el-row>
|
|
|
- </el-form>
|
|
|
- <template #footer>
|
|
|
- <span class="dialog-footer">
|
|
|
- <el-button @click="onCancel" size="default">取 消</el-button>
|
|
|
- <el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
|
|
|
- </span>
|
|
|
- </template>
|
|
|
- </el-dialog>
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script setup lang="ts" name="underlyingProductManageEdit">
|
|
|
-import { reactive, ref } from 'vue';
|
|
|
-import { ElMessage, ElTree } from 'element-plus';
|
|
|
-import type Node from 'element-plus/es/components/tree/src/model/node';
|
|
|
-import { Plus } from '@element-plus/icons-vue';
|
|
|
-import type { UploadProps } from 'element-plus';
|
|
|
-import config from '/@/config.ts';
|
|
|
-import Role from '/@/api/role/role.ts';
|
|
|
-import ruleReg from '/@/utils/ruleReg.ts';
|
|
|
-import Data from './role.ts';
|
|
|
-
|
|
|
-// 定义子组件向父组件传值/事件
|
|
|
-const emit = defineEmits(['refresh']);
|
|
|
-
|
|
|
-// 定义变量内容
|
|
|
-const deptDialogFormRef = ref();
|
|
|
-const state = reactive({
|
|
|
- ruleForm: {
|
|
|
- id: 0,
|
|
|
- name: '',
|
|
|
- remark: '',
|
|
|
- valid: 1,
|
|
|
- code:<any> [],
|
|
|
- codes:<any> [],
|
|
|
- codes_cn:<any> [],
|
|
|
- },
|
|
|
- code:<any> [],
|
|
|
- codes:<any> [],
|
|
|
- codes_cn:<any> [],
|
|
|
- status: true,
|
|
|
- options: [], // 单位类型
|
|
|
- dialog: {
|
|
|
- isShowDialog: false,
|
|
|
- type: '',
|
|
|
- title: '',
|
|
|
- submitTxt: '',
|
|
|
- },
|
|
|
- action: config.host + '/admin/upload/file',
|
|
|
- menuData: [] as TreeType[],
|
|
|
- menuProps: {
|
|
|
- children: 'children',
|
|
|
- label: 'label',
|
|
|
- },
|
|
|
- role_list: [],//Data.role_list
|
|
|
-});
|
|
|
-
|
|
|
-const handleCheckChange = (
|
|
|
- data: TreeType,
|
|
|
- checked: boolean,
|
|
|
- indeterminate: boolean
|
|
|
-) => {
|
|
|
- let getCheckedNodes = treeRef.value!.getCheckedNodes(false, true);
|
|
|
- console.log('getCheckedNodes', getCheckedNodes);
|
|
|
- treeFormat(getCheckedNodes);
|
|
|
-}
|
|
|
-
|
|
|
-const treeRef = ref<InstanceType<typeof ElTree>>()
|
|
|
-const getCheckedNodes = () => {
|
|
|
- let getCheckedNodes = treeRef.value!.getCheckedNodes(false, true);
|
|
|
- console.log('getCheckedNodes', getCheckedNodes);
|
|
|
- treeFormat(getCheckedNodes);
|
|
|
-}
|
|
|
-// 树状列表处理
|
|
|
-const treeFormat = (tree_list:any) => {
|
|
|
- state.code = [];
|
|
|
- state.codes = [];
|
|
|
- state.codes_cn = [];
|
|
|
- let ids:any = [];
|
|
|
- tree_list.forEach((item:any)=>{
|
|
|
- state.codes.push(item.id);
|
|
|
- state.codes_cn.push(item.label);
|
|
|
- })
|
|
|
- for(let i=0;i<tree_list.length;i++){
|
|
|
- for(let j=0;j<tree_list.length;j++){
|
|
|
- if(tree_list[i].id==tree_list[j].pId){
|
|
|
- ids.push(tree_list[i].id);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for(let k=0;k<tree_list.length;k++){
|
|
|
- for(let l=0;l<ids.length;l++){
|
|
|
- if(tree_list[k].id==ids[l]){
|
|
|
- tree_list.splice(k,1);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- tree_list.forEach((item:any)=>{
|
|
|
- state.code.push(item.id);
|
|
|
- })
|
|
|
- console.log('state.code',state.code);
|
|
|
- console.log('state.codes',state.codes);
|
|
|
- console.log('state.codes_cn',state.codes_cn);
|
|
|
-}
|
|
|
-
|
|
|
-// 打开弹窗
|
|
|
-const openDialog = (type: string, row: any) => {
|
|
|
- state.dialog.type = type;
|
|
|
- if (type === 'edit') {
|
|
|
- state.ruleForm = {
|
|
|
- id: row.id,
|
|
|
- name: row.name,
|
|
|
- remark: row.remark,
|
|
|
- valid: row.valid,
|
|
|
- code: row.code,
|
|
|
- codes: row.codes,
|
|
|
- codes_cn: row.codes_cn,
|
|
|
- };
|
|
|
- state.dialog.title = '编辑权限022';
|
|
|
- state.dialog.submitTxt = '修 改';
|
|
|
- state.code = row.code;
|
|
|
- state.codes = row.codes;
|
|
|
- state.codes_cn = row.codes_cn;
|
|
|
- console.log('state.ruleForm.codes->',state.ruleForm.code);
|
|
|
- console.log('state.ruleForm.codes->',state.ruleForm.codes);
|
|
|
- console.log('state.ruleForm.codes_cn->',state.ruleForm.codes_cn);
|
|
|
- } else {
|
|
|
- state.ruleForm = {
|
|
|
- id: 0,
|
|
|
- name: '',
|
|
|
- remark: '',
|
|
|
- valid: 1,
|
|
|
- code: [],
|
|
|
- codes: [],
|
|
|
- codes_cn: [],
|
|
|
- };
|
|
|
- state.status = true;
|
|
|
- state.dialog.title = '新增权限021';
|
|
|
- state.dialog.submitTxt = '保 存';
|
|
|
- // 清空表单,此项需加表单验证才能使用
|
|
|
- // nextTick(() => {
|
|
|
- // deptDialogFormRef.value.resetFields();
|
|
|
- // });
|
|
|
- }
|
|
|
- state.dialog.isShowDialog = true;
|
|
|
- getMenuData();
|
|
|
-};
|
|
|
-// 关闭弹窗
|
|
|
-const closeDialog = () => {
|
|
|
- state.dialog.isShowDialog = false;
|
|
|
-};
|
|
|
-// 取消
|
|
|
-const onCancel = () => {
|
|
|
- closeDialog();
|
|
|
-};
|
|
|
-// 提交
|
|
|
-const onSubmit = async() => {
|
|
|
- if(!ruleReg.emptyReg(state.ruleForm.name)){
|
|
|
- return ElMessage.warning("请输入权限名称");
|
|
|
- }
|
|
|
- if(!ruleReg.emptyReg(state.ruleForm.remark)){
|
|
|
- return ElMessage.warning("请输入备注说明");
|
|
|
- }
|
|
|
- if(state.code[0]!=='home'&&state.codes[0]!=='home'&&state.codes_cn[0]!=='首页'){
|
|
|
- state.code.unshift('home');
|
|
|
- state.codes.unshift('home');
|
|
|
- state.codes_cn.unshift('首页');
|
|
|
- }
|
|
|
- state.ruleForm.code = state.code;
|
|
|
- state.ruleForm.codes = state.codes;
|
|
|
- state.ruleForm.codes_cn = state.codes_cn;
|
|
|
- // state.ruleForm.code.push([]);
|
|
|
- // state.ruleForm.codes.push([]);
|
|
|
- // state.ruleForm.codes_cn.push([]);
|
|
|
- // state.ruleForm.code.splice(-1,1);
|
|
|
- // state.ruleForm.codes.splice(-1,1);
|
|
|
- // state.ruleForm.codes_cn.splice(-1,1);
|
|
|
- let res: any = null;
|
|
|
- if(state.dialog.type=='edit' || state.ruleForm.id!=0){
|
|
|
- res = await Role.edit(state.ruleForm);
|
|
|
- if(res.code != 0){
|
|
|
- return ElMessage.error(res.msg);
|
|
|
- }
|
|
|
- }else{
|
|
|
- res = await Role.add(state.ruleForm);
|
|
|
- if(res.code != 0){
|
|
|
- return ElMessage.error(res.msg);
|
|
|
- }
|
|
|
- }
|
|
|
- ElMessage.success(res.msg);
|
|
|
- closeDialog();
|
|
|
- emit('refresh');
|
|
|
-};
|
|
|
-
|
|
|
-// 初始化权限菜单
|
|
|
-const init = async() => {
|
|
|
- let res = await Role.init();
|
|
|
- if(res.code != 0){
|
|
|
- return ElMessage.error(res.msg);
|
|
|
- }
|
|
|
- state.role_list = res.data;
|
|
|
-};
|
|
|
-
|
|
|
-// 获取菜单结构数据
|
|
|
-const getMenuData = () => {
|
|
|
- init();
|
|
|
-};
|
|
|
-
|
|
|
-// 暴露变量
|
|
|
-defineExpose({
|
|
|
- openDialog,
|
|
|
-});
|
|
|
-</script>
|
|
|
-
|
|
|
-<style lang="scss" scoped>
|
|
|
- .avatar-uploader .avatar {
|
|
|
- width: 178px;
|
|
|
- height: 178px;
|
|
|
- display: block;
|
|
|
- }
|
|
|
- .avatar-uploader .el-upload {
|
|
|
- border: 1px dashed var(--el-border-color);
|
|
|
- border-radius: 6px;
|
|
|
- cursor: pointer;
|
|
|
- position: relative;
|
|
|
- overflow: hidden;
|
|
|
- transition: var(--el-transition-duration-fast);
|
|
|
- }
|
|
|
- .avatar-uploader .el-upload:hover {
|
|
|
- border-color: var(--el-color-primary);
|
|
|
- }
|
|
|
- .el-icon.avatar-uploader-icon {
|
|
|
- font-size: 28px;
|
|
|
- color: #8c939d;
|
|
|
- width: 178px;
|
|
|
- height: 178px;
|
|
|
- text-align: center;
|
|
|
- }
|
|
|
- .system-role-dialog-container {
|
|
|
- .menu-data-tree {
|
|
|
- width: 100%;
|
|
|
- border: 1px solid var(--el-border-color);
|
|
|
- border-radius: var(--el-input-border-radius, var(--el-border-radius-base));
|
|
|
- padding: 5px;
|
|
|
- }
|
|
|
- }
|
|
|
-</style>
|