3月30
This commit is contained in:
parent
6b2c2f9f16
commit
884cee76e7
BIN
src/20260330145422_131_70.jpg
Normal file
BIN
src/20260330145422_131_70.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 436 KiB |
58
src/api/dashboard.ts
Normal file
58
src/api/dashboard.ts
Normal 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
67
src/api/setting/role.ts
Normal 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
|
||||
})
|
||||
}
|
||||
@ -45,11 +45,23 @@ defineExpose({
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
:deep(.el-scrollbar__bar) {
|
||||
bottom: 0px;
|
||||
height: 4px;
|
||||
}
|
||||
|
||||
: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>
|
||||
|
||||
@ -272,72 +272,81 @@ onMounted(() => {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
// background: #fafafa;
|
||||
// border-top: 1px solid #eee;
|
||||
border-bottom: 1px solid #eee;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #f0f2f5;
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
color: #000000;
|
||||
font-size: 14px;
|
||||
color: #909399;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
// background: #f0f2f5;
|
||||
// color: #409EFF;
|
||||
background: #f5f7fa;
|
||||
color: #409EFF;
|
||||
}
|
||||
}
|
||||
|
||||
.tags-view-wrapper {
|
||||
height: 32px;
|
||||
// border-bottom: 1px solid #d8dce5;
|
||||
// background-color: #e0dbdb;
|
||||
height: 35px;
|
||||
width: 100%;
|
||||
background: #f0f2f5;
|
||||
border-bottom: 1px solid #d8dce5;
|
||||
|
||||
.tags-view-item {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
height: 26px;
|
||||
line-height: 26px;
|
||||
// border: 1px solid #d8dce5;
|
||||
border: 1px solid #d8dce5;
|
||||
color: #495060;
|
||||
background: #b8b5b5;
|
||||
padding: 0 10px;
|
||||
background: #fff;
|
||||
padding: 0 12px;
|
||||
font-size: 12px;
|
||||
margin-left: 5px;
|
||||
margin-top: 3px;
|
||||
margin-left: 6px;
|
||||
// margin-top: 5px; // 移除 margin-top,改用 flex 居中
|
||||
border-radius: 3px;
|
||||
text-decoration: none;
|
||||
transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
|
||||
|
||||
&:first-of-type {
|
||||
margin-left: 15px;
|
||||
}
|
||||
&:last-of-type {
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: #f6f6f6;
|
||||
border-color: #b4bccc;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #42b983;
|
||||
color: #fff;
|
||||
// border-color: #42b983;
|
||||
border-color: #42b983;
|
||||
&::before {
|
||||
content: '';
|
||||
content: "";
|
||||
background: #fff;
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
position: relative;
|
||||
margin-right: 2px;
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
.close-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
vertical-align: 2px;
|
||||
line-height: 14px;
|
||||
vertical-align: middle;
|
||||
border-radius: 50%;
|
||||
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%;
|
||||
margin-left: 5px;
|
||||
&:before {
|
||||
transform: scale(.6);
|
||||
display: inline-block;
|
||||
vertical-align: -3px;
|
||||
}
|
||||
font-size: 12px;
|
||||
|
||||
&:hover {
|
||||
background-color: #b4bccc;
|
||||
color: #fff;
|
||||
|
||||
@ -4,24 +4,14 @@
|
||||
<div class="module-header">
|
||||
<span class="module-title">{{ title }}</span>
|
||||
<div class="module-actions">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
:icon="Refresh"
|
||||
:loading="loading"
|
||||
@click="refreshData"
|
||||
/>
|
||||
<el-button type="primary" link :icon="Refresh" :loading="loading" @click="refreshData" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="module-content">
|
||||
<div v-if="error" class="error-message">
|
||||
<el-alert
|
||||
:title="error"
|
||||
type="error"
|
||||
:closable="false"
|
||||
/>
|
||||
<el-alert :title="error" type="error" :closable="false" />
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
@ -38,15 +28,11 @@
|
||||
<div class="rank-cell rank-trend">{{ $t('dashboard.trend') }}</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="(item, index) in rankData"
|
||||
:key="item.id || index"
|
||||
class="rank-item"
|
||||
@click="handleRankClick(item)"
|
||||
>
|
||||
<div v-for="(item, index) in rankData" :key="item.id || index" class="rank-item"
|
||||
@click="handleRankClick(item)">
|
||||
<div class="rank-cell rank-index">
|
||||
<div :class="['rank-badge', getRankClass(Number(index) + 1)]">
|
||||
{{ Number(index) + 1 }}
|
||||
{{ Number(index) + 1 }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rank-cell rank-name">
|
||||
@ -73,12 +59,7 @@
|
||||
</div>
|
||||
|
||||
<div class="module-footer">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
size="small"
|
||||
@click="viewAll"
|
||||
>
|
||||
<el-button type="primary" link size="small" @click="viewAll">
|
||||
{{ $t('dashboard.viewAll') }}
|
||||
</el-button>
|
||||
</div>
|
||||
@ -166,7 +147,8 @@ onMounted(() => {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0; /* Important for nested flex scroll */
|
||||
min-height: 0;
|
||||
/* Important for nested flex scroll */
|
||||
}
|
||||
|
||||
.module-header {
|
||||
@ -282,7 +264,8 @@ onMounted(() => {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
overflow: hidden; /* Ensure text truncation works */
|
||||
overflow: hidden;
|
||||
/* Ensure text truncation works */
|
||||
}
|
||||
|
||||
.product-name {
|
||||
@ -328,7 +311,8 @@ onMounted(() => {
|
||||
padding: 12px 20px;
|
||||
border-top: 1px solid #ebeef5;
|
||||
text-align: center;
|
||||
margin-top: auto; /* Push to bottom */
|
||||
margin-top: auto;
|
||||
/* Push to bottom */
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
|
||||
@ -197,15 +197,6 @@ const handleDataSuccess = (apiData: any) => {
|
||||
let categories: any[] = []
|
||||
let orders: 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
|
||||
|
||||
|
||||
69
src/views/dashboard/composables/dashboard-config.ts
Normal file
69
src/views/dashboard/composables/dashboard-config.ts
Normal 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
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
import { ref, onMounted, onBeforeUnmount, unref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import request from '@/utils/request'
|
||||
import { getDashboardData } from '@/api/dashboard'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
export function useDashboard(props: { method: string; queryParams?: any }) {
|
||||
@ -18,18 +18,8 @@ export function useDashboard(props: { method: string; queryParams?: any }) {
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
// Use the request utility directly as in Vue 2 mixin
|
||||
const res: any = await request({
|
||||
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
|
||||
})
|
||||
// Use the dashboard api utility
|
||||
const res: any = await getDashboardData(props.method, unref(props.queryParams) || {})
|
||||
|
||||
if (res.code === 200) {
|
||||
data.value = res.data
|
||||
|
||||
@ -22,11 +22,12 @@
|
||||
</template>
|
||||
|
||||
<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 WelcomCard from './components/WelcomCard.vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { MODULE_PERMISSIONS, moduleComponents, RAW_MODULE_CONFIGS } from './composables/dashboard-config'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const { t } = useI18n()
|
||||
@ -40,71 +41,22 @@ const checkPermission = (key: string) => {
|
||||
const windowWidth = ref(window.innerWidth)
|
||||
const currentTime = ref(dayjs().format('YYYY-MM-DD HH:mm:ss'))
|
||||
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
|
||||
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',
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
}))
|
||||
// Module Configs computed with i18n
|
||||
const MODULE_CONFIGS = computed(() => {
|
||||
const configs: Record<string, any> = {}
|
||||
Object.keys(RAW_MODULE_CONFIGS).forEach(key => {
|
||||
const raw = RAW_MODULE_CONFIGS[key]
|
||||
if (raw) {
|
||||
configs[key] = {
|
||||
...raw,
|
||||
title: t(raw.titleKey),
|
||||
props: { ...(raw.props || {}), title: t(raw.titleKey) }
|
||||
}
|
||||
}
|
||||
})
|
||||
return configs
|
||||
})
|
||||
|
||||
const getAccessibleModules = (perms: string[]) => {
|
||||
const configs = MODULE_CONFIGS.value
|
||||
@ -134,9 +86,15 @@ const getAccessibleModules = (perms: string[]) => {
|
||||
const prioritized = [
|
||||
MODULE_PERMISSIONS.WAREHOUSE_BASE,
|
||||
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 => {
|
||||
if (prioritized.includes(permission)) return
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ export const accountColumns = [
|
||||
{ label: '用户名', prop: 'username', width: 120 },
|
||||
{ label: '邮箱', prop: 'email', minWidth: 150 },
|
||||
{ label: '状态', prop: 'status', width: 100 },
|
||||
{ label: '操作', prop: 'actions', width: 200, fixed: 'right' }
|
||||
{ label: '操作', prop: 'actions', width: 280, fixed: 'right' }
|
||||
]
|
||||
|
||||
export const defaultTemp = {
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
</template>
|
||||
<template #column-actions="{ row }">
|
||||
<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>
|
||||
</template>
|
||||
</upper-table>
|
||||
@ -98,12 +99,55 @@
|
||||
</div>
|
||||
</template>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, reactive } from 'vue'
|
||||
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 ImagesUpload from '@/components/ImagesUpload/index.vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
@ -159,8 +203,8 @@ const handleCreate = () => {
|
||||
|
||||
const createData = async () => {
|
||||
try {
|
||||
const { phone, real_name, username, password,email } = temp
|
||||
await accountAdd({ phone, real_name, username, password, email })
|
||||
const { phone, real_name, email } = temp
|
||||
await accountAdd({ phone, real_name, email })
|
||||
dialogFormVisible.value = false
|
||||
ElMessage.success('创建成功')
|
||||
getList()
|
||||
@ -208,6 +252,105 @@ const handleAvatarSuccess = (res: any) => {
|
||||
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(() => {
|
||||
getList()
|
||||
})
|
||||
@ -251,4 +394,31 @@ onMounted(() => {
|
||||
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>
|
||||
120
src/接口文档.txt
Normal file
120
src/接口文档.txt
Normal 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 个角色
|
||||
|
||||
接口响应:
|
||||
待补充
|
||||
Loading…
x
Reference in New Issue
Block a user