1
This commit is contained in:
parent
637a1092cc
commit
4822637729
183
docs/camera-local-stream-api.md
Normal file
183
docs/camera-local-stream-api.md
Normal file
@ -0,0 +1,183 @@
|
||||
# 摄像头本地流服务接口文档
|
||||
|
||||
> 服务地址:`http://localhost:17311`(主端口,备用端口依次为 `17312`、`17313`)
|
||||
> 服务职责:代理前端与海康威视录像机(NVR)之间的连接,拉取实时视频流并转为 MJPEG 输出。
|
||||
> 本服务独立于主后端 `/system`,由前端 `src/api/camera_server/localServerApi.ts` 直接调用。
|
||||
|
||||
## 目录
|
||||
|
||||
- [1. 获取海康通道列表](#1-获取海康通道列表)
|
||||
- [2. 获取实时流(MJPEG)](#2-获取实时流mjpeg)
|
||||
- [3. 停止实时流](#3-停止实时流)
|
||||
|
||||
---
|
||||
|
||||
## 1. 获取海康通道列表
|
||||
|
||||
用于测试录像服务器连通性,并获取其通道列表。
|
||||
|
||||
- **URL**:`POST /api/hikvision/channels`
|
||||
- **Content-Type**:`application/json`
|
||||
|
||||
### 请求参数
|
||||
|
||||
| 字段 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| ip | string | 是 | 录像机 IP 地址 |
|
||||
| port | number | 否 | 录像机端口,默认 `8000` |
|
||||
| user | string | 是 | 录像机登录账号 |
|
||||
| pass | string | 是 | 录像机登录密码 |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "192.168.8.241",
|
||||
"port": 8000,
|
||||
"user": "admin",
|
||||
"pass": "ky666888"
|
||||
}
|
||||
```
|
||||
|
||||
### 响应示例
|
||||
|
||||
```json
|
||||
{
|
||||
"success": true,
|
||||
"channels": [
|
||||
{ "channel": 1, "name": "通道1" },
|
||||
{ "channel": 2, "name": "通道2" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
或兼容格式:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": [
|
||||
{ "channel": 1, "name": "通道1" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 获取实时流(MJPEG)
|
||||
|
||||
拉取指定通道的实时视频流,以 `multipart/x-mixed-replace` 的 MJPEG 流返回,前端用 `<img src="...">` 直接渲染。
|
||||
|
||||
- **URL**:`GET /api/hikvision/live-stream`
|
||||
- **返回**:`multipart/x-mixed-replace` 的 MJPEG 流(长连接)
|
||||
|
||||
### Query 参数
|
||||
|
||||
| 字段 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| ip | string | 是 | 录像机 IP 地址 |
|
||||
| user | string | 是 | 录像机登录账号 |
|
||||
| pass | string | 是 | 录像机登录密码 |
|
||||
| channel | number | 是 | 通道号 |
|
||||
| streamType | number | 否 | 码流类型,`0` 主码流(默认),`1` 子码流 |
|
||||
| port | number | 否 | 录像机端口,默认 `8000` |
|
||||
|
||||
### 请求示例
|
||||
|
||||
```
|
||||
GET /api/hikvision/live-stream?ip=192.168.8.241&user=admin&pass=ky666888&channel=9&streamType=0&port=8000
|
||||
```
|
||||
|
||||
### 后端实现要求
|
||||
|
||||
- 每个「录像机 + 通道」应维护**独立的 ffmpeg 子进程**,并按 `ip + channel`(或生成的 session id)登记。
|
||||
- 客户端断开(`req.on('close')` / `res.on('close')`)时,应立即 `kill` 对应 ffmpeg 子进程,作为兜底回收机制。
|
||||
- 同一 `ip + channel` 若已有活跃进程,建议复用或先停旧再启新,避免重复拉起。
|
||||
|
||||
---
|
||||
|
||||
## 3. 停止实时流
|
||||
|
||||
显式停止指定通道的实时流,后端据此 kill 对应 ffmpeg 子进程。前端在关闭预览浮窗、切换摄像头、组件卸载时调用。
|
||||
|
||||
- **URL**:`POST /api/hikvision/stop-stream`
|
||||
- **Content-Type**:`application/json`
|
||||
|
||||
### 请求参数
|
||||
|
||||
| 字段 | 类型 | 必填 | 说明 |
|
||||
|------|------|------|------|
|
||||
| ip | string | 是 | 录像机 IP 地址 |
|
||||
| user | string | 是 | 录像机登录账号 |
|
||||
| pass | string | 是 | 录像机登录密码 |
|
||||
| channel | number | 是 | 通道号 |
|
||||
| port | number | 否 | 录像机端口,默认 `8000` |
|
||||
|
||||
> `ip + channel` 作为流实例的定位键,与「获取实时流」一致。
|
||||
|
||||
### 请求示例
|
||||
|
||||
```json
|
||||
{
|
||||
"ip": "192.168.8.241",
|
||||
"user": "admin",
|
||||
"pass": "ky666888",
|
||||
"channel": 9,
|
||||
"port": 8000
|
||||
}
|
||||
```
|
||||
|
||||
### 响应示例
|
||||
|
||||
成功:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": {
|
||||
"stopped": true,
|
||||
"channel": 9
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
无对应流(幂等,不报错):
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "no active stream",
|
||||
"data": {
|
||||
"stopped": false,
|
||||
"channel": 9
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 后端实现要求
|
||||
|
||||
1. 根据 `ip + channel` 在进程表中查找对应 ffmpeg 子进程;
|
||||
2. 找到后 `ffmpeg.kill('SIGKILL')`(或先 `SIGTERM` 再兜底 `SIGKILL`),并从进程表移除;
|
||||
3. **幂等**:未找到对应流时也应返回成功(`stopped: false`),不应返回 4xx/5xx;
|
||||
4. 若同时存在基于 session id 的实例,应同时支持按 `sessionId` 定位(可选扩展)。
|
||||
|
||||
---
|
||||
|
||||
## 前端调用关系
|
||||
|
||||
```
|
||||
returnUnpackwork/index.vue
|
||||
└─ 关闭浮窗 closePreview() → livePreviewRef.stop()
|
||||
CameraLivePreview.vue
|
||||
├─ 拉流成功 → 记录 activeStream
|
||||
└─ stopStream() → stopLiveStream(activeStream) // POST /api/hikvision/stop-stream
|
||||
```
|
||||
|
||||
前端调用封装位于 `src/api/camera_server/localServerApi.ts`:
|
||||
|
||||
- `getHikvisionChannels(baseUrl, params)` → `POST /api/hikvision/channels`
|
||||
- `getLiveStreamUrl(params)` → 生成 `GET /api/hikvision/live-stream` 地址
|
||||
- `stopLiveStream(params)` → `POST /api/hikvision/stop-stream`
|
||||
|
||||
@ -182,7 +182,8 @@ export interface AfterSaleRelated {
|
||||
|
||||
/** 售后步骤对象 */
|
||||
export interface AfterSaleStep {
|
||||
id: number
|
||||
/** 步骤ID(虚拟步骤为 null) */
|
||||
id: number | null
|
||||
after_sale_id: number
|
||||
step_status: StepStatus
|
||||
operator_id: number | null
|
||||
@ -193,6 +194,8 @@ export interface AfterSaleStep {
|
||||
completed_at: string | null
|
||||
created_at: string
|
||||
attachments: FileReference[]
|
||||
/** 是否虚拟步骤(主表 description 非空时列表第一条,不落库) */
|
||||
is_virtual?: boolean
|
||||
}
|
||||
|
||||
/** 文件引用 */
|
||||
@ -206,6 +209,40 @@ export interface FileReference {
|
||||
mime_type?: string
|
||||
}
|
||||
|
||||
// ==================== 响应类型 ====================
|
||||
|
||||
/** 售后工作列表项(主表字段 + detail_count + store_name) */
|
||||
export interface AfterSaleWorkListItem extends AfterSale {
|
||||
/** 售后单关联计数 */
|
||||
detail_count: number
|
||||
/** 货主名称:取合约表 store_remask,无合约或备注为空时回退公司全称,无货主时为空字符串 */
|
||||
store_name: string
|
||||
}
|
||||
|
||||
/** 分页信息 */
|
||||
export interface AfterSalePagination {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
/** afterSale.workList 响应 */
|
||||
export interface AfterSaleWorkListResponse {
|
||||
list: AfterSaleWorkListItem[]
|
||||
pagination: AfterSalePagination
|
||||
}
|
||||
|
||||
/** afterSale.detail 响应 */
|
||||
export interface AfterSaleDetailResponse {
|
||||
/** 售后主表完整记录(含格式化时间字段) */
|
||||
after_sale: AfterSale
|
||||
/** 售后进度步骤列表(含附件),按创建时间升序 */
|
||||
steps: AfterSaleStep[]
|
||||
/** 关联单据详情(订单/运单/货主合约),无关联时为空对象 */
|
||||
related: AfterSaleRelated
|
||||
}
|
||||
|
||||
// ==================== 请求参数类型 ====================
|
||||
|
||||
/** 列表查询参数 */
|
||||
@ -312,7 +349,7 @@ export interface AfterSaleBatchCloseFailedItem {
|
||||
// ==================== API 方法 ====================
|
||||
|
||||
/** 2.1 工作列表 afterSale.workList */
|
||||
export function afterSaleWorkList(data: AfterSaleListParams = {}) {
|
||||
export function afterSaleWorkList(data: AfterSaleListParams = {}): Promise<AfterSaleWorkListResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
@ -342,7 +379,7 @@ export function afterSaleAuditList(data: AfterSaleListParams = {}) {
|
||||
}
|
||||
|
||||
/** 2.3 售后明细 afterSale.detail */
|
||||
export function afterSaleDetail(id: number) {
|
||||
export function afterSaleDetail(id: number): Promise<AfterSaleDetailResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
|
||||
@ -116,5 +116,29 @@ export function getLiveStreamUrl(params: {
|
||||
return `${DEFAULT_PROXY_BASE}/api/hikvision/live-stream?ip=${encodeURIComponent(ip)}&user=${encodeURIComponent(user)}&pass=${encodeURIComponent(pass)}&channel=${channel}&streamType=${streamType}${portParam}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止实时流(显式通知后端 kill 对应 ffmpeg 进程)
|
||||
* 后端 POST /api/hikvision/stop-stream
|
||||
*
|
||||
* @example
|
||||
* stopLiveStream({ ip: '192.168.8.241', user: 'admin', pass: 'ky666888', channel: 9, port: 8000 })
|
||||
*/
|
||||
export interface LiveStreamTarget {
|
||||
ip: string
|
||||
user: string
|
||||
pass: string
|
||||
channel: number
|
||||
port?: number
|
||||
}
|
||||
|
||||
export async function stopLiveStream(params: LiveStreamTarget) {
|
||||
const client = createClient(DEFAULT_PROXY_BASE)
|
||||
try {
|
||||
await client.post('/api/hikvision/stop-stream', params)
|
||||
} catch {
|
||||
// 停止失败忽略:后端应在客户端连接断开时兜底回收 ffmpeg
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 后续在此追加其他 API ----------
|
||||
// export async function getSomeOtherApi(baseUrl: string, params?: any) { ... }
|
||||
|
||||
@ -149,7 +149,10 @@ export type PendingOrderBatchInterceptProgressParams = {
|
||||
};
|
||||
|
||||
export type PendingOrderParseAddressParams = {
|
||||
address: string;
|
||||
/** 单条地址解析(与 addresses 二选一) */
|
||||
address?: string;
|
||||
/** 批量地址解析(单次最多 50 条) */
|
||||
addresses?: string[];
|
||||
};
|
||||
|
||||
export type PendingOrderParseAddressData = {
|
||||
@ -162,12 +165,21 @@ export type PendingOrderParseAddressData = {
|
||||
mobile?: string
|
||||
};
|
||||
|
||||
/** 批量解析结果项(按输入顺序返回) */
|
||||
export type PendingOrderParseAddressItem = PendingOrderParseAddressData & {
|
||||
address?: string
|
||||
flag?: string
|
||||
message?: string
|
||||
};
|
||||
|
||||
export type PendingOrderParseAddressResponse = {
|
||||
flag?: string;
|
||||
code: number;
|
||||
message: string;
|
||||
timestamp?: number;
|
||||
data?: PendingOrderParseAddressData;
|
||||
data?: PendingOrderParseAddressData & { list?: PendingOrderParseAddressItem[] };
|
||||
/** 批量解析结果数组(实际响应中位于顶层,兼容 data.list) */
|
||||
list?: PendingOrderParseAddressItem[];
|
||||
} & PendingOrderParseAddressData;
|
||||
|
||||
export function extractPendingOrderParseAddressData(
|
||||
@ -197,6 +209,16 @@ export function extractPendingOrderParseAddressData(
|
||||
};
|
||||
}
|
||||
|
||||
/** 提取批量解析结果列表,未返回时为空数组(兼容顶层 list 与 data.list) */
|
||||
export function extractPendingOrderParseAddressList(
|
||||
res?: PendingOrderParseAddressResponse | null,
|
||||
): PendingOrderParseAddressItem[] {
|
||||
const nestedList = res?.data?.list;
|
||||
if (Array.isArray(nestedList)) return nestedList;
|
||||
const topList = res?.list;
|
||||
return Array.isArray(topList) ? topList : [];
|
||||
}
|
||||
|
||||
/** 与文档 Params 别名对齐;不再传 warehouse_id(由登录上下文决定仓库) */
|
||||
export type PendingOrderAllocateStorageParams = {
|
||||
allow_storage_location?: boolean;
|
||||
@ -576,6 +598,8 @@ export function orderPendingOrderParseAddress(
|
||||
},
|
||||
data,
|
||||
isSystemApi: true,
|
||||
// 地址解析可能调用外部服务,延长超时时间至 35 秒
|
||||
timeout: 35000,
|
||||
} as any);
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,91 @@ import request from '@/utils/request'
|
||||
|
||||
const v = '1.0'
|
||||
|
||||
// ============ 通用数据类型 ============
|
||||
|
||||
/** 库存详情(识别命中商品时附加,由 stockWarehouse.getStockDetails 拉取) */
|
||||
export type ReturnUnpackStockDetail = {
|
||||
item_code?: string
|
||||
item_name?: string
|
||||
sku_property?: string
|
||||
/** 条码数组 */
|
||||
barcodes?: { id?: number; barcode?: string }[]
|
||||
/** 图片数组 */
|
||||
image_url?: string[]
|
||||
packing_requirements?: string
|
||||
stock_unit?: string
|
||||
quantity?: number
|
||||
locked_quantity?: number
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 拆包明细行 */
|
||||
export type ReturnUnpackDetailItem = {
|
||||
id?: number
|
||||
unpack_id?: number
|
||||
stock_id?: number | null
|
||||
barcode?: string
|
||||
quantity?: number
|
||||
product_status?: 'normal' | 'damaged'
|
||||
/** 是否识别:1 识别到系统商品 / 0 非识别物品 */
|
||||
is_recognized?: 0 | 1
|
||||
item_code?: string
|
||||
item_name?: string
|
||||
spec?: string
|
||||
product_snapshot?: any
|
||||
remark?: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
/** 识别命中时的库存详情对象 */
|
||||
stock?: ReturnUnpackStockDetail
|
||||
/** 识别命中时的 stockWarehouse 关联 */
|
||||
stockWarehouse?: any
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 拆包单主表记录 */
|
||||
export type ReturnUnpackRecord = {
|
||||
id?: number
|
||||
unpack_no?: string
|
||||
waybill_code?: string
|
||||
unpack_date?: string
|
||||
start_time?: string
|
||||
end_time?: string
|
||||
unpacker_id?: number
|
||||
unpacker_name?: string
|
||||
status?: 'unpacking' | 'completed' | 'cancelled'
|
||||
detail_status?: 'none_recognized' | 'partial_recognized' | 'all_recognized'
|
||||
camera_ids?: number[]
|
||||
order_express_id?: number
|
||||
order_id?: number
|
||||
store_id?: number
|
||||
source_order_codes?: string
|
||||
shop_name?: string
|
||||
is_original_return?: boolean
|
||||
total_items?: number
|
||||
total_quantity?: number
|
||||
/** 幂等复用时携带 */
|
||||
details?: ReturnUnpackDetailItem[]
|
||||
videos?: any[]
|
||||
returnReceived?: any
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 原订单详情(原单退回时返回,含 items 明细) */
|
||||
export type ReturnUnpackOriginalOrder = {
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
/** 分页信息 */
|
||||
export type ReturnUnpackPagination = {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
totalPages: number
|
||||
hasPrevious?: boolean
|
||||
hasNext?: boolean
|
||||
}
|
||||
|
||||
// ============ returnUnpack.create ============
|
||||
|
||||
/** returnUnpack.create 请求参数 */
|
||||
@ -16,8 +101,24 @@ export type ReturnUnpackCreateParams = {
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** returnUnpack.create 响应 */
|
||||
export type ReturnUnpackCreateResponse = {
|
||||
/** 拆包单主键ID(后续明细收录的依据) */
|
||||
id: number
|
||||
/** 拆包单主表记录(幂等复用时含 details/videos/returnReceived) */
|
||||
record: ReturnUnpackRecord
|
||||
/** 是否原单退回 */
|
||||
is_original_return: boolean
|
||||
/** 货主的合约货主备注名称,未命中时为空字符串 */
|
||||
store_remark: string
|
||||
/** 原订单详情(仅原单退回时返回,非原单为 null) */
|
||||
order?: ReturnUnpackOriginalOrder | null
|
||||
/** 是否幂等复用已有拆包单 */
|
||||
reused?: boolean
|
||||
}
|
||||
|
||||
/** returnUnpack.create:开拆包单(明细不在此提交,由 returnUnpack.addDetail 逐件录入) */
|
||||
export function returnUnpackCreate(data: ReturnUnpackCreateParams): Promise<any> {
|
||||
export function returnUnpackCreate(data: ReturnUnpackCreateParams): Promise<ReturnUnpackCreateResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
@ -49,8 +150,22 @@ export type ReturnUnpackAddDetailParams = {
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** returnUnpack.addDetail 响应 */
|
||||
export type ReturnUnpackAddDetailResponse = {
|
||||
/** 新增明细ID(供 updateDetail / removeDetail 使用) */
|
||||
detail_id: number
|
||||
/** 新增的明细行(识别到系统商品时附加 stock 库存详情对象) */
|
||||
detail: ReturnUnpackDetailItem
|
||||
/** 主表最新物品种类数(明细行数) */
|
||||
total_items: number
|
||||
/** 主表最新物品总数量(明细数量合计) */
|
||||
total_quantity: number
|
||||
/** 主表最新明细识别状态 */
|
||||
detail_status: 'none_recognized' | 'partial_recognized' | 'all_recognized'
|
||||
}
|
||||
|
||||
/** returnUnpack.addDetail:以拆包单ID为依据录入一条明细 */
|
||||
export function returnUnpackAddDetail(data: ReturnUnpackAddDetailParams): Promise<any> {
|
||||
export function returnUnpackAddDetail(data: ReturnUnpackAddDetailParams): Promise<ReturnUnpackAddDetailResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
@ -78,8 +193,20 @@ export type ReturnUnpackUpdateDetailParams = {
|
||||
remark?: string
|
||||
}
|
||||
|
||||
/** returnUnpack.updateDetail 响应 */
|
||||
export type ReturnUnpackUpdateDetailResponse = {
|
||||
/** 更新后的明细行(识别到系统商品时附加 stock 库存详情对象) */
|
||||
detail: ReturnUnpackDetailItem
|
||||
/** 主表最新物品种类数 */
|
||||
total_items: number
|
||||
/** 主表最新物品总数量(quantity 变更时重算) */
|
||||
total_quantity: number
|
||||
/** 主表最新明细识别状态 */
|
||||
detail_status: 'none_recognized' | 'partial_recognized' | 'all_recognized'
|
||||
}
|
||||
|
||||
/** returnUnpack.updateDetail:更新明细(仅允许更新 quantity/remark) */
|
||||
export function returnUnpackUpdateDetail(data: ReturnUnpackUpdateDetailParams): Promise<any> {
|
||||
export function returnUnpackUpdateDetail(data: ReturnUnpackUpdateDetailParams): Promise<ReturnUnpackUpdateDetailResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
@ -263,8 +390,15 @@ export type ReturnUnpackDetailListParams = {
|
||||
sort?: ReturnUnpackDetailListSort
|
||||
}
|
||||
|
||||
/** returnUnpack.detailList 响应 */
|
||||
export type ReturnUnpackDetailListResponse = {
|
||||
/** 明细行列表(识别命中时含 stockWarehouse 关联与 stock 库存详情对象) */
|
||||
list: ReturnUnpackDetailItem[]
|
||||
pagination: ReturnUnpackPagination
|
||||
}
|
||||
|
||||
/** returnUnpack.detailList:拆包明细分页列表(命中识别商品时含 stockWarehouse 关联) */
|
||||
export function returnUnpackDetailList(data: ReturnUnpackDetailListParams = {}): Promise<any> {
|
||||
export function returnUnpackDetailList(data: ReturnUnpackDetailListParams = {}): Promise<ReturnUnpackDetailListResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
|
||||
@ -80,12 +80,13 @@ export interface ShopAuthorizeSessionKeyResponse {
|
||||
}
|
||||
}
|
||||
|
||||
/** 按店铺所属平台生成授权会话(callbackurl 必填;视频号平台另传 appId/toUserName) */
|
||||
/** 按店铺所属平台生成授权会话(视频号平台不传 callbackurl,另传 appId/toUserName;京东平台另传 VenderID) */
|
||||
export function shopGetAuthorizeSessionKey(data: {
|
||||
id: number
|
||||
callbackurl: string
|
||||
callbackurl?: string
|
||||
appId?: string
|
||||
toUserName?: string
|
||||
VenderID?: string
|
||||
}): Promise<ShopAuthorizeSessionKeyResponse> {
|
||||
return request({
|
||||
url: '/system',
|
||||
|
||||
@ -129,6 +129,8 @@
|
||||
<el-descriptions-item label="扫描日期">{{ formatTime(detailData.record?.scan_date) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="扫描人员工号">{{ detailData.record?.scanner_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="扫描人员">{{ detailData.record?.scanner_name ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="仓库ID">{{ detailData.record?.warehouse_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="货主ID">{{ detailData.record?.store_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="是否原单退回">
|
||||
<el-tag :type="detailData.record?.is_original_return ? 'success' : 'info'" size="small">
|
||||
{{ detailData.record?.is_original_return ? '是' : '否' }}
|
||||
@ -138,6 +140,7 @@
|
||||
<el-descriptions-item label="原订单ID">{{ detailData.record?.order_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="货主备注">{{ detailData.record?.store_remark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="登记时间">{{ formatTime(detailData.record?.created_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="更新时间">{{ formatTime(detailData.record?.updated_at) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="3">{{ detailData.record?.remark || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
@ -188,8 +191,11 @@ import { safeInvoke } from '@/utils/safe-invoke'
|
||||
|
||||
function formatTime(val: any): string {
|
||||
if (val === null || val === undefined || val === '') return '-'
|
||||
const str = String(val)
|
||||
// 纯日期字符串直接返回,避免时区偏移
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(str)) return str
|
||||
const d = new Date(val)
|
||||
if (isNaN(d.getTime())) return String(val)
|
||||
if (isNaN(d.getTime())) return str
|
||||
return d.toLocaleString('zh-CN', { hour12: false })
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,85 @@
|
||||
<template>
|
||||
<el-table :data="list" size="small" border class="detail-table" empty-text="暂无明细">
|
||||
<el-table-column prop="id" label="明细ID" width="80" />
|
||||
<el-table-column label="商品图片" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-image
|
||||
v-if="stockImage(row)"
|
||||
:src="stockImage(row)"
|
||||
:preview-src-list="stockImages(row)"
|
||||
preview-teleported
|
||||
fit="cover"
|
||||
class="stock-thumb"
|
||||
/>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="item_code" label="商品编码" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column label="SKU" min-width="110" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ stockSku(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="条码" min-width="130" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ stockBarcodes(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="barcode" label="扫描条码" min-width="130" show-overflow-tooltip />
|
||||
<el-table-column label="库存单位" width="90">
|
||||
<template #default="{ row }">{{ row.stock?.stock_unit || row.stockWarehouse?.stock_unit || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="stock_id" label="商品ID" width="90">
|
||||
<template #default="{ row }">{{ row.stock_id ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="is_recognized" label="识别" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_recognized ? 'success' : 'info'" size="small">
|
||||
{{ row.is_recognized ? '已识别' : '未识别' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="product_status" label="产品状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.product_status === 'damaged' ? 'danger' : 'success'" size="small">
|
||||
{{ row.product_status === 'damaged' ? '破损' : '正常' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="quantity" label="数量" width="70" />
|
||||
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
|
||||
</el-table>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps<{ list: any[] }>()
|
||||
|
||||
function stockImage(row: any): string {
|
||||
return row?.stock?.image_url?.[0] ?? row?.stockWarehouse?.image_url?.[0] ?? ''
|
||||
}
|
||||
|
||||
function stockImages(row: any): string[] {
|
||||
return row?.stock?.image_url ?? row?.stockWarehouse?.image_url ?? []
|
||||
}
|
||||
|
||||
function stockSku(row: any): string {
|
||||
return row?.stock?.sku_property || row?.stockWarehouse?.sku_property || '-'
|
||||
}
|
||||
|
||||
function stockBarcodes(row: any): string {
|
||||
const barcodes = row?.stock?.barcodes ?? []
|
||||
if (barcodes.length) {
|
||||
return barcodes.map((b: any) => b?.barcode ?? '').filter(Boolean).join(', ')
|
||||
}
|
||||
return row?.barcode || '-'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.detail-table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.stock-thumb {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
@ -23,7 +23,7 @@
|
||||
:layout-key="toolbarLayoutKey"
|
||||
@action="handleToolbarButtonClick"
|
||||
/>
|
||||
<el-divider direction="vertical" />
|
||||
<!-- <el-divider direction="vertical" /> -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -67,8 +67,8 @@
|
||||
</el-tag>
|
||||
</template>
|
||||
|
||||
<template #column-store_id="{ row }">
|
||||
<span v-if="row.store_id != null">{{ row.store_id }}</span>
|
||||
<template #column-shop_name="{ row }">
|
||||
<span v-if="row.shop_name">{{ row.shop_name }}</span>
|
||||
<span v-else>-</span>
|
||||
</template>
|
||||
|
||||
@ -89,6 +89,8 @@
|
||||
<!-- ========== 拆包详情弹窗 ========== -->
|
||||
<el-dialog v-model="detailVisible" title="退回拆包详情" width="1080px" destroy-on-close align-center>
|
||||
<div v-loading="detailLoading" class="detail-content">
|
||||
<el-tabs v-model="detailActiveTab" @tab-change="handleDetailTabChange">
|
||||
<el-tab-pane label="拆包详情" name="detail">
|
||||
<template v-if="detailRecord">
|
||||
<!-- 主表信息 -->
|
||||
<el-descriptions title="拆包单信息" :column="3" border size="small" class="detail-section">
|
||||
@ -131,9 +133,12 @@
|
||||
<el-descriptions-item label="拆包开始时间">{{ formatTime(detailRecord.start_time) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="拆包结束时间">{{ formatTime(detailRecord.end_time) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="货主ID">{{ detailRecord.store_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="货主名称">{{ detailRecord.shop_name || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="平台交易单号">{{ detailRecord.source_order_codes || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="原运单ID">{{ detailRecord.order_express_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="原订单ID">{{ detailRecord.order_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="货主备注" :span="3">{{ detailRecord.store_remark || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="关联退回收到单">{{ detailRecord.return_received_id ?? '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="摄像头" :span="3">{{ cameraIdsLabel(detailRecord.camera_ids) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="3">{{ detailRecord.remark || '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
@ -147,37 +152,30 @@
|
||||
<el-descriptions-item label="商品件数">{{ detailOrder.items?.length ?? '-' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<!-- 明细表格 -->
|
||||
<!-- 明细表格(returnUnpack.detail 内嵌 record.details) -->
|
||||
<div class="detail-list-header">
|
||||
<span class="detail-list-title">拆包明细({{ detailList.length }})</span>
|
||||
<span class="detail-list-title">拆包明细({{ detailRecord.details?.length ?? 0 }})</span>
|
||||
</div>
|
||||
<el-table :data="detailList" size="small" border class="detail-table" empty-text="暂无明细">
|
||||
<el-table-column prop="id" label="明细ID" width="80" />
|
||||
<el-table-column prop="barcode" label="条码" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="stock_id" label="商品ID" width="90">
|
||||
<template #default="{ row }">{{ row.stock_id ?? '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="item_code" label="商品编码" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="item_name" label="商品名称" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="spec" label="规格" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="is_recognized" label="是否识别" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.is_recognized ? 'success' : 'info'" size="small">
|
||||
{{ row.is_recognized ? '已识别' : '未识别' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="product_status" label="产品状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.product_status === 'damaged' ? 'danger' : 'success'" size="small">
|
||||
{{ row.product_status === 'damaged' ? '破损' : '正常' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="quantity" label="数量" width="80" />
|
||||
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
|
||||
</el-table>
|
||||
<unpack-detail-table :list="detailRecord.details ?? []" />
|
||||
</template>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- Tab2: returnUnpack.detailList -->
|
||||
<el-tab-pane label="明细分页" name="detailList">
|
||||
<div v-loading="detailListLoading" class="detail-list-pane">
|
||||
<unpack-detail-table :list="detailList" />
|
||||
<el-pagination
|
||||
v-if="detailPagination.total > detailPagination.pageSize"
|
||||
class="detail-pagination"
|
||||
layout="prev, pager, next, total"
|
||||
:current-page="detailPagination.currentPage"
|
||||
:page-size="detailPagination.pageSize"
|
||||
:total="detailPagination.total"
|
||||
@current-change="handleDetailListPageChange"
|
||||
/>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
@ -203,13 +201,17 @@ import { returnUnpackAvailableFields, returnUnpackColumns, returnUnpackToolbarBu
|
||||
import ScanBox from '@/components/ScanBox/index.vue'
|
||||
import UpperTable from '@/components/UpperTable/index.vue'
|
||||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||||
import UnpackDetailTable from './components/UnpackDetailTable.vue'
|
||||
|
||||
// ==================== 常量 / 工具 ====================
|
||||
|
||||
function formatTime(val: any): string {
|
||||
if (val === null || val === undefined || val === '') return '-'
|
||||
const str = String(val)
|
||||
// 纯日期字符串直接返回,避免时区偏移
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(str)) return str
|
||||
const d = new Date(val)
|
||||
if (isNaN(d.getTime())) return String(val)
|
||||
if (isNaN(d.getTime())) return str
|
||||
return d.toLocaleString('zh-CN', { hour12: false })
|
||||
}
|
||||
|
||||
@ -249,6 +251,11 @@ function detailStatusTagType(val: any): 'success' | 'warning' | 'info' | 'danger
|
||||
return map[String(val)] ?? 'info'
|
||||
}
|
||||
|
||||
function cameraIdsLabel(ids: any): string {
|
||||
if (!Array.isArray(ids) || ids.length === 0) return '-'
|
||||
return ids.join(', ')
|
||||
}
|
||||
|
||||
function isOk(res: any): boolean {
|
||||
return Boolean(res && (res.code === 1 || res.code === 200 || res.code === 20000))
|
||||
}
|
||||
@ -465,26 +472,34 @@ function handleSortChange({ prop, order }: any) {
|
||||
|
||||
const detailVisible = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const detailActiveTab = ref('detail')
|
||||
const detailRecord = ref<any>(null)
|
||||
const detailOrder = ref<any>(null)
|
||||
|
||||
// Tab2(returnUnpack.detailList)分页明细状态
|
||||
const detailListLoading = ref(false)
|
||||
const detailList = ref<any[]>([])
|
||||
const detailPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||||
|
||||
async function handleViewDetail(row: any) {
|
||||
detailVisible.value = true
|
||||
detailLoading.value = true
|
||||
detailActiveTab.value = 'detail'
|
||||
detailRecord.value = null
|
||||
detailOrder.value = null
|
||||
detailList.value = []
|
||||
detailPagination.currentPage = 1
|
||||
detailPagination.total = 0
|
||||
try {
|
||||
const res: any = await returnUnpackDetail({ id: row.id })
|
||||
if (isOk(res)) {
|
||||
const data = res.data ?? res
|
||||
detailRecord.value = data.record ?? data
|
||||
detailOrder.value = data.related?.order ?? data.order ?? null
|
||||
const record = data.record ?? data
|
||||
detailRecord.value = record
|
||||
detailOrder.value = data.related?.order ?? null
|
||||
} else {
|
||||
ElMessage.error(res?.message || '获取详情失败')
|
||||
}
|
||||
await loadDetailList(row.id)
|
||||
} catch {
|
||||
// 请求层已提示错误
|
||||
} finally {
|
||||
@ -492,23 +507,44 @@ async function handleViewDetail(row: any) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetailList(unpackId: number) {
|
||||
// Tab 切换:切到「明细分页」时按分页加载 detailList
|
||||
async function handleDetailTabChange(name: string | number) {
|
||||
if (name === 'detailList' && detailRecord.value) {
|
||||
await loadDetailListPage(detailPagination.currentPage || 1)
|
||||
}
|
||||
}
|
||||
|
||||
async function loadDetailListPage(page: number) {
|
||||
if (!detailRecord.value) return
|
||||
detailListLoading.value = true
|
||||
try {
|
||||
const res: any = await returnUnpackDetailList({
|
||||
pagination: { page: 1, pageSize: 500 },
|
||||
where: { unpack_id: unpackId },
|
||||
pagination: { page, pageSize: detailPagination.pageSize },
|
||||
where: { unpack_id: detailRecord.value.id },
|
||||
})
|
||||
if (isOk(res)) {
|
||||
const data = res.data ?? res
|
||||
detailList.value = data.list ?? []
|
||||
const total = data.pagination?.total ?? 0
|
||||
detailPagination.currentPage = page
|
||||
detailPagination.total = total
|
||||
} else {
|
||||
detailList.value = []
|
||||
detailPagination.total = 0
|
||||
ElMessage.error(res?.message || '获取明细分页失败')
|
||||
}
|
||||
} catch {
|
||||
detailList.value = []
|
||||
detailPagination.total = 0
|
||||
} finally {
|
||||
detailListLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleDetailListPageChange(page: number) {
|
||||
loadDetailListPage(page)
|
||||
}
|
||||
|
||||
// ==================== 货主选项加载 ====================
|
||||
|
||||
async function loadStoreOptions() {
|
||||
@ -585,8 +621,14 @@ onMounted(() => {
|
||||
}
|
||||
}
|
||||
|
||||
.detail-table {
|
||||
width: 100%;
|
||||
.detail-list-pane {
|
||||
min-height: 160px;
|
||||
}
|
||||
|
||||
.detail-pagination {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -71,8 +71,8 @@ export const returnUnpackColumns = [
|
||||
{ prop: 'total_quantity', label: '总数量', width: '90' },
|
||||
{ prop: 'unpacker_name', label: '拆包人', minWidth: '100', showOverflowTooltip: true },
|
||||
{ prop: 'unpack_date', label: '拆包日期', width: '130' },
|
||||
{ prop: 'shop_name', label: '货主/店铺', minWidth: '120', showOverflowTooltip: true },
|
||||
{ prop: 'is_original_return', label: '原单退回', width: '100' },
|
||||
{ prop: 'store_id', label: '货主ID', width: '90' },
|
||||
{ prop: 'created_at', label: '创建时间', width: '170', sortable: 'custom' },
|
||||
{ prop: 'actions', label: '操作', width: '240', fixed: 'right' },
|
||||
]
|
||||
|
||||
@ -12,8 +12,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { getLiveStreamUrl } from '@/api/camera_server/localServerApi'
|
||||
import { ref, computed, watch, onUnmounted } from 'vue'
|
||||
import { getLiveStreamUrl, stopLiveStream } from '@/api/camera_server/localServerApi'
|
||||
import { list as serverList, detail as serverDetail } from '@/api/camera_server/camera_server'
|
||||
|
||||
export interface CameraLiveItem {
|
||||
@ -33,6 +33,7 @@ const error = ref('')
|
||||
const streamReady = ref(false)
|
||||
const streamKey = ref(0)
|
||||
let probeAbort: AbortController | null = null
|
||||
const activeStream = ref<{ ip: string; user: string; pass: string; channel: number; port?: number } | null>(null)
|
||||
|
||||
const nvrIp = ref('')
|
||||
const nvrPort = ref<number | undefined>(undefined)
|
||||
@ -69,6 +70,18 @@ async function getServerInfo(id: number) {
|
||||
return null
|
||||
}
|
||||
|
||||
function currentStreamTarget() {
|
||||
const row = props.camera
|
||||
if (!row?.channel_id || !nvrIp.value || !nvrUser.value || !nvrPass.value) return null
|
||||
return {
|
||||
ip: nvrIp.value,
|
||||
user: nvrUser.value,
|
||||
pass: nvrPass.value,
|
||||
channel: row.channel_id,
|
||||
port: nvrPort.value,
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const row = props.camera
|
||||
if (!row) {
|
||||
@ -77,6 +90,9 @@ async function init() {
|
||||
return
|
||||
}
|
||||
|
||||
// 切换摄像头前先停止上一路流,避免残留 ffmpeg 进程
|
||||
stopStream()
|
||||
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
streamReady.value = false
|
||||
@ -134,6 +150,10 @@ async function probeStream() {
|
||||
streamReady.value = true
|
||||
loading.value = false
|
||||
streamKey.value += 1
|
||||
activeStream.value = currentStreamTarget()
|
||||
// 探测完成,立即断开探测连接,避免与 <img> 渲染重复拉起后端 ffmpeg 进程
|
||||
probeAbort?.abort()
|
||||
probeAbort = null
|
||||
} else if (!signal.aborted) {
|
||||
await handleProbeFail('nvr')
|
||||
}
|
||||
@ -171,14 +191,27 @@ async function handleProbeFail(reason: 'proxy' | 'nvr') {
|
||||
|
||||
function stopStream() {
|
||||
if (probeAbort) { probeAbort.abort(); probeAbort = null }
|
||||
if (activeStream.value) {
|
||||
void stopLiveStream(activeStream.value)
|
||||
activeStream.value = null
|
||||
}
|
||||
streamReady.value = false
|
||||
}
|
||||
|
||||
// 组件卸载时显式停止流:先调用后端 stop-stream kill ffmpeg,再断开前端连接
|
||||
onUnmounted(() => {
|
||||
stopStream()
|
||||
})
|
||||
|
||||
function reload() {
|
||||
stopStream()
|
||||
void init()
|
||||
}
|
||||
defineExpose({ reload })
|
||||
|
||||
function stop() {
|
||||
stopStream()
|
||||
}
|
||||
defineExpose({ reload, stop })
|
||||
|
||||
watch(() => props.camera, () => {
|
||||
void init()
|
||||
|
||||
@ -20,19 +20,6 @@
|
||||
<el-form-item>
|
||||
<el-button type="success" :loading="createLoading" @click="handleCreate">创建拆包</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="createResult?.id" label="货主">
|
||||
<el-select
|
||||
v-model="selectedStoreId"
|
||||
placeholder="无"
|
||||
clearable
|
||||
filterable
|
||||
size="small"
|
||||
class="full-width"
|
||||
@change="handleStoreChange"
|
||||
>
|
||||
<el-option v-for="store in storeOptions" :key="store.value" :label="store.label" :value="store.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="createResult?.id" label="产品状态">
|
||||
<el-select v-model="defaultProductStatus" size="small" class="full-width">
|
||||
<el-option label="正常" value="normal" />
|
||||
@ -50,6 +37,20 @@
|
||||
@change="handleBarcodeQuickAdd"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="createResult?.id" label="货主">
|
||||
<el-select
|
||||
ref="storeSelectRef"
|
||||
v-model="selectedStoreId"
|
||||
placeholder="无"
|
||||
clearable
|
||||
filterable
|
||||
size="small"
|
||||
class="full-width"
|
||||
@change="handleStoreChange"
|
||||
>
|
||||
<el-option v-for="store in storeOptions" :key="store.value" :label="store.label" :value="store.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="createResult?.id" label="操作">
|
||||
<div class="unpack-actions">
|
||||
<el-button v-if="createResult?.record?.status === 'unpacking'" size="small" type="success" :loading="submitLoading" @click="handleSubmit">提交确认</el-button>
|
||||
@ -58,6 +59,25 @@
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<div class="shortcut-tips">
|
||||
<div class="shortcut-tips-title">⌨ 键盘快捷键</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd>Enter</kbd><span>运单号:创建拆包单</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd>Enter</kbd><span>商品条码:查询并添加</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd>←</kbd><kbd>→</kbd><span>切换焦点(运单号/商品条码/货主/无选中)</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd>↑</kbd><kbd>↓</kbd><span>产品状态:正常 / 破损</span>
|
||||
</div>
|
||||
<div class="shortcut-row">
|
||||
<kbd>空格</kbd><kbd>Enter</kbd><span>无选中时:提交确认</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧区域 -->
|
||||
@ -103,7 +123,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="quantity" label="数量" width="130">
|
||||
<template #default="{ row }">
|
||||
<el-input-number v-model="row.quantity" :min="1" :max="999999" size="small" class="inline-number" />
|
||||
<el-input-number v-model="row.quantity" :min="1" :max="999999" size="small" class="inline-number" @change="() => handleAutoSave(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="product_status" label="产品状态" width="100">
|
||||
@ -115,12 +135,11 @@
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" min-width="140">
|
||||
<template #default="{ row }">
|
||||
<el-input v-model="row.remark" size="small" placeholder="备注" />
|
||||
<el-input v-model="row.remark" size="small" placeholder="备注" @change="() => handleAutoSave(row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<el-table-column label="操作" width="90" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button size="small" type="success" link :disabled="!isDetailModified(row)" :loading="savingDetailId === row.id" @click="handleSaveDetail(row)">保存</el-button>
|
||||
<el-button size="small" type="danger" link @click="handleRemoveDetail(row)">移除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@ -268,7 +287,7 @@
|
||||
<el-select v-model="activeCameraId" size="small" class="float-camera-select">
|
||||
<el-option v-for="cam in selectedCameras" :key="cam.id" :label="cameraLabel(cam)" :value="cam.id" />
|
||||
</el-select>
|
||||
<el-button link size="small" class="float-close" @click="floatVisible = false">✕</el-button>
|
||||
<el-button link size="small" class="float-close" @click="closePreview">✕</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="float-body">
|
||||
@ -336,6 +355,36 @@ const storeOptions = ref<Array<{ label: string; value: number }>>([])
|
||||
// 产品状态(快速添加明细时使用)
|
||||
const defaultProductStatus = ref<'normal' | 'damaged'>('normal')
|
||||
|
||||
// 货主下拉 ref
|
||||
const storeSelectRef = ref<any>(null)
|
||||
|
||||
// 焦点切换与提交确认弹窗防重
|
||||
const FOCUS_ORDER = ['waybill', 'barcode', 'store', 'none'] as const
|
||||
type FocusTarget = (typeof FOCUS_ORDER)[number]
|
||||
const focusTarget = ref<FocusTarget>('waybill')
|
||||
const submitConfirmOpen = ref(false)
|
||||
|
||||
function focusTargetElement(target: FocusTarget) {
|
||||
if (target === 'waybill') {
|
||||
waybillInputRef.value?.focus()
|
||||
} else if (target === 'barcode') {
|
||||
detailBarcodeRef.value?.focus()
|
||||
} else if (target === 'store') {
|
||||
storeSelectRef.value?.focus()
|
||||
} else {
|
||||
const active = document.activeElement as HTMLElement | null
|
||||
active?.blur?.()
|
||||
}
|
||||
}
|
||||
|
||||
function moveFocus(direction: 1 | -1) {
|
||||
const idx = FOCUS_ORDER.indexOf(focusTarget.value)
|
||||
const next = (idx + direction + FOCUS_ORDER.length) % FOCUS_ORDER.length
|
||||
const target = FOCUS_ORDER[next] as FocusTarget
|
||||
focusTarget.value = target
|
||||
focusTargetElement(target)
|
||||
}
|
||||
|
||||
function currentStoreId(): number | undefined {
|
||||
if (selectedStoreId.value != null) return selectedStoreId.value
|
||||
const recordStoreId = createResult.value?.record?.store_id
|
||||
@ -400,6 +449,12 @@ function ensureFloatPos() {
|
||||
}
|
||||
}
|
||||
|
||||
function closePreview() {
|
||||
// 显式停止当前流(kill 后端 ffmpeg),再隐藏浮窗
|
||||
livePreviewRef.value?.stop?.()
|
||||
floatVisible.value = false
|
||||
}
|
||||
|
||||
function startDrag(e: MouseEvent) {
|
||||
const startX = e.clientX
|
||||
const startY = e.clientY
|
||||
@ -846,9 +901,28 @@ async function refreshCurrentUnpack() {
|
||||
|
||||
// ==================== 拆包单操作 ====================
|
||||
|
||||
function resetWorkState() {
|
||||
createResult.value = null
|
||||
detailList.value = []
|
||||
detailPagination.total = 0
|
||||
waybillCode.value = ''
|
||||
detailBarcode.value = ''
|
||||
selectedStoreId.value = null
|
||||
storeOptions.value = []
|
||||
defaultProductStatus.value = 'normal'
|
||||
}
|
||||
|
||||
function focusWaybill() {
|
||||
focusTarget.value = 'waybill'
|
||||
nextTick(() => {
|
||||
waybillInputRef.value?.focus()
|
||||
})
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
const id = createResult.value?.id
|
||||
if (!id) return
|
||||
if (!id || submitConfirmOpen.value) return
|
||||
submitConfirmOpen.value = true
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'确认提交拆包单?提交后转为已完成终态,不可再录/移除明细。',
|
||||
@ -856,15 +930,18 @@ async function handleSubmit() {
|
||||
{ type: 'warning', confirmButtonText: '提交', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch {
|
||||
submitConfirmOpen.value = false
|
||||
return
|
||||
}
|
||||
submitConfirmOpen.value = false
|
||||
submitLoading.value = true
|
||||
try {
|
||||
const res: any = await returnUnpackSubmit({ id })
|
||||
if (isOk(res)) {
|
||||
ElMessage.success('提交成功')
|
||||
await refreshCurrentUnpack()
|
||||
resetWorkState()
|
||||
loadUnpackList()
|
||||
focusWaybill()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '提交失败')
|
||||
}
|
||||
@ -892,8 +969,7 @@ async function handleCancel() {
|
||||
const res: any = await returnUnpackCancel({ id })
|
||||
if (isOk(res)) {
|
||||
ElMessage.success('已取消拆包单')
|
||||
createResult.value = null
|
||||
detailList.value = []
|
||||
resetWorkState()
|
||||
loadUnpackList()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '取消拆包失败')
|
||||
@ -922,8 +998,7 @@ async function handleDeleteUnpack() {
|
||||
const res: any = await returnUnpackDelete({ id })
|
||||
if (isOk(res)) {
|
||||
ElMessage.success('删除成功')
|
||||
createResult.value = null
|
||||
detailList.value = []
|
||||
resetWorkState()
|
||||
loadUnpackList()
|
||||
} else {
|
||||
ElMessage.error(res?.message || '删除失败')
|
||||
@ -943,9 +1018,17 @@ function handleKeydown(e: KeyboardEvent) {
|
||||
const isTyping = tag === 'INPUT' || tag === 'TEXTAREA' || el?.isContentEditable === true
|
||||
const inSelect = el?.closest?.('.el-select') != null
|
||||
|
||||
// 空格键:提交确认(输入框/下拉内不触发)
|
||||
// 左/右方向键:在 运单号 → 商品条码 → 货主 → 无选中 间循环切换焦点(备注文本域除外)
|
||||
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
||||
if (tag === 'TEXTAREA') return
|
||||
e.preventDefault()
|
||||
moveFocus(e.key === 'ArrowRight' ? 1 : -1)
|
||||
return
|
||||
}
|
||||
|
||||
// 空格键:提交确认(输入框/下拉内不触发;确认弹窗打开时不重复触发)
|
||||
if (e.code === 'Space' || e.key === ' ') {
|
||||
if (isTyping || inSelect) return
|
||||
if (isTyping || inSelect || submitConfirmOpen.value) return
|
||||
const record = createResult.value?.record
|
||||
if (createResult.value?.id && record?.status === 'unpacking') {
|
||||
e.preventDefault()
|
||||
@ -954,6 +1037,18 @@ function handleKeydown(e: KeyboardEvent) {
|
||||
return
|
||||
}
|
||||
|
||||
// 回车键:无选中状态下确认提交
|
||||
if (e.key === 'Enter') {
|
||||
if (focusTarget.value === 'none' && !submitConfirmOpen.value) {
|
||||
const record = createResult.value?.record
|
||||
if (createResult.value?.id && record?.status === 'unpacking') {
|
||||
e.preventDefault()
|
||||
handleSubmit()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 上/下方向键:切换产品状态(textarea/数字输入框/下拉内不触发)
|
||||
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
||||
const isNumberInput = tag === 'INPUT' && (el?.className?.includes('el-input-number') ?? false)
|
||||
@ -970,6 +1065,10 @@ onMounted(async () => {
|
||||
await loadCameraList()
|
||||
restoreCameraSelection()
|
||||
window.addEventListener('keydown', handleKeydown)
|
||||
nextTick(() => {
|
||||
focusTarget.value = 'waybill'
|
||||
waybillInputRef.value?.focus()
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
@ -1029,6 +1128,11 @@ function isDetailModified(row: any): boolean {
|
||||
return quantityChanged || remarkChanged
|
||||
}
|
||||
|
||||
function handleAutoSave(row: any) {
|
||||
if (!isDetailModified(row)) return
|
||||
handleSaveDetail(row)
|
||||
}
|
||||
|
||||
async function handleSaveDetail(row: any) {
|
||||
const unpackId = createResult.value?.id
|
||||
if (!unpackId || savingDetailId.value != null) return
|
||||
@ -1106,7 +1210,9 @@ async function handleRemoveDetail(row: any) {
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
@ -1114,6 +1220,44 @@ async function handleRemoveDetail(row: any) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 键盘快捷键说明 */
|
||||
.shortcut-tips {
|
||||
border-top: 1px dashed #e8eef7;
|
||||
padding-top: 12px;
|
||||
}
|
||||
|
||||
.shortcut-tips-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.shortcut-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
margin-bottom: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.shortcut-row kbd {
|
||||
display: inline-block;
|
||||
min-width: 24px;
|
||||
padding: 2px 6px;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-bottom-width: 2px;
|
||||
border-radius: 4px;
|
||||
background: #f5f7fa;
|
||||
color: #303133;
|
||||
font-size: 12px;
|
||||
font-family: inherit;
|
||||
text-align: center;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.waybill-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
@ -46,6 +46,7 @@ export const returnWaybillAvailableFields = [
|
||||
export const returnWaybillColumns = [
|
||||
{ prop: 'id', label: 'ID', width: '80', sortable: 'custom' },
|
||||
{ prop: 'waybill_code', label: '运单号', minWidth: '180', showOverflowTooltip: true, copyAction: 'copy' as const },
|
||||
{ prop: 'warehouse_id', label: '仓库ID', width: '100' },
|
||||
{ prop: 'store_id', label: '货主ID', width: '100' },
|
||||
{ prop: 'is_notified', label: '是否已通知', width: '110' },
|
||||
{ prop: 'is_back', label: '是否退回', width: '100' },
|
||||
|
||||
@ -450,6 +450,7 @@ import {
|
||||
import { orderList } from '@/api/order.index/orderindex'
|
||||
import {
|
||||
extractPendingOrderParseAddressData,
|
||||
extractPendingOrderParseAddressList,
|
||||
orderPendingOrder,
|
||||
orderPendingOrderParseAddress,
|
||||
type PendingOrderParseAddressData
|
||||
@ -1296,7 +1297,31 @@ async function queryPendingOrdersByDeliveryCodes(codes: string[]) {
|
||||
|
||||
const DELIVERY_CODE_CHECK_BATCH_SIZE = 5
|
||||
const DELIVERY_CODE_CHECK_MAX_CONCURRENT = 5
|
||||
const ADDRESS_RECOGNIZE_MAX_CONCURRENT = 5
|
||||
|
||||
/** 单次批量解析地址的最大条数(与接口文档一致) */
|
||||
const PARSE_ADDRESS_BATCH_SIZE = 20
|
||||
|
||||
/** 批量解析地址:返回与输入 address 一一对应的解析结果(失败项为 null) */
|
||||
async function batchParseAddresses(addresses: string[]): Promise<(PendingOrderParseAddressData | null)[]> {
|
||||
const results: (PendingOrderParseAddressData | null)[] = new Array(addresses.length).fill(null)
|
||||
for (let i = 0; i < addresses.length; i += PARSE_ADDRESS_BATCH_SIZE) {
|
||||
const batch = addresses.slice(i, i + PARSE_ADDRESS_BATCH_SIZE)
|
||||
try {
|
||||
const res: any = await orderPendingOrderParseAddress({ addresses: batch })
|
||||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||||
const list = extractPendingOrderParseAddressList(res)
|
||||
batch.forEach((_, idx) => {
|
||||
const item = list[idx]
|
||||
if (ok && item && item.flag !== 'failure') {
|
||||
results[i + idx] = item
|
||||
}
|
||||
})
|
||||
} catch {
|
||||
// 该批解析失败,保持 null
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
function chunkDeliveryOrderCodes(codes: string[], size = DELIVERY_CODE_CHECK_BATCH_SIZE) {
|
||||
const chunks: string[][] = []
|
||||
@ -1357,30 +1382,20 @@ async function handleReRecognizeAddresses() {
|
||||
let failCount = 0
|
||||
|
||||
try {
|
||||
await runWithConcurrencyLimit(targetRows, ADDRESS_RECOGNIZE_MAX_CONCURRENT, async (row) => {
|
||||
const address = getPreviewRowParseAddressInput(row)
|
||||
if (!address) return
|
||||
const rowAddressPairs = targetRows
|
||||
.map((row) => ({ row, address: getPreviewRowParseAddressInput(row) }))
|
||||
.filter((item) => Boolean(item.address))
|
||||
|
||||
try {
|
||||
const res: any = await orderPendingOrderParseAddress({ address })
|
||||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||||
if (!ok) {
|
||||
failCount += 1
|
||||
return
|
||||
}
|
||||
|
||||
const data = extractPendingOrderParseAddressData(res)
|
||||
if (!data) {
|
||||
failCount += 1
|
||||
return
|
||||
}
|
||||
|
||||
applyParsedAddressToRow(row, data)
|
||||
successCount += 1
|
||||
persistCreateOrderDraft()
|
||||
} catch {
|
||||
const results = await batchParseAddresses(rowAddressPairs.map((item) => item.address))
|
||||
rowAddressPairs.forEach(({ row }, idx) => {
|
||||
const data = results[idx]
|
||||
if (!data) {
|
||||
failCount += 1
|
||||
return
|
||||
}
|
||||
applyParsedAddressToRow(row, data)
|
||||
successCount += 1
|
||||
persistCreateOrderDraft()
|
||||
})
|
||||
|
||||
if (!successCount) {
|
||||
@ -1610,35 +1625,30 @@ async function parseImportPreviewFromFile(file: File) {
|
||||
return
|
||||
}
|
||||
|
||||
// 省市区为空时自动地址智能识别(逐个订单串行执行避免并发)
|
||||
for (const row of mergedRows) {
|
||||
// 省市区为空时自动地址智能识别(批量解析)
|
||||
const needParseRows = mergedRows.filter((row) => {
|
||||
if (String(row.province || '').trim() && String(row.city || '').trim() && String(row.area || '').trim()) {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
return Boolean(getPreviewRowParseAddressInput(row))
|
||||
})
|
||||
const parseResults = await batchParseAddresses(needParseRows.map((row) => getPreviewRowParseAddressInput(row)))
|
||||
needParseRows.forEach((row, idx) => {
|
||||
const address = getPreviewRowParseAddressInput(row)
|
||||
if (!address) continue
|
||||
try {
|
||||
const res: any = await orderPendingOrderParseAddress({ address })
|
||||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||||
if (!ok) continue
|
||||
const data = extractPendingOrderParseAddressData(res)
|
||||
if (data) {
|
||||
if (data.province) row.province = String(data.province).trim()
|
||||
if (data.city) row.city = String(data.city).trim()
|
||||
if (data.area) row.area = String(data.area).trim()
|
||||
if (data.detailAddress) row.detail_address = String(data.detailAddress).trim()
|
||||
if (!row._source_address) row._source_address = address
|
||||
if (data.name && !row.name) row.name = String(data.name).trim()
|
||||
if (data.mobile && !row.mobile) row.mobile = String(data.mobile).trim()
|
||||
const regionCodes = resolvePreviewRowRegionCodes({ province: row.province, city: row.city, area: row.area })
|
||||
if (regionCodes.provinceCode) row.province_code = regionCodes.provinceCode
|
||||
if (regionCodes.cityCode) row.city_code = regionCodes.cityCode
|
||||
if (regionCodes.districtCode) row.area_code = regionCodes.districtCode
|
||||
}
|
||||
} catch {
|
||||
// 解析失败不影响导入
|
||||
}
|
||||
}
|
||||
const data = parseResults[idx]
|
||||
if (!data) return
|
||||
if (data.province) row.province = String(data.province).trim()
|
||||
if (data.city) row.city = String(data.city).trim()
|
||||
if (data.area) row.area = String(data.area).trim()
|
||||
if (data.detailAddress) row.detail_address = String(data.detailAddress).trim()
|
||||
if (!row._source_address) row._source_address = address
|
||||
if (data.name && !row.name) row.name = String(data.name).trim()
|
||||
if (data.mobile && !row.mobile) row.mobile = String(data.mobile).trim()
|
||||
const regionCodes = resolvePreviewRowRegionCodes({ province: row.province, city: row.city, area: row.area })
|
||||
if (regionCodes.provinceCode) row.province_code = regionCodes.provinceCode
|
||||
if (regionCodes.cityCode) row.city_code = regionCodes.cityCode
|
||||
if (regionCodes.districtCode) row.area_code = regionCodes.districtCode
|
||||
})
|
||||
|
||||
// 订单号预检查:查询系统中是否已存在相同订单号
|
||||
const orderCodesToCheck = mergedRows
|
||||
@ -1963,8 +1973,9 @@ async function submitImportOrders() {
|
||||
return
|
||||
}
|
||||
|
||||
// 省市区为空时,自动使用详细地址做地址智能识别
|
||||
// 省市区为空时,自动使用详细地址做地址智能识别(批量解析)
|
||||
const groupsBeforeValidate = groupPendingRowsByOrder()
|
||||
const needParseGroups: { rows: ImportPreviewRow[]; address: string }[] = []
|
||||
for (const [, rows] of groupsBeforeValidate) {
|
||||
const header = rows[0]
|
||||
if (!header) continue
|
||||
@ -1973,18 +1984,16 @@ async function submitImportOrders() {
|
||||
}
|
||||
const address = getPreviewRowParseAddressInput(header)
|
||||
if (!address) continue
|
||||
try {
|
||||
const res: any = await orderPendingOrderParseAddress({ address })
|
||||
const ok = res && (res.code === 1 || res.code === 200 || res.flag === 'success')
|
||||
if (!ok) continue
|
||||
const data = extractPendingOrderParseAddressData(res)
|
||||
for (const row of rows) {
|
||||
applyParsedAddressToRow(row, data)
|
||||
}
|
||||
} catch {
|
||||
// 解析失败不影响提交流程
|
||||
}
|
||||
needParseGroups.push({ rows, address })
|
||||
}
|
||||
const parseResults = await batchParseAddresses(needParseGroups.map((g) => g.address))
|
||||
needParseGroups.forEach(({ rows }, idx) => {
|
||||
const data = parseResults[idx]
|
||||
if (!data) return
|
||||
for (const row of rows) {
|
||||
applyParsedAddressToRow(row, data)
|
||||
}
|
||||
})
|
||||
|
||||
if (!validatePreviewRowsBeforeSubmit()) return
|
||||
|
||||
@ -2149,22 +2158,15 @@ async function handleCreateOrderFromAddress() {
|
||||
const failedAddresses: string[] = []
|
||||
|
||||
try {
|
||||
for (const address of addressLines) {
|
||||
try {
|
||||
const res = await orderPendingOrderParseAddress({ address })
|
||||
const ok = res && (res.code === 1 || res.code === 200 || (res as any).flag === 'success')
|
||||
if (!ok) {
|
||||
failedAddresses.push(address)
|
||||
continue
|
||||
}
|
||||
|
||||
const data = extractPendingOrderParseAddressData(res)
|
||||
createdRows.push(createPreviewRowFromParsedAddress(data, address))
|
||||
} catch (error) {
|
||||
console.error('create order from address failed:', error)
|
||||
const parseResults = await batchParseAddresses(addressLines)
|
||||
addressLines.forEach((address, idx) => {
|
||||
const data = parseResults[idx]
|
||||
if (!data) {
|
||||
failedAddresses.push(address)
|
||||
return
|
||||
}
|
||||
}
|
||||
createdRows.push(createPreviewRowFromParsedAddress(data, address))
|
||||
})
|
||||
|
||||
if (!createdRows.length) {
|
||||
ElMessage.error('地址解析失败,未能新增明细')
|
||||
|
||||
@ -157,6 +157,13 @@
|
||||
去授权
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="!isWechatChannel" label="回调地址" prop="callbackurl">
|
||||
<el-input
|
||||
v-model="authForm.callbackurl"
|
||||
placeholder="请输入授权完成后的回调 URL"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<template v-if="isWechatChannel">
|
||||
<el-form-item label="appId" prop="appId">
|
||||
<el-input v-model="authForm.appId" placeholder="请输入视频号 appId" clearable />
|
||||
@ -165,12 +172,8 @@
|
||||
<el-input v-model="authForm.toUserName" placeholder="请输入视频号 toUserName" clearable />
|
||||
</el-form-item>
|
||||
</template>
|
||||
<el-form-item v-else-if="authNeedCallbackUrl" label="回调地址" prop="callbackurl">
|
||||
<el-input
|
||||
v-model="authForm.callbackurl"
|
||||
placeholder="请输入授权完成后的回调 URL"
|
||||
clearable
|
||||
/>
|
||||
<el-form-item v-if="isJingdong" label="VenderID" prop="venderId">
|
||||
<el-input v-model="authForm.venderId" placeholder="请输入京东商家 VenderID" clearable />
|
||||
</el-form-item>
|
||||
|
||||
</el-form>
|
||||
@ -314,10 +317,11 @@ const authForm = reactive({
|
||||
platformCode: '',
|
||||
callbackurl: '',
|
||||
appId: '',
|
||||
toUserName: ''
|
||||
toUserName: '',
|
||||
venderId: ''
|
||||
})
|
||||
|
||||
/** 视频号平台需要 appId + toUserName,callbackUrl 固定为 "-" */
|
||||
/** 视频号平台需要 appId + toUserName */
|
||||
const isWechatChannel = computed(() => {
|
||||
const code = String(authForm.platformCode || '').trim().toLowerCase()
|
||||
const name = String(authForm.platform_name || '').trim().toLowerCase()
|
||||
@ -328,34 +332,33 @@ const isWechatChannel = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
const authNeedCallbackUrl = computed(() => {
|
||||
const code = String(authForm.platformCode || '').trim()
|
||||
if (!code) return false
|
||||
// 视频号不需要显示 callbackurl
|
||||
if (isWechatChannel.value) return false
|
||||
const platform = platformOptions.value.find((item) => item.code === code)
|
||||
return isNeedCallbackUrl(platform?.need_callback_url)
|
||||
/** 京东平台需要附带 VenderID */
|
||||
const isJingdong = computed(() => {
|
||||
const code = String(authForm.platformCode || '').trim().toLowerCase()
|
||||
const name = String(authForm.platform_name || '').trim().toLowerCase()
|
||||
return code.includes('jd') || code.includes('jingdong') || name.includes('京东')
|
||||
})
|
||||
|
||||
const authRules = computed<FormRules>(() => {
|
||||
const rules: FormRules = {}
|
||||
if (!isWechatChannel.value) {
|
||||
rules.callbackurl = [
|
||||
{ required: true, message: '请输入回调地址', trigger: 'blur' },
|
||||
{ max: 500, message: '回调地址最长 500 字符', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
if (isWechatChannel.value) {
|
||||
return {
|
||||
appId: [{ required: true, message: '请输入 appId', trigger: 'blur' }],
|
||||
toUserName: [{ required: true, message: '请输入 toUserName', trigger: 'blur' }]
|
||||
}
|
||||
rules.appId = [{ required: true, message: '请输入 appId', trigger: 'blur' }]
|
||||
rules.toUserName = [{ required: true, message: '请输入 toUserName', trigger: 'blur' }]
|
||||
}
|
||||
if (!authNeedCallbackUrl.value) return {}
|
||||
return {
|
||||
callbackurl: [{ required: true, message: '请输入回调地址', trigger: 'blur' }]
|
||||
if (isJingdong.value) {
|
||||
rules.venderId = [{ required: true, message: '请输入 VenderID', trigger: 'blur' }]
|
||||
}
|
||||
return rules
|
||||
})
|
||||
|
||||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||||
|
||||
function isNeedCallbackUrl(value: unknown): boolean {
|
||||
return value === 1 || value === '1' || value === true
|
||||
}
|
||||
|
||||
function extractOauthUrl(res: any): string {
|
||||
const data = res?.data
|
||||
if (typeof data === 'string') return data
|
||||
@ -631,6 +634,7 @@ function resetAuthForm() {
|
||||
authForm.callbackurl = ''
|
||||
authForm.appId = ''
|
||||
authForm.toUserName = ''
|
||||
authForm.venderId = ''
|
||||
authFormRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
@ -641,6 +645,9 @@ function openAuthorize(row: ShopRecord) {
|
||||
authForm.platform_name = String(row.platform_name || '').trim()
|
||||
authForm.platformCode = String(row.platform_code || '').trim()
|
||||
authForm.callbackurl = ''
|
||||
authForm.appId = ''
|
||||
authForm.toUserName = ''
|
||||
authForm.venderId = ''
|
||||
authDialogVisible.value = true
|
||||
authFormRef.value?.clearValidate()
|
||||
}
|
||||
@ -689,17 +696,18 @@ async function submitConfirmAuthorize() {
|
||||
|
||||
authConfirmLoading.value = true
|
||||
try {
|
||||
const payload: { id: number; callbackurl: string; appId?: string; toUserName?: string } = {
|
||||
id: authForm.shopId,
|
||||
callbackurl: ''
|
||||
const payload: { id: number; callbackurl?: string; appId?: string; toUserName?: string; VenderID?: string } = {
|
||||
id: authForm.shopId
|
||||
}
|
||||
if (isWechatChannel.value) {
|
||||
payload.appId = authForm.appId.trim()
|
||||
payload.toUserName = authForm.toUserName.trim()
|
||||
payload.callbackurl = '-'
|
||||
} else {
|
||||
payload.callbackurl = String(authForm.callbackurl || '').trim()
|
||||
}
|
||||
if (isJingdong.value) {
|
||||
payload.VenderID = authForm.venderId.trim()
|
||||
}
|
||||
|
||||
const res: any = await shopGetAuthorizeSessionKey(payload)
|
||||
if (!isSuccess(res)) {
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="包含店铺名称" prop="shop_name">
|
||||
<el-form-item label="店铺名称" prop="shop_name">
|
||||
<div class="tag-input-wrapper">
|
||||
<div class="tag-list" v-if="formData.shopNameList.length">
|
||||
<el-tag
|
||||
@ -312,6 +312,7 @@ import { expressIndexGetExpressList } from '@/api/setting.express/express'
|
||||
import { getProhibitedType } from '@/api/stock/stock'
|
||||
import { loadStores } from '@/api/index/index'
|
||||
import { useSettingsStore } from '@/stores/modules/settings'
|
||||
import { useUserStore } from '@/stores/modules/user'
|
||||
import {
|
||||
buildPolicyListPayload,
|
||||
formatPolicyStatus,
|
||||
@ -323,6 +324,7 @@ import {
|
||||
} from './storeExpressBindingPolicy-config'
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
const userStore = useUserStore()
|
||||
const scanBox = ref<any>(null)
|
||||
const upperTable = ref<any>(null)
|
||||
|
||||
@ -591,6 +593,11 @@ async function submitForm() {
|
||||
|
||||
if (dialogMode.value === 'create') {
|
||||
const payload = buildPayload()
|
||||
// 创建人账户ID(兼容 creatorId;后端也会注入,此处显式传入保证传参完整)
|
||||
const creatorId = Number(userStore.user?.id)
|
||||
if (Number.isInteger(creatorId) && creatorId > 0) {
|
||||
payload.creator_id = creatorId
|
||||
}
|
||||
const res: any = await storeExpressBindingPolicyAdd(payload)
|
||||
if (!isSuccess(res)) {
|
||||
ElMessage.error(res?.message || '新增失败')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user