瀏覽代碼

商品分享页修改上传

viczhq 1 周之前
父節點
當前提交
22f7eb27c9

+ 5 - 19
src/components/index/ProductList/index.jsx

@@ -7,8 +7,9 @@ import React, {
7
 import { View, Text, Image, Button } from "@tarojs/components";
7
 import { View, Text, Image, Button } from "@tarojs/components";
8
 import { AtCheckbox, AtActivityIndicator } from "taro-ui";
8
 import { AtCheckbox, AtActivityIndicator } from "taro-ui";
9
 import { setShareContent } from "../../../common/share";
9
 import { setShareContent } from "../../../common/share";
10
-import { getShareJump, getProductDetail } from "../../../service";
10
+import { getShareJump } from "../../../service";
11
 import { handleLog } from "../../../common/track";
11
 import { handleLog } from "../../../common/track";
12
+import { isDebounce } from "../../../common/debounce";
12
 import Taro from "@tarojs/taro";
13
 import Taro from "@tarojs/taro";
13
 import "./index.less";
14
 import "./index.less";
14
 import ShareModal from "../../shareModal";
15
 import ShareModal from "../../shareModal";
@@ -101,27 +102,12 @@ const ProductList = forwardRef((props, ref) => {
101
   };
102
   };
102
   // 分享商品
103
   // 分享商品
103
   const shareProduct = async (product, e) => {
104
   const shareProduct = async (product, e) => {
105
+    if (!isDebounce(500)) return; // 如果在500ms内重复触发,直接返回
104
     e.stopPropagation(); // 防止事件穿透
106
     e.stopPropagation(); // 防止事件穿透
105
     setCurrentShareProduct(product);
107
     setCurrentShareProduct(product);
106
-    const productRes = await getProductDetail({
107
-      goods_id: product.id,
108
+    Taro.navigateTo({
109
+      url: `/pages/indexSub/sharePage/index?isSeckill=${isSeckill}&&tagTitle=${tagTitle}&&shareUserId=${shareUserId}&id=${product.id}`,
108
     });
110
     });
109
-    // 使用 encodeURIComponent 编码商品详情数据
110
-    const encodedProductDetail = encodeURIComponent(JSON.stringify(productRes));
111
-    // 设置分享路径
112
-    const share_extend = JSON.stringify({
113
-      path: `pages/indexSub/productDetail/index?id=${product.id}&isShare=true&isSeckill=${isSeckill}&shareType=11&&shareUserId=${shareUserId}`,
114
-    });
115
-    getShareJump({
116
-      share_type: 11,
117
-      share_id: product.id,
118
-      share_extend,
119
-    }).then((res) => {
120
-      Taro.navigateTo({
121
-        url: `/pages/indexSub/sharePage/index?isSeckill=${isSeckill}&&tagTitle=${tagTitle}&&productDetail=${encodedProductDetail}&&shareJump=${res.share_unique_value}&&share_scheme_link=${encodeURIComponent(res.share_scheme_link)}&&shareUserId=${shareUserId}`,
122
-      });
123
-    });
124
-    return;
125
     // 埋点
111
     // 埋点
126
     if (isSeckill) {
112
     if (isSeckill) {
127
       handleLog({
113
       handleLog({

+ 3 - 11
src/pages/indexSub/productDetail/index.jsx

@@ -9,6 +9,7 @@ import {
9
   bindShareJump,
9
   bindShareJump,
10
 } from "../../../service";
10
 } from "../../../service";
11
 import { handleLog } from "../../../common/track";
11
 import { handleLog } from "../../../common/track";
12
+import { isDebounce } from "../../../common/debounce";
12
 import "./index.less";
13
 import "./index.less";
13
 import Taro from "@tarojs/taro";
14
 import Taro from "@tarojs/taro";
14
 import productDetailIcon from "../../../images/productDetail/productDetailIcon.png";
15
 import productDetailIcon from "../../../images/productDetail/productDetailIcon.png";
@@ -173,26 +174,17 @@ export default class Index extends Component {
173
   };
174
   };
174
   // 分享
175
   // 分享
175
   openSharePopup = async () => {
176
   openSharePopup = async () => {
177
+    if (!isDebounce(500)) return; // 如果在500ms内重复触发,直接返回
176
     let shareUserId = "";
178
     let shareUserId = "";
177
     if (Taro.getStorageSync("loginInfo")) {
179
     if (Taro.getStorageSync("loginInfo")) {
178
       shareUserId = Taro.getStorageSync("loginInfo").id;
180
       shareUserId = Taro.getStorageSync("loginInfo").id;
179
     }
181
     }
180
-    // 设置分享路径
181
-    const share_extend = JSON.stringify({
182
-      path: `pages/indexSub/productDetail/index?id=${this.state.id}&isShare=true&isSeckill=${this.state.isSeckill}&shareType=11&&shareUserId=${shareUserId}`,
183
-    });
184
-    // 获取分享跳转标识
185
-    const res = await getShareJump({
186
-      share_type: 11,
187
-      share_id: this.state.id,
188
-      share_extend,
189
-    });
190
     // 使用 encodeURIComponent 编码商品详情数据
182
     // 使用 encodeURIComponent 编码商品详情数据
191
     const encodedProductDetail = encodeURIComponent(
183
     const encodedProductDetail = encodeURIComponent(
192
       JSON.stringify(this.state.productDetail)
184
       JSON.stringify(this.state.productDetail)
193
     );
185
     );
194
     Taro.navigateTo({
186
     Taro.navigateTo({
195
-      url: `/pages/indexSub/sharePage/index?isSeckill=${this.state.isSeckill}&shareJump=${res.share_unique_value}&tagTitle=${this.state.tagTitle}&productDetail=${encodedProductDetail}&shareUserId=${shareUserId}&&share_scheme_link=${encodeURIComponent(res.share_scheme_link)}`,
187
+      url: `/pages/indexSub/sharePage/index?isSeckill=${this.state.isSeckill}&tagTitle=${this.state.tagTitle}&productDetail=${encodedProductDetail}&shareUserId=${shareUserId}`,
196
     });
188
     });
197
     // 埋点
189
     // 埋点
198
     if (this.state.isSeckill) {
190
     if (this.state.isSeckill) {

+ 88 - 29
src/pages/indexSub/sharePage/index.jsx

@@ -1,10 +1,12 @@
1
 import { Component } from "react";
1
 import { Component } from "react";
2
-import { View, Image, Text, Button, Input } from "@tarojs/components";
2
+import { View, Image, Button, Input } from "@tarojs/components";
3
+import { getShareJump, getProductDetail } from "../../../service/index";
3
 import Taro from "@tarojs/taro";
4
 import Taro from "@tarojs/taro";
4
 import "./index.less";
5
 import "./index.less";
5
 
6
 
6
 export default class Index extends Component {
7
 export default class Index extends Component {
7
   state = {
8
   state = {
9
+    id: "", //商品id(专题列表分享过来的)
8
     shareTitle: "", //分享标题
10
     shareTitle: "", //分享标题
9
     productDetail: {}, //商品详情
11
     productDetail: {}, //商品详情
10
     isSeckill: false, //是否是秒杀商品
12
     isSeckill: false, //是否是秒杀商品
@@ -17,18 +19,58 @@ export default class Index extends Component {
17
     Taro.hideShareMenu({
19
     Taro.hideShareMenu({
18
       menus: ["shareAppMessage", "shareTimeline"],
20
       menus: ["shareAppMessage", "shareTimeline"],
19
     });
21
     });
20
-    const { isSeckill, shareJump, tagTitle, productDetail,shareUserId,share_scheme_link } =
22
+    const { isSeckill, tagTitle, productDetail, shareUserId, id } =
21
       Taro.getCurrentInstance().router.params;
23
       Taro.getCurrentInstance().router.params;
24
+    this.setState(
25
+      {
26
+        isSeckill: isSeckill === "true",
27
+        tagTitle,
28
+        productDetail: productDetail ? JSON.parse(decodeURIComponent(productDetail)) : {},
29
+        shareTitle: productDetail ? JSON.parse(decodeURIComponent(productDetail)).item_title : "",
30
+        shareUserId,
31
+        id: id,
32
+      },
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
+        }
45
+      }
46
+    );
47
+  }
48
+  // 获取商品详情
49
+  getProductDetail = async (id='') => {
50
+    const res = await getProductDetail({
51
+      goods_id: id||this.state.productDetail.id,
52
+    });
22
     this.setState({
53
     this.setState({
23
-      isSeckill: isSeckill === "true",
24
-      shareJump,
25
-      tagTitle,
26
-      productDetail: JSON.parse(decodeURIComponent(productDetail)),
27
-      shareTitle: JSON.parse(decodeURIComponent(productDetail)).item_title,
28
-      shareUserId,
29
-      share_scheme_link:decodeURIComponent(share_scheme_link)
54
+      productDetail: res,
55
+      shareTitle: res.item_title,
30
     });
56
     });
31
   }
57
   }
58
+  // 获取分享跳转标识
59
+  getShareJump = async (id='') => {
60
+    // 设置分享路径
61
+    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}`,
63
+    });
64
+    const res = await getShareJump({
65
+      share_type: 11,
66
+      share_id: id||this.state.productDetail.id,
67
+      share_extend,
68
+    });
69
+    this.setState({
70
+      shareJump: res.share_unique_value,
71
+      share_scheme_link: res.share_scheme_link,
72
+    });
73
+  };
32
   // 设置分享标题
74
   // 设置分享标题
33
   handleShareTitleChange = (newTitle) => {
75
   handleShareTitleChange = (newTitle) => {
34
     this.setState({
76
     this.setState({
@@ -66,33 +108,35 @@ export default class Index extends Component {
66
 
108
 
67
   saveImage = async () => {
109
   saveImage = async () => {
68
     Taro.showLoading({
110
     Taro.showLoading({
69
-      title: '保存中...',
111
+      title: "保存中...",
70
     });
112
     });
71
     const { images } = this.state.productDetail;
113
     const { images } = this.state.productDetail;
72
     try {
114
     try {
73
       for (const image of images) {
115
       for (const image of images) {
74
-        // 下载图片
75
-        const downloadRes = await Taro.downloadFile({
76
-          url: image.img
116
+        // 转换图片链接从 http 到 https
117
+        const imgUrl = image.img.startsWith("http:")
118
+          ? image.img.replace("http:", "https:")
119
+          : image.img;
120
+        // 先获取图片信息
121
+        const imageInfo = await Taro.getImageInfo({
122
+          src: imgUrl,
77
         });
123
         });
78
-
79
-        // 保存到相册
124
+        // 使用图片路径保存
80
         await Taro.saveImageToPhotosAlbum({
125
         await Taro.saveImageToPhotosAlbum({
81
-          filePath: downloadRes.tempFilePath
126
+          filePath: imageInfo.path,
82
         });
127
         });
83
       }
128
       }
84
-
85
       // 全部保存成功后提示
129
       // 全部保存成功后提示
86
       Taro.showToast({
130
       Taro.showToast({
87
         title: "所有图片保存成功",
131
         title: "所有图片保存成功",
88
         icon: "success",
132
         icon: "success",
89
-        duration: 2000
133
+        duration: 2000,
90
       });
134
       });
91
     } catch (error) {
135
     } catch (error) {
92
       Taro.showToast({
136
       Taro.showToast({
93
         title: "保存失败",
137
         title: "保存失败",
94
         icon: "none",
138
         icon: "none",
95
-        duration: 2000
139
+        duration: 2000,
96
       });
140
       });
97
     }
141
     }
98
   };
142
   };
@@ -110,9 +154,9 @@ export default class Index extends Component {
110
         Taro.showToast({
154
         Taro.showToast({
111
           title: "标题复制成功",
155
           title: "标题复制成功",
112
           icon: "none",
156
           icon: "none",
113
-          duration: 1500
157
+          duration: 1500,
114
         });
158
         });
115
-      }
159
+      },
116
     });
160
     });
117
   };
161
   };
118
   // 复制链接
162
   // 复制链接
@@ -123,9 +167,9 @@ export default class Index extends Component {
123
         Taro.showToast({
167
         Taro.showToast({
124
           title: "链接复制成功",
168
           title: "链接复制成功",
125
           icon: "none",
169
           icon: "none",
126
-          duration: 1500
170
+          duration: 1500,
127
         });
171
         });
128
-      }
172
+      },
129
     });
173
     });
130
   };
174
   };
131
   // 配置分享内容
175
   // 配置分享内容
@@ -165,7 +209,9 @@ export default class Index extends Component {
165
         <View className="text-box">
209
         <View className="text-box">
166
           <View className="text-box-top">
210
           <View className="text-box-top">
167
             <View className="text-box-title">文案素材</View>
211
             <View className="text-box-title">文案素材</View>
168
-            <View onClick={this.handleCopyAll} className="text-box-save">复制全部内容</View>
212
+            <View onClick={this.handleCopyAll} className="text-box-save">
213
+              复制全部内容
214
+            </View>
169
           </View>
215
           </View>
170
           <View className="text-box-content">
216
           <View className="text-box-content">
171
             {/* 商品标题盒子 */}
217
             {/* 商品标题盒子 */}
@@ -174,7 +220,10 @@ export default class Index extends Component {
174
                 <View className="text-box-content-title-top-title">
220
                 <View className="text-box-content-title-top-title">
175
                   商品标题
221
                   商品标题
176
                 </View>
222
                 </View>
177
-                <View onClick={this.handleCopyTitle} className="text-box-content-title-top-copy">
223
+                <View
224
+                  onClick={this.handleCopyTitle}
225
+                  className="text-box-content-title-top-copy"
226
+                >
178
                   复制标题
227
                   复制标题
179
                 </View>
228
                 </View>
180
               </View>
229
               </View>
@@ -204,16 +253,26 @@ export default class Index extends Component {
204
                 />
253
                 />
205
                 <View className="copy-box">
254
                 <View className="copy-box">
206
                   <View className="copy-box-line"></View>
255
                   <View className="copy-box-line"></View>
207
-                  <Image onClick={this.handleCopyLink} className="copy-box-icon" src='https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png' />
256
+                  <Image
257
+                    onClick={this.handleCopyLink}
258
+                    className="copy-box-icon"
259
+                    src="https://yushi.tos-cn-beijing.volces.com/productDetail/copy.png"
260
+                  />
208
                 </View>
261
                 </View>
209
               </View>
262
               </View>
210
             </View>
263
             </View>
211
           </View>
264
           </View>
212
         </View>
265
         </View>
213
         {/* 分享按钮 */}
266
         {/* 分享按钮 */}
214
-        <Button className="share-button" openType="share" onClick={this.handleShare}>
215
-          直接分享商品卡片到聊天框
216
-        </Button>
267
+        {this.state.shareJump && (
268
+          <Button
269
+            className="share-button"
270
+            openType="share"
271
+            onClick={this.handleShare}
272
+          >
273
+            直接分享商品卡片到聊天框
274
+          </Button>
275
+        )}
217
       </View>
276
       </View>
218
     );
277
     );
219
   }
278
   }

+ 3 - 1
src/pages/indexSub/sharePage/index.less

@@ -42,13 +42,15 @@
42
         .image-box-content {
42
         .image-box-content {
43
             display: flex;
43
             display: flex;
44
             flex-wrap: nowrap;
44
             flex-wrap: nowrap;
45
-            overflow-x: auto;
45
+            overflow-x: scroll;
46
 
46
 
47
             .image-box-content-item {
47
             .image-box-content-item {
48
                 width: 240px;
48
                 width: 240px;
49
                 height: 240px;
49
                 height: 240px;
50
                 border-radius: 40px;
50
                 border-radius: 40px;
51
                 margin-right: 20px;
51
                 margin-right: 20px;
52
+                background-color: #f7f8fa;
53
+                flex-shrink: 0;
52
             }
54
             }
53
         }
55
         }
54
     }
56
     }