This commit is contained in:
yin 2026-03-31 09:15:36 +08:00
parent 6b2c2f9f16
commit 884cee76e7
13 changed files with 573 additions and 145 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 KiB

58
src/api/dashboard.ts Normal file
View File

@ -0,0 +1,58 @@
import request from '@/utils/request'
const v = "1.0"
export function getDashboardData(method: string, data: any) {
return request({
url: '/system',
method: 'post',
params: {
method,
v,
timestamp: new Date().getTime()
},
data: data,
isSystemApi: true
} as any)
}
/**
* 获取仓库基础统计数据
*/
export function getWarehouseStats(data: any = {}) {
return getDashboardData('dashboard.warehouseStats', data)
}
/**
* 获取门店基础统计数据
*/
export function getStoreStats(data: any = {}) {
return getDashboardData('dashboard.storeStats', data)
}
/**
* 获取订单趋势数据
*/
export function getOrderTrend(data: any = {}) {
return getDashboardData('dashboard.orderTrend', data)
}
/**
* 获取平台分布数据
*/
export function getPlatformDist(data: any = {}) {
return getDashboardData('dashboard.platformDist', data)
}
/**
* 获取商品排行数据
*/
export function getHotOrderRank(data: any = {}) {
return getDashboardData('dashboard.hotOrderRank', data)
}
/**
* 获取快递占比数据
*/
export function getExpressRatio(data: any = {}) {
return getDashboardData('dashboard.expressRatio', data)
}

67
src/api/setting/role.ts Normal file
View File

@ -0,0 +1,67 @@
import request from '@/utils/request'
const v = "1.0";
/**
* 查询当前主体可分配角色列表,可选返回指定工号已选角色
*/
export function roleList(data: { employee_id?: number, includeDisabled?: boolean, includeSystem?: boolean }) {
return request({
url: '/system',
method: 'post',
params: {
method: 'setting.role.list',
v,
timestamp: new Date().getTime(),
},
data
})
}
/**
* 给工号新增单个角色绑定
*/
export function roleAdd(data: { employee_id: number, role_id: number }) {
return request({
url: '/system',
method: 'post',
params: {
method: 'setting.role.add',
v,
timestamp: new Date().getTime()
},
data
})
}
/**
* 删除工号单个角色绑定
*/
export function roleDelete(data: { employee_id: number, role_id: number }) {
return request({
url: '/system',
method: 'post',
params: {
method: 'setting.role.delete',
v,
timestamp: new Date().getTime()
},
data
})
}
/**
* 批量重置工号角色绑定
*/
export function roleUpdate(data: { employee_id: number, role_ids: number[] }) {
return request({
url: '/system',
method: 'post',
params: {
method: 'setting.role.update',
v,
timestamp: new Date().getTime()
},
data
})
}

View File

@ -45,11 +45,23 @@ defineExpose({
position: relative; position: relative;
overflow: hidden; overflow: hidden;
width: 100%; width: 100%;
height: 100%;
:deep(.el-scrollbar__bar) { :deep(.el-scrollbar__bar) {
bottom: 0px; bottom: 0px;
height: 4px;
} }
:deep(.el-scrollbar__wrap) { :deep(.el-scrollbar__wrap) {
height: 55px; height: 30px;
overflow-x: auto;
overflow-y: hidden;
}
:deep(.el-scrollbar__view) {
height: 30px;
display: flex;
align-items: center;
} }
} }
</style> </style>

View File

@ -272,72 +272,81 @@ onMounted(() => {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
// background: #fafafa; background: #fff;
// border-top: 1px solid #eee; border-bottom: 1px solid #f0f2f5;
border-bottom: 1px solid #eee;
cursor: pointer; cursor: pointer;
font-size: 12px; font-size: 14px;
color: #000000; color: #909399;
transition: all 0.3s;
&:hover { &:hover {
// background: #f0f2f5; background: #f5f7fa;
// color: #409EFF; color: #409EFF;
} }
} }
.tags-view-wrapper { .tags-view-wrapper {
height: 32px; height: 35px;
// border-bottom: 1px solid #d8dce5; width: 100%;
// background-color: #e0dbdb; background: #f0f2f5;
border-bottom: 1px solid #d8dce5;
.tags-view-item { .tags-view-item {
display: inline-block; display: inline-block;
position: relative; position: relative;
cursor: pointer; cursor: pointer;
height: 26px; height: 26px;
line-height: 26px; line-height: 26px;
// border: 1px solid #d8dce5; border: 1px solid #d8dce5;
color: #495060; color: #495060;
background: #b8b5b5; background: #fff;
padding: 0 10px; padding: 0 12px;
font-size: 12px; font-size: 12px;
margin-left: 5px; margin-left: 6px;
margin-top: 3px; // margin-top: 5px; // 移除 margin-top,改用 flex 居中
border-radius: 3px;
text-decoration: none; text-decoration: none;
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
&:first-of-type { &:first-of-type {
margin-left: 15px; margin-left: 15px;
} }
&:last-of-type { &:last-of-type {
margin-right: 15px; margin-right: 15px;
} }
&:hover {
background-color: #f6f6f6;
border-color: #b4bccc;
}
&.active { &.active {
background-color: #42b983; background-color: #42b983;
color: #fff; color: #fff;
// border-color: #42b983; border-color: #42b983;
&::before { &::before {
content: ''; content: "";
background: #fff; background: #fff;
display: inline-block; display: inline-block;
width: 8px; width: 8px;
height: 8px; height: 8px;
border-radius: 50%; border-radius: 50%;
position: relative; position: relative;
margin-right: 2px; margin-right: 4px;
} }
} }
.close-icon { .close-icon {
width: 16px; width: 16px;
height: 16px; height: 16px;
vertical-align: 2px; line-height: 14px;
vertical-align: middle;
border-radius: 50%; border-radius: 50%;
text-align: center; text-align: center;
transition: all .3s cubic-bezier(.645, .045, .355, 1); transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
transform-origin: 100% 50%; transform-origin: 100% 50%;
margin-left: 5px; margin-left: 5px;
&:before { font-size: 12px;
transform: scale(.6);
display: inline-block;
vertical-align: -3px;
}
&:hover { &:hover {
background-color: #b4bccc; background-color: #b4bccc;
color: #fff; color: #fff;

View File

@ -4,24 +4,14 @@
<div class="module-header"> <div class="module-header">
<span class="module-title">{{ title }}</span> <span class="module-title">{{ title }}</span>
<div class="module-actions"> <div class="module-actions">
<el-button <el-button type="primary" link :icon="Refresh" :loading="loading" @click="refreshData" />
type="primary"
link
:icon="Refresh"
:loading="loading"
@click="refreshData"
/>
</div> </div>
</div> </div>
</template> </template>
<div class="module-content"> <div class="module-content">
<div v-if="error" class="error-message"> <div v-if="error" class="error-message">
<el-alert <el-alert :title="error" type="error" :closable="false" />
:title="error"
type="error"
:closable="false"
/>
</div> </div>
<div v-else> <div v-else>
@ -38,12 +28,8 @@
<div class="rank-cell rank-trend">{{ $t('dashboard.trend') }}</div> <div class="rank-cell rank-trend">{{ $t('dashboard.trend') }}</div>
</div> </div>
<div <div v-for="(item, index) in rankData" :key="item.id || index" class="rank-item"
v-for="(item, index) in rankData" @click="handleRankClick(item)">
:key="item.id || index"
class="rank-item"
@click="handleRankClick(item)"
>
<div class="rank-cell rank-index"> <div class="rank-cell rank-index">
<div :class="['rank-badge', getRankClass(Number(index) + 1)]"> <div :class="['rank-badge', getRankClass(Number(index) + 1)]">
{{ Number(index) + 1 }} {{ Number(index) + 1 }}
@ -73,12 +59,7 @@
</div> </div>
<div class="module-footer"> <div class="module-footer">
<el-button <el-button type="primary" link size="small" @click="viewAll">
type="primary"
link
size="small"
@click="viewAll"
>
{{ $t('dashboard.viewAll') }} {{ $t('dashboard.viewAll') }}
</el-button> </el-button>
</div> </div>
@ -166,7 +147,8 @@ onMounted(() => {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-height: 0; /* Important for nested flex scroll */ min-height: 0;
/* Important for nested flex scroll */
} }
.module-header { .module-header {
@ -282,7 +264,8 @@ onMounted(() => {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 2px; gap: 2px;
overflow: hidden; /* Ensure text truncation works */ overflow: hidden;
/* Ensure text truncation works */
} }
.product-name { .product-name {
@ -328,7 +311,8 @@ onMounted(() => {
padding: 12px 20px; padding: 12px 20px;
border-top: 1px solid #ebeef5; border-top: 1px solid #ebeef5;
text-align: center; text-align: center;
margin-top: auto; /* Push to bottom */ margin-top: auto;
/* Push to bottom */
} }
@media (max-width: 768px) { @media (max-width: 768px) {

View File

@ -198,15 +198,6 @@ const handleDataSuccess = (apiData: any) => {
let orders: any[] = [] let orders: any[] = []
let shipments: any[] = [] let shipments: any[] = []
// Check if data is nested inside `data` property (common in some backends)
// or if it's the direct payload.
// Based on mixin, `handleDataSuccess(data.data)` was called.
// So `apiData` here is the payload.
// However, in Vue 2 OrderTrend, it did `const apiData = data.data` again?
// If so, then `apiData` passed to this function might need another unwrap?
// Let's assume standard payload structure.
const payload = apiData const payload = apiData
if (dateRange.value === 'day') { if (dateRange.value === 'day') {

View File

@ -0,0 +1,69 @@
import { defineAsyncComponent } from 'vue'
// Module Permissions Mapping
export const MODULE_PERMISSIONS = {
WAREHOUSE_BASE: 'dashboard.warehouseBaseData',
STORE_BASE: 'dashboard.storeBaseData',
ORDER_TREND: 'dashboard.orderTrend',
PLATFORM_DISTRIBUTION: 'dashboard.platformDist',
HOT_ORDER_RANK: 'dashboard.hotOrderRank',
EXPRESS_RATIO: 'dashboard.expressRatio',
}
// Dynamic Components Map
export const moduleComponents: Record<string, any> = {
StatsCardsWarehouse: defineAsyncComponent(() => import('../components/StatsCardsWarehouse.vue')),
StatsCardsStore: defineAsyncComponent(() => import('../components/StatsCardsStore.vue')),
OrderTrend: defineAsyncComponent(() => import('../components/OrderTrend.vue')),
PlatformDistribution: defineAsyncComponent(() => import('../components/PlatformDistribution.vue')),
HotOrderRank: defineAsyncComponent(() => import('../components/HotOrderRank.vue')),
ExpressRatio: defineAsyncComponent(() => import('../components/ExpressRatio.vue')),
}
export interface DashboardModule {
name: string
component: string
titleKey: string
colSpan?: number
props?: Record<string, any>
}
// Static definitions without i18n functions directly (to be used with t() in component)
export const RAW_MODULE_CONFIGS: Record<string, DashboardModule> = {
[MODULE_PERMISSIONS.WAREHOUSE_BASE]: {
name: 'StatsCardsWarehouse',
component: 'StatsCardsWarehouse',
titleKey: 'dashboard.warehouseStatistics',
colSpan: 3
},
[MODULE_PERMISSIONS.STORE_BASE]: {
name: 'StatsCardsStore',
component: 'StatsCardsStore',
titleKey: 'dashboard.storeStatistics',
colSpan: 3
},
[MODULE_PERMISSIONS.ORDER_TREND]: {
name: 'OrderTrend',
component: 'OrderTrend',
titleKey: 'dashboard.orderTrend',
colSpan: 2
},
[MODULE_PERMISSIONS.PLATFORM_DISTRIBUTION]: {
name: 'PlatformDistribution',
component: 'PlatformDistribution',
titleKey: 'dashboard.platformDistribution',
colSpan: 1
},
[MODULE_PERMISSIONS.HOT_ORDER_RANK]: {
name: 'HotOrderRank',
component: 'HotOrderRank',
titleKey: 'dashboard.hotOrderRank',
colSpan: 2
},
[MODULE_PERMISSIONS.EXPRESS_RATIO]: {
name: 'ExpressRatio',
component: 'ExpressRatio',
titleKey: 'dashboard.expressRatio',
colSpan: 1
}
}

View File

@ -1,6 +1,6 @@
import { ref, onMounted, onBeforeUnmount, unref } from 'vue' import { ref, onMounted, onBeforeUnmount, unref } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import request from '@/utils/request' import { getDashboardData } from '@/api/dashboard'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
export function useDashboard(props: { method: string; queryParams?: any }) { export function useDashboard(props: { method: string; queryParams?: any }) {
@ -18,18 +18,8 @@ export function useDashboard(props: { method: string; queryParams?: any }) {
error.value = null error.value = null
try { try {
// Use the request utility directly as in Vue 2 mixin // Use the dashboard api utility
const res: any = await request({ const res: any = await getDashboardData(props.method, unref(props.queryParams) || {})
url: '/system',
method: 'post',
params: {
method: props.method,
v: '1.0',
timestamp: new Date().getTime()
},
data: unref(props.queryParams) || {},
// isSystemApi: true // Not sure if this flag is needed in Vue 3 request util, removing for now
})
if (res.code === 200) { if (res.code === 200) {
data.value = res.data data.value = res.data

View File

@ -22,11 +22,12 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, onBeforeUnmount, watch, defineAsyncComponent } from 'vue' import { ref, computed, onMounted, onBeforeUnmount, watch } from 'vue'
import { useUserStore } from '@/stores/modules/user' import { useUserStore } from '@/stores/modules/user'
import WelcomCard from './components/WelcomCard.vue' import WelcomCard from './components/WelcomCard.vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { useI18n } from 'vue-i18n' import { useI18n } from 'vue-i18n'
import { MODULE_PERMISSIONS, moduleComponents, RAW_MODULE_CONFIGS } from './composables/dashboard-config'
const userStore = useUserStore() const userStore = useUserStore()
const { t } = useI18n() const { t } = useI18n()
@ -40,71 +41,22 @@ const checkPermission = (key: string) => {
const windowWidth = ref(window.innerWidth) const windowWidth = ref(window.innerWidth)
const currentTime = ref(dayjs().format('YYYY-MM-DD HH:mm:ss')) const currentTime = ref(dayjs().format('YYYY-MM-DD HH:mm:ss'))
const accessibleModules = ref<any[]>([]) const accessibleModules = ref<any[]>([])
// Dynamic Components Map
const moduleComponents: Record<string, any> = {
StatsCardsWarehouse: defineAsyncComponent(() => import('./components/StatsCardsWarehouse.vue')),
StatsCardsStore: defineAsyncComponent(() => import('./components/StatsCardsStore.vue')),
OrderTrend: defineAsyncComponent(() => import('./components/OrderTrend.vue')),
PlatformDistribution: defineAsyncComponent(() => import('./components/PlatformDistribution.vue')),
HotOrderRank: defineAsyncComponent(() => import('./components/HotOrderRank.vue')),
ExpressRatio: defineAsyncComponent(() => import('./components/ExpressRatio.vue')),
}
// Module Permissions Mapping // Module Configs computed with i18n
const MODULE_PERMISSIONS = { const MODULE_CONFIGS = computed(() => {
WAREHOUSE_BASE: 'dashboard.warehouseBaseData', const configs: Record<string, any> = {}
STORE_BASE: 'dashboard.storeBaseData', Object.keys(RAW_MODULE_CONFIGS).forEach(key => {
ORDER_TREND: 'dashboard.orderTrend', const raw = RAW_MODULE_CONFIGS[key]
PLATFORM_DISTRIBUTION: 'dashboard.platformDist', if (raw) {
HOT_ORDER_RANK: 'dashboard.hotOrderRank', configs[key] = {
EXPRESS_RATIO: 'dashboard.expressRatio', ...raw,
title: t(raw.titleKey),
props: { ...(raw.props || {}), title: t(raw.titleKey) }
} }
// Module Configs
const MODULE_CONFIGS = computed<Record<string, any>>(() => ({
[MODULE_PERMISSIONS.WAREHOUSE_BASE]: {
name: 'StatsCardsWarehouse',
component: 'StatsCardsWarehouse',
title: t('dashboard.warehouseStatistics'),
props: { title: t('dashboard.warehouseStatistics') },
colSpan: 3
},
[MODULE_PERMISSIONS.STORE_BASE]: {
name: 'StatsCardsStore',
component: 'StatsCardsStore',
title: t('dashboard.storeStatistics'),
props: { title: t('dashboard.storeStatistics') },
colSpan: 3
},
[MODULE_PERMISSIONS.ORDER_TREND]: {
name: 'OrderTrend',
component: 'OrderTrend',
title: t('dashboard.orderTrend'),
props: { title: t('dashboard.orderTrend') },
colSpan: 2
},
[MODULE_PERMISSIONS.PLATFORM_DISTRIBUTION]: {
name: 'PlatformDistribution',
component: 'PlatformDistribution',
title: t('dashboard.platformDistribution'),
props: { title: t('dashboard.platformDistribution') },
colSpan: 1
},
[MODULE_PERMISSIONS.HOT_ORDER_RANK]: {
name: 'HotOrderRank',
component: 'HotOrderRank',
title: t('dashboard.hotOrderRank'),
props: { title: t('dashboard.hotOrderRank') },
colSpan: 2
},
[MODULE_PERMISSIONS.EXPRESS_RATIO]: {
name: 'ExpressRatio',
component: 'ExpressRatio',
title: t('dashboard.expressRatio'),
props: { title: t('dashboard.expressRatio') },
colSpan: 1
} }
})) })
return configs
})
const getAccessibleModules = (perms: string[]) => { const getAccessibleModules = (perms: string[]) => {
const configs = MODULE_CONFIGS.value const configs = MODULE_CONFIGS.value
@ -134,9 +86,15 @@ const getAccessibleModules = (perms: string[]) => {
const prioritized = [ const prioritized = [
MODULE_PERMISSIONS.WAREHOUSE_BASE, MODULE_PERMISSIONS.WAREHOUSE_BASE,
MODULE_PERMISSIONS.ORDER_TREND, MODULE_PERMISSIONS.ORDER_TREND,
MODULE_PERMISSIONS.PLATFORM_DISTRIBUTION MODULE_PERMISSIONS.PLATFORM_DISTRIBUTION,
MODULE_PERMISSIONS.EXPRESS_RATIO // Also prioritized but handled below
] ]
// Direct addition of Express Ratio (no permission check)
if (configs[MODULE_PERMISSIONS.EXPRESS_RATIO]) {
modules.push({ ...configs[MODULE_PERMISSIONS.EXPRESS_RATIO] })
}
Object.keys(configs).forEach(permission => { Object.keys(configs).forEach(permission => {
if (prioritized.includes(permission)) return if (prioritized.includes(permission)) return

View File

@ -6,7 +6,7 @@ export const accountColumns = [
{ label: '用户名', prop: 'username', width: 120 }, { label: '用户名', prop: 'username', width: 120 },
{ label: '邮箱', prop: 'email', minWidth: 150 }, { label: '邮箱', prop: 'email', minWidth: 150 },
{ label: '状态', prop: 'status', width: 100 }, { label: '状态', prop: 'status', width: 100 },
{ label: '操作', prop: 'actions', width: 200, fixed: 'right' } { label: '操作', prop: 'actions', width: 280, fixed: 'right' }
] ]
export const defaultTemp = { export const defaultTemp = {

View File

@ -36,6 +36,7 @@
</template> </template>
<template #column-actions="{ row }"> <template #column-actions="{ row }">
<el-button type="primary" size="small" icon="Edit" @click="handleUpdate(row)">编辑</el-button> <el-button type="primary" size="small" icon="Edit" @click="handleUpdate(row)">编辑</el-button>
<el-button type="success" size="small" icon="User" @click="handleAssignRole(row)">分配角色</el-button>
<el-button v-if="row.status === 1" type="danger" size="small" icon="Delete" @click="handleDelete(row)">停用</el-button> <el-button v-if="row.status === 1" type="danger" size="small" icon="Delete" @click="handleDelete(row)">停用</el-button>
</template> </template>
</upper-table> </upper-table>
@ -98,12 +99,55 @@
</div> </div>
</template> </template>
</el-dialog> </el-dialog>
<!-- 角色分配弹窗 -->
<el-dialog title="分配角色" v-model="roleDialogVisible" width="600px" top="10vh">
<div v-loading="roleLoading" class="role-tree-container">
<el-tree
ref="roleTreeRef"
:data="allRoles"
:props="defaultProps"
show-checkbox
node-key="role_id"
default-expand-all
:default-checked-keys="selectedRoleIds"
check-strictly
>
<template #default="{ node, data }">
<span class="custom-tree-node">
<span>{{ node.label }}</span>
<span class="role-desc">
({{ data.description || (data.is_system === 1 ? '系统默认' : '停用') }})
</span>
<el-button
v-if="data.selected"
type="danger"
link
size="small"
icon="Delete"
class="delete-role-btn"
@click.stop="handleRemoveSingleRole(data)"
>
移除
</el-button>
</span>
</template>
</el-tree>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="roleDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="roleSubmitting" @click="submitRoleUpdate">确认改动</el-button>
</div>
</template>
</el-dialog>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted, reactive } from 'vue' import { ref, onMounted, reactive } from 'vue'
import { accountList, accountAdd, accountUpdate, accountdelete } from '@/api/setting/account' import { accountList, accountAdd, accountUpdate, accountdelete } from '@/api/setting/account'
import { roleList, roleUpdate, roleDelete } from '@/api/setting/role'
import UpperTable from '@/components/UpperTable/index.vue' import UpperTable from '@/components/UpperTable/index.vue'
import ImagesUpload from '@/components/ImagesUpload/index.vue' import ImagesUpload from '@/components/ImagesUpload/index.vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
@ -159,8 +203,8 @@ const handleCreate = () => {
const createData = async () => { const createData = async () => {
try { try {
const { phone, real_name, username, password,email } = temp const { phone, real_name, email } = temp
await accountAdd({ phone, real_name, username, password, email }) await accountAdd({ phone, real_name, email })
dialogFormVisible.value = false dialogFormVisible.value = false
ElMessage.success('创建成功') ElMessage.success('创建成功')
getList() getList()
@ -208,6 +252,105 @@ const handleAvatarSuccess = (res: any) => {
temp.avatar_url = res.url temp.avatar_url = res.url
} }
// ---------------- 角色分配相关 ----------------
const roleDialogVisible = ref(false)
const roleLoading = ref(false)
const roleSubmitting = ref(false)
const allRoles = ref<any[]>([])
const selectedRoleIds = ref<number[]>([])
const currentEmployeeId = ref<number | null>(null)
const roleTreeRef = ref()
const defaultProps = {
children: 'children',
label: 'role_name'
}
// 递归提取已选中的角色ID
const extractSelectedRoleIds = (roles: any[]) => {
let ids: number[] = []
roles.forEach(role => {
if (role.selected) {
ids.push(role.role_id)
}
if (role.children && role.children.length > 0) {
ids = ids.concat(extractSelectedRoleIds(role.children))
}
})
return ids
}
const handleAssignRole = async (row: any) => {
currentEmployeeId.value = row.employee_id
roleDialogVisible.value = true
roleLoading.value = true
try {
const res = await roleList({ employee_id: row.employee_id, includeDisabled: false, includeSystem: true })
if (res.data && res.data.roles) {
allRoles.value = res.data.roles
selectedRoleIds.value = extractSelectedRoleIds(res.data.roles)
// 更新树的选中状态
if (roleTreeRef.value) {
roleTreeRef.value.setCheckedKeys(selectedRoleIds.value)
}
}
} catch (error) {
console.error(error)
} finally {
roleLoading.value = false
}
}
const handleRemoveSingleRole = (role: any) => {
if (!currentEmployeeId.value) return
ElMessageBox.confirm(`确认移除该用户拥有的角色 [${role.role_name}] 吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
try {
await roleDelete({
employee_id: currentEmployeeId.value!,
role_id: role.role_id
})
ElMessage.success('移除成功')
// 重新加载当前用户的角色状态
const res = await roleList({ employee_id: currentEmployeeId.value!, includeDisabled: false, includeSystem: true })
if (res.data && res.data.roles) {
allRoles.value = res.data.roles
selectedRoleIds.value = extractSelectedRoleIds(res.data.roles)
if (roleTreeRef.value) {
roleTreeRef.value.setCheckedKeys(selectedRoleIds.value)
}
}
} catch (error) {
console.error(error)
}
})
}
const submitRoleUpdate = async () => {
if (!currentEmployeeId.value) return
// 获取树中选中的节点 key
const checkedKeys = roleTreeRef.value ? roleTreeRef.value.getCheckedKeys() : []
if (!checkedKeys.length) {
ElMessage.warning('至少需要分配一个角色')
return
}
roleSubmitting.value = true
try {
await roleUpdate({ employee_id: currentEmployeeId.value, role_ids: checkedKeys })
ElMessage.success('角色分配成功')
roleDialogVisible.value = false
} catch (error) {
console.error(error)
} finally {
roleSubmitting.value = false
}
}
onMounted(() => { onMounted(() => {
getList() getList()
}) })
@ -251,4 +394,31 @@ onMounted(() => {
overflow-y: auto; overflow-y: auto;
} }
} }
.role-tree-container {
max-height: 400px;
overflow-y: auto;
border: 1px solid #ebeef5;
padding: 10px;
border-radius: 4px;
}
.custom-tree-node {
flex: 1;
display: flex;
align-items: center;
font-size: 14px;
.role-desc {
margin-left: 8px;
color: #999;
font-size: 12px;
}
.delete-role-btn {
margin-left: auto;
margin-right: 15px;
padding: 0;
}
}
</style> </style>

120
src/接口文档.txt Normal file
View File

@ -0,0 +1,120 @@
工号角色管理模块
所有请求为Post请求,请求Body为JSON格式
setting.role.list
查询当前主体可分配角色列表,可选返回指定工号已选角色
employee_id number 否 可选,传入后返回该工号的角色选中状态
includeDisabled boolean 否 是否包含停用角色,默认 false
includeSystem boolean 否 是否包含系统默认角色(store_id=0/null),默认 true
接口响应:
{
"flag": "success",
"code": 200,
"message": "ok",
"data": {
"employee_id": 34,
"roles": [
{
"role_id": 2,
"role_code": "warehouse_admin_default",
"role_name": "仓库管理员",
"description": "仓库全部权限",
"role_type": 1,
"scope": 1,
"is_system": 1,
"status": 1,
"store_id": null,
"pid": 0,
"selected": true,
"children": [
{
"role_id": 8,
"role_code": "2",
"role_name": "仓库经理",
"description": "仓库经理权限",
"role_type": 1,
"scope": 1,
"is_system": 0,
"status": 1,
"store_id": 1000028,
"pid": 2,
"selected": false,
"children": []
}
]
},
{
"role_id": 5,
"role_code": "store_admin_default",
"role_name": "货主管理员",
"description": "货主全部权限",
"role_type": 1,
"scope": 1,
"is_system": 1,
"status": 1,
"store_id": null,
"pid": 0,
"selected": false,
"children": []
},
{
"role_id": 7,
"role_code": "1",
"role_name": "超级管理员",
"description": "系统管理权限",
"role_type": 1,
"scope": 1,
"is_system": 1,
"status": 1,
"store_id": null,
"pid": 0,
"selected": false,
"children": []
}
]
},
"timestamp": 1774861907
}
setting.role.add
给工号新增单个角色绑定
employee_id number 是 工号ID
role_id number 是 角色ID
接口响应:
待补充
setting.role.delete
删除工号单个角色绑定
employee_id number 是 工号ID
role_id number 是 角色ID
接口响应:
待补充
setting.role.update
批量重置工号角色绑定
employee_id number 是 工号ID
role_ids number[] 是 目标角色ID列表,至少包含 1 个角色
接口响应:
待补充