Browse Source

✨ 全局:优化请求的提示

YunaiV 1 year ago
parent
commit
22139d9a2d

+ 1 - 1
pages/chat/socket.js

@@ -1,6 +1,6 @@
 import { reactive, ref, unref } from 'vue';
 import sheep from '@/sheep';
-import chat from '@/sheep/api/chat';
+// import chat from '@/sheep/api/chat';
 import dayjs from 'dayjs';
 import io from '@hyoga/uni-socket.io';
 

+ 2 - 2
pages/index/page.vue

@@ -17,7 +17,7 @@
 <script setup>
   import { reactive } from 'vue';
   import { onLoad, onPageScroll } from '@dcloudio/uni-app';
-  import DiyPageApi from "@/sheep/api/promotion/diy/page";
+  import DiyApi from '@/sheep/api/promotion/diy';
 
   const state = reactive({
     name: '',
@@ -36,7 +36,7 @@
     }
     // #endif
 
-    const { code, data } = await DiyPageApi.getDiyPage(id);
+    const { code, data } = await DiyApi.getDiyPage(id);
     if (code === 0) {
       state.name = data.name;
       state.components = data.property?.components;

+ 10 - 2
sheep/api/member/address.js

@@ -13,7 +13,11 @@ const AddressApi = {
     return request({
       url: '/member/address/create',
       method: 'POST',
-      data
+      data,
+      custom: {
+        showSuccess: true,
+        successMsg: '保存成功'
+      },
     });
   },
   // 更新用户收件地址
@@ -21,7 +25,11 @@ const AddressApi = {
     return request({
       url: '/member/address/update',
       method: 'PUT',
-      data
+      data,
+      custom: {
+        showSuccess: true,
+        successMsg: '更新成功'
+      },
     });
   },
   // 获得用户收件地址

+ 2 - 1
sheep/api/member/user.js

@@ -19,8 +19,9 @@ const UserApi = {
       method: 'PUT',
       data,
       custom: {
-        showSuccess: true,
         auth: true,
+        showSuccess: true,
+        successMsg: '更新成功'
       },
     });
   },

+ 5 - 1
sheep/api/product/comment.js

@@ -10,7 +10,11 @@ const CommentApi = {
         spuId,
         pageNo,
         pageSize,
-        type
+        type,
+      },
+      custom: {
+        showLoading: false,
+        showError: false,
       },
     });
   },

+ 19 - 9
sheep/api/product/favorite.js

@@ -6,7 +6,7 @@ const FavoriteApi = {
     return request({
       url: '/product/favorite/page',
       method: 'GET',
-      params: data
+      params: data,
     });
   },
   // 检查是否收藏过商品
@@ -15,8 +15,8 @@ const FavoriteApi = {
       url: '/product/favorite/exits',
       method: 'GET',
       params: {
-        spuId
-      }
+        spuId,
+      },
     });
   },
   // 添加商品收藏
@@ -25,8 +25,13 @@ const FavoriteApi = {
       url: '/product/favorite/create',
       method: 'POST',
       data: {
-        spuId
-      }
+        spuId,
+      },
+      custom: {
+        auth: true,
+        showSuccess: true,
+        successMsg: '收藏成功',
+      },
     });
   },
   // 取消商品收藏
@@ -35,10 +40,15 @@ const FavoriteApi = {
       url: '/product/favorite/delete',
       method: 'DELETE',
       data: {
-        spuId
-      }
+        spuId,
+      },
+      custom: {
+        auth: true,
+        showSuccess: true,
+        successMsg: '取消成功',
+      },
     });
-  }
+  },
 };
 
-export default FavoriteApi;
+export default FavoriteApi;

+ 34 - 23
sheep/api/product/history.js

@@ -1,28 +1,39 @@
 import request from '@/sheep/request';
 
 const SpuHistoryApi = {
-    // 删除商品浏览记录
-    deleteBrowseHistory: (spuIds) => {
-        return request({
-            url: '/product/browse-history/delete',
-            method: 'DELETE',
-            data: { spuIds },
-        });
-    },
-    // 清空商品浏览记录
-    cleanBrowseHistory: () => {
-        return request({
-            url: '/product/browse-history/clean',
-            method: 'DELETE',
-        });
-    },
-    // 获得商品浏览记录分页
-    getBrowseHistoryPage: (data) => {
-        return request({
-            url: '/product/browse-history/page',
-            method: 'GET',
-            data
-        });
-    }
+  // 删除商品浏览记录
+  deleteBrowseHistory: (spuIds) => {
+    return request({
+      url: '/product/browse-history/delete',
+      method: 'DELETE',
+      data: { spuIds },
+      custom: {
+        showSuccess: true,
+        successMsg: '删除成功',
+      },
+    });
+  },
+  // 清空商品浏览记录
+  cleanBrowseHistory: () => {
+    return request({
+      url: '/product/browse-history/clean',
+      method: 'DELETE',
+      custom: {
+        showSuccess: true,
+        successMsg: '清空成功',
+      },
+    });
+  },
+  // 获得商品浏览记录分页
+  getBrowseHistoryPage: (data) => {
+    return request({
+      url: '/product/browse-history/page',
+      method: 'GET',
+      data,
+      custom: {
+        showLoading: false
+      },
+    });
+  },
 };
 export default SpuHistoryApi;

+ 36 - 32
sheep/api/product/spu.js

@@ -1,37 +1,41 @@
 import request from '@/sheep/request';
 
 const SpuApi = {
-    // 获得商品 SPU 列表
-    getSpuList: (recommendType) => {
-        return request({
-            url: '/product/spu/list',
-            method: 'GET',
-            params: {recommendType},
-        });
-    },
-    // 获得商品 SPU 列表
-    getSpuListByIds: (ids) => {
-        return request({
-            url: '/product/spu/list-by-ids',
-            method: 'GET',
-            params: {ids},
-        });
-    },
-    // 获得商品 SPU 分页
-    getSpuPage: (data) => {
-        return request({
-            url: '/product/spu/page',
-            method: 'GET',
-            data
-        });
-    },
-    // 查询商品
-    getSpuDetail: (id) => {
-        return request({
-            url: '/product/spu/get-detail',
-            method: 'GET',
-            params: { id },
-        });
-    }
+  // 获得商品 SPU 列表
+  getSpuListByIds: (ids) => {
+    return request({
+      url: '/product/spu/list-by-ids',
+      method: 'GET',
+      params: { ids },
+      custom: {
+        showLoading: false,
+        showError: false,
+      },
+    });
+  },
+  // 获得商品 SPU 分页
+  getSpuPage: (params) => {
+    return request({
+      url: '/product/spu/page',
+      method: 'GET',
+      params,
+      custom: {
+        showLoading: false,
+        showError: false,
+      },
+    });
+  },
+  // 查询商品
+  getSpuDetail: (id) => {
+    return request({
+      url: '/product/spu/get-detail',
+      method: 'GET',
+      params: { id },
+      custom: {
+        showLoading: false,
+        showError: false,
+      },
+    });
+  },
 };
 export default SpuApi;

+ 15 - 0
sheep/api/promotion/coupon.js

@@ -7,6 +7,10 @@ const CouponApi = {
       url: '/promotion/coupon-template/list-by-ids',
       method: 'GET',
       params: { ids },
+      custom: {
+        showLoading: false, // 不展示 Loading,避免领取优惠劵时,不成功提示
+        showError: false,
+      },
     });
   },
   // 获得优惠劵模版列表
@@ -47,6 +51,13 @@ const CouponApi = {
       url: '/promotion/coupon/take',
       method: 'POST',
       data: { templateId },
+      custom: {
+        auth: true,
+        showLoading: true,
+        loadingMsg: '领取中',
+        showSuccess: true,
+        successMsg: '领取成功',
+      },
     });
   },
   // 获得优惠劵
@@ -79,6 +90,10 @@ const CouponApi = {
         skuIds: skuIds.join(','),
         categoryIds: categoryIds.join(','),
       },
+      custom: {
+        showError: false,
+        showLoading: false, // 避免影响 settlementOrder 结算的结果
+      },
     });
   }
 };

+ 38 - 0
sheep/api/promotion/diy.js

@@ -0,0 +1,38 @@
+import request from '@/sheep/request';
+
+const DiyApi = {
+  getUsedDiyTemplate: () => {
+    return request({
+      url: '/promotion/diy-template/used',
+      method: 'GET',
+      custom: {
+        showError: false,
+        showLoading: false,
+      },
+    });
+  },
+  getDiyTemplate: (id) => {
+    return request({
+      url: '/promotion/diy-template/get',
+      method: 'GET',
+      params: {
+        id
+      },
+      custom: {
+        showError: false,
+        showLoading: false,
+      },
+    });
+  },
+  getDiyPage: (id) => {
+    return request({
+      url: '/promotion/diy-page/get',
+      method: 'GET',
+      params: {
+        id
+      }
+    });
+  },
+};
+
+export default DiyApi;

+ 0 - 15
sheep/api/promotion/diy/page.js

@@ -1,15 +0,0 @@
-import request from '@/sheep/request';
-
-const DiyPageApi = {
-	getDiyPage: (id) => {
-		return request({
-			url: '/promotion/diy-page/get',
-			method: 'GET',
-			params: {
-				id
-			}
-		});
-	},
-};
-
-export default DiyPageApi;

+ 0 - 21
sheep/api/promotion/diy/template.js

@@ -1,21 +0,0 @@
-import request from '@/sheep/request';
-
-const DiyTemplateApi = {
-	getUsedDiyTemplate: () => {
-	    return request({
-	        url: '/promotion/diy-template/used',
-	        method: 'GET',
-	    });
-	},
-	getDiyTemplate: (id) => {
-		return request({
-			url: '/promotion/diy-template/get',
-			method: 'GET',
-			params: {
-				id
-			}
-		});
-	},
-};
-
-export default DiyTemplateApi;

+ 4 - 0
sheep/api/trade/cart.js

@@ -39,6 +39,10 @@ const CartApi = {
     return request({
       url: '/trade/cart/list',
       method: 'GET',
+      custom: {
+        showLoading: false,
+        auth: true,
+      },
     });
   },
 };

+ 3 - 0
sheep/api/trade/order.js

@@ -59,6 +59,9 @@ const OrderApi = {
       params: {
         id,
       },
+      custom: {
+        showLoading: false,
+      },
     });
   },
   // 订单列表

+ 3 - 3
sheep/store/app.js

@@ -1,4 +1,4 @@
-import diyTemplateApi from '@/sheep/api/promotion/diy/template';
+import DiyApi from '@/sheep/api/promotion/diy';
 import { defineStore } from 'pinia';
 import $platform from '@/sheep/platform';
 import $router from '@/sheep/router';
@@ -117,8 +117,8 @@ const app = defineStore({
 const adaptTemplate = async (appTemplate, templateId) => {
   const { data: diyTemplate } = templateId
       // 查询指定模板,一般是预览时使用
-      ? await diyTemplateApi.getDiyTemplate(templateId)
-      : await diyTemplateApi.getUsedDiyTemplate();
+      ? await DiyApi.getDiyTemplate(templateId)
+      : await DiyApi.getUsedDiyTemplate();
   // 模板不存在
   if (!diyTemplate) {
     $router.error('TemplateError');