| | |
| | | import {onBeforeMount, onMounted, reactive, ref} from "vue" |
| | | import {changeFilterEvent,filterChanged} from "@/hook" |
| | | import request from "@/utils/request" |
| | | import {useRouter,useRoute} from "vue-router" |
| | | import {useI18n} from "vue-i18n" |
| | | import {ElMessage, ElMessageBox} from "element-plus" |
| | | const { t } = useI18n() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | const dialogVisible = ref(false) |
| | | let roleList = ref([]) |
| | | let userRole= ref({ |
| | | userId:'', |
| | | roles:[] |
| | | }) |
| | | const xGrid = ref() |
| | | const gridOptions = reactive({ |
| | | border: "full",//表格加边框 |
| | |
| | | const columnName = { |
| | | loginName: '用户ID', |
| | | userName:'用户', |
| | | address:'地址', |
| | | phone:'电话', |
| | | // address:'地址', |
| | | // phone:'电话', |
| | | role:'角色', |
| | | createTime:'创建时间' |
| | | } |
| | |
| | | }) |
| | | onMounted(()=>{ |
| | | request.get('/userInfo/findAll').then(res=>{ |
| | | gridOptions.data = res.data |
| | | console.log(res.data) |
| | | let arr = res.data.users[0] |
| | | arr.forEach(item=>{ |
| | | let bValues = item.userRoleList.map(item => item.role); |
| | | item.role = bValues.join(',') |
| | | }) |
| | | gridOptions.data = res.data.users[0] |
| | | roleList.value = res.data.role[0] |
| | | }) |
| | | }) |
| | | |
| | | const getTableRow = (row,type) => { |
| | | switch (type) { |
| | | case 'edit': { |
| | | userRole.value.roles = [] |
| | | dialogVisible.value = true |
| | | row.userRoleList.forEach(item=>{ |
| | | userRole.value.roles.push(item.roleId) |
| | | }) |
| | | userRole.value.userId = row.id |
| | | break |
| | | } |
| | | case 'delete': { |
| | | request.post(`/userInfo/userDelete/${row.id}`).then((res) => { |
| | | if(res.code==200 && res.data ===true){ |
| | | ElMessage.success(t('searchOrder.msgDeleteSuccess')) |
| | | router.push({path:'/main/user/userList',query:{random:Math.random()}}) |
| | | }else{ |
| | | ElMessage.warning(t('searchOrder.msgDeleteFail')) |
| | | } |
| | | }) |
| | | break |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | const handleClose = (done) => { |
| | | userRole.value.roles = [] |
| | | done() |
| | | } |
| | | |
| | | const roleUpdate = () => { |
| | | request.post('userRole/updateUserRole',userRole.value).then(res=>{ |
| | | if(res.code==200 && res.data===true){ |
| | | ElMessage.success(t('basicData.msg.saveSuccess')) |
| | | router.push({path:'/main/user/userList',query:{random:Math.random()}}) |
| | | } |
| | | |
| | | }) |
| | | dialogVisible.value = false |
| | | } |
| | | |
| | | |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | </el-popconfirm> |
| | | </template> |
| | | </vxe-grid> |
| | | |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | title="角色选择" |
| | | width="30%" |
| | | :before-close="handleClose" |
| | | > |
| | | <span> |
| | | <el-checkbox v-for="(item) in roleList" |
| | | :label="item.id" |
| | | v-model="userRole.roles" > |
| | | {{item.role}} |
| | | </el-checkbox> |
| | | </span> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="dialogVisible = false">取消</el-button> |
| | | <el-button type="primary" @click="roleUpdate"> |
| | | 确认 |
| | | </el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | .dialog-footer button:first-child { |
| | | margin-right: 10px; |
| | | } |
| | | </style> |