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 './systemInfo';
|
||||||
export * from './use-loading';
|
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">
|
<script setup lang="ts">
|
||||||
import { reactive } from 'vue';
|
import { reactive } from 'vue';
|
||||||
import { onLoad, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
import { onLoad , onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
|
||||||
import { queryGoodsDetail, queryCartNum, queryShare, queryGoodsDetailByToken, queryPromotionList, queryAddCart, queryUserInfo } from '@/core/api';
|
import { queryGoodsDetail, queryCartNum, queryShare, queryGoodsDetailByToken, queryPromotionList, queryAddCart } from '@/core/api';
|
||||||
import type { Response, GoodsAgentListType, GoodsPromotionType, GoodsSkuListType } from "@/core/models";
|
import type { Response, GoodsAgentListType, GoodsPromotionType, GoodsSkuListType } from "@/core/models";
|
||||||
import { PromotionEnum, AddCartEnum, PaymentTypeEnum, ShareClientEnum, ShareModelEnum, ShareEnum } from '@/core/enum';
|
import { PromotionEnum, AddCartEnum, PaymentTypeEnum, ShareClientEnum, ShareModelEnum, ShareEnum } from '@/core/enum';
|
||||||
import { UserToken, shareUrl } from '@/core/consts'
|
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 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 GoodsDetailRecommend from '@/pages/components/goods-detail/components/goods-detail-recommend/goods-detail-recommend.vue';
|
||||||
import { useLoginStore } from '@/core/store';
|
import { useLoginStore } from '@/core/store';
|
||||||
|
import { useShareHook } from '@/core/hooks';
|
||||||
|
|
||||||
interface QueryParams {
|
interface QueryParams {
|
||||||
id : number;
|
id : number;
|
||||||
@@ -122,14 +123,45 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 获取分享url */
|
/** 获取分享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)) {
|
if (uni.getStorageSync(UserToken)) {
|
||||||
getCartNum();
|
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 getCartNum = async () => {
|
||||||
const num : Response<number> = await queryCartNum();
|
const num : Response<number> = await queryCartNum();
|
||||||
@@ -210,27 +242,29 @@
|
|||||||
}
|
}
|
||||||
const share = await queryShare(data);
|
const share = await queryShare(data);
|
||||||
if (share.status) {
|
if (share.status) {
|
||||||
state.shareUrl = share.data
|
state.shareUrl = share.data;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
handleShowToast(share.msg);
|
handleShowToast(share.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 分享 */
|
|
||||||
onShareAppMessage(() => {
|
// /** 分享 */
|
||||||
return {
|
// onShareAppMessage(() => {
|
||||||
title: state.goodsDetailData.name,
|
// return {
|
||||||
imageUrl: state.goodsDetailData.image,
|
// title: state.goodsDetailData.name,
|
||||||
path: state.shareUrl
|
// imageUrl: state.goodsDetailData.image,
|
||||||
}
|
// path: state.shareUrl
|
||||||
});
|
// }
|
||||||
onShareTimeline(() => {
|
// });
|
||||||
return {
|
// onShareTimeline(() => {
|
||||||
title: state.goodsDetailData.name,
|
// return {
|
||||||
imageUrl: state.goodsDetailData.image,
|
// title: state.goodsDetailData.name,
|
||||||
path: state.shareUrl
|
// imageUrl: state.goodsDetailData.image,
|
||||||
}
|
// path: state.shareUrl
|
||||||
});
|
// }
|
||||||
|
// });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user