xiaoe_mp_npm 0.3.105-t220428 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
  wx:for="{{friendList}}"
15
15
  >
16
16
  <image wx:if="{{item.wx_avatar}}" class="img-avatar" src="{{item.wx_avatar}}" />
17
- <image wx:else class="img-avatar" src="//wechatavator-1252524126.cos.ap-shanghai.myqcloud.com/aaa/default.svg" />
17
+ <image wx:else class="img-avatar" src="//wechatavator-1252524126.cdn.xiaoeknow.com/aaa/default.svg" />
18
18
  <view class="name">
19
19
  {{ item.wx_nickname }}
20
20
  </view>
@@ -24,7 +24,7 @@
24
24
  width: 750rpx;
25
25
  height: calc(100vh - 494rpx);
26
26
  background-color: #fff !important;
27
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
27
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
28
28
  background-size: contain;
29
29
  background-repeat: no-repeat;
30
30
  border-radius: 16rpx 16rpx 0 0;
@@ -8,7 +8,7 @@
8
8
  height: 100%;
9
9
  flex:1;
10
10
  background-color: #fff !important;
11
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
11
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
12
12
  background-size: contain;
13
13
  background-repeat: no-repeat;
14
14
  border-radius: 16px 16px 0 0;
@@ -20,13 +20,13 @@
20
20
  animation: popping ease 300ms;
21
21
  // height: 1035rpx;
22
22
  background-color: #fff !important;
23
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
23
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
24
24
  background-size: contain;
25
25
  background-repeat: no-repeat;
26
26
  border-radius: 16px 16px 0 0;
27
27
  }
28
28
  .img-background {
29
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
29
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
30
30
  background-size: cover;
31
31
  display: flex;
32
32
  align-items: center;
@@ -52,7 +52,7 @@
52
52
  <view wx:else class="num">{{ item.ranking }}</view>
53
53
  <view class="warp-avatar">
54
54
  <image wx:if="{{item.avatar}}" class="img-avatar" src="{{item.avatar}}" />
55
- <image wx:else class="img-avatar" src="//wechatavator-1252524126.cos.ap-shanghai.myqcloud.com/aaa/default.svg" />
55
+ <image wx:else class="img-avatar" src="//wechatavator-1252524126.cdn.xiaoeknow.com/aaa/default.svg" />
56
56
  <view class="name">
57
57
  {{ item.name }}
58
58
  </view>
@@ -8,7 +8,7 @@
8
8
  height: 100%;
9
9
  flex: 1;
10
10
  background-color: #fff !important;
11
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
11
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
12
12
  background-size: contain;
13
13
  background-repeat: no-repeat;
14
14
  border-radius: 16px 16px 0 0;
@@ -19,13 +19,13 @@
19
19
  .container-ranking {
20
20
  animation: popping ease 300ms;
21
21
  background-color: #fff !important;
22
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
22
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
23
23
  background-size: contain;
24
24
  background-repeat: no-repeat;
25
25
  border-radius: 16px 16px 0 0;
26
26
  }
27
27
  .img-background {
28
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
28
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
29
29
  background-size: cover;
30
30
  display: flex;
31
31
  align-items: center;
@@ -273,6 +273,7 @@ Component({
273
273
  union_id: wx.getStorageSync('userInfo').universal_union_id,
274
274
  current_role: sensorReportParams.current_role,
275
275
  resource_id: aliveInfo.alive_id,
276
+ url_path: `alive/${aliveInfo.alive_id}`,
276
277
  type: sensorReportParams.type,
277
278
  cmm1: sensorReportParams.alive_type,
278
279
  cmm2: sensorReportParams.version_type,
@@ -332,6 +333,7 @@ Component({
332
333
  union_id: wx.getStorageSync('userInfo').universal_union_id,
333
334
  current_role: sensorReportParams.current_role,
334
335
  resource_id: aliveInfo.alive_id,
336
+ url_path: `alive/${aliveInfo.alive_id}`,
335
337
  type: sensorReportParams.type,
336
338
  cmm1: sensorReportParams.alive_type,
337
339
  cmm2: sensorReportParams.version_type,
@@ -506,6 +508,7 @@ Component({
506
508
  union_id: wx.getStorageSync('userInfo').universal_union_id,
507
509
  current_role: sensorReportParams.current_role,
508
510
  resource_id: aliveInfo.alive_id,
511
+ url_path: `alive/${aliveInfo.alive_id}`,
509
512
  type: sensorReportParams.type,
510
513
  cmm1: sensorReportParams.alive_type,
511
514
  cmm2: sensorReportParams.version_type,
@@ -109,6 +109,7 @@ Component({
109
109
  union_id: wx.getStorageSync('userInfo').universal_union_id,
110
110
  current_role: sensorReportParams.current_role ? sensorReportParams.current_role :'',
111
111
  resource_id: aliveInfo.alive_id,
112
+ url_path: `alive/${aliveInfo.alive_id}`,
112
113
  type: sensorReportParams.type ? sensorReportParams.type :'',
113
114
  cmm1: sensorReportParams.alive_type ? sensorReportParams.alive_type :'',
114
115
  cmm2: sensorReportParams.version_type ? sensorReportParams.version_type : '',
@@ -0,0 +1,8 @@
1
+ export const NEED_REPLACE = [
2
+ '.picsh.myqcloud.com',
3
+ '.file.myqcloud.com',
4
+ '.cossh.myqcloud.com',
5
+ '.cdn.xiaoeknow.com'
6
+ ]
7
+
8
+ export const COS_V5 = '.cdn.xiaoeknow.com'
@@ -0,0 +1,7 @@
1
+ import { replaceCDN, replaceAllImg } from './utils'
2
+
3
+ // 处理图片链接
4
+ export const getImageCdnSlimUrl = (url, config = '/2/w/1025/a/100') => url ? replaceCDN(url, `?imageView2${config}`, true) : url;
5
+
6
+ // 处理富文本
7
+ export const getImageCdnSlimRichTextContent = richText => replaceAllImg(richText, false, {quality: '80'});
@@ -0,0 +1,157 @@
1
+ import { NEED_REPLACE, COS_V5 } from './constant'
2
+
3
+ /**
4
+ * 图片CDN替换
5
+ * @param src 字符串,图片URL链接,或者数组['src']
6
+ * @param ci 数据万象参数
7
+ * 如果为字符串会直接把参数拼接到cdn后面
8
+ * 如果是对象参数见_genCI方法
9
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
10
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
11
+ * */
12
+ export const replaceCDN = function (src = '', ci) {
13
+ if (!src.length) return src
14
+ const isSrcArray = Array.isArray(src);
15
+ src = isSrcArray ? src : [src];
16
+ // 生成数据万象链接
17
+ ci = typeof ci === 'string' ? ci : _genCI(ci);
18
+ const hasValue = (item, aim) => item.indexOf(aim) > -1;
19
+ // 获取文件格式
20
+ const getFileSuffix = (item = '') => item.split('.').pop().toLowerCase();
21
+ // 获取需要替换为CDN的链接
22
+ const getReplaceURL = (item = '') => {
23
+ // cos 源站地址 例如:cos.ap-shanghai.myqcloud.com
24
+ const cosMatch = item.match(/\.cos\.ap-([^.]*)\.myqcloud.com/);
25
+ if (cosMatch) {
26
+ return cosMatch[0]
27
+ }
28
+ return NEED_REPLACE.find(url => hasValue(item, url))
29
+ }
30
+ // 转换后的格式
31
+ let formatSuffix = ci.match(/\/format\/([^/|?]+)/);
32
+ formatSuffix = formatSuffix ? formatSuffix[1].toLowerCase() : null;
33
+ // 不支持webp时会降级成jpeg
34
+ if (!isWebp() && formatSuffix === 'webp') {
35
+ ci = ci.replace('format/webp', '')
36
+ }
37
+ // 转换后格式是否为静态图片
38
+ const isFormatStaticType = ['jpg', 'jpeg', 'png', 'bmp', 'tpg', 'heif'].includes(formatSuffix);
39
+ // imgView2|imgMorg2 错误兼容
40
+ ci = `${ci}|imageMogr2/ignore-error/1`
41
+ const result = src.map(item => {
42
+ const fileSuffix = getFileSuffix(item);
43
+ const replaceUrl = getReplaceURL(item);
44
+ // 不支持svg格式,且需要有符合条件可替换成url才进行替换
45
+ if (fileSuffix !== 'svg' && replaceUrl) {
46
+ let srcCI = ci;
47
+ // 动态图片不能转成静态图片,不然会静止
48
+ if (fileSuffix == 'gif' && isFormatStaticType) {
49
+ srcCI = srcCI.replace(`/format/${formatSuffix}`, '')
50
+ }
51
+ item = item.replace(replaceUrl, COS_V5) + srcCI;
52
+ }
53
+ return item
54
+ })
55
+ return isSrcArray ? result : result[0];
56
+
57
+ }
58
+
59
+
60
+ /**
61
+ * 富文本html图片CDN替换
62
+ * @param html html字符串
63
+ * @param lazyLoad 是否需要懒加载
64
+ * @param ci 数据万象参数
65
+ * 如果为字符串会直接把参数拼接到cdn后面
66
+ * 如果是对象参数见_genCI方法
67
+ * example: replaceAllImg('html', true, '?imageView2/2/w/800')
68
+ * return: html
69
+ * */
70
+ export const replaceAllImg = function (html, lazyLoad = false, ci = '?imageMogr2/thumbnail/800x>/format/webp') {
71
+ return html.replace(/<img[^>]*>/gi, str => {
72
+ const srcReg = /src=['"]?([^'"]*)['"]?/i;
73
+ const dataSrc = lazyLoad ? 'data-src' : 'src'
74
+ const url = str.match(srcReg);
75
+ //没有 src 属性的 <img></img> 匹配不到 返回 <img src="@/assets/imgs/photo_error.png" />
76
+ if (Array.isArray(url) && url.length > 1) {
77
+ const newSrc = replaceCDN(url[1], ci)
78
+ return str.replace(url[0], `${dataSrc}="${newSrc}"`);
79
+ }
80
+ return `<img ${dataSrc}="https://wechatapppro-1252524126.cdn.xiaoeknow.com/appAKLWLitn7978/image/b_u_5b2225aa46488_oGKN7IvA/ky19qhac05ix.png" />`
81
+
82
+ });
83
+ }
84
+
85
+ /**
86
+ * 根据参数生成数据万象链接
87
+ * @param data 参数为 { type, width, height, quality, rquality, lquality, format, extra }
88
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
89
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
90
+ * */
91
+ const _genCI = (data = {}) => {
92
+ const defaultParams = { type: '2', format: 'webp', quality: '80'};
93
+ if (data.rquality || data.lquality) {
94
+ delete defaultParams.quality
95
+ }
96
+ data = Object.assign(defaultParams, data);
97
+ const paramMap = {
98
+ width: 'w',
99
+ height: 'h',
100
+ quality: 'q',
101
+ rquality: 'rq',
102
+ lquality: 'lq',
103
+ format: 'format'
104
+ }
105
+ const keys = Object.keys(paramMap);
106
+
107
+ let path = ''
108
+ keys.forEach(key => {
109
+ const dataVal = data[key];
110
+ if (dataVal) {
111
+ path += `/${paramMap[key]}/${data[key]}`
112
+ }
113
+ })
114
+
115
+ if (path) {
116
+ const extra = data.extra || '';
117
+ path = `?imageView2/${data.type}${path}${extra}`
118
+ }
119
+ return path;
120
+ }
121
+
122
+ /**
123
+ * 检测是否支持Webp
124
+ * @param data 参数为 { type, width, height, quality, rquality, lquality, format, extra }
125
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
126
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
127
+ * */
128
+ const isWebp = () => {
129
+ let support = false;
130
+
131
+ try {
132
+ const _wx$getSystemInfoSync = wx.getSystemInfoSync(),
133
+ platform = _wx$getSystemInfoSync.platform,
134
+ system = _wx$getSystemInfoSync.system;
135
+
136
+ const versionResult = /[0-9.]*$/.exec(system);
137
+ const systemVersion = versionResult ? versionResult[0] : '';
138
+ const iosSystemSupport =
139
+ platform === 'ios' &&
140
+ !!systemVersion &&
141
+ compareVersion(systemVersion, '14.0') >= 0; // ios 14以下的版本不支持 webp
142
+
143
+ support =
144
+ platform === 'devtools' ||
145
+ platform === 'android' ||
146
+ iosSystemSupport;
147
+ } catch (e) {
148
+ console.log(e);
149
+ }
150
+
151
+ return support;
152
+ }
153
+
154
+ // 比较前面的版本是否比后面的版本要大
155
+ const compareVersion = (currentVersion, targetVersion) => {
156
+ return Math.ceil(currentVersion - targetVersion)
157
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xiaoe_mp_npm",
3
- "version": "0.3.105-t220428",
3
+ "version": "0.4.2",
4
4
  "description": "",
5
5
  "main": "miniprogram_dist/index.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@
14
14
  wx:for="{{friendList}}"
15
15
  >
16
16
  <image wx:if="{{item.wx_avatar}}" class="img-avatar" src="{{item.wx_avatar}}" />
17
- <image wx:else class="img-avatar" src="//wechatavator-1252524126.cos.ap-shanghai.myqcloud.com/aaa/default.svg" />
17
+ <image wx:else class="img-avatar" src="//wechatavator-1252524126.cdn.xiaoeknow.com/aaa/default.svg" />
18
18
  <view class="name">
19
19
  {{ item.wx_nickname }}
20
20
  </view>
@@ -24,7 +24,7 @@
24
24
  width: 750rpx;
25
25
  height: calc(100vh - 494rpx);
26
26
  background-color: #fff !important;
27
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
27
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
28
28
  background-size: contain;
29
29
  background-repeat: no-repeat;
30
30
  border-radius: 16rpx 16rpx 0 0;
@@ -8,7 +8,7 @@
8
8
  height: 100%;
9
9
  flex:1;
10
10
  background-color: #fff !important;
11
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
11
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
12
12
  background-size: contain;
13
13
  background-repeat: no-repeat;
14
14
  border-radius: 16px 16px 0 0;
@@ -20,13 +20,13 @@
20
20
  animation: popping ease 300ms;
21
21
  // height: 1035rpx;
22
22
  background-color: #fff !important;
23
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
23
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
24
24
  background-size: contain;
25
25
  background-repeat: no-repeat;
26
26
  border-radius: 16px 16px 0 0;
27
27
  }
28
28
  .img-background {
29
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
29
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
30
30
  background-size: cover;
31
31
  display: flex;
32
32
  align-items: center;
@@ -52,7 +52,7 @@
52
52
  <view wx:else class="num">{{ item.ranking }}</view>
53
53
  <view class="warp-avatar">
54
54
  <image wx:if="{{item.avatar}}" class="img-avatar" src="{{item.avatar}}" />
55
- <image wx:else class="img-avatar" src="//wechatavator-1252524126.cos.ap-shanghai.myqcloud.com/aaa/default.svg" />
55
+ <image wx:else class="img-avatar" src="//wechatavator-1252524126.cdn.xiaoeknow.com/aaa/default.svg" />
56
56
  <view class="name">
57
57
  {{ item.name }}
58
58
  </view>
@@ -8,7 +8,7 @@
8
8
  height: 100%;
9
9
  flex: 1;
10
10
  background-color: #fff !important;
11
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
11
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
12
12
  background-size: contain;
13
13
  background-repeat: no-repeat;
14
14
  border-radius: 16px 16px 0 0;
@@ -19,13 +19,13 @@
19
19
  .container-ranking {
20
20
  animation: popping ease 300ms;
21
21
  background-color: #fff !important;
22
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
22
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2l510aau.png?imageView2/2/w/200/q/60");
23
23
  background-size: contain;
24
24
  background-repeat: no-repeat;
25
25
  border-radius: 16px 16px 0 0;
26
26
  }
27
27
  .img-background {
28
- background: url("https://wechatapppro-1252524126.cos.ap-shanghai.myqcloud.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
28
+ background: url("https://wechatapppro-1252524126.cdn.xiaoeknow.com/appgwaqerxu2025/image/b_u_5b2225aa46488_oGKN7IvA/kpzb2k2t0iqn.png?imageView2/2/w/200/q/60");
29
29
  background-size: cover;
30
30
  display: flex;
31
31
  align-items: center;
@@ -273,6 +273,7 @@ Component({
273
273
  union_id: wx.getStorageSync('userInfo').universal_union_id,
274
274
  current_role: sensorReportParams.current_role,
275
275
  resource_id: aliveInfo.alive_id,
276
+ url_path: `alive/${aliveInfo.alive_id}`,
276
277
  type: sensorReportParams.type,
277
278
  cmm1: sensorReportParams.alive_type,
278
279
  cmm2: sensorReportParams.version_type,
@@ -332,6 +333,7 @@ Component({
332
333
  union_id: wx.getStorageSync('userInfo').universal_union_id,
333
334
  current_role: sensorReportParams.current_role,
334
335
  resource_id: aliveInfo.alive_id,
336
+ url_path: `alive/${aliveInfo.alive_id}`,
335
337
  type: sensorReportParams.type,
336
338
  cmm1: sensorReportParams.alive_type,
337
339
  cmm2: sensorReportParams.version_type,
@@ -506,6 +508,7 @@ Component({
506
508
  union_id: wx.getStorageSync('userInfo').universal_union_id,
507
509
  current_role: sensorReportParams.current_role,
508
510
  resource_id: aliveInfo.alive_id,
511
+ url_path: `alive/${aliveInfo.alive_id}`,
509
512
  type: sensorReportParams.type,
510
513
  cmm1: sensorReportParams.alive_type,
511
514
  cmm2: sensorReportParams.version_type,
@@ -109,6 +109,7 @@ Component({
109
109
  union_id: wx.getStorageSync('userInfo').universal_union_id,
110
110
  current_role: sensorReportParams.current_role ? sensorReportParams.current_role :'',
111
111
  resource_id: aliveInfo.alive_id,
112
+ url_path: `alive/${aliveInfo.alive_id}`,
112
113
  type: sensorReportParams.type ? sensorReportParams.type :'',
113
114
  cmm1: sensorReportParams.alive_type ? sensorReportParams.alive_type :'',
114
115
  cmm2: sensorReportParams.version_type ? sensorReportParams.version_type : '',
@@ -0,0 +1,8 @@
1
+ export const NEED_REPLACE = [
2
+ '.picsh.myqcloud.com',
3
+ '.file.myqcloud.com',
4
+ '.cossh.myqcloud.com',
5
+ '.cdn.xiaoeknow.com'
6
+ ]
7
+
8
+ export const COS_V5 = '.cdn.xiaoeknow.com'
@@ -0,0 +1,7 @@
1
+ import { replaceCDN, replaceAllImg } from './utils'
2
+
3
+ // 处理图片链接
4
+ export const getImageCdnSlimUrl = (url, config = '/2/w/1025/a/100') => url ? replaceCDN(url, `?imageView2${config}`, true) : url;
5
+
6
+ // 处理富文本
7
+ export const getImageCdnSlimRichTextContent = richText => replaceAllImg(richText, false, {quality: '80'});
@@ -0,0 +1,157 @@
1
+ import { NEED_REPLACE, COS_V5 } from './constant'
2
+
3
+ /**
4
+ * 图片CDN替换
5
+ * @param src 字符串,图片URL链接,或者数组['src']
6
+ * @param ci 数据万象参数
7
+ * 如果为字符串会直接把参数拼接到cdn后面
8
+ * 如果是对象参数见_genCI方法
9
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
10
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
11
+ * */
12
+ export const replaceCDN = function (src = '', ci) {
13
+ if (!src.length) return src
14
+ const isSrcArray = Array.isArray(src);
15
+ src = isSrcArray ? src : [src];
16
+ // 生成数据万象链接
17
+ ci = typeof ci === 'string' ? ci : _genCI(ci);
18
+ const hasValue = (item, aim) => item.indexOf(aim) > -1;
19
+ // 获取文件格式
20
+ const getFileSuffix = (item = '') => item.split('.').pop().toLowerCase();
21
+ // 获取需要替换为CDN的链接
22
+ const getReplaceURL = (item = '') => {
23
+ // cos 源站地址 例如:cos.ap-shanghai.myqcloud.com
24
+ const cosMatch = item.match(/\.cos\.ap-([^.]*)\.myqcloud.com/);
25
+ if (cosMatch) {
26
+ return cosMatch[0]
27
+ }
28
+ return NEED_REPLACE.find(url => hasValue(item, url))
29
+ }
30
+ // 转换后的格式
31
+ let formatSuffix = ci.match(/\/format\/([^/|?]+)/);
32
+ formatSuffix = formatSuffix ? formatSuffix[1].toLowerCase() : null;
33
+ // 不支持webp时会降级成jpeg
34
+ if (!isWebp() && formatSuffix === 'webp') {
35
+ ci = ci.replace('format/webp', '')
36
+ }
37
+ // 转换后格式是否为静态图片
38
+ const isFormatStaticType = ['jpg', 'jpeg', 'png', 'bmp', 'tpg', 'heif'].includes(formatSuffix);
39
+ // imgView2|imgMorg2 错误兼容
40
+ ci = `${ci}|imageMogr2/ignore-error/1`
41
+ const result = src.map(item => {
42
+ const fileSuffix = getFileSuffix(item);
43
+ const replaceUrl = getReplaceURL(item);
44
+ // 不支持svg格式,且需要有符合条件可替换成url才进行替换
45
+ if (fileSuffix !== 'svg' && replaceUrl) {
46
+ let srcCI = ci;
47
+ // 动态图片不能转成静态图片,不然会静止
48
+ if (fileSuffix == 'gif' && isFormatStaticType) {
49
+ srcCI = srcCI.replace(`/format/${formatSuffix}`, '')
50
+ }
51
+ item = item.replace(replaceUrl, COS_V5) + srcCI;
52
+ }
53
+ return item
54
+ })
55
+ return isSrcArray ? result : result[0];
56
+
57
+ }
58
+
59
+
60
+ /**
61
+ * 富文本html图片CDN替换
62
+ * @param html html字符串
63
+ * @param lazyLoad 是否需要懒加载
64
+ * @param ci 数据万象参数
65
+ * 如果为字符串会直接把参数拼接到cdn后面
66
+ * 如果是对象参数见_genCI方法
67
+ * example: replaceAllImg('html', true, '?imageView2/2/w/800')
68
+ * return: html
69
+ * */
70
+ export const replaceAllImg = function (html, lazyLoad = false, ci = '?imageMogr2/thumbnail/800x>/format/webp') {
71
+ return html.replace(/<img[^>]*>/gi, str => {
72
+ const srcReg = /src=['"]?([^'"]*)['"]?/i;
73
+ const dataSrc = lazyLoad ? 'data-src' : 'src'
74
+ const url = str.match(srcReg);
75
+ //没有 src 属性的 <img></img> 匹配不到 返回 <img src="@/assets/imgs/photo_error.png" />
76
+ if (Array.isArray(url) && url.length > 1) {
77
+ const newSrc = replaceCDN(url[1], ci)
78
+ return str.replace(url[0], `${dataSrc}="${newSrc}"`);
79
+ }
80
+ return `<img ${dataSrc}="https://wechatapppro-1252524126.cdn.xiaoeknow.com/appAKLWLitn7978/image/b_u_5b2225aa46488_oGKN7IvA/ky19qhac05ix.png" />`
81
+
82
+ });
83
+ }
84
+
85
+ /**
86
+ * 根据参数生成数据万象链接
87
+ * @param data 参数为 { type, width, height, quality, rquality, lquality, format, extra }
88
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
89
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
90
+ * */
91
+ const _genCI = (data = {}) => {
92
+ const defaultParams = { type: '2', format: 'webp', quality: '80'};
93
+ if (data.rquality || data.lquality) {
94
+ delete defaultParams.quality
95
+ }
96
+ data = Object.assign(defaultParams, data);
97
+ const paramMap = {
98
+ width: 'w',
99
+ height: 'h',
100
+ quality: 'q',
101
+ rquality: 'rq',
102
+ lquality: 'lq',
103
+ format: 'format'
104
+ }
105
+ const keys = Object.keys(paramMap);
106
+
107
+ let path = ''
108
+ keys.forEach(key => {
109
+ const dataVal = data[key];
110
+ if (dataVal) {
111
+ path += `/${paramMap[key]}/${data[key]}`
112
+ }
113
+ })
114
+
115
+ if (path) {
116
+ const extra = data.extra || '';
117
+ path = `?imageView2/${data.type}${path}${extra}`
118
+ }
119
+ return path;
120
+ }
121
+
122
+ /**
123
+ * 检测是否支持Webp
124
+ * @param data 参数为 { type, width, height, quality, rquality, lquality, format, extra }
125
+ * example: replaceCDN('https://wechatapppro-1252524126.picsh.myqcloud.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg', '?imageView2/2/w/800')
126
+ * return: 'https://wechatapppro-1252524126.cdn.xiaoeknow.com/appaBx10ofe8494/image/kpcbjfwx0sdvg37z6dy.jpg??imageView2/2/w/800'
127
+ * */
128
+ const isWebp = () => {
129
+ let support = false;
130
+
131
+ try {
132
+ const _wx$getSystemInfoSync = wx.getSystemInfoSync(),
133
+ platform = _wx$getSystemInfoSync.platform,
134
+ system = _wx$getSystemInfoSync.system;
135
+
136
+ const versionResult = /[0-9.]*$/.exec(system);
137
+ const systemVersion = versionResult ? versionResult[0] : '';
138
+ const iosSystemSupport =
139
+ platform === 'ios' &&
140
+ !!systemVersion &&
141
+ compareVersion(systemVersion, '14.0') >= 0; // ios 14以下的版本不支持 webp
142
+
143
+ support =
144
+ platform === 'devtools' ||
145
+ platform === 'android' ||
146
+ iosSystemSupport;
147
+ } catch (e) {
148
+ console.log(e);
149
+ }
150
+
151
+ return support;
152
+ }
153
+
154
+ // 比较前面的版本是否比后面的版本要大
155
+ const compareVersion = (currentVersion, targetVersion) => {
156
+ return Math.ceil(currentVersion - targetVersion)
157
+ }