Files
sweekar-app/hooks/useSharePage.js
T
2026-01-04 17:53:40 +08:00

30 lines
850 B
JavaScript

import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
export function useSharePage(getParams) {
const info = uni.getSystemInfoSync();
// 页面中仍需要导入onShareAppMessage
onShareAppMessage((e) => {
if (info.uniPlatform !== 'web' && info.uniPlatform !== 'app') {
uni.showShareMenu({
withShareTicket: true,
menu: ['shareAppMessage', 'shareTimeline'],
});
}
const params = getParams || {}; // 每次分享时获取最新的参数
const buttonParams = e.target?.dataset || {};
return {
title: '',
...params,
...buttonParams,
};
});
// 页面中仍需要导入onShareTimeline
onShareTimeline(() => {
const params = getParams || {}; // 每次分享时获取最新的参数
return {
title: '',
...params,
};
});
}