Update
This commit is contained in:
parent
8497d1ae9b
commit
7cbcfb72ef
@ -37,11 +37,15 @@ export const useUserStore = defineStore('user', {
|
|||||||
async getUserInfo() {
|
async getUserInfo() {
|
||||||
try {
|
try {
|
||||||
const res = await api.getUserInfo()
|
const res = await api.getUserInfo()
|
||||||
|
if (res.code === 401) {
|
||||||
|
this.logout()
|
||||||
|
return
|
||||||
|
}
|
||||||
const { id, username, email, avatar, roles, is_superuser, is_active } = res.data
|
const { id, username, email, avatar, roles, is_superuser, is_active } = res.data
|
||||||
this.userInfo = { id, username, email, avatar, roles, is_superuser, is_active }
|
this.userInfo = { id, username, email, avatar, roles, is_superuser, is_active }
|
||||||
return Promise.resolve(res.data)
|
return res.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return Promise.reject(error)
|
return error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async logout() {
|
async logout() {
|
||||||
|
|||||||
@ -90,10 +90,6 @@ function buildApiTree(data) {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
$table.value?.handleSearch()
|
$table.value?.handleSearch()
|
||||||
api.getMenus({ page: 1, page_size: 9999 }).then((res) => (menuOption.value = res.data))
|
|
||||||
api
|
|
||||||
.getApis({ page: 1, page_size: 9999 })
|
|
||||||
.then((res) => (apiOption.value = buildApiTree(res.data)))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
@ -144,9 +140,9 @@ const columns = [
|
|||||||
{
|
{
|
||||||
default: () => '编辑',
|
default: () => '编辑',
|
||||||
icon: renderIcon('material-symbols:edit-outline', { size: 16 }),
|
icon: renderIcon('material-symbols:edit-outline', { size: 16 }),
|
||||||
},
|
}
|
||||||
),
|
),
|
||||||
[[vPermission, 'post/api/v1/role/update']],
|
[[vPermission, 'post/api/v1/role/update']]
|
||||||
),
|
),
|
||||||
h(
|
h(
|
||||||
NPopconfirm,
|
NPopconfirm,
|
||||||
@ -167,12 +163,12 @@ const columns = [
|
|||||||
{
|
{
|
||||||
default: () => '删除',
|
default: () => '删除',
|
||||||
icon: renderIcon('material-symbols:delete-outline', { size: 16 }),
|
icon: renderIcon('material-symbols:delete-outline', { size: 16 }),
|
||||||
},
|
}
|
||||||
),
|
),
|
||||||
[[vPermission, 'delete/api/v1/role/delete']],
|
[[vPermission, 'delete/api/v1/role/delete']]
|
||||||
),
|
),
|
||||||
default: () => h('div', {}, '确定删除该角色吗?'),
|
default: () => h('div', {}, '确定删除该角色吗?'),
|
||||||
},
|
}
|
||||||
),
|
),
|
||||||
withDirectives(
|
withDirectives(
|
||||||
h(
|
h(
|
||||||
@ -181,23 +177,36 @@ const columns = [
|
|||||||
size: 'small',
|
size: 'small',
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
active.value = true
|
try {
|
||||||
role_id.value = row.id
|
// 使用 Promise.all 来同时发送所有请求
|
||||||
const result = await api.getRoleAuthorized({ id: row.id })
|
const [menusResponse, apisResponse, roleAuthorizedResponse] = await Promise.all([
|
||||||
menu_ids.value = result.data.menus.map((v) => {
|
api.getMenus({ page: 1, page_size: 9999 }),
|
||||||
return v.id
|
api.getApis({ page: 1, page_size: 9999 }),
|
||||||
})
|
api.getRoleAuthorized({ id: row.id }),
|
||||||
api_ids.value = result.data.apis.map((v) => {
|
])
|
||||||
return v.method.toLowerCase() + v.path
|
|
||||||
})
|
// 处理每个请求的响应
|
||||||
|
menuOption.value = menusResponse.data
|
||||||
|
apiOption.value = buildApiTree(apisResponse.data)
|
||||||
|
menu_ids.value = roleAuthorizedResponse.data.menus.map((v) => v.id)
|
||||||
|
api_ids.value = roleAuthorizedResponse.data.apis.map(
|
||||||
|
(v) => v.method.toLowerCase() + v.path
|
||||||
|
)
|
||||||
|
|
||||||
|
active.value = true
|
||||||
|
role_id.value = row.id
|
||||||
|
} catch (error) {
|
||||||
|
// 错误处理
|
||||||
|
console.error('Error loading data:', error)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
default: () => '设置权限',
|
default: () => '设置权限',
|
||||||
icon: renderIcon('material-symbols:edit-outline', { size: 16 }),
|
icon: renderIcon('material-symbols:edit-outline', { size: 16 }),
|
||||||
},
|
}
|
||||||
),
|
),
|
||||||
[[vPermission, 'get/api/v1/role/authorized']],
|
[[vPermission, 'get/api/v1/role/authorized']]
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user