xiaoe_mp_npm 1.0.21 → 1.0.22-test02

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.
Files changed (149) hide show
  1. package/.prettierrc.js +32 -6
  2. package/miniprogram_dist/GoodsItem/index.json +6 -6
  3. package/miniprogram_dist/GoodsItem/index.wxs +18 -18
  4. package/miniprogram_dist/LiveGoodsList/Header/index.js +54 -54
  5. package/miniprogram_dist/LiveGoodsList/Header/index.json +6 -6
  6. package/miniprogram_dist/LiveGoodsList/Header/index.less +45 -45
  7. package/miniprogram_dist/LiveGoodsList/Header/index.scss +105 -105
  8. package/miniprogram_dist/LiveGoodsList/Header/index.wxml +32 -32
  9. package/miniprogram_dist/LiveGoodsList/README.md +9 -9
  10. package/miniprogram_dist/LiveGoodsList/index.json +8 -8
  11. package/miniprogram_dist/LiveGoodsList/index.less +53 -53
  12. package/miniprogram_dist/LiveGoodsList/index.scss +92 -92
  13. package/miniprogram_dist/Task/TaskBubble/index.js +2 -1
  14. package/miniprogram_dist/Task/TaskPopup/component/TaskItem/index.js +241 -166
  15. package/miniprogram_dist/Task/TaskPopup/component/TaskItem/index.scss +26 -0
  16. package/miniprogram_dist/Task/TaskPopup/component/TaskItem/index.wxml +27 -8
  17. package/miniprogram_dist/Task/TaskPopup/component/TaskItem/index.wxss +96 -0
  18. package/miniprogram_dist/Task/TaskPopup/component/TaskList/index.js +4 -0
  19. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.js +132 -0
  20. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.json +6 -0
  21. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.scss +192 -0
  22. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.wxml +65 -0
  23. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.wxs +79 -0
  24. package/miniprogram_dist/Task/TaskQuizPopup/components/quizContent/index.wxss +521 -0
  25. package/miniprogram_dist/Task/TaskQuizPopup/components/quizRichText/index.js +47 -0
  26. package/miniprogram_dist/Task/TaskQuizPopup/components/quizRichText/index.json +6 -0
  27. package/miniprogram_dist/Task/TaskQuizPopup/components/quizRichText/index.scss +7 -0
  28. package/miniprogram_dist/Task/TaskQuizPopup/components/quizRichText/index.wxml +2 -0
  29. package/miniprogram_dist/Task/TaskQuizPopup/components/quizRichText/index.wxss +298 -0
  30. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/base.wxml +50 -0
  31. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/html2json.js +623 -0
  32. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/htmlparser.js +183 -0
  33. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/iframeParse.js +216 -0
  34. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/loop.wxml +3563 -0
  35. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/showdown.js +2364 -0
  36. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/wxDiscode.js +209 -0
  37. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/wxParse.js +269 -0
  38. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/wxParse.wxml +1276 -0
  39. package/miniprogram_dist/Task/TaskQuizPopup/components/wxParse/wxParse.wxss +316 -0
  40. package/miniprogram_dist/Task/TaskQuizPopup/index.js +232 -0
  41. package/miniprogram_dist/Task/TaskQuizPopup/index.json +8 -0
  42. package/miniprogram_dist/Task/TaskQuizPopup/index.scss +159 -0
  43. package/miniprogram_dist/Task/TaskQuizPopup/index.wxml +97 -0
  44. package/miniprogram_dist/Task/TaskQuizPopup/index.wxss +478 -0
  45. package/miniprogram_dist/Task/taskQuizRemindPopup/index.js +79 -0
  46. package/miniprogram_dist/Task/taskQuizRemindPopup/index.json +6 -0
  47. package/miniprogram_dist/Task/taskQuizRemindPopup/index.scss +108 -0
  48. package/miniprogram_dist/Task/taskQuizRemindPopup/index.wxml +27 -0
  49. package/miniprogram_dist/Task/taskQuizRemindPopup/index.wxss +286 -0
  50. package/miniprogram_dist/common/utils/tool.js +54 -48
  51. package/package.json +1 -1
  52. package/src/AliveInvite/LiveRoomVertical/index.wxss +252 -252
  53. package/src/CollectionAddress/index.wxss +5 -5
  54. package/src/ConfirmOrder/components/AddressEdit/index.wxss +120 -120
  55. package/src/ConfirmOrder/components/AddressManage/index.wxss +98 -98
  56. package/src/ConfirmOrder/components/AddressSelect/index.wxss +67 -67
  57. package/src/ConfirmOrder/components/ChoosePicker/index.wxss +18 -18
  58. package/src/ConfirmOrder/components/GoodsInfo/components/GoodsCommerce/components/entityGiftList/index.wxss +45 -45
  59. package/src/ConfirmOrder/components/GoodsInfo/components/GoodsCommerce/components/entityItem/index.wxss +100 -100
  60. package/src/ConfirmOrder/components/GoodsInfo/components/GoodsCommerce/index.wxss +55 -55
  61. package/src/ConfirmOrder/components/GoodsInfo/components/ImageData/index.wxss +13 -13
  62. package/src/ConfirmOrder/components/Header/index.wxss +26 -26
  63. package/src/ConfirmOrder/components/IntegralSelect/componenets/integralTips/index.wxss +85 -85
  64. package/src/ConfirmOrder/components/Invoice/components/InvoiceSelect/index.wxss +155 -155
  65. package/src/ConfirmOrder/components/Invoice/components/InvoiceTip/index.wxss +51 -51
  66. package/src/ConfirmOrder/components/ModeSelect/index.wxss +44 -44
  67. package/src/ConfirmOrder/components/PickupSelect/index.wxss +22 -22
  68. package/src/ConfirmOrder/components/SelectSite/index.wxss +82 -82
  69. package/src/ConfirmOrder/components/Shipper/index.wxss +76 -76
  70. package/src/ConfirmOrder/components/ShipperEdit/index.wxss +78 -78
  71. package/src/ConfirmOrder/components/WechatAddress/index.wxss +22 -22
  72. package/src/ConfirmOrder/index.wxss +5 -5
  73. package/src/CouponList/couponMsg/index.wxss +3 -3
  74. package/src/CustomPopup/index.wxss +22 -22
  75. package/src/GoodsItem/index.json +6 -6
  76. package/src/GoodsItem/index.wxs +18 -18
  77. package/src/LiveGoodsList/Header/index.js +54 -54
  78. package/src/LiveGoodsList/Header/index.json +6 -6
  79. package/src/LiveGoodsList/Header/index.less +45 -45
  80. package/src/LiveGoodsList/Header/index.scss +105 -105
  81. package/src/LiveGoodsList/Header/index.wxml +32 -32
  82. package/src/LiveGoodsList/README.md +9 -9
  83. package/src/LiveGoodsList/index.json +8 -8
  84. package/src/LiveGoodsList/index.less +53 -53
  85. package/src/LiveGoodsList/index.scss +92 -92
  86. package/src/LiveGoodsList/index.wxss +218 -218
  87. package/src/PayComplete/Components/CouponItem/index.wxss +122 -122
  88. package/src/PayComplete/Components/Header/index.wxss +27 -27
  89. package/src/PayComplete/Components/LeadGroup/index.wxss +33 -33
  90. package/src/PayComplete/Components/PayGifts/index.wxss +157 -157
  91. package/src/PayComplete/Components/PayState/earnIntegral/index.wxss +23 -23
  92. package/src/PayComplete/Components/PayState/index.wxss +20 -20
  93. package/src/PayComplete/index.wxss +27 -27
  94. package/src/PayModule/wechatLoading/index.wxss +57 -57
  95. package/src/Recommend/index.wxss +110 -110
  96. package/src/Sku/Header/index.wxss +27 -27
  97. package/src/Sku/goods-info/index.wxss +52 -52
  98. package/src/Sku/index/index.wxss +52 -52
  99. package/src/Sku/row-item/index.wxss +50 -50
  100. package/src/Sku/step/index.wxss +11 -11
  101. package/src/Task/TaskBubble/index.js +2 -1
  102. package/src/Task/TaskBubble/index.wxss +289 -289
  103. package/src/Task/TaskIcon/index.wxss +130 -130
  104. package/src/Task/TaskPopup/component/RewardList/index.wxss +18 -18
  105. package/src/Task/TaskPopup/component/TaskItem/index.js +241 -166
  106. package/src/Task/TaskPopup/component/TaskItem/index.scss +26 -0
  107. package/src/Task/TaskPopup/component/TaskItem/index.wxml +27 -8
  108. package/src/Task/TaskPopup/component/TaskItem/index.wxss +1 -394
  109. package/src/Task/TaskPopup/component/TaskList/index.js +4 -0
  110. package/src/Task/TaskPopup/component/TaskList/index.wxss +118 -118
  111. package/src/Task/TaskPopup/component/TaskType/index.wxss +110 -110
  112. package/src/Task/TaskPopup/index.wxss +406 -406
  113. package/src/Task/TaskQuizPopup/components/quizContent/index.js +132 -0
  114. package/src/Task/TaskQuizPopup/components/quizContent/index.json +6 -0
  115. package/src/Task/TaskQuizPopup/components/quizContent/index.scss +192 -0
  116. package/src/Task/TaskQuizPopup/components/quizContent/index.wxml +65 -0
  117. package/src/Task/TaskQuizPopup/components/quizContent/index.wxs +79 -0
  118. package/src/Task/TaskQuizPopup/components/quizContent/index.wxss +1 -0
  119. package/src/Task/TaskQuizPopup/components/quizRichText/index.js +47 -0
  120. package/src/Task/TaskQuizPopup/components/quizRichText/index.json +6 -0
  121. package/src/Task/TaskQuizPopup/components/quizRichText/index.scss +7 -0
  122. package/src/Task/TaskQuizPopup/components/quizRichText/index.wxml +2 -0
  123. package/src/Task/TaskQuizPopup/components/quizRichText/index.wxss +1 -0
  124. package/src/Task/TaskQuizPopup/components/wxParse/base.wxml +50 -0
  125. package/src/Task/TaskQuizPopup/components/wxParse/html2json.js +623 -0
  126. package/src/Task/TaskQuizPopup/components/wxParse/htmlparser.js +183 -0
  127. package/src/Task/TaskQuizPopup/components/wxParse/iframeParse.js +216 -0
  128. package/src/Task/TaskQuizPopup/components/wxParse/loop.wxml +3563 -0
  129. package/src/Task/TaskQuizPopup/components/wxParse/showdown.js +2364 -0
  130. package/src/Task/TaskQuizPopup/components/wxParse/wxDiscode.js +209 -0
  131. package/src/Task/TaskQuizPopup/components/wxParse/wxParse.js +269 -0
  132. package/src/Task/TaskQuizPopup/components/wxParse/wxParse.wxml +1276 -0
  133. package/src/Task/TaskQuizPopup/components/wxParse/wxParse.wxss +283 -0
  134. package/src/Task/TaskQuizPopup/index.js +232 -0
  135. package/src/Task/TaskQuizPopup/index.json +8 -0
  136. package/src/Task/TaskQuizPopup/index.scss +159 -0
  137. package/src/Task/TaskQuizPopup/index.wxml +97 -0
  138. package/src/Task/TaskQuizPopup/index.wxss +1 -0
  139. package/src/Task/taskQuizRemindPopup/index.js +79 -0
  140. package/src/Task/taskQuizRemindPopup/index.json +6 -0
  141. package/src/Task/taskQuizRemindPopup/index.scss +108 -0
  142. package/src/Task/taskQuizRemindPopup/index.wxml +27 -0
  143. package/src/Task/taskQuizRemindPopup/index.wxss +1 -0
  144. package/src/Task/taskReceivePopup/customPrizes/index.wxss +220 -220
  145. package/src/Task/taskReceivePopup/index.wxss +1 -1
  146. package/src/Task/taskReceivePopup/integral/index.wxss +94 -94
  147. package/src/common/css/theme.wxss +16 -16
  148. package/src/common/utils/tool.js +54 -48
  149. package/src/miniprogram_npm/miniprogram-computed/index.js +1 -0
@@ -0,0 +1,183 @@
1
+ /**
2
+ * author: Di (微信小程序开发工程师)
3
+ * organization: WeAppDev(微信小程序开发论坛)(http://weappdev.com)
4
+ * 垂直微信小程序开发交流社区
5
+ *
6
+ * github地址: https://github.com/icindy/wxParse
7
+ *
8
+ * for: 微信小程序富文本解析
9
+ * detail : http://weappdev.com/t/wxparse-alpha0-1-html-markdown/184
10
+ */
11
+ // Regular Expressions for parsing tags and attributes
12
+ var startTag =
13
+ /^<([-A-Za-z0-9_]+)((?:\s+[a-zA-Z_:][-a-zA-Z0-9_:.]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
14
+ endTag = /^<\/([-A-Za-z0-9_]+)[^>]*>/,
15
+ attr = /([a-zA-Z_:][-a-zA-Z0-9_:.]*)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g
16
+
17
+ // Empty Elements - HTML 5
18
+ var empty = makeMap(
19
+ 'area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr',
20
+ )
21
+
22
+ // Block Elements - HTML 5
23
+ var block = makeMap(
24
+ 'a,address,code,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video',
25
+ )
26
+
27
+ // Inline Elements - HTML 5
28
+ var inline = makeMap(
29
+ 'abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var',
30
+ )
31
+
32
+ // Elements that you can, intentionally, leave open
33
+ // (and which close themselves)
34
+ var closeSelf = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr')
35
+
36
+ // Attributes that have their values filled in disabled="disabled"
37
+ var fillAttrs = makeMap(
38
+ 'checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected',
39
+ )
40
+
41
+ // Special Elements (can contain anything)
42
+ var special = makeMap('wxxxcode-style,script,style,view,scroll-view,block')
43
+
44
+ function HTMLParser(html, handler) {
45
+ var index,
46
+ chars,
47
+ match,
48
+ stack = [],
49
+ last = html
50
+ stack.last = function () {
51
+ return this[this.length - 1]
52
+ }
53
+
54
+ while (html) {
55
+ chars = true
56
+
57
+ // Make sure we're not in a script or style element
58
+ if (!stack.last() || !special[stack.last()]) {
59
+ // Comment
60
+ if (html.indexOf('<!--') == 0) {
61
+ index = html.indexOf('-->')
62
+
63
+ if (index >= 0) {
64
+ if (handler.comment) handler.comment(html.substring(4, index))
65
+ html = html.substring(index + 3)
66
+ chars = false
67
+ }
68
+
69
+ // end tag
70
+ } else if (html.indexOf('</') == 0) {
71
+ match = html.match(endTag)
72
+
73
+ if (match) {
74
+ html = html.substring(match[0].length)
75
+ match[0].replace(endTag, parseEndTag)
76
+ chars = false
77
+ }
78
+
79
+ // start tag
80
+ } else if (html.indexOf('<') == 0) {
81
+ match = html.match(startTag)
82
+
83
+ if (match) {
84
+ html = html.substring(match[0].length)
85
+ match[0].replace(startTag, parseStartTag)
86
+ chars = false
87
+ }
88
+ }
89
+
90
+ if (chars) {
91
+ index = html.indexOf('<')
92
+
93
+ var text = index < 0 ? html : html.substring(0, index)
94
+ html = index < 0 ? '' : html.substring(index)
95
+
96
+ if (handler.chars) handler.chars(text)
97
+ }
98
+ } else {
99
+ html = html.replace(new RegExp('([\\s\\S]*?)</' + stack.last() + '[^>]*>'), function (all, text) {
100
+ text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, '$1$2')
101
+ if (handler.chars) handler.chars(text)
102
+
103
+ return ''
104
+ })
105
+
106
+ parseEndTag('', stack.last())
107
+ }
108
+
109
+ if (html == last) throw 'Parse Error: ' + html
110
+ last = html
111
+ }
112
+
113
+ // Clean up any remaining tags
114
+ parseEndTag()
115
+
116
+ function parseStartTag(tag, tagName, rest, unary) {
117
+ tagName = tagName.toLowerCase()
118
+
119
+ if (block[tagName]) {
120
+ while (stack.last() && inline[stack.last()]) {
121
+ parseEndTag('', stack.last())
122
+ }
123
+ }
124
+
125
+ if (closeSelf[tagName] && stack.last() == tagName) {
126
+ parseEndTag('', tagName)
127
+ }
128
+
129
+ unary = empty[tagName] || !!unary
130
+
131
+ if (!unary) stack.push(tagName)
132
+
133
+ if (handler.start) {
134
+ var attrs = []
135
+
136
+ rest.replace(attr, function (match, name) {
137
+ var value = arguments[2]
138
+ ? arguments[2]
139
+ : arguments[3]
140
+ ? arguments[3]
141
+ : arguments[4]
142
+ ? arguments[4]
143
+ : fillAttrs[name]
144
+ ? name
145
+ : ''
146
+
147
+ attrs.push({
148
+ name: name,
149
+ value: value,
150
+ escaped: value.replace(/(^|[^\\])"/g, '$1\\"'), //"
151
+ })
152
+ })
153
+
154
+ if (handler.start) {
155
+ handler.start(tagName, attrs, unary)
156
+ }
157
+ }
158
+ }
159
+
160
+ function parseEndTag(tag, tagName) {
161
+ // If no tag name is provided, clean shop
162
+ if (!tagName) var pos = 0
163
+ // Find the closest opened tag of the same type
164
+ else for (var pos = stack.length - 1; pos >= 0; pos--) if (stack[pos] == tagName) break
165
+
166
+ if (pos >= 0) {
167
+ // Close all the open elements, up the stack
168
+ for (var i = stack.length - 1; i >= pos; i--) if (handler.end) handler.end(stack[i])
169
+
170
+ // Remove the open elements from the stack
171
+ stack.length = pos
172
+ }
173
+ }
174
+ }
175
+
176
+ function makeMap(str) {
177
+ var obj = {},
178
+ items = str.split(',')
179
+ for (var i = 0; i < items.length; i++) obj[items[i]] = true
180
+ return obj
181
+ }
182
+
183
+ module.exports = HTMLParser
@@ -0,0 +1,216 @@
1
+ /**
2
+ * iframe 解析器
3
+ */
4
+ class iframeParser {
5
+ constructor(domTree) {
6
+ console.warn('----------------------')
7
+ console.warn('domTree', domTree)
8
+ this.domTree = domTree // wxParse 解析出来的 dom树
9
+ this.audioArr = [] // dom 树中的 iframe 音频对象引用
10
+ this.videoArr = [] // dom 树中的 iframe 视频对象引用
11
+ this.audioMap = [] // audioArr 中对象的 id 数组, 请求用
12
+ this.videoMap = [] // videoArr 中对象的 id 数组, 请求用
13
+ this.timer = null // 定时器,请求过久的时候做容错返回
14
+ this.delay = 3000 // 延迟时间,超时返回原数据
15
+ }
16
+
17
+ /**
18
+ * 解析 domTree 并替换自有 iframe 成 video 或 audio 组件
19
+ * @return [Promise对象]
20
+ */
21
+ parse() {
22
+ return new Promise((resolve, reject) => {
23
+ // 获取所有 本地视频 和 本地音频 的 iframe 对象引用
24
+ this.findAllIFrame(this.domTree.nodes)
25
+
26
+ if (this.audioArr.length !== 0 || this.videoArr.length !== 0) {
27
+ // 生成 id 数组用于请求
28
+ this.audioMap = this.audioArr.map((el) => this.getParams('id', el.attr && el.attr.src) || false)
29
+ this.videoMap = this.videoArr.map((el) => this.getParams('id', el.attr && el.attr.src) || false)
30
+
31
+ // 延迟时间, 超时则不显示音视频资源,按老的返回
32
+ this.timer = setTimeout(() => {
33
+ reject('request timeout 3 seconds')
34
+ }, this.delay)
35
+
36
+ // 获取数据
37
+ const audioPromise = this.getAudioData()
38
+ const videoPromise = this.getVideoData()
39
+
40
+ // 等待两个回调都完成再进行替换操作
41
+ Promise.all([audioPromise, videoPromise])
42
+ .then((res) => {
43
+ this.replaceAudio(res[0], reject)
44
+ this.replaceVideo(res[1], reject)
45
+ // 清除定时器
46
+ clearTimeout(this.timer)
47
+ resolve(this.domTree)
48
+ })
49
+ .catch((err) => {
50
+ console.error('[iframeParse Error]: promise all err', err)
51
+ // 清除定时器
52
+ clearTimeout(this.timer)
53
+ reject(err)
54
+ })
55
+ } else {
56
+ resolve(this.domTree)
57
+ }
58
+ })
59
+ }
60
+
61
+ /**
62
+ * 获取 URL 中的参数
63
+ * @param {string} key [参数名称]
64
+ * @param {string} href [链接]
65
+ * @return [参数值,获取失败为空]
66
+ */
67
+ getParams(key, href) {
68
+ if (!href) return ''
69
+ const match = href.match(new RegExp('[?&]' + key + '=([^&]*)'))
70
+ return (match && match[1] && decodeURIComponent(match[1])) || ''
71
+ }
72
+
73
+ /**
74
+ * 递归获取 iframe 数组并放入 audioArr 和 videoArr 中
75
+ * @param {object} nodes [dom数组]
76
+ */
77
+ findAllIFrame(nodes) {
78
+ if (!nodes) return
79
+ let i = nodes.length - 1
80
+ for (; i >= 0; i--) {
81
+ if (nodes[i].tag === 'iframe') {
82
+ if (nodes[i].classStr && nodes[i].classStr.indexOf('xiaoe-iframe-audio') > -1) {
83
+ this.audioArr.push(nodes[i])
84
+ } else if (nodes[i].classStr && nodes[i].classStr.indexOf('xiaoe-iframe-video') > -1) {
85
+ this.videoArr.push(nodes[i])
86
+ }
87
+ if (nodes[i].nodes && nodes[i].nodes.length > 0) {
88
+ this.findAllIFrame(nodes[i].nodes)
89
+ }
90
+ } else {
91
+ this.findAllIFrame(nodes[i].nodes)
92
+ }
93
+ }
94
+ }
95
+
96
+ /**
97
+ * 获取视频链接
98
+ * @return [Promise对象]
99
+ */
100
+ getVideoData() {
101
+ if (this.videoMap.length > 0) {
102
+ return new Promise((resolve, reject) => {
103
+ getApp()
104
+ .globalData.xiaoeRequest.RICHTEXTVideo.post({ id: this.videoMap }, false)
105
+ .then((res) => {
106
+ if (res.code === 0) {
107
+ resolve(res.data)
108
+ } else {
109
+ reject('request error')
110
+ }
111
+ })
112
+ })
113
+ } else {
114
+ return Promise.resolve()
115
+ }
116
+ }
117
+
118
+ /**
119
+ * 根据 id 数组获取音频链接
120
+ * @return [Promise对象]
121
+ */
122
+ getAudioData() {
123
+ if (this.audioMap.length > 0) {
124
+ return new Promise((resolve, reject) => {
125
+ getApp()
126
+ .globalData.xiaoeRequest.RICHTEXTAudio.post({ id: this.audioMap }, false)
127
+ .then((res) => {
128
+ if (res.code === 0) {
129
+ resolve(res.data)
130
+ } else {
131
+ reject('request error')
132
+ }
133
+ })
134
+ })
135
+ } else {
136
+ return Promise.resolve()
137
+ }
138
+ }
139
+
140
+ /**
141
+ * 替换音频数据
142
+ * @param {object} res [请求返回对象]
143
+ * @param {function} reject [错误回调]
144
+ */
145
+ replaceAudio(res) {
146
+ if (this.audioMap.length === 0) return
147
+ // 根据 map 替换 audioArr 的值
148
+ this.audioMap.forEach((el) => {
149
+ const data = res[el]
150
+ if (data) {
151
+ // 每次都进行一次比对
152
+ this.audioArr.map((audioDom, index) => {
153
+ if (audioDom.attr && typeof audioDom.attr.src === 'string' && audioDom.attr.src.indexOf(el) >= 0) {
154
+ // 判断原本的 src 里有没有带对应带 audio id
155
+ this.audioArr[index].attr.src = data.file_url
156
+ this.audioArr[index].attr.length = data.audio_length
157
+ this.audioArr[index].attr.title = data.audio_title
158
+ this.audioArr[index].tag = 'xeAudio'
159
+ this.audioArr[index].id = el
160
+ }
161
+ })
162
+ }
163
+ })
164
+ }
165
+
166
+ /**
167
+ * 替换 video 资源
168
+ * @param {object} res [请求返回对象]
169
+ * @param {function} reject [错误回调]
170
+ */
171
+ replaceVideo(res) {
172
+ if (this.videoMap.length === 0) return
173
+ this.videoMap.forEach((el) => {
174
+ const data = res[el]
175
+ if (data) {
176
+ this.videoArr.map((videoDom, index) => {
177
+ if (videoDom.attr && typeof videoDom.attr.src === 'string' && videoDom.attr.src.indexOf(el) >= 0) {
178
+ this.videoArr[index].attr.src = data.file_url
179
+ this.videoArr[index].tag = 'xeVideo'
180
+ }
181
+ })
182
+ }
183
+ })
184
+ }
185
+
186
+ /**
187
+ * 格式化时间
188
+ * @param {number} time [时间/秒数]
189
+ */
190
+ formatTime(time) {
191
+ if (typeof +time === 'number' && time >= 0) {
192
+ let m = parseInt(time / 60)
193
+ let s = parseInt(time % 60)
194
+ m = m < 10 ? `0${m}` : m
195
+ s = s < 10 ? `0${s}` : s
196
+ return `${m}:${s}`
197
+ } else {
198
+ return '--:--'
199
+ }
200
+ }
201
+ }
202
+
203
+ // 修改 domTree , 将自用 iframe 替换成 video 和 audio 组件
204
+ function iframeParse(domTree, callback) {
205
+ const parser = new iframeParser(domTree, callback)
206
+ parser
207
+ .parse()
208
+ .then((res) => {
209
+ callback(res)
210
+ })
211
+ .catch((err) => {
212
+ console.error('[iFrameParse Error]: ', err)
213
+ callback(domTree)
214
+ })
215
+ }
216
+ module.exports = iframeParse