@10yun/cv-mobile-ui 0.5.29 → 0.5.30
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 +1 -1
- package/plugins/luch-request/adapters/index.js +131 -0
- package/plugins/luch-request/core/InterceptorManager.js +50 -0
- package/plugins/luch-request/core/Request.js +199 -0
- package/plugins/luch-request/core/buildFullPath.js +20 -0
- package/plugins/luch-request/core/defaults.js +32 -0
- package/plugins/luch-request/core/dispatchRequest.js +5 -0
- package/plugins/luch-request/core/mergeConfig.js +125 -0
- package/plugins/luch-request/core/settle.js +16 -0
- package/plugins/luch-request/helpers/buildURL.js +71 -0
- package/plugins/luch-request/helpers/combineURLs.js +12 -0
- package/plugins/luch-request/helpers/isAbsoluteURL.js +14 -0
- package/plugins/luch-request/index.d.ts +197 -0
- package/plugins/luch-request/index.js +2 -0
- package/plugins/luch-request/readme.md +3 -0
- package/plugins/luch-request/utils/clone.js +264 -0
- package/plugins/luch-request/utils.js +131 -0
- package/plugins/request.js +2 -2
- package/ui-cv/components/cv-form-item/cv-form-item.vue +1 -1
- package/ui-fireui/fui-actionsheet/fui-actionsheet.vue +202 -0
- package/ui-fireui/fui-alert/fui-alert.vue +141 -0
- package/ui-fireui/fui-badge/fui-badge.vue +158 -0
- package/ui-fireui/fui-bottom-navigation/fui-bottom-navigation.vue +390 -0
- package/ui-fireui/fui-bottom-popup/fui-bottom-popup.vue +100 -0
- package/ui-fireui/fui-bubble-popup/fui-bubble-popup.vue +236 -0
- package/ui-fireui/fui-button/fui-button.vue +424 -0
- package/ui-fireui/fui-calendar/fui-calendar.js +915 -0
- package/ui-fireui/fui-calendar/fui-calendar.vue +868 -0
- package/ui-fireui/fui-card/fui-card.vue +231 -0
- package/ui-fireui/fui-cascade-selection/fui-cascade-selection.vue +538 -0
- package/ui-fireui/fui-circular-progress/fui-circular-progress.vue +261 -0
- package/ui-fireui/fui-collapse/fui-collapse.vue +179 -0
- package/ui-fireui/fui-countdown/fui-countdown.vue +301 -0
- package/ui-fireui/fui-datetime/fui-datetime.vue +570 -0
- package/ui-fireui/fui-divider/fui-divider.vue +118 -0
- package/ui-fireui/fui-drawer/fui-drawer.vue +103 -0
- package/ui-fireui/fui-dropdown-list/fui-dropdown-list.vue +70 -0
- package/ui-fireui/fui-fab/fui-fab.vue +284 -0
- package/ui-fireui/fui-footer/fui-footer.vue +131 -0
- package/ui-fireui/fui-grid/fui-grid.vue +42 -0
- package/ui-fireui/fui-grid-item/fui-grid-item.vue +142 -0
- package/ui-fireui/fui-icon/fui-icon.vue +820 -0
- package/ui-fireui/fui-image-cropper/fui-image-cropper.vue +1058 -0
- package/ui-fireui/fui-image-group/fui-image-group.vue +149 -0
- package/ui-fireui/fui-keyboard/fui-keyboard.vue +254 -0
- package/ui-fireui/fui-keyboard-input/fui-keyboard-input.vue +78 -0
- package/ui-fireui/fui-list-cell/fui-list-cell.vue +178 -0
- package/ui-fireui/fui-list-view/fui-list-view.vue +87 -0
- package/ui-fireui/fui-loading/fui-loading.vue +78 -0
- package/ui-fireui/fui-loadmore/fui-loadmore.vue +163 -0
- package/ui-fireui/fui-modal/fui-modal.vue +392 -0
- package/ui-fireui/fui-navigation-bar/fui-navigation-bar.vue +180 -0
- package/ui-fireui/fui-no-data/fui-no-data.vue +116 -0
- package/ui-fireui/fui-nomore/fui-nomore.vue +116 -0
- package/ui-fireui/fui-numberbox/fui-numberbox.vue +234 -0
- package/ui-fireui/fui-numberbox-border/fui-numberbox-border.vue +232 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.vue +682 -0
- package/ui-fireui/fui-picture-cropper/fui-picture-cropper.wxs +560 -0
- package/ui-fireui/fui-rate/fui-rate.vue +167 -0
- package/ui-fireui/fui-round-progress/fui-round-progress.vue +306 -0
- package/ui-fireui/fui-scroll-top/fui-scroll-top.vue +189 -0
- package/ui-fireui/fui-sharemodel/fui-sharemodel.vue +181 -0
- package/ui-fireui/fui-skeleton/fui-skeleton.vue +248 -0
- package/ui-fireui/fui-steps/fui-steps.vue +214 -0
- package/ui-fireui/fui-sticky/fui-sticky.vue +155 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky-wxs.vue +133 -0
- package/ui-fireui/fui-sticky-wxs/fui-sticky.wxs +44 -0
- package/ui-fireui/fui-swipe-action/fui-swipe-action.vue +301 -0
- package/ui-fireui/fui-tabbar/fui-tabbar.vue +283 -0
- package/ui-fireui/fui-tabs/fui-tabs.vue +284 -0
- package/ui-fireui/fui-tabs2/fui-tabs2.vue +284 -0
- package/ui-fireui/fui-tag/fui-tag.vue +374 -0
- package/ui-fireui/fui-time-axis/fui-time-axis.vue +36 -0
- package/ui-fireui/fui-timeaxis-item/fui-timeaxis-item.vue +48 -0
- package/ui-fireui/fui-tips/fui-tips.vue +161 -0
- package/ui-fireui/fui-toast/fui-toast.vue +117 -0
- package/ui-fireui/fui-top-dropdown/fui-top-dropdown.vue +129 -0
- package/ui-fireui/fui-upload/fui-upload.vue +446 -0
- package/ui-fireui/fui-uploadsamll/fui-uploadsamll.vue +472 -0
- package/uview-plus/README.md +1 -1
- package/uview-plus/changelog-wu-tool.md +21 -0
- package/uview-plus/changelog-wu.md +91 -0
- package/uview-plus/components/u-action-sheet/_doc/changelog.md +12 -0
- package/uview-plus/components/u-action-sheet/_doc/package.json +92 -0
- package/uview-plus/components/u-action-sheet/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/_doc/changelog.md +26 -0
- package/uview-plus/components/u-app-update/_doc/package.json +89 -0
- package/uview-plus/components/u-app-update/_doc/readme.md +16 -0
- package/uview-plus/components/u-app-update/config.js +120 -0
- package/uview-plus/components/u-app-update/img/act.png +0 -0
- package/uview-plus/components/u-app-update/img/appUploadAlertBoxBg.png +0 -0
- package/uview-plus/components/u-app-update/img/close.png +0 -0
- package/uview-plus/components/u-app-update/js-sdk/checkVersion.js +81 -0
- package/uview-plus/components/u-app-update/js-sdk/silentlyAppUpdate.js +41 -0
- package/uview-plus/components/u-app-update/pages/index.vue +8 -0
- package/uview-plus/components/u-app-update/u-app-update.vue +583 -0
- package/uview-plus/components/u-button-wu/_doc/changelog.md +6 -0
- package/uview-plus/components/u-button-wu/_doc/package.json +89 -0
- package/uview-plus/components/u-button-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-button-wu/u-button-wu.vue +522 -0
- package/uview-plus/components/u-button-wu/vue.scss +81 -0
- package/uview-plus/components/u-calendar-wu/_doc/changelog.md +145 -0
- package/uview-plus/components/u-calendar-wu/_doc/package.json +90 -0
- package/uview-plus/components/u-calendar-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-calendar-wu/calendar.js +664 -0
- package/uview-plus/components/u-calendar-wu/i18n/en.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/index.js +8 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hans.json +14 -0
- package/uview-plus/components/u-calendar-wu/i18n/zh-Hant.json +14 -0
- package/uview-plus/components/u-calendar-wu/props.js +166 -0
- package/uview-plus/components/u-calendar-wu/style.css +196 -0
- package/uview-plus/components/u-calendar-wu/u-calendar-wu.vue +921 -0
- package/uview-plus/components/u-calendar-wu/util.js +552 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/props.js +73 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-block/wu-calendar-block.vue +122 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/props.js +55 -0
- package/uview-plus/components/u-calendar-wu/wu-calendar-item/wu-calendar-item.vue +293 -0
- package/uview-plus/components/u-cell/_doc/changelog.md +6 -0
- package/uview-plus/components/u-cell/_doc/package.json +89 -0
- package/uview-plus/components/u-cell/_doc/readme.md +25 -0
- package/uview-plus/components/u-checkbox/_doc/changelog.md +8 -0
- package/uview-plus/components/u-checkbox/_doc/package.json +88 -0
- package/uview-plus/components/u-checkbox/_doc/readme.md +25 -0
- package/uview-plus/components/u-code/_doc/changelog.md +6 -0
- package/uview-plus/components/u-code/_doc/package.json +86 -0
- package/uview-plus/components/u-code/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/_doc/changelog.md +0 -0
- package/uview-plus/components/u-drag-sort/_doc/package.json +85 -0
- package/uview-plus/components/u-drag-sort/_doc/readme.md +16 -0
- package/uview-plus/components/u-drag-sort/u-drag-sort.vue +3 -0
- package/uview-plus/components/u-empty/u-empty.vue +27 -1
- package/uview-plus/components/u-gap/_doc/changelog.md +4 -0
- package/uview-plus/components/u-gap/_doc/package.json +86 -0
- package/uview-plus/components/u-gap/_doc/readme.md +22 -0
- package/uview-plus/components/u-icon/_doc/changelog.md +10 -0
- package/uview-plus/components/u-icon/_doc/package.json +85 -0
- package/uview-plus/components/u-icon/_doc/readme.md +10 -0
- package/uview-plus/components/u-icon/icon.js +23 -25
- package/uview-plus/components/u-icon/icons.js +213 -213
- package/uview-plus/components/u-icon/style.css +3 -3
- package/uview-plus/components/u-icon/u-icon2.vue +149 -0
- package/uview-plus/components/u-image-wu/_doc/changelog.md +21 -0
- package/uview-plus/components/u-image-wu/_doc/package.json +88 -0
- package/uview-plus/components/u-image-wu/_doc/readme.md +11 -0
- package/uview-plus/components/u-image-wu/props.js +94 -0
- package/uview-plus/components/u-image-wu/u-image-wu.vue +243 -0
- package/uview-plus/components/u-input/_doc/changelog.md +6 -0
- package/uview-plus/components/u-input/_doc/package.json +88 -0
- package/uview-plus/components/u-input/_doc/readme.md +16 -0
- package/uview-plus/components/u-line/_doc/changelog.md +8 -0
- package/uview-plus/components/u-line/_doc/package.json +86 -0
- package/uview-plus/components/u-line/_doc/readme.md +16 -0
- package/uview-plus/components/u-link/_doc/changelog.md +8 -0
- package/uview-plus/components/u-link/_doc/package.json +86 -0
- package/uview-plus/components/u-link/_doc/readme.md +20 -0
- package/uview-plus/components/u-loading-icon/_doc/changelog.md +12 -0
- package/uview-plus/components/u-loading-icon/_doc/package.json +86 -0
- package/uview-plus/components/u-loading-icon/_doc/readme.md +16 -0
- package/uview-plus/components/u-loading-icon/props.js +1 -1
- package/uview-plus/components/u-navbar/_doc/changelog.md +6 -0
- package/uview-plus/components/u-navbar/_doc/package.json +89 -0
- package/uview-plus/components/u-navbar/_doc/readme.md +16 -0
- package/uview-plus/components/u-navbar-wu/props.js +102 -0
- package/uview-plus/components/u-navbar-wu/u-navbar-wu.vue +196 -0
- package/uview-plus/components/u-number-box/_doc/changelog.md +19 -0
- package/uview-plus/components/u-number-box/_doc/package.json +88 -0
- package/uview-plus/components/u-number-box/_doc/readme.md +16 -0
- package/uview-plus/components/u-overlay/_doc/changelog.md +4 -0
- package/uview-plus/components/u-overlay/_doc/package.json +88 -0
- package/uview-plus/components/u-overlay/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup/_doc/changelog.md +4 -0
- package/uview-plus/components/u-popup/_doc/package.json +92 -0
- package/uview-plus/components/u-popup/_doc/readme.md +16 -0
- package/uview-plus/components/u-popup-wu/keypress.js +45 -0
- package/uview-plus/components/u-popup-wu/u-popup-wu.vue +519 -0
- package/uview-plus/components/u-radio/_doc/changelog.md +6 -0
- package/uview-plus/components/u-radio/_doc/package.json +88 -0
- package/uview-plus/components/u-radio/_doc/readme.md +25 -0
- package/uview-plus/components/u-row/_doc/changelog.md +8 -0
- package/uview-plus/components/u-row/_doc/package.json +86 -0
- package/uview-plus/components/u-row/_doc/readme.md +16 -0
- package/uview-plus/components/u-safe-bottom/_doc/changelog.md +6 -0
- package/uview-plus/components/u-safe-bottom/_doc/package.json +86 -0
- package/uview-plus/components/u-safe-bottom/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/_doc/changelog.md +27 -0
- package/uview-plus/components/u-sku-wu/_doc/package.json +93 -0
- package/uview-plus/components/u-sku-wu/_doc/readme.md +16 -0
- package/uview-plus/components/u-sku-wu/props.js +86 -0
- package/uview-plus/components/u-sku-wu/style.css +271 -0
- package/uview-plus/components/u-sku-wu/u-sku-wu.vue +864 -0
- package/uview-plus/components/u-status-bar/_doc/changelog.md +4 -0
- package/uview-plus/components/u-status-bar/_doc/package.json +86 -0
- package/uview-plus/components/u-status-bar/_doc/readme.md +16 -0
- package/uview-plus/components/u-text/_doc/changelog.md +10 -0
- package/uview-plus/components/u-text/_doc/package.json +89 -0
- package/uview-plus/components/u-text/_doc/readme.md +20 -0
- package/uview-plus/components/u-textarea/_doc/changelog.md +6 -0
- package/uview-plus/components/u-textarea/_doc/package.json +86 -0
- package/uview-plus/components/u-textarea/_doc/readme.md +25 -0
- package/uview-plus/components/u-transition/_doc/changelog.md +14 -0
- package/uview-plus/components/u-transition/_doc/package.json +86 -0
- package/uview-plus/components/u-transition/_doc/readme.md +16 -0
- package/uview-plus/components/u-transition-wu/createAnimation.js +148 -0
- package/uview-plus/components/u-transition-wu/props.js +32 -0
- package/uview-plus/components/u-transition-wu/u-transition.vue +300 -0
- package/uview-plus/components/u-verification-code/u-verification-code.vue +161 -0
- package/uview-plus/index.js +107 -94
- package/uview-plus/libs/config/config.js +46 -48
- package/uview-plus/libs/css/color.scss +32 -311
- package/uview-plus/libs/css/components-wu.scss +30 -0
- package/uview-plus/libs/css/vue.scss +10 -10
- package/uview-plus/libs/function/calc.js +61 -55
- package/uview-plus/libs/function/cc.js +66 -0
- package/uview-plus/libs/function/color/color-convert/CHANGELOG.md +54 -0
- package/uview-plus/libs/function/color/color-convert/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-convert/README.md +68 -0
- package/uview-plus/libs/function/color/color-convert/conversions.js +839 -0
- package/uview-plus/libs/function/color/color-convert/index.js +81 -0
- package/uview-plus/libs/function/color/color-convert/package.json +48 -0
- package/uview-plus/libs/function/color/color-convert/route.js +97 -0
- package/uview-plus/libs/function/color/color-name/LICENSE +8 -0
- package/uview-plus/libs/function/color/color-name/README.md +11 -0
- package/uview-plus/libs/function/color/color-name/index.js +152 -0
- package/uview-plus/libs/function/color/color-name/package.json +28 -0
- package/uview-plus/libs/function/color/color-string/LICENSE +21 -0
- package/uview-plus/libs/function/color/color-string/README.md +62 -0
- package/uview-plus/libs/function/color/color-string/index.js +244 -0
- package/uview-plus/libs/function/color/color-string/package.json +39 -0
- package/uview-plus/libs/function/color/color.js +496 -0
- package/uview-plus/libs/function/color/index.js +158 -0
- package/uview-plus/libs/function/color/is-arrayish/LICENSE +21 -0
- package/uview-plus/libs/function/color/is-arrayish/README.md +16 -0
- package/uview-plus/libs/function/color/is-arrayish/index.js +9 -0
- package/uview-plus/libs/function/color/is-arrayish/package.json +45 -0
- package/uview-plus/libs/function/color/is-arrayish/yarn-error.log +1443 -0
- package/uview-plus/libs/function/color/simple-swizzle/LICENSE +21 -0
- package/uview-plus/libs/function/color/simple-swizzle/README.md +39 -0
- package/uview-plus/libs/function/color/simple-swizzle/index.js +29 -0
- package/uview-plus/libs/function/color/simple-swizzle/package.json +36 -0
- package/uview-plus/libs/function/colorGradient.js +108 -106
- package/uview-plus/libs/function/debounce.js +17 -17
- package/uview-plus/libs/function/digit.js +1 -3
- package/uview-plus/libs/function/http.js +3 -3
- package/uview-plus/libs/function/index-wu.js +231 -0
- package/uview-plus/libs/function/index.js +579 -566
- package/uview-plus/libs/function/platform.js +18 -18
- package/uview-plus/libs/function/test.js +135 -137
- package/uview-plus/libs/function/throttle.js +17 -17
- package/uview-plus/libs/luch-request/core/Request.js +199 -199
- package/uview-plus/libs/mixin/mpMixin.js +1 -0
- package/uview-plus/libs/mixin/openType.js +33 -0
- package/uview-plus/libs/util/async-validator.js +1343 -1343
- package/uview-plus/libs/util/dayjs.js +404 -0
- package/uview-plus/libs/util/route.js +101 -105
- package/uview-plus/package-wu-tool.json +84 -0
- package/uview-plus/package-wu.json +112 -0
- package/uview-plus/package.json +106 -95
- package/uview-plus/readme-wu.md +148 -0
- package/uview-ui/index.js +51 -52
- package/plugins/uni-upgrade.js +0 -294
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
array as testArray,
|
|
4
|
-
empty as testEmpty
|
|
5
|
-
} from './test'
|
|
6
|
-
import { round } from './digit.js'
|
|
1
|
+
import { number as testNumber, array as testArray, empty as testEmpty } from './test';
|
|
2
|
+
import { round } from './digit.js';
|
|
7
3
|
import config from '../config/config';
|
|
8
4
|
/**
|
|
9
5
|
* @description 如果value小于min,取min;如果value大于max,取max
|
|
10
|
-
* @param {number} min
|
|
11
|
-
* @param {number} max
|
|
6
|
+
* @param {number} min
|
|
7
|
+
* @param {number} max
|
|
12
8
|
* @param {number} value
|
|
13
9
|
*/
|
|
14
10
|
export function range(min = 0, max = 0, value = 0) {
|
|
15
|
-
|
|
11
|
+
return Math.max(min, Math.min(max, Number(value)));
|
|
16
12
|
}
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.rpx2px进行转换
|
|
20
16
|
* @param {number|string} value 用户传递值的px值
|
|
21
|
-
* @param {boolean} unit
|
|
17
|
+
* @param {boolean} unit
|
|
22
18
|
* @returns {number|string}
|
|
23
19
|
*/
|
|
24
20
|
export function getPx(value, unit = false) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
if (testNumber(value)) {
|
|
22
|
+
return unit ? `${value}px` : Number(value);
|
|
23
|
+
}
|
|
24
|
+
// 如果带有rpx,先取出其数值部分,再转为px值
|
|
25
|
+
if (/(rpx|upx)$/.test(value)) {
|
|
26
|
+
return unit ? `${uni.upx2px(parseInt(value))}px` : Number(uni.upx2px(parseInt(value)));
|
|
27
|
+
}
|
|
28
|
+
return unit ? `${parseInt(value)}px` : parseInt(value);
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
/**
|
|
@@ -38,51 +34,51 @@ export function getPx(value, unit = false) {
|
|
|
38
34
|
* @returns {Promise} 返回promise
|
|
39
35
|
*/
|
|
40
36
|
export function sleep(value = 30) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
resolve();
|
|
40
|
+
}, value);
|
|
41
|
+
});
|
|
46
42
|
}
|
|
47
43
|
/**
|
|
48
44
|
* @description 运行期判断平台
|
|
49
|
-
* @returns {string} 返回所在平台(小写)
|
|
45
|
+
* @returns {string} 返回所在平台(小写)
|
|
50
46
|
* @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
|
|
51
47
|
*/
|
|
52
48
|
export function os() {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
// #ifdef APP || H5 || MP-WEIXIN
|
|
50
|
+
return uni.getDeviceInfo().platform.toLowerCase();
|
|
51
|
+
// #endif
|
|
52
|
+
// #ifndef APP || H5 || MP-WEIXIN
|
|
53
|
+
return uni.getSystemInfoSync().platform.toLowerCase();
|
|
54
|
+
// #endif
|
|
59
55
|
}
|
|
60
56
|
/**
|
|
61
57
|
* @description 获取系统信息同步接口
|
|
62
|
-
* @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
|
|
58
|
+
* @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
|
|
63
59
|
*/
|
|
64
60
|
export function sys() {
|
|
65
|
-
|
|
61
|
+
return uni.getSystemInfoSync();
|
|
66
62
|
}
|
|
67
63
|
export function getWindowInfo() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
let ret = {};
|
|
65
|
+
// #ifdef APP || H5 || MP-WEIXIN
|
|
66
|
+
ret = uni.getWindowInfo();
|
|
67
|
+
// #endif
|
|
68
|
+
// #ifndef APP || H5 || MP-WEIXIN
|
|
69
|
+
ret = sys();
|
|
70
|
+
// #endif
|
|
71
|
+
return ret;
|
|
76
72
|
}
|
|
77
73
|
export function getDeviceInfo() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
74
|
+
let ret = {};
|
|
75
|
+
// #ifdef APP || H5 || MP-WEIXIN
|
|
76
|
+
ret = uni.getDeviceInfo();
|
|
77
|
+
// #endif
|
|
78
|
+
// #ifndef APP || H5 || MP-WEIXIN
|
|
79
|
+
ret = sys();
|
|
80
|
+
// #endif
|
|
81
|
+
return ret;
|
|
86
82
|
}
|
|
87
83
|
|
|
88
84
|
/**
|
|
@@ -91,11 +87,11 @@ export function getDeviceInfo() {
|
|
|
91
87
|
* @param {Number} max 最大值
|
|
92
88
|
*/
|
|
93
89
|
export function random(min, max) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
if (min >= 0 && max > 0 && max >= min) {
|
|
91
|
+
const gab = max - min + 1;
|
|
92
|
+
return Math.floor(Math.random() * gab + min);
|
|
93
|
+
}
|
|
94
|
+
return 0;
|
|
99
95
|
}
|
|
100
96
|
|
|
101
97
|
/**
|
|
@@ -104,32 +100,32 @@ export function random(min, max) {
|
|
|
104
100
|
* @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制
|
|
105
101
|
*/
|
|
106
102
|
export function guid(len = 32, firstU = true, radix = null) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
103
|
+
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
|
|
104
|
+
const uuid = [];
|
|
105
|
+
radix = radix || chars.length;
|
|
106
|
+
|
|
107
|
+
if (len) {
|
|
108
|
+
// 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位
|
|
109
|
+
for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
|
|
110
|
+
} else {
|
|
111
|
+
let r;
|
|
112
|
+
// rfc4122标准要求返回的uuid中,某些位为固定的字符
|
|
113
|
+
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
|
|
114
|
+
uuid[14] = '4';
|
|
115
|
+
|
|
116
|
+
for (let i = 0; i < 36; i++) {
|
|
117
|
+
if (!uuid[i]) {
|
|
118
|
+
r = 0 | (Math.random() * 16);
|
|
119
|
+
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class
|
|
124
|
+
if (firstU) {
|
|
125
|
+
uuid.shift();
|
|
126
|
+
return `u${uuid.join('')}`;
|
|
127
|
+
}
|
|
128
|
+
return uuid.join('');
|
|
133
129
|
}
|
|
134
130
|
|
|
135
131
|
/**
|
|
@@ -140,19 +136,19 @@ export function guid(len = 32, firstU = true, radix = null) {
|
|
|
140
136
|
* @param {string|undefined} name 父组件的参数名
|
|
141
137
|
*/
|
|
142
138
|
export function $parent(name = undefined) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
let parent = this.$parent;
|
|
140
|
+
// 通过while历遍,这里主要是为了H5需要多层解析的问题
|
|
141
|
+
while (parent) {
|
|
142
|
+
// 父组件
|
|
143
|
+
name = name.replace(/up-([a-zA-Z0-9-_]+)/g, 'u-$1');
|
|
144
|
+
if (parent.$options && parent.$options.name !== name) {
|
|
145
|
+
// 如果组件的name不相等,继续上一级寻找
|
|
146
|
+
parent = parent.$parent;
|
|
147
|
+
} else {
|
|
148
|
+
return parent;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return false;
|
|
156
152
|
}
|
|
157
153
|
|
|
158
154
|
/**
|
|
@@ -163,39 +159,42 @@ export function $parent(name = undefined) {
|
|
|
163
159
|
* @returns {object|string}
|
|
164
160
|
*/
|
|
165
161
|
export function addStyle(customStyle, target = 'object') {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
162
|
+
// 字符串转字符串,对象转对象情形,直接返回
|
|
163
|
+
if (
|
|
164
|
+
testEmpty(customStyle) ||
|
|
165
|
+
(typeof customStyle === 'object' && target === 'object') ||
|
|
166
|
+
(target === 'string' && typeof customStyle === 'string')
|
|
167
|
+
) {
|
|
168
|
+
return customStyle;
|
|
169
|
+
}
|
|
170
|
+
// 字符串转对象
|
|
171
|
+
if (target === 'object') {
|
|
172
|
+
// 去除字符串样式中的两端空格(中间的空格不能去掉,比如padding: 20px 0如果去掉了就错了),空格是无用的
|
|
173
|
+
customStyle = trim(customStyle);
|
|
174
|
+
// 根据";"将字符串转为数组形式
|
|
175
|
+
const styleArray = customStyle.split(';');
|
|
176
|
+
const style = {};
|
|
177
|
+
// 历遍数组,拼接成对象
|
|
178
|
+
for (let i = 0; i < styleArray.length; i++) {
|
|
179
|
+
// 'font-size:20px;color:red;',如此最后字符串有";"的话,会导致styleArray最后一个元素为空字符串,这里需要过滤
|
|
180
|
+
if (styleArray[i]) {
|
|
181
|
+
const item = styleArray[i].split(':');
|
|
182
|
+
style[trim(item[0])] = trim(item[1]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return style;
|
|
186
|
+
}
|
|
187
|
+
// 这里为对象转字符串形式
|
|
188
|
+
let string = '';
|
|
189
|
+
if (typeof customStyle === 'object') {
|
|
190
|
+
customStyle.forEach((val, i) => {
|
|
191
|
+
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
|
|
192
|
+
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
193
|
+
string += `${key}:${val};`;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// 去除两端空格
|
|
197
|
+
return trim(string);
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
/**
|
|
@@ -204,15 +203,15 @@ export function addStyle(customStyle, target = 'object') {
|
|
|
204
203
|
* @param {string} unit 添加的单位名 比如px
|
|
205
204
|
*/
|
|
206
205
|
export function addUnit(value = 'auto', unit = '') {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
206
|
+
if (!unit) {
|
|
207
|
+
unit = config.unit || 'px';
|
|
208
|
+
}
|
|
209
|
+
if (unit == 'rpx' && testNumber(String(value))) {
|
|
210
|
+
value = value * 2;
|
|
211
|
+
}
|
|
212
|
+
value = String(value);
|
|
213
|
+
// 用内置验证规则中的number判断是否为数值
|
|
214
|
+
return testNumber(value) ? `${value}${unit}` : value;
|
|
216
215
|
}
|
|
217
216
|
|
|
218
217
|
/**
|
|
@@ -221,19 +220,19 @@ export function addUnit(value = 'auto', unit = '') {
|
|
|
221
220
|
* @returns {*} 克隆后的对象或者原值(不是对象)
|
|
222
221
|
*/
|
|
223
222
|
export function deepClone(obj) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
223
|
+
// 对常见的“非”值,直接返回原来值
|
|
224
|
+
if ([null, undefined, NaN, false].includes(obj)) return obj;
|
|
225
|
+
if (typeof obj !== 'object' && typeof obj !== 'function') {
|
|
226
|
+
// 原始类型直接返回
|
|
227
|
+
return obj;
|
|
228
|
+
}
|
|
229
|
+
const o = testArray(obj) ? [] : {};
|
|
230
|
+
for (const i in obj) {
|
|
231
|
+
if (obj.hasOwnProperty(i)) {
|
|
232
|
+
o[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return o;
|
|
237
236
|
}
|
|
238
237
|
|
|
239
238
|
/**
|
|
@@ -243,27 +242,27 @@ export function deepClone(obj) {
|
|
|
243
242
|
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
|
244
243
|
*/
|
|
245
244
|
export function deepMerge(targetOrigin = {}, source = {}) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
245
|
+
let target = deepClone(targetOrigin);
|
|
246
|
+
if (typeof target !== 'object' || typeof source !== 'object') return false;
|
|
247
|
+
for (const prop in source) {
|
|
248
|
+
if (!source.hasOwnProperty(prop)) continue;
|
|
249
|
+
if (prop in target) {
|
|
250
|
+
if (source[prop] == null) {
|
|
251
|
+
target[prop] = source[prop];
|
|
252
|
+
} else if (typeof target[prop] !== 'object') {
|
|
253
|
+
target[prop] = source[prop];
|
|
254
|
+
} else if (typeof source[prop] !== 'object') {
|
|
255
|
+
target[prop] = source[prop];
|
|
256
|
+
} else if (target[prop].concat && source[prop].concat) {
|
|
257
|
+
target[prop] = target[prop].concat(source[prop]);
|
|
258
|
+
} else {
|
|
259
|
+
target[prop] = deepMerge(target[prop], source[prop]);
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
target[prop] = source[prop];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return target;
|
|
267
266
|
}
|
|
268
267
|
/**
|
|
269
268
|
* @description JS对象深度合并
|
|
@@ -272,26 +271,26 @@ export function deepMerge(targetOrigin = {}, source = {}) {
|
|
|
272
271
|
* @returns {object|boolean} 深度合并后的对象或者false(入参有不是对象)
|
|
273
272
|
*/
|
|
274
273
|
export function shallowMerge(target, source = {}) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
274
|
+
if (typeof target !== 'object' || typeof source !== 'object') return false;
|
|
275
|
+
for (const prop in source) {
|
|
276
|
+
if (!source.hasOwnProperty(prop)) continue;
|
|
277
|
+
if (prop in target) {
|
|
278
|
+
if (source[prop] == null) {
|
|
279
|
+
target[prop] = source[prop];
|
|
280
|
+
} else if (typeof target[prop] !== 'object') {
|
|
281
|
+
target[prop] = source[prop];
|
|
282
|
+
} else if (typeof source[prop] !== 'object') {
|
|
283
|
+
target[prop] = source[prop];
|
|
284
|
+
} else if (target[prop].concat && source[prop].concat) {
|
|
285
|
+
target[prop] = target[prop].concat(source[prop]);
|
|
286
|
+
} else {
|
|
287
|
+
target[prop] = shallowMerge(target[prop], source[prop]);
|
|
288
|
+
}
|
|
289
|
+
} else {
|
|
290
|
+
target[prop] = source[prop];
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return target;
|
|
295
294
|
}
|
|
296
295
|
|
|
297
296
|
/**
|
|
@@ -299,10 +298,10 @@ export function shallowMerge(target, source = {}) {
|
|
|
299
298
|
* @param {*} err 错误内容
|
|
300
299
|
*/
|
|
301
300
|
export function error(err) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
301
|
+
// 开发环境才提示,生产环境不会提示
|
|
302
|
+
if (process.env.NODE_ENV === 'development') {
|
|
303
|
+
console.error(`uView提示:${err}`);
|
|
304
|
+
}
|
|
306
305
|
}
|
|
307
306
|
|
|
308
307
|
/**
|
|
@@ -311,34 +310,32 @@ export function error(err) {
|
|
|
311
310
|
* @returns {array} 打乱后的数组
|
|
312
311
|
*/
|
|
313
312
|
export function randomArray(array = []) {
|
|
314
|
-
|
|
315
|
-
|
|
313
|
+
// 原理是sort排序,Math.random()产生0<= x < 1之间的数,会导致x-0.05大于或者小于0
|
|
314
|
+
return array.sort(() => Math.random() - 0.5);
|
|
316
315
|
}
|
|
317
316
|
|
|
318
317
|
// padStart 的 polyfill,因为某些机型或情况,还无法支持es7的padStart,比如电脑版的微信小程序
|
|
319
318
|
// 所以这里做一个兼容polyfill的兼容处理
|
|
320
319
|
if (!String.prototype.padStart) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
return fillString.slice(0, fillLength) + str
|
|
341
|
-
}
|
|
320
|
+
// 为了方便表示这里 fillString 用了ES6 的默认参数,不影响理解
|
|
321
|
+
String.prototype.padStart = function (maxLength, fillString = ' ') {
|
|
322
|
+
if (Object.prototype.toString.call(fillString) !== '[object String]') {
|
|
323
|
+
throw new TypeError('fillString must be String');
|
|
324
|
+
}
|
|
325
|
+
const str = this;
|
|
326
|
+
// 返回 String(str) 这里是为了使返回的值是字符串字面量,在控制台中更符合直觉
|
|
327
|
+
if (str.length >= maxLength) return String(str);
|
|
328
|
+
|
|
329
|
+
const fillLength = maxLength - str.length;
|
|
330
|
+
let times = Math.ceil(fillLength / fillString.length);
|
|
331
|
+
while ((times >>= 1)) {
|
|
332
|
+
fillString += fillString;
|
|
333
|
+
if (times === 1) {
|
|
334
|
+
fillString += fillString;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return fillString.slice(0, fillLength) + str;
|
|
338
|
+
};
|
|
342
339
|
}
|
|
343
340
|
|
|
344
341
|
/**
|
|
@@ -348,94 +345,90 @@ if (!String.prototype.padStart) {
|
|
|
348
345
|
* @returns {string} 返回格式化后的字符串
|
|
349
346
|
*/
|
|
350
347
|
export function timeFormat(dateTime = null, formatStr = 'yyyy-mm-dd') {
|
|
351
|
-
let date
|
|
352
|
-
|
|
348
|
+
let date;
|
|
349
|
+
// 若传入时间为假值,则取当前时间
|
|
353
350
|
if (!dateTime) {
|
|
354
|
-
date = new Date()
|
|
351
|
+
date = new Date();
|
|
355
352
|
}
|
|
356
353
|
// 若为unix秒时间戳,则转为毫秒时间戳(逻辑有点奇怪,但不敢改,以保证历史兼容)
|
|
357
354
|
else if (/^\d{10}$/.test(dateTime.toString().trim())) {
|
|
358
|
-
date = new Date(dateTime * 1000)
|
|
355
|
+
date = new Date(dateTime * 1000);
|
|
359
356
|
}
|
|
360
357
|
// 若用户传入字符串格式时间戳,new Date无法解析,需做兼容
|
|
361
358
|
else if (typeof dateTime === 'string' && /^\d+$/.test(dateTime.trim())) {
|
|
362
|
-
date = new Date(Number(dateTime))
|
|
359
|
+
date = new Date(Number(dateTime));
|
|
363
360
|
}
|
|
364
361
|
// 其他都认为符合 RFC 2822 规范
|
|
365
362
|
else {
|
|
366
363
|
// 处理平台性差异,在Safari/Webkit中,new Date仅支持/作为分割符的字符串时间
|
|
367
|
-
date = new Date(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
)
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
'M': date.getMinutes().toString().padStart(2, '0'), // 分
|
|
380
|
-
's': date.getSeconds().toString().padStart(2, '0') // 秒
|
|
381
|
-
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
|
382
|
-
}
|
|
364
|
+
date = new Date(typeof dateTime === 'string' ? dateTime.replace(/-/g, '/') : dateTime);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const timeSource = {
|
|
368
|
+
y: date.getFullYear().toString(), // 年
|
|
369
|
+
m: (date.getMonth() + 1).toString().padStart(2, '0'), // 月
|
|
370
|
+
d: date.getDate().toString().padStart(2, '0'), // 日
|
|
371
|
+
h: date.getHours().toString().padStart(2, '0'), // 时
|
|
372
|
+
M: date.getMinutes().toString().padStart(2, '0'), // 分
|
|
373
|
+
s: date.getSeconds().toString().padStart(2, '0') // 秒
|
|
374
|
+
// 有其他格式化字符需求可以继续添加,必须转化成字符串
|
|
375
|
+
};
|
|
383
376
|
|
|
384
377
|
for (const key in timeSource) {
|
|
385
|
-
const [ret] = new RegExp(`${key}+`).exec(formatStr) || []
|
|
378
|
+
const [ret] = new RegExp(`${key}+`).exec(formatStr) || [];
|
|
386
379
|
if (ret) {
|
|
387
380
|
// 年可能只需展示两位
|
|
388
|
-
const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0
|
|
389
|
-
formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex))
|
|
381
|
+
const beginIndex = key === 'y' && ret.length === 2 ? 2 : 0;
|
|
382
|
+
formatStr = formatStr.replace(ret, timeSource[key].slice(beginIndex));
|
|
390
383
|
}
|
|
391
384
|
}
|
|
392
385
|
|
|
393
|
-
return formatStr
|
|
386
|
+
return formatStr;
|
|
394
387
|
}
|
|
395
388
|
|
|
396
389
|
/**
|
|
397
390
|
* @description 时间戳转为多久之前
|
|
398
391
|
* @param {String|Number} timestamp 时间戳
|
|
399
|
-
* @param {String|Boolean} format
|
|
392
|
+
* @param {String|Boolean} format
|
|
400
393
|
* 格式化规则如果为时间格式字符串,超出一定时间范围,返回固定的时间格式;
|
|
401
394
|
* 如果为布尔值false,无论什么时间,都返回多久以前的格式
|
|
402
395
|
* @returns {string} 转化后的内容
|
|
403
396
|
*/
|
|
404
397
|
export function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
398
|
+
if (timestamp == null) timestamp = Number(new Date());
|
|
399
|
+
timestamp = parseInt(timestamp);
|
|
400
|
+
// 判断用户输入的时间戳是秒还是毫秒,一般前端js获取的时间戳是毫秒(13位),后端传过来的为秒(10位)
|
|
401
|
+
if (timestamp.toString().length == 10) timestamp *= 1000;
|
|
402
|
+
let timer = new Date().getTime() - timestamp;
|
|
403
|
+
timer = parseInt(timer / 1000);
|
|
404
|
+
// 如果小于5分钟,则返回"刚刚",其他以此类推
|
|
405
|
+
let tips = '';
|
|
406
|
+
switch (true) {
|
|
407
|
+
case timer < 300:
|
|
408
|
+
tips = '刚刚';
|
|
409
|
+
break;
|
|
410
|
+
case timer >= 300 && timer < 3600:
|
|
411
|
+
tips = `${parseInt(timer / 60)}分钟前`;
|
|
412
|
+
break;
|
|
413
|
+
case timer >= 3600 && timer < 86400:
|
|
414
|
+
tips = `${parseInt(timer / 3600)}小时前`;
|
|
415
|
+
break;
|
|
416
|
+
case timer >= 86400 && timer < 2592000:
|
|
417
|
+
tips = `${parseInt(timer / 86400)}天前`;
|
|
418
|
+
break;
|
|
419
|
+
default:
|
|
420
|
+
// 如果format为false,则无论什么时间戳,都显示xx之前
|
|
421
|
+
if (format === false) {
|
|
422
|
+
if (timer >= 2592000 && timer < 365 * 86400) {
|
|
423
|
+
tips = `${parseInt(timer / (86400 * 30))}个月前`;
|
|
424
|
+
} else {
|
|
425
|
+
tips = `${parseInt(timer / (86400 * 365))}年前`;
|
|
426
|
+
}
|
|
427
|
+
} else {
|
|
428
|
+
tips = timeFormat(timestamp, format);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return tips;
|
|
439
432
|
}
|
|
440
433
|
|
|
441
434
|
/**
|
|
@@ -444,20 +437,20 @@ export function timeFrom(timestamp = null, format = 'yyyy-mm-dd') {
|
|
|
444
437
|
* @param String pos both(左右)|left|right|all 默认both
|
|
445
438
|
*/
|
|
446
439
|
export function trim(str, pos = 'both') {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
440
|
+
str = String(str);
|
|
441
|
+
if (pos == 'both') {
|
|
442
|
+
return str.replace(/^\s+|\s+$/g, '');
|
|
443
|
+
}
|
|
444
|
+
if (pos == 'left') {
|
|
445
|
+
return str.replace(/^\s*/, '');
|
|
446
|
+
}
|
|
447
|
+
if (pos == 'right') {
|
|
448
|
+
return str.replace(/(\s*$)/g, '');
|
|
449
|
+
}
|
|
450
|
+
if (pos == 'all') {
|
|
451
|
+
return str.replace(/\s+/g, '');
|
|
452
|
+
}
|
|
453
|
+
return str;
|
|
461
454
|
}
|
|
462
455
|
|
|
463
456
|
/**
|
|
@@ -467,55 +460,55 @@ export function trim(str, pos = 'both') {
|
|
|
467
460
|
* @param {string} arrayFormat 规则 indices|brackets|repeat|comma
|
|
468
461
|
*/
|
|
469
462
|
export function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets') {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
463
|
+
const prefix = isPrefix ? '?' : '';
|
|
464
|
+
const _result = [];
|
|
465
|
+
if (['indices', 'brackets', 'repeat', 'comma'].indexOf(arrayFormat) == -1) arrayFormat = 'brackets';
|
|
466
|
+
for (const key in data) {
|
|
467
|
+
const value = data[key];
|
|
468
|
+
// 去掉为空的参数
|
|
469
|
+
if (['', undefined, null].indexOf(value) >= 0) {
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
// 如果值为数组,另行处理
|
|
473
|
+
if (value.constructor === Array) {
|
|
474
|
+
// e.g. {ids: [1, 2, 3]}
|
|
475
|
+
switch (arrayFormat) {
|
|
476
|
+
case 'indices':
|
|
477
|
+
// 结果: ids[0]=1&ids[1]=2&ids[2]=3
|
|
478
|
+
for (let i = 0; i < value.length; i++) {
|
|
479
|
+
_result.push(`${key}[${i}]=${value[i]}`);
|
|
480
|
+
}
|
|
481
|
+
break;
|
|
482
|
+
case 'brackets':
|
|
483
|
+
// 结果: ids[]=1&ids[]=2&ids[]=3
|
|
484
|
+
value.forEach((_value) => {
|
|
485
|
+
_result.push(`${key}[]=${_value}`);
|
|
486
|
+
});
|
|
487
|
+
break;
|
|
488
|
+
case 'repeat':
|
|
489
|
+
// 结果: ids=1&ids=2&ids=3
|
|
490
|
+
value.forEach((_value) => {
|
|
491
|
+
_result.push(`${key}=${_value}`);
|
|
492
|
+
});
|
|
493
|
+
break;
|
|
494
|
+
case 'comma':
|
|
495
|
+
// 结果: ids=1,2,3
|
|
496
|
+
let commaStr = '';
|
|
497
|
+
value.forEach((_value) => {
|
|
498
|
+
commaStr += (commaStr ? ',' : '') + _value;
|
|
499
|
+
});
|
|
500
|
+
_result.push(`${key}=${commaStr}`);
|
|
501
|
+
break;
|
|
502
|
+
default:
|
|
503
|
+
value.forEach((_value) => {
|
|
504
|
+
_result.push(`${key}[]=${_value}`);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
} else {
|
|
508
|
+
_result.push(`${key}=${value}`);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
return _result.length ? prefix + _result.join('&') : '';
|
|
519
512
|
}
|
|
520
513
|
|
|
521
514
|
/**
|
|
@@ -524,11 +517,11 @@ export function queryParams(data = {}, isPrefix = true, arrayFormat = 'brackets'
|
|
|
524
517
|
* @param {Number} duration 提示的延迟时间,单位毫秒,默认:2000
|
|
525
518
|
*/
|
|
526
519
|
export function toast(title, duration = 2000) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
520
|
+
uni.showToast({
|
|
521
|
+
title: String(title),
|
|
522
|
+
icon: 'none',
|
|
523
|
+
duration
|
|
524
|
+
});
|
|
532
525
|
}
|
|
533
526
|
|
|
534
527
|
/**
|
|
@@ -537,32 +530,32 @@ export function toast(title, duration = 2000) {
|
|
|
537
530
|
* @param {boolean} fill 是否使用fill填充实体的图标
|
|
538
531
|
*/
|
|
539
532
|
export function type2icon(type = 'success', fill = false) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
533
|
+
// 如果非预置值,默认为success
|
|
534
|
+
if (['primary', 'info', 'error', 'warning', 'success'].indexOf(type) == -1) type = 'success';
|
|
535
|
+
let iconName = '';
|
|
536
|
+
// 目前(2019-12-12),info和primary使用同一个图标
|
|
537
|
+
switch (type) {
|
|
538
|
+
case 'primary':
|
|
539
|
+
iconName = 'info-circle';
|
|
540
|
+
break;
|
|
541
|
+
case 'info':
|
|
542
|
+
iconName = 'info-circle';
|
|
543
|
+
break;
|
|
544
|
+
case 'error':
|
|
545
|
+
iconName = 'close-circle';
|
|
546
|
+
break;
|
|
547
|
+
case 'warning':
|
|
548
|
+
iconName = 'error-circle';
|
|
549
|
+
break;
|
|
550
|
+
case 'success':
|
|
551
|
+
iconName = 'checkmark-circle';
|
|
552
|
+
break;
|
|
553
|
+
default:
|
|
554
|
+
iconName = 'checkmark-circle';
|
|
555
|
+
}
|
|
556
|
+
// 是否是实体类型,加上-fill,在icon组件库中,实体的类名是后面加-fill的
|
|
557
|
+
if (fill) iconName += '-fill';
|
|
558
|
+
return iconName;
|
|
566
559
|
}
|
|
567
560
|
|
|
568
561
|
/**
|
|
@@ -574,24 +567,24 @@ export function type2icon(type = 'success', fill = false) {
|
|
|
574
567
|
* @returns {string} 格式化后的数字
|
|
575
568
|
*/
|
|
576
569
|
export function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsSeparator = ',') {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
570
|
+
number = `${number}`.replace(/[^0-9+-Ee.]/g, '');
|
|
571
|
+
const n = !isFinite(+number) ? 0 : +number;
|
|
572
|
+
const prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
|
|
573
|
+
const sep = typeof thousandsSeparator === 'undefined' ? ',' : thousandsSeparator;
|
|
574
|
+
const dec = typeof decimalPoint === 'undefined' ? '.' : decimalPoint;
|
|
575
|
+
let s = '';
|
|
576
|
+
|
|
577
|
+
s = (prec ? round(n, prec) + '' : `${Math.round(n)}`).split('.');
|
|
578
|
+
const re = /(-?\d+)(\d{3})/;
|
|
579
|
+
while (re.test(s[0])) {
|
|
580
|
+
s[0] = s[0].replace(re, `$1${sep}$2`);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
if ((s[1] || '').length < prec) {
|
|
584
|
+
s[1] = s[1] || '';
|
|
585
|
+
s[1] += new Array(prec - s[1].length + 1).join('0');
|
|
586
|
+
}
|
|
587
|
+
return s.join(dec);
|
|
595
588
|
}
|
|
596
589
|
|
|
597
590
|
/**
|
|
@@ -600,17 +593,17 @@ export function priceFormat(number, decimals = 0, decimalPoint = '.', thousandsS
|
|
|
600
593
|
* 比如以30位阈值,那么300大于30,可以理解为用户想要的是300ms,而不是想花300s去执行一个动画
|
|
601
594
|
* @param {String|number} value 比如: "1s"|"100ms"|1|100
|
|
602
595
|
* @param {boolean} unit 提示: 如果是false 默认返回number
|
|
603
|
-
* @return {string|number}
|
|
596
|
+
* @return {string|number}
|
|
604
597
|
*/
|
|
605
598
|
export function getDuration(value, unit = true) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
599
|
+
const valueNum = parseInt(value);
|
|
600
|
+
if (unit) {
|
|
601
|
+
if (/s$/.test(value)) return value;
|
|
602
|
+
return value > 30 ? `${value}ms` : `${value}s`;
|
|
603
|
+
}
|
|
604
|
+
if (/ms$/.test(value)) return valueNum;
|
|
605
|
+
if (/s$/.test(value)) return valueNum > 30 ? valueNum : valueNum * 1000;
|
|
606
|
+
return valueNum;
|
|
614
607
|
}
|
|
615
608
|
|
|
616
609
|
/**
|
|
@@ -618,7 +611,7 @@ export function getDuration(value, unit = true) {
|
|
|
618
611
|
* @param {String} value 需要补零的值
|
|
619
612
|
*/
|
|
620
613
|
export function padZero(value) {
|
|
621
|
-
|
|
614
|
+
return `00${value}`.slice(-2);
|
|
622
615
|
}
|
|
623
616
|
|
|
624
617
|
/**
|
|
@@ -627,13 +620,13 @@ export function padZero(value) {
|
|
|
627
620
|
* @param {*} event
|
|
628
621
|
*/
|
|
629
622
|
export function formValidate(instance, event) {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
623
|
+
const formItem = $parent.call(instance, 'u-form-item');
|
|
624
|
+
const form = $parent.call(instance, 'u-form');
|
|
625
|
+
// 如果发生变化的input或者textarea等,其父组件中有u-form-item或者u-form等,就执行form的validate方法
|
|
626
|
+
// 同时将form-item的pros传递给form,让其进行精确对象验证
|
|
627
|
+
if (formItem && form) {
|
|
628
|
+
form.validateField(formItem.prop, () => {}, event);
|
|
629
|
+
}
|
|
637
630
|
}
|
|
638
631
|
|
|
639
632
|
/**
|
|
@@ -643,24 +636,24 @@ export function formValidate(instance, event) {
|
|
|
643
636
|
* @returns {*}
|
|
644
637
|
*/
|
|
645
638
|
export function getProperty(obj, key) {
|
|
646
|
-
|
|
647
|
-
|
|
639
|
+
if (typeof obj !== 'object' || null == obj) {
|
|
640
|
+
return '';
|
|
641
|
+
}
|
|
642
|
+
if (typeof key !== 'string' || key === '') {
|
|
643
|
+
return '';
|
|
644
|
+
}
|
|
645
|
+
if (key.indexOf('.') !== -1) {
|
|
646
|
+
const keys = key.split('.');
|
|
647
|
+
let firstObj = obj[keys[0]] || {};
|
|
648
|
+
|
|
649
|
+
for (let i = 1; i < keys.length; i++) {
|
|
650
|
+
if (firstObj) {
|
|
651
|
+
firstObj = firstObj[keys[i]];
|
|
652
|
+
}
|
|
648
653
|
}
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
if (key.indexOf('.') !== -1) {
|
|
653
|
-
const keys = key.split('.')
|
|
654
|
-
let firstObj = obj[keys[0]] || {}
|
|
655
|
-
|
|
656
|
-
for (let i = 1; i < keys.length; i++) {
|
|
657
|
-
if (firstObj) {
|
|
658
|
-
firstObj = firstObj[keys[i]]
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
return firstObj
|
|
662
|
-
}
|
|
663
|
-
return obj[key]
|
|
654
|
+
return firstObj;
|
|
655
|
+
}
|
|
656
|
+
return obj[key];
|
|
664
657
|
}
|
|
665
658
|
|
|
666
659
|
/**
|
|
@@ -670,64 +663,68 @@ export function getProperty(obj, key) {
|
|
|
670
663
|
* @param {string} value 设置的值
|
|
671
664
|
*/
|
|
672
665
|
export function setProperty(obj, key, value) {
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
666
|
+
if (typeof obj !== 'object' || null == obj) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
// 递归赋值
|
|
670
|
+
const inFn = function (_obj, keys, v) {
|
|
671
|
+
// 最后一个属性key
|
|
672
|
+
if (keys.length === 1) {
|
|
673
|
+
_obj[keys[0]] = v;
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
// 0~length-1个key
|
|
677
|
+
while (keys.length > 1) {
|
|
678
|
+
const k = keys[0];
|
|
679
|
+
if (!_obj[k] || typeof _obj[k] !== 'object') {
|
|
680
|
+
_obj[k] = {};
|
|
681
|
+
}
|
|
682
|
+
const key = keys.shift();
|
|
683
|
+
// 自调用判断是否存在属性,不存在则自动创建对象
|
|
684
|
+
inFn(_obj[k], keys, v);
|
|
685
|
+
}
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
if (typeof key !== 'string' || key === '') {
|
|
689
|
+
} else if (key.indexOf('.') !== -1) {
|
|
690
|
+
// 支持多层级赋值操作
|
|
691
|
+
const keys = key.split('.');
|
|
692
|
+
inFn(obj, keys, value);
|
|
693
|
+
} else {
|
|
694
|
+
obj[key] = value;
|
|
695
|
+
}
|
|
703
696
|
}
|
|
704
697
|
|
|
705
698
|
/**
|
|
706
699
|
* @description 获取当前页面路径
|
|
707
700
|
*/
|
|
708
701
|
export function page() {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
702
|
+
const pages = getCurrentPages();
|
|
703
|
+
// 某些特殊情况下(比如页面进行redirectTo时的一些时机),pages可能为空数组
|
|
704
|
+
return `/${pages[pages.length - 1].route || ''}`;
|
|
705
|
+
|
|
706
|
+
//const route = pages[pages.length - 1]?.route;
|
|
707
|
+
// 某些特殊情况下(比如页面进行redirectTo时的一些时机),pages可能为空数组
|
|
708
|
+
//return `/${route ? route : ''}`;
|
|
712
709
|
}
|
|
713
710
|
|
|
714
711
|
/**
|
|
715
712
|
* @description 获取当前路由栈实例数组
|
|
716
713
|
*/
|
|
717
714
|
export function pages() {
|
|
718
|
-
|
|
719
|
-
|
|
715
|
+
const pages = getCurrentPages();
|
|
716
|
+
return pages;
|
|
720
717
|
}
|
|
721
718
|
|
|
722
719
|
export function getValueByPath(obj, path) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
720
|
+
// 将路径字符串按 '.' 分割成数组
|
|
721
|
+
const pathArr = path.split('.');
|
|
722
|
+
// 使用 reduce 方法从 obj 开始,逐级访问嵌套属性
|
|
723
|
+
return pathArr.reduce((acc, curr) => {
|
|
724
|
+
// 如果当前累加器(acc)是对象且包含当前键(curr),则返回该键对应的值
|
|
725
|
+
// 否则返回 undefined(表示路径不存在)
|
|
726
|
+
return acc && acc[curr] !== undefined ? acc[curr] : undefined;
|
|
727
|
+
}, obj);
|
|
731
728
|
}
|
|
732
729
|
|
|
733
730
|
/**
|
|
@@ -737,117 +734,133 @@ export function getValueByPath(obj, path) {
|
|
|
737
734
|
* @returns {string} 十六进制颜色值
|
|
738
735
|
*/
|
|
739
736
|
export function genLightColor(textColor, lightness = 95) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
737
|
+
// 手动解析颜色值(避免使用document)
|
|
738
|
+
const rgb = parseColorWithoutDOM(textColor);
|
|
739
|
+
|
|
740
|
+
// RGB转HSL色域
|
|
741
|
+
const hsl = rgbToHsl(rgb.r, rgb.g, rgb.b);
|
|
742
|
+
|
|
743
|
+
// 生成浅色背景
|
|
744
|
+
const bgHsl = {
|
|
745
|
+
h: hsl.h,
|
|
746
|
+
s: hsl.s,
|
|
747
|
+
l: Math.min(lightness, 95)
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
return hslToHex(bgHsl.h, bgHsl.s, bgHsl.l);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/* 手动解析颜色字符串(兼容uni-app环境) */
|
|
754
|
+
function parseColorWithoutDOM(colorStr) {
|
|
755
|
+
// 统一转小写处理
|
|
756
|
+
const str = colorStr.toLowerCase().trim();
|
|
757
|
+
|
|
758
|
+
// 处理十六进制格式
|
|
759
|
+
if (str.startsWith('#')) {
|
|
760
|
+
const hex = str.replace('#', '');
|
|
761
|
+
const fullHex =
|
|
762
|
+
hex.length === 3
|
|
763
|
+
? hex
|
|
764
|
+
.split('')
|
|
765
|
+
.map((c) => c + c)
|
|
766
|
+
.join('')
|
|
767
|
+
: hex;
|
|
768
|
+
|
|
769
|
+
return {
|
|
770
|
+
r: parseInt(fullHex.substring(0, 2), 16),
|
|
771
|
+
g: parseInt(fullHex.substring(2, 4), 16),
|
|
772
|
+
b: parseInt(fullHex.substring(4, 6), 16)
|
|
773
|
+
};
|
|
754
774
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
const fullHex = hex.length === 3 ?
|
|
765
|
-
hex.split('').map(c => c + c).join('') : hex;
|
|
766
|
-
|
|
767
|
-
return {
|
|
768
|
-
r: parseInt(fullHex.substring(0,2), 16),
|
|
769
|
-
g: parseInt(fullHex.substring(2,4), 16),
|
|
770
|
-
b: parseInt(fullHex.substring(4,6), 16)
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// 处理rgb/rgba格式
|
|
775
|
-
const rgbMatch = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
776
|
-
if (rgbMatch) {
|
|
777
|
-
return {
|
|
778
|
-
r: +rgbMatch[1],
|
|
779
|
-
g: +rgbMatch[2],
|
|
780
|
-
b: +rgbMatch[3]
|
|
781
|
-
};
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
throw new Error('Invalid color format');
|
|
775
|
+
|
|
776
|
+
// 处理rgb/rgba格式
|
|
777
|
+
const rgbMatch = str.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
778
|
+
if (rgbMatch) {
|
|
779
|
+
return {
|
|
780
|
+
r: +rgbMatch[1],
|
|
781
|
+
g: +rgbMatch[2],
|
|
782
|
+
b: +rgbMatch[3]
|
|
783
|
+
};
|
|
785
784
|
}
|
|
786
785
|
|
|
786
|
+
throw new Error('Invalid color format');
|
|
787
|
+
}
|
|
788
|
+
|
|
787
789
|
// 辅助函数:RGB 转 HSL(色相、饱和度、亮度)
|
|
788
790
|
function rgbToHsl(r, g, b) {
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
791
|
+
(r /= 255), (g /= 255), (b /= 255);
|
|
792
|
+
const max = Math.max(r, g, b),
|
|
793
|
+
min = Math.min(r, g, b);
|
|
794
|
+
let h,
|
|
795
|
+
s,
|
|
796
|
+
l = (max + min) / 2;
|
|
797
|
+
|
|
798
|
+
if (max === min) {
|
|
799
|
+
h = s = 0; // achromatic
|
|
800
|
+
} else {
|
|
801
|
+
const d = max - min;
|
|
802
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
803
|
+
switch (max) {
|
|
804
|
+
case r:
|
|
805
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
806
|
+
break;
|
|
807
|
+
case g:
|
|
808
|
+
h = (b - r) / d + 2;
|
|
809
|
+
break;
|
|
810
|
+
case b:
|
|
811
|
+
h = (r - g) / d + 4;
|
|
812
|
+
break;
|
|
813
|
+
}
|
|
814
|
+
h = (h * 60).toFixed(1);
|
|
815
|
+
}
|
|
816
|
+
return { h: +h, s: +(s * 100).toFixed(1), l: +(l * 100).toFixed(1) };
|
|
806
817
|
}
|
|
807
818
|
|
|
808
819
|
// 辅助函数:HSL 转十六进制
|
|
809
820
|
function hslToHex(h, s, l) {
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
821
|
+
l /= 100;
|
|
822
|
+
const a = (s * Math.min(l, 1 - l)) / 100;
|
|
823
|
+
const f = (n) => {
|
|
824
|
+
const k = (n + h / 30) % 12;
|
|
825
|
+
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
826
|
+
return Math.round(255 * color)
|
|
827
|
+
.toString(16)
|
|
828
|
+
.padStart(2, '0');
|
|
829
|
+
};
|
|
830
|
+
return `#${f(0)}${f(8)}${f(4)}`;
|
|
818
831
|
}
|
|
819
832
|
|
|
820
833
|
export default {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
}
|
|
834
|
+
range,
|
|
835
|
+
getPx,
|
|
836
|
+
sleep,
|
|
837
|
+
os,
|
|
838
|
+
sys,
|
|
839
|
+
getWindowInfo,
|
|
840
|
+
random,
|
|
841
|
+
guid,
|
|
842
|
+
$parent,
|
|
843
|
+
addStyle,
|
|
844
|
+
addUnit,
|
|
845
|
+
deepClone,
|
|
846
|
+
deepMerge,
|
|
847
|
+
shallowMerge,
|
|
848
|
+
error,
|
|
849
|
+
randomArray,
|
|
850
|
+
timeFormat,
|
|
851
|
+
timeFrom,
|
|
852
|
+
trim,
|
|
853
|
+
queryParams,
|
|
854
|
+
toast,
|
|
855
|
+
type2icon,
|
|
856
|
+
priceFormat,
|
|
857
|
+
getDuration,
|
|
858
|
+
padZero,
|
|
859
|
+
formValidate,
|
|
860
|
+
getProperty,
|
|
861
|
+
setProperty,
|
|
862
|
+
page,
|
|
863
|
+
pages,
|
|
864
|
+
getValueByPath,
|
|
865
|
+
genLightColor
|
|
866
|
+
};
|