diff --git a/common/api/market/distribution.js b/common/api/market/distribution.js
index acfc46e..85f66e0 100644
--- a/common/api/market/distribution.js
+++ b/common/api/market/distribution.js
@@ -136,6 +136,15 @@ export const getInviteCode = (data) => {
data: data,
});
};
+export const autoGetInviteCode = (data) => {
+ return request({
+ url: prveUrl + "/user/distribution/autoGetInviteCode",
+ method: "get",
+ data: data,
+ });
+};
+
+
// 获取配置
export const getConfig = (data) => {
diff --git a/common/config.js b/common/config.js
index 91fe54d..bc7c7ef 100644
--- a/common/config.js
+++ b/common/config.js
@@ -1,6 +1,6 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false;
// const debug = false; // false线上 true本地
-const debug = false; // false线上 true本地
+const debug = true; // false线上 true本地
let baseUrl = ''
let baseUrlwws = ''
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 379cecf..c2a25f9 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -5,7 +5,8 @@
-
+
+
@@ -133,424 +134,438 @@
+
\ No newline at end of file
diff --git a/pages/index/indexs.vue b/pages/index/indexs.vue
index 0cfbdc8..77794c3 100644
--- a/pages/index/indexs.vue
+++ b/pages/index/indexs.vue
@@ -2,9 +2,11 @@
-
+
-
+
@@ -118,516 +120,535 @@
+
\ No newline at end of file
diff --git a/pages/product/index.vue b/pages/product/index.vue
index 65902cc..7e63d5c 100644
--- a/pages/product/index.vue
+++ b/pages/product/index.vue
@@ -749,7 +749,7 @@
useCartStore
} from '@/stores/order.js';
import {
- computed, provide
+ computed, provide, reactive
} from 'vue';
const cartStore = useCartStore();
/**
@@ -2436,28 +2436,51 @@
}
});
}
-
+
+
+ import {
+ shareMixin,
+ handleMixinOnLoad,returnQuery
+ } from '@/utils/share.js'
+ defineOptions({
+ mixins: [shareMixin],
+ });
+
+ onShareAppMessage((res)=>{
+ let query=returnQuery()
+ query+='&type=beforehand'
+ return {
+ ...res,
+ ...query,
+ path: '/pages/product/index' + '?' + query,
+ query,
+ }
+ })
+
+ const pageOptions=reactive({})
onLoad(async (e) => {
+ Object.assign(pageOptions,e)
if (e.type) {
orderType.value = e.type;
}
- //获取用户信息
- const userInfo = await APIshopUserInfo({
- shopId: uni.cache.get('shopId')
- })
- //获取店铺信息
- const shopInfoRes = await APIusershopInfodetail({
- shopId: uni.cache.get('shopId')
- });
+ await handleMixinOnLoad(e)
+ const userInfo= userStore.userInfo
+ const shopInfoRes=userStore.shopInfo
+ // //获取用户信息
+ // const userInfo = await APIshopUserInfo({
+ // shopId: uni.cache.get('shopId')
+ // })
+ // //获取店铺信息
+ // const shopInfoRes = await APIusershopInfodetail({
+ // shopId: uni.cache.get('shopId')
+ // });
if (shopInfoRes && shopInfoRes.shopInfo) {
Object.assign(shopInfo, shopInfoRes.shopInfo);
- uni.cache.set('shopInfo', shopInfoRes.shopInfo)
}
if (userInfo && typeof userInfo === 'object') {
shopUserInfo.value = userInfo
- uni.cache.set('shopUserInfo', userInfo)
}
await productqueryProduct();
diff --git a/stores/user.js b/stores/user.js
index f271a91..336729b 100644
--- a/stores/user.js
+++ b/stores/user.js
@@ -49,7 +49,7 @@ export const Storelogin = defineStore("login", {
rawData: infoRes.rawData,
source: "wechat",
});
- console.log('APIuserlogin',res);
+ console.log('APIuserlogin', res);
if (res) {
this.token = res.token;
this.miniAppOpenId = res.userInfo
@@ -110,12 +110,90 @@ export const productStore = defineStore("product", {
latitude: "",
longitude: "",
},
+ token: "",
+ miniAppOpenId: "",
+ userInfo: "",
+ shopId: uni.cache.get('shopId') || '',
shopInfo: {
shopId: "",
isOrderFence: 0,
+ id: '',
},
+ shopUserInfo:{
+
+ },
+ isHasLogin:false
}),
actions: {
+ actionslogin() {
+ return new Promise(async (resolve, reject) => {
+ // #ifdef MP-WEIXIN
+ uni.login({
+ provider: "weixin",
+ success: (data) => {
+ // 微信小程序环境
+ uni.getUserInfo({
+ provider: "weixin",
+ success: async (infoRes) => {
+ let res = await APIuserlogin({
+ code: data.code, //临时登录凭证
+ rawData: infoRes.rawData,
+ source: "wechat",
+ });
+ console.log('APIuserlogin', res);
+ if (res) {
+ this.token = res.token;
+ this.isHasLogin=true
+ this.miniAppOpenId = res.userInfo
+ .miniAppOpenId;
+ this.userInfo = res.userInfo;
+ uni.cache.set("token", res.token);
+ uni.cache.set("userInfo", res.userInfo);
+ uni.cache.set("followIndex", res
+ .followIndex || "");
+ }
+ resolve(true);
+ },
+ fail: (err) => {
+ reject(false);
+ },
+ });
+ },
+ });
+ // #endif
+ // #ifdef MP-ALIPAY
+ my.getAuthCode({
+ scopes: "auth_base",
+ success: async (data) => {
+ // 支付宝小程序环境
+ // my.getAuthUserInfo({
+ // success: async (infoRes) => {
+ let res = await APIuserlogin({
+ code: data.authCode, //临时登录凭证
+ // rawData: JSON.stringify(infoRes),
+ source: "alipay",
+ });
+ if (res) {
+ this.isHasLogin=true
+ this.token = res.token;
+ this.miniAppOpenId = res.userInfo.miniAppOpenId;
+ this.userInfo = res.userInfo;
+ uni.cache.set("token", res.token);
+ uni.cache.set("openId", res.userInfo.alipayOpenId);
+ uni.cache.set("userInfo", res.userInfo);
+ resolve(true);
+ }
+ },
+ fail: () => {
+ reject(false);
+ },
+ });
+ // #endif
+ // #ifdef H5
+ resolve(true)
+ // #endif
+ });
+ },
getLocation() {
return new Promise((resolve, reject) => {
console.log("获取经纬度");
@@ -185,11 +263,11 @@ export const productStore = defineStore("product", {
console.log("扫码内容", q);
// #ifdef H5
uni.navigateTo({
- url:'/pages/product/index'
+ url: '/pages/product/index'
})
- return
+ return
// #endif
-
+
return new Promise(async (resolve, reject) => {
if (q) {
console.log(q);
@@ -448,19 +526,41 @@ export const productStore = defineStore("product", {
// 通过shopId 获取店铺会员信息
actionsproductqueryProduct() {
+ console.log('actionsproductqueryProduct:token',uni.cache.get('token'));
return new Promise(async (resolve, reject) => {
try {
let res = await APIshopUserInfo();
- uni.cache.set("shopUserInfo", res);
- uni.cache.set("orderVIP", res);
- uni.cache.set("ordershopUserInfo", res.shopInfo);
- resolve(res);
+ if(res&& typeof res === 'object'){
+ this.shopUserInfo=res;
+ uni.cache.set("shopUserInfo", res);
+ uni.cache.set("orderVIP", res);
+ uni.cache.set("ordershopUserInfo", res.shopInfo);
+ resolve(res);
+ }else{
+ reject(false);
+ }
+
} catch (e) {
reject(false);
}
});
},
+ async pageOnload() {
+ //登录
+ await this.actionslogin()
+ //获取会员信息
+ await this.actionsproductqueryProduct()
+ //获取店铺信息
+ await this.getShopInfo()
+ },
+ async getShopInfo(shopId) {
+ const shopRes = await APIusershopInfodetail({
+ shopId: this.shopId || shopId,
+ });
+ this.shopInfo = shopRes.shopInfo;
+ uni.cache.set("shopInfo", shopRes.shopInfo);
+ },
// 用户信息获取
actionsAPIuser() {
return new Promise(async (resolve, reject) => {
diff --git a/utils/share.js b/utils/share.js
index 3b3fd87..88e88af 100644
--- a/utils/share.js
+++ b/utils/share.js
@@ -1,7 +1,15 @@
import {
- autoBindInviteUser
+ autoBindInviteUser,
+ autoGetInviteCode
} from '@/common/api/market/distribution.js'
-
+import {
+ APIshopUserInfo,
+ APIusershopInfodetail
+} from '@/common/api/member.js'
+import {
+ productStore
+} from '@/stores/user.js';
+const accountStore = productStore();
const accountInfo = wx.getAccountInfoSync();
export const envVersion = accountInfo.miniProgram.envVersion;
let type = 3;
@@ -32,7 +40,7 @@ export function bindInvite(args) {
shopUserId,
shopId,
inviteCode
- } = args;
+ } = args;
// 校验邀请码有效性:若邀请码为空、null、undefined,则直接返回,不执行后续绑定逻辑
if (!inviteCode || inviteCode === null || inviteCode === undefined) {
@@ -52,4 +60,238 @@ export function wxShare(par) {
...par,
type
}
-}
\ No newline at end of file
+}
+
+export async function returnQuery(query) {
+
+
+ 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,
+ ...query
+ }
+ 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
+
+ let result = ''
+ for (let key in queryJson) {
+ if (queryJson[key]) {
+ if (result === '') {
+ result += `${key}=${queryJson[key]}`
+ } else {
+ result += `&${key}=${queryJson[key]}`
+ }
+ }
+ }
+ return result
+}
+
+function parseQueryString(queryString) {
+ const queryParams = queryString.split("&").map((param) => param.split("="));
+ const params = {};
+ for (const [key, value] of queryParams) {
+ params[key] = value;
+ }
+ return params;
+}
+/**
+ * 混入的 onLoad 核心逻辑(抽成独立函数)
+ * @param {Object} opt - 页面 onLoad 接收的参数
+ * @param {Object} vm - 组件实例(this)
+ */
+export async function handleMixinOnLoad(opt, vm) {
+ console.log('onLoad');
+ const options = {}
+ if (opt.q) {
+ const q = decodeURIComponent(opt.q);
+ const params = parseQueryString(q.split("?")[1]);
+ Object.assign(options, params);
+ } else {
+ Object.assign(options, opt);
+ }
+ console.log('options', options);
+ if (options.shopId) {
+ uni.cache.set('shopId', options.shopId)
+ accountStore.shopId = options.shopId
+ await accountStore.pageOnload()
+ }
+ uni.setStorageSync('loadFinsh', true)
+ // 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
+ // })
+
+ if (options.inviteCode) {
+ bindInvite(options)
+ }
+}
+// utils/share.js
+export const shareMixin = {
+
+ // async onLoad(opt) {
+ // console.log('onLoad');
+ // const options = {}
+ // if (opt.q) {
+ // const q = decodeURIComponent(opt.q);
+ // const params = parseQueryString(q.split("?")[1]);
+ // Object.assign(options, params);
+ // } else {
+ // Object.assign(options, opt);
+ // }
+ // console.log('options', options);
+ // if (options.shopId) {
+ // uni.cache.set('shopId', options.shopId)
+ // }
+
+ // 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
+ // })
+
+ // uni.setStorageSync('loadFinsh',true)
+
+
+ // if (options.inviteCode) {
+ // bindInvite(options)
+ // }
+ // },
+ 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 = returnQuery()
+
+
+ // 全局默认配置(可被页面覆盖)
+ const defaultShareConfig = {
+ title: shopInfo.shopName,
+ path: sharePath + '?' + query,
+ imageUrl: shopInfo.logo,
+ query,
+ // desc: '描述',
+ success: (res) => {
+ console.log('分享好友成功', res);
+ // 可加埋点等统一逻辑
+ },
+ fail: (err) => {
+ console.error('分享好友失败', err);
+ }
+ };
+
+
+
+
+
+ // 页面自定义配置覆盖全局
+ const pageShareConfig = this.$options.shareConfig || {};
+ console.log('mixIn onShareAppMessage', {
+ ...defaultShareConfig,
+ ...pageShareConfig
+ })
+ return {
+ ...defaultShareConfig,
+ ...pageShareConfig
+ };
+ },
+
+
+ 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];
+ 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 = returnQuery()
+
+ const defaultTimelineConfig = {
+ title: shopInfo.shopName,
+ path: sharePath + '?' + query,
+ imageUrl: shopInfo.logo,
+ query,
+ };
+
+ const pageTimelineConfig = this.$options.shareTimelineConfig || {};
+ return {
+ ...defaultTimelineConfig,
+ ...pageTimelineConfig
+ };
+ }
+};
\ No newline at end of file