|
@@ -1,10 +1,12 @@
|
1
|
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
|
4
|
import Taro from "@tarojs/taro";
|
4
|
5
|
import "./index.less";
|
5
|
6
|
|
6
|
7
|
export default class Index extends Component {
|
7
|
8
|
state = {
|
|
9
|
+ id: "", //商品id(专题列表分享过来的)
|
8
|
10
|
shareTitle: "", //分享标题
|
9
|
11
|
productDetail: {}, //商品详情
|
10
|
12
|
isSeckill: false, //是否是秒杀商品
|
|
@@ -17,18 +19,58 @@ export default class Index extends Component {
|
17
|
19
|
Taro.hideShareMenu({
|
18
|
20
|
menus: ["shareAppMessage", "shareTimeline"],
|
19
|
21
|
});
|
20
|
|
- const { isSeckill, shareJump, tagTitle, productDetail,shareUserId,share_scheme_link } =
|
|
22
|
+ const { isSeckill, tagTitle, productDetail, shareUserId, id } =
|
21
|
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
|
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
|
75
|
handleShareTitleChange = (newTitle) => {
|
34
|
76
|
this.setState({
|
|
@@ -66,33 +108,35 @@ export default class Index extends Component {
|
66
|
108
|
|
67
|
109
|
saveImage = async () => {
|
68
|
110
|
Taro.showLoading({
|
69
|
|
- title: '保存中...',
|
|
111
|
+ title: "保存中...",
|
70
|
112
|
});
|
71
|
113
|
const { images } = this.state.productDetail;
|
72
|
114
|
try {
|
73
|
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
|
125
|
await Taro.saveImageToPhotosAlbum({
|
81
|
|
- filePath: downloadRes.tempFilePath
|
|
126
|
+ filePath: imageInfo.path,
|
82
|
127
|
});
|
83
|
128
|
}
|
84
|
|
-
|
85
|
129
|
// 全部保存成功后提示
|
86
|
130
|
Taro.showToast({
|
87
|
131
|
title: "所有图片保存成功",
|
88
|
132
|
icon: "success",
|
89
|
|
- duration: 2000
|
|
133
|
+ duration: 2000,
|
90
|
134
|
});
|
91
|
135
|
} catch (error) {
|
92
|
136
|
Taro.showToast({
|
93
|
137
|
title: "保存失败",
|
94
|
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
|
154
|
Taro.showToast({
|
111
|
155
|
title: "标题复制成功",
|
112
|
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
|
167
|
Taro.showToast({
|
124
|
168
|
title: "链接复制成功",
|
125
|
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
|
209
|
<View className="text-box">
|
166
|
210
|
<View className="text-box-top">
|
167
|
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
|
215
|
</View>
|
170
|
216
|
<View className="text-box-content">
|
171
|
217
|
{/* 商品标题盒子 */}
|
|
@@ -174,7 +220,10 @@ export default class Index extends Component {
|
174
|
220
|
<View className="text-box-content-title-top-title">
|
175
|
221
|
商品标题
|
176
|
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
|
228
|
</View>
|
180
|
229
|
</View>
|
|
@@ -204,16 +253,26 @@ export default class Index extends Component {
|
204
|
253
|
/>
|
205
|
254
|
<View className="copy-box">
|
206
|
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
|
261
|
</View>
|
209
|
262
|
</View>
|
210
|
263
|
</View>
|
211
|
264
|
</View>
|
212
|
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
|
276
|
</View>
|
218
|
277
|
);
|
219
|
278
|
}
|