changePopup.js
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const IMG_URL =
"https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/";
Component({
properties: {
show: {
type: Boolean,
value: false,
},
title: {
type: String,
value: "选择商品",
},
height: {
type: String,
value: "70%",
},
changes: {
type: Array,
value: [],
},
singleButton: {
type: Boolean,
value: false,
},
confirmText: {
type: String,
value: "确认",
},
},
data: {
IMG_URL,
videoProcess: "?x-oss-process=video/snapshot,t_0,f_jpg",
},
methods: {
onConfirm() {
this.triggerEvent("confirm");
},
onCancel() {
this.triggerEvent("cancel");
},
// 预览图片/视频
onPreview(e) {
const { url, type } = e.currentTarget.dataset;
if (!url) return;
if (type === "video") {
wx.previewMedia({
sources: [
{
url,
type: "video",
},
],
});
} else {
wx.previewImage({
current: url,
urls: [url],
});
}
},
isVideo(url) {
if (!url || typeof url !== "string") return false;
const lower = url.toLowerCase();
return (
lower.includes("mp4") ||
lower.includes("mov") ||
lower.includes("video")
);
},
isMedia(url) {
if (!url || typeof url !== "string") return false;
// 判断是否为URL(http/https开头)或图片/视频扩展名
const lower = url.toLowerCase();
return (
url.startsWith("http://") ||
url.startsWith("https://") ||
lower.includes(".jpg") ||
lower.includes(".jpeg") ||
lower.includes(".png") ||
lower.includes(".webp") ||
lower.includes(".gif") ||
lower.includes(".mp4") ||
lower.includes(".mov")
);
},
formatType(type) {
console.log(type, "type");
if (type === "image") return "图像变更";
if (type === "video") return "视频变更";
return "文本变更";
},
},
});