From 907df04070010db277d3fcf27e053a851db543c3 Mon Sep 17 00:00:00 2001 From: liufumingren Date: Fri, 30 Oct 2026 23:06:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E5=95=86=E5=93=81=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E3=80=81=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81=E4=B8=8E?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E4=BB=BB=E5=8A=A1=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增商品属性页(分类/品牌/单位)与商品表单的品牌/单位选择 - 新增订单状态页:状态分视图列表、新建/编辑弹窗、明细维护、审核/驳回/取消/作废/恢复/推送仓库等操作 - 导出任务按类型动态渲染筛选表单与任务进度;导出按钮/筛选组件抽为公共组件 - 旧地址 order-split / order-create / order-delivery 重定向到 /order,导航与多标签页适配新页面 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- frontend/index.html | 33 +- frontend/package-lock.json | 16 + frontend/src/App.vue | 7 + frontend/src/api/exportTask.ts | 57 +- frontend/src/api/orderStatus.ts | 396 ++++++++ frontend/src/api/product.ts | 4 + frontend/src/api/productBrand.ts | 57 ++ frontend/src/api/productCategory.ts | 57 ++ frontend/src/api/productUnit.ts | 57 ++ frontend/src/components/ExportButton.vue | 47 + frontend/src/components/ExportFilterField.vue | 152 +++ frontend/src/composables/useExportTasks.ts | 109 +++ frontend/src/layouts/BasicLayout.vue | 13 +- frontend/src/main.ts | 31 +- frontend/src/router/index.ts | 15 +- frontend/src/store/menu.ts | 4 +- frontend/src/store/tabs.ts | 37 +- frontend/src/views/ComboProduct/Index.vue | 14 +- frontend/src/views/ExportTask/Index.vue | 275 ++---- frontend/src/views/ExternalApi/Index.vue | 54 +- frontend/src/views/InboundOrder/Index.vue | 13 +- frontend/src/views/Order/OrderFormDialog.vue | 876 +++++++++++++++++ frontend/src/views/Order/Status.vue | 63 ++ frontend/src/views/Order/StatusPanel.vue | 925 ++++++++++++++++++ frontend/src/views/OutboundOrder/Index.vue | 13 +- frontend/src/views/Principal/Index.vue | 13 +- frontend/src/views/PrincipalUser/Index.vue | 12 +- frontend/src/views/Product/Index.vue | 256 ++++- frontend/src/views/ProductAttribute/Index.vue | 51 + .../ProductAttributePanel.vue | 350 +++++++ frontend/src/views/Shop/Index.vue | 15 +- frontend/src/views/ShopProduct/Index.vue | 12 + frontend/src/views/StockRecord/Index.vue | 20 +- 33 files changed, 3757 insertions(+), 297 deletions(-) create mode 100644 frontend/src/api/orderStatus.ts create mode 100644 frontend/src/api/productBrand.ts create mode 100644 frontend/src/api/productCategory.ts create mode 100644 frontend/src/api/productUnit.ts create mode 100644 frontend/src/components/ExportButton.vue create mode 100644 frontend/src/components/ExportFilterField.vue create mode 100644 frontend/src/composables/useExportTasks.ts create mode 100644 frontend/src/views/Order/OrderFormDialog.vue create mode 100644 frontend/src/views/Order/Status.vue create mode 100644 frontend/src/views/Order/StatusPanel.vue create mode 100644 frontend/src/views/ProductAttribute/Index.vue create mode 100644 frontend/src/views/ProductAttribute/ProductAttributePanel.vue diff --git a/frontend/index.html b/frontend/index.html index 2a42c88..90b37fa 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -6,7 +6,38 @@ OMS 管理系统 -
+
+ +
+ + 正在加载… +
+
+ diff --git a/frontend/package-lock.json b/frontend/package-lock.json index a89d7e0..11a9459 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@element-plus/icons-vue": "^2.3.1", "axios": "^1.20.0", + "element-china-area-data": "^6.1.0", "element-plus": "^2.9.1", "pinia": "^2.3.1", "vue": "^3.5.13", @@ -1270,6 +1271,12 @@ "node": ">= 0.4" } }, + "node_modules/china-division": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/china-division/-/china-division-2.7.0.tgz", + "integrity": "sha512-4uUPAT+1WfqDh5jytq7omdCmHNk3j+k76zEG/2IqaGcYB90c2SwcixttcypdsZ3T/9tN1TTpBDoeZn+Yw/qBEA==", + "license": "MIT" + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -1341,6 +1348,15 @@ "node": ">= 0.4" } }, + "node_modules/element-china-area-data": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/element-china-area-data/-/element-china-area-data-6.1.0.tgz", + "integrity": "sha512-IkpcjwQv2A/2AxFiSoaISZ+oMw1rZCPUSOg5sOCwT5jKc96TaawmKZeY81xfxXsO0QbKxU5LLc6AirhG52hUmg==", + "license": "MIT", + "dependencies": { + "china-division": "^2.7.0" + } + }, "node_modules/element-plus": { "version": "2.14.5", "resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.14.5.tgz", diff --git a/frontend/src/App.vue b/frontend/src/App.vue index d09dd9a..792e6d6 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -29,6 +29,13 @@ body, padding: 10px; } +/* 页面标题行的右侧操作按钮组(如「新增 + 导出」) */ +.header-actions { + display: flex; + align-items: center; + gap: 8px; +} + /* 卡片:头部与内容 */ .el-card__header { padding: 10px 12px; diff --git a/frontend/src/api/exportTask.ts b/frontend/src/api/exportTask.ts index 41fe9aa..f736053 100644 --- a/frontend/src/api/exportTask.ts +++ b/frontend/src/api/exportTask.ts @@ -1,16 +1,45 @@ import { get, post } from '@/utils/request' import request from '@/utils/request' -/** 导出类型:出入库记录 / 商品 / 订单 */ -export type ExportType = 'stock_record' | 'product' | 'order' +/** + * 导出类型:由后端注册表定义(见 backend/app/utils/exportDefs.js#EXPORT_TYPES), + * 前端不做枚举收窄,新增类型时后端改一处即可 + */ +export type ExportType = string + +/** 筛选字段控件类型:文本 / 下拉 / 日期 / 数字 / 商品选择器 / 店铺选择器 / 仓库选择器 */ +export type ExportFilterType = + | 'text' + | 'select' + | 'date' + | 'number' + | 'product' + | 'shop' + | 'warehouse' + +/** 筛选字段下拉选项 */ +export interface ExportFilterOption { + label: string + value: string | number +} + +/** 筛选字段定义(后端随导出类型一起下发,前端据此动态渲染提交表单) */ +export interface ExportFilterDef { + key: string + label: string + type: ExportFilterType + options?: ExportFilterOption[] + placeholder?: string +} /** 导出任务状态:0待处理 1处理中 2已完成 3失败 */ export type ExportStatus = 0 | 1 | 2 | 3 -/** 导出类型选项(后端返回) */ +/** 导出类型选项(后端返回,含该类型可传的筛选字段定义) */ export interface ExportTypeOption { value: ExportType label: string + filters: ExportFilterDef[] } /** 导出任务项 */ @@ -31,26 +60,10 @@ export interface ExportTaskItem { created_at: string } -/** 导出筛选条件(按类型可选字段) */ -export interface ExportFilters { - product_id?: number | null - warehouse_id?: number | null - biz_type?: string - direction?: number | string - bill_type?: number | string - item_type?: string - bill_no?: string - keyword?: string - category_name?: string - status?: number | string - submit_status?: number | string - shop_id?: number | null - start_time?: string - end_time?: string - [key: string]: unknown -} +/** 导出筛选条件(按类型可选,字段集合见后端下发的 ExportFilterDef[]) */ +export type ExportFilters = Record -/** 导出类型选项 */ +/** 导出类型选项(含筛选字段定义) */ export function getExportTypes() { return get('/export-tasks/types') } diff --git a/frontend/src/api/orderStatus.ts b/frontend/src/api/orderStatus.ts new file mode 100644 index 0000000..5442c67 --- /dev/null +++ b/frontend/src/api/orderStatus.ts @@ -0,0 +1,396 @@ +import { get, post, put, del } from '@/utils/request' + +/** + * 订单(状态分表) + * + * 订单按状态分表存储,状态同时代表「所在表」: + * pending 待审核 / queued 待推送 / exception 异常 / outsourcing 委外中 / delivery 配送 + * / void 已作废 / canceled 已取消 / history 历史(归档表)。 + * 流转:待审核 →(审核+锁库存)待推送 →(推送仓库成功)委外中 →(仓库回传确认)配送;推送失败 → 异常。 + * 列表按状态分视图(左侧 tab),状态流转由后端业务事务推动,前端只提交动作。 + */ +export type OrderStage = + | 'pending' + | 'queued' + | 'exception' + | 'outsourcing' + | 'delivery' + | 'void' + | 'canceled' + | 'history' + +/** 页面左侧 tab(顺序即状态流转顺序) */ +export const ORDER_STAGE_TABS: { key: OrderStage; label: string }[] = [ + { key: 'pending', label: '待审核' }, + { key: 'queued', label: '待推送' }, + { key: 'exception', label: '异常' }, + { key: 'outsourcing', label: '委外中' }, + { key: 'delivery', label: '配送' }, + { key: 'void', label: '已作废' }, + { key: 'canceled', label: '已取消' }, + { key: 'history', label: '历史' }, +] + +/** 状态展示口径(文案与颜色,与后端 app/lib/orderStatus.js 对齐) */ +export const ORDER_STAGE_META: Record< + OrderStage, + { label: string; tag: '' | 'info' | 'warning' | 'success' | 'danger' } +> = { + pending: { label: '待审核', tag: 'warning' }, + queued: { label: '待推送', tag: '' }, + exception: { label: '异常', tag: 'danger' }, + outsourcing: { label: '委外中', tag: '' }, + delivery: { label: '配送', tag: 'success' }, + void: { label: '已作废', tag: 'info' }, + canceled: { label: '已取消', tag: 'info' }, + history: { label: '历史', tag: 'info' }, +} + +/** 商品明细行(product_info JSON 元素,列表摘要用) */ +export interface OrderProductLine { + item_code: string | null + item_name: string | null + quantity: number | null + price: number | null +} + +/** 商品明细(order_status_items:发货单明细与平台明细的超集) */ +export interface OrderItemLine { + id?: number + order_id?: number + order_line_no?: string + item_id?: number | null + item_code?: string | null + item_name?: string | null + plan_qty: number + actual_price?: number | null + retail_price?: number | null + ext_code?: string | null + inventory_type?: string + source_order_code?: string | null + sub_source_order_code?: string | null + stock_id?: number | null + product_id?: number | null + sku_code?: string | null + spec?: string | null + image?: string | null + created_at?: string + updated_at?: string +} + +export interface OrderStatusItem { + id: number + principal_id: number + order_no: string + parent_order_no: string | null + shop_id: number | null + shop_name?: string | null + warehouse_id?: number | null + warehouse_code?: string | null + warehouse_name?: string | null + product_info: OrderProductLine[] | null + product_summary?: string + product_kind?: number + receiver: string | null + address: string | null + status: OrderStage + status_label?: string + remark: string | null + /** —— 老发货单口径字段(为容纳老表而扩展) —— */ + order_type?: string | null + is_urgency?: string | null + invoice_flag?: string | null + shop_nick?: string | null + buyer_message?: string | null + seller_message?: string | null + total_amount?: number | string | null + item_amount?: number | string | null + discount_amount?: number | string | null + freight?: number | string | null + ar_amount?: number | string | null + got_amount?: number | string | null + logistics_code?: string | null + logistics_name?: string | null + express_code?: string | null + express_codes?: string[] | null + logistics_area_code?: string | null + operator_name?: string | null + tel?: string | null + mobile?: string | null + email?: string | null + country_code?: string | null + province?: string | null + city?: string | null + area?: string | null + town?: string | null + detail_address?: string | null + zip_code?: string | null + oaid?: string | null + stock_locked?: number | null + wms_status?: string | null + wms_order_no?: string | null + wms_synced_at?: string | null + pushed_at?: string | null + wms_push_result?: Record | null + legacy_source?: string | null + legacy_order_id?: number | null + legacy_status?: number | null + item_total?: number | string | null + item_kind?: number | null + audit_by?: number | null + audit_time?: string | null + void_at?: string | null + void_by?: number | null + void_reason?: string | null + /** 索引表记录的当前所在表 */ + current_table?: OrderStage + created_at?: string + updated_at?: string + /** 仅历史视图 */ + archived_at?: string | null + transferred_at?: string | null +} + +export interface OrderStatusQuery { + status: OrderStage + page: number + pageSize: number + order_no?: string + parent_order_no?: string + shop_id?: number | '' + receiver?: string + address?: string + remark?: string + created_from?: string + created_to?: string + archived_from?: string + archived_to?: string +} + +export interface OrderStatusFilters { + statuses: { value: OrderStage; label: string }[] + status_labels: Record + active_statuses: OrderStage[] + /** 超期自动归档阈值(月) */ + archive_months: number + /** 订单索引表名 */ + index_table?: string + shops: { id: number; name: string }[] + warehouses: { id: number; code: string; name: string }[] +} + +/** 新建/编辑订单(发货单口径) */ +export interface OrderStatusPayload { + /** 来源订单号(上游/平台订单号;与 order_no 至少传一个) */ + parent_order_no?: string + order_no?: string + shop_id?: number | null + warehouse_id?: number | null + order_type?: string + receiver?: string + tel?: string + mobile?: string + email?: string + country_code?: string + province?: string + city?: string + area?: string + town?: string + detail_address?: string + zip_code?: string + address?: string + oaid?: string + is_urgency?: string + invoice_flag?: string + total_amount?: number | null + item_amount?: number | null + discount_amount?: number | null + freight?: number | null + ar_amount?: number | null + got_amount?: number | null + logistics_code?: string + logistics_name?: string + seller_message?: string + buyer_message?: string + remark?: string + product_info?: OrderProductLine[] + /** 商品明细(发货单口径;与 product_info 二选一) */ + items?: OrderItemLine[] +} + +/** 流转结果(审核 / 推送 / 转回待审核 / 取消 / 作废 / 按 id 归档) */ +export interface OrderStatusTransitionResult { + count: number + status: OrderStage + status_label: string + order_nos: string[] + /** 单条审核:本次锁定库存的明细行数 */ + stock_locked?: number + /** 批量审核:失败明细 */ + failed?: number + failures?: { id: number; message: string }[] +} + +/** 单据级流转结果(驳回 / 恢复:可能换号) */ +export interface OrderStatusSingleFlowResult { + count: number + status: OrderStage + status_label: string + items: { id: number; order_no: string; bill_no_changed: boolean }[] +} + +/** 推送仓库结果 */ +export interface OrderPushWmsResult { + id: number + attempts: number + wms_response?: Record +} + +export interface OrderPushWmsBatchResult { + requested: number + processed: number + pendingRest: number + pushed: number + failed: number + retry: number + skipped: number + details: { id: number; ok: boolean; message: string }[] +} + +/** 归档结果(不传 ids 时按创建时间超期批量归档) */ +export interface OrderStatusArchiveResult { + count: number + status?: OrderStage + status_label?: string + order_nos?: string[] + months?: number + threshold?: string + by_status?: Record +} + +/** 订单列表(按 status 定位状态表;principal_id 由请求拦截器注入) */ +export function getOrderStatusList(params: OrderStatusQuery) { + return get<{ list: OrderStatusItem[]; total: number; page: number; pageSize: number }>( + '/order-status/list', + params as unknown as object, + ) +} + +/** 筛选项数据源:状态枚举 + 当前主体下的店铺/仓库 + 归档阈值 */ +export function getOrderStatusFilters() { + return get('/order-status/filters') +} + +/** 订单详情(单据头 + 商品明细) */ +export function getOrderStatusDetail(id: number) { + return get<{ order: OrderStatusItem; items: OrderItemLine[] }>(`/order-status/${id}`) +} + +/** 新建订单 / 发货单(写入索引表 + 待审核表;带 items 时同时写入明细) */ +export function createOrderStatus(data: OrderStatusPayload) { + return post<{ + id: number + order_no: string + status: OrderStage + status_label: string + item_count: number + }>('/order-status', data) +} + +/** 编辑订单(仅待审核 / 异常;未传字段保持原值) */ +export function updateOrderStatus(id: number, data: OrderStatusPayload) { + return put<{ id: number; order_no: string }>(`/order-status/${id}`, data) +} + +/** 删除订单(仅待审核 / 异常 / 已取消) */ +export function removeOrderStatus(id: number) { + return del<{ count: number; order_nos: string[] }>(`/order-status/${id}`) +} + +/** 商品明细(按订单ID) */ +export function getOrderItems(orderId: number) { + return get<{ list: OrderItemLine[]; total: number }>('/order-status/items', { order_id: orderId }) +} + +/** 保存商品明细(整体替换,仅待审核 / 异常) */ +export function saveOrderItems(orderId: number, items: OrderItemLine[]) { + return post<{ list: OrderItemLine[]; total: number }>('/order-status/items', { + order_id: orderId, + items, + }) +} + +/** 收件人文本智能识别 */ +export function parseReceiverText(text: string) { + return post>('/order-status/parse-receiver', { text }) +} + +/** 批量审核:待审核 / 异常 → 委外中 */ +export function auditOrders(ids: number[]) { + return post('/order-status/audit', { ids }) +} + +/** 批量推送外部:outcome=success 成功回传(→ 配送)/ failed 推送失败(→ 异常,remark 记录原因) */ +export function pushOrders(ids: number[], outcome: 'success' | 'failed', remark?: string) { + return post('/order-status/push', { ids, outcome, remark }) +} + +/** 异常批量转回待审核 */ +export function returnOrdersToPending(ids: number[]) { + return post('/order-status/return-to-pending', { ids }) +} + +/** 归档:传 ids 归档指定订单;不传则归档创建时间超过 months(默认 3)个月的订单 */ +export function archiveOrders(data: { ids?: number[]; months?: number }) { + return post('/order-status/archive', data) +} + +/** 驳回(委外中 → 待审核;换号 + 释放锁定库存) */ +export function rejectOrders(ids: number[]) { + return post('/order-status/reject', { ids }) +} + +/** 取消(待审核 / 异常 / 委外中 → 已取消;已推送的会先取消外部单据) */ +export function cancelOrders(ids: number[], remark?: string) { + return post('/order-status/cancel', { ids, remark }) +} + +/** 作废(待审核 / 异常 / 委外中 → 已作废;记录作废原因并释放锁定库存) */ +export function voidOrders(ids: number[], voidReason?: string, remark?: string) { + return post('/order-status/void', { + ids, + void_reason: voidReason, + remark, + }) +} + +/** 恢复(已取消 / 已作废 → 待审核;曾推送过的自动换号) */ +export function restoreOrders(ids: number[]) { + return post('/order-status/restore', { ids }) +} + +/** 推送仓库(WMS deliveryorder.create):单条立即推送 */ +export function pushOrderToWms(id: number) { + return post(`/order-status/${id}/push-wms`, {}) +} + +/** 推送仓库:批量(顺序限流,超出部分交给定时任务) */ +export function pushOrdersToWms(ids: number[]) { + return post('/order-status/push-wms', { ids }) +} + +/** 批量切换发货仓库(同步刷新 warehouse_code 快照) */ +export function changeOrdersWarehouse(ids: number[], warehouseId: number) { + return post<{ updated: number; target: { id: number; code: string; name: string } }>( + '/order-status/change-warehouse', + { ids, warehouse_id: warehouseId }, + ) +} + +/** 批量设置所属店铺(同步刷新 shop_nick 快照) */ +export function changeOrdersShop(ids: number[], shopId: number) { + return post<{ updated: number; target: { id: number; name: string } }>('/order-status/change-shop', { + ids, + shop_id: shopId, + }) +} diff --git a/frontend/src/api/product.ts b/frontend/src/api/product.ts index 41203e7..fc4a563 100644 --- a/frontend/src/api/product.ts +++ b/frontend/src/api/product.ts @@ -17,7 +17,9 @@ export interface ProductItem { item_type: number category_id: number | null category_name: string | null + brand_id: number | null brand_name: string | null + unit_id: number | null length: number | string | null // 长度,单位 cm width: number | string | null // 宽度,单位 cm height: number | string | null // 高度,单位 cm @@ -64,7 +66,9 @@ export interface ProductPayload { item_type?: number category_id?: number | null category_name?: string + brand_id?: number | null brand_name?: string + unit_id?: number | null sku_property?: string stock_unit?: string length?: number | null // 长度,单位 cm diff --git a/frontend/src/api/productBrand.ts b/frontend/src/api/productBrand.ts new file mode 100644 index 0000000..aa34f42 --- /dev/null +++ b/frontend/src/api/productBrand.ts @@ -0,0 +1,57 @@ +import { get, post, put, del } from '@/utils/request' + +/** 商品品牌(按主体隔离) */ +export interface ProductBrand { + id: number + principal_id: number + name: string + code: string | null + status: number + sort: number + remark: string | null + /** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */ + is_system?: number + /** 被商品使用次数(被引用时禁止删除) */ + used_count?: number + created_at?: string + updated_at?: string +} + +/** 下拉项(仅启用) */ +export interface ProductAttributeOption { + id: number + name: string + code: string | null +} + +export interface ProductBrandPayload { + name: string + code?: string | null + status?: number + sort?: number + remark?: string | null +} + +export function getProductBrands(params?: object) { + return get<{ list: ProductBrand[]; total: number; page: number; pageSize: number }>( + '/product-brands', + params, + ) +} + +/** 下拉用:仅返回启用商品品牌(按 sort 升序) */ +export function getProductBrandOptions() { + return get('/product-brands/select') +} + +export function createProductBrand(data: ProductBrandPayload) { + return post<{ id: number }>('/product-brands', data) +} + +export function updateProductBrand(id: number, data: Partial) { + return put<{ id: number }>(`/product-brands/${id}`, data) +} + +export function deleteProductBrand(id: number) { + return del<{ id: number }>(`/product-brands/${id}`) +} diff --git a/frontend/src/api/productCategory.ts b/frontend/src/api/productCategory.ts new file mode 100644 index 0000000..87121c2 --- /dev/null +++ b/frontend/src/api/productCategory.ts @@ -0,0 +1,57 @@ +import { get, post, put, del } from '@/utils/request' + +/** 商品分类(按主体隔离) */ +export interface ProductCategory { + id: number + principal_id: number + name: string + code: string | null + status: number + sort: number + remark: string | null + /** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */ + is_system?: number + /** 被商品使用次数(被引用时禁止删除) */ + used_count?: number + created_at?: string + updated_at?: string +} + +/** 下拉项(仅启用) */ +export interface ProductAttributeOption { + id: number + name: string + code: string | null +} + +export interface ProductCategoryPayload { + name: string + code?: string | null + status?: number + sort?: number + remark?: string | null +} + +export function getProductCategories(params?: object) { + return get<{ list: ProductCategory[]; total: number; page: number; pageSize: number }>( + '/product-categories', + params, + ) +} + +/** 下拉用:仅返回启用商品分类(按 sort 升序) */ +export function getProductCategoryOptions() { + return get('/product-categories/select') +} + +export function createProductCategory(data: ProductCategoryPayload) { + return post<{ id: number }>('/product-categories', data) +} + +export function updateProductCategory(id: number, data: Partial) { + return put<{ id: number }>(`/product-categories/${id}`, data) +} + +export function deleteProductCategory(id: number) { + return del<{ id: number }>(`/product-categories/${id}`) +} diff --git a/frontend/src/api/productUnit.ts b/frontend/src/api/productUnit.ts new file mode 100644 index 0000000..aa0797b --- /dev/null +++ b/frontend/src/api/productUnit.ts @@ -0,0 +1,57 @@ +import { get, post, put, del } from '@/utils/request' + +/** 商品单位(按主体隔离) */ +export interface ProductUnit { + id: number + principal_id: number + name: string + code: string | null + status: number + sort: number + remark: string | null + /** 是否系统默认:1系统数据(不可改/删,全部主体可见) 0自定义(按主体隔离) */ + is_system?: number + /** 被商品使用次数(被引用时禁止删除) */ + used_count?: number + created_at?: string + updated_at?: string +} + +/** 下拉项(仅启用) */ +export interface ProductAttributeOption { + id: number + name: string + code: string | null +} + +export interface ProductUnitPayload { + name: string + code?: string | null + status?: number + sort?: number + remark?: string | null +} + +export function getProductUnits(params?: object) { + return get<{ list: ProductUnit[]; total: number; page: number; pageSize: number }>( + '/product-units', + params, + ) +} + +/** 下拉用:仅返回启用商品单位(按 sort 升序) */ +export function getProductUnitOptions() { + return get('/product-units/select') +} + +export function createProductUnit(data: ProductUnitPayload) { + return post<{ id: number }>('/product-units', data) +} + +export function updateProductUnit(id: number, data: Partial) { + return put<{ id: number }>(`/product-units/${id}`, data) +} + +export function deleteProductUnit(id: number) { + return del<{ id: number }>(`/product-units/${id}`) +} diff --git a/frontend/src/components/ExportButton.vue b/frontend/src/components/ExportButton.vue new file mode 100644 index 0000000..7ba39cc --- /dev/null +++ b/frontend/src/components/ExportButton.vue @@ -0,0 +1,47 @@ + + + diff --git a/frontend/src/components/ExportFilterField.vue b/frontend/src/components/ExportFilterField.vue new file mode 100644 index 0000000..2edd0ca --- /dev/null +++ b/frontend/src/components/ExportFilterField.vue @@ -0,0 +1,152 @@ + + + + + diff --git a/frontend/src/composables/useExportTasks.ts b/frontend/src/composables/useExportTasks.ts new file mode 100644 index 0000000..b0ff75c --- /dev/null +++ b/frontend/src/composables/useExportTasks.ts @@ -0,0 +1,109 @@ +import { computed, ref } from 'vue' +import { ElMessage } from 'element-plus' +import { + downloadExport, + getExportTask, + submitExport, + type ExportFilters, + type ExportType, +} from '@/api/exportTask' + +/** + * 导出任务提交与自动下载(全局单例) + * + * 任意页面提交导出后立即返回任务ID,本模块在后台轮询任务进度,完成后自动触发浏览器下载并提示; + * 失败时提示原因。导出任务页的列表只负责展示进度,不再重复下载(避免下载两次)。 + */ + +/** 轮询间隔(毫秒) */ +const POLL_INTERVAL = 2000 + +/** 待下载的任务ID(有值即代表轮询进行中) */ +const pendingIds = ref([]) +let timer: number | null = null + +/** + * 触发浏览器下载导出文件 + * @param id 任务ID + * @param fileName 文件名(后端返回,缺省按任务ID命名) + */ +export async function downloadExportFile(id: number, fileName?: string | null) { + const blob = await downloadExport(id) + const url = window.URL.createObjectURL(blob) + const link = document.createElement('a') + link.href = url + link.download = fileName || `export_${id}.xlsx` + document.body.appendChild(link) + link.click() + document.body.removeChild(link) + window.URL.revokeObjectURL(url) +} + +function removePending(id: number) { + pendingIds.value = pendingIds.value.filter(item => item !== id) +} + +/** 轮询一轮:完成的自动下载,失败的提示原因,未完成的留到下一轮 */ +async function pollOnce() { + for (const id of [ ...pendingIds.value ]) { + try { + const task = await getExportTask(id) + if (task.status === 2) { + removePending(id) + await downloadExportFile(task.id, task.file_name) + ElMessage.success(`导出完成(${task.type_label || task.type},共 ${task.total_count} 行),已开始下载`) + } else if (task.status === 3) { + removePending(id) + ElMessage.error(`导出失败:${task.error_message || '未知原因'}`) + } + } catch { + // 单次查询失败(如网络抖动)不打断轮询,下一轮重试 + } + } + if (!pendingIds.value.length) stopPolling() +} + +function startPolling() { + if (timer != null) return + timer = window.setInterval(() => { pollOnce().catch(() => {}) }, POLL_INTERVAL) + pollOnce().catch(() => {}) +} + +function stopPolling() { + if (timer != null) { + window.clearInterval(timer) + timer = null + } +} + +/** + * 导出任务提交(组合式函数) + * @return {Object} submitting 提交中标记 / submit 提交方法 / pendingCount 待下载任务数 + */ +export function useExportTasks() { + const submitting = ref(false) + + /** + * 提交导出任务 + * @param type 导出类型(后端注册表 key) + * @param filters 筛选条件(字段需在该类型声明内,多余字段后端会丢弃) + */ + async function submit(type: ExportType, filters: ExportFilters = {}) { + submitting.value = true + try { + const res = await submitExport({ type, filters }) + pendingIds.value = [ ...pendingIds.value, res.id ] + startPolling() + ElMessage.success('已提交导出任务,处理完成后将自动下载(可在顶栏「导出任务」查看进度)') + return res + } finally { + submitting.value = false + } + } + + return { + submitting, + submit, + pendingCount: computed(() => pendingIds.value.length), + } +} diff --git a/frontend/src/layouts/BasicLayout.vue b/frontend/src/layouts/BasicLayout.vue index cec625b..c313794 100644 --- a/frontend/src/layouts/BasicLayout.vue +++ b/frontend/src/layouts/BasicLayout.vue @@ -48,6 +48,11 @@ const visibleTabs = computed(() => { return slice }) +// 「更多」下拉里只展示被收起(未渲染在标签条上)的标签 +const hiddenTabs = computed(() => + tabs.tabs.filter((t) => !visibleTabs.value.some((v) => v.key === t.key)), +) + function estimateWidth(t: { key: string; title: string; affix: boolean }): number { const cached = tabWidths.get(t.key) if (cached) return cached @@ -178,12 +183,12 @@ function onPrincipalChange(id: number) { :closable="!tab.affix" /> - + 更多 @@ -463,4 +683,16 @@ onMounted(fetchList) gap: 8px; width: 100%; } +.select-with-add { + display: flex; + gap: 8px; + width: 100%; +} +.select-with-add .el-button { + flex: 0 0 auto; + padding-left: 12px; + padding-right: 12px; + font-size: 16px; + line-height: 1; +} diff --git a/frontend/src/views/ProductAttribute/Index.vue b/frontend/src/views/ProductAttribute/Index.vue new file mode 100644 index 0000000..370ba8d --- /dev/null +++ b/frontend/src/views/ProductAttribute/Index.vue @@ -0,0 +1,51 @@ + + + + + diff --git a/frontend/src/views/ProductAttribute/ProductAttributePanel.vue b/frontend/src/views/ProductAttribute/ProductAttributePanel.vue new file mode 100644 index 0000000..46e32b1 --- /dev/null +++ b/frontend/src/views/ProductAttribute/ProductAttributePanel.vue @@ -0,0 +1,350 @@ + + + + + diff --git a/frontend/src/views/Shop/Index.vue b/frontend/src/views/Shop/Index.vue index 58ae67f..3167f96 100644 --- a/frontend/src/views/Shop/Index.vue +++ b/frontend/src/views/Shop/Index.vue @@ -1,5 +1,5 @@