提交
This commit is contained in:
1 parent
d84f4b944c
commit
7c838cfb2d
249 files changed
+50600
-18556
No files matched your search
@@ -0,0 +1,2 @@
|
||||
/** Demo 模板页 API 统一出口(Mock,无后端) */
|
||||
export * from './mock-api'
|
||||
@@ -0,0 +1,389 @@
|
||||
/**
|
||||
* Demo 模板页 Mock API(本地内存,不依赖后端)
|
||||
* 供 views/demo/* 与 product-view-dialog 使用
|
||||
*/
|
||||
import { fetchUserList } from '@/api/admin'
|
||||
import {
|
||||
demoCategories,
|
||||
demoOrders,
|
||||
demoProducts,
|
||||
demoRegions,
|
||||
demoUnits
|
||||
} from './mock-data'
|
||||
import { DEFAULT_LIST_PAGE_SIZE } from '@/utils/table/tableConfig'
|
||||
|
||||
type PageParams = { page?: number; pageSize?: number; keyword?: string }
|
||||
|
||||
const delay = (ms = 120) => new Promise((resolve) => setTimeout(resolve, ms))
|
||||
|
||||
function paginate<T>(list: T[], page = 1, pageSize = DEFAULT_LIST_PAGE_SIZE) {
|
||||
const p = Math.max(1, page)
|
||||
const ps = Math.max(1, pageSize)
|
||||
const start = (p - 1) * ps
|
||||
const slice = list.slice(start, start + ps)
|
||||
return {
|
||||
list: slice,
|
||||
total: list.length,
|
||||
page: p,
|
||||
pageSize: ps,
|
||||
totalPages: Math.max(1, Math.ceil(list.length / ps))
|
||||
}
|
||||
}
|
||||
|
||||
function filterKeyword<T extends Record<string, any>>(
|
||||
list: T[],
|
||||
keys: string[],
|
||||
keyword?: string
|
||||
) {
|
||||
const kw = (keyword || '').trim().toLowerCase()
|
||||
if (!kw) return list
|
||||
return list.filter((row) => keys.some((k) => String(row[k] ?? '').toLowerCase().includes(kw)))
|
||||
}
|
||||
|
||||
const units = [...demoUnits]
|
||||
const categories = [...demoCategories]
|
||||
const products = [...demoProducts]
|
||||
const orders = [...demoOrders]
|
||||
|
||||
function newId(prefix: string) {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
||||
}
|
||||
|
||||
// ─── 物品单位 ─────────────────────────────────────────
|
||||
|
||||
export async function fetchItemUnitList(params?: PageParams) {
|
||||
await delay()
|
||||
const filtered = filterKeyword(units, ['unitName', 'unitCode'], params?.keyword)
|
||||
return paginate(filtered, params?.page, params?.pageSize)
|
||||
}
|
||||
|
||||
export async function fetchCreateItemUnit(data: {
|
||||
unitCode: string
|
||||
unitName: string
|
||||
orderNum?: number
|
||||
remark?: string
|
||||
}) {
|
||||
await delay()
|
||||
const row: Api.ItemUnit.ItemUnitItem = {
|
||||
id: newId('demo-unit'),
|
||||
unitCode: data.unitCode,
|
||||
unitName: data.unitName,
|
||||
tenantNo: 'demo',
|
||||
orderNum: data.orderNum ?? 0,
|
||||
remark: data.remark || '',
|
||||
createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||
updateTime: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
units.unshift(row)
|
||||
return row
|
||||
}
|
||||
|
||||
export async function fetchUpdateItemUnit(
|
||||
id: string,
|
||||
data: Partial<{ unitCode: string; unitName: string; orderNum: number; remark: string }>
|
||||
) {
|
||||
await delay()
|
||||
const idx = units.findIndex((u) => u.id === id)
|
||||
if (idx >= 0) units[idx] = { ...units[idx], ...data }
|
||||
return units[idx]
|
||||
}
|
||||
|
||||
export async function fetchDeleteItemUnit(id: string) {
|
||||
await delay()
|
||||
const idx = units.findIndex((u) => u.id === id)
|
||||
if (idx >= 0) units.splice(idx, 1)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
// ─── 分类 ───────────────────────────────────────────
|
||||
|
||||
export async function fetchCategoryList(params?: PageParams & { isActive?: boolean }) {
|
||||
await delay()
|
||||
let list = [...categories]
|
||||
if (params?.isActive != null) list = list.filter((c) => c.isActive === params.isActive)
|
||||
list = filterKeyword(list, ['name'], params?.keyword)
|
||||
return paginate(list, params?.page, params?.pageSize)
|
||||
}
|
||||
|
||||
export async function fetchCreateCategory(data: {
|
||||
name: string
|
||||
parentId?: string
|
||||
sortOrder?: number
|
||||
imageUrl?: string
|
||||
}) {
|
||||
await delay()
|
||||
const row: Api.Category.CategoryItem = {
|
||||
id: newId('demo-cat'),
|
||||
name: data.name,
|
||||
parentId: data.parentId || '0',
|
||||
sortOrder: data.sortOrder ?? 0,
|
||||
isActive: true,
|
||||
imageUrl: data.imageUrl || '',
|
||||
createAt: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
categories.push(row)
|
||||
return row
|
||||
}
|
||||
|
||||
export async function fetchUpdateCategory(id: string, data: Partial<Api.Category.CategoryItem>) {
|
||||
await delay()
|
||||
const idx = categories.findIndex((c) => c.id === id)
|
||||
if (idx >= 0) categories[idx] = { ...categories[idx], ...data }
|
||||
return categories[idx]
|
||||
}
|
||||
|
||||
export async function fetchDeleteCategory(id: string) {
|
||||
await delay()
|
||||
const idx = categories.findIndex((c) => c.id === id)
|
||||
if (idx >= 0) categories.splice(idx, 1)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchUploadCategoryImage(_data: FormData) {
|
||||
await delay()
|
||||
return { fileUrl: '', fileName: 'demo.png' }
|
||||
}
|
||||
|
||||
export async function fetchProductParameterSimple() {
|
||||
await delay()
|
||||
return { list: [] as Api.Product.ProductParameterSimple[], total: 0 }
|
||||
}
|
||||
|
||||
export async function fetchCategoryParameters(_categoryId: string) {
|
||||
await delay()
|
||||
return { list: [] as Api.Product.CategoryParameter[], total: 0 }
|
||||
}
|
||||
|
||||
export async function fetchUpdateCategoryParameters(_categoryId: string, _items: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
// ─── 商品单位(Unit 命名,商品页用) ─────────────────
|
||||
|
||||
export async function fetchUnitList(params?: PageParams) {
|
||||
await delay()
|
||||
const list: Api.Unit.UnitItem[] = units.map((u) => ({
|
||||
id: u.id,
|
||||
name: u.unitName,
|
||||
code: u.unitCode,
|
||||
isActive: true,
|
||||
createAt: u.createTime
|
||||
}))
|
||||
const filtered = filterKeyword(list, ['name', 'code'], params?.keyword)
|
||||
return paginate(filtered, params?.page, params?.pageSize)
|
||||
}
|
||||
|
||||
// ─── 商品 ───────────────────────────────────────────
|
||||
|
||||
export async function fetchProductList(params?: PageParams & { categoryId?: string }) {
|
||||
await delay()
|
||||
let list = [...products]
|
||||
if (params?.categoryId) list = list.filter((p) => p.categoryId === params.categoryId)
|
||||
list = filterKeyword(list, ['name'], params?.keyword)
|
||||
return paginate(list, params?.page, params?.pageSize)
|
||||
}
|
||||
|
||||
export async function fetchProductDetail(id: string) {
|
||||
await delay()
|
||||
const base = products.find((p) => p.id === id)
|
||||
if (!base) throw new Error('商品不存在')
|
||||
return {
|
||||
...base,
|
||||
updateAt: base.createAt,
|
||||
updateBy: 'demo',
|
||||
skuCode: 'SKU-DEMO',
|
||||
measureValue: 1,
|
||||
detailContent: ''
|
||||
} as Api.Product.ProductDetail & { skuCode?: string; measureValue?: number; detailContent?: string }
|
||||
}
|
||||
|
||||
export async function fetchCreateProduct(data: Partial<Api.Product.ProductItem> & { name: string }) {
|
||||
await delay()
|
||||
const row: Api.Product.ProductItem = {
|
||||
id: newId('demo-prod'),
|
||||
name: data.name,
|
||||
categoryId: data.categoryId,
|
||||
categoryName: categories.find((c) => c.id === data.categoryId)?.name,
|
||||
unitId: data.unitId,
|
||||
unitName: units.find((u) => u.id === data.unitId)?.unitName,
|
||||
description: data.description || '',
|
||||
imageUrl: data.imageUrl || '',
|
||||
isActive: data.isActive ?? true,
|
||||
createAt: new Date().toISOString().slice(0, 19).replace('T', ' ')
|
||||
}
|
||||
products.unshift(row)
|
||||
return row
|
||||
}
|
||||
|
||||
export async function fetchUpdateProduct(id: string, data: Partial<Api.Product.ProductItem>) {
|
||||
await delay()
|
||||
const idx = products.findIndex((p) => p.id === id)
|
||||
if (idx >= 0) products[idx] = { ...products[idx], ...data }
|
||||
return products[idx]
|
||||
}
|
||||
|
||||
export async function fetchDeleteProduct(id: string) {
|
||||
await delay()
|
||||
const idx = products.findIndex((p) => p.id === id)
|
||||
if (idx >= 0) products.splice(idx, 1)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchProductBannerList(_productId: string) {
|
||||
await delay()
|
||||
return { list: [] as Api.Product.ProductBanner[], total: 0 }
|
||||
}
|
||||
|
||||
export async function fetchCreateProductBanners(_productId: string, _items: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchUpdateProductBannerSort(_productId: string, _items: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchDeleteProductBanner(_id: string) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchProductDetailMediaList(_productId: string) {
|
||||
await delay()
|
||||
return { list: [] as Api.Product.ProductDetailMedia[], total: 0 }
|
||||
}
|
||||
|
||||
export async function fetchCreateProductDetailMedia(_productId: string, _items: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchUpdateProductDetailMediaSort(_productId: string, _items: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchDeleteProductDetailMedia(_id: string) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchProductParameterValues(_productId: string) {
|
||||
await delay()
|
||||
return { list: [] as Api.Product.ProductParameterValue[], total: 0 }
|
||||
}
|
||||
|
||||
export async function fetchSaveProductParameterValues(_productId: string, _values: unknown[]) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchProductRegionPrices(_productId: string) {
|
||||
await delay()
|
||||
return {
|
||||
list: demoRegions.map((r) => ({
|
||||
regionId: r.id,
|
||||
regionName: r.name,
|
||||
price: 100,
|
||||
unitId: null,
|
||||
unitName: null
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 区域 / 用户(订单页) ───────────────────────────
|
||||
|
||||
export async function fetchNotDeletedRegions() {
|
||||
await delay()
|
||||
return [...demoRegions]
|
||||
}
|
||||
|
||||
export { fetchUserList }
|
||||
|
||||
// ─── business.ts 订单等 ─────────────────────────────
|
||||
|
||||
export async function fetchOrderList(params?: PageParams & Record<string, unknown>) {
|
||||
await delay()
|
||||
let list = [...orders]
|
||||
list = filterKeyword(list, ['orderNo', 'clientName'], params?.keyword as string | undefined)
|
||||
return paginate(list, params?.page, params?.pageSize)
|
||||
}
|
||||
|
||||
export async function fetchOrderDetail(id: string) {
|
||||
await delay()
|
||||
const base = orders.find((o) => o.id === id)
|
||||
if (!base) throw new Error('订单不存在')
|
||||
return {
|
||||
...base,
|
||||
items: [],
|
||||
remark: 'Demo 订单详情'
|
||||
} as Api.Order.OrderDetail
|
||||
}
|
||||
|
||||
export async function fetchAssignDelivery(_data: unknown) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchReviewCancel(_data: unknown) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchCancelOrder(_data: unknown) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchOrderItems(_orderId: string) {
|
||||
await delay()
|
||||
return { list: [] }
|
||||
}
|
||||
|
||||
export async function fetchAdjustOrder(_data: unknown) {
|
||||
await delay()
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function fetchOrderAdjusts(_orderId: string) {
|
||||
await delay()
|
||||
return { list: [] }
|
||||
}
|
||||
|
||||
export async function fetchPriceVersionDetail(_id: string) {
|
||||
await delay()
|
||||
return { id: _id, name: 'Demo 价目表' }
|
||||
}
|
||||
|
||||
export async function fetchUploadAttachment(_data: FormData) {
|
||||
await delay()
|
||||
return {
|
||||
id: newId('att'),
|
||||
fileName: 'demo.pdf',
|
||||
fileUrl: '#',
|
||||
fileSize: 0
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchUploadProductImage(_data: FormData) {
|
||||
await delay()
|
||||
return { fileUrl: '', fileName: 'demo.png' }
|
||||
}
|
||||
|
||||
export async function fetchSystemConfig() {
|
||||
await delay()
|
||||
return {
|
||||
orderCancelReasons: ['客户取消', '库存不足'],
|
||||
paymentMethods: [
|
||||
{ value: 'cash', label: '现金' },
|
||||
{ value: 'transfer', label: '转账' }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchAttachmentDownloadUrl(_data: { fileUrl: string; fileName?: string }) {
|
||||
await delay()
|
||||
return { downloadUrl: '#' }
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/** Demo 模板页本地种子数据(无后端依赖) */
|
||||
|
||||
export const demoUnits: Api.ItemUnit.ItemUnitItem[] = [
|
||||
{
|
||||
id: 'demo-unit-1',
|
||||
unitCode: 'KG',
|
||||
unitName: '千克',
|
||||
tenantNo: 'demo',
|
||||
orderNum: 1,
|
||||
remark: 'Demo 示例',
|
||||
createTime: '2026-01-01 10:00:00',
|
||||
updateTime: '2026-01-01 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-unit-2',
|
||||
unitCode: 'TON',
|
||||
unitName: '吨',
|
||||
tenantNo: 'demo',
|
||||
orderNum: 2,
|
||||
remark: '',
|
||||
createTime: '2026-01-02 10:00:00',
|
||||
updateTime: '2026-01-02 10:00:00'
|
||||
}
|
||||
]
|
||||
|
||||
export const demoCategories: Api.Category.CategoryItem[] = [
|
||||
{
|
||||
id: 'demo-cat-1',
|
||||
name: '化工原料',
|
||||
parentId: '0',
|
||||
sortOrder: 1,
|
||||
isActive: true,
|
||||
imageUrl: '',
|
||||
createAt: '2026-01-01 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-cat-2',
|
||||
name: '树脂类',
|
||||
parentId: 'demo-cat-1',
|
||||
sortOrder: 1,
|
||||
isActive: true,
|
||||
imageUrl: '',
|
||||
createAt: '2026-01-01 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-cat-3',
|
||||
name: '溶剂类',
|
||||
parentId: 'demo-cat-1',
|
||||
sortOrder: 2,
|
||||
isActive: true,
|
||||
imageUrl: '',
|
||||
createAt: '2026-01-01 10:00:00'
|
||||
}
|
||||
]
|
||||
|
||||
export const demoProducts: Api.Product.ProductItem[] = [
|
||||
{
|
||||
id: 'demo-prod-1',
|
||||
name: '环氧树脂 E-51',
|
||||
categoryId: 'demo-cat-2',
|
||||
categoryName: '树脂类',
|
||||
unitId: 'demo-unit-1',
|
||||
unitName: '千克',
|
||||
description: 'Demo 商品示例',
|
||||
imageUrl: '',
|
||||
isActive: true,
|
||||
createAt: '2026-01-03 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-prod-2',
|
||||
name: '丙酮',
|
||||
categoryId: 'demo-cat-3',
|
||||
categoryName: '溶剂类',
|
||||
unitId: 'demo-unit-2',
|
||||
unitName: '吨',
|
||||
description: '',
|
||||
imageUrl: '',
|
||||
isActive: true,
|
||||
createAt: '2026-01-04 10:00:00'
|
||||
}
|
||||
]
|
||||
|
||||
export const demoOrders: Api.Order.OrderItem[] = [
|
||||
{
|
||||
id: 'demo-order-1',
|
||||
orderNo: 'DD202601001',
|
||||
clientId: 'demo-client-1',
|
||||
clientName: '示例客户 A',
|
||||
regionId: 'demo-region-1',
|
||||
regionName: '华东区',
|
||||
priceListId: 'demo-price-1',
|
||||
totalAmount: '12800.00',
|
||||
paidAmount: '12800.00',
|
||||
receivableAmount: '0.00',
|
||||
refundAmount: '0.00',
|
||||
status: 'completed',
|
||||
paymentMethod: 'transfer',
|
||||
contactPerson: '张三',
|
||||
contactPhone: '13800000001',
|
||||
deliveryAddress: '浙江省杭州市示例路 1 号',
|
||||
createAt: '2026-01-10 09:30:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-order-2',
|
||||
orderNo: 'DD202601002',
|
||||
clientId: 'demo-client-2',
|
||||
clientName: '示例客户 B',
|
||||
regionId: 'demo-region-2',
|
||||
regionName: '华南区',
|
||||
priceListId: 'demo-price-1',
|
||||
totalAmount: '5600.00',
|
||||
paidAmount: '0.00',
|
||||
receivableAmount: '5600.00',
|
||||
refundAmount: '0.00',
|
||||
status: 'pending_payment',
|
||||
paymentMethod: 'cash',
|
||||
contactPerson: '李四',
|
||||
contactPhone: '13800000002',
|
||||
deliveryAddress: '广东省广州市示例路 2 号',
|
||||
createAt: '2026-01-11 14:20:00'
|
||||
}
|
||||
]
|
||||
|
||||
export const demoRegions: Api.Region.RegionItem[] = [
|
||||
{
|
||||
id: 'demo-region-1',
|
||||
name: '华东区',
|
||||
code: 'EAST',
|
||||
isActive: true,
|
||||
sortOrder: 1,
|
||||
createAt: '2026-01-01 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 'demo-region-2',
|
||||
name: '华南区',
|
||||
code: 'SOUTH',
|
||||
isActive: true,
|
||||
sortOrder: 2,
|
||||
createAt: '2026-01-01 10:00:00'
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user