| | |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="isShowRoleDialog = !isShowRoleDialog" size="default">取 消</el-button> |
| | | <el-button type="primary" @click="onSubmit" size="default">{{ buttonName }}</el-button> |
| | | <el-button type="primary" @click="onSubmit" v-throttle size="default">{{ buttonName }}</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | |
| | | <script lang="ts"> |
| | | import { ElMessage } from 'element-plus'; |
| | | import { reactive, toRefs, defineComponent } from 'vue'; |
| | | import {useRoleApi} from "/@/api/role"; |
| | | import { useRoleApi } from '/@/api/role'; |
| | | |
| | | // 定义接口来定义对象的类型 |
| | | interface MenuDataTree { |
| | |
| | | children?: MenuDataTree[]; |
| | | } |
| | | interface RoleState { |
| | | title:string, |
| | | buttonName:string, |
| | | title: string; |
| | | buttonName: string; |
| | | isShowRoleDialog: boolean; |
| | | roleForm: { |
| | | roleName: string; |
| | |
| | | roleForm: { |
| | | roleName: '', // 角色名称 |
| | | roleCode: '', // 角色标识 |
| | | roleInfo: '', // 排序 |
| | | roleInfo: '' // 排序 |
| | | }, |
| | | menuData: [], |
| | | menuProps: { |
| | | children: 'children', |
| | | label: 'label', |
| | | }, |
| | | label: 'label' |
| | | } |
| | | }); |
| | | // 打开弹窗 |
| | | const openDialog = (type: string, value: any) => { |
| | | state.isShowRoleDialog = true; |
| | | if(type === '新增'){ |
| | | state.title = '新增角色' |
| | | state.buttonName = '新增' |
| | | state.title = '新增角色'; |
| | | state.buttonName = '新增'; |
| | | state.roleForm = { |
| | | roleName:'', |
| | | roleCode:'', |
| | | roleInfo:'', |
| | | } |
| | | roleInfo: '' |
| | | }; |
| | | }else{ |
| | | state.title = '修改角色' |
| | | state.buttonName = '修改' |
| | | state.roleForm = JSON.parse(JSON.stringify(value)) |
| | | state.title = '修改角色'; |
| | | state.buttonName = '修改'; |
| | | state.roleForm = JSON.parse(JSON.stringify(value)); |
| | | } |
| | | }; |
| | | // 新增 |
| | | const onSubmit = async () => { |
| | | if(state.title === '新增角色'){ |
| | | let res = await useRoleApi().addRole(state.roleForm) |
| | | let res = await useRoleApi().addRole(state.roleForm); |
| | | if(res.data.code === '200'){ |
| | | ElMessage({ |
| | | type:'success', |
| | | message:'角色新增成功', |
| | | duration:2000 |
| | | }) |
| | | state.isShowRoleDialog = false |
| | | context.emit('refreshRoleList') |
| | | }); |
| | | state.isShowRoleDialog = false; |
| | | context.emit('refreshRoleList'); |
| | | }else{ |
| | | ElMessage({ |
| | | type:'warning', |
| | | message:res.data.msg |
| | | }) |
| | | }); |
| | | } |
| | | }else{ |
| | | let res = await useRoleApi().modRole(state.roleForm) |
| | | let res = await useRoleApi().modRole(state.roleForm); |
| | | if(res.data.code === '200'){ |
| | | ElMessage({ |
| | | type:'success', |
| | | message:'角色修改成功', |
| | | duration:2000 |
| | | }) |
| | | state.isShowRoleDialog = false |
| | | context.emit('refreshRoleList') |
| | | }); |
| | | state.isShowRoleDialog = false; |
| | | context.emit('refreshRoleList'); |
| | | }else{ |
| | | ElMessage({ |
| | | type:'warning', |
| | | message:res.data.msg |
| | | }) |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | |
| | | return { |
| | | onSubmit, |
| | | openDialog, |
| | | ...toRefs(state), |
| | | ...toRefs(state) |
| | | }; |
| | | }, |
| | | } |
| | | }); |
| | | </script> |
| | | |