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

View File

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

View File

@ -3,7 +3,7 @@
<view class='swiper-container'> <view class='swiper-container'>
<swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'> <swiper class='swiper' :interval='1500' :duration='1000' @change='swiperChange'>
<swiper-item v-for='(item,index) in bannerList' :key='index'> <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-item>
</swiper> </swiper>
<view class='indicator'> <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 = () => { const isNotStated = () => {
return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now()); return dayjs(groupBuyBean.value?.startDate).isAfter(Date.now());
}; };
const isPending = () => { const isPending = () => {
return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now()); return dayjs(groupBuyBean.value?.startDate).isBefore(Date.now()) && dayjs(groupBuyBean.value?.endDate).isAfter(Date.now());
;
}; };
const isEnded = () => { const isEnded = () => {

View File

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

View File

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

View File

@ -72,7 +72,7 @@ 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, getOpenId, goPath, isLogin } from '@/utils';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { UserBean } from '@/store/modules/user/types'; import { UserBean } from '@/store/modules/user/types';
@ -128,35 +128,73 @@ onLoad((e) => {
onShow(async () => { onShow(async () => {
if(isLogin()) { if(isLogin()) {
// userStore.getProfile(); // userStore.getProfile();
if(userInfo.value.maOpenId) { fetchCompanyList();
fetchCompanyList();
} else {
await userStore.getProfile();
}
} else { } else {
// setToken('42ae187265fb4688804fd294cbcf99f1') // setToken('42ae187265fb4688804fd294cbcf99f1')
uni.showModal({
title: '提示',
content: '您还未登录,请先登录',
showCancel: true,
success: (res) => {
if(res.confirm) {
goPath('/pages/common/login/index');
}
}
});
} }
}); });
const switchCompany = () => { const switchCompany = () => {
fetchCompanyList((companyList: any[], userList: any[]) => { fetchCompanyList((companyList: any[], userList: any[]) => {
companyDialogRef.value.show(getCompanyId(), (index: number) => { companyDialogRef.value.show(getApp().globalData?.companyId, (index: number) => {
userStore.setUserInfo(userList[index]); userStore.setUserInfo(userList[index]);
userStore.setCompanyInfo(companyList[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 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 => { getCompanyList(maOpenId).then(res => {
companyList.value = res.map((res: { company: any }) => res.company); companyList.value = res.map((res: { company: any }) => res.company);
userList.value = res.map((res: { user: any }) => res.user); 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) { if(fn != undefined && fn instanceof Function) {
fn(companyList.value, userList.value); fn(companyList.value, userList.value);
} else { } 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) { if(index < 0) {
goPath('/pages/common/register/index'); goPath('/pages/common/register/index');
@ -164,6 +202,7 @@ const fetchCompanyList = (fn: any = undefined) => {
} }
userStore.setUserInfo(userList.value[index]); userStore.setUserInfo(userList.value[index]);
userStore.setCompanyInfo(companyList.value[index]); userStore.setCompanyInfo(companyList.value[index]);
avatarModifyRemind();
} }
}); });
}; };

View File

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

View File

@ -147,6 +147,13 @@ onLoad(async (e: any) => {
uni.hideLoading(); 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 getStockColorCount = computed(() => {
const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName))) const list = Array.from(new Set(goodsBean.value?.stocks?.map(item => item.colorName)))
.map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!); .map(colorName => goodsBean.value?.stocks?.find(item => item.colorName === colorName)!);

View File

@ -48,7 +48,7 @@
<view class='c-flex-row'> <view class='c-flex-row'>
<text>生日</text> <text>生日</text>
<picker mode='date' :disabled='(userInfo.birthday?.length||0)!=0' @change='changeDate'> <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> </picker>
</view> </view>
</view> </view>

View File

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

View File

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

View File

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

View File

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