bug修复

This commit is contained in:
Waiting 2024-06-01 20:06:30 +08:00
parent 4344adeb0b
commit 3945b36b0a
14 changed files with 124 additions and 35 deletions

View File

@ -1,19 +1,26 @@
<script lang='ts'>
import { mpUpdate, setCompanyId, setReferrerUserId, setRegisterStoreId } from '@/utils';
import {
getCompanyId,
getRegisterStoreId,
mpUpdate,
setCompanyId,
setReferrerUserId,
setRegisterStoreId
} from '@/utils';
import { Logger } from '@/utils/common/logger';
const logger = new Logger();
export default {
onLaunch: async (options: any) => {
console.log('App Launch options ', options);
const miniProgram = uni.getAccountInfoSync().miniProgram;
const env = miniProgram.envVersion;
console.log(`App Launch options ${env}: `, options);
//
if(env === 'release') {
logger.info(`launch options ${env}: `, options);
logger.info(`App Launch options ${env}: `, options);
async function getVersionStatus() {
return new Promise((resolve, reject) => {
@ -102,6 +109,8 @@ export default {
}
}
logger.info(`App Launch options ${env}: { companyId: `, getCompanyId() + ', storeId: ' + getRegisterStoreId() + ' }');
// #ifdef MP
mpUpdate();
// #endif
@ -114,7 +123,9 @@ export default {
},
globalData: {
logger: logger
logger: logger,
companyId: getCompanyId(),
storeId: getRegisterStoreId()
}
};

View File

@ -31,6 +31,7 @@ export interface LoginResult {
user: UserBean;
userInfo: any;
token: string;
maOpenId: string;
}
export interface IntegralBean {

View File

@ -3,7 +3,7 @@
<view class='swiper-container'>
<swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'>
<swiper-item v-for='(item,index) in bannerList' :key='index'>
<image :src='item||defaultImage' mode='aspectFill'/>
<image :src='item||defaultImage' mode='aspectFill' />
</swiper-item>
</swiper>
<view class='indicator'>
@ -189,13 +189,19 @@ onUnload(() => {
}
});
onShareAppMessage((e) => {
return {
title: groupBuyBean.value?.goods?.name || 'VIP顾客中心',
path: `/pages/common/groupbuy/detail?id=${groupBuyBean.value?.id}&companyId=${getApp().globalData?.companyId}&storeId=${getApp().globalData?.storeId}`
};
});
const isNotStated = () => {
return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now());
};
const isPending = () => {
return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now());
;
};
const isEnded = () => {

View File

@ -37,11 +37,6 @@ async function wechatLogin() {
return;
}
if(!getRegisterStoreId()) {
showToast('请从公众号消息窗口点击店名打开小程序');
return;
}
userStore.login().then(() => {
uni.hideLoading();
uni.reLaunch({ url: '/pages/home/index' });

View File

@ -48,13 +48,13 @@ import { ref } from 'vue';
import { getTelephone } from '@/api/user';
import { useUserStore } from '@/store';
import { assetsUrl } from '@/utils/assets';
import { getSessionKey, showToast } from '@/utils';
import { getRegisterStoreId, getSessionKey, showToast } from '@/utils';
import dayjs from 'dayjs';
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const birthday = ref(userInfo.value.birthday);
const birthday = ref(userInfo.value.birthday || dayjs().format('YYYY-MM-DD'));
const nickName = ref(userInfo.value.nickName);
const gender = ref(userInfo.value.gender);
const telephone = ref(userInfo.value.telephone);
@ -109,13 +109,18 @@ const changeGender = (index: number) => {
};
const save = async () => {
if(!getRegisterStoreId()) {
showToast('请从公众号消息窗口点击店名打开小程序');
return;
}
await uni.showLoading();
const registerForm = {
image: avatarUrl.value,
avatarUrl: avatarUrl.value,
nickName: nickName.value,
telephone: telephone.value,
birthday: dayjs(birthday.value).format("YYYY-MM-DD HH:mm:ss"),
birthday: dayjs(birthday.value).format('YYYY-MM-DD HH:mm:ss'),
gender: gender.value
};

View File

@ -72,7 +72,7 @@ import CompanyDialog from '@/components/company-dialog.vue';
import { getCompanyList } from '@/api/company';
import { useUserStore } from '@/store';
import { assetsUrl, defaultAvatar, defaultImage } from '@/utils/assets';
import { getCompanyId, goPath, isLogin } from '@/utils';
import { getCompanyId, getOpenId, goPath, isLogin } from '@/utils';
import { storeToRefs } from 'pinia';
import { UserBean } from '@/store/modules/user/types';
@ -128,35 +128,73 @@ onLoad((e) => {
onShow(async () => {
if(isLogin()) {
// userStore.getProfile();
if(userInfo.value.maOpenId) {
fetchCompanyList();
} else {
await userStore.getProfile();
}
fetchCompanyList();
} else {
// setToken('42ae187265fb4688804fd294cbcf99f1')
uni.showModal({
title: '提示',
content: '您还未登录,请先登录',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/common/login/index');
}
}
});
}
});
const switchCompany = () => {
fetchCompanyList((companyList: any[], userList: any[]) => {
companyDialogRef.value.show(getCompanyId(), (index: number) => {
companyDialogRef.value.show(getApp().globalData?.companyId, (index: number) => {
userStore.setUserInfo(userList[index]);
userStore.setCompanyInfo(companyList[index]);
avatarModifyRemind();
});
});
};
function avatarModifyRemind() {
setTimeout(() => {
if(userInfo.value.image === defaultAvatar) {
uni.showModal({
title: '提示',
content: '为了提供更优质的个性化服务,请先修改头像',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/mine/subs/profile/index');
}
}
});
}
}, 300);
}
const fetchCompanyList = (fn: any = undefined) => {
const maOpenId = userInfo.value?.maOpenId || (userList.value.filter((res: UserBean) => res?.maOpenId !== '')[0]?.maOpenId);
const maOpenId = getOpenId() || userInfo.value?.maOpenId || (userList.value.filter((res: UserBean) => res?.maOpenId !== '')[0]?.maOpenId);
getCompanyList(maOpenId).then(res => {
companyList.value = res.map((res: { company: any }) => res.company);
userList.value = res.map((res: { user: any }) => res.user);
if(companyList.value.length === 0) {
uni.showModal({
title: '提示',
content: '当前店铺还未注册,请先注册',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/common/register/index');
}
}
});
return;
}
if(fn != undefined && fn instanceof Function) {
fn(companyList.value, userList.value);
} else {
let index = companyList.value.findIndex((res: { id: string }) => res.id === getCompanyId());
let index = companyList.value.findIndex((res: { id: string }) => res.id === getApp().globalData?.companyId);
//
if(index < 0) {
goPath('/pages/common/register/index');
@ -164,6 +202,7 @@ const fetchCompanyList = (fn: any = undefined) => {
}
userStore.setUserInfo(userList.value[index]);
userStore.setCompanyInfo(companyList.value[index]);
avatarModifyRemind();
}
});
};

View File

@ -38,7 +38,7 @@ const coupons = ref<CouponBean[]>([]);
const fetchData = async (status: number) => {
const { list } = await getCouponList({
companyId: getCompanyId(),
companyId: getApp()?.globalData?.companyId,
memberId: userInfo.value?.id,
status: status,
pageNum: 1,

View File

@ -147,6 +147,13 @@ onLoad(async (e: any) => {
uni.hideLoading();
});
onShareAppMessage((e) => {
return {
title: goodsBean.value?.name || 'VIP顾客中心',
path: `/pages/common/groupbuy/detail?id=${goodsBean.value?.id}&companyId=${getApp().globalData?.companyId}&storeId=${getApp().globalData?.storeId}`
};
});
const getStockColorCount = computed(() => {
const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName)))
.map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!);

View File

@ -48,7 +48,7 @@
<view class='c-flex-row'>
<text>生日</text>
<picker mode='date' :disabled='(userInfo.birthday?.length||0)!=0' @change='changeDate'>
<text>{{ dayjs(params?.birthday).format('YYYY-MM-DD') || '请选择生日' }}</text>
<text>{{ dayjs(params?.birthday || Date.now()).format('YYYY-MM-DD') || '请选择生日' }}</text>
</picker>
</view>
</view>

View File

@ -1,7 +1,15 @@
import { defineStore } from 'pinia';
import type { providerType, UserBean } from './types';
import { getTerminal, getUserProfile, login, logout as userLogout, register } from '@/api/user/index';
import { clearToken, getCompanyId, getRegisterStoreId, setCompanyId, setSessionKey, setToken } from '@/utils/auth';
import {
clearToken,
getCompanyId,
getRegisterStoreId,
setCompanyId,
setOpenId,
setSessionKey,
setToken
} from '@/utils/auth';
import type { RegisterParams, TerminalBean } from '@/api/user/types';
import { getCompanyInfo } from '@/api/company';
@ -87,6 +95,7 @@ const useUserStore = defineStore('user', {
getApp().globalData?.logger.info('login result: ', res);
setToken(res.token);
setSessionKey(res.sessionKey);
setOpenId(res.maOpenId)
await this.setUserInfo(res.user);
// }
resolve(res);

View File

@ -1,4 +1,3 @@
export const assetsUrl = (name: string) => `https://img.lakeapp.cn/wx/images/${name}`;
export const defaultAvatar = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';
export const defaultImage = '/static/images/ic_noimage.svg';

View File

@ -1,5 +1,6 @@
const TokenKey = 'accessToken';
const SessionKey = 'sessionKey';
const OpenIdKey = 'openId';
const CompanyIdKey = 'companyId';
const ReferrerUserIdKey = 'referrerUserId';
const RegisterStoreIdKey = 'storeId';
@ -22,10 +23,18 @@ function getSessionKey() {
return uni.getStorageSync(SessionKey);
}
function setSessionKey(sessionKey: string){
function setSessionKey(sessionKey: string) {
uni.setStorageSync(SessionKey, sessionKey);
}
function getOpenId() {
return uni.getStorageSync(OpenIdKey);
}
function setOpenId(openId: string) {
uni.setStorageSync(OpenIdKey, openId);
}
function getCompanyId() {
return uni.getStorageSync(CompanyIdKey);
}
@ -63,6 +72,8 @@ export {
setToken,
getSessionKey,
setSessionKey,
getOpenId,
setOpenId,
getCompanyId,
setCompanyId,
getReferrerUserId,

View File

@ -13,18 +13,24 @@ export class Logger {
info(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.info(key, value);
} else {
console.info(key, value);
}
}
warn(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.warn(key, value);
}else {
console.warn(key, value);
}
}
error(key: string, value: any) {
if(this.env === 'release' || this.env === 'trial') {
this.logger.error(key, value);
}else {
console.error(key, value);
}
}
}

View File

@ -1,7 +1,7 @@
import type { HttpError, HttpRequestConfig, HttpResponse } from 'uview-plus/libs/luch-request';
import { getCompanyId, getToken } from '@/utils/auth';
import useUserStore from '@/store/modules/user';
import { getToken } from '@/utils/auth';
import { showMessage } from '@/utils/request/status';
import { useUserStore } from '@/store';
// 是否正在刷新token的标记
let isRefreshing: boolean = false;
@ -22,7 +22,7 @@ function requestInterceptors() {
const token = getToken();
if(token && config.header) {
config.header.token = token;
config.header.companyid = getCompanyId();
config.header.companyid = getApp().globalData?.companyId;
// config.header.contentType = "x-www-form-urlencoded"
}
@ -53,7 +53,7 @@ function responseInterceptors() {
return data;
}
getApp().globalData?.logger.info('response: ', config);
getApp().globalData?.logger.info('response: ', data);
// 请求成功则返回结果
if(data.code === 200 || data?.retcode == 0) {
@ -61,7 +61,7 @@ function responseInterceptors() {
}
// 登录状态失效,重新登录
if(data.code === 401) {
if(data.code === 4011) {
// 是否在获取token中,防止重复获取
if(!isRefreshing) {
// 修改登录状态为true