提交 95df79b3 authored 作者: 王鹏飞's avatar 王鹏飞

refactor: 重构角色管理

上级 ae079c8b
<script setup lang="ts"> <script setup lang="ts">
import type { Info } from '../types' import type { RoleInfo, RoleMember } from '../types'
const emit = defineEmits<{ defineProps<{ data: RoleMember; role: RoleInfo }>()
(e: 'update:modelValue', visible: boolean): void
}>()
const prop = defineProps<{
data: Info
}>()
</script> </script>
<template> <template>
<el-dialog class="dialogClass" title="用户信息" width="500px" :close-on-click-modal="false"> <el-dialog class="dialogClass" title="用户信息" width="800px">
<div class="info"> <el-form label-width="100px" label-suffix=":">
<div class="item"> <el-row justify="space-between">
<div class="label">姓名:</div> <el-form-item label="姓名">{{ data.user_name }}</el-form-item>
<div class="value">{{ prop.data.user_name }}</div> <el-form-item label="用户手机">{{ data.mobile }}</el-form-item>
</div> <el-form-item label="用户邮箱">{{ data.email }}</el-form-item>
<div class="item"> </el-row>
<div class="label">用户手机:</div> <el-form-item label="角色类型">
<div class="value">{{ prop.data.mobile }}</div> <el-tag v-for="(item, index) in role.levels" :key="index" size="large">{{ item }}</el-tag>
</div> </el-form-item>
<div class="item"> <el-form-item label="角色名称">
<div class="label">用户邮箱:</div> <el-tag size="large">{{ role.name }}</el-tag>
<div class="value">{{ prop.data.email }}</div> </el-form-item>
</div> <el-form-item label="应用项目">
<div class="item"> <el-tag v-for="(item, index) in data.projects" :key="index" size="large">{{ item }}</el-tag>
<div class="label">角色类型:</div> </el-form-item>
<div class="value" v-if="Array.isArray(prop.data.levels)"> <el-form-item label="应用渠道">
<el-tag class="ml-2" v-for="(item, index) in prop.data.levels" :key="index">{{ item }}</el-tag> <el-tag v-for="(item, index) in data.channels" :key="index" size="large">{{ item }}</el-tag>
</div> </el-form-item>
<div class="value" v-else>{{ prop.data.levels }}</div> </el-form>
</div>
<div class="item">
<div class="label">角色名称:</div>
<div class="value">
<el-tag>{{ prop.data.name }}</el-tag>
</div>
</div>
<div class="item">
<div class="label">应用项目:</div>
<div class="value" v-if="Array.isArray(prop.data.projects)">
<el-tag class="ml-2" v-for="(item, index) in prop.data.projects" :key="index">{{ item }}</el-tag>
</div>
<div class="value" v-else>{{ prop.data.projects }}</div>
</div>
<div class="item">
<div class="label">应用渠道:</div>
<div class="value" v-if="Array.isArray(prop.data.channels)">
<el-tag class="ml-2" v-for="(item, index) in prop.data.channels" :key="index">{{ item }}</el-tag>
</div>
<div class="value" v-else>{{ prop.data.channels }}</div>
</div>
</div>
<template #footer> <template #footer>
<span class="dialog-footer"> <el-button @click="$emit('update:modelValue', false)" auto-insert-space>关闭</el-button>
<el-button @click="emit('update:modelValue', false)">关闭</el-button>
</span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<style lang="scss"> <style lang="scss" scoped>
.dialogClass { .el-tag {
.el-dialog__body { margin-bottom: 10px;
padding: 10px 20px 20px; margin-right: 10px;
}
.info {
.item {
display: flex;
.label {
width: 110px;
display: inline-flex;
justify-content: flex-end;
align-items: flex-start;
flex: 0 0 auto;
font-size: 14px;
color: #969696;
height: 32px;
line-height: 32px;
box-sizing: border-box;
text-align: right;
}
.value {
font-size: 14px;
line-height: 32px;
.el-tag {
margin-top: 5px;
}
.ml-2 {
margin-right: 10px;
}
}
}
}
} }
</style> </style>
...@@ -6,4 +6,27 @@ export interface Info { ...@@ -6,4 +6,27 @@ export interface Info {
levels: string | string[] levels: string | string[]
projects: string | string[] projects: string | string[]
channels: string | string[] channels: string | string[]
} }
\ No newline at end of file
// 角色信息
export interface RoleInfo {
id: string
name: string
desc: string
user_count: number
created_at: string
updated_at: string
levels: string[]
members: RoleMember[]
}
// 角色成员
export interface RoleMember {
user_id: string
user_name: string
mobile: string
email: string
join_time: string
projects: string[]
channels: string[]
}
<script setup lang="ts"> <script setup lang="ts">
import AppList from '@/components/base/AppList.vue' import AppList from '@/components/base/AppList.vue'
import { getManagementDetail } from '../api' import { getManagementDetail } from '../api'
import type { Info } from '../types' import type { RoleInfo, RoleMember } from '../types'
const route = useRoute() const route = useRoute()
...@@ -9,17 +9,15 @@ const UserInfo = defineAsyncComponent(() => import('../components/UserInfo.vue') ...@@ -9,17 +9,15 @@ const UserInfo = defineAsyncComponent(() => import('../components/UserInfo.vue')
const appList = $ref<InstanceType<typeof AppList> | null>(null) const appList = $ref<InstanceType<typeof AppList> | null>(null)
let userInfoData: any = $ref() let roleInfo = $ref<RoleInfo>()
const listOptions = $computed(() => { const listOptions = $computed(() => {
return { return {
remote: { remote: {
httpRequest: getManagementDetail, httpRequest: getManagementDetail,
params: { params: { role_id: route.params.id },
role_id: route.params.id callback: (res: RoleInfo) => {
}, roleInfo = res
callback: (res: any) => {
userInfoData = res
return { list: res.members } return { list: res.members }
} }
}, },
...@@ -34,23 +32,25 @@ const listOptions = $computed(() => { ...@@ -34,23 +32,25 @@ const listOptions = $computed(() => {
}) })
// 查看 // 查看
let labelVisible = $ref(false) let viewVisible = $ref(false)
const currentRow = ref<Info>() let currentRow = $ref<RoleMember>()
function handleView(row: Info) { function handleView(row: RoleMember) {
row.name = userInfoData.name currentRow = row
row.levels = userInfoData.levels viewVisible = true
currentRow.value = row
labelVisible = true
} }
</script> </script>
<template> <template>
<AppCard title="用户信息"> <AppCard title="用户信息">
<AppList v-bind="listOptions" ref="appList"> <AppList v-bind="listOptions" ref="appList">
<template #table-x="{ row }: { row: Info }"> <template #table-x="{ row }: { row: RoleMember }">
<el-button text type="primary" @click="handleView(row)">查看详情</el-button> <el-button text type="primary" @click="handleView(row)">查看详情</el-button>
</template> </template>
</AppList> </AppList>
<UserInfo v-if="labelVisible && currentRow" v-model="labelVisible" :data="currentRow"></UserInfo> <UserInfo
v-if="viewVisible && roleInfo && currentRow"
v-model="viewVisible"
:role="roleInfo"
:data="currentRow"></UserInfo>
</AppCard> </AppCard>
</template> </template>
...@@ -10,17 +10,12 @@ const listOptions = $computed(() => { ...@@ -10,17 +10,12 @@ const listOptions = $computed(() => {
return { return {
remote: { remote: {
httpRequest: getManagementList, httpRequest: getManagementList,
params: { params: { user_name: '', mobile: '', email: '', role_name: '' }
user_name: '',
mobile: '',
email: '',
role_name: ''
}
}, },
filters: [ filters: [
{ type: 'input', prop: 'user_name', placeholder: '请输入用户姓名' }, { type: 'input', prop: 'user_name', placeholder: '请输入用户姓名' },
{ type: 'input', prop: 'mobile', placeholder: '请输入用户手机号' }, { type: 'input', prop: 'mobile', placeholder: '请输入用户手机号' },
{ type: 'input', prop: 'email', placeholder: '请输入角色邮箱' }, { type: 'input', prop: 'email', placeholder: '请输入用户邮箱' },
{ type: 'input', prop: 'role_name', placeholder: '请输入角色名称' } { type: 'input', prop: 'role_name', placeholder: '请输入角色名称' }
], ],
columns: [ columns: [
...@@ -29,20 +24,14 @@ const listOptions = $computed(() => { ...@@ -29,20 +24,14 @@ const listOptions = $computed(() => {
{ label: '包含用户数量', prop: 'user_count' }, { label: '包含用户数量', prop: 'user_count' },
{ label: '角色类型', prop: 'levels' }, { label: '角色类型', prop: 'levels' },
{ label: '更新时间', prop: 'updated_at' }, { label: '更新时间', prop: 'updated_at' },
{ label: '操作', prop: 'name', slots: 'table-x', width: 100 } { label: '操作', slots: 'table-x', width: 100 }
],
data: [
{ id: 1, code: 123 },
{ id: 2, code: 456 }
] ]
} }
}) })
// 查看 // 查看
function handleView(row: any) { function handleView(row: any) {
router.push({ router.push({ path: `/base/roles/detail/${row.id}` })
path: `/base/roles/detail/${row.id}`
})
} }
</script> </script>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论