diff --git a/CoreCms.Net.Uni-App/CoreShop/core/hooks/index.ts b/CoreCms.Net.Uni-App/CoreShop/core/hooks/index.ts index 015a01b7..932f35ab 100644 --- a/CoreCms.Net.Uni-App/CoreShop/core/hooks/index.ts +++ b/CoreCms.Net.Uni-App/CoreShop/core/hooks/index.ts @@ -1,3 +1,4 @@ /** 系统配置 */ export * from './systemInfo'; export * from './use-loading'; +export * from './use-share'; diff --git a/CoreCms.Net.Uni-App/CoreShop/core/hooks/use-share.ts b/CoreCms.Net.Uni-App/CoreShop/core/hooks/use-share.ts new file mode 100644 index 00000000..b3945b4a --- /dev/null +++ b/CoreCms.Net.Uni-App/CoreShop/core/hooks/use-share.ts @@ -0,0 +1,61 @@ +import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'; +import { queryShare } from '@/core/api'; +import { ShareClientEnum, ShareModelEnum, ShareEnum } from '@/core/enum'; +import { handleShowToast } from '@/core/utils'; +import { UserToken } from '@/core/consts'; + +interface RequestParam { + client ?: ShareClientEnum; + url ?: string; + type ?: ShareModelEnum; + page ?: ShareEnum; + params ?: any; + token ?: string; +} + +export const useShareHook = () => { + + /** 获取分享url */ + const getShareUrl = (requestParam : RequestParam) => { + return new Promise(async (resolve) => { + let data = requestParam; + if (uni.getStorageSync(UserToken)) { + data['token'] = uni.getStorageSync(UserToken) + } + const share = await queryShare(data); + if (share.status) { + resolve(share.data); + } else { + handleShowToast(share.msg); + } + }) + } + + const shareAppMessage = (options : Page.CustomShareContent) => { + onShareAppMessage(() => { + console.log('onShareAppMessage'); + return { + ...options + }; + }); + return { onShareAppMessage }; + }; + + const shareTimeline = (options : Page.CustomShareContent) => { + onShareTimeline(() => { + console.log('shareTimeline'); + return { + ...options + }; + }); + return { onShareTimeline }; + }; + + const share = (customShareContent : Page.CustomShareContent, shareTimelineContent ?: Page.CustomShareContent) => { + const { onShareAppMessage } = shareAppMessage(customShareContent); + const { onShareTimeline } = shareTimeline(shareTimelineContent ? shareTimelineContent : customShareContent); + return { onShareAppMessage, onShareTimeline }; + }; + + return { share, getShareUrl, shareAppMessage, shareTimeline }; +}; \ No newline at end of file diff --git a/CoreCms.Net.Uni-App/CoreShop/pages/goods/detail.vue b/CoreCms.Net.Uni-App/CoreShop/pages/goods/detail.vue index d14e26e2..70cdc3de 100644 --- a/CoreCms.Net.Uni-App/CoreShop/pages/goods/detail.vue +++ b/CoreCms.Net.Uni-App/CoreShop/pages/goods/detail.vue @@ -26,8 +26,8 @@