feat:【mall 商城】分销用户的 list modal 迁移(ele 60%)

This commit is contained in:
YunaiV
2025-10-10 19:40:02 +08:00
parent f41e746a81
commit 5e66e6bfac
2 changed files with 60 additions and 43 deletions

View File

@@ -1,5 +1,6 @@
import type { VbenFormSchema } from '#/adapter/form'; import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table'; import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
import { DICT_TYPE } from '@vben/constants'; import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks'; import { getDictOptions } from '@vben/hooks';
@@ -31,6 +32,7 @@ export function useGridFormSchema(): VbenFormSchema[] {
{ label: '无', value: false }, { label: '无', value: false },
], ],
}, },
defaultValue: true,
}, },
{ {
fieldName: 'createTime', fieldName: 'createTime',
@@ -45,7 +47,12 @@ export function useGridFormSchema(): VbenFormSchema[] {
} }
/** 列表的字段 */ /** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] { export function useGridColumns(
onBrokerageEnabledChange?: (
newEnabled: boolean,
row: MallBrokerageUserApi.BrokerageUser,
) => PromiseLike<boolean | undefined>,
): VxeTableGridOptions['columns'] {
return [ return [
{ {
field: 'id', field: 'id',
@@ -58,11 +65,6 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
minWidth: 70, minWidth: 70,
cellRender: { cellRender: {
name: 'CellImage', name: 'CellImage',
props: {
width: 24,
height: 24,
shape: 'circle',
},
}, },
}, },
{ {
@@ -113,7 +115,17 @@ export function useGridColumns(): VxeTableGridOptions['columns'] {
field: 'brokerageEnabled', field: 'brokerageEnabled',
title: '推广资格', title: '推广资格',
minWidth: 80, minWidth: 80,
slots: { default: 'brokerageEnabled' }, align: 'center',
cellRender: {
attrs: { beforeChange: onBrokerageEnabledChange },
name: 'CellSwitch',
props: {
activeValue: true,
inactiveValue: false,
activeText: '有',
inactiveText: '无',
},
},
}, },
{ {
field: 'brokerageTime', field: 'brokerageTime',
@@ -147,16 +159,14 @@ export function useUserListFormSchema(): VbenFormSchema[] {
{ {
fieldName: 'level', fieldName: 'level',
label: '用户类型', label: '用户类型',
component: 'RadioGroup', component: 'Select',
// TODO @霖:这里会折行
componentProps: { componentProps: {
options: [ options: [
{ label: '全部', value: undefined }, { label: '全部', value: undefined },
{ label: '一级推广人', value: '1' }, { label: '一级推广人', value: '1' },
{ label: '二级推广人', value: '2' }, { label: '二级推广人', value: '2' },
], ],
buttonStyle: 'solid', clearable: true,
optionType: 'button',
}, },
}, },
{ {
@@ -211,7 +221,10 @@ export function useUserListColumns(): VxeTableGridOptions['columns'] {
field: 'brokerageEnabled', field: 'brokerageEnabled',
title: '推广资格', title: '推广资格',
minWidth: 80, minWidth: 80,
slots: { default: 'brokerageEnabled' }, cellRender: {
name: 'CellDict',
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
},
}, },
{ {
field: 'bindUserTime', field: 'bindUserTime',
@@ -313,4 +326,3 @@ export function useOrderListColumns(): VxeTableGridOptions['columns'] {
}, },
]; ];
} }

View File

@@ -5,7 +5,7 @@ import type { MallBrokerageUserApi } from '#/api/mall/trade/brokerage/user';
import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui'; import { confirm, DocAlert, Page, useVbenModal } from '@vben/common-ui';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { ElMessage, ElSwitch } from 'element-plus'; import { ElLoading, ElMessage } from 'element-plus';
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
@@ -69,32 +69,47 @@ function handleOpenOrderList(row: MallBrokerageUserApi.BrokerageUser) {
/** 清除上级推广人 */ /** 清除上级推广人 */
async function handleClearBindUser(row: MallBrokerageUserApi.BrokerageUser) { async function handleClearBindUser(row: MallBrokerageUserApi.BrokerageUser) {
await confirm(`确定清除"${row.nickname}"的上级推广人吗?`); const loadingInstance = ElLoading.service({
text: $t('ui.actionMessage.deleting', [row.nickname]),
});
try { try {
await clearBindUser({ id: row.id as number }); await clearBindUser({ id: row.id as number });
ElMessage.success('清除成功'); ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.nickname]));
handleRefresh(); handleRefresh();
} catch { } finally {
// 清除失败时不做处理 loadingInstance.close();
} }
} }
/** 更新推广资格 */ /** 更新推广资格 */
async function handleBrokerageEnabledChange( async function handleBrokerageEnabledChange(
newEnabled: boolean,
row: MallBrokerageUserApi.BrokerageUser, row: MallBrokerageUserApi.BrokerageUser,
) { ): Promise<boolean | undefined> {
const text = row.brokerageEnabled ? '开通' : '关闭'; return new Promise((resolve, reject) => {
try { const text = newEnabled ? '开通' : '关闭';
await updateBrokerageEnabled({ confirm({
id: row.id as number, content: `你要将${row.nickname}的推广资格切换为【${text}】吗?`,
enabled: row.brokerageEnabled as boolean, })
}); .then(async () => {
ElMessage.success(`${text}成功`); // 更新推广资格
handleRefresh(); const res = await updateBrokerageEnabled({
} catch { id: row.id!,
// 异常时,需要重置回之前的值 enabled: newEnabled,
row.brokerageEnabled = !row.brokerageEnabled; });
} if (res) {
// 提示并返回成功
ElMessage.success($t('ui.actionMessage.operationSuccess'));
handleRefresh();
resolve(true);
} else {
reject(new Error('更新失败'));
}
})
.catch(() => {
reject(new Error('取消操作'));
});
});
} }
const [Grid, gridApi] = useVbenVxeGrid({ const [Grid, gridApi] = useVbenVxeGrid({
@@ -102,7 +117,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
schema: useGridFormSchema(), schema: useGridFormSchema(),
}, },
gridOptions: { gridOptions: {
columns: useGridColumns(), columns: useGridColumns(handleBrokerageEnabledChange),
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
proxyConfig: { proxyConfig: {
@@ -145,7 +160,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
<UserListModal /> <UserListModal />
<!-- 推广订单列表 --> <!-- 推广订单列表 -->
<OrderListModal /> <OrderListModal />
<Grid> <Grid table-title="分销用户列表">
<template #toolbar-tools> <template #toolbar-tools>
<TableAction <TableAction
:actions="[ :actions="[
@@ -159,16 +174,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
]" ]"
/> />
</template> </template>
<template #brokerageEnabled="{ row }">
<ElSwitch
v-model="row.brokerageEnabled"
checked-children=""
un-checked-children=""
@change="handleBrokerageEnabledChange(row)"
/>
</template>
<template #actions="{ row }"> <template #actions="{ row }">
<TableAction <TableAction
:drop-down-actions="[ :drop-down-actions="[