处理未登录情况

This commit is contained in:
2024-03-31 19:10:00 +08:00
parent a06d74934f
commit 935d56227d
8 changed files with 78 additions and 48 deletions

View File

@@ -131,7 +131,7 @@
<script lang='ts' setup>
import { assetsUrl } from '@/utils/assets';
import dayjs from 'dayjs';
import { formatTimeWithZeroPad, goPath } from '@/utils';
import { formatTimeWithZeroPad, goPath, isLogin } from '@/utils';
import SkuDialog from '@/components/sku-dialog.vue';
import CouponItem from './components/coupon-item.vue';
@@ -163,12 +163,14 @@ const recordList = ref<RecordBean[]>([]);
const currentPageNum = ref(1);
onLoad(async (e: any) => {
groupBuyBean.value = await getGroupBuyDetail(e.id);
groupBuyBean.value.goods.price = groupBuyBean.value.price;
bannerList.value = JSON.parse(groupBuyBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images);
countdown();
await fetchRecommendList();
await fetchBuyRecordList();
if(isLogin()) {
groupBuyBean.value = await getGroupBuyDetail(e.id);
groupBuyBean.value.goods.price = groupBuyBean.value.price;
bannerList.value = JSON.parse(groupBuyBean.value.content).filter((item: any) => item.type === 2).map((item: any) => item.images);
countdown();
await fetchRecommendList();
await fetchBuyRecordList();
}
});
onUnload(() => {

View File

@@ -14,16 +14,16 @@
</view>
</view>
<view class='user-info-card'>
<image class='user-avatar' :src='userInfo.image' mode='aspectFill' />
<text class='user-name primary-text-color'>{{ userInfo?.nickName }}</text>
<view class='user-info-card' @click.stop='goPath("/pages/mine/index")'>
<image class='user-avatar' :src='userInfo.image||defaultAvatar' mode='aspectFill' />
<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")'>
<text>{{ userInfo?.integration }}</text>
<text>{{ userInfo?.integration || 0 }}</text>
<text>积分</text>
</view>
<view class='divider' style='height: 83rpx' />
<view class='balance-view' @click.stop='goPath("/pages/mine/subs/recharge/index")'>
<text class='accent-text-color'>{{ userInfo?.balance }}</text>
<text class='accent-text-color'>{{ userInfo?.balance || 0 }}</text>
<text>余额()</text>
</view>
</view>
@@ -65,12 +65,12 @@
<script setup lang='ts'>
import { getCompanyInfo, getCompanyList } from '@/api/company';
import { useUserStore } from '@/store';
import { assetsUrl } from '@/utils/assets';
import { assetsUrl, defaultAvatar } from '@/utils/assets';
import { getCompanyId, goPath, isLogin, setCompanyId } from '@/utils';
import { storeToRefs } from 'pinia';
const store = useUserStore();
const { userInfo } = storeToRefs(store);
const userStore = useUserStore();
const { userInfo } = storeToRefs(userStore);
const bannerList = ref<string[]>([]);
const currentBannerIndex = ref(0);
const recommendBannerList = ref<string[]>([]);
@@ -103,19 +103,24 @@ onShow(async () => {
bannerList.value = data.bannerinx?.map((res: { src: string }) => res.src);
recommendBannerList.value = data.bannerhot?.map((res: { src: string }) => res.src);
getCompanyList(userInfo.value.maOpenId).then(res => {
const companyList = res.map((res: { company: any }) => res.company);
const userList = res.map((res: { user: any }) => res.user);
// if(!getCompanyId()) {
uni.showActionSheet({
itemList: companyList.map((res: { companyName: string }) => res.companyName),
success: (res) => {
setCompanyId(companyList[res.tapIndex].id);
store.setUserInfo(userList[res.tapIndex]);
}
});
// }
});
if(userInfo.value.maOpenId) {
getCompanyList(userInfo.value.maOpenId).then(res => {
const companyList = res.map((res: { company: any }) => res.company);
const userList = res.map((res: { user: any }) => res.user);
if(!getCompanyId()) {
uni.showActionSheet({
itemList: companyList.map((res: { companyName: string }) => res.companyName),
success: (res) => {
setCompanyId(companyList[res.tapIndex].id);
userStore.setUserInfo(userList[res.tapIndex]);
userStore.fetchTerminal();
}
});
}
});
} else {
await userStore.getProfile();
}
}
});

View File

@@ -40,7 +40,7 @@
<script setup lang='ts'>
import SkuDialog from '@/components/sku-dialog.vue';
import { assetsUrl } from '@/utils/assets';
import { goPath } from '@/utils';
import { goLogin, goPath, isLogin } from '@/utils';
import { getCategoryList, getGoodsList } from '@/api/goods';
import { CategoryBean, GoodsBean } from '@/api/goods/types';
import useShoppingCartStore from '@/store/modules/shoppingcart';
@@ -54,6 +54,11 @@ const categorySelectedIndex = ref<number>(0);
const goodsList = ref<GoodsBean[]>([]);
onLoad(() => {
if(!isLogin()) {
goLogin();
return;
}
fetchCategoryList();
});

View File

@@ -7,10 +7,10 @@
/>
<view class='top-row'>
<image :src='userInfo.image' />
<image :src='userInfo?.image||defaultAvatar' />
<view class='u-flex-column'>
<text>{{ userInfo.nickName }}</text>
<text>{{ userInfo.telephone }}</text>
<text>{{ userInfo?.nickName || '未登录' }}</text>
<text>{{ userInfo?.telephone }}</text>
</view>
<image :src='assetsUrl("ic_qrcode_white.png")' @click.stop='gotoPath("qrcode")' />
@@ -18,15 +18,15 @@
<view class='bottom-row'>
<view @click.stop='gotoPath("/pages/mine/subs/integral/index")'>
<text>{{ userInfo.integration }}</text>
<text>{{ userInfo?.integration||0 }}</text>
<text>积分</text>
</view>
<view @click.stop='gotoPath("/pages/mine/subs/recharge/index")'>
<text>{{ userInfo.balance }}</text>
<text>{{ userInfo?.balance||0 }}</text>
<text>余额</text>
</view>
<view @click.stop='gotoPath("/pages/mine/subs/coupon/index")'>
<text>3</text>
<text>{{ userInfo?.couponsCount || 0}}</text>
<text>优惠券</text>
</view>
</view>
@@ -45,7 +45,7 @@
<view v-for='(item,index) in orderActionList' :key='index' @click.stop='gotoPath(item.path)'>
<image :src='item.icon' />
<text>{{ item.title }}</text>
<text v-if='index==0&&userInfo.orderNum>0'>{{ userInfo.orderNum }}</text>
<text v-if='index==0&&userInfo?.orderNum>0'>{{ userInfo?.orderNum }}</text>
</view>
</view>
@@ -65,10 +65,10 @@
</template>
<script setup lang='ts'>
import { useUserStore } from '@/store';
import { assetsUrl } from '@/utils/assets';
import { goPath } from '@/utils';
import { assetsUrl, defaultAvatar } from '@/utils/assets';
import { goLogin, goPath, isLogin } from '@/utils';
import OfficialAccountDialog from '@/components/official-account-dialog.vue';
import { useUserStore } from '@/store';
const officialAccountDialogRef = ref();
@@ -124,6 +124,13 @@ title.value = import.meta.env.VITE_APP_TITLE;
const store = useUserStore();
const { userInfo } = storeToRefs(store);
onLoad(() => {
if(!isLogin()) {
goLogin();
return;
}
});
const gotoPath = (path: string) => {
if(path === 'follow_official_account') {
showOfficialAccountDialog();

View File

@@ -2,7 +2,7 @@
<view class='content'>
<view class='top-card-view'>
<image class='bg-image' :src='assetsUrl("test_bg.png")' />
<image class='avatar-image' :src='userInfo.image' />
<image class='avatar-image' :src='params.avatarUrl' />
<text>{{ userInfo.name }}</text>
<text>{{ userInfo.levelName }}</text>
</view>
@@ -80,7 +80,7 @@ const params = ref<{
});
onLoad(() => {
store.getProfile();
// store.getProfile();
});
const chooseAvatar = (e: any) => {

View File

@@ -3,14 +3,14 @@
<view class='member-info-view'>
<image :src='assetsUrl("ic_crown.png")' />
<view class='flex flex-col'>
<text>{{ userInfo.levelName}}</text>
<text>{{ userInfo?.levelName }}</text>
<view />
</view>
</view>
<view class='qrcode-card'>
<view class='balance-view'>
<text class='balance-text'>账户余额{{ userInfo.balance || 0 }}</text>
<text class='balance-text'>账户余额{{ userInfo?.balance || 0 }}</text>
<view class='btn-recharge' @click.stop='goPath("/pages/mine/subs/recharge/index")'>
<text>去充值</text>
<image :src='assetsUrl("ic_arrow_right.png")' />
@@ -33,8 +33,8 @@
<text>卡信息</text>
</view>
<text>店铺名称{{userInfo.creatorName}}</text>
<text>{{ userInfo.storeId }}</text>
<text>店铺名称{{ userInfo?.creatorName }}</text>
<text>{{ userInfo?.storeId }}</text>
</view>
</view>
@@ -47,8 +47,7 @@ import { assetsUrl } from '@/utils/assets';
import { generateBarCode, generateQrCode } from '@/api/common';
import { getDynamicCode } from '@/api/user';
import { useUserStore } from '@/store';
import { goPath } from '@/utils';
import { use } from 'licia';
import { goLogin, goPath, isLogin } from '@/utils';
const store = useUserStore();
const { userInfo } = storeToRefs(store);
@@ -58,6 +57,10 @@ const codeContent = ref<string>('');
const codeRefreshInterval = ref(30);
onLoad(() => {
if(!isLogin()) {
goLogin();
return;
}
generateCode();
setInterval(() => {

View File

@@ -1 +1,2 @@
export const assetsUrl = (name) => `/static/images/${name}`;
export const assetsUrl = (name: string) => `/static/images/${name}`;
export const defaultAvatar = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132';

View File

@@ -42,6 +42,13 @@ export function goPath(path: string) {
});
}
export function goLogin() {
uni.navigateTo({
url: '/pages/common/login/index'
}).then(r => {
});
}
export function formatTimeWithZeroPad(num: number): string {
return num < 10 ? '0' + num : num + '';
}