修复分享问题

This commit is contained in:
2026-01-22 11:36:49 +08:00
parent 2afc2f9fab
commit 9037e205a0
7 changed files with 109 additions and 81 deletions

View File

@@ -70,7 +70,7 @@
v-else-if="item1.isTemporary &&item1.productName=='签子'"
src="https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/5/b97054debd83486ab7ad8e20ca6a360a.png"
></u-image>
<u-image width="112" height="112" radius="20"
<u-image width="56" height="56" radius="10"
:src="'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/table.png'"
mode="heightFix" v-else></u-image>
<text class="productName"> {{ item1.productName }} </text>
@@ -151,7 +151,7 @@
uni.cache.set("shopId", item.shopId);
uni.navigateTo({
url: "/pages/product/index?type=beforehand&order_id=" + item.id +
'&one_more_order=1',
'&one_more_order=1&shopId='+item.shopId,
});
}
})

View File

@@ -2456,10 +2456,10 @@
shareMixin,
handleMixinOnLoad,
returnQuery,
jsonToUrl,wxShare,
jsonToUrl,
wxShare,
returnCommonQuery
} from '@/utils/share.js'
import { onShareTimeline } from '@dcloudio/uni-app';
// defineOptions({
// mixins: [shareMixin],
// });
@@ -2470,21 +2470,22 @@ import { onShareTimeline } from '@dcloudio/uni-app';
function shareClick() {
isGoodsShare.value = true
}
async function onShare(){
async function onShare() {
const queryJson = await returnCommonQuery()
let query = jsonToUrl(queryJson)
query += '&type=beforehand'
let json={}
let json = {}
const shopName = uni.cache.get('shopInfo').shopName || ''
if (goodsModalList.value.length && isGoodsShare.value) {
const goods = goodsModalList.value[goodsModalList.value.length - 1].goods
query += '&showGoodsId=' + goods.id
json.title = goods.name
json.title = goods.name + (shopName ? `-${shopName}` : '')
json.imageUrl = goods.coverImg
json.showGoodsId = goods.id
}else{
json.title=uni.cache.get('shopInfo').shopName||''
json.imageUrl=uni.cache.get('shopInfo').logo||''
} else {
json.title = shopName
json.imageUrl = uni.cache.get('shopInfo').logo || ''
}
console.log('onShareAppMessage', {
query,
@@ -2497,9 +2498,9 @@ import { onShareTimeline } from '@dcloudio/uni-app';
path: '/pages/product/index' + '?' + query
})
}
onShareAppMessage(onShare)
onShareTimeline(onShare)
const pageOptions = reactive({})
@@ -2513,7 +2514,6 @@ import { onShareTimeline } from '@dcloudio/uni-app';
shopId: e.shopId || uni.cache.get('shopId')
})
const userInfo = userStore.userInfo
const shopInfoRes = userStore.shopInfo
// //获取用户信息
// const userInfo = await APIshopUserInfo({
// shopId: uni.cache.get('shopId')
@@ -2522,9 +2522,7 @@ import { onShareTimeline } from '@dcloudio/uni-app';
// const shopInfoRes = await APIusershopInfodetail({
// shopId: uni.cache.get('shopId')
// });
if (shopInfoRes && shopInfoRes.shopInfo) {
Object.assign(shopInfo, shopInfoRes.shopInfo);
}
Object.assign(shopInfo, userStore.shopInfo);
if (userInfo && typeof userInfo === 'object') {
@@ -2661,7 +2659,7 @@ import { onShareTimeline } from '@dcloudio/uni-app';
useSocket.setOnMessage(() => {});
}
onHide(() => {
isGoodsShare.value=false
isGoodsShare.value = false
closeSocket();
});
onUnload(() => {

View File

@@ -27,7 +27,10 @@
</view>
<text class="text">剩余{{item.quantity}}</text>
</view>
<view class="goods-name">{{item.goodsName}}</view>
<view class="goods-name u-flex u-row-between">
<text class="u-m-r-30" style="word-break: break-all;">{{item.goodsName}}</text>
<ymfShare color="#333" />
</view>
<view class="bg-f7" style="height: 24rpx"></view>
<view class="desc">
<view class="u-flex">
@@ -116,6 +119,7 @@
</view>
</template>
<script setup>
import ymfShare from '@/components/ymf-components/ymf-share.vue'
import {
computed,
reactive
@@ -335,7 +339,7 @@
import {
shareMixin,
handleMixinOnLoad,wxShare,returnQuery
handleMixinOnLoad,wxShare,returnQuery ,returnIndexBg,
} from '@/utils/share.js'
// defineOptions({
// mixins: [shareMixin],
@@ -343,12 +347,13 @@
onShareAppMessage(async(res)=>{
const query=await returnQuery()
const shopInfo=uni.cache.get('shopInfo')
return wxShare({
...res,
title:item.goodsName,
title:item.goodsName +'-'+shopInfo.shopName,
path:'/scoreShop/detail/index'+'?'+query,
query,
imageUrl:item.goodsImageUrl||''
imageUrl:item.goodsImageUrl||returnIndexBg()||''
})
})

View File

@@ -31,10 +31,13 @@
<view class="tab-item" :class="tabActive === 0 ? 'active' : ''" @click="tabActive = 0">优惠券</view>
<view class="tab-item" :class="tabActive === 1 ? 'active' : ''" @click="tabActive = 1">其它商品</view>
</view>
<view class="u-flex gap-20" @click="toggleLayout">
<image :src="layout === 'block' ? imgs.layout_block : imgs.layout" class="layout" />
<view class="u-flex gap-20">
<view @click="toggleLayout">
<image :src="layout === 'block' ? imgs.layout_block : imgs.layout" class="layout" />
</view>
<ymfShare size="40rpx" color="#9C571F"></ymfShare>
</view>
</view>
<goodsList :pointsUser="pointsUser" :layout="layout" :list="list" @exchange="exchange"></goodsList>
@@ -73,17 +76,17 @@
function back() {
const pages = getCurrentPages();
if(pages.length<2){
if (pages.length < 2) {
uni.switchTab({
url: '/pages/index/index'
url: '/pages/index/index'
})
}else{
} else {
uni.navigateBack({
delta: 1,
});
}
}
// function exchange(item) {
@@ -148,12 +151,32 @@
import {
shareMixin,
handleMixinOnLoad
handleMixinOnLoad,
returnQuery,
jsonToUrl,
wxShare,returnIndexBg ,
returnCommonQuery
} from '@/utils/share.js'
defineOptions({
mixins: [shareMixin],
});
// defineOptions({
// mixins: [shareMixin],
// });
async function onShare() {
const queryJson = await returnCommonQuery()
let query = jsonToUrl(queryJson)
let json = {}
json.title = '积分乐园,好物兑换'
json.imageUrl = returnIndexBg()||uni.cache.get('shopInfo').logo || ''
return wxShare({
query,
...json,
path: '/scoreShop/index/index' + '?' + query
})
}
onShareAppMessage(onShare)
onShareTimeline(onShare)
const options = reactive({
})
@@ -180,6 +203,10 @@
import {
productStore
} from '@/stores/user.js';
import {
onShareAppMessage
} from '@dcloudio/uni-app';
import { onShareTimeline } from '@dcloudio/uni-app';
const storeuser = productStore();
@@ -200,9 +227,11 @@
flex-direction: column;
justify-content: flex-end;
}
.gap-20{
.gap-20 {
gap: 20rpx;
}
.top {
padding: 138rpx 26rpx 48rpx 42rpx;
display: flex;

View File

@@ -39,6 +39,7 @@ declare global {
const onScopeDispose: typeof import('vue')['onScopeDispose']
const onServerPrefetch: typeof import('vue')['onServerPrefetch']
const onShareAppMessage: typeof import('@dcloudio/uni-app')['onShareAppMessage']
const onShareTimeline: typeof import('@dcloudio/uni-app')['onShareTimeline']
const onShow: typeof import('@dcloudio/uni-app')['onShow']
const onUnload: typeof import('@dcloudio/uni-app')['onUnload']
const onUnmounted: typeof import('vue')['onUnmounted']

View File

@@ -144,7 +144,7 @@ export async function returnQuery(query, showkeys) {
}
}
}
return Promise.resolve(result)
return Promise.resolve(result)
}
function parseQueryString(queryString) {
@@ -189,6 +189,34 @@ export async function handleMixinOnLoad(opt, vm) {
bindInvite(options)
}
}
import {
isJsonArrayString
} from '@/utils/util.js';
/**
* 返回店铺首页图片
*/
export function returnIndexBg() {
try {
const orderVIP = uni.cache.get('orderVIP')
if (!orderVIP || !orderVIP.shopExtendList) {
return ''
}
if (!isJsonArrayString(orderVIP.shopExtendList[0].value)) {
return ''
}
return JSON.parse(orderVIP.shopExtendList[0].value)[0]
} catch (error) {
console.error('orderVIP.shopExtendList[0].value 格式不正确')
return ''
//TODO handle the exception
}
}
// utils/share.js
export const shareMixin = {
@@ -223,41 +251,25 @@ export const shareMixin = {
// }
// },
async onShareAppMessage(res) {
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const currentPath = currentPage.route;
const currentOptions = currentPage.options;
let sharePath = `/${currentPath}`;
// const queryJson = {
// inviteCode: (inviteCode && inviteCode !== true) ? inviteCode : null,
// shopId,
// shopUserId: shopUserInfo.id,
// }
// for (const key in currentOptions) {
// if (currentOptions.hasOwnProperty(key)) {
// queryJson[key] = encodeURIComponent(currentOptions[key])
// }
// }
// queryJson.shopId = shopId
// queryJson.inviteCode = (inviteCode && inviteCode !== true) ? inviteCode : null
// queryJson.shopUserId = shopUserInfo.id
const query =await returnQuery()
const query = await returnQuery()
const indexBg = returnIndexBg()
console.log('indexBg', indexBg);
const imageUrl = indexBg || shopInfo.logo
// 全局默认配置(可被页面覆盖)
const defaultShareConfig = {
title: shopInfo.shopName,
path: sharePath + '?' + query,
imageUrl: shopInfo.logo,
imageUrl: imageUrl,
query,
// desc: '描述',
success: (res) => {
@@ -270,9 +282,6 @@ export const shareMixin = {
};
// 页面自定义配置覆盖全局
const pageShareConfig = this.$options.shareConfig || {};
console.log('mixIn onShareAppMessage', {
@@ -286,16 +295,12 @@ export const shareMixin = {
},
async onShareTimeline() {
// const shopId = uni.cache.get('shopId')
// const shopUserInfo = uni.cache.get('shopUserInfo')
const shopInfo = uni.cache.get('shopInfo')
// const inviteCode = await autoGetInviteCode({
// shopId: shopId,
// shopUserId: shopUserInfo.id
// })
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
@@ -304,26 +309,15 @@ export const shareMixin = {
let sharePath = `/${currentPath}`;
// const queryJson = {
// inviteCode: (inviteCode && inviteCode !== true) ? inviteCode : null,
// shopId,
// shopUserId: shopUserInfo.id,
// }
// for (const key in currentOptions) {
// if (currentOptions.hasOwnProperty(key)) {
// queryJson[key] = encodeURIComponent(currentOptions[key])
// }
// }
// queryJson.shopId = shopId
// queryJson.inviteCode = (inviteCode && inviteCode !== true) ? inviteCode : null
// queryJson.shopUserId = shopUserInfo.id
const query = await returnQuery()
const indexBg = returnIndexBg()
const imageUrl = indexBg || shopInfo.logo
const defaultTimelineConfig = {
title: shopInfo.shopName,
path: sharePath + '?' + query,
imageUrl: shopInfo.logo,
imageUrl: imageUrl,
query,
};

View File

@@ -15,6 +15,7 @@ module.exports = defineConfig({
{
"@dcloudio/uni-app": [
"onShareAppMessage",
"onShareTimeline",
"onLoad",
"onShow",
"onHide",