mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 19:53:27 +08:00
测试分享
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/** 系统配置 */
|
||||
export * from './systemInfo';
|
||||
export * from './use-loading';
|
||||
export * from './use-share';
|
||||
|
||||
61
CoreCms.Net.Uni-App/CoreShop/core/hooks/use-share.ts
Normal file
61
CoreCms.Net.Uni-App/CoreShop/core/hooks/use-share.ts
Normal file
@@ -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 };
|
||||
};
|
||||
@@ -26,8 +26,8 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive } from 'vue';
|
||||
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
||||
import { queryGoodsDetail, queryCartNum, queryShare, queryGoodsDetailByToken, queryPromotionList, queryAddCart, queryUserInfo } from '@/core/api';
|
||||
import { onLoad , onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
||||
import { queryGoodsDetail, queryCartNum, queryShare, queryGoodsDetailByToken, queryPromotionList, queryAddCart } from '@/core/api';
|
||||
import type { Response, GoodsAgentListType, GoodsPromotionType, GoodsSkuListType } from "@/core/models";
|
||||
import { PromotionEnum, AddCartEnum, PaymentTypeEnum, ShareClientEnum, ShareModelEnum, ShareEnum } from '@/core/enum';
|
||||
import { UserToken, shareUrl } from '@/core/consts'
|
||||
@@ -38,6 +38,7 @@
|
||||
import GoodsDetailSkuPopup from '@/pages/components/goods-detail/components/goods-detail-sku/goods-detail-sku.vue';
|
||||
import GoodsDetailRecommend from '@/pages/components/goods-detail/components/goods-detail-recommend/goods-detail-recommend.vue';
|
||||
import { useLoginStore } from '@/core/store';
|
||||
import { useShareHook } from '@/core/hooks';
|
||||
|
||||
interface QueryParams {
|
||||
id : number;
|
||||
@@ -122,14 +123,45 @@
|
||||
}
|
||||
|
||||
/** 获取分享url */
|
||||
getShareUrl(goodsDetail.data.id);
|
||||
// getShareUrl(goodsDetail.data.id);
|
||||
// state.shareUrl = (await useShareHook().getShareUrl({
|
||||
// client: ShareClientEnum.wxMiNiProgram,
|
||||
// url: shareUrl,
|
||||
// type: ShareModelEnum.url,
|
||||
// page: ShareEnum.goods,
|
||||
// params: { goodsId: goodsDetail.data.id, }
|
||||
// }) as string);
|
||||
|
||||
// const { onShareAppMessage, onShareTimeline } = useShareHook().share({ title: 'xxx2', content: 'yyy2' }, { title: '哇哈哈2' });
|
||||
|
||||
/** 如果用户登录,获取购物车数量 */
|
||||
if (uni.getStorageSync(UserToken)) {
|
||||
getCartNum();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const { onShareAppMessage, onShareTimeline } = useShareHook().share({
|
||||
title: state.goodsDetailData.name || '123123',
|
||||
imageUrl: state.goodsDetailData.image || '123',
|
||||
});
|
||||
|
||||
// onShareAppMessage(() => {
|
||||
// return {
|
||||
// title: state.goodsDetailData.name,
|
||||
// imageUrl: state.goodsDetailData.image,
|
||||
// }
|
||||
// });
|
||||
// onShareTimeline(() => {
|
||||
// return {
|
||||
// title: state.goodsDetailData.name,
|
||||
// imageUrl: state.goodsDetailData.image,
|
||||
// }
|
||||
// })
|
||||
|
||||
/** 获取购物车数量 */
|
||||
const getCartNum = async () => {
|
||||
const num : Response<number> = await queryCartNum();
|
||||
@@ -210,27 +242,29 @@
|
||||
}
|
||||
const share = await queryShare(data);
|
||||
if (share.status) {
|
||||
state.shareUrl = share.data
|
||||
state.shareUrl = share.data;
|
||||
|
||||
} else {
|
||||
handleShowToast(share.msg);
|
||||
}
|
||||
}
|
||||
|
||||
/** 分享 */
|
||||
onShareAppMessage(() => {
|
||||
return {
|
||||
title: state.goodsDetailData.name,
|
||||
imageUrl: state.goodsDetailData.image,
|
||||
path: state.shareUrl
|
||||
}
|
||||
});
|
||||
onShareTimeline(() => {
|
||||
return {
|
||||
title: state.goodsDetailData.name,
|
||||
imageUrl: state.goodsDetailData.image,
|
||||
path: state.shareUrl
|
||||
}
|
||||
});
|
||||
|
||||
// /** 分享 */
|
||||
// onShareAppMessage(() => {
|
||||
// return {
|
||||
// title: state.goodsDetailData.name,
|
||||
// imageUrl: state.goodsDetailData.image,
|
||||
// path: state.shareUrl
|
||||
// }
|
||||
// });
|
||||
// onShareTimeline(() => {
|
||||
// return {
|
||||
// title: state.goodsDetailData.name,
|
||||
// imageUrl: state.goodsDetailData.image,
|
||||
// path: state.shareUrl
|
||||
// }
|
||||
// });
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user