144 lines
4.8 KiB
TypeScript
144 lines
4.8 KiB
TypeScript
import type { MerchantMember, MerchantProduct } from '../types'
|
|
|
|
export const orderStatusMap: Record<string, { color: string; text: string }> = {
|
|
paid: { color: 'blue', text: '待发货' },
|
|
delivering: { color: 'cyan', text: '发货中' },
|
|
delivered: { color: 'green', text: '已交付' },
|
|
ship_failed: { color: 'red', text: '发货失败' },
|
|
cancelled: { color: 'default', text: '已取消' },
|
|
}
|
|
|
|
export const orderStatusOptions = [
|
|
{ value: '', label: '全部' },
|
|
{ value: 'paid', label: '待发货' },
|
|
{ value: 'delivering', label: '发货中' },
|
|
{ value: 'delivered', label: '已交付' },
|
|
{ value: 'ship_failed', label: '发货失败' },
|
|
{ value: 'cancelled', label: '已取消' },
|
|
]
|
|
|
|
export const memberRoleOptions = [
|
|
{ value: 'owner', label: '负责人' },
|
|
{ value: 'operator', label: '运营' },
|
|
{ value: 'finance', label: '财务' },
|
|
{ value: 'support', label: '客服' },
|
|
]
|
|
|
|
export const rolePermissionOptions = [
|
|
{ value: 'products:manage', label: '商品管理' },
|
|
{ value: 'orders:manage', label: '订单与发货管理' },
|
|
{ value: 'wallet:view', label: '查看钱包与充值记录' },
|
|
{ value: 'wallet:ledger', label: '查看积分明细' },
|
|
{ value: 'recharge:manage', label: '申请充值与管理余额告警' },
|
|
{ value: 'api:manage', label: '管理 API 密钥' },
|
|
{ value: 'callbacks:manage', label: '管理回调' },
|
|
{ value: 'members:manage', label: '管理团队成员与角色' },
|
|
]
|
|
|
|
export function rolePermissionText(permission: string) {
|
|
return rolePermissionOptions.find((item) => item.value === permission)?.label || permission
|
|
}
|
|
|
|
export const apiClientMax = 5
|
|
|
|
export const scopeOptions = [
|
|
{ value: 'products:read', label: '商品读取' },
|
|
{ value: 'orders:read', label: '订单读取' },
|
|
{ value: 'orders:write', label: '订单写入' },
|
|
{ value: 'shipping:read', label: '发货读取' },
|
|
{ value: 'wallet:read', label: '钱包读取' },
|
|
]
|
|
|
|
export const eventOptions = [
|
|
{ value: 'order.created', label: '订单创建' },
|
|
{ value: 'order.shipping.updated', label: '发货更新' },
|
|
{ value: 'order.cancelled', label: '订单取消' },
|
|
]
|
|
|
|
export const testOrderStatusOptions = [
|
|
{ value: 'paid', label: '已支付,可发货' },
|
|
{ value: 'ship_failed', label: '发货失败,可重试' },
|
|
{ value: 'cancelled', label: '已取消,不可发货' },
|
|
]
|
|
|
|
export type MerchantCenterTab = 'products' | 'orders' | 'wallet' | 'api' | 'callbacks' | 'members'
|
|
|
|
export interface MerchantCenterProps {
|
|
fixedTab?: MerchantCenterTab
|
|
title?: string
|
|
}
|
|
|
|
export function pageConfig<T extends { page: number; size: number; total: number }>(
|
|
data: T,
|
|
load: (page: number, size: number) => void,
|
|
) {
|
|
return {
|
|
current: data.page,
|
|
pageSize: data.size,
|
|
total: data.total,
|
|
showSizeChanger: true,
|
|
showTotal: (total: number) => `共 ${total} 条`,
|
|
onChange: load,
|
|
}
|
|
}
|
|
|
|
export function featuresToList(features?: string) {
|
|
const list = (features || '')
|
|
.split(/[,\s]+/)
|
|
.map((item) => item.trim())
|
|
.filter(Boolean)
|
|
return list.length > 0 ? list : ['products', 'orders', 'wallet', 'api', 'callbacks']
|
|
}
|
|
|
|
export function defaultCallbackFormValues() {
|
|
return {
|
|
events: ['order.shipping.updated'],
|
|
status: 'active',
|
|
}
|
|
}
|
|
|
|
export function eventsToValue(events?: string) {
|
|
return (events || '')
|
|
.split(',')
|
|
.map((item) => item.trim())
|
|
.filter(Boolean)
|
|
}
|
|
|
|
export function tabFromSearch(search: string): MerchantCenterTab | null {
|
|
const tab = new URLSearchParams(search).get('tab')
|
|
const allowedTabs: MerchantCenterTab[] = ['products', 'orders', 'wallet', 'api', 'callbacks', 'members']
|
|
return allowedTabs.includes(tab as MerchantCenterTab) ? tab as MerchantCenterTab : null
|
|
}
|
|
|
|
export function resolveEnabledTab(current: MerchantCenterTab, features?: string): MerchantCenterTab {
|
|
const enabled = new Set(featuresToList(features))
|
|
const tabFeatures: Record<MerchantCenterTab, string | null> = {
|
|
products: 'products',
|
|
orders: 'orders',
|
|
wallet: 'wallet',
|
|
api: 'api',
|
|
callbacks: 'callbacks',
|
|
members: null,
|
|
}
|
|
const feature = tabFeatures[current]
|
|
if (feature === null || enabled.has(feature)) {
|
|
return current
|
|
}
|
|
return (['products', 'orders', 'wallet', 'api', 'callbacks'] as MerchantCenterTab[]).find((key) => enabled.has(key)) || 'members'
|
|
}
|
|
|
|
export function money(value?: number | null) {
|
|
return `${Number(value || 0)} 积分`
|
|
}
|
|
export function productOptionLabel(item: MerchantProduct) {
|
|
const name = item.display_name || item.product?.name || item.sku
|
|
return name === item.sku ? item.sku : `${name} / ${item.sku}`
|
|
}
|
|
export function scopeLabel(scope: string) {
|
|
return scopeOptions.find((item) => item.value === scope)?.label || scope
|
|
}
|
|
|
|
export function roleText(value: MerchantMember['role']) {
|
|
return memberRoleOptions.find((item) => item.value === value)?.label || value
|
|
}
|