1
This commit is contained in:
parent
54e1caf8de
commit
68f7990373
551
src/api/inbox/autoReply.ts
Normal file
551
src/api/inbox/autoReply.ts
Normal file
@ -0,0 +1,551 @@
|
||||
import type { AxiosRequestConfig } from 'axios'
|
||||
import request from '@/utils/request'
|
||||
|
||||
const v = '1.0'
|
||||
|
||||
// ============================================================
|
||||
// 站内信 v2 可配置回信引擎 —— 配置管理 API(inbox.v2.*)
|
||||
//
|
||||
// 说明:
|
||||
// - 所有接口经 /system 网关,method 形如 inbox.v2.type.list;
|
||||
// - warehouseId 由服务端从登录上下文注入,前端不传;
|
||||
// - 系统预设数据(is_system=1 / warehouse_id=null)只读,写操作会被后端拒绝;
|
||||
// - 写操作后端会自动失效该仓库 v2 配置缓存(TTL 300s),无需前端额外处理。
|
||||
// ============================================================
|
||||
|
||||
/** /system 网关统一响应结构 */
|
||||
export interface InboxV2Response<T = unknown> {
|
||||
flag?: string
|
||||
code?: number
|
||||
message?: string
|
||||
data?: T
|
||||
timestamp?: number
|
||||
}
|
||||
|
||||
/** 分页信息 */
|
||||
export interface InboxV2Pagination {
|
||||
page: number
|
||||
pageSize: number
|
||||
total: number
|
||||
}
|
||||
|
||||
function call<T = unknown>(method: string, data?: Record<string, unknown>): Promise<InboxV2Response<T>> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method,
|
||||
v,
|
||||
timestamp: Date.now(),
|
||||
},
|
||||
data: data ?? {},
|
||||
// 自定义标记:request 内部据此走 /system 网关(非 axios 标准字段)
|
||||
isSystemApi: true,
|
||||
} as AxiosRequestConfig) as unknown as Promise<InboxV2Response<T>>
|
||||
}
|
||||
|
||||
/**
|
||||
* 取网关返回的业务数据(服务层返回值)。
|
||||
* 兼容 data 为空时回退到顶层(便于容错)。
|
||||
*/
|
||||
export function unwrapInboxV2Data<T>(res: InboxV2Response<T> | null | undefined): T | null {
|
||||
if (!res) return null
|
||||
if (res.data !== null && res.data !== undefined) return res.data
|
||||
return (res as unknown as T) ?? null
|
||||
}
|
||||
|
||||
// ─────────────────────────── 类型 ───────────────────────────
|
||||
|
||||
/** 售后类型(wms_after_sale_type) */
|
||||
export interface InboxV2TypeItem {
|
||||
id: number
|
||||
/** NULL=系统级(全部仓库可见且只读);非 NULL=该仓库自定义 */
|
||||
warehouse_id: number | null
|
||||
/** 类型编码(order/receiving/entry/stockout 或仓库自定义编码) */
|
||||
type: string
|
||||
name: string
|
||||
is_system: number
|
||||
is_enabled: number
|
||||
sort_order: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface InboxV2TypeListParams {
|
||||
isEnabled?: number
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface InboxV2TypeListData {
|
||||
list: InboxV2TypeItem[]
|
||||
pagination: InboxV2Pagination
|
||||
}
|
||||
|
||||
/** 类型列表(系统级 + 本仓库自定义,分页) */
|
||||
export function inboxV2TypeList(data: InboxV2TypeListParams = {}) {
|
||||
return call<InboxV2TypeListData>('inbox.v2.type.list', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2TypeCreateParams {
|
||||
/** 类型编码(≤20),仓库内唯一 */
|
||||
type: string
|
||||
/** 类型名称(≤50) */
|
||||
name: string
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 创建仓库自定义类型 */
|
||||
export function inboxV2TypeCreate(data: InboxV2TypeCreateParams) {
|
||||
return call<{ id: number; message: string }>('inbox.v2.type.create', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2TypeUpdateParams {
|
||||
id: number
|
||||
name?: string
|
||||
isEnabled?: number
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 更新仓库自定义类型(系统预设拒绝修改) */
|
||||
export function inboxV2TypeUpdate(data: InboxV2TypeUpdateParams) {
|
||||
return call<{ message: string }>('inbox.v2.type.update', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/** 删除仓库自定义类型(有子类型引用时拒绝) */
|
||||
export function inboxV2TypeDelete(id: number) {
|
||||
return call<{ message: string }>('inbox.v2.type.delete', { id })
|
||||
}
|
||||
|
||||
// ─────────────────────────── 子类型 ───────────────────────────
|
||||
|
||||
/** 售后子类型(wms_after_sale_sub_type) */
|
||||
export interface InboxV2SubTypeItem {
|
||||
id: number
|
||||
warehouse_id: number | null
|
||||
/** 所属类型编码 */
|
||||
type: string
|
||||
/** 子类型编码 */
|
||||
sub_type: string
|
||||
name: string
|
||||
is_system: number
|
||||
is_enabled: number
|
||||
sort_order: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface InboxV2SubTypeListParams {
|
||||
type?: string
|
||||
isEnabled?: number
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface InboxV2SubTypeListData {
|
||||
list: InboxV2SubTypeItem[]
|
||||
pagination: InboxV2Pagination
|
||||
}
|
||||
|
||||
/** 子类型列表(系统级 + 本仓库自定义,分页) */
|
||||
export function inboxV2SubTypeList(data: InboxV2SubTypeListParams = {}) {
|
||||
return call<InboxV2SubTypeListData>('inbox.v2.subType.list', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2SubTypeCreateParams {
|
||||
/** 所属类型编码(系统级类型或本仓库自定义类型均可) */
|
||||
type: string
|
||||
/** 子类型编码(≤50) */
|
||||
subType: string
|
||||
/** 子类型名称(≤50) */
|
||||
name: string
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 创建仓库自定义子类型 */
|
||||
export function inboxV2SubTypeCreate(data: InboxV2SubTypeCreateParams) {
|
||||
return call<{ id: number; message: string }>('inbox.v2.subType.create', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2SubTypeUpdateParams {
|
||||
id: number
|
||||
name?: string
|
||||
isEnabled?: number
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 更新仓库自定义子类型(系统预设拒绝修改) */
|
||||
export function inboxV2SubTypeUpdate(data: InboxV2SubTypeUpdateParams) {
|
||||
return call<{ message: string }>('inbox.v2.subType.update', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/** 删除仓库自定义子类型(有关联引用时拒绝) */
|
||||
export function inboxV2SubTypeDelete(id: number) {
|
||||
return call<{ message: string }>('inbox.v2.subType.delete', { id })
|
||||
}
|
||||
|
||||
// ─────────────────────────── 关键词 ───────────────────────────
|
||||
|
||||
/** 关键词(wms_after_sale_keyword) */
|
||||
export interface InboxV2KeywordItem {
|
||||
id: number
|
||||
warehouse_id: number | null
|
||||
sub_type_id: number
|
||||
keyword: string
|
||||
is_system: number
|
||||
is_enabled: number
|
||||
sort_order: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface InboxV2KeywordListParams {
|
||||
subTypeId?: number
|
||||
isEnabled?: number
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface InboxV2KeywordListData {
|
||||
list: InboxV2KeywordItem[]
|
||||
pagination: InboxV2Pagination
|
||||
}
|
||||
|
||||
/** 关键词列表 */
|
||||
export function inboxV2KeywordList(data: InboxV2KeywordListParams = {}) {
|
||||
return call<InboxV2KeywordListData>('inbox.v2.keyword.list', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2KeywordCreateParams {
|
||||
subTypeId: number
|
||||
/** 关键词(≤100),仓库内唯一 */
|
||||
keyword: string
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 创建仓库自定义关键词 */
|
||||
export function inboxV2KeywordCreate(data: InboxV2KeywordCreateParams) {
|
||||
return call<{ id: number; message: string }>('inbox.v2.keyword.create', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2KeywordUpdateParams {
|
||||
id: number
|
||||
keyword?: string
|
||||
subTypeId?: number
|
||||
isEnabled?: number
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/** 更新仓库自定义关键词(系统预设拒绝修改) */
|
||||
export function inboxV2KeywordUpdate(data: InboxV2KeywordUpdateParams) {
|
||||
return call<{ message: string }>('inbox.v2.keyword.update', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/** 删除仓库自定义关键词 */
|
||||
export function inboxV2KeywordDelete(id: number) {
|
||||
return call<{ message: string }>('inbox.v2.keyword.delete', { id })
|
||||
}
|
||||
|
||||
// ─────────────────────────── 取号规则(全局只读) ───────────────────────────
|
||||
|
||||
/** 取号规则(wms_inbox_number_rule,全局资源,仓库侧只读) */
|
||||
export interface InboxV2NumberRuleItem {
|
||||
id: number
|
||||
/** 规则名称 */
|
||||
name: string
|
||||
/** 提取目标类型:waybill_no/receiving_no/entry_order_no/stockout_no/order_no/source_order_codes/express_name/plate_no */
|
||||
target: string
|
||||
/** 取号正则(JS 正则源字符串) */
|
||||
regexp: string
|
||||
sort_order: number
|
||||
}
|
||||
|
||||
/** 取号规则列表(只读,供关联配置选择) */
|
||||
export function inboxV2NumberRuleList() {
|
||||
return call<{ list: InboxV2NumberRuleItem[] }>('inbox.v2.numberRule.list')
|
||||
}
|
||||
|
||||
// ─────────────────────────── 处理函数 ───────────────────────────
|
||||
|
||||
/** 处理函数(wms_after_sale_function,代码同步权威) */
|
||||
export interface InboxV2FunctionItem {
|
||||
id: number
|
||||
function_code: string
|
||||
name: string
|
||||
description?: string | null
|
||||
is_enabled: number
|
||||
sort_order: number
|
||||
/** 是否存在于代码注册表(false 表示已下线) */
|
||||
in_registry?: boolean | null
|
||||
}
|
||||
|
||||
export interface InboxV2FunctionListParams {
|
||||
isEnabled?: number
|
||||
keyword?: string
|
||||
}
|
||||
|
||||
/** 处理函数列表 */
|
||||
export function inboxV2FunctionList(data: InboxV2FunctionListParams = {}) {
|
||||
return call<{ list: InboxV2FunctionItem[] }>('inbox.v2.function.list', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2FunctionUpdateParams {
|
||||
id: number
|
||||
isEnabled?: number
|
||||
sortOrder?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新函数启用开关 / 排序(function_code 不可改)。
|
||||
*
|
||||
* 注意:函数是否启用**不在「自动回复设置」页面做配置**(由后台代码注册表/运维控制),
|
||||
* 本方法仅保留后端接口映射以备他用,页面侧不再调用。
|
||||
*/
|
||||
export function inboxV2FunctionUpdate(data: InboxV2FunctionUpdateParams) {
|
||||
return call<{ message: string }>('inbox.v2.function.update', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
// ─────────────────────────── 回复配置 ───────────────────────────
|
||||
|
||||
/** 回复配置(wms_after_sale_reply) */
|
||||
export interface InboxV2ReplyItem {
|
||||
id: number
|
||||
/** NULL=系统级回复(只读兜底);非 NULL=仓库级回复(整条覆盖系统级) */
|
||||
warehouse_id: number | null
|
||||
sub_type_id: number
|
||||
reply: string
|
||||
/** 1=命中后回复,0=静默(不回复消息) */
|
||||
is_reply: number
|
||||
/** 1=执行函数并登记工单(默认),0=函数照常执行但跳过工单登记 */
|
||||
create_work_order: number
|
||||
/** 未取到单据号时的引导语 */
|
||||
no_number_hint: string | null
|
||||
is_enabled: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface InboxV2ReplyListParams {
|
||||
subTypeId?: number
|
||||
isEnabled?: number
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface InboxV2ReplyListData {
|
||||
list: InboxV2ReplyItem[]
|
||||
pagination: InboxV2Pagination
|
||||
}
|
||||
|
||||
/** 合并后的生效回复配置(inbox.v2.reply.merged;仓库级整条覆盖系统级,每子类型一条) */
|
||||
export interface InboxV2MergedReplyItem {
|
||||
/** 生效行 id(自定义时为仓库级行 id,继承时为系统级行 id) */
|
||||
id: number
|
||||
sub_type_id: number
|
||||
type: string
|
||||
sub_type: string
|
||||
sub_type_name: string
|
||||
/** 自定义时为本仓库 id;继承系统级时为 null */
|
||||
warehouse_id: number | null
|
||||
/** 1=本仓库自定义,0=继承系统级 */
|
||||
is_custom: number
|
||||
reply: string
|
||||
is_reply: number
|
||||
create_work_order: number
|
||||
/** 无引导语时为空串 */
|
||||
no_number_hint: string
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export interface InboxV2ReplyMergedParams {
|
||||
/** 只看某子类型 */
|
||||
subTypeId?: number
|
||||
}
|
||||
|
||||
/** 合并后的生效配置列表(全量,无分页) */
|
||||
export interface InboxV2ReplyMergedData {
|
||||
/** 每个子类型一条生效配置 */
|
||||
merged: InboxV2MergedReplyItem[]
|
||||
total: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复配置列表(合并后的**生效配置**,推荐接口)。
|
||||
* 每个子类型只返回一条:本仓库有自定义则整条覆盖系统级,读取口径与 v2 引擎一致,前端无需自行合并。
|
||||
* 返回结构为 `{ merged, total }`,不分页。
|
||||
*/
|
||||
export function inboxV2ReplyMerged(data: InboxV2ReplyMergedParams = {}) {
|
||||
return call<InboxV2ReplyMergedData>('inbox.v2.reply.merged', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/**
|
||||
* 回复配置原始行列表(系统级 + 本仓库级,未合并)。
|
||||
* @deprecated 页面展示用 {@link inboxV2ReplyMerged}(合并后的生效配置);本接口保留供排查原始行使用。
|
||||
*/
|
||||
export function inboxV2ReplyList(data: InboxV2ReplyListParams = {}) {
|
||||
return call<InboxV2ReplyListData>('inbox.v2.reply.list', data as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存(upsert)仓库级回复配置参数 —— **按传入字段保存,未传字段保持原值**;
|
||||
* 无仓库级配置时按传入字段创建(默认 reply 空、isReply=1、createWorkOrder=1、isEnabled=1)。
|
||||
* 仓库级与系统级为整条覆盖关系,未配置或停用时回退系统级。
|
||||
* 注意:createWorkOrder=0 是「函数照常执行、仅跳过工单登记」,不是不执行函数。
|
||||
*/
|
||||
export interface InboxV2ReplySaveParams {
|
||||
subTypeId: number
|
||||
/** 回复文案,支持 {keyword}/{express}/{sub_type_name}/{back_text} 占位符(≤2000) */
|
||||
reply?: string
|
||||
/** 1 回复 0 不回复 */
|
||||
isReply?: number
|
||||
/** 1 登记工单 0 不登记工单 */
|
||||
createWorkOrder?: number
|
||||
noNumberHint?: string
|
||||
}
|
||||
|
||||
/** 保存结果 */
|
||||
export interface InboxV2ReplySaveResult {
|
||||
/** 已有仓库级行的 ID;新建时为 null */
|
||||
id: number | null
|
||||
message: string
|
||||
}
|
||||
|
||||
/** 保存仓库级回复配置(upsert,推荐接口;未传字段保持原值) */
|
||||
export function inboxV2ReplySave(data: InboxV2ReplySaveParams) {
|
||||
return call<InboxV2ReplySaveResult>('inbox.v2.reply.save', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/**
|
||||
* 还原仓库级回复配置:删除仓库级行,回退系统级配置(幂等)。
|
||||
* 无仓库级配置时同样返回成功(message 为「…已是系统级配置」)。
|
||||
*/
|
||||
export function inboxV2ReplyRestore(subTypeId: number) {
|
||||
return call<{ message: string }>('inbox.v2.reply.restore', { subTypeId })
|
||||
}
|
||||
|
||||
/** @deprecated 见 {@link InboxV2ReplySaveParams} */
|
||||
export interface InboxV2ReplyCreateParams {
|
||||
subTypeId: number
|
||||
/** 回复文案,支持 {keyword}/{express}/{sub_type_name}/{back_text} 占位符 */
|
||||
reply: string
|
||||
/** 1 回复 0 静默,默认 1 */
|
||||
isReply?: number
|
||||
/** 1 执行函数并登记工单(默认)0 函数照常执行但跳过工单登记 */
|
||||
createWorkOrder?: number
|
||||
noNumberHint?: string
|
||||
isEnabled?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建仓库级回复配置(每子类型仅一条)。
|
||||
* @deprecated 后端保留的兼容接口,页面统一改用 {@link inboxV2ReplySave}(upsert)。
|
||||
*/
|
||||
export function inboxV2ReplyCreate(data: InboxV2ReplyCreateParams) {
|
||||
return call<{ id: number; message: string }>('inbox.v2.reply.create', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
export interface InboxV2ReplyUpdateParams {
|
||||
id: number
|
||||
reply?: string
|
||||
isReply?: number
|
||||
createWorkOrder?: number
|
||||
noNumberHint?: string
|
||||
isEnabled?: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新仓库级回复配置(系统级回复只读)。
|
||||
* @deprecated 后端保留的兼容接口,页面统一改用 {@link inboxV2ReplySave}(upsert)。
|
||||
*/
|
||||
export function inboxV2ReplyUpdate(data: InboxV2ReplyUpdateParams) {
|
||||
return call<{ message: string }>('inbox.v2.reply.update', data as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除仓库级回复配置(删除后回退系统级)。
|
||||
* @deprecated 后端保留的兼容接口,页面统一改用 {@link inboxV2ReplyRestore}(幂等还原)。
|
||||
*/
|
||||
export function inboxV2ReplyDelete(id: number) {
|
||||
return call<{ message: string }>('inbox.v2.reply.delete', { id })
|
||||
}
|
||||
|
||||
// ─────────────────────────── 子类型关联关系 ───────────────────────────
|
||||
// set 语义:全量替换(items 传全量数组)
|
||||
|
||||
/** 子类型-处理函数关联行(wms_after_sale_sub_type_function) */
|
||||
export interface InboxV2SubTypeFunctionItem {
|
||||
id: number
|
||||
sub_type_id: number
|
||||
function_id: number
|
||||
sort_order: number
|
||||
}
|
||||
|
||||
/** 子类型-取号规则关联行(wms_after_sale_sub_type_rule) */
|
||||
export interface InboxV2SubTypeRuleItem {
|
||||
id: number
|
||||
sub_type_id: number
|
||||
number_rule_id: number
|
||||
sort_order: number
|
||||
}
|
||||
|
||||
/** 子类型-群白名单关联行(wms_after_sale_sub_type_group) */
|
||||
export interface InboxV2SubTypeGroupItem {
|
||||
id: number
|
||||
sub_type_id: number
|
||||
/** 群类型:store / warehouse / express */
|
||||
group_type: string
|
||||
/** 群子类型编码 */
|
||||
sub_group: string
|
||||
/** 1=系统预设关联(不可删);0=自定义 */
|
||||
is_system: number
|
||||
sort_order: number
|
||||
}
|
||||
|
||||
/** 子类型已关联的处理函数列表 */
|
||||
export function inboxV2RelationFunctionList(subTypeId: number) {
|
||||
return call<{ list: InboxV2SubTypeFunctionItem[] }>('inbox.v2.relation.function.list', { subTypeId })
|
||||
}
|
||||
|
||||
/** 全量替换子类型的处理函数关联 */
|
||||
export function inboxV2RelationFunctionSet(
|
||||
subTypeId: number,
|
||||
items: Array<{ functionId: number; sortOrder?: number }>
|
||||
) {
|
||||
return call<{ message: string }>('inbox.v2.relation.function.set', {
|
||||
subTypeId,
|
||||
items,
|
||||
} as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/** 子类型已关联的取号规则列表 */
|
||||
export function inboxV2RelationRuleList(subTypeId: number) {
|
||||
return call<{ list: InboxV2SubTypeRuleItem[] }>('inbox.v2.relation.rule.list', { subTypeId })
|
||||
}
|
||||
|
||||
/** 全量替换子类型的取号规则关联 */
|
||||
export function inboxV2RelationRuleSet(
|
||||
subTypeId: number,
|
||||
items: Array<{ ruleId: number; sortOrder?: number }>
|
||||
) {
|
||||
return call<{ message: string }>('inbox.v2.relation.rule.set', {
|
||||
subTypeId,
|
||||
items,
|
||||
} as unknown as Record<string, unknown>)
|
||||
}
|
||||
|
||||
/** 子类型已关联的群白名单列表 */
|
||||
export function inboxV2RelationGroupList(subTypeId: number) {
|
||||
return call<{ list: InboxV2SubTypeGroupItem[] }>('inbox.v2.relation.group.list', { subTypeId })
|
||||
}
|
||||
|
||||
/** 替换子类型的群白名单(系统预设行后端自动保留) */
|
||||
export function inboxV2RelationGroupSet(
|
||||
subTypeId: number,
|
||||
items: Array<{ groupType: string; subGroup: string; sortOrder?: number }>
|
||||
) {
|
||||
return call<{ message: string }>('inbox.v2.relation.group.set', {
|
||||
subTypeId,
|
||||
items,
|
||||
} as unknown as Record<string, unknown>)
|
||||
}
|
||||
@ -196,8 +196,9 @@ export interface InboxGroupUpdateParams {
|
||||
subType?: string // 群子类型,值取决于groupType。store→after_sales/finance/receiving。warehouse→receiving/production/stockout/finance/all/customer_service/exception。express→pickup/after_sales
|
||||
storeId?: number // 关联货主ID
|
||||
expressInterfaces?: number[] // 快递接口ID数组,仅groupType=express时生效
|
||||
systemExpressCode?: string // 系统快递编码,groupType=express时必填
|
||||
aiEnabled?: number // 是否启用AI自动回复: 0=关闭 1=开启,默认1
|
||||
systemExpressCode?: string // 系统快递编码,groupType=express时必填。需校验wms_express.code存在
|
||||
aiEnabled?: number // 是否启用AI自动回复: 0=关闭 1=开启,默认1(所有群类型均支持,用于灰度测试)
|
||||
templateReplyEnabled?: number // 是否启用模板消息回复: 0=关闭(普通文本回复) 1=开启(模板消息回复),默认0(所有群类型均支持,独立于aiEnabled)
|
||||
}
|
||||
|
||||
/** 修改群信息(inbox.group.update) */
|
||||
|
||||
@ -152,6 +152,16 @@ export const constantRoutes: RouteRecordRaw[] = [
|
||||
icon: 'connection',
|
||||
affix: false
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'autoReply',
|
||||
name: 'InboxAutoReply',
|
||||
component: () => import('@/views/inbox/autoReply/index.vue'),
|
||||
meta: {
|
||||
title: '自动回复设置',
|
||||
icon: 'chat-dot-round',
|
||||
affix: false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@ -77,6 +77,8 @@ export const componentMap: Record<string, any> = {
|
||||
'system/setting/storeExpressBindingPolicy/index':() => import('@/views/system/setting/storeExpressBindingPolicy/index.vue'),
|
||||
'inbox/message/index': () => import('@/views/inbox/message/index.vue'),
|
||||
'inbox/group/index': () => import('@/views/inbox/group/index.vue'),
|
||||
'inbox/autoReply/index': () => import('@/views/inbox/autoReply/index.vue'),
|
||||
'inbox/autoReply': () => import('@/views/inbox/autoReply/index.vue'),
|
||||
'express/returnUnpack/index': () => import('@/views/express/returnUnpack/index.vue'),
|
||||
'express/returnwaybill/index': () => import('@/views/express/returnwaybill/index.vue'),
|
||||
'express/returnUnpackwork/index': () => import('@/views/express/returnUnpackwork/index.vue'),
|
||||
|
||||
210
src/views/inbox/autoReply/autoReply-config.ts
Normal file
210
src/views/inbox/autoReply/autoReply-config.ts
Normal file
@ -0,0 +1,210 @@
|
||||
import type {
|
||||
InboxV2SubTypeGroupItem,
|
||||
InboxV2SubTypeItem,
|
||||
InboxV2TypeItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
|
||||
// ============================================================
|
||||
// 自动回复设置 - 常量与选项
|
||||
// ============================================================
|
||||
|
||||
/** 群类型选项(对应 wms_inbox_group.group_type) */
|
||||
export const groupTypeOptions = [
|
||||
{ label: '货主群', value: 'store' },
|
||||
{ label: '仓库群', value: 'warehouse' },
|
||||
{ label: '快递群', value: 'express' },
|
||||
]
|
||||
|
||||
/** 群子类型选项(对应 wms_inbox_group.sub_type,受群类型约束) */
|
||||
export const subGroupOptionsMap: Record<string, Array<{ label: string; value: string }>> = {
|
||||
store: [
|
||||
{ label: '售后', value: 'after_sales' },
|
||||
{ label: '财务', value: 'finance' },
|
||||
{ label: '收货', value: 'receiving' },
|
||||
],
|
||||
warehouse: [
|
||||
{ label: '收货', value: 'receiving' },
|
||||
{ label: '生产', value: 'production' },
|
||||
{ label: '出库', value: 'stockout' },
|
||||
{ label: '财务', value: 'finance' },
|
||||
{ label: '全体', value: 'all' },
|
||||
{ label: '客服', value: 'customer_service' },
|
||||
{ label: '异常', value: 'exception' },
|
||||
],
|
||||
express: [
|
||||
{ label: '揽收', value: 'pickup' },
|
||||
{ label: '售后', value: 'after_sales' },
|
||||
],
|
||||
}
|
||||
|
||||
/** 群类型通配:全部群(对应 group_type='*') */
|
||||
export const wildcardGroupTypeOption = { label: '全部', value: '*' }
|
||||
|
||||
/** 群子类型通配:该群类型下所有子类型(对应 sub_group='*') */
|
||||
export const wildcardSubGroupOption = { label: '全部', value: '*' }
|
||||
|
||||
/** 群类型选项(含通配「全部」,置顶) */
|
||||
export function getGroupTypeOptions() {
|
||||
return [ wildcardGroupTypeOption, ...groupTypeOptions ]
|
||||
}
|
||||
|
||||
/** 群子类型选项(含通配「全部」,置顶) */
|
||||
export function getSubGroupOptions(groupType: string) {
|
||||
return [ wildcardSubGroupOption, ...(subGroupOptionsMap[groupType] ?? []) ]
|
||||
}
|
||||
|
||||
export function groupTypeLabel(groupType: string): string {
|
||||
if (!groupType) return '-'
|
||||
if (groupType === '*') return wildcardGroupTypeOption.label
|
||||
return groupTypeOptions.find((item) => item.value === groupType)?.label ?? groupType
|
||||
}
|
||||
|
||||
export function subGroupLabel(groupType: string, subGroup: string): string {
|
||||
if (!subGroup) return '-'
|
||||
if (subGroup === '*') return wildcardSubGroupOption.label
|
||||
const hit = getSubGroupOptions(groupType).find((item) => item.value === subGroup)
|
||||
return hit?.label ?? subGroup
|
||||
}
|
||||
|
||||
/** 取号目标类型中文标签(对应 wms_inbox_number_rule.target) */
|
||||
export const numberRuleTargetLabels: Record<string, string> = {
|
||||
waybill_no: '运单号',
|
||||
receiving_no: '收货单号',
|
||||
entry_order_no: '入库单号',
|
||||
stockout_no: '出库单号',
|
||||
order_no: '订单编号',
|
||||
source_order_codes: '平台订单号',
|
||||
express_name: '快递名称',
|
||||
plate_no: '车牌号',
|
||||
}
|
||||
|
||||
export function numberRuleTargetLabel(target: string): string {
|
||||
return numberRuleTargetLabels[target] ?? target ?? '-'
|
||||
}
|
||||
|
||||
/** 回复文案支持的占位符(后端 rules 引擎替换;back_text 来自函数返回 data.back_text) */
|
||||
export const replyPlaceholders = ['{keyword}', '{express}', '{sub_type_name}', '{back_text}']
|
||||
|
||||
/**
|
||||
* 判断记录是否为系统预设(只读)。
|
||||
* 系统级:warehouse_id 为 null,或 is_system=1。
|
||||
* 注意:关键词与回复属仓库级数据,可挂在系统级子类型下(后端只对子类型做存在性校验);
|
||||
* 处理函数/取号规则/群白名单的关联写操作仍要求本仓库自定义子类型。
|
||||
*/
|
||||
export function isSystemRecord(row: {
|
||||
warehouse_id?: number | null
|
||||
is_system?: number | null
|
||||
}): boolean {
|
||||
if (Number(row?.is_system) === 1) return true
|
||||
const wid = row?.warehouse_id
|
||||
return wid === null || wid === undefined
|
||||
}
|
||||
|
||||
/** 系统预设标记文案 */
|
||||
export const systemTagText = '系统预设'
|
||||
|
||||
// ============================================================
|
||||
// 表格列配置
|
||||
// ============================================================
|
||||
|
||||
export interface AutoReplyColumn {
|
||||
prop: string
|
||||
label: string
|
||||
width?: string
|
||||
minWidth?: string
|
||||
align?: 'left' | 'center' | 'right'
|
||||
showOverflowTooltip?: boolean
|
||||
}
|
||||
|
||||
/** 类型列表列 */
|
||||
export const typeColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'type', label: '类型编码', minWidth: '120', showOverflowTooltip: true },
|
||||
{ prop: 'name', label: '类型名称', minWidth: '120', showOverflowTooltip: true },
|
||||
{ prop: 'source', label: '来源', width: '90', align: 'center' },
|
||||
{ prop: 'is_enabled', label: '状态', width: '80', align: 'center' },
|
||||
{ prop: 'sort_order', label: '排序', width: '70', align: 'center' },
|
||||
]
|
||||
|
||||
/** 子类型列表列 */
|
||||
export const subTypeColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'sub_type', label: '子类型编码', minWidth: '130', showOverflowTooltip: true },
|
||||
{ prop: 'name', label: '子类型名称', minWidth: '120', showOverflowTooltip: true },
|
||||
{ prop: 'source', label: '来源', width: '90', align: 'center' },
|
||||
{ prop: 'is_enabled', label: '状态', width: '80', align: 'center' },
|
||||
{ prop: 'sort_order', label: '排序', width: '70', align: 'center' },
|
||||
]
|
||||
|
||||
/** 关键词列表列 */
|
||||
export const keywordColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'keyword', label: '关键词', minWidth: '180', showOverflowTooltip: true },
|
||||
{ prop: 'source', label: '来源', width: '90', align: 'center' },
|
||||
{ prop: 'is_enabled', label: '启用', width: '80', align: 'center' },
|
||||
{ prop: 'sort_order', label: '匹配优先级', width: '100', align: 'center' },
|
||||
{ prop: 'actions', label: '操作', width: '130', align: 'center' },
|
||||
]
|
||||
|
||||
/** 处理函数关联列 */
|
||||
export const functionColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'sort_order', label: '顺序', width: '70', align: 'center' },
|
||||
{ prop: 'name', label: '函数名称', minWidth: '150', showOverflowTooltip: true },
|
||||
{ prop: 'function_code', label: '函数编码', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'status', label: '状态', width: '160', align: 'center' },
|
||||
{ prop: 'actions', label: '操作', width: '130', align: 'center' },
|
||||
]
|
||||
|
||||
/** 取号规则关联列 */
|
||||
export const numberRuleColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'sort_order', label: '顺序', width: '70', align: 'center' },
|
||||
{ prop: 'name', label: '规则名称', minWidth: '150', showOverflowTooltip: true },
|
||||
{ prop: 'target_label', label: '提取目标', width: '110', align: 'center' },
|
||||
{ prop: 'regexp', label: '取号正则', minWidth: '200', showOverflowTooltip: true },
|
||||
{ prop: 'actions', label: '操作', width: '130', align: 'center' },
|
||||
]
|
||||
|
||||
/** 群白名单列 */
|
||||
export const groupColumns: AutoReplyColumn[] = [
|
||||
{ prop: 'group_type_label', label: '群类型', width: '110', align: 'center' },
|
||||
{ prop: 'sub_group_label', label: '群子类型', width: '130', align: 'center' },
|
||||
{ prop: 'source', label: '来源', width: '90', align: 'center' },
|
||||
{ prop: 'sort_order', label: '排序', width: '80', align: 'center' },
|
||||
{ prop: 'actions', label: '操作', width: '90', align: 'center' },
|
||||
]
|
||||
|
||||
// ============================================================
|
||||
// 类型 / 子类型 / 关键词 / 回复 归一化辅助
|
||||
// ============================================================
|
||||
|
||||
/** 归一化布尔/数字开关 */
|
||||
export function toFlag(value: unknown, fallback = 0): number {
|
||||
if (value === undefined || value === null || value === '') return fallback
|
||||
return Number(value) === 1 || value === true || value === 'true' ? 1 : 0
|
||||
}
|
||||
|
||||
export type AutoReplyTreeNode = {
|
||||
key: string
|
||||
kind: 'type' | 'subType'
|
||||
label: string
|
||||
/** 所属类型编码 */
|
||||
typeCode: string
|
||||
subTypeId?: number
|
||||
isSystem: boolean
|
||||
isEnabled: boolean
|
||||
typeRaw?: InboxV2TypeItem
|
||||
subTypeRaw?: InboxV2SubTypeItem
|
||||
children?: AutoReplyTreeNode[]
|
||||
}
|
||||
|
||||
/** 类型节点 key */
|
||||
export function typeNodeKey(typeCode: string) {
|
||||
return `type:${typeCode}`
|
||||
}
|
||||
|
||||
/** 子类型节点 key */
|
||||
export function subTypeNodeKey(subTypeId: number) {
|
||||
return `subType:${subTypeId}`
|
||||
}
|
||||
|
||||
/** 群白名单行是否可删(系统预设关联不可删) */
|
||||
export function isGroupRelationRemovable(row: InboxV2SubTypeGroupItem): boolean {
|
||||
return Number(row?.is_system) !== 1
|
||||
}
|
||||
295
src/views/inbox/autoReply/components/FunctionPanel.vue
Normal file
295
src/views/inbox/autoReply/components/FunctionPanel.vue
Normal file
@ -0,0 +1,295 @@
|
||||
<template>
|
||||
<div class="ar-panel">
|
||||
<div class="ar-panel-toolbar">
|
||||
<div class="ar-panel-toolbar-left">
|
||||
<span class="ar-panel-tip">
|
||||
按顺序执行关联函数,可用性由代码注册表决定
|
||||
</span>
|
||||
</div>
|
||||
<div class="ar-panel-toolbar-right">
|
||||
<el-select
|
||||
v-model="pendingFunctionId"
|
||||
placeholder="选择函数加入关联"
|
||||
filterable
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 220px"
|
||||
:loading="libraryLoading"
|
||||
:disabled="!writable"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in addableFunctions"
|
||||
:key="item.id"
|
||||
:label="`${item.name}(${item.function_code})`"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-button size="small" type="primary" :disabled="!writable || !pendingFunctionId" @click="handleAddRow">
|
||||
添加
|
||||
</el-button>
|
||||
<el-button size="small" :loading="loading" @click="handleRefresh">刷新</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
:loading="saving"
|
||||
:disabled="!writable || !dirty"
|
||||
@click="handleSave"
|
||||
>
|
||||
保存关联
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ar-panel-table">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
empty-text="暂未关联处理函数"
|
||||
>
|
||||
<el-table-column
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
:min-width="col.minWidth"
|
||||
:align="col.align ?? 'left'"
|
||||
:show-overflow-tooltip="col.showOverflowTooltip"
|
||||
>
|
||||
<template #default="{ row, $index }">
|
||||
<template v-if="col.prop === 'status'">
|
||||
<el-tag v-if="row.in_registry === null || row.in_registry === undefined" size="small" type="info">
|
||||
未知
|
||||
</el-tag>
|
||||
<el-tag v-else size="small" :type="row.in_registry ? 'success' : 'danger'">
|
||||
{{ row.in_registry ? '可用' : '代码已下线' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'sort_order'">
|
||||
{{ $index + 1 }}
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'actions'">
|
||||
<el-button size="small" type="primary" link :disabled="!writable || $index === 0" @click="moveRow($index, -1)">
|
||||
上移
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
:disabled="!writable || $index === rows.length - 1"
|
||||
@click="moveRow($index, 1)"
|
||||
>
|
||||
下移
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" link :disabled="!writable" @click="removeRow($index)">
|
||||
移除
|
||||
</el-button>
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'name'">
|
||||
{{ row.function_name || row.function_code || '-' }}
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ row[col.prop] ?? '-' }}
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
inboxV2FunctionList,
|
||||
inboxV2RelationFunctionList,
|
||||
inboxV2RelationFunctionSet,
|
||||
unwrapInboxV2Data,
|
||||
type InboxV2FunctionItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import { functionColumns } from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
subTypeId: number
|
||||
writable: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 未保存改动状态变化,供父级切换节点前拦截 */
|
||||
'dirty-change': [value: boolean]
|
||||
}>()
|
||||
|
||||
type RelationRow = {
|
||||
function_id: number
|
||||
function_name: string
|
||||
function_code: string
|
||||
/** 代码注册表是否存在该函数(可用性以此为准,只读展示) */
|
||||
in_registry: boolean | null
|
||||
}
|
||||
|
||||
const columns = functionColumns
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const dirty = ref(false)
|
||||
const rows = ref<RelationRow[]>([])
|
||||
const pendingFunctionId = ref<number | null>(null)
|
||||
|
||||
const functionLibrary = ref<InboxV2FunctionItem[]>([])
|
||||
const libraryLoading = ref(false)
|
||||
|
||||
const functionMap = computed(() => {
|
||||
const map = new Map<number, InboxV2FunctionItem>()
|
||||
for (const item of functionLibrary.value) map.set(item.id, item)
|
||||
return map
|
||||
})
|
||||
|
||||
const addableFunctions = computed(() => {
|
||||
const used = new Set(rows.value.map((row) => row.function_id))
|
||||
return functionLibrary.value.filter((item) => !used.has(item.id))
|
||||
})
|
||||
|
||||
function buildRelationRows(
|
||||
relations: Array<{ function_id: number; sort_order: number }>
|
||||
): RelationRow[] {
|
||||
return [...relations]
|
||||
.sort((a, b) => (Number(a.sort_order) || 0) - (Number(b.sort_order) || 0))
|
||||
.map((relation) => {
|
||||
const fn = functionMap.value.get(Number(relation.function_id))
|
||||
return {
|
||||
function_id: Number(relation.function_id),
|
||||
function_name: fn?.name ?? '',
|
||||
function_code: fn?.function_code ?? '',
|
||||
in_registry: fn ? fn.in_registry ?? null : false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function loadFunctions() {
|
||||
libraryLoading.value = true
|
||||
try {
|
||||
const res = await inboxV2FunctionList()
|
||||
const data = unwrapInboxV2Data(res)
|
||||
functionLibrary.value = data?.list ?? []
|
||||
} catch (error) {
|
||||
console.error('加载处理函数列表失败:', error)
|
||||
functionLibrary.value = []
|
||||
} finally {
|
||||
libraryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadRelations() {
|
||||
if (!props.subTypeId) {
|
||||
rows.value = []
|
||||
return
|
||||
}
|
||||
const res = await inboxV2RelationFunctionList(props.subTypeId)
|
||||
const data = unwrapInboxV2Data(res)
|
||||
rows.value = buildRelationRows(data?.list ?? [])
|
||||
dirty.value = false
|
||||
}
|
||||
|
||||
/** 刷新前若有未保存改动先确认 */
|
||||
async function handleRefresh() {
|
||||
if (dirty.value) {
|
||||
try {
|
||||
await ElMessageBox.confirm('当前有未保存的关联修改,刷新后将被丢弃,是否继续?', '未保存修改', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '放弃修改并继续',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
await loadAll()
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
try {
|
||||
if (!functionLibrary.value.length) {
|
||||
await loadFunctions()
|
||||
}
|
||||
await loadRelations()
|
||||
} catch (error) {
|
||||
console.error('加载函数关联失败:', error)
|
||||
rows.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddRow() {
|
||||
const id = Number(pendingFunctionId.value)
|
||||
if (!id) return
|
||||
const fn = functionMap.value.get(id)
|
||||
if (!fn) {
|
||||
ElMessage.warning('函数不存在或已下线')
|
||||
return
|
||||
}
|
||||
rows.value.push({
|
||||
function_id: id,
|
||||
function_name: fn.name,
|
||||
function_code: fn.function_code,
|
||||
in_registry: fn.in_registry ?? null,
|
||||
})
|
||||
pendingFunctionId.value = null
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
function removeRow(index: number) {
|
||||
rows.value.splice(index, 1)
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
function moveRow(index: number, offset: number) {
|
||||
const target = index + offset
|
||||
if (target < 0 || target >= rows.value.length) return
|
||||
const item = rows.value.splice(index, 1)[0]
|
||||
if (!item) return
|
||||
rows.value.splice(target, 0, item)
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!props.subTypeId) return
|
||||
saving.value = true
|
||||
try {
|
||||
await inboxV2RelationFunctionSet(
|
||||
props.subTypeId,
|
||||
rows.value.map((row, index) => ({ functionId: row.function_id, sortOrder: index }))
|
||||
)
|
||||
dirty.value = false
|
||||
ElMessage.success('处理函数关联已保存')
|
||||
await loadRelations()
|
||||
} catch (error) {
|
||||
console.error('保存函数关联失败:', error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 未保存改动上报(父级切换节点前拦截)
|
||||
watch(dirty, (value) => emit('dirty-change', value))
|
||||
|
||||
watch(
|
||||
() => props.subTypeId,
|
||||
() => {
|
||||
pendingFunctionId.value = null
|
||||
dirty.value = false
|
||||
void loadAll()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "./panel.scss";
|
||||
</style>
|
||||
273
src/views/inbox/autoReply/components/GroupPanel.vue
Normal file
273
src/views/inbox/autoReply/components/GroupPanel.vue
Normal file
@ -0,0 +1,273 @@
|
||||
<template>
|
||||
<div class="ar-panel">
|
||||
<div class="ar-panel-toolbar">
|
||||
<div class="ar-panel-toolbar-left">
|
||||
<span class="ar-panel-tip">
|
||||
命中白名单的群才走该子类型链路;子类型选「全部子类型」即通配该群类型下所有子类型,系统预设行不可删
|
||||
</span>
|
||||
</div>
|
||||
<div class="ar-panel-toolbar-right">
|
||||
<el-select
|
||||
v-model="pendingGroupType"
|
||||
placeholder="群类型"
|
||||
size="small"
|
||||
style="width: 120px"
|
||||
:disabled="!writable"
|
||||
@change="pendingSubGroup = ''"
|
||||
>
|
||||
<el-option v-for="item in groupTypeSelectOptions" :key="item.value" :label="item.label" :value="item.value" />
|
||||
</el-select>
|
||||
<el-select
|
||||
v-model="pendingSubGroup"
|
||||
placeholder="群子类型"
|
||||
size="small"
|
||||
style="width: 140px"
|
||||
:disabled="!writable || !pendingGroupType"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in pendingSubGroupOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
:disabled="!writable || !pendingGroupType || !pendingSubGroup"
|
||||
@click="handleAddRow"
|
||||
>
|
||||
添加
|
||||
</el-button>
|
||||
<el-button size="small" :loading="loading" @click="handleRefresh">刷新</el-button>
|
||||
<el-button size="small" type="primary" :loading="saving" :disabled="!writable || !dirty" @click="handleSave">
|
||||
保存白名单
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ar-panel-table">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
empty-text="暂未配置群白名单"
|
||||
>
|
||||
<el-table-column
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
:min-width="col.minWidth"
|
||||
:align="col.align ?? 'left'"
|
||||
:show-overflow-tooltip="col.showOverflowTooltip"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<template v-if="col.prop === 'source'">
|
||||
<el-tag size="small" :type="Number(row.is_system) === 1 ? 'info' : 'success'">
|
||||
{{ Number(row.is_system) === 1 ? systemTagText : '自定义' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'actions'">
|
||||
<el-tooltip
|
||||
:disabled="isGroupRelationRemovable(row)"
|
||||
content="系统预设关联不可删除"
|
||||
placement="top"
|
||||
>
|
||||
<span>
|
||||
<el-button
|
||||
size="small"
|
||||
type="danger"
|
||||
link
|
||||
:disabled="!writable || !isGroupRelationRemovable(row)"
|
||||
@click="removeRow(row)"
|
||||
>
|
||||
移除
|
||||
</el-button>
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ row[col.prop] ?? '-' }}
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
inboxV2RelationGroupList,
|
||||
inboxV2RelationGroupSet,
|
||||
unwrapInboxV2Data,
|
||||
type InboxV2SubTypeGroupItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import {
|
||||
getGroupTypeOptions,
|
||||
getSubGroupOptions,
|
||||
groupColumns,
|
||||
groupTypeLabel,
|
||||
isGroupRelationRemovable,
|
||||
subGroupLabel,
|
||||
systemTagText,
|
||||
} from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
subTypeId: number
|
||||
writable: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 未保存改动状态变化,供父级切换节点前拦截 */
|
||||
'dirty-change': [value: boolean]
|
||||
}>()
|
||||
|
||||
type GroupRow = {
|
||||
uid: string
|
||||
group_type: string
|
||||
sub_group: string
|
||||
group_type_label: string
|
||||
sub_group_label: string
|
||||
is_system: number
|
||||
sort_order: number
|
||||
}
|
||||
|
||||
const columns = groupColumns
|
||||
|
||||
/** 群类型选项:「全部」置顶 */
|
||||
const groupTypeSelectOptions = getGroupTypeOptions()
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const dirty = ref(false)
|
||||
const rows = ref<GroupRow[]>([])
|
||||
const pendingGroupType = ref('')
|
||||
const pendingSubGroup = ref('')
|
||||
|
||||
const pendingSubGroupOptions = computed(() => getSubGroupOptions(pendingGroupType.value))
|
||||
|
||||
function toRow(row: InboxV2SubTypeGroupItem): GroupRow {
|
||||
return {
|
||||
uid: `${row.group_type}:${row.sub_group}`,
|
||||
group_type: row.group_type,
|
||||
sub_group: row.sub_group,
|
||||
group_type_label: groupTypeLabel(row.group_type),
|
||||
sub_group_label: subGroupLabel(row.group_type, row.sub_group),
|
||||
is_system: Number(row.is_system) === 1 ? 1 : 0,
|
||||
sort_order: Number(row.sort_order) || 0,
|
||||
}
|
||||
}
|
||||
|
||||
/** 刷新前若有未保存改动先确认 */
|
||||
async function handleRefresh() {
|
||||
if (dirty.value) {
|
||||
try {
|
||||
await ElMessageBox.confirm('当前有未保存的白名单修改,刷新后将被丢弃,是否继续?', '未保存修改', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '放弃修改并继续',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
await loadRelations()
|
||||
}
|
||||
|
||||
async function loadRelations() {
|
||||
if (!props.subTypeId) {
|
||||
rows.value = []
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await inboxV2RelationGroupList(props.subTypeId)
|
||||
const data = unwrapInboxV2Data(res)
|
||||
rows.value = (data?.list ?? []).map(toRow)
|
||||
dirty.value = false
|
||||
} catch (error) {
|
||||
console.error('加载群白名单失败:', error)
|
||||
rows.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddRow() {
|
||||
const groupType = pendingGroupType.value
|
||||
const subGroup = pendingSubGroup.value
|
||||
if (!groupType || !subGroup) return
|
||||
const uid = `${groupType}:${subGroup}`
|
||||
if (rows.value.some((row) => row.uid === uid)) {
|
||||
ElMessage.warning('该群类型/群子类型已在白名单中')
|
||||
return
|
||||
}
|
||||
rows.value.push({
|
||||
uid,
|
||||
group_type: groupType,
|
||||
sub_group: subGroup,
|
||||
group_type_label: groupTypeLabel(groupType),
|
||||
sub_group_label: subGroupLabel(groupType, subGroup),
|
||||
is_system: 0,
|
||||
sort_order: rows.value.length,
|
||||
})
|
||||
pendingSubGroup.value = ''
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
function removeRow(row: GroupRow) {
|
||||
const index = rows.value.findIndex((item) => item.uid === row.uid)
|
||||
if (index < 0) return
|
||||
rows.value.splice(index, 1)
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!props.subTypeId) return
|
||||
saving.value = true
|
||||
try {
|
||||
// 系统预设行由后端自动保留,前端只提交自定义行
|
||||
const items = rows.value
|
||||
.filter((row) => Number(row.is_system) !== 1)
|
||||
.map((row, index) => ({
|
||||
groupType: row.group_type,
|
||||
subGroup: row.sub_group,
|
||||
sortOrder: index,
|
||||
}))
|
||||
await inboxV2RelationGroupSet(props.subTypeId, items)
|
||||
dirty.value = false
|
||||
ElMessage.success('群白名单已保存')
|
||||
await loadRelations()
|
||||
} catch (error) {
|
||||
console.error('保存群白名单失败:', error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 未保存改动上报(父级切换节点前拦截)
|
||||
watch(dirty, (value) => emit('dirty-change', value))
|
||||
|
||||
watch(
|
||||
() => props.subTypeId,
|
||||
() => {
|
||||
pendingGroupType.value = ''
|
||||
pendingSubGroup.value = ''
|
||||
dirty.value = false
|
||||
void loadRelations()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "./panel.scss";
|
||||
</style>
|
||||
310
src/views/inbox/autoReply/components/KeywordPanel.vue
Normal file
310
src/views/inbox/autoReply/components/KeywordPanel.vue
Normal file
@ -0,0 +1,310 @@
|
||||
<template>
|
||||
<div class="ar-panel">
|
||||
<div class="ar-panel-toolbar">
|
||||
<div class="ar-panel-toolbar-left">
|
||||
<span class="ar-panel-tip">
|
||||
关键词命中即进入该子类型,系统预设关键词只读
|
||||
</span>
|
||||
</div>
|
||||
<div class="ar-panel-toolbar-right">
|
||||
<el-button size="small" :loading="loading" @click="loadList">刷新</el-button>
|
||||
<el-button size="small" type="primary" @click="openCreate">新增关键词</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ar-panel-table">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="list"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
row-key="id"
|
||||
empty-text="暂无关键词"
|
||||
>
|
||||
<el-table-column
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
:min-width="col.minWidth"
|
||||
:align="col.align ?? 'left'"
|
||||
:show-overflow-tooltip="col.showOverflowTooltip"
|
||||
>
|
||||
<template #default="{ row }">
|
||||
<template v-if="col.prop === 'source'">
|
||||
<el-tag size="small" :type="isSystemRecord(row) ? 'info' : 'success'">
|
||||
{{ isSystemRecord(row) ? systemTagText : '自定义' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'is_enabled'">
|
||||
<el-switch
|
||||
:model-value="toFlag(row.is_enabled)"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
:disabled="isSystemRecord(row) || togglingId === row.id"
|
||||
@change="(val: number) => handleToggleEnabled(row, val)"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'actions'">
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
:disabled="isSystemRecord(row)"
|
||||
@click="openEdit(row)"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="danger"
|
||||
link
|
||||
:disabled="isSystemRecord(row)"
|
||||
@click="handleDelete(row)"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ row[col.prop] ?? '-' }}
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<div class="ar-panel-pagination">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:total="pagination.total"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:disabled="loading"
|
||||
background
|
||||
small
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@current-change="loadList"
|
||||
@size-change="handlePageSizeChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="editingId ? '编辑关键词' : '新增关键词'"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px" size="small">
|
||||
<el-form-item label="关键词" prop="keyword">
|
||||
<el-input v-model="form.keyword" placeholder="请输入关键词(≤100 字符)" maxlength="100" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="editingId" label="启用状态">
|
||||
<el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
|
||||
</el-form-item>
|
||||
<el-form-item label="匹配优先级">
|
||||
<el-input-number v-model="form.sortOrder" :min="0" :max="9999" controls-position="right" />
|
||||
<span class="ar-form-tip">数值越小越优先</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button size="small" :disabled="submitting" @click="dialogVisible = false">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
inboxV2KeywordCreate,
|
||||
inboxV2KeywordDelete,
|
||||
inboxV2KeywordList,
|
||||
inboxV2KeywordUpdate,
|
||||
unwrapInboxV2Data,
|
||||
type InboxV2KeywordItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import {
|
||||
isSystemRecord,
|
||||
keywordColumns,
|
||||
systemTagText,
|
||||
toFlag,
|
||||
} from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
subTypeId: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 未保存改动状态变化(表单弹窗未提交),供父级切换节点前拦截 */
|
||||
'dirty-change': [value: boolean]
|
||||
}>()
|
||||
|
||||
const columns = keywordColumns
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const togglingId = ref<number | null>(null)
|
||||
const list = ref<InboxV2KeywordItem[]>([])
|
||||
const pagination = reactive({ page: 1, pageSize: 20, total: 0 })
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editingId = ref<number | null>(null)
|
||||
const formRef = ref<FormInstance | null>(null)
|
||||
const form = reactive({
|
||||
keyword: '',
|
||||
isEnabled: 1,
|
||||
sortOrder: 0,
|
||||
})
|
||||
|
||||
/** 弹窗打开即视为有未提交输入 */
|
||||
const dialogDirty = computed(() => dialogVisible.value)
|
||||
|
||||
watch(dialogDirty, (value) => emit('dirty-change', value))
|
||||
|
||||
const rules: FormRules = {
|
||||
keyword: [
|
||||
{ required: true, message: '请输入关键词', trigger: 'blur' },
|
||||
{ max: 100, message: '关键词不超过 100 字符', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
if (!props.subTypeId) {
|
||||
list.value = []
|
||||
pagination.total = 0
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await inboxV2KeywordList({
|
||||
subTypeId: props.subTypeId,
|
||||
page: pagination.page,
|
||||
pageSize: pagination.pageSize,
|
||||
})
|
||||
const data = unwrapInboxV2Data(res)
|
||||
list.value = data?.list ?? []
|
||||
pagination.page = data?.pagination?.page ?? pagination.page
|
||||
pagination.pageSize = data?.pagination?.pageSize ?? pagination.pageSize
|
||||
pagination.total = data?.pagination?.total ?? list.value.length
|
||||
} catch (error) {
|
||||
console.error('加载关键词列表失败:', error)
|
||||
list.value = []
|
||||
pagination.total = 0
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handlePageSizeChange() {
|
||||
pagination.page = 1
|
||||
void loadList()
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
editingId.value = null
|
||||
form.keyword = ''
|
||||
form.isEnabled = 1
|
||||
form.sortOrder = 0
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
resetForm()
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function openEdit(row: InboxV2KeywordItem) {
|
||||
resetForm()
|
||||
editingId.value = row.id
|
||||
form.keyword = row.keyword ?? ''
|
||||
form.isEnabled = toFlag(row.is_enabled, 1)
|
||||
form.sortOrder = Number(row.sort_order) || 0
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
if (editingId.value) {
|
||||
await inboxV2KeywordUpdate({
|
||||
id: editingId.value,
|
||||
keyword: form.keyword.trim(),
|
||||
isEnabled: form.isEnabled,
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('关键词已更新')
|
||||
} else {
|
||||
await inboxV2KeywordCreate({
|
||||
subTypeId: props.subTypeId,
|
||||
keyword: form.keyword.trim(),
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('关键词已创建')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await loadList()
|
||||
} catch (error) {
|
||||
console.error('保存关键词失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleToggleEnabled(row: InboxV2KeywordItem, value: number) {
|
||||
togglingId.value = row.id
|
||||
try {
|
||||
await inboxV2KeywordUpdate({ id: row.id, isEnabled: value })
|
||||
row.is_enabled = value
|
||||
ElMessage.success(value === 1 ? '已启用' : '已停用')
|
||||
} catch (error) {
|
||||
console.error('切换关键词状态失败:', error)
|
||||
} finally {
|
||||
togglingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete(row: InboxV2KeywordItem) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除关键词「${row.keyword}」吗?`, '删除确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '删除',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await inboxV2KeywordDelete(row.id)
|
||||
ElMessage.success('关键词已删除')
|
||||
await loadList()
|
||||
} catch (error) {
|
||||
console.error('删除关键词失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.subTypeId,
|
||||
() => {
|
||||
pagination.page = 1
|
||||
resetForm()
|
||||
dialogVisible.value = false
|
||||
void loadList()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "./panel.scss";
|
||||
</style>
|
||||
267
src/views/inbox/autoReply/components/NumberRulePanel.vue
Normal file
267
src/views/inbox/autoReply/components/NumberRulePanel.vue
Normal file
@ -0,0 +1,267 @@
|
||||
<template>
|
||||
<div class="ar-panel">
|
||||
<div class="ar-panel-toolbar">
|
||||
<div class="ar-panel-toolbar-left">
|
||||
<span class="ar-panel-tip">
|
||||
取号规则全局只读,按顺序用正则从消息中提取单据号
|
||||
</span>
|
||||
</div>
|
||||
<div class="ar-panel-toolbar-right">
|
||||
<el-select
|
||||
v-model="pendingRuleId"
|
||||
placeholder="选择取号规则加入"
|
||||
filterable
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 260px"
|
||||
:disabled="!writable"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in addableRules"
|
||||
:key="item.id"
|
||||
:label="`${item.name}(${numberRuleTargetLabel(item.target)})`"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-button size="small" type="primary" :disabled="!writable || !pendingRuleId" @click="handleAddRow">
|
||||
添加
|
||||
</el-button>
|
||||
<el-button size="small" :loading="loading" @click="handleRefresh">刷新</el-button>
|
||||
<el-button size="small" type="primary" :loading="saving" :disabled="!writable || !dirty" @click="handleSave">
|
||||
保存关联
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ar-panel-table">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="rows"
|
||||
border
|
||||
stripe
|
||||
size="small"
|
||||
height="100%"
|
||||
empty-text="暂未关联取号规则"
|
||||
>
|
||||
<el-table-column
|
||||
v-for="col in columns"
|
||||
:key="col.prop"
|
||||
:prop="col.prop"
|
||||
:label="col.label"
|
||||
:width="col.width"
|
||||
:min-width="col.minWidth"
|
||||
:align="col.align ?? 'left'"
|
||||
:show-overflow-tooltip="col.showOverflowTooltip"
|
||||
>
|
||||
<template #default="{ row, $index }">
|
||||
<template v-if="col.prop === 'sort_order'">
|
||||
{{ $index + 1 }}
|
||||
</template>
|
||||
<template v-else-if="col.prop === 'actions'">
|
||||
<el-button size="small" type="primary" link :disabled="!writable || $index === 0" @click="moveRow($index, -1)">
|
||||
上移
|
||||
</el-button>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
link
|
||||
:disabled="!writable || $index === rows.length - 1"
|
||||
@click="moveRow($index, 1)"
|
||||
>
|
||||
下移
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" link :disabled="!writable" @click="removeRow($index)">
|
||||
移除
|
||||
</el-button>
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ row[col.prop] ?? '-' }}
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
inboxV2NumberRuleList,
|
||||
inboxV2RelationRuleList,
|
||||
inboxV2RelationRuleSet,
|
||||
unwrapInboxV2Data,
|
||||
type InboxV2NumberRuleItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import { numberRuleColumns, numberRuleTargetLabel } from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
subTypeId: number
|
||||
writable: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 未保存改动状态变化,供父级切换节点前拦截 */
|
||||
'dirty-change': [value: boolean]
|
||||
}>()
|
||||
|
||||
type RelationRow = {
|
||||
number_rule_id: number
|
||||
name: string
|
||||
target: string
|
||||
target_label: string
|
||||
regexp: string
|
||||
}
|
||||
|
||||
const columns = numberRuleColumns
|
||||
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const dirty = ref(false)
|
||||
const rows = ref<RelationRow[]>([])
|
||||
const pendingRuleId = ref<number | null>(null)
|
||||
const ruleLibrary = ref<InboxV2NumberRuleItem[]>([])
|
||||
|
||||
const ruleMap = computed(() => {
|
||||
const map = new Map<number, InboxV2NumberRuleItem>()
|
||||
for (const item of ruleLibrary.value) map.set(item.id, item)
|
||||
return map
|
||||
})
|
||||
|
||||
const addableRules = computed(() => {
|
||||
const used = new Set(rows.value.map((row) => row.number_rule_id))
|
||||
return ruleLibrary.value.filter((item) => !used.has(item.id))
|
||||
})
|
||||
|
||||
async function loadRules() {
|
||||
const res = await inboxV2NumberRuleList()
|
||||
const data = unwrapInboxV2Data(res)
|
||||
ruleLibrary.value = data?.list ?? []
|
||||
}
|
||||
|
||||
function buildRelationRows(relations: Array<{ number_rule_id: number; sort_order: number }>): RelationRow[] {
|
||||
return [...relations]
|
||||
.sort((a, b) => (Number(a.sort_order) || 0) - (Number(b.sort_order) || 0))
|
||||
.map((relation) => {
|
||||
const rule = ruleMap.value.get(Number(relation.number_rule_id))
|
||||
return {
|
||||
number_rule_id: Number(relation.number_rule_id),
|
||||
name: rule?.name ?? '',
|
||||
target: rule?.target ?? '',
|
||||
target_label: rule ? numberRuleTargetLabel(rule.target) : '-',
|
||||
regexp: rule?.regexp ?? '',
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function loadRelations() {
|
||||
if (!props.subTypeId) {
|
||||
rows.value = []
|
||||
return
|
||||
}
|
||||
const res = await inboxV2RelationRuleList(props.subTypeId)
|
||||
const data = unwrapInboxV2Data(res)
|
||||
rows.value = buildRelationRows(data?.list ?? [])
|
||||
dirty.value = false
|
||||
}
|
||||
|
||||
/** 刷新前若有未保存改动先确认 */
|
||||
async function handleRefresh() {
|
||||
if (dirty.value) {
|
||||
try {
|
||||
await ElMessageBox.confirm('当前有未保存的关联修改,刷新后将被丢弃,是否继续?', '未保存修改', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '放弃修改并继续',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
}
|
||||
await loadAll()
|
||||
}
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
try {
|
||||
if (!ruleLibrary.value.length) {
|
||||
await loadRules()
|
||||
}
|
||||
await loadRelations()
|
||||
} catch (error) {
|
||||
console.error('加载取号规则关联失败:', error)
|
||||
rows.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddRow() {
|
||||
const id = Number(pendingRuleId.value)
|
||||
if (!id) return
|
||||
const rule = ruleMap.value.get(id)
|
||||
if (!rule) {
|
||||
ElMessage.warning('取号规则不存在')
|
||||
return
|
||||
}
|
||||
rows.value.push({
|
||||
number_rule_id: id,
|
||||
name: rule.name,
|
||||
target: rule.target,
|
||||
target_label: numberRuleTargetLabel(rule.target),
|
||||
regexp: rule.regexp,
|
||||
})
|
||||
pendingRuleId.value = null
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
function removeRow(index: number) {
|
||||
rows.value.splice(index, 1)
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
function moveRow(index: number, offset: number) {
|
||||
const target = index + offset
|
||||
if (target < 0 || target >= rows.value.length) return
|
||||
const item = rows.value.splice(index, 1)[0]
|
||||
if (!item) return
|
||||
rows.value.splice(target, 0, item)
|
||||
dirty.value = true
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (!props.subTypeId) return
|
||||
saving.value = true
|
||||
try {
|
||||
await inboxV2RelationRuleSet(
|
||||
props.subTypeId,
|
||||
rows.value.map((row, index) => ({ ruleId: row.number_rule_id, sortOrder: index }))
|
||||
)
|
||||
dirty.value = false
|
||||
ElMessage.success('取号规则关联已保存')
|
||||
await loadRelations()
|
||||
} catch (error) {
|
||||
console.error('保存取号规则关联失败:', error)
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 未保存改动上报(父级切换节点前拦截)
|
||||
watch(dirty, (value) => emit('dirty-change', value))
|
||||
|
||||
watch(
|
||||
() => props.subTypeId,
|
||||
() => {
|
||||
pendingRuleId.value = null
|
||||
dirty.value = false
|
||||
void loadAll()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "./panel.scss";
|
||||
</style>
|
||||
244
src/views/inbox/autoReply/components/ReplyPanel.vue
Normal file
244
src/views/inbox/autoReply/components/ReplyPanel.vue
Normal file
@ -0,0 +1,244 @@
|
||||
<template>
|
||||
<div class="ar-panel reply-panel">
|
||||
<div class="ar-panel-toolbar">
|
||||
<div class="ar-panel-toolbar-right">
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSave">
|
||||
保存配置
|
||||
</el-button>
|
||||
<el-button size="small" type="danger" :disabled="submitting" @click="handleRestore">
|
||||
还原配置
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-loading="loading" class="reply-body">
|
||||
<el-form :model="form" label-width="120px" size="small">
|
||||
<el-form-item label="回复方式">
|
||||
<el-radio-group v-model="form.isReply">
|
||||
<el-radio :value="1">回复</el-radio>
|
||||
<el-radio :value="0">不回复</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="处理方式">
|
||||
<el-radio-group v-model="form.createWorkOrder">
|
||||
<el-radio :value="1">登记工单</el-radio>
|
||||
<el-radio :value="0">不登记工单</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="回复文案" prop="reply">
|
||||
<el-input
|
||||
v-model="form.reply"
|
||||
type="textarea"
|
||||
:rows="6"
|
||||
maxlength="2000"
|
||||
show-word-limit
|
||||
placeholder="支持换行;可使用占位符"
|
||||
/>
|
||||
<div class="placeholder-bar">
|
||||
<span class="placeholder-label">可用占位符:</span>
|
||||
<el-tag v-for="item in replyPlaceholders" :key="item" size="small" type="info">{{ item }}</el-tag>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="取号失败引导语">
|
||||
<el-input
|
||||
v-model="form.noNumberHint"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
maxlength="500"
|
||||
show-word-limit
|
||||
placeholder="关联取号规则但未提取到单据号时回复(留空则用默认引导语)"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-alert
|
||||
v-if="silentAndNoWorkOrder"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="不回复 + 不登记工单:函数仍执行,但不回消息也不建单"
|
||||
/>
|
||||
</el-form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
inboxV2ReplyMerged,
|
||||
inboxV2ReplyRestore,
|
||||
inboxV2ReplySave,
|
||||
unwrapInboxV2Data,
|
||||
type InboxV2MergedReplyItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import { replyPlaceholders, toFlag } from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
subTypeId: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 未保存改动状态变化,供父级切换节点前拦截 */
|
||||
'dirty-change': [value: boolean]
|
||||
}>()
|
||||
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
/** 当前子类型的生效配置(merged:仓库级覆盖系统级) */
|
||||
const effective = ref<InboxV2MergedReplyItem | null>(null)
|
||||
const formDirty = ref(false)
|
||||
|
||||
watch(formDirty, (value) => emit('dirty-change', value))
|
||||
|
||||
const form = reactive({
|
||||
isReply: 1,
|
||||
/** 1=执行函数并登记工单(默认)0=函数照常执行但跳过工单登记 */
|
||||
createWorkOrder: 1,
|
||||
reply: '',
|
||||
noNumberHint: '',
|
||||
})
|
||||
|
||||
/** 静默 + 不登记工单:函数仍执行,但不回消息也不建单 */
|
||||
const silentAndNoWorkOrder = computed(() => form.isReply === 0 && form.createWorkOrder === 0)
|
||||
|
||||
let syncing = false
|
||||
|
||||
function syncForm() {
|
||||
syncing = true
|
||||
// 表单 = merged 返回的生效配置,保证与接口数据一致
|
||||
const row = effective.value
|
||||
if (row) {
|
||||
form.isReply = toFlag(row.is_reply, 1)
|
||||
form.createWorkOrder = toFlag(row.create_work_order, 1)
|
||||
form.reply = row.reply ?? ''
|
||||
form.noNumberHint = row.no_number_hint ?? ''
|
||||
} else {
|
||||
form.isReply = 1
|
||||
form.createWorkOrder = 1
|
||||
form.reply = ''
|
||||
form.noNumberHint = ''
|
||||
}
|
||||
formDirty.value = false
|
||||
void nextTick(() => {
|
||||
syncing = false
|
||||
})
|
||||
}
|
||||
|
||||
async function loadReplies() {
|
||||
if (!props.subTypeId) {
|
||||
effective.value = null
|
||||
syncForm()
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const res = await inboxV2ReplyMerged({ subTypeId: props.subTypeId })
|
||||
const data = unwrapInboxV2Data(res)
|
||||
effective.value = data?.merged?.[0] ?? null
|
||||
syncForm()
|
||||
} catch (error) {
|
||||
console.error('加载回复配置失败:', error)
|
||||
effective.value = null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [form.isReply, form.createWorkOrder, form.reply, form.noNumberHint],
|
||||
() => {
|
||||
if (syncing) return
|
||||
formDirty.value = true
|
||||
}
|
||||
)
|
||||
|
||||
/** 保存(upsert):未传字段保持原值,无仓库级配置时按传入值创建 */
|
||||
async function handleSave() {
|
||||
if (!props.subTypeId) return
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await inboxV2ReplySave({
|
||||
subTypeId: props.subTypeId,
|
||||
reply: form.reply.trim(),
|
||||
isReply: form.isReply,
|
||||
createWorkOrder: form.createWorkOrder,
|
||||
noNumberHint: form.noNumberHint.trim(),
|
||||
})
|
||||
const data = unwrapInboxV2Data(res)
|
||||
ElMessage.success(data?.message || '回复配置已保存')
|
||||
await loadReplies()
|
||||
} catch (error) {
|
||||
console.error('保存回复配置失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 还原:删除仓库级行,回退系统级(幂等) */
|
||||
async function handleRestore() {
|
||||
if (!props.subTypeId) return
|
||||
try {
|
||||
await ElMessageBox.confirm('删除仓库级配置后,该子类型将回退使用系统级配置,确定吗?', '还原确认', {
|
||||
type: 'warning',
|
||||
confirmButtonText: '还原',
|
||||
cancelButtonText: '取消',
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const res = await inboxV2ReplyRestore(props.subTypeId)
|
||||
const data = unwrapInboxV2Data(res)
|
||||
ElMessage.success(data?.message || '已还原为系统级配置')
|
||||
await loadReplies()
|
||||
} catch (error) {
|
||||
console.error('还原系统级配置失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.subTypeId,
|
||||
() => {
|
||||
void loadReplies()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "./panel.scss";
|
||||
|
||||
.reply-body {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
// 工具栏只剩右侧操作按钮,靠右对齐
|
||||
.ar-panel-toolbar-right {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.placeholder-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.placeholder-label {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
</style>
|
||||
163
src/views/inbox/autoReply/components/SubTypeFormDialog.vue
Normal file
163
src/views/inbox/autoReply/components/SubTypeFormDialog.vue
Normal file
@ -0,0 +1,163 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="mode === 'create' ? '新增子类型' : '编辑子类型'"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="110px" size="small">
|
||||
<el-form-item label="所属类型">
|
||||
<el-input :model-value="`${typeName || typeCode}(${typeCode})`" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="子类型编码" prop="subType">
|
||||
<el-input
|
||||
v-model="form.subType"
|
||||
placeholder="如 after_sales,≤50 字符"
|
||||
maxlength="50"
|
||||
show-word-limit
|
||||
:disabled="mode === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="子类型名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="如 售后处理" maxlength="50" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="mode === 'edit'" label="启用状态">
|
||||
<el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序值">
|
||||
<el-input-number v-model="form.sortOrder" :min="0" :max="9999" controls-position="right" />
|
||||
<span class="ar-form-tip">数值越小越靠前</span>
|
||||
</el-form-item>
|
||||
<el-alert
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
title="子类型编码在「该类型 + 本仓库」内唯一"
|
||||
/>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button size="small" :disabled="submitting" @click="visible = false">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
inboxV2SubTypeCreate,
|
||||
inboxV2SubTypeUpdate,
|
||||
type InboxV2SubTypeItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import { toFlag } from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
mode: 'create' | 'edit'
|
||||
/** 所属类型编码(新增时必填) */
|
||||
typeCode: string
|
||||
/** 所属类型名称(展示用) */
|
||||
typeName?: string
|
||||
row?: InboxV2SubTypeItem | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
success: []
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: boolean) => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance | null>(null)
|
||||
const form = reactive({
|
||||
subType: '',
|
||||
name: '',
|
||||
isEnabled: 1,
|
||||
sortOrder: 0,
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
subType: [
|
||||
{ required: true, message: '请输入子类型编码', trigger: 'blur' },
|
||||
{ max: 50, message: '子类型编码不超过 50 字符', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^[A-Za-z0-9_-]+$/,
|
||||
message: '子类型编码仅支持字母、数字、下划线、中划线',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: '请输入子类型名称', trigger: 'blur' },
|
||||
{ max: 50, message: '子类型名称不超过 50 字符', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
function initForm() {
|
||||
if (props.mode === 'edit' && props.row) {
|
||||
form.subType = props.row.sub_type ?? ''
|
||||
form.name = props.row.name ?? ''
|
||||
form.isEnabled = toFlag(props.row.is_enabled, 1)
|
||||
form.sortOrder = Number(props.row.sort_order) || 0
|
||||
} else {
|
||||
form.subType = ''
|
||||
form.name = ''
|
||||
form.isEnabled = 1
|
||||
form.sortOrder = 0
|
||||
}
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) initForm()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
if (props.mode === 'edit' && props.row) {
|
||||
await inboxV2SubTypeUpdate({
|
||||
id: props.row.id,
|
||||
name: form.name.trim(),
|
||||
isEnabled: form.isEnabled,
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('子类型已更新')
|
||||
} else {
|
||||
await inboxV2SubTypeCreate({
|
||||
type: props.typeCode,
|
||||
subType: form.subType.trim(),
|
||||
name: form.name.trim(),
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('子类型已创建')
|
||||
}
|
||||
visible.value = false
|
||||
emit('success')
|
||||
} catch (error) {
|
||||
console.error('保存子类型失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleClosed() {
|
||||
submitting.value = false
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
</script>
|
||||
149
src/views/inbox/autoReply/components/TypeFormDialog.vue
Normal file
149
src/views/inbox/autoReply/components/TypeFormDialog.vue
Normal file
@ -0,0 +1,149 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
v-model="visible"
|
||||
:title="mode === 'create' ? '新增类型' : '编辑类型'"
|
||||
width="480px"
|
||||
align-center
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
@closed="handleClosed"
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px" size="small">
|
||||
<el-form-item label="类型编码" prop="type">
|
||||
<el-input
|
||||
v-model="form.type"
|
||||
placeholder="如 order / receiving,≤20 字符"
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
:disabled="mode === 'edit'"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="类型名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="如 订单售后" maxlength="50" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="mode === 'edit'" label="启用状态">
|
||||
<el-switch v-model="form.isEnabled" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
|
||||
</el-form-item>
|
||||
<el-form-item label="排序值">
|
||||
<el-input-number v-model="form.sortOrder" :min="0" :max="9999" controls-position="right" />
|
||||
<span class="ar-form-tip">数值越小越靠前</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button size="small" :disabled="submitting" @click="visible = false">取消</el-button>
|
||||
<el-button size="small" type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
inboxV2TypeCreate,
|
||||
inboxV2TypeUpdate,
|
||||
type InboxV2TypeItem,
|
||||
} from '@/api/inbox/autoReply'
|
||||
import { toFlag } from '../autoReply-config'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
mode: 'create' | 'edit'
|
||||
row?: InboxV2TypeItem | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: boolean]
|
||||
success: []
|
||||
}>()
|
||||
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value: boolean) => emit('update:modelValue', value),
|
||||
})
|
||||
|
||||
const submitting = ref(false)
|
||||
const formRef = ref<FormInstance | null>(null)
|
||||
const form = reactive({
|
||||
type: '',
|
||||
name: '',
|
||||
isEnabled: 1,
|
||||
sortOrder: 0,
|
||||
})
|
||||
|
||||
const rules: FormRules = {
|
||||
type: [
|
||||
{ required: true, message: '请输入类型编码', trigger: 'blur' },
|
||||
{ max: 20, message: '类型编码不超过 20 字符', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^[A-Za-z0-9_-]+$/,
|
||||
message: '类型编码仅支持字母、数字、下划线、中划线',
|
||||
trigger: 'blur',
|
||||
},
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: '请输入类型名称', trigger: 'blur' },
|
||||
{ max: 50, message: '类型名称不超过 50 字符', trigger: 'blur' },
|
||||
],
|
||||
}
|
||||
|
||||
function initForm() {
|
||||
if (props.mode === 'edit' && props.row) {
|
||||
form.type = props.row.type ?? ''
|
||||
form.name = props.row.name ?? ''
|
||||
form.isEnabled = toFlag(props.row.is_enabled, 1)
|
||||
form.sortOrder = Number(props.row.sort_order) || 0
|
||||
} else {
|
||||
form.type = ''
|
||||
form.name = ''
|
||||
form.isEnabled = 1
|
||||
form.sortOrder = 0
|
||||
}
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) initForm()
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!formRef.value) return
|
||||
const valid = await formRef.value.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
submitting.value = true
|
||||
try {
|
||||
if (props.mode === 'edit' && props.row) {
|
||||
await inboxV2TypeUpdate({
|
||||
id: props.row.id,
|
||||
name: form.name.trim(),
|
||||
isEnabled: form.isEnabled,
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('类型已更新')
|
||||
} else {
|
||||
await inboxV2TypeCreate({
|
||||
type: form.type.trim(),
|
||||
name: form.name.trim(),
|
||||
sortOrder: form.sortOrder,
|
||||
})
|
||||
ElMessage.success('类型已创建')
|
||||
}
|
||||
visible.value = false
|
||||
emit('success')
|
||||
} catch (error) {
|
||||
console.error('保存类型失败:', error)
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handleClosed() {
|
||||
submitting.value = false
|
||||
formRef.value?.clearValidate()
|
||||
}
|
||||
</script>
|
||||
62
src/views/inbox/autoReply/components/panel.scss
Normal file
62
src/views/inbox/autoReply/components/panel.scss
Normal file
@ -0,0 +1,62 @@
|
||||
// 自动回复设置 - 配置面板通用样式(由各子面板 @use 复用)
|
||||
|
||||
.ar-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ar-panel-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ar-panel-toolbar-left {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ar-panel-toolbar-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ar-panel-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.ar-panel-table {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ar-panel-pagination {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.ar-form-tip {
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
}
|
||||
|
||||
.ar-inline-empty {
|
||||
padding: 24px 0;
|
||||
text-align: center;
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
}
|
||||
1018
src/views/inbox/autoReply/index.vue
Normal file
1018
src/views/inbox/autoReply/index.vue
Normal file
File diff suppressed because it is too large
Load Diff
@ -61,6 +61,7 @@ export const groupColumns = [
|
||||
{ prop: 'express_interfaces', label: '快递接口', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'system_express_name', label: '系统快递', width: '110', showOverflowTooltip: true },
|
||||
{ prop: 'ai_enabled', label: 'AI回复', width: '90' },
|
||||
{ prop: 'template_reply_enabled', label: '模板回复', width: '90' },
|
||||
{ prop: 'is_blocked', label: '状态', width: '80' },
|
||||
{ prop: 'created_at', label: '创建时间', width: '170' },
|
||||
{ prop: 'updated_at', label: '更新时间', width: '170' },
|
||||
|
||||
@ -86,6 +86,12 @@
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #column-template_reply_enabled="{ row }">
|
||||
<span :class="getStatusTextClass(row.template_reply_enabled ? 'success' : 'info')">
|
||||
{{ row.template_reply_enabled ? '开' : '关' }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #column-actions="{ row }">
|
||||
<div class="wave-operation-actions">
|
||||
<el-button size="small" type="primary" link @click.stop="handleEdit(row)">编辑</el-button>
|
||||
@ -183,6 +189,10 @@
|
||||
<el-form-item label="AI 自动回复">
|
||||
<el-switch v-model="editForm.aiEnabled" :active-value="1" :inactive-value="0" active-text="开" inactive-text="关" />
|
||||
</el-form-item>
|
||||
<el-form-item label="模板消息回复">
|
||||
<el-switch v-model="editForm.templateReplyEnabled" :active-value="1" :inactive-value="0" active-text="开" inactive-text="关" />
|
||||
<span class="form-tip">开启后命中处理以模板消息形式回复(独立于 AI 自动回复)</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button size="small" @click="editDialogVisible = false">取消</el-button>
|
||||
@ -470,7 +480,7 @@ const editDialogVisible = ref(false)
|
||||
const editLoading = ref(false)
|
||||
const editFormRef = ref<FormInstance>()
|
||||
const editingRow = ref<any>(null)
|
||||
const editForm = reactive({ groupId: '', groupName: '', groupType: '' as string, subType: '' as string, storeId: null as number | null, expressInterfaces: [] as number[], systemExpressCode: '' as string, aiEnabled: 1 as number })
|
||||
const editForm = reactive({ groupId: '', groupName: '', groupType: '' as string, subType: '' as string, storeId: null as number | null, expressInterfaces: [] as number[], systemExpressCode: '' as string, aiEnabled: 1 as number, templateReplyEnabled: 0 as number })
|
||||
const editRules: FormRules = { systemExpressCode: [{ validator: (_r, _v, cb) => { if (editForm.groupType === 'express' && !editForm.systemExpressCode) cb(new Error('快递类型时系统快递编码不能为空')); else cb() }, trigger: 'change' }] }
|
||||
|
||||
const expressInterfaceOptions = ref<Array<{ label: string; value: number }>>([])
|
||||
@ -487,6 +497,7 @@ function handleEdit(row: any) {
|
||||
: []
|
||||
editForm.systemExpressCode = row.system_express_code ?? ''
|
||||
editForm.aiEnabled = row.ai_enabled ?? 1
|
||||
editForm.templateReplyEnabled = row.template_reply_enabled ?? 0
|
||||
editDialogVisible.value = true; loadStoreList()
|
||||
if (editForm.groupType === 'express') { loadExpressCodes(); loadExpressInterfacesByCode() }
|
||||
}
|
||||
@ -542,6 +553,7 @@ async function handleSubmitEdit() {
|
||||
if (editForm.groupType === 'store' && editForm.storeId) params.storeId = editForm.storeId
|
||||
if (editForm.groupType === 'express') { params.expressInterfaces = editForm.expressInterfaces; params.systemExpressCode = editForm.systemExpressCode }
|
||||
params.aiEnabled = editForm.aiEnabled
|
||||
params.templateReplyEnabled = editForm.templateReplyEnabled
|
||||
const res: any = await inboxGroupUpdate(params)
|
||||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
|
||||
ElMessage.success(res.data?.message || res.message || '群信息修改成功')
|
||||
@ -568,7 +580,7 @@ async function handleToggleDisable(row: any) {
|
||||
async function handleResetGroupConfig(row: any) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确定要清空群组「${row.group_name}」的群类型配置吗?群类型/子类型/货主/快递接口/系统快递编码将被清空,AI 自动回复将关闭,仅保留群创建时信息。`,
|
||||
`确定要清空群组「${row.group_name}」的群类型配置吗?群类型/子类型/货主/快递接口/系统快递编码将被清空,AI 自动回复与模板消息回复将关闭,仅保留群创建时信息。`,
|
||||
'清空配置确认',
|
||||
{ type: 'warning', confirmButtonText: '清空', confirmButtonClass: 'el-button--danger' }
|
||||
)
|
||||
@ -641,6 +653,8 @@ onMounted(() => { loadStoreList(); fetchData() })
|
||||
}
|
||||
}
|
||||
|
||||
.form-tip { margin-left: 10px; font-size: 12px; color: #909399; line-height: 1.4; }
|
||||
|
||||
.msg-filter-bar { display: flex; align-items: center; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid #ebeef5; }
|
||||
.msg-table-wrapper { margin-bottom: 0; }
|
||||
.msg-pagination-wrapper { display: flex; justify-content: flex-end; margin-top: 10px; }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user