WEB/src/views/inbox/group/index.vue
yin 6838d69788 perf(app): 详情面板统一迁移 UpperTable,路由按需加载并优化跨浏览器性能
- 新增 router/view-glob.ts,动态菜单兜底的全量 glob 表改为按需动态加载,
  入口 chunk 由 465KB 降至 393KB;Sidebar / TaskView 用 utils/path 的
  resolveRoutePath 替换 path-browserify 静态引用
- 新增 utils/perf-probe 轻量探针(?perf=1 或 localStorage 开启),输出导航耗时、
  资源分类统计、长任务与硬件信息;移除 text-rendering: optimizeLegibility,
  breadcrumb 过渡由 all 改为 opacity/transform,降低弱 CPU 与非 Chrome 内核开销
- Navbar 工单角标轮询在后台标签页跳过,通过 visibilitychange 回到前台补刷一次
- 库存详情、货位、条码、入库日志、出库日志与明细、收货日志、盘点记录等
  详情面板由 el-table 迁移到 UpperTable,统一展开行、分页、选择与列插槽
- 11 处模板配置及内嵌表格开启行选择;转储、转退货、批量复核弹窗改用
  SelectedTags 展示已选项并支持逐个移除,移除最后一个后自动关闭
- ImagesUpload 重构为「图库 + 上传区」面板,支持多选、最多 20 张、
  单张 10MB 校验与数量提示
- 新增《跨浏览器性能-分析与优化清单》文档
2026-11-11 18:00:42 +08:00

1181 lines
42 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="order-sub-container">
<scan-box
ref="scanBox"
cache-key="inbox:group"
width="220px"
:tree-props="{ children: 'children', label: 'label' }"
:auto-submit="false"
:available-fields="availableFields"
:initial-conditions="initialConditions"
@condition-change="handleConditionChange"
@reset="handleConditionReset"
@condition-clear="handleConditionClear"
/>
<div class="main-content">
<div class="toolbar">
<div class="toolbar-left">
<order-toolbar-button-group
:buttons="toolbarButtons"
:resolve-disabled="resolveButtonDisabled"
:resolve-loading="resolveButtonLoading"
:resolve-label="resolveButtonLabel"
:layout-key="toolbarLayoutKey"
@action="handleToolbarButtonClick"
/>
</div>
</div>
<div class="split-stack">
<div class="upper-wrapper">
<upper-table
ref="upperTable"
title="群组列表"
default-align="center"
table-id="inbox-group-list"
:data="tableData"
:columns="columns"
:table-size="tableSize"
:pagination="upperPagination"
:show-index="true"
:show-actions="true"
:show-selection="true"
:loading="loading"
:query-time="queryTime"
row-key="id"
@current-change="handleRowClick"
@page-change="handlePageChange"
@page-size-change="handlePageSizeChange"
@sort-change="handleSortChange"
@refresh="handleRefresh"
>
<template #column-group_type="{ row }">
<span :class="getStatusTextClass(groupTypeTagType(row.group_type))">
{{ groupTypeLabel(row.group_type) }}
</span>
</template>
<template #column-sub_type="{ row }">
{{ subTypeLabel(row.sub_type) }}
</template>
<template #column-source_type="{ row }">
<span :class="getStatusTextClass(row.source_type === 'api' ? 'success' : 'info')">
{{ row.source_type === 'api' ? 'API' : row.source_type || '-' }}
</span>
</template>
<template #column-express_interfaces="{ row }">
<template v-if="row.express_interfaces && row.express_interfaces.length">
<el-tag v-for="(iface, idx) in row.express_interfaces" :key="idx" size="small" style="margin: 1px 2px">
{{ iface.name || iface }}
</el-tag>
</template>
<span v-else>-</span>
</template>
<template #column-is_blocked="{ row }">
<span :class="getStatusTextClass(row.is_blocked ? 'danger' : 'success')">
{{ row.is_blocked ? '已禁用' : '启用' }}
</span>
</template>
<template #column-ai_enabled="{ row }">
<span :class="getStatusTextClass(row.ai_enabled ? 'success' : 'info')">
{{ row.ai_enabled ? '开' : '关' }}
</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>
<el-button size="small" :type="row.is_blocked ? 'success' : 'danger'" link @click.stop="handleToggleDisable(row)">
{{ row.is_blocked ? '启用' : '禁用' }}
</el-button>
<el-button size="small" type="primary" link @click.stop="handleViewMessages(row)">消息</el-button>
<el-button size="small" type="danger" link @click.stop="handleResetGroupConfig(row)">清空配置</el-button>
</div>
</template>
<template #empty>
<div class="empty-tip">暂无群组数据</div>
</template>
</upper-table>
</div>
</div>
</div>
<!-- ========== 弹窗 ========== -->
<!-- 生成绑群码弹窗:面板结构 / 尺寸对齐「手工录入运单号」(ManualWaybillForm) -->
<el-dialog
v-model="bindDialogVisible"
class="bind-code-dialog"
width="min(560px, 92vw)"
align-center
append-to-body
:show-close="false"
destroy-on-close
:close-on-click-modal="false"
@closed="resetBindForm"
>
<div class="task-panel">
<header class="task-panel__head">
<div class="task-panel__titles">
<h2>生成绑群码</h2>
<p>选择货主后生成绑群码,生成后 5 分钟内有效</p>
</div>
<button
class="task-panel__close"
type="button"
aria-label="关闭"
@click="bindDialogVisible = false"
>
<svg viewBox="0 0 12 12" fill="none">
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</header>
<div class="task-panel__body">
<el-form ref="bindFormRef" :model="bindForm" :rules="bindRules" class="task-panel__form">
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">选择货主</span>
<div class="task-panel__field-control">
<el-form-item prop="storeId">
<el-select
v-model="bindForm.storeId"
size="default"
placeholder="请选择货主"
filterable
style="width: 100%"
:loading="storeLoading"
>
<el-option v-for="store in storeList" :key="store.value" :label="store.label" :value="store.value" />
</el-select>
</el-form-item>
</div>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">子类型</span>
<div class="task-panel__field-control">
<el-select v-model="bindForm.subType" size="default" placeholder="可选" clearable style="width: 100%">
<el-option label="售后" value="after_sales" />
<el-option label="财务" value="finance" />
<el-option label="收货" value="receiving" />
</el-select>
</div>
</div>
</el-form>
<!-- 提示条:对齐「手工录入运单号」的 .task-panel__form-tip -->
<p class="task-panel__form-tip">
子类型不选则生成通用绑群码;绑群码 5 分钟内有效且仅可使用一次,过期需重新生成。
</p>
</div>
<footer class="task-panel__foot">
<span class="task-panel__hint">绑群码仅可使用一次,过期需重新生成</span>
<div class="task-panel__actions">
<el-button size="small" @click="bindDialogVisible = false">取消</el-button>
<el-button size="small" type="primary" :loading="bindLoading" @click="handleGenerateCode">生成</el-button>
</div>
</footer>
</div>
</el-dialog>
<!-- 绑群码结果弹窗 -->
<el-dialog v-model="resultDialogVisible" title="绑群码已生成" width="480px" destroy-on-close>
<div class="result-content">
<div class="result-tip">绑群码 5 分钟有效,请将以下码发送给货主,货主可在对应 IM 工具中使用该码完成群组绑定。</div>
<div class="result-code-box">
<span class="result-code">{{ generatedCode }}</span>
<el-button type="primary" size="small" @click="handleCopyGeneratedCode">复制</el-button>
</div>
</div>
<template #footer>
<el-button size="small" @click="resultDialogVisible = false">关闭</el-button>
</template>
</el-dialog>
<!-- 编辑群信息弹窗:面板结构 / 尺寸对齐「手工录入运单号」(ManualWaybillForm) -->
<el-dialog
v-model="editDialogVisible"
class="edit-group-dialog"
align-center
width="min(600px, 94vw)"
append-to-body
destroy-on-close
:show-close="false"
:close-on-click-modal="false"
@closed="resetEditForm"
>
<div class="task-panel">
<header class="task-panel__head">
<div class="task-panel__titles">
<h2>编辑群信息</h2>
<p>调整群类型、关联对象与自动回复策略,保存后立即生效</p>
</div>
<button
class="task-panel__close"
type="button"
aria-label="关闭"
@click="editDialogVisible = false"
>
<svg viewBox="0 0 12 12" fill="none">
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</header>
<div class="task-panel__body">
<el-form ref="editFormRef" :model="editForm" :rules="editRules" class="task-panel__form">
<!-- 静态信息行:群 ID / 群名称 -->
<div class="task-panel__field">
<span class="task-panel__field-label">群ID</span>
<strong class="task-panel__field-value">{{ editForm.groupId || '—' }}</strong>
</div>
<div class="task-panel__field">
<span class="task-panel__field-label">群名称</span>
<strong class="task-panel__field-value">{{ editForm.groupName || '—' }}</strong>
</div>
<div class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label is-required">群类型</span>
<el-form-item prop="groupType">
<el-select v-model="editForm.groupType" style="width: 100%" @change="onEditGroupTypeChange">
<el-option label="货主群" value="store" />
<el-option label="仓库群" value="warehouse" />
<el-option label="快递群" value="express" />
</el-select>
</el-form-item>
</div>
<div v-if="editForm.groupType" class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">子类型</span>
<el-form-item>
<el-select v-model="editForm.subType" placeholder="可选" clearable style="width: 100%">
<el-option
v-for="opt in getSubTypeOptions(editForm.groupType)"
:key="opt.value"
:label="opt.label"
:value="opt.value"
/>
</el-select>
</el-form-item>
</div>
<div v-if="editForm.groupType === 'store'" class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">关联货主</span>
<el-form-item prop="storeId">
<el-select
v-model="editForm.storeId"
placeholder="请选择货主"
filterable
clearable
style="width: 100%"
:loading="storeLoading"
>
<el-option v-for="store in storeList" :key="store.value" :label="store.label" :value="store.value" />
</el-select>
</el-form-item>
</div>
<div v-if="editForm.groupType === 'express'" class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">系统快递编码</span>
<el-form-item prop="systemExpressCode">
<el-select
v-model="editForm.systemExpressCode"
placeholder="请选择系统快递编码"
filterable
clearable
style="width: 100%"
:loading="expressLoading"
@change="onSystemExpressCodeChange"
>
<el-option v-for="item in expressCodeOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</div>
<div v-if="editForm.groupType === 'express'" class="task-panel__field task-panel__field--input">
<span class="task-panel__field-label">快递接口</span>
<el-form-item prop="expressInterfaces">
<el-select
v-model="editForm.expressInterfaces"
placeholder="请选择快递接口(空=全部)"
multiple
filterable
style="width: 100%"
:loading="expressLoading"
>
<el-option v-for="item in expressInterfaceOptions" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
</div>
<div class="task-panel__field task-panel__field--control">
<span class="task-panel__field-label">AI 自动回复</span>
<div class="task-panel__field-control">
<el-switch v-model="editForm.aiEnabled" :active-value="1" :inactive-value="0" active-text="开" inactive-text="关" />
</div>
</div>
<div class="task-panel__field task-panel__field--control">
<span class="task-panel__field-label">模板消息回复</span>
<div class="task-panel__field-control">
<el-switch
v-model="editForm.templateReplyEnabled"
:active-value="1"
:inactive-value="0"
active-text="开"
inactive-text="关"
/>
</div>
</div>
</el-form>
<!-- 提示条:对齐「手工录入运单号」的 .task-panel__form-tip -->
<p class="task-panel__form-tip">
子类型不选表示通用;模板消息回复开启后,命中处理将以模板消息形式回复(独立于 AI 自动回复)。
</p>
</div>
<footer class="task-panel__foot">
<span class="task-panel__hint">提交前请确认群类型与关联对象无误</span>
<div class="task-panel__actions">
<el-button size="small" @click="editDialogVisible = false">取消</el-button>
<el-button type="primary" size="small" :loading="editLoading" @click="handleSubmitEdit">保存</el-button>
</div>
</footer>
</div>
</el-dialog>
<!-- 群消息弹窗:面板结构 / 尺寸对齐 storage/receiving「批量导入商品」 -->
<el-dialog
v-model="messagesDialogVisible"
class="group-messages-dialog"
align-center
width="min(1000px, 96vw)"
append-to-body
destroy-on-close
:show-close="false"
:close-on-click-modal="false"
>
<div class="task-panel">
<header class="task-panel__head">
<div class="task-panel__titles">
<h2>群消息</h2>
<p>{{ currentGroupName ? `群:${currentGroupName}` : '查看该群的消息收发记录' }}</p>
</div>
<button
class="task-panel__close"
type="button"
aria-label="关闭"
@click="messagesDialogVisible = false"
>
<svg viewBox="0 0 12 12" fill="none">
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</header>
<div class="task-panel__body">
<div class="task-panel__toolbar">
<div class="task-panel__toolbar-main">
<el-select
v-model="msgFilter.direction"
placeholder="消息方向"
clearable
size="small"
style="width: 120px"
@change="fetchGroupMessages"
>
<el-option label="入站" value="inbound" />
<el-option label="出站" value="outbound" />
</el-select>
<el-input
v-model="msgFilter.keyword"
placeholder="搜索 ext_id / 内容"
clearable
size="small"
style="width: 220px"
@keyup.enter="fetchGroupMessages"
@clear="fetchGroupMessages"
/>
<el-button size="small" type="primary" plain @click="fetchGroupMessages">查询</el-button>
</div>
<span class="task-panel__meta">共 {{ msgPagination.total }} 条</span>
</div>
<div class="task-panel__section">
<div class="msg-table-wrapper">
<el-table
:data="msgTableData"
v-loading="msgLoading"
border
size="small"
style="width: 100%"
max-height="420"
empty-text="暂无消息"
>
<el-table-column prop="id" label="ID" width="70" align="center" header-align="center" />
<el-table-column prop="ext_id" label="外部ID" min-width="140" align="center" header-align="center" show-overflow-tooltip />
<el-table-column prop="direction" label="方向" width="80" align="center" header-align="center">
<template #default="{ row: r }">
<span :class="getStatusTextClass(r.direction === 'inbound' ? 'primary' : 'success')">
{{ r.direction === 'inbound' ? '入站' : '出站' }}
</span>
</template>
</el-table-column>
<el-table-column prop="content" label="内容" min-width="200" align="center" header-align="center" show-overflow-tooltip />
<el-table-column prop="created_at" label="时间" width="170" align="center" header-align="center" show-overflow-tooltip />
</el-table>
</div>
</div>
</div>
<footer class="task-panel__foot">
<div class="task-panel__actions">
<el-pagination
v-model:current-page="msgPagination.currentPage"
v-model:page-size="msgPagination.pageSize"
:total="msgPagination.total"
:page-sizes="[20, 50, 100, 200]"
layout="total, sizes, prev, pager, next"
background
size="small"
class="msg-pagination"
@size-change="onMsgPageSizeChange"
@current-change="onMsgPageChange"
/>
<el-button size="small" @click="messagesDialogVisible = false">关闭</el-button>
</div>
</footer>
</div>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
import {
inboxGroupList,
inboxGroupDisable,
inboxGroupUpdate,
inboxGroupMessages,
inboxGroupReset,
inboxBindCode,
} from '@/api/inbox/inbox'
import { loadStores, loadExpressInterfaces } from '@/api/index/index'
import { extractStoreListFromResponse, fillStoreScanFieldOptions, mapStoreListToSelectOptions } from '@/utils/storeScanOptions'
import { getStatusTextClass } from '@/utils/statusText'
import { expressIndexGetExpressList } from '@/api/setting.express/express'
import { groupAvailableFields, groupColumns, groupToolbarButtons } from './group-config'
import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import OrderToolbarButtonGroup from '@/components/ToolbarButtonGroup/index.vue'
import type { ToolbarButtonConfig } from '@/components/ToolbarButtonGroup/types'
import { safeInvoke } from '@/utils/safe-invoke'
// ==================== 常量 ====================
const groupTypeLabelMap: Record<string, string> = { store: '货主群', warehouse: '仓库群', express: '快递群' }
const groupTypeTagTypeMap: Record<string, string> = { store: 'primary', warehouse: 'warning', express: 'success' }
const subTypeLabelMap: Record<string, string> = {
after_sales: '售后', finance: '财务', receiving: '收货',
production: '生产', stockout: '出库', all: '全体', customer_service: '客服', exception: '异常',
pickup: '揽收',
}
function groupTypeLabel(t: string) { return groupTypeLabelMap[t] ?? t ?? '-' }
function groupTypeTagType(t: string) { return groupTypeTagTypeMap[t] ?? 'info' }
function subTypeLabel(s: string) { return subTypeLabelMap[s] ?? s ?? '-' }
/** 子类型选项,受群类型约束 */
const subTypeConfigMap: 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' },
],
}
function getSubTypeOptions(groupType: string) {
return subTypeConfigMap[groupType] ?? []
}
// ==================== 配置 ====================
const availableFields = groupAvailableFields
const columns = groupColumns
const tableSize = 'small'
const toolbarButtons = groupToolbarButtons
const buttonLoadingMap = ref<Record<string, boolean>>({ loading: false })
const buttonDisabledMap = ref<Record<string, boolean>>({})
const buttonLabelMap = ref<Record<string, string>>({})
const toolbarLayoutKey = ref('')
function resolveButtonLoading(loadingKey?: string) {
if (!loadingKey) return false
return Boolean(buttonLoadingMap.value[loadingKey])
}
function resolveButtonDisabled(disabledKey?: string) {
if (!disabledKey) return false
return Boolean(buttonDisabledMap.value[disabledKey])
}
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
return dynamicLabelKey ? (buttonLabelMap.value[dynamicLabelKey] || defaultLabel) : defaultLabel
}
const toolbarActionMap: Record<string, () => void> = {
loadData: () => { handleRefresh() },
showBindDialog: () => { showBindDialog() }
}
function handleToolbarButtonClick(action: string) {
const handler = toolbarActionMap[action]
if (!handler) return
safeInvoke(() => handler())
}
// ==================== 数据状态 ====================
const scanBox = ref<any>(null)
const upperTable = ref<any>(null)
const loading = ref(false)
const queryTime = ref(0)
const tableData = ref<any[]>([])
const currentConditions = ref<Record<string, any>>({})
const selectedRow = ref<any>(null)
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const upperPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
// ==================== ScanBox 事件 ====================
function handleConditionChange(conditions: Record<string, any>) {
currentConditions.value = conditions ?? {}
pagination.currentPage = 1
upperPagination.currentPage = 1
fetchData()
}
function handleConditionReset() {
currentConditions.value = { is_blocked: { value: 0, operator: 'eq', type: 'select' } }
pagination.currentPage = 1; upperPagination.currentPage = 1
fetchData()
}
function handleConditionClear() {
currentConditions.value = {}
pagination.currentPage = 1; upperPagination.currentPage = 1
fetchData()
}
function handleRowClick(row: any) { selectedRow.value = row }
// ==================== 数据查询 ====================
function buildWhereFromConditions(conditions: Record<string, any>) {
const where: Record<string, any> = {}
for (const [key, cond] of Object.entries(conditions)) {
if (cond === undefined || cond === null || cond === '') continue
if (typeof cond === 'object' && cond.value !== undefined) {
const val = cond.value
const op = cond.operator || 'eq'
// 空值跳过
if (val === undefined || val === null || val === '' || (Array.isArray(val) && val.length === 0)) continue
where[key] = { operator: op, value: val }
} else {
where[key] = { operator: 'eq', value: cond }
}
}
return where
}
async function fetchData() {
loading.value = true
const start = Date.now()
try {
const where = buildWhereFromConditions(currentConditions.value)
const params: any = {
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
where,
}
const res: any = await inboxGroupList(params)
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
const data = res.data ?? res
tableData.value = data.list ?? []
const total = data.total ?? 0
pagination.total = total; upperPagination.total = total
} else {
tableData.value = []; pagination.total = 0; upperPagination.total = 0
ElMessage.error(res?.message || '获取群组列表失败')
}
} catch (error) {
console.error('获取群组列表失败:', error)
tableData.value = []; pagination.total = 0; upperPagination.total = 0
} finally { loading.value = false; queryTime.value = Date.now() - start }
}
function handleRefresh() {
upperPagination.currentPage = 1
fetchData()
}
function handleSortChange(_sort: { prop: string; order: string }) {
// 预留排序事件处理
}
function handlePageChange(page: number) { pagination.currentPage = page; upperPagination.currentPage = page; fetchData() }
function handlePageSizeChange(size: number) { pagination.pageSize = size; upperPagination.pageSize = size; pagination.currentPage = 1; upperPagination.currentPage = 1; fetchData() }
// ==================== 生成绑群码 ====================
const bindDialogVisible = ref(false)
const bindLoading = ref(false)
const storeLoading = ref(false)
const bindFormRef = ref<FormInstance>()
const storeList = ref<any[]>([])
const bindForm = reactive({ storeId: null as number | null, subType: '' as string })
const bindRules: FormRules = { storeId: [{ required: true, message: '请选择货主', trigger: 'change' }] }
const resultDialogVisible = ref(false)
const generatedCode = ref('')
function showBindDialog() { bindForm.storeId = null; bindForm.subType = ''; bindDialogVisible.value = true; loadStoreList() }
function resetBindForm() { bindFormRef.value?.resetFields() }
async function loadStoreList() {
storeLoading.value = true
try {
const storesRes: any = await loadStores()
const rawStores = extractStoreListFromResponse(storesRes)
storeList.value = mapStoreListToSelectOptions(rawStores)
// 同时注入 ScanBox 货主筛选选项
fillStoreScanFieldOptions(availableFields, rawStores)
} catch {
storeList.value = []
fillStoreScanFieldOptions(availableFields, [])
} finally { storeLoading.value = false }
}
async function handleGenerateCode() {
const valid = await bindFormRef.value?.validate().catch(() => false)
if (!valid) return
bindLoading.value = true
try {
const params: any = { storeId: bindForm.storeId! }
if (bindForm.subType) params.subType = bindForm.subType
const res: any = await inboxBindCode(params)
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
generatedCode.value = res.data?.code ?? ''
bindDialogVisible.value = false; resultDialogVisible.value = true
} else { ElMessage.error(res?.message || '生成绑群码失败') }
} catch { ElMessage.error('生成绑群码失败') } finally { bindLoading.value = false }
}
function handleCopyGeneratedCode() {
navigator.clipboard.writeText(generatedCode.value).then(() => ElMessage.success('已复制到剪贴板')).catch(() => ElMessage.warning('复制失败,请手动复制'))
}
// ==================== 编辑群信息 ====================
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, 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 }>>([])
const expressCodeOptions = ref<Array<{ label: string; value: string }>>([])
const expressLoading = ref(false)
function handleEdit(row: any) {
editingRow.value = row
editForm.groupId = row.group_id ?? ''; editForm.groupName = row.group_name ?? ''
editForm.groupType = row.group_type ?? ''; editForm.subType = row.sub_type ?? ''
editForm.storeId = row.store_id ?? null
editForm.expressInterfaces = Array.isArray(row.express_interfaces)
? row.express_interfaces.map((item: any) => (typeof item === 'object' ? item.id : item))
: []
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() }
}
function resetEditForm() { editFormRef.value?.resetFields(); editingRow.value = null }
async function loadExpressCodes() {
try {
const expressRes: any = await expressIndexGetExpressList({ systemOnly: true })
const expressList = expressRes?.data?.list || expressRes?.data || []
expressCodeOptions.value = expressList.map((item: any) => ({
label: `${item.code || ''} - ${item.name || ''}`,
value: item.code || '',
}))
} catch {
expressCodeOptions.value = []
}
}
async function loadExpressInterfacesByCode() {
expressLoading.value = true
try {
const ifaceRes: any = await loadExpressInterfaces(
editForm.systemExpressCode ? { systemExpressCode: editForm.systemExpressCode } : undefined
)
expressInterfaceOptions.value = ifaceRes?.expressInterfaces || []
} catch {
expressInterfaceOptions.value = []
} finally {
expressLoading.value = false
}
}
function onSystemExpressCodeChange() {
editForm.expressInterfaces = []
loadExpressInterfacesByCode()
}
function onEditGroupTypeChange() {
editForm.subType = ''
if (editForm.groupType !== 'express') { editForm.expressInterfaces = []; editForm.systemExpressCode = '' }
if (editForm.groupType !== 'store') editForm.storeId = null
if (editForm.groupType === 'express') { loadExpressCodes(); loadExpressInterfacesByCode() }
}
async function handleSubmitEdit() {
const valid = await editFormRef.value?.validate().catch(() => false)
if (!valid) return
editLoading.value = true
try {
const params: any = { id: editingRow.value.id }
if (editForm.groupType) params.groupType = editForm.groupType
if (editForm.subType) params.subType = editForm.subType
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 || '群信息修改成功')
editDialogVisible.value = false; fetchData()
} else { ElMessage.error(res?.message || '修改失败') }
} catch { ElMessage.error('修改失败') } finally { editLoading.value = false }
}
// ==================== 禁用/启用 ====================
async function handleToggleDisable(row: any) {
const action = row.is_blocked ? '启用' : '禁用'
try {
await ElMessageBox.confirm(`确定要${action}群组「${row.group_name}」吗?`, `${action}确认`, {
type: 'warning',
// 按钮尺寸对齐面板表单底部按钮(Element Plus small)
buttonSize: 'small'
})
const res: any = await inboxGroupDisable({ id: row.id, isBlocked: row.is_blocked ? 0 : 1 })
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
ElMessage.success(res.data?.message || res.message || `群已${action}`); fetchData()
} else { ElMessage.error(res?.message || `${action}失败`) }
} catch { /* 用户取消 */ }
}
// ==================== 清空群类型配置 ====================
async function handleResetGroupConfig(row: any) {
try {
await ElMessageBox.confirm(
`确定要清空群组「${row.group_name}」的群类型配置吗?群类型/子类型/货主/快递接口/系统快递编码将被清空,AI 自动回复与模板消息回复将关闭,仅保留群创建时信息。`,
'清空配置确认',
{
type: 'warning',
confirmButtonText: '清空',
confirmButtonClass: 'el-button--danger',
// 按钮尺寸对齐面板表单底部按钮(Element Plus small)
buttonSize: 'small'
}
)
const res: any = await inboxGroupReset({ id: row.id })
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
ElMessage.success(res.data?.message || res.message || '群类型配置已清空'); fetchData()
} else { ElMessage.error(res?.message || '清空失败') }
} catch { /* 用户取消 */ }
}
// ==================== 群消息 ====================
const messagesDialogVisible = ref(false)
const msgLoading = ref(false)
const currentGroupId = ref('')
const currentGroupName = ref('')
const msgTableData = ref<any[]>([])
const msgFilter = reactive({ direction: '' as string, keyword: '' as string })
const msgPagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
function handleViewMessages(row: any) {
currentGroupId.value = row.group_id; currentGroupName.value = row.group_name
msgFilter.direction = ''; msgFilter.keyword = ''
msgPagination.currentPage = 1; msgPagination.pageSize = 20; msgTableData.value = []
messagesDialogVisible.value = true; fetchGroupMessages()
}
async function fetchGroupMessages() {
msgLoading.value = true
try {
const params: any = { groupId: currentGroupId.value, page: msgPagination.currentPage, pageSize: msgPagination.pageSize }
if (msgFilter.direction) params.direction = msgFilter.direction
if (msgFilter.keyword) params.keyword = msgFilter.keyword
const res: any = await inboxGroupMessages(params)
if (res && (res.code === 1 || res.code === 200 || res.code === 20000)) {
const data = res.data ?? res; msgTableData.value = data.list ?? []; msgPagination.total = data.pagination?.total ?? 0
} else { msgTableData.value = []; msgPagination.total = 0; ElMessage.error(res?.message || '获取群消息失败') }
} catch { msgTableData.value = []; msgPagination.total = 0 } finally { msgLoading.value = false }
}
function onMsgPageChange(page: number) { msgPagination.currentPage = page; fetchGroupMessages() }
function onMsgPageSizeChange(size: number) { msgPagination.pageSize = size; msgPagination.currentPage = 1; fetchGroupMessages() }
// ==================== 默认筛选:仅显示启用群组 ====================
const initialConditions = {
is_blocked: { value: 0, operator: 'eq', type: 'select' },
}
onMounted(() => { loadStoreList(); fetchData() })
</script>
<style scoped lang="scss">
@use "@/styles/list-page.scss";
@use "@/styles/status-text.scss";
.wave-operation-actions {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
flex-wrap: wrap;
}
.result-content {
text-align: center;
.result-tip { font-size: 13px; color: #606266; margin-bottom: 16px; }
.result-code-box {
display: flex; align-items: center; justify-content: center; gap: 12px;
padding: 16px; background: #f5f7fa; border-radius: 6px;
.result-code { font-size: 20px; font-weight: 700; color: #409eff; letter-spacing: 2px; font-family: monospace; }
}
}
.form-tip { margin-left: 10px; font-size: 12px; color: #909399; line-height: 1.4; }
/* 群消息:表格容器与分页(对齐「批量导入商品」) */
.msg-table-wrapper { margin-bottom: 0; }
.msg-pagination { margin-right: 0; }
.empty-tip { color: #909399; font-size: 13px; padding: 16px; text-align: center; }
/* 生成绑群码:面板结构 / 尺寸对齐「手工录入运单号」(ManualWaybillForm) */
.task-panel {
display: flex;
flex-direction: column;
max-height: calc(100vh - 96px);
background: #fff;
color: #303133;
&__head {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 16px 16px 8px;
flex-shrink: 0;
}
&__titles {
flex: 1;
min-width: 0;
h2 {
margin: 0;
font-size: 18px;
line-height: 24px;
font-weight: 400;
color: #303133;
}
p {
margin: 4px 0 0;
font-size: 12px;
line-height: 18px;
color: #909399;
}
}
&__close {
width: 24px;
height: 24px;
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
border-radius: 4px;
background: transparent;
color: #909399;
cursor: pointer;
transition: color 0.2s;
svg {
width: 12px;
height: 12px;
}
&:hover {
color: #409eff;
}
}
&__body {
flex: 1;
min-height: 0;
padding: 6px 16px 0;
display: flex;
flex-direction: column;
overflow-y: auto;
}
/* 工具栏:筛选控件 + 统计文案(对齐「批量导入商品」) */
&__toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-shrink: 0;
margin-bottom: 10px;
}
&__toolbar-main {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
:deep(.el-button) {
margin-left: 0;
margin-right: 0;
}
}
&__meta {
font-size: 12px;
color: #909399;
white-space: nowrap;
}
/* 列表区(表格容器) */
&__section {
display: flex;
flex-direction: column;
gap: 6px;
min-height: 0;
flex-shrink: 0;
}
&__form {
display: flex;
flex-direction: column;
gap: 8px;
}
&__field {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 40px;
padding: 8px 12px;
border: 1px solid #ebeef5;
border-radius: 4px;
background: #fafafa;
/* 输入行:去掉灰色容器,与静态信息行区分 */
&--input {
align-items: flex-start;
min-height: 0;
padding: 4px 0 0 12px;
border: none;
border-radius: 0;
background: transparent;
.task-panel__field-label {
padding-top: 7px;
&.is-required::before {
top: 7px;
}
}
}
/* 控件行(开关):与输入行同尺寸,去掉灰色容器 */
&--control {
align-items: flex-start;
min-height: 36px;
padding: 4px 0 0 12px;
border: none;
border-radius: 0;
background: transparent;
.task-panel__field-label {
padding-top: 7px;
&.is-required::before {
top: 7px;
}
}
.task-panel__field-control {
display: flex;
align-items: center;
min-height: 32px;
}
}
}
/* 静态信息行的值(群 ID / 群名称) */
&__field-value {
font-size: 13px;
font-weight: 500;
color: #303133;
text-align: right;
word-break: break-all;
}
/* 标签列固定宽度(含必填星号占位):保证各选项输入框左边缘对齐、长度一致 */
&__field-label {
position: relative;
flex: 0 0 88px;
width: 88px;
padding-left: 10px;
box-sizing: border-box;
font-size: 12px;
line-height: 20px;
color: #606266;
text-align: left;
white-space: nowrap;
&.is-required::before {
content: '*';
position: absolute;
left: 0;
top: 0;
line-height: 20px;
color: #f56c6c;
}
}
&__field-control {
flex: 1;
min-width: 0;
}
&__form-tip {
margin: 8px 0 0;
padding: 8px 12px;
border-radius: 4px;
background: #f4f4f5;
font-size: 12px;
line-height: 18px;
color: #909399;
}
&__foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 16px 16px;
flex-shrink: 0;
}
&__hint {
font-size: 12px;
color: #909399;
}
&__actions {
display: flex;
align-items: center;
justify-content: flex-end;
width: 100%;
/* 与工具栏按钮组(OrderToolbarButtonGroup)保持一致:gap 6px */
gap: 6px;
:deep(.el-button) {
margin-left: 0;
margin-right: 0;
}
}
}
/* 面板内嵌 el-form-item:占满剩余宽度,去掉默认间距,错误提示改回文档流内展示 */
.task-panel__form {
:deep(.el-form-item) {
/* 关键:行内布局下必须撑满剩余宽度,否则下拉框会收缩到内容宽度、右侧对不齐 */
flex: 1;
min-width: 0;
margin-bottom: 0;
}
:deep(.el-form-item__content) {
margin-left: 0 !important;
width: 100%;
line-height: 1.4;
}
:deep(.el-form-item__error) {
position: static;
padding-top: 4px;
}
}
</style>
<style lang="scss">
/* el-dialog 会被 append 到 body:去掉默认头/内边距,统一交给面板 */
.el-dialog.bind-code-dialog,
.el-dialog.edit-group-dialog,
.el-dialog.group-messages-dialog {
padding: 0;
overflow: hidden;
.el-dialog__header {
display: none;
}
.el-dialog__body {
padding: 0;
}
}
</style>