@aochuang/common 1.0.1 → 1.0.126

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 (283) hide show
  1. package/common/index.js +13 -0
  2. package/common/resizable/index.js +3 -0
  3. package/common/resizable/resizable.vue +260 -0
  4. package/common/scroll-load-more/index.js +3 -0
  5. package/common/scroll-load-more/scroll-load-more.vue +397 -0
  6. package/common/static-map/index.js +3 -0
  7. package/common/static-map/static-map.vue +87 -0
  8. package/common/tooltip/tooltip.vue +27 -7
  9. package/common/viewer/index.js +4 -0
  10. package/common/viewer/util.js +40 -0
  11. package/common/viewer/viewer.vue +607 -0
  12. package/common/viewer-pedestal/index.js +3 -0
  13. package/common/viewer-pedestal/viewer-pedestal.vue +70 -0
  14. package/common/voice/index.js +21 -0
  15. package/common/voice/util.js +18 -0
  16. package/common/voice/voice-player-aac.js +584 -0
  17. package/common/voice/voice-player-audio.js +159 -0
  18. package/common/voice/voice-player.js +309 -0
  19. package/common/voice/voice.vue +274 -0
  20. package/common/voice-player/index.js +3 -0
  21. package/common/voice-player/voice-player.vue +785 -0
  22. package/common/waterfall/index.js +3 -0
  23. package/common/waterfall/waterfall.vue +169 -0
  24. package/common/wechat-emoji/emoji/666.png +0 -0
  25. package/common/wechat-emoji/emoji/Emm.png +0 -0
  26. package/common/wechat-emoji/emoji/OK.png +0 -0
  27. package/common/wechat-emoji/emoji//344/272/262/344/272/262.png +0 -0
  28. package/common/wechat-emoji/emoji//344/276/277/344/276/277.png +0 -0
  29. package/common/wechat-emoji/emoji//345/201/267/347/254/221.png +0 -0
  30. package/common/wechat-emoji/emoji//345/202/262/346/205/242.png +0 -0
  31. package/common/wechat-emoji/emoji//345/206/215/350/247/201.png +0 -0
  32. package/common/wechat-emoji/emoji//345/207/213/350/260/242.png +0 -0
  33. package/common/wechat-emoji/emoji//345/210/240/351/231/244.png +0 -0
  34. package/common/wechat-emoji/emoji//345/212/240/346/262/271.png +0 -0
  35. package/common/wechat-emoji/emoji//345/213/276/345/274/225.png +0 -0
  36. package/common/wechat-emoji/emoji//345/217/221/345/221/206.png +0 -0
  37. package/common/wechat-emoji/emoji//345/217/221/346/200/222.png +0 -0
  38. package/common/wechat-emoji/emoji//345/217/221/346/212/226.png +0 -0
  39. package/common/wechat-emoji/emoji//345/217/257/346/200/234.png +0 -0
  40. package/common/wechat-emoji/emoji//345/217/263/345/223/274/345/223/274.png +0 -0
  41. package/common/wechat-emoji/emoji//345/217/271/346/260/224.png +0 -0
  42. package/common/wechat-emoji/emoji//345/220/203/347/223/234.png +0 -0
  43. package/common/wechat-emoji/emoji//345/220/210/345/215/201.png +0 -0
  44. package/common/wechat-emoji/emoji//345/220/220.png +0 -0
  45. package/common/wechat-emoji/emoji//345/220/220/350/210/214/345/244/264.png +0 -0
  46. package/common/wechat-emoji/emoji//345/221/262/347/211/231.png +0 -0
  47. package/common/wechat-emoji/emoji//345/222/222/351/252/202.png +0 -0
  48. package/common/wechat-emoji/emoji//345/222/226/345/225/241.png +0 -0
  49. package/common/wechat-emoji/emoji//345/223/207.png +0 -0
  50. package/common/wechat-emoji/emoji//345/223/210/346/254/240.png +0 -0
  51. package/common/wechat-emoji/emoji//345/225/244/351/205/222.png +0 -0
  52. package/common/wechat-emoji/emoji//345/230/230.png +0 -0
  53. package/common/wechat-emoji/emoji//345/230/264/345/224/207.png +0 -0
  54. package/common/wechat-emoji/emoji//345/230/277/345/223/210.png +0 -0
  55. package/common/wechat-emoji/emoji//345/233/247.png +0 -0
  56. package/common/wechat-emoji/emoji//345/233/260.png +0 -0
  57. package/common/wechat-emoji/emoji//345/235/217/347/254/221.png +0 -0
  58. package/common/wechat-emoji/emoji//345/244/247/345/223/255.png +0 -0
  59. package/common/wechat-emoji/emoji//345/244/251/345/225/212.png +0 -0
  60. package/common/wechat-emoji/emoji//345/244/252/351/230/263.png +0 -0
  61. package/common/wechat-emoji/emoji//345/244/261/346/234/233.png +0 -0
  62. package/common/wechat-emoji/emoji//345/245/213/346/226/227.png +0 -0
  63. package/common/wechat-emoji/emoji//345/245/270/347/254/221.png +0 -0
  64. package/common/wechat-emoji/emoji//345/245/275/347/232/204.png +0 -0
  65. package/common/wechat-emoji/emoji//345/247/224/345/261/210.png +0 -0
  66. package/common/wechat-emoji/emoji//345/256/263/347/276/236.png +0 -0
  67. package/common/wechat-emoji/emoji//345/260/264/345/260/254.png +0 -0
  68. package/common/wechat-emoji/emoji//345/267/246/345/223/274/345/223/274.png +0 -0
  69. package/common/wechat-emoji/emoji//345/272/206/347/245/235.png +0 -0
  70. package/common/wechat-emoji/emoji//345/274/261.png +0 -0
  71. package/common/wechat-emoji/emoji//345/274/272.png +0 -0
  72. package/common/wechat-emoji/emoji//345/276/227/346/204/217.png +0 -0
  73. package/common/wechat-emoji/emoji//345/276/256/347/254/221.png +0 -0
  74. package/common/wechat-emoji/emoji//345/277/203/347/242/216.png +0 -0
  75. package/common/wechat-emoji/emoji//345/277/253/345/223/255/344/272/206.png +0 -0
  76. package/common/wechat-emoji/emoji//346/200/204/347/201/253.png +0 -0
  77. package/common/wechat-emoji/emoji//346/201/220/346/203/247.png +0 -0
  78. package/common/wechat-emoji/emoji//346/202/240/351/227/262.png +0 -0
  79. package/common/wechat-emoji/emoji//346/203/212/346/201/220.png +0 -0
  80. package/common/wechat-emoji/emoji//346/203/212/350/256/266.png +0 -0
  81. package/common/wechat-emoji/emoji//346/204/211/345/277/253.png +0 -0
  82. package/common/wechat-emoji/emoji//346/206/250/347/254/221.png +0 -0
  83. package/common/wechat-emoji/emoji//346/211/223/350/204/270.png +0 -0
  84. package/common/wechat-emoji/emoji//346/212/223/347/213/202.png +0 -0
  85. package/common/wechat-emoji/emoji//346/212/240/351/274/273.png +0 -0
  86. package/common/wechat-emoji/emoji//346/212/261/346/213/263.png +0 -0
  87. package/common/wechat-emoji/emoji//346/213/245/346/212/261.png +0 -0
  88. package/common/wechat-emoji/emoji//346/213/263/345/244/264.png +0 -0
  89. package/common/wechat-emoji/emoji//346/215/202/350/204/270.png +0 -0
  90. package/common/wechat-emoji/emoji//346/217/241/346/211/213.png +0 -0
  91. package/common/wechat-emoji/emoji//346/222/207/345/230/264.png +0 -0
  92. package/common/wechat-emoji/emoji//346/223/246/346/261/227.png +0 -0
  93. package/common/wechat-emoji/emoji//346/225/262/346/211/223.png +0 -0
  94. package/common/wechat-emoji/emoji//346/227/240/350/257/255.png +0 -0
  95. package/common/wechat-emoji/emoji//346/227/272/346/237/264.png +0 -0
  96. package/common/wechat-emoji/emoji//346/231/225.png +0 -0
  97. package/common/wechat-emoji/emoji//346/234/210/344/272/256.png +0 -0
  98. package/common/wechat-emoji/emoji//346/234/272/346/231/272.png +0 -0
  99. package/common/wechat-emoji/emoji//346/261/227.png +0 -0
  100. package/common/wechat-emoji/emoji//346/265/201/346/261/227.png +0 -0
  101. package/common/wechat-emoji/emoji//346/265/201/346/263/252.png +0 -0
  102. package/common/wechat-emoji/emoji//347/202/270/345/274/271.png +0 -0
  103. package/common/wechat-emoji/emoji//347/203/237/350/212/261.png +0 -0
  104. package/common/wechat-emoji/emoji//347/210/206/347/253/271.png +0 -0
  105. package/common/wechat-emoji/emoji//347/210/261/345/277/203.png +0 -0
  106. package/common/wechat-emoji/emoji//347/214/252/345/244/264.png +0 -0
  107. package/common/wechat-emoji/emoji//347/216/253/347/221/260.png +0 -0
  108. package/common/wechat-emoji/emoji//347/224/237/347/227/205.png +0 -0
  109. package/common/wechat-emoji/emoji//347/226/221/351/227/256.png +0 -0
  110. package/common/wechat-emoji/emoji//347/231/274.png +0 -0
  111. package/common/wechat-emoji/emoji//347/231/275/347/234/274.png +0 -0
  112. package/common/wechat-emoji/emoji//347/232/261/347/234/211.png +0 -0
  113. package/common/wechat-emoji/emoji//347/235/241.png +0 -0
  114. package/common/wechat-emoji/emoji//347/240/264/346/266/225/344/270/272/347/254/221.png +0 -0
  115. package/common/wechat-emoji/emoji//347/244/274/347/211/251.png +0 -0
  116. package/common/wechat-emoji/emoji//347/244/276/344/274/232/347/244/276/344/274/232.png +0 -0
  117. package/common/wechat-emoji/emoji//347/246/217.png +0 -0
  118. package/common/wechat-emoji/emoji//347/254/221/350/204/270.png +0 -0
  119. package/common/wechat-emoji/emoji//347/272/242/345/214/205.png +0 -0
  120. package/common/wechat-emoji/emoji//347/277/273/347/231/275/347/234/274.png +0 -0
  121. package/common/wechat-emoji/emoji//350/200/266.png +0 -0
  122. package/common/wechat-emoji/emoji//350/203/234/345/210/251.png +0 -0
  123. package/common/wechat-emoji/emoji//350/204/270/347/272/242.png +0 -0
  124. package/common/wechat-emoji/emoji//350/211/262.png +0 -0
  125. package/common/wechat-emoji/emoji//350/213/246/346/266/251.png +0 -0
  126. package/common/wechat-emoji/emoji//350/217/234/345/210/200.png +0 -0
  127. package/common/wechat-emoji/emoji//350/233/213/347/263/225.png +0 -0
  128. package/common/wechat-emoji/emoji//350/241/260.png +0 -0
  129. package/common/wechat-emoji/emoji//350/243/202/345/274/200.png +0 -0
  130. package/common/wechat-emoji/emoji//350/245/277/347/223/234.png +0 -0
  131. package/common/wechat-emoji/emoji//350/256/251/346/210/221/347/234/213/347/234/213.png +0 -0
  132. package/common/wechat-emoji/emoji//350/260/203/347/232/256.png +0 -0
  133. package/common/wechat-emoji/emoji//350/267/263/350/267/263.png +0 -0
  134. package/common/wechat-emoji/emoji//350/275/254/345/234/210.png +0 -0
  135. package/common/wechat-emoji/emoji//351/204/231/350/247/206.png +0 -0
  136. package/common/wechat-emoji/emoji//351/227/255/345/230/264.png +0 -0
  137. package/common/wechat-emoji/emoji//351/230/264/351/231/251.png +0 -0
  138. package/common/wechat-emoji/emoji//351/232/276/350/277/207.png +0 -0
  139. package/common/wechat-emoji/emoji//351/252/267/351/253/205.png +0 -0
  140. package/common/wechat-emoji/emoji//351/254/274/350/204/270.png +0 -0
  141. package/common/wechat-emoji/emoji//351/270/241.png +0 -0
  142. package/common/wechat-emoji/emoji//351/274/223/346/216/214.png +0 -0
  143. package/common/wechat-emoji/index.js +14 -0
  144. package/common/wechat-emoji/order.json +111 -0
  145. package/common/wechat-emoji/utils.js +52 -0
  146. package/common/wechat-emoji/wechat-emoji.vue +74 -0
  147. package/common/wechat-emoji-select/index.js +3 -0
  148. package/common/wechat-emoji-select/wechat-emoji-select.vue +67 -0
  149. package/components/advanced-filter/advanced-filter-condition.vue +1 -1
  150. package/components/advanced-filter/advanced-filter.vue +6 -1
  151. package/components/advanced-filter/index.js +11 -12
  152. package/components/avatar/avatar.vue +9 -5
  153. package/components/button/button.vue +15 -2
  154. package/components/date-picker/date-picker.vue +9 -2
  155. package/components/dialog/dialog.vue +6 -1
  156. package/components/dropdown/dropdown-item.vue +10 -2
  157. package/components/dropdown/dropdown.vue +45 -5
  158. package/components/dropdown/index.js +8 -8
  159. package/components/empty/empty.vue +29 -2
  160. package/components/filter/filter.vue +1 -1
  161. package/components/filter/index.js +10 -10
  162. package/components/form/form.vue +33 -2
  163. package/components/form/index.js +11 -0
  164. package/components/grid/grid-column.vue +1 -0
  165. package/components/grid/grid-table.vue +6 -4
  166. package/components/grid/grid.vue +15 -3
  167. package/components/grid/index.js +31 -32
  168. package/components/icon/demo_index.html +2752 -1073
  169. package/components/icon/iconfont.css +299 -7
  170. package/components/icon/iconfont.js +1 -1
  171. package/components/icon/iconfont.json +518 -7
  172. package/components/icon/iconfont.ttf +0 -0
  173. package/components/icon/iconfont.woff +0 -0
  174. package/components/icon/iconfont.woff2 +0 -0
  175. package/components/image/image.vue +91 -13
  176. package/components/image/index.js +3 -1
  177. package/components/image/util.js +82 -1
  178. package/components/index.js +6 -2
  179. package/components/menu/index.js +13 -7
  180. package/components/menu/menu-group.vue +6 -1
  181. package/components/menu/menu-item.vue +57 -3
  182. package/components/menu/menu.vue +1 -1
  183. package/components/message/message.js +12 -9
  184. package/components/message-box/index.js +4 -0
  185. package/components/pagination/pagination.vue +11 -7
  186. package/components/popover/popover.vue +24 -1
  187. package/components/searchbox/searchbox.vue +15 -3
  188. package/components/select/index.js +2 -0
  189. package/components/select/select.vue +7 -1
  190. package/components/skeleton/index.js +2 -0
  191. package/components/sortable/index.js +7 -5
  192. package/components/sortable/sortable.vue +5 -0
  193. package/components/tabbar/index.js +9 -0
  194. package/components/tabbar/tabbar-item.vue +162 -0
  195. package/components/tabbar/tabbar.vue +49 -0
  196. package/components/tabs/index.js +2 -0
  197. package/components/tabs/tabs.vue +5 -0
  198. package/components/tag/index.js +4 -4
  199. package/components/tag/tag.less +12 -3
  200. package/components/textarea/textarea.vue +19 -3
  201. package/components/time-picker/time-picker.vue +7 -0
  202. package/components/toolbar/index.js +2 -0
  203. package/components/transfer/index.js +4 -4
  204. package/components/transfer/transfer-element.vue +109 -0
  205. package/components/transfer/transfer.vue +22 -7
  206. package/components/tree/tree.vue +175 -16
  207. package/components/video/video.vue +50 -2
  208. package/package.json +12 -1
  209. package/uni-common/more-button/more-button.vue +23 -0
  210. package/uni-common/popup-select/popup-select.vue +217 -0
  211. package/uni-common/portray/portray.vue +54 -0
  212. package/uni-common/refresh-view/refresh-view.vue +94 -0
  213. package/uni-common/scroll-load-more/scroll-load-more.vue +201 -0
  214. package/uni-common/tree-popup-select/index.js +3 -0
  215. package/uni-common/tree-popup-select/tree-popup-select-panel.vue +92 -0
  216. package/uni-common/tree-popup-select/tree-popup-select.vue +124 -0
  217. package/uni-common/tree-popup-select/util.js +19 -0
  218. package/uni-common/wechat-emoji/index.js +13 -0
  219. package/uni-common/wechat-emoji/order.json +438 -0
  220. package/uni-common/wechat-emoji/utils.js +52 -0
  221. package/uni-common/wechat-emoji/wechat-emoji.vue +74 -0
  222. package/uni-components/avatar/avatar.vue +81 -0
  223. package/uni-components/badge/badge.vue +57 -0
  224. package/uni-components/empty/empty.vue +27 -0
  225. package/uni-components/exception/exception.vue +47 -0
  226. package/uni-components/icon/demo.css +539 -0
  227. package/uni-components/icon/demo_index.html +1591 -0
  228. package/uni-components/icon/icon.vue +48 -0
  229. package/uni-components/icon/iconfont.css +259 -0
  230. package/uni-components/icon/iconfont.js +1 -0
  231. package/uni-components/icon/iconfont.json +436 -0
  232. package/uni-components/icon/iconfont.ttf +0 -0
  233. package/uni-components/icon/iconfont.woff +0 -0
  234. package/uni-components/icon/iconfont.woff2 +0 -0
  235. package/uni-components/icon/index.js +3 -0
  236. package/uni-components/image/image.vue +38 -0
  237. package/uni-components/image/index.js +3 -0
  238. package/uni-components/loading/index.js +3 -0
  239. package/uni-components/loading/loading.vue +30 -0
  240. package/uni-components/message/message-item.vue +29 -0
  241. package/uni-components/message/message.js +80 -0
  242. package/uni-components/message/message.vue +30 -0
  243. package/uni-components/message-box/message-box-item.vue +54 -0
  244. package/uni-components/message-box/message-box.js +91 -0
  245. package/uni-components/message-box/message-box.vue +52 -0
  246. package/uni-components/picker/picker.vue +270 -0
  247. package/uni-components/popup/index.js +3 -0
  248. package/uni-components/popup/popup.vue +143 -0
  249. package/uni-components/search/index.js +3 -0
  250. package/uni-components/search/search.vue +86 -0
  251. package/uni-components/skeleton/skeleton-chat.vue +85 -0
  252. package/uni-components/skeleton/skeleton-contact.vue +84 -0
  253. package/uni-components/skeleton/skeleton-detail.vue +84 -0
  254. package/uni-components/skeleton/skeleton.vue +32 -0
  255. package/uni-components/tabbar/tabbar-item.vue +33 -0
  256. package/uni-components/tabbar/tabbar.vue +87 -0
  257. package/uni-components/tree/index.js +3 -0
  258. package/uni-components/tree/tree-select-loading.vue +48 -0
  259. package/uni-components/tree/tree-select-node.vue +202 -0
  260. package/uni-components/tree/tree-select-store.js +520 -0
  261. package/uni-components/tree/tree-select.vue +210 -0
  262. package/uni-components/tree/utils.js +33 -0
  263. package/uni-components/video/index.js +3 -0
  264. package/uni-components/video/video.vue +29 -0
  265. package/uni-components/voice/index.js +3 -0
  266. package/uni-components/voice/voice.vue +24 -0
  267. package/uni-components/waterfall/index.js +3 -0
  268. package/uni-components/waterfall/util.js +72 -0
  269. package/uni-components/waterfall/waterfall.vue +147 -0
  270. package/utils/data.js +128 -0
  271. package/utils/date.js +484 -44
  272. package/utils/dom.js +37 -0
  273. package/utils/event.js +92 -0
  274. package/utils/file.js +76 -0
  275. package/utils/json.js +22 -1
  276. package/utils/network-detector.js +258 -0
  277. package/utils/oss.js +11 -0
  278. package/utils/share-message.js +81 -0
  279. package/utils/share-websocket.js +127 -0
  280. package/utils/string.js +59 -0
  281. package/utils/time-task.js +60 -0
  282. package/utils/url.js +46 -0
  283. package/utils/util.js +416 -1
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 创建定时任务
3
+ * @params { Function } execFn - 执行任务的异步函数
4
+ * @params { Function } resultFn - 获取结果的函数
5
+ * @params { Function } callbackFn - 执行完毕回调函数
6
+ * @params { Number } spanTime - 检查结果间隔秒数
7
+ * @params { Number } timeout - 超时时间,3分钟超时
8
+ */
9
+ export function createTimeTask (execFn, resultFn, callbackFn, spanTime = 1000 * 5, timeout = 1000 * 60 * 3) {
10
+ let timer = null
11
+ let canceld = false
12
+ if (typeof callbackFn === 'number') {
13
+ spanTime = callbackFn
14
+ callbackFn = null
15
+ }
16
+ let startTime = Date.now()
17
+ const ps = new Promise((resolve, reject) => {
18
+ if (!execFn || !resultFn) {
19
+ throw new Error('缺少必须参数')
20
+ }
21
+ const checkFn = (result) => {
22
+ clearTimeout(timer)
23
+ if (canceld) {
24
+ return
25
+ }
26
+ if (Date.now() - startTime > timeout) {
27
+ reject('timeout')
28
+ return
29
+ }
30
+ Promise.all([resultFn(result)]).then(rs => rs[0]).then((rs) => {
31
+ if (rs === null) {
32
+ timer = setTimeout(() => {
33
+ checkFn(result)
34
+ }, spanTime)
35
+ } else {
36
+ if (callbackFn) {
37
+ const rrs = callbackFn(rs)
38
+ if (rrs && rrs.then) {
39
+ rrs.then(resolve, reject)
40
+ } else {
41
+ resolve(rrs)
42
+ }
43
+ } else {
44
+ resolve()
45
+ }
46
+ }
47
+ }, reject)
48
+ }
49
+ execFn().then((rs) => {
50
+ timer = setTimeout(() => {
51
+ checkFn(rs)
52
+ }, spanTime)
53
+ }, reject)
54
+ })
55
+ ps.cancel = () => {
56
+ canceld = true
57
+ clearTimeout(timer)
58
+ }
59
+ return ps
60
+ }
package/utils/url.js ADDED
@@ -0,0 +1,46 @@
1
+ import qs from 'query-string'
2
+
3
+ export function buildUrl (url, params) {
4
+ let nextParams = buildUrlParams(params)
5
+ if (nextParams) {
6
+ if (url.indexOf('?') >= 0) {
7
+ return url + '&' + nextParams
8
+ } else {
9
+ return url + '?' + nextParams
10
+ }
11
+ } else {
12
+ return url
13
+ }
14
+ }
15
+
16
+ export function buildUrlParams (params) {
17
+ return qs.stringify(params, {
18
+ arrayFormat: 'comma'
19
+ })
20
+ }
21
+
22
+ export function getUrlParams (url, options) {
23
+ if (!url) {
24
+ const pageHref = window.location.href
25
+ const searchIndex = pageHref.indexOf('?')
26
+ if (searchIndex >= 0) {
27
+ url = pageHref.substr(searchIndex)
28
+ // http://localhost:8082/?tenantId=yangyutest&_layout=left#/admin/app/workchat/livecode?_layout=left&_mode=module&tenantId=yangyutest
29
+ return url.split('#').reduce((rs, search) => {
30
+ const hashQuery = search.indexOf('?')
31
+ if (hashQuery >= 0) {
32
+ search = search.substr(hashQuery)
33
+ rs = Object.assign({}, rs, qs.parse(search, options))
34
+ }
35
+ return rs
36
+ }, {})
37
+ } else {
38
+ return {}
39
+ }
40
+ } else {
41
+ if (url.indexOf('?') >= 0) {
42
+ url = url.substr(url.indexOf('?') + 1)
43
+ }
44
+ return qs.parse(url, options)
45
+ }
46
+ }
package/utils/util.js CHANGED
@@ -1,3 +1,5 @@
1
+ import mergeOpts from 'merge-options'
2
+
1
3
  /**
2
4
  * 获取唯一字符串
3
5
  */
@@ -7,6 +9,419 @@ export function unique (prefix = 'unique_') {
7
9
  return (prefix || '') + _unique
8
10
  }
9
11
 
12
+ /**
13
+ * 批量合并
14
+ */
15
+ export function batchMerge (source, data) {
16
+ for (const i in source) {
17
+ const nv = (typeof data === 'function' ? data(source[i]) : data) || {}
18
+ source[i] = {
19
+ ...source[i],
20
+ ...nv
21
+ }
22
+ }
23
+ return source
24
+ }
25
+
26
+ /**
27
+ * 根据给定的正则匹配路径的符合规则的部分
28
+ */
29
+ export function getPathByRegex (fullPath, regex) {
30
+ if (!fullPath || !regex) {
31
+ return
32
+ }
33
+ fullPath = fullPath.split('?')[0] // 去掉参数部分,vue的路由正则不支持参数,目前传了参数的是内嵌模式_mode
34
+ while (fullPath) {
35
+ const match = fullPath.match(regex)
36
+ if (match) {
37
+ return match[0]
38
+ } else {
39
+ fullPath = fullPath.substr(0, fullPath.lastIndexOf('/'))
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
45
+ * 表格导出工具
46
+ */
47
+
48
+ export function toolXlsFilte (data, fileName) {
49
+ const blob = new Blob([data])
50
+ if ('download' in document.createElement('a')) { // 非IE下载
51
+ const elink = document.createElement('a')
52
+ elink.download = fileName
53
+ elink.style.display = 'none'
54
+ elink.href = URL.createObjectURL(blob)
55
+ document.body.appendChild(elink)
56
+ elink.click()
57
+ URL.revokeObjectURL(elink.href) // 释放URL 对象
58
+ document.body.removeChild(elink)
59
+ } else { // IE10+下载
60
+ navigator.msSaveBlob(blob, fileName)
61
+ }
62
+ }
63
+
64
+ /**
65
+ * base64转换为文件
66
+ */
67
+ export function dataURLtoFile (dataurl, filename) {
68
+ const arr = dataurl.split(',')
69
+ const mime = arr[0].match(/:(.*?);/)[1]
70
+ const bstr = atob(arr[1])
71
+ let n = bstr.length
72
+ const u8arr = new Uint8Array(n)
73
+ while (n--) {
74
+ u8arr[n] = bstr.charCodeAt(n)
75
+ }
76
+ return new File([u8arr], filename, { type: mime })
77
+ }
78
+
79
+ /**
80
+ * 格式化文件尺寸
81
+ */
82
+ export function formatBytes (bytes) {
83
+ if (bytes === undefined || bytes === null) {
84
+ return
85
+ }
86
+ var b = 2
87
+ if (bytes === 0) {
88
+ return '0 B'
89
+ }
90
+ var c = 1024
91
+ var d = b || 2
92
+ var e = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
93
+ var f = Math.floor(Math.log(bytes) / Math.log(c))
94
+ return parseFloat((bytes / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
95
+ }
96
+
97
+ /**
98
+ * 字节转化为指定单位大小
99
+ */
100
+ export function bytesToUnit (bytes, unit, toFixed = 2) {
101
+ if (!bytes) {
102
+ return 0
103
+ }
104
+ const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
105
+ if (!units.includes(unit)) {
106
+ throw new Error('单位不合法')
107
+ }
108
+ const index = units.indexOf(unit)
109
+ for (let i = 0; i < index; i++) {
110
+ bytes = bytes / 1024
111
+ }
112
+ if (toFixed === null) {
113
+ return bytes
114
+ }
115
+ return bytes.toFixed(toFixed)
116
+ }
117
+
118
+ export function mergeOptions (...args) {
119
+ return mergeOpts.apply(null, args)
120
+ }
121
+
122
+ /**
123
+ * 创建开发测试api
124
+ */
125
+ export function createTestApi (name, fn) {
126
+ if (!window.DEVELOP_TEST_API) {
127
+ window.DEVELOP_TEST_API = {}
128
+ }
129
+ window.DEVELOP_TEST_API[name] = fn
130
+ }
131
+
132
+ /**
133
+ * 创建一个动态列
134
+ */
135
+ export function createDynamicColumn (fileName, title, moduleName) {
136
+ return {
137
+ accountId: unique(),
138
+ columnName: fileName,
139
+ columnType: 'base-column',
140
+ id: unique(),
141
+ moduleName: moduleName,
142
+ show: true,
143
+ sortIndex: 1,
144
+ _custom: true,
145
+ title: title
146
+ }
147
+ }
148
+
149
+ export function createPromise () {
150
+ let psReject, psResolve
151
+ const ps = new Promise((resolve, reject) => {
152
+ psResolve = resolve
153
+ psReject = reject
154
+ })
155
+ ps.reject = psReject
156
+ ps.resolve = psResolve
157
+ return ps
158
+ }
159
+
10
160
  export function isEmpty (value) {
11
161
  return value === null || value === undefined || value === ''
12
- }
162
+ }
163
+
164
+ /**
165
+ * 轮循加载
166
+ */
167
+ export function createPollRequest (requestFn, spanTime = 5 * 1000, timeout = 60 * 1000) {
168
+ let _stop = false
169
+ let _timer = null
170
+ function stop () {
171
+ _stop = true
172
+ clearTimeout(_timer)
173
+ }
174
+ function start () {
175
+ return loopFn()
176
+ }
177
+ function loopFn () {
178
+ let countdown = timeout
179
+ return new Promise((resolve, reject) => {
180
+ const nextFn = () => {
181
+ if (_stop) {
182
+ reject('stop')
183
+ return
184
+ }
185
+ if (countdown <= 0) {
186
+ reject('timeout')
187
+ return
188
+ }
189
+ countdown = countdown - spanTime
190
+ requestFn({
191
+ done (res) {
192
+ stop()
193
+ resolve(res)
194
+ },
195
+ fail (err) {
196
+ stop()
197
+ reject(err)
198
+ }
199
+ }).then(() => {
200
+ _timer = setTimeout(() => {
201
+ nextFn()
202
+ }, spanTime)
203
+ }, reject)
204
+ }
205
+ nextFn()
206
+ })
207
+ }
208
+ return {
209
+ start,
210
+ stop
211
+ }
212
+ }
213
+
214
+ /**
215
+ * 将多个请求合并为一个请求
216
+ * @params { String } id - 请求的唯一id
217
+ * @params { Function } requestFn - 请求函数
218
+ */
219
+ export function createThrottleRequest (requestFn, idField = 'id') {
220
+ let cacheMap = {}
221
+ let loadMap = {}
222
+ let timer = null
223
+ return (id) => {
224
+ const ps = createPromise()
225
+ cacheMap[id] = ps
226
+ loadMap[id] = true
227
+ clearTimeout(timer)
228
+ timer = setTimeout(() => {
229
+ const keys = Object.keys(loadMap)
230
+ loadMap = {}
231
+ requestFn(keys).then(rs => {
232
+ if (rs && rs.length) {
233
+ rs.forEach(v => {
234
+ cacheMap[v[idField]]._execed = true
235
+ cacheMap[v[idField]].resolve(v)
236
+ })
237
+ }
238
+ keys.forEach(id => {
239
+ if (!cacheMap[id]._execed) {
240
+ // 如果没有返回表示没有找到数据
241
+ cacheMap[id].reject(new Error('未找到数据'))
242
+ }
243
+ })
244
+ return rs
245
+ }, err => {
246
+ keys.forEach(id => {
247
+ cacheMap[id]._execed = true
248
+ cacheMap[id].reject(err)
249
+ })
250
+ }).finally(() => {
251
+ cacheMap = {}
252
+ })
253
+ }, 20)
254
+ return ps
255
+ }
256
+ }
257
+
258
+ /**
259
+ * 合并请求,上面createThrottleRequest将被作废
260
+ * @param { String } groupName 分组名称
261
+ * @param { Function } mergeParamsMethod 合并参数方法
262
+ * @param { Function } sendRequestMethod 发送请求方法
263
+ * @param { Function } assignResultMethod 分配结果方法
264
+ * @example
265
+ * return mergeRequest('getAccountUnreadMessageNumMethod', (nextParams) => {
266
+ * if (!nextParams.wechatAccountIds) {
267
+ * nextParams.wechatAccountIds = []
268
+ * }
269
+ * nextParams.wechatAccountIds = [].concat(nextParams.wechatAccountIds, params.wechatAccountIds)
270
+ * return nextParams
271
+ * }, (nextParams) => {
272
+ * return getAccountUnreadMessageNum(nextParams)
273
+ * }, (rs) => {
274
+ * const currentRs = (rs.data || []).find(v => v.wxAccountId === params.wechatAccountIds[0])
275
+ * if (currentRs) {
276
+ * return Promise.resolve({
277
+ * code: rs.code,
278
+ * data: [currentRs],
279
+ * msg: rs.msg
280
+ * })
281
+ * } else {
282
+ * return Promise.reject(`未找到${params.wechatAccountIds}统计数据`)
283
+ * }
284
+ * })
285
+ */
286
+ const mergeRequestMap = {}
287
+ let mergeRequestTimer = null
288
+ export function mergeRequest (groupName, mergeParamsMethod, sendRequestMethod, assignResultMethod) {
289
+ const ps = createPromise()
290
+ if (typeof groupName !== 'string' || typeof mergeParamsMethod !== 'function' || typeof sendRequestMethod !== 'function' || typeof assignResultMethod !== 'function') {
291
+ ps.reject(new Error('参数类型不正确'))
292
+ } else {
293
+ if (!mergeRequestMap[groupName]) {
294
+ mergeRequestMap[groupName] = {
295
+ params: {},
296
+ promise: createPromise()
297
+ }
298
+ }
299
+ mergeRequestMap[groupName].params = mergeParamsMethod(mergeRequestMap[groupName].params)
300
+ clearTimeout(mergeRequestTimer)
301
+ mergeRequestTimer = setTimeout(() => {
302
+ sendRequestMethod(mergeRequestMap[groupName].params).then((rs) => {
303
+ mergeRequestMap[groupName].promise.resolve(rs)
304
+ }, err => {
305
+ mergeRequestMap[groupName].promise.reject(err)
306
+ }).finally(() => {
307
+ delete mergeRequestMap[groupName]
308
+ })
309
+ }, 30)
310
+ mergeRequestMap[groupName].promise.then(rs => {
311
+ return assignResultMethod(rs).then(ps.resolve, ps.reject)
312
+ }, err => {
313
+ pr.reject(err)
314
+ })
315
+ }
316
+ return ps
317
+ }
318
+
319
+ /**
320
+ * 重试请求,后端请求频繁时,使用此方法降低频率
321
+ */
322
+ export const retryRequest = (() => {
323
+ const retryRequestMap = {}
324
+ return {
325
+ /**
326
+ * @param { String } requestId - 首次请求的id,第一次发起请求需要传一个id,后续重试的时候需要带上这个id穿透使用
327
+ * @param { String } requestUrl - 请求的url地址,相同的地址,会做分组排队请求
328
+ * @param { Function } requestFn - 重试的请求方法
329
+ */
330
+ add (requestId, requestUrl, requestFn) {
331
+ if (!requestId || !requestUrl || !requestFn) {
332
+ throw new Error('缺少必须参数')
333
+ }
334
+ if (!retryRequestMap[requestUrl]) {
335
+ retryRequestMap[requestUrl] = {
336
+ requestList: [],
337
+ promiseMap: {},
338
+ checkTimeout: null
339
+ }
340
+ }
341
+ let ps = retryRequestMap[requestUrl].promiseMap[requestId]
342
+ if (!ps) {
343
+ ps = createPromise()
344
+ retryRequestMap[requestUrl].promiseMap[requestId] = ps
345
+ }
346
+ const requestItem = {
347
+ status: 'normal',
348
+ requestId,
349
+ requestFn: (index) => {
350
+ let isEnd = false
351
+ const rs = requestFn(index, (err) => {
352
+ ps.reject(err)
353
+ isEnd = true
354
+ this.clear(requestId, requestUrl)
355
+ })
356
+ if (rs && rs.then) {
357
+ requestItem.status = 'loading'
358
+ rs.then((res) => {
359
+ ps.resolve(res)
360
+ this.clear(requestId, requestUrl)
361
+ this.check(requestUrl)
362
+ }, err => {
363
+ requestItem.status = 'complete'
364
+ this.check(requestUrl)
365
+ })
366
+ } else {
367
+ requestItem.status = 'complete'
368
+ // 如果结束了,需要清理一下剩下的requestId排队请求
369
+ if (isEnd) {
370
+ this.clear(requestId, requestUrl)
371
+ }
372
+ // 继续其他非当前requestId的相同requestUrl的请求
373
+ this.check(requestUrl)
374
+ }
375
+ }
376
+ }
377
+ retryRequestMap[requestUrl].requestList.push(requestItem)
378
+ this.check(requestUrl)
379
+ },
380
+ check (requestUrl) {
381
+ if (!requestUrl) {
382
+ throw new Error('缺少必须参数')
383
+ }
384
+ if (!retryRequestMap[requestUrl]) {
385
+ return
386
+ }
387
+ if (!retryRequestMap[requestUrl].requestList) {
388
+ return
389
+ }
390
+ retryRequestMap[requestUrl].requestList.some((v, i) => {
391
+ if (v.status === 'normal') {
392
+ clearTimeout(retryRequestMap[requestUrl].checkTimeout)
393
+ retryRequestMap[requestUrl].checkTimeout = setTimeout(() => {
394
+ v.requestFn(i)
395
+ }, 500)
396
+ return true
397
+ }
398
+ })
399
+ },
400
+ get (requestId, requestUrl) {
401
+ if (!requestId || !requestUrl) {
402
+ throw new Error('缺少必须参数')
403
+ }
404
+ if (!retryRequestMap[requestUrl] || !retryRequestMap[requestUrl].promiseMap) {
405
+ return
406
+ }
407
+ return retryRequestMap[requestUrl].promiseMap[requestId]
408
+ },
409
+ clear (requestId, requestUrl) {
410
+ if (!requestId || !requestUrl) {
411
+ throw new Error('缺少必须参数')
412
+ }
413
+ if (retryRequestMap[requestUrl]) {
414
+ if (retryRequestMap[requestUrl].promiseMap) {
415
+ delete retryRequestMap[requestUrl].promiseMap[requestId]
416
+ }
417
+ if (retryRequestMap[requestUrl].requestList) {
418
+ for (let i = retryRequestMap[requestUrl].requestList.length - 1; i >= 0; i--) {
419
+ if (retryRequestMap[requestUrl].requestList[i].requestId === requestId) {
420
+ retryRequestMap[requestUrl].requestList.splice(i, 1)
421
+ }
422
+ }
423
+ }
424
+ }
425
+ }
426
+ }
427
+ })()