Просмотр исходного кода

fix(mall): 优化团购参团与搜索词处理

- 参团失败时由页面展示更长时效的明确提示,避免加载态遮挡

- 兼容路由搜索词双重编码,确保中文关键词正确回填
shizhongqi 19 часов назад
Родитель
Сommit
ab5d97ac74
3 измененных файлов с 54 добавлено и 8 удалено
  1. 6 2
      mallApp/src/api/group-buy/index.js
  2. 26 1
      mallApp/src/pages/goods/list.vue
  3. 22 5
      mallApp/src/pages/groupBuy/detail.vue

+ 6 - 2
mallApp/src/api/group-buy/index.js

@@ -13,8 +13,12 @@ export const getGroupDetail = data => https.get('/group-buy/detail', data)
 /** 我要开团 */
 /** 我要开团 */
 export const createGroup = data => https.post('/group-buy/create', data)
 export const createGroup = data => https.post('/group-buy/create', data)
 
 
-/** 我要参团 */
-export const joinGroup = data => https.post('/group-buy/join', data)
+/**
+ * 我要参团
+ * @param {Object} data 业务参数
+ * @param {Object} config 请求控制,如 hideError 由页面自行弹失败提示
+ */
+export const joinGroup = (data, config = {}) => https.post('/group-buy/join', data, {}, config)
 
 
 /** 我的拼团列表 */
 /** 我的拼团列表 */
 export const getMyList = data => https.get('/group-buy/my-list', data)
 export const getMyList = data => https.get('/group-buy/my-list', data)

+ 26 - 1
mallApp/src/pages/goods/list.vue

@@ -310,6 +310,31 @@ export default {
         url: '/pages/home/cart?account=' + account + '&hdId=' + hdId
         url: '/pages/home/cart?account=' + account + '&hdId=' + hdId
       })
       })
     },
     },
+    /**
+     * 解码路由里的搜索词
+     * 首页跳转会 encodeURIComponent;微信/uni-app 可能再编一层,onLoad 只解一次时仍是 %E9..,需再解才是中文
+     */
+    decodeRouteKeyword(raw) {
+      let s = String(raw || '')
+      if (!s) {
+        return ''
+      }
+      // 最多解两层,兼容「只编一次已被框架解开」和「双重编码仍带 %」
+      let i = 0
+      while (i < 2 && s.indexOf('%') !== -1) {
+        i += 1
+        try {
+          const next = decodeURIComponent(s)
+          if (next === s) {
+            break
+          }
+          s = next
+        } catch (e) {
+          break
+        }
+      }
+      return s
+    },
     /**
     /**
      * 解析路由带入的筛选与搜索关键词
      * 解析路由带入的筛选与搜索关键词
      * searchText:首页搜索框跳转带入,回填搜索框并参与首次列表请求
      * searchText:首页搜索框跳转带入,回填搜索框并参与首次列表请求
@@ -318,7 +343,7 @@ export default {
      */
      */
     applyRouteFilter() {
     applyRouteFilter() {
       // 首页搜索跳转:回填关键词,init 随后 loadGoods 会带上 searchText
       // 首页搜索跳转:回填关键词,init 随后 loadGoods 会带上 searchText
-      const keyword = (this.option && this.option.searchText) ? String(this.option.searchText) : ''
+      const keyword = (this.option && this.option.searchText) ? this.decodeRouteKeyword(this.option.searchText) : ''
       if (keyword) {
       if (keyword) {
         this.searchText = keyword
         this.searchText = keyword
       }
       }

+ 22 - 5
mallApp/src/pages/groupBuy/detail.vue

@@ -544,16 +544,23 @@ export default {
       if (!this.openGroup || !this.openGroup.id) return
       if (!this.openGroup || !this.openGroup.id) return
       this.doJoin(this.openGroup.id)
       this.doJoin(this.openGroup.id)
     },
     },
+    /**
+     * 参团:默认自取下单,成功后去待付款
+     * hideError 避免拦截器先弹默认 1.5s toast,再被 hideLoading 立刻关掉
+     */
     doJoin(groupBuyId) {
     doJoin(groupBuyId) {
       if (this.submitting) return
       if (this.submitting) return
       if (!this.ensureLogin()) return
       if (!this.ensureLogin()) return
       this.submitting = true
       this.submitting = true
       uni.showLoading({ title: '参团中', mask: true })
       uni.showLoading({ title: '参团中', mask: true })
-      joinGroup({
-        groupBuyId,
-        goodsNum: 1,
-        sendType: 1
-      })
+      joinGroup(
+        {
+          groupBuyId,
+          goodsNum: 1,
+          sendType: 1
+        },
+        { hideError: true }
+      )
         .then((res) => {
         .then((res) => {
           uni.hideLoading()
           uni.hideLoading()
           this.submitting = false
           this.submitting = false
@@ -561,6 +568,16 @@ export default {
             this.groupBuyId = res.data.groupBuyId
             this.groupBuyId = res.data.groupBuyId
             this.setupShare()
             this.setupShare()
             this.goPay(res.data)
             this.goPay(res.data)
+            return
+          }
+          // 如「已在该团中」:先关 loading 再弹,时长在默认 1500ms 上加长 1.5s
+          if (res && res.msg) {
+            uni.showToast({
+              title: res.msg,
+              icon: 'none',
+              mask: true,
+              duration: 3000
+            })
           }
           }
         })
         })
         .catch(() => {
         .catch(() => {