封装分享功能
This commit is contained in:
116
stores/user.js
116
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) => {
|
||||
|
||||
Reference in New Issue
Block a user