Browse Source

refactor(app): 优化购物车功能和mall页面逻辑

- 在购物车页面添加query对象以优化请求参数管理
- 在mall页面添加动态query计算和handleChange函数
- 更新产品组件,添加购物车变更事件
- 优化用户权限管理,统一登录相关逻辑- 修复设计师首页分享图片链接
EvilDragon 4 months ago
parent
commit
7d92113b7c

+ 14 - 11
packages/app/src/composables/permissions.ts

@@ -6,31 +6,34 @@ export const usePermissions = () => {
   const { isLogined, isDesigner } = storeToRefs(userStore)
   const routes = [
     { path: '/pages/mine/homepage/index', meta: { canNotLogin: false } },
-    { path: '/pages/material/mini-class/index', meta: { canNotLogin: false, showToast: true } },
-    { path: '/pages/material/recommend/index', meta: { canNotLogin: false, showToast: true } },
-    { path: '/pages/publish/moment/index', meta: { canNotLogin: false, showToast: true } },
-    { path: '/pages/publish/moment/index', meta: { canNotLogin: false, showToast: true } },
-    { path: '/pages/messages/index', meta: { canNotLogin: false, showToast: true } },
-    { path: '/pages/mine/setting/index', meta: { canNotLogin: false, showToast: true } },
+    {
+      path: '/pages/material/mini-class/index',
+      meta: { canNotLogin: false, toLogin: true },
+    },
+    { path: '/pages/material/recommend/index', meta: { canNotLogin: false, toLogin: true } },
+    { path: '/pages/publish/moment/index', meta: { canNotLogin: false, toLogin: true } },
+    { path: '/pages/publish/moment/index', meta: { canNotLogin: false, toLogin: true } },
+    { path: '/pages/messages/index', meta: { canNotLogin: false, toLogin: true } },
+    { path: '/pages/mine/setting/index', meta: { canNotLogin: false, toLogin: true } },
     {
       path: '/pages/mine/homepage/statistics/index',
-      meta: { canNotLogin: false, showToast: true },
+      meta: { canNotLogin: false, toLogin: true },
     },
     {
       path: '/pages/mine/points/index',
-      meta: { canNotLogin: false, showToast: true },
+      meta: { canNotLogin: false, toLogin: true },
     },
     {
       path: '/pages/mine/coupons/index',
-      meta: { canNotLogin: false, showToast: true },
+      meta: { canNotLogin: false, toLogin: true },
     },
     {
       path: '/pages/mine/orders/index',
-      meta: { canNotLogin: false, showToast: true },
+      meta: { canNotLogin: false, toLogin: true },
     },
     {
       path: '/pages/mine/agents/index',
-      meta: { canNotLogin: false, showToast: true },
+      meta: { canNotLogin: false, toLogin: true },
     },
   ]
   return { isLogined, isDesigner, routes }

+ 3 - 0
packages/app/src/core/utils/router.ts

@@ -13,6 +13,9 @@ export const useRouter = () => {
       if (route.meta.showToast) {
         uni.showToast({ title: '暂无权限', icon: 'none' })
       }
+      if (route.meta.toLogin) {
+        push('/pages/login/index')
+      }
       return false
     }
     if (switchTab) {

+ 2 - 1
packages/app/src/pages/home/mall/components/product.vue

@@ -1,5 +1,4 @@
 <script lang="ts" setup>
-import { publish } from '../../../../core/libs/svgs'
 import { addBlack } from '@designer-hub/assets/src/assets/svgs'
 import { useRouter } from '../../../../core/utils/router'
 import { PropType } from 'vue'
@@ -14,6 +13,7 @@ const props = defineProps({
     default: () => {},
   },
 })
+const emits = defineEmits<{ change: [] }>()
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
 
@@ -33,6 +33,7 @@ const handleAddToCart = async () => {
       }),
     { success: true, successTitle: '加入购物车成功' },
   )
+  emits('change')
 }
 </script>
 <template>

+ 9 - 5
packages/app/src/pages/home/mall/index.vue

@@ -43,6 +43,13 @@ const current = ref<number>(0)
 const swiperList = computed(() => banners.value.map((it) => it.bannerImgUrl))
 const categories = computed(() => productCategories.value.find(({ id }) => id === 1)?.children)
 const category = ref()
+const query = computed(() => ({
+  oneCategory: category.value?.parentId,
+  secondCategory: category.value?.id,
+}))
+const handleChange = async () => {
+  setCarts()
+}
 onMounted(async () => {
   await setProductCategories()
   await setBanners()
@@ -74,10 +81,7 @@ onMounted(async () => {
       v-slot="{ data }"
       class="flex-grow flex flex-col"
       :request="getProducts"
-      :query="{
-        oneCategory: category?.parentId,
-        secondCategory: category?.id,
-      }"
+      :query="query"
     >
       <!-- <wd-skeleton
         :row-col="[[{ width: 100, height: 100 }, , { width: 100, height: 100 }]]"
@@ -85,7 +89,7 @@ onMounted(async () => {
       > -->
       <div class="grid grid-cols-2 gap-2.5">
         <template v-for="(it, i) of data" :key="i">
-          <Product :options="it"></Product>
+          <Product :options="it" @change="handleChange"></Product>
         </template>
       </div>
       <!-- </wd-skeleton> -->

+ 2 - 1
packages/app/src/pages/home/mall/shopping-cart/index.vue

@@ -35,6 +35,7 @@ const selected = ref([])
 const points = computed(() =>
   selected.value.reduce((acc, item) => acc + item.points * item.nums, 0),
 )
+const query = ref({ userId: userInfo.value?.userId })
 const handleSelect = (product) => {
   if (selected.value.map((it) => it.productId).includes(product.productId)) {
     selected.value = selected.value.filter(({ productId }) => productId !== product.productId)
@@ -100,7 +101,7 @@ const handlePlaceOrder = async () => {
     <PageHelper
       ref="pageHelperRef"
       :request="getProductItemBuy"
-      :query="{ userId: userInfo.userId }"
+      :query="query"
       class="flex-grow flex flex-col"
     >
       <template #default="{ source }">

+ 1 - 1
packages/app/src/pages/mine/homepage/index.vue

@@ -140,7 +140,7 @@ onUnload(async () => {
 })
 onShareAppMessage(() => ({
   title: `${userInfo.value.nickname}: “${designerInfo.value.designDesc}”`,
-  imageUrl: designerInfo.value?.homePageUrl,
+  imageUrl: designerInfo.value?.sharePageUrl,
 }))
 onShareTimeline(() => ({}))
 defineExpose({