提交 9596dca9 authored 作者: 王鹏飞's avatar 王鹏飞

refactor: 重构用户管理

上级 96a73e15
<script setup lang="ts"> <script setup lang="ts">
import type { UserInfo, UserProject, UserChannel } from '../types'
import { getMemberDetail } from '../api' import { getMemberDetail } from '../api'
const emit = defineEmits<{ const prop = defineProps<{ id: string }>()
(e: 'update:modelValue', visible: boolean): void
}>()
const prop = defineProps({ let userInfo = $ref<UserInfo>()
id: String function fetchInfo() {
}) getMemberDetail({ user_id: prop.id }).then(res => {
userInfo = res.data
interface Channels { })
channel_id: string
title: string
roles: string[]
} }
onMounted(() => {
interface Info { fetchInfo()
user_id: string
user_name: string
mobile: string
email: string
projects: [
{
title: string
project_id: string
roles: string[]
channels: Channels[]
}
]
}
let userInfo = $ref<Info>()
getMemberDetail({ user_id: prop.id }).then((res: any) => {
userInfo = res.data
console.log(userInfo, 'userInfouserInfo')
}) })
const projectValue = $ref() // 项目
const channelValue = $ref() const projectValue = $ref<UserProject>()
let projectRole = $ref<string[]>() // 渠道
let channelRole = $ref<string[]>() const channelValue = $ref<UserChannel>()
let channelsOption = $ref<Channels[]>()
// 项目渠道联动
const projectChange = function () {
const findData = userInfo.projects.find(item => item.project_id === projectValue)
if (findData) {
channelsOption = findData.channels
projectRole = findData.roles
}
}
// 选择渠道
const channelChange = function () {
const findData = channelsOption.find(item => item.channel_id === channelValue)
if (findData) {
channelRole = findData.roles
}
}
</script> </script>
<template> <template>
...@@ -80,47 +41,39 @@ const channelChange = function () { ...@@ -80,47 +41,39 @@ const channelChange = function () {
<div class="item"> <div class="item">
<div class="label">选择项目:</div> <div class="label">选择项目:</div>
<div class="value"> <div class="value">
<el-select @change="projectChange" v-model="projectValue" class="m-2" placeholder="选择项目" size="small"> <el-select v-model="projectValue" placeholder="选择项目" size="small" value-key="project_id">
<el-option <el-option v-for="item in userInfo.projects" :key="item.project_id" :label="item.title" :value="item" />
v-for="item in userInfo.projects"
:key="item.project_id"
:label="item.title"
:value="item.project_id"
/>
</el-select> </el-select>
</div> </div>
</div> </div>
<div class="item"> <div class="item">
<div class="label">角色权限:</div> <div class="label">角色权限:</div>
<div v-for="(item, index) in projectRole" :key="index" class="value" style="margin-right: 10px"> <div v-for="(item, index) in projectValue?.roles" :key="index" class="value" style="margin-right: 10px">
<el-tag>{{ item }}</el-tag> <el-tag>{{ item }}</el-tag>
</div> </div>
</div> </div>
<div class="item mt-20"> <div class="item mt-20">
<div class="label">选择渠道:</div> <div class="label">选择渠道:</div>
<div class="value"> <div class="value">
<el-select @change="channelChange" v-model="channelValue" class="m-2" placeholder="选择渠道" size="small"> <el-select v-model="channelValue" placeholder="选择渠道" size="small" value-key="channel_id">
<el-option <el-option
v-for="item in channelsOption" v-for="item in projectValue?.channels"
:key="item.channel_id" :key="item.channel_id"
:label="item.title" :label="item.title"
:value="item.channel_id" :value="item" />
/>
</el-select> </el-select>
</div> </div>
</div> </div>
<div class="item"> <div class="item">
<div class="label">角色权限:</div> <div class="label">角色权限:</div>
<div v-for="(item, index) in channelRole" :key="index" class="value" style="margin-right: 10px"> <div v-for="(item, index) in channelValue?.roles" :key="index" class="value" style="margin-right: 10px">
<el-tag>{{ item }}</el-tag> <el-tag>{{ item }}</el-tag>
</div> </div>
</div> </div>
</div> </div>
</el-card> </el-card>
<template #footer> <template #footer>
<span class="dialog-footer"> <el-button @click="$emit('update:modelValue', false)">关闭</el-button>
<el-button @click="emit('update:modelValue', false)">关闭</el-button>
</span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
......
export interface UserItem {
email: string
mobile: string
roles_count: number
user_id: string
user_name: string
}
export interface UserProject {
project_id: string
title: string
channels: UserChannel[]
roles: string[]
}
export interface UserChannel {
channel_id: string
title: string
projects: string[]
roles: string[]
}
export type UserInfo = UserItem & { projects: UserProject[] }
<script setup lang="ts"> <script setup lang="ts">
import type { UserItem } from '../types'
import AppList from '@/components/base/AppList.vue' import AppList from '@/components/base/AppList.vue'
import { getMemberList } from '../api' import { getMemberList } from '../api'
...@@ -35,19 +36,19 @@ const listOptions = $computed(() => { ...@@ -35,19 +36,19 @@ const listOptions = $computed(() => {
}) })
// 查看 // 查看
let labelVisible = $ref(false) let viewVisible = $ref(false)
let currentRowId = $ref('') let currentRow = $ref<UserItem>()
function handleView(row: any) { function handleView(row: UserItem) {
currentRowId = row.user_id currentRow = row
labelVisible = true viewVisible = true
} }
</script> </script>
<template> <template>
<AppCard title="用户管理"> <AppCard title="用户管理">
<AppList v-bind="listOptions" ref="appList"> <AppList v-bind="listOptions" ref="appList">
<UserInfo v-if="currentRowId && labelVisible" v-model="labelVisible" :id="currentRowId"></UserInfo> <UserInfo v-model="viewVisible" :id="currentRow.user_id" v-if="viewVisible && currentRow"></UserInfo>
<template #table-x="{ row }"> <template #table-x="{ row }: { row: UserItem }">
<el-button text type="primary" @click="handleView(row)">查看</el-button> <el-button text type="primary" @click="handleView(row)">查看</el-button>
</template> </template>
</AppList> </AppList>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论