ocpview-plus 1.3.15 → 1.3.16

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 (213) hide show
  1. package/README.md +55 -43
  2. package/dist/ocpviewplus.min.esm.js +574 -482
  3. package/dist/ocpviewplus.min.js +9 -9
  4. package/dist/style.css +1 -1
  5. package/dist/styles/efviewplus.css +1 -1
  6. package/package.json +146 -146
  7. package/src/components/base/ContractPrintMixins.js +30 -30
  8. package/src/components/base/controlbase.vue +190 -190
  9. package/src/components/base/controlbox.vue +102 -102
  10. package/src/components/base/index.js +2 -2
  11. package/src/components/base/load.js +19 -19
  12. package/src/components/base/probase.js +220 -220
  13. package/src/components/base/size.js +78 -78
  14. package/src/components/billbox/billbox.vue +67 -67
  15. package/src/components/billbox/index.js +1 -1
  16. package/src/components/cascaderbox/cascaderbox.vue +184 -184
  17. package/src/components/cascaderbox/index.js +2 -2
  18. package/src/components/checkbox/checkbox.vue +75 -75
  19. package/src/components/checkbox/checkgroupbox.vue +103 -103
  20. package/src/components/checkbox/index.js +2 -2
  21. package/src/components/colorbox/colorbox.vue +43 -43
  22. package/src/components/colorbox/index.js +1 -1
  23. package/src/components/combobox/combobox.vue +219 -219
  24. package/src/components/combobox/index.js +1 -1
  25. package/src/components/conditionbox/conditionbase.vue +194 -194
  26. package/src/components/conditionbox/conditionbox.vue +62 -62
  27. package/src/components/conditionbox/conditionfilterbox.vue +479 -479
  28. package/src/components/conditionbox/conditionselectorbox.vue +237 -237
  29. package/src/components/conditionbox/index.js +4 -4
  30. package/src/components/conditionbox/queryconditionbox.vue +25 -25
  31. package/src/components/conditionbox/queryconditionboxbase.vue +123 -123
  32. package/src/components/conditionbox/searchconditionbox.vue +113 -113
  33. package/src/components/conditionbox/searchgrid.vue +391 -391
  34. package/src/components/datebox/DateBoxV1.vue +22 -22
  35. package/src/components/datebox/datebox.vue +129 -129
  36. package/src/components/datebox/daterangebox.vue +154 -154
  37. package/src/components/datebox/index.js +5 -5
  38. package/src/components/form/baseform.vue +676 -676
  39. package/src/components/form/detailsbox.vue +487 -487
  40. package/src/components/form/formbox.vue +28 -28
  41. package/src/components/form/formcardbox.vue +267 -267
  42. package/src/components/form/formcardbox2.vue +228 -228
  43. package/src/components/form/formcardgroupbox.vue +251 -251
  44. package/src/components/form/formcompro.js +18 -18
  45. package/src/components/form/formdetail.vue +128 -128
  46. package/src/components/form/formdetailtwo.vue +302 -302
  47. package/src/components/form/index.js +9 -9
  48. package/src/components/form/toolanchor.js +45 -45
  49. package/src/components/form/workform.vue +167 -167
  50. package/src/components/grid/basegrid.vue +1062 -1062
  51. package/src/components/grid/editgrid.vue +51 -51
  52. package/src/components/grid/editgridbase.vue +1062 -1062
  53. package/src/components/grid/editgridcard.vue +193 -193
  54. package/src/components/grid/expandrow.vue +137 -137
  55. package/src/components/grid/index.js +5 -5
  56. package/src/components/grid/viewgrid.vue +121 -121
  57. package/src/components/grid/viewgridbase.vue +1286 -1286
  58. package/src/components/icon/common-icon.vue +53 -53
  59. package/src/components/icon/eicon.vue +28 -28
  60. package/src/components/icon/icons.vue +42 -42
  61. package/src/components/icon/index.js +1 -1
  62. package/src/components/label/index.js +2 -2
  63. package/src/components/label/showtext.vue +94 -94
  64. package/src/components/load/loadcartoon.vue +227 -227
  65. package/src/components/map/index.js +1 -1
  66. package/src/components/map/mapbox.vue +348 -348
  67. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanel.vue +184 -184
  68. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTable.vue +838 -838
  69. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTableControlbox.vue +126 -126
  70. package/src/components/masterplate/RewriteBillListDetails/BillInfoPanelEditTableControlboxNumberbox.vue +27 -27
  71. package/src/components/masterplate/RewriteBillListDetails/BillListPanel.vue +126 -126
  72. package/src/components/masterplate/RewriteBillListDetails/BillListPanelQueryBar.vue +280 -280
  73. package/src/components/masterplate/RewriteBillListDetails/BillListPanelTable.vue +346 -346
  74. package/src/components/masterplate/RewriteBillListDetails/index.vue +325 -325
  75. package/src/components/masterplate/RewriteBillListDetails/mixins/useVxeGridEditTypeKeydownEventHook.js +251 -251
  76. package/src/components/masterplate/RewriteListdetails/BillListPanelV2.vue +115 -115
  77. package/src/components/masterplate/RewriteListdetails/BillListPanelV2QueryBar.vue +24 -24
  78. package/src/components/masterplate/RewriteListdetails/BillListPanelV3.vue +121 -121
  79. package/src/components/masterplate/RewriteListdetails/BillListPanelV3QueryBar.vue +275 -275
  80. package/src/components/masterplate/RewriteListdetails/indexV2.vue +320 -320
  81. package/src/components/masterplate/RewriteListdetails/indexV3.vue +331 -331
  82. package/src/components/masterplate/appendix.vue +586 -586
  83. package/src/components/masterplate/approval.vue +863 -863
  84. package/src/components/masterplate/base.vue +1028 -1028
  85. package/src/components/masterplate/billasyncimport.vue +614 -614
  86. package/src/components/masterplate/billconditionbox.vue +223 -223
  87. package/src/components/masterplate/billconditionsbox.vue +427 -427
  88. package/src/components/masterplate/billdetailform.vue +1028 -1028
  89. package/src/components/masterplate/billimport.vue +301 -301
  90. package/src/components/masterplate/billquerygrid.vue +391 -391
  91. package/src/components/masterplate/billsinglegrid.vue +234 -234
  92. package/src/components/masterplate/birtreport.vue +185 -185
  93. package/src/components/masterplate/contractappendix.vue +688 -688
  94. package/src/components/masterplate/detailbtntoolbar.vue +311 -311
  95. package/src/components/masterplate/detailsbox.vue +386 -386
  96. package/src/components/masterplate/editgridcard.vue +292 -292
  97. package/src/components/masterplate/editgridcard2.vue +127 -127
  98. package/src/components/masterplate/formcard.vue +105 -105
  99. package/src/components/masterplate/formcardgroupbox.vue +167 -167
  100. package/src/components/masterplate/formdetailtwo.vue +366 -366
  101. package/src/components/masterplate/gridcolset.vue +226 -226
  102. package/src/components/masterplate/index.js +54 -54
  103. package/src/components/masterplate/layouttemplate.vue +51 -51
  104. package/src/components/masterplate/leftlistrightdetails.vue +581 -581
  105. package/src/components/masterplate/leftlistrightlist.vue +464 -464
  106. package/src/components/masterplate/lefttreerightdetails.vue +636 -636
  107. package/src/components/masterplate/levelreport.vue +510 -510
  108. package/src/components/masterplate/listbtntoolbar.vue +276 -276
  109. package/src/components/masterplate/listdetails.vue +768 -768
  110. package/src/components/masterplate/operlog.vue +272 -272
  111. package/src/components/masterplate/options.vue +110 -110
  112. package/src/components/masterplate/page.vue +102 -102
  113. package/src/components/masterplate/promptmessage.vue +73 -73
  114. package/src/components/masterplate/querybar.vue +490 -490
  115. package/src/components/masterplate/report.vue +357 -357
  116. package/src/components/masterplate/rowbtntoolbar.vue +126 -126
  117. package/src/components/masterplate/simpletree.vue +137 -137
  118. package/src/components/masterplate/simpleviewgrid.vue +144 -144
  119. package/src/components/mychart/bar/bar.vue +201 -201
  120. package/src/components/mychart/basechart.vue +190 -190
  121. package/src/components/mychart/complexmychart/barline.vue +153 -153
  122. package/src/components/mychart/gauge/gauge.vue +82 -82
  123. package/src/components/mychart/index.js +8 -8
  124. package/src/components/mychart/line/line.vue +201 -201
  125. package/src/components/mychart/liquidfill/liquidfill.vue +108 -108
  126. package/src/components/mychart/pie/pie.vue +95 -95
  127. package/src/components/mychart/radar/radar.vue +121 -121
  128. package/src/components/mychart/scatter/scatter.vue +75 -75
  129. package/src/components/numberbox/NumberBoxV1.vue +39 -39
  130. package/src/components/numberbox/append.js +11 -11
  131. package/src/components/numberbox/index.js +4 -4
  132. package/src/components/numberbox/numberbox.vue +302 -302
  133. package/src/components/numberbox/numberrangebox.vue +422 -422
  134. package/src/components/picturebox/filebox.vue +369 -369
  135. package/src/components/picturebox/index.js +2 -2
  136. package/src/components/picturebox/picturebox.vue +541 -541
  137. package/src/components/picturebox/uploadbox.vue +164 -164
  138. package/src/components/poptagbox/index.js +1 -1
  139. package/src/components/poptagbox/poptagbox.vue +388 -388
  140. package/src/components/poptextbox/index.js +1 -1
  141. package/src/components/poptextbox/poptextbox.vue +624 -624
  142. package/src/components/radiobox/index.js +1 -1
  143. package/src/components/radiobox/radiogroupbox.vue +75 -75
  144. package/src/components/richtextbox/editor.vue +150 -150
  145. package/src/components/richtextbox/index.js +1 -1
  146. package/src/components/richtextbox/richtextbox.vue +448 -448
  147. package/src/components/textbox/index.js +1 -1
  148. package/src/components/textbox/textbox.vue +97 -97
  149. package/src/components/timebox/index.js +1 -1
  150. package/src/components/timebox/timebox.vue +75 -75
  151. package/src/components/toolbar/ebutton.vue +169 -169
  152. package/src/components/toolbar/index.js +3 -3
  153. package/src/components/toolbar/toolbar.vue +445 -445
  154. package/src/components/tree/CompatTree.vue +297 -297
  155. package/src/components/tree/basetree.vue +1098 -1098
  156. package/src/components/tree/index.js +2 -2
  157. package/src/components/tree/treedata.vue +53 -53
  158. package/src/components/tree/treedatabase.vue +189 -189
  159. package/src/components/upload/billimport.vue +233 -233
  160. package/src/components/upload/index.js +1 -1
  161. package/src/components/videobox/index.js +1 -1
  162. package/src/components/videobox/uploadbox.vue +148 -148
  163. package/src/components/videobox/videobox.vue +503 -503
  164. package/src/components/wrichtextbox/editor.vue +219 -219
  165. package/src/components/wrichtextbox/index.js +1 -1
  166. package/src/components/wrichtextbox/wrichtextbox.vue +62 -62
  167. package/src/index.js +231 -231
  168. package/src/locale/format.js +51 -51
  169. package/src/locale/index.js +63 -63
  170. package/src/locale/lang/zh-CN.js +123 -123
  171. package/src/locale/lang/zh-TW.js +114 -114
  172. package/src/locale/lang/zh-UG.js +115 -115
  173. package/src/locale/lang.js +15 -15
  174. package/src/method/case/case.js +1274 -1274
  175. package/src/method/config/queryconfig.js +24 -24
  176. package/src/method/const/const.js +815 -815
  177. package/src/method/index.js +7 -7
  178. package/src/plugins/theme/theme-variable.css +114 -114
  179. package/src/plugins/vxeTable/index.js +241 -241
  180. package/src/plugins/vxeTable/renderer/components/TableFilterInput.vue +51 -51
  181. package/src/plugins/vxeTable/renderer/filter.js +32 -32
  182. package/src/static/excel/exportexcel.js +626 -626
  183. package/src/static/iview/coustom.js +462 -462
  184. package/src/store/index.js +18 -18
  185. package/src/store/modules/app.js +53 -53
  186. package/src/styles/README.md +3 -3
  187. package/src/styles/common.less +80 -80
  188. package/src/styles/components/anchor.less +74 -74
  189. package/src/styles/components/approval.less +135 -135
  190. package/src/styles/components/button.less +208 -208
  191. package/src/styles/components/card.less +51 -51
  192. package/src/styles/components/content.less +38 -38
  193. package/src/styles/components/font.less +313 -313
  194. package/src/styles/components/form.less +71 -71
  195. package/src/styles/components/iconfont/fonts/iconfont.less +1384 -1384
  196. package/src/styles/components/iconfont/fonts/iconfont.svg +703 -703
  197. package/src/styles/components/index.less +16 -16
  198. package/src/styles/components/input.less +290 -290
  199. package/src/styles/components/modal.less +203 -203
  200. package/src/styles/components/page.less +340 -340
  201. package/src/styles/components/select.less +361 -361
  202. package/src/styles/components/steps.less +367 -367
  203. package/src/styles/components/table.less +544 -544
  204. package/src/styles/components/tabs.less +249 -249
  205. package/src/styles/components/upload.less +82 -82
  206. package/src/styles/custom.less +67 -67
  207. package/src/styles/index.less +6 -6
  208. package/src/styles/pack.less +6 -6
  209. package/src/utils/EfuMessenger.js +155 -155
  210. package/src/utils/assist.js +353 -353
  211. package/src/utils/index.js +1 -1
  212. package/src/utils/random_str.js +10 -10
  213. package/src/components/masterplate/detailgridbox.vue +0 -386
@@ -1,353 +1,353 @@
1
- import { isClient } from './index';
2
-
3
- // 判断参数是否是其中之一
4
- export function oneOf (value, validList) {
5
- for (let i = 0; i < validList.length; i++) {
6
- if (value === validList[i]) {
7
- return true;
8
- }
9
- }
10
- return false;
11
- }
12
-
13
- export function camelcaseToHyphen (str) {
14
- return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
15
- }
16
-
17
- // For Modal scrollBar hidden
18
- let cached;
19
- export function getScrollBarSize (fresh) {
20
- // if (isServer) return 0;
21
- if (isClient && (fresh || cached === undefined)) {
22
- const inner = document.createElement('div');
23
- inner.style.width = '100%';
24
- inner.style.height = '200px';
25
-
26
- const outer = document.createElement('div');
27
- const outerStyle = outer.style;
28
-
29
- outerStyle.position = 'absolute';
30
- outerStyle.top = 0;
31
- outerStyle.left = 0;
32
- outerStyle.pointerEvents = 'none';
33
- outerStyle.visibility = 'hidden';
34
- outerStyle.width = '200px';
35
- outerStyle.height = '150px';
36
- outerStyle.overflow = 'hidden';
37
-
38
- outer.appendChild(inner);
39
-
40
- document.body.appendChild(outer);
41
-
42
- const widthContained = inner.offsetWidth;
43
- outer.style.overflow = 'scroll';
44
- let widthScroll = inner.offsetWidth;
45
-
46
- if (widthContained === widthScroll) {
47
- widthScroll = outer.clientWidth;
48
- }
49
-
50
- document.body.removeChild(outer);
51
-
52
- cached = widthContained - widthScroll;
53
- }
54
- return cached;
55
- }
56
-
57
- // watch DOM change
58
- // export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
59
- export const MutationObserver = isClient ? window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false : false;
60
-
61
- const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
62
- const MOZ_HACK_REGEXP = /^moz([A-Z])/;
63
-
64
- function camelCase(name) {
65
- return name.replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
66
- return offset ? letter.toUpperCase() : letter;
67
- }).replace(MOZ_HACK_REGEXP, 'Moz$1');
68
- }
69
- // getStyle
70
- export function getStyle (element, styleName) {
71
- if (!isClient) return;
72
- if (!element || !styleName) return null;
73
- styleName = camelCase(styleName);
74
- if (styleName === 'float') {
75
- styleName = 'cssFloat';
76
- }
77
- try {
78
- const computed = document.defaultView.getComputedStyle(element, '');
79
- return element.style[styleName] || computed ? computed[styleName] : null;
80
- } catch(e) {
81
- return element.style[styleName];
82
- }
83
- }
84
-
85
- // firstUpperCase
86
- function firstUpperCase(str) {
87
- return str.toString()[0].toUpperCase() + str.toString().slice(1);
88
- }
89
- export {firstUpperCase};
90
-
91
- // Warn
92
- export function warnProp(component, prop, correctType, wrongType) {
93
- correctType = firstUpperCase(correctType);
94
- wrongType = firstUpperCase(wrongType);
95
- console.error(`[View UI warn]: Invalid prop: type check failed for prop ${prop}. Expected ${correctType}, got ${wrongType}. (found in component: ${component})`); // eslint-disable-line
96
- }
97
-
98
- export function typeOf(obj) {
99
- const toString = Object.prototype.toString;
100
- const map = {
101
- '[object Boolean]' : 'boolean',
102
- '[object Number]' : 'number',
103
- '[object String]' : 'string',
104
- '[object Function]' : 'function',
105
- '[object Array]' : 'array',
106
- '[object Date]' : 'date',
107
- '[object RegExp]' : 'regExp',
108
- '[object Undefined]': 'undefined',
109
- '[object Null]' : 'null',
110
- '[object Object]' : 'object'
111
- };
112
- return map[toString.call(obj)];
113
- }
114
-
115
- // deepCopy
116
- function deepCopy(data) {
117
- const t = typeOf(data);
118
- let o;
119
-
120
- if (t === 'array') {
121
- o = [];
122
- } else if ( t === 'object') {
123
- o = {};
124
- } else {
125
- return data;
126
- }
127
-
128
- if (t === 'array') {
129
- for (let i = 0; i < data.length; i++) {
130
- o.push(deepCopy(data[i]));
131
- }
132
- } else if ( t === 'object') {
133
- for (let i in data) {
134
- o[i] = deepCopy(data[i]);
135
- }
136
- }
137
- return o;
138
- }
139
-
140
- export {deepCopy};
141
-
142
- // scrollTop animation
143
- export function scrollTop(el, from = 0, to, duration = 500, endCallback) {
144
- if (!isClient) return;
145
- if (!window.requestAnimationFrame) {
146
- window.requestAnimationFrame = (
147
- window.webkitRequestAnimationFrame ||
148
- window.mozRequestAnimationFrame ||
149
- window.msRequestAnimationFrame ||
150
- function (callback) {
151
- return window.setTimeout(callback, 1000/60);
152
- }
153
- );
154
- }
155
- const difference = Math.abs(from - to);
156
- const step = Math.ceil(difference / duration * 50);
157
-
158
- function scroll(start, end, step) {
159
- if (start === end) {
160
- endCallback && endCallback();
161
- return;
162
- }
163
-
164
- let d = (start + step > end) ? end : start + step;
165
- if (start > end) {
166
- d = (start - step < end) ? end : start - step;
167
- }
168
-
169
- if (el === window) {
170
- window.scrollTo(d, d);
171
- } else {
172
- el.scrollTop = d;
173
- }
174
- window.requestAnimationFrame(() => scroll(d, end, step));
175
- }
176
- scroll(from, to, step);
177
- }
178
-
179
- // Find components upward
180
- function findComponentUpward (context, componentName, componentNames) {
181
- if (typeof componentName === 'string') {
182
- componentNames = [componentName];
183
- } else {
184
- componentNames = componentName;
185
- }
186
-
187
- let parent = context.$parent;
188
- let name = parent.$options.name;
189
- while (parent && (!name || componentNames.indexOf(name) < 0)) {
190
- parent = parent.$parent;
191
- if (parent) name = parent.$options.name;
192
- }
193
- return parent;
194
- }
195
- export {findComponentUpward};
196
-
197
- // Find component downward
198
- export function findComponentDownward (context, componentName) {
199
- const $children = context.$children;
200
- let children = null;
201
-
202
- if ($children.length) {
203
- for (const child of $children) {
204
- const name = child.$options.name;
205
- if (name === componentName) {
206
- children = child;
207
- break;
208
- } else {
209
- children = findComponentDownward(child, componentName);
210
- if (children) break;
211
- }
212
- }
213
- }
214
- return children;
215
- }
216
-
217
- // Find components downward
218
- export function findComponentsDownward (context, componentName) {
219
- return context.$children.reduce((components, child) => {
220
- if (child.$options.name === componentName) components.push(child);
221
- const foundChilds = findComponentsDownward(child, componentName);
222
- return components.concat(foundChilds);
223
- }, []);
224
- }
225
-
226
- // Find components upward
227
- export function findComponentsUpward (context, componentName) {
228
- let parents = [];
229
- const parent = context.$parent;
230
- if (parent) {
231
- if (parent.$options.name === componentName) parents.push(parent);
232
- return parents.concat(findComponentsUpward(parent, componentName));
233
- } else {
234
- return [];
235
- }
236
- }
237
-
238
- // Find brothers components
239
- export function findBrothersComponents (context, componentName, exceptMe = true) {
240
- let res = context.$parent.$children.filter(item => {
241
- return item.$options.name === componentName;
242
- });
243
- let index = res.findIndex(item => item._uid === context._uid);
244
- if (exceptMe) res.splice(index, 1);
245
- return res;
246
- }
247
-
248
- /* istanbul ignore next */
249
- const trim = function(string) {
250
- return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
251
- };
252
-
253
- /* istanbul ignore next */
254
- export function hasClass(el, cls) {
255
- if (!el || !cls) return false;
256
- if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
257
- if (el.classList) {
258
- return el.classList.contains(cls);
259
- } else {
260
- return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
261
- }
262
- }
263
-
264
- /* istanbul ignore next */
265
- export function addClass(el, cls) {
266
- if (!el) return;
267
- let curClass = el.className;
268
- const classes = (cls || '').split(' ');
269
-
270
- for (let i = 0, j = classes.length; i < j; i++) {
271
- const clsName = classes[i];
272
- if (!clsName) continue;
273
-
274
- if (el.classList) {
275
- el.classList.add(clsName);
276
- } else {
277
- if (!hasClass(el, clsName)) {
278
- curClass += ' ' + clsName;
279
- }
280
- }
281
- }
282
- if (!el.classList) {
283
- el.className = curClass;
284
- }
285
- }
286
-
287
- /* istanbul ignore next */
288
- export function removeClass(el, cls) {
289
- if (!el || !cls) return;
290
- const classes = cls.split(' ');
291
- let curClass = ' ' + el.className + ' ';
292
-
293
- for (let i = 0, j = classes.length; i < j; i++) {
294
- const clsName = classes[i];
295
- if (!clsName) continue;
296
-
297
- if (el.classList) {
298
- el.classList.remove(clsName);
299
- } else {
300
- if (hasClass(el, clsName)) {
301
- curClass = curClass.replace(' ' + clsName + ' ', ' ');
302
- }
303
- }
304
- }
305
- if (!el.classList) {
306
- el.className = trim(curClass);
307
- }
308
- }
309
-
310
- export const dimensionMap = {
311
- xs: '480px',
312
- sm: '576px',
313
- md: '768px',
314
- lg: '992px',
315
- xl: '1200px',
316
- xxl: '1600px',
317
- };
318
-
319
- export function setMatchMedia () {
320
- if (!isClient) return;
321
- const matchMediaPolyfill = mediaQuery => {
322
- return {
323
- media: mediaQuery,
324
- matches: false,
325
- on() {},
326
- off() {},
327
- };
328
- };
329
- window.matchMedia = window.matchMedia || matchMediaPolyfill;
330
- }
331
-
332
- export const sharpMatcherRegx = /#([^#]+)$/;
333
-
334
- // download file
335
- export async function downloadFile(url, name = 'unnamed') {
336
- if (!isClient) return Promise.reject();
337
- try {
338
- const res = await fetch(url);
339
- const blob = await res.blob();
340
-
341
- if (!blob) return Promise.reject();
342
-
343
- const localUrl = URL.createObjectURL(blob);
344
- const a = document.createElement('a');
345
- a.setAttribute('href', localUrl);
346
- a.setAttribute('download', name);
347
- a.click();
348
- URL.revokeObjectURL(localUrl);
349
- return Promise.resolve();
350
- } catch(e) {
351
- return Promise.reject(e);
352
- }
353
- }
1
+ import { isClient } from './index';
2
+
3
+ // 判断参数是否是其中之一
4
+ export function oneOf (value, validList) {
5
+ for (let i = 0; i < validList.length; i++) {
6
+ if (value === validList[i]) {
7
+ return true;
8
+ }
9
+ }
10
+ return false;
11
+ }
12
+
13
+ export function camelcaseToHyphen (str) {
14
+ return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
15
+ }
16
+
17
+ // For Modal scrollBar hidden
18
+ let cached;
19
+ export function getScrollBarSize (fresh) {
20
+ // if (isServer) return 0;
21
+ if (isClient && (fresh || cached === undefined)) {
22
+ const inner = document.createElement('div');
23
+ inner.style.width = '100%';
24
+ inner.style.height = '200px';
25
+
26
+ const outer = document.createElement('div');
27
+ const outerStyle = outer.style;
28
+
29
+ outerStyle.position = 'absolute';
30
+ outerStyle.top = 0;
31
+ outerStyle.left = 0;
32
+ outerStyle.pointerEvents = 'none';
33
+ outerStyle.visibility = 'hidden';
34
+ outerStyle.width = '200px';
35
+ outerStyle.height = '150px';
36
+ outerStyle.overflow = 'hidden';
37
+
38
+ outer.appendChild(inner);
39
+
40
+ document.body.appendChild(outer);
41
+
42
+ const widthContained = inner.offsetWidth;
43
+ outer.style.overflow = 'scroll';
44
+ let widthScroll = inner.offsetWidth;
45
+
46
+ if (widthContained === widthScroll) {
47
+ widthScroll = outer.clientWidth;
48
+ }
49
+
50
+ document.body.removeChild(outer);
51
+
52
+ cached = widthContained - widthScroll;
53
+ }
54
+ return cached;
55
+ }
56
+
57
+ // watch DOM change
58
+ // export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
59
+ export const MutationObserver = isClient ? window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false : false;
60
+
61
+ const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
62
+ const MOZ_HACK_REGEXP = /^moz([A-Z])/;
63
+
64
+ function camelCase(name) {
65
+ return name.replace(SPECIAL_CHARS_REGEXP, function(_, separator, letter, offset) {
66
+ return offset ? letter.toUpperCase() : letter;
67
+ }).replace(MOZ_HACK_REGEXP, 'Moz$1');
68
+ }
69
+ // getStyle
70
+ export function getStyle (element, styleName) {
71
+ if (!isClient) return;
72
+ if (!element || !styleName) return null;
73
+ styleName = camelCase(styleName);
74
+ if (styleName === 'float') {
75
+ styleName = 'cssFloat';
76
+ }
77
+ try {
78
+ const computed = document.defaultView.getComputedStyle(element, '');
79
+ return element.style[styleName] || computed ? computed[styleName] : null;
80
+ } catch(e) {
81
+ return element.style[styleName];
82
+ }
83
+ }
84
+
85
+ // firstUpperCase
86
+ function firstUpperCase(str) {
87
+ return str.toString()[0].toUpperCase() + str.toString().slice(1);
88
+ }
89
+ export {firstUpperCase};
90
+
91
+ // Warn
92
+ export function warnProp(component, prop, correctType, wrongType) {
93
+ correctType = firstUpperCase(correctType);
94
+ wrongType = firstUpperCase(wrongType);
95
+ console.error(`[View UI warn]: Invalid prop: type check failed for prop ${prop}. Expected ${correctType}, got ${wrongType}. (found in component: ${component})`); // eslint-disable-line
96
+ }
97
+
98
+ export function typeOf(obj) {
99
+ const toString = Object.prototype.toString;
100
+ const map = {
101
+ '[object Boolean]' : 'boolean',
102
+ '[object Number]' : 'number',
103
+ '[object String]' : 'string',
104
+ '[object Function]' : 'function',
105
+ '[object Array]' : 'array',
106
+ '[object Date]' : 'date',
107
+ '[object RegExp]' : 'regExp',
108
+ '[object Undefined]': 'undefined',
109
+ '[object Null]' : 'null',
110
+ '[object Object]' : 'object'
111
+ };
112
+ return map[toString.call(obj)];
113
+ }
114
+
115
+ // deepCopy
116
+ function deepCopy(data) {
117
+ const t = typeOf(data);
118
+ let o;
119
+
120
+ if (t === 'array') {
121
+ o = [];
122
+ } else if ( t === 'object') {
123
+ o = {};
124
+ } else {
125
+ return data;
126
+ }
127
+
128
+ if (t === 'array') {
129
+ for (let i = 0; i < data.length; i++) {
130
+ o.push(deepCopy(data[i]));
131
+ }
132
+ } else if ( t === 'object') {
133
+ for (let i in data) {
134
+ o[i] = deepCopy(data[i]);
135
+ }
136
+ }
137
+ return o;
138
+ }
139
+
140
+ export {deepCopy};
141
+
142
+ // scrollTop animation
143
+ export function scrollTop(el, from = 0, to, duration = 500, endCallback) {
144
+ if (!isClient) return;
145
+ if (!window.requestAnimationFrame) {
146
+ window.requestAnimationFrame = (
147
+ window.webkitRequestAnimationFrame ||
148
+ window.mozRequestAnimationFrame ||
149
+ window.msRequestAnimationFrame ||
150
+ function (callback) {
151
+ return window.setTimeout(callback, 1000/60);
152
+ }
153
+ );
154
+ }
155
+ const difference = Math.abs(from - to);
156
+ const step = Math.ceil(difference / duration * 50);
157
+
158
+ function scroll(start, end, step) {
159
+ if (start === end) {
160
+ endCallback && endCallback();
161
+ return;
162
+ }
163
+
164
+ let d = (start + step > end) ? end : start + step;
165
+ if (start > end) {
166
+ d = (start - step < end) ? end : start - step;
167
+ }
168
+
169
+ if (el === window) {
170
+ window.scrollTo(d, d);
171
+ } else {
172
+ el.scrollTop = d;
173
+ }
174
+ window.requestAnimationFrame(() => scroll(d, end, step));
175
+ }
176
+ scroll(from, to, step);
177
+ }
178
+
179
+ // Find components upward
180
+ function findComponentUpward (context, componentName, componentNames) {
181
+ if (typeof componentName === 'string') {
182
+ componentNames = [componentName];
183
+ } else {
184
+ componentNames = componentName;
185
+ }
186
+
187
+ let parent = context.$parent;
188
+ let name = parent.$options.name;
189
+ while (parent && (!name || componentNames.indexOf(name) < 0)) {
190
+ parent = parent.$parent;
191
+ if (parent) name = parent.$options.name;
192
+ }
193
+ return parent;
194
+ }
195
+ export {findComponentUpward};
196
+
197
+ // Find component downward
198
+ export function findComponentDownward (context, componentName) {
199
+ const $children = context.$children;
200
+ let children = null;
201
+
202
+ if ($children.length) {
203
+ for (const child of $children) {
204
+ const name = child.$options.name;
205
+ if (name === componentName) {
206
+ children = child;
207
+ break;
208
+ } else {
209
+ children = findComponentDownward(child, componentName);
210
+ if (children) break;
211
+ }
212
+ }
213
+ }
214
+ return children;
215
+ }
216
+
217
+ // Find components downward
218
+ export function findComponentsDownward (context, componentName) {
219
+ return context.$children.reduce((components, child) => {
220
+ if (child.$options.name === componentName) components.push(child);
221
+ const foundChilds = findComponentsDownward(child, componentName);
222
+ return components.concat(foundChilds);
223
+ }, []);
224
+ }
225
+
226
+ // Find components upward
227
+ export function findComponentsUpward (context, componentName) {
228
+ let parents = [];
229
+ const parent = context.$parent;
230
+ if (parent) {
231
+ if (parent.$options.name === componentName) parents.push(parent);
232
+ return parents.concat(findComponentsUpward(parent, componentName));
233
+ } else {
234
+ return [];
235
+ }
236
+ }
237
+
238
+ // Find brothers components
239
+ export function findBrothersComponents (context, componentName, exceptMe = true) {
240
+ let res = context.$parent.$children.filter(item => {
241
+ return item.$options.name === componentName;
242
+ });
243
+ let index = res.findIndex(item => item._uid === context._uid);
244
+ if (exceptMe) res.splice(index, 1);
245
+ return res;
246
+ }
247
+
248
+ /* istanbul ignore next */
249
+ const trim = function(string) {
250
+ return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
251
+ };
252
+
253
+ /* istanbul ignore next */
254
+ export function hasClass(el, cls) {
255
+ if (!el || !cls) return false;
256
+ if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
257
+ if (el.classList) {
258
+ return el.classList.contains(cls);
259
+ } else {
260
+ return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
261
+ }
262
+ }
263
+
264
+ /* istanbul ignore next */
265
+ export function addClass(el, cls) {
266
+ if (!el) return;
267
+ let curClass = el.className;
268
+ const classes = (cls || '').split(' ');
269
+
270
+ for (let i = 0, j = classes.length; i < j; i++) {
271
+ const clsName = classes[i];
272
+ if (!clsName) continue;
273
+
274
+ if (el.classList) {
275
+ el.classList.add(clsName);
276
+ } else {
277
+ if (!hasClass(el, clsName)) {
278
+ curClass += ' ' + clsName;
279
+ }
280
+ }
281
+ }
282
+ if (!el.classList) {
283
+ el.className = curClass;
284
+ }
285
+ }
286
+
287
+ /* istanbul ignore next */
288
+ export function removeClass(el, cls) {
289
+ if (!el || !cls) return;
290
+ const classes = cls.split(' ');
291
+ let curClass = ' ' + el.className + ' ';
292
+
293
+ for (let i = 0, j = classes.length; i < j; i++) {
294
+ const clsName = classes[i];
295
+ if (!clsName) continue;
296
+
297
+ if (el.classList) {
298
+ el.classList.remove(clsName);
299
+ } else {
300
+ if (hasClass(el, clsName)) {
301
+ curClass = curClass.replace(' ' + clsName + ' ', ' ');
302
+ }
303
+ }
304
+ }
305
+ if (!el.classList) {
306
+ el.className = trim(curClass);
307
+ }
308
+ }
309
+
310
+ export const dimensionMap = {
311
+ xs: '480px',
312
+ sm: '576px',
313
+ md: '768px',
314
+ lg: '992px',
315
+ xl: '1200px',
316
+ xxl: '1600px',
317
+ };
318
+
319
+ export function setMatchMedia () {
320
+ if (!isClient) return;
321
+ const matchMediaPolyfill = mediaQuery => {
322
+ return {
323
+ media: mediaQuery,
324
+ matches: false,
325
+ on() {},
326
+ off() {},
327
+ };
328
+ };
329
+ window.matchMedia = window.matchMedia || matchMediaPolyfill;
330
+ }
331
+
332
+ export const sharpMatcherRegx = /#([^#]+)$/;
333
+
334
+ // download file
335
+ export async function downloadFile(url, name = 'unnamed') {
336
+ if (!isClient) return Promise.reject();
337
+ try {
338
+ const res = await fetch(url);
339
+ const blob = await res.blob();
340
+
341
+ if (!blob) return Promise.reject();
342
+
343
+ const localUrl = URL.createObjectURL(blob);
344
+ const a = document.createElement('a');
345
+ a.setAttribute('href', localUrl);
346
+ a.setAttribute('download', name);
347
+ a.click();
348
+ URL.revokeObjectURL(localUrl);
349
+ return Promise.resolve();
350
+ } catch(e) {
351
+ return Promise.reject(e);
352
+ }
353
+ }