| | |
| | | import request from "@/utils/request" |
| | | import {useRouter,useRoute} from "vue-router" |
| | | import {useI18n} from "vue-i18n" |
| | | import i18n from "@/lang/index" |
| | | const lang = i18n.global.locale.value |
| | | import {ElMessage, ElMessageBox} from "element-plus" |
| | | const { t } = useI18n() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | const dialogVisible = ref(false) |
| | | let selectValue = ref(null) |
| | | let options = ref([]) |
| | | let selectValue = ref([null,null]) |
| | | let options = ref(null) |
| | | let checkId = ref(null) |
| | | |
| | | |
| | | const xGrid = ref() |
| | | const gridOptions = reactive({ |
| | |
| | | buttons: [ |
| | | |
| | | ], |
| | | slots:{ |
| | | buttons: "role_add" |
| | | |
| | | }, |
| | | zoom: true, |
| | | custom: true |
| | | }, |
| | |
| | | customConfig: { |
| | | storage: true |
| | | }, |
| | | checkboxConfig: { |
| | | checkField:'checked', |
| | | }, |
| | | editConfig: { |
| | | trigger: 'click', |
| | | mode: 'row', |
| | |
| | | |
| | | //表头按钮 |
| | | toolbarConfig: { |
| | | buttons: [ |
| | | |
| | | ], |
| | | slots:{ |
| | | buttons: "toolbar_buttons" |
| | | buttons: "toolbar_buttons", |
| | | tools:'save_buttons' |
| | | |
| | | }, |
| | | buttons: [ |
| | | ], |
| | | zoom: true, |
| | | custom: true |
| | | }, |
| | |
| | | |
| | | let columnsP = [ |
| | | { type: 'seq', width: 60 }, |
| | | { type: 'checkbox', width: 50 } |
| | | { type: 'checkbox', |
| | | width: 50 , |
| | | field:"checked", |
| | | |
| | | } |
| | | ] |
| | | const columnNameP = { |
| | | id: 'ID', |
| | |
| | | }) |
| | | |
| | | onMounted(()=>{ |
| | | request.get('/role/findAll').then(res=>{ |
| | | request.get(`/role/findAll`).then(res=>{ |
| | | gridOptions.data = res.data |
| | | }) |
| | | request.post('/permission/getPermissionList').then(res=>{ |
| | | request.post(`/permission/getPermissionList/${lang}`).then(res=>{ |
| | | options.value = res.data |
| | | }) |
| | | }) |
| | |
| | | switch (type) { |
| | | case 'edit': { |
| | | dialogVisible.value = true |
| | | checkId.value = row.id |
| | | break |
| | | } |
| | | } |
| | | } |
| | | |
| | | const getPermissionList = () => { |
| | | request.post(`/permission/getPermission/${2}`).then(res=>{ |
| | | permissionOptions.data = res.data |
| | | request.post(`/permission/getPermission/${checkId.value}/${lang}`,selectValue.value).then(res=>{ |
| | | pGrid.value.reloadData(res.data) |
| | | }) |
| | | } |
| | | |
| | | const selectChange = ()=>{ |
| | | console.log(selectValue.value) |
| | | const selectChange = () => { |
| | | getPermissionList() |
| | | } |
| | | |
| | | const saveBatch = () => { |
| | | const $grid = pGrid.value |
| | | if($grid.getCheckboxRecords().length === 0){ |
| | | ElMessage.warning("请先选择权限") |
| | | return |
| | | } |
| | | ElMessageBox.confirm( |
| | | '确认修改角色权限?', |
| | | 'Warning', |
| | | { |
| | | confirmButtonText: '确认', |
| | | cancelButtonText: '取消', |
| | | type: 'warning', |
| | | } |
| | | ).then(() => { |
| | | const permission = { |
| | | id: checkId.value, |
| | | detail: $grid.getCheckboxRecords() |
| | | } |
| | | request.post(`/permissionRole/savePermissionRole`,permission).then(res=>{ |
| | | if(res.data=== true && res.code==='200'){ |
| | | ElMessage.success('保存成功') |
| | | dialogVisible.value = false |
| | | getPermissionList() |
| | | }else{ |
| | | ElMessage.error('保存失败') |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | const addRole = () =>{ |
| | | ElMessageBox.prompt('请输入新角色', '新增角色', { |
| | | confirmButtonText: '确定', |
| | | cancelButtonText: '取消', |
| | | inputPattern:/^.{1,255}$/, |
| | | inputErrorMessage: '不能为空且长度不能超过255', |
| | | }) |
| | | .then(({ value }) => { |
| | | const role= { |
| | | role: value |
| | | } |
| | | request.post("/role/add",role).then(res=>{ |
| | | if(res.code==='200' && res.data===true){ |
| | | ElMessage.success('新增成功') |
| | | router.push({path:'/main/role/roleList',query:{random:Math.random()}}) |
| | | }else{ |
| | | ElMessage.error('新增失败') |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | </script> |
| | |
| | | ref="xGrid" |
| | | v-bind="gridOptions" |
| | | > |
| | | <template #role_add> |
| | | <vxe-button |
| | | @click="addRole" |
| | | status='primary' |
| | | style="margin-right: 1rem" |
| | | >角色新增</vxe-button> |
| | | </template> |
| | | |
| | | |
| | | <template #filter="{ column, $panel }"> |
| | | <div> |
| | | <div v-for="(option, index) in column.filters" :key="index"> |
| | |
| | | @change="selectChange" |
| | | /> |
| | | </template> |
| | | <template #save_buttons> |
| | | <vxe-button |
| | | @click="saveBatch" |
| | | status='primary' |
| | | style="margin-right: 1rem" |
| | | >新增</vxe-button> |
| | | </template> |
| | | |
| | | </vxe-grid> |
| | | |