@gmcb/uv-ui 0.2.26
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/CHANGELOG.md +295 -0
- package/LICENSE +21 -0
- package/README.md +164 -0
- package/components/uv-action-sheet/props.js +50 -0
- package/components/uv-action-sheet/uv-action-sheet.vue +280 -0
- package/components/uv-album/uv-album.vue +312 -0
- package/components/uv-alert/props.js +45 -0
- package/components/uv-alert/uv-alert.vue +246 -0
- package/components/uv-avatar/props.js +85 -0
- package/components/uv-avatar/uv-avatar.vue +182 -0
- package/components/uv-avatar-group/props.js +53 -0
- package/components/uv-avatar-group/uv-avatar-group.vue +106 -0
- package/components/uv-back-top/props.js +58 -0
- package/components/uv-back-top/uv-back-top.vue +116 -0
- package/components/uv-badge/props.js +73 -0
- package/components/uv-badge/uv-badge.vue +176 -0
- package/components/uv-button/nvue.scss +46 -0
- package/components/uv-button/props.js +163 -0
- package/components/uv-button/uv-button.vue +529 -0
- package/components/uv-button/vue.scss +93 -0
- package/components/uv-calendar/calendar.js +546 -0
- package/components/uv-calendar/header.vue +104 -0
- package/components/uv-calendar/month.vue +616 -0
- package/components/uv-calendar/props.js +145 -0
- package/components/uv-calendar/uv-calendar.vue +390 -0
- package/components/uv-calendars/calendar-body.vue +376 -0
- package/components/uv-calendars/calendar-item.vue +248 -0
- package/components/uv-calendars/calendar.js +546 -0
- package/components/uv-calendars/i18n/en.json +12 -0
- package/components/uv-calendars/i18n/index.js +8 -0
- package/components/uv-calendars/i18n/zh-Hans.json +12 -0
- package/components/uv-calendars/i18n/zh-Hant.json +12 -0
- package/components/uv-calendars/util.js +435 -0
- package/components/uv-calendars/uv-calendars.vue +452 -0
- package/components/uv-cell/props.js +116 -0
- package/components/uv-cell/uv-cell.vue +209 -0
- package/components/uv-cell-group/props.js +15 -0
- package/components/uv-cell-group/uv-cell-group.vue +63 -0
- package/components/uv-checkbox/props.js +70 -0
- package/components/uv-checkbox/uv-checkbox.vue +371 -0
- package/components/uv-checkbox-group/props.js +84 -0
- package/components/uv-checkbox-group/uv-checkbox-group.vue +119 -0
- package/components/uv-code/props.js +35 -0
- package/components/uv-code/uv-code.vue +136 -0
- package/components/uv-code-input/props.js +83 -0
- package/components/uv-code-input/uv-code-input.vue +272 -0
- package/components/uv-col/props.js +30 -0
- package/components/uv-col/uv-col.vue +165 -0
- package/components/uv-collapse/props.js +20 -0
- package/components/uv-collapse/uv-collapse.vue +86 -0
- package/components/uv-collapse-item/props.js +60 -0
- package/components/uv-collapse-item/uv-collapse-item.vue +228 -0
- package/components/uv-column-notice/props.js +61 -0
- package/components/uv-column-notice/uv-column-notice.vue +176 -0
- package/components/uv-count-down/props.js +25 -0
- package/components/uv-count-down/utils.js +62 -0
- package/components/uv-count-down/uv-count-down.vue +169 -0
- package/components/uv-count-to/props.js +60 -0
- package/components/uv-count-to/uv-count-to.vue +187 -0
- package/components/uv-datetime-picker/props.js +130 -0
- package/components/uv-datetime-picker/uv-datetime-picker.vue +355 -0
- package/components/uv-divider/props.js +45 -0
- package/components/uv-divider/uv-divider.vue +113 -0
- package/components/uv-drop-down/uv-drop-down.vue +135 -0
- package/components/uv-drop-down-item/uv-drop-down-item.vue +169 -0
- package/components/uv-drop-down-popup/uv-drop-down-popup.vue +242 -0
- package/components/uv-empty/props.js +60 -0
- package/components/uv-empty/uv-empty.vue +126 -0
- package/components/uv-form/props.js +46 -0
- package/components/uv-form/uv-form.vue +209 -0
- package/components/uv-form/valid.js +1343 -0
- package/components/uv-form-item/props.js +49 -0
- package/components/uv-form-item/uv-form-item.vue +226 -0
- package/components/uv-gap/props.js +25 -0
- package/components/uv-gap/uv-gap.vue +36 -0
- package/components/uv-grid/props.js +20 -0
- package/components/uv-grid/uv-grid.vue +100 -0
- package/components/uv-grid-item/props.js +15 -0
- package/components/uv-grid-item/uv-grid-item.vue +223 -0
- package/components/uv-icon/icons.js +160 -0
- package/components/uv-icon/props.js +90 -0
- package/components/uv-icon/uv-icon.vue +226 -0
- package/components/uv-icon/uvicons.ttf +0 -0
- package/components/uv-image/props.js +100 -0
- package/components/uv-image/uv-image.vue +296 -0
- package/components/uv-index-anchor/props.js +30 -0
- package/components/uv-index-anchor/uv-index-anchor.vue +98 -0
- package/components/uv-index-item/uv-index-item.vue +87 -0
- package/components/uv-index-list/props.js +30 -0
- package/components/uv-index-list/uv-index-list.vue +461 -0
- package/components/uv-input/props.js +175 -0
- package/components/uv-input/uv-input.vue +348 -0
- package/components/uv-keyboard/props.js +95 -0
- package/components/uv-keyboard/uv-keyboard.vue +180 -0
- package/components/uv-keyboard-car/props.js +24 -0
- package/components/uv-keyboard-car/uv-keyboard-car.vue +347 -0
- package/components/uv-keyboard-number/props.js +19 -0
- package/components/uv-keyboard-number/uv-keyboard-number.vue +201 -0
- package/components/uv-line/props.js +34 -0
- package/components/uv-line/uv-line.vue +60 -0
- package/components/uv-line-progress/props.js +29 -0
- package/components/uv-line-progress/uv-line-progress.vue +146 -0
- package/components/uv-link/props.js +40 -0
- package/components/uv-link/uv-link.vue +83 -0
- package/components/uv-list/uv-list.vue +147 -0
- package/components/uv-list-item/uv-list-item.vue +535 -0
- package/components/uv-load-more/props.js +95 -0
- package/components/uv-load-more/uv-load-more.vue +152 -0
- package/components/uv-loading-icon/props.js +67 -0
- package/components/uv-loading-icon/uv-loading-icon.vue +347 -0
- package/components/uv-loading-page/props.js +55 -0
- package/components/uv-loading-page/uv-loading-page.vue +96 -0
- package/components/uv-modal/props.js +90 -0
- package/components/uv-modal/uv-modal.vue +245 -0
- package/components/uv-navbar/props.js +89 -0
- package/components/uv-navbar/uv-navbar.vue +245 -0
- package/components/uv-no-network/props.js +20 -0
- package/components/uv-no-network/uv-no-network.vue +222 -0
- package/components/uv-notice-bar/props.js +76 -0
- package/components/uv-notice-bar/uv-notice-bar.vue +110 -0
- package/components/uv-notify/props.js +45 -0
- package/components/uv-notify/uv-notify.vue +220 -0
- package/components/uv-number-box/props.js +118 -0
- package/components/uv-number-box/uv-number-box.vue +397 -0
- package/components/uv-overlay/props.js +25 -0
- package/components/uv-overlay/uv-overlay.vue +85 -0
- package/components/uv-parse/node/node.vue +576 -0
- package/components/uv-parse/parser.js +1335 -0
- package/components/uv-parse/uv-parse.vue +498 -0
- package/components/uv-pick-color/colors.js +217 -0
- package/components/uv-pick-color/props.js +47 -0
- package/components/uv-pick-color/uv-pick-color.vue +551 -0
- package/components/uv-picker/props.js +95 -0
- package/components/uv-picker/uv-picker.vue +329 -0
- package/components/uv-popup/keypress.js +45 -0
- package/components/uv-popup/uv-popup.vue +537 -0
- package/components/uv-preview-video/uv-preview-video.vue +52 -0
- package/components/uv-qrcode/cache.js +1 -0
- package/components/uv-qrcode/gcanvas/bridge/bridge-weex.js +241 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStyleLinearGradient.js +18 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStylePattern.js +8 -0
- package/components/uv-qrcode/gcanvas/context-2d/FillStyleRadialGradient.js +17 -0
- package/components/uv-qrcode/gcanvas/context-2d/RenderingContext.js +666 -0
- package/components/uv-qrcode/gcanvas/context-webgl/ActiveInfo.js +11 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Buffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Framebuffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLenum.js +298 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLmethod.js +142 -0
- package/components/uv-qrcode/gcanvas/context-webgl/GLtype.js +23 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Program.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Renderbuffer.js +21 -0
- package/components/uv-qrcode/gcanvas/context-webgl/RenderingContext.js +1191 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Shader.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/ShaderPrecisionFormat.js +11 -0
- package/components/uv-qrcode/gcanvas/context-webgl/Texture.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/UniformLocation.js +22 -0
- package/components/uv-qrcode/gcanvas/context-webgl/classUtils.js +3 -0
- package/components/uv-qrcode/gcanvas/env/canvas.js +74 -0
- package/components/uv-qrcode/gcanvas/env/image.js +96 -0
- package/components/uv-qrcode/gcanvas/env/tool.js +24 -0
- package/components/uv-qrcode/gcanvas/index.js +39 -0
- package/components/uv-qrcode/props.js +85 -0
- package/components/uv-qrcode/qrcode.js +34 -0
- package/components/uv-qrcode/queue.js +41 -0
- package/components/uv-qrcode/uv-qrcode.vue +1038 -0
- package/components/uv-radio/props.js +65 -0
- package/components/uv-radio/uv-radio.vue +349 -0
- package/components/uv-radio-group/props.js +89 -0
- package/components/uv-radio-group/uv-radio-group.vue +115 -0
- package/components/uv-rate/props.js +73 -0
- package/components/uv-rate/uv-rate.vue +274 -0
- package/components/uv-read-more/props.js +62 -0
- package/components/uv-read-more/uv-read-more.vue +162 -0
- package/components/uv-row/props.js +20 -0
- package/components/uv-row/uv-row.vue +95 -0
- package/components/uv-row-notice/props.js +40 -0
- package/components/uv-row-notice/uv-row-notice.vue +341 -0
- package/components/uv-safe-bottom/uv-safe-bottom.vue +67 -0
- package/components/uv-scroll-list/nvue.js +29 -0
- package/components/uv-scroll-list/props.js +35 -0
- package/components/uv-scroll-list/scrollWxs.wxs +51 -0
- package/components/uv-scroll-list/uv-scroll-list.vue +218 -0
- package/components/uv-search/props.js +127 -0
- package/components/uv-search/uv-search.vue +311 -0
- package/components/uv-skeleton/props.js +65 -0
- package/components/uv-skeleton/uv-skeleton.vue +250 -0
- package/components/uv-skeletons/uv-skeletons.vue +247 -0
- package/components/uv-slider/props.js +58 -0
- package/components/uv-slider/uv-slider.vue +58 -0
- package/components/uv-status-bar/props.js +8 -0
- package/components/uv-status-bar/uv-status-bar.vue +54 -0
- package/components/uv-steps/props.js +40 -0
- package/components/uv-steps/uv-steps.vue +83 -0
- package/components/uv-steps-item/props.js +25 -0
- package/components/uv-steps-item/uv-steps-item.vue +347 -0
- package/components/uv-sticky/props.js +41 -0
- package/components/uv-sticky/uv-sticky.vue +223 -0
- package/components/uv-subsection/props.js +54 -0
- package/components/uv-subsection/uv-subsection.vue +269 -0
- package/components/uv-swipe-action/props.js +10 -0
- package/components/uv-swipe-action/uv-swipe-action.vue +65 -0
- package/components/uv-swipe-action-item/index - backup.wxs +256 -0
- package/components/uv-swipe-action-item/index.wxs +225 -0
- package/components/uv-swipe-action-item/nvue - backup.js +264 -0
- package/components/uv-swipe-action-item/nvue.js +182 -0
- package/components/uv-swipe-action-item/props.js +40 -0
- package/components/uv-swipe-action-item/uv-swipe-action-item.vue +200 -0
- package/components/uv-swipe-action-item/wxs.js +15 -0
- package/components/uv-swiper/props.js +136 -0
- package/components/uv-swiper/uv-swiper.vue +263 -0
- package/components/uv-swiper-indicator/props.js +30 -0
- package/components/uv-swiper-indicator/uv-swiper-indicator.vue +112 -0
- package/components/uv-switch/props.js +58 -0
- package/components/uv-switch/uv-switch.vue +182 -0
- package/components/uv-tabbar/props.js +50 -0
- package/components/uv-tabbar/uv-tabbar.vue +146 -0
- package/components/uv-tabbar-item/props.js +40 -0
- package/components/uv-tabbar-item/uv-tabbar-item.vue +146 -0
- package/components/uv-tabs/props.js +71 -0
- package/components/uv-tabs/uv-tabs.vue +391 -0
- package/components/uv-tags/props.js +104 -0
- package/components/uv-tags/uv-tags.vue +379 -0
- package/components/uv-text/props.js +113 -0
- package/components/uv-text/uv-text.vue +218 -0
- package/components/uv-text/value.js +87 -0
- package/components/uv-textarea/props.js +138 -0
- package/components/uv-textarea/uv-textarea.vue +238 -0
- package/components/uv-toast/uv-toast.vue +292 -0
- package/components/uv-toolbar/props.js +40 -0
- package/components/uv-toolbar/uv-toolbar.vue +109 -0
- package/components/uv-tooltip/props.js +60 -0
- package/components/uv-tooltip/uv-tooltip.vue +372 -0
- package/components/uv-transition/createAnimation.js +131 -0
- package/components/uv-transition/props.js +31 -0
- package/components/uv-transition/uv-transition.vue +320 -0
- package/components/uv-upload/mixin.js +22 -0
- package/components/uv-upload/props.js +130 -0
- package/components/uv-upload/utils.js +151 -0
- package/components/uv-upload/uv-upload.vue +488 -0
- package/components/uv-vtabs/props.js +79 -0
- package/components/uv-vtabs/uv-vtabs.vue +438 -0
- package/components/uv-vtabs-item/uv-vtabs-item.vue +68 -0
- package/components/uv-waterfall/props.js +69 -0
- package/components/uv-waterfall/uv-waterfall.vue +265 -0
- package/index.js +82 -0
- package/index.scss +7 -0
- package/libs/config/config.js +34 -0
- package/libs/css/color.scss +32 -0
- package/libs/css/common.scss +100 -0
- package/libs/css/components.scss +23 -0
- package/libs/css/variable.scss +111 -0
- package/libs/css/vue.scss +40 -0
- package/libs/function/colorGradient.js +134 -0
- package/libs/function/compress.js +27 -0
- package/libs/function/debounce.js +29 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +734 -0
- package/libs/function/platform.js +75 -0
- package/libs/function/test.js +287 -0
- package/libs/function/throttle.js +30 -0
- package/libs/luch-request/adapters/index.js +132 -0
- package/libs/luch-request/core/InterceptorManager.js +51 -0
- package/libs/luch-request/core/Request.js +201 -0
- package/libs/luch-request/core/buildFullPath.js +20 -0
- package/libs/luch-request/core/defaults.js +33 -0
- package/libs/luch-request/core/dispatchRequest.js +6 -0
- package/libs/luch-request/core/mergeConfig.js +126 -0
- package/libs/luch-request/core/settle.js +16 -0
- package/libs/luch-request/helpers/buildURL.js +64 -0
- package/libs/luch-request/helpers/combineURLs.js +14 -0
- package/libs/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/libs/luch-request/index.d.ts +197 -0
- package/libs/luch-request/index.js +2 -0
- package/libs/luch-request/utils/clone.js +264 -0
- package/libs/luch-request/utils.js +135 -0
- package/libs/mixin/button.js +13 -0
- package/libs/mixin/mixin.js +172 -0
- package/libs/mixin/mpMixin.js +8 -0
- package/libs/mixin/mpShare.js +13 -0
- package/libs/mixin/openType.js +47 -0
- package/libs/mixin/touch.js +59 -0
- package/libs/util/dayjs.js +216 -0
- package/libs/util/route.js +126 -0
- package/package.json +28 -0
- package/theme.scss +43 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 求两个颜色之间的渐变值
|
|
3
|
+
* @param {string} startColor 开始的颜色
|
|
4
|
+
* @param {string} endColor 结束的颜色
|
|
5
|
+
* @param {number} step 颜色等分的份额
|
|
6
|
+
* */
|
|
7
|
+
function colorGradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 255)', step = 10) {
|
|
8
|
+
const startRGB = hexToRgb(startColor, false) // 转换为rgb数组模式
|
|
9
|
+
const startR = startRGB[0]
|
|
10
|
+
const startG = startRGB[1]
|
|
11
|
+
const startB = startRGB[2]
|
|
12
|
+
|
|
13
|
+
const endRGB = hexToRgb(endColor, false)
|
|
14
|
+
const endR = endRGB[0]
|
|
15
|
+
const endG = endRGB[1]
|
|
16
|
+
const endB = endRGB[2]
|
|
17
|
+
|
|
18
|
+
const sR = (endR - startR) / step // 总差值
|
|
19
|
+
const sG = (endG - startG) / step
|
|
20
|
+
const sB = (endB - startB) / step
|
|
21
|
+
const colorArr = []
|
|
22
|
+
for (let i = 0; i < step; i++) {
|
|
23
|
+
// 计算每一步的hex值
|
|
24
|
+
let hex = rgbToHex(`rgb(${Math.round((sR * i + startR))},${Math.round((sG * i + startG))},${Math.round((sB
|
|
25
|
+
* i + startB))})`)
|
|
26
|
+
// 确保第一个颜色值为startColor的值
|
|
27
|
+
if (i === 0) hex = rgbToHex(startColor)
|
|
28
|
+
// 确保最后一个颜色值为endColor的值
|
|
29
|
+
if (i === step - 1) hex = rgbToHex(endColor)
|
|
30
|
+
colorArr.push(hex)
|
|
31
|
+
}
|
|
32
|
+
return colorArr
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 将hex表示方式转换为rgb表示方式(这里返回rgb数组模式)
|
|
36
|
+
function hexToRgb(sColor, str = true) {
|
|
37
|
+
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
38
|
+
sColor = String(sColor).toLowerCase()
|
|
39
|
+
if (sColor && reg.test(sColor)) {
|
|
40
|
+
if (sColor.length === 4) {
|
|
41
|
+
let sColorNew = '#'
|
|
42
|
+
for (let i = 1; i < 4; i += 1) {
|
|
43
|
+
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
|
|
44
|
+
}
|
|
45
|
+
sColor = sColorNew
|
|
46
|
+
}
|
|
47
|
+
// 处理六位的颜色值
|
|
48
|
+
const sColorChange = []
|
|
49
|
+
for (let i = 1; i < 7; i += 2) {
|
|
50
|
+
sColorChange.push(parseInt(`0x${sColor.slice(i, i + 2)}`))
|
|
51
|
+
}
|
|
52
|
+
if (!str) {
|
|
53
|
+
return sColorChange
|
|
54
|
+
}
|
|
55
|
+
return `rgb(${sColorChange[0]},${sColorChange[1]},${sColorChange[2]})`
|
|
56
|
+
} if (/^(rgb|RGB)/.test(sColor)) {
|
|
57
|
+
const arr = sColor.replace(/(?:\(|\)|rgb|RGB)*/g, '').split(',')
|
|
58
|
+
return arr.map((val) => Number(val))
|
|
59
|
+
}
|
|
60
|
+
return sColor
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 将rgb表示方式转换为hex表示方式
|
|
64
|
+
function rgbToHex(rgb) {
|
|
65
|
+
const _this = rgb
|
|
66
|
+
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
67
|
+
if (/^(rgb|RGB)/.test(_this)) {
|
|
68
|
+
const aColor = _this.replace(/(?:\(|\)|rgb|RGB)*/g, '').split(',')
|
|
69
|
+
let strHex = '#'
|
|
70
|
+
for (let i = 0; i < aColor.length; i++) {
|
|
71
|
+
let hex = Number(aColor[i]).toString(16)
|
|
72
|
+
hex = String(hex).length == 1 ? `${0}${hex}` : hex // 保证每个rgb的值为2位
|
|
73
|
+
if (hex === '0') {
|
|
74
|
+
hex += hex
|
|
75
|
+
}
|
|
76
|
+
strHex += hex
|
|
77
|
+
}
|
|
78
|
+
if (strHex.length !== 7) {
|
|
79
|
+
strHex = _this
|
|
80
|
+
}
|
|
81
|
+
return strHex
|
|
82
|
+
} if (reg.test(_this)) {
|
|
83
|
+
const aNum = _this.replace(/#/, '').split('')
|
|
84
|
+
if (aNum.length === 6) {
|
|
85
|
+
return _this
|
|
86
|
+
} if (aNum.length === 3) {
|
|
87
|
+
let numHex = '#'
|
|
88
|
+
for (let i = 0; i < aNum.length; i += 1) {
|
|
89
|
+
numHex += (aNum[i] + aNum[i])
|
|
90
|
+
}
|
|
91
|
+
return numHex
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
return _this
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* JS颜色十六进制转换为rgb或rgba,返回的格式为 rgba(255,255,255,0.5)字符串
|
|
100
|
+
* sHex为传入的十六进制的色值
|
|
101
|
+
* alpha为rgba的透明度
|
|
102
|
+
*/
|
|
103
|
+
function colorToRgba(color, alpha) {
|
|
104
|
+
color = rgbToHex(color)
|
|
105
|
+
// 十六进制颜色值的正则表达式
|
|
106
|
+
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
107
|
+
/* 16进制颜色转为RGB格式 */
|
|
108
|
+
let sColor = String(color).toLowerCase()
|
|
109
|
+
if (sColor && reg.test(sColor)) {
|
|
110
|
+
if (sColor.length === 4) {
|
|
111
|
+
let sColorNew = '#'
|
|
112
|
+
for (let i = 1; i < 4; i += 1) {
|
|
113
|
+
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1))
|
|
114
|
+
}
|
|
115
|
+
sColor = sColorNew
|
|
116
|
+
}
|
|
117
|
+
// 处理六位的颜色值
|
|
118
|
+
const sColorChange = []
|
|
119
|
+
for (let i = 1; i < 7; i += 2) {
|
|
120
|
+
sColorChange.push(parseInt(`0x${sColor.slice(i, i + 2)}`))
|
|
121
|
+
}
|
|
122
|
+
// return sColorChange.join(',')
|
|
123
|
+
return `rgba(${sColorChange.join(',')},${alpha})`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return sColor
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
colorGradient,
|
|
131
|
+
hexToRgb,
|
|
132
|
+
rgbToHex,
|
|
133
|
+
colorToRgba
|
|
134
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function image(url, style) {
|
|
2
|
+
url = String(url || '');
|
|
3
|
+
if (/^https?:\/\//.test(url)) {
|
|
4
|
+
const { width, height } = style || {};
|
|
5
|
+
let params = '';
|
|
6
|
+
if (/\d+(r?px)?$/.test(String(width))) {
|
|
7
|
+
const size = Number.parseFloat(width);
|
|
8
|
+
params = `imageMogr2/thumbnail/${size}x/format/webp`;
|
|
9
|
+
} else if (/\d+(r?px)?$/.test(String(height))) {
|
|
10
|
+
const size = Number.parseFloat(height);
|
|
11
|
+
params = `imageMogr2/thumbnail/x${size}/format/webp`;
|
|
12
|
+
}
|
|
13
|
+
if (params) {
|
|
14
|
+
if (url.lastIndexOf('?') === -1) {
|
|
15
|
+
return `${url}?${params}`;
|
|
16
|
+
}
|
|
17
|
+
if (url.lastIndexOf('imageMogr2/') === -1) {
|
|
18
|
+
return `${url}&${params}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return url;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
image,
|
|
27
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
let timeout = null
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 防抖原理:一定时间内,只有最后一次操作,再过wait毫秒后才执行函数
|
|
5
|
+
*
|
|
6
|
+
* @param {Function} func 要执行的回调函数
|
|
7
|
+
* @param {Number} wait 延时的时间
|
|
8
|
+
* @param {Boolean} immediate 是否立即执行
|
|
9
|
+
* @return null
|
|
10
|
+
*/
|
|
11
|
+
function debounce(func, wait = 500, immediate = false) {
|
|
12
|
+
// 清除定时器
|
|
13
|
+
if (timeout !== null) clearTimeout(timeout)
|
|
14
|
+
// 立即执行,此类情况一般用不到
|
|
15
|
+
if (immediate) {
|
|
16
|
+
const callNow = !timeout
|
|
17
|
+
timeout = setTimeout(() => {
|
|
18
|
+
timeout = null
|
|
19
|
+
}, wait)
|
|
20
|
+
if (callNow) typeof func === 'function' && func()
|
|
21
|
+
} else {
|
|
22
|
+
// 设置定时器,当最后一次操作后,timeout不会再被清除,所以在延时wait毫秒后执行func回调方法
|
|
23
|
+
timeout = setTimeout(() => {
|
|
24
|
+
typeof func === 'function' && func()
|
|
25
|
+
}, wait)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default debounce
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
let _boundaryCheckingState = true; // 是否进行越界检查的全局开关
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 把错误的数据转正
|
|
5
|
+
* @private
|
|
6
|
+
* @example strip(0.09999999999999998)=0.1
|
|
7
|
+
*/
|
|
8
|
+
function strip(num, precision = 15) {
|
|
9
|
+
return +parseFloat(Number(num).toPrecision(precision));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return digits length of a number
|
|
14
|
+
* @private
|
|
15
|
+
* @param {*number} num Input number
|
|
16
|
+
*/
|
|
17
|
+
function digitLength(num) {
|
|
18
|
+
// Get digit length of e
|
|
19
|
+
const eSplit = num.toString().split(/[eE]/);
|
|
20
|
+
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
21
|
+
return len > 0 ? len : 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 把小数转成整数,如果是小数则放大成整数
|
|
26
|
+
* @private
|
|
27
|
+
* @param {*number} num 输入数
|
|
28
|
+
*/
|
|
29
|
+
function float2Fixed(num) {
|
|
30
|
+
if (num.toString().indexOf('e') === -1) {
|
|
31
|
+
return Number(num.toString().replace('.', ''));
|
|
32
|
+
}
|
|
33
|
+
const dLen = digitLength(num);
|
|
34
|
+
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 检测数字是否越界,如果越界给出提示
|
|
39
|
+
* @private
|
|
40
|
+
* @param {*number} num 输入数
|
|
41
|
+
*/
|
|
42
|
+
function checkBoundary(num) {
|
|
43
|
+
if (_boundaryCheckingState) {
|
|
44
|
+
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
|
45
|
+
console.warn(`${num} 超出了精度限制,结果可能不正确`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 把递归操作扁平迭代化
|
|
52
|
+
* @param {number[]} arr 要操作的数字数组
|
|
53
|
+
* @param {function} operation 迭代操作
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
function iteratorOperation(arr, operation) {
|
|
57
|
+
const [num1, num2, ...others] = arr;
|
|
58
|
+
let res = operation(num1, num2);
|
|
59
|
+
|
|
60
|
+
others.forEach((num) => {
|
|
61
|
+
res = operation(res, num);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 高精度乘法
|
|
69
|
+
* @export
|
|
70
|
+
*/
|
|
71
|
+
export function times(...nums) {
|
|
72
|
+
if (nums.length > 2) {
|
|
73
|
+
return iteratorOperation(nums, times);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const [num1, num2] = nums;
|
|
77
|
+
const num1Changed = float2Fixed(num1);
|
|
78
|
+
const num2Changed = float2Fixed(num2);
|
|
79
|
+
const baseNum = digitLength(num1) + digitLength(num2);
|
|
80
|
+
const leftValue = num1Changed * num2Changed;
|
|
81
|
+
|
|
82
|
+
checkBoundary(leftValue);
|
|
83
|
+
|
|
84
|
+
return leftValue / Math.pow(10, baseNum);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 高精度加法
|
|
89
|
+
* @export
|
|
90
|
+
*/
|
|
91
|
+
export function plus(...nums) {
|
|
92
|
+
if (nums.length > 2) {
|
|
93
|
+
return iteratorOperation(nums, plus);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const [num1, num2] = nums;
|
|
97
|
+
// 取最大的小数位
|
|
98
|
+
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
99
|
+
// 把小数都转为整数然后再计算
|
|
100
|
+
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 高精度减法
|
|
105
|
+
* @export
|
|
106
|
+
*/
|
|
107
|
+
export function minus(...nums) {
|
|
108
|
+
if (nums.length > 2) {
|
|
109
|
+
return iteratorOperation(nums, minus);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const [num1, num2] = nums;
|
|
113
|
+
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
114
|
+
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 高精度除法
|
|
119
|
+
* @export
|
|
120
|
+
*/
|
|
121
|
+
export function divide(...nums) {
|
|
122
|
+
if (nums.length > 2) {
|
|
123
|
+
return iteratorOperation(nums, divide);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const [num1, num2] = nums;
|
|
127
|
+
const num1Changed = float2Fixed(num1);
|
|
128
|
+
const num2Changed = float2Fixed(num2);
|
|
129
|
+
checkBoundary(num1Changed);
|
|
130
|
+
checkBoundary(num2Changed);
|
|
131
|
+
// 重要,这里必须用strip进行修正
|
|
132
|
+
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 四舍五入
|
|
137
|
+
* @export
|
|
138
|
+
*/
|
|
139
|
+
export function round(num, ratio) {
|
|
140
|
+
const base = Math.pow(10, ratio);
|
|
141
|
+
let result = divide(Math.round(Math.abs(times(num, base))), base);
|
|
142
|
+
if (num < 0 && result !== 0) {
|
|
143
|
+
result = times(result, -1);
|
|
144
|
+
}
|
|
145
|
+
// 位数不足则补0
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 是否进行边界检查,默认开启
|
|
151
|
+
* @param flag 标记开关,true 为开启,false 为关闭,默认为 true
|
|
152
|
+
* @export
|
|
153
|
+
*/
|
|
154
|
+
export function enableBoundaryChecking(flag = true) {
|
|
155
|
+
_boundaryCheckingState = flag;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
export default {
|
|
160
|
+
times,
|
|
161
|
+
plus,
|
|
162
|
+
minus,
|
|
163
|
+
divide,
|
|
164
|
+
round,
|
|
165
|
+
enableBoundaryChecking,
|
|
166
|
+
};
|
|
167
|
+
|