bug修复

This commit is contained in:
Waiting 2024-05-20 00:49:16 +08:00
parent 6cd0361f33
commit 448ee810de
5 changed files with 151 additions and 44 deletions

View File

@ -1,7 +1,7 @@
<script setup lang='ts'> <script setup lang='ts'>
import { mpUpdate, setCompanyId, setReferrerUserId, setRegisterStoreId } from '@/utils'; import { mpUpdate, setCompanyId, setReferrerUserId, setRegisterStoreId } from '@/utils';
onLaunch((options) => { onLaunch(async (options) => {
console.log('App Launch options ', options); console.log('App Launch options ', options);
const miniProgram = uni.getAccountInfoSync().miniProgram; const miniProgram = uni.getAccountInfoSync().miniProgram;
@ -9,19 +9,31 @@ onLaunch((options) => {
// //
if(env === 'release' || env === 'trial') { if(env === 'release' || env === 'trial') {
uni.request({ async function getVersionStatus() {
url: 'https://api.lakeapp.cn/wechat/version_info', return new Promise((resolve, reject) => {
success(res) { uni.request({
console.log(res); url: 'https://api.lakeapp.cn/wechat/version_info',
success(res) {
console.log(res);
resolve(res);
},
fail(exception) {
reject(exception);
}
});
}).then((res) => {
const { version, audit } = res.data; const { version, audit } = res.data;
// if(miniProgram.version === version && audit == 1) { // if(miniProgram.version === version && audit == 1) {
if(audit == 1) { if(audit == 1) {
setCompanyId('1150930317231112193'); setCompanyId('1150930317231112193');
setRegisterStoreId('1150930317436633090'); setRegisterStoreId('1150930317436633090');
} }
} });
}); }
await getVersionStatus();
} }
// trial,develop // trial,develop
else { else {
setCompanyId('1150930317231112193'); setCompanyId('1150930317231112193');
@ -30,6 +42,8 @@ onLaunch((options) => {
if(options?.query) { if(options?.query) {
// options.query.scene = 'companyId%3D1150930317231112193%26wxOpenId%3D111%26ticketId%3D123456%26storeId%3D1150930317436633090'
//id //id
if(options.query.referrerUserId) { if(options.query.referrerUserId) {
setReferrerUserId(options.query.referrerUserId); setReferrerUserId(options.query.referrerUserId);
@ -46,12 +60,20 @@ onLaunch((options) => {
} }
if(options?.query.scene) { if(options?.query.scene) {
//id function getQueryParam(queryParams: string, key: string) {
const params = decodeURIComponent(options?.query.scene); let regex = new RegExp('(?:[?&]|^)' + key + '=([^&]+)'),
if(params.split('=')[0] === 'storeId') { match = queryParams.match(regex);
setRegisterStoreId(params.split('=')[1]); return match && match[1];
} }
//id
const params = decodeURIComponent(options?.query.scene);
if(params.includes('companyId')) {
setCompanyId(getQueryParam(params, 'companyId') || '');
}
if(params.includes('storeId')) {
setRegisterStoreId(getQueryParam(params, 'storeId') || '');
}
if(options?.query.scene === 'edit_avatar_nickname') { if(options?.query.scene === 'edit_avatar_nickname') {
setTimeout(() => { setTimeout(() => {
uni.reLaunch({ uni.reLaunch({

View File

@ -0,0 +1,86 @@
<template>
<uni-popup ref='popupRef' type='bottom' :mask-click='false' @touchmove.stop.prevent=''>
<view class='content'>
<text class='title'>切换门店</text>
<scroll-view scroll-y style='max-height: 600rpx;padding: 15rpx'>
<view class='store-item' v-for='(item, index) in companyList' :key='index' @click='() => {
handleClick(index)
}'>
<text>{{ item?.companyName || '' }}</text>
</view>
</scroll-view>
<view class='close-btn primary-button' @click='close'>
<text>取消</text>
</view>
</view>
</uni-popup>
</template>
<script lang='ts' setup>
defineProps({
companyList: {
type: Array,
default: () => []
}
});
const popupRef = ref();
let callback: Function;
const show = (fn: Function) => {
callback = fn;
popupRef.value.open();
};
const handleClick = (index: number) => {
callback(index);
close();
};
const close = () => {
popupRef.value.close();
};
defineExpose({
show, close
});
</script>
<style lang='scss' scoped>
.content {
display: flex;
flex-direction: column;
background: #FFFFFF;
border-radius: 20rpx 20rpx 0 0;
padding: 20rpx 30rpx 30rpx 30rpx;
.title {
display: flex;
align-self: center;
font-size: 30rpx;
font-weight: bold;
padding: 20rpx;
}
.store-item {
display: flex;
flex-direction: column;
font-size: 35rpx;
color: #333333;
//padding: 20rpx 20rpx;
}
.store-item:after {
content: '';
background: #F5F5F5;
height: 0.5rpx;
width: 100%;
margin: 25rpx 0;
}
.close-btn {
background: #F5F5F5;
color: #333333;
}
}
</style>

View File

@ -15,7 +15,7 @@
</view> </view>
<view class='user-info-card' @click.stop='goPath("/pages/mine/index")'> <view class='user-info-card' @click.stop='goPath("/pages/mine/index")'>
<image class='user-avatar' :src='userInfo.image||defaultAvatar' mode='aspectFill' /> <image class='user-avatar' :src='userInfo?.image||defaultAvatar' mode='aspectFill' />
<text class='user-name primary-text-color'>{{ userInfo?.nickName || '点击注册会员' }}</text> <text class='user-name primary-text-color'>{{ userInfo?.nickName || '点击注册会员' }}</text>
<view class='integral-view primary-text-color' @click.stop='goPath("/pages/mine/subs/integral/index")'> <view class='integral-view primary-text-color' @click.stop='goPath("/pages/mine/subs/integral/index")'>
<text>{{ userInfo?.integration || 0 }}</text> <text>{{ userInfo?.integration || 0 }}</text>
@ -64,15 +64,19 @@
</view> </view>
</view> </view>
</view> </view>
<CompanyDialog ref='companyDialogRef' :companyList='companyList' />
</template> </template>
<script setup lang='ts'> <script setup lang='ts'>
import CompanyDialog from '@/components/company-dialog.vue';
import { getCompanyList } from '@/api/company'; import { getCompanyList } from '@/api/company';
import { useUserStore } from '@/store'; import { useUserStore } from '@/store';
import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets'; import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets';
import { getCompanyId, goPath, isLogin } from '@/utils'; import { getCompanyId, goPath, isLogin } from '@/utils';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { UserBean } from '@/store/modules/user/types';
const companyDialogRef = ref();
const userStore = useUserStore(); const userStore = useUserStore();
const { userInfo, companyConfigInfo } = storeToRefs(userStore); const { userInfo, companyConfigInfo } = storeToRefs(userStore);
const currentBannerIndex = ref(0); const currentBannerIndex = ref(0);
@ -94,6 +98,8 @@ const submenuList = [
path: '/pages/home/subs/group/join' path: '/pages/home/subs/group/join'
} }
]; ];
const companyList = ref([]);
const userList = ref<UserBean[]>([]);
onMounted(() => { onMounted(() => {
wx.getPrivacySetting({ wx.getPrivacySetting({
@ -132,42 +138,30 @@ onShow(async () => {
}); });
const switchCompany = () => { const switchCompany = () => {
// getCompanyList(userInfo.value.maOpenId).then(res => {
// const companyList = res.map((res: { company: any }) => res.company);
// const userList = res.map((res: { user: any }) => res.user);
// uni.showActionSheet({
// itemList: companyList.map((res: { companyName: string }) => res.companyName),
// success: (res) => {
// userStore.setUserInfo(userList[res.tapIndex]);
// userStore.setCompanyInfo(companyList[res.tapIndex]);
// }
// });
// });
fetchCompanyList((companyList: any[], userList: any[]) => { fetchCompanyList((companyList: any[], userList: any[]) => {
uni.showActionSheet({ companyDialogRef.value.show((index: number) => {
itemList: companyList.map((res: { companyName: string }) => res.companyName), userStore.setUserInfo(userList[index]);
success: (res) => { userStore.setCompanyInfo(companyList[index]);
userStore.setUserInfo(userList[res.tapIndex]);
userStore.setCompanyInfo(companyList[res.tapIndex]);
}
}); });
}); });
}; };
const fetchCompanyList = (fn: any = undefined) => { const fetchCompanyList = (fn: any = undefined) => {
getCompanyList(userInfo.value.maOpenId).then(res => { const maOpenId = userInfo.value?.maOpenId || (userList.value.filter((res: UserBean) => res?.maOpenId !== '')[0]?.maOpenId);
const companyList = res.map((res: { company: any }) => res.company); getCompanyList(maOpenId).then(res => {
const userList = res.map((res: { user: any }) => res.user); companyList.value = res.map((res: { company: any }) => res.company);
userList.value = res.map((res: { user: any }) => res.user);
if(fn != undefined && fn instanceof Function) { if(fn != undefined && fn instanceof Function) {
fn(companyList, userList); fn(companyList.value, userList.value);
} else { } else {
let index = companyList.findIndex((res: { id: string }) => res.id === getCompanyId()); let index = companyList.value.findIndex((res: { id: string }) => res.id === getCompanyId());
if(index < 0) { if(index < 0) {
index = 0; index = 0;
} }
userStore.setUserInfo(userList[index]); userStore.setUserInfo(userList.value[index]);
userStore.setCompanyInfo(companyList[index]); userStore.setCompanyInfo(companyList.value[index]);
} }
// uni.showActionSheet({ // uni.showActionSheet({
// itemList: companyList.map((res: { companyName: string }) => res.companyName), // itemList: companyList.map((res: { companyName: string }) => res.companyName),
// success: (res) => { // success: (res) => {

View File

@ -52,16 +52,16 @@ const useUserStore = defineStore('user', {
// } // }
getUserDiscount(): number { getUserDiscount(): number {
if(this.userInfo.levelEntity?.discount > 0 && this.userInfo.levelEntity?.discount < 10) { if(this.userInfo?.levelEntity?.discount > 0 && this.userInfo?.levelEntity?.discount < 10) {
return this.userInfo.levelEntity?.discount / 10; return this.userInfo?.levelEntity?.discount / 10;
} else if(this.userInfo.levelEntity?.discount >= 10 && this.userInfo.levelEntity?.discount <= 100) { } else if(this.userInfo?.levelEntity?.discount >= 10 && this.userInfo?.levelEntity?.discount <= 100) {
return this.userInfo.levelEntity?.discount / 100; return this.userInfo?.levelEntity?.discount / 100;
} }
return 1; return 1;
}, },
getRealGoodsPrice: (state) => (price: number, priceExt: number) => { getRealGoodsPrice: (state) => (price: number, priceExt: number) => {
return state.userInfo.salePrice == 'price_ext' ? priceExt||0 : price; return state.userInfo.salePrice == 'price_ext' ? priceExt || 0 : price;
} }
}, },
@ -71,8 +71,12 @@ const useUserStore = defineStore('user', {
this.userInfo = partial as UserBean; this.userInfo = partial as UserBean;
// this.userInfo.levelEntity?.discount = 79; // this.userInfo.levelEntity?.discount = 79;
// this.userInfo.salePrice = 'price_ext'; // this.userInfo.salePrice = 'price_ext';
this.userInfo.userDiscount = this.getUserDiscount; if(this.userInfo) {
await setCompanyId(this.userInfo.companyId); this.userInfo.userDiscount = this.getUserDiscount;
await setCompanyId(this.userInfo.companyId);
} else {
await clearToken();
}
await this.fetchTerminal(); await this.fetchTerminal();
await this.fetchCompanyInfo(); await this.fetchCompanyInfo();
}, },
@ -178,7 +182,7 @@ const useUserStore = defineStore('user', {
}, },
async fetchTerminal() { async fetchTerminal() {
this.terminalInfo = await getTerminal(this.userInfo.companyId); this.terminalInfo = await getTerminal(this.userInfo?.companyId);
} }
} }
}); });

View File

@ -7,6 +7,7 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
CompanyDialog: typeof import('./../src/components/company-dialog.vue')['default']
OfficialAccountDialog: typeof import('./../src/components/official-account-dialog.vue')['default'] OfficialAccountDialog: typeof import('./../src/components/official-account-dialog.vue')['default']
PageNav: typeof import('./../src/components/page-nav/page-nav.vue')['default'] PageNav: typeof import('./../src/components/page-nav/page-nav.vue')['default']
PaymentButton: typeof import('./../src/components/payment-button.vue')['default'] PaymentButton: typeof import('./../src/components/payment-button.vue')['default']