Forráskód Böngészése

首页优化

(cherry picked from commit b42738e776df97812086892bd2a69b8b6019f05e)
lishanshan 4 hónapja
szülő
commit
7c7d23371c

+ 30 - 19
src/components/couponList.vue

@@ -44,7 +44,7 @@ const { send, data, pageCount, loading, page, pageSize, isLastPage, refresh, rel
     name: searchValue.value === '' ? '' : searchValue.value,
     relatedId: categoryType.value,
     type: couponType.value === '0' ? '' : couponType.value,
-    country: currentCity.value?.value === 'all' ? '' : currentCity.value?.value,
+    country: currentCity.value?.value === 'all' ? '' : currentCity.value.value,
 }), {
     initialPage: 1,
     initialPageSize: 7,
@@ -99,7 +99,7 @@ const downOption = reactive({
 })
 
 const upOption  = computed(() => ({
-    use: hasLogin.value,
+    use: true,
     auto: false,
     noMoreSize: 6,
     isBounce: true,
@@ -108,7 +108,7 @@ const upOption  = computed(() => ({
         size: pageSize.value,
     },
     empty: {
-        use: hasLogin.value,
+        use: true,
         tip: '暂无优惠券',
         // btnText: '刷新试试',
         icon: '/static/images/mescroll-empty1.png',
@@ -168,10 +168,22 @@ onLoad(async () => {
 })
 
 onHide(() => {
-
     areaStore.resetCurrentCity();
 })
 
+onShow(async () => {
+    // 登录后重新获取分类列表
+    if (hasLogin.value) {
+        couponType.value = '2'
+        // 重置分类类型
+        categoryType.value = '0'
+        searchValue.value = ''
+        await sendCategoryList()
+    }
+    // 重新获取优惠券数据
+    await send()
+})
+
 onUnload(() => {
     areaStore.resetCurrentCity();
 })
@@ -266,8 +278,8 @@ async function couponTypeChange(type) {
                     @click="couponTypeChange('3')">
                     满减券
                 </view>
-                <view :class="{ 'coupon_type_active': couponType === '1' }"
-                    @click="couponTypeChange('1')">
+                <view :class="{ 'coupon_type_active': couponType === '4' }"
+                    @click="couponTypeChange('4')">
                     兑换券
                 </view>
             </view>
@@ -301,7 +313,16 @@ async function couponTypeChange(type) {
             </view>
 
             <!-- coupon-list -->
-            <view class="invite-content-list">
+            <view v-if="!hasLogin" class="empty-container">
+                <view class="custom-empty"
+                :style="{
+                    backgroundImage: `url(${getImageUrl('@img/index/login_bg.png')})`,
+                    backgroundSize: 'cover',
+                    backgroundPosition: 'center'
+                }"/>
+                <view class="login-btn" @click="login">去登录</view>
+            </view>
+            <view v-else class="invite-content-list">
                 <!-- :style="{ height: `calc(100vh - ${topSafeAreaHeight}px - 70rpx - 88rpx - 20rpx - 176rpx)` }"> -->
                 <mescroll-uni id="mescrollContainer" :down="downOption" :up="upOption" :fixed="false" offset="70"
                     @init="mescrollInit" @down="downCallback" @up="upCallback" @emptyclick="reload">
@@ -323,8 +344,8 @@ async function couponTypeChange(type) {
                     <template v-else>
                         <view v-for="item in data" :key="item.templateId" class="invite-content-item">
                             <!-- <invite-item :data="item" /> -->
-                            <!-- 优惠券类型:1-兑换券,2-兑换券,3-满减券 -->
-                            <template v-if="item.type == '1'">
+                            <!-- 优惠券类型:4-兑换券,2-折扣券,3-满减券 -->
+                            <template v-if="item.type == '4'">
                                 <ExchangeCoupon :coupon="item" />
                             </template>
                             <template v-else>
@@ -337,15 +358,6 @@ async function couponTypeChange(type) {
                         <view class="loading-spinner" />
                         <text class="loading-text">加载中...</text>
                     </view>
-                    <view v-if="!hasLogin" class="empty-container">
-                        <view class="custom-empty"
-                        :style="{
-                            backgroundImage: `url(${getImageUrl('@img/index/login_bg.png')})`,
-                            backgroundSize: 'cover',
-                            backgroundPosition: 'center'
-                        }"/>
-                        <view class="login-btn" @click="login">去登录</view>
-                    </view>
                 </mescroll-uni>
             </view>
         </view>
@@ -354,7 +366,6 @@ async function couponTypeChange(type) {
 
 <style lang="scss" scoped>
 .invite-container {
-    // height: 100vh;
     padding: 0 20rpx 20rpx;
     margin-bottom: 20rpx;
     background: linear-gradient( 180deg, #FF8180 0%, rgba(255,127,92,0.49) 30%);

+ 1 - 1
src/hooks/useCouponShare.ts

@@ -20,7 +20,7 @@ export function useCouponShare() {
     // 复制成功提示
     const copySuccess = ref(false)
 
-    const redirectPath = ref('pages/home/home')
+    const redirectPath = ref('pages/home/index')
 
     // 获取分享短链的请求
     const {

+ 1 - 1
src/hooks/useShare.ts

@@ -28,7 +28,7 @@ interface ShareInfo {
  */
 const defaultOptions: Required<ShareOptions> = {
     title: '领券省心,消费超值,优质生活轻松开启!',
-    path: '/pages/home/home',
+    path: '/pages/home/index',
     imageUrl: `${getImageUrl('@img/share.png')}`,
     shareType: 'INVITE',
     showLoading: true,

+ 1 - 3
src/pages-A/shareCoupon/index.vue

@@ -106,8 +106,6 @@ const topSafeAreaHeight = safeAreaInsets?.top || 0
 const inviteCodeStore = useInviteCodeStore()
 const { inviteCode } = storeToRefs(inviteCodeStore)
 
-// import { c } from 'node_modules/vite/dist/node/types.d-aGj9QkWt'
-
 // 系统信息
 const systemInfo = ref({})
 
@@ -172,7 +170,7 @@ async function getWxacodeBase64() {
     // const res = await getWxacode(token.data.access_token, shareId.value)
     const res = await getWxQcCode({
         shareType: 'COUPON',
-        sharePath: 'pages/home/home',
+        sharePath: 'pages/home/index',
         shareContentId: shareId.value,
         width: 290,
     })

+ 1 - 1
src/pages-A/sharePage/index.vue

@@ -175,7 +175,7 @@ async function getWxacodeBase64() {
     // const res = await getWxacode(token.data.access_token, shareId.value)
     const res = await getWxQcCode({
         shareType: 'COUPON',
-        sharePath: 'pages/home/home',
+        sharePath: 'pages/home/index',
         shareContentId: shareId.value,
         width: 290,
     })

+ 1 - 0
src/pages-fg/login/login.vue

@@ -39,6 +39,7 @@ function checkAgreement() {
 }
 
 async function doLogin() {
+    
     if (tokenStore.hasLogin) {
         uni.navigateBack()
         return

+ 1 - 1
src/pages/my/my.vue

@@ -71,7 +71,7 @@ function handleLogout() {
                     complete: () => {
                         // #ifdef MP-WEIXIN
                         // 微信小程序,去首页
-                        uni.reLaunch({ url: '/pages/home/home' })
+                        uni.reLaunch({ url: '/pages/home/index' })
                         // #endif
                         // #ifndef MP-WEIXIN
                         // 非微信小程序,去登录页

+ 17 - 10
src/store/area.ts

@@ -56,23 +56,19 @@ export const useAreaStore = defineStore('area', () => {
                     
                     // 2.天地图逆地理编码 (经纬度 -> 获取城市信息)
                     await updateGeocode(res.latitude, res.longitude);    
-                    
-                    // 3. 首页默认当前城市
-                    const cityInfo = { 
-                        name: uni.getStorageSync('cityName'), 
-                        value: uni.getStorageSync('cityCode') 
-                    }
-                    initCurrentCity.value = cityInfo
-                    addLastSelectedCity(cityInfo)
+
+                    resolve()
+
                 },
                 fail: (err) => {
                     console.error('获取地理位置失败:', err)
                     // 获取失败时使用默认城市
-                    initCurrentCity.value = {
+                    const defaultCity = {
                         name: '太原市',
                         value: '140100',
                     }
-                    reject(err)
+                    initCurrentCity.value = defaultCity
+                    resolve(defaultCity)
                 },
             })
         })
@@ -102,6 +98,17 @@ export const useAreaStore = defineStore('area', () => {
                         // uni.setStorageSync('town', obj.town);
                         // uni.setStorageSync('townCode', obj.town_code.slice(3));
                         console.log('逆地理编码更新成功:', obj.city);
+
+                        //  添加位置历史记录
+                        const cityInfo = { 
+                            name: obj.city, 
+                            value: obj.city_code.slice(3) 
+                        }
+                        initCurrentCity.value = cityInfo
+                        addLastSelectedCity(cityInfo)
+                        
+                        // 3. 首页默认当前城市
+                        currentCity.value = cityInfo
                     }
                 }
             });

+ 1 - 1
src/store/inviteQCCode.ts

@@ -47,7 +47,7 @@ export const useInviteCodeStore = defineStore('inviteCode', () => {
     const fetchInviteCode = async () => {
         const res = await getWxQcCode({
             shareType: 'INVITE',
-            sharePath: 'pages/home/home',
+            sharePath: 'pages/home/index',
             width: 290,
         })
 

+ 5 - 4
src/store/token.ts

@@ -172,15 +172,16 @@ export const useTokenStore = defineStore(
                     await addInviteConversion(JSON.parse(uni.getStorageSync('shareParams')))
                 }
 
-                // 登录成功后获取地理位置
-                const areaStore = useAreaStore()
-                await areaStore.getLocationAndSetCity()
-
                 uni.showToast({
                     title: '登录成功',
                     icon: 'success',
                 })
                 cleanShareParams()
+
+                // 登录成功后获取地理位置
+                const areaStore = useAreaStore()
+                await areaStore.getLocationAndSetCity()
+
                 return res
             }
             catch (error) {