sh-tools 1.2.2 → 1.2.6

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.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "sh-tools",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "description": "基于xe-ajax和xe-utils二次封装",
5
- "main": "lib/sh-tools.common.js",
5
+ "main": "packages/index.js",
6
6
  "scripts": {
7
7
  "lib": "vue-cli-service build --target lib packages/index.js --name sh-tools --dest lib"
8
8
  },
@@ -13,9 +13,9 @@
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
15
  "hot-formula-parser": "^4.0.0",
16
- "view-ui-plus": "^1.3.1",
16
+ "view-ui-plus": "^1.3.14",
17
17
  "xe-ajax": "^4.0.5",
18
- "xe-utils": "^3.5.10"
18
+ "xe-utils": "^3.5.11"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@babel/core": "^7.12.16",
@@ -36,8 +36,6 @@
36
36
  "html-webpack-tags-plugin": "^3.0.2",
37
37
  "node-polyfill-webpack-plugin": "^2.0.1",
38
38
  "prettier": "^2.4.1",
39
- "sass": "^1.32.7",
40
- "sass-loader": "^12.0.0",
41
39
  "vue": "^3.3.4"
42
40
  }
43
41
  }
@@ -0,0 +1,85 @@
1
+ import XEAjax from 'xe-ajax'
2
+ import { Notice } from 'view-ui-plus'
3
+
4
+ class HttpRequest {
5
+ constructor(options = {}) {
6
+ this.instance = XEAjax
7
+ this.options = options
8
+ this.setOptions(options)
9
+ this.interceptors()
10
+ }
11
+ setOptions(options) {
12
+ this.instance.setup(options)
13
+ }
14
+ // 继承类重写方法 用于处理个性化业务 预留
15
+ setRequest(request) {}
16
+ setResponse(response) {}
17
+ request(options) {
18
+ return this.instance.ajax(options)
19
+ }
20
+ get(url, params, options) {
21
+ return this.instance.get(url, params, options)
22
+ }
23
+ post(url, params, options) {
24
+ return this.instance.post(url, params, options)
25
+ }
26
+ put(url, params, options) {
27
+ return this.instance.put(url, params, options)
28
+ }
29
+ delete(url, params, options) {
30
+ return this.instance.delete(url, params, options)
31
+ }
32
+ patch(url, params, options) {
33
+ return this.instance.patch(url, params, options)
34
+ }
35
+ head(url, params, options) {
36
+ return this.instance.head(url, params, options)
37
+ }
38
+ jsonp(url, params, options) {
39
+ return this.instance.jsonp(url, params, options)
40
+ }
41
+ // 拦截器
42
+ interceptors() {
43
+ // 请求拦截
44
+ this.instance.interceptors.request.use((request, next) => {
45
+ this.setRequest(request)
46
+ next()
47
+ })
48
+ // 响应拦截
49
+ this.instance.interceptors.response.use((response, next) => {
50
+ this.responseNext(response, next)
51
+ })
52
+ }
53
+ // 错误处理
54
+ async responseNext(response, next) {
55
+ const { status, statusText, headers } = response
56
+ const duration = 5
57
+ let resBody = null
58
+ try {
59
+ resBody = await response.json()
60
+ } catch (e) {
61
+ resBody = response.__response || {}
62
+ }
63
+ let errorMsg = resBody.error || resBody.msg || resBody.message || resBody.result || statusText || '系统错误'
64
+ switch (status) {
65
+ case 0:
66
+ Notice.error({ title: '请求错误', desc: errorMsg, duration: duration })
67
+ break
68
+ case 200:
69
+ break
70
+ case 401:
71
+ Notice.error({ title: '系统提示 401', desc: '未授权,请重新登录', duration: duration })
72
+ return
73
+ case 504:
74
+ Notice.error({ title: '系统提示 网络超时', desc: errorMsg, duration: duration })
75
+ break
76
+ default:
77
+ Notice.error({ title: `系统提示 ${status}`, desc: errorMsg, duration: duration })
78
+ break
79
+ }
80
+ this.setResponse(resBody)
81
+ next({ status: 200, body: resBody })
82
+ }
83
+ }
84
+
85
+ export default HttpRequest
@@ -0,0 +1,5 @@
1
+ import http from './api/index'
2
+
3
+ import utils from './utils/index'
4
+
5
+ export { http, utils }
@@ -0,0 +1,10 @@
1
+ import XEUtils from 'xe-utils'
2
+
3
+ export default {
4
+ isPromise(obj) {
5
+ return Object.prototype.toString.call(obj).slice(8, -1) === 'Promise'
6
+ },
7
+ isNone(value) {
8
+ return ['', null, undefined].includes(value)
9
+ }
10
+ }
@@ -0,0 +1,395 @@
1
+ const colorKeywords = new Map([
2
+ ['transparent', 'rgba(0,0,0,0)'],
3
+ ['black', '#000000'],
4
+ ['silver', '#C0C0C0'],
5
+ ['gray', '#808080'],
6
+ ['white', '#FFFFFF'],
7
+ ['maroon', '#800000'],
8
+ ['red', '#FF0000'],
9
+ ['purple', '#800080'],
10
+ ['fuchsia', '#FF00FF'],
11
+ ['green', '#008000'],
12
+ ['lime', '#00FF00'],
13
+ ['olive', '#808000'],
14
+ ['yellow', '#FFFF00'],
15
+ ['navy', '#000080'],
16
+ ['blue', '#0000FF'],
17
+ ['teal', '#008080'],
18
+ ['aqua', '#00FFFF'],
19
+ ['aliceblue', '#f0f8ff'],
20
+ ['antiquewhite', '#faebd7'],
21
+ ['aquamarine', '#7fffd4'],
22
+ ['azure', '#f0ffff'],
23
+ ['beige', '#f5f5dc'],
24
+ ['bisque', '#ffe4c4'],
25
+ ['blanchedalmond', '#ffebcd'],
26
+ ['blueviolet', '#8a2be2'],
27
+ ['brown', '#a52a2a'],
28
+ ['burlywood', '#deb887'],
29
+ ['cadetblue', '#5f9ea0'],
30
+ ['chartreuse', '#7fff00'],
31
+ ['chocolate', '#d2691e'],
32
+ ['coral', '#ff7f50'],
33
+ ['cornflowerblue', '#6495ed'],
34
+ ['cornsilk', '#fff8dc'],
35
+ ['crimson', '#dc143c'],
36
+ ['cyan', '#00ffff'],
37
+ ['darkblue', '#00008b'],
38
+ ['darkcyan', '#008b8b'],
39
+ ['darkgoldenrod', '#b8860b'],
40
+ ['darkgray', '#a9a9a9'],
41
+ ['darkgreen', '#006400'],
42
+ ['darkgrey', '#a9a9a9'],
43
+ ['darkkhaki', '#bdb76b'],
44
+ ['darkmagenta', '#8b008b'],
45
+ ['darkolivegreen', '#556b2f'],
46
+ ['darkorange', '#ff8c00'],
47
+ ['darkorchid', '#9932cc'],
48
+ ['darkred', '#8b0000'],
49
+ ['darksalmon', '#e9967a'],
50
+ ['darkseagreen', '#8fbc8f'],
51
+ ['darkslateblue', '#483d8b'],
52
+ ['darkslategray', '#2f4f4f'],
53
+ ['darkslategrey', '#2f4f4f'],
54
+ ['darkturquoise', '#00ced1'],
55
+ ['darkviolet', '#9400d3'],
56
+ ['deeppink', '#ff1493'],
57
+ ['deepskyblue', '#00bfff'],
58
+ ['dimgray', '#696969'],
59
+ ['dimgrey', '#696969'],
60
+ ['dodgerblue', '#1e90ff'],
61
+ ['firebrick', '#b22222'],
62
+ ['floralwhite', '#fffaf0'],
63
+ ['forestgreen', '#228b22'],
64
+ ['gainsboro', '#dcdcdc'],
65
+ ['ghostwhite', '#f8f8ff'],
66
+ ['gold', '#ffd700'],
67
+ ['goldenrod', '#daa520'],
68
+ ['greenyellow', '#adff2f'],
69
+ ['grey', '#808080'],
70
+ ['honeydew', '#f0fff0'],
71
+ ['hotpink', '#ff69b4'],
72
+ ['indianred', '#cd5c5c'],
73
+ ['indigo', '#4b0082'],
74
+ ['ivory', '#fffff0'],
75
+ ['khaki', '#f0e68c'],
76
+ ['lavender', '#e6e6fa'],
77
+ ['lavenderblush', '#fff0f5'],
78
+ ['lawngreen', '#7cfc00'],
79
+ ['lemonchiffon', '#fffacd'],
80
+ ['lightblue', '#add8e6'],
81
+ ['lightcoral', '#f08080'],
82
+ ['lightcyan', '#e0ffff'],
83
+ ['lightgoldenrodyellow', '#fafad2'],
84
+ ['lightgray', '#d3d3d3'],
85
+ ['lightgreen', '#90ee90'],
86
+ ['lightgrey', '#d3d3d3'],
87
+ ['lightpink', '#ffb6c1'],
88
+ ['lightsalmon', '#ffa07a'],
89
+ ['lightseagreen', '#20b2aa'],
90
+ ['lightskyblue', '#87cefa'],
91
+ ['lightslategray', '#778899'],
92
+ ['lightslategrey', '#778899'],
93
+ ['lightsteelblue', '#b0c4de'],
94
+ ['lightyellow', '#ffffe0'],
95
+ ['limegreen', '#32cd32'],
96
+ ['linen', '#faf0e6'],
97
+ ['magenta', '#ff00ff'],
98
+ ['mediumaquamarine', '#66cdaa'],
99
+ ['mediumblue', '#0000cd'],
100
+ ['mediumorchid', '#ba55d3'],
101
+ ['mediumpurple', '#9370db'],
102
+ ['mediumseagreen', '#3cb371'],
103
+ ['mediumslateblue', '#7b68ee'],
104
+ ['mediumspringgreen', '#00fa9a'],
105
+ ['mediumturquoise', '#48d1cc'],
106
+ ['mediumvioletred', '#c71585'],
107
+ ['midnightblue', '#191970'],
108
+ ['mintcream', '#f5fffa'],
109
+ ['mistyrose', '#ffe4e1'],
110
+ ['moccasin', '#ffe4b5'],
111
+ ['navajowhite', '#ffdead'],
112
+ ['oldlace', '#fdf5e6'],
113
+ ['olivedrab', '#6b8e23'],
114
+ ['orange', '#ffa500'],
115
+ ['orangered', '#ff4500'],
116
+ ['orchid', '#da70d6'],
117
+ ['palegoldenrod', '#eee8aa'],
118
+ ['palegreen', '#98fb98'],
119
+ ['paleturquoise', '#afeeee'],
120
+ ['palevioletred', '#db7093'],
121
+ ['papayawhip', '#ffefd5'],
122
+ ['peachpuff', '#ffdab9'],
123
+ ['peru', '#cd853f'],
124
+ ['pink', '#ffc0cb'],
125
+ ['plum', '#dda0dd'],
126
+ ['powderblue', '#b0e0e6'],
127
+ ['rosybrown', '#bc8f8f'],
128
+ ['royalblue', '#4169e1'],
129
+ ['saddlebrown', '#8b4513'],
130
+ ['salmon', '#fa8072'],
131
+ ['sandybrown', '#f4a460'],
132
+ ['seagreen', '#2e8b57'],
133
+ ['seashell', '#fff5ee'],
134
+ ['sienna', '#a0522d'],
135
+ ['skyblue', '#87ceeb'],
136
+ ['slateblue', '#6a5acd'],
137
+ ['slategray', '#708090'],
138
+ ['slategrey', '#708090'],
139
+ ['snow', '#fffafa'],
140
+ ['springgreen', '#00ff7f'],
141
+ ['steelblue', '#4682b4'],
142
+ ['tan', '#d2b48c'],
143
+ ['thistle', '#d8bfd8'],
144
+ ['tomato', '#ff6347'],
145
+ ['turquoise', '#40e0d0'],
146
+ ['violet', '#ee82ee'],
147
+ ['wheat', '#f5deb3'],
148
+ ['whitesmoke', '#f5f5f5'],
149
+ ['yellowgreen', '#9acd32']
150
+ ])
151
+
152
+ const hexReg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
153
+ const rgbReg = /^(rgb|rgba|RGB|RGBA)/
154
+ const rgbaReg = /^(rgba|RGBA)/
155
+
156
+ /**
157
+ * @description Color validator
158
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
159
+ * @return {String|Boolean} Valid color Or false
160
+ */
161
+ function validator(color) {
162
+ const isHex = hexReg.test(color)
163
+ const isRgb = rgbReg.test(color)
164
+ if (isHex || isRgb) return color
165
+ color = getColorByKeyword(color)
166
+ if (!color) {
167
+ console.error('Color: Invalid color!')
168
+ return false
169
+ }
170
+ return color
171
+ }
172
+
173
+ /**
174
+ * @description Get color by keyword
175
+ * @param {String} keyword Color keyword like red, green and etc.
176
+ * @return {String|Boolean} Hex or rgba color (Invalid keyword will return false)
177
+ */
178
+ function getColorByKeyword(keyword) {
179
+ if (!keyword) {
180
+ console.error('getColorByKeywords: Missing parameters!')
181
+ return false
182
+ }
183
+ if (!colorKeywords.has(keyword)) return false
184
+ return colorKeywords.get(keyword)
185
+ }
186
+
187
+ /**
188
+ * @description Get the Rgb value of the color
189
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
190
+ * @return {Array<Number>|Boolean} Rgb value of the color (Invalid input will return false)
191
+ */
192
+ export function getRgbValue(color) {
193
+ if (!color) {
194
+ console.error('getRgbValue: Missing parameters!')
195
+ return false
196
+ }
197
+ color = validator(color)
198
+ if (!color) return false
199
+ const isHex = hexReg.test(color)
200
+ const isRgb = rgbReg.test(color)
201
+ const lowerColor = color.toLowerCase()
202
+ if (isHex) return getRgbValueFromHex(lowerColor)
203
+ if (isRgb) return getRgbValueFromRgb(lowerColor)
204
+ }
205
+
206
+ /**
207
+ * @description Get the rgb value of the hex color
208
+ * @param {String} color Hex color
209
+ * @return {Array<Number>} Rgb value of the color
210
+ */
211
+ function getRgbValueFromHex(color) {
212
+ color = color.replace('#', '')
213
+ if (color.length === 3)
214
+ color = Array.from(color)
215
+ .map(hexNum => hexNum + hexNum)
216
+ .join('')
217
+ color = color.split('')
218
+ return new Array(3).fill(0).map((t, i) => parseInt(`0x${color[i * 2]}${color[i * 2 + 1]}`))
219
+ }
220
+
221
+ /**
222
+ * @description Get the rgb value of the rgb/rgba color
223
+ * @param {String} color Hex color
224
+ * @return {Array} Rgb value of the color
225
+ */
226
+ function getRgbValueFromRgb(color) {
227
+ return color
228
+ .replace(/rgb\(|rgba\(|\)/g, '')
229
+ .split(',')
230
+ .slice(0, 3)
231
+ .map(n => parseInt(n))
232
+ }
233
+
234
+ /**
235
+ * @description Get the Rgba value of the color
236
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
237
+ * @return {Array<Number>|Boolean} Rgba value of the color (Invalid input will return false)
238
+ */
239
+ export function getRgbaValue(color) {
240
+ if (!color) {
241
+ console.error('getRgbaValue: Missing parameters!')
242
+ return false
243
+ }
244
+
245
+ const colorValue = getRgbValue(color)
246
+ if (!colorValue) return false
247
+ colorValue.push(getOpacity(color))
248
+ return colorValue
249
+ }
250
+
251
+ /**
252
+ * @description Get the opacity of color
253
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
254
+ * @return {Number|Boolean} Color opacity (Invalid input will return false)
255
+ */
256
+ export function getOpacity(color) {
257
+ if (!color) {
258
+ console.error('getOpacity: Missing parameters!')
259
+ return false
260
+ }
261
+ color = validator(color)
262
+ if (!color) return false
263
+ const isRgba = rgbaReg.test(color)
264
+ if (!isRgba) return 1
265
+ color = color.toLowerCase()
266
+ return Number(
267
+ color
268
+ .split(',')
269
+ .slice(-1)[0]
270
+ .replace(/[)|\s]/g, '')
271
+ )
272
+ }
273
+
274
+ /**
275
+ * @description Convert color to Rgb|Rgba color
276
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
277
+ * @param {Number} opacity The opacity of color
278
+ * @return {String|Boolean} Rgb|Rgba color (Invalid input will return false)
279
+ */
280
+ export function toRgb(color, opacity) {
281
+ if (!color) {
282
+ console.error('toRgb: Missing parameters!')
283
+ return false
284
+ }
285
+ const rgbValue = getRgbValue(color)
286
+ if (!rgbValue) return false
287
+ const addOpacity = typeof opacity === 'number'
288
+ if (addOpacity) return 'rgba(' + rgbValue.join(',') + `,${opacity})`
289
+ return 'rgb(' + rgbValue.join(',') + ')'
290
+ }
291
+
292
+ /**
293
+ * @description Convert color to Hex color
294
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
295
+ * @return {String|Boolean} Hex color (Invalid input will return false)
296
+ */
297
+ export function toHex(color) {
298
+ if (!color) {
299
+ console.error('toHex: Missing parameters!')
300
+ return false
301
+ }
302
+ if (hexReg.test(color)) return color
303
+ color = getRgbValue(color)
304
+ if (!color) return false
305
+ return (
306
+ '#' +
307
+ color
308
+ .map(n => Number(n).toString(16))
309
+ .map(n => (n === '0' ? '00' : n))
310
+ .join('')
311
+ )
312
+ }
313
+
314
+ /**
315
+ * @description Get Color from Rgb|Rgba value
316
+ * @param {Array<Number>} value Rgb|Rgba color value
317
+ * @return {String|Boolean} Rgb|Rgba color (Invalid input will return false)
318
+ */
319
+ export function getColorFromRgbValue(value) {
320
+ if (!value) {
321
+ console.error('getColorFromRgbValue: Missing parameters!')
322
+ return false
323
+ }
324
+ const valueLength = value.length
325
+ if (valueLength !== 3 && valueLength !== 4) {
326
+ console.error('getColorFromRgbValue: Value is illegal!')
327
+ return false
328
+ }
329
+ let color = valueLength === 3 ? 'rgb(' : 'rgba('
330
+ color += value.join(',') + ')'
331
+ return color
332
+ }
333
+
334
+ /**
335
+ * @description Deepen color
336
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
337
+ * @return {Number} Percent of Deepen (1-100)
338
+ * @return {String|Boolean} Rgba color (Invalid input will return false)
339
+ */
340
+ export function darken(color, percent = 0) {
341
+ if (!color) {
342
+ console.error('darken: Missing parameters!')
343
+ return false
344
+ }
345
+ let rgbaValue = getRgbaValue(color)
346
+ if (!rgbaValue) return false
347
+ rgbaValue = rgbaValue.map((v, i) => (i === 3 ? v : v - Math.ceil(2.55 * percent))).map(v => (v < 0 ? 0 : v))
348
+ return getColorFromRgbValue(rgbaValue)
349
+ }
350
+
351
+ /**
352
+ * @description Brighten color
353
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
354
+ * @return {Number} Percent of brighten (1-100)
355
+ * @return {String|Boolean} Rgba color (Invalid input will return false)
356
+ */
357
+ export function lighten(color, percent = 0) {
358
+ if (!color) {
359
+ console.error('lighten: Missing parameters!')
360
+ return false
361
+ }
362
+ let rgbaValue = getRgbaValue(color)
363
+ if (!rgbaValue) return false
364
+ rgbaValue = rgbaValue.map((v, i) => (i === 3 ? v : v + Math.ceil(2.55 * percent))).map(v => (v > 255 ? 255 : v))
365
+ return getColorFromRgbValue(rgbaValue)
366
+ }
367
+
368
+ /**
369
+ * @description Adjust color opacity
370
+ * @param {String} color Hex|Rgb|Rgba color or color keyword
371
+ * @param {Number} percent of opacity
372
+ * @return {String|Boolean} Rgba color (Invalid input will return false)
373
+ */
374
+ export function fade(color, percent = 100) {
375
+ if (!color) {
376
+ console.error('fade: Missing parameters!')
377
+ return false
378
+ }
379
+ const rgbValue = getRgbValue(color)
380
+ if (!rgbValue) return false
381
+ const rgbaValue = [...rgbValue, percent / 100]
382
+ return getColorFromRgbValue(rgbaValue)
383
+ }
384
+
385
+ export default {
386
+ fade,
387
+ toHex,
388
+ toRgb,
389
+ darken,
390
+ lighten,
391
+ getOpacity,
392
+ getRgbValue,
393
+ getRgbaValue,
394
+ getColorFromRgbValue
395
+ }
@@ -0,0 +1,111 @@
1
+ const getScrollEventTarget = element => {
2
+ let currentNode = element
3
+ while (currentNode && currentNode.tagName !== 'HTML' && currentNode.nodeType === 1) {
4
+ const overflowY = window.getComputedStyle(currentNode).overflowY
5
+ if (overflowY === 'scroll' || overflowY === 'auto') {
6
+ return currentNode
7
+ }
8
+ currentNode = currentNode.parentNode
9
+ }
10
+ return window
11
+ }
12
+
13
+ const getScrollTop = element => {
14
+ if (element === window) {
15
+ return Math.max(window.pageYOffset || 0, document.documentElement.scrollTop)
16
+ } else {
17
+ return element.scrollTop
18
+ }
19
+ }
20
+
21
+ const getOffset = el => {
22
+ const box = el.getBoundingClientRect()
23
+ const body = document.body
24
+ const clientTop = el.clientTop || body.clientTop || 0
25
+ const clientLeft = el.clientLeft || body.clientLeft || 0
26
+ const scrollTop = window.pageYOffset || el.scrollTop
27
+ const scrollLeft = window.pageXOffset || el.scrollLeft
28
+ return {
29
+ top: box.top + scrollTop - clientTop,
30
+ left: box.left + scrollLeft - clientLeft
31
+ }
32
+ }
33
+
34
+ const transitionEnd = (el, fun) => {
35
+ const arr = ['msTransitionEnd', 'mozTransitionEnd', 'oTransitionEnd', 'webkitTransitionEnd', 'transitionend']
36
+ const handler = {
37
+ handleEvent(event) {
38
+ arr.forEach(function (eventName) {
39
+ el.removeEventListener(eventName, handler, false)
40
+ })
41
+ fun.apply(el, arguments)
42
+ }
43
+ }
44
+ arr.forEach(function (eventName) {
45
+ el.addEventListener(eventName, handler, false)
46
+ })
47
+ }
48
+
49
+ const hasClass = (el, cls) => {
50
+ if (!el || !cls) return false
51
+ if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.')
52
+ if (el.classList) {
53
+ return el.classList.contains(cls)
54
+ } else {
55
+ return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1
56
+ }
57
+ }
58
+
59
+ const addClass = (el, cls) => {
60
+ if (!el) return
61
+ var curClass = el.className
62
+ var classes = (cls || '').split(' ')
63
+
64
+ for (var i = 0, j = classes.length; i < j; i++) {
65
+ var clsName = classes[i]
66
+ if (!clsName) continue
67
+
68
+ if (el.classList) {
69
+ el.classList.add(clsName)
70
+ } else {
71
+ if (!hasClass(el, clsName)) {
72
+ curClass += ' ' + clsName
73
+ }
74
+ }
75
+ }
76
+ if (!el.classList) {
77
+ el.className = curClass
78
+ }
79
+ }
80
+
81
+ const removeClass = (el, cls) => {
82
+ if (!el || !cls) return
83
+ var classes = cls.split(' ')
84
+ var curClass = ' ' + el.className + ' '
85
+
86
+ for (var i = 0, j = classes.length; i < j; i++) {
87
+ var clsName = classes[i]
88
+ if (!clsName) continue
89
+
90
+ if (el.classList) {
91
+ el.classList.remove(clsName)
92
+ } else {
93
+ if (hasClass(el, clsName)) {
94
+ curClass = curClass.replace(' ' + clsName + ' ', ' ')
95
+ }
96
+ }
97
+ }
98
+ if (!el.classList) {
99
+ el.className = curClass ? curClass.trim() : curClass
100
+ }
101
+ }
102
+
103
+ export default {
104
+ getScrollEventTarget,
105
+ getScrollTop,
106
+ getOffset,
107
+ transitionEnd,
108
+ hasClass,
109
+ addClass,
110
+ removeClass
111
+ }
@@ -0,0 +1,25 @@
1
+ import XEUtils from 'xe-utils'
2
+
3
+ XEUtils.setup({})
4
+
5
+ import number from './number'
6
+ import string from './string'
7
+ import boolean from './boolean'
8
+ import color from './color'
9
+ import dom from './dom'
10
+ import other from './other'
11
+ import validate from './validate'
12
+ import pattern from './pattern'
13
+
14
+ XEUtils.mixin({
15
+ ...number,
16
+ ...string,
17
+ ...boolean,
18
+ ...color,
19
+ ...dom,
20
+ ...other,
21
+ ...validate,
22
+ ...pattern
23
+ })
24
+
25
+ export default XEUtils
@@ -0,0 +1,24 @@
1
+ import XEUtils from 'xe-utils'
2
+ import stringUtil from './string'
3
+ import { Parser } from 'hot-formula-parser'
4
+ const formulaParser = new Parser()
5
+
6
+ export default {
7
+ truncate(num, digits) {
8
+ if (num < 0) {
9
+ let rnum = '-' + XEUtils.floor(String(num).replace('-', ''), digits)
10
+ return Number(rnum)
11
+ } else {
12
+ return XEUtils.floor(num, digits)
13
+ }
14
+ },
15
+
16
+ calculate(formula, data) {
17
+ if (!formula) return ''
18
+ if (data && XEUtils.isPlainObject(data)) {
19
+ formula = stringUtil.format(formula, data)
20
+ }
21
+ let { result } = formulaParser.parse(formula)
22
+ return result
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ export default {}