Compare commits

..

4 Commits

44 changed files with 633 additions and 5339 deletions

3
.gitignore vendored
View File

@@ -5,9 +5,8 @@
/iconfont-preview.html
.codebuddy
.workbuddy
.vscode
.trae*
.trae
# 本地调试配置 (含 uniacid / 域名, 每人不同, 不应入仓)
# 注意: 如果 .local.config.js 已经被之前的 commit 入仓,
# 需要手动 `git rm --cached .local.config.js` 并用 filter-branch

View File

@@ -214,27 +214,14 @@ const localDevConfig = ({
uniacid: 3007,
domain: 'https://xcx.aigc-quickapp.com/',
},
'2843': { // 蔬菜种子网
uniacid: 2843,
domain: 'https://xcx.aigc-quickapp.com/',
},
'5g-317': { // 电磁兼容,模板显示不全商品
uniacid: 317,
domain: 'https://5g.aigc-quickapp.com/',
},
'5g-312': { // 天然植物功效活性物
uniacid: 312,
domain: 'https://5g.aigc-quickapp.com/',
},
'5g-248': { // 工业称重
uniacid: 248,
domain: 'https://5g.aigc-quickapp.com/',
},
'5g-325': { // 检验检测机构
uniacid: 325,
domain: 'https://5g.aigc-quickapp.com/',
},
// })['5g-237']; // 商品分类,没有立即咨询文字
// })['5g-97']; // 大宗商品贸易,支持自定义字体大小、颜色
// })['5g-50']; // 燃气安全产品机器人,购物车无反应
@@ -257,7 +244,7 @@ const localDevConfig = ({
// })['2811']; // 本地
// })['5g-317']; // 电磁兼容
// })['5g-351']; //
})['2881']; // 本地
})['5g-351']; // 本地
// })['local-2']; // 本地
// })['local-11']; // 本地
// })['1-test']; // test

13
App.vue
View File

@@ -9,11 +9,6 @@
// 登录态恢复后通知 aiService 清旧 user key,避免串会话
import aiService from 'common/js/ai-service.js';
// 记录 App 是否已至少展示过一次: 首次 onShow = 启动展示(由 onLaunch 完成初始化),
// 之后每一次 onShow(含微信 ... 菜单"重新进入小程序"、从后台切回)都视为"重新进入"。
// 微信"重新进入小程序"不一定触发 onHide,所以用"是否展示过"判断更稳妥。
let _appHasShown = false;
import {
Weixin
} from 'common/js/wx-jssdk.js';
@@ -507,14 +502,6 @@
},
onShow: function(options) {
// #ifdef MP
// 微信小程序"重新进入小程序"(...) 等场景: onLaunch 不重跑,但模块级内存缓存仍在,
// 会让 cachedStorage / 语言包缓存继续返回进入前的旧值。首次 onShow 是启动展示,
// 之后每次 onShow(含 ... 重新进入、从后台切回前台)都视为重新进入,主动失效缓存并重新对齐。
if (_appHasShown) {
try { Lang.onAppReentry(); } catch (e) {}
}
_appHasShown = true;
// 自动授权登录
this.getAuthInfo();
if (this.$store.state.token) {

View File

@@ -523,9 +523,6 @@ export default {
user: getUserId(),
conversation_id: this.getConversationId() || '',
attachments: (options && options.attachments) || [],
// PR-BASIC-CONTEXT-TO-WB (2026-09-28): 透传位置/时间/页面上下文
// 给 WbAgentOsClient 提供 timestamp/timezone/location/page/metadata 等基础元素
context: (options && options.context) || null,
...getDomainParams()
},
header: {
@@ -591,8 +588,6 @@ export default {
user_id: getUserId(),
conversation_id: this.getConversationId() || '',
attachments: opts.attachments || [],
// PR-BASIC-CONTEXT-TO-WB (2026-09-28): 透传位置/时间/页面上下文
context: (opts && opts.context) || null,
...getDomainParams()
})
});
@@ -613,11 +608,7 @@ export default {
*/
async _fallbackToHttp(message, onEvent, onComplete, opts = {}) {
try {
const result = await this.sendMessage(message, {
attachments: (opts && opts.attachments) || [],
// PR-BASIC-CONTEXT-TO-WB (2026-09-28): MP HTTP 降级路径同步传递 context
context: (opts && opts.context) || null
});
const result = await this.sendMessage(message, { attachments: (opts && opts.attachments) || [] });
const content = result && result.content ? result.content : '';
// 阻塞式降级也尝试把后端返回的思考过程/用量透出来, 让小程序在 WS 不可用时仍能显示"思考过程 (N 步)"
const fallbackPayload = {
@@ -675,8 +666,6 @@ export default {
user_id: getUserId(),
conversation_id: this.getConversationId() || '',
attachments: (opts && opts.attachments) || [],
// PR-BASIC-CONTEXT-TO-WB (2026-09-28): 透传位置/时间/页面上下文
context: (opts && opts.context) || null,
...getDomainParams()
})
});

View File

@@ -284,21 +284,6 @@ export async function loadBundleTree(options = {}) {
const version = String(payload.version || '');
const sign = payload.sign || '';
// 诊断(真机定位用): tree 顶层结构不完整(非对象/为空/缺 common 或 components)时,
// 打印实际拿到的 tree 顶层 key + 请求上下文, 便于排查为什么 isBundleComplete 失败
// (真机上若看到这条 warn, 说明服务端返回了残缺 bundle, 这才是英文回退/ toast 的根因)
if (!tree || typeof tree !== 'object' || !tree.common || !tree.components) {
console.warn(
'[lang-loader] bundle tree INCOMPLETE. ' +
'topLevelKeys=' + JSON.stringify(Object.keys(tree || {})) +
' lang=' + lang +
' appType=' + appType +
' uniacid=' + uniacid +
' version=' + version +
' hasPayloadTree=' + ((payload && payload.tree) !== undefined)
);
}
// 4) 签名校验(可选)
const secret = langConfig.remote.signSecret || '';
const signValid = validateSign(tree, version, sign, secret);

View File

@@ -489,36 +489,27 @@ function isBundleComplete(tree) {
return false;
}
// 2) tree 不能是空对象(空对象没有 common 也没有 components, 显然不可用)
// 2) tree 不能是空对象(空对象没有任何可用文案, 显然不可用)
const treeKeys = Object.keys(tree);
if (treeKeys.length === 0) {
return false;
}
// 3) tree 必须有 common 节点(基础文案, 几乎所有 UI 都依赖)
if (!tree.common || typeof tree.common !== 'object') {
return false;
// === 粗粒度校验(与上方设计哲学一致) ===
// 不再硬性要求 common / components 节点必须同时存在。
// 远端可能在某些时刻少发某个节点(部署期间、缓存未刷新、租户未配置 common 等),
// 此时仍应让 boot 成功写入 remoteTreeCache, 缺失字段由 $lang() 自然回落为空,
// UI 降级显示(空文案/空按钮文字), 而不是让整个 boot 失败导致整站变英文 / raw key。
// 软校验: components.privacyPopup(节点存在才检查, 避免 tree.components 为 undefined 时报错)
const privacyPopup = tree.components && tree.components.privacyPopup;
if (privacyPopup && typeof privacyPopup === 'object') {
// defaultAppNameMp 存在性仅作诊断, 不阻止 boot
if (typeof privacyPopup.defaultAppNameMp !== 'string' || !privacyPopup.defaultAppNameMp) {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
}
}
// 4) tree 必须有 components 节点(组件级文案)
if (!tree.components || typeof tree.components !== 'object') {
return false;
}
// === 以下为软校验(只 warn 不 return false) ===
// 设计: 不再因为"缺某个 key"就让整个 boot 失败
// 缺失的字段让 $lang() 自然返回空, UI 降级显示
// 软校验 1: components.privacyPopup
const privacyPopup = tree.components.privacyPopup;
if (!privacyPopup || typeof privacyPopup !== 'object') {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
} else if (typeof privacyPopup.defaultAppNameMp !== 'string' || !privacyPopup.defaultAppNameMp) {
// 软校验不阻止 boot, 仅记录(暂无控制台输出, 避免污染生产)
}
// 软校验 2: 哪些 key 看起来像隐私弹窗,但在错误位置?(诊断)
// 此处仅保留注释说明, 不在生产代码中输出
return true;
}
@@ -628,26 +619,6 @@ function loadLangPackSync(lang, path) {
* 获得当前本地语言
* @returns
*/
/**
* 语言切换开关钩子(由后台 shop_info.ischina 决定,经 store/index.js 的 setShopInfo 写入)。
*
* 设计原则: 只"在关闭时清理持久化语种", 绝不在开启态加任何门控 —— 否则一旦 ischina
* 取值/语义判断偏差, 就会误伤"开启双语后切换英文"的正常行为(回归)。
*
* 行为:
* - 后台关闭双语/小程序(ischina 为假): 清掉用户此前持久化到 storage 的语种 + 缓存,
* 使刷新/重新进入时 getCurrentLocale() 回退默认中文, 满足
* "后台关闭双语后, 刷新重新进入必须是中文" 的需求。
* - 后台开启双语(ischina 为真): 不做任何拦截, 完全保持原有"切换英文"行为不变。
*/
function setLangSwitchEnabled(enabled) {
if (!enabled) {
// 关闭语言切换: 清掉持久化语种 + 缓存, 强制回到默认中文
invalidateStorageCache('lang');
try { uni.removeStorageSync('lang'); } catch (e) {}
}
}
function getCurrentLocale() {
// 关键:使用 cachedStorageGet,防止 uni.getStorageSync 触发 Vue 事件导致 lang() 递归
const val = cachedStorageGet('lang', null);
@@ -993,13 +964,6 @@ export default {
*/
getCurrentLocale,
/**
* 语言切换功能开关(后台 shop_info.ischina 决定)。
* 关闭后 getCurrentLocale() 强制返回默认语言(中文),并清掉已持久化的语种。
* 详见本文件 setLangSwitchEnabled 函数与 store/index.js 的 setShopInfo 钩子。
*/
setLangSwitchEnabled,
/**
* 从后端数据中提取当前语言的文案(向后兼容)
* 优先使用 xxx_map 多语言 map,没有则回退到 xxx / en_xxx 二元模式
@@ -1081,13 +1045,6 @@ export default {
// force 失败时 loadBundleTree 内部直接抛错(不回退 cache), 让这里进入 catch
let isComplete1 = isBundleComplete(result.tree);
if (!isComplete1) {
// [debug] 首次拉取的 bundle 不完整: 打印顶层 key, 便于定位远端是否缺 common/components
try {
console.warn('[i18n:boot] bundle incomplete (1st fetch). ' +
'lang=' + lang + ', appType=' + appType + ', uniacid=' + uniacid +
', source=' + (result && result.source) +
', topKeys=' + JSON.stringify(Object.keys(result && result.tree || {})));
} catch (e) {}
// 强制重试前清掉所有 cache, 避免 force 路径残留旧数据
delete remoteTreeCache[_preloadMk];
result = await loadBundleTree({ lang, appType, uniacid, force: true });
@@ -1098,13 +1055,6 @@ export default {
// 不加载本地 lang 兜底(remote-only 模式, 本地 lang 已被 webpack 排除)
let isComplete2 = isBundleComplete(result.tree);
if (!isComplete2) {
// [debug] force 重试后仍不完整: 打印顶层 key, 确认远端确实返回残缺 tree
try {
console.warn('[i18n:boot] bundle incomplete (after force retry). ' +
'lang=' + lang + ', appType=' + appType + ', uniacid=' + uniacid +
', source=' + (result && result.source) +
', topKeys=' + JSON.stringify(Object.keys(result && result.tree || {})));
} catch (e) {}
throw new Error('lang bundle unusable after force retry');
}
@@ -1144,14 +1094,10 @@ export default {
setRemoteStatus('fail', { reason: _reason, lang });
bootCompleted = true;
emitUpdated(lang);
// 注意: 这里已用缓存兜底成功(UI 可用), 不应再标 status:'fail',
// 否则 App.vue 会弹"Failed to load i18n"误报 toast。
// remoteStatus 仍保持 'fail'(上方已 setRemoteStatus), 用于离线指示。
return {
ok: true,
source: 'cache',
status: 'ok',
degraded: true,
status: 'fail',
reason: _errMsg || 'fallback to cache',
lang,
cacheAge: cached.ts ? Date.now() - cached.ts : 0,
@@ -1221,42 +1167,6 @@ export default {
loadOverrides(lang);
},
/**
* 微信小程序"重新进入小程序"(右上角 ... 菜单)场景调用:
* 该操作销毁页面栈重新进首页,但小程序 JS 上下文往往不重置(热重启),
* 于是 App.onLaunch(里面跑 boot 全量初始化)不会重跑,而模块级内存缓存仍在:
* - _storageResultCache(cachedStorage): 可能返回进入前缓存的 lang/uniacid
* - _mergedLangCache / _fieldResultCache: 沿用进入前的翻译结果
* - remote-only 模式下远端 bundle 不会被重新拉取
* 这里主动失效所有内存缓存,并重新对齐远端 bundle,使重新进入后按当前
* storage 的 locale 重新读取并合并,不再沿用旧值。
* 注意: 首次 onShow(启动展示)不应调用本方法,App.vue 负责区分。
*/
onAppReentry() {
// [debug] 验证微信"重新进入小程序"是否真的命中本分支:真机复现后搜 i18n:reentry
try {
console.log('[i18n:reentry] onAppReentry triggered, IS_REMOTE_ONLY=' + IS_REMOTE_ONLY +
', beforeInvalidateLang=' + (cachedStorageGet('lang', null)) +
', beforeInvalidateUniacid=' + (cachedStorageGet('uniacid', null)));
} catch (e) {}
// 1) cachedStorage 失效: 下次 cachedStorageGet 必须重新读 storage(locale/uniacid)
invalidateStorageCache();
// 2) 语言包合并/字段缓存失效,并 bump _overrideVersion → lang() 用当前 locale 重新合并
invalidateLangCaches();
// [debug] 失效后立刻重新读,确认 cachedStorage 已重新走 storage(而非命中旧缓存)
try {
console.log('[i18n:reentry] after invalidate, freshLang=' + getCurrentLocale() +
', freshUniacid=' + getCurrentUniacid());
} catch (e) {}
// 3) remote-only: 重新进入时 onLaunch 不重跑,这里重新拉当前 locale 的 bundle 并推送重渲染
if (IS_REMOTE_ONLY) {
this.boot();
} else {
this.refresh(true);
}
},
/**
* * 订阅远端状态变化(status: 'unknown' | 'ok' | 'fail', detail.reason 有 fail 分类)
* @param {(status:string, detail:object) => void} fn

View File

@@ -40,16 +40,10 @@ const EXT_MIME_MAP = {
m4a: 'audio/mp4', flac: 'audio/flac', ogg: 'audio/ogg',
oga: 'audio/ogg', opus: 'audio/opus', amr: 'audio/amr', wma: 'audio/x-ms-wma',
aiff: 'audio/aiff', aif: 'audio/aiff', ape: 'audio/x-ape', mid: 'audio/midi',
// PR-AV-FULL-SUPPORT (2026-09-24): 全量音视频格式 (与后端 MediaUploadPolicy::guessMimeByExt 对齐)
midi: 'audio/midi', caf: 'audio/x-caf', mka: 'audio/x-matroska', ac3: 'audio/ac3',
mp4: 'video/mp4', mov: 'video/quicktime', avi: 'video/x-msvideo',
mkv: 'video/x-matroska', webm: 'video/webm', flv: 'video/x-flv',
m4v: 'video/x-m4v', wmv: 'video/x-ms-wmv', '3gp': 'video/3gpp',
mpeg: 'video/mpeg', mpg: 'video/mpeg', ts: 'video/mp2t',
'3g2': 'video/3gpp2', f4v: 'video/x-flv', mpe: 'video/mpeg', m2v: 'video/mpeg',
m2ts: 'video/mp2t', mts: 'video/mp2t', ogv: 'video/ogg', vob: 'video/mpeg',
asf: 'video/x-ms-asf', rm: 'application/vnd.rn-realmedia',
rmvb: 'application/vnd.rn-realmedia-vbr', divx: 'video/x-divx',
doc: 'application/msword',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
ppt: 'application/vnd.ms-powerpoint',

View File

@@ -5,6 +5,24 @@
import lang from './lang.js';
/**
* 判断是否为「微信剪贴板隐私声明缺失」导致的复制失败
*
* 微信自 2023-09-15 起把剪贴板接口纳入《小程序用户隐私保护指引》,
* 若小程序后台未声明「剪贴板」(或声明未审核通过),调用会返回:
* { errno: 112, errMsg: 'setClipboardData:fail api scope is not declared in the privacy agreement' }
* 这是平台侧配置问题,不改代码也能复现,因此不能把原始英文 errMsg 直接展示给用户。
*
* @param {*} err uni.setClipboardData 的 fail 回调参数
* @returns {Boolean} true=剪贴板隐私声明缺失
*/
export const isClipboardPrivacyError = (err) => {
if (!err) return false;
if (Number(err.errno) === 112) return true;
const msg = `${err.errMsg || err.message || ''}`;
return /privacy agreement/i.test(msg) || /api scope is not declared/i.test(msg);
};
/**
* 显示错误信息
* @param {Exception} err
@@ -97,8 +115,12 @@ export const copyTextAsync = (text, { copySuccess = '', copyFailed = '' } = {})
fail: (err) => {
clearTimeout(timeoutId);
try {
// 剪贴板隐私声明缺失(errno 112)属平台配置问题, 用可读文案替代微信原始英文错误
const tip = isClipboardPrivacyError(err)
? lang.lang('uniappUtils.clipboardPrivacyNotDeclared')
: (err.message || err.errMsg || copyFailed || lang.lang('uniappUtils.copyFailed'));
uni.showToast({
title: err.message || err.errMsg || copyFailed || lang.lang('uniappUtils.copyFailed'),
title: tip,
icon: 'none',
duration: 2000
});

View File

@@ -1254,21 +1254,6 @@ export default {
link.wap_url = resolvedUrl;
}
// ===== 仅微信小程序: 装修"文件"链接直开, 不进 files/detail 中间页 =====
// 命中: page_key=PAGE_FILES_DETAIL / name=FILES_xx / wap_url 指向 files/detail
// 且能提取到 files_id。拉取或打开失败时自动降级回原详情页(openDiyFileDirect 内部处理)。
// #ifdef MP-WEIXIN
if (link && (link.page_key === 'PAGE_FILES_DETAIL'
|| (link.name && /^FILES_\d+$/i.test(String(link.name)))
|| String(link.wap_url || '').indexOf('files/detail') !== -1)) {
const filesId = this._extractFilesIdFromLink(link);
if (filesId) {
this.openDiyFileDirect(link, filesId);
return;
}
}
// #endif
// 修复: 内部页面被后台存成【绝对 URL】(如 https://host/hwappx/common/pages_tool/form/formdata)
// 时,下方 `indexOf('http') != -1` 会把它误判为"外部链接":
// - H5 走 window.location.href → 整页刷新,点返回时整个 App 重启、启动屏重播、状态/滚动丢失
@@ -1442,123 +1427,6 @@ export default {
});
}
},
/**
* 从装修"文件"链接中提取 files_id(仅微信小程序直开链路使用)。
* 兼容三种位置: 顶层字段(files_id/file_id/id) / page_params(JSON字符串或对象) / wap_url query。
* @returns {String} 拿不到返回 ''
*/
_extractFilesIdFromLink(link) {
if (!link) return '';
let id = link.files_id || link.file_id || link.id || '';
if (!id) {
const params = _parsePageParams(link.page_params);
id = params.files_id || params.file_id || params.id || '';
}
if (!id) {
const url = String(link.wap_url || '');
const qIdx = url.indexOf('?');
if (qIdx !== -1) {
url.slice(qIdx + 1).split('&').forEach(kv => {
if (id) return;
const eq = kv.indexOf('=');
const k = eq === -1 ? kv : kv.slice(0, eq);
if (k === 'files_id' || k === 'file_id' || k === 'id') {
id = eq === -1 ? '' : kv.slice(eq + 1);
}
});
}
}
return id === '' || id === undefined || id === null ? '' : String(id);
},
/**
* 微信小程序: 装修"文件"链接直开, 不进 files/detail 中间页。
* 链路: /api/files/getfile(files_url 已由后端 img() 补全域名)
* → downloadFile → saveFile 用文件名重命名 → openDocument(原生 PDF 阅读器)
* 任一环节失败 → 降级跳原详情页(files/detail), 保持旧体验兜底。
* @param {Object} link 装修链接对象(用于取标题)
* @param {String} filesId 文件 id
*/
openDiyFileDirect(link, filesId) {
const fallback = () => {
this.redirectTo(PAGE_KEY_MAP.PAGE_FILES_DETAIL, {
files_id: filesId,
title: link.title || '',
enable_set_title: link.enable_set_title ? 1 : 0,
page_params: Object.assign({}, _parsePageParams(link.page_params), { files_id: filesId })
});
};
const safeTitle = String(link.title || '').replace(/[\\/:*?"<>|\r\n\t]/g, '_');
Http.sendRequest({
url: '/api/files/getfile',
data: { files_id: filesId },
noRetry: true,
silentError: true,
success: res => {
if (!res || res.code !== 0 || !res.data || !res.data.files_url) {
fallback();
return;
}
let url = String(res.data.files_url);
// 相对路径补全域名($util.img 对含逗号路径会按多图截断, 规避)
if (!/^https?:\/\//i.test(url) && url.indexOf(',') === -1) {
url = this.img(url);
}
if (!/^https?:\/\//i.test(url)) {
fallback();
return;
}
const rawTitle = String(res.data.files_title || safeTitle || 'file');
const title = rawTitle.replace(/[\\/:*?"<>|\r\n\t]/g, '_');
const matched = url.split('?')[0].match(/\.([a-zA-Z0-9]+)$/);
const ext = matched ? matched[1].toLowerCase() : 'pdf';
uni.showLoading({ title: Lang.lang('files.list.loading') || 'Loading', mask: true });
uni.downloadFile({
url,
success: dres => {
if (dres.statusCode !== 200) {
uni.hideLoading();
fallback();
return;
}
const fs = uni.getFileSystemManager();
const targetPath = `${wx.env.USER_DATA_PATH}/fs_${Date.now()}_${title}.${ext}`;
fs.saveFile({
tempFilePath: dres.tempFilePath,
filePath: targetPath,
success: r => {
uni.hideLoading();
uni.openDocument({
filePath: r.savedFilePath,
fileType: ext,
showMenu: true,
fail: () => fallback(),
complete: () => {
try { fs.removeSavedFile({ filePath: r.savedFilePath }); } catch (e) { }
}
});
},
fail: () => {
// saveFile 失败(配额等), 直接用临时文件打开兜底
uni.hideLoading();
uni.openDocument({
filePath: dres.tempFilePath,
fileType: ext,
showMenu: true,
fail: () => fallback()
});
}
});
},
fail: () => {
uni.hideLoading();
fallback();
}
});
},
fail: () => fallback()
});
},
/**
* 获取默认图
*/

View File

@@ -1,819 +0,0 @@
/**
* voice-recorder.js — 跨端录音抽象层
*
* PR-FRONTEND-VOICE-INPUT (2026-09-24)
* 统一 H5 / 微信小程序 / App-Plus / 鸿蒙元服务 四端的录音接口,
* 把麦克风采集 + 振幅事件 + 自动停止 + 资源回收 收敛到一处。
*
* PR-FRONTEND-VOICE-WAV (2026-09-25)
* H5 分支从 MediaRecorder (产出 webm/opus) 改为 AudioContext + ScriptProcessor
* 采原始 PCM, 停止时手动封装成标准 WAV (PCM 16-bit LE mono, 16kHz).
* 原因: Chrome MediaRecorder 只支持 webm/ogg 容器, 不支持 wav/mp3 录制;
* 大多数 STT / 后端 Agent 框架无法解析 webm/opus.
* 产 wav 后所有 STT 服务 (Whisper / 达摩院 / 腾讯 ASR / ...) 都吃.
*
* 平台分支:
* - H5 : navigator.mediaDevices.getUserMedia → AudioContext
* → ScriptProcessor 采 PCM Float32 → 停止时封装 WAV.
* 振幅采样走 AnalyserNode (与采 PCM 并行, 不冲突).
* - MP / APP / 鸿蒙: uni.getRecorderManager()(uni-app 鸿蒙 runtime 已映射)
* 走 onFrameRecorded 推 progress 事件.
* uni-app format 参数可指定 wav/mp3/aac.
*
* 统一事件:
* progress → { level: 0..1, duration: ms } 持续采样, 用于驱动波形动画
* error → Error 录音失败
*
* 统一结果 (stop() 解析):
* {
* filePath?: string, // MP/APP/鸿蒙: tempFilePath; H5: blob URL
* blob?: Blob, // H5: WAV Blob (供 FileReader / uploadMedia 二次处理)
* fileName?: string, // H5: voice_<ts>.wav; MP 按 uni 约定
* duration: number, // ms
* mime: string, // 录音产物 MIME: H5='audio/wav', MP/APP/鸿蒙按 format
* size: number, // bytes
* cancelled: false
* }
*
* 取消时 resolve(null);调用方拿到 null 时不要 push 到 pendingFiles。
*/
const DEFAULT_MAX_DURATION_MS = 60 * 1000
// PR-FRONTEND-VOICE-SINGLETON (2026-09-29): uni.getRecorderManager() / wx.getRecorderManager()
// 是全局单例, 且微信内部状态极易因上一次未完全停止而残留, 导致下一次 start() 报
// "operateRecorder:fail:audio is recording, don't start"。
// 这里用模块级 Promise 把所有 start/stop 串行化, 确保前一个实例 onStop/onError 完成后
// 才允许下一个实例 start()。
let _singletonIdlePromise = Promise.resolve()
let _singletonIdleResolver = null
let _singletonRec = null
let _singletonBusyInstance = null
function _getSingletonRecorder() {
if (!_singletonRec) {
_singletonRec = uni.getRecorderManager()
}
return _singletonRec
}
let _singletonIdleTimer = null
function _setSingletonBusy(instance, maxDurationMs = DEFAULT_MAX_DURATION_MS) {
if (_singletonIdleTimer) {
clearTimeout(_singletonIdleTimer)
_singletonIdleTimer = null
}
if (_singletonIdleResolver) {
// 已经有未释放的 busy promise, 理论上不应发生; 先强制释放避免死锁
_singletonIdleResolver()
_singletonIdleResolver = null
}
_singletonIdlePromise = new Promise((resolve) => {
_singletonIdleResolver = resolve
})
_singletonBusyInstance = instance
// 保险: 即使 onStop/onError 因异常没触发, 最多等 10s 也要释放,
// 避免死锁导致后续所有 start() 永远挂起。
_singletonIdleTimer = setTimeout(() => {
console.warn('[voice-recorder:singleton] idle timeout, force release')
_setSingletonIdle(instance)
}, Math.min(maxDurationMs + 5000, 10000))
}
function _setSingletonIdle(instance) {
if (_singletonIdleTimer) {
clearTimeout(_singletonIdleTimer)
_singletonIdleTimer = null
}
if (_singletonBusyInstance && _singletonBusyInstance !== instance) {
// 不是当前占用者释放, 忽略
return
}
if (_singletonIdleResolver) {
_singletonIdleResolver()
_singletonIdleResolver = null
}
_singletonIdlePromise = Promise.resolve()
_singletonBusyInstance = null
}
// H5 录音参数: 16kHz mono PCM → 16-bit LE WAV
// 16kHz/16-bit 是大多数 STT 服务 (Whisper / 达摩院 / 腾讯 ASR 等) 最常见的输入规格.
const H5_SAMPLE_RATE = 16000
const H5_NUM_CHANNELS = 1
const H5_SCRIPT_PROCESSOR_BUFFER_SIZE = 4096
/**
* 构造带 code 字段的 Error
* - code: 稳定的英文枚举, 供调用方按 code 走 $lang() 翻译
* - message: 兜底英文 message, 用于开发/调试或未识别 code
* 注意: voice-recorder.js 自身不持有 Vue 上下文, 翻译必须在调用方完成
*/
function _err(code, message) {
const e = new Error(message || code)
e.code = code
return e
}
/**
* 检测当前运行环境 (避免编译器把所有分支都打进去)
* - true / false 都是运行时结果;条件编译靠注释里的 #ifdef
*/
function isH5() {
// #ifdef H5
return true
// #endif
// #ifndef H5
return false
// #endif
}
function isMpOrApp() {
// #ifdef MP-WEIXIN || APP-PLUS || MP-HARMONY
return true
// #endif
// #ifndef MP-WEIXIN || APP-PLUS || MP-HARMONY
return false
// #endif
}
/**
* 由 mime 反推文件扩展名
*/
function mimeToExt(mime) {
if (!mime) return 'wav'
if (mime.indexOf('wav') !== -1) return 'wav'
if (mime.indexOf('webm') !== -1) return 'webm'
if (mime.indexOf('ogg') !== -1) return 'ogg'
if (mime.indexOf('mp4') !== -1) return 'm4a'
if (mime.indexOf('mpeg') !== -1) return 'mp3'
if (mime.indexOf('aac') !== -1) return 'aac'
return 'audio'
}
/**
* 合并多个 Float32Array (PCM 帧缓冲) 为单个 Float32Array
*/
function mergeFloat32Arrays(arrays) {
let totalLength = 0
for (let i = 0; i < arrays.length; i++) totalLength += arrays[i].length
const out = new Float32Array(totalLength)
let offset = 0
for (let i = 0; i < arrays.length; i++) {
out.set(arrays[i], offset)
offset += arrays[i].length
}
return out
}
/**
* 将 Float32 PCM (-1..1) 编码为标准 WAV (PCM 16-bit LE, RIFF/WAVE 头).
* 所有 STT 服务都吃这个格式; 浏览器 H5 录音不依赖 MediaRecorder 也能产出.
*
* 参考 RIFF/WAVE 规范:
* https://docs.fileformat.com/audio/wav/
* http://soundfile.sapp.org/doc/WaveFormat/
*/
function encodeWavPcm16LE(samples, sampleRate, numChannels) {
const bytesPerSample = 2 // 16-bit
const dataSize = samples.length * numChannels * bytesPerSample
const buffer = new ArrayBuffer(44 + dataSize)
const view = new DataView(buffer)
// RIFF chunk descriptor (12 bytes)
writeAscii(view, 0, 'RIFF')
view.setUint32(4, 36 + dataSize, true) // ChunkSize = 文件总字节 - 8
writeAscii(view, 8, 'WAVE')
// fmt subchunk (24 bytes)
writeAscii(view, 12, 'fmt ')
view.setUint32(16, 16, true) // Subchunk1Size for PCM = 16
view.setUint16(20, 1, true) // AudioFormat: 1 = PCM
view.setUint16(22, numChannels, true)
view.setUint32(24, sampleRate, true)
view.setUint32(28, sampleRate * numChannels * bytesPerSample, true) // ByteRate
view.setUint16(32, numChannels * bytesPerSample, true) // BlockAlign
view.setUint16(34, 16, true) // BitsPerSample
// data subchunk (8 + N bytes)
writeAscii(view, 36, 'data')
view.setUint32(40, dataSize, true)
// PCM 样本: Float32 (-1..1) → Int16 LE (clamp 到 [-1, 1] 防溢出)
let offset = 44
for (let i = 0; i < samples.length; i++) {
let s = samples[i]
if (s > 1) s = 1
else if (s < -1) s = -1
const int16 = s < 0 ? Math.round(s * 0x8000) : Math.round(s * 0x7FFF)
view.setInt16(offset, int16, true)
offset += 2
}
return buffer
}
function writeAscii(view, offset, str) {
for (let i = 0; i < str.length; i++) {
view.setUint8(offset + i, str.charCodeAt(i))
}
}
/**
* 创建录音器实例。
*
* @param {object} [opts]
* @param {number} [opts.maxDuration=60000] 自动停止时长 (ms)
* @param {string} [opts.format] MP/APP/鸿蒙 'mp3'|'aac'|'wav' (uni-app 文档)
* @param {number} [opts.sampleRate=16000]
* @param {number} [opts.numberOfChannels=1]
* @param {number} [opts.encodeBitRate=48000]
*
* @returns {VoiceRecorder}
*/
export function createVoiceRecorder(opts = {}) {
return new VoiceRecorder(opts)
}
class VoiceRecorder {
constructor(opts) {
this._maxDuration = opts.maxDuration || DEFAULT_MAX_DURATION_MS
// PR-FRONTEND-VOICE-FORMAT (2026-09-29): 微信小程序在部分 Android 机型上对 mp3/aac 兼容性差,
// 表现为一启动就 onStop(duration~100ms)。wav 是无压缩格式, 兼容性最好, 优先使用。
this._format = opts.format || 'wav'
this._sampleRate = opts.sampleRate || 16000
this._channels = opts.numberOfChannels || 1
this._bitRate = opts.encodeBitRate || 48000
this._listeners = { progress: [], error: [] }
this._isRecording = false
this._isStarting = false // start() 已调用, 但 onStart 尚未回调
this._stopResolve = null // 当前 stop() 等待 onStop 解析的 resolve
this._pendingStop = false // onStart 之前就调用了 stop() → 等开始后立即停
this._startTs = 0
this._id = Math.random().toString(36).slice(2, 8)
this._autoStopTimer = null
this._stopFallbackTimer = null // PR-FRONTEND-VOICE-FALLBACK: stop()/cancel() 兜底定时器
this._earlyStopResult = null // PR-FRONTEND-VOICE-RACE: onStop 在 stop() 之前触发时缓存结果
// 平台相关句柄
this._h5 = null // { mediaRecorder, stream, audioCtx, analyser, chunks, mime, rafId }
this._uniRec = null // uni.getRecorderManager() 返回值
console.log(`[voice-recorder:${this._id}] created`)
}
on(event, cb) {
if (!this._listeners[event]) this._listeners[event] = []
this._listeners[event].push(cb)
}
off(event, cb) {
const arr = this._listeners[event]
if (!arr) return
const idx = arr.indexOf(cb)
if (idx !== -1) arr.splice(idx, 1)
}
_emit(event, payload) {
const arr = this._listeners[event]
if (!arr) return
for (const cb of arr.slice()) {
try { cb(payload) } catch (e) { /* swallow */ }
}
}
get isRecording() { return this._isRecording }
/**
* 开始录音。
* resolve() 仅表示「启动成功」,真正的产物在 stop()/cancel() 中拿到。
*/
start() {
if (this._isRecording) {
return Promise.reject(_err('ALREADY_STARTED', 'recorder already started'))
}
if (this._isStarting) {
return Promise.reject(_err('ALREADY_STARTED', 'recorder is starting'))
}
this._isStarting = true
let p = null
if (isH5()) {
p = this._startH5()
} else if (isMpOrApp()) {
p = this._startUni()
} else {
this._isStarting = false
return Promise.reject(_err('NOT_SUPPORTED', 'voice input not supported on this platform'))
}
// 启动失败时复位状态, 避免后续 stop()/cancel() 一直挂起
p.catch((e) => {
this._isStarting = false
return Promise.reject(e)
})
return p
}
/**
* 停止录音并返回产物。
* resolve(null) 表示已取消 / 无产物,调用方应忽略。
*/
stop() {
console.log(`[voice-recorder:${this._id}] stop() called`, { isRecording: this._isRecording, isStarting: this._isStarting, hasUniRec: !!this._uniRec, hasStopResolve: !!this._stopResolve, earlyResult: !!this._earlyStopResult })
if (!this._isRecording) {
// PR-FRONTEND-VOICE-RACE (2026-09-29): 真机常见"按住即松手"——
// onStart 尚未回调 (录音未真正开始) 就调用 stop(), 原逻辑直接返回 null
// 导致上层判定"录音失败,请重试"。这里改为挂起, 等 onStart 触发后立即停,
// 产物仍走 onStop 正常返回 (太短的音轨后端可自行拒绝)。
if (this._isStarting) {
console.log(`[voice-recorder:${this._id}] stop() deferred: waiting for onStart`)
return new Promise((resolve) => {
this._pendingStop = true
this._stopResolve = resolve
})
}
// onStop 在 stop() 之前触发, 且有有效产物则返回缓存结果
if (this._earlyStopResult) {
const r = this._earlyStopResult
this._earlyStopResult = null
console.log(`[voice-recorder:${this._id}] stop() returning early onStop result`)
return Promise.resolve(r)
}
console.log(`[voice-recorder:${this._id}] stop() early return null (not recording)`)
return Promise.resolve(null)
}
if (isH5()) return this._stopH5()
return this._stopUni()
}
/**
* 中断录音并丢弃产物。
*/
cancel() {
if (this._isStarting) {
// PR-FRONTEND-VOICE-CANCEL-RACE (2026-09-29): onStart 尚未触发就取消,
// 不能立即返回, 否则录音器启动后会继续录制。挂起 pendingStop,
// 等 onStart 触发后立即 stop(), 产物被丢弃。
console.log(`[voice-recorder:${this._id}] cancel() deferred: waiting for onStart`)
return new Promise((resolve) => {
this._pendingStop = true
this._stopResolve = () => resolve()
})
}
if (!this._isRecording) {
this._clearAutoStopTimer()
return Promise.resolve()
}
if (isH5()) return this._cancelH5()
return this._cancelUni()
}
// ===================== H5 实现 =====================
// PR-FRONTEND-VOICE-WAV (2026-09-25): 改为 AudioContext + ScriptProcessor 采 PCM,
// 停止时手动封装标准 WAV. 不再依赖 MediaRecorder, 解决 Chrome 只能产 webm/opus
// 导致后端 STT / Agent framework 无法解析的问题.
//
// 关键设计:
// 1. PCM 采样率固定 16kHz mono, 浏览器会自动 resample 麦克风输入
// (实际由 AudioContext sampleRate 参数保证)
// 2. ScriptProcessor 必须 connect 到 audioCtx.destination 才会触发
// onaudioprocess; 通过 GainNode(gain=0) 静音防止麦克风外放回声
// 3. 振幅采样走 AnalyserNode (与 PCM 采样并行, 不冲突)
// 4. onaudioprocess 每帧必须拷贝 channelData (new Float32Array(input)),
// 否则下一帧会覆盖导致 PCM 数据丢失
_startH5() {
return new Promise((resolve, reject) => {
if (typeof navigator === 'undefined' || !navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
reject(_err('H5_NO_MIC_API', 'mic API not available (HTTPS or localhost required)'))
return
}
const Ctx = window.AudioContext || window.webkitAudioContext
if (!Ctx) {
reject(_err('H5_NO_AUDIO_CTX', 'AudioContext not available'))
return
}
const buffers = []
let stream = null
let audioCtx = null
let source = null
let processor = null
let analyser = null
let silentGain = null
let rafId = null
// 清理 H5 资源 (失败 / 异常路径统一调用)
const cleanup = () => {
try { if (rafId) cancelAnimationFrame(rafId) } catch (e) { /* noop */ }
try { if (processor) processor.disconnect() } catch (e) { /* noop */ }
try { if (analyser) analyser.disconnect() } catch (e) { /* noop */ }
try { if (source) source.disconnect() } catch (e) { /* noop */ }
try { if (silentGain) silentGain.disconnect() } catch (e) { /* noop */ }
try { if (audioCtx && audioCtx.state !== 'closed') audioCtx.close().catch(() => {}) } catch (e) { /* noop */ }
try { if (stream) stream.getTracks().forEach(t => t.stop()) } catch (e) { /* noop */ }
}
navigator.mediaDevices.getUserMedia({
audio: {
channelCount: H5_NUM_CHANNELS,
// 注意: 部分浏览器会忽略 sampleRate 约束, 实际采样率以 AudioContext 为准
sampleRate: H5_SAMPLE_RATE,
echoCancellation: true,
noiseSuppression: true,
autoGainControl: true
}
})
.then((s) => {
stream = s
audioCtx = new Ctx({ sampleRate: H5_SAMPLE_RATE })
// 麦克风 → ScriptProcessor → 静音 GainNode → destination
// (ScriptProcessor 必须连到 destination 才会触发 onaudioprocess;
// 用 GainNode(gain=0) 静音, 防止麦克风声音外放产生回声)
source = audioCtx.createMediaStreamSource(stream)
const BufferSize = H5_SCRIPT_PROCESSOR_BUFFER_SIZE
processor = audioCtx.createScriptProcessor(BufferSize, H5_NUM_CHANNELS, H5_NUM_CHANNELS)
processor.onaudioprocess = (e) => {
const channelData = e.inputBuffer.getChannelData(0)
// 必须拷贝: inputBuffer 数据会被下一帧覆盖, 不拷贝会导致 PCM 丢失
buffers.push(new Float32Array(channelData))
}
silentGain = audioCtx.createGain()
silentGain.gain.value = 0
source.connect(processor)
processor.connect(silentGain)
silentGain.connect(audioCtx.destination)
// AnalyserNode 并行采振幅 (驱动波形动画)
analyser = audioCtx.createAnalyser()
analyser.fftSize = 256
source.connect(analyser)
const freqBuf = new Uint8Array(analyser.frequencyBinCount)
const tick = () => {
if (!this._isRecording) return
try {
analyser.getByteFrequencyData(freqBuf)
let sum = 0
for (let i = 0; i < freqBuf.length; i++) sum += freqBuf[i]
const level = Math.min(1, sum / (freqBuf.length * 255))
this._emit('progress', { level, duration: Date.now() - this._startTs })
} catch (e) { /* noop */ }
rafId = requestAnimationFrame(tick)
}
tick()
this._h5 = { stream, audioCtx, source, processor, analyser, silentGain, rafId, buffers, sampleRate: audioCtx.sampleRate, cleanup }
this._isRecording = true
this._startTs = Date.now()
this._setAutoStopTimer()
resolve()
})
.catch((err) => {
// 麦克风权限拒绝 / 设备不可用
cleanup()
reject(_err('H5_MIC_PERMISSION', (err && err.message) || 'mic permission denied or device unavailable'))
})
})
}
_stopH5() {
return new Promise((resolve) => {
const h5 = this._h5
if (!h5) { resolve(null); return }
// 1) 拆 audio graph + 停流 (避免 onprocess 继续累积 buffer)
try { h5.cleanup() } catch (e) { /* noop */ }
// 2) 合并 PCM 帧缓冲
const sampleRate = h5.sampleRate || H5_SAMPLE_RATE
const merged = mergeFloat32Arrays(h5.buffers || [])
// 3) 编码标准 WAV (PCM 16-bit LE mono)
const wavBuffer = encodeWavPcm16LE(merged, sampleRate, H5_NUM_CHANNELS)
const blob = new Blob([wavBuffer], { type: 'audio/wav' })
this._h5 = null
this._isRecording = false
this._clearAutoStopTimer()
if (merged.length === 0) {
// 没有采到任何 PCM (例如用户没说话或立即 stop)
resolve(null)
return
}
const fileName = `voice_${Date.now()}.wav`
const blobUrl = (typeof URL !== 'undefined' && URL.createObjectURL)
? URL.createObjectURL(blob)
: ''
resolve({
filePath: blobUrl,
blob,
fileName,
duration: Date.now() - this._startTs,
mime: 'audio/wav',
size: blob.size,
cancelled: false
})
})
}
_cancelH5() {
return new Promise((resolve) => {
const h5 = this._h5
if (!h5) {
this._isRecording = false
this._clearAutoStopTimer()
resolve()
return
}
try { h5.cleanup() } catch (e) { /* noop */ }
this._h5 = null
this._isRecording = false
this._clearAutoStopTimer()
resolve()
})
}
// ===================== uni-app (MP/APP/鸿蒙) 实现 =====================
_startUni() {
// PR-FRONTEND-VOICE-SINGLETON: 串行化所有对微信录音单例的访问,
// 防止"上一个 onStop 还没触发, 下一个 start() 就报 audio is recording"。
return _singletonIdlePromise.then(() => {
// 防竞态: 注册 .then() 后到回调执行前, 可能有其他实例先占用了单例, 需要重新排队。
if (_singletonBusyInstance && _singletonBusyInstance !== this) {
console.log(`[voice-recorder:${this._id}] _startUni: singleton busy by ${_singletonBusyInstance._id}, re-queue`)
return this._startUni()
}
_setSingletonBusy(this, this._maxDuration)
console.log(`[voice-recorder:${this._id}] _startUni: singleton busy acquired`)
return this._doStartUni()
})
}
_doStartUni() {
return new Promise((resolve, reject) => {
let rec = null
try {
rec = _getSingletonRecorder()
} catch (e) {
_setSingletonIdle(this)
reject(_err('NO_RECORDER_MANAGER', 'uni.getRecorderManager unavailable'))
return
}
if (!rec) {
_setSingletonIdle(this)
reject(_err('NO_RECORDER_MANAGER', 'recorder manager unavailable'))
return
}
this._uniRec = rec
this._isStarting = true
console.log(`[voice-recorder:${this._id}] _startUni: start() invoked on singleton`)
rec.onStart(() => {
console.log(`[voice-recorder:${this._id}] onStart fired`)
this._isRecording = true
this._isStarting = false
this._startTs = Date.now()
this._setAutoStopTimer()
if (this._pendingStop) {
// 用户在录音真正开始前就松手: 立即结束, 产物经 onStop 返回
console.log(`[voice-recorder:${this._id}] onStart: pendingStop detected, calling rec.stop()`)
this._pendingStop = false
try { rec.stop() } catch (e) { /* onStop 自会兜底 */ }
}
resolve()
})
rec.onStop((res) => {
// res = { tempFilePath, duration, fileSize }
console.log(`[voice-recorder:${this._id}] onStop fired`, res, 'hasStopResolve=', !!this._stopResolve)
this._clearStopFallbackTimer()
this._uniRec = null
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
// PR-FRONTEND-VOICE-FORMAT (2026-09-29): 微信临时文件后缀才是真实容器格式:
// Android aac → .m4a, iOS aac → .aac, mp3 → .mp3。按实际后缀给 mime/文件名,
// 避免播放器/后端因后缀与容器不符而失败。
const tempPath = (res && res.tempFilePath) || ''
const rawExt = (tempPath.split('?')[0].split('/').pop().match(/\.([a-z0-9]+)$/i) || [])[1] || ''
const ext = rawExt.toLowerCase()
const mime = ext === 'm4a' ? 'audio/mp4'
: ext === 'aac' ? 'audio/aac'
: ext === 'mp3' ? 'audio/mpeg'
: ext === 'wav' ? 'audio/wav'
: (this._format === 'wav' ? 'audio/wav'
: this._format === 'aac' ? 'audio/aac'
: 'audio/mpeg')
// PR-FRONTEND-VOICE-DURATION-FIX (2026-09-29): 微信 onStop 的 duration
// 偶尔为 0, 用 start→stop 真实时长兜底, 避免下游按 duration=0 丢弃。
const realDuration = this._startTs ? Date.now() - this._startTs : 0
const reportedDuration = (res && typeof res.duration === 'number') ? res.duration : 0
const duration = reportedDuration > 0 ? reportedDuration : realDuration
const result = {
filePath: tempPath,
blob: null,
fileName: tempPath ? `voice_${Date.now()}.${ext || 'aac'}` : '',
duration,
mime,
size: res.fileSize || 0,
cancelled: false
}
if (this._stopResolve) {
const r = this._stopResolve
this._stopResolve = null
r(result)
} else if (result.filePath && result.duration > 0) {
// PR-FRONTEND-VOICE-RACE: onStop 在 stop() 之前触发且产物有效, 缓存起来
this._earlyStopResult = result
}
_setSingletonIdle(this)
})
rec.onError((err) => {
this._clearStopFallbackTimer()
const e = _err('UNI_RECORD_ERROR', (err && (err.errMsg || err.message)) || 'record failed')
console.error(`[voice-recorder:${this._id}] UNI_RECORD_ERROR raw:`, err, 'errMsg=', err && err.errMsg, 'message=', err && err.message)
this._uniRec = null
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
this._emit('error', e)
if (this._stopResolve) {
const r = this._stopResolve
this._stopResolve = null
r(null)
} else {
// 启动阶段的 reject
reject(e)
}
_setSingletonIdle(this)
})
// 振幅事件 (uni-app 文档:onFrameRecorded, frameSize 单位 KB, frameBuffer ArrayBuffer)
if (typeof rec.onFrameRecorded === 'function') {
rec.onFrameRecorded((res) => {
if (!res || !res.frameBuffer) return
// frameBuffer 是 PCM 字节,简单用 |sample| / 0x8000 取平均振幅
try {
const view = new DataView(res.frameBuffer)
let sum = 0
const len = res.frameBuffer.byteLength
const step = Math.max(2, Math.floor(len / 256))
for (let i = 0; i < len; i += step) {
const v = view.getInt16(i, true)
sum += Math.abs(v)
}
const avg = sum / Math.max(1, Math.floor(len / step))
const level = Math.min(1, avg / 16384)
this._emit('progress', { level, duration: Date.now() - this._startTs })
} catch (e) { /* noop */ }
})
}
try {
rec.start({
// PR-FRONTEND-VOICE-DURATION-UNIT (2026-09-29): 微信 RecorderManager.start 的 duration
// 单位是毫秒(ms), 不是秒。之前 /1000 导致只录 60ms 就被自动停止。
duration: this._maxDuration,
sampleRate: this._sampleRate,
numberOfChannels: this._channels,
encodeBitRate: this._bitRate,
format: this._format
// PR-FRONTEND-VOICE-FRAMESIZE (2026-09-29): 去掉 frameSize, 部分机型对此参数敏感,
// 可能导致录音被提前中断。
})
} catch (e) {
this._clearStopFallbackTimer()
this._uniRec = null
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
_setSingletonIdle(this)
// 启动阶段就被 stop()/cancel() 抢占, 需要 Fulfill 挂起的 Promise, 而不是 reject
if (this._stopResolve && this._pendingStop) {
const r = this._stopResolve
this._stopResolve = null
this._pendingStop = false
r(null)
return
}
reject(e)
}
})
}
_stopUni() {
return new Promise((resolve) => {
console.log(`[voice-recorder:${this._id}] _stopUni called`)
const rec = this._uniRec
if (!rec) { resolve(null); return }
this._earlyStopResult = null
this._stopResolve = resolve
this._clearStopFallbackTimer()
// PR-FRONTEND-VOICE-FALLBACK: 真机偶发 onStop 不回调, 导致 stop() 永远挂起,
// UI 无法释放旧实例, 新录音提示"recorder already exists"。最多等 3s 强制 resolve。
this._stopFallbackTimer = setTimeout(() => {
console.warn(`[voice-recorder:${this._id}] _stopUni fallback timeout, force resolve`)
this._stopResolve = null
this._pendingStop = false
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
this._uniRec = null
_setSingletonIdle(this)
resolve(null)
}, 3000)
try { rec.stop() } catch (e) {
this._clearStopFallbackTimer()
this._stopResolve = null
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
this._uniRec = null
_setSingletonIdle(this)
resolve(null)
}
})
}
_cancelUni() {
return new Promise((resolve) => {
console.log(`[voice-recorder:${this._id}] _cancelUni called`)
this._earlyStopResult = null
const rec = this._uniRec
if (!rec) {
// 挂起的 stop 需要一并了结, 避免松手后卡在 pending
if (this._stopResolve && this._pendingStop) {
const r = this._stopResolve
this._stopResolve = null
this._pendingStop = false
r(null)
}
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
_setSingletonIdle(this)
resolve()
return
}
this._stopResolve = () => resolve()
this._pendingStop = false
this._clearStopFallbackTimer()
// PR-FRONTEND-VOICE-FALLBACK: cancel() 同样可能因 onStop 不回调而挂起。
this._stopFallbackTimer = setTimeout(() => {
console.warn(`[voice-recorder:${this._id}] _cancelUni fallback timeout, force resolve`)
this._stopResolve = null
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
this._uniRec = null
_setSingletonIdle(this)
resolve()
}, 3000)
try { rec.stop() } catch (e) {
this._clearStopFallbackTimer()
this._isRecording = false
this._isStarting = false
this._clearAutoStopTimer()
this._uniRec = null
_setSingletonIdle(this)
resolve()
}
})
}
// ===================== 工具 =====================
_setAutoStopTimer() {
this._clearAutoStopTimer()
this._autoStopTimer = setTimeout(() => {
// 自动停止 (上限到达)
if (this._isRecording) {
this.stop().catch(() => { /* swallow */ })
}
}, this._maxDuration)
}
_clearAutoStopTimer() {
if (this._autoStopTimer) {
clearTimeout(this._autoStopTimer)
this._autoStopTimer = null
}
}
_clearStopFallbackTimer() {
if (this._stopFallbackTimer) {
clearTimeout(this._stopFallbackTimer)
this._stopFallbackTimer = null
}
}
}
export default createVoiceRecorder

View File

@@ -187,8 +187,9 @@
<!-- 三级分类(及更深层级): 一级分类标题 + 二级分类网格(图3) -->
<view :class="['category-title', '']">{{ category.category_name }}</view>
<view class="category-list">
<!-- 点二级分类进入商品列表: 带 list_style=grid 让列表页默认用竖版(双列宫格)视图, hide_sort=1 隐藏排序栏 -->
<view class="category-item" v-for="(one, oneIndex) in category.child_list" :key="oneIndex"
@tap.stop="$util.redirectTo('/pages_goods/list', { category_id: one.category_id })">
@tap.stop="$util.redirectTo('/pages_goods/list', { category_id: one.category_id, list_style: 'grid', hide_sort: 1 })">
<view class="img-box">
<image :src="categoryImg(one.image)" mode="aspectFit" @error="categoryImgError(2, oneIndex, -1)" show-menu-by-longpress />
</view>

View File

@@ -1,499 +0,0 @@
<template>
<view data-component-name="diy-webview" class="diy-webview" :style="containerStyle" @tap="handleTap">
<template v-if="src">
<!-- #ifdef H5 -->
<iframe
v-if="!lazyPending"
class="diy-webview-iframe"
:src="src"
:scrolling="scrollMode"
referrerpolicy="no-referrer"
frameborder="0"
allow="fullscreen"
loading="lazy"
@load="handleIframeLoad"
@error="handleIframeError"
></iframe>
<!-- 后台配置的占位图 / 懒加载未进入视口时的展示 -->
<image
v-if="placeholderUrl && (lazyPending || !loaded)"
class="diy-webview-placeholder"
:src="placeholderUrl"
mode="aspectFill"
></image>
<!-- 加载中遮罩:iframe 触发 load 前展示,避免白屏观感 -->
<view v-if="!loaded && !loadError && !lazyPending" class="webview-loading" :style="errorStyle">
<view class="webview-loading-spinner"></view>
<text class="webview-loading-text">网页加载中...</text>
</view>
<!-- H5 下 iframe 内部点击不会冒泡到父容器,提供角标按钮保证"点击跳转"可用 -->
<view class="webview-open-chip" @tap.stop="mpGo">
<text class="iconfont icon-fuzhilianjie"></text>
<text class="webview-open-chip-text">{{ mpGoText }}</text>
</view>
<!-- #endif -->
<!-- #ifndef H5 -->
<!-- 小程序/APP:内嵌 web-view 会整页覆盖原生层,改为卡片展示 + 点击跳转 -->
<view class='webview-mp-go' :style='mpGoStyle' @tap.stop='mpGo'>
<text class='iconfont icon-fuzhilianjie'></text>
<text class='webview-mp-go-text'>{{ mpGoText }}</text>
</view>
<!-- #endif -->
<!-- 加载失败兜底(如目标站禁止被嵌入/内核过旧加载失败):可点击直接打开 -->
<view v-if="loadError" class="webview-error" :style="errorStyle" @tap.stop="mpGo">
<text class="iconfont icon-fuzhilianjie"></text>
<text class="error-text">{{ errorText }}</text>
<text class="error-open">点击此处打开网页</text>
</view>
</template>
<view v-else class="webview-empty" :style="emptyStyle">
<text class="iconfont icon-fuzhilianjie"></text>
<text class="empty-text">请配置网页链接</text>
</view>
</view>
</template>
<script>
// 网页/WebView 组件:后台配置 URL 后嵌入展示,H5 使用 iframe,小程序/APP 使用原生 web-view
import DiyMinx from './minx.js'
export default {
name: 'diy-webview',
props: {
value: {
type: Object,
default: () => ({})
}
},
data() {
return {
src: '',
loaded: false,
loadError: false,
// 后台开启"懒加载"时,iframe 需等容器滚动进入视口后才真正渲染
lazyPending: false
};
},
mixins: [DiyMinx],
created() {
this.initWebview();
},
mounted() {
this._mountedFlag = true;
// #ifdef H5
if (this.lazyPending) this._setupLazyObserver();
// #endif
},
beforeDestroy() {
if (this._observer) {
try { this._observer.disconnect(); } catch (e) {}
this._observer = null;
}
this._clearLoadTimer();
},
watch: {
value: {
immediate: true,
deep: true,
handler(newVal) {
if (newVal) {
this.initWebview();
}
}
}
},
computed: {
containerStyle() {
let style = '';
// 后台高度为 px 值,与项目其他组件一致 ×2 转 rpx(diy-horz-blank 同款换算)
const height = Number(this.value?.height) || 300;
style += `height:${height * 2}rpx;`;
// 组件角度 round 时按后台圆角值渲染(×2 rpx)
if (this.value?.componentAngle === 'round') {
const topR = Number(this.value?.topAroundRadius) || 0;
const bottomR = Number(this.value?.bottomAroundRadius) || 0;
style += `border-radius:${topR * 2}rpx ${topR * 2}rpx ${bottomR * 2}rpx ${bottomR * 2}rpx;`;
}
if (this.value?.bgColor) {
style += `background:${this.value.bgColor};`;
}
if (this.value?.marginTop) {
style += `margin-top:${this.value.marginTop}rpx;`;
}
if (this.value?.marginBottom) {
style += `margin-bottom:${this.value.marginBottom}rpx;`;
}
if (this.value?.padding) {
style += `padding:${this.value.padding}rpx;`;
}
return style;
},
emptyStyle() {
let style = '';
if (this.value?.bgColor) {
style += `background:${this.value.bgColor};`;
}
return style;
},
errorStyle() {
let style = '';
if (this.value?.bgColor) {
style += `background:${this.value.bgColor};`;
}
return style;
},
mpGoText() {
// 注意:this.$lang(key) 在 key 不存在时返回 key 字符串本身,不能仅靠 this.$lang 是否存在判断。
// 取到 key 与传入 key 不同才视为命中语言包,否则用 fallback。
const t = this.$lang && this.$lang('components-diy.diy-webview.mpGo');
return (t && t !== 'components-diy.diy-webview.mpGo') ? t : '点击查看网页内容';
},
mpGoStyle() {
let style = '';
if (this.value && this.value.bgColor) {
style += 'background:' + this.value.bgColor + ';';
}
return style;
},
errorText() {
const t = this.$lang && this.$lang('components-diy.diy-webview.loadError');
return (t && t !== 'components-diy.diy-webview.loadError') ? t : '网页加载失败,请检查链接';
},
// iframe 滚动条开关(后台"滚动"配置:true 显示 / false 隐藏)
scrollMode() {
const s = this.value?.scrolling;
return (s === false || s === 'false' || s === 0) ? 'no' : 'yes';
},
// 占位图(后台 imageUrl,iframe 加载完成前展示)
placeholderUrl() {
const url = this.value?.imageUrl;
return url ? (this.$util.img ? this.$util.img(url) : url) : '';
}
},
methods: {
initWebview() {
const config = this.value || {};
this.loadError = false;
this.loaded = false;
// 调试用:把后台下发的完整 value 对象打印到控制台,方便定位 URL 字段名
console.log('[diy-webview] value:', JSON.stringify(config));
// 兼容后台可能使用的多种链接字段名/嵌套结构
const url = this.extractUrl(config);
// 懒加载:开启时等容器进入视口再渲染 iframe
this.lazyPending = !!(config.lazyRender || config.lazyLoad);
// #ifdef H5
// 数据热更新时(后台重新保存)若尚未进入过视口,需重建观察器(仅在挂载后才可建立)
if (this.lazyPending && this._mountedFlag) this._setupLazyObserver();
// #endif
// 优先使用后台直接下发的 url;若配置的是接口来源(source=api),则通过接口拉取
if (config.source === 'api' && config.apiUrl) {
this.loadUrlFromApi(config.apiUrl);
} else if (url) {
this.src = this.buildSrc(url);
console.log('[diy-webview] src:', this.src);
this._startLoadTimer();
} else {
this.src = '';
console.warn('[diy-webview] 未找到有效链接字段');
}
},
// 在格式化后的 URL 基础上,拼接后台配置的"附加参数"与"携带登录态"(token / member_id)
buildSrc(url) {
let src = this.formatUrl(url);
const config = this.value || {};
const extra = [];
// 附加参数(后台 urlParams 字段,格式 "a=1&b=2",多组参数用 & 连接)
const rawExtra = config.urlParams || config.extraParams || config.appendParams || config.additionalParams || config.params;
if (rawExtra && typeof rawExtra === 'string') {
extra.push(rawExtra.replace(/^[?&]+/, ''));
}
// 携带登录态(后台 carryToken 字段:none 不携带 / token / member_id)
const loginState = config.carryToken || config.loginState || config.login_state;
if (loginState === 'token') {
const token = (this.$store && this.$store.state && this.$store.state.token) || '';
if (token) extra.push('token=' + encodeURIComponent(token));
} else if (loginState === 'member_id') {
const memberInfo = (this.$store && this.$store.state && this.$store.state.memberInfo) || {};
const memberId = memberInfo.member_id || memberInfo.memberId || '';
if (memberId) extra.push('member_id=' + memberId);
}
if (extra.length) {
src += (src.indexOf('?') !== -1 ? '&' : '?') + extra.filter(Boolean).join('&');
}
return src;
},
// #ifdef H5
// 懒加载:容器滚动进入视口(含预加载缓冲 200px)后才渲染 iframe
_setupLazyObserver() {
try {
if (this._observer) {
this._observer.disconnect();
this._observer = null;
}
this._observer = uni.createIntersectionObserver(this, { thresholds: [0] });
this._observer.relativeToViewport({ bottom: 200 }).observe('.diy-webview', () => {
this.lazyPending = false;
if (this._observer) {
this._observer.disconnect();
this._observer = null;
}
});
} catch (e) {
// 观察器异常时直接渲染,避免内容永远空白
this.lazyPending = false;
}
},
// #endif
extractUrl(config) {
if (!config || typeof config !== 'object') return '';
// 优先读取常见字段名(兼容后台不同命名习惯)
let direct = config.url || config.link || config.linkUrl || config.pageUrl || config.webUrl || config.web_url || config.externalUrl || config.targetUrl || config.src || config.href || config.path || config.address;
// 兼容装修链接选择器下发的对象形态:link = { wap_url / url / h5_url ... }
if (direct && typeof direct === 'object') {
direct = direct.wap_url || direct.h5_url || direct.url || direct.app_url || direct.link || '';
}
if (direct && typeof direct === 'string') return direct.trim();
// 兼容嵌套结构:如 value.value.url / value.config.url / value.data.url
for (const key of ['value', 'config', 'data', 'content', 'params']) {
if (config[key] && typeof config[key] === 'object') {
const nested = this.extractUrl(config[key]);
if (nested) return nested;
}
}
return '';
},
formatUrl(url) {
if (!url || typeof url !== 'string') return '';
let formatted = url.trim();
// 如果后台把 URL 编码存储,做一次解码
if (formatted.indexOf('%') !== -1) {
try { formatted = decodeURIComponent(formatted); } catch (e) {}
}
// 支持以 http:// 或 https:// 开头的完整地址
if (/^https?:\/\//i.test(formatted)) return formatted;
// 支持相对路径或站点内链接,自动补全
return this.$util.img ? this.$util.img(formatted) : formatted;
},
loadUrlFromApi(apiUrl) {
this.$api.sendRequest({
url: apiUrl,
success: res => {
if (res.code == 0 && res.data) {
const data = typeof res.data === 'string' ? { url: res.data } : res.data;
this.src = this.formatUrl(data.url || data.link || '');
}
},
fail: () => {
this.src = '';
}
});
},
updateNavbarTitle(e) {
// 参照 pages-tool/webview.vue:当 web-view 页面标题更新时,可同步设置导航栏标题
const title = e?.detail?.title || e?.title || '';
if (title) {
uni.setNavigationBarTitle({ title });
}
this.$emit('titleUpdate', e);
},
// 点击网页容器整体 → 跳转到配置的链接(走统一 diyRedirectTo,外链自动进 web-view / 新窗口)
handleTap() {
if (this.src) this.mpGo();
},
mpGo() {
if (!this.src) return;
if (this.$util && this.$util.diyRedirectTo) {
this.$util.diyRedirectTo({
wap_url: this.src,
title: (this.value && this.value.title) || (this.value && this.value.name) || '网页',
name: (this.value && this.value.name) ? this.value.name : '网页'
});
} else {
uni.navigateTo({ url: '/pages_tool/webview/webview?src=' + encodeURIComponent(this.src) });
}
},
// 注意:方法名不能叫 onLoad/onError —— uni-app 会把组件里的 onLoad 当页面
// 生命周期提升出 methods,导致 @load="onLoad" 渲染时报 handler undefined。
handleIframeLoad(e) {
this.loaded = true;
this.loadError = false;
this._clearLoadTimer();
this.$emit('load', e);
},
handleIframeError(e) {
this.loadError = true;
this.loaded = true;
this._clearLoadTimer();
console.error('[diy-webview] 加载失败:', this.src, e);
this.$emit('error', e);
},
// 加载超时兜底:部分浏览器内核(如 HBuilderX 内置浏览器的老 CEF 内核)对跨域 iframe
// 请求失败时不会触发 error 事件,用定时器兜住,避免容器一直白屏
_startLoadTimer() {
this._clearLoadTimer();
// #ifdef H5
this._loadTimer = setTimeout(() => {
if (!this.loaded) {
this.loadError = true;
console.warn('[diy-webview] 加载超时(10s),显示兜底内容:', this.src);
}
}, 10000);
// #endif
},
_clearLoadTimer() {
if (this._loadTimer) {
clearTimeout(this._loadTimer);
this._loadTimer = null;
}
},
onMessage(e) {
// 接收 web-view / iframe 发来的消息,可用于与后台数据交互
this.$emit('message', e);
// 同时通过事件总线广播,方便页面级监听
this.__$emitEvent({
eventName: 'diy-webview-message',
data: {
componentName: this.value?.componentName,
moduleIndex: this.value?.moduleIndex,
message: e?.detail?.data || e?.data
}
});
}
}
};
</script>
<style lang="scss">
.diy-webview {
width: 100%;
position: relative;
overflow: hidden;
box-sizing: border-box;
.diy-webview-iframe,
.diy-webview-native {
width: 100%;
height: 100%;
display: block;
border: none;
}
/* 占位图 / 懒加载未进入视口时的展示 */
.diy-webview-placeholder {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* H5 角标跳转按钮:iframe 内部点击不冒泡,用它兜底"点击跳转" */
.webview-open-chip {
position: absolute;
right: 16rpx;
bottom: 16rpx;
z-index: 3;
display: flex;
align-items: center;
padding: 8rpx 20rpx;
border-radius: 999rpx;
background: rgba(0, 0, 0, 0.55);
color: #fff;
font-size: 22rpx;
line-height: 1;
.iconfont {
font-size: 24rpx;
margin-right: 6rpx;
}
}
/* 加载中遮罩 */
.webview-loading {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #f7f8fa;
color: #999;
font-size: 24rpx;
}
.webview-loading-spinner {
width: 44rpx;
height: 44rpx;
border: 4rpx solid #e5e6eb;
border-top-color: #576b95;
border-radius: 50%;
margin-bottom: 16rpx;
animation: webview-spin 0.8s linear infinite;
}
@keyframes webview-spin {
to {
transform: rotate(360deg);
}
}
.webview-empty,
.webview-mp-go {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #f5f5f5;
color: #576B95;
font-size: 26rpx;
.iconfont {
font-size: 48rpx;
margin-bottom: 12rpx;
}
}
.webview-error {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: #f5f5f5;
color: #999;
font-size: 26rpx;
.iconfont {
font-size: 48rpx;
margin-bottom: 12rpx;
}
}
.webview-error {
position: absolute;
top: 0;
left: 0;
z-index: 2;
background: rgba(255, 255, 255, 0.96);
color: #ff6b35;
.error-open {
margin-top: 16rpx;
font-size: 24rpx;
color: #576b95;
text-decoration: underline;
}
}
}
</style>

View File

@@ -1,7 +1,7 @@
<template>
<!-- Vue 2 / uni-app 单根约束:用 view 包一层 -->
<view>
<view v-if="(pageCount === 1 || need) && fbVisible && hasAnyButton" class="fixed-box"
<view v-if="(pageCount === 1 || need) && hasVisibleFixBtn" class="fixed-box"
:style="[customContainerStyle, {
height: containerHeight,
bottom: containerBottom,
@@ -11,18 +11,18 @@
}]">
<!-- 多语言切换按钮:根据语言数智能切换交互 -->
<view
v-if="isLanguageSwitchEnabled && hasLangButton"
v-if="isLanguageSwitchEnabled && fixBtnShow"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.lang }]"
:style="btnItemStyle"
@click="handleLangButtonClick"
>
<view class="lang-btn-text">{{ langButtonText }}</view>
<view class="lang-btn-text">{{ currentLangDisplayName }}</view>
</view>
<!-- 微信官方客服按钮-->
<button
v-if="hasKefuButton && hasValidKefuConfig && isWeappOfficialKefu"
v-if="fixBtnShow && hasValidKefuConfig && isWeappOfficialKefu"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.kefu }]"
:style="btnItemStyle"
open-type="contact"
>
<text class="icox icox-kefu" v-if="!kefuimg"></text>
@@ -30,9 +30,9 @@
<!-- 其他类型客服按钮(智能客服、企业微信等)-->
<view
v-if="hasKefuButton && hasValidKefuConfig && !isWeappOfficialKefu && !showWeappSystemKefu"
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && !showWeappSystemKefu"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.kefu }]"
:style="btnItemStyle"
@click="handleUnifiedKefuClick"
>
<image
@@ -48,9 +48,9 @@
<!-- 智能客服按钮(当同时显示小程序系统客服时)-->
<view
v-if="hasKefuButton && hasValidKefuConfig && !isWeappOfficialKefu && showWeappSystemKefu"
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && showWeappSystemKefu"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.kefu }]"
:style="btnItemStyle"
@click="handleUnifiedKefuClick"
>
<image
@@ -66,19 +66,20 @@
<!-- 小程序系统客服按钮 -->
<button
v-if="hasKefuButton && hasValidKefuConfig && showWeappSystemKefu"
v-if="fixBtnShow && hasValidKefuConfig && showWeappSystemKefu"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.kefu }]"
:style="btnItemStyle"
open-type="contact"
>
<text class="icox icox-kefu" v-if="!kefuimg"></text>
</button>
<!-- 电话按钮 -->
<!-- 电话按钮 (已隐藏: 仅 display:none, DOM/事件/逻辑全部保留, 把 hidePhoneBtn 改回 false 即恢复) -->
<view
v-if="hasPhoneButton"
v-if="fixBtnShow"
class="btn-item common-bg"
:style="[btnItemStyle, { order: orderIndex.phone }, { backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
:class="{ 'btn-item-hide': hidePhoneBtn }"
:style="[btnItemStyle, { backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
@click="call"
>
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
@@ -109,10 +110,6 @@
<script>
import { createCustomerService } from '@/common/js/customer-service.js';
import i18nLazyMixin from '@/common/mixin/i18n-lazy.js';
import {
getCurrentRoute, shouldShowOnPage, resolveVisibleButtons,
resolveLangButtonText, isLangButtonVisible,
} from '@/common/js/floating-button.js';
// 语言短码映射表(currentLangDisplayName 展示用,可按需扩展)
// key: 语言 value,value: 显示短码(按钮上展示)
@@ -174,7 +171,7 @@ export default {
data() {
return {
pageCount: 0,
currentRoute: '', // 当前页面路由(onShow / created 时刷新, 供页面范围判定)
fixBtnShow: true,
shopInfo: null,
currentLangIndex: 0,
langIndexMap: {},
@@ -182,6 +179,9 @@ export default {
langDisplayMap: { ...LANG_DISPLAY_NAMES }, // 后端 langDisplayNames 会覆盖默认值
showLangPopup: false, // 语言选择弹窗显隐
customerService: null,
// 是否隐藏「电话」悬浮按钮: true = 隐藏(只隐藏不移除, DOM/点击事件/拨打逻辑都保留)
// 需要恢复时改回 false 即可, 或按需接后端配置
hidePhoneBtn: true,
// ============================================================
// 布局参数(从 App.vue 的 :root CSS 变量读取,权威源在 App.vue)
// 关键设计:
@@ -241,57 +241,6 @@ export default {
customButtonStyle() {
return this.shopInfo?.floatingButton?.button || {};
},
// ============================================================
// 浮动侧边栏配置消费 (来源: /api/config/init → data.floating_button,
// store/index.js 的 floatingButtonConfig, 初始 state 已声明 → 响应式)
// fbConfig 为 null (老缓存响应缺字段) 时, 各判定全部走老行为兜底。
// ============================================================
// 接口下发的浮动侧边栏配置 (老缓存响应 → null)
fbConfig() {
return (this.$store && this.$store.state && this.$store.state.floatingButtonConfig) || null;
},
// 总开关 + 强制隐藏 + 页面范围 判定结果
fbVisible() {
return shouldShowOnPage(this.fbConfig, this.currentRoute, true);
},
// 最终要渲染的按钮 (已按 button_order 排序 + 显隐过滤); null = 用老行为
visibleButtons() {
return resolveVisibleButtons(this.fbConfig);
},
hasAnyButton() {
const b = this.visibleButtons;
return b ? b.length > 0 : true; // 老行为: 电话按钮恒显
},
hasLangButton() {
const b = this.visibleButtons;
return b ? b.indexOf('lang') !== -1
: isLangButtonVisible(this.fbConfig, this.shopInfo, this.langList.length);
},
hasKefuButton() {
const b = this.visibleButtons;
return b ? b.indexOf('kefu') !== -1 : true;
},
hasPhoneButton() {
const b = this.visibleButtons;
return b ? b.indexOf('phone') !== -1 : true;
},
// 语言按钮文案: 商家可配「目标语言 / 当前语言 / 固定文案」。
// 配置缺失时回退老行为 currentLangDisplayName(展示当前语言)。
langButtonText() {
if (!this.fbConfig) return this.currentLangDisplayName;
return resolveLangButtonText(this.fbConfig, this.langList, this.currentLangIndex);
},
// 按钮渲染顺序 (button_order 自上而下); .fixed-box 是 flex-direction: column,
// 用 CSS order 控制三段(语言/客服/电话)的先后, 配置缺失时退回老顺序。
orderIndex() {
const order = (this.fbConfig && Array.isArray(this.fbConfig.button_order))
? this.fbConfig.button_order
: ['lang', 'kefu', 'phone'];
const map = {};
for (let i = 0; i < order.length; i++) map[order[i]] = i + 1;
map.lang = map.lang || 1; map.kefu = map.kefu || 2; map.phone = map.phone || 3;
return map;
},
// 所有 .btn-item 的 inline-style 兜底:
// 1) 测试发现 .btn-item 的 min-*/max-*/aspect-ratio/flex-shrink 等 !important
// 规则在 scoped 样式下,被某些 flex 布局的隐式约束吃掉,只 width/height/border-radius
@@ -350,25 +299,31 @@ export default {
const customerService = createCustomerService(this);
return customerService.hasValidKefuConfig();
},
// 是否还有需要展示的浮动按钮:
// 电话按钮被隐藏、且没有语言切换/客服按钮时, 整个浮动按钮容器都不渲染,
// 避免留下一个透明的空容器挡住下面的页面内容点击
hasVisibleFixBtn() {
return !this.hidePhoneBtn || this.isLanguageSwitchEnabled || this.hasValidKefuConfig;
},
//根据显示的按钮数量动态计算容器高度
// 计算明细(buttonCount 按钮场景):
// 每个按钮槽位:72rpx(按钮,与 to-top 一致) + 14rpx(上 margin) + 14rpx(下 margin) = 100rpx
// 容器 padding:20rpx 上 + 20rpx 下 = 40rpx
// 总高度 (rpx):buttonCount × 100 + 40
// 新配置生效时按 visibleButtons 的实际按钮数算,避免隐藏按钮后留下空白档;
// 全部按钮被关掉时返回 0rpx(根节点 v-if 已含 hasAnyButton, 这里是双保险);
// 配置缺失(fbConfig 为 null)时保持老行为: 电话恒显 + 可选语言 + 可选系统客服。
// extraKefuSlot: 小程序系统客服与客服主按钮并存时模板会多渲染一个按钮,
// 需要为它多留一个槽位(fallback 分支与老逻辑等价)。
// 修复:改返回 rpx 而非 px(原 *0.5 硬编码 iPhone 6 375px 转换比),
// 在微信小程序/其他设备(iPhone 13 390px、iPad 等)下由 uni-app 框架
// 按 windowWidth 动态换算,避免 4+ 按钮时容器偏小导致内容被裁切
// 关联:按钮尺寸与 to-top 同步(72rpx),所以槽位高度也是 100rpx;
// 之前按钮 80rpx 时槽位 108rpx,改为 72rpx 后槽位缩小 8rpx,容器整体更紧凑
containerHeight() {
const b = this.visibleButtons;
if (b && b.length === 0) return '0rpx';
if (!this.fixBtnShow) return '320rpx';
const extraKefuSlot = (this.hasKefuButton && this.showWeappSystemKefu) ? 1 : 0;
const buttonCount = b
? b.length + extraKefuSlot
: 1 + (this.isLanguageSwitchEnabled ? 1 : 0) + extraKefuSlot;
// 电话按钮隐藏时不再占用容器高度, 避免底部留白
let buttonCount = this.hidePhoneBtn ? 0 : 1;
if (this.isLanguageSwitchEnabled) buttonCount++;
if (this.showWeappSystemKefu) buttonCount++;
buttonCount++;
const totalRpx = buttonCount * 100 + 40;
return `${totalRpx}rpx`;
@@ -393,6 +348,7 @@ export default {
// 与 Top 按钮的 .mescroll-totop { margin-bottom: var(--window-bottom) } 一致,
// 两者会被安全区同步上推,space 保持不变
containerBottom() {
if (!this.fixBtnShow) return '240rpx';
let space = 18 * 5;
// #ifdef MP-WEIXIN
space = 18 * 1;
@@ -412,6 +368,7 @@ export default {
// - right edge 对齐(46rpx):左侧突出 28rpx,中心错位 14rpx
// center 对齐不仅中心精准,突出量也更小
containerRight() {
if (!this.fixBtnShow) return '0rpx';
const offset = this.layoutTopRight + this.layoutTopSize / 2 - this.layoutFloatingWidth / 2;
return `${offset}rpx`;
},
@@ -474,14 +431,9 @@ export default {
}
}
},
// 页面生命周期: hover-nav 是常驻组件, 路由变化必须靠 onShow 通知,
// 否则 currentRoute 停留在首次加载页, 页面范围判定(fbVisible)会失效。
onShow() {
this.refreshRoute();
},
created() {
this.initLanguage();
this.refreshRoute();
this.pageCount = getCurrentPages().length;
// 三源兜底(store / 同步 storage / 异步 storage),
// 任何一个先就绪就先使用,后续由 initStatus watcher 再次同步
@@ -582,11 +534,6 @@ export default {
// #endif
},
methods: {
// 刷新当前路由与页面栈深度(供 fbVisible 的页面范围判定 / pageCount 老判定)
refreshRoute() {
this.currentRoute = getCurrentRoute();
this.pageCount = getCurrentPages().length;
},
// #ifdef H5
/**
* 从 :root 读取 CSS 变量(App.vue 中定义)到 data,
@@ -928,6 +875,11 @@ export default {
background-color: var(--hover-nav-bg-color);
}
/* 电话悬浮按钮隐藏态: 只隐藏不移除(DOM、点击事件、拨打逻辑都还在), 去掉该类即恢复 */
.btn-item-hide {
display: none !important;
}
.btn-item text {
font-size: 28rpx;
}

View File

@@ -567,12 +567,6 @@ export default {
flex: 1;
margin-right: 30rpx;
justify-content: center;
/* 关键修复: 微信 <button> 原生默认 padding-left/right: 14px 没有被重置,
* 会挤压按钮内容区。真机窄屏(375px 以下)上「同意并继续」5 个字被裁成
* 「同意并继」。这里显式清零 padding 并锁定 border-box。 */
padding: 0;
box-sizing: border-box;
white-space: nowrap;
}
.privacy-button-btn::after {

View File

@@ -105,4 +105,38 @@ components/mescroll/components/mescroll-empty.json
有些"修模拟器表现"的尝试(@load 多次重试 setNavigationBarTitle、加看门狗定时器)会让真机代码变得复杂、可能和内嵌页 `document.title` 抢控制权、引入边界 case。
**结论**:遇到 navigationBar / web-view 相关问题,先在真机上复现确认;只在真机还在问题再继续查代码。
**结论**:遇到 navigationBar / web-view 相关问题,先在真机上复现确认;只在真机还在问题再继续查代码。
#### 4. `setClipboardData:fail api scope is not declared in the privacy agreement`
**症状**:AI 智能(`pages_tool/ai-chat`)复制消息时 Toast 提示
`复制失败:setClipboardData:fail api scope is not declared in the privacy agreement`,
H5 正常,**只有微信小程序失败**。
**根因**:微信自 2023-09-15 起把剪贴板接口(`setClipboardData` / `getClipboardData`)纳入
《小程序用户隐私保护指引》。小程序后台未声明「剪贴板」,或声明还在审核中时,调用直接失败,
返回 `errno: 112`。这是**平台侧配置问题,不是代码问题**:
`app.json` 的 `permission` / `requiredPrivateInfos` 都不涉及剪贴板,改代码无法绕过。
**正确处理**:
- 微信公众平台 → 设置 → 基本设置 → 服务内容声明 → 用户隐私保护指引 → 更新 →
在「开发者收集你的……信息」中勾选「剪贴板」并填写用途 → 提交审核;
**审核通过后才生效**,通过后重新编译/发版即恢复。
- 代码侧只做兜底:`common/js/uniapp.utils.js` 的 `isClipboardPrivacyError()` 识别
`errno === 112` / errMsg 含 `privacy agreement`,用 i18n 文案替换微信原始英文错误
(AI 聊天页 `copyMessage` 同样处理),不要把平台英文报错抛给用户。
- 开发期想临时绕过校验:把 `manifest.json` → `mp-weixin` → `"__usePrivacyCheck__"` 改成 `false`
(**仅限本地调试**,上线前必须还原,并按上面的后台配置完成声明)。
**注意**:根目录的 `privacy.json`(内容为 `Scope.writeClipboard`)不是微信的隐私声明机制,
未被任何代码或构建流程引用,不要把它当成剪贴板隐私的解决方案。
**代码侧备选(无法改后台、只想先跑起来时)**:
- 写剪贴板在微信里只有 `wx.setClipboardData` 这一个 JS API,平台拦截 errno 112 时**任何代码都绕不过**,
所以「复制」按钮在没声明剪贴板权限前必然失败。
- AI 回复的**展示**走 `<rich-text>` 富文本(豆包风格:加粗标题、悬挂缩进列表、彩色链接),由
`parseMarkdown()` 生成 HTML、`getAIDisplayContent()` 输出,H5 用 `v-html`、微信小程序用 `<rich-text :nodes>`。
- 富文本**不可长按选区复制**(微信 rich-text 不支持),复制只能走「复制」按钮(即 `wx.setClipboardData`),
因此必须声明剪贴板权限,或开发期把 `manifest.json` → `mp-weixin` → `"__usePrivacyCheck__"` 改 `false`
(仅本地调试,上线前必须还原)。
- 失败时提示会引导用户复制不可用(`isClipboardPrivacyError()` 识别 errno 112)。

View File

@@ -2625,7 +2625,7 @@
},
"ai-chat": {
"index": {
"title": "AI智能客服",
"title": "AI智能",
"cancel": "取消",
"save": "保存",
"send": "发送",
@@ -2642,7 +2642,7 @@
"loadMoreHistory": "加载更多历史消息",
"loadingHistory": "加载历史消息中...",
"aiThinking": "AI正在思考",
"receivingReply": "正在接收回复",
"receivingReply": "思考中",
"aiThinkingStatus1": "AI正在思考",
"aiThinkingStatus2": "AI正在分析",
"aiThinkingStatus3": "AI正在检索",
@@ -2652,6 +2652,10 @@
"noContentToCopy": "无可复制的内容",
"copySuccess": "已复制",
"copySelected": "已复制选中内容",
"selectTextToCopy": "选取文字复制",
"selectedText": "已选文字",
"copyAll": "复制全部",
"selectTextTip": "长按文字拖动两端手柄,可自由选择复制范围",
"copyFail": "复制失败",
"copyFailWithReason": "复制失败:{reason}",
"openingFile": "打开文件中...",

View File

@@ -22,25 +22,14 @@ export const lang = {
// ====== ai-chat-message ======
aiNickname: 'AI Assistant',
defaultNickname: 'Me',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): query text for attachment-only messages
// audioMessage / videoMessage: short label for the user-bubble filename fallback (still used by bubble template)
// *Instruction* keys: explicit directive sent to the AI as the query.
// Just a label gets ignored — the AI needs an explicit "please listen/look"
// to actually invoke STT/vision/file parsing on the attachment payload.
audioMessage: 'Voice Message',
videoMessage: 'Video Message',
audioInstruction: 'I sent a voice message. Please listen to it and reply.',
audioInstructionWithDuration: 'I sent a voice message ({seconds}s). Please listen to it and reply.',
imageInstruction: 'I sent an image. Please look at it and reply.',
videoInstruction: 'I sent a video. Please watch it and reply.',
fileInstruction: 'I sent a file. Please review it and reply.',
attachmentInstruction: 'I sent attachments. Please review them and reply.',
inputPlaceholder: 'Please enter your question...',
expandEditorTitle: 'Edit Content',
loadMoreHistory: 'Load more history',
loadingHistory: 'Loading history...',
aiThinking: 'AI is thinking',
receivingReply: 'Receiving reply',
receivingReply: 'Thinking',
aiThinkingStatus1: 'AI is thinking',
aiThinkingStatus2: 'AI is analyzing',
aiThinkingStatus3: 'AI is searching',
@@ -52,6 +41,7 @@ export const lang = {
copySelected: 'Copied selected content',
copyFail: 'Copy failed',
copyFailWithReason: 'Copy failed: {reason}',
copyFailPrivacyReason: 'clipboard permission not declared, copy unavailable',
openingFile: 'Opening file...',
openingFileName: 'Opening file: {name}',
openingFileTitle: 'Opening: {title}',
@@ -140,37 +130,12 @@ export const lang = {
chooseVideoFail: 'Failed to select video',
audioNotReady: 'Audio not ready',
location: 'Location',
// PR-AUTO-LOCATION (2026-09-28): automatic location permission prompts
locationPermissionTitle: 'Location Permission Required',
locationPermissionH5: 'Please enable location permission via the lock icon in your browser address bar, then resend the message.',
locationPermissionMp: 'To help the AI better answer location-related questions, please enable location permission.\n\nTap "Open Settings" to enable it in your system settings, then return to this page and resend the message.',
locationSettingBtn: 'Open Settings',
locationSkipBtn: 'Not Now',
locationH5GuideBtn: 'Got it',
// ====== ai-chat-voice-panel ======
voiceInputTitle: 'Voice Input',
recordingTip: 'Recording, release to end',
startRecordTip: 'Tap to start recording',
voiceInputFailed: 'Voice input failed',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): press-and-hold gesture + recorder error messages
holdToTalk: 'Hold to talk',
releaseToSend: 'Release to send',
releaseToCancel: 'Release to cancel',
slideUpToCancel: '↑ Slide up to cancel',
slideUpToCancelHint: '↑ Slide up to cancel',
// PR-INPUT-PLACEHOLDER-DYNAMIC (2026-09-28): dynamic input placeholder by context
placeholderDefault: 'Type a message or hold to talk',
placeholderWithAudio: 'Add a note for your voice (optional)',
placeholderWithMedia: 'Add a caption (optional)',
slideUpToCancelHint: '↑ Release to cancel',
voiceStartFailed: 'Cannot start recording',
voiceStopFailed: 'Recording failed, please try again',
voiceNotSupported: 'Voice input is not supported on this platform',
voiceTooShort: 'Speaking time too short',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): upload error (recorder result -> cloud)
uploadFailed: 'Upload failed',
uploadFailedWithReason: 'Upload failed: {reason}',
// ====== index.vue - Menu ======
menuClearChat: 'Clear Chat',
@@ -185,7 +150,7 @@ export const lang = {
logEventHandleError: 'Event handling error',
logInitNavbarFailed: 'Failed to initialize navigation bar',
logChatComponentNotInit: 'Chat component not initialized',
logServicerConfigNotLoaded: '[AI Customer Service] servicerConfig not loaded, retrying after 200ms...'
logServicerConfigNotLoaded: '[AI Customer Service] servicerConfig not loaded, retrying after 200ms...',
// ====== AI Agent general copy (customer service is the first agent) ======
aiAgentDefaultTitle: 'AI Agent',

View File

@@ -126,6 +126,8 @@ export const lang = {
copyTimeoutReason: 'Reason:',
wechatClipboardReason1: '1. WeChat Platform -> User Privacy Protection Guidelines -> "Clipboard" feature not added or review not passed;',
wechatClipboardReason2: '2. WeChat platform has restrictions on clipboard API call frequency',
// readable tip when clipboard privacy scope is not declared (errno 112)
clipboardPrivacyNotDeclared: 'Clipboard privacy permission is not configured',
copyFailed: 'Copy failed',
},

View File

@@ -1,83 +0,0 @@
export const lang = {
// diy-recommend-code referral code component
// Title
title: 'My Referral Code',
// Share now button
buttonText: 'Share Now',
// Copy code button
copyButtonText: 'Copy Code',
// Get a new code
placeholderRegenerateText: 'Get a New Code',
// Consent description
consentText: 'Your referral code is used to track enterprise registrations via your shared link. We record each application completed through your link for commission settlement.',
// Agree and get code button
consentButtonText: 'Agree & Get Code',
// Login guide tip
loginTipText: 'Log in to view your referral code',
// Log in button
loginBtnText: 'Log In',
// Poster QR tip
posterQrTip: 'Scan to enter and fill in registration info',
// Exclusive code label
exclusiveCode: 'Exclusive Code',
// Code pending label
pendingCode: 'Code Pending',
// Pending
pending: 'Pending',
// Loading code
loading: 'Loading code...',
// Code obtained label
obtainedCode: 'Code Obtained',
// Obtained
obtained: 'Obtained',
// Share invite reward description
shareInviteReward: 'Share with friends and earn rewards for invites',
// Active
activated: '✓ Active',
// Code generated description
codeGenerated: 'Code generated. Use it to invite friends or bind referral for enterprise registration',
// Submitting
submitting: 'Submitting...',
// Share title
shareTitle: 'Inviting you to join the low-altitude economy platform',
// Get failed
getFail: 'Failed to get code. Please retry later',
// Get failed (business code)
getFailCode: 'Failed to get code (business code={code})',
// Get success
getSuccess: 'Obtained',
// Network error
netError: 'Network error. Please retry later',
// Renew code modal title
regenTitle: 'Renew Code',
// Renew code modal content
regenContent: 'After renewal, the old code becomes invalid immediately. All registrations via the old link will no longer be attributed to you. Continue?',
// Confirm renew
regenConfirm: 'Confirm Renew',
// Cancel
regenCancel: 'Cancel',
// Renew failed
regenFail: 'Renewal failed. Please retry later',
// Renew success (old disabled)
regenSuccessOld: 'New code issued. Old code {old} disabled',
// Renew success
regenSuccess: 'Renewed',
// Code not ready yet
codeNotReady: 'Code not ready yet. Please wait',
// Code copied
codeCopied: 'Code copied',
// Copy failed
copyFail: 'Copy failed',
// Copy content is empty
copyEmpty: 'Content is empty',
// Copy after code finishes loading
loadThenCopy: 'Copy after code finishes loading',
// Share link copied
linkCopied: 'Share link copied',
// Poster subtitle
posterShareInvite: 'Share with friends, earn rewards for invites',
// Poster link prefix
posterLinkPrefix: 'Link:',
// Poster link not generated
posterLinkEmpty: '(not generated)',
}

View File

@@ -1,5 +0,0 @@
export const lang = {
// diy-webview webview component
emptyTip: 'Please configure the web link',
loadError: 'Failed to load web page',
}

View File

@@ -1,4 +0,0 @@
export const lang = {
//title为每个页面的标题
title: 'File Details',
}

View File

@@ -22,24 +22,14 @@ export const lang = {
// ====== ai-chat-message ======
aiNickname: '智能助手',
defaultNickname: '我',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 纯附件时发给后端的 query 文案
// audioMessage / videoMessage: 用户气泡里文件名的兜底 (短标签, 仍在 bubble 模板用)
// *Instruction* 系列: 纯附件时发给 AI 的 query, 显式要求 AI "去看/听" 附件内容
// AI 必须看到指令才会主动调 STT / 视觉 / 文件解析, 光有 label 容易被忽略
audioMessage: '语音消息',
videoMessage: '视频消息',
audioInstruction: '我发送了一段语音,请听一下并回复我',
audioInstructionWithDuration: '我发送了一段语音({seconds} 秒),请听一下并回复我',
imageInstruction: '我发送了一张图片,请查看图片内容并回复我',
videoInstruction: '我发送了一段视频,请查看视频内容并回复我',
fileInstruction: '我发送了一个文件,请查看文件内容并回复我',
attachmentInstruction: '我发送了附件,请查看附件内容并回复我',
inputPlaceholder: '请输入您的问题...',
expandEditorTitle: '编辑内容',
loadMoreHistory: '加载更多历史消息',
loadingHistory: '加载历史消息中...',
aiThinking: 'AI正在思考',
receivingReply: '正在接收回复',
receivingReply: '思考中',
aiThinkingStatus1: 'AI正在思考',
aiThinkingStatus2: 'AI正在分析',
aiThinkingStatus3: 'AI正在检索',
@@ -51,6 +41,7 @@ export const lang = {
copySelected: '已复制选中内容',
copyFail: '复制失败',
copyFailWithReason: '复制失败:{reason}',
copyFailPrivacyReason: '小程序未声明剪贴板权限,复制不可用',
openingFile: '打开文件中...',
openingFileName: '正在打开文件:{name}',
openingFileTitle: '正在打开:{title}',
@@ -139,38 +130,12 @@ export const lang = {
chooseVideoFail: '选择视频失败',
audioNotReady: '音频尚未就绪',
location: '位置',
// PR-AUTO-LOCATION (2026-09-28): 自动定位权限提示
locationPermissionTitle: '需要位置权限',
locationPermissionH5: '请在浏览器地址栏左侧的锁形图标中开启位置权限,然后重新发送消息。',
locationPermissionMp: '为了让 AI 更好地回答位置相关问题,需要您开启位置权限。\n\n点击"去设置"在系统设置中开启后,请回到本页面再次发送消息。',
locationSettingBtn: '去设置',
locationSkipBtn: '暂不开启',
locationH5GuideBtn: '我知道了',
// ====== ai-chat-voice-panel ======
voiceInputTitle: '语音输入',
recordingTip: '正在录音,松开结束',
startRecordTip: '点击开始录音',
voiceInputFailed: '语音输入失败',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 按住说话手势 + 录音异常文案
holdToTalk: '按住说话',
releaseToSend: '松开发送',
releaseToCancel: '松开取消',
slideUpToCancel: '↑ 上滑取消',
slideUpToCancelHint: '↑ 松开取消',
// PR-INPUT-PLACEHOLDER-DYNAMIC (2026-09-28): 输入框 placeholder 按上下文动态切换
// 默认 / 有语音附件 / 有其他媒体附件, 三态文案互不冲突
placeholderDefault: '发消息或按住说话',
placeholderWithAudio: '给语音留言加个说明(可选)',
placeholderWithMedia: '添加文字说明(可选)',
voiceStartFailed: '无法开始录音',
voiceStopFailed: '录音失败,请重试',
voiceNotSupported: '当前平台不支持语音输入',
voiceTooShort: '说话时间太短',
voiceRecorderBusy: '录音器正在初始化,请稍后再试',
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 上传失败 (录音产物上传到云端)
uploadFailed: '上传失败',
uploadFailedWithReason: '上传失败:{reason}',
// ====== index.vue - 菜单 ======
menuClearChat: '清空聊天',
@@ -185,7 +150,7 @@ export const lang = {
logEventHandleError: '事件处理错误',
logInitNavbarFailed: '初始化导航栏失败',
logChatComponentNotInit: '聊天组件未初始化',
logServicerConfigNotLoaded: '【AI客服】servicerConfig 未加载,200ms后重试...'
logServicerConfigNotLoaded: '【AI客服】servicerConfig 未加载,200ms后重试...',
// ====== AI Agent 通用文案(智能客服是首个 agent) ======
aiAgentDefaultTitle: 'AI 智能体',

View File

@@ -126,6 +126,8 @@ export const lang = {
copyTimeoutReason: '原因:',
wechatClipboardReason1: '1.微信平台->用户隐私保护指引->"剪贴板"功能未添加或审核未通过;',
wechatClipboardReason2: '2.微信平台对剪贴板API调用频率有限制',
// 微信剪贴板隐私声明缺失(errno 112)时的可读提示
clipboardPrivacyNotDeclared: '剪贴板隐私权限未配置',
copyFailed: '复制失败',
},

View File

@@ -1,83 +0,0 @@
export const lang = {
// diy-recommend-code 推荐码组件
// 标题
title: '我的推荐码',
// 立即分享按钮
buttonText: '立即分享',
// 复制推荐码按钮
copyButtonText: '复制推荐码',
// 换一个新码
placeholderRegenerateText: '换一个新码',
// 同意说明文案
consentText: '您的推荐码将用于企业入驻来源追踪,我们会记录每一次通过您分享链接完成的入驻申请,用于您的推广收益结算。',
// 同意并获取推荐码按钮
consentButtonText: '同意并获取推荐码',
// 未登录引导提示
loginTipText: '登录后查看我的推荐码',
// 去登录按钮
loginBtnText: '去登录',
// 海报二维码提示
posterQrTip: '扫码进入并填写入驻信息',
// 专属推荐码标签
exclusiveCode: '专属推荐码',
// 待获取推荐码标签
pendingCode: '待获取推荐码',
// 待获取
pending: '待获取',
// 推荐码加载中
loading: '推荐码加载中...',
// 已获得推荐码标签
obtainedCode: '已获得推荐码',
// 已获得
obtained: '已获得',
// 分享邀请奖励描述
shareInviteReward: '分享给好友,邀请注册即可获得奖励',
// 已生效
activated: '✓ 已生效',
// 推荐码已生成描述
codeGenerated: '推荐码已生成,可用于邀请好友或企业入驻绑定推荐关系',
// 提交中
submitting: '提交中...',
// 分享标题
shareTitle: '邀您入驻低空经济产业平台',
// 获取失败
getFail: '推荐码获取失败,请稍后重试',
// 获取失败(业务码)
getFailCode: '推荐码获取失败(业务码={code})',
// 获取成功
getSuccess: '获取成功',
// 网络异常
netError: '网络异常,请稍后重试',
// 换新码弹窗标题
regenTitle: '换新码',
// 换新码弹窗内容
regenContent: '换新码后旧码会立即失效,后续所有使用旧分享链接的入驻申请都不会归属到您,确认继续?',
// 确认换新
regenConfirm: '确认换新',
// 取消
regenCancel: '取消',
// 换新失败
regenFail: '换新失败,请稍后重试',
// 换新成功(旧码停用)
regenSuccessOld: '已换新码,旧码 {old} 已停用',
// 换新成功
regenSuccess: '换新成功',
// 推荐码还未生成
codeNotReady: '推荐码还未生成,请稍候',
// 推荐码已复制
codeCopied: '推荐码已复制',
// 复制失败
copyFail: '复制失败',
// 复制内容为空
copyEmpty: '内容为空',
// 推荐码加载完成后再复制
loadThenCopy: '推荐码加载完成后再复制',
// 推广链接已复制
linkCopied: '推广链接已复制',
// 海报副标题
posterShareInvite: '分享给好友,邀请入驻获得奖励',
// 海报链接前缀
posterLinkPrefix: '链接:',
// 海报链接未生成
posterLinkEmpty: '(未生成)',
}

View File

@@ -1,5 +0,0 @@
export const lang = {
// diy-webview 网页组件
emptyTip: '请配置网页链接',
loadError: '网页加载失败',
}

View File

@@ -1,4 +0,0 @@
export const lang = {
//title为每个页面的标题
title: '文件详情',
}

View File

@@ -79,13 +79,10 @@
},
"scope.writePhotosAlbum" : {
"desc" : "用于从相册选择和保存头像"
},
"scope.record" : {
"desc" : "用于语音录制功能,录制完成后发送到 AI 助手"
}
},
"requiredPrivateInfos" : [ "chooseLocation", "getLocation", "chooseAddress" ],
"__usePrivacyCheck__" : true,
"__usePrivacyCheck__" : false,
"optimization" : {
"subPackages" : true
}

View File

@@ -13,7 +13,8 @@
"zion-uniapp-mp-load-package": "^1.0.13"
},
"dependencies": {
"jweixin-module": "^1.6.0"
"jweixin-module": "^1.6.0",
"playwright-core": "^1.63.0"
},
"uni-app": {
"scripts": {

View File

@@ -1086,7 +1086,7 @@
{
"path": "ai-chat/index",
"style": {
"navigationBarTitleText": "AI智能客服",
"navigationBarTitleText": "AI智能",
"componentPlaceholder": {
"diy-article": "view",
"diy-audio": "view",
@@ -2499,12 +2499,6 @@
}
}
},
{
"path": "files/detail",
"style": {
"navigationBarTitleText": "文件详情"
}
},
{
"path": "file-preview/file-preview",
"style": {
@@ -2557,6 +2551,7 @@
"pages/index/index": {
"network": "all",
"packages": [
"pages_tool",
"components-diy"
]
}

View File

@@ -90,16 +90,17 @@ export default {
}
},
// 跟随 goodsSkuDetail 变化重新决定默认 Tab
// 解决 refreshGoodsSkuDetail 后续合并 pdf_url 时,Tab 已显示但 detailTab 仍为 'html' 的问题
// 默认展示排在前面的「商品详情」, 只有在没有图文详情、仅有说明书(pdf_url)时才默认选中说明书;
// 同时解决 refreshGoodsSkuDetail 后续合并数据时,Tab 已显示但 detailTab 未跟上的问题
goodsSkuDetail: {
deep: true,
immediate: true,
handler(newVal) {
if (!newVal) return;
if (newVal.pdf_url) {
this.detailTab = 'pdf';
} else if (newVal.goods_content) {
if (this.hasHtmlTab) {
this.detailTab = 'html';
} else if (newVal.pdf_url) {
this.detailTab = 'pdf';
}
}
}

View File

@@ -386,14 +386,15 @@
<!-- 商品详情 -->
<view v-if="hasDetailContent" class="goods-detail-tab">
<view class="detail-tab">
<view v-if="goodsSkuDetail.pdf_url" class="tab-item"
:class="{ active: detailTab === 'pdf' }" @click="switchDetailTab('pdf')">
<text class="tab-label">{{ $lang('goods.detail.document') }}</text>
</view>
<!-- 商品详情 在前, 产品说明书(文档详情) 在后 -->
<view v-if="hasHtmlTab" class="tab-item"
:class="{ active: detailTab === 'html' }" @click="switchDetailTab('html')">
<text class="tab-label">{{ $lang('goods.detail.details') }}</text>
</view>
<view v-if="goodsSkuDetail.pdf_url" class="tab-item"
:class="{ active: detailTab === 'pdf' }" @click="switchDetailTab('pdf')">
<text class="tab-label">{{ $lang('goods.detail.document') }}</text>
</view>
</view>
<view class="detail-content active">
<!-- PDF文档 -->

View File

@@ -1,6 +1,6 @@
<template>
<view class="content" :style="themeColor">
<view class="head-wrap">
<view class="head-wrap" :class="{ 'head-wrap-extend': hideSort }">
<!-- 搜索区域 -->
<view class="search-wrap uni-flex uni-row">
<view class="flex-item input-wrap">
@@ -12,8 +12,8 @@
@click="changeListStyle()"></view>
</view>
<!-- 排序 -->
<view class="sort-wrap">
<!-- 排序 (商品分类模板5进入时隐藏, 只隐藏不移除) -->
<view class="sort-wrap" :class="{ 'sort-wrap-hide': hideSort }">
<view class="comprehensive-wrap" :class="{ 'color-base-text': orderType === '' }"
@click="sortTabClick('')">
<text :class="{ 'color-base-text': orderType === '' }">{{ $lang('goods.list.Random') }}</text>
@@ -45,7 +45,7 @@
</view>
</view>
<mescroll-uni top="180" ref="mescroll" @getData="getGoodsList">
<mescroll-uni :top="hideSort ? 120 : 180" ref="mescroll" @getData="getGoodsList">
<block slot="list">
<view v-if="isList" class="goods-list single-column" :class="{ show: isList }">
<view class="goods-item margin-bottom" v-for="(item, index) in goodsList" :key="item.id"

View File

@@ -5,6 +5,13 @@
left: 0;
z-index: 1;
// 商品分类模板5进入时排序栏被隐藏, 让白色背景继续向下延伸(搜索框位置不变),
// 一直覆盖到第一行商品卡片顶部, 避免搜索框下方出现灰色空白条
&.head-wrap-extend {
// 26rpx = mescroll top(100rpx) - 搜索区高度(94rpx) + 列表 padding-top($margin-updown: 20rpx)
padding-bottom: 20rpx;
}
.search-wrap {
flex: 0.5;
padding: 30rpx 30rpx 0;
@@ -60,6 +67,12 @@
.sort-wrap {
display: flex;
padding: 10rpx 20rpx 10rpx 0;
// 商品分类模板5进入商品列表时隐藏排序栏(综合/销量/价格/筛选), 只隐藏不移除
&.sort-wrap-hide {
display: none;
}
> view {
flex: 1;
text-align: center;

View File

@@ -19,6 +19,7 @@ export default {
coupon: 0,
emptyShow: false,
isList: true, //列表样式
hideSort: false, //是否隐藏排序栏(综合/销量/价格/筛选)
//分享所需标题
share_title: '',
//搜索到多少件商品
@@ -82,6 +83,15 @@ export default {
});
this.categoryId = options.category_id || 0;
// 商品分类(模板5)点二级分类进入时带 list_style=grid, 默认展示竖版(双列宫格)视图;
// 其它入口(搜索/优惠券/品牌等)保持原有的单列列表视图
if (options.list_style === 'grid') {
this.isList = false;
}
// 商品分类(模板5)进入时隐藏排序栏(综合/销量/价格/筛选), 只隐藏不移除
if (options.hide_sort == 1) {
this.hideSort = true;
}
this.keyword = options.keyword || '';
this.coupon = options.coupon || 0;
this.goods_id_arr = options.goods_id_arr || 0;

File diff suppressed because it is too large Load Diff

View File

@@ -12,33 +12,32 @@
<!-- PR-CHAT-UI-CONFIG (2026-09-20): 每个附件 tab 由 attachmentTypes 控制显隐
支持的 kind: image / file / audio / video, 缺失的 kind 自动隐藏
location 不属于附件, 不受此开关控制 -->
<view v-if="isTypeEnabled('image')" class="tool-item tool-item-new tool-item-image" @click="selectImage">
<view v-if="isTypeEnabled('image')" class="tool-item" @click="selectImage">
<view class="tool-icon">
<view class="image-icon"></view>
<text class="icondiy icon-system-image-line"></text>
</view>
<text class="tool-text">{{ $lang('ai-chat.index.image') }}</text>
</view>
<view v-if="isTypeEnabled('video')" class="tool-item tool-item-new tool-item-video" @click="selectVideo">
<view v-if="isTypeEnabled('video')" class="tool-item" @click="selectVideo">
<view class="tool-icon">
<text class="icondiy icon-system-video"></text>
</view>
<!-- 第二个参数是 $lang 的默认值: 后端 bundle 尚未下发该 key 时也不会显示 raw key -->
<text class="tool-text">{{ $lang('ai-chat.index.video', '视频/音频') }}</text>
</view>
<view v-if="isTypeEnabled('file')" class="tool-item tool-item-new tool-item-file" @click="selectFile">
<view v-if="isTypeEnabled('file')" class="tool-item" @click="selectFile">
<view class="tool-icon">
<view class="paperclip-icon"></view>
<text class="icondiy icon-system-file-2-line"></text>
</view>
<text class="tool-text">添加文件</text>
<text class="tool-text">{{ $lang('ai-chat.index.file') }}</text>
</view>
<!-- 更多功能里的语音入口暂时隐藏 -->
<view v-if="false" class="tool-item" @click="selectVoiceOrAudio">
<view v-if="isTypeEnabled('audio')" class="tool-item" @click="selectVoiceOrAudio">
<view class="tool-icon">
<text class="icondiy icon-system-chat-voice-line"></text>
</view>
<text class="tool-text">{{ $lang('ai-chat.index.voice') }}</text>
</view>
<view v-if="false" class="tool-item tool-item-new tool-item-location" @click="selectLocation">
<view class="tool-item" @click="selectLocation">
<view class="tool-icon">
<text class="icondiy icon-system-map-pin-line"></text>
</view>
@@ -221,8 +220,7 @@ export default {
if (type.indexOf('audio/') === 0) return 'audio'
if (type.indexOf('video/') === 0) return 'video'
const ext = String((file && file.name) || '').split('.').pop().toLowerCase()
// PR-AV-FULL-SUPPORT (2026-09-24): 与后端 MediaUploadPolicy::allowedUploadExtensions 音频段对齐
const audioExt = ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'oga', 'amr', 'wma', 'aiff', 'aif', 'opus', 'ape', 'mid', 'midi', 'caf', 'mka', 'ac3']
const audioExt = ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'oga', 'amr', 'wma', 'aiff', 'aif', 'opus', 'ape', 'mid']
if (audioExt.indexOf(ext) !== -1) return 'audio'
// 兜底: mime 为空且扩展名不认识的 (如 Windows 未关联的音频) 交给后端按 URL 判断, 先按音频走
return type ? 'video' : 'audio'
@@ -299,7 +297,7 @@ export default {
chooseFileApi({
count: 1,
type: 'file',
extension: ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'oga', 'amr', 'wma', 'aiff', 'aif', 'opus', 'ape', 'mid', 'midi', 'caf', 'mka', 'ac3'],
extension: ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'amr', 'wma', 'aiff'],
success: async (res) => {
const file = (res.tempFiles && res.tempFiles[0]) || null
if (!file) return
@@ -317,7 +315,7 @@ export default {
// #ifdef APP-PLUS
uni.chooseFile({
count: 1,
extension: ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'oga', 'amr', 'wma', 'aiff', 'aif', 'opus', 'ape', 'mid', 'midi', 'caf', 'mka', 'ac3'],
extension: ['mp3', 'wav', 'aac', 'm4a', 'flac', 'ogg', 'amr'],
success: async (res) => {
const file = res.tempFiles[0]
if (!file) return
@@ -394,8 +392,6 @@ export default {
},
startRecord() {
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 仅作转发, 真正的录音由 ai-chat-voice-panel.vue 接管
// (panel 现在已经接通 common/js/voice-recorder.js, 这里不用直接调用 recorder)
this.$emit('voice-start')
this.hideToolsPanel()
},
@@ -466,9 +462,9 @@ export default {
position: relative; // 为 .close-btn 绝对定位提供参考
text {
font-size: 30rpx;
font-weight: 400;
color: #000000;
font-size: 34rpx;
font-weight: 600;
color: $color-text;
}
.close-btn {
@@ -485,14 +481,14 @@ export default {
right: 10rpx; //
.iconfont {
font-size: 28rpx;
color: #000000;
color: $color-text-light;
}
}
}
.tools-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-columns: repeat(4, 1fr);
gap: 24rpx;
.tool-item {
@@ -527,62 +523,6 @@ export default {
font-weight: 500;
}
}
// 新样式: 图片 / 添加文件 大卡片, 一比一还原参考图
.tool-item-new {
background-color: #f2f3f5;
border-radius: 28rpx;
padding: 36rpx 0;
.tool-icon {
width: 48rpx;
height: 48rpx;
border-radius: 0;
background-color: transparent;
box-shadow: none;
margin-bottom: 6rpx;
line-height: 1;
.iconfont,
.icondiy {
font-size: 48rpx;
line-height: 1;
color: #333;
}
// 图片图标: 左上角开口 + 大四角星在开口处 + 右侧实心圆点 (参考图样式)
.image-icon {
width: 48rpx;
height: 48rpx;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjEuNyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMTEuNCA1IEgxNy41IEEzLjUgMy41IDAgMCAxIDIxIDguNSBWMTUuNSBBMy41IDMuNSAwIDAgMSAxNy41IDE5IEg2LjUgQTMuNSAzLjUgMCAwIDEgMyAxNS41IFY4LjUiLz48cGF0aCBkPSJNNS4yIDEuMyBRNS45IDQuMzUgOC45IDUgUTUuOSA1LjY1IDUuMiA4LjcgUTQuNSA1LjY1IDEuNSA1IFE0LjUgNC4zNSA1LjIgMS4zIFoiIGZpbGw9IiMzMzMiIHN0cm9rZT0ibm9uZSIvPjxjaXJjbGUgY3g9IjE2IiBjeT0iOS44IiByPSIxLjUiIGZpbGw9IiMzMzMiIHN0cm9rZT0ibm9uZSIvPjxwYXRoIGQ9Ik01LjUgMTEuNiBRMTAgOS42IDE0LjUgMTYuNCIvPjwvc3ZnPg==");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
// 添加文件图标: 斜向回形针 (参考图样式)
.paperclip-icon {
width: 40rpx;
height: 40rpx;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEuNDQgMTEuMDUgMTIuMjUgMjAuMjRhNiA2IDAgMCAxLTguNDktOC40OWw4LjU3LTguNTdhNCA0IDAgMSAxIDUuNjYgNS42NmwtOC41OSA4LjU3YTIgMiAwIDAgMS0yLjgzLTIuODNsOC40OS04LjQ4Ii8+PC9zdmc+");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
}
.tool-text {
font-size: 26rpx;
line-height: 1;
color: #333;
font-weight: 500;
}
// 视频/音频图标小一号 (tool-item-video 与该元素同级, 必须用 & 连接)
&.tool-item-video .tool-icon .icondiy {
font-size: 40rpx;
}
}
}
}
}

View File

@@ -1,403 +1,239 @@
<template>
<view class="voice-popup" v-if="visible">
<view class="voice-mask" @click="hideVoicePanel"></view>
<view class="voice-input-panel">
<view class="voice-header">
<text>{{ $lang('ai-chat.index.voiceInputTitle') }}</text>
<button class="close-btn" @click="hideVoicePanel">
<text class="iconfont icon-close"></text>
</button>
</view>
<view class="voice-content">
<view class="voice-wave" :class="{ recording: voiceInputing }">
<view
v-for="i in 8"
:key="i"
class="wave-bar"
:style="waveBarStyle(i)"></view>
</view>
<text class="voice-tip">{{ currentTip }}</text>
<text v-if="voiceInputing" class="voice-duration">{{ formattedDuration }}</text>
</view>
<view class="voice-actions">
<button class="voice-btn" :class="{ 'is-recording': voiceInputing }" @click="toggleVoiceInput">
<text class="iconfont" :class="voiceInputing ? 'icon-stop' : 'icon-voice'"></text>
</button>
<text v-if="voiceInputing" class="cancel-link" @click="cancelVoiceInput">{{ $lang('ai-chat.index.cancel') }}</text>
</view>
</view>
</view>
</template>
<script>
import { createVoiceRecorder } from '@/common/js/voice-recorder.js'
/**
* ai-chat-voice-panel - 语音输入面板组件
*
* PR-FRONTEND-VOICE-INPUT (2026-09-24): 真录音 UI。
* - 接入 common/js/voice-recorder.js,跨 H5 / 微信小程序 / App-Plus / 鸿蒙元服务
* - 波形振幅由 progress 事件 (level 0..1) 驱动
* - 录音上限 60s,自动停止
* - 关闭面板时如果还在录音,先 cancel 释放资源
*
* Props:
* visible: Boolean - 控制显示/隐藏
*
* Events:
* update:visible - 同步关闭状态
* close - 请求关闭面板
* audio-ready - 录音完成, 参数 { filePath, blob, duration, mime, size }
*/
export default {
name: 'AiChatVoicePanel',
props: {
visible: {
type: Boolean,
default: false
}
},
data() {
return {
voiceInputing: false,
// 录音中的振幅 0..1;8 根波形的高度按 level 抖动
voiceLevel: 0,
// 录音累计时长 (秒,整数)
voiceDuration: 0,
_durationTimer: null,
_voiceRecorder: null,
_onProgress: null,
_onError: null,
// 防止 stop 回调被多次触发 (录音器自己 stop + 用户手动 stop 重叠)
_resolved: false
}
},
computed: {
currentTip() {
if (this.voiceInputing) {
return this.$lang('ai-chat.index.recordingTip')
}
return this.$lang('ai-chat.index.startRecordTip')
},
formattedDuration() {
const s = Math.max(0, Math.floor(this.voiceDuration))
return s + '″'
}
},
watch: {
visible(val) {
if (val) {
// 每次重新打开都重置
this.voiceInputing = false
this.voiceLevel = 0
this.voiceDuration = 0
this._resolved = false
} else {
// 关闭时如果还在录音,丢弃
this._discardRecorderIfAny()
}
}
},
beforeDestroy() {
this._discardRecorderIfAny()
},
methods: {
hideVoicePanel() {
// 关闭时若还在录,默认作废;如需保留产物应先点 stop 按钮
this._discardRecorderIfAny()
this.$emit('update:visible', false)
this.$emit('close')
},
toggleVoiceInput() {
if (this.voiceInputing) {
this._finishRecording()
} else {
this._beginRecording()
}
},
cancelVoiceInput() {
this._discardRecorderIfAny()
this.hideVoicePanel()
},
waveBarStyle(i) {
// 每根 bar 基础高度 24rpx + level*振幅 + 不同 bar 的 offset (错相)
const base = 24
const offset = ((i * 17) % 32) + 12 // 12..44
const levelPx = Math.round(this.voiceLevel * 80)
const h = Math.max(16, base + offset + levelPx) + 'rpx'
const delay = (i * 0.08) + 's'
return { height: h, animationDelay: delay }
},
_beginRecording() {
if (this._voiceRecorder) return
const rec = createVoiceRecorder({ maxDuration: 60 * 1000 })
this._voiceRecorder = rec
this._onProgress = ({ level }) => {
// 平滑一下,避免波形抖动太狠
this.voiceLevel = this.voiceLevel * 0.4 + level * 0.6
}
this._onError = (err) => {
console.warn('[voice-panel] recorder error:', err)
console.error('[voice-panel] recorder error raw:', JSON.stringify(err), 'errMsg=', err && err.errMsg, 'message=', err && err.message)
uni.showToast({ title: this._voiceErrMsg(err) || this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
this._discardRecorderIfAny()
}
rec.on('progress', this._onProgress)
rec.on('error', this._onError)
rec.start()
.then(() => {
this.voiceInputing = true
this.voiceDuration = 0
this._startDurationTimer()
})
.catch((err) => {
this._teardownRecorder()
uni.showToast({ title: this._voiceErrMsg(err) || this.$lang('ai-chat.index.voiceStartFailed'), icon: 'none' })
})
},
async _finishRecording() {
if (!this._voiceRecorder || this._resolved) return
this._resolved = true
this._stopDurationTimer()
try {
const result = await this._voiceRecorder.stop()
if (!result || !result.filePath) {
// 录音产物为空,可能是被系统打断
uni.showToast({ title: this.$lang('ai-chat.index.voiceStopFailed'), icon: 'none' })
this._teardownRecorder()
this.voiceInputing = false
return
}
this._teardownRecorder()
this.voiceInputing = false
this.$emit('audio-ready', {
filePath: result.filePath,
blob: result.blob || null,
fileName: result.fileName || '',
duration: result.duration,
mime: result.mime,
size: result.size
})
this.hideVoicePanel()
} catch (e) {
this._teardownRecorder()
this.voiceInputing = false
uni.showToast({ title: this._voiceErrMsg(e) || this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
}
},
_discardRecorderIfAny() {
if (!this._voiceRecorder) return
try { this._voiceRecorder.cancel() } catch (e) { /* noop */ }
this._teardownRecorder()
this.voiceInputing = false
},
_teardownRecorder() {
this._stopDurationTimer()
if (this._voiceRecorder) {
if (this._onProgress) this._voiceRecorder.off('progress', this._onProgress)
if (this._onError) this._voiceRecorder.off('error', this._onError)
}
this._voiceRecorder = null
this._onProgress = null
this._onError = null
this._resolved = false
this.voiceLevel = 0
},
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 把 voice-recorder 抛出的 code 翻译成 i18n 文案
_voiceErrMsg(err) {
if (!err) return ''
switch (err.code) {
case 'NOT_SUPPORTED':
case 'NO_RECORDER_MANAGER':
return this.$lang('ai-chat.index.voiceNotSupported')
case 'H5_NO_MIC_API':
case 'ALREADY_STARTED':
return this.$lang('ai-chat.index.voiceStartFailed')
case 'UNI_RECORD_ERROR':
return (err && (err.errMsg || err.message)) || this.$lang('ai-chat.index.voiceStopFailed')
default:
return err.message || ''
}
},
_startDurationTimer() {
this._stopDurationTimer()
this._durationTimer = setInterval(() => {
this.voiceDuration += 1
}, 1000)
},
_stopDurationTimer() {
if (this._durationTimer) {
clearInterval(this._durationTimer)
this._durationTimer = null
}
}
}
}
</script>
<style lang="scss" scoped>
/* 引入图标字体: 由 main.wxss 全局提供, 不再重复 import */
@import '../styles/ai-chat-global.scss';
.voice-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
.voice-mask {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
}
.voice-input-panel {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: $bg-card;
border-radius: $radius-lg;
padding: 48rpx;
width: 60%;
max-width: 520rpx;
box-shadow: 0 8rpx 36rpx rgba(0, 0, 0, 0.15);
.voice-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32rpx;
border-bottom: 2rpx solid #f0f4f8;
padding-bottom: 16rpx;
text {
font-size: 34rpx;
font-weight: 600;
color: $color-text;
}
.close-btn {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background-color: $bg-main;
display: flex;
align-items: center;
justify-content: center;
border: none;
.iconfont {
font-size: 28rpx;
color: $color-text-light;
}
}
}
.voice-content {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 32rpx;
.voice-wave {
width: 280rpx;
height: 160rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 24rpx;
&.recording .wave-bar {
animation: wave 1.0s infinite ease-in-out;
}
.wave-bar {
width: 8rpx;
margin: 0 4rpx;
background-color: $color-primary;
border-radius: 4rpx;
transition: height 0.12s ease-out;
animation: none;
}
}
.voice-tip {
font-size: 28rpx;
color: $color-text-light;
}
.voice-duration {
font-size: 36rpx;
font-weight: 600;
color: $color-primary;
margin-top: 8rpx;
}
}
.voice-actions {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.voice-btn {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background-color: $color-primary;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(108, 142, 191, 0.3);
border: none;
transition: transform 0.15s ease-out, background-color 0.15s ease-out;
&.is-recording {
background-color: #e94e4e;
transform: scale(0.92);
}
.iconfont {
font-size: 56rpx;
color: white;
}
}
.cancel-link {
margin-top: 20rpx;
font-size: 26rpx;
color: $color-text-light;
padding: 8rpx 16rpx;
}
}
}
}
@keyframes wave {
0%, 100% { transform: scaleY(0.6); }
50% { transform: scaleY(1.15); }
}
</style>
<template>
<view class="voice-popup" v-if="visible">
<view class="voice-mask" @click="hideVoicePanel"></view>
<view class="voice-input-panel">
<view class="voice-header">
<text>{{ $lang('ai-chat.index.voiceInputTitle') }}</text>
<button class="close-btn" @click="hideVoicePanel">
<text class="iconfont icon-close"></text>
</button>
</view>
<view class="voice-content">
<view class="voice-wave" :class="{ recording: voiceInputing }">
<view
v-for="i in 8"
:key="i"
class="wave-bar"
:style="{ animationDelay: (i * 0.1) + 's' }"></view>
</view>
<text class="voice-tip">{{ voiceInputing ? $lang('ai-chat.index.recordingTip') : $lang('ai-chat.index.startRecordTip') }}</text>
</view>
<view class="voice-actions">
<button class="voice-btn" @click="toggleVoiceInput">
<text class="iconfont" :class="voiceInputing ? 'icon-stop' : 'icon-voice'"></text>
</button>
</view>
</view>
</view>
</template>
<script>
/**
* ai-chat-voice-panel - 语音输入面板组件
*
* Props:
* visible: Boolean - 控制显示/隐藏
*
* Events:
* update:visible - 同步关闭状态
* close - 请求关闭面板
*/
export default {
name: 'AiChatVoicePanel',
props: {
visible: {
type: Boolean,
default: false
}
},
data() {
return {
voiceInputing: false
}
},
watch: {
visible(val) {
if (!val) {
this.voiceInputing = false
}
}
},
methods: {
hideVoicePanel() {
this.voiceInputing = false
this.$emit('update:visible', false)
this.$emit('close')
},
toggleVoiceInput() {
this.voiceInputing = !this.voiceInputing
if (this.voiceInputing) {
this.startVoiceInput()
} else {
this.stopVoiceInput()
}
},
startVoiceInput() {
// #ifdef H5
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ audio: true })
.then(stream => {
// 录音中,可扩展实时转文字
})
.catch(error => {
uni.showToast({ title: this.$lang('ai-chat.index.voiceInputFailed'), icon: 'none' })
this.voiceInputing = false
})
}
// #endif
},
stopVoiceInput() {
this.voiceInputing = false
}
}
}
</script>
<style lang="scss" scoped>
/* 引入图标字体: 由 main.wxss 全局提供, 不再重复 import */
@import '../styles/ai-chat-global.scss';
.voice-popup {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
.voice-mask {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
}
.voice-input-panel {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: $bg-card;
border-radius: $radius-lg;
padding: 48rpx;
width: 60%;
max-width: 520rpx;
box-shadow: 0 8rpx 36rpx rgba(0, 0, 0, 0.15);
.voice-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 32rpx;
border-bottom: 2rpx solid #f0f4f8;
padding-bottom: 16rpx;
text {
font-size: 34rpx;
font-weight: 600;
color: $color-text;
}
.close-btn {
width: 56rpx;
height: 56rpx;
border-radius: 50%;
background-color: $bg-main;
display: flex;
align-items: center;
justify-content: center;
border: none;
.iconfont {
font-size: 28rpx;
color: $color-text-light;
}
}
}
.voice-content {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 48rpx;
.voice-wave {
width: 280rpx;
height: 160rpx;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 24rpx;
&.recording .wave-bar {
animation: wave 1.2s infinite ease-in-out;
}
.wave-bar {
width: 8rpx;
height: 40rpx;
margin: 0 4rpx;
background-color: $color-primary;
border-radius: 4rpx;
animation: none;
&:nth-child(1) { height: 60rpx; animation-delay: 0s; }
&:nth-child(2) { height: 90rpx; animation-delay: 0.1s; }
&:nth-child(3) { height: 50rpx; animation-delay: 0.2s; }
&:nth-child(4) { height: 120rpx; animation-delay: 0.3s; }
&:nth-child(5) { height: 70rpx; animation-delay: 0.4s; }
&:nth-child(6) { height: 100rpx; animation-delay: 0.5s; }
&:nth-child(7) { height: 80rpx; animation-delay: 0.6s; }
&:nth-child(8) { height: 40rpx; animation-delay: 0.7s; }
}
}
.voice-tip {
font-size: 28rpx;
color: $color-text-light;
}
}
.voice-actions {
display: flex;
justify-content: center;
.voice-btn {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background-color: $color-primary;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 24rpx rgba(108, 142, 191, 0.3);
border: none;
.iconfont {
font-size: 56rpx;
color: white;
}
}
}
}
}
@keyframes wave {
0%, 100% { transform: scaleY(0.5); }
50% { transform: scaleY(1.2); }
}
</style>

View File

@@ -40,39 +40,20 @@
export default {
data() {
return {
list: [],
// 从跳转 URL 上携带的参数
categoryId: '',
title: '',
pageKey: '',
pageParams: {}
list: []
};
},
onLoad(options) {
// 还原跳转时携带的过滤/展示参数,避免请求 API 时丢失
if (options.category_id) this.categoryId = options.category_id;
if (options.title) {
this.title = decodeURIComponent(options.title);
if (this.title) uni.setNavigationBarTitle({ title: this.title });
}
if (options.page_key) this.pageKey = options.page_key;
this.pageParams = this.$util.parsePageParams(options.page_params) || {};
},
onShow() {
this.setPublicShare();
},
methods: {
getData(mescroll) {
// 合并 page_params 与显式参数,保证后端拿到完整过滤条件
let data = Object.assign({}, this.pageParams, {
page_size: mescroll.size,
page: mescroll.num
});
if (this.categoryId) data.category_id = this.categoryId;
this.$api.sendRequest({
url: '/api/article/page',
data: data,
data: {
page_size: mescroll.size,
page: mescroll.num
},
success: res => {
let newArr = [];
let msg = res.message;
@@ -106,32 +87,17 @@ export default {
// 设置公众号分享
setPublicShare() {
let shareUrl = this.$config.h5Domain + '/pages_tool/article/list';
let query = this.shareQuery();
if (query) shareUrl += '?' + query;
this.$util.setPublicShare({
title: this.title || this.$lang('article.list.title'),
title: this.$lang('article.list.title'),
desc: '',
link: shareUrl,
imgUrl: this.siteInfo ? this.$util.img(this.siteInfo.logo_square) : ''
});
},
// 组装带回过滤参数的 query 串,保证分享/跳转后参数不丢失
shareQuery() {
let params = {};
if (this.categoryId) params.category_id = this.categoryId;
if (this.title) params.title = encodeURIComponent(this.title);
if (this.pageKey) params.page_key = this.pageKey;
if (Object.keys(this.pageParams).length) params.page_params = encodeURIComponent(JSON.stringify(this.pageParams));
return Object.keys(params)
.map(k => k + '=' + params[k])
.join('&');
}
},
onShareAppMessage(res) {
var title = this.title || this.$lang('article.list.title');
var title = this.$lang('article.list.title');
var path = '/pages_tool/article/list';
var query = this.shareQuery();
if (query) path += '?' + query;
return {
title: title,
path: path,
@@ -141,10 +107,8 @@ export default {
},
//分享到朋友圈
onShareTimeline() {
var title = this.title || this.$lang('article.list.title');
var title = this.$lang('article.list.title');
var query = '/pages_tool/article/list';
var q = this.shareQuery();
if (q) query += '?' + q;
return {
title: title,
query: query,

View File

@@ -1,589 +0,0 @@
<template>
<view class="files-detail" :style="themeColor">
<view class="file-card">
<view class="pdf-icon">
<text class="pdf-icon-p">P</text>
<view class="pdf-icon-fold"></view>
<view class="pdf-icon-lines">
<view class="pdf-icon-line"></view>
<view class="pdf-icon-line"></view>
<view class="pdf-icon-line"></view>
</view>
</view>
<view class="info-wrap">
<view class="title">{{ displayTitle }}</view>
<view v-if="!loaded" class="read-wrap">
<text>{{ $lang('files.list.loading') }}</text>
</view>
</view>
</view>
<view v-if="fileUrl" class="action-area">
<button class="action-btn primary" @tap="openFile">{{ $lang('files.list.viewPdf') }}</button>
</view>
<view v-if="failed" class="error-tip">{{ $lang('files.list.fileNotExist') }}</view>
<loading-cover ref="loadingCover"></loading-cover>
<!-- 隐私弹窗 -->
<privacy-popup ref="privacyPopup"></privacy-popup>
</view>
</template>
<script>
/**
* 文件详情页 —— 承接 DIY 装修里的文件链接: /pages_tool/files/detail?files_id=43&title=xxx
*
* 背景: 后台装修数据(如"图标导航/文本导航"的 FILES_xx 链接)把文件指向本页,
* 此前页面缺失导致点击后打不开。本页负责:
* 1) 按 files_id 取到文件信息(files_url / files_title)
* 2) 进入页面即自动按平台打开文件(与 files/list 点击行为一致)
* 3) 自动打开失败时,可点击"查看PDF文件"按钮重试
*
* 注1: 本页文案只使用语言包中已存在的 key(files.list.*),避免新增 key 未同步到服务端
* (lang 为 remote-only 模式,运行时取 /api/lang/bundle)。
* 注2: Files 控制器没有单文件详情接口,只能从列表接口里按 files_id 取,详见 fetchFile()。
*/
export default {
data() {
return {
filesId: '',
filesTitle: '',
detail: null,
fileUrl: '',
loaded: false,
failed: false,
// 排查用:记录列表接口扫过的文件(files_id:标题)
scanned: [],
titleTimers: []
};
},
computed: {
displayTitle() {
if (this.filesTitle) return this.filesTitle;
if (this.detail && (this.detail.files_title || this.detail.title)) {
return this.detail.files_title || this.detail.title;
}
return this.$lang('files.list.title');
},
themeColor() {
if (this.$shop && this.$shop.themeColor) {
return `--theme-color: ${this.$shop.themeColor};`;
}
return '';
}
},
onLoad(options) {
options = options || {};
// page_params 可能是 JSON 字符串 / 对象 / 数组(装修数据里常见 [])
const params = this.$util.parsePageParams(options.page_params) || {};
const rawId = options.files_id || options.file_id || options.filesId || options.id
|| params.files_id || params.file_id || params.id || '';
this.filesId = rawId === '' || rawId === undefined || rawId === null ? '' : String(rawId);
const rawTitle = options.title || params.title || '';
if (rawTitle) this.filesTitle = this.decodeTitle(rawTitle);
this.scheduleTitleSync();
this.getData();
},
onUnload() {
this.clearTitleTimers();
},
watch: {
// main.js 的全局 mixin 监听 componentRefresh,变化时调用 $langConfig.refresh(),
// 而 refresh() 会用 $lang('title') 重置导航标题。本页标题就是文件名、且远端语言包里
// 没有 files/detail 词条(remote-only 模式),$lang('title') 会退化成字面量 "title"。
// refresh() 对每个组件都会跑一遍、"最后一个生效",所以这里延时补写几次兜底。
componentRefresh() {
if (this.isCurrentPage()) this.scheduleTitleSync();
}
},
onShareAppMessage() {
return {
title: this.displayTitle,
path: `/pages_tool/files/detail?files_id=${this.filesId}`
};
},
onShareTimeline() {
return {
title: this.displayTitle,
query: `files_id=${this.filesId}`
};
},
methods: {
syncNavigationTitle() {
this.$langConfig.title(this.displayTitle);
},
// 导航标题兜底:立即写一次,再延时补几次(等全局 refresh() 都跑完)
scheduleTitleSync() {
this.clearTitleTimers();
this.syncNavigationTitle();
[100, 500, 1500].forEach(delay => {
this.titleTimers.push(setTimeout(() => {
if (this.isCurrentPage()) this.syncNavigationTitle();
}, delay));
});
},
clearTitleTimers() {
this.titleTimers.forEach(id => clearTimeout(id));
this.titleTimers = [];
},
// 本页是否在最上层(避免本页在后台时去改别的页面标题)
isCurrentPage() {
try {
const pages = getCurrentPages();
const current = pages[pages.length - 1];
if (!current) return false;
const route = current.route || (current.$page && current.$page.path) || '';
return route.indexOf('files/detail') !== -1;
} catch (e) {
return false;
}
},
decodeTitle(value) {
const str = String(value || '');
// 多数端 uni 已自动 decode 一次,这里只在明显还是百分号编码时才解码,避免二次解码破坏文案
if (!str || str.indexOf('%') === -1) return str;
try {
return decodeURIComponent(str);
} catch (e) {
return str;
}
},
hideLoadingCover() {
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
},
async getData() {
if (!this.filesId) {
this.finishLoad(null);
return;
}
// 优先走后端单文件详情接口: 按 files_id 直接取, 无需翻列表(文件多时省几十个请求)
let detail = await this.fetchGetfile(this.filesId);
// 兜底: 列表逐页扫(可能为空/被过滤) / 企业文件接口
if (!detail) detail = await this.fetchFile(this.filesId) || await this.fetchFromPersonnel();
if (!detail || !this.normalizeUrl(detail.files_url)) {
this.finishLoad(null);
this.$util.showToast({
title: this.$lang('files.list.fileNotExist'),
icon: 'none'
});
return;
}
this.detail = detail;
if (!this.filesTitle) this.filesTitle = detail.files_title || detail.title || '';
this.syncNavigationTitle();
this.fileUrl = this.normalizeUrl(detail.files_url);
this.finishLoad(detail);
// 进入详情页即自动打开,与点击文件列表项行为一致
this.openFile();
},
finishLoad(detail) {
this.loaded = true;
this.failed = !detail;
this.hideLoadingCover();
},
/**
* 取单个文件信息(优先链路)。
* 后端接口: GET /api/files/getfile?files_id=xxx
* 内部 getFilesInfo([['files_id','=',$files_id]]) → model('files')->getInfo(),
* 返回整条记录(files_title / files_url / files_desc / category_id 等),
* files_url 已 img() 补全域名; files 表带 site_id, bootSiteGuard 自动注入当前站点,多租户不串号。
* 仅 files_id 一个参数即可,后端无需改造。
*/
async fetchGetfile(filesId) {
const res = await this.request('/api/files/getfile', { files_id: filesId });
if (!res || res.code !== 0 || !res.data) return null;
const d = res.data;
return {
files_id: d.files_id || filesId,
files_title: d.files_title || d.title || '',
files_url: d.files_url || '',
files_desc: d.files_desc,
category_id: d.category_id,
category_name: d.category_name
};
},
/**
* 兜底链路(优先链路 fetchGetfile 失败时): 逐页拉列表按 files_id 精确匹配。
* 该 addon 之前 Files 控制器只提供列表接口(实测 /api/files/info、/detail、/getinfo 均 404:
* "method not exists:app\api\controller\Files->info()"),所以用 getpage 翻页扫。
*/
async fetchFile(filesId) {
// 1) 有标题时先拿标题当关键词搜一次(命中就 1 个请求解决,不必深翻页)
if (this.filesTitle) {
const searched = await this.queryList({ page: 1, page_size: 100, keyword: this.filesTitle }, filesId, true);
if (searched && searched.hit) return searched.hit;
}
// 2) 逐页遍历全量列表(后端只返回 10 条/页时最多翻 30 页)
for (let page = 1; page <= 30; page++) {
const queried = await this.queryList({ page: page, page_size: 100 }, filesId);
if (queried && queried.hit) return queried.hit;
if (!queried || queried.empty) return null;
}
return null;
},
/**
* 兜底链路: 从企业文件接口(/api/member/personnel, 电子名片页"企业文件"同源)取文件。
* 该接口返回 res.file_list, 每项形如 { name, url }(可能带 files_id/file_id/id)。
* 先按 files_id 精确匹配, 再按标题精确匹配, 最后按标题互相包含模糊匹配。
*/
async fetchFromPersonnel() {
const res = await this.request('/api/member/personnel', {});
if (!res || res.code !== 0) return null;
const list = res.file_list || (res.data && res.data.file_list) || [];
if (!Array.isArray(list)) return null;
const title = (this.filesTitle || '').toString();
const getId = item => item.files_id || item.file_id || item.id || '';
let fuzzyHit = null;
for (const item of list) {
if (!item) continue;
// 1) files_id 精确匹配
const id = getId(item);
if (id !== '' && String(id) === String(this.filesId)) return this.wrapPersonnelFile(item);
// 2) 标题精确匹配
const name = (item.name || item.files_title || item.title || '').toString();
if (title && name === title) return this.wrapPersonnelFile(item);
// 3) 标题互相包含(记下第一个命中, 优先级最低)
if (title && !fuzzyHit && (name.indexOf(title) !== -1 || title.indexOf(name) !== -1)) {
fuzzyHit = item;
}
}
return fuzzyHit ? this.wrapPersonnelFile(fuzzyHit) : null;
},
wrapPersonnelFile(item) {
return {
files_id: item.files_id || item.file_id || item.id || this.filesId,
files_title: item.name || item.files_title || item.title || '',
files_url: item.url || item.files_url || ''
};
},
/**
* 请求一页文件列表,并按 files_id 精确匹配(入参与 files/list 页保持一致)
* @param {Boolean} allowTitleMatch 该页是标题搜索结果时,允许退一步用标题全等匹配
* @returns {Object|null} 命中返回 { hit };本页无数据返回 { empty: true };请求失败返回 null
*/
async queryList(data, filesId, allowTitleMatch) {
const res = await this.request('/api/files/getpage', Object.assign({
category_id: '',
keyword: ''
}, data));
if (!res || res.code !== 0 || !res.data || !Array.isArray(res.data.list)) return null;
const list = res.data.list;
let titleHit = null;
for (const item of list) {
const src = item && item.$orig ? item.$orig : item;
if (!src) continue;
if (String(src.files_id) === String(filesId)) return { hit: src };
// 兜底:装修链接里的 files_id 与接口不一致时,用标题全等再认一次
if (allowTitleMatch && !titleHit && this.filesTitle && src.files_title === this.filesTitle) {
titleHit = src;
}
}
if (titleHit) return { hit: titleHit };
return { empty: list.length === 0 };
},
async request(url, data) {
try {
return await this.$api.sendRequest({
url,
data,
async: false,
noRetry: true,
// 失败静默返回 null,由调用方兜底,不弹全局报错
silentError: true
});
} catch (e) {
return null;
}
},
normalizeUrl(url) {
if (!url) return '';
const str = String(url);
if (/^https?:\/\//i.test(str)) return str;
// $util.img 对含逗号的路径会按"多图字段"截断,文件名可能含逗号,这里规避
if (str.indexOf(',') !== -1) return str;
// 相对路径补全域名(与图片同一套域名规则)
return this.$util.img(str);
},
getFileExt() {
let ext = 'pdf';
if (this.fileUrl) {
const clean = this.fileUrl.split('?')[0];
const matched = clean.match(/\.([a-zA-Z0-9]+)$/);
if (matched) ext = matched[1].toLowerCase();
}
return ext;
},
getFileName() {
const title = (this.displayTitle || 'file').toString().replace(/[\\/:*?"<>|\r\n\t]/g, '_');
return `${title}.${this.getFileExt()}`;
},
getFileType() {
const ext = this.getFileExt();
return ['pdf'].includes(ext) ? 'pdf'
: ['doc', 'docx'].includes(ext) ? 'word'
: ['mp4', 'avi', 'mov', 'wmv', 'flv', 'mkv', 'webm'].includes(ext) ? 'video'
: 'pdf';
},
buildPreviewUrl() {
const fileName = encodeURIComponent(this.getFileName());
const fileUrl = encodeURIComponent(this.fileUrl);
const fileType = encodeURIComponent(this.getFileType());
return `/pages_tool/file-preview/file-preview?fileName=${fileName}&fileUrl=${fileUrl}&fileType=${fileType}`;
},
openFile() {
if (!this.fileUrl) {
this.failed = true;
this.$util.showToast({
title: this.$lang('files.list.fileNotExist'),
icon: 'none'
});
return;
}
this.failed = false;
const ext = this.getFileExt();
const previewPage = this.buildPreviewUrl();
// ========== H5 端: 用预览页替换当前页(web-view 走 iframe),失败则新标签页打开 ==========
// #ifdef H5
uni.redirectTo({
url: previewPage,
fail: () => {
try {
window.open(this.fileUrl, '_blank');
} catch (e) {
this.failed = true;
}
}
});
return;
// #endif
// ========== 非 H5 端: 下载文件后按平台分支打开 ==========
// #ifndef H5
uni.showLoading({ title: this.$lang('files.list.loading'), mask: true });
uni.downloadFile({
url: this.fileUrl,
success: res => {
if (res.statusCode !== 200) {
uni.hideLoading();
this.failed = true;
uni.showToast({ title: this.$lang('files.list.fileNotExist'), icon: 'none' });
return;
}
// ----- 微信小程序: saveFile 重命名 + openDocument(标题取短文件名) -----
// #ifdef MP-WEIXIN
const fs = uni.getFileSystemManager();
const title = (this.displayTitle || 'file').toString().replace(/[\\/:*?"<>|\r\n\t]/g, '_');
const targetPath = `${wx.env.USER_DATA_PATH}/fs_${Date.now()}_${title}.${ext}`;
const openByPath = (filePath, cleanup) => {
uni.openDocument({
filePath,
fileType: ext,
showMenu: true,
fail: () => {
this.failed = true;
uni.showToast({ title: this.$lang('files.list.fileNotExist'), icon: 'none' });
},
complete: () => {
if (cleanup) {
try { fs.removeSavedFile({ filePath }); } catch (e) {}
}
}
});
};
try {
fs.saveFile({
tempFilePath: res.tempFilePath,
filePath: targetPath,
success: r => {
uni.hideLoading();
openByPath(r.savedFilePath, true);
},
fail: () => {
// saveFile 失败(配额等),直接用临时文件兜底
uni.hideLoading();
openByPath(res.tempFilePath, false);
}
});
} catch (e) {
uni.hideLoading();
openByPath(res.tempFilePath, false);
}
// #endif
// ----- App / 其他小程序: 直接 openDocument;失败兜底跳转预览页 -----
// #ifndef MP-WEIXIN
uni.hideLoading();
uni.openDocument({
filePath: res.tempFilePath,
fileType: ext,
showMenu: true,
fail: () => {
uni.navigateTo({
url: previewPage,
fail: () => {
this.failed = true;
uni.showToast({ title: this.$lang('files.list.fileNotExist'), icon: 'none' });
}
});
}
});
// #endif
},
fail: () => {
uni.hideLoading();
this.failed = true;
uni.showToast({ title: this.$lang('files.list.fileNotExist'), icon: 'none' });
},
complete: res => {
if (res && res.statusCode === 404) {
uni.hideLoading();
this.failed = true;
uni.showToast({ title: this.$lang('files.list.fileNotExist'), icon: 'none' });
}
}
});
// #endif
}
}
};
</script>
<style scoped>
.files-detail {
width: 100%;
min-height: 100vh;
padding: 30rpx;
box-sizing: border-box;
background-color: #f8f8f8;
}
.files-detail .file-card {
display: flex;
align-items: center;
padding: 30rpx;
background-color: #fff;
border-radius: 16rpx;
}
.files-detail .file-card .pdf-icon {
margin-right: 24rpx;
width: 96rpx;
height: 96rpx;
flex-shrink: 0;
background-color: #e64340;
border-radius: 10rpx;
position: relative;
overflow: hidden;
box-shadow: 0 2rpx 8rpx rgba(230, 67, 64, 0.2);
}
.files-detail .file-card .pdf-icon .pdf-icon-p {
position: absolute;
top: 2rpx;
left: 10rpx;
color: #ffffff;
font-size: 48rpx;
font-weight: 900;
font-family: Arial, Helvetica, sans-serif;
line-height: 1;
}
.files-detail .file-card .pdf-icon .pdf-icon-fold {
position: absolute;
top: 0;
right: 0;
width: 28rpx;
height: 28rpx;
background: linear-gradient(135deg, transparent 50%, #ffeceb 50%);
border-bottom-left-radius: 4rpx;
}
.files-detail .file-card .pdf-icon .pdf-icon-lines {
position: absolute;
right: 8rpx;
bottom: 8rpx;
width: 42rpx;
display: flex;
flex-direction: column;
align-items: flex-end;
}
.files-detail .file-card .pdf-icon .pdf-icon-line {
width: 100%;
height: 3rpx;
background-color: #ffffff;
opacity: 0.85;
margin-bottom: 4rpx;
border-radius: 2rpx;
}
.files-detail .file-card .pdf-icon .pdf-icon-line:nth-child(2) {
width: 80%;
}
.files-detail .file-card .pdf-icon .pdf-icon-line:nth-child(3) {
width: 60%;
margin-bottom: 0;
}
.files-detail .file-card .info-wrap {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
}
.files-detail .file-card .info-wrap .title {
font-weight: 700;
color: #303133;
font-size: 30rpx;
line-height: 1.4;
word-break: break-all;
}
.files-detail .file-card .info-wrap .read-wrap {
display: flex;
color: #999ca7;
align-items: center;
margin-top: 12rpx;
line-height: 1;
}
.files-detail .file-card .info-wrap .read-wrap text {
font-size: 24rpx;
}
.files-detail .action-area {
margin-top: 40rpx;
}
.files-detail .action-area .action-btn {
height: 84rpx;
line-height: 84rpx;
margin: 0;
padding: 0;
font-size: 30rpx;
border-radius: 42rpx;
background: linear-gradient(90deg, #ff7e47 0%, #f73131 100%);
color: #fff;
border: none;
font-weight: 600;
box-shadow: 0 4rpx 12rpx rgba(247, 49, 49, 0.25);
}
.files-detail .action-area .action-btn::after {
border: none;
}
.files-detail .error-tip {
margin-top: 30rpx;
text-align: center;
color: #999;
font-size: 26rpx;
line-height: 1.6;
}
</style>

View File

@@ -8,7 +8,7 @@ const paths = [
['pages_promotion/merch/detail','商户首页'],
['pages_promotion/fenxiao/ranking_list','排行榜'],
['pages_promotion/fenxiao/child_fenxiao','分销商'],
['pages_tool/ai-chat/index','AI智能客服'],
['pages_tool/ai-chat/index','AI智能'],
['pages_tool/contact/contact','电子名片'],
['pages_tool/member/info','个人资料'],
['pages_tool/order/activist','退款'],

View File

@@ -1,119 +0,0 @@
import re
path = r"D:\0.daima\lucky_shop\components-diy\diy-recommend-code.vue"
with open(path, "r", encoding="utf-8") as f:
s = f.read()
BASE = "components-diy.diy-recommend-code."
# ---- 1. value.xxx || '中文' / nc.xxx || '中文' ----
TEXT_FIELDS = {
'title','buttonText','copyButtonText','consentText','consentButtonText',
'loginTipText','loginBtnText','posterQrTip','placeholderRegenerateText',
}
def repl_value_nc(m):
prefix = m.group(1) # e.g. "value.title || "
field = m.group(2)
if field in TEXT_FIELDS:
return prefix + "$lang('" + BASE + field + "')"
return m.group(0)
s = re.sub(r"((?:value|nc)\.(\w+)\s*\|\|\s*)'([^']*)'", repl_value_nc, s)
# ---- 2. standalone template text nodes ----
standalone = {
'\u4e13\u5c5e\u63a8\u8350\u7801': 'exclusiveCode',
'\u5f85\u83b7\u53d6\u63a8\u8350\u7801': 'pendingCode',
'\u5f85\u83b7\u53d6': 'pending',
'\u63a8\u8350\u7801\u52a0\u8f7d\u4e2d...': 'loading',
'\u5df2\u83b7\u5f97\u63a8\u8350\u7801': 'obtainedCode',
'\u5df2\u83b7\u5f97': 'obtained',
'\u5206\u4eab\u7ed9\u597d\u53cb\uff0c\u9080\u8bf7\u6ce8\u518c\u5373\u53ef\u83b7\u5f97\u5956\u52b1': 'shareInviteReward',
'\u2713 \u5df2\u751f\u6548': 'activated',
'\u63a8\u8350\u7801\u5df2\u751f\u6210\uff0c\u53ef\u7528\u4e8e\u9080\u8bf7\u597d\u53cb\u6216\u4f01\u4e1a\u5165\u9a7b\u7ed1\u5b9a\u63a8\u8350\u5173\u7cfb': 'codeGenerated',
}
for zh, key in standalone.items():
s = s.replace(">%s</text>" % zh, ">{{ $lang('%s%s') }}</text>" % (BASE, key))
# ---- 3. '提交中...' standalone in template ternary ----
s = s.replace("'\u63d0\u4ea4\u4e2d...'", "$lang('%ssubmitting')" % BASE)
# ---- 4. default() Chinese literals -> '' ----
default_map = {
"title: '\u6211\u7684\u63a8\u8350\u7801'": "title: ''",
"buttonText: '\u7acb\u5373\u5206\u4eab'": "buttonText: ''",
"copyButtonText: '\u590d\u5236\u63a8\u8350\u7801'": "copyButtonText: ''",
"placeholderRegenerateText: '\u6362\u4e00\u4e2a\u65b0\u7801'": "placeholderRegenerateText: ''",
"consentText: '\u60a8\u7684\u63a8\u8350\u7801\u5c06\u7528\u4e8e\u4f01\u4e1a\u5165\u9a7b\u6765\u6e90\u8ffd\u8e2a\uff0c\u6211\u4eec\u4f1a\u8bb0\u5f55\u6bcf\u4e00\u6b21\u901a\u8fc7\u60a8\u5206\u4eab\u94fe\u63a5\u5b8c\u6210\u7684\u5165\u9a7b\u7533\u8bf7\uff0c\u7528\u4e8e\u60a8\u7684\u63a8\u5e7f\u6536\u76ca\u7ed3\u7b97\u3002'": "consentText: ''",
"consentButtonText: '\u540c\u610f\u5e76\u83b7\u53d6\u63a8\u8350\u7801'": "consentButtonText: ''",
"loginTipText: '\u767b\u5f55\u540e\u67e5\u770b\u6211\u7684\u63a8\u8350\u7801'": "loginTipText: ''",
"loginBtnText: '\u53bb\u767b\u5f55'": "loginBtnText: ''",
"posterQrTip: '\u626b\u7801\u8fdb\u5165\u5e76\u586b\u5199\u5165\u9a7b\u4fe1\u606f'": "posterQrTip: ''",
}
for a, b in default_map.items():
s = s.replace(a, b)
# ---- 5. JS user-facing strings ----
# rcCopyToClipboard util (uses vm.$lang)
s = s.replace("cb && cb(false, '\u5185\u5bb9\u4e3a\u7a7a')",
"cb && cb(false, vm.$lang('%scopyEmpty'))" % BASE)
s = s.replace("fail: () => cb && cb(false, '\u590d\u5236\u5931\u8d25')",
"fail: () => cb && cb(false, vm.$lang('%scopyFail'))" % BASE)
s = s.replace("cb && cb(ok ? true : false, ok ? null : '\u590d\u5236\u5931\u8d25')",
"cb && cb(ok ? true : false, ok ? null : vm.$lang('%scopyFail'))" % BASE)
s = s.replace("cb && cb(false, '\u590d\u5236\u5931\u8d25')",
"cb && cb(false, vm.$lang('%scopyFail'))" % BASE)
# getFail / getFailCode / getSuccess / netError
s = s.replace("var lastMsg = '\u63a8\u8350\u7801\u83b7\u53d6\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5';",
"var lastMsg = this.$lang('%sgetFail');" % BASE)
s = s.replace("('\u63a8\u8350\u7801\u83b7\u53d6\u5931\u8d25(\u4e1a\u52a1\u7801=' + unpacked.businessCode + ')')",
"this.$lang('%sgetFailCode', { code: unpacked.businessCode })" % BASE)
s = s.replace("uni.showToast({ title: '\u83b7\u53d6\u6210\u529f', icon: 'success' })",
"uni.showToast({ title: this.$lang('%sgetSuccess'), icon: 'success' })" % BASE)
s = s.replace("'\u7f51\u7edc\u5f02\u5e38\uff1a' + failMsg.slice(0, 30)",
"this.$lang('%snetError')" % BASE)
s = s.replace("'\u7f51\u7edc\u5f02\u5e38\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5'",
"this.$lang('%snetError')" % BASE)
# regen modal
s = s.replace("title: '\u6362\u65b0\u7801',", "title: this.$lang('%sregenTitle')," % BASE)
s = s.replace("content: '\u6362\u65b0\u7801\u540e\u65e7\u7801\u4f1a\u7acb\u5373\u5931\u6548\uff0c\u540e\u7eed\u6240\u6709\u4f7f\u7528\u65e7\u5206\u4eab\u94fe\u63a5\u7684\u5165\u9a7b\u7533\u8bf7\u90fd\u4e0d\u4f1a\u5f52\u5c5e\u5230\u60a8\uff0c\u786e\u8ba4\u7ee7\u7eed\uff1f',",
"content: this.$lang('%sregenContent')," % BASE)
s = s.replace("confirmText: '\u786e\u8ba4\u6362\u65b0',", "confirmText: this.$lang('%sregenConfirm')," % BASE)
s = s.replace("cancelText: '\u53d6\u6d88',", "cancelText: this.$lang('%sregenCancel')," % BASE)
s = s.replace("title: unpacked.msg ? String(unpacked.msg) : '\u6362\u65b0\u5931\u8d25\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5',",
"title: unpacked.msg ? String(unpacked.msg) : this.$lang('%sregenFail')," % BASE)
s = s.replace("title: old ? ('\u5df2\u6362\u65b0\u7801\uff0c\u65e7\u7801 ' + old + ' \u5df2\u505c\u7528') : '\u6362\u65b0\u6210\u529f',",
"title: old ? this.$lang('%sregenSuccessOld', { old: old }) : this.$lang('%sregenSuccess')," % (BASE, BASE))
s = s.replace("uni.showToast({ title: '\u7f51\u7edc\u5f02\u5e38\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5', icon: 'none' })",
"uni.showToast({ title: this.$lang('%snetError'), icon: 'none' })" % BASE)
# share title (L1128 specific) then global for the rest
s = s.replace("(vm.nc && (vm.nc.shareTitle || vm.nc.title)) || '\u9080\u60a8\u5165\u9a7b\u4f4e\u7a7a\u7ecf\u6d4e\u4ea7\u4e1a\u5e73\u53f0'",
"(vm.nc && (vm.nc.shareTitle || vm.nc.title)) || this.$lang('%sshareTitle')" % BASE)
s = s.replace("'\u9080\u60a8\u5165\u9a7b\u4f4e\u7a7a\u7ecf\u6d4e\u4ea7\u4e1a\u5e73\u53f0'",
"this.$lang('%sshareTitle')" % BASE)
# copy / link toasts
s = s.replace("title: ok ? '\u63a8\u8350\u7801\u5df2\u590d\u5236' : (err || '\u590d\u5236\u5931\u8d25')",
"title: ok ? this.$lang('%scodeCopied') : (err || this.$lang('%scopyFail'))" % (BASE, BASE))
s = s.replace("uni.showToast({ title: '\u63a8\u8350\u7801\u8fd8\u672a\u751f\u6210\uff0c\u8bf7\u7a0d\u5019', icon: 'none' })",
"uni.showToast({ title: this.$lang('%scodeNotReady'), icon: 'none' })" % BASE)
s = s.replace("uni.showToast({ title: '\u63a8\u8350\u7801\u52a0\u8f7d\u5b8c\u6210\u540e\u518d\u590d\u5236', icon: 'none' })",
"uni.showToast({ title: this.$lang('%sloadThenCopy'), icon: 'none' })" % BASE)
s = s.replace("title: ok ? '\u63a8\u5e7f\u94fe\u63a5\u5df2\u590d\u5236' : (err || '\u590d\u5236\u5931\u8d25')",
"title: ok ? this.$lang('%slinkCopied') : (err || this.$lang('%scopyFail'))" % (BASE, BASE))
# poster title + canvas
s = s.replace("const title = v.title || '\u6211\u7684\u63a8\u8350\u7801';",
"const title = v.title || this.$lang('%stitle');" % BASE)
s = s.replace("ctx.fillText('\u5206\u4eab\u7ed9\u597d\u53cb,\u9080\u8bf7\u5165\u9a7b\u83b7\u5f97\u5956\u52b1', 24, 70);",
"ctx.fillText(this.$lang('%sposterShareInvite'), 24, 70);" % BASE)
s = s.replace("ctx.fillText('\u94fe\u63a5:' + (linkText || '(\u672a\u751f\u6210)'), 24, urlY);",
"ctx.fillText(this.$lang('%sposterLinkPrefix') + (linkText || this.$lang('%sposterLinkEmpty')), 24, urlY);" % (BASE, BASE))
s = s.replace("ctx.fillText(v.posterQrTip || '\u626b\u7801\u8fdb\u5165\u5e76\u586b\u5199\u5165\u9a7b\u4fe1\u606f', W / 2, qrY + qrSize + 24);",
"ctx.fillText(v.posterQrTip || this.$lang('%sposterQrTip'), W / 2, qrY + qrSize + 24);" % BASE)
with open(path, "w", encoding="utf-8") as f:
f.write(s)
print("done")

View File

@@ -121,7 +121,7 @@
],
[
"pages_tool/ai-chat/index",
"AI智能客服"
"AI智能"
],
[
"pages_tool/contact/contact",

View File

@@ -9,7 +9,6 @@ import util from '../common/js/util.js'
import ThemeOverride from '../common/js/theme-override.js'
import { sanitizeFlatMap, mergeThemeBuckets } from '../common/js/merge-theme.js'
import PrivacyManager from '../common/js/privacy.js'
import LangConfig from '../common/js/lang.js'
// themeColor 结果缓存(避免每次都全量遍历 theme 对象)
// key: JSON.stringify(theme) + tabBarHeight, value: CSS变量字符串
@@ -98,7 +97,6 @@ const store = new Vuex.Store({
wap_valid_time: 0,
},
copyright: null,
floatingButtonConfig: null, // 来自 /api/config/init 的 data.floating_button (浮动侧边栏配置)
initStatus: false,
offlineWhiteList: ['pages_order/payment', 'pages_order/list', 'pages_order/detail'],//线下支付白名单
canReceiveRegistergiftInfo: {
@@ -165,23 +163,6 @@ const store = new Vuex.Store({
setShopInfo(state, value) {
state.shopInfo = value;
uni.setStorageSync('shopInfo', value); // 初始化数据调用
// 语言切换开关 fallback: 后台 shop_info.ischina 决定(老「双语模式」)。
// 新配置下发后由 setFloatingButtonConfig 里的 lang_switch.enabled 接管,
// 这里的 ischina 只是配置缺失(老缓存响应)时的兜底。
// 关闭时强制返回默认中文,并清掉用户此前持久化到 storage 的语种,
// 满足"后台关闭双语/小程序后,刷新重新进入必须是中文"的需求。
try { LangConfig.setLangSwitchEnabled(!!(value && value.ischina)); } catch (e) {}
},
// 浮动侧边栏配置 (来自 /api/config/init → data.floating_button)
setFloatingButtonConfig(state, value) {
state.floatingButtonConfig = value || null;
uni.setStorageSync('floatingButtonConfig', value || null);
// 与 setShopInfo 的 setLangSwitchEnabled 配对: 新配置存在时以新配置为准
try {
if (value && value.lang_switch) {
LangConfig.setLangSwitchEnabled(Number(value.lang_switch.enabled) === 1);
}
} catch (e) {}
},
setCartChange(state) {
state.cartChange += 1;
@@ -329,8 +310,6 @@ const store = new Vuex.Store({
//联系我们
this.commit('setShopInfo', data.shop_info);
// 浮动侧边栏配置; 缺失时显式置 null → 前端走老行为兜底
this.commit('setFloatingButtonConfig', data.floating_button || null);
this.commit('setWechatConfigStatus', data?.wechat_config_status);
// 默认总店
if (data.store_info) {

View File

@@ -65,16 +65,6 @@
"when": "always"
}
},
{
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 元服务录音需要麦克风权限
"name": "ohos.permission.MICROPHONE",
"usedScene": {
"abilities": [
"EntryAbility"
],
"when": "always"
}
},
{
"name": "ohos.permission.VIBRATE"
}