ref:编辑用户导致角色修改逻辑修改

This commit is contained in:
zy7y 2022-09-18 10:50:35 +08:00
parent a0282c99f1
commit e319578676
3 changed files with 32 additions and 26 deletions

View File

@ -24,12 +24,8 @@ const showModal = () => {
const handleOk = () => {
loading.value = true
store.userSelectRole(currentRoleId.value)
setTimeout(() => {
loading.value = false
// todo
visible.value = false
// -
location.reload()
}, 1000)
}
const handleCancel = () => {
@ -46,7 +42,14 @@ defineExpose({
<a-modal v-model:visible="visible" title="切换角色" @ok="handleOk">
<template #footer>
<a-button key="back" @click="handleCancel">取消</a-button>
<a-button key="submit" type="primary" :loading="loading" @click="handleOk">确定</a-button>
<a-button
key="submit"
type="primary"
:loading="loading"
@click="handleOk"
:disabled="currentRoleId === store.userInfo.roles[0]['id']"
>确定</a-button
>
</template>
<span>选择角色</span>

View File

@ -91,6 +91,7 @@ export const userStore = defineStore(
isLoading,
selectKey,
$reset,
getUserData,
loginAction,
loadRoleRouter,
userSelectRole

View File

@ -8,7 +8,8 @@ import { getRoles } from '@/service/role'
import { columns, addUserRules, putUserRules } from './conf'
import { message } from 'ant-design-vue'
import { userStore } from '@/stores/user'
import router from '@/router'
const store = userStore()
/**查询表单响应式数据 */
const queryFormRef = ref()
@ -157,31 +158,32 @@ const putUserForm = reactive({
const putId = ref()
//modal
const onOkPut = () => {
const onOkPut = async () => {
//
putUserFormRef.value.validateFields().then(() => {
putUserFormRef.value.validateFields().then(async () => {
//
const { nickname, password, roles } = putUserForm
let rids = roles.map((e, i) => ({ rid: e, status: i === 0 ? 5 : 1 }))
putUser(putId.value, { nickname, password, roles: rids }).then((res) => {
const res = await putUser(putId.value, { nickname, password, roles: rids })
if (res.msg === '请求成功') {
message.success('修改成功')
// 1. modal
putVisible.value = !putVisible.value
// 2.
putUserFormRef.value.resetFields()
if (putId.value === userStore().userInfo.id) {
//
message.warning('修改了自己,请重新登录')
userStore().$reset()
router.push('/login')
//
if (putId.value === store.userInfo.id) {
//
if (rids[0]['rid'] !== store.userInfo.roles[0]['id']) {
store.getUserData(putId.value)
// todo
}
} else {
// 3.
getPageData()
}
}
})
})
}
const onCancelPut = () => {