export type ShopRecord = { id?: number platform_code?: string platform_name?: string custom_name?: string shop_name?: string auth_expire_at?: string | number status?: string | number access_token?: string } export const shopColumns = [ { prop: 'id', label: 'ID', width: '80', sortable: true }, { prop: 'platform_code', label: '平台编码', minWidth: '120', showOverflowTooltip: true }, { prop: 'platform_name', label: '平台名称', minWidth: '140', showOverflowTooltip: true }, { prop: 'custom_name', label: '自定义名称', minWidth: '160', showOverflowTooltip: true }, { prop: 'shop_name', label: '平台真实店铺名', minWidth: '160', showOverflowTooltip: true }, { prop: 'auth_expire_at', label: '授权过期时间', minWidth: '180' }, { prop: 'access_token', label: '密钥', minWidth: '200', showOverflowTooltip: true }, { prop: 'status', label: '状态', width: '100' }, { prop: 'actions', label: '操作', width: '220', fixed: 'right' } ] export const shopScanFields = [ { value: 'quickWhere', label: '关键词', type: 'text', placeholder: '自定义名称/平台真实店铺名', operators: ['contains', 'eq'], defaultOperator: 'eq' }, { value: 'platform_code', label: '平台编码', type: 'select', filterable: true, clearable: true, options: [] as { label: string; value: string }[] }, { value: 'status', label: '状态', type: 'select', clearable: true, options: [ { label: '已激活', value: '1' }, { label: '未激活', value: '0' } ] }, { value: 'id', label: 'ID', type: 'number', placeholder: '店铺 ID', operators: ['eq', 'ne'], defaultOperator: 'eq' }, { value: 'custom_name', label: '自定义名称', type: 'text', placeholder: '请输入自定义名称', operators: ['eq', 'contains', 'like'], defaultOperator: 'eq' }, { value: 'shop_name', label: '平台真实店铺名', type: 'text', placeholder: '请输入平台真实店铺名', operators: ['eq', 'contains', 'like'], defaultOperator: 'eq' } ] function getFieldConfig(key: string, fields: typeof shopScanFields) { return fields.find((f) => f.value === key) } function mapFieldType(type: string, value: unknown) { if (type === 'daterange' || Array.isArray(value)) return 'daterange' if (type === 'number' || typeof value === 'number') return 'number' return 'text' } function processConditionValue(key: string, raw: any, fields: typeof shopScanFields) { if (key === 'quickWhere') { const val = raw?.value !== undefined ? raw.value : raw const text = val == null ? '' : String(val).trim() return text ? text : null } const config = getFieldConfig(key, fields) const fieldType = config?.type || 'text' if (raw && typeof raw === 'object' && !Array.isArray(raw)) { const op = raw.operator || (fieldType === 'select' ? 'eq' : fieldType === 'number' ? 'eq' : 'contains') const type = raw.type || mapFieldType(fieldType, raw.value) if (['isnull', 'isnotnull'].includes(op)) { return { operator: op, value: null, type } } const val = raw.value !== undefined ? raw.value : raw if (val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)) { return null } if (fieldType === 'select') { return { operator: op || 'eq', value: val, type: 'text' } } return { operator: op, value: val, type } } if (raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0)) { return null } const simpleOp = fieldType === 'select' || fieldType === 'number' ? 'eq' : 'contains' return { operator: simpleOp, value: raw, type: mapFieldType(fieldType, raw) } } /** 将 ScanBox 条件转为 shops.list 接口 where */ export function normalizeShopScanConditionToWhere( condition: any, fields: typeof shopScanFields = shopScanFields ): Record { if (!condition) return {} const conds = condition?.conditions && typeof condition.conditions === 'object' ? condition.conditions : condition && typeof condition === 'object' ? condition : null if (!conds) return {} const where: Record = {} for (const key of Object.keys(conds)) { const result = processConditionValue(key, conds[key], fields) if (result == null) continue if (key === 'quickWhere' && typeof result === 'string') { where.quickWhere = result } else { where[key] = result } } return where } export function formatShopStatus(status: string | number | undefined) { const raw = String(status ?? '').trim().toUpperCase() if (!raw) return { text: '--', type: 'info' as const } if (['1', 'ACTIVE', 'ENABLED', 'ENABLE'].includes(raw)) { return { text: '已激活', type: 'success' as const } } if (['0', 'INACTIVE', 'DISABLED', 'DISABLE'].includes(raw)) { return { text: '未激活', type: 'info' as const } } return { text: String(status), type: 'info' as const } } export function buildShopListPayload(options: { page: number pageSize: number where?: Record }) { const payload: Record = { page: options.page, pageSize: options.pageSize, pagination: { page: options.page, pageSize: options.pageSize } } if (options.where && Object.keys(options.where).length) { payload.where = options.where } return payload }