feat(frontend): 初始化 Vue3 + Vite 前端工程与业务页面
- 工程脚手架:Vite、TypeScript 配置、路由、Pinia store(auth/principal/menu)、请求封装 - 布局与通用组件:BasicLayout、SideMenu、DataTable/VirtualTable、VirtualSelect、ProductSelect、ImageUploader 等 - 业务页面:登录、首页、商品、店铺、店铺商品、组合商品、仓库/接口配置、库存、入库单、出库单、发货单(列表 + 创建)、外部接口、主体/主体用户、个人资料 - API 层:api/*.ts 与后端接口一一对应
This commit is contained in:
parent
0a9ee3c593
commit
a51cb4df15
21
frontend/.gitignore
vendored
Normal file
21
frontend/.gitignore
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
# Logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependencies
|
||||
node_modules
|
||||
|
||||
# Build output
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor / OS
|
||||
.DS_Store
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
7
frontend/env.d.ts
vendored
Normal file
7
frontend/env.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<Record<string, unknown>, Record<string, unknown>, unknown>
|
||||
export default component
|
||||
}
|
||||
12
frontend/index.html
Normal file
12
frontend/index.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>OMS 管理系统</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
2131
frontend/package-lock.json
generated
Normal file
2131
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
26
frontend/package.json
Normal file
26
frontend/package.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "oms-frontend",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc --noEmit && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
"axios": "^1.20.0",
|
||||
"element-plus": "^2.9.1",
|
||||
"pinia": "^2.3.1",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.10.2",
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"typescript": "~5.7.2",
|
||||
"vite": "^6.0.5",
|
||||
"vue-tsc": "^2.2.0"
|
||||
}
|
||||
}
|
||||
16
frontend/src/App.vue
Normal file
16
frontend/src/App.vue
Normal file
@ -0,0 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterView } from 'vue-router'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterView />
|
||||
</template>
|
||||
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
70
frontend/src/api/auth.ts
Normal file
70
frontend/src/api/auth.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { post, get } from '@/utils/request'
|
||||
|
||||
export interface LoginResult {
|
||||
token: string
|
||||
user_id: number
|
||||
expires_in: number
|
||||
}
|
||||
|
||||
export interface UserInfo {
|
||||
id: number
|
||||
username: string
|
||||
nickname: string | null
|
||||
email: string | null
|
||||
phone: string | null
|
||||
avatar: string | null
|
||||
status: number
|
||||
last_login_at: string | null
|
||||
created_at: string
|
||||
updated_at: string
|
||||
principals?: { id: number; name: string }[]
|
||||
}
|
||||
|
||||
export interface RegisterPayload {
|
||||
username: string
|
||||
password: string
|
||||
email: string
|
||||
code: string
|
||||
nickname?: string
|
||||
phone?: string
|
||||
}
|
||||
|
||||
/** 账号密码登录(account 支持用户名或邮箱) */
|
||||
export function login(data: { account: string; password: string }) {
|
||||
return post<LoginResult>('/auth/login', data)
|
||||
}
|
||||
|
||||
/** 发送邮箱验证码(注册前置步骤) */
|
||||
export function sendEmailCode(data: { email: string }) {
|
||||
return post<{ email: string; expires_in: number }>('/auth/email-code', data)
|
||||
}
|
||||
|
||||
/** 注册账号,成功后直接返回 token */
|
||||
export function register(data: RegisterPayload) {
|
||||
return post<LoginResult>('/auth/register', data)
|
||||
}
|
||||
|
||||
/** 获取当前登录用户信息 */
|
||||
export function getProfile() {
|
||||
return get<UserInfo>('/auth/profile')
|
||||
}
|
||||
|
||||
/** 发送邮箱登录验证码(6 位数字,邮箱需已注册) */
|
||||
export function sendLoginCode(email: string) {
|
||||
return post<{ email: string; expires_in: number }>('/auth/email-login/code', { email })
|
||||
}
|
||||
|
||||
/** 邮箱验证码登录,成功后直接返回 token */
|
||||
export function loginByEmailCode(data: { email: string; code: string }) {
|
||||
return post<LoginResult>('/auth/email-login', data)
|
||||
}
|
||||
|
||||
/** 发送密码重置验证码(4 位数字,邮箱需已注册) */
|
||||
export function sendResetCode(email: string) {
|
||||
return post<{ email: string; expires_in: number }>('/auth/reset-password/code', { email })
|
||||
}
|
||||
|
||||
/** 通过邮箱验证码重置密码 */
|
||||
export function resetPasswordByCode(data: { email: string; code: string; password: string }) {
|
||||
return post<{ id: number }>('/auth/reset-password', data)
|
||||
}
|
||||
61
frontend/src/api/comboProduct.ts
Normal file
61
frontend/src/api/comboProduct.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 明细中冗余返回的系统商品信息(后端 include 提供,便于展示) */
|
||||
export interface ComboItemProduct {
|
||||
id: number
|
||||
item_code: string
|
||||
item_name: string
|
||||
sku_property: string | null
|
||||
stock_unit: string | null
|
||||
retail_price?: number | string
|
||||
}
|
||||
|
||||
export interface ComboItem {
|
||||
product_id: number
|
||||
quantity: number
|
||||
product?: ComboItemProduct | null
|
||||
}
|
||||
|
||||
export interface ComboProductItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
code: string
|
||||
name: string
|
||||
price: number | string
|
||||
items: ComboItem[] | null
|
||||
status: number
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface ComboProductPayload {
|
||||
code: string
|
||||
name: string
|
||||
price: number
|
||||
items?: ComboItem[] | null
|
||||
status?: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** 当前主体下的组合商品列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getComboProducts(params?: object) {
|
||||
return get<{ list: ComboProductItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/combo-products',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 新增组合商品(同一主体下 code 唯一) */
|
||||
export function createComboProduct(data: ComboProductPayload) {
|
||||
return post<{ id: number }>('/combo-products', data)
|
||||
}
|
||||
|
||||
/** 更新组合商品 */
|
||||
export function updateComboProduct(id: number, data: Partial<ComboProductPayload>) {
|
||||
return put<{ id: number }>(`/combo-products/${id}`, data)
|
||||
}
|
||||
|
||||
/** 删除组合商品 */
|
||||
export function deleteComboProduct(id: number) {
|
||||
return del<{ id: number }>(`/combo-products/${id}`)
|
||||
}
|
||||
52
frontend/src/api/expressCompany.ts
Normal file
52
frontend/src/api/expressCompany.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 快递公司字典项(通用字典,不区分主体) */
|
||||
export interface ExpressCompany {
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
status: number
|
||||
sort: number
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 下拉项(仅启用) */
|
||||
export interface ExpressCompanyOption {
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface ExpressCompanyPayload {
|
||||
code: string
|
||||
name: string
|
||||
status?: number
|
||||
sort?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export function getExpressCompanies(params?: object) {
|
||||
return get<{ list: ExpressCompany[]; total: number; page: number; pageSize: number }>(
|
||||
'/express-companies',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 下拉用:仅返回启用快递公司(按 sort 升序) */
|
||||
export function getExpressCompanyOptions() {
|
||||
return get<ExpressCompanyOption[]>('/express-companies/select')
|
||||
}
|
||||
|
||||
export function createExpressCompany(data: ExpressCompanyPayload) {
|
||||
return post<{ id: number }>('/express-companies', data)
|
||||
}
|
||||
|
||||
export function updateExpressCompany(id: number, data: Partial<ExpressCompanyPayload>) {
|
||||
return put<{ id: number }>(`/express-companies/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteExpressCompany(id: number) {
|
||||
return del<{ id: number }>(`/express-companies/${id}`)
|
||||
}
|
||||
56
frontend/src/api/file.ts
Normal file
56
frontend/src/api/file.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import { get, post } from '@/utils/request'
|
||||
|
||||
export interface FileItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
hash: string
|
||||
name: string
|
||||
ext: string
|
||||
mime: string | null
|
||||
size: number
|
||||
path: string
|
||||
url: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 上传结果:deduped=true 表示命中已有文件,服务端未重复落盘 */
|
||||
export interface UploadedFile extends FileItem {
|
||||
deduped: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算文件内容 SHA256(十六进制),与后端去重口径一致。
|
||||
* 非安全上下文(如 http 局域网访问)拿不到 crypto.subtle,返回空串,由服务端兜底去重
|
||||
*/
|
||||
export async function hashFile(file: File): Promise<string> {
|
||||
const subtle = globalThis.crypto?.subtle
|
||||
if (!subtle) return ''
|
||||
const buffer = await file.arrayBuffer()
|
||||
const digest = await subtle.digest('SHA-256', buffer)
|
||||
return Array.from(new Uint8Array(digest))
|
||||
.map((byte) => byte.toString(16).padStart(2, '0'))
|
||||
.join('')
|
||||
}
|
||||
|
||||
/** 按 hash 批量查验:命中即可直接复用已有 url,无需再次上传 */
|
||||
export function checkFiles(hashes: string[]) {
|
||||
return post<FileItem[]>('/files/check', { hashes })
|
||||
}
|
||||
|
||||
/** 上传单个文件(服务端会再次按 hash 去重),上传超时放宽到 60s 并回传进度 */
|
||||
export function uploadFile(file: File, onProgress?: (percent: number) => void) {
|
||||
const data = new FormData()
|
||||
data.append('file', file)
|
||||
return post<UploadedFile>('/files/upload', data, {
|
||||
timeout: 60000,
|
||||
onUploadProgress: (event) => {
|
||||
if (onProgress && event.total) onProgress(Math.round((event.loaded / event.total) * 100))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 文件资源列表(按主体隔离) */
|
||||
export function getFiles(params?: object) {
|
||||
return get<{ list: FileItem[]; total: number; page: number; pageSize: number }>('/files', params)
|
||||
}
|
||||
134
frontend/src/api/inboundOrder.ts
Normal file
134
frontend/src/api/inboundOrder.ts
Normal file
@ -0,0 +1,134 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
import type { StockItemLine, StockItemPayload } from './stockOrder'
|
||||
|
||||
/** 入库单(单据头) */
|
||||
export interface InboundOrder {
|
||||
id: number
|
||||
bill_no: string
|
||||
principal_id: number
|
||||
shop_id: number | null
|
||||
inbound_type: string
|
||||
status: number
|
||||
warehouse_id: number | null
|
||||
warehouse?: { id: number; code: string; name: string } | null
|
||||
shop?: { id: number; name: string } | null
|
||||
creator?: { id: number; nickname?: string | null; username: string } | null
|
||||
auditor?: { id: number; nickname?: string | null; username: string } | null
|
||||
audit_by?: number | null
|
||||
audit_time?: string | null
|
||||
supplier?: string | null
|
||||
supplier_code?: string | null
|
||||
operator?: string | null
|
||||
operator_code?: string | null
|
||||
operate_time?: string | null
|
||||
purchase_order_code?: string | null
|
||||
expect_start_time?: string | null
|
||||
expect_end_time?: string | null
|
||||
logistics_code?: string | null
|
||||
logistics_name?: string | null
|
||||
express_code?: string | null
|
||||
sender_info?: Record<string, string> | null
|
||||
receiver_info?: Record<string, string> | null
|
||||
extend_props?: Record<string, string> | null
|
||||
pushed_at?: string | null
|
||||
wms_push_result?: {
|
||||
success?: boolean
|
||||
code?: string | number | null
|
||||
message?: string | null
|
||||
flag?: string | null
|
||||
entryOrderCode?: string
|
||||
warehouseApiId?: number
|
||||
apiType?: string
|
||||
response?: unknown
|
||||
error?: string
|
||||
pushedAt?: string
|
||||
} | null
|
||||
item_total: number | string
|
||||
item_kind: number | null
|
||||
total_amount: number | string
|
||||
remark?: string | null
|
||||
void_at?: string | null
|
||||
void_by?: number | null
|
||||
void_reason?: string | null
|
||||
voider?: { id: number; nickname?: string | null; username: string } | null
|
||||
items?: StockItemLine[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 明细行(创建时随单提交) */
|
||||
export interface InboundItemInput {
|
||||
product_id?: number | null
|
||||
name?: string | null
|
||||
code?: string | null
|
||||
spec?: string | null
|
||||
unit?: string | null
|
||||
quantity?: number
|
||||
price?: number | null
|
||||
inventory_type?: 'ZP' | 'CC'
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
/** 创建 / 更新载荷 */
|
||||
export interface InboundOrderPayload {
|
||||
warehouse_id?: number | null
|
||||
shop_id?: number | null
|
||||
inbound_type?: string
|
||||
status?: number
|
||||
supplier?: string | null
|
||||
supplier_code?: string | null
|
||||
operator?: string | null
|
||||
operator_code?: string | null
|
||||
operate_time?: string | null
|
||||
purchase_order_code?: string | null
|
||||
expect_start_time?: string | null
|
||||
expect_end_time?: string | null
|
||||
logistics_code?: string | null
|
||||
logistics_name?: string | null
|
||||
express_code?: string | null
|
||||
sender_info?: unknown
|
||||
receiver_info?: unknown
|
||||
extend_props?: unknown
|
||||
total_amount?: number
|
||||
remark?: string
|
||||
items?: InboundItemInput[]
|
||||
}
|
||||
|
||||
/** 明细提交(含库存类型 ZP 正品 / CC 残次) */
|
||||
export type InboundItemPayload = StockItemPayload & { inventory_type?: 'ZP' | 'CC' }
|
||||
|
||||
export const inboundOrderApi = {
|
||||
getList: (params?: object) =>
|
||||
get<{ list: InboundOrder[]; total: number; page: number; pageSize: number }>('/inbound-orders', params),
|
||||
get: (id: number) => get<InboundOrder>(`/inbound-orders/${id}`),
|
||||
create: (data: InboundOrderPayload) => post<{ id: number }>('/inbound-orders', data),
|
||||
update: (id: number, data: Partial<InboundOrderPayload>) =>
|
||||
put<{ id: number }>(`/inbound-orders/${id}`, data),
|
||||
audit: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/audit`),
|
||||
push: (id: number) => post<{ id: number; reused?: boolean }>(`/inbound-orders/${id}/push`),
|
||||
complete: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/complete`),
|
||||
cancel: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/cancel`),
|
||||
restore: (id: number) => post<{ id: number }>(`/inbound-orders/${id}/restore`),
|
||||
/** 作废:仅「已审核(2)」可作废,记录作废人/时间/原因,不可恢复 */
|
||||
voidOrder: (id: number, data?: { void_reason?: string }) =>
|
||||
post<{ id: number }>(`/inbound-orders/${id}/void`, data || {}),
|
||||
/** 驳回:已审核(2)/已推送(3) 且未完成 -> 回到待入库(1),已推送的先走接口取消外部单据 */
|
||||
reject: (id: number) => post<{
|
||||
id: number
|
||||
bill_no?: string
|
||||
cancel?: { attempted: boolean; success: boolean; orderType?: string; message?: string }
|
||||
}>(`/inbound-orders/${id}/reject`),
|
||||
remove: (id: number) => del<{ id: number }>(`/inbound-orders/${id}`),
|
||||
/** 明细列表(复用通用 stock_items,bill_type=1 入库) */
|
||||
getItems: (billId: number, params?: object) =>
|
||||
get<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>('/stock-items', {
|
||||
bill_id: billId,
|
||||
bill_type: 1,
|
||||
...params,
|
||||
}),
|
||||
createItem: (data: InboundItemPayload) =>
|
||||
post<{ id: number }>('/stock-items', { ...data, bill_type: 1 }),
|
||||
updateItem: (id: number, data: Partial<InboundItemPayload>) =>
|
||||
put<{ id: number }>(`/stock-items/${id}`, data),
|
||||
removeItem: (id: number) => del<{ id: number }>(`/stock-items/${id}`),
|
||||
}
|
||||
7
frontend/src/api/menu.ts
Normal file
7
frontend/src/api/menu.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { get } from '@/utils/request'
|
||||
import type { MenuItem } from '@/store/menu'
|
||||
|
||||
/** 拉取菜单树(一次性返回全量并按 parent_id 组装为树形) */
|
||||
export function getMenuTree() {
|
||||
return get<MenuItem[]>('/menus/tree')
|
||||
}
|
||||
78
frontend/src/api/order.ts
Normal file
78
frontend/src/api/order.ts
Normal file
@ -0,0 +1,78 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
import type { OrderItemLine } from '@/api/orderItem'
|
||||
|
||||
export interface Receiver {
|
||||
name?: string
|
||||
phone?: string
|
||||
address?: string
|
||||
}
|
||||
|
||||
export interface OrderItem {
|
||||
id: number
|
||||
order_no: string
|
||||
principal_id: number
|
||||
shop_id: number | null
|
||||
order_type: number
|
||||
status: number
|
||||
wms_status: string | null
|
||||
wms_order_no: string | null
|
||||
wms_synced_at: string | null
|
||||
submit_status: number
|
||||
submit_order_no: string | null
|
||||
submit_at: string | null
|
||||
submit_msg: string | null
|
||||
total_amount: number | string
|
||||
pay_amount: number | string | null
|
||||
receiver: Receiver | null
|
||||
remark: string | null
|
||||
shop?: { id: number; name: string } | null
|
||||
items?: OrderItemLine[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface OrderPayload {
|
||||
order_no: string
|
||||
shop_id?: number | null
|
||||
items?: OrderItemLine[]
|
||||
order_type?: number
|
||||
total_amount?: number
|
||||
pay_amount?: number | null
|
||||
receiver?: Receiver | null
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface OrderStatusPayload {
|
||||
status?: number
|
||||
submit_status?: number
|
||||
submit_order_no?: string
|
||||
submit_msg?: string
|
||||
}
|
||||
|
||||
/** 当前主体下的订单列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getOrders(params?: object) {
|
||||
return get<{ list: OrderItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/orders',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 新增订单(order_no 全局唯一) */
|
||||
export function createOrder(data: OrderPayload) {
|
||||
return post<{ id: number }>('/orders', data)
|
||||
}
|
||||
|
||||
/** 更新订单 */
|
||||
export function updateOrder(id: number, data: Partial<OrderPayload>) {
|
||||
return put<{ id: number }>(`/orders/${id}`, data)
|
||||
}
|
||||
|
||||
/** 订单状态流转:主状态 / 上交状态 */
|
||||
export function updateOrderStatus(id: number, data: OrderStatusPayload) {
|
||||
return put<{ id: number }>(`/orders/${id}/status`, data)
|
||||
}
|
||||
|
||||
/** 删除订单 */
|
||||
export function deleteOrder(id: number) {
|
||||
return del<{ id: number }>(`/orders/${id}`)
|
||||
}
|
||||
342
frontend/src/api/orderDelivery.ts
Normal file
342
frontend/src/api/orderDelivery.ts
Normal file
@ -0,0 +1,342 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 发货单明细(子表商品明细,对应奇门 orderLines) */
|
||||
export interface OrderDeliveryLine {
|
||||
id: number
|
||||
principal_id: number
|
||||
order_delivery_id: number
|
||||
order_line_no: string
|
||||
item_id: number | null
|
||||
item_code: string | null
|
||||
item_name: string | null
|
||||
plan_qty: number | string
|
||||
actual_price: number | string | null
|
||||
retail_price: number | string | null
|
||||
ext_code: string | null
|
||||
inventory_type: string
|
||||
owner_code: string | null
|
||||
source_order_code: string | null
|
||||
sub_source_order_code: string | null
|
||||
stock_id: number | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 明细提交载荷 */
|
||||
export interface OrderDeliveryLineInput {
|
||||
order_line_no?: string | number | null
|
||||
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?: 'ZP' | 'CC'
|
||||
owner_code?: string | null
|
||||
source_order_code?: string | null
|
||||
sub_source_order_code?: string | null
|
||||
stock_id?: number | null
|
||||
}
|
||||
|
||||
/** 发货单(单据头):字段口径对齐 WMS 发货单 wms_order_delivery 与奇门 deliveryOrder/receiverInfo */
|
||||
export interface OrderDelivery {
|
||||
id: number
|
||||
principal_id: number
|
||||
legacy_order_id?: number | null
|
||||
warehouse_id: number | null
|
||||
shop_id: number | null
|
||||
warehouse_code: string | null
|
||||
delivery_order_code: string
|
||||
order_type: string | null
|
||||
order_flag: string | null
|
||||
pre_delivery_order_code: string | null
|
||||
pre_delivery_order_id: string | null
|
||||
is_urgency: 'Y' | 'N' | null
|
||||
invoice_flag: 'Y' | 'N' | null
|
||||
source_platform_code: string | null
|
||||
source_platform_name: string | null
|
||||
shop_nick: string | null
|
||||
seller_nick: string | null
|
||||
buyer_nick: string | null
|
||||
buyer_message: string | null
|
||||
seller_message: string | null
|
||||
place_order_time: string | null
|
||||
pay_time: string | null
|
||||
pay_no: string | null
|
||||
operate_time: string | null
|
||||
total_amount: number | string
|
||||
item_amount: number | string
|
||||
discount_amount: number | string
|
||||
freight: number | string
|
||||
ar_amount: number | string
|
||||
got_amount: number | string
|
||||
logistics_code: string | null
|
||||
logistics_name: string | null
|
||||
express_code: string | null
|
||||
logistics_area_code: string | null
|
||||
operator_name: string | null
|
||||
oaid_order_source_code: string | null
|
||||
source_order_codes: string | null
|
||||
need_oms_waybill: number
|
||||
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
|
||||
// 站内字段
|
||||
item_total: number | string
|
||||
item_kind: number
|
||||
status: number
|
||||
audit_by: number | null
|
||||
audit_time: string | null
|
||||
void_at: string | null
|
||||
void_by: number | null
|
||||
void_reason: string | null
|
||||
created_by: number | null
|
||||
pushed_at?: string | null
|
||||
wms_push_result?: Record<string, unknown> | null
|
||||
shop?: { id: number; name: string } | null
|
||||
warehouse?: { id: number; code: string; name: string } | null
|
||||
creator?: { id: number; nickname?: string | null; username: string } | null
|
||||
auditor?: { id: number; nickname?: string | null; username: string } | null
|
||||
voider?: { id: number; nickname?: string | null; username: string } | null
|
||||
items?: OrderDeliveryLine[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 创建 / 更新载荷(状态与统计、审核/作废痕迹由系统托管,不接受提交) */
|
||||
export interface OrderDeliveryPayload {
|
||||
delivery_order_code?: string
|
||||
warehouse_id?: number | null
|
||||
shop_id?: number | null
|
||||
order_type?: string | null
|
||||
order_flag?: string | null
|
||||
pre_delivery_order_code?: string | null
|
||||
pre_delivery_order_id?: string | null
|
||||
is_urgency?: 'Y' | 'N' | null
|
||||
invoice_flag?: 'Y' | 'N' | null
|
||||
source_platform_code?: string | null
|
||||
source_platform_name?: string | null
|
||||
shop_nick?: string | null
|
||||
seller_nick?: string | null
|
||||
buyer_nick?: string | null
|
||||
buyer_message?: string | null
|
||||
seller_message?: string | null
|
||||
place_order_time?: string | null
|
||||
pay_time?: string | null
|
||||
pay_no?: string | null
|
||||
operate_time?: string | null
|
||||
total_amount?: number | null
|
||||
discount_amount?: number | null
|
||||
freight?: number | null
|
||||
ar_amount?: number | null
|
||||
got_amount?: number | null
|
||||
logistics_code?: string | null
|
||||
logistics_name?: string | null
|
||||
operator_name?: string | null
|
||||
oaid_order_source_code?: string | null
|
||||
source_order_codes?: string | null
|
||||
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
|
||||
/** 明细(仅创建时随单提交) */
|
||||
items?: OrderDeliveryLineInput[]
|
||||
}
|
||||
|
||||
/** 收件人智能识别结果(未识别到的字段为空串) */
|
||||
export interface ReceiverParseResult {
|
||||
name: string
|
||||
tel: string
|
||||
mobile: string
|
||||
email: string
|
||||
country_code: string
|
||||
province: string
|
||||
city: string
|
||||
area: string
|
||||
town: string
|
||||
detail_address: string
|
||||
zip_code: string
|
||||
}
|
||||
|
||||
/** 收件人信息智能识别(AI 抽取,不落库;未配置 AI 密钥时后端返回 400) */
|
||||
export function parseReceiver(text: string) {
|
||||
return post<ReceiverParseResult>('/order-deliveries/parse-receiver', { text })
|
||||
}
|
||||
|
||||
/** 批量切换发货仓库的入参:ids(勾选)优先,否则按条件;dry_run=true 仅预览影响范围 */
|
||||
export interface WarehouseChangeParams {
|
||||
/** 目标仓库ID(必填,需属于当前主体) */
|
||||
warehouse_id: number
|
||||
/** 按勾选切换:发货单ID数组(scope_by='ids' 时必传) */
|
||||
ids?: number[]
|
||||
/** 切换范围:ids=按勾选 / filter=按筛选条件(显式传 filter 时后端忽略 ids) */
|
||||
scope_by?: 'ids' | 'filter'
|
||||
/** true=只预览影响范围(不写库) */
|
||||
dry_run?: boolean
|
||||
// ---- 条件(与列表筛选同口径)----
|
||||
delivery_order_code?: string
|
||||
status?: number
|
||||
order_type?: string
|
||||
shop_id?: number
|
||||
/** 原发货仓库ID */
|
||||
from_warehouse_id?: number
|
||||
}
|
||||
|
||||
/** 批量切换发货仓库的结果(dry_run 时额外返回 samples) */
|
||||
export interface WarehouseChangeResult {
|
||||
target_warehouse: { id: number; code: string; name: string }
|
||||
/** 命中范围条数(已排除本就属于目标仓库的单据) */
|
||||
matched: number
|
||||
/** 可切换条数:待处理(1) / 已审核(2) */
|
||||
switchable: number
|
||||
/** 不可切换条数:已推送(3) / 已完成(4) / 已作废(5) / 已取消(9) */
|
||||
blocked: number
|
||||
/** 不可切换的状态分布,如 { 3: 2, 4: 1 } */
|
||||
blocked_reason: Record<string, number>
|
||||
/** 范围内已属于目标仓库的条数(无需切换) */
|
||||
same_warehouse: number
|
||||
scope: { by: 'ids' | 'filter'; ids: number[] }
|
||||
/** 样例单据(最多 5 条,仅预览返回) */
|
||||
samples?: { id: number; delivery_order_code: string; status: number; warehouse_name: string | null }[]
|
||||
/** 实际更新条数(仅执行返回) */
|
||||
updated?: number
|
||||
}
|
||||
|
||||
/** 批量切换发货仓库(dry_run=true 时只预览影响范围) */
|
||||
export function changeDeliveryWarehouse(data: WarehouseChangeParams) {
|
||||
return post<WarehouseChangeResult>('/order-deliveries/change-warehouse', data)
|
||||
}
|
||||
|
||||
/** 发货单列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getOrderDeliveries(params?: object) {
|
||||
return get<{ list: OrderDelivery[]; total: number; page: number; pageSize: number }>(
|
||||
'/order-deliveries',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 发货单详情(含明细 items) */
|
||||
export function getOrderDelivery(id: number) {
|
||||
return get<OrderDelivery>(`/order-deliveries/${id}`)
|
||||
}
|
||||
|
||||
export function createOrderDelivery(data: OrderDeliveryPayload) {
|
||||
return post<{ id: number }>('/order-deliveries', data)
|
||||
}
|
||||
|
||||
export function updateOrderDelivery(id: number, data: OrderDeliveryPayload) {
|
||||
return put<{ id: number }>(`/order-deliveries/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteOrderDelivery(id: number) {
|
||||
return del<{ id: number }>(`/order-deliveries/${id}`)
|
||||
}
|
||||
|
||||
/** 状态流转:审核 待处理(1)→已审核(2);只入队不立即推送,由定时任务异步推送仓库 */
|
||||
export function auditOrderDelivery(id: number) {
|
||||
return post<{ id: number; status: number }>(`/order-deliveries/${id}/audit`)
|
||||
}
|
||||
|
||||
/** 推送已审核的发货单到仓库(WMS deliveryorder.create),失败规则见后端服务说明 */
|
||||
export function pushOrderDelivery(id: number) {
|
||||
return post<{ id: number; status: number; attempts?: number; wms_response?: unknown }>(`/order-deliveries/${id}/push`)
|
||||
}
|
||||
|
||||
/** 批量操作范围:勾选 ids 或筛选条件(与列表筛选同口径) */
|
||||
export interface BatchScopeParams {
|
||||
/** ids=按勾选(ids 必传)/ filter=按筛选条件(忽略 ids) */
|
||||
scope_by: 'ids' | 'filter'
|
||||
ids?: number[]
|
||||
/** true=只预览影响范围 */
|
||||
dry_run?: boolean
|
||||
delivery_order_code?: string
|
||||
status?: number
|
||||
order_type?: string
|
||||
shop_id?: number
|
||||
/** 原发货仓库ID */
|
||||
from_warehouse_id?: number
|
||||
}
|
||||
|
||||
/** 批量操作结果(审核与推送共用;dry_run 时额外返回 samples) */
|
||||
export interface BatchOperationResult {
|
||||
matched: number
|
||||
affected: number
|
||||
auditable?: number
|
||||
pushable?: number
|
||||
skipped: number
|
||||
pending_rest?: number
|
||||
pushed?: number
|
||||
failed?: number
|
||||
retry?: number
|
||||
skipped_push?: number
|
||||
details?: { id: number; ok: boolean; skipped: boolean; retry: boolean; message: string }[]
|
||||
samples?: { id: number; delivery_order_code: string; status: number }[]
|
||||
scope: { by: 'ids' | 'filter'; ids: number[] }
|
||||
}
|
||||
|
||||
/** 批量审核(1→2,只入队不推送;dry_run=true 只预览影响范围) */
|
||||
export function auditBatchOrderDeliveries(data: BatchScopeParams) {
|
||||
return post<BatchOperationResult>('/order-deliveries/audit-batch', data)
|
||||
}
|
||||
|
||||
/** 批量推送已审核单据(顺序限流,其余交给定时任务;dry_run=true 只预览影响范围) */
|
||||
export function pushBatchOrderDeliveries(data: BatchScopeParams) {
|
||||
return post<BatchOperationResult>('/order-deliveries/push-batch', data)
|
||||
}
|
||||
|
||||
/** 状态流转:驳回 已审核(2)→待处理(1),不换号 */
|
||||
export function rejectOrderDelivery(id: number) {
|
||||
return post<{ id: number }>(`/order-deliveries/${id}/reject`)
|
||||
}
|
||||
|
||||
/** 状态流转:取消 →已取消(9) */
|
||||
export function cancelOrderDelivery(id: number) {
|
||||
return post<{ id: number }>(`/order-deliveries/${id}/cancel`)
|
||||
}
|
||||
|
||||
/** 状态流转:恢复 已取消(9)→待处理(1) */
|
||||
export function restoreOrderDelivery(id: number) {
|
||||
return post<{ id: number }>(`/order-deliveries/${id}/restore`)
|
||||
}
|
||||
|
||||
/** 状态流转:作废 已审核(2)→已作废(5) */
|
||||
export function voidOrderDelivery(id: number, data?: { void_reason?: string }) {
|
||||
return post<{ id: number }>(`/order-deliveries/${id}/void`, data)
|
||||
}
|
||||
|
||||
/** 发货单明细列表(order_delivery_id 必填) */
|
||||
export function getOrderDeliveryItems(params: { order_delivery_id: number; page?: number; pageSize?: number }) {
|
||||
return get<{ list: OrderDeliveryLine[]; total: number; page: number; pageSize: number }>(
|
||||
'/order-delivery-items',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
export function createOrderDeliveryItem(data: OrderDeliveryLineInput & { order_delivery_id: number }) {
|
||||
return post<{ id: number }>('/order-delivery-items', data)
|
||||
}
|
||||
|
||||
export function updateOrderDeliveryItem(id: number, data: OrderDeliveryLineInput) {
|
||||
return put<{ id: number }>(`/order-delivery-items/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteOrderDeliveryItem(id: number) {
|
||||
return del<{ id: number }>(`/order-delivery-items/${id}`)
|
||||
}
|
||||
81
frontend/src/api/orderItem.ts
Normal file
81
frontend/src/api/orderItem.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 解析状态:0未解析 1已解析 2解析失败 */
|
||||
export const PARSE_STATUS = { none: 0, done: 1, failed: 2 } as const
|
||||
|
||||
export interface OrderItemLine {
|
||||
id: number
|
||||
principal_id: number
|
||||
order_id: number
|
||||
shop_id: number | null
|
||||
product_id: number | null
|
||||
combo_product_id: number | null
|
||||
shop_product_id: number | null
|
||||
item_type: number
|
||||
parse_status: number
|
||||
parse_msg: string | null
|
||||
outer_item_id: string | null
|
||||
outer_sku_id: string | null
|
||||
sku_code: string | null
|
||||
name: string | null
|
||||
spec: string | null
|
||||
image: string | null
|
||||
quantity: number | string
|
||||
price: number | string | null
|
||||
total_amount: number | string
|
||||
created_at?: string
|
||||
product?: { id: number; item_code: string; item_name: string; sku_property: string | null } | null
|
||||
comboProduct?: { id: number; code: string; name: string } | null
|
||||
}
|
||||
|
||||
export interface OrderItemPayload {
|
||||
order_id: number
|
||||
shop_id?: number | null
|
||||
product_id?: number | null
|
||||
combo_product_id?: number | null
|
||||
outer_item_id?: string
|
||||
outer_sku_id?: string
|
||||
sku_code?: string
|
||||
name?: string
|
||||
spec?: string
|
||||
quantity?: number
|
||||
price?: number | null
|
||||
total_amount?: number
|
||||
}
|
||||
|
||||
/** 订单明细列表(需传 order_id) */
|
||||
export function getOrderItems(params?: object) {
|
||||
return get<{ list: OrderItemLine[]; total: number; page: number; pageSize: number }>(
|
||||
'/order-items',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 新增订单明细 */
|
||||
export function createOrderItem(data: OrderItemPayload) {
|
||||
return post<{ id: number }>('/order-items', data)
|
||||
}
|
||||
|
||||
/** 更新订单明细 */
|
||||
export function updateOrderItem(id: number, data: Partial<OrderItemPayload>) {
|
||||
return put<{ id: number }>(`/order-items/${id}`, data)
|
||||
}
|
||||
|
||||
/** 解析单条明细:按商家编码/店铺商品绑定匹配系统商品 */
|
||||
export function parseOrderItem(id: number) {
|
||||
return post<{ id: number; parse_status: number; parse_msg: string | null }>(
|
||||
`/order-items/${id}/parse`,
|
||||
)
|
||||
}
|
||||
|
||||
/** 整单解析:解析该订单下所有未解析/失败的明细 */
|
||||
export function parseOrderItems(orderId: number) {
|
||||
return post<{ total: number; resolved: number; failed: number }>(
|
||||
`/orders/${orderId}/parse-items`,
|
||||
)
|
||||
}
|
||||
|
||||
/** 删除订单明细 */
|
||||
export function deleteOrderItem(id: number) {
|
||||
return del<{ id: number }>(`/order-items/${id}`)
|
||||
}
|
||||
30
frontend/src/api/outboundLog.ts
Normal file
30
frontend/src/api/outboundLog.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { get } from '@/utils/request'
|
||||
|
||||
/** 对外 API 请求记录(OMS → 外部 WMS 的调用) */
|
||||
export interface OutboundLogItem {
|
||||
id: number
|
||||
principal_id: number | null
|
||||
warehouse_id: number | null
|
||||
warehouse_api_id: number | null
|
||||
api_type: string | null
|
||||
method: string
|
||||
url: string | null
|
||||
request_headers: string | null
|
||||
request_body: string | null
|
||||
response_status: number | null
|
||||
response_body: string | null
|
||||
is_success: number
|
||||
business_code: string | null
|
||||
business_message: string | null
|
||||
error: string | null
|
||||
duration: number | null
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** 对外 API 调用日志列表(按当前主体、可选仓库过滤) */
|
||||
export function getOutboundLogs(params?: object) {
|
||||
return get<{ list: OutboundLogItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/outbound-logs',
|
||||
params,
|
||||
)
|
||||
}
|
||||
101
frontend/src/api/outboundOrder.ts
Normal file
101
frontend/src/api/outboundOrder.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
import type { StockItemLine, StockItemPayload } from './stockOrder'
|
||||
|
||||
/** 出库单(单据头) */
|
||||
export interface OutboundOrder {
|
||||
id: number
|
||||
bill_no: string
|
||||
principal_id: number
|
||||
shop_id: number | null
|
||||
outbound_type: string
|
||||
status: number
|
||||
customer?: string | null
|
||||
operator?: string | null
|
||||
warehouse_id: number | null
|
||||
warehouse?: { id: number; code: string; name: string } | null
|
||||
shop?: { id: number; name: string } | null
|
||||
creator?: { id: number; nickname?: string | null; username: string } | null
|
||||
item_total: number | string
|
||||
item_kind: number | null
|
||||
total_amount: number | string
|
||||
remark?: string | null
|
||||
stock_deducted?: number
|
||||
void_at?: string | null
|
||||
void_by?: number | null
|
||||
void_reason?: string | null
|
||||
voider?: { id: number; nickname?: string | null; username: string } | null
|
||||
pushed_at?: string | null
|
||||
wms_push_result?: {
|
||||
success?: boolean
|
||||
code?: string | number | null
|
||||
message?: string | null
|
||||
error?: string | null
|
||||
deliveryOrderCode?: string | null
|
||||
pushedAt?: string | null
|
||||
[key: string]: unknown
|
||||
} | null
|
||||
items?: StockItemLine[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 明细行(创建时随单提交) */
|
||||
export interface OutboundItemInput {
|
||||
product_id?: number | null
|
||||
name?: string | null
|
||||
code?: string | null
|
||||
spec?: string | null
|
||||
unit?: string | null
|
||||
quantity?: number
|
||||
price?: number | null
|
||||
inventory_type?: 'ZP' | 'CC'
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
/** 创建 / 更新载荷 */
|
||||
export interface OutboundOrderPayload {
|
||||
warehouse_id?: number | null
|
||||
shop_id?: number | null
|
||||
outbound_type?: string
|
||||
status?: number
|
||||
customer?: string | null
|
||||
operator?: string | null
|
||||
total_amount?: number
|
||||
remark?: string
|
||||
items?: OutboundItemInput[]
|
||||
}
|
||||
|
||||
/** 明细提交(含库存类型 ZP 正品 / CC 残次,与入库单对齐) */
|
||||
export type OutboundItemPayload = StockItemPayload & { inventory_type?: 'ZP' | 'CC' }
|
||||
|
||||
export const outboundOrderApi = {
|
||||
getList: (params?: object) =>
|
||||
get<{ list: OutboundOrder[]; total: number; page: number; pageSize: number }>('/outbound-orders', params),
|
||||
get: (id: number) => get<OutboundOrder>(`/outbound-orders/${id}`),
|
||||
create: (data: OutboundOrderPayload) => post<{ id: number }>('/outbound-orders', data),
|
||||
update: (id: number, data: Partial<OutboundOrderPayload>) =>
|
||||
put<{ id: number }>(`/outbound-orders/${id}`, data),
|
||||
audit: (id: number) => post<{ id: number }>(`/outbound-orders/${id}/audit`),
|
||||
push: (id: number) => post<{ id: number }>(`/outbound-orders/${id}/push`),
|
||||
complete: (id: number) => post<{ id: number }>(`/outbound-orders/${id}/complete`),
|
||||
cancel: (id: number) => post<{ id: number }>(`/outbound-orders/${id}/cancel`),
|
||||
restore: (id: number) => post<{ id: number }>(`/outbound-orders/${id}/restore`),
|
||||
/** 作废:仅「已审核(2)」可作废,记录作废人/时间/原因,不可恢复 */
|
||||
voidOrder: (id: number, data?: { void_reason?: string }) =>
|
||||
post<{ id: number }>(`/outbound-orders/${id}/void`, data || {}),
|
||||
/** 驳回:已审核(2)/已推送(3) 且未完成 -> 回到待出库(1),已推送的先走接口取消外部单据 */
|
||||
reject: (id: number) => post<{ id: number; bill_no?: string }>(`/outbound-orders/${id}/reject`),
|
||||
remove: (id: number) => del<{ id: number }>(`/outbound-orders/${id}`),
|
||||
/** 明细列表(复用通用 stock_items,bill_type=2 出库) */
|
||||
getItems: (billId: number, params?: object) =>
|
||||
get<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>('/stock-items', {
|
||||
bill_id: billId,
|
||||
bill_type: 2,
|
||||
...params,
|
||||
}),
|
||||
createItem: (data: OutboundItemPayload) =>
|
||||
post<{ id: number }>('/stock-items', { ...data, bill_type: 2 }),
|
||||
updateItem: (id: number, data: Partial<OutboundItemPayload>) =>
|
||||
put<{ id: number }>(`/stock-items/${id}`, data),
|
||||
removeItem: (id: number) => del<{ id: number }>(`/stock-items/${id}`),
|
||||
}
|
||||
33
frontend/src/api/principal.ts
Normal file
33
frontend/src/api/principal.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { post, get } from '@/utils/request'
|
||||
|
||||
export interface PrincipalPayload {
|
||||
name: string
|
||||
type?: number
|
||||
contact_name?: string
|
||||
contact_phone?: string
|
||||
remark?: string
|
||||
}
|
||||
|
||||
export interface PrincipalItem {
|
||||
id: number
|
||||
name: string
|
||||
type: number
|
||||
contact_name: string | null
|
||||
contact_phone: string | null
|
||||
status: number
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
/** 创建主体(同时会将当前用户关联为默认主体用户) */
|
||||
export function createPrincipal(data: PrincipalPayload) {
|
||||
return post<{ id: number }>('/principals', data)
|
||||
}
|
||||
|
||||
/** 主体列表 */
|
||||
export function getPrincipals(params?: object) {
|
||||
return get<{ list: PrincipalItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/principals',
|
||||
params,
|
||||
)
|
||||
}
|
||||
49
frontend/src/api/principalUser.ts
Normal file
49
frontend/src/api/principalUser.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
export interface PrincipalUserItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
user_id: number
|
||||
role: string | null
|
||||
is_default: number
|
||||
status: number
|
||||
created_at?: string
|
||||
user?: {
|
||||
id: number
|
||||
username: string
|
||||
nickname: string | null
|
||||
email: string | null
|
||||
} | null
|
||||
}
|
||||
|
||||
export interface InviteResult {
|
||||
user_id: number
|
||||
relation_id: number
|
||||
email: string
|
||||
username: string
|
||||
nickname: string
|
||||
password: string
|
||||
}
|
||||
|
||||
/** 当前主体下的用户关联列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getPrincipalUsers(params?: object) {
|
||||
return get<{ list: PrincipalUserItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/principal-users',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 邀请开通主体账号:创建新用户(随机初始密码)并绑定到当前主体 */
|
||||
export function invitePrincipalUser(data: { email: string; name: string }) {
|
||||
return post<InviteResult>('/principal-users/invite', data)
|
||||
}
|
||||
|
||||
/** 更新关联(角色 / 状态) */
|
||||
export function updatePrincipalUser(id: number, data: { role?: string; status?: number }) {
|
||||
return put<{ id: number }>(`/principal-users/${id}`, data)
|
||||
}
|
||||
|
||||
/** 解绑用户与主体 */
|
||||
export function deletePrincipalUser(id: number) {
|
||||
return del<{ id: number }>(`/principal-users/${id}`)
|
||||
}
|
||||
115
frontend/src/api/product.ts
Normal file
115
frontend/src/api/product.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
export interface ProductItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
item_code: string
|
||||
goods_code: string | null
|
||||
barcode: string | null
|
||||
item_name: string
|
||||
sku_property: string | null
|
||||
stock_unit: string | null
|
||||
/** 库存(来自 product_stocks):正品/次品的可用与锁定数量 */
|
||||
zc_available?: number
|
||||
zc_locked?: number
|
||||
cc_available?: number
|
||||
cc_locked?: number
|
||||
item_type: number
|
||||
category_id: number | null
|
||||
category_name: string | null
|
||||
brand_name: string | null
|
||||
length: number | string | null // 长度,单位 cm
|
||||
width: number | string | null // 宽度,单位 cm
|
||||
height: number | string | null // 高度,单位 cm
|
||||
volume: number | string | null // 体积,单位 cm³
|
||||
gross_weight: number | null // 毛重,单位 g
|
||||
net_weight: number | null // 净重,单位 g
|
||||
is_area_sale: string
|
||||
is_sn_mgmt: string
|
||||
is_shelf_life_mgmt: string
|
||||
is_batch_mgmt: string
|
||||
tag_price: number | string | null
|
||||
retail_price: number | string
|
||||
cost_price: number | string | null
|
||||
image: string | null // 主图,取 images 首张
|
||||
images: string[] | null // 图片组(URL 数组),首张为主图
|
||||
status: number
|
||||
remark: string | null
|
||||
create_from?: string | null
|
||||
stock_id: number | null
|
||||
warehouse_id: number | null
|
||||
store_id: number | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
deleted_at?: string | null
|
||||
}
|
||||
|
||||
/** 商品快速搜索返回(聚合:商品编码/货物编码/条码/商品名称) */
|
||||
export interface ProductSearchItem {
|
||||
id: number
|
||||
item_code: string
|
||||
goods_code: string | null
|
||||
barcode: string | null
|
||||
item_name: string
|
||||
sku_property: string | null
|
||||
stock_unit: string | null
|
||||
status: number
|
||||
}
|
||||
|
||||
export interface ProductPayload {
|
||||
item_code: string
|
||||
item_name: string
|
||||
goods_code?: string | null
|
||||
barcode?: string | null
|
||||
item_type?: number
|
||||
category_id?: number | null
|
||||
category_name?: string
|
||||
brand_name?: string
|
||||
sku_property?: string
|
||||
stock_unit?: string
|
||||
length?: number | null // 长度,单位 cm
|
||||
width?: number | null // 宽度,单位 cm
|
||||
height?: number | null // 高度,单位 cm
|
||||
volume?: number | null // 体积,单位 cm³
|
||||
gross_weight?: number | null // 毛重,单位 g
|
||||
net_weight?: number | null // 净重,单位 g
|
||||
is_area_sale?: string
|
||||
is_sn_mgmt?: string
|
||||
is_shelf_life_mgmt?: string
|
||||
is_batch_mgmt?: string
|
||||
tag_price?: number | null
|
||||
retail_price: number
|
||||
cost_price?: number | null
|
||||
image?: string // 主图,取 images 首张
|
||||
images?: string[] // 图片组(URL 数组),首张作为主图写入 image
|
||||
status?: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** 当前主体下的商品列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getProducts(params?: object) {
|
||||
return get<{ list: ProductItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/products',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 商品快速搜索:商品编码/货物编码/条码/商品名称 聚合匹配,返回启用商品 */
|
||||
export function searchProducts(keyword?: string) {
|
||||
return get<ProductSearchItem[]>('/products/search', keyword ? { keyword } : undefined)
|
||||
}
|
||||
|
||||
/** 新增商品(同一主体下 item_code 唯一,已删除的不影响) */
|
||||
export function createProduct(data: ProductPayload) {
|
||||
return post<{ id: number }>('/products', data)
|
||||
}
|
||||
|
||||
/** 更新商品 */
|
||||
export function updateProduct(id: number, data: Partial<ProductPayload>) {
|
||||
return put<{ id: number }>(`/products/${id}`, data)
|
||||
}
|
||||
|
||||
/** 删除商品(软删除) */
|
||||
export function deleteProduct(id: number) {
|
||||
return del<{ id: number }>(`/products/${id}`)
|
||||
}
|
||||
69
frontend/src/api/shop.ts
Normal file
69
frontend/src/api/shop.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
export interface ShopItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
code: string
|
||||
name: string
|
||||
platform: string | null
|
||||
contact_name: string | null
|
||||
contact_phone: string | null
|
||||
status: number
|
||||
extra: unknown | null
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface ShopPayload {
|
||||
/** 店铺编码:留空由后端自动生成 OMS 前缀编码 */
|
||||
code?: string
|
||||
name: string
|
||||
platform?: string
|
||||
contact_name?: string
|
||||
contact_phone?: string
|
||||
status?: number
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** 当前主体下的店铺列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getShops(params?: object) {
|
||||
return get<{ list: ShopItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/shops',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 店铺关联统计(详情接口返回) */
|
||||
export interface ShopStats {
|
||||
shop_product_count: number
|
||||
shop_product_bound_count: number
|
||||
order_count: number
|
||||
order_amount: number
|
||||
latest_order_at: string | null
|
||||
}
|
||||
|
||||
/** 店铺详情(含关联统计) */
|
||||
export interface ShopDetail extends ShopItem {
|
||||
stats: ShopStats
|
||||
}
|
||||
|
||||
/** 店铺详情(含店铺商品、订单等关联统计) */
|
||||
export function getShop(id: number) {
|
||||
return get<ShopDetail>(`/shops/${id}`)
|
||||
}
|
||||
|
||||
/** 新增店铺(未传 code 时返回自动生成的 OMS 前缀编码) */
|
||||
export function createShop(data: ShopPayload) {
|
||||
return post<{ id: number; code: string }>('/shops', data)
|
||||
}
|
||||
|
||||
/** 更新店铺 */
|
||||
export function updateShop(id: number, data: Partial<ShopPayload>) {
|
||||
return put<{ id: number }>(`/shops/${id}`, data)
|
||||
}
|
||||
|
||||
/** 删除店铺(存在订单引用时不可删除) */
|
||||
export function deleteShop(id: number) {
|
||||
return del<{ id: number }>(`/shops/${id}`)
|
||||
}
|
||||
70
frontend/src/api/shopProduct.ts
Normal file
70
frontend/src/api/shopProduct.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 绑定类型:0未绑定 1系统商品 2组合商品 */
|
||||
export const BIND_TYPES = { none: 0, product: 1, combo: 2 } as const
|
||||
|
||||
export interface ShopProductItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
shop_id: number
|
||||
outer_item_id: string
|
||||
outer_sku_id: string | null
|
||||
title: string | null
|
||||
outer_code: string | null
|
||||
spec: string | null
|
||||
image: string | null
|
||||
price: number | string | null
|
||||
stock: number
|
||||
status: number
|
||||
bind_type: number
|
||||
product_id: number | null
|
||||
combo_product_id: number | null
|
||||
synced_at: string | null
|
||||
created_at?: string
|
||||
/** 列表接口 include 带回的关联对象 */
|
||||
shop?: { id: number; name: string; platform: string | null } | null
|
||||
product?: { id: number; item_code: string; item_name: string } | null
|
||||
comboProduct?: { id: number; code: string; name: string } | null
|
||||
}
|
||||
|
||||
export interface ShopProductPayload {
|
||||
shop_id: number
|
||||
outer_item_id: string
|
||||
outer_sku_id?: string
|
||||
title?: string
|
||||
outer_code?: string
|
||||
spec?: string
|
||||
image?: string
|
||||
price?: number
|
||||
stock?: number
|
||||
status?: number
|
||||
}
|
||||
|
||||
export interface BindPayload {
|
||||
bind_type: number
|
||||
product_id?: number | null
|
||||
combo_product_id?: number | null
|
||||
}
|
||||
|
||||
/** 当前主体下的店铺商品列表(principal_id 由请求拦截器自动注入) */
|
||||
export function getShopProducts(params?: object) {
|
||||
return get<{ list: ShopProductItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/shop-products',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 更新店铺商品采集信息 */
|
||||
export function updateShopProduct(id: number, data: Partial<ShopProductPayload>) {
|
||||
return put<{ id: number }>(`/shop-products/${id}`, data)
|
||||
}
|
||||
|
||||
/** 绑定系统商品 / 组合商品,bind_type=0 为解绑 */
|
||||
export function bindShopProduct(id: number, data: BindPayload) {
|
||||
return post<{ id: number }>(`/shop-products/${id}/bind`, data)
|
||||
}
|
||||
|
||||
/** 删除店铺商品 */
|
||||
export function deleteShopProduct(id: number) {
|
||||
return del<{ id: number }>(`/shop-products/${id}`)
|
||||
}
|
||||
136
frontend/src/api/stockOrder.ts
Normal file
136
frontend/src/api/stockOrder.ts
Normal file
@ -0,0 +1,136 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 单据类型:1入库 2出库 */
|
||||
export const STOCK_BILL_TYPE = { inbound: 1, outbound: 2 } as const
|
||||
export type StockBillType = 1 | 2
|
||||
|
||||
/** 出入库明细行 */
|
||||
export interface StockItemLine {
|
||||
id: number
|
||||
principal_id: number
|
||||
bill_type: number
|
||||
bill_id: number
|
||||
shop_id: number | null
|
||||
product_id: number | null
|
||||
combo_product_id: number | null
|
||||
shop_product_id: number | null
|
||||
name: string | null
|
||||
code: string | null
|
||||
spec: string | null
|
||||
unit: string | null
|
||||
quantity: number | string
|
||||
/** 应/已数量(系统维护:应=明细数量,已=WMS 回推),只读 */
|
||||
plan_in_qty?: number | string
|
||||
actual_in_qty?: number | string
|
||||
plan_out_qty?: number | string
|
||||
actual_out_qty?: number | string
|
||||
price: number | string | null
|
||||
total_amount: number | string
|
||||
remark: string | null
|
||||
inventory_type?: string | null
|
||||
product?: { id: number; item_code: string; item_name: string; sku_property: string | null } | null
|
||||
comboProduct?: { id: number; code: string; name: string } | null
|
||||
}
|
||||
|
||||
/** 明细提交载荷 */
|
||||
export interface StockItemPayload {
|
||||
bill_id?: number
|
||||
bill_type?: number
|
||||
shop_id?: number | null
|
||||
product_id?: number | null
|
||||
combo_product_id?: number | null
|
||||
shop_product_id?: number | null
|
||||
name?: string | null
|
||||
code?: string | null
|
||||
spec?: string | null
|
||||
unit?: string | null
|
||||
quantity?: number
|
||||
price?: number | null
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
/** 出入库单据(单据头) */
|
||||
export interface StockOrder {
|
||||
id: number
|
||||
bill_no: string
|
||||
principal_id: number
|
||||
shop_id: number | null
|
||||
inbound_type?: number
|
||||
outbound_type?: number
|
||||
status: number
|
||||
supplier?: string | null
|
||||
customer?: string | null
|
||||
operator?: string | null
|
||||
total_amount: number | string
|
||||
remark?: string | null
|
||||
created_by?: number | null
|
||||
creator?: { id: number; nickname?: string | null; username?: string } | null
|
||||
warehouse_id?: number | null
|
||||
warehouse?: { id: number; code: string; name: string } | null
|
||||
item_total?: number | string
|
||||
item_kind?: number | null
|
||||
shop?: { id: number; name: string } | null
|
||||
items?: StockItemLine[]
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
/** 单据提交载荷 */
|
||||
export interface StockOrderPayload {
|
||||
shop_id?: number | null
|
||||
warehouse_id?: number | null
|
||||
inbound_type?: number
|
||||
outbound_type?: number
|
||||
status?: number
|
||||
supplier?: string | null
|
||||
customer?: string | null
|
||||
operator?: string | null
|
||||
total_amount?: number
|
||||
remark?: string
|
||||
items?: StockItemPayload[]
|
||||
}
|
||||
|
||||
export interface StockOrderApi {
|
||||
getList: (params?: object) => Promise<{ list: StockOrder[]; total: number; page: number; pageSize: number }>
|
||||
create: (data: StockOrderPayload) => Promise<{ id: number }>
|
||||
update: (id: number, data: Partial<StockOrderPayload>) => Promise<{ id: number }>
|
||||
audit: (id: number) => Promise<{ id: number }>
|
||||
push: (id: number) => Promise<{ id: number }>
|
||||
complete: (id: number) => Promise<{ id: number }>
|
||||
cancel: (id: number) => Promise<{ id: number }>
|
||||
restore: (id: number) => Promise<{ id: number }>
|
||||
remove: (id: number) => Promise<{ id: number }>
|
||||
getItems: (billId: number, params?: object) => Promise<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>
|
||||
createItem: (data: StockItemPayload) => Promise<{ id: number }>
|
||||
updateItem: (id: number, data: Partial<StockItemPayload>) => Promise<{ id: number }>
|
||||
removeItem: (id: number) => Promise<{ id: number }>
|
||||
}
|
||||
|
||||
/**
|
||||
* 按单据类型生成出入库 API(入库/出库共用同一套逻辑,仅 base 路径与 bill_type 不同)
|
||||
* @param billType 1入库 2出库
|
||||
*/
|
||||
export function createStockOrderApi(billType: StockBillType): StockOrderApi {
|
||||
const base = billType === STOCK_BILL_TYPE.inbound ? '/inbound-orders' : '/outbound-orders'
|
||||
return {
|
||||
getList: (params) =>
|
||||
get<{ list: StockOrder[]; total: number; page: number; pageSize: number }>(base, params),
|
||||
create: (data) => post<{ id: number }>(base, data),
|
||||
update: (id, data) => put<{ id: number }>(`${base}/${id}`, data),
|
||||
audit: (id) => post<{ id: number }>(`${base}/${id}/audit`),
|
||||
push: (id) => post<{ id: number }>(`${base}/${id}/push`),
|
||||
complete: (id) => post<{ id: number }>(`${base}/${id}/complete`),
|
||||
cancel: (id) => post<{ id: number }>(`${base}/${id}/cancel`),
|
||||
restore: (id) => post<{ id: number }>(`${base}/${id}/restore`),
|
||||
remove: (id) => del<{ id: number }>(`${base}/${id}`),
|
||||
getItems: (billId, params) =>
|
||||
get<{ list: StockItemLine[]; total: number; page: number; pageSize: number }>('/stock-items', {
|
||||
bill_id: billId,
|
||||
bill_type: billType,
|
||||
...params,
|
||||
}),
|
||||
createItem: (data) => post<{ id: number }>('/stock-items', { ...data, bill_type: billType }),
|
||||
updateItem: (id, data) => put<{ id: number }>(`/stock-items/${id}`, data),
|
||||
removeItem: (id) => del<{ id: number }>(`/stock-items/${id}`),
|
||||
}
|
||||
}
|
||||
19
frontend/src/api/user.ts
Normal file
19
frontend/src/api/user.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { put } from '@/utils/request'
|
||||
import type { UserInfo } from '@/api/auth'
|
||||
|
||||
export interface UpdateProfilePayload {
|
||||
nickname?: string
|
||||
email?: string
|
||||
phone?: string
|
||||
avatar?: string
|
||||
}
|
||||
|
||||
/** 修改当前登录用户自己的资料(昵称/邮箱/手机号/头像) */
|
||||
export function updateProfile(data: UpdateProfilePayload) {
|
||||
return put<UserInfo>('/auth/profile', data)
|
||||
}
|
||||
|
||||
/** 修改当前登录用户自己的密码(需提供原密码) */
|
||||
export function changePassword(data: { old_password: string; password: string }) {
|
||||
return put<{ id: number }>('/auth/password', data)
|
||||
}
|
||||
157
frontend/src/api/warehouse.ts
Normal file
157
frontend/src/api/warehouse.ts
Normal file
@ -0,0 +1,157 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
import type { WarehouseApiItem } from '@/api/warehouseApi'
|
||||
|
||||
export interface WarehouseItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
code: string
|
||||
name: string
|
||||
type: string | null
|
||||
status: number
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
/** 列表接口带出的接口配置(一个仓库可有多条) */
|
||||
apis?: WarehouseApiItem[]
|
||||
}
|
||||
|
||||
export interface WarehouseOption {
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
}
|
||||
|
||||
/** 仓库关联统计(详情接口返回) */
|
||||
export interface WarehouseStats {
|
||||
api_count: number
|
||||
api_enabled_count: number
|
||||
inbound_order_count: number
|
||||
outbound_order_count: number
|
||||
}
|
||||
|
||||
/** 仓库详情(含关联统计) */
|
||||
export interface WarehouseDetail extends WarehouseItem {
|
||||
stats: WarehouseStats
|
||||
}
|
||||
|
||||
export interface WarehousePayload {
|
||||
/** 仓库编码由后端自动生成(WH 前缀),无需传入 */
|
||||
code?: string
|
||||
name: string
|
||||
type?: string | null
|
||||
status?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
export function getWarehouses(params?: object) {
|
||||
return get<{ list: WarehouseItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/warehouses',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 仓库详情(含接口配置、入库/出库单关联统计) */
|
||||
export function getWarehouse(id: number) {
|
||||
return get<WarehouseDetail>(`/warehouses/${id}`)
|
||||
}
|
||||
|
||||
/** 下拉用:仅返回启用仓库 */
|
||||
export function getWarehouseOptions() {
|
||||
return get<WarehouseOption[]>('/warehouses/select')
|
||||
}
|
||||
|
||||
export function createWarehouse(data: WarehousePayload) {
|
||||
return post<{ id: number }>('/warehouses', data)
|
||||
}
|
||||
|
||||
export function updateWarehouse(id: number, data: Partial<WarehousePayload>) {
|
||||
return put<{ id: number }>(`/warehouses/${id}`, data)
|
||||
}
|
||||
|
||||
export function deleteWarehouse(id: number) {
|
||||
return del<{ id: number }>(`/warehouses/${id}`)
|
||||
}
|
||||
|
||||
/** 仓库下的商品行:商品基础字段 + 该仓库的推送状态(来自仓库-商品关联表) */
|
||||
export interface WarehouseProductItem {
|
||||
id: number
|
||||
item_code: string
|
||||
goods_code: string | null
|
||||
item_name: string
|
||||
sku_property: string | null
|
||||
barcode: string | null
|
||||
image: string | null
|
||||
status: number
|
||||
/** 是否已推送到该仓库,未建立关联时为 false */
|
||||
pushed: boolean
|
||||
/** 最近一次推送时间,未推送为 null */
|
||||
pushed_at: string | null
|
||||
/** WMS 内部商品ID(singleitem.synchronize 返回),未推送/未记录为 null */
|
||||
wms_item_id?: number | null
|
||||
/** 正品库存(副表 product_stocks) */
|
||||
good_quantity: number
|
||||
good_lock_quantity: number
|
||||
good_available: number
|
||||
/** 残次品库存(副表 product_stocks) */
|
||||
defect_quantity: number
|
||||
defect_lock_quantity: number
|
||||
defect_available: number
|
||||
}
|
||||
|
||||
/** 仓库下的商品列表(分页,含是否已推送状态) */
|
||||
export function getWarehouseProducts(id: number, params?: object) {
|
||||
return get<{ list: WarehouseProductItem[]; total: number; page: number; pageSize: number }>(
|
||||
`/warehouses/${id}/products`,
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 批量推送商品到仓库 WMS,返回逐条汇总结果 */
|
||||
export function pushWarehouseProducts(
|
||||
id: number,
|
||||
productIds: number[],
|
||||
) {
|
||||
return post<{ total: number; success: number; failed: number; results: Array<{ product_id: number; item_code?: string; success: boolean; message: string }> }>(
|
||||
`/warehouses/${id}/products/push`,
|
||||
{ product_ids: productIds },
|
||||
)
|
||||
}
|
||||
|
||||
/** 单个商品的 WMS 库存信息(inventory.query 返回),按正品 / 残次品拆分 */
|
||||
export interface WarehouseProductWmsInventoryItem {
|
||||
item_id: number
|
||||
good_quantity: number
|
||||
good_lock_quantity: number
|
||||
good_available: number
|
||||
defect_quantity: number
|
||||
defect_lock_quantity: number
|
||||
defect_available: number
|
||||
}
|
||||
|
||||
/** 键为 OMS 商品ID,值为该商品在 WMS 的库存信息 */
|
||||
export type WarehouseProductWmsInventory = Record<number, WarehouseProductWmsInventoryItem>
|
||||
|
||||
/** 批量查询该仓库商品的 WMS 外部库存数量,productIds 不传则查该仓库全部已推送商品 */
|
||||
export function getWarehouseProductWmsInventory(id: number, productIds?: number[]) {
|
||||
return post<{ inventories: WarehouseProductWmsInventory }>(
|
||||
`/warehouses/${id}/products/wms-inventory`,
|
||||
productIds && productIds.length ? { product_ids: productIds } : {},
|
||||
)
|
||||
}
|
||||
|
||||
/** 库存同步(覆盖本地数量)请求项,按正品 / 残次品分别给出 WMS 目标值 */
|
||||
export interface InventorySyncItem {
|
||||
product_id: number
|
||||
/** 外部 WMS 正品库存数量(目标值) */
|
||||
wms_good_quantity: number
|
||||
/** 外部 WMS 残次品库存数量(目标值) */
|
||||
wms_defect_quantity: number
|
||||
}
|
||||
|
||||
/** 库存同步:用外部 WMS 库存覆盖系统库存,差异以完成的出入库单平衡 */
|
||||
export function syncWarehouseInventory(id: number, items: InventorySyncItem[]) {
|
||||
return post<{ inbound_count: number; outbound_count: number; skipped: number }>(
|
||||
`/warehouses/${id}/inventory/sync`,
|
||||
{ items },
|
||||
)
|
||||
}
|
||||
123
frontend/src/api/warehouseApi.ts
Normal file
123
frontend/src/api/warehouseApi.ts
Normal file
@ -0,0 +1,123 @@
|
||||
import { get, post, put, del } from '@/utils/request'
|
||||
|
||||
/** 仓库接口配置(一个仓库可有多条) */
|
||||
export interface WarehouseApiItem {
|
||||
id: number
|
||||
principal_id: number
|
||||
warehouse_id: number
|
||||
name: string
|
||||
/** 接口类型:固定 qimen(类奇门JSON接口),当前系统仅支持这一种 */
|
||||
type: string | null
|
||||
base_url: string | null
|
||||
app_key: string | null
|
||||
app_secret: string | null
|
||||
/** 对外通用回调接口地址(POST /openapi),外部系统据此回调 OMS */
|
||||
callback_url?: string | null
|
||||
extra?: Record<string, unknown> | null
|
||||
status: number
|
||||
remark: string | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
/** 列表接口 include 带回的仓库 */
|
||||
warehouse?: { id: number; code: string; name: string } | null
|
||||
}
|
||||
|
||||
export interface WarehouseApiPayload {
|
||||
warehouse_id: number
|
||||
name: string
|
||||
/** 接口类型,固定传 qimen(类奇门JSON接口),服务端亦会固定写入 */
|
||||
type?: string | null
|
||||
base_url?: string | null
|
||||
app_key?: string | null
|
||||
app_secret?: string | null
|
||||
extra?: Record<string, unknown> | null
|
||||
status?: number
|
||||
remark?: string | null
|
||||
}
|
||||
|
||||
/** 接口配置项的类型枚举(与后端 app/lib/warehouseApiFields.js 保持一致) */
|
||||
export type WarehouseApiFieldType = 'text' | 'textarea' | 'number' | 'switch' | 'select' | 'password' | 'json'
|
||||
|
||||
export interface WarehouseApiFieldOption {
|
||||
label: string
|
||||
value: string
|
||||
}
|
||||
|
||||
/** 配置项分组(后端硬编码,前端按组渲染小标题) */
|
||||
export interface WarehouseApiFieldGroup {
|
||||
key: string
|
||||
label: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
/** 配置项定义(后端硬编码,前端按 group 分组、按 type 渲染表单控件) */
|
||||
export interface WarehouseApiFieldDef {
|
||||
key: string
|
||||
/** 所属分组标识(WarehouseApiFieldGroup.key) */
|
||||
group?: string
|
||||
label: string
|
||||
type: WarehouseApiFieldType
|
||||
required?: boolean
|
||||
defaultValue?: unknown
|
||||
options?: WarehouseApiFieldOption[]
|
||||
min?: number
|
||||
max?: number
|
||||
placeholder?: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
/** 配置项值:{ 字段key: 值 } */
|
||||
export type WarehouseApiFieldValues = Record<string, unknown>
|
||||
|
||||
/** 配置项分组、定义与类型枚举(硬编码,无需主体) */
|
||||
export function getWarehouseApiFields() {
|
||||
return get<{
|
||||
types: WarehouseApiFieldType[]
|
||||
groups: WarehouseApiFieldGroup[]
|
||||
fields: WarehouseApiFieldDef[]
|
||||
}>('/warehouse-api-fields')
|
||||
}
|
||||
|
||||
/** 查询某条接口配置的配置项值 */
|
||||
export function getWarehouseApiFieldValues(id: number) {
|
||||
return get<{ api_id: number; values: WarehouseApiFieldValues }>(`/warehouse-apis/${id}/fields`)
|
||||
}
|
||||
|
||||
/** 保存某条接口配置的配置项值(整体覆盖,按字段类型校验) */
|
||||
export function updateWarehouseApiFieldValues(id: number, values: WarehouseApiFieldValues) {
|
||||
return put<{ api_id: number }>(`/warehouse-apis/${id}/fields`, { values })
|
||||
}
|
||||
|
||||
/** 仓库接口配置列表(按 warehouse_id 过滤,principal_id 由请求拦截器自动注入) */
|
||||
export function getWarehouseApis(params?: object) {
|
||||
return get<{ list: WarehouseApiItem[]; total: number; page: number; pageSize: number }>(
|
||||
'/warehouse-apis',
|
||||
params,
|
||||
)
|
||||
}
|
||||
|
||||
/** 新增仓库接口配置 */
|
||||
export function createWarehouseApi(data: WarehouseApiPayload) {
|
||||
return post<{ id: number }>('/warehouse-apis', data)
|
||||
}
|
||||
|
||||
/** 更新仓库接口配置 */
|
||||
export function updateWarehouseApi(id: number, data: Partial<WarehouseApiPayload>) {
|
||||
return put<{ id: number }>(`/warehouse-apis/${id}`, data)
|
||||
}
|
||||
|
||||
/** 删除仓库接口配置 */
|
||||
export function deleteWarehouseApi(id: number) {
|
||||
return del<{ id: number }>(`/warehouse-apis/${id}`)
|
||||
}
|
||||
|
||||
/** 测试接口连通性(调用 WMS index.ping),返回 { ok, code?, message?, error?, wms? } */
|
||||
export function testWarehouseApi(id: number) {
|
||||
return post<{
|
||||
ok: boolean
|
||||
code?: number
|
||||
message?: string
|
||||
error?: string
|
||||
wms?: object
|
||||
}>(`/warehouse-apis/${id}/test`)
|
||||
}
|
||||
94
frontend/src/components/DataTable.vue
Normal file
94
frontend/src/components/DataTable.vue
Normal file
@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 列表统一表格组件
|
||||
* - 统一封装 el-table:默认 border / stripe / size="small",并统一压低行高与字号
|
||||
* - 常用透传项(height / highlight-current-row / @row-click)已显式声明,
|
||||
* 其余未声明属性与事件仍通过 $attrs 透传给 el-table
|
||||
* - 列定义依旧使用 el-table-column,直接写在默认插槽中
|
||||
*/
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
data?: any[]
|
||||
loading?: boolean
|
||||
size?: 'large' | 'default' | 'small'
|
||||
border?: boolean
|
||||
stripe?: boolean
|
||||
/** 固定表头高度,如 "100%",对齐 el-table 的 height */
|
||||
height?: string | number
|
||||
/** 高亮当前行 */
|
||||
highlightCurrentRow?: boolean
|
||||
}>(),
|
||||
{
|
||||
data: () => [],
|
||||
loading: false,
|
||||
size: 'small',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightCurrentRow: false,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
rowClick: [row: any, column: any, event: Event]
|
||||
}>()
|
||||
|
||||
function onRowClick(row: any, column: any, event: Event) {
|
||||
emit('rowClick', row, column, event)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="data"
|
||||
:size="size"
|
||||
:border="border"
|
||||
:stripe="stripe"
|
||||
:height="height"
|
||||
:highlight-current-row="highlightCurrentRow"
|
||||
class="data-table"
|
||||
v-bind="$attrs"
|
||||
@row-click="onRowClick"
|
||||
>
|
||||
<slot />
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 统一压缩行高与字号,让列表更紧凑 */
|
||||
.data-table {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 表头 */
|
||||
.data-table :deep(.el-table__header-wrapper th.el-table__cell) {
|
||||
padding: 6px 0;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 数据行 */
|
||||
.data-table :deep(.el-table__body-wrapper td.el-table__cell) {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
/* 单元格内容 */
|
||||
.data-table :deep(.cell) {
|
||||
padding: 0 8px;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
/* 操作列按钮跟随单元格字号 */
|
||||
.data-table :deep(.el-button) {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 空数据提示 */
|
||||
.data-table :deep(.el-table__empty-text) {
|
||||
font-size: 12px;
|
||||
line-height: 40px;
|
||||
}
|
||||
</style>
|
||||
240
frontend/src/components/FieldValueForm.vue
Normal file
240
frontend/src/components/FieldValueForm.vue
Normal file
@ -0,0 +1,240 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import type { FormItemRule } from 'element-plus'
|
||||
import type { WarehouseApiFieldDef, WarehouseApiFieldGroup } from '@/api/warehouseApi'
|
||||
|
||||
/**
|
||||
* 按字段定义(含分组与类型枚举)动态渲染表单控件,值双向绑定为 { 字段key: 值 }
|
||||
* 分组:按 groups 顺序渲染小标题(未在 groups 中声明的 group 追加在后)
|
||||
* 类型映射:text/password/textarea/json -> el-input;number -> el-input-number;
|
||||
* switch -> el-switch;select -> el-select(选项来自字段定义 options)
|
||||
* 分组、字段清单与类型由后端硬编码(app/lib/warehouseApiFields.js),前端不写死
|
||||
*/
|
||||
const props = defineProps<{
|
||||
/** 字段分组列表,来自 /warehouse-api-fields */
|
||||
groups?: WarehouseApiFieldGroup[]
|
||||
/** 字段定义列表,来自 /warehouse-api-fields */
|
||||
fields: WarehouseApiFieldDef[]
|
||||
/** 字段值:{ 字段key: 值 } */
|
||||
modelValue: Record<string, unknown>
|
||||
}>()
|
||||
|
||||
/** 按 groups 顺序把字段分组,groups 未覆盖的 group 按字段出现顺序追加 */
|
||||
const groupedFields = computed(() => {
|
||||
const order: WarehouseApiFieldGroup[] = [...(props.groups || [])]
|
||||
const knownKeys = new Set(order.map(group => group.key))
|
||||
for (const field of props.fields) {
|
||||
const key = field.group || ''
|
||||
if (knownKeys.has(key)) continue
|
||||
knownKeys.add(key)
|
||||
order.push({ key, label: key || '其他' })
|
||||
}
|
||||
return order
|
||||
.map(group => ({
|
||||
...group,
|
||||
fields: props.fields.filter(field => (field.group || '') === group.key),
|
||||
}))
|
||||
.filter(group => group.fields.length > 0)
|
||||
})
|
||||
|
||||
/** 把分组说明中的 http(s) 地址拆出来,渲染为可点击链接 */
|
||||
function descParts(text: string): { text: string; href?: string }[] {
|
||||
const parts: { text: string; href?: string }[] = []
|
||||
const pattern = /(https?:\/\/[^\s,。;]+)/g
|
||||
let last = 0
|
||||
let matched = pattern.exec(text)
|
||||
while (matched) {
|
||||
if (matched.index > last) parts.push({ text: text.slice(last, matched.index) })
|
||||
parts.push({ text: matched[1], href: matched[1] })
|
||||
last = matched.index + matched[1].length
|
||||
matched = pattern.exec(text)
|
||||
}
|
||||
if (last < text.length) parts.push({ text: text.slice(last) })
|
||||
return parts
|
||||
}
|
||||
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', value: Record<string, unknown>): void }>()
|
||||
|
||||
function setValue(key: string, value: unknown) {
|
||||
emit('update:modelValue', { ...props.modelValue, [key]: value })
|
||||
}
|
||||
|
||||
function asText(key: string): string {
|
||||
const value = props.modelValue[key]
|
||||
if (value === undefined || value === null) return ''
|
||||
if (typeof value === 'object') return JSON.stringify(value, null, 2)
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function asNumber(key: string): number | undefined {
|
||||
const value = props.modelValue[key]
|
||||
if (value === undefined || value === null || value === '') return undefined
|
||||
const num = Number(value)
|
||||
return Number.isFinite(num) ? num : undefined
|
||||
}
|
||||
|
||||
function asBoolean(key: string): boolean {
|
||||
const value = props.modelValue[key]
|
||||
return value === true || value === 1 || value === '1' || value === 'true'
|
||||
}
|
||||
|
||||
/** 按字段定义生成校验规则:必填 + JSON 格式 */
|
||||
function rulesOf(field: WarehouseApiFieldDef): FormItemRule[] {
|
||||
const rules: FormItemRule[] = []
|
||||
if (field.required) {
|
||||
rules.push({
|
||||
required: true,
|
||||
message: field.type === 'select' ? `请选择${field.label}` : `请输入${field.label}`,
|
||||
trigger: field.type === 'select' || field.type === 'switch' ? 'change' : 'blur',
|
||||
})
|
||||
}
|
||||
if (field.type === 'json') {
|
||||
rules.push({
|
||||
validator: (_rule: unknown, value: unknown, callback: (error?: Error) => void) => {
|
||||
if (value === undefined || value === null || value === '') return callback()
|
||||
try {
|
||||
JSON.parse(String(value))
|
||||
callback()
|
||||
} catch {
|
||||
callback(new Error(`${field.label}需为合法的 JSON`))
|
||||
}
|
||||
},
|
||||
trigger: 'blur',
|
||||
})
|
||||
}
|
||||
return rules
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-for="group in groupedFields" :key="group.key" class="field-group">
|
||||
<div class="group-title">{{ group.label }}</div>
|
||||
<div v-if="group.description" class="group-hint">
|
||||
<template v-for="(part, index) in descParts(group.description)" :key="index">
|
||||
<a v-if="part.href" :href="part.href" target="_blank" rel="noopener">{{ part.text }}</a>
|
||||
<span v-else>{{ part.text }}</span>
|
||||
</template>
|
||||
</div>
|
||||
<el-form-item
|
||||
v-for="field in group.fields"
|
||||
:key="field.key"
|
||||
:label="field.label"
|
||||
:prop="field.key"
|
||||
:rules="rulesOf(field)"
|
||||
class="field-item"
|
||||
>
|
||||
<div class="field-control">
|
||||
<el-input
|
||||
v-if="field.type === 'text'"
|
||||
:model-value="asText(field.key)"
|
||||
:placeholder="field.placeholder || '请输入'"
|
||||
clearable
|
||||
@update:model-value="(v: string) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-input
|
||||
v-else-if="field.type === 'password'"
|
||||
:model-value="asText(field.key)"
|
||||
type="password"
|
||||
show-password
|
||||
:placeholder="field.placeholder || '请输入'"
|
||||
@update:model-value="(v: string) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-input
|
||||
v-else-if="field.type === 'textarea'"
|
||||
:model-value="asText(field.key)"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
:placeholder="field.placeholder || '请输入'"
|
||||
@update:model-value="(v: string) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-input
|
||||
v-else-if="field.type === 'json'"
|
||||
:model-value="asText(field.key)"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder='JSON 对象,如 {"warehouse":"SH01"}'
|
||||
@update:model-value="(v: string) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-input-number
|
||||
v-else-if="field.type === 'number'"
|
||||
:model-value="asNumber(field.key)"
|
||||
:min="field.min"
|
||||
:max="field.max"
|
||||
controls-position="right"
|
||||
class="field-number"
|
||||
@update:model-value="(v: number | undefined) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-switch
|
||||
v-else-if="field.type === 'switch'"
|
||||
:model-value="asBoolean(field.key)"
|
||||
@update:model-value="(v: boolean) => setValue(field.key, v)"
|
||||
/>
|
||||
<el-select
|
||||
v-else-if="field.type === 'select'"
|
||||
:model-value="asText(field.key)"
|
||||
:placeholder="field.placeholder || '请选择'"
|
||||
clearable
|
||||
class="field-select"
|
||||
@update:model-value="(v: string) => setValue(field.key, v)"
|
||||
>
|
||||
<el-option
|
||||
v-for="option in field.options || []"
|
||||
:key="option.value"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
<div v-if="field.description" class="field-hint">{{ field.description }}</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.field-group + .field-group {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.group-title {
|
||||
font-weight: 600;
|
||||
font-size: 13px;
|
||||
color: var(--el-text-color-primary);
|
||||
padding-bottom: 4px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 1px solid var(--el-border-color-lighter);
|
||||
}
|
||||
|
||||
.group-hint {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
margin: -4px 0 10px;
|
||||
}
|
||||
|
||||
.group-hint a {
|
||||
color: var(--el-color-primary);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* 长标签字段(如「已有物流单号的销售单,递交仓库发货时清空物流单号再进行递交」)标签换行展示 */
|
||||
.field-item :deep(.el-form-item__label) {
|
||||
line-height: 1.4;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
.field-control {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.field-number,
|
||||
.field-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.field-hint {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
margin-top: 2px;
|
||||
}
|
||||
</style>
|
||||
251
frontend/src/components/ImageUploader.vue
Normal file
251
frontend/src/components/ImageUploader.vue
Normal file
@ -0,0 +1,251 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { checkFiles, hashFile, uploadFile, type FileItem } from '@/api/file'
|
||||
|
||||
/** el-upload 自定义上传回调参数(仅用到 file / onProgress / onSuccess / onError) */
|
||||
interface UploadRequestOptions {
|
||||
file: File
|
||||
onProgress?: (event: { percent: number }) => void
|
||||
onSuccess?: (response: FileItem) => void
|
||||
onError?: (error: Error) => void
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: string[]
|
||||
/** 最多上传张数 */
|
||||
limit?: number
|
||||
/** 单张大小上限(MB) */
|
||||
maxSize?: number
|
||||
disabled?: boolean
|
||||
/** 自定义底部提示文案 */
|
||||
tip?: string
|
||||
}>(),
|
||||
{ limit: 10, maxSize: 20, disabled: false, tip: '' },
|
||||
)
|
||||
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', value: string[]): void }>()
|
||||
|
||||
// 本地维护一份副本:多张图片并发上传完成时不会互相覆盖
|
||||
const urls = ref<string[]>([])
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
urls.value = Array.isArray(value) ? [ ...value ] : []
|
||||
},
|
||||
{ immediate: true, deep: true },
|
||||
)
|
||||
|
||||
const uploading = ref(false)
|
||||
const percent = ref(0)
|
||||
|
||||
function update() {
|
||||
emit('update:modelValue', [ ...urls.value ])
|
||||
}
|
||||
|
||||
function addUrl(url: string) {
|
||||
if (!url || urls.value.includes(url)) return
|
||||
urls.value.push(url)
|
||||
update()
|
||||
}
|
||||
|
||||
function removeAt(index: number) {
|
||||
urls.value.splice(index, 1)
|
||||
update()
|
||||
}
|
||||
|
||||
/** 设为主图(列表首张):商品主图取 images[0] */
|
||||
function setCover(index: number) {
|
||||
if (index === 0) return
|
||||
const [ url ] = urls.value.splice(index, 1)
|
||||
urls.value.unshift(url)
|
||||
update()
|
||||
}
|
||||
|
||||
function beforeUpload(file: File) {
|
||||
if (props.disabled) return false
|
||||
if (urls.value.length >= props.limit) {
|
||||
ElMessage.warning(`最多上传 ${props.limit} 张图片`)
|
||||
return false
|
||||
}
|
||||
if (!file.type.startsWith('image/')) {
|
||||
ElMessage.warning('只能上传图片文件')
|
||||
return false
|
||||
}
|
||||
if (file.size > props.maxSize * 1024 * 1024) {
|
||||
ElMessage.warning(`单张图片不能超过 ${props.maxSize}MB`)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义上传:先用浏览器本地 SHA256 查验,命中已有文件直接复用 URL(无需上传);
|
||||
* 未命中才真正上传,服务端还会再按 hash 去重一次
|
||||
*/
|
||||
async function handleRequest(options: UploadRequestOptions) {
|
||||
uploading.value = true
|
||||
percent.value = 0
|
||||
try {
|
||||
const hash = await hashFile(options.file)
|
||||
if (hash) {
|
||||
const hits = await checkFiles([ hash ])
|
||||
if (hits.length) {
|
||||
addUrl(hits[0].url)
|
||||
ElMessage.success('图片已存在,直接复用')
|
||||
options.onSuccess?.(hits[0])
|
||||
return
|
||||
}
|
||||
}
|
||||
const saved = await uploadFile(options.file, (value) => {
|
||||
percent.value = value
|
||||
options.onProgress?.({ percent: value })
|
||||
})
|
||||
addUrl(saved.url)
|
||||
options.onSuccess?.(saved)
|
||||
} catch (err) {
|
||||
options.onError?.(err as Error)
|
||||
} finally {
|
||||
uploading.value = false
|
||||
percent.value = 0
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="image-uploader">
|
||||
<div class="image-grid">
|
||||
<div v-for="(url, index) in urls" :key="`${url}-${index}`" class="image-item">
|
||||
<el-image
|
||||
:src="url"
|
||||
fit="cover"
|
||||
:preview-src-list="urls"
|
||||
:initial-index="index"
|
||||
preview-teleported
|
||||
/>
|
||||
<span v-if="index === 0" class="cover-tag">主图</span>
|
||||
<div v-if="!disabled" class="image-actions">
|
||||
<el-tooltip v-if="index !== 0" content="设为主图" placement="top">
|
||||
<el-icon @click.stop="setCover(index)"><Star /></el-icon>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="移除" placement="top">
|
||||
<el-icon @click.stop="removeAt(index)"><Delete /></el-icon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-upload
|
||||
v-if="!disabled && urls.length < limit"
|
||||
class="image-add"
|
||||
:show-file-list="false"
|
||||
accept="image/*"
|
||||
:before-upload="beforeUpload"
|
||||
:http-request="handleRequest"
|
||||
>
|
||||
<div class="image-add-inner">
|
||||
<el-icon v-if="uploading" class="is-loading"><Loading /></el-icon>
|
||||
<el-icon v-else><Plus /></el-icon>
|
||||
<span>{{ uploading ? `上传中 ${percent}%` : '上传图片' }}</span>
|
||||
</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
|
||||
<div class="image-tip">
|
||||
{{ tip || `最多 ${limit} 张,单张不超过 ${maxSize}MB;内容相同的图片自动复用,不会重复上传` }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.image-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.image-item :deep(.el-image) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.cover-tag {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
padding: 0 6px;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #fff;
|
||||
background: var(--el-color-primary);
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
|
||||
.image-actions {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
padding: 2px 0;
|
||||
color: #fff;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.image-item:hover .image-actions {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.image-actions .el-icon {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.image-add :deep(.el-upload) {
|
||||
width: 96px;
|
||||
height: 96px;
|
||||
border: 1px dashed var(--el-border-color);
|
||||
border-radius: 4px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.image-add :deep(.el-upload:hover) {
|
||||
border-color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.image-add-inner {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.image-add-inner .el-icon {
|
||||
font-size: 22px;
|
||||
}
|
||||
|
||||
.image-tip {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
</style>
|
||||
140
frontend/src/components/ListPager.vue
Normal file
140
frontend/src/components/ListPager.vue
Normal file
@ -0,0 +1,140 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 列表统一分页组件
|
||||
* - 统计(共 N 条 + 请求用时)与上一页/下一页按钮统一使用中文,不依赖 Element Plus 语言包
|
||||
* - 每页条数下拉自绘 el-select,选项只显示纯数字(默认的“10条/页”文案已去掉)
|
||||
* - 整体字号在 Element Plus 基准 14px 上减少 30%
|
||||
* - 其余属性经 $attrs 透传给 el-pagination(如 size、pager-count、hide-on-single-page)
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import { DEFAULT_PAGE_SIZE, PAGE_SIZES } from '@/composables/useListPage'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 总条数 */
|
||||
total?: number
|
||||
/** 当前页码(受控) */
|
||||
page?: number
|
||||
/** 每页条数 */
|
||||
pageSize?: number
|
||||
/** 每页条数可选项 */
|
||||
pageSizes?: number[]
|
||||
/** 分页布局:每页条数已由组件自绘,layout 中无需再声明 sizes */
|
||||
layout?: string
|
||||
/** 最近一次列表请求用时(毫秒),为空时不展示 */
|
||||
elapsed?: number | null
|
||||
}>(),
|
||||
{
|
||||
total: 0,
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
pageSizes: () => [ ...PAGE_SIZES ],
|
||||
layout: 'prev, pager, next',
|
||||
elapsed: null,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
pageChange: [page: number]
|
||||
sizeChange: [pageSize: number]
|
||||
}>()
|
||||
|
||||
/** 请求用时文案:1 秒内按毫秒展示,超过按秒展示(保留两位小数) */
|
||||
const elapsedText = computed(() => {
|
||||
const ms = props.elapsed
|
||||
if (ms === null || ms === undefined) return ''
|
||||
return ms < 1000 ? `${ms} ms` : `${(ms / 1000).toFixed(2)} s`
|
||||
})
|
||||
|
||||
function onChange(page: number) {
|
||||
emit('pageChange', page)
|
||||
}
|
||||
|
||||
function onSizeChange(pageSize: number | string) {
|
||||
emit('sizeChange', Number(pageSize))
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="list-pager">
|
||||
<span class="list-pager__summary">
|
||||
共 {{ props.total }} 条
|
||||
<span v-if="elapsedText" class="list-pager__elapsed">· 请求用时 {{ elapsedText }}</span>
|
||||
</span>
|
||||
|
||||
<el-select
|
||||
class="list-pager__size"
|
||||
size="small"
|
||||
:model-value="props.pageSize"
|
||||
popper-class="list-pager__size-popper"
|
||||
@change="onSizeChange"
|
||||
>
|
||||
<el-option v-for="size in props.pageSizes" :key="size" :label="String(size)" :value="size" />
|
||||
</el-select>
|
||||
|
||||
<el-pagination
|
||||
class="list-pager__pagination"
|
||||
background
|
||||
:layout="props.layout"
|
||||
:total="props.total"
|
||||
:page-size="props.pageSize"
|
||||
:current-page="props.page"
|
||||
prev-text="上一页"
|
||||
next-text="下一页"
|
||||
v-bind="$attrs"
|
||||
@current-change="onChange"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.list-pager {
|
||||
/* 分页整体字号:12px */
|
||||
--list-pager-font-size: 12px;
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
margin-top: 12px;
|
||||
font-size: var(--list-pager-font-size);
|
||||
}
|
||||
|
||||
.list-pager__summary {
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
|
||||
.list-pager__elapsed {
|
||||
margin-left: 4px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.list-pager__size {
|
||||
width: 76px;
|
||||
font-size: var(--list-pager-font-size);
|
||||
}
|
||||
|
||||
/* el-select 内部默认写死 14px,需要显式覆盖 */
|
||||
.list-pager__size :deep(.el-select__wrapper) {
|
||||
font-size: var(--list-pager-font-size);
|
||||
}
|
||||
|
||||
/* 页码/上一页/下一页的字号取自该变量(EP 默认在分页根节点上写死 14px) */
|
||||
.list-pager .list-pager__pagination {
|
||||
--el-pagination-font-size: var(--list-pager-font-size);
|
||||
/* 行高更小的紧凑分页 */
|
||||
--el-pagination-button-height: 24px;
|
||||
--el-pagination-button-width: 28px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
/* 每页条数下拉挂载在 body 上,无法使用 scoped,这里用独立的 popper-class 限定作用范围 */
|
||||
.list-pager__size-popper .el-select-dropdown__item {
|
||||
font-size: 12px;
|
||||
line-height: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
</style>
|
||||
232
frontend/src/components/ProductSelect.vue
Normal file
232
frontend/src/components/ProductSelect.vue
Normal file
@ -0,0 +1,232 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import {
|
||||
getProducts,
|
||||
searchProducts,
|
||||
type ProductItem,
|
||||
type ProductSearchItem,
|
||||
} from '@/api/product'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: number | null
|
||||
placeholder?: string
|
||||
disabled?: boolean
|
||||
/** 已选中但选项尚未加载(如编辑回显)时用于展示的标签 */
|
||||
modelLabel?: string
|
||||
}>(),
|
||||
{
|
||||
placeholder: '搜索并选择商品',
|
||||
disabled: false,
|
||||
modelLabel: '',
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: number | null]
|
||||
select: [product: ProductSearchItem]
|
||||
}>()
|
||||
|
||||
const options = ref<ProductSearchItem[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
async function remoteMethod(keyword: string) {
|
||||
loading.value = true
|
||||
try {
|
||||
options.value = await searchProducts(keyword || '')
|
||||
} catch {
|
||||
options.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 已选中但选项未加载(编辑回显)时,用 modelLabel 合成一个兜底选项
|
||||
const selectOptions = computed(() => {
|
||||
const list = [...options.value]
|
||||
if (
|
||||
props.modelValue != null &&
|
||||
!list.some((o) => o.id === props.modelValue) &&
|
||||
props.modelLabel
|
||||
) {
|
||||
list.push({
|
||||
id: props.modelValue,
|
||||
item_code: '',
|
||||
item_name: props.modelLabel,
|
||||
goods_code: null,
|
||||
barcode: null,
|
||||
sku_property: null,
|
||||
stock_unit: null,
|
||||
status: 1,
|
||||
})
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
function optLabel(p: ProductSearchItem) {
|
||||
return p.item_code ? `${p.item_code} ${p.item_name}` : p.item_name
|
||||
}
|
||||
|
||||
function onChange(val: number | null) {
|
||||
emit('update:modelValue', val)
|
||||
if (val != null) {
|
||||
const p = options.value.find((x) => x.id === val)
|
||||
if (p) emit('select', p)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 查询弹窗(可翻页浏览) -------------------- */
|
||||
const pickerVisible = ref(false)
|
||||
const searchKey = ref('')
|
||||
const pickerLoading = ref(false)
|
||||
const pickerList = ref<ProductItem[]>([])
|
||||
const pickerTotal = ref(0)
|
||||
const pickerPage = ref(1)
|
||||
const pickerPageSize = ref(10)
|
||||
|
||||
async function openPicker() {
|
||||
pickerVisible.value = true
|
||||
searchKey.value = ''
|
||||
pickerPage.value = 1
|
||||
await fetchPicker()
|
||||
}
|
||||
async function fetchPicker() {
|
||||
pickerLoading.value = true
|
||||
try {
|
||||
const res = await getProducts({
|
||||
page: pickerPage.value,
|
||||
pageSize: pickerPageSize.value,
|
||||
keyword: searchKey.value || undefined,
|
||||
status: 1,
|
||||
})
|
||||
pickerList.value = res.list
|
||||
pickerTotal.value = res.total
|
||||
} catch {
|
||||
pickerList.value = []
|
||||
} finally {
|
||||
pickerLoading.value = false
|
||||
}
|
||||
}
|
||||
function onPickerSearch() {
|
||||
pickerPage.value = 1
|
||||
fetchPicker()
|
||||
}
|
||||
function onPickerPageChange(page: number) {
|
||||
pickerPage.value = page
|
||||
fetchPicker()
|
||||
}
|
||||
function pickProduct(row: ProductItem) {
|
||||
const mapped: ProductSearchItem = {
|
||||
id: row.id,
|
||||
item_code: row.item_code,
|
||||
goods_code: row.goods_code,
|
||||
barcode: row.barcode,
|
||||
item_name: row.item_name,
|
||||
sku_property: row.sku_property,
|
||||
stock_unit: row.stock_unit,
|
||||
status: row.status,
|
||||
}
|
||||
if (!options.value.some((o) => o.id === row.id)) options.value.push(mapped)
|
||||
emit('update:modelValue', row.id)
|
||||
emit('select', mapped)
|
||||
pickerVisible.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="product-select">
|
||||
<el-select
|
||||
:model-value="modelValue"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:remote-method="remoteMethod"
|
||||
:loading="loading"
|
||||
:disabled="disabled"
|
||||
:placeholder="placeholder"
|
||||
class="product-select__input"
|
||||
@update:model-value="onChange"
|
||||
>
|
||||
<el-option v-for="p in selectOptions" :key="p.id" :label="optLabel(p)" :value="p.id" />
|
||||
</el-select>
|
||||
<el-button size="small" :disabled="disabled" @click="openPicker">查询</el-button>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="pickerVisible" title="商品查询" width="760px" append-to-body>
|
||||
<el-form :inline="true" class="picker-search">
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="searchKey"
|
||||
placeholder="商品编码 / 名称 / 货物编码 / 条码"
|
||||
clearable
|
||||
style="width: 280px"
|
||||
@keyup.enter="onPickerSearch"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="onPickerSearch">查询</el-button>
|
||||
<el-button @click="searchKey = ''; onPickerSearch()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table
|
||||
:data="pickerList"
|
||||
v-loading="pickerLoading"
|
||||
height="360"
|
||||
size="small"
|
||||
highlight-current-row
|
||||
@row-dblclick="pickProduct"
|
||||
>
|
||||
<el-table-column prop="item_code" label="商品编码" width="140" />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="160" />
|
||||
<el-table-column prop="sku_property" label="规格" width="140" />
|
||||
<el-table-column prop="stock_unit" label="单位" width="80" />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="80" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="pickProduct(row)">选择</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-pagination
|
||||
class="picker-pager"
|
||||
layout="prev, pager, next, total"
|
||||
:total="pickerTotal"
|
||||
:current-page="pickerPage"
|
||||
:page-size="pickerPageSize"
|
||||
@current-change="onPickerPageChange"
|
||||
/>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.product-select {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
}
|
||||
.product-select__input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.picker-search {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.picker-pager {
|
||||
margin-top: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
/* 弹窗(append-to-body 仍带组件 scope 属性,可用 :deep 命中) */
|
||||
.product-select :deep(.el-dialog__header) {
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.product-select :deep(.el-dialog__body) {
|
||||
padding: 4px 16px 14px;
|
||||
}
|
||||
</style>
|
||||
24
frontend/src/components/SideMenu.vue
Normal file
24
frontend/src/components/SideMenu.vue
Normal file
@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { defineOptions } from 'vue'
|
||||
import type { MenuItem } from '@/store/menu'
|
||||
|
||||
defineOptions({ name: 'SideMenu' })
|
||||
|
||||
defineProps<{ menus: MenuItem[] }>()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="m in menus" :key="m.id">
|
||||
<el-sub-menu v-if="m.type === 1 && m.children && m.children.length" :index="String(m.id)">
|
||||
<template #title>
|
||||
<el-icon v-if="m.icon"><component :is="m.icon" /></el-icon>
|
||||
<span>{{ m.name }}</span>
|
||||
</template>
|
||||
<SideMenu :menus="m.children" />
|
||||
</el-sub-menu>
|
||||
<el-menu-item v-else-if="m.type === 2" :index="m.path || String(m.id)">
|
||||
<el-icon v-if="m.icon"><component :is="m.icon" /></el-icon>
|
||||
<template #title>{{ m.name }}</template>
|
||||
</el-menu-item>
|
||||
</template>
|
||||
</template>
|
||||
184
frontend/src/components/SplitLayout.vue
Normal file
184
frontend/src/components/SplitLayout.vue
Normal file
@ -0,0 +1,184 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** vertical = 上下排列(中间横条);horizontal = 左右排列(中间竖条) */
|
||||
direction?: 'vertical' | 'horizontal'
|
||||
/** 第一块(上/左)初始尺寸,单位 px */
|
||||
firstSize?: number
|
||||
/** 第一块最小尺寸 px */
|
||||
minFirst?: number
|
||||
/** 第一块最大尺寸 px,默认取容器剩余 - 80 */
|
||||
maxFirst?: number
|
||||
/** 提供后把当前尺寸持久化到 localStorage,刷新后保留 */
|
||||
storageKey?: string
|
||||
/** 是否显示第二块(下/右)。为 false 时第一块占满整个容器 */
|
||||
showSecond?: boolean
|
||||
}>(),
|
||||
{
|
||||
direction: 'vertical',
|
||||
firstSize: 300,
|
||||
minFirst: 120,
|
||||
maxFirst: Number.POSITIVE_INFINITY,
|
||||
storageKey: '',
|
||||
showSecond: true,
|
||||
},
|
||||
)
|
||||
|
||||
const containerRef = ref<HTMLElement | null>(null)
|
||||
const firstSize = ref(props.firstSize)
|
||||
const dragging = ref(false)
|
||||
let startPos = 0
|
||||
let startSize = 0
|
||||
|
||||
if (props.storageKey) {
|
||||
const saved = Number(localStorage.getItem(props.storageKey))
|
||||
if (Number.isFinite(saved) && saved > 0) firstSize.value = saved
|
||||
}
|
||||
|
||||
watch(firstSize, (v) => {
|
||||
if (props.storageKey) localStorage.setItem(props.storageKey, String(Math.round(v)))
|
||||
})
|
||||
|
||||
const isVertical = () => props.direction === 'vertical'
|
||||
|
||||
const firstStyle = computed(() => {
|
||||
if (!props.showSecond) return {}
|
||||
return isVertical() ? { height: firstSize.value + 'px' } : { width: firstSize.value + 'px' }
|
||||
})
|
||||
|
||||
function clamp(v: number): number {
|
||||
const min = props.minFirst
|
||||
let max = props.maxFirst
|
||||
if (!Number.isFinite(max) && containerRef.value) {
|
||||
const total = isVertical() ? containerRef.value.clientHeight : containerRef.value.clientWidth
|
||||
max = Math.max(min, total - 80)
|
||||
}
|
||||
return Math.max(min, Math.min(max, v))
|
||||
}
|
||||
|
||||
function onDown(e: MouseEvent) {
|
||||
dragging.value = true
|
||||
startPos = isVertical() ? e.clientY : e.clientX
|
||||
startSize = firstSize.value
|
||||
window.addEventListener('mousemove', onMove)
|
||||
window.addEventListener('mouseup', onUp)
|
||||
document.body.style.cursor = isVertical() ? 'ns-resize' : 'ew-resize'
|
||||
document.body.style.userSelect = 'none'
|
||||
e.preventDefault()
|
||||
}
|
||||
function onMove(e: MouseEvent) {
|
||||
if (!dragging.value) return
|
||||
const cur = isVertical() ? e.clientY : e.clientX
|
||||
firstSize.value = clamp(startSize + (cur - startPos))
|
||||
}
|
||||
function onUp() {
|
||||
dragging.value = false
|
||||
window.removeEventListener('mousemove', onMove)
|
||||
window.removeEventListener('mouseup', onUp)
|
||||
document.body.style.cursor = ''
|
||||
document.body.style.userSelect = ''
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('mousemove', onMove)
|
||||
window.removeEventListener('mouseup', onUp)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="containerRef"
|
||||
class="split-layout"
|
||||
:class="[direction, { dragging, 'no-second': !showSecond }]"
|
||||
>
|
||||
<div class="split-panel split-first" :style="firstStyle">
|
||||
<slot name="first" />
|
||||
</div>
|
||||
|
||||
<template v-if="showSecond">
|
||||
<div
|
||||
class="split-divider"
|
||||
:class="{ dragging }"
|
||||
:title="isVertical() ? '拖拽调整上下高度' : '拖拽调整左右宽度'"
|
||||
@mousedown="onDown"
|
||||
>
|
||||
<span class="split-grip" />
|
||||
</div>
|
||||
|
||||
<div class="split-panel split-second">
|
||||
<slot name="second" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.split-layout {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.split-layout.vertical {
|
||||
flex-direction: column;
|
||||
}
|
||||
.split-layout.horizontal {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.split-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.split-first {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.split-layout.no-second .split-first {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
.split-second {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
|
||||
.split-divider {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: ns-resize;
|
||||
background: var(--el-fill-color-light);
|
||||
user-select: none;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
.split-layout.vertical .split-divider {
|
||||
height: 12px;
|
||||
margin: 6px 0;
|
||||
}
|
||||
.split-layout.horizontal .split-divider {
|
||||
width: 12px;
|
||||
margin: 0 6px;
|
||||
cursor: ew-resize;
|
||||
}
|
||||
.split-divider:hover,
|
||||
.split-divider.dragging {
|
||||
background: var(--el-color-primary-light-7);
|
||||
}
|
||||
|
||||
.split-grip {
|
||||
width: 100%;
|
||||
height: 4px;
|
||||
border-radius: 2px;
|
||||
background: var(--el-border-color);
|
||||
}
|
||||
.split-layout.horizontal .split-grip {
|
||||
width: 4px;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
41
frontend/src/components/VirtualSelect.vue
Normal file
41
frontend/src/components/VirtualSelect.vue
Normal file
@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 大数据量下拉选择(虚拟滚动)
|
||||
* - 基于 el-select-v2,只渲染可视区域内的选项,几百~上万条选项也不会卡顿
|
||||
* - 用法与 el-select 基本一致:把 el-option 列表换成 options,
|
||||
* 选项默认取 label / value 字段,原始对象可用 label-key / value-key 指定字段
|
||||
* - 其余属性与事件(placeholder / clearable / filterable / remote / @change 等)通过 $attrs 透传
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
|
||||
defineOptions({ inheritAttrs: false })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 选项列表,形如 [{ label, value }],也可直接传业务对象并配合 labelKey / valueKey */
|
||||
options?: any[]
|
||||
/** 选项文案字段,默认 label */
|
||||
labelKey?: string
|
||||
/** 选项值字段,默认 value */
|
||||
valueKey?: string
|
||||
}>(),
|
||||
{ options: () => [], labelKey: 'label', valueKey: 'value' },
|
||||
)
|
||||
|
||||
const list = computed(() =>
|
||||
(props.options || []).map((item) => {
|
||||
if (item === null || typeof item !== 'object') {
|
||||
return { label: String(item ?? ''), value: item }
|
||||
}
|
||||
return {
|
||||
label: String(item[props.labelKey] ?? ''),
|
||||
value: item[props.valueKey],
|
||||
disabled: Boolean(item.disabled),
|
||||
}
|
||||
}),
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-select-v2 v-bind="$attrs" :options="list" />
|
||||
</template>
|
||||
196
frontend/src/components/VirtualTable.vue
Normal file
196
frontend/src/components/VirtualTable.vue
Normal file
@ -0,0 +1,196 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 大列表虚拟滚动表格
|
||||
* - 基于 el-table-v2,只渲染可视区域内的行,几百~上万行依然流畅
|
||||
* - 需要放在具有确定高度的父容器里(默认铺满父容器高度,通过 ResizeObserver 自动跟随尺寸)
|
||||
* - 列通过 columns 配置(不再使用 el-table-column);单元格内容用与 column.slot 同名的插槽自定义,
|
||||
* 插槽参数为 { row, index, value }
|
||||
* - 视觉风格与 DataTable 保持一致:12px 字号、紧凑行高、边框、斑马纹
|
||||
*/
|
||||
import { computed, h, onBeforeUnmount, onMounted, ref, useSlots } from 'vue'
|
||||
import type { VirtualColumn } from './virtualTable'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
data?: any[]
|
||||
columns: VirtualColumn[]
|
||||
loading?: boolean
|
||||
/** 行高 px */
|
||||
rowHeight?: number
|
||||
/** 表头行高 px */
|
||||
headerHeight?: number
|
||||
/** 行唯一键 */
|
||||
rowKey?: string
|
||||
emptyText?: string
|
||||
/** 斑马纹 */
|
||||
stripe?: boolean
|
||||
}>(),
|
||||
{
|
||||
data: () => [],
|
||||
loading: false,
|
||||
rowHeight: 29,
|
||||
headerHeight: 33,
|
||||
rowKey: 'id',
|
||||
emptyText: '暂无数据',
|
||||
stripe: true,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
rowClick: [row: any, index: number]
|
||||
}>()
|
||||
|
||||
const slots = useSlots()
|
||||
const wrapRef = ref<HTMLElement>()
|
||||
const size = ref({ width: 0, height: 0 })
|
||||
let observer: ResizeObserver | null = null
|
||||
|
||||
onMounted(() => {
|
||||
observer = new ResizeObserver((entries) => {
|
||||
const rect = entries[0]?.contentRect
|
||||
if (!rect) return
|
||||
const width = Math.floor(rect.width)
|
||||
const height = Math.floor(rect.height)
|
||||
if (width === size.value.width && height === size.value.height) return
|
||||
size.value = { width, height }
|
||||
})
|
||||
if (wrapRef.value) observer.observe(wrapRef.value)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
observer?.disconnect()
|
||||
observer = null
|
||||
})
|
||||
|
||||
function display(value: unknown) {
|
||||
if (value === null || value === undefined || value === '') return '-'
|
||||
return String(value)
|
||||
}
|
||||
|
||||
/** 单元格渲染:优先用同名插槽,否则直接展示字段值 */
|
||||
function cellRenderer(column: VirtualColumn) {
|
||||
return (params: any) => {
|
||||
const slot = column.slot ? slots[column.slot] : undefined
|
||||
const text = display(params.cellData)
|
||||
const content = slot
|
||||
? slot({ row: params.rowData, index: params.rowIndex, value: params.cellData })
|
||||
: text
|
||||
return h(
|
||||
'div',
|
||||
{
|
||||
class: params.class,
|
||||
title: slot ? undefined : text,
|
||||
style: { textAlign: column.align ?? 'left' },
|
||||
},
|
||||
content as any,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const tableColumns = computed(() =>
|
||||
props.columns.map((column) => ({
|
||||
key: column.key,
|
||||
dataKey: column.dataKey ?? column.key,
|
||||
title: column.title,
|
||||
align: column.align ?? 'left',
|
||||
fixed: column.fixed ? ('right' as const) : undefined,
|
||||
width: column.width ?? column.minWidth ?? 120,
|
||||
minWidth: column.width ? undefined : column.minWidth,
|
||||
// 未设置固定宽度的列按剩余空间伸展,与 el-table 的 min-width 行为一致
|
||||
flexGrow: column.width ? 0 : 1,
|
||||
flexShrink: column.width ? 0 : 1,
|
||||
cellRenderer: cellRenderer(column),
|
||||
})),
|
||||
)
|
||||
|
||||
function rowClass({ rowIndex }: { rowIndex: number }) {
|
||||
return props.stripe && rowIndex % 2 === 1 ? 'is-striped' : ''
|
||||
}
|
||||
|
||||
const rowEventHandlers = {
|
||||
onClick: (params: { rowData: any; rowIndex: number }) => emit('rowClick', params.rowData, params.rowIndex),
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="wrapRef" v-loading="loading" class="virtual-table">
|
||||
<el-table-v2
|
||||
v-if="size.width > 0 && size.height > 0"
|
||||
:columns="tableColumns"
|
||||
:data="data"
|
||||
:width="size.width"
|
||||
:height="size.height"
|
||||
:row-height="rowHeight"
|
||||
:header-height="headerHeight"
|
||||
:row-key="rowKey"
|
||||
:row-class="rowClass"
|
||||
:row-event-handlers="rowEventHandlers"
|
||||
>
|
||||
<template #empty>
|
||||
<div class="virtual-table__empty">{{ emptyText }}</div>
|
||||
</template>
|
||||
</el-table-v2>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.virtual-table {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
font-size: 12px;
|
||||
border: 1px solid var(--el-border-color-lighter);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 表头 */
|
||||
.virtual-table :deep(.el-table-v2__header-cell) {
|
||||
padding: 0 8px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
border-inline-end: 1px solid var(--el-table-border-color);
|
||||
}
|
||||
.virtual-table :deep(.el-table-v2__header-cell:last-child) {
|
||||
border-inline-end: none;
|
||||
}
|
||||
|
||||
/* 数据行 */
|
||||
.virtual-table :deep(.el-table-v2__row-cell) {
|
||||
padding: 0 8px;
|
||||
font-size: 12px;
|
||||
line-height: 20px;
|
||||
border-inline-end: 1px solid var(--el-table-border-color);
|
||||
}
|
||||
.virtual-table :deep(.el-table-v2__row-cell:last-child),
|
||||
.virtual-table :deep(.el-table-v2__row-cell--placeholder) {
|
||||
border-inline-end: none;
|
||||
}
|
||||
|
||||
/* 单元格内容:超长省略,避免行高被撑开 */
|
||||
.virtual-table :deep(.el-table-v2__cell-text) {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
/* 斑马纹与 hover */
|
||||
.virtual-table :deep(.el-table-v2__row.is-striped) {
|
||||
background-color: var(--el-fill-color-lighter);
|
||||
}
|
||||
.virtual-table :deep(.el-table-v2__row.is-striped:hover) {
|
||||
background-color: var(--el-table-row-hover-bg-color);
|
||||
}
|
||||
|
||||
/* 操作列按钮跟随单元格字号 */
|
||||
.virtual-table :deep(.el-button) {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.virtual-table__empty {
|
||||
padding: 24px 0;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
18
frontend/src/components/virtualTable.ts
Normal file
18
frontend/src/components/virtualTable.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/** 虚拟滚动表格的列配置 */
|
||||
export interface VirtualColumn {
|
||||
/** 列唯一标识 */
|
||||
key: string
|
||||
/** 表头文字 */
|
||||
title?: string
|
||||
/** 无自定义插槽时取该字段的值,默认取 key */
|
||||
dataKey?: string
|
||||
/** 固定列宽,设置后该列不随容器伸缩 */
|
||||
width?: number
|
||||
/** 弹性列最小宽度,容器有多余空间时按比例伸展 */
|
||||
minWidth?: number
|
||||
align?: 'left' | 'center' | 'right'
|
||||
/** 固定在右侧 */
|
||||
fixed?: boolean
|
||||
/** 自定义单元格插槽名 */
|
||||
slot?: string
|
||||
}
|
||||
93
frontend/src/composables/useListPage.ts
Normal file
93
frontend/src/composables/useListPage.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import { ref, type Ref } from 'vue'
|
||||
|
||||
/** 每页条数下拉可选项 */
|
||||
export const PAGE_SIZES = [10, 20, 50, 100]
|
||||
/** 默认每页条数 */
|
||||
export const DEFAULT_PAGE_SIZE = 10
|
||||
|
||||
/** 分页查询条件:各列表页的 query 至少要含 page / pageSize */
|
||||
export interface PageQuery {
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
/** 列表接口统一返回结构 */
|
||||
export interface PageResult<T> {
|
||||
list: T[]
|
||||
total: number
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
/** useListPage 的入参 */
|
||||
export interface UseListPageOptions<T, Q extends PageQuery> {
|
||||
/** 列表页自己的查询条件(含 page / pageSize),组合式函数会直接修改其中的分页字段 */
|
||||
query: Q
|
||||
/** 拉取数据的方法:内部读取 query 上的 page / pageSize 传给后端 */
|
||||
fetcher: () => Promise<PageResult<T>>
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表分页封装
|
||||
* - 统一维护 loading / list / total,列表页不再各写一套
|
||||
* - 统一分页交互语义:条件查询回到第一页;切换页码按页拉取;切换每页条数回到第一页再拉取
|
||||
* - 记录每次列表请求耗时(elapsed),供分页处展示“请求用时”
|
||||
* - 请求异常不在这里提示,交给响应拦截器统一处理
|
||||
* @param options 见 UseListPageOptions
|
||||
* @return 列表状态与分页事件处理函数
|
||||
*/
|
||||
export function useListPage<T, Q extends PageQuery>(options: UseListPageOptions<T, Q>) {
|
||||
const { query, fetcher } = options
|
||||
|
||||
const loading = ref(false)
|
||||
const total = ref(0)
|
||||
const list = ref([]) as Ref<T[]>
|
||||
/** 最近一次列表请求用时(毫秒),用于分页处展示统计耗时 */
|
||||
const elapsed = ref<number | null>(null)
|
||||
|
||||
/** 按当前分页参数拉取列表 */
|
||||
async function fetchList() {
|
||||
loading.value = true
|
||||
const startAt = performance.now()
|
||||
try {
|
||||
const res = await fetcher()
|
||||
list.value = res.list || []
|
||||
total.value = res.total || 0
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
} finally {
|
||||
elapsed.value = Math.round(performance.now() - startAt)
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 条件查询:回到第一页后再拉取 */
|
||||
function search() {
|
||||
query.page = 1
|
||||
return fetchList()
|
||||
}
|
||||
|
||||
/** 切换页码 */
|
||||
function handlePageChange(page: number) {
|
||||
query.page = page
|
||||
return fetchList()
|
||||
}
|
||||
|
||||
/** 切换每页条数:默认回到第一页后再拉取 */
|
||||
function handleSizeChange(pageSize: number) {
|
||||
query.pageSize = pageSize
|
||||
query.page = 1
|
||||
return fetchList()
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
list,
|
||||
total,
|
||||
elapsed,
|
||||
fetchList,
|
||||
search,
|
||||
handlePageChange,
|
||||
handleSizeChange,
|
||||
}
|
||||
}
|
||||
149
frontend/src/layouts/BasicLayout.vue
Normal file
149
frontend/src/layouts/BasicLayout.vue
Normal file
@ -0,0 +1,149 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue'
|
||||
import { RouterView, useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { ArrowDown } from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useMenuStore } from '@/store/menu'
|
||||
import { usePrincipalStore } from '@/store/principal'
|
||||
import SideMenu from '@/components/SideMenu.vue'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const menuStore = useMenuStore()
|
||||
const principalStore = usePrincipalStore()
|
||||
const router = useRouter()
|
||||
|
||||
onMounted(() => {
|
||||
// 当前主体若已不在所属列表内(如切换账号),重置为第一个
|
||||
const ids = (auth.user?.principals || []).map((p) => p.id)
|
||||
principalStore.ensureValid(ids)
|
||||
})
|
||||
|
||||
function logout() {
|
||||
ElMessageBox.confirm('确定要退出登录吗?', '提示', { type: 'warning' })
|
||||
.then(() => {
|
||||
auth.logout()
|
||||
menuStore.reset()
|
||||
})
|
||||
.catch(() => {})
|
||||
}
|
||||
|
||||
function goLogin() {
|
||||
router.push('/login')
|
||||
}
|
||||
|
||||
// 切换当前主体:持久化到 localStorage 并刷新页面以按新主体重新拉取数据
|
||||
function onPrincipalChange(id: number) {
|
||||
principalStore.setCurrentId(id)
|
||||
window.location.reload()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-container class="app-container">
|
||||
<el-aside width="220px" class="app-aside">
|
||||
<div class="logo">OMS 管理系统</div>
|
||||
<el-menu :router="true" class="app-menu" :default-active="router.currentRoute.value.path">
|
||||
<SideMenu :menus="menuStore.menus" />
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header class="app-header">
|
||||
<div class="user-area">
|
||||
<el-select
|
||||
v-if="auth.user?.principals && auth.user.principals.length"
|
||||
:model-value="principalStore.currentId"
|
||||
class="principal-select"
|
||||
placeholder="选择主体"
|
||||
@change="onPrincipalChange"
|
||||
>
|
||||
<template #prefix>主体</template>
|
||||
<el-option
|
||||
v-for="p in auth.user.principals"
|
||||
:key="p.id"
|
||||
:label="`${p.name}`"
|
||||
:value="p.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-dropdown v-if="auth.user">
|
||||
<span class="user-name">
|
||||
{{ auth.user.nickname || auth.user.username }}
|
||||
<el-icon><ArrowDown /></el-icon>
|
||||
</span>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="logout">退出登录</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
<el-button v-else text type="primary" @click="goLogin">登录</el-button>
|
||||
</div>
|
||||
</el-header>
|
||||
<el-main class="app-main">
|
||||
<RouterView />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.app-container {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.app-aside {
|
||||
background-color: #fff;
|
||||
border-right: 1px solid var(--el-border-color);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 56px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--el-color-primary);
|
||||
border-bottom: 1px solid var(--el-border-color);
|
||||
}
|
||||
|
||||
.app-menu {
|
||||
flex: 1;
|
||||
border-right: none;
|
||||
}
|
||||
|
||||
.app-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
padding: 0 24px;
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid var(--el-border-color);
|
||||
}
|
||||
|
||||
.user-area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.principal-select {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
color: var(--el-text-color-primary);
|
||||
}
|
||||
|
||||
.app-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
</style>
|
||||
18
frontend/src/main.ts
Normal file
18
frontend/src/main.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { createApp } from 'vue'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import pinia from './store'
|
||||
|
||||
const app = createApp(App)
|
||||
|
||||
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
||||
app.component(key, component)
|
||||
}
|
||||
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
||||
63
frontend/src/router/index.ts
Normal file
63
frontend/src/router/index.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { getToken } from '@/utils/request'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/Login.vue'),
|
||||
meta: { public: true },
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/BasicLayout.vue'),
|
||||
name: 'layout',
|
||||
redirect: { name: 'home' },
|
||||
children: [
|
||||
{ path: '', name: 'home', component: () => import('@/views/Home.vue'), meta: { title: '首页' } },
|
||||
{ path: 'about', name: 'about', component: () => import('@/views/About.vue'), meta: { title: '关于' } },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
// 全局前置守卫:未登录跳登录页;已登录则确保菜单(侧边栏 + 动态路由)已加载
|
||||
router.beforeEach(async (to) => {
|
||||
const token = getToken()
|
||||
if (!to.meta.public && !token) {
|
||||
return { name: 'login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
if (to.name === 'login' && token) {
|
||||
return { name: 'home' }
|
||||
}
|
||||
if (token) {
|
||||
const { useAuthStore } = await import('@/store/auth')
|
||||
const auth = useAuthStore()
|
||||
if (!auth.user) {
|
||||
try {
|
||||
await auth.fetchProfile()
|
||||
} catch {
|
||||
// 401 等已由拦截器处理,profile 失败时 hasPrincipal 为 false
|
||||
}
|
||||
}
|
||||
const { useMenuStore } = await import('@/store/menu')
|
||||
const menuStore = useMenuStore()
|
||||
if (!menuStore.loaded) {
|
||||
await menuStore.fetchMenus()
|
||||
// 动态路由是本次导航期间注册的,深链接刷新时会早于匹配阶段,
|
||||
// 当前 to 尚未匹配到任何路由 → 用新的路由表重新解析当前目标
|
||||
if (to.matched.length === 0) {
|
||||
return to.fullPath
|
||||
}
|
||||
}
|
||||
// 已登录但无主体:强制停留在创建主体面板,隐藏其余菜单
|
||||
if (!auth.hasPrincipal && to.path !== '/principal/create') {
|
||||
return { path: '/principal/create' }
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
115
frontend/src/store/auth.ts
Normal file
115
frontend/src/store/auth.ts
Normal file
@ -0,0 +1,115 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import router from '@/router'
|
||||
import {
|
||||
login as loginApi,
|
||||
register as registerApi,
|
||||
sendEmailCode as sendEmailCodeApi,
|
||||
sendLoginCode as sendLoginCodeApi,
|
||||
loginByEmailCode as loginByEmailCodeApi,
|
||||
sendResetCode as sendResetCodeApi,
|
||||
resetPasswordByCode as resetPasswordByCodeApi,
|
||||
getProfile,
|
||||
type UserInfo,
|
||||
type RegisterPayload,
|
||||
} from '@/api/auth'
|
||||
import { getToken, setToken, clearToken } from '@/utils/request'
|
||||
import { useMenuStore } from '@/store/menu'
|
||||
import { usePrincipalStore } from '@/store/principal'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref<string>(getToken())
|
||||
const user = ref<UserInfo | null>(null)
|
||||
|
||||
/** 是否已有所属主体(多租户隔离的开关) */
|
||||
const hasPrincipal = computed(
|
||||
() => Array.isArray(user.value?.principals) && user.value!.principals.length > 0,
|
||||
)
|
||||
|
||||
/** 拉取并缓存当前用户信息 */
|
||||
async function fetchProfile() {
|
||||
user.value = await getProfile()
|
||||
// 尚未在 localStorage 选择主体时,默认选中第一个所属主体
|
||||
const ps = usePrincipalStore()
|
||||
if (!ps.currentId && user.value?.principals?.length) {
|
||||
ps.setCurrentId(user.value.principals[0].id)
|
||||
}
|
||||
}
|
||||
|
||||
/** 账号登录 */
|
||||
async function login(account: string, password: string) {
|
||||
const res = await loginApi({ account, password })
|
||||
applyToken(res.token)
|
||||
await fetchProfile()
|
||||
await useMenuStore().fetchMenus()
|
||||
return res
|
||||
}
|
||||
|
||||
/** 邮箱验证码登录 */
|
||||
async function loginByEmailCode(email: string, code: string) {
|
||||
const res = await loginByEmailCodeApi({ email, code })
|
||||
applyToken(res.token)
|
||||
await fetchProfile()
|
||||
await useMenuStore().fetchMenus()
|
||||
return res
|
||||
}
|
||||
|
||||
/** 注册账号 */
|
||||
async function register(payload: RegisterPayload) {
|
||||
const res = await registerApi(payload)
|
||||
applyToken(res.token)
|
||||
await fetchProfile()
|
||||
await useMenuStore().fetchMenus()
|
||||
return res
|
||||
}
|
||||
|
||||
/** 发送邮箱验证码(注册场景,6 位) */
|
||||
async function sendEmailCode(email: string) {
|
||||
return sendEmailCodeApi({ email })
|
||||
}
|
||||
|
||||
/** 发送邮箱登录验证码(6 位) */
|
||||
async function sendLoginCode(email: string) {
|
||||
return sendLoginCodeApi(email)
|
||||
}
|
||||
|
||||
/** 发送密码重置验证码(4 位) */
|
||||
async function sendResetCode(email: string) {
|
||||
return sendResetCodeApi(email)
|
||||
}
|
||||
|
||||
/** 通过邮箱验证码重置密码 */
|
||||
async function resetPasswordByCode(data: { email: string; code: string; password: string }) {
|
||||
return resetPasswordByCodeApi(data)
|
||||
}
|
||||
|
||||
/** 退出登录 */
|
||||
function logout() {
|
||||
clearToken()
|
||||
token.value = ''
|
||||
user.value = null
|
||||
ElMessage.success('已退出登录')
|
||||
router.replace('/login')
|
||||
}
|
||||
|
||||
function applyToken(value: string) {
|
||||
token.value = value
|
||||
setToken(value)
|
||||
}
|
||||
|
||||
return {
|
||||
token,
|
||||
user,
|
||||
hasPrincipal,
|
||||
login,
|
||||
loginByEmailCode,
|
||||
register,
|
||||
sendEmailCode,
|
||||
sendLoginCode,
|
||||
sendResetCode,
|
||||
resetPasswordByCode,
|
||||
fetchProfile,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
3
frontend/src/store/index.ts
Normal file
3
frontend/src/store/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
export default createPinia()
|
||||
164
frontend/src/store/menu.ts
Normal file
164
frontend/src/store/menu.ts
Normal file
@ -0,0 +1,164 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import type { RouteComponent } from 'vue-router'
|
||||
import router from '@/router'
|
||||
import { getMenuTree } from '@/api/menu'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
|
||||
export interface MenuItem {
|
||||
id: number
|
||||
parent_id: number
|
||||
name: string
|
||||
type: number // 1目录 2菜单 3按钮
|
||||
path?: string | null
|
||||
icon?: string | null
|
||||
permission?: string | null
|
||||
component?: string | null
|
||||
sort: number
|
||||
status: number
|
||||
children?: MenuItem[]
|
||||
}
|
||||
|
||||
// 接口不可用时的兜底菜单(与后端种子数据保持一致的设计)
|
||||
const defaultMenus: MenuItem[] = [
|
||||
{ id: 1, parent_id: 0, name: '仪表盘', type: 2, path: '/dashboard', icon: 'HomeFilled', component: 'views/Home.vue', sort: 100, status: 1 },
|
||||
{
|
||||
id: 4, parent_id: 0, name: '订单管理', type: 1, icon: 'List', sort: 90, status: 1,
|
||||
children: [
|
||||
{ id: 42, parent_id: 4, name: '创建发货单', type: 2, path: '/order-create', icon: 'Plus', permission: 'orderDelivery:create', component: 'views/Order/Create.vue', sort: 80, status: 1 },
|
||||
{ id: 41, parent_id: 4, name: '订单', type: 2, path: '/order', icon: 'Tickets', permission: 'order:list', component: 'views/Order/Index.vue', sort: 70, status: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3, parent_id: 0, name: '商品管理', type: 1, icon: 'Goods', sort: 80, status: 1,
|
||||
children: [
|
||||
{ id: 31, parent_id: 3, name: '商品', type: 2, path: '/product', icon: 'Box', permission: 'product:list', component: 'views/Product/Index.vue', sort: 80, status: 1 },
|
||||
{ id: 32, parent_id: 3, name: '组合商品', type: 2, path: '/combo-product', icon: 'Files', permission: 'comboProduct:list', component: 'views/ComboProduct/Index.vue', sort: 70, status: 1 },
|
||||
{ id: 52, parent_id: 3, name: '店铺商品', type: 2, path: '/shop-product', icon: 'GoodsFilled', permission: 'shopProduct:list', component: 'views/ShopProduct/Index.vue', sort: 65, status: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 6, parent_id: 0, name: '库存管理', type: 1, icon: 'Box', sort: 82, status: 1,
|
||||
children: [
|
||||
{ id: 61, parent_id: 6, name: '入库单', type: 2, path: '/inbound-order', icon: 'Bottom', permission: 'inboundOrder:list', component: 'views/InboundOrder/Index.vue', sort: 75, status: 1 },
|
||||
{ id: 62, parent_id: 6, name: '出库单', type: 2, path: '/outbound-order', icon: 'Top', permission: 'outboundOrder:list', component: 'views/OutboundOrder/Index.vue', sort: 70, status: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 5, parent_id: 0, name: '店铺管理', type: 1, icon: 'Shop', sort: 85, status: 1,
|
||||
children: [
|
||||
{ id: 51, parent_id: 5, name: '店铺', type: 2, path: '/shop', icon: 'Shop', permission: 'shop:list', component: 'views/Shop/Index.vue', sort: 80, status: 1 },
|
||||
],
|
||||
},
|
||||
{ id: 25, parent_id: 0, name: '外部仓库', type: 2, path: '/system/external-api', icon: 'Link', permission: 'principalExternalApi:list', component: 'views/ExternalApi/Index.vue', sort: 75, status: 1 },
|
||||
{
|
||||
id: 2, parent_id: 0, name: '系统管理', type: 1, icon: 'Setting', sort: 70, status: 1,
|
||||
children: [
|
||||
{ id: 21, parent_id: 2, name: '我的', type: 2, path: '/system/user', icon: 'User', permission: null, component: 'views/User/Profile.vue', sort: 90, status: 1 },
|
||||
{ id: 22, parent_id: 2, name: '主体管理', type: 2, path: '/system/principal', icon: 'OfficeBuilding', permission: 'principal:list', component: 'views/Principal/Index.vue', sort: 80, status: 1 },
|
||||
{ id: 23, parent_id: 2, name: '账号', type: 2, path: '/system/principal-user', icon: 'Connection', permission: 'principalUser:list', component: 'views/PrincipalUser/Index.vue', sort: 70, status: 1 },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
// 预加载所有视图组件,供动态路由按 component 路径解析。
|
||||
// 使用相对路径(相对于本文件 src/store/),保证 dev/build 下 key 格式一致、可稳定命中。
|
||||
const viewModules = import.meta.glob('../views/**/*.vue')
|
||||
|
||||
// 无主体时仅展示的「创建主体」面板菜单
|
||||
const createPrincipalMenu: MenuItem = {
|
||||
id: 9001,
|
||||
parent_id: 0,
|
||||
name: '创建主体',
|
||||
type: 2,
|
||||
path: '/principal/create',
|
||||
icon: 'OfficeBuilding',
|
||||
component: 'views/Principal/Create.vue',
|
||||
sort: 1,
|
||||
status: 1,
|
||||
}
|
||||
|
||||
function resolveComponent(component?: string | null): RouteComponent {
|
||||
if (component) {
|
||||
const key = component.startsWith('../') ? component : `../${component}`
|
||||
const loader = viewModules[key] as unknown as RouteComponent | undefined
|
||||
if (loader) return loader
|
||||
}
|
||||
return viewModules['../views/Generic.vue'] as unknown as RouteComponent
|
||||
}
|
||||
|
||||
function flatten(tree: MenuItem[]): MenuItem[] {
|
||||
return tree.flatMap((m) => [m, ...(m.children ? flatten(m.children) : [])])
|
||||
}
|
||||
|
||||
export const useMenuStore = defineStore('menu', () => {
|
||||
const menus = ref<MenuItem[]>([])
|
||||
const loaded = ref(false)
|
||||
|
||||
/** 始终注册「创建主体」路由,保证该页面可直接访问 */
|
||||
function registerCreateRoute() {
|
||||
if (!createPrincipalMenu.path) return
|
||||
router.addRoute('layout', {
|
||||
path: createPrincipalMenu.path.replace(/^\//, ''),
|
||||
name: `menu-${createPrincipalMenu.id}`,
|
||||
component: resolveComponent(createPrincipalMenu.component),
|
||||
meta: {
|
||||
title: createPrincipalMenu.name,
|
||||
icon: createPrincipalMenu.icon,
|
||||
permission: createPrincipalMenu.permission,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/** 拉取菜单树 → 构建侧边栏 + 动态路由 */
|
||||
async function fetchMenus() {
|
||||
// 无主体:仅展示「创建主体」面板,隐藏其余菜单
|
||||
if (!useAuthStore().hasPrincipal) {
|
||||
menus.value = [createPrincipalMenu]
|
||||
} else {
|
||||
let tree: MenuItem[] = []
|
||||
try {
|
||||
tree = await getMenuTree()
|
||||
} catch {
|
||||
tree = []
|
||||
}
|
||||
if (!tree.length) tree = JSON.parse(JSON.stringify(defaultMenus))
|
||||
menus.value = tree
|
||||
}
|
||||
|
||||
registerRoutes(menus.value)
|
||||
registerCreateRoute() // 创建主体路由始终可用,避免直接访问空白
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
/** 将菜单(type=2)注册为 layout 下的动态子路由 */
|
||||
function registerRoutes(tree: MenuItem[]) {
|
||||
// 清理上一次注册的动态路由,避免重复添加
|
||||
router
|
||||
.getRoutes()
|
||||
.filter((r) => typeof r.name === 'string' && r.name.startsWith('menu-'))
|
||||
.forEach((r) => router.removeRoute(r.name as string))
|
||||
|
||||
flatten(tree).forEach((item) => {
|
||||
if (item.type !== 2 || !item.path) return
|
||||
router.addRoute('layout', {
|
||||
path: item.path.replace(/^\//, ''),
|
||||
name: `menu-${item.id}`,
|
||||
component: resolveComponent(item.component),
|
||||
meta: { title: item.name, icon: item.icon, permission: item.permission },
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/** 重置(退出登录时调用) */
|
||||
function reset() {
|
||||
router
|
||||
.getRoutes()
|
||||
.filter((r) => typeof r.name === 'string' && r.name.startsWith('menu-'))
|
||||
.forEach((r) => router.removeRoute(r.name as string))
|
||||
menus.value = []
|
||||
loaded.value = false
|
||||
}
|
||||
|
||||
return { menus, loaded, fetchMenus, reset }
|
||||
})
|
||||
30
frontend/src/store/principal.ts
Normal file
30
frontend/src/store/principal.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const CURRENT_PRINCIPAL_KEY = 'oms_current_principal'
|
||||
|
||||
function readStored(): number | null {
|
||||
const v = localStorage.getItem(CURRENT_PRINCIPAL_KEY)
|
||||
return v ? Number(v) : null
|
||||
}
|
||||
|
||||
export const usePrincipalStore = defineStore('principal', () => {
|
||||
// 当前选中的主体 ID,持久化到 localStorage,跨页面/刷新保持
|
||||
const currentId = ref<number | null>(readStored())
|
||||
|
||||
function setCurrentId(id: number | null) {
|
||||
currentId.value = id
|
||||
if (id == null) localStorage.removeItem(CURRENT_PRINCIPAL_KEY)
|
||||
else localStorage.setItem(CURRENT_PRINCIPAL_KEY, String(id))
|
||||
}
|
||||
|
||||
/** 若当前主体不在可选列表内,重置为列表第一个(或不选) */
|
||||
function ensureValid(principalIds: number[]) {
|
||||
if (currentId.value == null) return
|
||||
if (!principalIds.includes(currentId.value)) {
|
||||
setCurrentId(principalIds.length ? principalIds[0] : null)
|
||||
}
|
||||
}
|
||||
|
||||
return { currentId, setCurrentId, ensureValid }
|
||||
})
|
||||
101
frontend/src/utils/request.ts
Normal file
101
frontend/src/utils/request.ts
Normal file
@ -0,0 +1,101 @@
|
||||
import axios, { type AxiosRequestConfig } from 'axios'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import router from '@/router'
|
||||
import { usePrincipalStore } from '@/store/principal'
|
||||
|
||||
const TOKEN_KEY = 'oms_token'
|
||||
|
||||
export function getToken(): string {
|
||||
return localStorage.getItem(TOKEN_KEY) || ''
|
||||
}
|
||||
|
||||
export function setToken(token: string): void {
|
||||
localStorage.setItem(TOKEN_KEY, token)
|
||||
}
|
||||
|
||||
export function clearToken(): void {
|
||||
localStorage.removeItem(TOKEN_KEY)
|
||||
}
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 15000,
|
||||
})
|
||||
|
||||
// 请求拦截器:自动携带 JWT 与当前主体(principal_id),实现多租户数据隔离
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
const token = getToken()
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`
|
||||
}
|
||||
// 携带当前选中的主体:GET 放 query,其余放 body(后端 principalCheck 据此隔离数据)
|
||||
const pid = usePrincipalStore().currentId
|
||||
if (pid) {
|
||||
if ((config.method || 'get').toLowerCase() === 'get') {
|
||||
config.params = { ...(config.params || {}), principal_id: pid }
|
||||
} else if (config.data instanceof FormData) {
|
||||
// 文件上传:principal_id 作为表单字段追加,直接展开会丢失文件
|
||||
config.data.append('principal_id', String(pid))
|
||||
} else {
|
||||
config.data = { ...(config.data || {}), principal_id: pid }
|
||||
}
|
||||
}
|
||||
return config
|
||||
},
|
||||
(error) => Promise.reject(error),
|
||||
)
|
||||
|
||||
// 响应拦截器:统一解包 { code, message, data } 并处理异常
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
const res = response.data
|
||||
// 兼容未包裹 code 的纯数据响应
|
||||
if (res && typeof res === 'object' && 'code' in res) {
|
||||
if (res.code !== 0) {
|
||||
ElMessage.error(res.message || '请求失败')
|
||||
return Promise.reject(new Error(res.message || 'Error'))
|
||||
}
|
||||
return res.data
|
||||
}
|
||||
return res
|
||||
},
|
||||
(error) => {
|
||||
const status = error.response?.status
|
||||
const data = error.response?.data
|
||||
const message = data?.message || error.message || '网络异常'
|
||||
|
||||
if (status === 401) {
|
||||
clearToken()
|
||||
ElMessageBox.confirm('登录状态已失效,请重新登录', '提示', {
|
||||
confirmButtonText: '去登录',
|
||||
showCancelButton: false,
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => router.replace('/login'))
|
||||
.catch(() => {})
|
||||
} else {
|
||||
ElMessage.error(message)
|
||||
}
|
||||
return Promise.reject(error)
|
||||
},
|
||||
)
|
||||
|
||||
// 带类型的请求封装:拦截器已解包 data,故直接返回业务数据 T
|
||||
export function get<T>(url: string, params?: object): Promise<T> {
|
||||
return service.get(url, { params }) as unknown as Promise<T>
|
||||
}
|
||||
|
||||
export function post<T>(url: string, data?: object, config?: AxiosRequestConfig): Promise<T> {
|
||||
return service.post(url, data, config) as unknown as Promise<T>
|
||||
}
|
||||
|
||||
export function put<T>(url: string, data?: object): Promise<T> {
|
||||
return service.put(url, data) as unknown as Promise<T>
|
||||
}
|
||||
|
||||
export function del<T>(url: string): Promise<T> {
|
||||
return service.delete(url) as unknown as Promise<T>
|
||||
}
|
||||
|
||||
export default service
|
||||
20
frontend/src/views/About.vue
Normal file
20
frontend/src/views/About.vue
Normal file
@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { ElMessage } from 'element-plus'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="about">
|
||||
<el-card header="关于">
|
||||
<p>这是一个基于 Vue 3 + TypeScript + Element Plus 的前端脚手架。</p>
|
||||
<el-button type="primary" @click="ElMessage.info('Hello OMS')">
|
||||
测试消息
|
||||
</el-button>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.about {
|
||||
padding: 24px;
|
||||
}
|
||||
</style>
|
||||
443
frontend/src/views/ComboProduct/Index.vue
Normal file
443
frontend/src/views/ComboProduct/Index.vue
Normal file
@ -0,0 +1,443 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getComboProducts,
|
||||
createComboProduct,
|
||||
updateComboProduct,
|
||||
deleteComboProduct,
|
||||
type ComboProductItem,
|
||||
} from '@/api/comboProduct'
|
||||
import { searchProducts, type ProductSearchItem } from '@/api/product'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
keyword: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (params.status === '') delete params.status
|
||||
return getComboProducts(params)
|
||||
},
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/** 把明细渲染为「商品名 × 数量」(明细已冗余商品信息) */
|
||||
function itemsText(items: ComboProductItem['items']) {
|
||||
if (!items || !items.length) return '-'
|
||||
return items
|
||||
.map((it) => `${it.product?.item_name || `商品#${it.product_id}`} × ${it.quantity}`)
|
||||
.join(',')
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
interface ComboRow {
|
||||
product_id: number
|
||||
quantity: number
|
||||
item_name: string
|
||||
item_code: string
|
||||
sku_property: string | null
|
||||
stock_unit: string | null
|
||||
}
|
||||
|
||||
const drawerVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
code: '',
|
||||
name: '',
|
||||
price: 0,
|
||||
status: 1,
|
||||
remark: '',
|
||||
})
|
||||
// 已添加的组合明细(含展示所需快照)
|
||||
const itemRows = ref<ComboRow[]>([])
|
||||
const rules: FormRules = {
|
||||
code: [{ required: true, message: '请输入组合商品编码', trigger: 'blur' }],
|
||||
name: [{ required: true, message: '请输入组合商品名称', trigger: 'blur' }],
|
||||
price: [{ required: true, message: '请输入组合售价', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
}
|
||||
|
||||
/* 右侧上方:系统商品搜索 */
|
||||
const productKeyword = ref('')
|
||||
const productList = ref<ProductSearchItem[]>([])
|
||||
const productLoading = ref(false)
|
||||
|
||||
async function fetchSearchProducts() {
|
||||
productLoading.value = true
|
||||
try {
|
||||
const keyword = productKeyword.value.trim()
|
||||
productList.value = await searchProducts(keyword || undefined)
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
productLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function isAdded(productId: number) {
|
||||
return itemRows.value.some((r) => r.product_id === productId)
|
||||
}
|
||||
|
||||
/** 添加系统商品:已存在则数量 +1,否则追加一行 */
|
||||
function addProduct(p: ProductSearchItem) {
|
||||
const exist = itemRows.value.find((r) => r.product_id === p.id)
|
||||
if (exist) {
|
||||
exist.quantity += 1
|
||||
return
|
||||
}
|
||||
itemRows.value.push({
|
||||
product_id: p.id,
|
||||
quantity: 1,
|
||||
item_name: p.item_name,
|
||||
item_code: p.item_code,
|
||||
sku_property: p.sku_property,
|
||||
stock_unit: p.stock_unit,
|
||||
})
|
||||
}
|
||||
|
||||
function removeRow(index: number) {
|
||||
itemRows.value.splice(index, 1)
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editId.value = null
|
||||
form.code = ''
|
||||
form.name = ''
|
||||
form.price = 0
|
||||
form.status = 1
|
||||
form.remark = ''
|
||||
itemRows.value = []
|
||||
productKeyword.value = ''
|
||||
drawerVisible.value = true
|
||||
fetchSearchProducts()
|
||||
}
|
||||
|
||||
function openEdit(row: ComboProductItem) {
|
||||
editId.value = row.id
|
||||
form.code = row.code
|
||||
form.name = row.name
|
||||
form.price = Number(row.price) || 0
|
||||
form.status = row.status
|
||||
form.remark = row.remark || ''
|
||||
itemRows.value = (row.items || []).map((it) => ({
|
||||
product_id: it.product_id,
|
||||
quantity: it.quantity,
|
||||
item_name: it.product?.item_name || `商品#${it.product_id}`,
|
||||
item_code: it.product?.item_code || '',
|
||||
sku_property: it.product?.sku_property ?? null,
|
||||
stock_unit: it.product?.stock_unit ?? null,
|
||||
}))
|
||||
productKeyword.value = ''
|
||||
drawerVisible.value = true
|
||||
fetchSearchProducts()
|
||||
}
|
||||
|
||||
/** 校验明细:至少一行,且每行的数量合法 */
|
||||
function validateRows(): boolean {
|
||||
if (!itemRows.value.length) {
|
||||
ElMessage.warning('请至少添加一条组合明细')
|
||||
return false
|
||||
}
|
||||
const invalid = itemRows.value.some((r) => !r.product_id || !r.quantity || r.quantity <= 0)
|
||||
if (invalid) {
|
||||
ElMessage.warning('每条明细都需选择商品且数量大于 0')
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
if (!validateRows()) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = {
|
||||
...form,
|
||||
items: itemRows.value.map((r) => ({
|
||||
product_id: Number(r.product_id),
|
||||
quantity: Number(r.quantity),
|
||||
})),
|
||||
}
|
||||
if (editId.value == null) {
|
||||
await createComboProduct(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await updateComboProduct(editId.value, payload)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
drawerVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(row: ComboProductItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除组合商品「${row.name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deleteComboProduct(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>组合商品</span>
|
||||
<el-button type="primary" @click="openCreate">新增组合商品</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="组合商品编码或名称"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option label="上架" :value="1" />
|
||||
<el-option label="下架" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<DataTable :loading="loading" :data="list">
|
||||
<el-table-column prop="code" label="组合编码" width="130" />
|
||||
<el-table-column prop="name" label="组合名称" min-width="150" />
|
||||
<el-table-column label="组合售价" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.price }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="组合明细" min-width="220" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ itemsText(row.items) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '上架' : '下架' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-drawer
|
||||
v-model="drawerVisible"
|
||||
:title="editId == null ? '新增组合商品' : '编辑组合商品'"
|
||||
direction="rtl"
|
||||
size="960px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<div class="combo-editor">
|
||||
<!-- 左:组合商品信息 -->
|
||||
<div class="combo-info">
|
||||
<div class="pane-title">组合商品信息</div>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="90px">
|
||||
<el-form-item label="组合编码" prop="code">
|
||||
<el-input v-model="form.code" placeholder="同一主体下唯一" />
|
||||
</el-form-item>
|
||||
<el-form-item label="组合名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入组合商品名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="组合售价" prop="price">
|
||||
<el-input-number v-model="form.price" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option label="上架" :value="1" />
|
||||
<el-option label="下架" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<!-- 右:上=搜索系统商品,下=已添加组合明细 -->
|
||||
<div class="combo-detail">
|
||||
<div class="pane pane-top">
|
||||
<div class="pane-head">
|
||||
<span class="pane-title">系统商品</span>
|
||||
<el-input
|
||||
v-model="productKeyword"
|
||||
placeholder="商品编码/货物编码/条码/名称"
|
||||
clearable
|
||||
style="width: 280px"
|
||||
@keyup.enter="fetchSearchProducts"
|
||||
>
|
||||
<template #append>
|
||||
<el-button @click="fetchSearchProducts">搜索</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<DataTable
|
||||
:loading="productLoading"
|
||||
:data="productList"
|
||||
height="100%"
|
||||
>
|
||||
<el-table-column prop="item_code" label="商品编码" width="120" />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="sku_property" label="SKU规格" width="90" />
|
||||
<el-table-column label="操作" width="80" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" :disabled="isAdded(row.id)" @click="addProduct(row)">
|
||||
{{ isAdded(row.id) ? '已添加' : '添加' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<div class="pane pane-bottom">
|
||||
<div class="pane-head">
|
||||
<span class="pane-title">已添加组合明细</span>
|
||||
<span class="pane-sub">共 {{ itemRows.length }} 项</span>
|
||||
</div>
|
||||
<DataTable :data="itemRows" height="100%">
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="item_code" label="商品编码" width="120" />
|
||||
<el-table-column prop="sku_property" label="SKU规格" width="90" />
|
||||
<el-table-column label="数量" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-input-number
|
||||
v-model="row.quantity"
|
||||
:min="1"
|
||||
:precision="0"
|
||||
size="small"
|
||||
style="width: 110px"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="80" align="center">
|
||||
<template #default="{ $index }">
|
||||
<el-button link type="danger" @click="removeRow($index)">移除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="drawerVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
:deep(.el-drawer__body) {
|
||||
padding: 16px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.combo-editor {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
height: 100%;
|
||||
}
|
||||
.combo-info {
|
||||
flex: none;
|
||||
width: 320px;
|
||||
padding-right: 16px;
|
||||
border-right: 1px solid var(--el-border-color-lighter);
|
||||
overflow: auto;
|
||||
}
|
||||
.combo-detail {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
min-width: 0;
|
||||
}
|
||||
.pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.pane-top,
|
||||
.pane-bottom {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
.pane-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.pane-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
.pane-sub {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
1325
frontend/src/views/ExternalApi/Index.vue
Normal file
1325
frontend/src/views/ExternalApi/Index.vue
Normal file
File diff suppressed because it is too large
Load Diff
18
frontend/src/views/Generic.vue
Normal file
18
frontend/src/views/Generic.vue
Normal file
@ -0,0 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>{{ (route.meta.title as string) || '页面' }}</template>
|
||||
<el-empty description="该模块页面建设中,菜单与路由已通过接口动态加载" />
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.el-empty) {
|
||||
padding: 48px 0;
|
||||
}
|
||||
</style>
|
||||
49
frontend/src/views/Home.vue
Normal file
49
frontend/src/views/Home.vue
Normal file
@ -0,0 +1,49 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { Check } from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const count = ref(0)
|
||||
const inputValue = ref('')
|
||||
|
||||
// 进入首页时若已有 token 但尚未加载用户信息,则拉取一次
|
||||
onMounted(async () => {
|
||||
if (auth.token && !auth.user) {
|
||||
try {
|
||||
await auth.fetchProfile()
|
||||
} catch {
|
||||
// 401 等已由拦截器处理
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="home">
|
||||
<el-card header="欢迎使用 OMS 前端脚手架">
|
||||
<el-space direction="vertical" size="large" fill>
|
||||
<el-alert
|
||||
v-if="auth.user"
|
||||
type="success"
|
||||
:closable="false"
|
||||
:title="`你好,${auth.user.nickname || auth.user.username}!Vue 3 + TypeScript + Element Plus 已就绪`"
|
||||
/>
|
||||
<el-alert v-else type="info" :closable="false" title="当前为游客态,请先登录" />
|
||||
<div>
|
||||
<el-button type="primary" @click="count++">点击计数: {{ count }}</el-button>
|
||||
<el-button>默认按钮</el-button>
|
||||
<el-button type="success" :icon="Check">成功</el-button>
|
||||
</div>
|
||||
<el-input v-model="inputValue" placeholder="请输入内容" style="max-width: 320px" />
|
||||
<span v-if="inputValue">你输入了:{{ inputValue }}</span>
|
||||
</el-space>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.home {
|
||||
padding: 24px;
|
||||
}
|
||||
</style>
|
||||
1108
frontend/src/views/InboundOrder/Index.vue
Normal file
1108
frontend/src/views/InboundOrder/Index.vue
Normal file
File diff suppressed because it is too large
Load Diff
502
frontend/src/views/Login.vue
Normal file
502
frontend/src/views/Login.vue
Normal file
@ -0,0 +1,502 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onUnmounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { User, Lock, Message } from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
/** 登录方式:账号密码登录 / 邮箱验证码登录 */
|
||||
const loginTab = ref<'account' | 'email'>('account')
|
||||
const loading = ref(false)
|
||||
|
||||
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
|
||||
|
||||
/** 倒计时:启动指定计数器的 60 秒重发限制 */
|
||||
function startCountdown(counter: { value: number }, timerRef: { value?: ReturnType<typeof setInterval> }) {
|
||||
counter.value = 60
|
||||
if (timerRef.value) clearInterval(timerRef.value)
|
||||
timerRef.value = setInterval(() => {
|
||||
counter.value -= 1
|
||||
if (counter.value <= 0) {
|
||||
if (timerRef.value) clearInterval(timerRef.value)
|
||||
timerRef.value = undefined
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
function goAfterLogin() {
|
||||
router.replace((route.query.redirect as string) || '/')
|
||||
}
|
||||
|
||||
/* -------------------- 账号登录 -------------------- */
|
||||
const loginFormRef = ref<FormInstance>()
|
||||
const loginForm = reactive({
|
||||
account: '',
|
||||
password: '',
|
||||
})
|
||||
const loginRules: FormRules = {
|
||||
account: [{ required: true, message: '请输入账号或邮箱', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
async function handleLogin() {
|
||||
if (!loginFormRef.value) return
|
||||
await loginFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
loading.value = true
|
||||
try {
|
||||
await auth.login(loginForm.account, loginForm.password)
|
||||
ElMessage.success('登录成功')
|
||||
goAfterLogin()
|
||||
} catch {
|
||||
// 错误信息已由响应拦截器统一提示
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 邮箱验证码登录 -------------------- */
|
||||
const emailLoginFormRef = ref<FormInstance>()
|
||||
const emailLoginForm = reactive({ email: '', code: '' })
|
||||
const emailLoginRules: FormRules = {
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
||||
{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' },
|
||||
],
|
||||
code: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{6}$/, message: '验证码为 6 位数字', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
const emailCodeCountdown = ref(0)
|
||||
const emailTimer: { value?: ReturnType<typeof setInterval> } = { value: undefined }
|
||||
const emailSending = ref(false)
|
||||
|
||||
async function sendLoginCode() {
|
||||
if (emailCodeCountdown.value > 0) return
|
||||
if (!EMAIL_RE.test(emailLoginForm.email)) {
|
||||
ElMessage.warning('请先填写正确的邮箱')
|
||||
return
|
||||
}
|
||||
emailSending.value = true
|
||||
try {
|
||||
const res = await auth.sendLoginCode(emailLoginForm.email)
|
||||
ElMessage.success(`验证码已发送,有效期 ${res.expires_in} 秒`)
|
||||
startCountdown(emailCodeCountdown, emailTimer)
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
emailSending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEmailLogin() {
|
||||
if (!emailLoginFormRef.value) return
|
||||
await emailLoginFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
loading.value = true
|
||||
try {
|
||||
await auth.loginByEmailCode(emailLoginForm.email, emailLoginForm.code)
|
||||
ElMessage.success('登录成功')
|
||||
goAfterLogin()
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 注册账号(弹窗) -------------------- */
|
||||
const registerVisible = ref(false)
|
||||
const registerFormRef = ref<FormInstance>()
|
||||
const registerForm = reactive({
|
||||
username: '',
|
||||
nickname: '',
|
||||
email: '',
|
||||
code: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
phone: '',
|
||||
})
|
||||
const registerRules: FormRules = {
|
||||
username: [{ required: true, message: '请输入登录账号', trigger: 'blur' }],
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
||||
{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' },
|
||||
],
|
||||
code: [{ required: true, message: '请输入邮箱验证码', trigger: 'blur' }],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ min: 6, message: '密码长度不能少于 6 位', trigger: 'blur' },
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请再次输入密码', trigger: 'blur' },
|
||||
{
|
||||
validator: (_rule: unknown, value: string, callback: (e?: string | Error) => void) => {
|
||||
if (value !== registerForm.password) callback(new Error('两次输入的密码不一致'))
|
||||
else callback()
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const registerCountdown = ref(0)
|
||||
const registerTimer: { value?: ReturnType<typeof setInterval> } = { value: undefined }
|
||||
const registerSending = ref(false)
|
||||
|
||||
function openRegister() {
|
||||
registerForm.username = ''
|
||||
registerForm.nickname = ''
|
||||
registerForm.email = ''
|
||||
registerForm.code = ''
|
||||
registerForm.password = ''
|
||||
registerForm.confirmPassword = ''
|
||||
registerForm.phone = ''
|
||||
registerCountdown.value = 0
|
||||
registerVisible.value = true
|
||||
}
|
||||
|
||||
async function sendRegisterCode() {
|
||||
if (registerCountdown.value > 0) return
|
||||
if (!EMAIL_RE.test(registerForm.email)) {
|
||||
ElMessage.warning('请先填写正确的邮箱')
|
||||
return
|
||||
}
|
||||
registerSending.value = true
|
||||
try {
|
||||
const res = await auth.sendEmailCode(registerForm.email)
|
||||
ElMessage.success(`验证码已发送,有效期 ${res.expires_in} 秒`)
|
||||
startCountdown(registerCountdown, registerTimer)
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
registerSending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRegister() {
|
||||
if (!registerFormRef.value) return
|
||||
await registerFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
loading.value = true
|
||||
try {
|
||||
await auth.register({
|
||||
username: registerForm.username,
|
||||
password: registerForm.password,
|
||||
email: registerForm.email,
|
||||
code: registerForm.code,
|
||||
nickname: registerForm.nickname || undefined,
|
||||
phone: registerForm.phone || undefined,
|
||||
})
|
||||
ElMessage.success('注册成功,已自动登录')
|
||||
registerVisible.value = false
|
||||
goAfterLogin()
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 忘记密码(邮箱验证码重置) -------------------- */
|
||||
const forgotVisible = ref(false)
|
||||
const forgotSubmitting = ref(false)
|
||||
const forgotSending = ref(false)
|
||||
const forgotFormRef = ref<FormInstance>()
|
||||
const forgotForm = reactive({
|
||||
email: '',
|
||||
code: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
})
|
||||
const forgotRules: FormRules = {
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
||||
{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' },
|
||||
],
|
||||
code: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'blur' },
|
||||
{ pattern: /^\d{4}$/, message: '验证码为 4 位数字', trigger: 'blur' },
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 6, message: '密码长度不能少于 6 位', trigger: 'blur' },
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||||
{
|
||||
validator: (_rule: unknown, value: string, callback: (e?: string | Error) => void) => {
|
||||
if (value !== forgotForm.password) callback(new Error('两次输入的密码不一致'))
|
||||
else callback()
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const forgotCountdown = ref(0)
|
||||
const forgotTimer: { value?: ReturnType<typeof setInterval> } = { value: undefined }
|
||||
|
||||
function openForgot() {
|
||||
forgotForm.email = ''
|
||||
forgotForm.code = ''
|
||||
forgotForm.password = ''
|
||||
forgotForm.confirmPassword = ''
|
||||
forgotCountdown.value = 0
|
||||
forgotVisible.value = true
|
||||
}
|
||||
|
||||
async function sendResetCode() {
|
||||
if (forgotCountdown.value > 0) return
|
||||
if (!EMAIL_RE.test(forgotForm.email)) {
|
||||
ElMessage.warning('请先填写正确的邮箱')
|
||||
return
|
||||
}
|
||||
forgotSending.value = true
|
||||
try {
|
||||
const res = await auth.sendResetCode(forgotForm.email)
|
||||
ElMessage.success(`验证码已发送,有效期 ${res.expires_in} 秒`)
|
||||
startCountdown(forgotCountdown, forgotTimer)
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
forgotSending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleResetPassword() {
|
||||
if (!forgotFormRef.value) return
|
||||
await forgotFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
forgotSubmitting.value = true
|
||||
try {
|
||||
await auth.resetPasswordByCode({
|
||||
email: forgotForm.email,
|
||||
code: forgotForm.code,
|
||||
password: forgotForm.password,
|
||||
})
|
||||
ElMessage.success('密码重置成功,请使用新密码登录')
|
||||
forgotVisible.value = false
|
||||
loginTab.value = 'account'
|
||||
loginForm.account = forgotForm.email
|
||||
loginForm.password = ''
|
||||
} catch {
|
||||
// 错误已由拦截器提示
|
||||
} finally {
|
||||
forgotSubmitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (emailTimer.value) clearInterval(emailTimer.value)
|
||||
if (registerTimer.value) clearInterval(registerTimer.value)
|
||||
if (forgotTimer.value) clearInterval(forgotTimer.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="login-page">
|
||||
<el-card class="login-card">
|
||||
<div class="login-title">OMS 管理系统</div>
|
||||
<el-tabs v-model="loginTab" stretch>
|
||||
<el-tab-pane label="账号登录" name="account">
|
||||
<el-form
|
||||
ref="loginFormRef"
|
||||
:model="loginForm"
|
||||
:rules="loginRules"
|
||||
label-position="top"
|
||||
@keyup.enter="handleLogin"
|
||||
>
|
||||
<el-form-item label="账号 / 邮箱" prop="account">
|
||||
<el-input v-model="loginForm.account" placeholder="用户名或邮箱" :prefix-icon="User" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
show-password
|
||||
:prefix-icon="Lock"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-button type="primary" :loading="loading" class="full-btn" @click="handleLogin">
|
||||
登录
|
||||
</el-button>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="邮箱登录" name="email">
|
||||
<el-form
|
||||
ref="emailLoginFormRef"
|
||||
:model="emailLoginForm"
|
||||
:rules="emailLoginRules"
|
||||
label-position="top"
|
||||
@keyup.enter="handleEmailLogin"
|
||||
>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="emailLoginForm.email" placeholder="请输入已注册的邮箱" :prefix-icon="Message" />
|
||||
</el-form-item>
|
||||
<el-form-item label="验证码" prop="code">
|
||||
<el-input v-model="emailLoginForm.code" placeholder="6 位数字验证码" maxlength="6">
|
||||
<template #append>
|
||||
<el-button :disabled="emailCodeCountdown > 0 || emailSending" @click="sendLoginCode">
|
||||
{{ emailCodeCountdown > 0 ? `${emailCodeCountdown}s 后重发` : '获取验证码' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-button type="primary" :loading="loading" class="full-btn" @click="handleEmailLogin">
|
||||
登录
|
||||
</el-button>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
<!-- 忘记密码 / 注册账号 入口 -->
|
||||
<div class="link-row">
|
||||
<el-link type="info" :underline="false" @click="openForgot">忘记密码?</el-link>
|
||||
<el-divider direction="vertical" />
|
||||
<el-link type="primary" :underline="false" @click="openRegister">注册账号</el-link>
|
||||
</div>
|
||||
|
||||
<el-dialog v-model="registerVisible" title="注册账号" width="460px" append-to-body>
|
||||
<el-form ref="registerFormRef" :model="registerForm" :rules="registerRules" label-position="top">
|
||||
<el-form-item label="登录账号" prop="username">
|
||||
<el-input v-model="registerForm.username" placeholder="用于登录的用户名" :prefix-icon="User" />
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="registerForm.email" placeholder="用于接收验证码" :prefix-icon="Message" />
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱验证码" prop="code">
|
||||
<el-input v-model="registerForm.code" placeholder="请输入验证码">
|
||||
<template #append>
|
||||
<el-button :disabled="registerCountdown > 0 || registerSending" @click="sendRegisterCode">
|
||||
{{ registerCountdown > 0 ? `${registerCountdown}s 后重发` : '获取验证码' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="密码" prop="password">
|
||||
<el-input
|
||||
v-model="registerForm.password"
|
||||
type="password"
|
||||
placeholder="至少 6 位"
|
||||
show-password
|
||||
:prefix-icon="Lock"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="确认密码" prop="confirmPassword">
|
||||
<el-input
|
||||
v-model="registerForm.confirmPassword"
|
||||
type="password"
|
||||
placeholder="请再次输入密码"
|
||||
show-password
|
||||
:prefix-icon="Lock"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="昵称" prop="nickname">
|
||||
<el-input v-model="registerForm.nickname" placeholder="选填,默认与账号相同" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="registerForm.phone" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="registerVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="handleRegister">注册并登录</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="forgotVisible" title="找回密码" width="420px" append-to-body>
|
||||
<el-form
|
||||
ref="forgotFormRef"
|
||||
:model="forgotForm"
|
||||
:rules="forgotRules"
|
||||
label-position="top"
|
||||
>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="forgotForm.email" placeholder="请输入已注册的邮箱" :prefix-icon="Message" />
|
||||
</el-form-item>
|
||||
<el-form-item label="验证码" prop="code">
|
||||
<el-input v-model="forgotForm.code" placeholder="4 位数字验证码" maxlength="4">
|
||||
<template #append>
|
||||
<el-button :disabled="forgotCountdown > 0 || forgotSending" @click="sendResetCode">
|
||||
{{ forgotCountdown > 0 ? `${forgotCountdown}s 后重发` : '获取验证码' }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="password">
|
||||
<el-input
|
||||
v-model="forgotForm.password"
|
||||
type="password"
|
||||
placeholder="至少 6 位"
|
||||
show-password
|
||||
:prefix-icon="Lock"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="确认新密码" prop="confirmPassword">
|
||||
<el-input
|
||||
v-model="forgotForm.confirmPassword"
|
||||
type="password"
|
||||
placeholder="请再次输入新密码"
|
||||
show-password
|
||||
:prefix-icon="Lock"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="forgotVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="forgotSubmitting" @click="handleResetPassword">
|
||||
确定重置
|
||||
</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-page {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
.login-card {
|
||||
width: 400px;
|
||||
max-width: 92vw;
|
||||
}
|
||||
|
||||
.login-title {
|
||||
text-align: center;
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: var(--el-color-primary);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.full-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.link-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 14px;
|
||||
}
|
||||
</style>
|
||||
678
frontend/src/views/Order/Create.vue
Normal file
678
frontend/src/views/Order/Create.vue
Normal file
@ -0,0 +1,678 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { createOrderDelivery, parseReceiver } from '@/api/orderDelivery'
|
||||
import { getShops, type ShopItem } from '@/api/shop'
|
||||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||||
import type { ProductSearchItem } from '@/api/product'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
|
||||
/** 订单类型:ORDER 组枚举,默认 JYCK 一般交易出库单 */
|
||||
const ORDER_TYPE_OPTIONS = [
|
||||
{ value: 'JYCK', label: '一般交易出库单(JYCK)' },
|
||||
{ value: 'HHCK', label: '换货出库(HHCK)' },
|
||||
{ value: 'BFCK', label: '补发出库(BFCK)' },
|
||||
]
|
||||
const DEFAULT_ORDER_TYPE = 'JYCK'
|
||||
const INVENTORY_TYPE_OPTIONS = [
|
||||
{ value: 'ZP', label: '正品(ZP)' },
|
||||
{ value: 'CC', label: '残次(CC)' },
|
||||
]
|
||||
|
||||
const router = useRouter()
|
||||
const shops = ref<ShopItem[]>([])
|
||||
const warehouses = ref<WarehouseOption[]>([])
|
||||
const expressCompanies = ref<ExpressCompanyOption[]>([])
|
||||
|
||||
/* -------------------- 订单信息(页面头部) -------------------- */
|
||||
interface HeaderForm {
|
||||
shop_id: number | null
|
||||
warehouse_id: number | null
|
||||
order_type: string
|
||||
is_urgency: 'Y' | 'N'
|
||||
invoice_flag: 'Y' | 'N'
|
||||
operator_name: string
|
||||
logistics_code: string
|
||||
logistics_name: string
|
||||
total_amount: number
|
||||
discount_amount: number
|
||||
freight: number
|
||||
ar_amount: number
|
||||
got_amount: number
|
||||
seller_message: string
|
||||
name: string
|
||||
tel: string
|
||||
mobile: string
|
||||
email: string
|
||||
country_code: string
|
||||
province: string
|
||||
city: string
|
||||
area: string
|
||||
town: string
|
||||
detail_address: string
|
||||
zip_code: string
|
||||
}
|
||||
|
||||
function emptyForm(): HeaderForm {
|
||||
return {
|
||||
shop_id: null,
|
||||
warehouse_id: null,
|
||||
order_type: DEFAULT_ORDER_TYPE,
|
||||
is_urgency: 'N',
|
||||
invoice_flag: 'N',
|
||||
operator_name: '',
|
||||
logistics_code: '',
|
||||
logistics_name: '',
|
||||
total_amount: 0,
|
||||
discount_amount: 0,
|
||||
freight: 0,
|
||||
ar_amount: 0,
|
||||
got_amount: 0,
|
||||
seller_message: '',
|
||||
name: '',
|
||||
tel: '',
|
||||
mobile: '',
|
||||
email: '',
|
||||
country_code: '',
|
||||
province: '',
|
||||
city: '',
|
||||
area: '',
|
||||
town: '',
|
||||
detail_address: '',
|
||||
zip_code: '',
|
||||
}
|
||||
}
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const form = reactive<HeaderForm>(emptyForm())
|
||||
|
||||
/** 电话与手机至少填一个 */
|
||||
function validateTelOrMobile(_rule: unknown, _value: unknown, callback: (error?: Error) => void) {
|
||||
if (form.tel || form.mobile) callback()
|
||||
else callback(new Error('电话与手机至少填写一个'))
|
||||
}
|
||||
|
||||
const rules: FormRules = {
|
||||
// 仓库必填:推送 WMS 需要 warehouseCode,且仓库接口配置(app_key/base_url)按仓库维度配置
|
||||
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
||||
name: [{ required: true, message: '请输入收件人姓名', trigger: 'blur' }],
|
||||
province: [{ required: true, message: '请输入省份', trigger: 'blur' }],
|
||||
city: [{ required: true, message: '请输入城市', trigger: 'blur' }],
|
||||
area: [{ required: true, message: '请输入区县', trigger: 'blur' }],
|
||||
town: [{ required: true, message: '请输入街道/镇', trigger: 'blur' }],
|
||||
tel: [{ validator: validateTelOrMobile, trigger: 'blur' }],
|
||||
}
|
||||
|
||||
/** 选择快递公司后自动带出名称 */
|
||||
function handleExpressChange(code: string | null) {
|
||||
const company = expressCompanies.value.find(c => c.code === code)
|
||||
form.logistics_name = company ? company.name : ''
|
||||
}
|
||||
|
||||
/* -------------------- 收件人智能识别(右侧识别区) -------------------- */
|
||||
const parseText = ref('')
|
||||
const parsing = ref(false)
|
||||
|
||||
/** 需要回填的收件人字段(与后端识别结果 / 表单一一致) */
|
||||
const PARSE_FIELDS = [
|
||||
'name', 'tel', 'mobile', 'email', 'country_code',
|
||||
'province', 'city', 'area', 'town', 'detail_address', 'zip_code',
|
||||
] as const
|
||||
|
||||
/** 粘贴文本 → AI 抽取 → 回填左侧表单(仅覆盖识别出内容的字段) */
|
||||
async function handleParseReceiver() {
|
||||
const text = parseText.value.trim()
|
||||
if (!text) {
|
||||
ElMessage.warning('请先粘贴需要识别的收件人信息')
|
||||
return
|
||||
}
|
||||
parsing.value = true
|
||||
try {
|
||||
const res = await parseReceiver(text)
|
||||
let filled = 0
|
||||
for (const key of PARSE_FIELDS) {
|
||||
const value = res[key]
|
||||
if (!value) continue
|
||||
;(form as unknown as Record<string, string>)[key] = value
|
||||
filled += 1
|
||||
}
|
||||
if (filled) ElMessage.success(`识别完成,已填充 ${filled} 个字段`)
|
||||
else ElMessage.warning('未识别到有效收件人信息,请调整文本后重试')
|
||||
} catch {
|
||||
// 拦截器已提示(未配置 AI 密钥 / 识别失败)
|
||||
} finally {
|
||||
parsing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** Enter 直接识别并阻止换行;Shift+Enter 保留换行;输入法候选确认不触发 */
|
||||
function onParseEnter(e: KeyboardEvent) {
|
||||
if (e.isComposing) return
|
||||
e.preventDefault()
|
||||
handleParseReceiver()
|
||||
}
|
||||
|
||||
/* -------------------- 商品明细(页面下方) -------------------- */
|
||||
interface DraftLine {
|
||||
product_id: number | null
|
||||
item_code: string
|
||||
item_name: string
|
||||
plan_qty: number
|
||||
actual_price: number | null
|
||||
inventory_type: 'ZP' | 'CC'
|
||||
}
|
||||
|
||||
const lines = ref<DraftLine[]>([])
|
||||
|
||||
function addLine() {
|
||||
lines.value.push({
|
||||
product_id: null,
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
plan_qty: 1,
|
||||
actual_price: null,
|
||||
inventory_type: 'ZP',
|
||||
})
|
||||
}
|
||||
|
||||
function removeLine(index: number) {
|
||||
lines.value.splice(index, 1)
|
||||
}
|
||||
|
||||
/** 选择商品后带出编码/名称,单价与数量由人工填写 */
|
||||
function onProductSelect(index: number, product: ProductSearchItem) {
|
||||
const line = lines.value[index]
|
||||
if (!line) return
|
||||
line.product_id = product.id
|
||||
line.item_code = product.item_code || ''
|
||||
line.item_name = product.item_name || ''
|
||||
}
|
||||
|
||||
/** 单行金额 = 数量 × 单价 */
|
||||
function lineAmount(line: DraftLine) {
|
||||
return (Number(line.plan_qty) || 0) * (Number(line.actual_price) || 0)
|
||||
}
|
||||
|
||||
/** 商品总价(与后端 item_amount 同口径:Σ 计划数量 × 实际单价) */
|
||||
const itemsAmount = computed(() => lines.value.reduce((sum, line) => sum + lineAmount(line), 0))
|
||||
|
||||
/** 商品总数 / 种类数(按商品编码去重) */
|
||||
const itemsTotal = computed(() => lines.value.reduce((sum, line) => sum + (Number(line.plan_qty) || 0), 0))
|
||||
const itemsKind = computed(() => new Set(lines.value.map(line => line.item_code || `#${line.product_id}`)).size)
|
||||
|
||||
/* -------------------- 提交 -------------------- */
|
||||
const submitting = ref(false)
|
||||
|
||||
async function submit() {
|
||||
if (!formRef.value) return
|
||||
|
||||
const valid = await formRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
if (!lines.value.length) {
|
||||
ElMessage.warning('请至少添加一件商品')
|
||||
return
|
||||
}
|
||||
for (let i = 0; i < lines.value.length; i++) {
|
||||
const line = lines.value[i]
|
||||
if (!line.item_code && line.product_id == null) {
|
||||
ElMessage.warning(`第 ${i + 1} 行:请选择商品`)
|
||||
return
|
||||
}
|
||||
if (!(Number(line.plan_qty) > 0)) {
|
||||
ElMessage.warning(`第 ${i + 1} 行:数量必须大于 0`)
|
||||
return
|
||||
}
|
||||
if (line.actual_price == null || String(line.actual_price).trim() === '') {
|
||||
ElMessage.warning(`第 ${i + 1} 行:请填写商品单价`)
|
||||
return
|
||||
}
|
||||
if (Number(line.actual_price) < 0) {
|
||||
ElMessage.warning(`第 ${i + 1} 行:商品单价不能小于 0`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
await createOrderDelivery({
|
||||
warehouse_id: form.warehouse_id,
|
||||
shop_id: form.shop_id,
|
||||
order_type: form.order_type,
|
||||
is_urgency: form.is_urgency,
|
||||
invoice_flag: form.invoice_flag,
|
||||
operator_name: form.operator_name || null,
|
||||
logistics_code: form.logistics_code || null,
|
||||
logistics_name: form.logistics_name || null,
|
||||
total_amount: form.total_amount,
|
||||
discount_amount: form.discount_amount,
|
||||
freight: form.freight,
|
||||
ar_amount: form.ar_amount,
|
||||
got_amount: form.got_amount,
|
||||
seller_message: form.seller_message || null,
|
||||
name: form.name,
|
||||
tel: form.tel || null,
|
||||
mobile: form.mobile || null,
|
||||
email: form.email || null,
|
||||
country_code: form.country_code || null,
|
||||
province: form.province,
|
||||
city: form.city,
|
||||
area: form.area,
|
||||
town: form.town,
|
||||
detail_address: form.detail_address || null,
|
||||
zip_code: form.zip_code || null,
|
||||
items: lines.value.map((line, index) => ({
|
||||
order_line_no: String(index + 1),
|
||||
item_code: line.item_code || null,
|
||||
item_name: line.item_name || null,
|
||||
plan_qty: Number(line.plan_qty),
|
||||
actual_price: line.actual_price == null ? null : Number(line.actual_price),
|
||||
inventory_type: line.inventory_type,
|
||||
})),
|
||||
})
|
||||
ElMessage.success('发货单创建成功')
|
||||
router.push('/order')
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
router.push('/order')
|
||||
}
|
||||
|
||||
async function fetchOptions() {
|
||||
try {
|
||||
const [ shopRes, warehouseRes, expressRes ] = await Promise.all([
|
||||
getShops({ page: 1, pageSize: 200 }),
|
||||
getWarehouseOptions(),
|
||||
getExpressCompanyOptions(),
|
||||
])
|
||||
shops.value = shopRes.list
|
||||
warehouses.value = warehouseRes
|
||||
expressCompanies.value = expressRes
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchOptions()
|
||||
addLine()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="create-card">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>创建发货单</span>
|
||||
<div>
|
||||
<el-button @click="cancel">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submit">保存</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="page-scroll">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="86px" class="compact-form">
|
||||
<el-divider content-position="left">订单信息</el-divider>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="6">
|
||||
<el-form-item label="店铺">
|
||||
<VirtualSelect
|
||||
v-model="form.shop_id"
|
||||
:options="shops"
|
||||
label-key="name"
|
||||
value-key="id"
|
||||
placeholder="未关联店铺"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="仓库" prop="warehouse_id">
|
||||
<VirtualSelect
|
||||
v-model="form.warehouse_id"
|
||||
:options="warehouses"
|
||||
label-key="name"
|
||||
value-key="id"
|
||||
placeholder="请选择仓库"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="订单类型">
|
||||
<el-select v-model="form.order_type" style="width: 100%">
|
||||
<el-option v-for="opt in ORDER_TYPE_OPTIONS" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="加急">
|
||||
<el-radio-group v-model="form.is_urgency">
|
||||
<el-radio value="N">否</el-radio>
|
||||
<el-radio value="Y">是</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="需要发票">
|
||||
<el-radio-group v-model="form.invoice_flag">
|
||||
<el-radio value="N">否</el-radio>
|
||||
<el-radio value="Y">是</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="操作人">
|
||||
<el-input v-model="form.operator_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="物流公司">
|
||||
<el-select
|
||||
v-model="form.logistics_code"
|
||||
placeholder="请选择快递公司"
|
||||
clearable
|
||||
filterable
|
||||
style="width: 100%"
|
||||
@change="handleExpressChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="c in expressCompanies"
|
||||
:key="c.code"
|
||||
:label="`${c.name}(${c.code})`"
|
||||
:value="c.code"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="6">
|
||||
<el-form-item label="物流公司名称">
|
||||
<el-input :model-value="form.logistics_name || '-'" disabled />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="订单总金额">
|
||||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="折扣金额">
|
||||
<el-input-number v-model="form.discount_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="快递费用">
|
||||
<el-input-number v-model="form.freight" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="应收金额">
|
||||
<el-input-number v-model="form.ar_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="已收金额">
|
||||
<el-input-number v-model="form.got_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="4">
|
||||
<el-form-item label="留言">
|
||||
<el-input v-model="form.seller_message" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-divider content-position="left">收件人</el-divider>
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="15">
|
||||
<el-row :gutter="0">
|
||||
<el-col :span="8">
|
||||
<el-form-item label="姓名" prop="name">
|
||||
<el-input v-model="form.name" placeholder="必填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="电话" prop="tel">
|
||||
<el-input v-model="form.tel" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="手机">
|
||||
<el-input v-model="form.mobile" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="邮箱">
|
||||
<el-input v-model="form.email" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="邮编">
|
||||
<el-input v-model="form.zip_code" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="国家编码">
|
||||
<el-input v-model="form.country_code" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="省份" prop="province">
|
||||
<el-input v-model="form.province" placeholder="必填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="城市" prop="city">
|
||||
<el-input v-model="form.city" placeholder="必填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="区县" prop="area">
|
||||
<el-input v-model="form.area" placeholder="必填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="街道/镇" prop="town">
|
||||
<el-input v-model="form.town" placeholder="必填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="16">
|
||||
<el-form-item label="详细地址">
|
||||
<el-input v-model="form.detail_address" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-col>
|
||||
<el-col :span="9">
|
||||
<div class="parse-box">
|
||||
<el-input
|
||||
v-model="parseText"
|
||||
type="textarea"
|
||||
resize="none"
|
||||
:disabled="parsing"
|
||||
placeholder="粘贴收件人信息后按 Enter 识别(Shift+Enter 换行)"
|
||||
@keydown.enter.exact="onParseEnter"
|
||||
/>
|
||||
<div class="parse-tip">
|
||||
{{ parsing ? '识别中…' : '填完按 Enter 识别,结果自动填入左侧,可再手动修改' }}
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-divider content-position="left">商品明细</el-divider>
|
||||
<div class="items-toolbar">
|
||||
<span class="items-title">共 {{ lines.length }} 项</span>
|
||||
<span class="items-title">商品总数 {{ itemsTotal }} · 种类 {{ itemsKind }}</span>
|
||||
<span class="items-total">商品总价:{{ itemsAmount.toFixed(2) }}</span>
|
||||
<el-button type="primary" size="small" @click="addLine">添加商品</el-button>
|
||||
</div>
|
||||
<el-table :data="lines" size="small" border max-height="240">
|
||||
<el-table-column label="商品" min-width="170">
|
||||
<template #default="{ row, $index }">
|
||||
<ProductSelect
|
||||
v-model="row.product_id"
|
||||
@select="(p: ProductSearchItem) => onProductSelect($index, p)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品编码" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.item_code" placeholder="自动带出" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品名称" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.item_name" placeholder="自动带出" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存类型" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-select v-model="row.inventory_type" style="width: 100%">
|
||||
<el-option
|
||||
v-for="opt in INVENTORY_TYPE_OPTIONS"
|
||||
:key="opt.value"
|
||||
:label="opt.label"
|
||||
:value="opt.value"
|
||||
/>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.plan_qty" :min="0" :precision="3" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.actual_price" :min="0" :precision="2" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="100" align="right">
|
||||
<template #default="{ row }">{{ lineAmount(row).toFixed(2) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="64" fixed="right">
|
||||
<template #default="{ $index }">
|
||||
<el-button link type="danger" @click="removeLine($index)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-form>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
/* 紧凑排版:压缩表单项行距、分割线边距与卡片内边距 */
|
||||
.compact-form :deep(.el-form-item) {
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
.compact-form :deep(.el-form-item__label) {
|
||||
padding-right: 6px;
|
||||
}
|
||||
/* 数值字段(金额)不必占满整列 */
|
||||
.compact-form :deep(.el-input-number) {
|
||||
max-width: 124px;
|
||||
}
|
||||
/* 明细表格内控件本身列宽已很窄,不做限制 */
|
||||
.compact-form :deep(.el-table .el-input-number) {
|
||||
max-width: none;
|
||||
}
|
||||
.compact-form :deep(.el-table .cell) {
|
||||
padding: 0 6px;
|
||||
}
|
||||
.compact-form :deep(.el-divider--horizontal) {
|
||||
margin: 6px 0 8px;
|
||||
}
|
||||
.compact-form :deep(.el-divider__text) {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
}
|
||||
.create-card {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.create-card :deep(.el-card__header) {
|
||||
padding: 10px 12px;
|
||||
}
|
||||
.create-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.page-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.items-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.items-title {
|
||||
color: #606266;
|
||||
font-size: 13px;
|
||||
}
|
||||
.items-total {
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
}
|
||||
/* 智能识别区(收件人右侧):高度与左侧表单一致,填完回车即识别 */
|
||||
.parse-box {
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
max-height: 100%;
|
||||
overflow: hidden;
|
||||
padding: 8px;
|
||||
border: 1px dashed #dcdfe6;
|
||||
border-radius: 4px;
|
||||
background: #fafafa;
|
||||
}
|
||||
.parse-box :deep(.el-textarea) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
}
|
||||
.parse-box :deep(.el-textarea__inner) {
|
||||
box-sizing: border-box;
|
||||
flex: 1 1 auto;
|
||||
height: auto;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.parse-tip {
|
||||
flex: 0 0 auto;
|
||||
margin-top: 6px;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
1358
frontend/src/views/Order/Index.vue
Normal file
1358
frontend/src/views/Order/Index.vue
Normal file
File diff suppressed because it is too large
Load Diff
917
frontend/src/views/OutboundOrder/Index.vue
Normal file
917
frontend/src/views/OutboundOrder/Index.vue
Normal file
@ -0,0 +1,917 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
outboundOrderApi,
|
||||
type OutboundOrder,
|
||||
type OutboundItemInput,
|
||||
type OutboundItemPayload,
|
||||
} from '@/api/outboundOrder'
|
||||
import type { StockItemLine } from '@/api/stockOrder'
|
||||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||||
import { getShops, type ShopItem } from '@/api/shop'
|
||||
import { type ProductSearchItem } from '@/api/product'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
import ProductSelect from '@/components/ProductSelect.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const STATUS_LABELS: Record<number, string> = {
|
||||
1: '待出库', 2: '已审核', 3: '已推送', 4: '已完成', 5: '已作废', 9: '已取消',
|
||||
}
|
||||
const STATUS_TAGS: Record<number, string> = { 1: 'info', 2: 'warning', 3: 'primary', 4: 'success', 5: 'danger', 9: 'danger' }
|
||||
|
||||
const TYPE_OPTIONS = [
|
||||
{ label: '普通出库单(PTCK)', value: 'PTCK' },
|
||||
{ label: '调拨出库(DBCK)', value: 'DBCK' },
|
||||
{ label: 'B2B出库(B2BCK)', value: 'B2BCK' },
|
||||
{ label: '其他出库(QTCK)', value: 'QTCK' },
|
||||
{ label: '采购退货出库单(CGTH)', value: 'CGTH' },
|
||||
]
|
||||
const INV_TYPE_OPTIONS = [
|
||||
{ label: '正品(ZP)', value: 'ZP' },
|
||||
{ label: '残次(CC)', value: 'CC' },
|
||||
]
|
||||
|
||||
const warehouses = ref<WarehouseOption[]>([])
|
||||
const warehouseSelectOptions = computed(() =>
|
||||
warehouses.value.map((w) => ({ label: `${w.code} ${w.name}`, value: w.id })),
|
||||
)
|
||||
const shops = ref<ShopItem[]>([])
|
||||
const shopSelectOptions = computed(() =>
|
||||
shops.value.map((s) => ({ label: `${s.code} ${s.name}`, value: s.id })),
|
||||
)
|
||||
|
||||
/* -------------------- 列表 -------------------- */
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
bill_no: '',
|
||||
status: '' as string | number,
|
||||
outbound_type: '' as string | number,
|
||||
})
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.bill_no) delete params.bill_no
|
||||
if (params.status === '') delete params.status
|
||||
if (params.outbound_type === '') delete params.outbound_type
|
||||
return outboundOrderApi.getList(params)
|
||||
},
|
||||
})
|
||||
async function fetchOptions() {
|
||||
try { warehouses.value = await getWarehouseOptions() } catch { warehouses.value = [] }
|
||||
try { shops.value = (await getShops({ pageSize: 200 })).list } catch { shops.value = [] }
|
||||
}
|
||||
function reset() {
|
||||
query.bill_no = ''
|
||||
query.status = ''
|
||||
query.outbound_type = ''
|
||||
search()
|
||||
}
|
||||
function typeLabel(row: OutboundOrder) {
|
||||
return TYPE_OPTIONS.find((o) => o.value === row.outbound_type)?.label || String(row.outbound_type)
|
||||
}
|
||||
/** 是否已录入明细:无明细不允许审核 */
|
||||
function hasItems(row: { item_kind?: number | string | null }) {
|
||||
return Number(row.item_kind) > 0
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 单据头 + 随单明细 -------------------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
warehouse_id: null as number | null,
|
||||
shop_id: null as number | null,
|
||||
outbound_type: 'PTCK',
|
||||
customer: '',
|
||||
operator: '',
|
||||
total_amount: 0,
|
||||
remark: '',
|
||||
})
|
||||
const rules: FormRules = {
|
||||
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
||||
}
|
||||
function resetForm() {
|
||||
Object.assign(form, {
|
||||
warehouse_id: null, shop_id: null, outbound_type: 'PTCK',
|
||||
customer: '', operator: '', total_amount: 0, remark: '',
|
||||
})
|
||||
}
|
||||
async function openCreate() {
|
||||
editId.value = null
|
||||
resetForm()
|
||||
formItems.value = []
|
||||
dialogVisible.value = true
|
||||
}
|
||||
async function openEdit(row: OutboundOrder) {
|
||||
const full = await outboundOrderApi.get(row.id)
|
||||
editId.value = full.id
|
||||
Object.assign(form, {
|
||||
warehouse_id: full.warehouse_id ?? null,
|
||||
shop_id: full.shop_id ?? null,
|
||||
outbound_type: full.outbound_type || 'PTCK',
|
||||
customer: full.customer || '',
|
||||
operator: full.operator || '',
|
||||
total_amount: Number(full.total_amount) || 0,
|
||||
remark: full.remark || '',
|
||||
})
|
||||
formItems.value = []
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = {
|
||||
warehouse_id: form.warehouse_id,
|
||||
shop_id: form.shop_id || null,
|
||||
outbound_type: form.outbound_type,
|
||||
customer: form.customer || null,
|
||||
operator: form.operator || null,
|
||||
total_amount: form.total_amount,
|
||||
remark: form.remark || null,
|
||||
} as Record<string, unknown>
|
||||
if (editId.value == null) {
|
||||
payload.items = formItems.value.map((it) => ({
|
||||
product_id: it.product_id ?? null,
|
||||
name: it.name || null,
|
||||
code: it.code || null,
|
||||
spec: it.spec || null,
|
||||
unit: it.unit || null,
|
||||
quantity: it.quantity,
|
||||
price: it.price,
|
||||
inventory_type: it.inventory_type || 'ZP',
|
||||
remark: it.remark || null,
|
||||
}))
|
||||
await outboundOrderApi.create(payload as any)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await outboundOrderApi.update(editId.value, payload as any)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 随单明细(创建时内联) -------------------- */
|
||||
const formItems = ref<OutboundItemInput[]>([])
|
||||
function addFormItem() {
|
||||
formItems.value.push({ product_id: null, name: '', code: '', spec: '', unit: '', quantity: 1, price: 0, inventory_type: 'ZP', remark: '' })
|
||||
}
|
||||
function removeFormItem(idx: number) {
|
||||
formItems.value.splice(idx, 1)
|
||||
}
|
||||
function onFormItemProductSelect(idx: number, p: ProductSearchItem) {
|
||||
const it = formItems.value[idx]
|
||||
if (!it) return
|
||||
it.product_id = p.id
|
||||
it.name = p.item_name || ''
|
||||
it.code = p.item_code || ''
|
||||
it.spec = p.sku_property || ''
|
||||
it.unit = p.stock_unit || ''
|
||||
}
|
||||
const formTotal = computed(() =>
|
||||
formItems.value.reduce((s, it) => s + (Number(it.quantity) || 0) * (Number(it.price) || 0), 0),
|
||||
)
|
||||
|
||||
/* -------------------- 状态流转 -------------------- */
|
||||
const transiting = ref(false)
|
||||
async function transit(action: 'audit' | 'push' | 'complete' | 'cancel' | 'restore') {
|
||||
if (!currentOrder.value) return
|
||||
transiting.value = true
|
||||
try {
|
||||
const id = currentOrder.value.id
|
||||
if (action === 'audit') await outboundOrderApi.audit(id)
|
||||
else if (action === 'push') await outboundOrderApi.push(id)
|
||||
else if (action === 'complete') await outboundOrderApi.complete(id)
|
||||
else if (action === 'cancel') await outboundOrderApi.cancel(id)
|
||||
else if (action === 'restore') await outboundOrderApi.restore(id)
|
||||
ElMessage.success('操作成功')
|
||||
const map: Record<string, number> = { audit: 2, push: 3, complete: 4, cancel: 9, restore: 1 }
|
||||
if (currentOrder.value) currentOrder.value.status = map[action]
|
||||
await fetchItems()
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
transiting.value = false
|
||||
}
|
||||
}
|
||||
async function handleDelete(row: OutboundOrder) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除出库单「${row.bill_no}」?`, '删除确认', {
|
||||
type: 'warning', confirmButtonText: '删除', cancelButtonText: '取消',
|
||||
})
|
||||
} catch { return }
|
||||
try {
|
||||
await outboundOrderApi.remove(row.id)
|
||||
ElMessage.success('已删除')
|
||||
if (currentOrder.value && currentOrder.value.id === row.id) {
|
||||
currentOrder.value = null
|
||||
editItems.value = []
|
||||
}
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
/** 作废:仅「已审核(2)」可作废,需确认并可填写作废原因;作废后不可恢复 */
|
||||
async function handleVoid(row: OutboundOrder) {
|
||||
let reason = ''
|
||||
try {
|
||||
const res = await ElMessageBox.prompt(
|
||||
`确认作废出库单「${row.bill_no}」?作废后不可恢复。`,
|
||||
'作废确认',
|
||||
{
|
||||
type: 'warning',
|
||||
confirmButtonText: '确认作废',
|
||||
cancelButtonText: '取消',
|
||||
inputType: 'textarea',
|
||||
inputPlaceholder: '作废原因(选填)',
|
||||
inputValidator: () => true,
|
||||
},
|
||||
)
|
||||
reason = (res.value || '').trim()
|
||||
} catch { return }
|
||||
try {
|
||||
await outboundOrderApi.voidOrder(row.id, reason ? { void_reason: reason } : {})
|
||||
ElMessage.success('已作废')
|
||||
await refreshCurrent(row.id)
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
/** 驳回:已审核/已推送且未完成 -> 回到待出库;已推送的会先调外部接口取消单据并回滚库存 */
|
||||
async function handleReject(row: OutboundOrder) {
|
||||
const tip = row.status === 3
|
||||
? `确认驳回出库单「${row.bill_no}」?将调用外部仓库接口取消已推送的单据、回滚锁定/已扣减库存,并退回「待出库」。驳回后单号会自动加后缀(如 _1),再次推送将使用新单号。`
|
||||
: `确认驳回出库单「${row.bill_no}」?驳回后回到「待出库」并自动加单号后缀(如 _1),可重新编辑后再次审核。`
|
||||
try {
|
||||
await ElMessageBox.confirm(tip, '驳回确认', {
|
||||
type: 'warning', confirmButtonText: '确认驳回', cancelButtonText: '取消',
|
||||
})
|
||||
} catch { return }
|
||||
try {
|
||||
const res = await outboundOrderApi.reject(row.id)
|
||||
ElMessage.success(res?.bill_no ? `已驳回,单号已变更为 ${res.bill_no}` : '已驳回')
|
||||
await refreshCurrent(row.id)
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
/** 若当前查看的正是被操作的这一单,重新拉取以刷新状态与统计 */
|
||||
async function refreshCurrent(id: number) {
|
||||
if (!currentOrder.value || currentOrder.value.id !== id) return
|
||||
await outboundOrderApi.get(id).then((r) => { currentOrder.value = r }).catch(() => {})
|
||||
}
|
||||
|
||||
/* -------------------- 明细 -------------------- */
|
||||
const itemsLoading = ref(false)
|
||||
const itemSaving = ref(false)
|
||||
const currentOrder = ref<OutboundOrder | null>(null)
|
||||
const activeDetailTab = ref('info')
|
||||
const initialItemIds = ref<number[]>([])
|
||||
interface EditItem {
|
||||
id: number | null
|
||||
product_id: number | null
|
||||
name: string
|
||||
code: string
|
||||
spec: string
|
||||
unit: string
|
||||
inventory_type: 'ZP' | 'CC'
|
||||
quantity: number
|
||||
/** 应/已数量(系统维护,只读展示) */
|
||||
plan_in_qty: number
|
||||
actual_in_qty: number
|
||||
plan_out_qty: number
|
||||
actual_out_qty: number
|
||||
price: number
|
||||
remark: string
|
||||
_label: string
|
||||
}
|
||||
function emptyRow(): EditItem {
|
||||
return { id: null, product_id: null, name: '', code: '', spec: '', unit: '', inventory_type: 'ZP', quantity: 1, price: 0, remark: '', _label: '', plan_in_qty: 0, actual_in_qty: 0, plan_out_qty: 0, actual_out_qty: 0 }
|
||||
}
|
||||
function isEmptyRow(it: EditItem) {
|
||||
return !it.product_id && !it.name && !it.code
|
||||
}
|
||||
const editItems = ref<EditItem[]>([])
|
||||
const editTotal = computed(() =>
|
||||
editItems.value.reduce((s, it) => s + (Number(it.quantity) || 0) * (Number(it.price) || 0), 0),
|
||||
)
|
||||
/** 明细锁定:仅「待出库(1)」可增删改明细,已审核及之后锁定(需先驳回) */
|
||||
const itemsLocked = computed(() => !!currentOrder.value && currentOrder.value.status !== 1)
|
||||
// 始终保留一行空行在末尾,选商品填充后可继续往下添加
|
||||
function ensureTrailingEmptyRow() {
|
||||
const arr = editItems.value
|
||||
const last = arr[arr.length - 1]
|
||||
if (!last || !isEmptyRow(last)) arr.push(emptyRow())
|
||||
}
|
||||
async function handleRowClick(row: OutboundOrder) {
|
||||
currentOrder.value = row
|
||||
await fetchItems()
|
||||
}
|
||||
/** 列表行内直接执行状态流转,作用于对应行 */
|
||||
async function transitRow(action: 'audit' | 'push' | 'complete' | 'cancel' | 'restore', row: OutboundOrder) {
|
||||
currentOrder.value = row
|
||||
await transit(action)
|
||||
}
|
||||
async function fetchItems() {
|
||||
if (!currentOrder.value) {
|
||||
editItems.value = [emptyRow()]
|
||||
initialItemIds.value = []
|
||||
return
|
||||
}
|
||||
itemsLoading.value = true
|
||||
try {
|
||||
const res = await outboundOrderApi.getItems(currentOrder.value.id, { pageSize: 200 })
|
||||
editItems.value = (res.list || []).map((row: StockItemLine) => ({
|
||||
id: row.id,
|
||||
product_id: row.product_id,
|
||||
name: row.name || '',
|
||||
code: row.code || '',
|
||||
spec: row.spec || '',
|
||||
unit: row.unit || '',
|
||||
inventory_type: (row.inventory_type as 'ZP' | 'CC') || 'ZP',
|
||||
quantity: Number(row.quantity) || 0,
|
||||
plan_in_qty: Number(row.plan_in_qty) || 0,
|
||||
actual_in_qty: Number(row.actual_in_qty) || 0,
|
||||
plan_out_qty: Number(row.plan_out_qty) || 0,
|
||||
actual_out_qty: Number(row.actual_out_qty) || 0,
|
||||
price: Number(row.price) || 0,
|
||||
remark: row.remark || '',
|
||||
_label: row.product ? `${row.product.item_code} ${row.product.item_name}` : (row.code ? `${row.code} ${row.name}` : ''),
|
||||
}))
|
||||
initialItemIds.value = editItems.value.filter((it) => it.id != null).map((it) => it.id as number)
|
||||
} catch {
|
||||
editItems.value = []
|
||||
} finally {
|
||||
itemsLoading.value = false
|
||||
ensureTrailingEmptyRow()
|
||||
}
|
||||
}
|
||||
function onEditItemSelect(idx: number, p: ProductSearchItem) {
|
||||
const it = editItems.value[idx]
|
||||
if (!it) return
|
||||
it.product_id = p.id
|
||||
it.name = p.item_name || ''
|
||||
it.code = p.item_code || ''
|
||||
it.spec = p.sku_property || ''
|
||||
it.unit = p.stock_unit || ''
|
||||
it._label = p.item_code ? `${p.item_code} ${p.item_name}` : p.item_name
|
||||
ensureTrailingEmptyRow()
|
||||
}
|
||||
function removeEditItem(idx: number) {
|
||||
editItems.value.splice(idx, 1)
|
||||
ensureTrailingEmptyRow()
|
||||
}
|
||||
async function saveItems() {
|
||||
if (!currentOrder.value) return
|
||||
itemSaving.value = true
|
||||
try {
|
||||
const current = editItems.value.filter((it) => !isEmptyRow(it))
|
||||
const currentIds = new Set(current.filter((it) => it.id != null).map((it) => it.id as number))
|
||||
// 删除已移除的明细
|
||||
for (const id of initialItemIds.value) {
|
||||
if (!currentIds.has(id)) await outboundOrderApi.removeItem(id)
|
||||
}
|
||||
// 新增 / 更新
|
||||
for (const it of current) {
|
||||
const payload = {
|
||||
bill_id: currentOrder.value.id,
|
||||
product_id: it.product_id,
|
||||
name: it.name || null,
|
||||
code: it.code || null,
|
||||
spec: it.spec || null,
|
||||
unit: it.unit || null,
|
||||
inventory_type: it.inventory_type,
|
||||
quantity: it.quantity,
|
||||
price: it.price,
|
||||
remark: it.remark || null,
|
||||
} as OutboundItemPayload
|
||||
if (it.id != null) await outboundOrderApi.updateItem(it.id, payload)
|
||||
else await outboundOrderApi.createItem(payload)
|
||||
}
|
||||
ElMessage.success('明细已保存')
|
||||
await fetchItems()
|
||||
// 刷新当前单据,使 item_kind 等统计字段同步(影响审核按钮可用状态)
|
||||
if (currentOrder.value) {
|
||||
await outboundOrderApi.get(currentOrder.value.id).then((r) => { currentOrder.value = r }).catch(() => {})
|
||||
}
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
itemSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchOptions()
|
||||
await fetchList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="stock-card">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>出库单</span>
|
||||
<el-button type="primary" @click="openCreate">新增出库单</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<SplitLayout :first-size="400" storage-key="outbound-order-split" :show-second="!!currentOrder">
|
||||
<template #first>
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="单号">
|
||||
<el-input v-model="query.bill_no" placeholder="支持模糊匹配" clearable @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 130px">
|
||||
<el-option v-for="(label, val) in STATUS_LABELS" :key="val" :label="label" :value="Number(val)" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="出库类型">
|
||||
<el-select v-model="query.outbound_type" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="top-table-wrap">
|
||||
<DataTable
|
||||
:loading="loading"
|
||||
:data="list"
|
||||
highlight-current-row
|
||||
class="fill-table"
|
||||
@row-click="handleRowClick"
|
||||
>
|
||||
<el-table-column prop="bill_no" label="单号" min-width="160" />
|
||||
<el-table-column label="仓库" width="150">
|
||||
<template #default="{ row }">{{ row.warehouse?.name || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="店铺" width="140">
|
||||
<template #default="{ row }">{{ row.shop?.name || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="110">
|
||||
<template #default="{ row }">{{ typeLabel(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="STATUS_TAGS[row.status]">{{ STATUS_LABELS[row.status] || row.status }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="客户" width="140">
|
||||
<template #default="{ row }">{{ row.customer || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作人" width="100">
|
||||
<template #default="{ row }">{{ row.operator || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建人" width="100">
|
||||
<template #default="{ row }">{{ row.creator?.nickname || row.creator?.username || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="110" align="right">
|
||||
<template #default="{ row }">{{ row.total_amount }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品总数" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.item_total ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品种类" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.item_kind ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="300" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button v-if="row.status === 1" link type="primary" size="small" :disabled="transiting || !hasItems(row)" @click="transitRow('audit', row)">审核</el-button>
|
||||
<el-button v-if="row.status === 2" link type="primary" size="small" :disabled="transiting" @click="transitRow('push', row)">推送</el-button>
|
||||
<el-button v-if="row.status === 3" link type="primary" size="small" :disabled="transiting" @click="transitRow('complete', row)">完成</el-button>
|
||||
<el-button v-if="row.status === 9" link type="primary" size="small" :disabled="transiting" @click="transitRow('restore', row)">恢复</el-button>
|
||||
<el-button v-if="row.status === 2 || row.status === 3" link type="warning" size="small" :disabled="transiting" @click="handleReject(row)">驳回</el-button>
|
||||
<el-button v-if="row.status === 2" link type="danger" size="small" :disabled="transiting" @click="handleVoid(row)">作废</el-button>
|
||||
<el-button v-if="row.status === 1 || row.status === 3" link type="danger" size="small" :disabled="transiting" @click="transitRow('cancel', row)">取消</el-button>
|
||||
<el-button v-if="row.status === 1" link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button v-if="row.status === 1 || row.status === 9" link type="danger" size="small" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #second>
|
||||
<div class="detail-wrap" v-if="currentOrder">
|
||||
<el-tabs v-model="activeDetailTab" type="border-card" class="detail-tabs">
|
||||
<el-tab-pane label="单据信息" name="info">
|
||||
<div class="info-pane">
|
||||
<div class="order-info">
|
||||
<el-descriptions :column="3" border size="small">
|
||||
<el-descriptions-item label="单号">{{ currentOrder.bill_no }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="STATUS_TAGS[currentOrder.status]">{{ STATUS_LABELS[currentOrder.status] || currentOrder.status }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="类型">{{ typeLabel(currentOrder) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="仓库">{{ currentOrder.warehouse?.name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="店铺">{{ currentOrder.shop?.name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="客户">{{ currentOrder.customer || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="操作人">{{ currentOrder.operator || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="总金额">{{ currentOrder.total_amount }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="2">{{ currentOrder.remark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废人">{{ currentOrder.voider?.nickname || currentOrder.voider?.username || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废时间">{{ currentOrder.void_at || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item v-if="currentOrder.status === 5" label="作废原因">{{ currentOrder.void_reason || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<div class="status-actions">
|
||||
<el-tooltip :content="currentOrder.status !== 1 ? '仅「待出库」状态可以审核' : (!hasItems(currentOrder) ? '单据无明细,请先录入明细' : '')" :disabled="currentOrder.status === 1 && hasItems(currentOrder)">
|
||||
<el-button size="small" :disabled="transiting || currentOrder.status !== 1 || !hasItems(currentOrder)" @click="transit('audit')">审核</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="currentOrder.status === 2 ? '' : '请先审核,仅「已审核」状态可推送到外部仓库'" :disabled="currentOrder.status === 2">
|
||||
<el-button size="small" type="primary" :disabled="transiting || currentOrder.status !== 2" @click="transit('push')">推送到外部仓库</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="currentOrder.status === 3 ? '' : '仅「已推送」状态可完成出库'" :disabled="currentOrder.status === 3">
|
||||
<el-button size="small" :disabled="transiting || currentOrder.status !== 3" @click="transit('complete')">完成</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="currentOrder.status === 9 ? '' : '仅「已取消」状态可恢复'" :disabled="currentOrder.status === 9">
|
||||
<el-button size="small" :disabled="transiting || currentOrder.status !== 9" @click="transit('restore')">恢复</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="(currentOrder.status === 2 || currentOrder.status === 3) ? '' : '仅「已审核」「已推送」状态可驳回'" :disabled="currentOrder.status === 2 || currentOrder.status === 3">
|
||||
<el-button size="small" type="warning" plain :disabled="transiting || (currentOrder.status !== 2 && currentOrder.status !== 3)" @click="handleReject(currentOrder)">驳回</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="currentOrder.status === 2 ? '' : '仅「已审核」状态可作废'" :disabled="currentOrder.status === 2">
|
||||
<el-button size="small" type="danger" plain :disabled="transiting || currentOrder.status !== 2" @click="handleVoid(currentOrder)">作废</el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip :content="(currentOrder.status === 2 || currentOrder.status === 4 || currentOrder.status === 9) ? '已审核请使用驳回/作废;已完成/已取消不可取消' : ''" :disabled="currentOrder.status !== 2 && currentOrder.status !== 4 && currentOrder.status !== 9">
|
||||
<el-button size="small" type="danger" plain :disabled="transiting || currentOrder.status === 2 || currentOrder.status === 4 || currentOrder.status === 9" @click="transit('cancel')">取消</el-button>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ext-wrap">
|
||||
<h4>WMS 推送结果</h4>
|
||||
<template v-if="currentOrder.wms_push_result">
|
||||
<el-descriptions :column="2" border size="small">
|
||||
<el-descriptions-item label="推送时间">{{ currentOrder.pushed_at || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="结果">
|
||||
<el-tag :type="currentOrder.wms_push_result.success ? 'success' : 'danger'">
|
||||
{{ currentOrder.wms_push_result.success ? '成功' : '失败' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="外部单号">{{ currentOrder.wms_push_result.deliveryOrderCode || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="返回码">{{ currentOrder.wms_push_result.code ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="消息" :span="2">{{ currentOrder.wms_push_result.message || currentOrder.wms_push_result.error || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</template>
|
||||
<p v-else class="muted">尚未推送到外部仓库</p>
|
||||
</div>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="明细" name="detail">
|
||||
<div class="items-toolbar">
|
||||
<span class="items-title">出库明细</span>
|
||||
<span class="total">合计金额:{{ editTotal.toFixed(2) }}</span>
|
||||
<span v-if="itemsLocked" class="lock-hint">单据已审核/已结束,明细已锁定(仅「待出库」可增删改)</span>
|
||||
<el-button type="primary" :disabled="!currentOrder || itemSaving || itemsLocked" :loading="itemSaving" @click="saveItems">保存明细</el-button>
|
||||
</div>
|
||||
<div class="bottom-table-wrap" v-loading="itemsLoading">
|
||||
<el-table :data="editItems" size="small" border class="fill-table">
|
||||
<el-table-column type="index" label="行号" width="60" align="center" />
|
||||
<el-table-column label="系统商品" min-width="220">
|
||||
<template #default="{ row, $index }">
|
||||
<ProductSelect
|
||||
v-model="row.product_id"
|
||||
:model-label="row._label"
|
||||
:disabled="itemsLocked"
|
||||
@select="(p: ProductSearchItem) => onEditItemSelect($index, p)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="名称" min-width="140">
|
||||
<template #default="{ row }"><el-input v-model="row.name" placeholder="自动带出" :disabled="itemsLocked" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="编码" width="110">
|
||||
<template #default="{ row }"><el-input v-model="row.code" placeholder="自动带出" :disabled="itemsLocked" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="规格" width="100">
|
||||
<template #default="{ row }"><el-input v-model="row.spec" :disabled="itemsLocked" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单位" width="80">
|
||||
<template #default="{ row }"><el-input v-model="row.unit" :disabled="itemsLocked" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存类型" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-select v-model="row.inventory_type" :disabled="itemsLocked" style="width: 100%">
|
||||
<el-option v-for="o in INV_TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.quantity" :min="0" :precision="0" :disabled="itemsLocked" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="应出数量" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.plan_out_qty ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="已出数量" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.actual_out_qty ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.price" :min="0" :precision="2" :disabled="itemsLocked" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="110" align="right">
|
||||
<template #default="{ row }">{{ ((Number(row.quantity) || 0) * (Number(row.price) || 0)).toFixed(2) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="70" fixed="right">
|
||||
<template #default="{ $index }">
|
||||
<el-button link type="danger" :disabled="itemsLocked" @click="removeEditItem($index)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<el-empty v-else description="请点击上方单据查看明细" />
|
||||
</template>
|
||||
</SplitLayout>
|
||||
|
||||
<!-- 新增 / 编辑 对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="editId == null ? '新增出库单' : '编辑出库单'"
|
||||
width="880px"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="仓库" prop="warehouse_id">
|
||||
<VirtualSelect
|
||||
v-model="form.warehouse_id"
|
||||
:options="warehouseSelectOptions"
|
||||
placeholder="请选择仓库"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="出库类型">
|
||||
<el-select v-model="form.outbound_type" style="width: 100%">
|
||||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="目标店铺">
|
||||
<VirtualSelect
|
||||
v-model="form.shop_id"
|
||||
:options="shopSelectOptions"
|
||||
placeholder="选填"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="客户/收货方">
|
||||
<el-input v-model="form.customer" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="操作人">
|
||||
<el-input v-model="form.operator" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="单据金额">
|
||||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 随单商品明细(仅新建时) -->
|
||||
<template v-if="editId == null">
|
||||
<el-divider content-position="left">商品明细</el-divider>
|
||||
<div class="items-toolbar">
|
||||
<span class="items-title">共 {{ formItems.length }} 项</span>
|
||||
<span class="total">合计金额:{{ formTotal.toFixed(2) }}</span>
|
||||
<el-button type="primary" @click="addFormItem">添加商品</el-button>
|
||||
</div>
|
||||
<el-table :data="formItems" size="small" border class="fill-table" style="max-height: 280px; overflow: auto">
|
||||
<el-table-column label="系统商品" min-width="220">
|
||||
<template #default="{ row, $index }">
|
||||
<ProductSelect
|
||||
v-model="row.product_id"
|
||||
@select="(p: ProductSearchItem) => onFormItemProductSelect($index, p)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="名称" min-width="140">
|
||||
<template #default="{ row }"><el-input v-model="row.name" placeholder="自动带出" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="编码" width="110">
|
||||
<template #default="{ row }"><el-input v-model="row.code" placeholder="自动带出" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="规格" width="100">
|
||||
<template #default="{ row }"><el-input v-model="row.spec" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单位" width="80">
|
||||
<template #default="{ row }"><el-input v-model="row.unit" /></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="库存类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-select v-model="row.inventory_type" style="width: 100%">
|
||||
<el-option v-for="o in INV_TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="数量" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.quantity" :min="0" :precision="0" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="单价" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.price" :min="0" :precision="2" style="width: 100%" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="70" fixed="right">
|
||||
<template #default="{ $index }">
|
||||
<el-button link type="danger" @click="removeFormItem($index)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</template>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.stock-card {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.stock-card :deep(.el-card__header) {
|
||||
padding: 8px 14px;
|
||||
}
|
||||
.stock-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 10px 14px;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.top-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.items-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.status-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.detail-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
.order-info {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.order-info :deep(.el-descriptions) {
|
||||
flex: 1;
|
||||
}
|
||||
.items-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
.total {
|
||||
color: #e6a23c;
|
||||
font-weight: 600;
|
||||
}
|
||||
.lock-hint {
|
||||
color: #e6a23c;
|
||||
}
|
||||
.bottom-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.detail-tabs {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.detail-tabs :deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.detail-tabs :deep(.el-tab-pane) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.fill-table {
|
||||
height: 100%;
|
||||
}
|
||||
.info-pane {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
.ext-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
padding: 8px 4px 4px;
|
||||
}
|
||||
.ext-wrap h4 {
|
||||
margin: 12px 0 8px;
|
||||
color: #606266;
|
||||
}
|
||||
.ext-collapse {
|
||||
margin-top: 8px;
|
||||
}
|
||||
.ext-block {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.ext-subtitle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #606266;
|
||||
}
|
||||
.muted {
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
110
frontend/src/views/Principal/Create.vue
Normal file
110
frontend/src/views/Principal/Create.vue
Normal file
@ -0,0 +1,110 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { useMenuStore } from '@/store/menu'
|
||||
import { createPrincipal } from '@/api/principal'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const menuStore = useMenuStore()
|
||||
const router = useRouter()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
const form = reactive({
|
||||
name: '',
|
||||
type: 1,
|
||||
contact_name: '',
|
||||
contact_phone: '',
|
||||
remark: '',
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入主体名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择主体类型', trigger: 'change' }],
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
await createPrincipal({ ...form })
|
||||
ElMessage.success('主体创建成功')
|
||||
// 重新拉取用户信息(已关联主体)并重建菜单/路由
|
||||
await auth.fetchProfile()
|
||||
await menuStore.fetchMenus()
|
||||
router.replace('/dashboard')
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="create-principal">
|
||||
<el-card class="panel" header="创建主体">
|
||||
<template #header>
|
||||
<div class="panel-header">
|
||||
<el-icon><OfficeBuilding /></el-icon>
|
||||
<span>创建主体</span>
|
||||
</div>
|
||||
</template>
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
title="你当前尚未关联任何主体,请先创建一个主体以使用系统功能"
|
||||
style="margin-bottom: 20px"
|
||||
/>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px" style="max-width: 520px">
|
||||
<el-form-item label="主体名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="主体显示名称,如 某某贸易公司" />
|
||||
</el-form-item>
|
||||
<el-form-item label="主体类型" prop="type">
|
||||
<el-select v-model="form.type" placeholder="请选择" style="width: 100%">
|
||||
<el-option :value="1" label="自营" />
|
||||
<el-option :value="2" label="加盟" />
|
||||
<el-option :value="3" label="外部" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="联系人">
|
||||
<el-input v-model="form.contact_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系电话">
|
||||
<el-input v-model="form.contact_phone" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="submitting" @click="handleSubmit">创建主体</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.create-principal {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 32px 16px;
|
||||
}
|
||||
|
||||
.panel {
|
||||
width: 640px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.panel-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
159
frontend/src/views/Principal/Index.vue
Normal file
159
frontend/src/views/Principal/Index.vue
Normal file
@ -0,0 +1,159 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { getPrincipals, createPrincipal, type PrincipalPayload } from '@/api/principal'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
const query = reactive({ page: 1, pageSize: DEFAULT_PAGE_SIZE, keyword: '' })
|
||||
|
||||
const TYPE_LABELS: Record<number, string> = { 1: '自营', 2: '加盟', 3: '外部' }
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => getPrincipals({ ...query }),
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
search()
|
||||
}
|
||||
|
||||
// 新建主体弹窗
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const form = reactive<PrincipalPayload>({
|
||||
name: '',
|
||||
type: 1,
|
||||
contact_name: '',
|
||||
contact_phone: '',
|
||||
remark: '',
|
||||
})
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入主体名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择主体类型', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
form.name = ''
|
||||
form.type = 1
|
||||
form.contact_name = ''
|
||||
form.contact_phone = ''
|
||||
form.remark = ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitCreate() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
await createPrincipal({ ...form })
|
||||
ElMessage.success('主体创建成功')
|
||||
dialogVisible.value = false
|
||||
// 新主体会被后端绑定为当前用户所属:刷新列表 + 重新拉取账号信息,使顶栏“选择主体”下拉实时同步
|
||||
await auth.fetchProfile()
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>主体管理</span>
|
||||
<el-button type="primary" @click="openCreate">新建主体</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="关键词">
|
||||
<el-input v-model="query.keyword" placeholder="主体名称" clearable @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<DataTable :loading="loading" :data="list">
|
||||
<el-table-column prop="name" label="名称" min-width="160" />
|
||||
<el-table-column label="类型" width="100">
|
||||
<template #default="{ row }">{{ TYPE_LABELS[row.type] || row.type }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="contact_name" label="联系人" width="120" />
|
||||
<el-table-column prop="contact_phone" label="联系电话" width="140" />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||||
</DataTable>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-dialog v-model="dialogVisible" title="新建主体" width="520px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px">
|
||||
<el-form-item label="主体名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="主体显示名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="主体类型" prop="type">
|
||||
<el-select v-model="form.type" placeholder="请选择" style="width: 100%">
|
||||
<el-option :value="1" label="自营" />
|
||||
<el-option :value="2" label="加盟" />
|
||||
<el-option :value="3" label="外部" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="联系人">
|
||||
<el-input v-model="form.contact_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系电话">
|
||||
<el-input v-model="form.contact_phone" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitCreate">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
335
frontend/src/views/PrincipalUser/Index.vue
Normal file
335
frontend/src/views/PrincipalUser/Index.vue
Normal file
@ -0,0 +1,335 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getPrincipalUsers,
|
||||
invitePrincipalUser,
|
||||
updatePrincipalUser,
|
||||
deletePrincipalUser,
|
||||
type PrincipalUserItem,
|
||||
} from '@/api/principalUser'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
role: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const ROLE_LABELS: Record<string, string> = { owner: '所有者', admin: '管理员', member: '成员' }
|
||||
|
||||
function roleText(role: string | null | undefined) {
|
||||
return (role && ROLE_LABELS[role]) || role || '-'
|
||||
}
|
||||
|
||||
function userLabel(row: PrincipalUserItem) {
|
||||
const u = row.user
|
||||
if (!u) return `用户#${row.user_id}`
|
||||
return u.nickname || u.username || u.email || `用户#${row.user_id}`
|
||||
}
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (params.role === '') delete params.role
|
||||
if (params.status === '') delete params.status
|
||||
return getPrincipalUsers(params)
|
||||
},
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.role = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
// 邀请用户
|
||||
const inviteVisible = ref(false)
|
||||
const inviteSubmitting = ref(false)
|
||||
const inviteFormRef = ref<FormInstance>()
|
||||
const inviteForm = reactive({ email: '', name: '' })
|
||||
const inviteRules: FormRules = {
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱', trigger: 'blur' },
|
||||
{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' },
|
||||
],
|
||||
name: [{ required: true, message: '请输入用户名称', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
/** 邀请成功后返回的账号信息(初始密码仅返回一次) */
|
||||
const inviteResult = ref<{ username: string; password: string } | null>(null)
|
||||
const inviteResultVisible = ref(false)
|
||||
|
||||
/** 复制文本:优先 Clipboard API,非安全上下文回退到 execCommand */
|
||||
async function copyText(text: string) {
|
||||
if (!text) return
|
||||
try {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
ElMessage.success('已复制')
|
||||
return
|
||||
}
|
||||
throw new Error('fallback')
|
||||
} catch {
|
||||
const input = document.createElement('textarea')
|
||||
input.value = text
|
||||
input.style.position = 'fixed'
|
||||
input.style.opacity = '0'
|
||||
document.body.appendChild(input)
|
||||
input.select()
|
||||
try {
|
||||
document.execCommand('copy')
|
||||
ElMessage.success('已复制')
|
||||
} catch {
|
||||
ElMessage.error('复制失败,请手动选择复制')
|
||||
} finally {
|
||||
document.body.removeChild(input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openInvite() {
|
||||
inviteForm.email = ''
|
||||
inviteForm.name = ''
|
||||
inviteVisible.value = true
|
||||
}
|
||||
|
||||
async function submitInvite() {
|
||||
if (!inviteFormRef.value) return
|
||||
await inviteFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
inviteSubmitting.value = true
|
||||
try {
|
||||
const res = await invitePrincipalUser({ ...inviteForm })
|
||||
inviteVisible.value = false
|
||||
ElMessage.success('邀请成功')
|
||||
// 账号与初始密码仅返回一次,展示在结果弹窗中并支持一键复制
|
||||
inviteResult.value = { username: res.username, password: res.password }
|
||||
inviteResultVisible.value = true
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
inviteSubmitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 编辑角色 / 状态
|
||||
const editVisible = ref(false)
|
||||
const editSubmitting = ref(false)
|
||||
const editFormRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const editForm = reactive({ role: 'member', status: 1 })
|
||||
const editRules: FormRules = {
|
||||
role: [{ required: true, message: '请选择角色', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openEdit(row: PrincipalUserItem) {
|
||||
editId.value = row.id
|
||||
editForm.role = row.role || 'member'
|
||||
editForm.status = row.status
|
||||
editVisible.value = true
|
||||
}
|
||||
|
||||
async function submitEdit() {
|
||||
if (!editFormRef.value || editId.value == null) return
|
||||
await editFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
editSubmitting.value = true
|
||||
try {
|
||||
await updatePrincipalUser(editId.value as number, { role: editForm.role, status: editForm.status })
|
||||
ElMessage.success('保存成功')
|
||||
editVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
editSubmitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleUnbind(row: PrincipalUserItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认将「${userLabel(row)}」从当前主体解绑?`, '解绑确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '解绑',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deletePrincipalUser(row.id)
|
||||
ElMessage.success('已解绑')
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>账号</span>
|
||||
<el-button type="primary" @click="openInvite">邀请用户</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="角色">
|
||||
<el-select v-model="query.role" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option label="所有者" value="owner" />
|
||||
<el-option label="管理员" value="admin" />
|
||||
<el-option label="成员" value="member" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<DataTable :loading="loading" :data="list">
|
||||
<el-table-column label="用户" min-width="140">
|
||||
<template #default="{ row }">{{ userLabel(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="邮箱" prop="user.email" min-width="180" />
|
||||
<el-table-column label="角色" width="100">
|
||||
<template #default="{ row }">{{ roleText(row.role) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="默认主体" width="100">
|
||||
<template #default="{ row }">{{ row.is_default === 1 ? '是' : '否' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="160" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleUnbind(row)">解绑</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-dialog v-model="inviteVisible" title="邀请用户" width="480px">
|
||||
<el-form ref="inviteFormRef" :model="inviteForm" :rules="inviteRules" label-width="88px">
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="inviteForm.email" placeholder="被邀请人邮箱,将作为登录账号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="用户名称" prop="name">
|
||||
<el-input v-model="inviteForm.name" placeholder="昵称 / 姓名" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="inviteVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="inviteSubmitting" @click="submitInvite">确定邀请</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="editVisible" title="编辑成员" width="480px">
|
||||
<el-form ref="editFormRef" :model="editForm" :rules="editRules" label-width="88px">
|
||||
<el-form-item label="角色" prop="role">
|
||||
<el-select v-model="editForm.role" style="width: 100%">
|
||||
<el-option label="所有者" value="owner" />
|
||||
<el-option label="管理员" value="admin" />
|
||||
<el-option label="成员" value="member" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="editForm.status" style="width: 100%">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="editVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="editSubmitting" @click="submitEdit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="inviteResultVisible" title="账号已开通" width="520px">
|
||||
<el-alert
|
||||
type="warning"
|
||||
:closable="false"
|
||||
title="初始密码仅显示一次,请复制后妥善交付给被邀请人,并提醒其尽快登录修改密码"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<div class="copy-row">
|
||||
<span class="copy-label">登录账号</span>
|
||||
<el-input :model-value="inviteResult?.username" readonly>
|
||||
<template #append>
|
||||
<el-button @click="copyText(inviteResult?.username || '')">复制</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<div class="copy-row">
|
||||
<span class="copy-label">初始密码</span>
|
||||
<el-input :model-value="inviteResult?.password" readonly show-password>
|
||||
<template #append>
|
||||
<el-button @click="copyText(inviteResult?.password || '')">复制</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<template #footer>
|
||||
<el-button @click="copyText(`登录账号:${inviteResult?.username}\n初始密码:${inviteResult?.password}`)">
|
||||
复制全部
|
||||
</el-button>
|
||||
<el-button type="primary" @click="inviteResultVisible = false">我已记录</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.copy-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.copy-label {
|
||||
width: 68px;
|
||||
flex-shrink: 0;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
465
frontend/src/views/Product/Index.vue
Normal file
465
frontend/src/views/Product/Index.vue
Normal file
@ -0,0 +1,465 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getProducts,
|
||||
createProduct,
|
||||
updateProduct,
|
||||
deleteProduct,
|
||||
type ProductItem,
|
||||
} from '@/api/product'
|
||||
import ImageUploader from '@/components/ImageUploader.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
keyword: '',
|
||||
category_name: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (!params.category_name) delete params.category_name
|
||||
if (params.status === '') delete params.status
|
||||
return getProducts(params)
|
||||
},
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
query.category_name = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
const drawerVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
goods_code: '',
|
||||
barcode: '',
|
||||
item_type: 1,
|
||||
category_id: null as number | null,
|
||||
category_name: '',
|
||||
brand_name: '',
|
||||
sku_property: '',
|
||||
stock_unit: '',
|
||||
length: null as number | null,
|
||||
width: null as number | null,
|
||||
height: null as number | null,
|
||||
volume: null as number | null,
|
||||
gross_weight: null as number | null,
|
||||
net_weight: null as number | null,
|
||||
is_area_sale: 'N',
|
||||
is_sn_mgmt: 'N',
|
||||
is_shelf_life_mgmt: 'N',
|
||||
is_batch_mgmt: 'N',
|
||||
tag_price: null as number | null,
|
||||
retail_price: 0,
|
||||
cost_price: null as number | null,
|
||||
image: '',
|
||||
images: [] as string[],
|
||||
status: 1,
|
||||
remark: '',
|
||||
})
|
||||
const EMPTY_FORM = {
|
||||
item_code: '',
|
||||
item_name: '',
|
||||
goods_code: '',
|
||||
barcode: '',
|
||||
item_type: 1,
|
||||
category_id: null,
|
||||
category_name: '',
|
||||
brand_name: '',
|
||||
sku_property: '',
|
||||
stock_unit: '',
|
||||
length: null,
|
||||
width: null,
|
||||
height: null,
|
||||
volume: null,
|
||||
gross_weight: null,
|
||||
net_weight: null,
|
||||
is_area_sale: 'N',
|
||||
is_sn_mgmt: 'N',
|
||||
is_shelf_life_mgmt: 'N',
|
||||
is_batch_mgmt: 'N',
|
||||
tag_price: null,
|
||||
retail_price: 0,
|
||||
cost_price: null,
|
||||
image: '',
|
||||
images: [] as string[],
|
||||
status: 1,
|
||||
remark: '',
|
||||
}
|
||||
const rules: FormRules = {
|
||||
item_code: [{ required: true, message: '请输入商品编码', trigger: 'blur' }],
|
||||
item_name: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
retail_price: [{ required: true, message: '请输入零售价', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editId.value = null
|
||||
Object.assign(form, EMPTY_FORM)
|
||||
// EMPTY_FORM 里的数组会被 Object.assign 共享引用,这里换成新数组
|
||||
form.images = []
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: ProductItem) {
|
||||
editId.value = row.id
|
||||
Object.assign(form, {
|
||||
item_code: row.item_code,
|
||||
item_name: row.item_name,
|
||||
goods_code: row.goods_code || '',
|
||||
barcode: row.barcode || '',
|
||||
item_type: row.item_type,
|
||||
category_id: row.category_id,
|
||||
category_name: row.category_name || '',
|
||||
brand_name: row.brand_name || '',
|
||||
sku_property: row.sku_property || '',
|
||||
stock_unit: row.stock_unit || '',
|
||||
length: toNumberOrNull(row.length),
|
||||
width: toNumberOrNull(row.width),
|
||||
height: toNumberOrNull(row.height),
|
||||
volume: toNumberOrNull(row.volume),
|
||||
gross_weight: toNumberOrNull(row.gross_weight),
|
||||
net_weight: toNumberOrNull(row.net_weight),
|
||||
is_area_sale: row.is_area_sale || 'N',
|
||||
is_sn_mgmt: row.is_sn_mgmt || 'N',
|
||||
is_shelf_life_mgmt: row.is_shelf_life_mgmt || 'N',
|
||||
is_batch_mgmt: row.is_batch_mgmt || 'N',
|
||||
tag_price: toNumberOrNull(row.tag_price),
|
||||
retail_price: Number(row.retail_price) || 0,
|
||||
cost_price: toNumberOrNull(row.cost_price),
|
||||
image: row.image || '',
|
||||
images: imagesOf(row),
|
||||
status: row.status,
|
||||
remark: row.remark || '',
|
||||
})
|
||||
drawerVisible.value = true
|
||||
}
|
||||
|
||||
/** 空值原样返回 null,避免把空串塞进 number 输入框 */
|
||||
function toNumberOrNull(value: number | string | null | undefined) {
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
return Number(value)
|
||||
}
|
||||
|
||||
/** 图片组:优先取 images,兼容历史单图 image */
|
||||
function imagesOf(row: ProductItem): string[] {
|
||||
const list = Array.isArray(row.images) ? row.images.filter(Boolean) : []
|
||||
if (list.length) return list
|
||||
return row.image ? [ row.image ] : []
|
||||
}
|
||||
|
||||
/** 主图:图片组首张 */
|
||||
function coverOf(row: ProductItem): string {
|
||||
return imagesOf(row)[0] || ''
|
||||
}
|
||||
|
||||
/** 随机生成商品编码(仅新增时使用):P + 时间戳 + 随机数,降低与手输编码冲突概率 */
|
||||
function genRandomCode() {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const d = new Date()
|
||||
const ts =
|
||||
`${pad(d.getFullYear() % 100)}${pad(d.getMonth() + 1)}${pad(d.getDate())}` +
|
||||
`${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`
|
||||
const rand = Math.floor(100000 + Math.random() * 900000)
|
||||
form.item_code = `P${ts}${rand}`
|
||||
formRef.value?.clearValidate('item_code')
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
// 主图冗余取图片组首张,继续兼容外部系统与历史单图字段
|
||||
const payload = { ...form, image: form.images[0] || '' }
|
||||
if (editId.value == null) {
|
||||
await createProduct(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await updateProduct(editId.value, payload)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
drawerVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(row: ProductItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除商品「${row.item_name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deleteProduct(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>商品</span>
|
||||
<el-button type="primary" @click="openCreate">新增商品</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="商品编码/货物编码/条码/名称"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称">
|
||||
<el-input
|
||||
v-model="query.category_name"
|
||||
placeholder="精确匹配"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<DataTable :loading="loading" :data="list">
|
||||
<el-table-column prop="item_code" label="商品编码" width="130" />
|
||||
<el-table-column prop="goods_code" label="货物编码" width="120" />
|
||||
<el-table-column prop="barcode" label="条码" width="120" />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="160" />
|
||||
<el-table-column label="图片" width="80" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-image
|
||||
v-if="coverOf(row)"
|
||||
:src="coverOf(row)"
|
||||
fit="cover"
|
||||
style="width: 44px; height: 44px; border-radius: 4px"
|
||||
:preview-src-list="imagesOf(row)"
|
||||
preview-teleported
|
||||
/>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="category_name" label="分类名称" width="110" />
|
||||
<el-table-column prop="sku_property" label="SKU规格" width="110" />
|
||||
<el-table-column prop="stock_unit" label="库存单位" width="90" />
|
||||
<el-table-column label="正品可用" width="90" align="right">
|
||||
<template #default="{ row }">{{ row.zc_available ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="正品锁定" width="90" align="right">
|
||||
<template #default="{ row }">{{ row.zc_locked ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="次品可用" width="90" align="right">
|
||||
<template #default="{ row }">{{ row.cc_available ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="次品锁定" width="90" align="right">
|
||||
<template #default="{ row }">{{ row.cc_locked ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="brand_name" label="品牌" width="100" />
|
||||
<el-table-column label="零售价" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.retail_price }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="成本价" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.cost_price ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-drawer
|
||||
v-model="drawerVisible"
|
||||
:title="editId == null ? '新增商品' : '编辑商品'"
|
||||
direction="rtl"
|
||||
size="580px"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
|
||||
<el-form-item label="商品编码" prop="item_code">
|
||||
<el-input v-model="form.item_code" placeholder="同一主体下唯一">
|
||||
<template v-if="editId == null" #append>
|
||||
<el-button @click="genRandomCode">随机生成</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品名称" prop="item_name">
|
||||
<el-input v-model="form.item_name" placeholder="请输入商品名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="货物编码" prop="goods_code">
|
||||
<el-input v-model="form.goods_code" placeholder="选填,与条码可二选一" />
|
||||
</el-form-item>
|
||||
<el-form-item label="条码" prop="barcode">
|
||||
<el-input v-model="form.barcode" placeholder="选填,商品条码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称" prop="category_name">
|
||||
<el-input v-model="form.category_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="SKU规格" prop="sku_property">
|
||||
<el-input v-model="form.sku_property" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="库存单位" prop="stock_unit">
|
||||
<el-input v-model="form.stock_unit" placeholder="如 件 / 箱" />
|
||||
</el-form-item>
|
||||
<el-form-item label="品牌名称" prop="brand_name">
|
||||
<el-input v-model="form.brand_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="标价" prop="tag_price">
|
||||
<el-input-number
|
||||
v-model="form.tag_price"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
placeholder="选填"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="零售价" prop="retail_price">
|
||||
<el-input-number v-model="form.retail_price" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="成本价" prop="cost_price">
|
||||
<el-input-number
|
||||
v-model="form.cost_price"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
placeholder="选填"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">物流属性(选填)</el-divider>
|
||||
<el-form-item label="长/宽/高 (cm)">
|
||||
<div class="field-row">
|
||||
<el-input-number v-model="form.length" :min="0" :precision="2" placeholder="长(cm)" />
|
||||
<el-input-number v-model="form.width" :min="0" :precision="2" placeholder="宽(cm)" />
|
||||
<el-input-number v-model="form.height" :min="0" :precision="2" placeholder="高(cm)" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="体积 (cm³)">
|
||||
<el-input-number
|
||||
v-model="form.volume"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
placeholder="留空可由长×宽×高自动推算"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="毛重/净重 (g)">
|
||||
<div class="field-row">
|
||||
<el-input-number v-model="form.gross_weight" :min="0" :precision="0" placeholder="毛重(g)" />
|
||||
<el-input-number v-model="form.net_weight" :min="0" :precision="0" placeholder="净重(g)" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="区域销售">
|
||||
<el-switch v-model="form.is_area_sale" active-value="Y" inactive-value="N" />
|
||||
</el-form-item>
|
||||
<el-form-item label="序列号管理">
|
||||
<el-switch v-model="form.is_sn_mgmt" active-value="Y" inactive-value="N" />
|
||||
</el-form-item>
|
||||
<el-form-item label="保质期管理">
|
||||
<el-switch v-model="form.is_shelf_life_mgmt" active-value="Y" inactive-value="N" />
|
||||
</el-form-item>
|
||||
<el-form-item label="批次管理">
|
||||
<el-switch v-model="form.is_batch_mgmt" active-value="Y" inactive-value="N" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">图片</el-divider>
|
||||
<el-form-item label="图片组" prop="images">
|
||||
<ImageUploader v-model="form.images" />
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">其它</el-divider>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="drawerVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.field-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
437
frontend/src/views/Shop/Index.vue
Normal file
437
frontend/src/views/Shop/Index.vue
Normal file
@ -0,0 +1,437 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getShops,
|
||||
getShop,
|
||||
createShop,
|
||||
updateShop,
|
||||
deleteShop,
|
||||
type ShopItem,
|
||||
type ShopDetail,
|
||||
} from '@/api/shop'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
|
||||
const PLATFORMS = [
|
||||
{ label: '淘宝/天猫', value: 'taobao' },
|
||||
{ label: '拼多多', value: 'pdd' },
|
||||
{ label: '抖音', value: 'douyin' },
|
||||
{ label: '京东', value: 'jd' },
|
||||
{ label: '其他', value: 'other' },
|
||||
]
|
||||
|
||||
const STATUS_LABELS: Record<number, string> = { 1: '启用', 0: '禁用' }
|
||||
|
||||
function platformLabel(value?: string | null) {
|
||||
return PLATFORMS.find((p) => p.value === value)?.label || value || '-'
|
||||
}
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
keyword: '',
|
||||
platform: '',
|
||||
status: '' as string | number,
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (!params.platform) delete params.platform
|
||||
if (params.status === '') delete params.status
|
||||
return getShops(params)
|
||||
},
|
||||
})
|
||||
|
||||
function reset() {
|
||||
query.keyword = ''
|
||||
query.platform = ''
|
||||
query.status = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/* -------------------- 详情 -------------------- */
|
||||
const activeDetailTab = ref('detail')
|
||||
const detailLoading = ref(false)
|
||||
const currentShop = ref<ShopDetail | null>(null)
|
||||
|
||||
/** 拉取店铺详情(点击列表行触发,展示在下方明细标签页) */
|
||||
async function fetchDetail(id: number) {
|
||||
detailLoading.value = true
|
||||
try {
|
||||
currentShop.value = await getShop(id)
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleRowClick(row: ShopItem) {
|
||||
fetchDetail(row.id)
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
code: '',
|
||||
name: '',
|
||||
platform: '',
|
||||
contact_name: '',
|
||||
contact_phone: '',
|
||||
status: 1,
|
||||
remark: '',
|
||||
})
|
||||
// 新增时无需填编码(由后端生成 OMS 前缀编码),故 code 不做必填校验
|
||||
const rules: FormRules = {
|
||||
name: [{ required: true, message: '请输入店铺名称', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editId.value = null
|
||||
form.code = ''
|
||||
form.name = ''
|
||||
form.platform = ''
|
||||
form.contact_name = ''
|
||||
form.contact_phone = ''
|
||||
form.status = 1
|
||||
form.remark = ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: ShopItem) {
|
||||
editId.value = row.id
|
||||
form.code = row.code
|
||||
form.name = row.name
|
||||
form.platform = row.platform || ''
|
||||
form.contact_name = row.contact_name || ''
|
||||
form.contact_phone = row.contact_phone || ''
|
||||
form.status = row.status
|
||||
form.remark = row.remark || ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = { ...form }
|
||||
if (editId.value == null) {
|
||||
const { code } = await createShop(payload)
|
||||
ElMessage.success(`新增成功,店铺编码:${code}`)
|
||||
} else {
|
||||
await updateShop(editId.value, payload)
|
||||
ElMessage.success('保存成功')
|
||||
// 详情面板正展示该店铺时同步刷新
|
||||
if (currentShop.value && currentShop.value.id === editId.value) {
|
||||
await fetchDetail(editId.value)
|
||||
}
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function handleDelete(row: ShopItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除店铺「${row.name}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deleteShop(row.id)
|
||||
ElMessage.success('已删除')
|
||||
if (currentShop.value && currentShop.value.id === row.id) currentShop.value = null
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="shop-card">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>店铺</span>
|
||||
<el-button type="primary" @click="openCreate">新增店铺</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<SplitLayout :first-size="420" storage-key="shop-split" :show-second="!!currentShop">
|
||||
<template #first>
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="店铺名称或编码"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="平台">
|
||||
<el-select v-model="query.platform" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option v-for="p in PLATFORMS" :key="p.value" :label="p.label" :value="p.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="top-table-wrap">
|
||||
<DataTable
|
||||
:loading="loading"
|
||||
:data="list"
|
||||
highlight-current-row
|
||||
class="fill-table"
|
||||
@row-click="handleRowClick"
|
||||
>
|
||||
<el-table-column prop="code" label="店铺编码" width="180" />
|
||||
<el-table-column prop="name" label="店铺名称" min-width="150" />
|
||||
<el-table-column label="平台" width="110">
|
||||
<template #default="{ row }">{{ platformLabel(row.platform) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="contact_name" label="联系人" width="100" />
|
||||
<el-table-column prop="contact_phone" label="联系电话" width="130" />
|
||||
<el-table-column label="状态" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'">
|
||||
{{ STATUS_LABELS[row.status] || row.status }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="130" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click.stop="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click.stop="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #second>
|
||||
<el-tabs v-model="activeDetailTab" type="border-card" class="detail-tabs">
|
||||
<el-tab-pane label="明细" name="detail">
|
||||
<div v-loading="detailLoading" class="detail-body">
|
||||
<template v-if="currentShop">
|
||||
<div class="detail-toolbar">
|
||||
<span class="detail-title">店铺详情 · {{ currentShop.name }}</span>
|
||||
<el-tag :type="currentShop.status === 1 ? 'success' : 'info'">
|
||||
{{ STATUS_LABELS[currentShop.status] || currentShop.status }}
|
||||
</el-tag>
|
||||
<el-button size="small" class="detail-edit" @click="openEdit(currentShop)">
|
||||
编辑
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-descriptions :column="3" border size="small" title="基本信息">
|
||||
<el-descriptions-item label="店铺编码">{{ currentShop.code }}</el-descriptions-item>
|
||||
<el-descriptions-item label="店铺名称">{{ currentShop.name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="所属平台">
|
||||
{{ platformLabel(currentShop.platform) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="联系人">
|
||||
{{ currentShop.contact_name || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="联系电话">
|
||||
{{ currentShop.contact_phone || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="创建时间">
|
||||
{{ currentShop.created_at || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">
|
||||
{{ currentShop.updated_at || '-' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="3">
|
||||
{{ currentShop.remark || '-' }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<el-descriptions :column="3" border size="small" title="关联统计" class="stat-block">
|
||||
<el-descriptions-item label="店铺商品数">
|
||||
{{ currentShop.stats?.shop_product_count ?? 0 }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="已绑定商品">
|
||||
{{ currentShop.stats?.shop_product_bound_count ?? 0 }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="订单数">
|
||||
{{ currentShop.stats?.order_count ?? 0 }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="订单金额合计">
|
||||
{{ currentShop.stats?.order_amount ?? 0 }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="最近订单时间" :span="2">
|
||||
{{ currentShop.stats?.latest_order_at || '暂无订单' }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</template>
|
||||
<el-empty v-else description="请点击上方店铺查看详情" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</template>
|
||||
</SplitLayout>
|
||||
|
||||
<el-dialog v-model="dialogVisible" :title="editId == null ? '新增店铺' : '编辑店铺'" width="560px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px">
|
||||
<el-alert
|
||||
v-if="editId == null"
|
||||
class="code-tip"
|
||||
type="info"
|
||||
show-icon
|
||||
:closable="false"
|
||||
title="店铺编码无需填写,保存后由系统自动生成(前缀 OMS,表示在 OMS 中创建)"
|
||||
/>
|
||||
<el-form-item label="店铺编码" prop="code">
|
||||
<el-input
|
||||
v-model="form.code"
|
||||
:disabled="editId == null"
|
||||
:placeholder="editId == null ? '保存后自动生成(前缀 OMS)' : '同一主体下唯一,留空表示不修改'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="店铺名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入店铺名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="平台" prop="platform">
|
||||
<el-select v-model="form.platform" placeholder="选填" clearable style="width: 100%">
|
||||
<el-option v-for="p in PLATFORMS" :key="p.value" :label="p.label" :value="p.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="联系人" prop="contact_name">
|
||||
<el-input v-model="form.contact_name" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="联系电话" prop="contact_phone">
|
||||
<el-input v-model="form.contact_phone" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.shop-card {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.shop-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.top-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.fill-table {
|
||||
height: 100%;
|
||||
}
|
||||
.code-tip {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.detail-tabs {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.detail-tabs :deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.detail-tabs :deep(.el-tab-pane) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.detail-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
.detail-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.detail-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
.detail-edit {
|
||||
margin-left: auto;
|
||||
}
|
||||
.stat-block {
|
||||
margin-top: 16px;
|
||||
}
|
||||
</style>
|
||||
422
frontend/src/views/ShopProduct/Index.vue
Normal file
422
frontend/src/views/ShopProduct/Index.vue
Normal file
@ -0,0 +1,422 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
getShopProducts,
|
||||
updateShopProduct,
|
||||
bindShopProduct,
|
||||
deleteShopProduct,
|
||||
BIND_TYPES,
|
||||
type ShopProductItem,
|
||||
} from '@/api/shopProduct'
|
||||
import { getShops, type ShopItem } from '@/api/shop'
|
||||
import { getProducts, type ProductItem } from '@/api/product'
|
||||
import { getComboProducts, type ComboProductItem } from '@/api/comboProduct'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
|
||||
const BIND_TAGS: Record<number, string> = { 0: 'info', 1: 'success', 2: 'warning' }
|
||||
const BIND_LABELS: Record<number, string> = { 0: '未绑定', 1: '系统商品', 2: '组合商品' }
|
||||
|
||||
const shops = ref<ShopItem[]>([])
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
shop_id: '' as string | number,
|
||||
bind_type: '' as string | number,
|
||||
status: '' as string | number,
|
||||
keyword: '',
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.keyword) delete params.keyword
|
||||
if (params.shop_id === '') delete params.shop_id
|
||||
if (params.bind_type === '') delete params.bind_type
|
||||
if (params.status === '') delete params.status
|
||||
return getShopProducts(params)
|
||||
},
|
||||
})
|
||||
|
||||
async function fetchShops() {
|
||||
try {
|
||||
const res = await getShops({ page: 1, pageSize: 200 })
|
||||
shops.value = res.list
|
||||
} catch {
|
||||
shops.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function reset() {
|
||||
query.shop_id = ''
|
||||
query.bind_type = ''
|
||||
query.status = ''
|
||||
query.keyword = ''
|
||||
search()
|
||||
}
|
||||
|
||||
/* -------------------- 编辑 -------------------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
shop_id: '' as string | number,
|
||||
outer_item_id: '',
|
||||
outer_sku_id: '',
|
||||
title: '',
|
||||
outer_code: '',
|
||||
spec: '',
|
||||
price: 0,
|
||||
stock: 0,
|
||||
status: 1,
|
||||
})
|
||||
const rules: FormRules = {
|
||||
shop_id: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
outer_item_id: [{ required: true, message: '请输入平台商品ID', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
function openEdit(row: ShopProductItem) {
|
||||
editId.value = row.id
|
||||
form.shop_id = row.shop_id
|
||||
form.outer_item_id = row.outer_item_id
|
||||
form.outer_sku_id = row.outer_sku_id || ''
|
||||
form.title = row.title || ''
|
||||
form.outer_code = row.outer_code || ''
|
||||
form.spec = row.spec || ''
|
||||
form.price = Number(row.price) || 0
|
||||
form.stock = Number(row.stock) || 0
|
||||
form.status = row.status
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value || editId.value == null) return
|
||||
// 提前取出 id:回调内无法沿用外层的 null 收窄
|
||||
const id = editId.value
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload = {
|
||||
shop_id: Number(form.shop_id),
|
||||
outer_item_id: form.outer_item_id,
|
||||
outer_sku_id: form.outer_sku_id,
|
||||
title: form.title,
|
||||
outer_code: form.outer_code,
|
||||
spec: form.spec,
|
||||
price: form.price,
|
||||
stock: form.stock,
|
||||
status: form.status,
|
||||
}
|
||||
await updateShopProduct(id, payload)
|
||||
ElMessage.success('保存成功')
|
||||
dialogVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 绑定商品 -------------------- */
|
||||
const bindVisible = ref(false)
|
||||
const bindSubmitting = ref(false)
|
||||
const bindId = ref<number | null>(null)
|
||||
const bindForm = reactive({
|
||||
bind_type: BIND_TYPES.none as number,
|
||||
product_id: null as number | null,
|
||||
combo_product_id: null as number | null,
|
||||
})
|
||||
const products = ref<ProductItem[]>([])
|
||||
const combos = ref<ComboProductItem[]>([])
|
||||
|
||||
/** 系统商品 / 组合商品下拉(几百条,虚拟滚动) */
|
||||
const productSelectOptions = computed(() =>
|
||||
products.value.map((p) => ({ label: `${p.item_code} ${p.item_name}`, value: p.id })),
|
||||
)
|
||||
const comboSelectOptions = computed(() =>
|
||||
combos.value.map((c) => ({ label: `${c.code} ${c.name}`, value: c.id })),
|
||||
)
|
||||
|
||||
async function loadOptions() {
|
||||
try {
|
||||
const [p, c] = await Promise.all([
|
||||
getProducts({ page: 1, pageSize: 200 }),
|
||||
getComboProducts({ page: 1, pageSize: 200 }),
|
||||
])
|
||||
products.value = p.list
|
||||
combos.value = c.list
|
||||
} catch {
|
||||
products.value = []
|
||||
combos.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function openBind(row: ShopProductItem) {
|
||||
bindId.value = row.id
|
||||
bindForm.bind_type = row.bind_type
|
||||
bindForm.product_id = row.product_id
|
||||
bindForm.combo_product_id = row.combo_product_id
|
||||
bindVisible.value = true
|
||||
loadOptions()
|
||||
}
|
||||
|
||||
async function submitBind() {
|
||||
if (bindId.value == null) return
|
||||
if (bindForm.bind_type === BIND_TYPES.product && !bindForm.product_id) {
|
||||
ElMessage.warning('请选择要绑定的系统商品')
|
||||
return
|
||||
}
|
||||
if (bindForm.bind_type === BIND_TYPES.combo && !bindForm.combo_product_id) {
|
||||
ElMessage.warning('请选择要绑定的组合商品')
|
||||
return
|
||||
}
|
||||
bindSubmitting.value = true
|
||||
try {
|
||||
const payload = {
|
||||
bind_type: bindForm.bind_type,
|
||||
product_id: bindForm.bind_type === BIND_TYPES.product ? bindForm.product_id : null,
|
||||
combo_product_id: bindForm.bind_type === BIND_TYPES.combo ? bindForm.combo_product_id : null,
|
||||
}
|
||||
await bindShopProduct(bindId.value, payload)
|
||||
ElMessage.success(bindForm.bind_type === BIND_TYPES.none ? '已解绑' : '绑定成功')
|
||||
bindVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
bindSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row: ShopProductItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除店铺商品「${row.title || row.outer_item_id}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await deleteShopProduct(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/** 已绑定的商品名称 */
|
||||
function boundName(row: ShopProductItem) {
|
||||
if (row.bind_type === BIND_TYPES.product) return row.product?.item_name || `商品#${row.product_id}`
|
||||
if (row.bind_type === BIND_TYPES.combo) return row.comboProduct?.name || `组合#${row.combo_product_id}`
|
||||
return '-'
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchShops()
|
||||
await fetchList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>店铺商品</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="店铺">
|
||||
<VirtualSelect
|
||||
v-model="query.shop_id"
|
||||
:options="shops"
|
||||
label-key="name"
|
||||
value-key="id"
|
||||
placeholder="全部"
|
||||
clearable
|
||||
style="width: 160px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键词">
|
||||
<el-input
|
||||
v-model="query.keyword"
|
||||
placeholder="标题 / 商家编码 / 平台商品ID"
|
||||
clearable
|
||||
@keyup.enter="search"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="绑定状态">
|
||||
<el-select v-model="query.bind_type" placeholder="全部" clearable style="width: 130px">
|
||||
<el-option label="未绑定" :value="0" />
|
||||
<el-option label="系统商品" :value="1" />
|
||||
<el-option label="组合商品" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 120px">
|
||||
<el-option label="在售" :value="1" />
|
||||
<el-option label="下架" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<DataTable :loading="loading" :data="list">
|
||||
<el-table-column label="店铺" width="140">
|
||||
<template #default="{ row }">{{ row.shop?.name || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="outer_item_id" label="平台商品ID" width="140" />
|
||||
<el-table-column prop="outer_sku_id" label="规格ID" width="120">
|
||||
<template #default="{ row }">{{ row.outer_sku_id || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="title" label="商品标题" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column prop="outer_code" label="商家编码" width="120">
|
||||
<template #default="{ row }">{{ row.outer_code || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="售价" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.price ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="stock" label="库存" width="90" align="right" />
|
||||
<el-table-column label="绑定" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="BIND_TAGS[row.bind_type]" size="small">
|
||||
{{ BIND_LABELS[row.bind_type] }}
|
||||
</el-tag>
|
||||
<span v-if="row.bind_type !== 0" class="bound-name">{{ boundName(row) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
|
||||
{{ row.status === 1 ? '在售' : '下架' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="warning" @click="openBind(row)">绑定</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
|
||||
<el-dialog v-model="dialogVisible" title="编辑店铺商品" width="560px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px">
|
||||
<el-form-item label="店铺" prop="shop_id">
|
||||
<VirtualSelect
|
||||
v-model="form.shop_id"
|
||||
:options="shops"
|
||||
label-key="name"
|
||||
value-key="id"
|
||||
placeholder="请选择店铺"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="平台商品ID" prop="outer_item_id">
|
||||
<el-input v-model="form.outer_item_id" placeholder="平台侧商品ID" />
|
||||
</el-form-item>
|
||||
<el-form-item label="规格ID" prop="outer_sku_id">
|
||||
<el-input v-model="form.outer_sku_id" placeholder="无规格时留空" />
|
||||
</el-form-item>
|
||||
<el-form-item label="商品标题" prop="title">
|
||||
<el-input v-model="form.title" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="商家编码" prop="outer_code">
|
||||
<el-input v-model="form.outer_code" placeholder="用于与系统商品匹配" />
|
||||
</el-form-item>
|
||||
<el-form-item label="规格" prop="spec">
|
||||
<el-input v-model="form.spec" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="售价" prop="price">
|
||||
<el-input-number v-model="form.price" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="库存" prop="stock">
|
||||
<el-input-number v-model="form.stock" :min="0" :precision="0" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option label="在售" :value="1" />
|
||||
<el-option label="下架" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog v-model="bindVisible" title="绑定商品" width="520px">
|
||||
<el-form :model="bindForm" label-width="110px">
|
||||
<el-form-item label="绑定类型">
|
||||
<el-select v-model="bindForm.bind_type" style="width: 100%">
|
||||
<el-option label="未绑定(解绑)" :value="0" />
|
||||
<el-option label="系统商品" :value="1" />
|
||||
<el-option label="组合商品" :value="2" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="bindForm.bind_type === 1" label="系统商品">
|
||||
<VirtualSelect
|
||||
v-model="bindForm.product_id"
|
||||
:options="productSelectOptions"
|
||||
filterable
|
||||
placeholder="请选择系统商品"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="bindForm.bind_type === 2" label="组合商品">
|
||||
<VirtualSelect
|
||||
v-model="bindForm.combo_product_id"
|
||||
:options="comboSelectOptions"
|
||||
filterable
|
||||
placeholder="请选择组合商品"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="bindVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="bindSubmitting" @click="submitBind">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.bound-name {
|
||||
margin-left: 8px;
|
||||
}
|
||||
</style>
|
||||
699
frontend/src/views/StockOrder/Index.vue
Normal file
699
frontend/src/views/StockOrder/Index.vue
Normal file
@ -0,0 +1,699 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
createStockOrderApi,
|
||||
type StockBillType,
|
||||
type StockItemLine,
|
||||
type StockOrder,
|
||||
type StockOrderPayload,
|
||||
type StockItemPayload,
|
||||
} from '@/api/stockOrder'
|
||||
import { getWarehouseOptions, type WarehouseOption } from '@/api/warehouse'
|
||||
import { searchProducts, type ProductSearchItem } from '@/api/product'
|
||||
import SplitLayout from '@/components/SplitLayout.vue'
|
||||
import DataTable from '@/components/DataTable.vue'
|
||||
import ListPager from '@/components/ListPager.vue'
|
||||
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
|
||||
import VirtualTable from '@/components/VirtualTable.vue'
|
||||
import VirtualSelect from '@/components/VirtualSelect.vue'
|
||||
import type { VirtualColumn } from '@/components/virtualTable'
|
||||
|
||||
const props = defineProps<{
|
||||
billType: number
|
||||
billTypeName: string
|
||||
partyField: 'supplier' | 'customer'
|
||||
partyLabel: string
|
||||
}>()
|
||||
|
||||
const api = createStockOrderApi(props.billType as StockBillType)
|
||||
|
||||
const STATUS_LABELS = computed<Record<number, string>>(() => {
|
||||
const done = props.billType === 1 ? '完成入库' : '完成出库'
|
||||
return { 1: '已创建', 2: '已审核', 3: '已推送', 4: done, 9: '已取消' }
|
||||
})
|
||||
const STATUS_TAGS: Record<number, string> = { 1: 'info', 2: 'warning', 3: 'primary', 4: 'success', 9: 'danger' }
|
||||
|
||||
const TYPE_OPTIONS = computed(() =>
|
||||
props.billType === 1
|
||||
? [
|
||||
{ label: '采购入库', value: 1 },
|
||||
{ label: '退货入库', value: 2 },
|
||||
{ label: '其他', value: 9 },
|
||||
]
|
||||
: [
|
||||
{ label: '销售出库', value: 1 },
|
||||
{ label: '退货出库', value: 2 },
|
||||
{ label: '其他', value: 9 },
|
||||
],
|
||||
)
|
||||
|
||||
const warehouses = ref<WarehouseOption[]>([])
|
||||
|
||||
/** 仓库下拉(全量仓库,虚拟滚动) */
|
||||
const warehouseSelectOptions = computed(() =>
|
||||
warehouses.value.map((w) => ({ label: `${w.code} ${w.name}`, value: w.id })),
|
||||
)
|
||||
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
pageSize: DEFAULT_PAGE_SIZE,
|
||||
bill_no: '',
|
||||
status: '' as string | number,
|
||||
type: '' as string | number,
|
||||
warehouse_id: '' as string | number,
|
||||
})
|
||||
|
||||
const { loading, list, total, elapsed, fetchList, search, handlePageChange, handleSizeChange } = useListPage({
|
||||
query,
|
||||
fetcher: () => {
|
||||
const params: Record<string, unknown> = { ...query }
|
||||
if (!params.bill_no) delete params.bill_no
|
||||
if (params.status === '') delete params.status
|
||||
if (params.type === '') delete params.type
|
||||
if (params.warehouse_id === '') delete params.warehouse_id
|
||||
return api.getList(params)
|
||||
},
|
||||
})
|
||||
|
||||
async function fetchWarehouses() {
|
||||
try {
|
||||
const res = await getWarehouseOptions()
|
||||
warehouses.value = res
|
||||
} catch {
|
||||
warehouses.value = []
|
||||
}
|
||||
}
|
||||
|
||||
function reset() {
|
||||
query.bill_no = ''
|
||||
query.status = ''
|
||||
query.type = ''
|
||||
query.warehouse_id = ''
|
||||
search()
|
||||
}
|
||||
|
||||
function typeLabel(row: StockOrder): string {
|
||||
const t = (props.billType === 1 ? row.inbound_type : row.outbound_type) as number
|
||||
return TYPE_OPTIONS.value.find((o) => o.value === t)?.label || String(t)
|
||||
}
|
||||
|
||||
function partyValue(row: StockOrder): string {
|
||||
return (row[props.partyField] as string) || '-'
|
||||
}
|
||||
|
||||
/* -------------------- 新增 / 编辑 -------------------- */
|
||||
const dialogVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const editId = ref<number | null>(null)
|
||||
const form = reactive({
|
||||
warehouse_id: null as number | null,
|
||||
type: 1,
|
||||
status: 1,
|
||||
party: '',
|
||||
operator: '',
|
||||
total_amount: 0,
|
||||
remark: '',
|
||||
})
|
||||
const rules: FormRules = {
|
||||
warehouse_id: [{ required: true, message: '请选择仓库', trigger: 'change' }],
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editId.value = null
|
||||
Object.assign(form, {
|
||||
warehouse_id: null,
|
||||
type: 1,
|
||||
status: 1,
|
||||
party: '',
|
||||
operator: '',
|
||||
total_amount: 0,
|
||||
remark: '',
|
||||
})
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: StockOrder) {
|
||||
editId.value = row.id
|
||||
form.warehouse_id = row.warehouse_id ?? null
|
||||
form.type = (props.billType === 1 ? row.inbound_type : row.outbound_type) || 1
|
||||
form.status = row.status
|
||||
form.party = (row[props.partyField] as string) || ''
|
||||
form.operator = row.operator || ''
|
||||
form.total_amount = Number(row.total_amount) || 0
|
||||
form.remark = row.remark || ''
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitForm() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const payload: StockOrderPayload = {
|
||||
warehouse_id: form.warehouse_id,
|
||||
status: form.status,
|
||||
operator: form.operator || null,
|
||||
total_amount: form.total_amount,
|
||||
remark: form.remark || undefined,
|
||||
}
|
||||
if (props.billType === 1) payload.inbound_type = form.type
|
||||
else payload.outbound_type = form.type
|
||||
payload[props.partyField] = form.party || null
|
||||
if (editId.value == null) {
|
||||
await api.create(payload)
|
||||
ElMessage.success('新增成功')
|
||||
} else {
|
||||
await api.update(editId.value, payload)
|
||||
ElMessage.success('保存成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/* -------------------- 状态流转(审核 / 推送 / 完成 / 取消 / 恢复) -------------------- */
|
||||
const transiting = ref(false)
|
||||
async function transit(action: 'audit' | 'push' | 'complete' | 'cancel' | 'restore') {
|
||||
if (!currentOrder.value) return
|
||||
transiting.value = true
|
||||
try {
|
||||
const id = currentOrder.value.id
|
||||
if (action === 'audit') await api.audit(id)
|
||||
else if (action === 'push') await api.push(id)
|
||||
else if (action === 'complete') await api.complete(id)
|
||||
else if (action === 'cancel') await api.cancel(id)
|
||||
else if (action === 'restore') await api.restore(id)
|
||||
ElMessage.success('操作成功')
|
||||
const map: Record<string, number> = { audit: 2, push: 3, complete: 4, cancel: 9, restore: 1 }
|
||||
currentOrder.value.status = map[action]
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
transiting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row: StockOrder) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除${props.billTypeName}「${row.bill_no}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await api.remove(row.id)
|
||||
ElMessage.success('已删除')
|
||||
if (currentOrder.value && currentOrder.value.id === row.id) {
|
||||
currentOrder.value = null
|
||||
items.value = []
|
||||
}
|
||||
await fetchList()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------- 明细 -------------------- */
|
||||
const itemsLoading = ref(false)
|
||||
const currentOrder = ref<StockOrder | null>(null)
|
||||
const activeDetailTab = ref('detail')
|
||||
const items = ref<StockItemLine[]>([])
|
||||
const productOptions = ref<ProductSearchItem[]>([])
|
||||
|
||||
/** 明细列(虚拟滚动,明细行可能有几百条) */
|
||||
const itemColumns: VirtualColumn[] = [
|
||||
{ key: 'name', title: '商品名称', minWidth: 140, slot: 'name' },
|
||||
{ key: 'code', title: '商品编码', width: 120, slot: 'code' },
|
||||
{ key: 'spec', title: '规格', width: 120, slot: 'spec' },
|
||||
{ key: 'unit', title: '单位', width: 80, slot: 'unit' },
|
||||
{ key: 'quantity', title: '数量', width: 90, align: 'right' },
|
||||
{ key: 'price', title: '单价', width: 100, align: 'right', slot: 'price' },
|
||||
{ key: 'total_amount', title: '金额', width: 110, align: 'right' },
|
||||
{ key: 'actions', title: '操作', width: 140, slot: 'actions', fixed: true },
|
||||
]
|
||||
const productSearching = ref(false)
|
||||
|
||||
/** 商品快速搜索(聚合:商品编码/货品编码/条码/商品名称),仅返回启用商品 */
|
||||
async function remoteSearchProduct(keyword: string) {
|
||||
productSearching.value = true
|
||||
try {
|
||||
productOptions.value = await searchProducts(keyword || '')
|
||||
} catch {
|
||||
productOptions.value = []
|
||||
} finally {
|
||||
productSearching.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchItems() {
|
||||
if (!currentOrder.value) return
|
||||
itemsLoading.value = true
|
||||
try {
|
||||
const res = await api.getItems(currentOrder.value.id, { pageSize: 200 })
|
||||
items.value = res.list
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
itemsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleRowClick(row: StockOrder) {
|
||||
currentOrder.value = row
|
||||
fetchItems()
|
||||
}
|
||||
|
||||
const itemDialogVisible = ref(false)
|
||||
const itemSubmitting = ref(false)
|
||||
const itemEditId = ref<number | null>(null)
|
||||
const itemForm = reactive({
|
||||
product_id: null as number | null,
|
||||
name: '',
|
||||
code: '',
|
||||
spec: '',
|
||||
unit: '',
|
||||
quantity: 1,
|
||||
price: 0,
|
||||
remark: '',
|
||||
})
|
||||
|
||||
function onProductChange(pid: number | null) {
|
||||
const p = productOptions.value.find((x) => x.id === pid)
|
||||
if (p) {
|
||||
itemForm.name = p.item_name || ''
|
||||
itemForm.code = p.item_code || ''
|
||||
itemForm.spec = p.sku_property || ''
|
||||
itemForm.unit = p.stock_unit || ''
|
||||
}
|
||||
}
|
||||
|
||||
function openItemCreate() {
|
||||
itemEditId.value = null
|
||||
Object.assign(itemForm, {
|
||||
product_id: null,
|
||||
name: '',
|
||||
code: '',
|
||||
spec: '',
|
||||
unit: '',
|
||||
quantity: 1,
|
||||
price: 0,
|
||||
remark: '',
|
||||
})
|
||||
itemDialogVisible.value = true
|
||||
}
|
||||
|
||||
function openItemEdit(row: StockItemLine) {
|
||||
itemEditId.value = row.id
|
||||
// 编辑时回显已关联商品,便于下拉展示(搜索接口仅返回启用商品)
|
||||
productOptions.value = row.product
|
||||
? [{ id: row.product.id, item_code: row.product.item_code, item_name: row.product.item_name, sku_property: row.product.sku_property, goods_code: null, barcode: null, stock_unit: row.unit || null, status: 1 }]
|
||||
: []
|
||||
Object.assign(itemForm, {
|
||||
product_id: row.product_id,
|
||||
name: row.name || '',
|
||||
code: row.code || '',
|
||||
spec: row.spec || '',
|
||||
unit: row.unit || '',
|
||||
quantity: Number(row.quantity) || 0,
|
||||
price: Number(row.price) || 0,
|
||||
remark: row.remark || '',
|
||||
})
|
||||
itemDialogVisible.value = true
|
||||
}
|
||||
|
||||
async function submitItem() {
|
||||
if (!currentOrder.value) return
|
||||
itemSubmitting.value = true
|
||||
try {
|
||||
const payload: StockItemPayload = {
|
||||
bill_id: currentOrder.value.id,
|
||||
product_id: itemForm.product_id,
|
||||
name: itemForm.name || null,
|
||||
code: itemForm.code || null,
|
||||
spec: itemForm.spec || null,
|
||||
unit: itemForm.unit || null,
|
||||
quantity: itemForm.quantity,
|
||||
price: itemForm.price,
|
||||
remark: itemForm.remark || null,
|
||||
}
|
||||
if (itemEditId.value == null) {
|
||||
await api.createItem(payload)
|
||||
ElMessage.success('已新增明细')
|
||||
} else {
|
||||
await api.updateItem(itemEditId.value, payload)
|
||||
ElMessage.success('已保存明细')
|
||||
}
|
||||
itemDialogVisible.value = false
|
||||
await fetchItems()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
itemSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteItem(row: StockItemLine) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确认删除明细「${row.name || row.code || row.id}」?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await api.removeItem(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await fetchItems()
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchWarehouses()
|
||||
await fetchList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card class="stock-card">
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>{{ billTypeName }}</span>
|
||||
<el-button type="primary" @click="openCreate">新增{{ billTypeName }}</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<SplitLayout :first-size="360" storage-key="stock-order-split" :show-second="!!currentOrder">
|
||||
<template #first>
|
||||
<el-form :inline="true" class="search-bar">
|
||||
<el-form-item label="单号">
|
||||
<el-input v-model="query.bill_no" placeholder="支持模糊匹配" clearable @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="query.status" placeholder="全部" clearable style="width: 130px">
|
||||
<el-option v-for="(label, val) in STATUS_LABELS" :key="val" :label="label" :value="Number(val)" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="billTypeName + '类型'">
|
||||
<el-select v-model="query.type" placeholder="全部" clearable style="width: 140px">
|
||||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="店铺/仓库">
|
||||
<VirtualSelect
|
||||
v-model="query.warehouse_id"
|
||||
:options="warehouseSelectOptions"
|
||||
placeholder="全部仓库"
|
||||
clearable
|
||||
style="width: 160px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="search">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="top-table-wrap">
|
||||
<DataTable
|
||||
:loading="loading"
|
||||
:data="list"
|
||||
highlight-current-row
|
||||
class="fill-table"
|
||||
@row-click="handleRowClick"
|
||||
>
|
||||
<el-table-column prop="bill_no" label="单号" min-width="160" />
|
||||
<el-table-column label="仓库" width="150">
|
||||
<template #default="{ row }">{{ row.warehouse?.name || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="120">
|
||||
<template #default="{ row }">{{ typeLabel(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="STATUS_TAGS[row.status]">{{ STATUS_LABELS[row.status] || row.status }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :label="partyLabel" width="140">
|
||||
<template #default="{ row }">{{ partyValue(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作人" width="100">
|
||||
<template #default="{ row }">{{ row.operator || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建人" width="100">
|
||||
<template #default="{ row }">{{ row.creator?.nickname || row.creator?.username || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="金额" width="120" align="right">
|
||||
<template #default="{ row }">{{ row.total_amount }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品总数" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.item_total ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品种类" width="100" align="right">
|
||||
<template #default="{ row }">{{ row.item_kind ?? 0 }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="200" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</DataTable>
|
||||
</div>
|
||||
|
||||
<ListPager
|
||||
:total="total"
|
||||
:elapsed="elapsed"
|
||||
:page="query.page"
|
||||
:page-size="query.pageSize"
|
||||
@page-change="handlePageChange"
|
||||
@size-change="handleSizeChange"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #second>
|
||||
<el-tabs v-model="activeDetailTab" type="border-card" class="detail-tabs">
|
||||
<el-tab-pane label="明细" name="detail">
|
||||
<div class="items-toolbar">
|
||||
<span class="items-title">
|
||||
{{ billTypeName }}明细<template v-if="currentOrder"> · {{ currentOrder.bill_no }}</template>
|
||||
</span>
|
||||
<div class="status-actions" v-if="currentOrder">
|
||||
<el-tag :type="STATUS_TAGS[currentOrder.status]">{{ STATUS_LABELS[currentOrder.status] || currentOrder.status }}</el-tag>
|
||||
<el-button size="small" :disabled="transiting" v-if="currentOrder.status === 1" @click="transit('audit')">审核</el-button>
|
||||
<el-button size="small" :disabled="transiting" v-if="currentOrder.status === 2" @click="transit('push')">推送</el-button>
|
||||
<el-button size="small" :disabled="transiting" v-if="currentOrder.status === 3" @click="transit('complete')">完成</el-button>
|
||||
<el-button size="small" :disabled="transiting" v-if="currentOrder.status === 9" @click="transit('restore')">恢复</el-button>
|
||||
<el-button size="small" type="danger" plain :disabled="transiting" v-if="currentOrder.status !== 4 && currentOrder.status !== 9" @click="transit('cancel')">取消</el-button>
|
||||
</div>
|
||||
<el-button type="primary" :disabled="!currentOrder" @click="openItemCreate">新增明细</el-button>
|
||||
</div>
|
||||
<div class="bottom-table-wrap">
|
||||
<template v-if="currentOrder">
|
||||
<VirtualTable
|
||||
:loading="itemsLoading"
|
||||
:data="items"
|
||||
:columns="itemColumns"
|
||||
class="fill-table"
|
||||
>
|
||||
<template #name="{ row }">{{ row.name || (row.product ? row.product.item_name : '-') }}</template>
|
||||
<template #code="{ row }">{{ row.code || (row.product ? row.product.item_code : '-') }}</template>
|
||||
<template #spec="{ row }">{{ row.spec || '-' }}</template>
|
||||
<template #unit="{ row }">{{ row.unit || '-' }}</template>
|
||||
<template #price="{ row }">{{ row.price ?? '-' }}</template>
|
||||
<template #actions="{ row }">
|
||||
<el-button link type="primary" @click="openItemEdit(row)">编辑</el-button>
|
||||
<el-button link type="danger" @click="handleDeleteItem(row)">删除</el-button>
|
||||
</template>
|
||||
</VirtualTable>
|
||||
</template>
|
||||
<el-empty v-else description="请点击上方单据查看明细" />
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</template>
|
||||
</SplitLayout>
|
||||
|
||||
<el-dialog v-model="dialogVisible" :title="editId == null ? '新增' + billTypeName : '编辑' + billTypeName" width="580px">
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="仓库" prop="warehouse_id">
|
||||
<VirtualSelect
|
||||
v-model="form.warehouse_id"
|
||||
:options="warehouseSelectOptions"
|
||||
placeholder="请选择仓库"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="billTypeName + '类型'" prop="type">
|
||||
<el-select v-model="form.type" style="width: 100%">
|
||||
<el-option v-for="o in TYPE_OPTIONS" :key="o.value" :label="o.label" :value="o.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="editId != null" label="状态" prop="status">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option v-for="(label, val) in STATUS_LABELS" :key="val" :label="label" :value="Number(val)" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item :label="partyLabel" prop="party">
|
||||
<el-input v-model="form.party" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="操作人" prop="operator">
|
||||
<el-input v-model="form.operator" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单据金额" prop="total_amount">
|
||||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="submitForm">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
v-model="itemDialogVisible"
|
||||
:title="itemEditId == null ? '新增明细' : '编辑明细'"
|
||||
width="520px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form :model="itemForm" label-width="100px">
|
||||
<el-form-item label="系统商品">
|
||||
<el-select
|
||||
v-model="itemForm.product_id"
|
||||
filterable
|
||||
remote
|
||||
clearable
|
||||
:remote-method="remoteSearchProduct"
|
||||
:loading="productSearching"
|
||||
placeholder="输入编码/货物编码/条码/名称搜索(仅启用商品)"
|
||||
style="width: 100%"
|
||||
@change="onProductChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="p in productOptions"
|
||||
:key="p.id"
|
||||
:label="`${p.item_code} ${p.item_name}`"
|
||||
:value="p.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品名称">
|
||||
<el-input v-model="itemForm.name" placeholder="商品名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="商品编码">
|
||||
<el-input v-model="itemForm.code" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="规格">
|
||||
<el-input v-model="itemForm.spec" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单位">
|
||||
<el-input v-model="itemForm.unit" placeholder="选填,如 件/箱" />
|
||||
</el-form-item>
|
||||
<el-form-item label="数量">
|
||||
<el-input-number v-model="itemForm.quantity" :min="0" :precision="0" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="单价">
|
||||
<el-input-number v-model="itemForm.price" :min="0" :precision="2" style="width: 100%" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="itemForm.remark" type="textarea" :rows="2" placeholder="选填" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="itemDialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="itemSubmitting" @click="submitItem">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.stock-card {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.stock-card :deep(.el-card__body) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 12px 16px;
|
||||
}
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.search-bar {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.top-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.items-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.status-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.items-title {
|
||||
font-weight: 600;
|
||||
}
|
||||
.bottom-table-wrap {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.detail-tabs {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.detail-tabs :deep(.el-tabs__content) {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.detail-tabs :deep(.el-tab-pane) {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.fill-table {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
178
frontend/src/views/User/Profile.vue
Normal file
178
frontend/src/views/User/Profile.vue
Normal file
@ -0,0 +1,178 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import { useAuthStore } from '@/store/auth'
|
||||
import { updateProfile, changePassword } from '@/api/user'
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
const submitting = ref(false)
|
||||
const form = reactive({ nickname: '', email: '', phone: '', avatar: '' })
|
||||
const rules: FormRules = {
|
||||
email: [{ type: 'email', message: '邮箱格式不正确', trigger: 'blur' }],
|
||||
phone: [{ pattern: /^1[3-9]\d{9}$|^[\d-+()\s]{6,20}$/, message: '手机号格式不正确', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
/** 用当前登录用户信息回填表单 */
|
||||
function fillForm() {
|
||||
const u = auth.user
|
||||
if (!u) return
|
||||
form.nickname = u.nickname || ''
|
||||
form.email = u.email || ''
|
||||
form.phone = u.phone || ''
|
||||
form.avatar = u.avatar || ''
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!auth.user) await auth.fetchProfile()
|
||||
fillForm()
|
||||
})
|
||||
|
||||
async function submitProfile() {
|
||||
if (!formRef.value) return
|
||||
await formRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
submitting.value = true
|
||||
try {
|
||||
await updateProfile({ ...form })
|
||||
ElMessage.success('资料已更新')
|
||||
// 同步刷新账号信息,顶栏昵称等即时生效
|
||||
await auth.fetchProfile()
|
||||
fillForm()
|
||||
} catch {
|
||||
// 错误已由响应拦截器统一提示
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 修改密码
|
||||
const pwdVisible = ref(false)
|
||||
const pwdSubmitting = ref(false)
|
||||
const pwdFormRef = ref<FormInstance>()
|
||||
const pwdForm = reactive({ old_password: '', password: '', confirm: '' })
|
||||
const pwdRules: FormRules = {
|
||||
old_password: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
|
||||
password: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ min: 6, message: '新密码长度不少于 6 位', trigger: 'blur' },
|
||||
],
|
||||
confirm: [
|
||||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||||
{
|
||||
validator: (_rule: unknown, value: string, callback: (e?: string | Error) => void) => {
|
||||
if (value !== pwdForm.password) callback(new Error('两次输入的密码不一致'))
|
||||
else callback()
|
||||
},
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
function openPwd() {
|
||||
pwdForm.old_password = ''
|
||||
pwdForm.password = ''
|
||||
pwdForm.confirm = ''
|
||||
pwdVisible.value = true
|
||||
}
|
||||
|
||||
async function submitPwd() {
|
||||
if (!pwdFormRef.value) return
|
||||
await pwdFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
pwdSubmitting.value = true
|
||||
try {
|
||||
await changePassword({ old_password: pwdForm.old_password, password: pwdForm.password })
|
||||
ElMessage.success('密码已修改,请牢记新密码')
|
||||
pwdVisible.value = false
|
||||
} catch {
|
||||
// 拦截器已提示
|
||||
} finally {
|
||||
pwdSubmitting.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<div class="page-header">
|
||||
<span>我的</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-descriptions :column="2" border class="info-block">
|
||||
<el-descriptions-item label="登录账号">{{ auth.user?.username || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="用户ID">{{ auth.user?.id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="auth.user?.status === 1 ? 'success' : 'info'">
|
||||
{{ auth.user?.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="最后登录">{{ auth.user?.last_login_at || '暂无' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<el-divider content-position="left">修改资料</el-divider>
|
||||
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px" class="profile-form">
|
||||
<el-form-item label="昵称" prop="nickname">
|
||||
<el-input v-model="form.nickname" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="form.email" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="form.phone" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="头像URL" prop="avatar">
|
||||
<el-input v-model="form.avatar" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="submitting" @click="submitProfile">保存资料</el-button>
|
||||
<el-button @click="openPwd">修改密码</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-dialog v-model="pwdVisible" title="修改密码" width="480px">
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
title="需验证原密码;修改成功后原密码立即失效,下次登录请使用新密码"
|
||||
style="margin-bottom: 16px"
|
||||
/>
|
||||
<el-form ref="pwdFormRef" :model="pwdForm" :rules="pwdRules" label-width="96px">
|
||||
<el-form-item label="原密码" prop="old_password">
|
||||
<el-input v-model="pwdForm.old_password" type="password" show-password placeholder="请输入当前密码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="password">
|
||||
<el-input v-model="pwdForm.password" type="password" show-password placeholder="不少于 6 位" />
|
||||
</el-form-item>
|
||||
<el-form-item label="确认密码" prop="confirm">
|
||||
<el-input v-model="pwdForm.confirm" type="password" show-password placeholder="再次输入新密码" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="pwdVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="pwdSubmitting" @click="submitPwd">确定</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-weight: 600;
|
||||
}
|
||||
.info-block {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.profile-form {
|
||||
max-width: 560px;
|
||||
}
|
||||
</style>
|
||||
25
frontend/tsconfig.json
Normal file
25
frontend/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src", "vite.config.ts", "env.d.ts"]
|
||||
}
|
||||
24
frontend/vite.config.ts
Normal file
24
frontend/vite.config.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
host: true,
|
||||
port: 5173,
|
||||
open: false,
|
||||
proxy: {
|
||||
// 开发环境将 /api 代理到 Egg.js 后端(默认端口 6090)
|
||||
'/api': {
|
||||
target: 'http://localhost:6090',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user