2025-07-30 09:13:52 +08:00
|
|
|
import { ref } from 'vue'
|
|
|
|
import { getRoleList as fetchRoleList } from '@/apis/system/role'
|
|
|
|
import type { LabelValueState } from '@/types/global'
|
|
|
|
|
|
|
|
/** 角色模块 */
|
|
|
|
export function useRole(options?: { onSuccess?: () => void }) {
|
|
|
|
const loading = ref(false)
|
|
|
|
const roleList = ref<LabelValueState[]>([])
|
|
|
|
|
|
|
|
const getRoleList = async () => {
|
|
|
|
try {
|
|
|
|
loading.value = true
|
|
|
|
const res = await fetchRoleList()
|
2025-07-31 17:32:21 +08:00
|
|
|
|
2025-07-30 09:13:52 +08:00
|
|
|
// 将新的角色数据格式转换为表单需要的 LabelValueState 格式
|
|
|
|
if (res && res.data) {
|
2025-07-31 17:32:21 +08:00
|
|
|
roleList.value = (res.data || []).map((role) => ({
|
2025-07-30 09:13:52 +08:00
|
|
|
label: role.roleName,
|
|
|
|
value: role.roleId,
|
2025-07-31 17:32:21 +08:00
|
|
|
disabled: role.status !== '1', // 假设状态为1表示启用
|
2025-07-30 09:13:52 +08:00
|
|
|
}))
|
|
|
|
}
|
2025-07-31 17:32:21 +08:00
|
|
|
|
2025-07-30 09:13:52 +08:00
|
|
|
options?.onSuccess && options.onSuccess()
|
|
|
|
} finally {
|
|
|
|
loading.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return { roleList, getRoleList, loading }
|
|
|
|
}
|