Compare commits

...

38 Commits

Author SHA1 Message Date
fc407935d2 chore :悬浮按钮自定义 2026-10-12 17:45:04 +08:00
df5be6045b common\js\floating-button.js
common\js\startup-ad.js
components\ns-mp-navbar\ns-mp-navbar.vue
2026-10-12 15:41:28 +08:00
571452cd30 chore:悬浮按钮可以自定义调节 2026-10-12 15:37:38 +08:00
1c0444b1ec chore:微信小程序真机广告 正常 2026-10-10 17:31:02 +08:00
09909f0dcf chore:真机上显示广告正常 2026-10-10 16:02:20 +08:00
b14032149e chore:启动广告,后台开启首次弹出,第一次进入小程序后会弹出广告,
后台开启每次弹出,每次重新进入小程序都会弹出广告
2026-10-10 11:35:55 +08:00
447f7cd7b5 chore:启动广告,后台开启首次弹出,每一次重新进入小程序后都会弹出广告 2026-10-10 11:20:36 +08:00
dd15ff8ea4 chore:智能客服的欢迎语标题可自定义调节 2026-10-10 09:04:09 +08:00
3ab78f5369 chore:AI智能题目可以自定义调节颜色大小,字号 2026-10-09 18:29:02 +08:00
e223e58425 chore:输入框切换正常 2026-10-09 18:17:03 +08:00
5ef5f275f0 chore:微信小程序的语音输入切换到文字输入不会闪 2026-10-09 18:10:31 +08:00
e7dd6aff62 chore:微信小程序的AI智能客服标题和图片之间有距离 2026-10-09 16:56:05 +08:00
8488aa39bc chore:输入框高度一致 2026-10-09 16:33:42 +08:00
817d2081d7 chore:输入框语音输入时,输入框样式修改 2026-10-09 16:21:27 +08:00
0a0ce88d82 chore:输入框样式突出 2026-10-09 14:45:08 +08:00
34c0df5320 chore:快捷问题,标题,换一换按钮,图片之间空隙变大 2026-10-09 14:34:14 +08:00
356a6d2bbf chore:真机用户隐私保护的“同意并继续”按钮显示正常 2026-10-09 09:16:18 +08:00
3b354992e3 chore:悬浮按钮可以自定义调节 2026-10-08 17:59:37 +08:00
fe0381a298 chore:微信小程序pdf正常打开 2026-10-08 17:26:16 +08:00
733c33a41c chore:新加源代码pages_tool/files/detail.vue,文件列表链接正常打开PDF 2026-10-08 17:07:10 +08:00
e8ff0e9be4 chore:快捷问题框浮起来 2026-10-08 09:22:36 +08:00
0faecf3603 chore:AI智能欢迎语的快捷问题的框改椭圆 2026-10-08 09:11:30 +08:00
e9c8bac60b chore:微信小程序正常 2026-09-30 17:02:26 +08:00
a72e1b733d chore:隐藏欢迎语页面的时间 2026-09-30 16:40:27 +08:00
132ecbb127 chore:随机生成快捷问题的图标 2026-09-30 16:36:15 +08:00
5173b5d38e chore:支持换一换按钮应用 2026-09-30 16:15:07 +08:00
4172da6201 chore:更新欢迎语和快捷问题的样式,点击输入框隐藏欢迎语整体 2026-09-30 16:02:20 +08:00
53be343159 chore:所有个更多功能正常 2026-09-30 15:26:14 +08:00
1de5f925ee chore:添加文件的图标正常 2026-09-30 14:48:38 +08:00
95b5484629 chore:新对话改成黑色,网址改成黑色 2026-09-30 14:36:56 +08:00
454bc3b522 chore:修改更多功能样式 2026-09-30 14:21:43 +08:00
1223ec9202 chore:隐藏更多功能中的语音 2026-09-30 12:01:17 +08:00
4f75347103 chore:语音输入图标正常 2026-09-30 11:58:34 +08:00
6e7dbdde94 chore:修改语音输入样式 2026-09-30 11:53:40 +08:00
04b5ed06a3 chore:修改语音输入图标 2026-09-30 11:37:04 +08:00
0507d600a0 chore:扬声器图标修改为黑色圆点 + 两道声波 2026-09-30 11:34:14 +08:00
cf902e0440 chore:语音输入图标更改 2026-09-30 11:30:26 +08:00
f555b8a946 chore:智能用户和回答都字号都25,不加粗 2026-09-30 10:49:08 +08:00
20 changed files with 2193 additions and 233 deletions

View File

@@ -214,14 +214,27 @@ 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']; // 燃气安全产品机器人,购物车无反应
@@ -244,7 +257,7 @@ const localDevConfig = ({
// })['2811']; // 本地
// })['5g-317']; // 电磁兼容
// })['5g-351']; //
})['2881']; // 本地
})['5g-97']; // 本地
// })['local-2']; // 本地
// })['local-11']; // 本地
// })['1-test']; // test

View File

@@ -8,6 +8,7 @@
// PR-MULTI-TURN-KEY-BINDING (2026-09-18): AI 客服会话 key 切换
// 登录态恢复后通知 aiService 清旧 user key,避免串会话
import aiService from 'common/js/ai-service.js';
import { markNeedStartupAd } from 'common/js/startup-ad.js';
// 记录 App 是否已至少展示过一次: 首次 onShow = 启动展示(由 onLaunch 完成初始化),
// 之后每一次 onShow(含微信 ... 菜单"重新进入小程序"、从后台切回)都视为"重新进入"。
@@ -512,6 +513,8 @@
// 之后每次 onShow(含 ... 重新进入、从后台切回前台)都视为重新进入,主动失效缓存并重新对齐。
if (_appHasShown) {
try { Lang.onAppReentry(); } catch (e) {}
// 重新进入小程序(从后台切回 / "重新进入小程序"菜单): 标记需要弹出启动广告
try { markNeedStartupAd(); } catch (e) {}
}
_appHasShown = true;

View File

@@ -2,6 +2,7 @@ import WxMap from 'common/js/map-wx-jssdk.js';
import Config from '@/common/js/config.js';
import util from '@/common/js/util.js';
import { classifyHttpError, httpErrorKey } from '@/common/js/http-error.js';
import { consumeNeedStartupAd, isColdLaunchPending } from '@/common/js/startup-ad.js';
let systemInfo = util.getDeviceInfo();
@@ -297,25 +298,84 @@ export default {
data: {},
async: false
});
this.adv = res.value
// 弹框形式,首次弹出 1,每次弹出 0
// 接口把启动广告配置放在 data 字段(少数环境也可能放在 value), 两者兼容,
// 避免取到 undefined 后模板 v-if 抛错导致 uni-popup 不渲染、真机广告弹不出来
let advData = (res && (res.data != null ? res.data : res.value)) || {};
this.adv = advData;
// 后台配置: advshow=1 开启启动广告; advtype 决定弹出策略
// advtype == 1: 首次弹出 —— 仅第一次进入小程序弹出(持久化标记, 清缓存后可再弹)
// advtype == 0: 每次弹出 —— 每次"重新进入小程序"都弹出(不含 Tab 切换回首页)
if (this.adv.advshow == 1) {
setTimeout(() => {
if (res.value.advtype == 1) {
var popwindow_count = uni.getStorageSync(this.id + this.name + '_popwindow_count');
if ((this.$refs.uniPopupWindow && popwindow_count == '') || (
this.$refs.uniPopupWindow && popwindow_count == 1)) {
setTimeout(async () => {
// 隐私协议未同意时, 先等用户点击隐私协议(同意/拒绝)关闭弹窗,
// 否则广告弹窗会被隐私弹窗(z-index:5000)盖住, 真机上表现为"点了隐私协议后广告不弹"
await this._waitPrivacyResolved();
if (!this.$refs.uniPopupWindow) return;
this.$refs.uniPopupWindow.open();
uni.setStorageSync(this.id + this.name + '_popwindow_count', 1);
// 先判定本次是否需要弹出, 避免无谓的图片预加载
let shouldOpen = false;
let isFirstType = false;
if (this.adv.advtype == 1) {
// 首次弹出: 从未展示过才弹
var popwindow_count = uni.getStorageSync(this.id + this.name + '_popwindow_count');
if (popwindow_count == '' || popwindow_count == 0) {
shouldOpen = true;
isFirstType = true;
}
} else if (res.value.advtype == 0) {
this.$refs.uniPopupWindow.open();
uni.setStorageSync(this.id + this.name + '_popwindow_count', 0);
} else {
// 每次弹出: 冷启动首次 或 真正"重新进入小程序"(App 前后台切换)时弹出,
// 由 App.onShow 在重新进入时置位的信号驱动, 切 Tab 不会触发 App.onShow 故不弹
if (consumeNeedStartupAd() || isColdLaunchPending()) {
shouldOpen = true;
}
}
if (!shouldOpen) return;
// 关键: 广告图片是网络图, 而 uni-popup 用 v-if 在 open() 时才渲染 slot,
// 图片要等弹窗打开后才开始请求/解码, 真机网络慢时就会"一截一截"逐步显示。
// 先把所有广告图片预加载进本地缓存, 全部就绪后再 open, 使弹窗一次性完整出现。
await this._preloadAdvImages(this.adv.list);
if (!this.$refs.uniPopupWindow) return;
this.$refs.uniPopupWindow.open();
if (isFirstType) {
uni.setStorageSync(this.id + this.name + '_popwindow_count', 1);
}
}, 500);
}
},
/**
* 等待隐私协议流程结束后再弹启动广告
* - 鸿蒙元服务: 隐私由系统托管, 应用层不弹自建弹窗, 直接放行
* - 已同意过(storage privacyAgreed): 无需等待, 直接放行
* - 未同意: 监听 PrivacyManager 广播的 privacy:agreed / privacy:disagreed,
* 用户点击隐私协议(同意/拒绝)关闭弹窗后放行
* - 兜底超时: 隐私协议因规则未弹等情况永不 emit 时也要弹广告, 避免卡死
* @param {number} [maxWait=15000]
* @returns {Promise<void>}
*/
_waitPrivacyResolved(maxWait = 15000) {
// 鸿蒙元服务: 隐私协议由系统托管, 应用层不弹自建隐私弹窗, 无需等待
// #ifdef MP-HARMONY
return Promise.resolve();
// #endif
// 已经同意过 → 隐私弹窗不会再出现, 直接放行
if (uni.getStorageSync('privacyAgreed')) return Promise.resolve();
return new Promise((resolve) => {
let done = false;
const finish = () => {
if (done) return;
done = true;
uni.$off('privacy:agreed', finish);
uni.$off('privacy:disagreed', finish);
clearTimeout(timer);
resolve();
};
uni.$on('privacy:agreed', finish);
uni.$on('privacy:disagreed', finish);
// 兜底: 隐私协议因规则未弹 / 一直未处理时, 超时后也要弹广告
const timer = setTimeout(finish, maxWait);
});
},
// 无法从网络获取 diy 数据时:在页面内渲染错误横幅(各端可靠、一定可见)
// 同时通过 uni.$emit 通知 splash-state 关闭启动屏 (否则 strict 模式永远不关)
@@ -542,9 +602,46 @@ export default {
console.warn('[DIY][getDiyInfo] no value in res.data', JSON.stringify(diyDataValue).slice(0, 200));
}
},
/**
* 预加载启动广告图片
* 广告弹窗由 uni-popup 在 open() 时才用 v-if 渲染内容, 图片是网络图,
* 若等到弹窗打开后才开始加载, 真机网络慢时会出现"一截一截"逐步显示。
* 这里提前把图片下载进本地缓存, 等全部加载完成(或超时)后再弹出,
* 使弹窗一次性完整呈现。
* @param {Array} list - adv.list, 元素形如 { imageUrl, link }
* @param {number} [timeout=4000] - 单张兜底超时, 避免个别图片卡住导致广告永不弹出
* @returns {Promise<void>}
*/
_preloadAdvImages(list, timeout = 4000) {
if (!list || !list.length) return Promise.resolve();
const tasks = list.map((item) => {
return new Promise((resolve) => {
const url = (item && item.imageUrl) ? this.$util.img(item.imageUrl) : '';
if (!url) return resolve();
let done = false;
const finish = () => {
if (done) return;
done = true;
clearTimeout(timer);
resolve();
};
const timer = setTimeout(finish, timeout);
try {
// getImageInfo 会下载图片并写入本地缓存, 之后 image 组件可直接命中缓存
uni.getImageInfo({
src: url,
success: finish,
fail: finish
});
} catch (e) {
finish();
}
});
});
return Promise.all(tasks).then(() => {});
},
closePopupWindow() {
this.$refs.uniPopupWindow.close();
uni.setStorageSync(this.id + this.name + '_popwindow_count', -1);
},
closeCollectPopupWindow() {
this.$refs.collectPopupWindow.close();

View File

@@ -68,6 +68,10 @@ export default {
hover_nav_bg_color: '#FFFC',
hover_nav_text_color: '#000',
hover_nav_font_size: '36rpx', // 悬浮按钮内文字/图标字号(后台可自定义, 默认与图标 36rpx 对齐)
hover_nav_lang_font_size: '36rpx', // 语言按钮内文字字号基准(文字实际按 0.667 缩放)
hover_nav_kefu_font_size: '36rpx', // 客服按钮内图标/emoji字号基准
hover_nav_phone_font_size: '36rpx', // 电话按钮内图标字号基准
// ===== DIY 分类页字号 token =====
diy_category_tree_select_size: '28rpx',

View File

@@ -0,0 +1,134 @@
/**
* 浮动侧边栏配置消费 (字段来源: /api/config/init → data.floating_button)
* 纯函数模块, 无副作用, 可直接单测
*/
/** 归一化路由: 'pages/index/index' → '/pages/index/index' */
export function normalizeRoute(route) {
if (!route) return '';
return String(route).charAt(0) === '/' ? String(route) : '/' + String(route);
}
/** 取当前页面路由 (兼容 H5 / 小程序; route 已含分包 root, 如 'pages_goods/detail') */
export function getCurrentRoute() {
try {
const pages = getCurrentPages();
const cur = pages[pages.length - 1];
return normalizeRoute((cur && (cur.route || (cur.$page && cur.$page.path))) || '');
} catch (e) {
return '';
}
}
/**
* 前缀命中判定
* '/pages/index' 命中 '/pages/index' 与 '/pages/index/xxx'
* '/pages_tool/' 命中 '/pages_tool/xxx' (前缀自带尾 /)
* '/pages/order/payment' 只命中它自己及其子路径
*/
export function hitPrefix(route, prefix) {
if (!route || !prefix) return false;
const p = prefix.charAt(prefix.length - 1) === '/' ? prefix : prefix + '/';
return route === prefix || route.indexOf(p) === 0;
}
/** 任一前缀命中 */
function hitAny(route, prefixes) {
if (!Array.isArray(prefixes)) return false;
for (let i = 0; i < prefixes.length; i++) {
if (hitPrefix(route, prefixes[i])) return true;
}
return false;
}
/** 找出路由命中的页面分组 key (未命中返回 null) */
export function matchPageGroup(route, prefixMap) {
if (!prefixMap) return null;
const keys = Object.keys(prefixMap);
for (let i = 0; i < keys.length; i++) {
if (hitAny(normalizeRoute(route), prefixMap[keys[i]])) return keys[i];
}
return null;
}
/**
* 侧边栏在当前页面是否显示 —— 唯一判定入口
*
* 优先级: 总开关 → 强制隐藏 → 显示范围
* 1) fb 不存在 (老缓存响应) → fallbackVisible (默认 true, 保持老行为)
* 2) enabled != 1 → false
* 3) 命中 force_hidden_prefixes 任意前缀 → false (最高优先级)
* 4) 命中 custom_pages / page_prefixes._custom → true
* 5) 命中 pages[组] == 1 → true
* 6) 都不命中 (如 /pages_goods/*) → false
*/
export function shouldShowOnPage(fb, route, fallbackVisible) {
if (!fb || typeof fb !== 'object') return fallbackVisible !== false;
if (Number(fb.enabled) !== 1) return false;
const r = normalizeRoute(route);
if (!r) return false;
// 强制隐藏 — 优先级最高
if (matchPageGroup(r, fb.force_hidden_prefixes)) return false;
// 自定义前缀优先判定
if (hitAny(r, fb.custom_pages) || hitAny(r, (fb.page_prefixes || {})['_custom'])) return true;
// 预设分组
const group = matchPageGroup(r, fb.page_prefixes);
if (group) return Number((fb.pages || {})[group]) === 1;
return false;
}
/**
* 当前页面要渲染的按钮列表 (已按 button_order 排序 + 显隐过滤)
* 返回 ['lang','kefu','phone'] 的子集, 空数组 = 整个侧边栏不渲染
* 返回 null = 配置缺失, 由调用方决定老行为
*/
export function resolveVisibleButtons(fb) {
if (!fb || typeof fb !== 'object') return null;
const order = Array.isArray(fb.button_order) ? fb.button_order : ['lang', 'kefu', 'phone'];
const map = fb.buttons || {};
const out = [];
for (let i = 0; i < order.length; i++) {
const k = order[i];
if (Number(map[k]) === 1) out.push(k);
}
return out;
}
/**
* 语言按钮显示文案
* @param {Object} fb data.floating_button
* @param {Array} langList [{ value:'zh-cn', name:'CN' }, ...]
* @param {Number} currentIdx 当前语言下标
*/
export function resolveLangButtonText(fb, langList, currentIdx) {
const list = Array.isArray(langList) ? langList : [];
if (!list.length) return '';
const style = (fb && fb.lang_switch && fb.lang_switch.style) || 'target';
if (style === 'text') {
const t = (fb && fb.lang_switch && fb.lang_switch.text) || '';
if (t) return t; // 空文案兜底走 target
}
if (style === 'current' || list.length < 2) {
return (list[currentIdx] && list[currentIdx].name) || '';
}
// target: 显示「点下去会切到的那个」语言
// 2 种语言 → 另一个; >2 种 → 取第一个不是当前的那个
let targetIdx = 0;
for (let i = 0; i < list.length; i++) {
if (i !== currentIdx) { targetIdx = i; break; }
}
return list[targetIdx] ? (list[targetIdx].name || '') : '';
}
/** 语言切换按钮是否可见 (含老「双语模式」fallback) */
export function isLangButtonVisible(fb, shopInfo, langCount) {
if (Number(langCount) < 2) return false;
if (fb && fb.lang_switch) return Number(fb.lang_switch.enabled) === 1;
return !!(shopInfo && shopInfo.ischina); // 老行为兜底
}

View File

@@ -629,16 +629,16 @@ function loadLangPackSync(lang, path) {
* @returns
*/
/**
* 语言切换开关钩子(由后台 shop_info.ischia 决定,经 store/index.js 的 setShopInfo 写入)。
* 语言切换开关钩子(由后台 shop_info.ischina 决定,经 store/index.js 的 setShopInfo 写入)。
*
* 设计原则: 只"在关闭时清理持久化语种", 绝不在开启态加任何门控 —— 否则一旦 ischia
* 设计原则: 只"在关闭时清理持久化语种", 绝不在开启态加任何门控 —— 否则一旦 ischina
* 取值/语义判断偏差, 就会误伤"开启双语后切换英文"的正常行为(回归)。
*
* 行为:
* - 后台关闭双语/小程序(ischia 为假): 清掉用户此前持久化到 storage 的语种 + 缓存,
* - 后台关闭双语/小程序(ischina 为假): 清掉用户此前持久化到 storage 的语种 + 缓存,
* 使刷新/重新进入时 getCurrentLocale() 回退默认中文, 满足
* "后台关闭双语后, 刷新重新进入必须是中文" 的需求。
* - 后台开启双语(ischia 为真): 不做任何拦截, 完全保持原有"切换英文"行为不变。
* - 后台开启双语(ischina 为真): 不做任何拦截, 完全保持原有"切换英文"行为不变。
*/
function setLangSwitchEnabled(enabled) {
if (!enabled) {
@@ -994,7 +994,7 @@ export default {
getCurrentLocale,
/**
* 语言切换功能开关(后台 shop_info.ischia 决定)。
* 语言切换功能开关(后台 shop_info.ischina 决定)。
* 关闭后 getCurrentLocale() 强制返回默认语言(中文),并清掉已持久化的语种。
* 详见本文件 setLangSwitchEnabled 函数与 store/index.js 的 setShopInfo 钩子。
*/

30
common/js/startup-ad.js Normal file
View File

@@ -0,0 +1,30 @@
// 启动广告弹出信号
// 用于判定"当前是否需要弹出启动广告":
// - 小程序冷启动(首次进入): 由模块级 _coldLaunchedShown 标记判定, 整个 app 进程只记一次
// - 小程序重新进入(从后台切回 / 微信"重新进入小程序"菜单):
// 由 App.onShow 在"非首次展示"时调用 markNeedStartupAd() 置位
// 信号消费一次即清除, 不落地到持久化存储, 因此无需清缓存即可每次重新进入都弹出。
// 关键: 切换 Tab 回到首页只触发"页面级 onShow", 不会触发 App.onShow, 也不会重置
// 模块级冷启动标记, 因此不会在 Tab 切换时误弹。
let _needStartupAd = false;
let _coldLaunchedShown = false;
// App 层检测到"重新进入小程序"时调用, 标记本次需要弹出启动广告
export function markNeedStartupAd() {
_needStartupAd = true;
}
// 页面层读取并消费该信号(消费后自动复位)
export function consumeNeedStartupAd() {
const v = _needStartupAd;
_needStartupAd = false;
return v;
}
// 是否为本 app 进程的首次冷启动(只返回一次 true, 之后恒为 false)
export function isColdLaunchPending() {
if (_coldLaunchedShown) return false;
_coldLaunchedShown = true;
return true;
}

View File

@@ -62,7 +62,13 @@ export default {
},
...{
hover_nav_bg_color: '#FFFC', //背景色: 红色 '#c6251b', 白色: '#FFFC'
hover_nav_text_color: '#000' // 文字颜色: 白色 '#FFFFFF', 黑色: '#000'
hover_nav_text_color: '#000', // 文字颜色: 白色 '#FFFFFF', 黑色: '#000'
hover_nav_font_size: '36rpx', // 悬浮按钮内文字/图标字号(后台可自定义, 默认与图标 36rpx 对齐)
// ===== 逐按钮字号(与 hover_nav_lang/kefu/phone 的 bg/text/size 同约定, 基准 36rpx) =====
// 未单独配置时回退到上面的 hover_nav_font_size(全局旋钮)
hover_nav_lang_font_size: '36rpx', // 语言按钮内文字字号基准(文字实际按 0.667 缩放)
hover_nav_kefu_font_size: '36rpx', // 客服按钮内图标/emoji字号基准
hover_nav_phone_font_size: '36rpx' // 电话按钮内图标字号基准
},
// ===== DIY 分类页字号 token(全 8 preset 一致, 远端可覆写) =====

View File

@@ -1254,6 +1254,21 @@ 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 重启、启动屏重播、状态/滚动丢失
@@ -1427,6 +1442,123 @@ 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,9 +1,10 @@
<template>
<!-- Vue 2 / uni-app 单根约束:用 view 包一层 -->
<view>
<view v-if="pageCount === 1 || need" class="fixed-box"
<view v-if="(pageCount === 1 || need) && fbVisible && hasAnyButton" class="fixed-box"
:style="[customContainerStyle, {
height: containerHeight,
width: containerWidth,
bottom: containerBottom,
right: containerRight,
backgroundImage: bgUrl ? `url(${bgUrl})` : '',
@@ -11,18 +12,18 @@
}]">
<!-- 多语言切换按钮:根据语言数智能切换交互 -->
<view
v-if="isLanguageSwitchEnabled && fixBtnShow"
class="btn-item common-bg"
:style="btnItemStyle"
v-if="isLanguageSwitchEnabled && hasLangButton"
class="btn-item common-bg btn-lang"
:style="[btnItemStyle('lang'), { order: orderIndex.lang }]"
@click="handleLangButtonClick"
>
<view class="lang-btn-text">{{ currentLangDisplayName }}</view>
<view class="lang-btn-text">{{ langButtonText }}</view>
</view>
<!-- 微信官方客服按钮-->
<button
v-if="fixBtnShow && hasValidKefuConfig && isWeappOfficialKefu"
class="btn-item common-bg"
:style="btnItemStyle"
v-if="hasKefuButton && hasValidKefuConfig && isWeappOfficialKefu"
class="btn-item common-bg btn-kefu"
:style="[btnItemStyle('kefu'), { order: orderIndex.kefu }]"
open-type="contact"
>
<text class="icox icox-kefu" v-if="!kefuimg"></text>
@@ -30,9 +31,9 @@
<!-- 其他类型客服按钮(智能客服、企业微信等)-->
<view
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && !showWeappSystemKefu"
class="btn-item common-bg"
:style="btnItemStyle"
v-if="hasKefuButton && hasValidKefuConfig && !isWeappOfficialKefu && !showWeappSystemKefu"
class="btn-item common-bg btn-kefu"
:style="[btnItemStyle('kefu'), { order: orderIndex.kefu }]"
@click="handleUnifiedKefuClick"
>
<image
@@ -48,9 +49,9 @@
<!-- 智能客服按钮(当同时显示小程序系统客服时)-->
<view
v-if="fixBtnShow && hasValidKefuConfig && !isWeappOfficialKefu && showWeappSystemKefu"
class="btn-item common-bg"
:style="btnItemStyle"
v-if="hasKefuButton && hasValidKefuConfig && !isWeappOfficialKefu && showWeappSystemKefu"
class="btn-item common-bg btn-kefu"
:style="[btnItemStyle('kefu'), { order: orderIndex.kefu }]"
@click="handleUnifiedKefuClick"
>
<image
@@ -66,9 +67,9 @@
<!-- 小程序系统客服按钮 -->
<button
v-if="fixBtnShow && hasValidKefuConfig && showWeappSystemKefu"
class="btn-item common-bg"
:style="btnItemStyle"
v-if="hasKefuButton && hasValidKefuConfig && showWeappSystemKefu"
class="btn-item common-bg btn-kefu"
:style="[btnItemStyle('kefu'), { order: orderIndex.kefu }]"
open-type="contact"
>
<text class="icox icox-kefu" v-if="!kefuimg"></text>
@@ -76,9 +77,9 @@
<!-- 电话按钮 -->
<view
v-if="fixBtnShow"
class="btn-item common-bg"
:style="[btnItemStyle, { backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
v-if="hasPhoneButton"
class="btn-item common-bg btn-phone"
:style="[btnItemStyle('phone'), { order: orderIndex.phone }, { backgroundImage: phoneimg ? `url(${phoneimg})` : '', backgroundSize: '100% 100%' }, customButtonStyle]"
@click="call"
>
<text class="iconfont icon-dianhua" v-if="!phoneimg"></text>
@@ -109,6 +110,10 @@
<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: 显示短码(按钮上展示)
@@ -161,6 +166,20 @@ function getLangShortCode(langValue, customMap) {
return prefix.toUpperCase();
}
// 跨页面/重挂载复用的悬浮按钮避让值(设计稿 rpx)。
// H5 切换页面时 hover-nav 会重新挂载并重新测量公告栏: 无公告栏的页面(如分类页)
// noticeRect 为 null, 若直接回落基础位置, 会与首页"公告下方"位置不一致,
// 切回首页时按钮突然上/下跳。缓存上次算出的避让值, 让所有页面位置恒定。
let cachedAvoidBottom = null;
// 需要隐藏悬浮按钮的页面路由(全平台生效: H5 + 小程序)
// /pages_goods/category 商品分类
// /pages_tool/contact/contact 电子名片(名片)
const H5_HIDDEN_ROUTES = [
'/pages_goods/category',
'/pages_tool/contact/contact',
];
export default {
name: 'hover-nav',
mixins: [i18nLazyMixin],
@@ -170,7 +189,7 @@ export default {
data() {
return {
pageCount: 0,
fixBtnShow: true,
currentRoute: '', // 当前页面路由(onShow / created 时刷新, 供页面范围判定)
shopInfo: null,
currentLangIndex: 0,
langIndexMap: {},
@@ -190,6 +209,12 @@ export default {
layoutTopBottom: 272, // --top-btn-bottom
layoutTopSize: 72, // --top-btn-size(Top 按钮正方形边长)
layoutFloatingWidth: 100, // --floating-btn-width
// 公告栏(diy-notice 跑马灯)实时测量数据,用于把悬浮按钮避让到其下方
// 注意: 字段名不能带 _ 前缀 —— Vue 2 不代理 _/$ 开头的 data 属性,
// 也不具备响应式,计算属性将永远读不到测量结果(踩过的坑)
noticeRect: null, // {top,bottom,height} 视口坐标(px)
winW: 0, // 视口宽(px)
winH: 0, // 视口高(px)
// i18n-lazy mixin 要求:data 中预声明 i18n 字段(初值空串),
// 模板只读 this.i18n.xxx,真实翻译在 openLangPicker() 中 prepareI18n() 后才填入
i18n: {
@@ -237,32 +262,75 @@ 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;
},
// 指定页面隐藏悬浮按钮(商品分类 / 电子名片), 全平台生效
hiddenOnRoute() {
const r = this.currentRoute;
return H5_HIDDEN_ROUTES.some((p) => r === p || r.indexOf(p + '/') === 0);
},
// 总开关 + 强制隐藏 + 页面范围 判定结果
fbVisible() {
if (this.hiddenOnRoute) return false; // 指定页面直接隐藏
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
// 生效,导致高度被压缩成 39.5px(从 41px),按钮显示为轻微椭圆。
// 2) inline-style 优先级高于 CSS class,直接锁死 72x72 + 正圆。
// 3) 用 max-width/max-height + flex-shrink 0 三重兜底,防止被任何层级的样式覆盖。
btnItemStyle() {
return {
width: '72rpx',
height: '72rpx',
'min-width': '72rpx',
'min-height': '72rpx',
'max-width': '72rpx',
'max-height': '72rpx',
'aspect-ratio': '1',
// border-radius 保留作 clip-path 不支持时的 fallback
'border-radius': '50%',
'flex-shrink': '0',
'flex-grow': '0',
'align-self': 'center',
'box-sizing': 'border-box',
padding: '0',
margin: '14rpx 0',
overflow: 'hidden',
};
},
// 2) inline-style 优先级高于 CSS class,直接锁死按钮尺寸 + 正圆。
// 3) 尺寸来源(逐按钮可调, 见 btnSizeRpx):
// hover_nav_lang_btn_size / hover_nav_lang_size
// hover_nav_kefu_btn_size / hover_nav_kefu_size
// hover_nav_phone_btn_size / hover_nav_phone_size
// 未配置时回退 72rpx(与原行为一致)。
// 4) 用 max-width/max-height + flex-shrink 0 三重兜底,防止被任何层级的样式覆盖。
// (已从 computed 改为 method: 模板按按钮类型调用 btnItemStyle('lang'|'kefu'|'phone'))
unreadCount() {
const customerService = createCustomerService(this);
return customerService.getUnreadCount();
@@ -296,53 +364,101 @@ export default {
return customerService.hasValidKefuConfig();
},
//根据显示的按钮数量动态计算容器高度
// 计算明细(buttonCount 按钮场景):
// 每个按钮槽位:72rpx(按钮,与 to-top 一致) + 14rpx(上 margin) + 14rpx(下 margin) = 100rpx
// 容器 padding:20rpx 上 + 20rpx 下 = 40rpx
// 总高度 (rpx):buttonCount × 100 + 40
// 修复:改返回 rpx 而非 px(原 *0.5 硬编码 iPhone 6 375px 转换比),
// 在微信小程序/其他设备(iPhone 13 390px、iPad 等)下由 uni-app 框架
// 按 windowWidth 动态换算,避免 4+ 按钮时容器偏小导致内容被裁切
// 关联:按钮尺寸与 to-top 同步(72rpx),所以槽位高度也是 100rpx;
// 之前按钮 80rpx 时槽位 108rpx,改为 72rpx 后槽位缩小 8rpx,容器整体更紧凑
// 当前实际会渲染出来的按钮尺寸列表(rpx), 与模板渲染一一对应。
// containerHeight / containerWidth 都以它为准, 后台把任一按钮调多大都能撑开容器。
renderedBtnSizes() {
const b = this.visibleButtons;
if (b && b.length === 0) return [];
const sizes = [];
if (this.isLanguageSwitchEnabled && this.hasLangButton) {
sizes.push(this.btnSizeRpx('lang'));
}
if (this.hasKefuButton && this.hasValidKefuConfig) {
sizes.push(this.btnSizeRpx('kefu'));
// 小程序系统客服与客服主按钮并存时, 模板会多渲染一个按钮
if (this.showWeappSystemKefu && !this.isWeappOfficialKefu) {
sizes.push(this.btnSizeRpx('kefu'));
}
}
if (this.hasPhoneButton) {
sizes.push(this.btnSizeRpx('phone'));
}
return sizes;
},
// 根据显示的按钮数量与各自尺寸动态计算容器高度
// 每个按钮槽位 = 按钮尺寸 + 14rpx(上 margin) + 14rpx(下 margin)
// 容器 padding: 20rpx 上 + 20rpx 下 = 40rpx
// 旧公式 buttonCount*100+40 是"所有按钮 72rpx"的特例, 现按逐按钮实际尺寸累加
containerHeightNum() {
const sizes = this.renderedBtnSizes;
if (sizes.length === 0) return 0;
return sizes.reduce((sum, s) => sum + s + 28, 0) + 40;
},
containerHeight() {
if (!this.fixBtnShow) return '320rpx';
let buttonCount = 1;
if (this.isLanguageSwitchEnabled) buttonCount++;
if (this.showWeappSystemKefu) buttonCount++;
buttonCount++;
const totalRpx = buttonCount * 100 + 40;
return `${totalRpx}rpx`;
return this.rpxStr(this.containerHeightNum);
},
// 容器宽度自适应: 至少保持原 --floating-btn-width(100rpx) 布局不变;
// 后台把任一按钮调大(如 hover_nav_lang_btn_size=120rpx)时, 容器随之撑大,
// 否则 .fixed-box 的 overflow:hidden 会把超宽按钮裁剪变形。
containerWidthNum() {
const maxBtn = this.renderedBtnSizes.reduce((m, s) => Math.max(m, s), 0);
// 额外 +12rpx 呼吸余量: 避免 rpx→px 亚像素取整导致按钮与容器边缘严丝合缝,
// 也给 bgUrl 背景胶囊留出按钮两侧各 6rpx 的边距; 按钮由 flex 居中, 不影响对齐。
return Math.max(this.layoutFloatingWidth, maxBtn + 12);
},
containerWidth() {
return this.rpxStr(this.containerWidthNum);
},
// 浮动按钮组底部 bottom 动态计算(在 Top 按钮上方):
// Top 按钮是 72x72 正方形,顶部边界 = bottom + size = layoutTopBottom + layoutTopSize
// containerBottom = Top 顶部边界 + space
// ------------------------------------------------------------
// space 是经验调优值(非数学推导),手调结果:
// H5 : 18 * 5 = 90rpx
// MP-WEIXIN: 18 * 1 = 18rpx
// 为什么 H5 反而大、微信反而小:
// 虽然 rpx 单位定义相同(windowWidth/750),但 Top 按钮
// <image mode="widthFix"> 在不同平台渲染有视觉差异。
// H5 浏览器(WebKit/Blink)渲染时,图片元素可能保留更多
// 内边距/基线,视觉上比 72rpx 大,需要更大间距才不挤;
// 微信 Skia 严格按 width=72rpx 渲染,视觉紧凑,
// 18rpx 就能有清晰的呼吸感。
// 90/18 是按"视觉上不挤"原则手调出来的,反过来都不行。
// space 两端统一为 18rpx:
// 旧的 H5=90rpx 特调是"H5 内联 rpx 全部失效、实际走 CSS fallback"年代的产物;
// 现在内联样式经 rpxStr() 在 H5 输出精确 px,几何计算两端一致,
// H5 必须与微信小程序保持相同位置(272+72+18 = 362rpx),不再需要平台特调。
// ------------------------------------------------------------
// 注意:安全区 var(--window-bottom) 由 CSS 的 margin-bottom 统一处理,
// 与 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;
// #endif
return `${this.layoutTopBottom + this.layoutTopSize + space}rpx`;
const space = 18;
const base = this.layoutTopBottom + this.layoutTopSize + space;
// 避让公告栏(diy-notice 跑马灯): 把悬浮按钮整体放到公告栏"正下方"。
// 关键:用「文档坐标」而非「视口坐标」算 bottom ——
// 公告栏随页面内容滚动, 其视口坐标(rect.bottom)随滚动变化;
// 若直接 (winH - rect.bottom) 算, 滚动时按钮会跟着公告栏上下移动。
// 这里把 rect 加上当前滚动距离得到"公告栏在文档中的底边",
// 再算 (winH - 文档底边): 该值与滚动无关, 按钮固定在"页面顶部时公告栏正下方",
// 滚动时按钮静止(公告栏自行滚走), 不再来回滑动。
const rect = this.noticeRect;
let target = null;
if (rect && this.winW > 0 && this.winH > 0 && rect.bottom > 0 && rect.top < this.winH) {
// 当前滚动距离(H5: window.pageYOffset; 小程序无 window 时回退 0)
let scrollY = 0;
try {
if (typeof window !== 'undefined' && 'pageYOffset' in window) {
scrollY = window.pageYOffset || 0;
} else if (typeof document !== 'undefined' && document.documentElement) {
scrollY = document.documentElement.scrollTop || 0;
}
} catch (e) { scrollY = 0; }
const scaleInv = 750 / this.winW; // px → 设计稿 rpx
const gap = 12; // 按钮与公告栏之间的间距(设计稿 rpx)
// 公告栏底边在文档中的坐标 = 视口坐标 + 滚动距离(滚动无关, 恒定)
const docBottom = rect.bottom + scrollY;
const distFromBottom = (this.winH - docBottom) * scaleInv;
// 按钮 bottom = 文档底边距视口底部 + 间距 - 按钮自身高度
const below = distFromBottom - gap - this.containerHeightNum;
if (Number.isFinite(below)) {
target = Math.max(0, below);
cachedAvoidBottom = target; // 缓存: 跨页面/重挂载复用, 位置恒定
}
}
// 无公告栏的页面(如分类页)复用上一次算出的避让值, 使悬浮按钮在所有页面位置一致
if (target === null && cachedAvoidBottom !== null) target = cachedAvoidBottom;
return this.rpxStr(target === null ? base : target);
},
// 浮动按钮组水平 right 动态计算(与 Top 按钮中心对齐):
// 公式: containerRight = TopRight + TopSize/2 - FloatingWidth/2
@@ -357,9 +473,10 @@ 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`;
// 用实际容器宽度(containerWidthNum, 随最大按钮自适应)做中心对齐,
// 按钮调大后容器变宽时仍与 Top 按钮保持中心对齐
const offset = this.layoutTopRight + this.layoutTopSize / 2 - this.containerWidthNum / 2;
return this.rpxStr(offset);
},
},
watch: {
@@ -420,9 +537,14 @@ export default {
}
}
},
// 页面生命周期: hover-nav 是常驻组件, 路由变化必须靠 onShow 通知,
// 否则 currentRoute 停留在首次加载页, 页面范围判定(fbVisible)会失效。
onShow() {
this.refreshRoute();
},
created() {
this.initLanguage();
this.pageCount = getCurrentPages().length;
this.refreshRoute();
// 三源兜底(store / 同步 storage / 异步 storage),
// 任何一个先就绪就先使用,后续由 initStatus watcher 再次同步
@@ -512,6 +634,23 @@ export default {
// 关键: 手动同步当前 themeColor(覆盖 watch immediate 失效的场景)
// 详见上面的注释。_applyThemeColor 内部已判 $el 存在性,所有平台都安全。
this._applyThemeColor(this.$store && this.$store.state && this.$store.state.themeColor);
// 公告栏避让: 测量视口 + 公告栏(diy-notice)位置, 把悬浮按钮放到其正下方
this.updateViewport();
this.measureNotice();
// 延迟复测: 页面 DIY 内容(含 diy-notice)可能晚于本组件挂载后才渲染
this._noticeTimers = [
setTimeout(() => this.measureNotice(), 300),
setTimeout(() => this.measureNotice(), 800),
];
// #ifdef H5
// 不再监听 scroll: containerBottom 已改用「文档坐标」(视口坐标 + 滚动距离)计算,
// 得到与滚动无关的恒定 bottom —— 按钮固定在"页面顶部时公告栏正下方",
// 滚动时按钮静止、公告栏自行滚走, 不再来回滑动。
// 仅监听 resize(旋转/尺寸变化), 让按钮在视口尺寸变化时重新避让一次。
this._scrollHandler = this._onScroll.bind(this);
window.addEventListener('resize', this._scrollHandler);
// #endif
},
beforeDestroy() {
// H5 Teleport 还原:把元素从 body 移回原父节点,避免内存泄漏
@@ -520,9 +659,163 @@ export default {
this._origParent.appendChild(this.$el);
this._origParent = null;
}
// 清理公告栏避让的滚动/缩放监听与定时器
if (this._scrollHandler) {
window.removeEventListener('scroll', this._scrollHandler);
window.removeEventListener('resize', this._scrollHandler);
this._scrollHandler = null;
}
if (this._noticeTimers) {
this._noticeTimers.forEach((t) => clearTimeout(t));
this._noticeTimers = null;
}
if (this._scrollRAF) {
cancelAnimationFrame(this._scrollRAF);
this._scrollRAF = null;
}
// #endif
},
methods: {
// ============================================================
// rpx 换算工具(内联样式单位跨端兼容的关键)
// ------------------------------------------------------------
// 问题: 动态 :style 绑定里的 rpx, 微信小程序原生支持,
// 但 vue2 uni-app 的 H5 端不做编译转换 —— 浏览器不认识 rpx,
// 整条内联声明被当作非法值忽略, 回落到旧 CSS(容器 100rpx),
// 这就是"小程序正常、H5 大按钮右侧被裁"的根因。
// 解决: H5 端所有内联尺寸一律用 upx2px 换算成 px 输出;
// 小程序端保持 rpx 原样输出。
// ============================================================
// #ifdef H5
rpxNum(n) {
const n2 = Number(n) || 0;
try {
const w = (typeof window !== 'undefined' && window.innerWidth) || 375;
return (n2 * w) / 750;
} catch (e) {
return n2 / 2; // window 异常时按 375px 视口兜底
}
},
rpxStr(n) {
return this.rpxNum(n) + 'px';
},
// #endif
// #ifndef H5
rpxNum(n) {
return Number(n) || 0;
},
rpxStr(n) {
return (Number(n) || 0) + 'rpx';
},
// #endif
// ============================================================
// 公告栏(diy-notice 跑马灯)实时测量: 让悬浮按钮避让到其正下方
// ------------------------------------------------------------
// 公告栏是页面流/固定底部的 DIY 组件(diy-notice), 高度与位置动态,
// 无法用固定常量避让。这里用 uni 选择器读取其视口坐标(px),
// containerBottom 据此把按钮放到公告栏底边之下。
// 滚动/缩放时公告栏视口坐标会变化, 故监听 scroll/resize 重新测量。
// ============================================================
// 更新视口尺寸(换算 rpx 用)
updateViewport() {
try {
if (typeof window !== 'undefined' && window.innerWidth) {
this.winW = window.innerWidth;
this.winH = window.innerHeight;
} else {
const info = uni.getSystemInfoSync();
this.winW = info.windowWidth || 375;
this.winH = info.windowHeight || 667;
}
} catch (e) {
this.winW = this.winW || 375;
this.winH = this.winH || 667;
}
},
// 测量 .diy-notice 的视口坐标(无公告栏时置空, 走基础定位)
measureNotice() {
try {
const q = uni.createSelectorQuery();
q.select('.diy-notice').boundingClientRect((rect) => {
if (rect && rect.height > 0) {
this.noticeRect = {
top: rect.top,
bottom: rect.bottom,
height: rect.height,
};
} else {
this.noticeRect = null; // 无公告栏 → 基础定位
}
}).exec();
} catch (e) {
this.noticeRect = null;
}
},
// #ifdef H5
// H5: 滚动/缩放用 rAF 节流重新测量, 让按钮始终跟随公告栏
_onScroll() {
if (this._scrollRAF) return;
this._scrollRAF = requestAnimationFrame(() => {
this._scrollRAF = null;
this.updateViewport();
this.measureNotice();
});
},
// #endif
// 读取逐按钮尺寸 token(rpx 数值):
// 优先 hover_nav_{type}_btn_size, 其次 hover_nav_{type}_size, 都未配置回退 72
// 数据源: store.state.themeStyle(响应式, 后台覆写 merge 后即生效)
// 兼容值格式: 97(数字) / '97rpx' / '97', 非法或 <=0 一律回退 72
btnSizeRpx(type) {
let theme = null;
try {
theme = (this.$store && this.$store.state) ? this.$store.state.themeStyle : null;
} catch (e) { theme = null; }
const keys = ['hover_nav_' + type + '_btn_size', 'hover_nav_' + type + '_size'];
if (theme && typeof theme === 'object') {
for (let i = 0; i < keys.length; i++) {
const raw = theme[keys[i]];
if (raw === undefined || raw === null || raw === '') continue;
const n = parseFloat(raw);
if (Number.isFinite(n) && n > 0) return n;
}
}
return 72;
},
// .btn-item 的 inline-style 锁定(按按钮类型取尺寸, 见 btnSizeRpx):
// inline-style 优先级高于 CSS class, 锁死尺寸 + 正圆, 防止被 flex 布局压缩成椭圆
btnItemStyle(type) {
const s = this.rpxStr(this.btnSizeRpx(type));
return {
width: s,
height: s,
'min-width': s,
'min-height': s,
'max-width': s,
'max-height': s,
// 内部图标(.iconfont/.icox)通过该变量跟随按钮尺寸:
// 图标盒子里原本锁死 72rpx, 按钮调大后图标仍 72rpx,
// 又因列 flex 横轴默认贴左 → 图标偏在按钮左上角
'--btn-size': s,
'aspect-ratio': '1',
// border-radius 保留作 clip-path 不支持时的 fallback
'border-radius': '50%',
'flex-shrink': '0',
'flex-grow': '0',
'align-self': 'center',
'box-sizing': 'border-box',
padding: '0',
margin: this.rpxStr(14) + ' 0',
overflow: 'hidden',
};
},
// 刷新当前路由与页面栈深度(供 fbVisible 的页面范围判定 / pageCount 老判定)
refreshRoute() {
this.currentRoute = getCurrentRoute();
this.pageCount = getCurrentPages().length;
},
// #ifdef H5
/**
* 从 :root 读取 CSS 变量(App.vue 中定义)到 data,
@@ -534,9 +827,13 @@ export default {
if (typeof document === 'undefined') return; // SSR/非浏览器环境兜底
const root = document.documentElement;
const computed = getComputedStyle(root);
// CSS 变量在 H5 编译后是 px;组件内部统一按 750 设计稿 rpx 值计算,
// 输出时再经 rpxStr() 换算回 px,避免 px/rpx 混算导致尺寸/位置错乱
const scale = ((typeof window !== 'undefined' && window.innerWidth) || 375) / 750;
const getNum = (name, fallback) => {
const v = parseFloat(computed.getPropertyValue(name));
return Number.isFinite(v) ? v : fallback;
if (!Number.isFinite(v) || scale <= 0) return fallback;
return v / scale; // px → 设计稿 rpx 值
};
this.layoutTopRight = getNum('--top-btn-right', 46);
this.layoutTopBottom = getNum('--top-btn-bottom', 272);
@@ -821,8 +1118,13 @@ export default {
* 保证容器的实际宽度与 JS 计算用到的宽度始终一致。 */
width: var(--floating-btn-width, 100rpx);
box-sizing: border-box;
transition: 0.3s;
overflow: hidden;
/* 去掉过渡动画: 切换页面重挂载时 bottom/width/right 变化会触发滑动,
* 造成"突然移动"的观感; 位置用缓存保证恒定, 无需动画 */
/* 关键: 不裁剪子元素。按钮尺寸由后台 token 任意调节(hover_nav_*_btn_size 可远超容器宽度),
* 且 rpx→px 取整存在亚像素误差, overflow:hidden 会把按钮右侧/四角切掉一条(变形元凶)。
* 按钮自身已有 border-radius:50% + overflow:hidden 自裁剪, 背景图圆角由本元素
* border-radius 保证(背景不受 overflow 影响), 故这里必须放开为 visible。 */
overflow: visible;
/* 与 to-top.vue 的 .mescroll-totop 一致,适配 iPhoneX 等安全区 */
margin-bottom: var(--window-bottom);
}
@@ -830,6 +1132,9 @@ export default {
.btn-item {
display: flex;
justify-content: center;
/* 横向居中: 列布局下横轴是 align-items, 固定宽度的子元素
* (如锁死尺寸的 .iconfont 图标盒)默认贴左, 必须显式居中 */
align-items: center;
text-align: center;
flex-direction: column;
line-height: 1;
@@ -864,22 +1169,42 @@ export default {
background-color: var(--hover-nav-bg-color);
}
/* 逐按钮背景/文字颜色覆写(与后台 9 个 key 对应, 未配置时回退全局 --hover-nav-*):
* hover_nav_lang_bg_color / hover_nav_lang_text_color → --hover-nav-lang-bg-color / --hover-nav-lang-text-color
* hover_nav_kefu_bg_color / hover_nav_kefu_text_color → --hover-nav-kefu-bg-color / --hover-nav-kefu-text-color
* hover_nav_phone_bg_color / hover_nav_phone_text_color → --hover-nav-phone-bg-color / --hover-nav-phone-text-color
* 文字色经 .btn-item 的 color 继承给内部 text/图标(.lang-btn-text 为 color: inherit) */
.btn-lang {
background-color: var(--hover-nav-lang-bg-color, var(--hover-nav-bg-color));
color: var(--hover-nav-lang-text-color, var(--hover-nav-text-color));
}
.btn-kefu {
background-color: var(--hover-nav-kefu-bg-color, var(--hover-nav-bg-color));
color: var(--hover-nav-kefu-text-color, var(--hover-nav-text-color));
}
.btn-phone {
background-color: var(--hover-nav-phone-bg-color, var(--hover-nav-bg-color));
color: var(--hover-nav-phone-text-color, var(--hover-nav-text-color));
}
.btn-item text {
font-size: 28rpx;
/* 悬浮按钮内文字/图标字号(后台 hover_nav_font_size 可调, 默认与图标 36rpx 对齐) */
font-size: var(--hover-nav-font-size, 36rpx);
}
.iconfont,
.icox {
font-size: 36rpx;
/* 悬浮按钮内图标字号(后台 hover_nav_font_size 可调) */
font-size: var(--hover-nav-font-size, 36rpx);
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
/* 不再设 width: 100% / height: 100% 再覆盖为 72rpx 的写法,
* 微信小程序/H5 对 width: 100% 在 flex 列布局里的高度计算有差异,
* 直接固定 72x72 更稳。 */
width: 72rpx;
height: 72rpx;
/* 尺寸跟随所在按钮: 按钮内联样式写入 --btn-size(=按钮实际尺寸),
* 图标盒不再锁死 72rpx —— 否则按钮调大后图标偏小且贴左上。
* 72rpx 兜底 = 按钮未走 btnItemStyle 内联样式时的默认尺寸。 */
width: var(--btn-size, 72rpx);
height: var(--btn-size, 72rpx);
margin: 0;
border-radius: 50%;
padding: 0;
@@ -897,9 +1222,17 @@ export default {
0 -1rpx 0 rgba(0, 0, 0, 0.18);
}
/* 逐按钮字号覆写: 后台 hover_nav_phone/kefu_font_size 可调, 未设时回退全局 --hover-nav-font-size */
.iconfont.icon-dianhua {
font-size: var(--hover-nav-phone-font-size, var(--hover-nav-font-size, 36rpx));
}
.icox.icox-kefu {
font-size: var(--hover-nav-kefu-font-size, var(--hover-nav-font-size, 36rpx));
}
.iconfont text,
.icox text {
font-size: 36rpx;
font-size: var(--hover-nav-font-size, 36rpx);
font-weight: bold;
}
@@ -911,7 +1244,8 @@ export default {
}
.ai-icon {
font-size: 40rpx;
/* emoji 客服图标: 基准字号用 hover_nav_kefu_font_size(回退全局), 再 ×1.11(原 40/36) */
font-size: calc(var(--hover-nav-kefu-font-size, var(--hover-nav-font-size, 36rpx)) * 1.11);
width: 100%;
height: 100%;
display: flex;
@@ -930,7 +1264,8 @@ export default {
justify-content: center;
width: 100%;
height: 100%;
font-size: 24rpx;
/* 语言短码文字: 基准字号用 hover_nav_lang_font_size(回退全局 hover_nav_font_size), 文字实际按 0.667 缩放 */
font-size: calc(var(--hover-nav-lang-font-size, var(--hover-nav-font-size, 36rpx)) * 0.667);
line-height: 1;
font-weight: 600;
letter-spacing: 0;

View File

@@ -0,0 +1,247 @@
<template>
<!--
自绘导航栏:把原生导航栏左侧的 "<" 换成 "‹ 返回" 文字
背景:微信小程序原生导航栏的返回按钮是客户端系统控件,pages.json 的任何配置、
官方 <navigation-bar> 组件(只支持 title / front-color / background-color / loading)
都无法修改它的内容。要显示"返回"二字,只能关闭原生栏后自绘。
使用前提:
1. 该页面在 pages.json 中开启 "navigationStyle": "custom"(组件只负责渲染,不自动改配置)
2. 该页面不能是 web-view 页面 —— 官方明确 "navigationStyle: custom 对 web-view 组件无效",
且 web-view 会铺满整页覆盖其他组件,自绘的导航栏不会显示
布局:组件是普通流式节点(非 fixed),放在页面顶部即可把内容自然下推。
-->
<view
v-if="visible"
class="ns-mp-navbar"
:class="{ 'is-fixed': fixed }"
:style="{ background: bgColor, paddingTop: statusBarHeight + 'px' }"
>
<view class="ns-mp-navbar__inner" :style="{ height: navBarHeight + 'px' }">
<view class="ns-mp-navbar__side">
<view
v-if="showBack && canBack"
class="ns-mp-navbar__back"
hover-class="ns-mp-navbar__back--hover"
hover-stay-time="80"
@tap="onBack"
>
<text class="iconfont icon-back_light ns-mp-navbar__arrow" :style="{ color }"></text>
<text class="ns-mp-navbar__text" :style="{ color }">{{ backText }}</text>
</view>
<slot name="left"></slot>
</view>
<view class="ns-mp-navbar__title" :style="{ color }">{{ title }}</view>
<view class="ns-mp-navbar__side ns-mp-navbar__side--right">
<slot name="right"></slot>
</view>
</view>
</view>
</template>
<script>
// 状态栏 / 胶囊信息:用于算出与原生导航栏一致的布局高度
let systemInfo = {};
let menuButtonInfo = { top: 0, height: 32, right: 0, width: 0 };
try {
systemInfo = uni.getSystemInfoSync() || {};
} catch (e) {
systemInfo = {};
}
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ || MP-HARMONY
try {
menuButtonInfo = uni.getMenuButtonBoundingClientRect() || menuButtonInfo;
} catch (e) {}
// #endif
export default {
name: 'ns-mp-navbar',
props: {
// 中间标题
title: {
type: String,
default: ''
},
// 导航栏背景色
bgColor: {
type: String,
default: '#ffffff'
},
// 文字 / 图标颜色
color: {
type: String,
default: '#000000'
},
// 返回按钮文字(原生导航栏只能显示 "<",这里可自定义)
backText: {
type: String,
default: '返回'
},
// 是否显示返回按钮
showBack: {
type: Boolean,
default: true
},
// 是否悬浮在页面之上(沉浸式页面用;false 时占文档流,会把内容往下推)
fixed: {
type: Boolean,
default: false
},
// 无页面栈时(如分享直接进入)跳转的首页地址
homePath: {
type: String,
default: '/pages/index/index'
},
// 自定义返回逻辑
customBack: {
type: Function,
default: null
},
// H5 端是否渲染(H5 由 uni-app 自带头像栏,默认不渲染,避免双导航栏)
showOnH5: {
type: Boolean,
default: false
}
},
data() {
return {
statusBarHeight: systemInfo.statusBarHeight || 20,
navBarHeight: 44,
visible: true,
// 页面栈里是否还有上级页面(无上级页面时原生导航栏也不显示返回键)
canBack: true
};
},
computed: {
// 导航栏总高度(状态栏 + 内容区),页面如需自行占位可取该值
navbarHeight() {
return this.statusBarHeight + this.navBarHeight;
}
},
created() {
// 导航栏内容区高度:MP 端按胶囊位置推算,与原生导航栏保持一致;其余端用 44
// #ifdef MP
const statusBarHeight = this.statusBarHeight;
const h = (menuButtonInfo.top - statusBarHeight) * 2 + menuButtonInfo.height;
// 兜底:胶囊信息异常时退回 44
this.navBarHeight = h > 0 ? h : 44;
// #endif
// #ifdef H5
this.visible = this.showOnH5;
// #endif
},
mounted() {
// 页面栈只有一页(分享/扫码直达)时,原生导航栏也无返回键,这里保持一致
const pages = (typeof getCurrentPages === 'function' && getCurrentPages()) || [];
this.canBack = pages.length > 1;
// 把实际总高度抛给页面,便于页面修正内容区高度,避免多出一屏空白
this.$emit('ready', this.statusBarHeight + this.navBarHeight);
},
methods: {
onBack() {
if (typeof this.customBack === 'function') {
this.customBack();
return;
}
const pages = (typeof getCurrentPages === 'function' && getCurrentPages()) || [];
if (pages.length > 1) {
uni.navigateBack();
return;
}
// 顶层页面(分享 / 扫码直接进入):回首页
uni.switchTab({
url: this.homePath,
fail: () => {
uni.reLaunch({ url: this.homePath });
}
});
}
}
};
</script>
<style scoped lang="scss">
.ns-mp-navbar {
width: 100%;
box-sizing: border-box;
}
.ns-mp-navbar.is-fixed {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 990;
}
.ns-mp-navbar__inner {
position: relative;
display: flex;
align-items: center;
width: 100%;
box-sizing: border-box;
}
.ns-mp-navbar__side {
position: relative;
z-index: 1;
display: flex;
align-items: center;
height: 100%;
min-width: 160rpx;
padding-left: 20rpx;
box-sizing: border-box;
}
.ns-mp-navbar__side--right {
justify-content: flex-end;
padding-left: 0;
padding-right: 20rpx;
}
.ns-mp-navbar__back {
display: flex;
align-items: center;
padding: 10rpx 20rpx 10rpx 0;
}
.ns-mp-navbar__back--hover {
opacity: 0.5;
}
.ns-mp-navbar__arrow {
font-size: 34rpx;
line-height: 1;
}
.ns-mp-navbar__text {
margin-left: 2rpx;
font-size: 30rpx;
line-height: 1;
}
.ns-mp-navbar__title {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
padding: 0 160rpx;
font-size: 32rpx;
line-height: 1.2;
text-align: center;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>

View File

@@ -567,6 +567,12 @@ 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

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

View File

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

View File

@@ -2499,6 +2499,12 @@
}
}
},
{
"path": "files/detail",
"style": {
"navigationBarTitleText": "文件详情"
}
},
{
"path": "file-preview/file-preview",
"style": {

View File

@@ -53,7 +53,7 @@
<ns-copyright v-show="isShowCopyRight" />
</view>
<template v-if="adv.advshow != -1">
<template v-if="adv && adv.advshow != -1">
<view @touchmove.prevent.stop>
<uni-popup ref="uniPopupWindow" type="center" class="wap-floating" :maskClick="false">
<view class="small-bot">

View File

@@ -61,7 +61,8 @@
:key="getMessageKey(message, index)"
:id="getMessageKey(message, index)"
class="message-item"
:class="[message.role, { 'first-message': index === 0, 'search-current': showSearchBar && searchResultFilteredIndex === index, 'search-flash': showSearchBar && searchFlashAnimatingIndex === index }]">
:class="[message.role, { 'first-message': index === 0, 'is-welcome': message.isWelcome, 'search-current': showSearchBar && searchResultFilteredIndex === index, 'search-flash': showSearchBar && searchFlashAnimatingIndex === index }]"
v-if="!(message.isWelcome && (inputFocused || hasUserMessage))">
<!-- 用户消息 (WorkBuddy 风格: 右对齐 + 浅灰气泡 + 头像在右) -->
<view v-if="message.role === 'user'" class="user-message">
@@ -223,8 +224,8 @@
</view>
</view>
<!-- AI 回答上方只显示时间(昵称"智能助手"已按需求移除) -->
<view class="message-nickname ai-nickname" v-if="chatUiConfig.ui_show_message_time">
<!-- AI 回答上方只显示时间(昵称"智能助手"已按需求移除);欢迎语消息不显示时间 -->
<view class="message-nickname ai-nickname" v-if="chatUiConfig.ui_show_message_time && !message.isWelcome">
<text class="message-time">{{ formatTime(message.timestamp) }}</text>
</view>
<view class="message-bubble">
@@ -233,10 +234,10 @@
<!-- #ifdef MP-WEIXIN -->
<!-- PR-CHAT-SELECTABLE (2026-09-23): rich-text 不支持文本选中, 改用 mp-html + selectable
开启原生长按选中(剪切/复制/粘贴/全选); force 同时兼容微信 iOS -->
<mp-html class="ai-message-rich" :content="getAIDisplayContent(message.content)" selectable="force" />
<mp-html class="ai-message-rich" :content="getAIDisplayContent(message.content, message.isWelcome)" selectable="force" />
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="ai-message-text selectable-md" v-html="getAIDisplayContent(message.content)"></view>
<view class="ai-message-text selectable-md" v-html="getAIDisplayContent(message.content, message.isWelcome)"></view>
<!-- #endif -->
</view>
@@ -249,10 +250,10 @@
<view class="markdown-body">
<!-- #ifdef MP-WEIXIN -->
<!-- PR-CHAT-SELECTABLE (2026-09-23): 同上, mp-html + selectable 支持长按选中复制 -->
<mp-html class="ai-message-rich" :content="getAIDisplayContent(message.content)" selectable="force" />
<mp-html class="ai-message-rich" :content="getAIDisplayContent(message.content, message.isWelcome)" selectable="force" />
<!-- #endif -->
<!-- #ifdef H5 -->
<view class="selectable-md" v-html="getAIDisplayContent(message.content)"></view>
<view class="selectable-md" v-html="getAIDisplayContent(message.content, message.isWelcome)"></view>
<!-- #endif -->
</view>
</view>
@@ -377,14 +378,17 @@
<!-- PR-WELCOME-QUICK-CHIPS (2026-09-19): 欢迎语配套快捷问题
欢迎语气泡下方显示快捷问题 chips, 点击直接作为用户消息发送
一次性,点了之后从 message 上摘除 (避免重复点) -->
<view v-if="message.quickQuestions && message.quickQuestions.length > 0" class="quick-questions-row">
<view v-if="message.quickQuestions && message.quickQuestions.length > 0 && !inputFocused" class="quick-questions-row">
<view
v-for="(q, qi) in message.quickQuestions"
:key="qi"
class="quick-question-chip"
hover-class="quick-question-chip--hover"
@click="onQuickQuestionClick(message, q)">
<text class="quick-question-icon">💬</text>
<view
class="quick-question-icon"
:style="{ backgroundImage: 'url(' + quickQuestionIconList[(qi + (message._qqBatchIndex || 0) * 4) % quickQuestionIconList.length] + ')' }">
</view>
<text class="quick-question-text">{{ getQuickQuestionText(q) }}</text>
</view>
</view>
@@ -440,20 +444,27 @@
<!-- AI 消息下方操作栏: 复制 / 点赞 / 不喜欢 / 更多 -->
<!-- PR-CHAT-UI-CONFIG (2026-09-20): 后端可关闭 ui_enable_feedback (隐藏点赞/点踩/更多), 默认 true -->
<!-- PR-AI-ACTIONS-AFTER-DONE (2026-09-28): 仅在 AI 完全回答完成后才显示操作栏 (排除流式中), 避免一边打字一边出现复制/点赞按钮的"半成品"感 -->
<view class="ai-actions" v-if="message.role === 'ai' && message.type !== 'loading' && !message.isStreaming && chatUiConfig.ui_enable_feedback">
<view class="ai-action-btn" @click="onAiActionCopy(message)">
<text class="iconfont icon-copy">⎘</text>
</view>
<view class="ai-action-btn" :class="{ active: message._liked }" @click="onAiActionLike(message)">
<!-- PR-FRONTEND-ACTION-SVG-ICON (2026-09-18): 点赞/点踩改用线性 SVG 矢量图, 不再用彩色 emoji -->
<view class="svg-icon icon-like"></view>
</view>
<view class="ai-action-btn" :class="{ active: message._disliked }" @click="onAiActionDislike(message)">
<view class="svg-icon icon-dislike"></view>
</view>
<view class="ai-action-btn more-btn" @click="onAiActionMore(message)">
<text class="iconfont icon-more">···</text>
<view class="ai-actions" v-if="message.role === 'ai' && message.type !== 'loading' && !message.isStreaming && (chatUiConfig.ui_enable_feedback || message.isWelcome)">
<!-- 欢迎语下方操作栏: 换成"换一换" -->
<view v-if="message.isWelcome" class="ai-action-btn refresh-welcome-btn" @click="onAiActionRefreshWelcome(message)">
<view class="refresh-icon"></view>
<text class="refresh-text">换一换</text>
</view>
<template v-else>
<view class="ai-action-btn" @click="onAiActionCopy(message)">
<text class="iconfont icon-copy">⎘</text>
</view>
<view class="ai-action-btn" :class="{ active: message._liked }" @click="onAiActionLike(message)">
<!-- PR-FRONTEND-ACTION-SVG-ICON (2026-09-18): 点赞/点踩改用线性 SVG 矢量图, 不再用彩色 emoji -->
<view class="svg-icon icon-like"></view>
</view>
<view class="ai-action-btn" :class="{ active: message._disliked }" @click="onAiActionDislike(message)">
<view class="svg-icon icon-dislike"></view>
</view>
<view class="ai-action-btn more-btn" @click="onAiActionMore(message)">
<text class="iconfont icon-more">···</text>
</view>
</template>
</view>
</view>
@@ -518,17 +529,29 @@
① 默认(未输入/未聚焦): 单行胶囊 —— 语音图标 + 输入框 + 加号
② 语音模式(点语音图标进入): 「按住说话」按钮 + 底部工具栏(表情/模型/加号)
③ 文字输入(聚焦或有文字): 输入框独占一行 + 底部工具栏(语音/模型/加号/发送) -->
<!-- 语音模式: 按住说话 (PR-FRONTEND-VOICE-INPUT 2026-09-24) -->
<!-- 语音模式 (PR-VOICE-MODE-ONE-ROW-V2): 整行即白色胶囊(flex),
键盘图标在左、+ 在右、按住说话占中间 —— 不依赖绝对定位, 结构上保证单行 -->
<view
v-if="voiceMode"
class="voice-hold-btn"
:class="{ 'is-holding': voiceHolding, 'is-cancelling': voiceHoldCancelling }"
@touchstart.stop.prevent="onVoiceHoldStart"
@touchmove.stop.prevent="onVoiceHoldMove"
@touchend.stop.prevent="onVoiceHoldEnd"
@touchcancel.stop.prevent="onVoiceHoldCancel"
@click.stop="onVoiceHoldEnd">
<text class="voice-hold-text">{{ voiceHoldText }}</text>
class="voice-mode-row"
:class="{ 'is-holding': voiceHolding, 'is-cancelling': voiceHoldCancelling, 'hidden-row': !voiceMode }">
<!-- 左侧: 键盘图标 (点击回到文字输入) -->
<view class="voice-side-btn voice-side-left" @click="exitVoiceMode">
<view class="emoji-icon-bg"></view>
</view>
<!-- 中间: 按住说话 (按住录音, 松开发送) -->
<view
class="voice-hold-btn"
@touchstart.stop.prevent="onVoiceHoldStart"
@touchmove.stop.prevent="onVoiceHoldMove"
@touchend.stop.prevent="onVoiceHoldEnd"
@touchcancel.stop.prevent="onVoiceHoldCancel"
@click.stop="onVoiceHoldEnd">
<text class="voice-hold-text">{{ voiceHoldText }}</text>
</view>
<!-- 右侧: 加号 -->
<button class="top-plus-btn voice-side-right" @click="showMoreTools">
<text class="plus-icon">+</text>
</button>
</view>
<!-- 按住时的「上滑取消」提示 (H5/MP 共用) -->
<view v-if="voiceHolding" class="voice-cancel-hint">{{ voiceHoldCancelling ? $lang('ai-chat.index.slideUpToCancelHint') : $lang('ai-chat.index.slideUpToCancel') }}</view>
@@ -537,7 +560,7 @@
Vue 2 要求 v-if/v-else 紧邻, 否则 v-else 会错配到上一个 v-if (voiceHolding),
导致 voiceMode=true 时 input-row-top 也被显示.
改成显式 v-if="!voiceMode", 避免依赖 v-else 的隐式配对 -->
<view v-if="!voiceMode" class="input-row-top">
<view class="input-row-top" :class="{ 'hidden-row': voiceMode }">
<!-- 默认态左侧: 点击进入语音(按住说话)模式 -->
<!-- PR-FRONTEND-H5-INPUT-FOCUS (2026-09-17): 兄弟节点加 key, 防止 H5 下 Vue 无 key 复用
同标签 view 导致 textarea 被销毁重建、聚焦即失焦(塌回胶囊无法输入) -->
@@ -576,14 +599,10 @@
</view>
</view>
<!-- 底部工具栏行: 语音模式 / 文字输入时显示 -->
<view v-if="voiceMode || showTextMode" class="input-toolbar-row">
<!-- 语音模式: 键盘图标 (点击回到文字输入) -->
<view v-if="voiceMode" class="toolbar-round-btn" @click="exitVoiceMode">
<view class="emoji-icon-bg"></view>
</view>
<!-- 底部工具栏行: 仅文字输入时显示 (语音模式的键盘/加号已并入按住说话同一行) -->
<view v-if="showTextMode" class="input-toolbar-row">
<!-- 文字输入: 语音图标 (切到按住说话) -->
<view v-else class="toolbar-round-btn" @click="enterVoiceMode">
<view class="toolbar-round-btn" @click="enterVoiceMode">
<view class="voice-icon-bg"></view>
</view>
@@ -835,6 +854,17 @@ export default {
_voiceHoldStartY: 0,
_voiceHoldLastLevel: 0,
voiceLevel: 0,
// PR-WELCOME-QUICK-ICONS: 快捷问题前面的随机图标库 (base64 SVG)
quickQuestionIconList: [
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48Y2lyY2xlIGN4PSIxMSIgY3k9IjExIiByPSI3Ii8+PHBhdGggZD0iTTIxIDIxbC00LjM1LTQuMzUiLz48L3N2Zz4=',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNNCA0aDE2djE2SDR6Ii8+PHBhdGggZD0iTTggOWg4TTggMTNoOE04IDE3aDUiLz48L3N2Zz4=',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMyAzdjE4aDE4Ii8+PHBhdGggZD0iTTcgMTZsNC00IDMgMyA1LTYiLz48L3N2Zz4=',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMTYgMThsNi02LTYtNk04IDZsLTYgNiA2IDYiLz48L3N2Zz4=',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMTQuNyA2LjNhMSAxIDAgMCAwIDAgMS40bDEuNiAxLjZhMSAxIDAgMCAwIDEuNCAwbDMuNzctMy43N2E2IDYgMCAwIDEtNy45NCA3Ljk0bC02LjkxIDYuOTFhMi4xMiAyLjEyIDAgMCAxLTMtM2w2LjkxLTYuOTFhNiA2IDAgMCAxIDcuOTQtNy45NGwtMy43NiAzLjc2eiIvPjwvc3ZnPg==',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cG9seWdvbiBwb2ludHM9IjEyIDIgMTUuMDkgOC4yNiAyMiA5LjI3IDE3IDE0LjE0IDE4LjE4IDIxLjAyIDEyIDE3Ljc3IDUuODIgMjEuMDIgNyAxNC4xNCAyIDkuMjcgOC45MSA4LjI2IDEyIDIiLz48L3N2Zz4=',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48Y2lyY2xlIGN4PSIxMiIgY3k9IjEyIiByPSIxMCIvPjxwYXRoIGQ9Ik0yIDEyaDIwIi8+PHBhdGggZD0iTTEyIDJhMTUuMyAxNS4zIDAgMCAxIDQgMTAgMTUuMyAxNS4zIDAgMCAxLTQgMTAgMTUuMyAxNS4zIDAgMCAxLTQtMTAgMTUuMyAxNS4zIDAgMCAxIDQtMTB6Ii8+PC9zdmc+',
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNOSAxOGg2Ii8+PHBhdGggZD0iTTEwIDIyaDQiLz48cGF0aCBkPSJNMTIgMmE3IDcgMCAwIDAtNyA3YzAgMi41IDEuNSA0LjUgMyA2djJoOHYtMmMxLjUtMS41IDMtMy41IDMtNmE3IDcgMCAwIDAtNy03eiIvPjwvc3ZnPg=='
],
// 失焦定时器: 用于延迟收起文字输入态, 避免 H5 布局变化触发的瞬时 blur 误收起
_blurTimer: null,
// 平台相关: H5 让浏览器自动把输入框顶起(adjust-position=true), 小程序用键盘垫高自行处理
@@ -982,6 +1012,10 @@ export default {
hasInputText() {
return this.inputText && this.inputText.trim() !== ''
},
// PR-WELCOME-HIDE-AFTER-SEND: 一旦用户发送过消息, 欢迎语消息就不再显示
hasUserMessage() {
return this.messages.some(m => m.role === 'user' && m.content && m.content.trim() !== '')
},
// PR-FRONTEND-INPUT-3STATES (2026-09-17): 文字输入态
// 聚焦 或 已有文字时展开为"输入框一行 + 工具栏一行", 否则回到单行胶囊。
// 用聚焦(而不是只判断文字)是为了: 删除最后一个字时布局不会突然塌回胶囊。
@@ -1717,9 +1751,9 @@ export default {
// 等路径再触发会造成欢迎气泡重复 push; 网络慢时尤其容易)
if (this._welcomeLoading) return
this._welcomeLoading = true
// 仅全新会话才需要欢迎语
if (this.currentConversationId) {
console.log('[AI Chat] 已有会话,跳过欢迎语')
// 只要当前没有消息(或历史为空)就展示欢迎语;已有消息/历史时会话 ID 不影响
if (this.messages.length > 0) {
console.log('[AI Chat] 已有消息,跳过欢迎语')
this._welcomeLoading = false
return
}
@@ -1767,8 +1801,10 @@ export default {
}
}
// 3. 插入欢迎语(再次检查是否仍是全新会话)
if (!this.currentConversationId && this.messages.length === 0) {
// 3. 插入欢迎语:只要当前消息列表仍为空就展示(兼容真机残留会话 ID 但无历史消息)
if (this.messages.length === 0) {
// PR-WELCOME-QUICK-BATCH: 所有快捷问题先存起来, 前端每 4 个一批轮播
const allQuickQuestions = this.normalizeQuickQuestions(welcomeInfo && welcomeInfo.quick_questions)
const welcomeMsg = {
id: ++this.messageId,
role: 'ai',
@@ -1779,7 +1815,12 @@ export default {
// PR-WELCOME-QUICK-CHIPS (2026-09-19): 欢迎语配套快捷问题 (chips)
// 后端可存 string[] 或 {id,text}[] ,前端统一归一化为 string[]
// message.quickQuestions 数组非空 → 模板渲染 chips;点击调 onQuickQuestionClick
quickQuestions: this.normalizeQuickQuestions(welcomeInfo && welcomeInfo.quick_questions)
// PR-WELCOME-QUICK-BATCH: 每 4 个一批展示, 点击换一换循环切换
quickQuestions: (allQuickQuestions || []).slice(0, 4),
allQuickQuestions: allQuickQuestions || [],
_qqBatchIndex: 0,
// PR-WELCOME-HIDE-AFTER-SEND: 标记这是欢迎语消息, 发送第一条用户消息后永久隐藏
isWelcome: true
}
this.messages.push(welcomeMsg)
this.$nextTick(() => this.scrollToBottom())
@@ -2797,6 +2838,9 @@ async onNewChat() {
}
}
this.clearMessages()
// 新对话后重新加载欢迎语
this._welcomeLoading = false
this._loadWelcomeMessage()
uni.showToast({ title: '已开始新对话', icon: 'success' })
},
@@ -2928,6 +2972,65 @@ _handleStreamError(msg) {
const BQ_MARGIN = COMPACT ? '6rpx 0' : '8rpx 0'
const BQ_LH = COMPACT ? '1.6' : '1.7'
// ===== HTML 白名单还原 (对齐后台预览 markedParse 的 WC_ALLOWED_TAGS / WC_ALLOWED_STYLE) =====
// 后台预览支持受限 HTML(染色/排版), 终端此前无条件转义所有 < >, 商家配置的
// <span style="..."> 在终端显示成字面文本。策略: 转义 → 识别白名单 → 只还原白名单。
// - 标签/属性/CSS 属性三张白名单, 其余(含 on* 事件、position、url())一律丢弃
// - 非白名单标签保持转义态, 照常显示为字面文本
const WC_TAGS = ['span', 'div', 'b', 'i', 'u', 's', 'em', 'strong', 'mark', 'small', 'sub', 'sup', 'br', 'hr', 'p', 'blockquote', 'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'th', 'td', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'pre', 'code']
const WC_VOID = { br: true, hr: true } // 自闭合标签, 还原时不带结束标签
const WC_STYLES = {
color: 1, 'background-color': 1, background: 1,
'font-size': 1, 'font-weight': 1, 'font-style': 1, 'font-family': 1,
'text-align': 1, 'text-decoration': 1, 'text-indent': 1, 'text-transform': 1,
'line-height': 1, 'letter-spacing': 1, 'vertical-align': 1, 'white-space': 1,
'list-style-type': 1, 'word-break': 1, 'word-wrap': 1,
margin: 1, 'margin-top': 1, 'margin-bottom': 1, 'margin-left': 1, 'margin-right': 1,
padding: 1, 'padding-top': 1, 'padding-bottom': 1, 'padding-left': 1, 'padding-right': 1,
'border-color': 1, 'border-style': 1, 'border-width': 1, 'border-radius': 1,
width: 1, height: 1, 'min-width': 1, 'max-width': 1,
display: 1, opacity: 1, 'text-shadow': 1
}
const WC_STYLE_BAD = /expression\s*\(|javascript:|vbscript:|behavior\s*:|-moz-binding|@import|url\s*\(/i
const wcFilterStyle = (s) => {
return s.split(';').map((p) => {
const i = p.indexOf(':')
if (i === -1) return ''
const prop = p.slice(0, i).trim().toLowerCase()
const val = p.slice(i + 1).trim()
// 值里不允许引号; 命中黑名单(expression/javascript/url( 等)整条丢弃
if (!WC_STYLES[prop] || WC_STYLE_BAD.test(val) || val.indexOf('"') !== -1) return ''
return prop + ': ' + val
}).filter(Boolean).join('; ')
}
const wcRestoreHtml = (escaped) => {
// 转义后标签形如 &lt;span style="..."&gt;, 引号未被转义仍是字面 "
return escaped.replace(/&lt;(\/?)([a-zA-Z0-9]+)([\s\S]*?)&gt;/g, (m, slash, rawTag, attrs) => {
const tag = rawTag.toLowerCase()
if (WC_TAGS.indexOf(tag) === -1) return m // 非白名单: 保持转义, 显示为字面文本
if (slash) return WC_VOID[tag] ? '' : '</' + tag + '>'
if (WC_VOID[tag]) return '<' + tag + '>'
const kept = []
const attrRe = /([a-zA-Z-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g
let am
while ((am = attrRe.exec(attrs)) !== null) {
const name = am[1].toLowerCase()
const val = am[2] !== undefined ? am[2] : am[3]
if (name === 'style') {
const fs = wcFilterStyle(val)
if (fs) kept.push('style="' + fs + '"')
} else if (name === 'href' || name === 'src') {
// 协议白名单: 挡 javascript:/vbscript:/data: 等
if (/^(https?:|mailto:|tel:|\/|#)/i.test(val)) kept.push(name + '="' + val + '"')
} else if (name === 'alt' || name === 'title' || name === 'colspan' || name === 'rowspan') {
kept.push(name + '="' + val + '"')
}
// 其余属性(含 on* 事件)一律丢弃
}
return '<' + tag + (kept.length ? ' ' + kept.join(' ') : '') + '>'
})
}
// 辅助:内联格式处理
// 思路: 先把"链接/图片/裸URL/电话"整体抽成占位符保护起来, 再做加粗/斜体等,
// 最后还原, 避免各规则互相串改对方的 href / 数字。
@@ -2967,7 +3070,7 @@ _handleStreamError(msg) {
// 之前行内代码是粉色(#d63384)、删除线是灰色(#999), 回答里颜色太杂。
t = t
.replace(/`([^`]+)`/g, '<code style="background:#f2f3f5;padding:2rpx 10rpx;border-radius:6rpx;font-size:24rpx;font-family:monospace;color:' + TEXT + ';">$1</code>')
.replace(/\*\*(.+?)\*\*/g, '<strong style="font-weight:700;color:' + TEXT + ';">$1</strong>')
.replace(/\*\*(.+?)\*\*/g, '<span style="color:' + TEXT + ';">$1</span>')
.replace(/\*(.+?)\*/g, '<em style="font-style:italic;color:' + TEXT + ';">$1</em>')
.replace(/~~(.+?)~~/g, '<del style="text-decoration:line-through;color:' + TEXT + ';">$1</del>')
@@ -2992,6 +3095,9 @@ _handleStreamError(msg) {
return `%%CODEBLOCK_${idx}%%`
})
// 2.5 还原白名单内 HTML (放在代码块抽离之后: 代码块里的示例 HTML 保持字面文本)
html = wcRestoreHtml(html)
// 3. 按行处理,用 <br> 连接单换行,双换行分割段落块
const lines = html.split('\n')
const out = []
@@ -3018,7 +3124,7 @@ _handleStreamError(msg) {
const flushTable = () => {
if (!inTable || tableRows.length === 0) return
const thead = tableRows[0].map(c =>
`<th style="padding:8rpx 12rpx;border:1rpx solid #eaecef;font-weight:600;background:#f6f8fa;text-align:left;font-size:24rpx;color:${TEXT};">${parseInline(c)}</th>`
`<th style="padding:8rpx 12rpx;border:1rpx solid #eaecef;font-weight:400;background:#f6f8fa;text-align:left;font-size:24rpx;color:${TEXT};">${parseInline(c)}</th>`
).join('')
const tbody = tableRows.slice(1).map(row =>
'<tr>' + row.map(c =>
@@ -3066,7 +3172,7 @@ _handleStreamError(msg) {
flushBuf(); out.push(closeList())
const lv = hMatch[1].length
const size = ['', '36rpx', '32rpx', '30rpx', '28rpx', '26rpx', '24rpx'][lv]
const wgt = ['', '700', '700', '600', '600', '500', '500'][lv]
const wgt = ['', '400', '400', '400', '400', '400', '400'][lv]
const mg = COMPACT ? ['', '14rpx 0 7rpx', '12rpx 0 6rpx', '10rpx 0 5rpx', '8rpx 0 5rpx', '7rpx 0 3rpx', '6rpx 0 3rpx'][lv] : ['', '20rpx 0 10rpx', '16rpx 0 8rpx', '14rpx 0 6rpx', '12rpx 0 6rpx', '10rpx 0 4rpx', '8rpx 0 4rpx'][lv]
out.push(`<h${lv} style="font-size:${size};font-weight:${wgt};margin:${mg};line-height:1.35;color:${TEXT};">${parseInline(hMatch[2])}</h${lv}>`)
continue
@@ -3752,6 +3858,26 @@ _handleStreamError(msg) {
} catch (e) { /* noop */ }
},
// 欢迎语"换一换": 快捷问题每 4 个一批, 点击后切换到下一批, 末尾循环回第一批
onAiActionRefreshWelcome(message) {
try {
const all = message.allQuickQuestions || []
if (!all.length) {
uni.showToast({ title: '暂无更多问题', icon: 'none' })
return
}
const batchSize = 4
const total = all.length
const batchCount = Math.ceil(total / batchSize) || 1
const current = message._qqBatchIndex || 0
const next = (current + 1) % batchCount
const start = next * batchSize
const end = Math.min(start + batchSize, total)
this.$set(message, '_qqBatchIndex', next)
this.$set(message, 'quickQuestions', all.slice(start, end))
} catch (e) { /* noop */ }
},
// 去掉 markdown 标记, 用于 TTS 朗读
_stripMarkdown(text) {
if (!text) return ''
@@ -3872,17 +3998,30 @@ _handleStreamError(msg) {
},
// AI 消息渲染(含关键词高亮)
getAIDisplayContent(content) {
// isWelcome: 欢迎语消息 — 小程序端 mp-html 组件有样式隔离, 页面样式(::v-deep)进不去,
// 图片间距只能在内容层面改内联样式(机器人图片与下方标题的间距, 对齐 WorkBuddy 参考稿)
getAIDisplayContent(content, isWelcome) {
let html
if (!this.searchKeyword || !content) {
return this.parseMarkdown(content)
html = this.parseMarkdown(content)
} else if (content.toLowerCase().indexOf(this.searchKeyword.toLowerCase()) === -1) {
html = this.parseMarkdown(content)
} else {
// 先做 markdown 渲染,再做关键词高亮
const mdHtml = this.parseMarkdown(content)
html = this._wrapHighlightInHtml(mdHtml, this.searchKeyword)
}
// 仅当内容包含关键词时才执行高亮,避免非匹配消息的额外处理
if (content.toLowerCase().indexOf(this.searchKeyword.toLowerCase()) === -1) {
return this.parseMarkdown(content)
if (isWelcome && html) {
// 仅替换 img 的 margin(机器人图片), 不影响列表等其他元素的 margin:8rpx 0
// 注意: 原始样式是 "margin:8rpx 0;" (8rpx 上下 / 0 左右), 正则必须匹配这个写法,
// 只改这里的 "0 0 0rpx 0" 最后一段调间距; 前面的搜索正则不要动, 改错会匹配失效
html = html.replace(/(<img[^>]*style="[^"]*?)margin:\s*8rpx 0;/, '$1margin:0 0 0rpx 0;')
// 图片是 display:block, 欢迎语里图片和标题之间有空行, parseMarkdown 会生成
// 连续多个 <br> (每个占一行行高), 之前只删一个导致间距看起来"没反应";
// 这里把 img 后面紧跟的所有 <br> 一次性清掉, 标题紧贴图片
html = html.replace(/(<img[^>]*(?:\/>|>))(?:\s*<br>)+/, '$1')
}
// 先做 markdown 渲染,再做关键词高亮
const mdHtml = this.parseMarkdown(content)
return this._wrapHighlightInHtml(mdHtml, this.searchKeyword)
return html
},
// 在纯文本中高亮关键词(用于用户消息)
@@ -4074,6 +4213,8 @@ _handleStreamError(msg) {
this.voiceHolding = false
this.voiceHoldCancelling = false
this.inputFocused = false
// 进入语音模式时清掉文字输入态, 避免白卡片背景 + 工具栏残留(切换时闪烁)
this.showTextMode = false
},
// 退出语音模式, 回到文字输入态
@@ -4719,6 +4860,25 @@ _handleStreamError(msg) {
scroll-margin-top: 300rpx;
scroll-margin-bottom: 200rpx;
// 欢迎语消息: 气泡背景纯白, 让快捷问题更明显
&.is-welcome .ai-message .message-bubble {
background: #ffffff !important;
}
// 欢迎语消息: 图片间距由内容内联样式控制(getAIDisplayContent 里改成 0 0 8rpx 0),
// 这里不再用 CSS 强制 48rpx —— 样式表 !important 会覆盖内联样式, 导致 H5 上调距无效
// 欢迎语消息: 隐藏上方时间戳
&.is-welcome .ai-message .message-nickname.ai-nickname {
display: none;
}
// 欢迎语消息: 标题与快捷问题的间距, 与"图片→标题"保持一致 (48rpx)
// 下方 5326 行的 .quick-questions-row 嵌套链更长、特异性更高, 必须 !important 覆盖
&.is-welcome .quick-questions-row {
margin-top: 48rpx !important;
}
// 搜索定位 - 当前结果: 用柔和的浅绿底色提示 (WorkBuddy 风格, 无气泡 box-shadow)
&.search-current {
position: relative;
@@ -4869,7 +5029,7 @@ _handleStreamError(msg) {
color: #1a1a1a;
strong {
font-weight: 600;
font-weight: 400;
color: #1a1a1a;
}
@@ -4888,8 +5048,9 @@ _handleStreamError(msg) {
}
a {
/* 网址/链接: 蓝色 (与 parseMarkdown 里的 LINK 常量保持一致) */
color: #3a7afe;
/* 网址/链接: 黑色, 不加粗 */
color: #1f1f1f !important;
font-weight: 400 !important;
text-decoration: underline;
text-underline-offset: 4rpx;
transition: color 0.2s ease;
@@ -5097,7 +5258,7 @@ _handleStreamError(msg) {
.link-url {
display: block;
font-size: 22rpx;
color: $color-primary;
color: #1f1f1f;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@@ -5246,30 +5407,38 @@ _handleStreamError(msg) {
.quick-questions-row {
margin-top: 16rpx;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
flex-direction: column;
align-items: flex-start;
max-width: 100%;
.quick-question-chip {
display: inline-flex;
align-items: center;
margin-right: 16rpx;
margin-bottom: 16rpx;
padding: 12rpx 24rpx;
padding: 12rpx 28rpx;
background: #ffffff;
border: 1rpx solid #1a1a1a;
border-radius: 32rpx;
border: 1rpx solid #eef0f3;
border-radius: 999rpx;
font-size: 26rpx;
color: #1a1a1a;
cursor: pointer;
transition: all 0.2s ease;
max-width: 100%;
line-height: 1.4;
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.14);
&:last-child {
margin-bottom: 0;
}
.quick-question-icon {
font-size: 24rpx;
width: 28rpx;
height: 28rpx;
flex-shrink: 0;
margin-right: 8rpx;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.quick-question-text {
@@ -5280,10 +5449,8 @@ _handleStreamError(msg) {
}
.quick-question-chip--hover {
background: #1a1a1a;
color: #ffffff;
transform: translateY(-1rpx);
box-shadow: 0 4rpx 12rpx rgba(26, 26, 26, 0.2);
background: #e4e5e7;
color: #1a1a1a;
}
}
@@ -5436,7 +5603,7 @@ _handleStreamError(msg) {
max-width: 100%;
.message-text {
font-size: 20rpx !important; // 还原为用户消息原字号
font-size: 25rpx !important; // 还原为用户消息原字号
}
&::before {
@@ -5520,10 +5687,25 @@ _handleStreamError(msg) {
}
}
// AI 回答文字字号统一为 25rpx
.message-text,
.ai-message-text {
font-size: 25rpx !important;
line-height: 1.7;
// H5 / 微信 AI 回答里的链接统一黑色
a {
color: #1f1f1f !important;
font-weight: 400 !important;
text-decoration: underline;
text-underline-offset: 4rpx;
}
}
// 微信端 AI 富文本(豆包风格)容器: 行高/字号/字色统一兜底
.ai-message-rich {
display: block;
font-size: 30rpx;
font-size: 25rpx;
line-height: 1.75;
color: #1a1a1a;
letter-spacing: 0.2rpx;
@@ -5545,7 +5727,7 @@ _handleStreamError(msg) {
align-items: center;
margin-top: 12rpx;
padding-top: 4rpx;
color: $color-primary;
color: #1f1f1f;
font-size: 24rpx;
font-weight: 500;
line-height: 1;
@@ -5569,7 +5751,7 @@ _handleStreamError(msg) {
}
.streaming-tail-text {
color: $color-primary;
color: #1f1f1f;
font-weight: 500;
}
@@ -5660,6 +5842,30 @@ _handleStreamError(msg) {
}
}
/* 欢迎语操作栏: 换一换按钮 */
&.refresh-welcome-btn {
height: 56rpx;
padding: 0 20rpx;
gap: 8rpx;
margin-top: 20rpx;
.refresh-icon {
width: 28rpx;
height: 28rpx;
flex-shrink: 0;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMjEgMTJhOSA5IDAgMSAxLTktOSA5Ljc1IDkuNzUgMCAwIDEgNi4zNiAyLjM2TDIxIDMiLz48cGF0aCBkPSJNMjEgM3Y2aC02Ii8+PC9zdmc+");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.refresh-text {
font-size: 24rpx;
color: #666;
line-height: 1;
}
}
&:active {
background: #ebebeb;
}
@@ -5670,10 +5876,10 @@ _handleStreamError(msg) {
}
}
/* 键盘垫高层:高度变化时平滑过渡 */
/* 键盘垫高层:高度变化不做过渡 —— 切换语音/文字时 hideKeyboard 触发高度变化,
若加 transition 会播放高度动画, 输入区整体跳动, 视觉上就是「频闪/看到上次样式」 */
.keyboard-spacer {
flex-shrink: 0;
transition: height 0.25s ease;
}
/* 输入区域 (新版: 顶部胶囊形输入条 + 底部 5 个图标均匀分布) */
@@ -5699,9 +5905,15 @@ _handleStreamError(msg) {
justify-content: space-between;
background: #ffffff;
border-radius: 999rpx;
padding: 18rpx 14rpx 18rpx 32rpx;
min-height: 108rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
/* border-box: 让 min-height 把上下 padding(10rpx*2)算进去, 否则 content-box 下
实际高度 = 96+20 = 116rpx, 与语音胶囊(96rpx)差 20rpx → 小程序里上下高度不一致 */
box-sizing: border-box;
/* 高度与语音模式胶囊(.voice-mode-row: height 96rpx)保持一致:
内部图标容器 76rpx + 上下 padding 10rpx*2 = 96rpx */
padding: 10rpx 14rpx 10rpx 32rpx;
min-height: 96rpx;
/* 与快捷问题按钮(.quick-question-chip)同款阴影, 白底更突出 */
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.14);
/* 无文字时左侧语音图标,点击打开语音面板
PR-INPUT-LAYOUT-SYMMETRY (2026-09-28): 容器从 52rpx 扩大到 76rpx,
@@ -5817,7 +6029,7 @@ _handleStreamError(msg) {
.voice-icon-bg {
width: 48rpx;
height: 48rpx;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMWYxZjFmIiBzdHJva2Utd2lkdGg9IjIuMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNMTAgMTIgaDYgbDYgLTQgdjE2IGwtNiAtNCBoLTYgYTIgMiAwIDAgMSAtMiAtMiB2LTQgYTIgMiAwIDAgMSAyIC0yIHoiLz48cGF0aCBkPSJNMjQgMTAgYzIgMyAyIDkgMCAxMiIvPjwvc3ZnPg==");
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMWYxZjFmIiBzdHJva2Utd2lkdGg9IjEuOCIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48Y2lyY2xlIGN4PSIzLjUiIGN5PSIxMiIgcj0iMi4yIiBmaWxsPSIjMWYxZjFmIiBzdHJva2U9Im5vbmUiLz48cGF0aCBkPSJNMTAgNy4xIEE3IDcgMCAwIDEgMTAgMTYuOSIvPjxwYXRoIGQ9Ik0xNS4zIDEuNyBBMTQuNSAxNC41IDAgMCAxIDE1LjMgMjIuMyIvPjwvc3ZnPg==");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
@@ -5833,17 +6045,24 @@ _handleStreamError(msg) {
background-size: contain;
}
/* 展开态: 卡片变白底圆角容器, 内部输入行不再单独成胶囊 */
/* 展开态: 文字输入时卡片变白底圆角容器;
语音模式卡片保持透明, 白色胶囊由 .voice-mode-row 自身呈现 (避免双层白底) */
.input-card {
&.is-voice-mode,
&.is-text-mode {
background: #ffffff;
border-radius: 28rpx;
padding: 14rpx 16rpx 6rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
/* 与快捷问题按钮(.quick-question-chip)同款阴影 */
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.14);
}
&.is-voice-mode {
background: transparent;
border-radius: 0;
padding: 0;
box-shadow: none;
}
&.is-voice-mode .input-row-top,
&.is-text-mode .input-row-top {
background: transparent;
border-radius: 0;
@@ -5853,30 +6072,65 @@ _handleStreamError(msg) {
}
}
/* 语音模式: 按住说话 */
.voice-hold-btn {
/* 语音/文字两态胶囊始终在 DOM 中, 用显隐切换而非 v-if 重建节点。
v-if 在微信小程序会触发节点卸载/重建, 切换瞬间旧节点那帧会闪(看到上次样式)。
!important 用于盖过 .voice-mode-row / .input-row-top 自身的 display:flex */
.hidden-row {
display: none !important;
}
/* 语音模式单行 (PR-VOICE-MODE-ONE-ROW-V2): 整行即白色胶囊(flex布局,不依赖绝对定位)
键盘图标在左 / 按住说话占中间 / + 在右, 与参考稿一致 */
.voice-mode-row {
position: relative; /* 「上滑取消」提示 .voice-cancel-hint 锚定到这里 */
display: flex;
align-items: center;
justify-content: center;
/* 与 .input-row-top 一致用 border-box, 保证两者 96rpx 计算口径相同, 高度一致 */
box-sizing: border-box;
height: 96rpx;
margin: 4rpx 0 8rpx;
border-radius: 16rpx;
background: #f2f2f3;
position: relative; // PR-FRONTEND-VOICE-INPUT: 让 .voice-cancel-hint 锚定到这里
/* 上下 margin 为 0: 与默认输入胶囊(.input-row-top margin 0)整块高度一致,
否则语音态多占 12rpx, 切换时聊天列表被顶/拉 12rpx 产生"看到上次样式"的频闪 */
margin: 0;
padding: 0 10rpx 0 24rpx;
border-radius: 999rpx;
background: #ffffff;
box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.14);
transition: background-color 0.15s ease-out;
&.is-holding {
background: #e2e2e4;
background: #f2f2f3;
}
// PR-FRONTEND-VOICE-INPUT (2026-09-24): 上滑到 80px+ 视为取消手势
&.is-cancelling {
background: #fdecec;
.voice-hold-text {
color: #d23f3f;
}
}
.voice-side-btn {
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.voice-side-right {
margin-left: 8rpx;
}
/* 按住说话区域: 透明, 占据中间剩余全部空间 */
.voice-hold-btn {
flex: 1;
height: 100%;
min-width: 0;
display: flex;
align-items: center;
justify-content: center;
}
.voice-hold-text {
font-size: 30rpx;
color: #1f1f1f;
@@ -6367,11 +6621,21 @@ _handleStreamError(msg) {
.input-area {
padding: 10rpx 16rpx 12rpx;
.input-card {
/* 卡片内边距/圆角只对文字输入态(白卡片)生效; 默认/语音胶囊保持 flush,
否则默认胶囊会多吃 12+10rpx, 与语音胶囊整块高度差 22rpx, 切换时跳动频闪 */
.input-card.is-text-mode {
padding: 12rpx 14rpx 10rpx;
border-radius: 18rpx;
}
/* 语音模式胶囊: 与默认输入胶囊左右对齐。
默认胶囊在 .input-card 内(左右各收进 14rpx), 而语音模式卡片 padding 被
.is-voice-mode 强制为 0, 胶囊全宽 —— 用同样的水平 margin 补齐, 两端长短一致。
上下 margin 保持 0, 与默认胶囊整块等高, 避免切换时聊天列表跳动 */
.voice-mode-row {
margin: 0 14rpx;
}
.input-row-top {
min-height: 64rpx;
@@ -6567,6 +6831,20 @@ _handleStreamError(msg) {
line-height: 1.7;
letter-spacing: 0.8rpx;
}
// AI 回答不加粗(兜底),同时统一 H5 markdown 容器字号为 25rpx
.ai-message {
.message-bubble,
.selectable-md {
strong, b, h1, h2, h3, h4, h5, h6, th {
font-weight: normal !important;
}
}
.selectable-md {
font-size: 25rpx !important;
}
}
}
/* ========== AI 回答: 无气泡 ==========
@@ -6596,15 +6874,14 @@ _handleStreamError(msg) {
padding: 10rpx 22rpx;
border-radius: 999rpx;
background: #f4f5f7;
color: #1f6cff;
color: #1f1f1f;
font-size: 24rpx;
/* 新对话图标: 圆角气泡 + 中间加号 + 左下角小尾巴的线性图标
微信小程序不支持内联 SVG, 沿用 base64 背景图方案 (与 svg-icon / voice-icon-bg 一致) */
/* 新对话图标: 圆角气泡 + 中间加号 + 左下角小尾巴的线性图标 (已改为黑色) */
.new-chat-icon {
width: 32rpx;
height: 32rpx;
flex-shrink: 0;
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMWY2Y2ZmIiBzdHJva2Utd2lkdGg9IjEuNyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNOC41IDIuNUgxNkE1LjUgNS41IDAgMCAxIDIxLjUgOFYxMi41QTUuNSA1LjUgMCAwIDEgMTYgMThIOC42TDMgMjJWOEE1LjUgNS41IDAgMCAxIDguNSAyLjVaIi8+PHBhdGggZD0iTTEyIDcuNVYxMy41TTkuMiAxMC41SDE0LjgiLz48L3N2Zz4=");
background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMWYxZjFmIiBzdHJva2Utd2lkdGg9IjEuNyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cGF0aCBkPSJNOC41IDIuNUgxNkE1LjUgNS41IDAgMCAxIDIxLjUgOFYxMi41QTUuNSA1LjUgMCAwIDEgMTYgMThIOC42TDMgMjJWOEE1LjUgNS41IDAgMCAxIDguNSAyLjVaIi8+PHBhdGggZD0iTTEyIDcuNVYxMy41TTkuMiAxMC41SDE0LjgiLz48L3N2Zz4=");
background-repeat: no-repeat;
background-position: center;
background-size: contain;

View File

@@ -12,32 +12,33 @@
<!-- PR-CHAT-UI-CONFIG (2026-09-20): 每个附件 tab 由 attachmentTypes 控制显隐
支持的 kind: image / file / audio / video, 缺失的 kind 自动隐藏
location 不属于附件, 不受此开关控制 -->
<view v-if="isTypeEnabled('image')" class="tool-item" @click="selectImage">
<view v-if="isTypeEnabled('image')" class="tool-item tool-item-new tool-item-image" @click="selectImage">
<view class="tool-icon">
<text class="icondiy icon-system-image-line"></text>
<view class="image-icon"></view>
</view>
<text class="tool-text">{{ $lang('ai-chat.index.image') }}</text>
</view>
<view v-if="isTypeEnabled('video')" class="tool-item" @click="selectVideo">
<view v-if="isTypeEnabled('video')" class="tool-item tool-item-new tool-item-video" @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" @click="selectFile">
<view v-if="isTypeEnabled('file')" class="tool-item tool-item-new tool-item-file" @click="selectFile">
<view class="tool-icon">
<text class="icondiy icon-system-file-2-line"></text>
<view class="paperclip-icon"></view>
</view>
<text class="tool-text">{{ $lang('ai-chat.index.file') }}</text>
<text class="tool-text">添加文件</text>
</view>
<view v-if="isTypeEnabled('audio')" class="tool-item" @click="selectVoiceOrAudio">
<!-- 更多功能里的语音入口暂时隐藏 -->
<view v-if="false" 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 class="tool-item" @click="selectLocation">
<view v-if="false" class="tool-item tool-item-new tool-item-location" @click="selectLocation">
<view class="tool-icon">
<text class="icondiy icon-system-map-pin-line"></text>
</view>
@@ -465,9 +466,9 @@ export default {
position: relative; // 为 .close-btn 绝对定位提供参考
text {
font-size: 34rpx;
font-weight: 600;
color: $color-text;
font-size: 30rpx;
font-weight: 400;
color: #000000;
}
.close-btn {
@@ -484,14 +485,14 @@ export default {
right: 10rpx; //
.iconfont {
font-size: 28rpx;
color: $color-text-light;
color: #000000;
}
}
}
.tools-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-columns: repeat(3, 1fr);
gap: 24rpx;
.tool-item {
@@ -526,6 +527,62 @@ 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;
}
}
}
}
}

589
pages_tool/files/detail.vue Normal file
View File

@@ -0,0 +1,589 @@
<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

@@ -98,6 +98,7 @@ 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: {
@@ -164,10 +165,23 @@ const store = new Vuex.Store({
setShopInfo(state, value) {
state.shopInfo = value;
uni.setStorageSync('shopInfo', value); // 初始化数据调用
// 语言切换开关: 后台 shop_info.ischia 决定。
// 关闭(ischia 为假)时强制返回默认中文,并清掉用户此前持久化到 storage 的语种,
// 语言切换开关 fallback: 后台 shop_info.ischina 决定(老「双语模式」)。
// 新配置下发后由 setFloatingButtonConfig 里的 lang_switch.enabled 接管,
// 这里的 ischina 只是配置缺失(老缓存响应)时的兜底。
// 关闭时强制返回默认中文,并清掉用户此前持久化到 storage 的语种,
// 满足"后台关闭双语/小程序后,刷新重新进入必须是中文"的需求。
try { LangConfig.setLangSwitchEnabled(!!(value && value.ischia)); } catch (e) {}
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;
@@ -315,6 +329,8 @@ 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) {