计算购物车钱之前

This commit is contained in:
wwz
2025-02-26 17:39:46 +08:00
parent f2513ef13a
commit 0ab9235f6c
33 changed files with 4225 additions and 903 deletions

View File

@@ -13,7 +13,8 @@ export const useNavbarStore = defineStore('navbar', {
isTransparent: false,
height: 0,
hasPlaceholder: true,
scrollTop: 0 //滚动高度
scrollTop: 0 ,//滚动高度
screenHeight:375
}),
actions: {
updateNavbarConfig(config) {
@@ -23,21 +24,21 @@ export const useNavbarStore = defineStore('navbar', {
uni.getSystemInfo({
success: (res) => {
const statusBarHeight = res.statusBarHeight;
// 总高度
this.screenHeight = res.screenHeight
let navBarHeight;
// 微信小程序的特殊处理
if (res.platform === 'weapp') {
if (res.uniPlatform === 'mp-weixin' || res.uniPlatform === 'mp-alipay') {
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
const topGap = menuButtonInfo.top - statusBarHeight;
const bottomGap = statusBarHeight + menuButtonInfo.height + topGap * 2 - (
menuButtonInfo.top + menuButtonInfo.height);
navBarHeight = menuButtonInfo.height + topGap + bottomGap;
navBarHeight = menuButtonInfo.height + topGap + bottomGap - 4;
} else if (uni.getSystemInfoSync().platform === 'ios') {
navBarHeight = 44;
} else {
navBarHeight = 48;
}
this.height = statusBarHeight + navBarHeight;
},
fail: (err) => {

View File

@@ -1,88 +0,0 @@
import {
defineStore
} from 'pinia';
import {
ref
} from 'vue';
import {
APIcustomlogin
} from '@/common/api/api.js'
export const Storelogin = defineStore('login', {
state: () => ({
token: '',
miniAppOpenId: '',
userInfo: ''
}),
actions: {
actionslogin() {
return new Promise((resolve, reject) => {
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
success: (data) => {
// 微信小程序环境
uni.getUserInfo({
provider: 'weixin',
success: async (infoRes) => {
let res = await APIcustomlogin({
code: data.code, //临时登录凭证
rawData: infoRes.rawData,
source: 'wechat'
})
if (res.code == 0) {
this.token = res.data.token
this.miniAppOpenId = res.data.userInfo
.miniAppOpenId
this.userInfo = res.data.userInfo
uni.cache.set('token', res.data.token);
uni.cache.set('miniAppOpenId', res.data
.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data
.userInfo);
}
resolve(true);
},
fail: (err) => {
reject(false);
}
});
}
});
// #endif
// #ifdef MP-ALIPAY
my.getAuthCode({
scopes: 'auth_base',
success: async (data) => {
console.log(data)
// 支付宝小程序环境
// my.getAuthUserInfo({
// success: async (infoRes) => {
let res = await APIcustomlogin({
code: data.authCode, //临时登录凭证
// rawData: JSON.stringify(infoRes),
source: 'alipay'
})
if (res.code == 0) {
this.token = res.data.token
this.miniAppOpenId = res.data.userInfo.miniAppOpenId
this.userInfo = res.data.userInfo
uni.cache.set('token', res.data.token);
uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo);
resolve(true);
}
},
fail: (err) => {
reject(false);
}
});
}
});
// #endif
}).catch((e) => {});
}
}
});

230
stores/user.js Normal file
View File

@@ -0,0 +1,230 @@
import {
defineStore
} from 'pinia';
import {
ref
} from 'vue';
import {
APIuserlogin,
APIuser
} from '@/common/api/api.js'
import {
APIproductqueryShop,
APIshopUserInfo
} from '@/common/api/product/product.js'
export const Storelogin = defineStore('login', {
state: () => ({
token: '',
miniAppOpenId: '',
userInfo: ''
}),
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'
})
if (res) {
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
.wechatOpenId)
uni.cache.set('userInfo', res
.userInfo);
}
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.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
})
}
}
});
export const productStore = defineStore('product', {
actions: {
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
// 扫码请求
scanCodeactions() {
return new Promise(async (resolve, reject) => {
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
uni.scanCode({
success: async (res) => {
let tableCode = this.getQueryString(
decodeURIComponent(res
.result),
'code')
// 储存卓玛
uni.cache.set('tableCode', tableCode)
if (tableCode) {
let data = await this.actionsproductqueryShop()
// -4请求登录
const store = Storelogin()
if (data.code == '-4') {
if (await store.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop()
}
}
if (uni.cache.get('productInfo')
.shopTableInfo && !uni
.cache.get('productInfo')
.shopTableInfo
.choseCount) {
uni.pro.navigateTo(
'/pagesOrder/orderAMeal/index', {
tableCode: tableCode,
shopId: uni.cache.get(
'shopId'),
})
} else {
uni.pro.navigateTo(
'product/index', {
tableCode: tableCode,
})
}
}
},
fail: (res) => {
console.log(111)
console.log(res)
}
});
// #endif
// #ifdef H5
if (uni.cache.get('tableCode')) {
let data = await this.actionsproductqueryShop()
// -4请求登录
const store = Storelogin()
if (data.code == '-4') {
if (await store.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop()
}
}
if (uni.cache.get('productInfo').shopTableInfo && !uni
.cache.get('productInfo').shopTableInfo.choseCount) {
uni.pro.navigateTo('/pagesOrder/orderAMeal/index', {
tableCode: uni.cache.get('tableCode'),
shopId: uni.cache.get('shopId'),
})
} else {
uni.pro.navigateTo('product/index', {
tableCode: uni.cache.get('tableCode'),
})
}
}
// #endif
})
},
// /通过桌码获取店铺信息
actionsproductqueryShop() {
return new Promise(async (resolve, reject) => {
try {
let res = await APIproductqueryShop({
tableCode: uni.cache.get('tableCode'),
})
// 店铺信息
uni.cache.set('shopTable', res.shopTable)
// 台桌信息
uni.cache.set('shopInfo', res.shopInfo)
uni.cache.set('shopId', res.shopTable.shopId)
// 当前用户距离店铺的米数
uni.cache.set('distance', res.distance)
resolve(res)
} catch (e) {
reject(false)
}
})
},
// 获取店铺会员信息
actionsproductqueryProduct() {
return new Promise(async (resolve, reject) => {
try {
let res = await APIshopUserInfo({
"shopId": uni.cache.get('shopId'),
"userId": uni.cache.get('userInfo').id
})
uni.cache.set('ShopUser', res)
resolve(true)
} catch (e) {
reject(false)
}
})
},
// 用户信息获取
actionsAPIuser() {
return new Promise(async (resolve, reject) => {
try {
let res = await APIuser()
uni.cache.set('userInfo', res);
resolve(true)
} catch (e) {
reject(false)
}
})
}
}
});