Showing
4 changed files
with
68 additions
and
2 deletions
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | "newFeature": true | 8 | "newFeature": true |
9 | }, | 9 | }, |
10 | "compileType": "miniprogram", | 10 | "compileType": "miniprogram", |
11 | - "libVersion": "1.6.6", | 11 | + "libVersion": "1.9.1", |
12 | "appid": "wx084ab813d88c594b", | 12 | "appid": "wx084ab813d88c594b", |
13 | "projectname": "%E7%BA%A2%E4%BA%BA%E5%B0%8F%E5%BA%97", | 13 | "projectname": "%E7%BA%A2%E4%BA%BA%E5%B0%8F%E5%BA%97", |
14 | "condition": { | 14 | "condition": { |
app/wxs/helper.wxs
0 → 100644
1 | +/* global getRegExp */ | ||
2 | +var regExpWidth = getRegExp('{width}', 'g'); | ||
3 | +var regExpHeight = getRegExp('{height}', 'g'); | ||
4 | +var regExpMode = getRegExp('{mode}', 'g'); | ||
5 | +var regExpQg = getRegExp('/q/d+', 'g'); | ||
6 | +var regExpQ = getRegExp('/q/d+'); | ||
7 | +var regExpQuality = getRegExp('/quality/d+'); | ||
8 | +var regExpQualityg = getRegExp('/quality/d+', 'g'); | ||
9 | +var regExpImageView = getRegExp('imageView'); | ||
10 | +var regExpImageMogr = getRegExp('imageMogr'); | ||
11 | + | ||
12 | +var defaultQuality = 75; | ||
13 | + | ||
14 | +function image(imgUrl, w, h, mode, q) { | ||
15 | + var urls, | ||
16 | + query, | ||
17 | + url; | ||
18 | + | ||
19 | + var params = { | ||
20 | + w: w, | ||
21 | + h: h, | ||
22 | + mode: mode || 2, | ||
23 | + q: q || defaultQuality | ||
24 | + }; | ||
25 | + | ||
26 | + if (imgUrl && (typeof imgUrl === 'string')) { | ||
27 | + urls = imgUrl.split('?'); | ||
28 | + query = urls[1] || ''; | ||
29 | + url = urls[0]; | ||
30 | + | ||
31 | + if (url.indexOf('http:') === 0) { | ||
32 | + url = url.replace('http:', 'https:'); | ||
33 | + } | ||
34 | + | ||
35 | + if (!query || query === 'imageslim') { | ||
36 | + url += params.q === defaultQuality ? '?imageslim' : '?imageView2/0/interlace/1/q/' + params.q; | ||
37 | + imgUrl = url; | ||
38 | + } else { | ||
39 | + imgUrl = imgUrl.replace(regExpWidth, params.w) | ||
40 | + .replace(regExpHeight, params.h) | ||
41 | + .replace(regExpMode, (params.mode)); | ||
42 | + | ||
43 | + if (regExpImageView.test(query)) { // imageView2 || imageView | ||
44 | + if (!regExpQ.test(query)) { | ||
45 | + imgUrl += '/q/' + params.q; | ||
46 | + } else { | ||
47 | + imgUrl = imgUrl.replace(regExpQg, '/q/' + params.q); | ||
48 | + } | ||
49 | + } else if (regExpImageMogr.test(query)) { | ||
50 | + if (!regExpQuality.test(query)) { | ||
51 | + imgUrl += '/quality/' + params.q; | ||
52 | + } else { | ||
53 | + imgUrl = imgUrl.replace(regExpQualityg, '/quality/' + params.q); | ||
54 | + } | ||
55 | + } | ||
56 | + } | ||
57 | + return imgUrl; | ||
58 | + } else { | ||
59 | + return ''; | ||
60 | + } | ||
61 | +} | ||
62 | + | ||
63 | +module.exports = { | ||
64 | + image: image | ||
65 | +}; |
-
Please register or login to post a comment