浏览代码

处理分享页面商品链接获取失败问题

viczhq 4 月之前
父节点
当前提交
0bb32c1c3a

+ 5 - 1
src/pages/indexSub/seckillIndex/index.jsx

@@ -206,9 +206,13 @@ export default class Index extends Component {
206
         share_type: 3,
206
         share_type: 3,
207
         share_id: this.state.id,
207
         share_id: this.state.id,
208
       }).then((res) => {
208
       }).then((res) => {
209
+        let shareJump = "";
210
+        if(res.code==200){
211
+          shareJump = res.data.share_unique_value;
212
+        }
209
         return {
213
         return {
210
           title: `${this.state.title}`,
214
           title: `${this.state.title}`,
211
-          path: `/pages/indexSub/seckillIndex/index?isShare=true&shareUserId=${shareUserId}&title=${this.state.title}&id=${this.state.id}&&shareJump=${res.share_unique_value}&&shareType=3&&isShowBack=true`,
215
+          path: `/pages/indexSub/seckillIndex/index?isShare=true&shareUserId=${shareUserId}&title=${this.state.title}&id=${this.state.id}&&shareJump=${shareJump}&&shareType=3&&isShowBack=true`,
212
           imageUrl: "",
216
           imageUrl: "",
213
         };
217
         };
214
       });
218
       });

+ 54 - 31
src/pages/indexSub/sharePage/index.jsx

@@ -1,6 +1,10 @@
1
 import { Component } from "react";
1
 import { Component } from "react";
2
 import { View, Image, Button, Input } from "@tarojs/components";
2
 import { View, Image, Button, Input } from "@tarojs/components";
3
-import { getShareJump, getProductDetail } from "../../../service/index";
3
+import {
4
+  getShareJump,
5
+  getProductDetail,
6
+  refreshToken,
7
+} from "../../../service/index";
4
 import Taro from "@tarojs/taro";
8
 import Taro from "@tarojs/taro";
5
 import "./index.less";
9
 import "./index.less";
6
 
10
 
@@ -25,51 +29,61 @@ export default class Index extends Component {
25
       {
29
       {
26
         isSeckill: isSeckill === "true",
30
         isSeckill: isSeckill === "true",
27
         tagTitle,
31
         tagTitle,
28
-        productDetail: productDetail ? JSON.parse(decodeURIComponent(productDetail)) : {},
29
-        shareTitle: productDetail ? JSON.parse(decodeURIComponent(productDetail)).item_title : "",
32
+        productDetail: productDetail
33
+          ? JSON.parse(decodeURIComponent(productDetail))
34
+          : {},
35
+        shareTitle: productDetail
36
+          ? JSON.parse(decodeURIComponent(productDetail)).item_title
37
+          : "",
30
         shareUserId,
38
         shareUserId,
31
         id: id,
39
         id: id,
32
       },
40
       },
33
-      async () => {
34
-        Taro.showLoading({
35
-          title: "加载中...",
36
-        });
37
-        try {
38
-          await Promise.all([
39
-            this.getProductDetail(id),
40
-            this.getShareJump(id)
41
-          ]);
42
-        } finally {
43
-          Taro.hideLoading();
44
-        }
41
+      () => {
42
+        this.getProductDetail(id);
43
+        this.getShareJump(id);
45
       }
44
       }
46
     );
45
     );
47
   }
46
   }
48
   // 获取商品详情
47
   // 获取商品详情
49
-  getProductDetail = async (id='') => {
48
+  getProductDetail = async (id = "") => {
50
     const res = await getProductDetail({
49
     const res = await getProductDetail({
51
-      goods_id: id||this.state.productDetail.id,
50
+      goods_id: id || this.state.productDetail.id,
52
     });
51
     });
53
     this.setState({
52
     this.setState({
54
       productDetail: res,
53
       productDetail: res,
55
       shareTitle: res.item_title,
54
       shareTitle: res.item_title,
56
     });
55
     });
57
-  }
56
+  };
57
+  // 重新获取分享跳转标识
58
+  regain = async () => {
59
+    const res = await refreshToken();
60
+    this.getShareJump();
61
+  };
58
   // 获取分享跳转标识
62
   // 获取分享跳转标识
59
-  getShareJump = async (id='') => {
63
+  getShareJump = async (id = "") => {
64
+    Taro.showLoading({
65
+      title: "加载中...",
66
+    });
60
     // 设置分享路径
67
     // 设置分享路径
61
     const share_extend = JSON.stringify({
68
     const share_extend = JSON.stringify({
62
-      path: `pages/indexSub/productDetail/index?id=${ id||this.state.productDetail.id}&isShare=true&isSeckill=${this.state.isSeckill}&shareType=11&&shareUserId=${this.state.shareUserId}`,
69
+      path: `pages/indexSub/productDetail/index?id=${
70
+        id || this.state.productDetail.id
71
+      }&isShare=true&isSeckill=${
72
+        this.state.isSeckill
73
+      }&shareType=11&&shareUserId=${this.state.shareUserId}`,
63
     });
74
     });
64
     const res = await getShareJump({
75
     const res = await getShareJump({
65
       share_type: 11,
76
       share_type: 11,
66
-      share_id: id||this.state.productDetail.id,
77
+      share_id: id || this.state.productDetail.id,
67
       share_extend,
78
       share_extend,
68
     });
79
     });
69
-    this.setState({
70
-      shareJump: res.share_unique_value,
71
-      share_scheme_link: res.share_scheme_link,
72
-    });
80
+    if (res.code == 200) {
81
+      this.setState({
82
+        shareJump: res.data.share_unique_value,
83
+        share_scheme_link: res.data.share_scheme_link,
84
+      });
85
+    }
86
+    Taro.hideLoading();
73
   };
87
   };
74
   // 设置分享标题
88
   // 设置分享标题
75
   handleShareTitleChange = (newTitle) => {
89
   handleShareTitleChange = (newTitle) => {
@@ -248,16 +262,25 @@ export default class Index extends Component {
248
                 <Input
262
                 <Input
249
                   onInput={this.handleShareTitleChange}
263
                   onInput={this.handleShareTitleChange}
250
                   className="linkInput"
264
                   className="linkInput"
251
-                  value={this.state.share_scheme_link}
265
+                  value={
266
+                    this.state.share_scheme_link ||
267
+                    "商品链接获取失败,请重新获取"
268
+                  }
252
                   disabled
269
                   disabled
253
                 />
270
                 />
254
                 <View className="copy-box">
271
                 <View className="copy-box">
255
                   <View className="copy-box-line"></View>
272
                   <View className="copy-box-line"></View>
256
-                  <Image
257
-                    onClick={this.handleCopyLink}
258
-                    className="copy-box-icon"
259
-                    src="https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png"
260
-                  />
273
+                  {this.state.share_scheme_link ? (
274
+                    <Image
275
+                      onClick={this.handleCopyLink}
276
+                      className="copy-box-icon"
277
+                      src="https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png"
278
+                    />
279
+                  ) : (
280
+                    <View className="getLink" onClick={this.regain}>
281
+                      重新获取
282
+                    </View>
283
+                  )}
261
                 </View>
284
                 </View>
262
               </View>
285
               </View>
263
             </View>
286
             </View>

+ 4 - 0
src/pages/indexSub/sharePage/index.less

@@ -173,6 +173,10 @@
173
                             width: 34px;
173
                             width: 34px;
174
                             height: 34px;
174
                             height: 34px;
175
                         }
175
                         }
176
+                        .getLink{
177
+                            font-size: 28px;
178
+                            color: #F48106;
179
+                        }
176
                     }
180
                     }
177
                 }
181
                 }
178
 
182
 

+ 5 - 1
src/pages/memberSub/storeManagement/index.jsx

@@ -155,9 +155,13 @@ export default class Index extends Component {
155
       share_type: 2,
155
       share_type: 2,
156
       share_id: this.state.shopDetail.id,
156
       share_id: this.state.shopDetail.id,
157
     }).then((res) => {
157
     }).then((res) => {
158
+      let shareJump = "";
159
+      if(res.code==200){
160
+        shareJump = res.data.share_unique_value;
161
+      }
158
       return {
162
       return {
159
         title: `${name||'分享者'}的店铺`,
163
         title: `${name||'分享者'}的店铺`,
160
-        path: `/pages/memberSub/storeManagement/index?shopId=${this.state.shopDetail.id}&isShare=true&isManager=false&&shareJump=${res.share_unique_value}&&shareType=2&&isShowBack=true`,
164
+        path: `/pages/memberSub/storeManagement/index?shopId=${this.state.shopDetail.id}&isShare=true&isManager=false&&shareJump=${shareJump}&&shareType=2&&isShowBack=true`,
161
         imageUrl: "",
165
         imageUrl: "",
162
       };
166
       };
163
     });
167
     });

+ 13 - 5
src/service/index.js

@@ -1,5 +1,6 @@
1
 //接口集成
1
 //接口集成
2
 import Request from '../api/request';
2
 import Request from '../api/request';
3
+import RequestApi from '../api/request_api';
3
 // -----------------------------------------------------------首页
4
 // -----------------------------------------------------------首页
4
 // 获取首页数据
5
 // 获取首页数据
5
 export const getHomeData = data =>
6
 export const getHomeData = data =>
@@ -50,8 +51,8 @@ export const getAllTags = data =>
50
     method: 'POST',
51
     method: 'POST',
51
     data,
52
     data,
52
   })
53
   })
53
-  // 获取鱼市tags
54
-  export const getFishMarketTags = data =>
54
+// 获取鱼市tags
55
+export const getFishMarketTags = data =>
55
   Request({
56
   Request({
56
     url: '/api/get_yushi_tags',
57
     url: '/api/get_yushi_tags',
57
     method: 'POST',
58
     method: 'POST',
@@ -95,7 +96,7 @@ export const getUserAgreement = data =>
95
   })
96
   })
96
 // 获取分享跳转标识(1:商品;2:店铺 3:专题页)
97
 // 获取分享跳转标识(1:商品;2:店铺 3:专题页)
97
 export const getShareJump = data =>
98
 export const getShareJump = data =>
98
-  Request({
99
+  RequestApi({
99
     url: '/user/get_not_oneself_store_detail',
100
     url: '/user/get_not_oneself_store_detail',
100
     method: 'POST',
101
     method: 'POST',
101
     data,
102
     data,
@@ -107,8 +108,8 @@ export const bindShareJump = data =>
107
     method: 'POST',
108
     method: 'POST',
108
     data,
109
     data,
109
   })
110
   })
110
-  // 获取我的页面数据
111
-  export const getMineData = data =>
111
+// 获取我的页面数据
112
+export const getMineData = data =>
112
   Request({
113
   Request({
113
     url: '/user/get_my_page',
114
     url: '/user/get_my_page',
114
     method: 'POST',
115
     method: 'POST',
@@ -221,6 +222,13 @@ export const login = data =>
221
     method: 'POST',
222
     method: 'POST',
222
     data,
223
     data,
223
   })
224
   })
225
+// 刷新小程序token
226
+export const refreshToken = data =>
227
+  Request({
228
+    url: '/user/refresh_app_token',
229
+    method: 'POST',
230
+    data,
231
+  })
224
 // ---------------------------------------埋点
232
 // ---------------------------------------埋点
225
 // 埋点
233
 // 埋点
226
 export const addLog = data =>
234
 export const addLog = data =>