This commit is contained in:
yin 2026-09-23 18:10:36 +08:00
parent 6a2e1c055e
commit c926beb226
8 changed files with 2568 additions and 316 deletions

View File

@ -18,12 +18,18 @@ export type WeChatAuthUrlPayload = {
[key: string]: unknown
}
/** wechat.getAuthUrl 入参:warehouse_id 可选,缺省取当前登录用户所属仓库 */
export type WeChatAuthUrlParams = {
/** 仓库 ID(可选;缺省取当前登录用户所属仓库) */
warehouse_id?: number
}
/**
* 获取微信授权链接(由用户点击「去授权」时调用,避免页面加载即跳转/弹窗被拦截)。
* 返回值中链接字段名做多形态兼容,取值见页面 pickUrl()。
*/
export function wechatGetAuthUrl(
data: Record<string, unknown> = {}
data: WeChatAuthUrlParams = {}
): Promise<{ code?: number; message?: string; data?: WeChatAuthUrlPayload } & Record<string, unknown>> {
return request({
url: '/system',
@ -78,7 +84,14 @@ export type WeChatQueryAuthData = {
[key: string]: unknown
}
export function wechatQueryAuth(): Promise<
export type WeChatQueryAuthParams = {
/** 认证任务 ID(可选;缺省时用库中 auth_task_id;小程序已认证时无需传入) */
taskid?: string
}
export function wechatQueryAuth(
data: WeChatQueryAuthParams = {}
): Promise<
{ code?: number; message?: string; data?: WeChatQueryAuthData } & Record<string, unknown>
> {
return request({
@ -89,41 +102,66 @@ export function wechatQueryAuth(): Promise<
v,
timestamp: new Date().getTime()
},
data: {},
data,
isSystemApi: true
} as any)
}
/**
* 发起小程序认证(wechat.wxaauth)—— 后端分步:
* 图片字段传 COS 文件 URL(http/https)→ 后端下载并调微信 `wxa/sec/wxaapi/uploadmedia` 换 media_id
* → 替换请求体 → 调微信 `wxa/sec/wxaapi/wxaauth`(权限集 18)一步提交。
* 图片字段传 COS 文件 URL(http/https)→ 后端下载并调微信 `wxa/sec/uploadauthmaterial` 换 mediaid
* → 替换请求体 → 以 `{ auth_data }` 包裹调微信 `wxa/sec/wxaauth`(权限集 18)一步提交。
* 成功后后端回写 `wms_wechat_app.auth_task_id`/`auth_apply_status`,返回 `taskid` 与 `auth_url`;
* 小程序已认证(verify_type_id >= 0)时会拒绝重复发起。
*/
export type WeChatWxaauthContactInfo = {
/** 联系人姓名(必填) */
name: string
/** 联系人邮箱(必填) */
email: string
/** 联系人手机(选填) */
mobile?: string
}
/** wechat.wxaauth 入参(新版 auth_data:6 个必填 + 下列可选字段) */
export type WeChatWxaauthParams = {
/** 联系人类型:1 法人、2 管理员 */
contact_type: number
/** 联系人姓名 */
contact_name: string
/** 账号主体类型:1 企业、12 个体工商户、15 个人 */
customer_type: number
/** 小程序账号名称 */
account_name: string
/** 命名类型:1 基于自选词汇、2 基于商标 */
account_name_type: number
/** 支付方式:1 消耗服务商预购包、2 小程序开发者自行支付 */
pay_type: number
/** 第三方联系电话 */
third_party_phone: string
/** 联系人信息(name/email 必填,mobile 选填) */
contact_info: WeChatWxaauthContactInfo
/** 发票信息(服务商代缴可不传) */
invoice_info?: Record<string, unknown>
/** 主体资质材料(mediaid 或 COS URL;**非个人主体必填**,单张) */
qualification?: string
/** 资质其他材料(mediaid / COS URL 数组,≤10 张) */
qualification_other?: string[]
/** 名称关键词补充材料(mediaid / COS URL 数组) */
account_supplemental?: string[]
/** 个人认证身份信息(选填) */
auth_identification?: Record<string, unknown>
/** 个人认证身份材料(mediaid / COS URL 数组) */
auth_ident_material?: string[]
/** 服务商代缴时必填:服务商 AppID */
service_appid?: string
/** 打回重填(reauth)时必填:原认证任务 ID */
taskid?: string
/**
* 其余白名单字段(后端透传微信 wxaauth 请求体):
* contact_idcard_number/contact_mobile/contact_cert_photo/contact_nationality/contact_address/contact_email、
* business_license_copy/business_license_number/business_license_address/business_license_expiration_date、
* legal_persona_media/legal_persona_idcard_copy/legal_persona_name/legal_persona_idcard_number/
* legal_persona_address/legal_persona_idcard_expiration_date、business_license_type/apply_type/
* extra_wxa_secure_info/nickname、pic_list/qualification_list/qualification_extra/license_list/
* statement_list、store_name/store_main_industry/store_scale/store_floor/store_address/open_type/pay_type。
* 图片字段(contact_cert_photo/business_license_copy/legal_persona_idcard_copy/legal_persona_media、
* pic_list 项的 pic_url、qualification_list 项 licence_list/certificate_list 的 value、statement_list 项的 value)
* 支持传 COS 文件 URL;传非 URL 时视为已传 media_id 原样透传。
* 其余白名单字段(后端透传 auth_data 原样给微信)。
* 图片字段(qualification / qualification_other[] / account_supplemental[] / auth_ident_material[])
* 支持传 COS 文件 URL;传非 URL 时视为已传 mediaid 原样透传。
*/
[key: string]: unknown
}
export type WeChatWxaauthData = {
/** 小程序 AppID */
appid?: string
/** 认证任务 ID(已回写 auth_task_id,供 wechat.queryauth 查进度) */
taskid?: string
/** 小程序管理员认证链接(可选,打开后继续完成认证) */
@ -406,6 +444,284 @@ export function wechatSubmitAudit(
} as any)
}
/** 用户列表 where 条件值:operator 结构(operator 支持 eq/ne/gt/lt/ge/le/in/notin/between/like/contains/notlike/startswith/endswith/isnull/isnotnull) */
export type WeChatUserWhereValue = {
operator?: string
value?: unknown
}
/** userList 的 where 字段白名单(后端) */
export type WeChatUserWhereField =
| 'id'
| 'user_id'
| 'app_id'
| 'openid'
| 'unionid'
| 'nickname'
| 'sex'
| 'login_time'
| 'login_count'
| 'created_at'
| 'updated_at'
/**
* userList 的 sort 字段白名单(后端)= where 白名单 + `agreement_version_id`
* (协议版本记录 id,小程序登录时自动回写)
*/
export type WeChatUserSortField = WeChatUserWhereField | 'agreement_version_id'
export type WeChatUserListParams = {
/** 指定 wms_wechat_app.id(可选,须属当前仓库且启用;缺省取当前仓库全部启用小程序) */
app_id?: number
/** 查询条件:字段级 `{ operator, value }`(字段白名单见 WeChatUserWhereField) */
where?: Partial<Record<WeChatUserWhereField, WeChatUserWhereValue>>
/** 分页:默认 page=1、pageSize=20 */
pagination?: { page?: number; pageSize?: number }
/** 排序:sortField 白名单见 WeChatUserSortField,默认 updated_at DESC */
sort?: { sortField?: WeChatUserSortField; sortOrder?: 'asc' | 'desc' | 'ASC' | 'DESC' }
}
/** 用户列表项(后端已排除 session_key / access_token / refresh_token 等敏感字段) */
export type WeChatUserItem = {
id?: number
/** 绑定的真实账号 ID(0=未绑定) */
user_id?: number
app_id?: number
openid?: string
unionid?: string
nickname?: string
/** 微信性别:0 未知、1 男、2 女 */
sex?: number
headimgurl?: string
login_time?: number | string
login_count?: number
/** 是否已绑定真实账号(user_id > 0) */
is_bound?: boolean
/**
* 用户最近一次登录时同意的**协议版本记录 id**(wms_wechat_agreement_version.id,由小程序 loginByCode 自动回写);
* 0 / 空表示未记录同意版本;可传给 `wechat.getAgreementVersion` 查看该版本协议原文。
*/
agreement_version_id?: number
created_at?: string
updated_at?: string
[key: string]: unknown
}
export type WeChatUserListData = {
list: WeChatUserItem[]
pagination: { page?: number; pageSize?: number; total?: number }
/** 本次查询命中的小程序列表(id/appid/nickname) */
apps?: { id?: number; appid?: string; nickname?: string }[]
[key: string]: unknown
}
/**
* 拉取当前仓库小程序的用户列表(wechat.userList)——
* 按 ctx.user.store_id 取仓库启用小程序(可用 app_id 指定单个,须属当前仓库),
* 支持 where(operator 结构)/ pagination / sort;响应已排除 session_key / access_token / refresh_token 等敏感字段,
* 并附 `is_bound`(user_id > 0 已绑定真实账号)与 `agreement_version_id`(协议版本记录 id,
* 由小程序 loginByCode 自动回写,可传给 wechat.getAgreementVersion 拉取该版本协议内容)。
*/
export function wechatUserList(
data: WeChatUserListParams = {}
): Promise<{ code?: number; message?: string; data?: WeChatUserListData } & Record<string, unknown>> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.userList',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/**
* 获取指定协议版本内容(wechat.getAgreementVersion)—— **需登录、免接口权限**。
* 传版本记录 id(`wms_wechat_agreement_version.id`,可由 `wechat.userList` 的 `agreement_version_id` 获取),
* 后端校验该版本对应 appid 属于**当前仓库的启用小程序**后返回协议内容(含 appid / nickname / text)。
*/
export type WeChatAgreementVersionParams = {
/** 协议版本记录 id(wms_wechat_agreement_version.id) */
id: number
}
export type WeChatAgreementVersionData = {
/** 协议版本记录 id */
id: number
/** 小程序 AppID */
appid: string
/** 小程序名称 */
nickname?: string
/** 协议富文本内容 */
text: string
}
export function wechatGetAgreementVersion(
data: WeChatAgreementVersionParams
): Promise<
{ code?: number; message?: string; data?: WeChatAgreementVersionData } & Record<string, unknown>
> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.getAgreementVersion',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/**
* 按工号绑定微信(wechat.bindByEmployee)—— PC 管理员操作,需登录 + 仓库上下文 + `wechat.bindByEmployee` 权限。
* 传工号 id(wms_account_store_employee.id)与微信绑定记录 id(wms_user_oauth.id,来自 wechat.userList 的 id),
* 后端查工号关联的账号 id 后写入 `wms_user_oauth.user_id` 完成绑定。
*
* - 已绑定**同一**账号时幂等返回(`already_bound=true`);
* - 以下情况会被拒绝:该微信已绑定其他账号、工号已解除或不属于当前仓库、
* 微信记录不属于当前仓库的小程序、账号被禁用。
*/
export type WeChatBindByEmployeeParams = {
/** 工号 id(wms_account_store_employee.id) */
id: number
/** 微信绑定记录 id(wms_user_oauth.id,可在 wechat.userList 结果中获取) */
oauth_id: number
}
export type WeChatBindByEmployeeData = {
/** 微信绑定记录 id */
oauth_id: number
/** 是否此前已绑定同一账号(幂等调用) */
already_bound: boolean
/** 工号信息 */
employee: { id?: number; account_id?: number; store_id?: number; real_name?: string }
/** 绑定的账号信息 */
account: { id?: number; username?: string; real_name?: string }
}
export function wechatBindByEmployee(
data: WeChatBindByEmployeeParams
): Promise<
{ code?: number; message?: string; data?: WeChatBindByEmployeeData } & Record<string, unknown>
> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.bindByEmployee',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/**
* 获取当前仓库小程序的「用户须知」(wechat.getUserAgreement)—— 需登录 + 仓库上下文。
* 按当前登录仓库取启用小程序(wms_wechat_app),从副表拉取**最新版本**(id 自增即最新);
* 仓库未绑定小程序时提示「无小程序,需要先绑定」,无版本时提示「该小程序暂无用户须知」。
*/
export type WeChatUserAgreementData = {
/** 当前仓库小程序 AppID */
appid: string
/** 小程序名称 */
nickname?: string
/** 最新协议版本记录 id(wms_wechat_agreement_version.id,id 自增即最新) */
version_id: number
/** 用户须知富文本内容 */
text: string
}
export function wechatGetUserAgreement(): Promise<
{ code?: number; message?: string; data?: WeChatUserAgreementData } & Record<string, unknown>
> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.getUserAgreement',
v,
timestamp: new Date().getTime()
},
data: {},
isSystemApi: true
} as any)
}
/**
* 获取小程序用户须知富文本(wechat.getUserAgreementText)—— **免登录**,入参 `appId`。
* 按 appid 查 `wms_wechat_app.user_agreement`,Redis 缓存 24 小时(`from_cache` 标识是否命中)。
*
* ⚠️ 这是给**小程序端**(无登录态)读取用户须知用的;网页端有登录态,回显请用 wechat.getUserAgreement。
*/
export type WeChatUserAgreementTextParams = {
/** 小程序 AppID(wx...) */
appId: string
}
export type WeChatUserAgreementTextData = {
/** 小程序 AppID */
appid: string
/** 最新协议版本记录 id(wms_wechat_agreement_version.id,id 自增即最新) */
version_id: number
/** 用户须知富文本内容 */
text: string
/** 是否命中 24h 缓存 */
from_cache: boolean
}
export function wechatGetUserAgreementText(
data: WeChatUserAgreementTextParams
): Promise<
{ code?: number; message?: string; data?: WeChatUserAgreementTextData } & Record<string, unknown>
> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.getUserAgreementText',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
/**
* 设置当前仓库小程序的「用户须知」(wechat.setUserAgreement)—— 需登录 + 仓库上下文。
* **每次提交自动新增一个版本**(直接插入副表 `wms_wechat_agreement_version`,id 自增即最新),
* 并清除 getUserAgreementText 的 24h 缓存;`text` 可传空字符串。
*/
export type WeChatSetUserAgreementParams = {
/** 用户须知富文本内容(可传空字符串清空) */
text: string
}
export function wechatSetUserAgreement(
data: WeChatSetUserAgreementParams
): Promise<
{ code?: number; message?: string; data?: WeChatUserAgreementData } & Record<string, unknown>
> {
return request({
url: '/system',
method: 'post',
params: {
method: 'wechat.setUserAgreement',
v,
timestamp: new Date().getTime()
},
data,
isSystemApi: true
} as any)
}
export const wechat = {
getAuthUrl: wechatGetAuthUrl,
queryAuth: wechatQueryAuth,
@ -415,7 +731,13 @@ export const wechat = {
getTemplateList: wechatGetTemplateList,
commit: wechatCommit,
getTrialQRCode: wechatGetTrialQRCode,
submitAudit: wechatSubmitAudit
submitAudit: wechatSubmitAudit,
userList: wechatUserList,
bindByEmployee: wechatBindByEmployee,
getUserAgreement: wechatGetUserAgreement,
getAgreementVersion: wechatGetAgreementVersion,
getUserAgreementText: wechatGetUserAgreementText,
setUserAgreement: wechatSetUserAgreement
}
export default wechat

View File

@ -0,0 +1,540 @@
<!--
RichTextEditor —— 轻量富文本编辑器(自研,无三方依赖)
设计要点:
· 基于 `contenteditable` + `document.execCommand`,v-model 直接收发 **HTML 字符串**。
· 只产出**基础标签**(p / h2 / h3 / blockquote / ul / ol / li / b / i / u / s / a / img / br),
不带 class、不带内联 style(已开启 styleWithCSS=false),便于微信小程序 `rich-text` 渲染。
· 粘贴默认**转纯文本**,避免带入外部样式、脚本、外链 class。
· 图片走项目统一 COS 直传(`uploadImageToCos`),插入绝对地址 <img>。
· 支持「源码」模式,直接编辑 HTML(用于微调标签或粘贴精确 HTML)。
用法:
<RichTextEditor v-model="html" placeholder="请输入内容" min-height="280px" />
<RichTextEditor v-model="html" disabled />
-->
<template>
<div class="rich-editor" :class="{ 'is-disabled': disabled, 'is-source': sourceMode }">
<div class="rich-editor__toolbar">
<template v-if="!sourceMode">
<button
v-for="btn in inlineButtons"
:key="btn.command"
type="button"
class="rich-editor__btn"
:title="btn.title"
:disabled="disabled"
@mousedown.prevent
@click="exec(btn.command)"
>
<span :style="btn.style">{{ btn.label }}</span>
</button>
<i class="rich-editor__divider" />
<button
v-for="btn in blockButtons"
:key="btn.value"
type="button"
class="rich-editor__btn is-wide"
:title="btn.title"
:disabled="disabled"
@mousedown.prevent
@click="exec('formatBlock', btn.value)"
>
{{ btn.label }}
</button>
<i class="rich-editor__divider" />
<button
v-for="btn in listButtons"
:key="btn.command"
type="button"
class="rich-editor__btn is-wide"
:title="btn.title"
:disabled="disabled"
@mousedown.prevent
@click="exec(btn.command)"
>
{{ btn.label }}
</button>
<i class="rich-editor__divider" />
<button
type="button"
class="rich-editor__btn is-wide"
title="减少缩进"
:disabled="disabled"
@mousedown.prevent
@click="exec('outdent')"
>
⇤
</button>
<button
type="button"
class="rich-editor__btn is-wide"
title="增加缩进"
:disabled="disabled"
@mousedown.prevent
@click="exec('indent')"
>
⇥
</button>
<i class="rich-editor__divider" />
<button
type="button"
class="rich-editor__btn is-wide"
title="插入链接"
:disabled="disabled"
@mousedown.prevent
@click="insertLink"
>
链接
</button>
<button
type="button"
class="rich-editor__btn is-wide"
title="取消所选文字的链接"
:disabled="disabled"
@mousedown.prevent
@click="exec('unlink')"
>
取消链接
</button>
<i class="rich-editor__divider" />
<button
type="button"
class="rich-editor__btn is-wide"
:title="uploading ? '图片上传中…' : '上传并插入图片'"
:disabled="disabled || uploading"
@mousedown.prevent
@click="pickImage"
>
{{ uploading ? '上传中' : '图片' }}
</button>
<button
type="button"
class="rich-editor__btn is-wide"
title="清除所选内容的格式"
:disabled="disabled"
@mousedown.prevent
@click="exec('removeFormat')"
>
清除格式
</button>
</template>
<span class="rich-editor__spacer" />
<button
type="button"
class="rich-editor__btn is-wide is-toggle"
:class="{ 'is-active': sourceMode }"
:title="sourceMode ? '切回可视化编辑' : '直接编辑 HTML 源码'"
:disabled="disabled"
@mousedown.prevent
@click="toggleSource"
>
{{ sourceMode ? '可视化' : '源码' }}
</button>
</div>
<!-- 可视化编辑区 -->
<div
v-if="!sourceMode"
ref="editableRef"
class="rich-editor__body"
role="textbox"
aria-multiline="true"
:contenteditable="!disabled"
:data-placeholder="placeholder"
:style="{ minHeight }"
@input="handleInput"
@paste="handlePaste"
/>
<!-- 源码模式 -->
<textarea
v-else
v-model="sourceText"
class="rich-editor__source"
spellcheck="false"
:style="{ minHeight }"
placeholder="直接编辑 HTML 源码,例如 <p>用户须知</p>"
@input="handleSourceInput"
/>
</div>
</template>
<script setup lang="ts">
import { nextTick, onMounted, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { uploadImageToCos } from '@/utils/cosImageUpload'
defineOptions({ name: 'RichTextEditor' })
const props = withDefaults(
defineProps<{
/** HTML 字符串(v-model) */
modelValue?: string
/** 空内容时的占位提示 */
placeholder?: string
/** 编辑区最小高度 */
minHeight?: string
/** 只读 */
disabled?: boolean
}>(),
{
modelValue: '',
placeholder: '请输入内容',
minHeight: '260px',
disabled: false
}
)
const emit = defineEmits<{ (e: 'update:modelValue', value: string): void }>()
/** 行内格式按钮 */
const inlineButtons: { command: string; label: string; title: string; style?: string }[] = [
{ command: 'bold', label: 'B', title: '加粗', style: 'font-weight: 700' },
{ command: 'italic', label: 'I', title: '斜体', style: 'font-style: italic' },
{ command: 'underline', label: 'U', title: '下划线', style: 'text-decoration: underline' },
{ command: 'strikeThrough', label: 'S', title: '删除线', style: 'text-decoration: line-through' }
]
/** 块级格式按钮(formatBlock) */
const blockButtons: { value: string; label: string; title: string }[] = [
{ value: 'p', label: '正文', title: '正文段落' },
{ value: 'h2', label: 'H2', title: '标题 2' },
{ value: 'h3', label: 'H3', title: '标题 3' },
{ value: 'blockquote', label: '引用', title: '引用' }
]
/** 列表按钮 */
const listButtons: { command: string; label: string; title: string }[] = [
{ command: 'insertOrderedList', label: '1.', title: '有序列表' },
{ command: 'insertUnorderedList', label: '•', title: '无序列表' }
]
const editableRef = ref<HTMLDivElement>()
const sourceMode = ref(false)
const sourceText = ref('')
const uploading = ref(false)
/** 防止「DOM → props → DOM」回写造成的光标跳动 */
let writingFromProp = false
/** 把 props.modelValue 同步到 DOM(仅在真的不一致时写,避免打断输入) */
async function syncFromProp(): Promise<void> {
const el = editableRef.value
if (!el) return
const next = props.modelValue || ''
if (el.innerHTML === next) return
writingFromProp = true
el.innerHTML = next
writingFromProp = false
}
watch(
() => props.modelValue,
() => {
if (writingFromProp || sourceMode.value) return
void syncFromProp()
}
)
watch(sourceMode, async (on) => {
if (on) {
// 进入源码模式:取当前 DOM 的 HTML(比 props 更实时)
sourceText.value = editableRef.value?.innerHTML ?? props.modelValue ?? ''
await nextTick()
return
}
// 退出源码模式:把源码写回 DOM
await nextTick()
const el = editableRef.value
if (el) {
writingFromProp = true
el.innerHTML = sourceText.value || ''
writingFromProp = false
el.focus()
}
})
onMounted(() => {
void syncFromProp()
// Enter 生成 <p>;加粗/斜体等输出标签(<b>/<i>/<u>)而不是内联 style —— 便于小程序 rich-text 渲染
try {
document.execCommand('defaultParagraphSeparator', false, 'p')
document.execCommand('styleWithCSS', false, 'false')
} catch {
/* 老浏览器不支持时忽略 */
}
})
function focusEditable(): void {
if (sourceMode.value) return
editableRef.value?.focus()
}
/** 上报当前 HTML */
function emitValue(): void {
const el = editableRef.value
if (!el) return
const html = el.innerHTML
if (html !== props.modelValue) emit('update:modelValue', html)
}
function handleInput(): void {
emitValue()
}
function exec(command: string, value?: string): void {
if (props.disabled) return
focusEditable()
document.execCommand(command, false, value)
emitValue()
}
function handleSourceInput(): void {
if (sourceText.value === props.modelValue) return
emit('update:modelValue', sourceText.value)
}
function toggleSource(): void {
if (props.disabled) return
sourceMode.value = !sourceMode.value
}
function escapeHtml(text: string): string {
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
}
/** 粘贴:默认转纯文本(按空行分段),避免带入外部样式与脚本 */
function handlePaste(e: ClipboardEvent): void {
if (props.disabled) return
e.preventDefault()
const text = e.clipboardData?.getData('text/plain') ?? ''
if (!text) return
focusEditable()
const html = text
.split(/\r?\n/)
.map((line) => (line.trim() ? `<p>${escapeHtml(line)}</p>` : '<p><br/></p>'))
.join('')
document.execCommand('insertHTML', false, html)
emitValue()
}
/** 插入链接(http/https) */
async function insertLink(): Promise<void> {
if (props.disabled) return
let url = ''
try {
const { value } = await ElMessageBox.prompt(
'请输入链接地址(需以 http:// 或 https:// 开头)',
'插入链接',
{
inputPattern: /^https?:\/\/.+/i,
inputErrorMessage: '链接需以 http:// 或 https:// 开头',
inputPlaceholder: 'https://',
confirmButtonText: '插入',
cancelButtonText: '取消'
}
)
url = String(value ?? '').trim()
} catch {
return // 用户取消
}
if (!url) return
exec('createLink', url)
}
/** 上传图片并插入(走项目统一 COS 直传) */
function pickImage(): void {
if (props.disabled || uploading.value) return
const input = document.createElement('input')
input.type = 'file'
input.accept = 'image/*'
input.onchange = async () => {
const file = input.files?.[0]
if (!file) return
if (!file.type.startsWith('image/')) {
ElMessage.warning('请选择图片文件')
return
}
uploading.value = true
try {
const uploaded = await uploadImageToCos(file)
focusEditable()
document.execCommand('insertImage', false, uploaded.fileUrl)
emitValue()
ElMessage.success('图片已插入')
} catch (error) {
ElMessage.error(error instanceof Error ? error.message : '图片上传失败')
} finally {
uploading.value = false
}
}
input.click()
}
/** 供父组件主动聚焦(可选) */
defineExpose({ focus: () => focusEditable() })
</script>
<style lang="scss" scoped>
.rich-editor {
border: 1px solid #dcdfe6;
border-radius: 6px;
background: #fff;
transition: border-color 0.15s;
&:hover {
border-color: #c0c4cc;
}
&:focus-within {
border-color: var(--el-color-primary);
}
&.is-disabled {
background: #f5f7fa;
cursor: not-allowed;
}
}
.rich-editor__toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
padding: 6px 8px;
border-bottom: 1px solid #ebeef5;
background: #fafafa;
border-radius: 6px 6px 0 0;
}
.rich-editor__divider {
width: 1px;
height: 16px;
margin: 0 4px;
background: #dcdfe6;
}
.rich-editor__spacer {
flex: 1;
}
.rich-editor__btn {
min-width: 26px;
height: 26px;
padding: 0 6px;
border: 1px solid transparent;
border-radius: 4px;
background: transparent;
color: #606266;
font-size: 13px;
line-height: 1;
cursor: pointer;
&:hover:not(:disabled) {
border-color: #dcdfe6;
background: #fff;
color: var(--el-color-primary);
}
&:disabled {
color: #c0c4cc;
cursor: not-allowed;
}
&.is-wide {
font-size: 12px;
}
&.is-toggle.is-active {
border-color: var(--el-color-primary);
background: var(--el-color-primary-light-9);
color: var(--el-color-primary);
}
}
.rich-editor__body,
.rich-editor__source {
width: 100%;
padding: 10px 12px;
border: none;
outline: none;
box-sizing: border-box;
color: #303133;
font-size: 14px;
line-height: 1.7;
overflow-y: auto;
}
.rich-editor__body {
&:empty::before {
content: attr(data-placeholder);
color: #a8abb2;
pointer-events: none;
}
:deep(h2) {
margin: 12px 0 8px;
font-size: 18px;
font-weight: 600;
line-height: 1.4;
}
:deep(h3) {
margin: 10px 0 6px;
font-size: 16px;
font-weight: 600;
line-height: 1.4;
}
:deep(p) {
margin: 6px 0;
}
:deep(ul),
:deep(ol) {
margin: 6px 0;
padding-left: 24px;
list-style: revert;
}
:deep(blockquote) {
margin: 8px 0;
padding: 4px 10px;
border-left: 3px solid #dcdfe6;
color: #606266;
background: #fafafa;
}
:deep(a) {
color: var(--el-color-primary);
text-decoration: underline;
word-break: break-all;
}
:deep(img) {
max-width: 100%;
height: auto;
vertical-align: middle;
}
}
.rich-editor__source {
display: block;
resize: vertical;
font-family: Consolas, Monaco, monospace;
font-size: 13px;
}
</style>

View File

@ -154,7 +154,9 @@ export default {
"todayOutbound": "Today Outbound",
"completionRate": "Completion Rate",
"interceptedOrders": "Intercepted Orders",
"exceptionOrders": "Exception Orders"
"exceptionOrders": "Exception Orders",
"recheckedOrders": "Rechecked Orders",
"packedOrders": "Packed Orders"
},
"inventory": {
"sku": "SKU",

View File

@ -157,7 +157,9 @@ export default {
"todayOutbound": "今日出库",
"completionRate": "完成率",
"interceptedOrders": "拦截订单",
"exceptionOrders": "异常订单"
"exceptionOrders": "异常订单",
"recheckedOrders": "已复核",
"packedOrders": "已打包"
},
"inventory": {
"sku": "商品SKU",

View File

@ -88,20 +88,20 @@
</el-col>
<el-col :xs="24" :sm="6" :lg="3">
<el-card shadow="hover" class="stats-card" @click="handlePendingShipments">
<el-card shadow="hover" class="stats-card" @click="handleRecheckedOrders">
<div class="card-content">
<div class="card-icon success">
<el-icon><Van /></el-icon>
<el-icon><Finished /></el-icon>
</div>
<div class="card-info">
<div class="card-title">{{ $t('dashboard.pendingShipment') }}</div>
<div class="card-value">{{ stats.pendingShipments }}</div>
<div class="card-title">{{ $t('dashboard.recheckedOrders') }}</div>
<div class="card-value">{{ stats.recheckedOrders }}</div>
<div class="card-trend">
<el-progress
:percentage="displayShipmentProgress"
:percentage="displayRecheckProgress"
:stroke-width="6"
:show-text="false"
:color="getProgressColor(displayShipmentProgress)" />
:color="getProgressColor(displayRecheckProgress)" />
</div>
</div>
<div class="card-action">
@ -112,16 +112,16 @@
</el-col>
<el-col :xs="24" :sm="6" :lg="3">
<el-card shadow="hover" class="stats-card" @click="handleTodayOutbound">
<el-card shadow="hover" class="stats-card" @click="handlePackedOrders">
<div class="card-content">
<div class="card-icon success">
<el-icon><Goods /></el-icon>
<el-icon><Box /></el-icon>
</div>
<div class="card-info">
<div class="card-title">{{ $t('dashboard.todayOutbound') }}</div>
<div class="card-value">{{ stats.todayOutbound }}</div>
<div class="card-title">{{ $t('dashboard.packedOrders') }}</div>
<div class="card-value">{{ stats.packedOrders }}</div>
<div class="card-trend">
{{ $t('dashboard.completionRate') }} {{ displayOutboundRate }}%
{{ $t('dashboard.completionRate') }} {{ displayPackRate }}%
</div>
</div>
<div class="card-action">
@ -182,8 +182,8 @@ import {
DocumentRemove,
Printer,
ShoppingCart,
Van,
Goods,
Finished,
Box,
Warning,
WarningFilled,
Top,
@ -210,10 +210,10 @@ const stats = ref({
unassignedOrders: "-",
unprintedOrders: "-",
unpickedOrders: "-",
pendingShipments: "-",
shipmentProgress: "-",
todayOutbound: "-",
outboundRate: "-",
recheckedOrders: "-",
recheckProgress: "-",
packedOrders: "-",
packRate: "-",
interceptedOrders: "-",
exceptionOrders: "-"
})
@ -225,26 +225,26 @@ watch(data, (newVal) => {
})
// Computed properties for fallbacks
const calculatedOutboundRate = computed(() => {
const calculatedRecheckProgress = computed(() => {
const todayOrders = Number(stats.value.todayOrders)
const todayOutbound = Number(stats.value.todayOutbound)
if (!todayOrders || isNaN(todayOrders) || todayOrders === 0) return "0"
return ((todayOutbound / todayOrders) * 100).toFixed(2)
const recheckedOrders = Number(stats.value.recheckedOrders)
if (!todayOrders || isNaN(todayOrders) || isNaN(recheckedOrders) || todayOrders === 0) return 0
return Math.min(100, (recheckedOrders / todayOrders) * 100)
})
const calculatedShipmentProgress = computed(() => {
const calculatedPackRate = computed(() => {
const todayOrders = Number(stats.value.todayOrders)
const pendingShipments = Number(stats.value.pendingShipments)
if (!todayOrders || isNaN(todayOrders) || todayOrders === 0) return 0
return Math.min(100, ((todayOrders - pendingShipments) / todayOrders) * 100)
const packedOrders = Number(stats.value.packedOrders)
if (!todayOrders || isNaN(todayOrders) || isNaN(packedOrders) || todayOrders === 0) return "0"
return ((packedOrders / todayOrders) * 100).toFixed(2)
})
const displayOutboundRate = computed(() => {
return stats.value.outboundRate !== "-" ? stats.value.outboundRate : calculatedOutboundRate.value
const displayRecheckProgress = computed(() => {
return stats.value.recheckProgress !== "-" ? Number(stats.value.recheckProgress) : calculatedRecheckProgress.value
})
const displayShipmentProgress = computed(() => {
return stats.value.shipmentProgress !== "-" ? Number(stats.value.shipmentProgress) : calculatedShipmentProgress.value
const displayPackRate = computed(() => {
return stats.value.packRate !== "-" ? stats.value.packRate : calculatedPackRate.value
})
const getProgressColor = (percentage: number) => {
@ -282,17 +282,17 @@ const handleUnpickedOrders = () => {
})
}
const handlePendingShipments = () => {
const handleRecheckedOrders = () => {
// 已复核 → 订单管理「待审核」页签(复核相关工作台)
gotoOrderPage({
tab: 'pendingShipment',
shipmentStatus: 'pending'
tab: 'reviewOrder'
})
}
const handleTodayOutbound = () => {
const handlePackedOrders = () => {
// 已打包 → 订单管理「待出库」页签(打包完成的订单进入出库环节)
gotoOrderPage({
tab: 'outboundOrder',
outboundDate: dayjs().format('YYYY-MM-DD')
tab: 'outboundOrder'
})
}

View File

@ -2,48 +2,125 @@
<el-dialog
:model-value="visible"
title="打包录像列表"
width="700px"
width="1080px"
align-center
:close-on-click-modal="false"
destroy-on-close
class="packing-video-dialog"
@update:model-value="$emit('update:visible', $event)"
@closed="handleClosed"
>
<div v-if="videos.length === 0" class="empty-hint">
<el-empty description="暂无录像" :image-size="80" />
<!-- 顶部:任务信息 -->
<div class="task-info-bar">
<div class="info-cell">
<span class="info-label">运单号</span>
<span class="info-value" :title="waybillText">{{ waybillText || '—' }}</span>
</div>
<div class="info-cell">
<span class="info-label">波次号</span>
<span class="info-value" :title="task?.wave_no">{{ task?.wave_no || '—' }}</span>
</div>
<div class="info-cell">
<span class="info-label">打包员</span>
<span class="info-value" :title="task?.operator_text">{{ task?.operator_text || '—' }}</span>
</div>
<div class="info-cell">
<span class="info-label">工作台</span>
<span class="info-value" :title="task?.workbench_name">{{ task?.workbench_name || '—' }}</span>
</div>
</div>
<div v-else class="video-list">
<div
v-for="(video, index) in videos"
:key="video.id ?? index"
class="video-item"
:class="{ 'video-item--disabled': !video.video_url }"
@click="video.video_url && $emit('play', video)"
>
<div class="video-item__thumb">
<el-icon size="28"><VideoPlay /></el-icon>
<div class="video-body">
<!-- 左侧:可播放录像列表 -->
<div class="video-list-pane">
<div class="pane-header">
<span class="pane-title">录像列表</span>
<span class="pane-count">{{ playableCount }} / {{ videos.length }} 可播放</span>
</div>
<div class="video-item__info">
<div class="video-item__name">
{{ video.camera_name || '录像 ' + (index + 1) }}
<div class="pane-body">
<el-empty v-if="!videos.length" description="暂无录像" :image-size="60" />
<template v-else>
<div
v-for="(video, index) in videos"
:key="video.id ?? index"
class="video-item"
:class="{
'video-item--disabled': !video.video_url,
'video-item--active': activeIndex === index
}"
@click="selectVideo(video, index)"
>
<div class="video-item__thumb">
<el-icon size="22"><VideoPlay /></el-icon>
</div>
<div class="video-item__info">
<div class="video-item__name">{{ video.camera_name || '录像 ' + (index + 1) }}</div>
<div class="video-item__meta">
<span>摄像头ID: {{ video.camera_id ?? '—' }}</span>
<span class="meta-divider">|</span>
<span>录像ID: {{ video.id ?? '—' }}</span>
</div>
</div>
<div class="video-item__action">
<el-tag v-if="!video.video_url" size="small" type="info" effect="plain">
{{ video.status === 'failed' ? '不可用' : '不可播放' }}
</el-tag>
<el-icon v-else-if="activeIndex === index" class="video-item__playing" size="18">
<VideoCameraFilled />
</el-icon>
</div>
</div>
</template>
</div>
</div>
<!-- 右侧:视频播放 -->
<div class="video-player-pane">
<div class="player-wrapper">
<video
v-if="activeVideo && activeVideo.video_url"
ref="videoRef"
class="video-element"
:src="activeVideo.video_url"
controls
autoplay
@loadeddata="loading = false"
@playing="loading = false"
@error="handleVideoError"
/>
<div v-if="!activeVideo || !activeVideo.video_url" class="player-overlay">
<el-icon size="30"><VideoPlay /></el-icon>
<span>请从左侧选择录像播放</span>
</div>
<div class="video-item__meta">
<span>摄像头ID: {{ video.camera_id ?? '—' }}</span>
<span class="meta-divider">|</span>
<span>录像ID: {{ video.id }}</span>
<template v-if="video.status">
<span class="meta-divider">|</span>
<el-tag size="small" :type="video.status === 'completed' ? 'success' : 'danger'">
{{ video.status === 'completed' ? '已完成' : video.status === 'failed' ? '失败' : video.status }}
<div v-else-if="loading" class="player-overlay">
<el-icon class="is-loading" size="26"><Loading /></el-icon>
<span>加载中…</span>
</div>
<div v-else-if="errorMsg" class="player-overlay">
<el-icon size="26"><WarningFilled /></el-icon>
<span class="error-text">{{ errorMsg }}</span>
<el-button size="small" type="primary" @click="retry">重试</el-button>
</div>
</div>
<div class="player-info-bar">
<template v-if="activeVideo">
<span>摄像头ID: {{ activeVideo.camera_id ?? '—' }}</span>
<span class="info-divider">|</span>
<span>{{ activeVideo.camera_name || '—' }}</span>
<span class="info-divider">|</span>
<span>录像ID: {{ activeVideo.id ?? '—' }}</span>
<template v-if="activeVideo.status">
<span class="info-divider">|</span>
<el-tag size="small" :type="statusTagType(activeVideo.status)">
{{ statusText(activeVideo.status) }}
</el-tag>
</template>
</div>
</div>
<div class="video-item__action">
<el-button v-if="video.video_url" type="primary" size="small" round>播放</el-button>
<span v-else-if="video.status === 'failed'" class="video-item__status video-item__status--unavailable">录像不可用</span>
<span v-else class="video-item__status video-item__status--unplayable">不可播放</span>
</template>
<span v-else class="player-info-bar__empty">暂无选中录像</span>
</div>
</div>
</div>
<template #footer>
<div class="dialog-footer">
<el-button type="warning" size="small" plain @click="$emit('force-record')">强制录制</el-button>
@ -54,36 +131,227 @@
</template>
<script setup lang="ts">
import { VideoPlay } from '@element-plus/icons-vue'
import { computed, nextTick, ref, watch } from 'vue'
import { Loading, VideoCameraFilled, VideoPlay, WarningFilled } from '@element-plus/icons-vue'
import type { VideoItem } from './VideoButton.vue'
import type { PackingTaskItem } from '@/api/order/packing/index'
import { getWaybill } from '../packingflow-config'
defineProps<{
const props = defineProps<{
visible: boolean
videos: VideoItem[]
/** 打包任务行/详情:用于顶部展示运单号、波次号、打包员、工作台 */
task?: PackingTaskItem | null
}>()
defineEmits<{
'update:visible': [value: boolean]
play: [video: VideoItem]
'force-record': []
}>()
const videoRef = ref<HTMLVideoElement | null>(null)
const activeIndex = ref(-1)
const loading = ref(false)
const errorMsg = ref('')
const videoList = computed<VideoItem[]>(() => props.videos || [])
const activeVideo = computed<VideoItem | null>(() =>
activeIndex.value >= 0 ? videoList.value[activeIndex.value] ?? null : null
)
const playableCount = computed(() => videoList.value.filter((v) => !!v.video_url).length)
const waybillText = computed(() => (props.task ? getWaybill(props.task) : ''))
function firstPlayableIndex(): number {
return videoList.value.findIndex((v) => !!v.video_url)
}
function resetPlayer() {
errorMsg.value = ''
loading.value = !!activeVideo.value?.video_url
}
function reloadVideo() {
nextTick(() => {
const el = videoRef.value
if (!el) return
el.load()
const played = el.play?.()
if (played && typeof played.catch === 'function') played.catch(() => {})
})
}
function stopVideo() {
const el = videoRef.value
if (el) {
el.pause()
el.removeAttribute('src')
el.load()
}
loading.value = false
errorMsg.value = ''
}
/** 打开时自动选中第一条可播放录像 */
watch(
() => props.visible,
(val) => {
if (val) {
activeIndex.value = firstPlayableIndex()
resetPlayer()
reloadVideo()
} else {
stopVideo()
activeIndex.value = -1
}
},
{ immediate: true }
)
/** 列表变化时,若当前选中已失效则回退到第一条可播放录像 */
watch(videoList, () => {
if (!props.visible) return
if (activeIndex.value < 0 || !activeVideo.value?.video_url) {
activeIndex.value = firstPlayableIndex()
resetPlayer()
reloadVideo()
}
})
/** 点击左侧录像 → 在右侧播放 */
function selectVideo(video: VideoItem, index: number) {
if (!video.video_url) return
activeIndex.value = index
resetPlayer()
reloadVideo()
}
function handleVideoError(e: Event) {
loading.value = false
const el = e.target as HTMLVideoElement
const code = el?.error?.code
const msgMap: Record<number, string> = {
1: '视频加载被中止',
2: '网络错误,无法加载视频',
3: '视频解码失败',
4: '视频格式不支持或文件不存在'
}
errorMsg.value = msgMap[code ?? 4] || '视频播放失败'
}
function retry() {
resetPlayer()
reloadVideo()
}
function handleClosed() {
stopVideo()
activeIndex.value = -1
}
function statusText(status?: string): string {
if (status === 'completed') return '已完成'
if (status === 'failed') return '失败'
return status || '—'
}
function statusTagType(status?: string): 'success' | 'danger' | 'info' {
if (status === 'completed') return 'success'
if (status === 'failed') return 'danger'
return 'info'
}
</script>
<style scoped>
.video-list {
/* ── 顶部任务信息 ───────────────────────────────────────────── */
.task-info-bar {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px 16px;
padding: 10px 16px;
margin-bottom: 12px;
background: #f5f7fa;
border: 1px solid #ebeef5;
border-radius: 8px;
}
.info-cell {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.info-label {
flex-shrink: 0;
font-size: 13px;
color: #909399;
}
.info-value {
flex: 1;
min-width: 0;
font-size: 13px;
font-weight: 600;
color: #303133;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* ── 左右分栏 ───────────────────────────────────────────────── */
.video-body {
display: flex;
gap: 12px;
align-items: stretch;
}
.video-list-pane {
width: 320px;
flex-shrink: 0;
display: flex;
flex-direction: column;
gap: 12px;
padding: 4px 0;
border: 1px solid #ebeef5;
border-radius: 8px;
overflow: hidden;
}
.pane-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 12px;
background: #fafafa;
border-bottom: 1px solid #ebeef5;
}
.pane-title {
font-size: 13px;
font-weight: 600;
color: #303133;
}
.pane-count {
font-size: 12px;
color: #909399;
}
.pane-body {
flex: 1;
height: 420px;
overflow-y: auto;
padding: 8px;
display: flex;
flex-direction: column;
gap: 8px;
}
.video-item {
display: flex;
align-items: center;
gap: 16px;
padding: 16px 20px;
gap: 10px;
padding: 8px 10px;
border: 1px solid #ebeef5;
border-radius: 10px;
border-radius: 8px;
cursor: pointer;
transition: all 0.2s;
background: #fff;
@ -92,20 +360,34 @@ defineEmits<{
.video-item:hover {
border-color: #409eff;
background: #ecf5ff;
box-shadow: 0 2px 8px rgba(64, 158, 255, 0.15);
transform: translateY(-1px);
}
.video-item--active {
border-color: #409eff;
background: #ecf5ff;
box-shadow: inset 0 0 0 1px rgba(64, 158, 255, 0.4);
}
.video-item--disabled {
cursor: default;
opacity: 0.7;
cursor: not-allowed;
opacity: 0.65;
}
.video-item--disabled:hover {
border-color: #ebeef5;
background: #fff;
box-shadow: none;
transform: none;
}
.video-item__thumb {
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #ecf5ff 0%, #d9ecff 100%);
border-radius: 8px;
color: #409eff;
flex-shrink: 0;
}
.video-item--disabled .video-item__thumb {
@ -113,41 +395,29 @@ defineEmits<{
color: #c0c4cc;
}
.video-item__thumb {
width: 56px;
height: 56px;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #ecf5ff 0%, #d9ecff 100%);
border-radius: 12px;
color: #409eff;
flex-shrink: 0;
}
.video-item:hover .video-item__thumb {
background: linear-gradient(135deg, #409eff 0%, #66b1ff 100%);
color: #fff;
}
.video-item__info {
flex: 1;
min-width: 0;
}
.video-item__name {
font-size: 15px;
font-size: 13px;
font-weight: 600;
color: #303133;
margin-bottom: 6px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.video-item__meta {
font-size: 13px;
margin-top: 2px;
font-size: 12px;
color: #909399;
display: flex;
align-items: center;
gap: 6px;
gap: 4px;
overflow: hidden;
white-space: nowrap;
}
.meta-divider {
@ -158,8 +428,69 @@ defineEmits<{
flex-shrink: 0;
}
.empty-hint {
padding: 40px 0;
.video-item__playing {
color: #67c23a;
}
/* ── 右侧播放器 ─────────────────────────────────────────────── */
.video-player-pane {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 8px;
}
.player-wrapper {
position: relative;
flex: 1;
height: 420px;
background: #000;
border-radius: 8px;
overflow: hidden;
}
.video-element {
width: 100%;
height: 100%;
display: block;
}
.player-overlay {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
background: rgba(0, 0, 0, 0.75);
color: #c0c4cc;
font-size: 13px;
}
.error-text {
color: #f56c6c;
max-width: 300px;
text-align: center;
}
.player-info-bar {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
min-height: 24px;
font-size: 12px;
color: #909399;
}
.player-info-bar__empty {
color: #c0c4cc;
}
.info-divider {
color: #dcdfe6;
}
.dialog-footer {
@ -168,16 +499,12 @@ defineEmits<{
align-items: center;
}
.video-item__status {
font-size: 13px;
white-space: nowrap;
/* 弹窗宽度自适应小屏 + 内边距收紧 */
.packing-video-dialog {
max-width: 96vw;
}
.video-item__status--unavailable {
color: #f56c6c;
}
.video-item__status--unplayable {
color: #c0c4cc;
.packing-video-dialog :deep(.el-dialog__body) {
padding-top: 12px;
}
</style>

View File

@ -271,11 +271,11 @@
</div>
</div>
<!-- 录像列表弹窗 -->
<!-- 录像列表弹窗(顶部任务信息 + 左侧可播放列表 + 右侧播放器) -->
<VideoListDialog
v-model:visible="videoListVisible"
:videos="currentVideos"
@play="handlePlayVideo"
:task="selectedRow"
@force-record="handleVideoListForceRecord"
/>