feat(mp-weixin): 新增全局兜底分享mixin与路径复制能力
为微信小程序端添加全局分享兜底支持,为所有未显式声明分享钩子的页面提供默认转发和朋友圈分享能力,同时新增小程序路径复制工具方法。
This commit is contained in:
@@ -6,6 +6,7 @@ import Lang from './lang.js'
|
||||
import {
|
||||
Weixin
|
||||
} from 'common/js/wx-jssdk.js';
|
||||
import { copyText } from './uniapp.utils.js';
|
||||
|
||||
//
|
||||
export function decodeEntity(str, amp) {
|
||||
@@ -1735,6 +1736,28 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 复制当前页面的小程序路径(含 query)到剪贴板(仅微信小程序)
|
||||
* 小程序本身没有"页面 URL"概念,仅可复制形如 pages/goods/detail?id=123 的内部路径,
|
||||
* 便于分享者在聊天里粘贴给对方识别。
|
||||
* 内部复用 common/js/uniapp.utils.js 导出的 copyText(回调形式),为保持 Promise 一致性包裹一层。
|
||||
* @param {Object} options { copySuccess: '', copyFailed: '' }
|
||||
* @returns {Promise<String>} 返回实际复制的文本
|
||||
*/
|
||||
// #ifdef MP-WEIXIN
|
||||
copyCurrentPath(options = {}) {
|
||||
const { copySuccess = '', copyFailed = '' } = options;
|
||||
const route = this.getCurrentRoute();
|
||||
// 去掉前导斜杠,保持与转发 path 兼容
|
||||
const text = (route && route.path ? route.path : '').replace(/^\//, '');
|
||||
return new Promise((resolve, reject) => {
|
||||
copyText(text, { copySuccess, copyFailed }, (success, err) => {
|
||||
if (success) resolve(text);
|
||||
else reject(err || new Error('复制失败'));
|
||||
});
|
||||
});
|
||||
},
|
||||
// #endif
|
||||
//获取当前路由
|
||||
getCurrentRoute() {
|
||||
let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
|
||||
|
||||
Reference in New Issue
Block a user