first commit
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
CI / CI OK (push) Has been cancelled
Deploy Website on push / Rerun on failure (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled

This commit is contained in:
2026-01-13 19:38:29 +08:00
commit 5816a8114a
1447 changed files with 125747 additions and 0 deletions

View File

@@ -0,0 +1,210 @@
/**
* 通用组件共同的使用的基础组件,原先放在 adapter/form 内部,限制了使用范围,这里提取出来,方便其他地方使用
* 可用于 vben-form、vben-modal、vben-drawer 等组件使用,
*/
import type { Component } from 'vue';
import type { BaseFormComponentType } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import {
defineAsyncComponent,
defineComponent,
getCurrentInstance,
h,
ref,
} from 'vue';
import { ApiComponent, globalShareState, IconPicker } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { notification } from 'ant-design-vue';
const AutoComplete = defineAsyncComponent(
() => import('ant-design-vue/es/auto-complete'),
);
const Button = defineAsyncComponent(() => import('ant-design-vue/es/button'));
const Checkbox = defineAsyncComponent(
() => import('ant-design-vue/es/checkbox'),
);
const CheckboxGroup = defineAsyncComponent(() =>
import('ant-design-vue/es/checkbox').then((res) => res.CheckboxGroup),
);
const DatePicker = defineAsyncComponent(
() => import('ant-design-vue/es/date-picker'),
);
const Divider = defineAsyncComponent(() => import('ant-design-vue/es/divider'));
const Input = defineAsyncComponent(() => import('ant-design-vue/es/input'));
const InputNumber = defineAsyncComponent(
() => import('ant-design-vue/es/input-number'),
);
const InputPassword = defineAsyncComponent(() =>
import('ant-design-vue/es/input').then((res) => res.InputPassword),
);
const Mentions = defineAsyncComponent(
() => import('ant-design-vue/es/mentions'),
);
const Radio = defineAsyncComponent(() => import('ant-design-vue/es/radio'));
const RadioGroup = defineAsyncComponent(() =>
import('ant-design-vue/es/radio').then((res) => res.RadioGroup),
);
const RangePicker = defineAsyncComponent(() =>
import('ant-design-vue/es/date-picker').then((res) => res.RangePicker),
);
const Rate = defineAsyncComponent(() => import('ant-design-vue/es/rate'));
const Select = defineAsyncComponent(() => import('ant-design-vue/es/select'));
const Space = defineAsyncComponent(() => import('ant-design-vue/es/space'));
const Switch = defineAsyncComponent(() => import('ant-design-vue/es/switch'));
const Textarea = defineAsyncComponent(() =>
import('ant-design-vue/es/input').then((res) => res.Textarea),
);
const TimePicker = defineAsyncComponent(
() => import('ant-design-vue/es/time-picker'),
);
const TreeSelect = defineAsyncComponent(
() => import('ant-design-vue/es/tree-select'),
);
const Upload = defineAsyncComponent(() => import('ant-design-vue/es/upload'));
const RichText = defineAsyncComponent(() =>
import('@vben-core/shadcn-ui').then((m) => m.RichText),
);
const withDefaultPlaceholder = <T extends Component>(
component: T,
type: 'input' | 'select',
componentProps: Recordable<any> = {},
) => {
return defineComponent({
inheritAttrs: false,
name: component.name,
setup: (props: any, { attrs, expose, slots }) => {
const placeholder =
props?.placeholder ||
attrs?.placeholder ||
$t(`ui.placeholder.${type}`);
// 透传组件暴露的方法
const innerRef = ref();
const publicApi: Recordable<any> = {};
expose(publicApi);
const instance = getCurrentInstance();
instance?.proxy?.$nextTick(() => {
for (const key in innerRef.value) {
if (typeof innerRef.value[key] === 'function') {
publicApi[key] = innerRef.value[key];
}
}
});
return () =>
h(
component,
{ ...componentProps, placeholder, ...props, ...attrs, ref: innerRef },
slots,
);
},
});
};
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
export type ComponentType =
| 'ApiSelect'
| 'ApiTreeSelect'
| 'AutoComplete'
| 'Checkbox'
| 'CheckboxGroup'
| 'DatePicker'
| 'DefaultButton'
| 'Divider'
| 'IconPicker'
| 'Input'
| 'InputNumber'
| 'InputPassword'
| 'Mentions'
| 'PrimaryButton'
| 'Radio'
| 'RadioGroup'
| 'RangePicker'
| 'Rate'
| 'RichText'
| 'Select'
| 'Space'
| 'Switch'
| 'Textarea'
| 'TimePicker'
| 'TreeSelect'
| 'Upload'
| BaseFormComponentType;
async function initComponentAdapter() {
const components: Partial<Record<ComponentType, Component>> = {
// 如果你的组件体积比较大,可以使用异步加载
// Button: () =>
// import('xxx').then((res) => res.Button),
ApiSelect: withDefaultPlaceholder(ApiComponent, 'select', {
component: Select,
loadingSlot: 'suffixIcon',
visibleEvent: 'onDropdownVisibleChange',
modelPropName: 'value',
}),
ApiTreeSelect: withDefaultPlaceholder(ApiComponent, 'select', {
component: TreeSelect,
fieldNames: { label: 'label', value: 'value', children: 'children' },
loadingSlot: 'suffixIcon',
modelPropName: 'value',
optionsPropName: 'treeData',
visibleEvent: 'onVisibleChange',
}),
AutoComplete,
Checkbox,
CheckboxGroup,
DatePicker,
// 自定义默认按钮
DefaultButton: (props, { attrs, slots }) => {
return h(Button, { ...props, attrs, type: 'default' }, slots);
},
Divider,
IconPicker: withDefaultPlaceholder(IconPicker, 'select', {
iconSlot: 'addonAfter',
inputComponent: Input,
modelValueProp: 'value',
}),
Input: withDefaultPlaceholder(Input, 'input'),
InputNumber: withDefaultPlaceholder(InputNumber, 'input'),
InputPassword: withDefaultPlaceholder(InputPassword, 'input'),
Mentions: withDefaultPlaceholder(Mentions, 'input'),
// 自定义主要按钮
PrimaryButton: (props, { attrs, slots }) => {
return h(Button, { ...props, attrs, type: 'primary' }, slots);
},
Radio,
RadioGroup,
RangePicker,
Rate,
Select: withDefaultPlaceholder(Select, 'select'),
Space,
Switch,
Textarea: withDefaultPlaceholder(Textarea, 'input'),
TimePicker,
TreeSelect: withDefaultPlaceholder(TreeSelect, 'select'),
Upload,
RichText,
};
// 将组件注册到全局共享状态中
globalShareState.setComponents(components);
// 定义全局共享状态中的消息提示
globalShareState.defineMessage({
// 复制成功消息提示
copyPreferencesSuccess: (title, content) => {
notification.success({
description: content,
message: title,
placement: 'bottomRight',
});
},
});
}
export { initComponentAdapter };

View File

@@ -0,0 +1,48 @@
import type {
VbenFormSchema as FormSchema,
VbenFormProps,
} from '@vben/common-ui';
import type { ComponentType } from './component';
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
setupVbenForm<ComponentType>({
config: {
// ant design vue组件库默认都是 v-model:value
baseModelPropName: 'value',
// 一些组件是 v-model:checked 或者 v-model:fileList
modelPropNameMap: {
Checkbox: 'checked',
Radio: 'checked',
Switch: 'checked',
Upload: 'fileList',
TinyMCE: 'modelValue',
},
},
defineRules: {
// 输入项目必填国际化适配
required: (value, _params, ctx) => {
if (value === undefined || value === null || value.length === 0) {
return $t('ui.formRules.required', [ctx.label]);
}
return true;
},
// 选择项目必填国际化适配
selectRequired: (value, _params, ctx) => {
if (value === undefined || value === null) {
return $t('ui.formRules.selectRequired', [ctx.label]);
}
return true;
},
},
});
const useVbenForm = useForm<ComponentType>;
export { useVbenForm, z };
export type VbenFormSchema = FormSchema<ComponentType>;
export type { VbenFormProps };

View File

@@ -0,0 +1,276 @@
import type { Recordable } from '@vben/types';
import { h } from 'vue';
import { IconifyIcon } from '@vben/icons';
import { $te } from '@vben/locales';
import { setupVbenVxeTable, useVbenVxeGrid } from '@vben/plugins/vxe-table';
import { get, isFunction, isString } from '@vben/utils';
import { objectOmit } from '@vueuse/core';
import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue';
import { $t } from '#/locales';
import { useVbenForm } from './form';
setupVbenVxeTable({
configVxeTable: (vxeUI) => {
vxeUI.setConfig({
grid: {
align: 'center',
border: false,
columnConfig: {
resizable: true,
},
formConfig: {
// 全局禁用vxe-table的表单配置使用formOptions
enabled: false,
},
minHeight: 180,
proxyConfig: {
autoLoad: true,
response: {
result: 'items',
total: 'total',
list: '',
},
showActiveMsg: true,
showResponseMsg: false,
},
round: true,
showOverflow: true,
size: 'small',
},
});
/**
* 解决vxeTable在热更新时可能会出错的问题
*/
vxeUI.renderer.forEach((_item, key) => {
if (key.startsWith('Cell')) {
vxeUI.renderer.delete(key);
}
});
// 表格配置项可以用 cellRender: { name: 'CellImage' },
vxeUI.renderer.add('CellImage', {
renderTableDefault(_renderOpts, params) {
const { column, row } = params;
return h(Image, { src: row[column.field] });
},
});
// 表格配置项可以用 cellRender: { name: 'CellLink' },
vxeUI.renderer.add('CellLink', {
renderTableDefault(renderOpts) {
const { props } = renderOpts;
return h(
Button,
{ size: 'small', type: 'link' },
{ default: () => props?.text },
);
},
});
// 单元格渲染: Tag
vxeUI.renderer.add('CellTag', {
renderTableDefault({ options, props }, { column, row }) {
const value = get(row, column.field);
const tagOptions = options ?? [
{ color: 'success', label: $t('common.enabled'), value: 1 },
{ color: 'error', label: $t('common.disabled'), value: 0 },
];
const tagItem = tagOptions.find((item) => item.value === value);
return h(
Tag,
{
...props,
...objectOmit(tagItem ?? {}, ['label']),
},
{ default: () => tagItem?.label ?? value },
);
},
});
vxeUI.renderer.add('CellSwitch', {
renderTableDefault({ attrs, props }, { column, row }) {
const loadingKey = `__loading_${column.field}`;
const finallyProps = {
checkedChildren: $t('common.enabled'),
checkedValue: 1,
unCheckedChildren: $t('common.disabled'),
unCheckedValue: 0,
...props,
checked: row[column.field],
loading: row[loadingKey] ?? false,
'onUpdate:checked': onChange,
};
async function onChange(newVal: any) {
row[loadingKey] = true;
try {
const result = await attrs?.beforeChange?.(newVal, row);
if (result !== false) {
row[column.field] = newVal;
}
} finally {
row[loadingKey] = false;
}
}
return h(Switch, finallyProps);
},
});
/**
* 注册表格的操作按钮渲染器
*/
vxeUI.renderer.add('CellOperation', {
renderTableDefault({ attrs, options, props }, { column, row }) {
const defaultProps = { size: 'small', type: 'link', ...props };
let align = 'end';
switch (column.align) {
case 'center': {
align = 'center';
break;
}
case 'left': {
align = 'start';
break;
}
default: {
align = 'end';
break;
}
}
const presets: Recordable<Recordable<any>> = {
delete: {
danger: true,
text: $t('common.delete'),
},
edit: {
text: $t('common.edit'),
},
};
const operations: Array<Recordable<any>> = (
options || ['edit', 'delete']
)
.map((opt) => {
if (isString(opt)) {
return presets[opt]
? { code: opt, ...presets[opt], ...defaultProps }
: {
code: opt,
text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt,
...defaultProps,
};
} else {
return { ...defaultProps, ...presets[opt.code], ...opt };
}
})
.map((opt) => {
const optBtn: Recordable<any> = {};
Object.keys(opt).forEach((key) => {
optBtn[key] = isFunction(opt[key]) ? opt[key](row) : opt[key];
});
return optBtn;
})
.filter((opt) => opt.show !== false);
function renderBtn(opt: Recordable<any>, listen = true) {
return h(
Button,
{
...props,
...opt,
icon: undefined,
onClick: listen
? () =>
attrs?.onClick?.({
code: opt.code,
row,
})
: undefined,
},
{
default: () => {
const content = [];
if (opt.icon) {
content.push(
h(IconifyIcon, { class: 'size-5', icon: opt.icon }),
);
}
content.push(opt.text);
return content;
},
},
);
}
function renderConfirm(opt: Recordable<any>) {
return h(
Popconfirm,
{
getPopupContainer(el) {
return (
el
.closest('.vxe-table--viewport-wrapper')
?.querySelector('.vxe-table--main-wrapper')
?.querySelector('tbody') || document.body
);
},
placement: 'topLeft',
title: $t('ui.actionTitle.delete', [attrs?.nameTitle || '']),
...props,
...opt,
icon: undefined,
onConfirm: () => {
attrs?.onClick?.({
code: opt.code,
row,
});
},
},
{
default: () => renderBtn({ ...opt }, false),
description: () =>
h(
'div',
{ class: 'truncate' },
$t('ui.actionMessage.deleteConfirm', [
row[attrs?.nameField || 'name'],
]),
),
},
);
}
const btns = operations.map((opt) =>
opt.code === 'delete' ? renderConfirm(opt) : renderBtn(opt),
);
return h(
'div',
{
class: 'flex table-operations',
style: { justifyContent: align },
},
btns,
);
},
});
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
// vxeUI.formats.add
},
useVbenForm,
});
export { useVbenVxeGrid };
export type OnActionClickParams<T = Recordable<any>> = {
code: string;
row: T;
};
export type OnActionClickFn<T = Recordable<any>> = (
params: OnActionClickParams<T>,
) => void;
export type * from '@vben/plugins/vxe-table';

View File

@@ -0,0 +1,594 @@
import { requestClient } from '#/api/request';
export namespace AgentApi {
export interface AgentListItem {
id: number;
user_id: number;
agent_code: number;
region: string;
mobile: string;
wechat_id?: string;
balance: number;
total_earnings: number;
withdrawn_amount: number;
create_time: string;
}
export interface AgentList {
total: number;
items: AgentListItem[];
}
export interface GetAgentListParams {
page: number;
pageSize: number;
mobile?: string;
region?: string;
id?: number;
create_time_start?: string;
create_time_end?: string;
order_by?: string;
order_type?: 'asc' | 'desc';
}
export interface AgentLinkListItem {
id: string;
agent_id: string;
product_id: string;
product_name: string;
set_price: number;
short_link: string;
create_time: string;
}
export interface AgentLinkList {
total: number;
items: AgentLinkListItem[];
}
export interface GetAgentLinkListParams {
page: number;
pageSize: number;
agent_id?: number;
product_id?: number;
product_name?: string;
link_identifier?: string;
}
// 代理佣金相关接口
export interface AgentCommissionListItem {
id: number;
agent_id: number;
order_id: number;
amount: number;
product_name: string;
status: number;
create_time: string;
}
export interface AgentCommissionList {
total: number;
items: AgentCommissionListItem[];
}
export interface GetAgentCommissionListParams {
page: number;
pageSize: number;
agent_id?: number;
product_name?: string;
status?: number;
}
// 代理产品配置列表项
export interface AgentProductionConfigItem {
id: number;
product_id: number;
product_name: string;
base_price: number;
price_range_min: number;
price_range_max: number;
price_threshold: number;
price_fee_rate: number;
create_time: string;
}
// 代理产品配置列表响应
export interface AgentProductionConfigList {
total: number;
items: AgentProductionConfigItem[];
}
// 获取代理产品配置列表参数
export interface GetAgentProductionConfigListParams {
page: number;
pageSize: number;
product_name?: string;
product_id?: number;
id?: number;
}
// 更新代理产品配置参数
export interface UpdateAgentProductionConfigParams {
id: number;
base_price: number;
price_range_max: number;
price_threshold?: number;
price_fee_rate?: number;
}
// 更新代理产品配置响应
export interface UpdateAgentProductionConfigResp {
success: boolean;
}
// 代理订单相关接口
export interface AgentOrderListItem {
id: number;
agent_id: number;
order_id: number;
product_id: number;
product_name: string;
order_amount: number;
process_status: number; // 0=待处理1=处理成功2=处理失败
create_time: string;
}
export interface AgentOrderList {
total: number;
items: AgentOrderListItem[];
}
export interface GetAgentOrderListParams {
page: number;
pageSize: number;
agent_id?: number;
order_id?: number;
process_status?: number;
}
// 系统配置相关接口(已简化:只保留税费配置)
export interface AgentConfig {
tax_rate: number; // 税率例如0.06表示6%
}
export interface UpdateAgentConfigParams {
tax_rate?: number;
}
// 代理订单列表项(整合订单、佣金、代理信息)
export interface AgentOrdersListItem {
id: number;
order_no: string;
platform_order_id: string;
// 代理信息
agent_id: number;
agent_mobile: string;
// 用户信息
user_id: number;
user_mobile?: string;
// 产品信息
product_id: number;
product_name: string;
// 金额信息
order_amount: number;
commission_amount: number;
// 支付信息
payment_platform: 'alipay' | 'appleiap' | 'wechat';
payment_scene: 'app' | 'h5' | 'mini_program' | 'public_account';
// 状态
order_status: 'pending' | 'paid' | 'failed' | 'refunded' | 'closed';
commission_status: number; // 0=待结算1=已结算2=已取消
// 时间
create_time: string;
pay_time?: string;
query_id?: string; // 查询记录ID用于报告结果跳转
}
export interface AgentOrdersList {
total: number;
items: AgentOrdersListItem[];
}
export interface GetAgentOrdersListParams {
page: number;
pageSize: number;
// 代理筛选
agent_id?: number;
agent_mobile?: string;
// 用户筛选
user_mobile?: string;
// 订单筛选
order_no?: string;
platform_order_id?: string;
product_name?: string;
// 支付筛选
payment_platform?: string;
payment_scene?: string;
// 状态筛选
order_status?: string;
commission_status?: number;
// 时间筛选
create_time_start?: string;
create_time_end?: string;
pay_time_start?: string;
pay_time_end?: string;
// 排序
order_by?: string;
order_type?: 'asc' | 'desc';
}
// 退款请求
export interface RefundAgentOrderRequest {
refund_amount: number;
refund_reason: string;
}
export interface RefundAgentOrderResponse {
status: string;
refund_no: string;
amount: number;
}
// 代理提现记录列表项
export interface AgentWithdrawListItem {
id: string;
agent_id: string;
agent_mobile: string;
agent_code: number;
withdraw_amount: number;
tax_amount: number;
actual_amount: number;
frozen_amount: number;
account_name: string;
bank_card_number: string;
bank_branch: string;
status: number; // 0=待审核1=已通过2=已拒绝
audit_user_id: string;
audit_time: string;
audit_remark: string;
create_time: string;
}
// 代理提现记录列表响应
export interface AgentWithdrawList {
total: number;
items: AgentWithdrawListItem[];
}
// 获取代理提现记录列表参数
export interface GetAgentWithdrawListParams {
page: number;
pageSize: number;
agent_id?: string;
status?: number;
}
// 审核代理提现申请请求
export interface AuditAgentWithdrawRequest {
withdraw_id: string;
status: number; // 1=通过2=拒绝
audit_reason?: string;
}
// 审核代理提现申请响应
export interface AuditAgentWithdrawResponse {
success: boolean;
message: string;
}
// 发送代理投诉通知请求
export interface SendAgentComplaintNotifyRequest {
agent_id: string;
user_name: string;
}
// 发送代理投诉通知响应
export interface SendAgentComplaintNotifyResponse {
success: boolean;
message: string;
}
// 统计概览响应
export interface StatisticsOverview {
total_agents: number;
today_new_agents: number;
total_orders: number;
today_orders: number;
total_order_amount: number;
today_order_amount: number;
total_commission: number;
today_commission: number;
pending_withdraw: number;
month_order_amount: number;
month_commission: number;
}
// 订单趋势请求
export interface OrderTrendsRequest {
start_date?: string;
end_date?: string;
}
// 订单趋势响应
export interface OrderTrendsResponse {
dates: string[];
amounts: number[];
counts: number[];
}
// 代理注册趋势请求
export interface AgentTrendsRequest {
start_date?: string;
end_date?: string;
}
// 代理注册趋势响应
export interface AgentTrendsResponse {
dates: string[];
counts: number[];
}
// 产品订单分布响应
export interface ProductDistributionResponse {
products: string[];
counts: number[];
amounts: number[];
}
// 区域代理分布响应
export interface RegionDistributionResponse {
regions: string[];
counts: number[];
}
// 代理排行榜请求
export interface AgentRankingRequest {
type: 'commission' | 'orders';
limit?: number;
}
// 代理排行榜项
export interface AgentRankingItem {
agent_id: string;
agent_mobile: string;
region: string;
value: number;
}
// 代理排行榜响应
export interface AgentRankingResponse {
items: AgentRankingItem[];
}
}
/**
* 获取代理列表数据
* @param params 查询参数
*/
async function getAgentList(params: AgentApi.GetAgentListParams) {
return requestClient.get<AgentApi.AgentList>('/agent/list', {
params,
});
}
/**
* 获取代理推广链接列表
*/
async function getAgentLinkList(params: AgentApi.GetAgentLinkListParams) {
return requestClient.get<AgentApi.AgentLinkList>('/agent/link/list', {
params,
});
}
/**
* 获取代理佣金列表
*/
async function getAgentCommissionList(
params: AgentApi.GetAgentCommissionListParams,
) {
return requestClient.get<AgentApi.AgentCommissionList>(
'/agent/commission/list',
{
params,
},
);
}
/**
* 获取代理产品配置列表
*/
async function getAgentProductionConfigList(
params: AgentApi.GetAgentProductionConfigListParams,
) {
return requestClient.get<AgentApi.AgentProductionConfigList>(
'/agent/product_config/list',
{
params,
},
);
}
/**
* 更新代理产品配置
*/
async function updateAgentProductionConfig(
params: AgentApi.UpdateAgentProductionConfigParams,
) {
return requestClient.post<AgentApi.UpdateAgentProductionConfigResp>(
'/agent/product_config/update',
params,
);
}
/**
* 获取代理订单列表
*/
async function getAgentOrderList(params: AgentApi.GetAgentOrderListParams) {
return requestClient.get<AgentApi.AgentOrderList>('/agent/order/list', {
params,
});
}
/**
* 获取系统配置
*/
async function getAgentConfig() {
return requestClient.get<AgentApi.AgentConfig>('/agent/config');
}
/**
* 更新系统配置
*/
async function updateAgentConfig(params: AgentApi.UpdateAgentConfigParams) {
return requestClient.post<{ success: boolean }>(
'/agent/config/update',
params,
);
}
/**
* 获取代理订单列表(整合订单、佣金、代理信息)
*/
async function getAgentOrdersList(params: AgentApi.GetAgentOrdersListParams) {
return requestClient.get<AgentApi.AgentOrdersList>('/agent/orders/list', {
params,
});
}
/**
* 代理订单退款
* @param id 订单ID
* @param data 退款请求数据
*/
async function refundAgentOrder(
id: string | number,
data: AgentApi.RefundAgentOrderRequest,
) {
return requestClient.post<AgentApi.RefundAgentOrderResponse>(
`/order/refund/${id}`,
data,
);
}
/**
* 获取代理提现记录列表
*/
async function adminGetAgentWithdrawList(
params: AgentApi.GetAgentWithdrawListParams,
) {
return requestClient.get<AgentApi.AgentWithdrawList>(
'/agent/withdraw/list',
{
params,
},
);
}
/**
* 审核代理提现申请
*/
async function adminAuditAgentWithdraw(
params: AgentApi.AuditAgentWithdrawRequest,
) {
return requestClient.post<AgentApi.AuditAgentWithdrawResponse>(
'/agent/withdraw/audit',
params,
);
}
/**
* 发送代理投诉通知短信
*/
async function sendAgentComplaintNotify(
params: AgentApi.SendAgentComplaintNotifyRequest,
) {
return requestClient.post<AgentApi.SendAgentComplaintNotifyResponse>(
'/agent/complaint/notify',
params,
);
}
/**
* 获取统计概览
*/
async function getStatisticsOverview() {
return requestClient.get<AgentApi.StatisticsOverview>(
'/agent/statistics/overview',
);
}
/**
* 获取订单趋势
*/
async function getOrderTrends(params?: AgentApi.OrderTrendsRequest) {
return requestClient.get<AgentApi.OrderTrendsResponse>(
'/agent/statistics/order/trends',
{
params,
},
);
}
/**
* 获取代理注册趋势
*/
async function getAgentTrends(params?: AgentApi.AgentTrendsRequest) {
return requestClient.get<AgentApi.AgentTrendsResponse>(
'/agent/statistics/agent/trends',
{
params,
},
);
}
/**
* 获取产品订单分布
*/
async function getProductDistribution() {
return requestClient.get<AgentApi.ProductDistributionResponse>(
'/agent/statistics/product/distribution',
);
}
/**
* 获取区域代理分布
*/
async function getRegionDistribution() {
return requestClient.get<AgentApi.RegionDistributionResponse>(
'/agent/statistics/region/distribution',
);
}
/**
* 获取代理排行榜
*/
async function getAgentRanking(params: AgentApi.AgentRankingRequest) {
return requestClient.get<AgentApi.AgentRankingResponse>(
'/agent/statistics/agent/ranking',
{
params,
},
);
}
export {
adminAuditAgentWithdraw,
adminGetAgentWithdrawList,
getAgentCommissionList,
getAgentConfig,
getAgentLinkList,
getAgentList,
getAgentOrderList,
getAgentOrdersList,
getAgentProductionConfigList,
getAgentRanking,
getAgentTrends,
getOrderTrends,
getProductDistribution,
getRegionDistribution,
getStatisticsOverview,
refundAgentOrder,
sendAgentComplaintNotify,
updateAgentConfig,
updateAgentProductionConfig,
};

View File

@@ -0,0 +1 @@
export * from './agent';

View File

@@ -0,0 +1,52 @@
import { baseRequestClient, requestClient } from '#/api/request';
export namespace AuthApi {
/** 登录接口参数 */
export interface LoginParams {
password?: string;
username?: string;
}
/** 登录接口返回值 */
export interface LoginResult {
access_token: string;
}
export interface RefreshTokenResult {
data: string;
status: number;
}
}
/**
* 登录
*/
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}
/**
* 刷新accessToken
*/
export async function refreshTokenApi() {
return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh', {
withCredentials: true,
});
}
/**
* 退出登录
*/
export async function logoutApi() {
return baseRequestClient.post('/auth/logout', {
withCredentials: true,
});
}
/**
* 获取用户权限码
*/
export async function getAccessCodesApi() {
// return requestClient.get<string[]>('/auth/codes');
return [];
}

View File

@@ -0,0 +1,3 @@
export * from './auth';
export * from './menu';
export * from './user';

View File

@@ -0,0 +1,10 @@
import type { RouteRecordStringComponent } from '@vben/types';
import { requestClient } from '#/api/request';
/**
* 获取用户所有菜单
*/
export async function getAllMenusApi() {
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
}

View File

@@ -0,0 +1,10 @@
import type { UserInfo } from '@vben/types';
import { requestClient } from '#/api/request';
/**
* 获取用户信息
*/
export async function getUserInfoApi() {
return requestClient.get<UserInfo>('/user/info');
}

View File

@@ -0,0 +1,36 @@
export * from './agent';
export * from './core';
export * from './notification';
export * from './order';
export * from './platform-user';
export * from './product-manage';
export * from './system';
export interface ApiResponse<T = any> {
code: number;
data: T;
message: string;
}
export interface PageResult<T> {
items: T[];
total: number;
}
declare global {
interface Window {
$http: {
delete<T = any>(url: string, config?: any): Promise<ApiResponse<T>>;
get<T = any>(url: string, config?: any): Promise<ApiResponse<T>>;
post<T = any>(
url: string,
data?: any,
config?: any,
): Promise<ApiResponse<T>>;
put<T = any>(
url: string,
data?: any,
config?: any,
): Promise<ApiResponse<T>>;
};
}
}

View File

@@ -0,0 +1,105 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace NotificationApi {
export interface NotificationItem {
id: number;
title: string;
content?: string;
notification_page: string;
start_date: string;
start_time: string;
end_date: string;
end_time: string;
status: number;
create_time: string;
update_time: string;
}
export interface NotificationList {
total: number;
items: NotificationItem[];
}
export interface CreateNotificationRequest {
title: string;
content: string;
notification_page: string;
start_date: string;
start_time: string;
end_date: string;
end_time: string;
status: 0 | 1;
}
export interface CreateNotificationResponse {
id: number;
}
export interface UpdateNotificationRequest
extends Partial<CreateNotificationRequest> {
id: number;
}
export interface UpdateNotificationResponse {
success: boolean;
}
export interface DeleteNotificationResponse {
success: boolean;
}
}
/**
* 获取通知列表
*/
async function getNotificationList(params: Recordable<any>) {
return requestClient.get<NotificationApi.NotificationList>(
'/notification/list',
{
params,
},
);
}
/**
* 创建通知
*/
async function createNotification(
data: NotificationApi.CreateNotificationRequest,
) {
return requestClient.post<NotificationApi.CreateNotificationResponse>(
'/notification/create',
data,
);
}
/**
* 更新通知
*/
async function updateNotification(
id: number,
data: NotificationApi.UpdateNotificationRequest,
) {
return requestClient.put<NotificationApi.UpdateNotificationResponse>(
`/notification/update/${id}`,
data,
);
}
/**
* 删除通知
*/
async function deleteNotification(id: number) {
return requestClient.delete<NotificationApi.DeleteNotificationResponse>(
`/notification/delete/${id}`,
);
}
export {
createNotification,
deleteNotification,
getNotificationList,
updateNotification,
};

View File

@@ -0,0 +1 @@
export * from './order';

View File

@@ -0,0 +1,59 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace OrderApi {
export interface Order {
id: number;
order_no: string;
platform_order_id: string;
product_name: string;
payment_platform: 'alipay' | 'appleiap' | 'wechat';
payment_scene: 'app' | 'h5' | 'mini_program' | 'public_account';
amount: number;
status: 'closed' | 'failed' | 'paid' | 'pending' | 'refunded';
query_state: 'cleaned' | 'failed' | 'pending' | 'processing' | 'success';
create_time: string;
pay_time: null | string;
refund_time: null | string;
}
export interface OrderList {
total: number;
items: Order[];
}
export interface RefundOrderRequest {
refund_amount: number;
refund_reason: string;
}
export interface RefundOrderResponse {
status: string;
refund_no: string;
amount: number;
}
}
/**
* 获取订单列表数据
*/
async function getOrderList(params: Recordable<any>) {
return requestClient.get<OrderApi.OrderList>('/order/list', {
params,
});
}
/**
* 订单退款
* @param id 订单 ID
* @param data 退款请求数据
*/
async function refundOrder(id: number, data: OrderApi.RefundOrderRequest) {
return requestClient.post<OrderApi.RefundOrderResponse>(
`/order/refund/${id}`,
data,
);
}
export { getOrderList, refundOrder };

View File

@@ -0,0 +1,184 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace OrderQueryApi {
export interface QueryItem {
feature: Recordable<any>;
data: Recordable<any>;
}
export interface QueryDetail {
id: string;
order_id: string;
user_id: string;
product_name: string;
query_params: Recordable<any>;
query_data: QueryItem[];
create_time: string;
update_time: string;
query_state: string;
}
export interface GetQueryDetailRequest {
order_id: string;
}
export interface GetQueryDetailResponse {
id: string;
order_id: string;
user_id: string;
product_name: string;
query_params: Recordable<any>;
query_data: QueryItem[];
create_time: string;
update_time: string;
query_state: string;
}
// 清理日志相关接口定义
export interface GetQueryCleanupLogListRequest {
page?: number;
page_size?: number;
status?: number;
start_time?: string;
end_time?: string;
}
export interface QueryCleanupLogItem {
id: number;
cleanup_time: string;
cleanup_before: string;
status: number;
affected_rows: number;
error_msg: string;
remark: string;
create_time: string;
}
export interface GetQueryCleanupLogListResponse {
total: number;
items: QueryCleanupLogItem[];
}
// 清理详情相关接口定义
export interface GetQueryCleanupDetailListRequest {
log_id: number;
page?: number;
page_size?: number;
}
export interface QueryCleanupDetailItem {
id: number;
cleanup_log_id: number;
query_id: number;
order_id: number;
user_id: number;
product_id: number;
query_state: string;
create_time_old: string;
create_time: string;
}
export interface GetQueryCleanupDetailListResponse {
total: number;
items: QueryCleanupDetailItem[];
}
// 清理配置相关接口定义
export interface GetQueryCleanupConfigListRequest {
status?: number;
}
export interface QueryCleanupConfigItem {
id: number;
config_key: string;
config_value: string;
config_desc: string;
status: number;
create_time: string;
update_time: string;
}
export interface GetQueryCleanupConfigListResponse {
items: QueryCleanupConfigItem[];
}
export interface UpdateQueryCleanupConfigRequest {
id: number;
config_value: string;
status: number;
}
export interface UpdateQueryCleanupConfigResponse {
success: boolean;
}
}
/**
* 获取订单查询详情
* @param orderId 订单ID
*/
async function getOrderQueryDetail(orderId: string) {
return requestClient.get<OrderQueryApi.GetQueryDetailResponse>(
`/query/detail/${orderId}`,
);
}
/**
* 获取清理日志列表
*/
async function getQueryCleanupLogList(
params: OrderQueryApi.GetQueryCleanupLogListRequest,
) {
return requestClient.get<OrderQueryApi.GetQueryCleanupLogListResponse>(
'/query/cleanup/logs',
{ params },
);
}
/**
* 获取清理详情列表
* @param logId 清理日志ID
*/
async function getQueryCleanupDetailList(
logId: number,
params: Omit<OrderQueryApi.GetQueryCleanupDetailListRequest, 'log_id'>,
) {
return requestClient.get<OrderQueryApi.GetQueryCleanupDetailListResponse>(
`/query/cleanup/details/${logId}`,
{ params },
);
}
/**
* 获取清理配置列表
*/
async function getQueryCleanupConfigList(
params?: OrderQueryApi.GetQueryCleanupConfigListRequest,
) {
return requestClient.get<OrderQueryApi.GetQueryCleanupConfigListResponse>(
'/query/cleanup/configs',
{ params },
);
}
/**
* 更新清理配置
*/
async function updateQueryCleanupConfig(
data: OrderQueryApi.UpdateQueryCleanupConfigRequest,
) {
return requestClient.put<OrderQueryApi.UpdateQueryCleanupConfigResponse>(
'/query/cleanup/config',
data,
);
}
export {
getOrderQueryDetail,
getQueryCleanupConfigList,
getQueryCleanupDetailList,
getQueryCleanupLogList,
updateQueryCleanupConfig,
};

View File

@@ -0,0 +1,53 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace PlatformUserApi {
export interface PlatformUserItem {
id: number;
mobile: string;
nickname: string;
info: string;
inside: number;
create_time: string;
update_time: string;
}
export interface PlatformUserList {
total: number;
items: PlatformUserItem[];
}
export interface UpdatePlatformUserRequest {
mobile: string;
nickname: string;
info: string;
inside: number;
}
}
/**
* 获取平台用户列表数据
*/
async function getPlatformUserList(params: Recordable<any>) {
return requestClient.get<PlatformUserApi.PlatformUserList>(
'/platform_user/list',
{
params,
},
);
}
/**
* 更新平台用户
* @param id 用户 ID
* @param data 用户数据
*/
async function updatePlatformUser(
id: number,
data: PlatformUserApi.UpdatePlatformUserRequest,
) {
return requestClient.put(`/platform_user/update/${id}`, data);
}
export { getPlatformUserList, updatePlatformUser };

View File

@@ -0,0 +1,137 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace FeatureApi {
export interface FeatureItem {
id: number;
api_id: string;
name: string;
create_time: string;
update_time: string;
}
export interface FeatureList {
total: number;
items: FeatureItem[];
}
export interface CreateFeatureRequest {
api_id: string;
name: string;
}
export interface UpdateFeatureRequest {
api_id?: string;
name?: string;
}
export interface FeatureExampleItem {
id: number;
feature_id: number;
api_id: string;
data: string;
create_time: string;
update_time: string;
}
export interface ConfigFeatureExampleRequest {
feature_id: number;
data: string;
}
export interface ConfigFeatureExampleResponse {
success: boolean;
}
export interface GetFeatureExampleRequest {
feature_id: number;
}
export interface GetFeatureExampleResponse {
id: number;
feature_id: number;
api_id: string;
data: string;
create_time: string;
update_time: string;
}
}
/**
* 获取模块列表数据
*/
async function getFeatureList(params: Recordable<any>) {
return requestClient.get<FeatureApi.FeatureList>('/feature/list', {
params,
});
}
/**
* 获取模块详情
* @param id 模块ID
*/
async function getFeatureDetail(id: number) {
return requestClient.get<FeatureApi.FeatureItem>(`/feature/detail/${id}`);
}
/**
* 创建模块
* @param data 模块数据
*/
async function createFeature(data: FeatureApi.CreateFeatureRequest) {
return requestClient.post<{ id: number }>('/feature/create', data);
}
/**
* 更新模块
* @param id 模块ID
* @param data 模块数据
*/
async function updateFeature(
id: number,
data: FeatureApi.UpdateFeatureRequest,
) {
return requestClient.put<{ success: boolean }>(`/feature/update/${id}`, data);
}
/**
* 删除模块
* @param id 模块ID
*/
async function deleteFeature(id: number) {
return requestClient.delete<{ success: boolean }>(`/feature/delete/${id}`);
}
/**
* 配置功能示例数据
* @param data 示例数据配置
*/
async function configFeatureExample(
data: FeatureApi.ConfigFeatureExampleRequest,
) {
return requestClient.post<FeatureApi.ConfigFeatureExampleResponse>(
'/feature/config-example',
data,
);
}
/**
* 获取功能示例数据
* @param featureId 功能ID
*/
async function getFeatureExample(featureId: number) {
return requestClient.get<FeatureApi.GetFeatureExampleResponse>(
`/feature/example/${featureId}`,
);
}
export {
configFeatureExample,
createFeature,
deleteFeature,
getFeatureDetail,
getFeatureExample,
getFeatureList,
updateFeature,
};

View File

@@ -0,0 +1,2 @@
export * from './feature';
export * from './product';

View File

@@ -0,0 +1,144 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace ProductApi {
export interface ProductItem {
id: number;
product_name: string;
product_en: string;
description: string;
notes: string;
cost_price: number;
sell_price: number;
create_time: string;
update_time: string;
}
export interface ProductList {
total: number;
items: ProductItem[];
}
export interface CreateProductRequest {
product_name: string;
product_en: string;
description: string;
notes?: string;
cost_price: number;
sell_price: number;
}
export interface UpdateProductRequest {
product_name?: string;
product_en?: string;
description?: string;
notes?: string;
cost_price?: number;
sell_price?: number;
}
export interface ProductFeatureListItem {
id: number;
product_id: number;
feature_id: number;
api_id: string;
name: string;
sort: number;
enable: number;
is_important: number;
create_time: string;
update_time: string;
}
export interface ProductFeatureItem {
feature_id: number;
sort: number;
enable: number;
is_important: number;
}
export interface UpdateProductFeaturesRequest {
features: ProductFeatureItem[];
}
}
/**
* 获取产品列表数据
*/
async function getProductList(params: Recordable<any>) {
return requestClient.get<ProductApi.ProductList>('/product/list', {
params,
});
}
/**
* 获取产品详情
* @param id 产品ID
*/
async function getProductDetail(id: number) {
return requestClient.get<ProductApi.ProductItem>(`/product/detail/${id}`);
}
/**
* 创建产品
* @param data 产品数据
*/
async function createProduct(data: ProductApi.CreateProductRequest) {
return requestClient.post<{ id: number }>('/product/create', data);
}
/**
* 更新产品
* @param id 产品ID
* @param data 产品数据
*/
async function updateProduct(
id: number,
data: ProductApi.UpdateProductRequest,
) {
return requestClient.put<{ success: boolean }>(`/product/update/${id}`, data);
}
/**
* 删除产品
* @param id 产品ID
*/
async function deleteProduct(id: number) {
return requestClient.delete<{ success: boolean }>(`/product/delete/${id}`);
}
/**
* 获取产品功能列表
* @param productId 产品ID
*/
async function getProductFeatureList(productId: number) {
return requestClient.get<ProductApi.ProductFeatureListItem[]>(
`/product/feature/list/${productId}`,
);
}
/**
* 更新产品功能关联
* @param productId 产品ID
* @param data 功能列表数据
*/
async function updateProductFeatures(
productId: number,
data: ProductApi.UpdateProductFeaturesRequest,
) {
return requestClient.put<{ success: boolean }>(
`/product/feature/update/${productId}`,
data,
);
}
export {
createProduct,
deleteProduct,
getProductDetail,
getProductFeatureList,
getProductList,
updateProduct,
updateProductFeatures,
};

View File

@@ -0,0 +1,113 @@
/**
* 该文件可自行根据业务逻辑进行调整
*/
import type { RequestClientOptions } from '@vben/request';
import { useAppConfig } from '@vben/hooks';
import { preferences } from '@vben/preferences';
import {
authenticateResponseInterceptor,
defaultResponseInterceptor,
errorMessageResponseInterceptor,
RequestClient,
} from '@vben/request';
import { useAccessStore } from '@vben/stores';
import { message } from 'ant-design-vue';
import { useAuthStore } from '#/store';
import { refreshTokenApi } from './core';
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
function createRequestClient(baseURL: string, options?: RequestClientOptions) {
const client = new RequestClient({
...options,
baseURL,
});
/**
* 重新认证逻辑
*/
async function doReAuthenticate() {
console.warn('Access token or refresh token is invalid or expired. ');
const accessStore = useAccessStore();
const authStore = useAuthStore();
accessStore.setAccessToken(null);
if (
preferences.app.loginExpiredMode === 'modal' &&
accessStore.isAccessChecked
) {
accessStore.setLoginExpired(true);
} else {
await authStore.logout();
}
}
/**
* 刷新token逻辑
*/
async function doRefreshToken() {
const accessStore = useAccessStore();
const resp = await refreshTokenApi();
const newToken = resp.data;
accessStore.setAccessToken(newToken);
return newToken;
}
function formatToken(token: null | string) {
return token ? `Bearer ${token}` : null;
}
// 请求头处理
client.addRequestInterceptor({
fulfilled: async (config) => {
const accessStore = useAccessStore();
config.headers.Authorization = formatToken(accessStore.accessToken);
config.headers['Accept-Language'] = preferences.app.locale;
return config;
},
});
// 处理返回的响应数据格式
client.addResponseInterceptor(
defaultResponseInterceptor({
codeField: 'code',
dataField: 'data',
successCode: 200,
}),
);
// token过期的处理
client.addResponseInterceptor(
authenticateResponseInterceptor({
client,
doReAuthenticate,
doRefreshToken,
enableRefreshToken: preferences.app.enableRefreshToken,
formatToken,
}),
);
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
client.addResponseInterceptor(
errorMessageResponseInterceptor((msg: string, error) => {
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
// 当前mock接口返回的错误字段是 error 或者 message
const responseData = error?.response?.data ?? {};
const errorMessage = responseData?.error ?? responseData?.msg ?? '';
// 如果没有错误信息,则会根据状态码进行提示
message.error(errorMessage || msg);
}),
);
return client;
}
export const requestClient = createRequestClient(apiURL, {
responseReturn: 'data',
});
export const baseRequestClient = new RequestClient({ baseURL: apiURL });

View File

@@ -0,0 +1,165 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace SystemApiApi {
export interface SystemApiItem {
id: string;
role_id?: string;
api_id?: string;
api_name: string;
api_code: string;
method: string;
url: string;
status: 0 | 1;
description?: string;
create_time?: string;
update_time?: string;
}
export interface SystemApi {
list: SystemApiItem[];
total: number;
}
export interface SystemApiAllResponse {
items: SystemApiItem[];
}
export interface SystemRoleApiResponse {
items: null | SystemApiItem[];
}
export interface RoleApiItem {
id: string;
role_id: string;
api_id: string;
api_name: string;
api_code: string;
method: string;
url: string;
status: 0 | 1;
description?: string;
}
export interface RoleApi {
list: RoleApiItem[];
}
}
/**
* 获取API列表数据
*/
async function getApiList(params: Recordable<any>) {
return requestClient.get<SystemApiApi.SystemApi>('/api/list', {
params,
});
}
/**
* 获取API详情
* @param id API ID
*/
async function getApiDetail(id: string) {
return requestClient.get<SystemApiApi.SystemApiItem>(`/api/detail/${id}`);
}
/**
* 创建API
* @param data API数据
*/
async function createApi(
data: Omit<SystemApiApi.SystemApiItem, 'create_time' | 'id' | 'update_time'>,
) {
return requestClient.post('/api/create', data);
}
/**
* 更新API
* @param id API ID
* @param data API数据
*/
async function updateApi(
id: string,
data: Omit<SystemApiApi.SystemApiItem, 'create_time' | 'id' | 'update_time'>,
) {
return requestClient.put(`/api/update/${id}`, data);
}
/**
* 删除API
* @param id API ID
*/
async function deleteApi(id: number) {
return requestClient.delete(`/api/delete/${id}`);
}
/**
* 批量更新API状态
* @param data.ids API ID数组
* @param data.status 状态值
*/
async function batchUpdateApiStatus(data: { ids: number[]; status: 0 | 1 }) {
return requestClient.put('/api/batch-update-status', data);
}
/**
* 获取角色API权限列表
* @param roleId 角色ID
*/
async function getRoleApiList(roleId: string) {
return requestClient.get<SystemApiApi.SystemRoleApiResponse>(
`/role/${roleId}/api/list`,
);
}
/**
* 分配角色API权限
* @param data.api_ids API ID数组
* @param data.role_id 角色ID
*/
async function assignRoleApi(data: { api_ids: string[]; role_id: string }) {
return requestClient.post('/role/api/assign', data);
}
/**
* 移除角色API权限
* @param data.api_ids API ID数组
* @param data.role_id 角色ID
*/
async function removeRoleApi(data: { api_ids: string[]; role_id: string }) {
return requestClient.post('/role/api/remove', data);
}
/**
* 更新角色API权限全量更新
* @param data.api_ids API ID数组
* @param data.role_id 角色ID
*/
async function updateRoleApi(data: { api_ids: string[]; role_id: string }) {
return requestClient.put('/role/api/update', data);
}
/**
* 获取所有API列表用于权限分配
* @param params.status 状态过滤
*/
async function getAllApiList(params?: { status?: number }) {
return requestClient.get<SystemApiApi.SystemApiAllResponse>('/api/all', {
params,
});
}
export {
assignRoleApi,
batchUpdateApiStatus,
createApi,
deleteApi,
getAllApiList,
getApiDetail,
getApiList,
getRoleApiList,
removeRoleApi,
updateApi,
updateRoleApi,
};

View File

@@ -0,0 +1,54 @@
import { requestClient } from '#/api/request';
export namespace SystemDeptApi {
export interface SystemDept {
[key: string]: any;
children?: SystemDept[];
id: string;
name: string;
remark?: string;
status: 0 | 1;
}
}
/**
* 获取部门列表数据
*/
async function getDeptList() {
return requestClient.get<Array<SystemDeptApi.SystemDept>>(
'/system/dept/list',
);
}
/**
* 创建部门
* @param data 部门数据
*/
async function createDept(
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
return requestClient.post('/system/dept', data);
}
/**
* 更新部门
*
* @param id 部门 ID
* @param data 部门数据
*/
async function updateDept(
id: string,
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
) {
return requestClient.put(`/system/dept/${id}`, data);
}
/**
* 删除部门
* @param id 部门 ID
*/
async function deleteDept(id: string) {
return requestClient.delete(`/system/dept/${id}`);
}
export { createDept, deleteDept, getDeptList, updateDept };

View File

@@ -0,0 +1,5 @@
export * from './api';
export * from './dept';
export * from './menu';
export * from './role';
export * from './user';

View File

@@ -0,0 +1,156 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace SystemMenuApi {
/** 徽标颜色集合 */
export const BadgeVariants = [
'default',
'destructive',
'primary',
'success',
'warning',
] as const;
/** 徽标类型集合 */
export const BadgeTypes = ['dot', 'normal'] as const;
/** 菜单类型集合 */
export const MenuTypes = [
'catalog',
'menu',
'embedded',
'link',
'button',
] as const;
/** 系统菜单 */
export interface SystemMenu {
[key: string]: any;
/** 后端权限标识 */
authCode: string;
/** 子级 */
children?: SystemMenu[];
/** 组件 */
component?: string;
/** 菜单ID */
id: string;
/** 菜单元数据 */
meta?: {
/** 激活时显示的图标 */
activeIcon?: string;
/** 作为路由时需要激活的菜单的Path */
activePath?: string;
/** 固定在标签栏 */
affixTab?: boolean;
/** 在标签栏固定的顺序 */
affixTabOrder?: number;
/** 徽标内容(当徽标类型为normal时有效) */
badge?: string;
/** 徽标类型 */
badgeType?: (typeof BadgeTypes)[number];
/** 徽标颜色 */
badgeVariants?: (typeof BadgeVariants)[number];
/** 在菜单中隐藏下级 */
hideChildrenInMenu?: boolean;
/** 在面包屑中隐藏 */
hideInBreadcrumb?: boolean;
/** 在菜单中隐藏 */
hideInMenu?: boolean;
/** 在标签栏中隐藏 */
hideInTab?: boolean;
/** 菜单图标 */
icon?: string;
/** 内嵌Iframe的URL */
iframeSrc?: string;
/** 是否缓存页面 */
keepAlive?: boolean;
/** 外链页面的URL */
link?: string;
/** 同一个路由最大打开的标签数 */
maxNumOfOpenTab?: number;
/** 无需基础布局 */
noBasicLayout?: boolean;
/** 是否在新窗口打开 */
openInNewWindow?: boolean;
/** 菜单排序 */
order?: number;
/** 额外的路由参数 */
query?: Recordable<any>;
/** 菜单标题 */
title?: string;
};
/** 菜单名称 */
name: string;
/** 路由路径 */
path: string;
/** 父级ID */
pid: string;
/** 重定向 */
redirect?: string;
/** 菜单类型 */
type: (typeof MenuTypes)[number];
}
}
/**
* 获取菜单数据列表
*/
async function getMenuList() {
return requestClient.get<Array<SystemMenuApi.SystemMenu>>('/menu/list');
}
async function isMenuNameExists(
name: string,
id?: SystemMenuApi.SystemMenu['id'],
) {
return requestClient.get<boolean>('/menu/name-exists', {
params: { id, name },
});
}
async function isMenuPathExists(
path: string,
id?: SystemMenuApi.SystemMenu['id'],
) {
return requestClient.get<boolean>('/menu/path-exists', {
params: { id, path },
});
}
/**
* 创建菜单
* @param data 菜单数据
*/
async function createMenu(
data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
) {
return requestClient.post('/menu/create', data);
}
/**
* 更新菜单
*
* @param id 菜单 ID
* @param data 菜单数据
*/
async function updateMenu(
id: string,
data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
) {
return requestClient.put(`/menu/update/${id}`, data);
}
/**
* 删除菜单
* @param id 菜单 ID
*/
async function deleteMenu(id: string) {
return requestClient.delete(`/menu/delete/${id}`);
}
export {
createMenu,
deleteMenu,
getMenuList,
isMenuNameExists,
isMenuPathExists,
updateMenu,
};

View File

@@ -0,0 +1,61 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace SystemRoleApi {
export interface SystemRoleItem {
id: string;
role_name: string;
role_code: string;
description?: string;
status: 0 | 1;
sort: number;
create_time: string;
menu_ids: string[];
}
export interface SystemRole {
total: number;
items: SystemRoleItem[];
}
}
/**
* 获取角色列表数据
*/
async function getRoleList(params: Recordable<any>) {
return requestClient.get<SystemRoleApi.SystemRole>('/role/list', {
params,
});
}
/**
* 创建角色
* @param data 角色数据
*/
async function createRole(data: Omit<SystemRoleApi.SystemRoleItem, 'id'>) {
return requestClient.post('/role/create', data);
}
/**
* 更新角色
*
* @param id 角色 ID
* @param data 角色数据
*/
async function updateRole(
id: string,
data: Omit<SystemRoleApi.SystemRoleItem, 'id'>,
) {
return requestClient.put(`/role/update/${id}`, data);
}
/**
* 删除角色
* @param id 角色 ID
*/
async function deleteRole(id: string) {
return requestClient.delete(`/role/delete/${id}`);
}
export { createRole, deleteRole, getRoleList, updateRole };

View File

@@ -0,0 +1,64 @@
import type { Recordable } from '@vben/types';
import { requestClient } from '#/api/request';
export namespace SystemUserApi {
export interface SystemUser {
[key: string]: any;
id: string;
name: string;
permissions: string[];
remark?: string;
status: 0 | 1;
}
}
/**
* 获取角色列表数据
*/
async function getUserList(params: Recordable<any>) {
return requestClient.get<Array<SystemUserApi.SystemUser>>('/user/list', {
params,
});
}
/**
* 创建角色
* @param data 角色数据
*/
async function createUser(data: Omit<SystemUserApi.SystemUser, 'id'>) {
return requestClient.post('/user/create', data);
}
/**
* 更新角色
*
* @param id 角色 ID
* @param data 角色数据
*/
async function updateUser(
id: string,
data: Omit<SystemUserApi.SystemUser, 'id'>,
) {
return requestClient.put(`/user/update/${id}`, data);
}
/**
* 删除角色
* @param id 角色 ID
*/
async function deleteUser(id: string) {
return requestClient.delete(`/user/delete/${id}`);
}
/**
* 重置用户密码
* @param id 用户 ID
* @param data 新密码数据
* @param data.password 新密码
*/
async function resetPassword(id: string, data: { password: string }) {
return requestClient.put(`/user/reset-password/${id}`, data);
}
export { createUser, deleteUser, getUserList, resetPassword, updateUser };

39
apps/web-antd/src/app.vue Normal file
View File

@@ -0,0 +1,39 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { useAntdDesignTokens } from '@vben/hooks';
import { preferences, usePreferences } from '@vben/preferences';
import { App, ConfigProvider, theme } from 'ant-design-vue';
import { antdLocale } from '#/locales';
defineOptions({ name: 'App' });
const { isDark } = usePreferences();
const { tokens } = useAntdDesignTokens();
const tokenTheme = computed(() => {
const algorithm = isDark.value
? [theme.darkAlgorithm]
: [theme.defaultAlgorithm];
// antd 紧凑模式算法
if (preferences.app.compact) {
algorithm.push(theme.compactAlgorithm);
}
return {
algorithm,
token: tokens,
};
});
</script>
<template>
<ConfigProvider :locale="antdLocale" :theme="tokenTheme">
<App>
<RouterView />
</App>
</ConfigProvider>
</template>

View File

@@ -0,0 +1,72 @@
import { createApp, watchEffect } from 'vue';
import { registerAccessDirective } from '@vben/access';
import { registerLoadingDirective } from '@vben/common-ui/es/loading';
import { preferences } from '@vben/preferences';
import { initStores } from '@vben/stores';
import '@vben/styles';
import '@vben/styles/antd';
import { useTitle } from '@vueuse/core';
import { $t, setupI18n } from '#/locales';
import { initComponentAdapter } from './adapter/component';
import App from './app.vue';
import { router } from './router';
async function bootstrap(namespace: string) {
// 初始化组件适配器
await initComponentAdapter();
// // 设置弹窗的默认配置
// setDefaultModalProps({
// fullscreenButton: false,
// });
// // 设置抽屉的默认配置
// setDefaultDrawerProps({
// zIndex: 1020,
// });
const app = createApp(App);
// 注册v-loading指令
registerLoadingDirective(app, {
loading: 'loading', // 在这里可以自定义指令名称也可以明确提供false表示不注册这个指令
spinning: 'spinning',
});
// 国际化 i18n 配置
await setupI18n(app);
// 配置 pinia-tore
await initStores(app, { namespace });
// 安装权限指令
registerAccessDirective(app);
// 初始化 tippy
const { initTippy } = await import('@vben/common-ui/es/tippy');
initTippy(app);
// 配置路由及路由守卫
app.use(router);
// 配置Motion插件
const { MotionPlugin } = await import('@vben/plugins/motion');
app.use(MotionPlugin);
// 动态更新标题
watchEffect(() => {
if (preferences.app.dynamicTitle) {
const routeTitle = router.currentRoute.value.meta?.title;
const pageTitle =
(routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name;
useTitle(pageTitle);
}
});
app.mount('#app');
}
export { bootstrap };

View File

@@ -0,0 +1,21 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { AuthPageLayout } from '@vben/layouts';
import { preferences } from '@vben/preferences';
const appName = computed(() => preferences.app.name);
const logo = computed(() => preferences.logo.source);
</script>
<template>
<AuthPageLayout
:app-name="appName"
:logo="logo"
:page-description="appName"
page-title="大型中后台管理系统"
>
<!-- 自定义工具栏 -->
<!-- <template #toolbar></template> -->
</AuthPageLayout>
</template>

View File

@@ -0,0 +1,81 @@
<script lang="ts" setup>
import type { NotificationItem } from '@vben/layouts';
import { computed, ref, watch } from 'vue';
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
import { useWatermark } from '@vben/hooks';
import { BasicLayout, LockScreen, UserDropdown } from '@vben/layouts';
import { preferences } from '@vben/preferences';
import { useAccessStore, useUserStore } from '@vben/stores';
import { useAuthStore } from '#/store';
import LoginForm from '#/views/_core/authentication/login.vue';
const notifications = ref<NotificationItem[]>([]);
const userStore = useUserStore();
const authStore = useAuthStore();
const accessStore = useAccessStore();
const { destroyWatermark, updateWatermark } = useWatermark();
const _showDot = computed(() =>
notifications.value.some((item) => !item.isRead),
);
const menus = computed(() => []);
const avatar = computed(() => {
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
});
async function handleLogout() {
await authStore.logout(false);
}
function _handleNoticeClear() {
notifications.value = [];
}
function _handleMakeAll() {
notifications.value.forEach((item) => (item.isRead = true));
}
watch(
() => preferences.app.watermark,
async (enable) => {
if (enable) {
await updateWatermark({
content: `${userStore.userInfo?.username} - ${userStore.userInfo?.realName}`,
});
} else {
destroyWatermark();
}
},
{
immediate: true,
},
);
</script>
<template>
<BasicLayout @clear-preferences-and-logout="handleLogout">
<template #user-dropdown>
<UserDropdown :avatar :menus :description="userStore.userInfo?.username" tag-text="云客查" @logout="handleLogout" />
</template>
<!-- <template #notification>
<Notification
:dot="showDot"
:notifications="notifications"
@clear="handleNoticeClear"
@make-all="handleMakeAll"
/>
</template> -->
<template #extra>
<AuthenticationLoginExpiredModal v-model:open="accessStore.loginExpired" :avatar>
<LoginForm />
</AuthenticationLoginExpiredModal>
</template>
<template #lock-screen>
<LockScreen :avatar @to-login="handleLogout" />
</template>
</BasicLayout>
</template>

View File

@@ -0,0 +1,6 @@
const BasicLayout = () => import('./basic.vue');
const AuthPageLayout = () => import('./auth.vue');
const IFrameView = () => import('@vben/layouts').then((m) => m.IFrameView);
export { AuthPageLayout, BasicLayout, IFrameView };

View File

@@ -0,0 +1,3 @@
# locale
每个app使用的国际化可能不同这里用于扩展国际化的功能例如扩展 dayjs、antd组件库的多语言切换以及app本身的国际化文件。

View File

@@ -0,0 +1,102 @@
import type { Locale } from 'ant-design-vue/es/locale';
import type { App } from 'vue';
import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales';
import { ref } from 'vue';
import {
$t,
setupI18n as coreSetup,
loadLocalesMapFromDir,
} from '@vben/locales';
import { preferences } from '@vben/preferences';
import antdEnLocale from 'ant-design-vue/es/locale/en_US';
import antdDefaultLocale from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs';
const antdLocale = ref<Locale>(antdDefaultLocale);
const modules = import.meta.glob('./langs/**/*.json');
const localesMap = loadLocalesMapFromDir(
/\.\/langs\/([^/]+)\/(.*)\.json$/,
modules,
);
/**
* 加载应用特有的语言包
* 这里也可以改造为从服务端获取翻译数据
* @param lang
*/
async function loadMessages(lang: SupportedLanguagesType) {
const [appLocaleMessages] = await Promise.all([
localesMap[lang]?.(),
loadThirdPartyMessage(lang),
]);
return appLocaleMessages?.default;
}
/**
* 加载第三方组件库的语言包
* @param lang
*/
async function loadThirdPartyMessage(lang: SupportedLanguagesType) {
await Promise.all([loadAntdLocale(lang), loadDayjsLocale(lang)]);
}
/**
* 加载dayjs的语言包
* @param lang
*/
async function loadDayjsLocale(lang: SupportedLanguagesType) {
let locale;
switch (lang) {
case 'en-US': {
locale = await import('dayjs/locale/en');
break;
}
case 'zh-CN': {
locale = await import('dayjs/locale/zh-cn');
break;
}
// 默认使用英语
default: {
locale = await import('dayjs/locale/en');
}
}
if (locale) {
dayjs.locale(locale);
} else {
console.error(`Failed to load dayjs locale for ${lang}`);
}
}
/**
* 加载antd的语言包
* @param lang
*/
async function loadAntdLocale(lang: SupportedLanguagesType) {
switch (lang) {
case 'en-US': {
antdLocale.value = antdEnLocale;
break;
}
case 'zh-CN': {
antdLocale.value = antdDefaultLocale;
break;
}
}
}
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
await coreSetup(app, {
defaultLocale: preferences.app.locale,
loadMessages,
missingWarn: !import.meta.env.PROD,
...options,
});
}
export { $t, antdLocale, setupI18n };

View File

@@ -0,0 +1,31 @@
export default {
platformUser: {
name: '平台用户',
list: '平台用户列表',
field: {
mobile: '手机号',
nickname: '昵称',
platform: '用户平台',
inside: '是否内部用户',
createTime: '创建时间',
updateTime: '更新时间',
info: '备注信息',
},
search: {
mobile: '请输入手机号',
nickname: '请输入昵称',
platform: '请选择用户平台',
inside: '请选择是否内部用户',
createTime: '请选择创建时间',
},
operation: '操作',
platformMap: {
h5: 'H5',
wechat: '微信',
},
insideMap: {
1: '是',
0: '否',
},
},
};

View File

@@ -0,0 +1,12 @@
{
"title": "Demos",
"antd": "Ant Design Vue",
"vben": {
"title": "Project",
"about": "About",
"document": "Document",
"antdv": "Ant Design Vue Version",
"naive-ui": "Naive UI Version",
"element-plus": "Element Plus Version"
}
}

View File

@@ -0,0 +1,14 @@
{
"auth": {
"login": "Login",
"register": "Register",
"codeLogin": "Code Login",
"qrcodeLogin": "Qr Code Login",
"forgetPassword": "Forget Password"
},
"dashboard": {
"title": "Dashboard",
"analytics": "Analytics",
"workspace": "Workspace"
}
}

View File

@@ -0,0 +1,99 @@
{
"title": "System Management",
"dept": {
"name": "Department",
"title": "Department Management",
"deptName": "Department Name",
"status": "Status",
"createTime": "Create Time",
"remark": "Remark",
"operation": "Operation",
"parentDept": "Parent Department"
},
"menu": {
"title": "Menu Management",
"parent": "Parent Menu",
"menuTitle": "Title",
"menuName": "Menu Name",
"name": "Menu",
"type": "Type",
"typeCatalog": "Catalog",
"typeMenu": "Menu",
"typeButton": "Button",
"typeLink": "Link",
"typeEmbedded": "Embedded",
"icon": "Icon",
"activeIcon": "Active Icon",
"activePath": "Active Path",
"path": "Route Path",
"component": "Component",
"status": "Status",
"authCode": "Auth Code",
"badge": "Badge",
"operation": "Operation",
"linkSrc": "Link Address",
"affixTab": "Affix In Tabs",
"keepAlive": "Keep Alive",
"hideInMenu": "Hide In Menu",
"hideInTab": "Hide In Tabbar",
"hideChildrenInMenu": "Hide Children In Menu",
"hideInBreadcrumb": "Hide In Breadcrumb",
"advancedSettings": "Other Settings",
"activePathMustExist": "The path could not find a valid menu",
"activePathHelp": "When jumping to the current route, \nthe menu path that needs to be activated must be specified when it does not display in the navigation menu.",
"badgeType": {
"title": "Badge Type",
"dot": "Dot",
"normal": "Text",
"none": "None"
},
"badgeVariants": "Badge Style"
},
"role": {
"title": "Role Management",
"list": "Role List",
"name": "Role",
"roleName": "Role Name",
"id": "Role ID",
"status": "Status",
"remark": "Remark",
"createTime": "Creation Time",
"operation": "Operation",
"permissions": "Permissions",
"setPermissions": "Permissions",
"setApiPermissions": "API Permissions",
"roleCode": "Role Code",
"description": "Description"
},
"api": {
"title": "API Management",
"list": "API List",
"name": "API",
"apiName": "API Name",
"apiCode": "API Code",
"method": "Request Method",
"url": "API URL",
"status": "Status",
"description": "Description",
"createTime": "Create Time",
"operation": "Operation",
"permissions": "Permissions",
"setPermissions": "Set Permissions"
},
"user": {
"title": "User Management",
"name": "User",
"list": "User List",
"userName": "Username",
"realName": "Real Name",
"status": "Status",
"setPermissions": "Set Permissions",
"createTime": "Create Time",
"operation": "Operation",
"resetPassword": "Reset Password",
"newPassword": "New Password",
"confirmPassword": "Confirm Password",
"confirmPasswordRequired": "Please confirm password",
"passwordMismatch": "The two passwords do not match"
}
}

View File

@@ -0,0 +1,12 @@
{
"title": "演示",
"antd": "Ant Design Vue",
"vben": {
"title": "项目",
"about": "关于",
"document": "文档",
"antdv": "Ant Design Vue 版本",
"naive-ui": "Naive UI 版本",
"element-plus": "Element Plus 版本"
}
}

View File

@@ -0,0 +1,14 @@
{
"auth": {
"login": "登录",
"register": "注册",
"codeLogin": "验证码登录",
"qrcodeLogin": "二维码登录",
"forgetPassword": "忘记密码"
},
"dashboard": {
"title": "概览",
"analytics": "分析页",
"workspace": "工作台"
}
}

View File

@@ -0,0 +1,101 @@
{
"dept": {
"list": "部门列表",
"createTime": "创建时间",
"deptName": "部门名称",
"name": "部门",
"operation": "操作",
"parentDept": "上级部门",
"remark": "备注",
"status": "状态",
"title": "部门管理"
},
"menu": {
"list": "菜单列表",
"activeIcon": "激活图标",
"activePath": "激活路径",
"activePathHelp": "跳转到当前路由时,需要激活的菜单路径。\n当不在导航菜单中显示时需要指定激活路径",
"activePathMustExist": "该路径未能找到有效的菜单",
"advancedSettings": "其它设置",
"affixTab": "固定在标签",
"authCode": "权限标识",
"badge": "徽章内容",
"badgeVariants": "徽标样式",
"badgeType": {
"dot": "点",
"none": "无",
"normal": "文字",
"title": "徽标类型"
},
"component": "页面组件",
"hideChildrenInMenu": "隐藏子菜单",
"hideInBreadcrumb": "在面包屑中隐藏",
"hideInMenu": "隐藏菜单",
"hideInTab": "在标签栏中隐藏",
"icon": "图标",
"keepAlive": "缓存标签页",
"linkSrc": "链接地址",
"menuName": "菜单名称",
"menuTitle": "标题",
"name": "菜单",
"operation": "操作",
"parent": "上级菜单",
"path": "路由地址",
"status": "状态",
"title": "菜单管理",
"type": "类型",
"typeButton": "按钮",
"typeCatalog": "目录",
"typeEmbedded": "内嵌",
"typeLink": "外链",
"typeMenu": "菜单"
},
"role": {
"title": "角色管理",
"list": "角色列表",
"name": "角色",
"roleName": "角色名称",
"id": "角色ID",
"status": "状态",
"remark": "备注",
"createTime": "创建时间",
"operation": "操作",
"permissions": "权限",
"setPermissions": "授权",
"setApiPermissions": "API权限",
"roleCode": "角色编号",
"description": "描述"
},
"title": "系统管理",
"api": {
"title": "API管理",
"list": "API列表",
"name": "API",
"apiName": "API名称",
"apiCode": "API编码",
"method": "请求方法",
"url": "API地址",
"status": "状态",
"description": "描述",
"createTime": "创建时间",
"operation": "操作",
"permissions": "权限",
"setPermissions": "设置权限"
},
"user": {
"title": "用户管理",
"name": "用户",
"list": "用户列表",
"userName": "用户名",
"realName": "真实姓名",
"status": "状态",
"setPermissions": "设置权限",
"createTime": "创建时间",
"operation": "操作",
"resetPassword": "重置密码",
"newPassword": "新密码",
"confirmPassword": "确认密码",
"confirmPasswordRequired": "请确认密码",
"passwordMismatch": "两次输入的密码不一致"
}
}

31
apps/web-antd/src/main.ts Normal file
View File

@@ -0,0 +1,31 @@
import { initPreferences } from '@vben/preferences';
import { unmountGlobalLoading } from '@vben/utils';
import { overridesPreferences } from './preferences';
/**
* 应用初始化完成之后再进行页面加载渲染
*/
async function initApplication() {
// name用于指定项目唯一标识
// 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据
const env = import.meta.env.PROD ? 'prod' : 'dev';
const appVersion = import.meta.env.VITE_APP_VERSION;
const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`;
// app偏好设置初始化
await initPreferences({
namespace,
overrides: overridesPreferences,
});
// 启动应用并挂载
// vue应用主要逻辑及视图
const { bootstrap } = await import('./bootstrap');
await bootstrap(namespace);
// 移除并销毁loading
unmountGlobalLoading();
}
initApplication();

View File

@@ -0,0 +1,27 @@
import { defineOverridesPreferences } from '@vben/preferences';
/**
* @description 项目配置文件
* 只需要覆盖项目中的一部分配置,不需要的配置不用覆盖,会自动使用默认配置
* !!! 更改配置后请清空缓存,否则可能不生效
*/
export const overridesPreferences = defineOverridesPreferences({
// overrides
app: {
name: import.meta.env.VITE_APP_TITLE,
accessMode: 'backend',
},
logo: {
source: 'https://admin.dsjcq168.cn/logo.png',
},
copyright: {
companyName: '成都市玖诺诚信息技术咨询有限公司',
companySiteLink: 'https://www.dsjcq168.cn',
date: '2025',
icp: '蜀ICP备2025178588号-1',
icpLink: 'https://beian.miit.gov.cn/',
},
footer: {
enable: false,
},
});

View File

@@ -0,0 +1,42 @@
import type {
ComponentRecordType,
GenerateMenuAndRoutesOptions,
} from '@vben/types';
import { generateAccessible } from '@vben/access';
import { preferences } from '@vben/preferences';
import { message } from 'ant-design-vue';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
const layoutMap: ComponentRecordType = {
BasicLayout,
IFrameView,
};
return await generateAccessible(preferences.app.accessMode, {
...options,
fetchMenuListAsync: async () => {
message.loading({
content: `${$t('common.loadingMenu')}...`,
duration: 1.5,
});
return await getAllMenusApi();
},
// 可以指定没有权限跳转403页面
forbiddenComponent,
// 如果 route.meta.menuVisibleWithForbidden = true
layoutMap,
pageMap,
});
}
export { generateAccess };

View File

@@ -0,0 +1,133 @@
import type { Router } from 'vue-router';
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
import { preferences } from '@vben/preferences';
import { useAccessStore, useUserStore } from '@vben/stores';
import { startProgress, stopProgress } from '@vben/utils';
import { accessRoutes, coreRouteNames } from '#/router/routes';
import { useAuthStore } from '#/store';
import { generateAccess } from './access';
/**
* 通用守卫配置
* @param router
*/
function setupCommonGuard(router: Router) {
// 记录已经加载的页面
const loadedPaths = new Set<string>();
router.beforeEach(async (to) => {
to.meta.loaded = loadedPaths.has(to.path);
// 页面加载进度条
if (!to.meta.loaded && preferences.transition.progress) {
startProgress();
}
return true;
});
router.afterEach((to) => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
loadedPaths.add(to.path);
// 关闭页面加载进度条
if (preferences.transition.progress) {
stopProgress();
}
});
}
/**
* 权限访问守卫配置
* @param router
*/
function setupAccessGuard(router: Router) {
router.beforeEach(async (to, from) => {
const accessStore = useAccessStore();
const userStore = useUserStore();
const authStore = useAuthStore();
// 基本路由,这些路由不需要进入权限拦截
if (coreRouteNames.includes(to.name as string)) {
if (to.path === LOGIN_PATH && accessStore.accessToken) {
return decodeURIComponent(
(to.query?.redirect as string) ||
userStore.userInfo?.homePath ||
DEFAULT_HOME_PATH,
);
}
return true;
}
// accessToken 检查
if (!accessStore.accessToken) {
// 明确声明忽略权限访问权限,则可以访问
if (to.meta.ignoreAccess) {
return true;
}
// 没有访问权限,跳转登录页面
if (to.fullPath !== LOGIN_PATH) {
return {
path: LOGIN_PATH,
// 如不需要,直接删除 query
query:
to.fullPath === DEFAULT_HOME_PATH
? {}
: { redirect: encodeURIComponent(to.fullPath) },
// 携带当前跳转的页面,登录后重新跳转该页面
replace: true,
};
}
return to;
}
// 是否已经生成过动态路由
if (accessStore.isAccessChecked) {
return true;
}
// 生成路由表
// 当前登录用户拥有的角色标识列表
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
const userRoles = userInfo.roles ?? [];
// 生成菜单和路由
const { accessibleMenus, accessibleRoutes } = await generateAccess({
roles: userRoles,
router,
// 则会在菜单中显示但是访问会被重定向到403
routes: accessRoutes,
});
// 保存菜单信息和路由信息
accessStore.setAccessMenus(accessibleMenus);
accessStore.setAccessRoutes(accessibleRoutes);
accessStore.setIsAccessChecked(true);
const redirectPath = (from.query.redirect ??
(to.path === DEFAULT_HOME_PATH
? userInfo.homePath || DEFAULT_HOME_PATH
: to.fullPath)) as string;
return {
...router.resolve(decodeURIComponent(redirectPath)),
replace: true,
};
});
}
/**
* 项目守卫配置
* @param router
*/
function createRouterGuard(router: Router) {
/** 通用 */
setupCommonGuard(router);
/** 权限访问 */
setupAccessGuard(router);
}
export { createRouterGuard };

View File

@@ -0,0 +1,37 @@
import {
createRouter,
createWebHashHistory,
createWebHistory,
} from 'vue-router';
import { resetStaticRoutes } from '@vben/utils';
import { createRouterGuard } from './guard';
import { routes } from './routes';
/**
* @zh_CN 创建vue-router实例
*/
const router = createRouter({
history:
import.meta.env.VITE_ROUTER_HISTORY === 'hash'
? createWebHashHistory(import.meta.env.VITE_BASE)
: createWebHistory(import.meta.env.VITE_BASE),
// 应该添加到路由的初始路由列表。
routes,
scrollBehavior: (to, _from, savedPosition) => {
if (savedPosition) {
return savedPosition;
}
return to.hash ? { behavior: 'smooth', el: to.hash } : { left: 0, top: 0 };
},
// 是否应该禁止尾部斜杠。
// strict: true,
});
const resetRoutes = () => resetStaticRoutes(router, routes);
// 创建路由守卫
createRouterGuard(router);
export { resetRoutes, router };

View File

@@ -0,0 +1,96 @@
import type { RouteRecordRaw } from 'vue-router';
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
import { $t } from '#/locales';
const BasicLayout = () => import('#/layouts/basic.vue');
const AuthPageLayout = () => import('#/layouts/auth.vue');
/** 全局404页面 */
const fallbackNotFoundRoute: RouteRecordRaw = {
component: () => import('#/views/_core/fallback/not-found.vue'),
meta: {
hideInBreadcrumb: true,
hideInMenu: true,
hideInTab: true,
title: '404',
},
name: 'FallbackNotFound',
path: '/:path(.*)*',
};
/** 基本路由,这些路由是必须存在的 */
const coreRoutes: RouteRecordRaw[] = [
/**
* 根路由
* 使用基础布局作为所有页面的父级容器子级就不必配置BasicLayout。
* 此路由必须存在,且不应修改
*/
{
component: BasicLayout,
meta: {
hideInBreadcrumb: true,
title: 'Root',
},
name: 'Root',
path: '/',
redirect: DEFAULT_HOME_PATH,
children: [],
},
{
component: AuthPageLayout,
meta: {
hideInTab: true,
title: 'Authentication',
},
name: 'Authentication',
path: '/auth',
redirect: LOGIN_PATH,
children: [
{
name: 'Login',
path: 'login',
component: () => import('#/views/_core/authentication/login.vue'),
meta: {
title: $t('page.auth.login'),
},
},
{
name: 'CodeLogin',
path: 'code-login',
component: () => import('#/views/_core/authentication/code-login.vue'),
meta: {
title: $t('page.auth.codeLogin'),
},
},
{
name: 'QrCodeLogin',
path: 'qrcode-login',
component: () =>
import('#/views/_core/authentication/qrcode-login.vue'),
meta: {
title: $t('page.auth.qrcodeLogin'),
},
},
{
name: 'ForgetPassword',
path: 'forget-password',
component: () =>
import('#/views/_core/authentication/forget-password.vue'),
meta: {
title: $t('page.auth.forgetPassword'),
},
},
{
name: 'Register',
path: 'register',
component: () => import('#/views/_core/authentication/register.vue'),
meta: {
title: $t('page.auth.register'),
},
},
],
},
];
export { coreRoutes, fallbackNotFoundRoute };

View File

@@ -0,0 +1,46 @@
import type { RouteRecordRaw } from 'vue-router';
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
import { coreRoutes, fallbackNotFoundRoute } from './core';
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
eager: true,
});
// 有需要可以自行打开注释,并创建文件夹
// const externalRouteFiles = import.meta.glob('./external/**/*.ts', { eager: true });
// const staticRouteFiles = import.meta.glob('./static/**/*.ts', { eager: true });
/** 动态路由 */
const dynamicRoutes: RouteRecordRaw[] = mergeRouteModules(dynamicRouteFiles);
/** 外部路由列表访问这些页面可以不需要Layout可能用于内嵌在别的系统(不会显示在菜单中) */
// const externalRoutes: RouteRecordRaw[] = mergeRouteModules(externalRouteFiles);
// const staticRoutes: RouteRecordRaw[] = mergeRouteModules(staticRouteFiles);
const staticRoutes: RouteRecordRaw[] = [];
const externalRoutes: RouteRecordRaw[] = [];
/** 路由列表由基本路由、外部路由和404兜底路由组成
* 无需走权限验证(会一直显示在菜单中) */
const routes: RouteRecordRaw[] = [
...coreRoutes,
...externalRoutes,
fallbackNotFoundRoute,
];
/** 基本路由列表,这些路由不需要进入权限拦截 */
const coreRouteNames = traverseTreeValues(coreRoutes, (route) => route.name);
/** 有权限校验的路由列表,包含动态路由和静态路由 */
const accessRoutes = [...dynamicRoutes, ...staticRoutes];
const componentKeys: string[] = Object.keys(
import.meta.glob('../../views/**/*.vue'),
)
.filter((item) => !item.includes('/modules/'))
.map((v) => {
const path = v.replace('../../views/', '/');
return path.endsWith('.vue') ? path.slice(0, -4) : path;
});
export { accessRoutes, componentKeys, coreRouteNames, routes };

View File

@@ -0,0 +1,72 @@
import type { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'mdi:account-group',
order: 2000,
title: '代理管理',
},
name: 'Agent',
path: '/agent',
children: [
{
path: '/agent/list',
name: 'AgentList',
meta: {
icon: 'mdi:account-multiple',
title: '代理列表',
},
component: () => import('#/views/agent/agent-list/list.vue'),
},
{
path: '/agent/links',
name: 'AgentLinks',
meta: {
icon: 'mdi:link-variant',
title: '推广链接',
},
component: () => import('#/views/agent/agent-links/list.vue'),
},
{
path: '/agent/commission',
name: 'AgentCommission',
meta: {
icon: 'mdi:cash-multiple',
title: '佣金记录',
},
component: () => import('#/views/agent/agent-commission/list.vue'),
},
{
path: '/agent/order',
name: 'AgentOrder',
meta: {
icon: 'mdi:package-variant',
title: '订单记录',
},
component: () => import('#/views/agent/agent-order/list.vue'),
},
{
path: '/agent/config',
name: 'AgentConfig',
meta: {
icon: 'mdi:cog',
title: '系统配置',
},
component: () => import('#/views/agent/agent-config/list.vue'),
},
{
path: '/agent/product-config',
name: 'AgentProductConfig',
meta: {
icon: 'mdi:package-variant-closed',
title: '产品配置',
},
component: () => import('#/views/agent/agent-product-config/list.vue'),
},
],
},
];
export default routes;

View File

@@ -0,0 +1,38 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'lucide:layout-dashboard',
order: -1,
title: $t('page.dashboard.title'),
},
name: 'Dashboard',
path: '/dashboard',
children: [
{
name: 'Analytics',
path: '/analytics',
component: () => import('#/views/dashboard/analytics/index.vue'),
meta: {
affixTab: true,
icon: 'lucide:area-chart',
title: $t('page.dashboard.analytics'),
},
},
{
name: 'Workspace',
path: '/workspace',
component: () => import('#/views/dashboard/workspace/index.vue'),
meta: {
icon: 'carbon:workspace',
title: $t('page.dashboard.workspace'),
},
},
],
},
];
export default routes;

View File

@@ -0,0 +1,16 @@
import type { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'lucide:shopping-cart',
order: 1000,
title: '订单管理',
},
name: 'Order',
path: '/order',
component: () => import('#/views/order/order/index.vue'),
},
];
export default routes;

View File

@@ -0,0 +1,64 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'ion:settings-outline',
order: 9997,
title: $t('system.title'),
},
name: 'System',
path: '/system',
children: [
{
path: '/system/user',
name: 'SystemUser',
meta: {
icon: 'mdi:account',
title: $t('system.user.title'),
},
component: () => import('#/views/system/user/list.vue'),
},
{
path: '/system/role',
name: 'SystemRole',
meta: {
icon: 'mdi:account-group',
title: $t('system.role.title'),
},
component: () => import('#/views/system/role/list.vue'),
},
{
path: '/system/api',
name: 'SystemApi',
meta: {
icon: 'mdi:api',
title: $t('system.api.title'),
},
component: () => import('#/views/system/api/list.vue'),
},
{
path: '/system/menu',
name: 'SystemMenu',
meta: {
icon: 'mdi:menu',
title: $t('system.menu.title'),
},
component: () => import('#/views/system/menu/list.vue'),
},
{
path: '/system/dept',
name: 'SystemDept',
meta: {
icon: 'charm:organisation',
title: $t('system.dept.title'),
},
component: () => import('#/views/system/dept/list.vue'),
},
],
},
];
export default routes;

View File

@@ -0,0 +1,115 @@
import type { Recordable, UserInfo } from '@vben/types';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { DEFAULT_HOME_PATH, LOGIN_PATH } from '@vben/constants';
import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { notification } from 'ant-design-vue';
import { defineStore } from 'pinia';
import { getAccessCodesApi, getUserInfoApi, loginApi, logoutApi } from '#/api';
import { $t } from '#/locales';
export const useAuthStore = defineStore('auth', () => {
const accessStore = useAccessStore();
const userStore = useUserStore();
const router = useRouter();
const loginLoading = ref(false);
/**
* 异步处理登录操作
* Asynchronously handle the login process
* @param params 登录表单数据
*/
async function authLogin(
params: Recordable<any>,
onSuccess?: () => Promise<void> | void,
) {
// 异步处理用户登录操作并获取 accessToken
let userInfo: null | UserInfo = null;
try {
loginLoading.value = true;
const { access_token } = await loginApi(params);
console.info('accessToken', access_token);
// 如果成功获取到 accessToken
if (access_token) {
accessStore.setAccessToken(access_token);
// 获取用户信息并存储到 accessStore 中
const [fetchUserInfoResult, accessCodes] = await Promise.all([
fetchUserInfo(),
getAccessCodesApi(),
]);
userInfo = fetchUserInfoResult;
userStore.setUserInfo(userInfo);
accessStore.setAccessCodes(accessCodes);
if (accessStore.loginExpired) {
accessStore.setLoginExpired(false);
} else {
onSuccess
? await onSuccess?.()
: await router.push(userInfo.homePath || DEFAULT_HOME_PATH);
}
if (userInfo?.realName) {
notification.success({
description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.realName}`,
duration: 3,
message: $t('authentication.loginSuccess'),
});
}
}
} finally {
loginLoading.value = false;
}
return {
userInfo,
};
}
async function logout(redirect: boolean = true) {
try {
await logoutApi();
} catch {
// 不做任何处理
}
resetAllStores();
accessStore.setLoginExpired(false);
// 回登录页带上当前路由地址
await router.replace({
path: LOGIN_PATH,
query: redirect
? {
redirect: encodeURIComponent(router.currentRoute.value.fullPath),
}
: {},
});
}
async function fetchUserInfo() {
let userInfo: null | UserInfo = null;
userInfo = await getUserInfoApi();
userStore.setUserInfo(userInfo);
return userInfo;
}
function $reset() {
loginLoading.value = false;
}
return {
$reset,
authLogin,
fetchUserInfo,
loginLoading,
logout,
};
});

View File

@@ -0,0 +1 @@
export * from './auth';

View File

@@ -0,0 +1,3 @@
# \_core
此目录包含应用程序正常运行所需的基本视图。这些视图是应用程序布局中使用的视图。

View File

@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { About } from '@vben/common-ui';
defineOptions({ name: 'About' });
</script>
<template>
<About />
</template>

View File

@@ -0,0 +1,69 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import { computed, ref } from 'vue';
import { AuthenticationCodeLogin, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
defineOptions({ name: 'CodeLogin' });
const loading = ref(false);
const CODE_LENGTH = 6;
const formSchema = computed((): VbenFormSchema[] => {
return [
{
component: 'VbenInput',
componentProps: {
placeholder: $t('authentication.mobile'),
},
fieldName: 'phoneNumber',
label: $t('authentication.mobile'),
rules: z
.string()
.min(1, { message: $t('authentication.mobileTip') })
.refine((v) => /^\d{11}$/.test(v), {
message: $t('authentication.mobileErrortip'),
}),
},
{
component: 'VbenPinInput',
componentProps: {
codeLength: CODE_LENGTH,
createText: (countdown: number) => {
const text =
countdown > 0
? $t('authentication.sendText', [countdown])
: $t('authentication.sendCode');
return text;
},
placeholder: $t('authentication.code'),
},
fieldName: 'code',
label: $t('authentication.code'),
rules: z.string().length(CODE_LENGTH, {
message: $t('authentication.codeTip', [CODE_LENGTH]),
}),
},
];
});
/**
* 异步处理登录操作
* Asynchronously handle the login process
* @param values 登录表单数据
*/
async function handleLogin(values: Recordable<any>) {
// eslint-disable-next-line no-console
console.log(values);
}
</script>
<template>
<AuthenticationCodeLogin
:form-schema="formSchema"
:loading="loading"
@submit="handleLogin"
/>
</template>

View File

@@ -0,0 +1,43 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import { computed, ref } from 'vue';
import { AuthenticationForgetPassword, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
defineOptions({ name: 'ForgetPassword' });
const loading = ref(false);
const formSchema = computed((): VbenFormSchema[] => {
return [
{
component: 'VbenInput',
componentProps: {
placeholder: 'example@example.com',
},
fieldName: 'email',
label: $t('authentication.email'),
rules: z
.string()
.min(1, { message: $t('authentication.emailTip') })
.email($t('authentication.emailValidErrorTip')),
},
];
});
function handleSubmit(value: Recordable<any>) {
// eslint-disable-next-line no-console
console.log('reset email:', value);
}
</script>
<template>
<AuthenticationForgetPassword
:form-schema="formSchema"
:loading="loading"
@submit="handleSubmit"
/>
</template>

View File

@@ -0,0 +1,57 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '@vben/common-ui';
import { computed, markRaw } from 'vue';
import { AuthenticationLogin, SliderCaptcha, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
import { useAuthStore } from '#/store';
defineOptions({ name: 'Login' });
const authStore = useAuthStore();
const formSchema = computed((): VbenFormSchema[] => {
return [
{
component: 'VbenInput',
componentProps: {
placeholder: $t('authentication.usernameTip'),
},
fieldName: 'username',
label: $t('authentication.username'),
rules: z.string().min(1, { message: $t('authentication.usernameTip') }),
},
{
component: 'VbenInputPassword',
componentProps: {
placeholder: $t('authentication.password'),
},
fieldName: 'password',
label: $t('authentication.password'),
rules: z.string().min(1, { message: $t('authentication.passwordTip') }),
},
{
component: markRaw(SliderCaptcha),
fieldName: 'captcha',
rules: z.boolean().refine((value) => value, {
message: $t('authentication.verifyRequiredTip'),
}),
},
];
});
</script>
<template>
<AuthenticationLogin
:form-schema="formSchema"
:loading="authStore.loginLoading"
:show-third-party-login="false"
:show-register="false"
:show-forget-password="false"
:show-qrcode-login="false"
:show-code-login="false"
@submit="authStore.authLogin"
/>
</template>

View File

@@ -0,0 +1,10 @@
<script lang="ts" setup>
import { AuthenticationQrCodeLogin } from '@vben/common-ui';
import { LOGIN_PATH } from '@vben/constants';
defineOptions({ name: 'QrCodeLogin' });
</script>
<template>
<AuthenticationQrCodeLogin :login-path="LOGIN_PATH" />
</template>

View File

@@ -0,0 +1,96 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '@vben/common-ui';
import type { Recordable } from '@vben/types';
import { computed, h, ref } from 'vue';
import { AuthenticationRegister, z } from '@vben/common-ui';
import { $t } from '@vben/locales';
defineOptions({ name: 'Register' });
const loading = ref(false);
const formSchema = computed((): VbenFormSchema[] => {
return [
{
component: 'VbenInput',
componentProps: {
placeholder: $t('authentication.usernameTip'),
},
fieldName: 'username',
label: $t('authentication.username'),
rules: z.string().min(1, { message: $t('authentication.usernameTip') }),
},
{
component: 'VbenInputPassword',
componentProps: {
passwordStrength: true,
placeholder: $t('authentication.password'),
},
fieldName: 'password',
label: $t('authentication.password'),
renderComponentContent() {
return {
strengthText: () => $t('authentication.passwordStrength'),
};
},
rules: z.string().min(1, { message: $t('authentication.passwordTip') }),
},
{
component: 'VbenInputPassword',
componentProps: {
placeholder: $t('authentication.confirmPassword'),
},
dependencies: {
rules(values) {
const { password } = values;
return z
.string({ required_error: $t('authentication.passwordTip') })
.min(1, { message: $t('authentication.passwordTip') })
.refine((value) => value === password, {
message: $t('authentication.confirmPasswordTip'),
});
},
triggerFields: ['password'],
},
fieldName: 'confirmPassword',
label: $t('authentication.confirmPassword'),
},
{
component: 'VbenCheckbox',
fieldName: 'agreePolicy',
renderComponentContent: () => ({
default: () =>
h('span', [
$t('authentication.agree'),
h(
'a',
{
class: 'vben-link ml-1 ',
href: '',
},
`${$t('authentication.privacyPolicy')} & ${$t('authentication.terms')}`,
),
]),
}),
rules: z.boolean().refine((value) => !!value, {
message: $t('authentication.agreeTip'),
}),
},
];
});
function handleSubmit(value: Recordable<any>) {
// eslint-disable-next-line no-console
console.log('register submit:', value);
}
</script>
<template>
<AuthenticationRegister
:form-schema="formSchema"
:loading="loading"
@submit="handleSubmit"
/>
</template>

View File

@@ -0,0 +1,7 @@
<script lang="ts" setup>
import { Fallback } from '@vben/common-ui';
</script>
<template>
<Fallback status="coming-soon" />
</template>

View File

@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { Fallback } from '@vben/common-ui';
defineOptions({ name: 'Fallback403Demo' });
</script>
<template>
<Fallback status="403" />
</template>

View File

@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { Fallback } from '@vben/common-ui';
defineOptions({ name: 'Fallback500Demo' });
</script>
<template>
<Fallback status="500" />
</template>

View File

@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { Fallback } from '@vben/common-ui';
defineOptions({ name: 'Fallback404Demo' });
</script>
<template>
<Fallback status="404" />
</template>

View File

@@ -0,0 +1,9 @@
<script lang="ts" setup>
import { Fallback } from '@vben/common-ui';
defineOptions({ name: 'FallbackOfflineDemo' });
</script>
<template>
<Fallback status="offline" />
</template>

View File

@@ -0,0 +1,74 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
// 佣金记录列表列配置
export function useCommissionColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'order_id',
title: '订单ID',
width: 100,
},
{
field: 'amount',
title: '佣金金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'product_name',
title: '产品名称',
width: 150,
},
{
field: 'status',
title: '状态',
width: 100,
formatter: ({ cellValue }: { cellValue: number }) => {
const statusMap: Record<number, string> = {
0: '待结算',
1: '已结算',
2: '已取消',
};
return statusMap[cellValue] || '未知';
},
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
];
}
// 佣金记录搜索表单配置
export function useCommissionFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
allowClear: true,
options: [
{ label: '待结算', value: 0 },
{ label: '已结算', value: 1 },
{ label: '已取消', value: 2 },
],
},
},
];
}

View File

@@ -0,0 +1,64 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentCommissionList } from '#/api/agent';
import { useCommissionColumns, useCommissionFormSchema } from './data';
interface Props {
agentId?: number;
}
interface QueryParams {
currentPage: number;
pageSize: number;
[key: string]: any;
}
const props = defineProps<Props>();
const queryParams = computed(() => ({
...(props.agentId ? { agent_id: props.agentId } : {}),
}));
const [Grid] = useVbenVxeGrid({
formOptions: {
schema: useCommissionFormSchema(),
submitOnChange: true,
},
gridOptions: {
columns: useCommissionColumns(),
proxyConfig: {
ajax: {
query: async ({
page,
form,
}: {
form: Record<string, any>;
page: QueryParams;
}) => {
return await getAgentCommissionList({
...queryParams.value,
...form,
page: page.currentPage,
pageSize: page.pageSize,
});
},
},
props: {
result: 'items',
total: 'total',
},
},
},
});
</script>
<template>
<Page :auto-content-height="!agentId">
<Grid :table-title="agentId ? '佣金记录列表' : '所有佣金记录'" />
</Page>
</template>

View File

@@ -0,0 +1,93 @@
<script lang="ts" setup>
import type { AgentApi } from '#/api/agent';
import { onMounted, reactive, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Card, Col, Form, InputNumber, Row, Space, message } from 'ant-design-vue';
import { getAgentConfig, updateAgentConfig } from '#/api/agent';
const loading = ref(false);
const config = ref<AgentApi.AgentConfig | null>(null);
// 系统简化后:只保留税率配置(移除免税额度)
const formData = reactive<AgentApi.AgentConfig>({
tax_rate: 0,
});
// 加载配置
async function loadConfig() {
loading.value = true;
try {
const res = await getAgentConfig();
config.value = res;
Object.assign(formData, res);
} catch (error) {
console.error('加载配置失败:', error);
} finally {
loading.value = false;
}
}
// 保存配置
async function handleSave() {
try {
const params: AgentApi.UpdateAgentConfigParams = {
tax_rate: formData.tax_rate,
};
await updateAgentConfig(params);
message.success('配置保存成功');
loadConfig();
} catch (error) {
console.error('保存配置失败:', error);
}
}
// 重置配置
function handleReset() {
if (config.value) {
Object.assign(formData, config.value);
}
}
onMounted(() => {
loadConfig();
});
</script>
<template>
<Page auto-content-height>
<Card title="代理系统配置" :loading="loading">
<Form layout="vertical">
<Card title="税费配置" size="small" class="mb-4">
<Row :gutter="[16, 16]">
<Col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
<Form.Item name="tax_rate" label="税率例如0.06表示6%">
<InputNumber
v-model:value="formData.tax_rate"
:min="0"
:max="1"
:precision="4"
:step="0.0001"
style="width: 100%"
/>
</Form.Item>
</Col>
</Row>
<div class="text-sm text-gray-500">
<p> 税率代理提现时需要扣除的税率0.06 = 6%</p>
<p> 税费计算公式税费 = 提现金额 × 税率</p>
<p> 实际到账 = 提现金额 - 税费</p>
</div>
</Card>
<Space>
<Button type="primary" @click="handleSave">保存配置</Button>
<Button @click="handleReset">重置</Button>
</Space>
</Form>
</Card>
</Page>
</template>

View File

@@ -0,0 +1,62 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
// 推广链接列表列配置
export function useLinkColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'product_id',
title: '产品ID',
width: 100,
},
{
field: 'product_name',
title: '产品名称',
width: 150,
},
{
field: 'set_price',
title: '设定价格',
width: 120,
formatter: ({ cellValue }) => `¥${cellValue.toFixed(2)}`,
},
{
field: 'short_link',
title: '短链链接',
minWidth: 200,
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
];
}
// 推广链接搜索表单配置
export function useLinkFormSchema(): VbenFormSchema[] {
return [
{
component: 'InputNumber',
fieldName: 'product_id',
label: '产品ID',
},
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
{
component: 'Input',
fieldName: 'link_identifier',
label: '推广码',
},
];
}

View File

@@ -0,0 +1,64 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentLinkList } from '#/api/agent';
import { useLinkColumns, useLinkFormSchema } from './data';
interface Props {
agentId?: number;
}
interface QueryParams {
currentPage: number;
pageSize: number;
[key: string]: any;
}
const props = defineProps<Props>();
const queryParams = computed(() => ({
...(props.agentId ? { agent_id: props.agentId } : {}),
}));
const [Grid] = useVbenVxeGrid({
formOptions: {
schema: useLinkFormSchema(),
submitOnChange: true,
},
gridOptions: {
columns: useLinkColumns(),
proxyConfig: {
ajax: {
query: async ({
page,
form,
}: {
form: Record<string, any>;
page: QueryParams;
}) => {
return await getAgentLinkList({
...queryParams.value,
...form,
page: page.currentPage,
pageSize: page.pageSize,
});
},
},
props: {
result: 'items',
total: 'total',
},
},
},
});
</script>
<template>
<Page :auto-content-height="!agentId">
<Grid :table-title="agentId ? '推广链接列表' : '所有推广链接'" />
</Page>
</template>

View File

@@ -0,0 +1,380 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
// 表单配置(系统简化:移除等级)
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'mobile',
label: '手机号',
rules: 'required',
},
{
component: 'Input',
fieldName: 'region',
label: '区域',
rules: 'required',
},
{
component: 'Input',
fieldName: 'wechat_id',
label: '微信号',
},
];
}
// 搜索表单配置(系统简化:移除等级和团队首领筛选)
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'mobile',
label: '手机号',
},
{
component: 'Input',
fieldName: 'region',
label: '区域',
},
{
component: 'RangePicker',
fieldName: 'create_time',
label: '创建时间',
componentProps: {
showTime: true,
},
},
];
}
// 表格列配置(系统简化:移除等级和实名认证)
export function useColumns(): VxeTableGridOptions['columns'] {
const columns = [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'user_id',
title: '用户ID',
width: 100,
},
{
field: 'agent_code',
title: '代理编码',
width: 100,
},
{
field: 'region',
title: '区域',
width: 120,
},
{
field: 'mobile',
title: '手机号',
width: 120,
},
{
field: 'wechat_id',
title: '微信号',
width: 120,
visible: false,
},
{
field: 'balance',
title: '钱包余额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'frozen_amount',
title: '冻结余额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'total_earnings',
title: '累计收益',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'withdrawn_amount',
title: '提现总额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'create_time',
title: '成为代理时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
{
align: 'center' as const,
slots: { default: 'operation' },
field: 'operation',
fixed: 'right' as const,
title: '操作',
width: 200,
},
];
return columns;
}
// 推广链接列表列配置
export function useLinkColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'product_name',
title: '产品名称',
width: 150,
},
{
field: 'link_identifier',
title: '推广码',
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
];
}
// 推广链接搜索表单配置
export function useLinkFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
{
component: 'Input',
fieldName: 'link_identifier',
label: '推广码',
},
];
}
// 佣金记录列表列配置
export function useCommissionColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'order_id',
title: '订单ID',
width: 100,
},
{
field: 'amount',
title: '佣金金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'product_name',
title: '产品名称',
width: 150,
},
{
field: 'status',
title: '状态',
width: 100,
formatter: ({ cellValue }: { cellValue: number }) => {
const statusMap: Record<number, string> = {
0: '待结算',
1: '已结算',
2: '已取消',
};
return statusMap[cellValue] || '未知';
},
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
},
] as const;
}
// 佣金记录搜索表单配置
export function useCommissionFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
allowClear: true,
options: [
{ label: '待结算', value: 0 },
{ label: '已结算', value: 1 },
{ label: '已取消', value: 2 },
],
},
},
];
}
// 奖励记录列表列配置
export function useRewardColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'relation_agent_id',
title: '关联代理ID',
width: 100,
},
{
field: 'amount',
title: '奖励金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'type',
title: '奖励类型',
width: 120,
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
},
] as const;
}
// 奖励记录搜索表单配置
export function useRewardFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'type',
label: '奖励类型',
},
{
component: 'Input',
fieldName: 'relation_agent_id',
label: '关联代理ID',
},
];
}
// 提现记录列表列配置
export function useWithdrawalColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'withdraw_no',
title: '提现单号',
width: 180,
},
{
field: 'amount',
title: '提现金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'status',
title: '状态',
width: 100,
formatter: ({ cellValue }: { cellValue: number }) => {
const statusMap: Record<number, string> = {
0: '待审核',
1: '已通过',
2: '已拒绝',
3: '已打款',
};
return statusMap[cellValue] || '未知';
},
},
{
field: 'payee_account',
title: '收款账户',
width: 180,
},
{
field: 'remark',
title: '备注',
width: 200,
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
},
] as const;
}
// 提现记录搜索表单配置
export function useWithdrawalFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'withdraw_no',
label: '提现单号',
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
allowClear: true,
options: [
{ label: '待审核', value: 0 },
{ label: '已通过', value: 1 },
{ label: '已拒绝', value: 2 },
{ label: '已打款', value: 3 },
],
},
},
];
}

View File

@@ -0,0 +1,221 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeGridListeners,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { AgentApi } from '#/api/agent';
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
import { Button, Dropdown, Menu } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentList } from '#/api/agent';
import { useColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
import ComplaintNotifyModal from './modules/complaint-notify-modal.vue';
import LinkModal from './modules/link-modal.vue';
import OrdersModal from './modules/orders-modal.vue';
// 表单抽屉
const [FormDrawer, formDrawerApi] = useVbenDrawer({
connectedComponent: Form,
destroyOnClose: true,
});
// 推广链接弹窗
const [LinkModalComponent, linkModalApi] = useVbenModal({
connectedComponent: LinkModal,
destroyOnClose: true,
});
// 订单列表弹窗
const [OrdersModalComponent, ordersModalApi] = useVbenModal({
connectedComponent: OrdersModal,
destroyOnClose: true,
});
// 投诉通知弹窗
const [ComplaintNotifyModalComponent, complaintNotifyModalApi] = useVbenModal({
connectedComponent: ComplaintNotifyModal,
destroyOnClose: true,
});
// 表格配置
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
fieldMappingTime: [
['create_time', ['create_time_start', 'create_time_end']],
],
schema: useGridFormSchema(),
submitOnChange: true,
},
gridEvents: {
sortChange: () => {
gridApi.query();
},
} as VxeGridListeners<AgentApi.AgentListItem>,
gridOptions: {
columns: useColumns(),
height: 'auto',
keepSource: true,
sortConfig: {
remote: true,
multiple: false,
trigger: 'default',
orders: ['asc', 'desc', null],
resetPage: true,
},
proxyConfig: {
ajax: {
query: async ({ page, sort }, formValues) => {
const sortParams = sort
? {
order_by: sort.field,
order_type: sort.order,
}
: {};
const res = await getAgentList({
page: page.currentPage,
pageSize: page.pageSize,
...formValues,
...sortParams,
});
return {
...res,
sort: sort || null,
};
},
},
props: {
result: 'items',
total: 'total',
},
autoLoad: true,
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
custom: true,
export: false,
refresh: { code: 'query' },
search: true,
zoom: true,
},
} as VxeTableGridOptions<AgentApi.AgentListItem>,
});
// 更多操作菜单项
const moreMenuItems = [
{
key: 'links',
label: '推广链接',
},
{
key: 'orders',
label: '订单记录',
},
{
key: 'complaint',
label: '投诉通知',
},
];
// 操作处理函数
function onActionClick(
e:
| OnActionClickParams<AgentApi.AgentListItem>
| { code: string; row: AgentApi.AgentListItem },
) {
switch (e.code) {
case 'edit': {
onEdit(e.row);
break;
}
case 'links': {
onViewLinks(e.row);
break;
}
case 'orders': {
onViewOrders(e.row);
break;
}
case 'complaint': {
onComplaintNotify(e.row);
break;
}
}
}
// 编辑处理
function onEdit(row: AgentApi.AgentListItem) {
formDrawerApi.setData(row).open();
}
// 查看推广链接
function onViewLinks(row: AgentApi.AgentListItem) {
linkModalApi.setData({ agentId: row.id }).open();
}
// 查看订单记录
function onViewOrders(row: AgentApi.AgentListItem) {
ordersModalApi.setData({ agentId: row.id }).open();
}
// 投诉通知处理
function onComplaintNotify(row: AgentApi.AgentListItem) {
complaintNotifyModalApi.setData({
agentId: String(row.id),
agentName: row.region || '未知',
agentMobile: row.mobile,
}).open();
}
// 刷新处理
function onRefresh() {
gridApi.query();
}
</script>
<template>
<Page auto-content-height>
<FormDrawer @success="onRefresh" />
<LinkModalComponent />
<OrdersModalComponent />
<ComplaintNotifyModalComponent />
<Grid table-title="代理列表">
<template #operation="{ row }">
<div class="operation-buttons">
<Button type="link" @click="onActionClick({ code: 'edit', row })">
编辑
</Button>
<Dropdown>
<Button type="link">更多操作</Button>
<template #overlay>
<Menu :items="moreMenuItems" @click="(e) => onActionClick({ code: String(e.key), row })" />
</template>
</Dropdown>
</div>
</template>
</Grid>
</Page>
</template>
<style lang="less" scoped>
.operation-buttons {
display: flex;
align-items: center;
justify-content: space-around;
gap: 4px;
:deep(.ant-btn-link) {
padding: 0 4px;
}
}
</style>

View File

@@ -0,0 +1,32 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import CommissionList from '../../agent-commission/list.vue';
interface ModalData {
agentId: number;
}
const [Modal, modalApi] = useVbenModal({
title: '佣金记录列表',
destroyOnClose: true,
});
const modalData = computed(() => modalApi.getData<ModalData>());
</script>
<template>
<Modal class="w-[calc(100vw-200px)]" :footer="false">
<div class="agent-commission-modal">
<CommissionList :agent-id="modalData?.agentId" />
</div>
</Modal>
</template>
<style lang="less" scoped>
.agent-commission-modal {
padding: 16px;
}
</style>

View File

@@ -0,0 +1,97 @@
<script lang="ts" setup>
import { computed, ref } from 'vue';
import { message, Form, FormItem, Input, Alert } from 'ant-design-vue';
import { useVbenModal } from '@vben/common-ui';
import { sendAgentComplaintNotify } from '#/api/agent';
interface ModalData {
agentId: string;
agentName: string;
agentMobile: string;
}
const [Modal, modalApi] = useVbenModal({
title: '投诉通知',
destroyOnClose: true,
onConfirm: handleSubmit,
});
const modalData = computed(() => modalApi.getData<ModalData>());
const loading = ref(false);
const userName = ref('');
// 重置表单
function resetForm() {
userName.value = '';
}
// 提交处理
async function handleSubmit() {
if (!userName.value.trim()) {
message.warning('请输入用户姓名');
return false;
}
if (!modalData.value) {
return false;
}
loading.value = true;
try {
await sendAgentComplaintNotify({
agent_id: modalData.value.agentId,
user_name: userName.value.trim(),
});
message.success('投诉通知发送成功');
modalApi.close();
resetForm();
} catch (error) {
message.error('投诉通知发送失败');
} finally {
loading.value = false;
}
return false; // 阻止自动关闭,等待处理完成
}
// 弹窗打开时重置表单
function onOpen() {
resetForm();
}
</script>
<template>
<Modal @open="onOpen">
<div class="complaint-notify-modal">
<Form layout="vertical">
<FormItem label="用户姓名" required>
<Input
v-model:value="userName"
placeholder="请输入投诉用户的姓名"
:maxlength="50"
/>
</FormItem>
<Alert
:message="`尊敬的代理商,您新增了一条用户${userName || 'xxx'}投诉,我们已帮您对用户进行安抚和解释,用户表示接受,该投诉目前已暂时处理完结。非常感谢您的理解与支持!`"
type="info"
show-icon
/>
<div style="margin-top: 16px; font-size: 12px; color: #6b7280;">
<p> 点击确认后将发送短信通知代理</p>
<p> 代理手机号{{ modalData?.agentMobile }}</p>
</div>
</Form>
</div>
</Modal>
</template>
<style lang="less" scoped>
.complaint-notify-modal {
padding: 16px;
}
</style>

View File

@@ -0,0 +1,62 @@
<script lang="ts" setup>
import type { AgentApi } from '#/api/agent';
import { computed, ref } from 'vue';
import { useVbenDrawer } from '@vben/common-ui';
import { useVbenForm } from '#/adapter/form';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<AgentApi.AgentListItem>();
const [Form, formApi] = useVbenForm({
schema: useFormSchema(),
showDefaultActions: false,
});
const id = ref();
const [Drawer, drawerApi] = useVbenDrawer({
async onConfirm() {
const { valid } = await formApi.validate();
if (!valid) return;
const values = await formApi.getValues();
drawerApi.lock();
// TODO: 实现更新代理信息的接口
// updateAgent(id.value, values as AgentApi.UpdateAgentRequest)
// .then(() => {
// emit('success');
// drawerApi.close();
// })
// .catch(() => {
// drawerApi.unlock();
// });
},
onOpenChange(isOpen) {
if (isOpen) {
const data = drawerApi.getData<AgentApi.AgentListItem>();
formApi.resetForm();
if (data) {
formData.value = data;
id.value = data.id;
formApi.setValues(data);
} else {
id.value = undefined;
}
}
},
});
const getDrawerTitle = computed(() => {
return formData.value?.id ? '编辑代理' : '创建代理';
});
</script>
<template>
<Drawer :title="getDrawerTitle">
<Form />
</Drawer>
</template>

View File

@@ -0,0 +1,32 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import LinkList from '../../agent-links/list.vue';
interface ModalData {
agentId: number;
}
const [Modal, modalApi] = useVbenModal({
title: '推广链接列表',
destroyOnClose: true,
});
const modalData = computed(() => modalApi.getData<ModalData>());
</script>
<template>
<Modal class="w-[calc(100vw-200px)]" :footer="false">
<div class="agent-link-modal">
<LinkList :agent-id="modalData?.agentId" />
</div>
</Modal>
</template>
<style lang="less" scoped>
.agent-link-modal {
padding: 16px;
}
</style>

View File

@@ -0,0 +1,33 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import OrderList from '../../agent-order/list.vue';
interface ModalData {
agentId: number;
}
const [Modal, modalApi] = useVbenModal({
title: '订单记录',
destroyOnClose: true,
});
const modalData = computed(() => modalApi.getData<ModalData>());
</script>
<template>
<Modal class="w-[calc(100vw-200px)]" :footer="false">
<div class="agent-order-modal">
<OrderList :agent-id="modalData?.agentId" />
</div>
</Modal>
</template>
<style lang="less" scoped>
.agent-order-modal {
padding: 16px;
}
</style>

View File

@@ -0,0 +1,32 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import AgentOrdersList from '../../agent-orders/index.vue';
interface ModalData {
agentId: string;
}
const [Modal, modalApi] = useVbenModal({
title: '代理订单列表',
destroyOnClose: true,
});
const modalData = computed(() => modalApi.getData<ModalData>());
</script>
<template>
<Modal class="w-[calc(100vw-200px)]" :footer="false">
<div class="agent-orders-modal">
<AgentOrdersList :agent-id="modalData?.agentId" />
</div>
</Modal>
</template>
<style lang="less" scoped>
.agent-orders-modal {
padding: 16px;
}
</style>

View File

@@ -0,0 +1,87 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
export function useOrderColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'order_id',
title: '订单ID',
width: 100,
},
{
field: 'product_id',
title: '产品ID',
width: 100,
},
{
field: 'product_name',
title: '产品名称',
width: 150,
},
{
field: 'order_amount',
title: '订单金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'process_status',
title: '处理状态',
width: 100,
cellRender: {
name: 'CellTag',
options: [
{ value: 0, color: 'warning', label: '待处理' },
{ value: 1, color: 'success', label: '处理成功' },
{ value: 2, color: 'error', label: '处理失败' },
],
},
},
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
},
] as const;
}
export function useOrderFormSchema(): VbenFormSchema[] {
return [
{
component: 'InputNumber',
fieldName: 'agent_id',
label: '代理ID',
},
{
component: 'InputNumber',
fieldName: 'order_id',
label: '订单ID',
},
{
component: 'Select',
fieldName: 'process_status',
label: '处理状态',
componentProps: {
allowClear: true,
options: [
{ label: '待处理', value: 0 },
{ label: '处理成功', value: 1 },
{ label: '处理失败', value: 2 },
],
},
},
];
}

View File

@@ -0,0 +1,64 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentOrderList } from '#/api/agent';
import { useOrderColumns, useOrderFormSchema } from './data';
interface Props {
agentId?: number;
}
interface QueryParams {
currentPage: number;
pageSize: number;
[key: string]: any;
}
const props = defineProps<Props>();
const queryParams = computed(() => ({
...(props.agentId ? { agent_id: props.agentId } : {}),
}));
const [Grid] = useVbenVxeGrid({
formOptions: {
schema: useOrderFormSchema(),
submitOnChange: true,
},
gridOptions: {
columns: useOrderColumns(),
proxyConfig: {
ajax: {
query: async ({
page,
form,
}: {
form: Record<string, any>;
page: QueryParams;
}) => {
return await getAgentOrderList({
...queryParams.value,
...form,
page: page.currentPage,
pageSize: page.pageSize,
});
},
},
props: {
result: 'items',
total: 'total',
},
},
},
});
</script>
<template>
<Page :auto-content-height="!agentId">
<Grid :table-title="agentId ? '订单记录列表' : '所有订单记录'" />
</Page>
</template>

View File

@@ -0,0 +1,276 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { OnActionClickFn, VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AgentApi } from '#/api/agent';
// 表格列配置
export function useColumns<T = AgentApi.AgentOrdersListItem>(
onActionClick: OnActionClickFn<T>,
): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
fixed: 'left',
},
{
field: 'order_no',
title: '商户订单号',
width: 180,
fixed: 'left',
},
{
field: 'platform_order_id',
title: '支付订单号',
width: 220,
},
// 代理信息
{
field: 'agent_mobile',
title: '代理手机号',
width: 120,
},
// 用户信息
{
field: 'user_mobile',
title: '用户手机号',
width: 120,
formatter: ({ cellValue }) => cellValue || '-',
},
// 产品信息
{
field: 'product_name',
title: '产品名称',
width: 150,
},
// 金额信息
{
field: 'order_amount',
title: '订单金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
{
field: 'commission_amount',
title: '佣金金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
cellValue != null ? `¥${cellValue.toFixed(2)}` : '-',
},
// 支付信息
{
field: 'payment_platform',
title: '支付方式',
width: 100,
formatter: ({ row }) => {
const platformMap: Record<string, string> = {
alipay: '支付宝',
wechat: '微信支付',
appleiap: '苹果支付',
};
return platformMap[row.payment_platform] || row.payment_platform;
},
},
{
field: 'payment_scene',
title: '支付平台',
width: 100,
formatter: ({ row }) => {
const sceneMap: Record<string, string> = {
app: 'APP',
h5: 'H5',
mini_program: '小程序',
public_account: '公众号',
};
return sceneMap[row.payment_scene] || row.payment_scene;
},
},
// 状态
{
cellRender: {
name: 'CellTag',
options: [
{ value: 'pending', color: 'warning', label: '待支付' },
{ value: 'paid', color: 'success', label: '已支付' },
{ value: 'failed', color: 'error', label: '支付失败' },
{ value: 'refunded', color: 'purple', label: '已退款' },
{ value: 'closed', color: 'default', label: '已关闭' },
],
},
field: 'order_status',
title: '订单状态',
width: 100,
},
{
cellRender: {
name: 'CellTag',
options: [
{ value: 0, color: 'warning', label: '待结算' },
{ value: 1, color: 'success', label: '已结算' },
{ value: 2, color: 'error', label: '已取消' },
],
},
field: 'commission_status',
title: '佣金状态',
width: 100,
},
// 时间
{
field: 'create_time',
title: '创建时间',
width: 160,
sortable: true,
},
{
field: 'pay_time',
title: '支付时间',
width: 160,
formatter: ({ cellValue }) => cellValue || '-',
},
// 操作
{
align: 'center',
cellRender: {
attrs: {
nameField: 'order_no',
nameTitle: '商户订单号',
onClick: onActionClick,
},
name: 'CellOperation',
options: [
{
code: 'detail',
text: '详情',
},
{
code: 'query',
text: '报告结果',
disabled: (row: AgentApi.AgentOrdersListItem) => {
return row.order_status !== 'paid';
},
},
{
code: 'refund',
text: '退款',
disabled: (row: AgentApi.AgentOrdersListItem) => {
return row.order_status !== 'paid';
},
},
],
},
field: 'operation',
fixed: 'right',
title: '操作',
width: 200,
},
];
}
// 搜索表单配置
export function useGridFormSchema(): VbenFormSchema[] {
return [
// 代理筛选
{
component: 'Input',
fieldName: 'agent_mobile',
label: '代理手机号',
},
// 用户筛选
{
component: 'Input',
fieldName: 'user_mobile',
label: '用户手机号',
},
// 订单筛选
{
component: 'Input',
fieldName: 'order_no',
label: '商户订单号',
},
{
component: 'Input',
fieldName: 'platform_order_id',
label: '支付订单号',
},
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
// 支付筛选
{
component: 'Select',
componentProps: {
allowClear: true,
options: [
{ label: '支付宝', value: 'alipay' },
{ label: '微信支付', value: 'wechat' },
{ label: '苹果支付', value: 'appleiap' },
],
},
fieldName: 'payment_platform',
label: '支付方式',
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: [
{ label: 'APP', value: 'app' },
{ label: 'H5', value: 'h5' },
{ label: '小程序', value: 'mini_program' },
{ label: '公众号', value: 'public_account' },
],
},
fieldName: 'payment_scene',
label: '支付平台',
},
// 状态筛选
{
component: 'Select',
componentProps: {
allowClear: true,
options: [
{ label: '待支付', value: 'pending' },
{ label: '已支付', value: 'paid' },
{ label: '支付失败', value: 'failed' },
{ label: '已退款', value: 'refunded' },
{ label: '已关闭', value: 'closed' },
],
},
fieldName: 'order_status',
label: '订单状态',
},
{
component: 'Select',
componentProps: {
allowClear: true,
options: [
{ label: '待结算', value: 0 },
{ label: '已结算', value: 1 },
{ label: '已取消', value: 2 },
],
},
fieldName: 'commission_status',
label: '佣金状态',
},
// 时间筛选
{
component: 'RangePicker',
fieldName: 'create_time',
label: '创建时间',
componentProps: {
showTime: true,
},
},
{
component: 'RangePicker',
fieldName: 'pay_time',
label: '支付时间',
componentProps: {
showTime: true,
},
},
];
}

View File

@@ -0,0 +1,170 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeGridListeners,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { AgentApi } from '#/api/agent';
import { message } from 'ant-design-vue';
import { computed } from 'vue';
import { useRouter } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentOrdersList } from '#/api/agent';
import { useColumns, useGridFormSchema } from './data';
import DetailModal from './modules/detail-modal.vue';
import RefundModal from './modules/refund-modal.vue';
interface Props {
agentId?: string;
}
const props = defineProps<Props>();
const queryParams = computed(() => ({
...(props.agentId ? { agent_id: props.agentId } : {}),
}));
// 详情弹窗
const [DetailModalComponent, detailModalApi] = useVbenModal({
connectedComponent: DetailModal,
destroyOnClose: true,
});
// 退款弹窗
const [RefundModalComponent, refundModalApi] = useVbenModal({
connectedComponent: RefundModal,
destroyOnClose: true,
});
const router = useRouter();
// 表格配置
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
fieldMappingTime: [
['create_time', ['create_time_start', 'create_time_end']],
['pay_time', ['pay_time_start', 'pay_time_end']],
],
schema: useGridFormSchema(),
submitOnChange: true,
},
gridEvents: {
sortChange: () => {
gridApi.query();
},
} as VxeGridListeners<AgentApi.AgentOrdersListItem>,
gridOptions: {
columns: useColumns(onActionClick),
height: 'auto',
keepSource: true,
sortConfig: {
remote: true,
multiple: false,
trigger: 'default',
orders: ['asc', 'desc', null],
resetPage: true,
},
proxyConfig: {
ajax: {
query: async ({ page, sort }, formValues) => {
const sortParams = sort
? {
order_by: sort.field,
order_type: sort.order,
}
: {};
const res = await getAgentOrdersList({
...queryParams.value,
page: page.currentPage,
pageSize: page.pageSize,
...formValues,
...sortParams,
});
return {
...res,
sort: sort || null,
};
},
},
props: {
result: 'items',
total: 'total',
},
autoLoad: true,
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
custom: true,
export: false,
refresh: { code: 'query' },
search: true,
zoom: true,
},
} as VxeTableGridOptions<AgentApi.AgentOrdersListItem>,
});
// 操作处理
function onActionClick(
e: OnActionClickParams<AgentApi.AgentOrdersListItem>,
) {
switch (e.code) {
case 'detail': {
onDetail(e.row);
break;
}
case 'query': {
onQuery(e.row);
break;
}
case 'refund': {
onRefund(e.row);
break;
}
}
}
// 详情处理
function onDetail(row: AgentApi.AgentOrdersListItem) {
detailModalApi.setData(row).open();
}
// 报告结果处理
function onQuery(row: AgentApi.AgentOrdersListItem) {
if (!row.query_id) {
message.warning('该订单没有关联的查询记录');
return;
}
router.push({
name: 'OrderQueryDetail',
params: {
id: row.id, // 传递订单ID后端API需要通过订单ID查询查询记录
},
});
}
// 退款处理
function onRefund(row: AgentApi.AgentOrdersListItem) {
refundModalApi.setData(row).open();
}
// 刷新处理
function onRefresh() {
gridApi.query();
}
</script>
<template>
<Page :auto-content-height="!agentId">
<DetailModalComponent />
<RefundModalComponent @success="onRefresh" />
<Grid :table-title="agentId ? '代理订单列表' : '代理订单列表'" />
</Page>
</template>

View File

@@ -0,0 +1,149 @@
<script lang="ts" setup>
import type { AgentApi } from '#/api/agent';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Descriptions, DescriptionsItem, Tag } from 'ant-design-vue';
const formData = ref<AgentApi.AgentOrdersListItem | null>(null);
const [Modal, modalApi] = useVbenModal({
destroyOnClose: true,
onOpenChange: (isOpen) => {
if (isOpen) {
const data = modalApi.getData<AgentApi.AgentOrdersListItem>();
formData.value = data || null;
}
},
});
const modalTitle = computed(() => {
return formData.value ? `订单详情 - ${formData.value.order_no}` : '订单详情';
});
// 支付方式映射
const paymentPlatformMap: Record<string, string> = {
alipay: '支付宝',
wechat: '微信支付',
appleiap: '苹果支付',
};
// 支付平台映射
const paymentSceneMap: Record<string, string> = {
app: 'APP',
h5: 'H5',
mini_program: '小程序',
public_account: '公众号',
};
// 订单状态映射
const orderStatusMap: Record<string, { text: string; color: string }> = {
pending: { text: '待支付', color: 'warning' },
paid: { text: '已支付', color: 'success' },
failed: { text: '支付失败', color: 'error' },
refunded: { text: '已退款', color: 'purple' },
closed: { text: '已关闭', color: 'default' },
};
// 佣金状态映射
const commissionStatusMap: Record<number, { text: string; color: string }> = {
0: { text: '待结算', color: 'warning' },
1: { text: '已结算', color: 'success' },
2: { text: '已取消', color: 'error' },
};
</script>
<template>
<Modal :title="modalTitle" class="w-[calc(100vw-200px)]" :footer="false">
<div v-if="formData" class="p-4">
<!-- 基本信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">基本信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="ID">{{ formData.id }}</DescriptionsItem>
<DescriptionsItem label="商户订单号">{{ formData.order_no }}</DescriptionsItem>
<DescriptionsItem label="支付订单号">
{{ formData.platform_order_id || '-' }}
</DescriptionsItem>
<DescriptionsItem label="创建时间">
{{ formData.create_time }}
</DescriptionsItem>
</Descriptions>
</div>
<!-- 代理信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">代理信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="代理ID">{{ formData.agent_id }}</DescriptionsItem>
<DescriptionsItem label="代理手机号">{{ formData.agent_mobile || '-' }}</DescriptionsItem>
</Descriptions>
</div>
<!-- 用户信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">用户信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="用户ID">{{ formData.user_id }}</DescriptionsItem>
<DescriptionsItem label="用户手机号">
{{ formData.user_mobile || '-' }}
</DescriptionsItem>
</Descriptions>
</div>
<!-- 产品信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">产品信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="产品ID">{{ formData.product_id }}</DescriptionsItem>
<DescriptionsItem label="产品名称">{{ formData.product_name }}</DescriptionsItem>
</Descriptions>
</div>
<!-- 金额信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">金额信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="订单金额">
<span class="text-base font-semibold text-green-600">
¥{{ formData.order_amount.toFixed(2) }}
</span>
</DescriptionsItem>
<DescriptionsItem label="佣金金额">
<span class="text-base font-semibold text-blue-600">
¥{{ formData.commission_amount.toFixed(2) }}
</span>
</DescriptionsItem>
</Descriptions>
</div>
<!-- 支付信息 -->
<div class="mb-6">
<div class="mb-2 text-base font-semibold">支付信息</div>
<Descriptions :column="2" bordered>
<DescriptionsItem label="支付方式">
{{ paymentPlatformMap[formData.payment_platform] || formData.payment_platform }}
</DescriptionsItem>
<DescriptionsItem label="支付平台">
{{ paymentSceneMap[formData.payment_scene] || formData.payment_scene }}
</DescriptionsItem>
<DescriptionsItem label="订单状态">
<Tag :color="orderStatusMap[formData.order_status]?.color">
{{ orderStatusMap[formData.order_status]?.text || formData.order_status }}
</Tag>
</DescriptionsItem>
<DescriptionsItem label="佣金状态">
<Tag :color="commissionStatusMap[formData.commission_status]?.color">
{{ commissionStatusMap[formData.commission_status]?.text }}
</Tag>
</DescriptionsItem>
<DescriptionsItem label="支付时间">
{{ formData.pay_time || '-' }}
</DescriptionsItem>
</Descriptions>
</div>
</div>
</Modal>
</template>

View File

@@ -0,0 +1,193 @@
<script lang="ts" setup>
import type { AgentApi } from '#/api/agent';
import { computed, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { useVbenForm, z } from '#/adapter/form';
import { refundAgentOrder } from '#/api/agent';
const emit = defineEmits(['success']);
const loading = ref(false);
const formData = ref<AgentApi.AgentOrdersListItem | null>(null);
// 预设退款原因选项
const refundReasonOptions = [
{ label: '用户不满意要求退款', value: '用户不满意要求退款' },
{ label: '产品问题退款', value: '产品问题退款' },
{ label: '重复下单退款', value: '重复下单退款' },
{ label: '其他原因', value: 'other' },
];
// 表单配置
const [Form, formApi] = useVbenForm({
schema: [
{
component: 'Input',
componentProps: {
disabled: true,
style: { width: '100%' },
},
fieldName: 'order_no',
label: '商户订单号',
},
{
component: 'InputNumber',
componentProps: {
disabled: true,
precision: 2,
style: { width: '100%' },
addonBefore: '¥',
},
fieldName: 'max_refund_amount',
label: '可退款金额',
},
{
component: 'InputNumber',
componentProps: {
min: 0,
max: computed(() => formData.value?.order_amount || 0),
precision: 2,
style: { width: '100%' },
addonBefore: '¥',
},
fieldName: 'refund_amount',
label: '退款金额',
rules: z
.number()
.min(0.01, '退款金额必须大于0')
.refine(
(val: number) => val <= (formData.value?.order_amount || 0),
'退款金额不能大于订单金额',
),
},
{
component: 'InputNumber',
componentProps: {
min: 0,
max: computed(() => formData.value?.order_amount || 0),
precision: 2,
style: { width: '100%' },
addonBefore: '¥',
},
fieldName: 'confirm_refund_amount',
label: '确认退款金额',
rules: z.number().refine(async (val: number) => {
const form = await formApi.getValues();
return val === (form as { refund_amount: number }).refund_amount;
}, '两次输入的退款金额不一致'),
},
{
component: 'RadioGroup',
componentProps: {
options: refundReasonOptions,
style: { width: '100%' },
},
fieldName: 'preset_reason',
label: '退款原因',
defaultValue: 'other',
},
{
component: 'Textarea',
componentProps: (values) => {
return {
rows: 3,
placeholder: '请输入具体退款原因',
maxLength: 200,
showCount: true,
style: { width: '100%' },
disabled:
(values as { preset_reason?: string })?.preset_reason !== 'other',
};
},
fieldName: 'refund_reason',
label: ' ',
rules: z.string().superRefine(async (val, ctx) => {
const values = await formApi.getValues();
const presetReason = (values as { preset_reason?: string })
?.preset_reason;
if (presetReason === 'other') {
if (!val || val.length === 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: '请输入具体退款原因',
});
} else if (val.length > 200) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: '退款原因不能超过200个字符',
});
}
}
}),
},
],
showDefaultActions: false,
});
const [Modal, modalApi] = useVbenModal({
onConfirm: async () => {
const { valid } = await formApi.validate();
if (!valid) return;
const values = await formApi.getValues<{
preset_reason: string;
refund_amount: number;
refund_reason: string;
}>();
if (!formData.value) return;
loading.value = true;
try {
await refundAgentOrder(formData.value.id, {
refund_amount: values.refund_amount,
refund_reason:
values.preset_reason === 'other'
? values.refund_reason
: values.preset_reason,
});
message.success('退款申请成功');
emit('success');
modalApi.close();
} catch (error) {
console.error('退款失败:', error);
} finally {
loading.value = false;
}
},
onOpenChange(isOpen) {
if (isOpen) {
const data = modalApi.getData<AgentApi.AgentOrdersListItem>();
formApi.resetForm();
if (data) {
formData.value = data;
// 默认填入订单金额和选择其他原因
formApi.setValues({
order_no: data.order_no,
max_refund_amount: data.order_amount,
refund_amount: data.order_amount,
confirm_refund_amount: data.order_amount,
preset_reason: 'other',
});
} else {
formData.value = null;
}
}
},
});
const modalTitle = computed(() => {
return formData.value ? `退款 - ${formData.value.order_no}` : '退款';
});
</script>
<template>
<Modal :title="modalTitle" :loading="loading">
<Form />
</Modal>
</template>

View File

@@ -0,0 +1,193 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { h } from 'vue';
import { z } from '#/adapter/form';
// 代理产品配置列表列配置
export function useColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: 'ID',
width: 80,
},
{
field: 'product_name',
title: '产品名称',
},
{
field: 'base_price',
title: '基础底价',
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'price_range_max',
title: '最高定价',
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'price_threshold',
title: '价格阈值',
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'price_fee_rate',
title: '提价费率',
formatter: ({ cellValue }: { cellValue: number }) =>
`${(cellValue * 100).toFixed(2)}%`,
},
{
align: 'center',
slots: { default: 'operation' },
field: 'operation',
fixed: 'right',
title: '操作',
width: 120,
},
] as const;
}
// 代理产品配置搜索表单配置
export function useGridFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'product_name',
label: '产品名称',
},
];
}
// 代理产品配置编辑表单配置
export function useFormSchema(): VbenFormSchema[] {
return [
{
component: 'InputNumber',
fieldName: 'base_price',
label: '基础底价',
rules: 'required',
componentProps: {
min: 0,
precision: 2,
step: 0.01,
},
},
{
component: 'InputNumber',
fieldName: 'price_range_max',
label: '最高定价',
rules: 'required',
componentProps: {
min: 0,
precision: 2,
step: 0.01,
},
},
{
component: 'InputNumber',
fieldName: 'price_threshold',
label: '价格阈值',
defaultValue: undefined,
componentProps: {
min: 0,
precision: 2,
step: 0.01,
placeholder: '可选,不设置则不限制',
},
rules: z
.number({
invalid_type_error: '请输入有效的数字',
})
.min(0, '价格阈值不能小于0')
.optional()
.nullable(),
dependencies: {
triggerFields: ['base_price'],
rules(values) {
// 动态校验:价格阈值不能低于基础底价
const basePrice = values.base_price;
if (basePrice !== undefined && basePrice !== null) {
return z
.number({
invalid_type_error: '请输入有效的数字',
})
.min(0, '价格阈值不能小于0')
.refine(
(val) => {
if (val === undefined || val === null) return true;
return val >= basePrice;
},
{
message: `价格阈值不能低于基础底价 ${basePrice}`,
},
)
.optional()
.nullable();
}
return z
.number({
invalid_type_error: '请输入有效的数字',
})
.min(0, '价格阈值不能小于0')
.optional()
.nullable();
},
trigger(_values, formApi) {
// 当基础底价变化时,重新校验价格阈值
formApi.validateField('price_threshold');
},
},
suffix: () => h('span', { class: 'text-gray-400 text-xs' }, '可选'),
},
{
component: 'InputNumber',
fieldName: 'price_fee_rate',
label: '提价费率',
defaultValue: undefined,
componentProps: {
min: 0,
max: 100,
precision: 4,
step: 0.01,
addonAfter: '%',
controls: true,
placeholder: '可选,不设置则不收费',
validateTrigger: ['blur', 'change'],
},
rules: z
.number({
invalid_type_error: '请输入有效的数字',
})
.min(0, '提价费率不能小于0')
.max(100, '提价费率不能大于100%')
.optional()
.nullable(),
dependencies: {
triggerFields: ['price_threshold'],
required(values) {
// 如果价格阈值有值,提价费率必填
return values.price_threshold !== undefined && values.price_threshold !== null;
},
rules(values) {
// 如果价格阈值有值,提价费率必填
if (values.price_threshold !== undefined && values.price_threshold !== null) {
return z.number().min(0, '提价费率不能小于0').max(100, '提价费率不能大于100%');
}
return z.number().optional().nullable();
},
trigger(values, formApi) {
// 当价格阈值清空时,也清空提价费率
if (values.price_threshold === undefined || values.price_threshold === null) {
formApi.setFieldValue('price_fee_rate', undefined);
}
},
},
suffix: () => h('span', { class: 'text-gray-400 text-xs' }, '可选'),
},
];
}

View File

@@ -0,0 +1,127 @@
<script lang="ts" setup>
import type {
OnActionClickParams,
VxeGridListeners,
VxeTableGridOptions,
} from '#/adapter/vxe-table';
import type { AgentApi } from '#/api/agent';
import { Page, useVbenDrawer } from '@vben/common-ui';
import { Button, Space } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getAgentProductionConfigList } from '#/api/agent';
import { useColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
// 表单抽屉
const [FormDrawer, formDrawerApi] = useVbenDrawer({
connectedComponent: Form,
destroyOnClose: true,
});
// 表格配置
const [Grid, gridApi] = useVbenVxeGrid({
formOptions: {
schema: useGridFormSchema(),
submitOnChange: true,
},
gridEvents: {
sortChange: () => {
gridApi.query();
},
} as VxeGridListeners<AgentApi.AgentProductionConfigItem>,
gridOptions: {
columns: useColumns(),
height: 'auto',
keepSource: true,
sortConfig: {
remote: true,
multiple: false,
trigger: 'default',
orders: ['asc', 'desc', null],
resetPage: true,
},
proxyConfig: {
ajax: {
query: async ({ page, sort }, formValues) => {
const sortParams = sort
? {
order_by: sort.field,
order_type: sort.order,
}
: {};
const params: AgentApi.GetAgentProductionConfigListParams = {
page: page.currentPage,
pageSize: page.pageSize,
product_name: formValues.product_name,
...sortParams,
};
const res = await getAgentProductionConfigList(params);
return {
...res,
sort: sort || null,
};
},
},
props: {
result: 'items',
total: 'total',
},
autoLoad: true,
},
rowConfig: {
keyField: 'id',
},
toolbarConfig: {
custom: true,
export: false,
refresh: { code: 'query' },
search: true,
zoom: true,
},
} as VxeTableGridOptions<AgentApi.AgentProductionConfigItem>,
});
// 操作处理函数
function onActionClick(
e: OnActionClickParams<AgentApi.AgentProductionConfigItem>,
) {
switch (e.code) {
case 'edit': {
onEdit(e.row);
break;
}
}
}
// 编辑处理
function onEdit(row: AgentApi.AgentProductionConfigItem) {
formDrawerApi.setData(row).open();
}
// 刷新处理
function onRefresh() {
gridApi.query();
}
</script>
<template>
<Page auto-content-height>
<FormDrawer @success="onRefresh" />
<Grid table-title="代理产品配置列表">
<template #operation="{ row }">
<Space>
<Button type="link" @click="onActionClick({ code: 'edit', row })">
配置
</Button>
</Space>
</template>
</Grid>
</Page>
</template>

View File

@@ -0,0 +1,95 @@
<script lang="ts" setup>
import type { AgentApi } from '#/api/agent';
import { ref } from 'vue';
import { Button, InputNumber } from 'ant-design-vue';
import { useVbenDrawer, useVbenForm } from '@vben/common-ui';
import { updateAgentProductionConfig } from '#/api/agent';
import { useFormSchema } from '../data';
const emit = defineEmits(['success']);
const formData = ref<AgentApi.AgentProductionConfigItem>();
const id = ref<number>();
const [Form, formApi] = useVbenForm({
schema: useFormSchema(),
showDefaultActions: false,
});
const drawerTitle = ref('产品配置');
const [Drawer, drawerApi] = useVbenDrawer({
title: drawerTitle.value,
destroyOnClose: true,
async onConfirm() {
const valid = await formApi.validate();
if (!valid || !id.value) return;
const values = await formApi.getValues();
const params: AgentApi.UpdateAgentProductionConfigParams = {
id: id.value,
base_price: values.base_price,
price_range_max: values.price_range_max,
price_threshold: values.price_threshold ?? undefined,
price_fee_rate: values.price_fee_rate ? values.price_fee_rate / 100 : undefined,
};
await updateAgentProductionConfig(params);
emit('success');
drawerApi.close();
},
onOpenChange(isOpen) {
if (isOpen) {
const data = drawerApi.getData<AgentApi.AgentProductionConfigItem>();
formApi.resetForm();
if (data) {
formData.value = data;
id.value = data.id;
formApi.setValues({
...data,
price_threshold: data.price_threshold ?? undefined,
price_fee_rate: data.price_fee_rate ? data.price_fee_rate * 100 : undefined,
});
} else {
id.value = undefined;
}
}
},
});
</script>
<template>
<Drawer :title="drawerTitle">
<Form>
<template #price_threshold="slotProps">
<div class="flex items-center gap-2">
<InputNumber :value="slotProps.componentField.modelValue" :min="0" :precision="2" :step="0.01"
placeholder="可选,不设置则不限制" class="flex-1" @update:value="slotProps.componentField['onUpdate:modelValue']" />
<Button type="link" size="small" @click="() => {
formApi.setFieldValue('price_threshold', undefined);
formApi.setFieldValue('price_fee_rate', undefined);
}">
不设置
</Button>
</div>
</template>
<template #price_fee_rate="slotProps">
<div class="flex items-center gap-2">
<InputNumber :value="slotProps.componentField.modelValue" :min="0" :max="100" :precision="4" :step="0.01"
addon-after="%" placeholder="可选,不设置则不收费" class="flex-1"
@update:value="slotProps.componentField['onUpdate:modelValue']" />
<Button type="link" size="small" @click="() => {
formApi.setFieldValue('price_fee_rate', undefined);
}">
不设置
</Button>
</div>
</template>
</Form>
</Drawer>
</template>

View File

@@ -0,0 +1,135 @@
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
// 提现记录列表列配置
export function useWithdrawColumns(): VxeTableGridOptions['columns'] {
return [
{
field: 'id',
title: '记录ID',
width: 100,
fixed: 'left',
},
{
field: 'agent_id',
title: '代理ID',
width: 100,
},
{
field: 'agent_mobile',
title: '代理手机号',
width: 130,
},
{
field: 'agent_code',
title: '代理编码',
width: 100,
},
{
field: 'withdraw_amount',
title: '提现金额',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'tax_amount',
title: '税费',
width: 100,
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'actual_amount',
title: '实际到账',
width: 120,
formatter: ({ cellValue }: { cellValue: number }) =>
`¥${cellValue.toFixed(2)}`,
},
{
field: 'account_name',
title: '收款人',
width: 100,
},
{
field: 'bank_card_number',
title: '银行卡号',
width: 150,
},
{
field: 'bank_branch',
title: '开户支行',
width: 200,
showOverflow: 'tooltip',
},
{
field: 'status',
title: '状态',
width: 100,
fixed: 'right',
formatter: ({ cellValue }: { cellValue: number }) => {
const statusMap: Record<number, string> = {
0: '待审核',
1: '已通过',
2: '已拒绝',
};
return statusMap[cellValue] || '未知';
},
},
{
field: 'audit_time',
title: '审核时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
{
field: 'create_time',
title: '申请时间',
width: 160,
sortable: true,
sortType: 'string' as const,
},
{
field: 'audit_remark',
title: '审核备注',
width: 200,
showOverflow: 'tooltip',
},
{
field: 'action',
title: '操作',
width: 120,
fixed: 'right',
slots: { default: 'action' },
},
];
}
// 提现记录搜索表单配置
export function useWithdrawFormSchema(): VbenFormSchema[] {
return [
{
component: 'Input',
fieldName: 'agent_id',
label: '代理ID',
componentProps: {
placeholder: '请输入代理ID',
},
},
{
component: 'Select',
fieldName: 'status',
label: '状态',
componentProps: {
allowClear: true,
placeholder: '请选择状态',
options: [
{ label: '待审核', value: 0 },
{ label: '已通过', value: 1 },
{ label: '已拒绝', value: 2 },
],
},
},
];
}

View File

@@ -0,0 +1,77 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { Page } from '@vben/common-ui';
import { VbenButton } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { adminGetAgentWithdrawList } from '#/api/agent';
import { useWithdrawColumns, useWithdrawFormSchema } from './data';
import AuditModal from './modules/audit-modal.vue';
const auditModalRef = ref<InstanceType<typeof AuditModal>>();
const [Grid, gridRef] = useVbenVxeGrid({
formOptions: {
schema: useWithdrawFormSchema(),
submitOnChange: true,
},
gridOptions: {
columns: useWithdrawColumns(),
proxyConfig: {
ajax: {
query: async ({
page,
form,
}: {
form: Record<string, any>;
page: {
currentPage: number;
pageSize: number;
};
}) => {
return await adminGetAgentWithdrawList({
...form,
page: page.currentPage,
pageSize: page.pageSize,
});
},
},
props: {
result: 'items',
total: 'total',
},
},
},
});
// 打开审核弹窗
const handleAudit = (record: any) => {
auditModalRef.value?.openAudit(record);
};
// 刷新表格
const handleRefresh = () => {
gridRef.value?.reload();
};
</script>
<template>
<Page auto-content-height>
<Grid table-title="代理提现记录">
<template #action="{ row }">
<VbenButton
v-if="row.status === 0"
type="primary"
@click="handleAudit(row)"
>
审核
</VbenButton>
<span v-else-if="row.status === 1" style="color: #16a34a">已通过</span>
<span v-else-if="row.status === 2" style="color: #ef4444">已拒绝</span>
</template>
</Grid>
<AuditModal ref="auditModalRef" @success="handleRefresh" />
</Page>
</template>

View File

@@ -0,0 +1,326 @@
<script lang="ts" setup>
import { computed, reactive, ref } from 'vue';
import {
message,
Modal,
RadioGroup,
RadioButton,
Form,
FormItem,
Input,
Textarea,
Button
} from 'ant-design-vue';
import { VbenButton } from '@vben/common-ui';
import { adminAuditAgentWithdraw, adminGetAgentWithdrawList } from '#/api/agent';
const emit = defineEmits<{
(e: 'success'): void;
}>();
const visible = ref(false);
const loading = ref(false);
const withdrawId = ref('');
const withdrawRecord = ref<any>(null);
// 审核表单
const formData = reactive({
status: 1 as number, // 1=通过, 2=拒绝
auditRemark: '',
});
// 税率预览(注意:实际税费由后端根据配置计算)
const taxRate = 0.06; // 6% - 仅用于前端显示预览
// 计算预览税费(仅用于显示,实际金额由后端计算)
const previewTaxAmount = computed(() => {
if (withdrawRecord.value && formData.status === 1) {
const withdrawAmount = withdrawRecord.value.withdraw_amount || 0;
return parseFloat((withdrawAmount * taxRate).toFixed(2));
}
return 0;
});
// 计算预览实际到账(仅用于显示,实际金额由后端计算)
const previewActualAmount = computed(() => {
if (withdrawRecord.value && formData.status === 1) {
const withdrawAmount = withdrawRecord.value.withdraw_amount || 0;
return parseFloat((withdrawAmount - previewTaxAmount.value).toFixed(2));
}
return 0;
});
// 打开审核弹窗
const openAudit = (record: any) => {
withdrawId.value = record.id;
withdrawRecord.value = record;
formData.status = 1; // 默认选中通过
formData.auditRemark = '';
visible.value = true;
};
// 暴露打开方法
defineExpose({ openAudit });
// 关闭弹窗
const handleClose = () => {
visible.value = false;
withdrawId.value = '';
withdrawRecord.value = null;
formData.status = 1;
formData.auditRemark = '';
};
// 提交审核
const handleSubmit = async () => {
// 验证
if (!withdrawId.value) {
message.warning('请选择提现记录');
return;
}
if (withdrawRecord.value.status !== 0) {
message.warning('该记录已被审核,请勿重复操作');
return;
}
if (formData.status === 2 && !formData.auditRemark.trim()) {
message.warning('拒绝提现时必须填写审核原因');
return;
}
loading.value = true;
try {
// 注意:税费和实际到账金额由后端根据配置计算,前端只传递审核状态和备注
await adminAuditAgentWithdraw({
withdraw_id: withdrawId.value,
status: formData.status,
audit_reason: formData.auditRemark,
});
message.success(formData.status === 1 ? '审核通过' : '已拒绝提现申请');
emit('success');
handleClose();
} catch (error) {
console.error('审核失败:', error);
// 失败时不关闭弹窗,也不重置状态,让用户可以重试
} finally {
loading.value = false;
}
};
// 确认弹窗
const showConfirm = () => {
const statusText = formData.status === 1 ? '通过' : '拒绝';
const confirmMessage = formData.status === 1
? `确认通过该提现申请?<br/>
提现金额:¥${withdrawRecord.value?.withdraw_amount?.toFixed(2)}<br/>
预计税费:¥${previewTaxAmount.value.toFixed(2)}(税率${(taxRate * 100).toFixed(0)}%<br/>
<strong>预计到账:¥${previewActualAmount.value.toFixed(2)}</strong><br/>
<small style="color: #f59e0b;">实际金额以系统计算为准</small>`
: `确认拒绝该提现申请?<br/>
提现金额:¥${withdrawRecord.value?.withdraw_amount?.toFixed(2)}<br/>
原因:${formData.auditRemark || '未填写'}`;
Modal.confirm({
title: `确认${statusText}提现申请`,
content: confirmMessage,
okText: '确认',
cancelText: '取消',
onOk: handleSubmit,
});
};
</script>
<template>
<div>
<VbenButton
type="primary"
@click="
() => {
message.info('请在列表中选择一条待审核的记录进行审核');
}
"
>
审核提现
</VbenButton>
<Modal
v-model:open="visible"
title="审核提现申请"
:width="600"
:confirm-loading="loading"
@cancel="handleClose"
>
<div v-if="withdrawRecord" class="audit-modal">
<!-- 提现信息 -->
<div class="section">
<h4>提现信息</h4>
<div class="info-grid">
<div class="info-item">
<span class="label">代理ID</span>
<span class="value">{{ withdrawRecord.agent_id }}</span>
</div>
<div class="info-item">
<span class="label">代理手机号</span>
<span class="value">{{ withdrawRecord.agent_mobile }}</span>
</div>
<div class="info-item">
<span class="label">代理编码</span>
<span class="value">{{ withdrawRecord.agent_code }}</span>
</div>
<div class="info-item">
<span class="label">提现金额</span>
<span class="value primary"
>¥{{ withdrawRecord.withdraw_amount?.toFixed(2) }}</span
>
</div>
<div class="info-item">
<span class="label">收款人</span>
<span class="value">{{ withdrawRecord.account_name }}</span>
</div>
<div class="info-item">
<span class="label">银行卡号</span>
<span class="value">{{ withdrawRecord.bank_card_number_full || withdrawRecord.bank_card_number }}</span>
</div>
<div class="info-item full-width">
<span class="label">开户支行</span>
<span class="value">{{
withdrawRecord.bank_branch || '未填写'
}}</span>
</div>
</div>
</div>
<!-- 审核操作 -->
<div class="section">
<h4>审核操作</h4>
<Form layout="vertical">
<FormItem label="审核结果" required>
<RadioGroup v-model:value="formData.status" button-style="solid">
<RadioButton :value="1">通过</RadioButton>
<RadioButton :value="2">拒绝</RadioButton>
</RadioGroup>
</FormItem>
<!-- 通过时显示税费信息预览 -->
<template v-if="formData.status === 1">
<FormItem label="税率(系统配置)">
<Input :value="`${(taxRate * 100).toFixed(0)}%`" disabled />
<div style="color: #f59e0b; font-size: 12px; margin-top: 4px;">
实际税率以系统配置为准
</div>
</FormItem>
<FormItem label="预计税费">
<Input
:value="`¥${previewTaxAmount.toFixed(2)}`"
disabled
/>
</FormItem>
<FormItem label="预计实际到账金额">
<Input
:value="`¥${previewActualAmount.toFixed(2)}`"
disabled
class="highlight-input"
/>
<div style="color: #f59e0b; font-size: 12px; margin-top: 4px;">
实际金额由系统根据配置计算
</div>
</FormItem>
</template>
<!-- 审核备注 -->
<FormItem
:label="formData.status === 2 ? '拒绝原因(必填)' : '审核备注'"
>
<Textarea
v-model:value="formData.auditRemark"
:placeholder="
formData.status === 2
? '请输入拒绝原因(必填)'
: '请输入审核备注(选填)'
"
:rows="3"
:maxlength="500"
show-count
/>
</FormItem>
</Form>
</div>
</div>
<template #footer>
<Button @click="handleClose">取消</Button>
<Button
type="primary"
:loading="loading"
:disabled="withdrawRecord?.status !== 0"
@click="showConfirm"
>
确认审核
</Button>
</template>
</Modal>
</div>
</template>
<style scoped>
.audit-modal {
padding: 10px 0;
}
.section {
margin-bottom: 24px;
}
.section h4 {
margin-bottom: 12px;
font-size: 16px;
font-weight: 600;
color: #1f2937;
border-left: 3px solid #1890ff;
padding-left: 8px;
}
.info-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
background: #f9fafb;
padding: 16px;
border-radius: 6px;
}
.info-item {
display: flex;
align-items: center;
}
.info-item.full-width {
grid-column: 1 / -1;
}
.info-item .label {
font-size: 13px;
color: #6b7280;
flex-shrink: 0;
}
.info-item .value {
font-size: 13px;
color: #1f2937;
font-weight: 500;
}
.info-item .value.primary {
color: #f59e0b;
font-size: 15px;
font-weight: 600;
}
:deep(.highlight-input input) {
color: #f59e0b;
font-weight: 600;
font-size: 15px;
}
</style>

View File

@@ -0,0 +1,110 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { getAgentRanking } from '#/api/agent';
import type { AgentApi } from '#/api/agent';
const loading = ref(false);
const rankingType = ref<'commission' | 'orders'>('commission');
const rankingList = ref<AgentApi.AgentRankingItem[]>([]);
const columns = [
{
dataIndex: 'rank',
key: 'rank',
title: '排名',
width: 80,
},
{
dataIndex: 'agent_mobile',
key: 'agent_mobile',
title: '代理手机号',
},
{
dataIndex: 'region',
key: 'region',
title: '区域',
},
{
dataIndex: 'value',
key: 'value',
title: '佣金(元)',
width: 150,
},
];
async function loadRanking() {
loading.value = true;
try {
const data = await getAgentRanking({
type: rankingType.value,
limit: 10,
});
rankingList.value = data.items.map((item, index) => ({
...item,
rank: index + 1,
}));
// 更新列标题
columns[3].title = rankingType.value === 'commission' ? '佣金(元)' : '订单数';
} catch (error) {
console.error('Failed to load agent ranking:', error);
} finally {
loading.value = false;
}
}
function handleTypeChange() {
loadRanking();
}
onMounted(() => {
loadRanking();
});
</script>
<template>
<div class="agent-ranking-table">
<div class="ranking-header">
<a-radio-group v-model:value="rankingType" button-style="solid" @change="handleTypeChange">
<a-radio-button value="commission">佣金排行</a-radio-button>
<a-radio-button value="orders">订单量排行</a-radio-button>
</a-radio-group>
</div>
<a-table
:columns="columns"
:data-source="rankingList"
:loading="loading"
:pagination="false"
row-key="agent_id"
size="small"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'rank'">
<a-tag v-if="record.rank === 1" color="gold">1</a-tag>
<a-tag v-else-if="record.rank === 2" color="silver">2</a-tag>
<a-tag v-else-if="record.rank === 3" color="#cd7f32">3</a-tag>
<span v-else>{{ record.rank }}</span>
</template>
<template v-else-if="column.key === 'value'">
{{
rankingType === 'commission'
? `¥${record.value.toFixed(2)}`
: record.value
}}
</template>
</template>
</a-table>
</div>
</template>
<style lang="less" scoped>
.agent-ranking-table {
.ranking-header {
margin-bottom: 16px;
display: flex;
justify-content: flex-end;
}
}
</style>

View File

@@ -0,0 +1,77 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { getAgentTrends } from '#/api/agent';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const loading = ref(false);
async function loadChartData() {
loading.value = true;
try {
const data = await getAgentTrends();
renderEcharts({
grid: {
bottom: 40,
containLabel: true,
left: '3%',
right: '4%',
top: '10%',
},
legend: {
data: ['新增代理'],
top: 0,
},
series: [
{
barMaxWidth: 80,
data: data.counts,
itemStyle: {
color: '#4f69fd',
},
name: '新增代理',
type: 'bar',
},
],
tooltip: {
axisPointer: {
lineStyle: {
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
data: data.dates,
type: 'category',
},
yAxis: {
name: '新增代理数',
splitNumber: 4,
type: 'value',
},
});
} catch (error) {
console.error('Failed to load agent trends:', error);
} finally {
loading.value = false;
}
}
onMounted(() => {
loadChartData();
});
</script>
<template>
<div class="agent-trends-chart">
<a-spin :spinning="loading">
<EchartsUI ref="chartRef" />
</a-spin>
</div>
</template>

View File

@@ -0,0 +1,81 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
grid: {
bottom: 0,
containLabel: true,
left: '1%',
right: '1%',
top: '2%',
},
series: [
{
areaStyle: {},
data: [
120, 300, 500, 800, 1200, 1800, 2500, 3000, 2800, 2600, 2400, 2200,
2000, 1800, 1600, 1400, 1200, 1000, 800, 600, 400, 200, 100, 50, 30,
20, 10, 5, 2, 1,
],
itemStyle: {
color: '#5ab1ef',
},
smooth: true,
type: 'line',
name: '访问量',
},
],
tooltip: {
axisPointer: {
lineStyle: {
color: '#5ab1ef',
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
axisTick: {
show: false,
},
boundaryGap: false,
data: Array.from({ length: 30 }).map(
(_item, index) => `Day ${index + 1}`,
),
splitLine: {
lineStyle: {
type: 'solid',
width: 1,
},
show: true,
},
type: 'category',
},
yAxis: [
{
axisTick: {
show: false,
},
max: 3000,
splitArea: {
show: true,
},
splitNumber: 4,
type: 'value',
},
],
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>

View File

@@ -0,0 +1,73 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
legend: {
bottom: 0,
data: ['渠道A', '渠道B', '渠道C', '渠道D'],
},
radar: {
indicator: [
{ name: '渠道A' },
{ name: '渠道B' },
{ name: '渠道C' },
{ name: '渠道D' },
],
radius: '60%',
splitNumber: 8,
},
series: [
{
areaStyle: {
opacity: 1,
shadowBlur: 0,
shadowColor: 'rgba(0,0,0,.2)',
shadowOffsetX: 0,
shadowOffsetY: 10,
},
data: [
{
itemStyle: { color: '#b6a2de' },
name: '渠道A',
value: [90, 50, 86, 40],
},
{
itemStyle: { color: '#5ab1ef' },
name: '渠道B',
value: [70, 75, 70, 76],
},
{
itemStyle: { color: '#67e0e3' },
name: '渠道C',
value: [60, 65, 60, 66],
},
{
itemStyle: { color: '#2ec7c9' },
name: '渠道D',
value: [50, 55, 50, 56],
},
],
itemStyle: {
borderRadius: 10,
borderWidth: 2,
},
symbolSize: 0,
type: 'radar',
},
],
tooltip: {},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>

View File

@@ -0,0 +1,42 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
series: [
{
animationDelay() {
return Math.random() * 400;
},
animationEasing: 'exponentialInOut',
animationType: 'scale',
center: ['50%', '50%'],
color: ['#5ab1ef', '#b6a2de', '#67e0e3'],
data: [
{ name: '佣金', value: 500 },
{ name: '奖励', value: 310 },
{ name: '提现', value: 274 },
],
name: '金额占比',
radius: '80%',
roseType: 'radius',
type: 'pie',
},
],
tooltip: {
trigger: 'item',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>

View File

@@ -0,0 +1,66 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
legend: {
bottom: '2%',
left: 'center',
data: ['产品A', '产品B', '产品C', '产品D'],
},
series: [
{
animationDelay() {
return Math.random() * 100;
},
animationEasing: 'exponentialInOut',
animationType: 'scale',
avoidLabelOverlap: false,
color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
data: [
{ name: '产品A', value: 1048 },
{ name: '产品B', value: 735 },
{ name: '产品C', value: 580 },
{ name: '产品D', value: 484 },
],
emphasis: {
label: {
fontSize: '12',
fontWeight: 'bold',
show: true,
},
},
itemStyle: {
// borderColor: '#fff',
borderRadius: 10,
borderWidth: 2,
},
label: {
position: 'center',
show: false,
},
labelLine: {
show: false,
},
name: '订单来源',
radius: ['40%', '65%'],
type: 'pie',
},
],
tooltip: {
trigger: 'item',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>

View File

@@ -0,0 +1,56 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
onMounted(() => {
renderEcharts({
grid: {
bottom: 0,
containLabel: true,
left: '1%',
right: '1%',
top: '2%',
},
series: [
{
barMaxWidth: 80,
data: [
30, 20, 33, 50, 32, 42, 32, 21, 30, 51, 60, 32, 48, 40, 35, 28, 22,
18, 15, 10, 8, 6, 4, 2, 1, 1, 0, 0, 0, 0,
],
type: 'bar',
name: '订单数',
},
],
tooltip: {
axisPointer: {
lineStyle: {
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
data: Array.from({ length: 30 }).map(
(_item, index) => `Day ${index + 1}`,
),
type: 'category',
},
yAxis: {
max: 80,
splitNumber: 4,
type: 'value',
},
});
});
</script>
<template>
<EchartsUI ref="chartRef" />
</template>

View File

@@ -0,0 +1,56 @@
<script lang="ts" setup>
import type { TabOption } from '@vben/types';
import {
AnalysisChartCard,
AnalysisChartsTabs,
} from '@vben/common-ui';
import StatisticsOverview from './statistics-overview.vue';
import AgentRankingTable from './agent-ranking-table.vue';
import AgentTrendsChart from './agent-trends-chart.vue';
import OrderTrendsChart from './order-trends-chart.vue';
import ProductDistributionChart from './product-distribution-chart.vue';
import RegionDistributionChart from './region-distribution-chart.vue';
const chartTabs: TabOption[] = [
{
label: '订单趋势',
value: 'order-trends',
},
{
label: '代理注册趋势',
value: 'agent-trends',
},
];
</script>
<template>
<div class="p-5">
<!-- 统计概览 -->
<StatisticsOverview />
<!-- 趋势图表 -->
<AnalysisChartsTabs :tabs="chartTabs" class="mt-5">
<template #order-trends>
<OrderTrendsChart />
</template>
<template #agent-trends>
<AgentTrendsChart />
</template>
</AnalysisChartsTabs>
<!-- 分布图表和排行榜 -->
<div class="mt-5 w-full md:flex">
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="产品订单分布">
<ProductDistributionChart />
</AnalysisChartCard>
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="区域代理分布">
<RegionDistributionChart />
</AnalysisChartCard>
<AnalysisChartCard class="mt-5 md:mt-0 md:w-1/3" title="代理排行榜">
<AgentRankingTable />
</AnalysisChartCard>
</div>
</div>
</template>

View File

@@ -0,0 +1,116 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { getOrderTrends } from '#/api/agent';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const loading = ref(false);
async function loadChartData() {
loading.value = true;
try {
const data = await getOrderTrends();
renderEcharts({
grid: {
bottom: 40,
containLabel: true,
left: '3%',
right: '4%',
top: '10%',
},
legend: {
data: ['订单金额', '订单数量'],
top: 0,
},
series: [
{
areaStyle: {},
data: data.amounts,
itemStyle: {
color: '#5ab1ef',
},
name: '订单金额',
smooth: true,
type: 'line',
},
{
areaStyle: {},
data: data.counts,
itemStyle: {
color: '#019680',
},
name: '订单数量',
smooth: true,
type: 'line',
yAxisIndex: 1,
},
],
tooltip: {
axisPointer: {
lineStyle: {
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
axisTick: {
show: false,
},
boundaryGap: false,
data: data.dates,
splitLine: {
lineStyle: {
type: 'solid',
width: 1,
},
show: true,
},
type: 'category',
},
yAxis: [
{
axisTick: {
show: false,
},
name: '金额(元)',
splitArea: {
show: true,
},
splitNumber: 4,
type: 'value',
},
{
axisTick: {
show: false,
},
name: '订单数',
splitNumber: 4,
type: 'value',
},
],
});
} catch (error) {
console.error('Failed to load order trends:', error);
} finally {
loading.value = false;
}
}
onMounted(() => {
loadChartData();
});
</script>
<template>
<div class="order-trends-chart">
<a-spin :spinning="loading">
<EchartsUI ref="chartRef" />
</a-spin>
</div>
</template>

View File

@@ -0,0 +1,66 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { getProductDistribution } from '#/api/agent';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const loading = ref(false);
async function loadChartData() {
loading.value = true;
try {
const data = await getProductDistribution();
renderEcharts({
legend: {
bottom: 0,
orient: 'horizontal',
},
series: [
{
data: data.products.map((product, index) => ({
name: product,
value: data.counts[index],
})),
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)',
},
},
label: {
formatter: '{b}: {c} ({d}%)',
},
radius: '70%',
type: 'pie',
},
],
tooltip: {
formatter: '{a} <br/>{b}: {c} ({d}%)',
trigger: 'item',
},
});
} catch (error) {
console.error('Failed to load product distribution:', error);
} finally {
loading.value = false;
}
}
onMounted(() => {
loadChartData();
});
</script>
<template>
<div class="product-distribution-chart">
<a-spin :spinning="loading">
<EchartsUI ref="chartRef" />
</a-spin>
</div>
</template>

View File

@@ -0,0 +1,97 @@
<script lang="ts" setup>
import type { EchartsUIType } from '@vben/plugins/echarts';
import { onMounted, ref } from 'vue';
import { EchartsUI, useEcharts } from '@vben/plugins/echarts';
import { getRegionDistribution } from '#/api/agent';
const chartRef = ref<EchartsUIType>();
const { renderEcharts } = useEcharts(chartRef);
const loading = ref(false);
async function loadChartData() {
loading.value = true;
try {
const data = await getRegionDistribution();
renderEcharts({
grid: {
bottom: 40,
containLabel: true,
left: '3%',
right: '4%',
top: '10%',
},
legend: {
data: ['代理数量'],
top: 0,
},
series: [
{
barMaxWidth: 80,
data: data.counts,
itemStyle: {
color: {
colorStops: [
{
color: '#4f69fd',
offset: 0,
},
{
color: '#7c85ff',
offset: 1,
},
],
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
},
},
name: '代理数量',
type: 'bar',
},
],
tooltip: {
axisPointer: {
lineStyle: {
width: 1,
},
},
trigger: 'axis',
},
xAxis: {
axisLabel: {
interval: 0,
rotate: 30,
},
data: data.regions,
type: 'category',
},
yAxis: {
name: '代理数量',
splitNumber: 4,
type: 'value',
},
});
} catch (error) {
console.error('Failed to load region distribution:', error);
} finally {
loading.value = false;
}
}
onMounted(() => {
loadChartData();
});
</script>
<template>
<div class="region-distribution-chart">
<a-spin :spinning="loading">
<EchartsUI ref="chartRef" />
</a-spin>
</div>
</template>

Some files were not shown because too many files have changed in this diff Show More