@ecolovo/uniapp-components 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/components/aspect/aspect.vue +4 -2
  2. package/components/badge/badge.scss +3 -1
  3. package/components/badge/badge.vue +15 -11
  4. package/components/button/button.vue +100 -27
  5. package/components/checkbox/checkbox.scss +1 -1
  6. package/components/checkbox/checkbox.vue +54 -23
  7. package/components/checkbox-group/checkbox-group.vue +11 -4
  8. package/components/checkbox-group2/checkbox-group2.vue +23 -8
  9. package/components/checkbox-group2/checkbox2.vue +11 -4
  10. package/components/data-list/data-list.vue +25 -5
  11. package/components/date-picker/date-picker-view.vue +45 -16
  12. package/components/date-picker/date-picker.vue +58 -18
  13. package/components/dialog/dialog-content.vue +39 -12
  14. package/components/dialog/dialog.vue +30 -19
  15. package/components/dropdown/dropdown.vue +29 -6
  16. package/components/empty/empty.vue +10 -3
  17. package/components/flex/flex.vue +16 -6
  18. package/components/form-item/form-item.vue +13 -4
  19. package/components/icon/icon.scss +9 -0
  20. package/components/icon/icon.vue +46 -8
  21. package/components/image/image.vue +13 -8
  22. package/components/index.d.ts +50 -0
  23. package/components/index.js +50 -0
  24. package/components/index.ts +50 -0
  25. package/components/input/input.vue +13 -3
  26. package/components/input/password-input.vue +2 -2
  27. package/components/list-page/list-page.vue +24 -6
  28. package/components/load-more/load-more.vue +7 -2
  29. package/components/loading/animations/loading-animation3.vue +10 -5
  30. package/components/loading/animations/loading-animation4.vue +65 -8
  31. package/components/loading/loading.vue +7 -6
  32. package/components/message-box/message-box.d.ts +18 -0
  33. package/components/message-box/message-box.js +1 -0
  34. package/components/message-box/message-box.ts +18 -0
  35. package/components/message-box/message-box.vue +53 -21
  36. package/components/number-dialog/number-dialog.vue +61 -21
  37. package/components/number-input/number-input.vue +53 -18
  38. package/components/numpad/numpad.vue +11 -5
  39. package/components/page/page-body.scss +1 -1
  40. package/components/page/page-body.vue +79 -11
  41. package/components/page/page-footer.vue +11 -5
  42. package/components/page/page-header.vue +49 -24
  43. package/components/page/page.scss +2 -1
  44. package/components/page/page.vue +74 -29
  45. package/components/picker/picker-popup.vue +96 -68
  46. package/components/picker/picker.vue +11 -5
  47. package/components/popover/popover-content.vue +59 -19
  48. package/components/popover/popover-mask.vue +18 -11
  49. package/components/popover/popover.vue +13 -3
  50. package/components/popup/popup-content.vue +35 -11
  51. package/components/popup/popup.vue +36 -17
  52. package/components/price/price.scss +1 -0
  53. package/components/price/price.vue +18 -7
  54. package/components/search/search.vue +24 -10
  55. package/components/searching/searching.scss +14 -0
  56. package/components/searching/searching.vue +17 -10
  57. package/components/selector/selector.vue +10 -3
  58. package/components/switch/switch.vue +31 -10
  59. package/components/tab/tab.vue +41 -8
  60. package/components/textarea/textarea.vue +55 -13
  61. package/composable/component-name.js +2 -1
  62. package/composable/component-name.ts +2 -1
  63. package/composable/message-box.d.ts +35 -0
  64. package/composable/message-box.js +56 -0
  65. package/composable/message-box.ts +98 -0
  66. package/configs/index.d.ts +8 -1
  67. package/configs/index.js +14 -3
  68. package/configs/index.ts +8 -1
  69. package/easyCom.js +10 -5
  70. package/easyCom.ts +10 -5
  71. package/globals.d.ts +36 -0
  72. package/index.d.ts +5 -0
  73. package/index.js +5 -0
  74. package/index.ts +5 -0
  75. package/package.json +14 -6
  76. package/styles/global.scss +123 -2
  77. package/styles/reset.scss +5 -0
  78. package/styles/utils/css-var.scss +11 -11
  79. package/styles/utils/index.scss +0 -1
  80. package/styles/var/component.scss +23 -20
  81. package/styles/var/theme.scss +3 -3
  82. package/utils/date.d.ts +7 -2
  83. package/utils/date.js +31 -10
  84. package/utils/date.ts +20 -6
  85. package/utils/price.d.ts +4 -1
  86. package/utils/price.js +12 -7
  87. package/utils/price.ts +8 -3
  88. package/utils/round.js +4 -1
  89. package/utils/round.ts +4 -1
  90. package/utils/windowInfo.d.ts +0 -1
  91. package/styles/utils/z-index.scss +0 -10
package/index.js CHANGED
@@ -1 +1,6 @@
1
+ export * from './globals.d';
1
2
  export { default as init } from './init';
3
+ export { default as componentEasyCom } from './easyCom';
4
+ export * from './components';
5
+ export * from './composable/message-box';
6
+ export * from './components/message-box/message-box';
package/index.ts CHANGED
@@ -1 +1,6 @@
1
+ export * from './globals.d';
1
2
  export { default as init } from './init';
3
+ export { default as componentEasyCom } from './easyCom';
4
+
5
+ export * from './composable/message-box';
6
+ export * from './components/message-box/message-box';
package/package.json CHANGED
@@ -1,28 +1,31 @@
1
1
  {
2
2
  "name": "@ecolovo/uniapp-components",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Ecolovo UniApp Vue3 组件库",
5
5
  "scripts": {
6
6
  "lint": "eslint",
7
7
  "lint:fix": "eslint --fix",
8
- "build": "tsc"
8
+ "build": "vue-tsc --noEmit && tsc",
9
+ "postbuild": "eslint --fix"
9
10
  },
10
11
  "keywords": [
11
12
  "uniapp",
12
13
  "components"
13
14
  ],
15
+ "types": "./index.d.ts",
14
16
  "author": "Yang",
15
17
  "license": "ISC",
16
18
  "dependencies": {
17
- "@ecolovo/utils": "^1.0.7",
19
+ "@ecolovo/utils": "^1.0.10",
18
20
  "case-anything": "3.1.2",
19
21
  "lodash-es": "4.17.21",
20
- "vue": "^3.4.21"
22
+ "vue": "3.4.21"
21
23
  },
22
24
  "devDependencies": {
23
25
  "@dcloudio/types": "^3.4.30",
24
26
  "@eslint/js": "^10.0.1",
25
27
  "@types/lodash-es": "^4.17.12",
28
+ "@vitejs/plugin-vue": "^6.0.7",
26
29
  "@vue/eslint-config-prettier": "^10.2.0",
27
30
  "@vue/eslint-config-typescript": "^14.8.0",
28
31
  "@vue/tsconfig": "^0.1.3",
@@ -31,9 +34,14 @@
31
34
  "eslint-plugin-prettier": "^5.5.5",
32
35
  "eslint-plugin-vue": "^10.8.0",
33
36
  "globals": "^17.4.0",
37
+ "jiti": "^2.7.0",
34
38
  "miniprogram-api-typings": "^5.2.1",
35
39
  "prettier": "^2.8.8",
36
- "typescript": "^4.9.4",
37
- "vue-eslint-parser": "^10.4.0"
40
+ "sass-embedded": "^1.100.0",
41
+ "typescript": "^5.9.3",
42
+ "vite": "^8.1.3",
43
+ "vite-plugin-dts": "^5.0.3",
44
+ "vue-eslint-parser": "^10.4.0",
45
+ "vue-tsc": "^3.3.6"
38
46
  }
39
47
  }
@@ -1,15 +1,26 @@
1
1
  @use 'sass:color';
2
2
  @use './var' as *;
3
3
  @use './utils' as *;
4
+ @use './reset' as *;
4
5
 
6
+ // 定义全局变量
5
7
  page {
8
+ @each $name, $value in $z-indexes {
9
+ #{DO_NOT_USE__global-var-name(z-index, $name)}: #{$value};
10
+ }
6
11
  @each $name, $value in $themes {
7
12
  @for $i from 9 through 1 {
8
- #{DO_NOT_USE__global-var-name(theme, $name + '-dark' + $i)}: #{color.scale($value, $blackness: $i * 10%)};
13
+ #{DO_NOT_USE__global-var-name(theme, '#{$name}-dark#{$i}')}: #{color.scale(
14
+ $value,
15
+ $blackness: $i * 10%
16
+ )};
9
17
  }
10
18
  #{DO_NOT_USE__global-var-name(theme, $name)}: #{$value};
11
19
  @for $i from 1 through 9 {
12
- #{DO_NOT_USE__global-var-name(theme, $name + '-light' + $i)}: #{color.scale($value, $whiteness: $i * 10%)};
20
+ #{DO_NOT_USE__global-var-name(theme, '#{$name}-light#{$i}')}: #{color.scale(
21
+ $value,
22
+ $whiteness: $i * 10%
23
+ )};
13
24
  }
14
25
  }
15
26
  @each $name, $value in $colors {
@@ -22,3 +33,113 @@ page {
22
33
  #{DO_NOT_USE__global-var-name(other, $name)}: #{$value};
23
34
  }
24
35
  }
36
+
37
+ // theme
38
+ @each $name, $value in $themes {
39
+ @for $i from 9 through 1 {
40
+ #{'.color-#{$name}-dark#{$i}'} {
41
+ color: UTILS__GLOBAL_VAR('theme', '#{$name}-dark#{$i}');
42
+ }
43
+ }
44
+ #{'.color-#{$name}'} {
45
+ color: UTILS__GLOBAL_VAR('theme', $name);
46
+ }
47
+ @for $i from 1 through 9 {
48
+ #{'.color-#{$name}-light#{$i}'} {
49
+ color: UTILS__GLOBAL_VAR('theme', '#{$name}-light#{$i}');
50
+ }
51
+ }
52
+ @for $i from 9 through 1 {
53
+ #{'.bg-#{$name}-dark#{$i}'} {
54
+ background-color: UTILS__GLOBAL_VAR('theme', '#{$name}-dark#{$i}');
55
+ }
56
+ }
57
+ #{'.bg-#{$name}'} {
58
+ background-color: UTILS__GLOBAL_VAR('theme', $name);
59
+ }
60
+ @for $i from 1 through 9 {
61
+ #{'.bg-#{$name}-light#{$i}'} {
62
+ background-color: UTILS__GLOBAL_VAR('theme', '#{$name}-light#{$i}');
63
+ }
64
+ }
65
+ }
66
+ @each $name, $value in $colors {
67
+ #{'.color-#{$name}'} {
68
+ color: UTILS__GLOBAL_VAR('color', $name);
69
+ }
70
+ #{'.bg-#{$name}'} {
71
+ background-color: UTILS__GLOBAL_VAR('color', $name);
72
+ }
73
+ }
74
+
75
+ // font
76
+ @each $name, $value in $font-sizes {
77
+ #{'.font-#{$name}'} {
78
+ font-size: UTILS__GLOBAL_VAR('font-size', $name);
79
+ }
80
+ }
81
+ .font-bold {
82
+ font-weight: 600;
83
+ }
84
+
85
+ // size
86
+ .w100,
87
+ .w-100 {
88
+ width: 100%;
89
+ }
90
+ .h100,
91
+ .h-100 {
92
+ height: 100%;
93
+ }
94
+ .w100vw,
95
+ .w-100vw {
96
+ width: 100vw;
97
+ }
98
+ .h100vw,
99
+ .h-100vw {
100
+ height: 100vw;
101
+ }
102
+
103
+ // flex
104
+ .flex-1 {
105
+ flex: 1;
106
+ }
107
+ .flex-0 {
108
+ flex: 0;
109
+ }
110
+ .flex-none {
111
+ flex: none;
112
+ }
113
+ .flex-auto {
114
+ flex: auto;
115
+ }
116
+ .flex-grow {
117
+ flex: 1 0 auto;
118
+ }
119
+ .flex-shrink {
120
+ flex: 0 1 auto;
121
+ }
122
+
123
+ // box-sizing
124
+ .box-border {
125
+ box-sizing: border-box;
126
+ }
127
+ .box-content {
128
+ box-sizing: content-box;
129
+ }
130
+
131
+ // other
132
+ .ellipsis {
133
+ @include UTILS__ELLIPSIS;
134
+ }
135
+ @for $i from 2 through 5 {
136
+ #{'.ellipsis-#{$i}'} {
137
+ @include UTILS__ELLIPSIS($i);
138
+ }
139
+ }
140
+ .overflow-hidden {
141
+ overflow: hidden;
142
+ }
143
+ .events-none {
144
+ pointer-events: none;
145
+ }
@@ -0,0 +1,5 @@
1
+ @use './utils' as *;
2
+
3
+ page {
4
+ font-size: UTILS__GLOBAL_VAR('font-size', 'normal');
5
+ }
@@ -5,29 +5,29 @@
5
5
  @use '../var/theme' as *;
6
6
 
7
7
  // 返回组件外部变量名
8
- @function UTILS__VAR_NAME($name, $component) {
8
+ @function UTILS__VAR_NAME($component, $name) {
9
9
  @return string.unquote('--#{$component-prefix}-#{$component}--#{$name}');
10
10
  }
11
11
 
12
12
  // 设置组件单个外部变量值
13
13
  @mixin UTILS__SET_VAR($component, $name, $value) {
14
- #{UTILS__VAR_NAME($name, $component)}: $value;
14
+ #{UTILS__VAR_NAME($component, $name)}: $value;
15
15
  }
16
16
 
17
17
  // 设置组件一组外部变量值
18
18
  @mixin UTILS__SET_VAR_LIST($component, $values) {
19
19
  @each $name, $value in $values {
20
- #{UTILS__VAR_NAME($name, $component)}: $value;
20
+ #{UTILS__VAR_NAME($component, $name)}: $value;
21
21
  }
22
22
  }
23
23
 
24
24
  // 返回组件外部变量值
25
- @function UTILS__VAR($name, $component, $default: null) {
25
+ @function UTILS__VAR($component, $name, $default: null) {
26
26
  @if $default != null {
27
- @return var(UTILS__VAR_NAME($name, $component), $default);
27
+ @return var(UTILS__VAR_NAME($component, $name), $default);
28
28
  }
29
29
 
30
- @return var(UTILS__VAR_NAME($name, $component));
30
+ @return var(UTILS__VAR_NAME($component, $name));
31
31
  }
32
32
 
33
33
  // 返回组件内部变量值
@@ -40,9 +40,9 @@
40
40
  }
41
41
 
42
42
  // 定义组件变量
43
- @mixin UTILS__DEFINE_COMPONENT_VARS($vars, $name) {
44
- @if not $name {
45
- @error "请传入 $name";
43
+ @mixin UTILS__DEFINE_COMPONENT_VARS($component, $vars) {
44
+ @if not $component {
45
+ @error "请传入 $component";
46
46
  }
47
47
 
48
48
  @if (not $vars) or (meta.type-of($vars) != 'map') {
@@ -50,7 +50,7 @@
50
50
  }
51
51
 
52
52
  @each $key, $value in $vars {
53
- @include __DO_NOT_USE__define-component-var($name, $key, $value);
53
+ @include __DO_NOT_USE__define-component-var($component, $key, $value);
54
54
  }
55
55
  }
56
56
 
@@ -75,7 +75,7 @@
75
75
  $default: true;
76
76
  }
77
77
 
78
- $var-name: UTILS__VAR_NAME($name, $component);
78
+ $var-name: UTILS__VAR_NAME($component, $name);
79
79
  $local-name: __DO_NOT_USE__local-var-name($name);
80
80
 
81
81
  @if $default {
@@ -2,4 +2,3 @@
2
2
  @forward './ellipsis';
3
3
  @forward './global-var';
4
4
  @forward './selector';
5
- @forward './z-index';
@@ -1,21 +1,24 @@
1
- // @forward '../../components/badge/badge.scss';
1
+ @forward '../../components/badge/badge.scss';
2
2
  @forward '../../components/button/button.scss';
3
- // @forward '../../components/checkbox/checkbox.scss';
4
- // @forward '../../components/data-list/data-list.scss';
5
- // @forward '../../components/dialog/dialog.scss';
6
- // @forward '../../components/empty/empty.scss';
7
- // @forward '../../components/form-item/form-item.scss';
8
- // @forward '../../components/load-more/load-more.scss';
9
- // @forward '../../components/number-dialog/number-dialog.scss';
10
- // @forward '../../components/number-input/number-input.scss';
11
- // @forward '../../components/numpad/numpad.scss';
12
- // @forward '../../components/page/page.scss';
13
- // @forward '../../components/page/page-header.scss';
14
- // @forward '../../components/page/page-body.scss';
15
- // @forward '../../components/page/page-footer.scss';
16
- // @forward '../../components/popover/popover.scss';
17
- // @forward '../../components/popup/popup.scss';
18
- // @forward '../../components/price/price.scss';
19
- // @forward '../../components/search/search.scss';
20
- // @forward '../../components/switch/switch.scss';
21
- // @forward '../../components/tab/tab.scss';
3
+ @forward '../../components/checkbox/checkbox.scss';
4
+ @forward '../../components/data-list/data-list.scss';
5
+ @forward '../../components/dialog/dialog.scss';
6
+ @forward '../../components/dropdown/dropdown.scss';
7
+ @forward '../../components/empty/empty.scss';
8
+ @forward '../../components/form-item/form-item.scss';
9
+ @forward '../../components/icon/icon.scss';
10
+ @forward '../../components/load-more/load-more.scss';
11
+ @forward '../../components/number-dialog/number-dialog.scss';
12
+ @forward '../../components/number-input/number-input.scss';
13
+ @forward '../../components/numpad/numpad.scss';
14
+ @forward '../../components/page/page-body.scss';
15
+ @forward '../../components/page/page-footer.scss';
16
+ @forward '../../components/page/page-header.scss';
17
+ @forward '../../components/page/page.scss';
18
+ @forward '../../components/popover/popover.scss';
19
+ @forward '../../components/popup/popup.scss';
20
+ @forward '../../components/price/price.scss';
21
+ @forward '../../components/search/search.scss';
22
+ @forward '../../components/searching/searching.scss';
23
+ @forward '../../components/switch/switch.scss';
24
+ @forward '../../components/tab/tab.scss';
@@ -2,8 +2,8 @@
2
2
 
3
3
  $component-prefix: 'app' !default;
4
4
 
5
- $z-index-maps: () !default;
6
- $z-index-maps-default: (
5
+ $z-indexes: () !default;
6
+ $z-indexes-default: (
7
7
  loading: 9999,
8
8
  dialog: 4000,
9
9
  dropdown: 3000,
@@ -11,7 +11,7 @@ $z-index-maps-default: (
11
11
  page-header: 2000,
12
12
  page-footer: 2000,
13
13
  );
14
- $z-index-maps: map.merge($z-index-maps-default, $z-index-maps);
14
+ $z-indexes: map.merge($z-indexes-default, $z-indexes);
15
15
 
16
16
  $themes: () !default;
17
17
  $themes-default: (
package/utils/date.d.ts CHANGED
@@ -4,7 +4,9 @@ type ValidDateValue = Date | number | string;
4
4
  * @param dateValue Date 对象、时间戳或时间格式字符串
5
5
  * @returns Date 对象
6
6
  */
7
- export declare function toDate(dateValue: ValidDateValue | null | undefined): Date | null;
7
+ export declare function toDate(
8
+ dateValue: ValidDateValue | null | undefined
9
+ ): Date | null;
8
10
  type FormatFn = {
9
11
  (date: Date | null | undefined, format?: string): string;
10
12
  DATE: string;
@@ -43,5 +45,8 @@ export declare const formatDate: FormatFn;
43
45
  * @param day2 时间2
44
46
  * @returns 天数差,负数: day1 < day2
45
47
  */
46
- export declare function daysDiff(day1: ValidDateValue, day2: ValidDateValue): number;
48
+ export declare function daysDiff(
49
+ day1: ValidDateValue,
50
+ day2: ValidDateValue
51
+ ): number;
47
52
  export {};
package/utils/date.js CHANGED
@@ -4,13 +4,23 @@
4
4
  * @returns Date 对象
5
5
  */
6
6
  export function toDate(dateValue) {
7
- if (dateValue instanceof Date) return new Date(dateValue);
8
- if (typeof dateValue === 'number') return new Date(dateValue);
9
- if (!dateValue) return null;
10
- if (typeof dateValue !== 'string') throw new Error("dateValue's type is invalid");
7
+ if (dateValue instanceof Date) {
8
+ return new Date(dateValue);
9
+ }
10
+ if (typeof dateValue === 'number') {
11
+ return new Date(dateValue);
12
+ }
13
+ if (!dateValue) {
14
+ return null;
15
+ }
16
+ if (typeof dateValue !== 'string') {
17
+ throw new Error("dateValue's type is invalid");
18
+ }
11
19
  // 兼容 iOS 日期格式
12
20
  const result = new Date(dateValue.replace(/-/g, '/'));
13
- if (isNaN(result.getTime())) throw new Error('dateValue cannot be parsed to Date object');
21
+ if (isNaN(result.getTime())) {
22
+ throw new Error('dateValue cannot be parsed to Date object');
23
+ }
14
24
  return result;
15
25
  }
16
26
  /**
@@ -31,7 +41,9 @@ export function toDate(dateValue) {
31
41
  * @returns 格式化后的日期
32
42
  */
33
43
  export const formatDate = (date, format = formatDate.DATE_WITH_YEAR) => {
34
- if (!date) return '';
44
+ if (!date) {
45
+ return '';
46
+ }
35
47
  const fullYear = date.getFullYear().toString();
36
48
  const year = fullYear.substring(fullYear.length - 2);
37
49
  const month = (date.getMonth() + 1).toString();
@@ -115,9 +127,15 @@ const TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000;
115
127
  * @returns 毫秒数
116
128
  */
117
129
  function toDayTimestamp(date) {
118
- if (typeof date === 'number') return date - TIMEZONE_OFFSET;
119
- if (typeof date === 'string') return toDate(date).getTime() - TIMEZONE_OFFSET;
120
- if (date instanceof Date) return date.getTime() - TIMEZONE_OFFSET;
130
+ if (typeof date === 'number') {
131
+ return date - TIMEZONE_OFFSET;
132
+ }
133
+ if (typeof date === 'string') {
134
+ return toDate(date).getTime() - TIMEZONE_OFFSET;
135
+ }
136
+ if (date instanceof Date) {
137
+ return date.getTime() - TIMEZONE_OFFSET;
138
+ }
121
139
  return Date.now() - TIMEZONE_OFFSET;
122
140
  }
123
141
  /**
@@ -127,5 +145,8 @@ function toDayTimestamp(date) {
127
145
  * @returns 天数差,负数: day1 < day2
128
146
  */
129
147
  export function daysDiff(day1, day2) {
130
- return Math.floor(toDayTimestamp(day1) / 8.64e7) - Math.floor(toDayTimestamp(day2) / 8.64e7);
148
+ return (
149
+ Math.floor(toDayTimestamp(day1) / 8.64e7) -
150
+ Math.floor(toDayTimestamp(day2) / 8.64e7)
151
+ );
131
152
  }
package/utils/date.ts CHANGED
@@ -5,15 +5,21 @@ type ValidDateValue = Date | number | string;
5
5
  * @param dateValue Date 对象、时间戳或时间格式字符串
6
6
  * @returns Date 对象
7
7
  */
8
- export function toDate(dateValue: ValidDateValue | null | undefined): Date | null {
8
+ export function toDate(
9
+ dateValue: ValidDateValue | null | undefined
10
+ ): Date | null {
9
11
  if (dateValue instanceof Date) return new Date(dateValue);
10
12
  if (typeof dateValue === 'number') return new Date(dateValue);
11
13
  if (!dateValue) return null;
12
- if (typeof dateValue !== 'string') throw new Error("dateValue's type is invalid");
14
+ if (typeof dateValue !== 'string') {
15
+ throw new Error("dateValue's type is invalid");
16
+ }
13
17
 
14
18
  // 兼容 iOS 日期格式
15
19
  const result = new Date(dateValue.replace(/-/g, '/'));
16
- if (isNaN(result.getTime())) throw new Error('dateValue cannot be parsed to Date object');
20
+ if (isNaN(result.getTime())) {
21
+ throw new Error('dateValue cannot be parsed to Date object');
22
+ }
17
23
  return result;
18
24
  }
19
25
 
@@ -48,7 +54,10 @@ type FormatFn = {
48
54
  * @param format 格式化参数 默认值 YYYY-MM-DD
49
55
  * @returns 格式化后的日期
50
56
  */
51
- export const formatDate: FormatFn = (date, format = formatDate.DATE_WITH_YEAR) => {
57
+ export const formatDate: FormatFn = (
58
+ date,
59
+ format = formatDate.DATE_WITH_YEAR
60
+ ) => {
52
61
  if (!date) return '';
53
62
  const fullYear = date.getFullYear().toString();
54
63
  const year = fullYear.substring(fullYear.length - 2);
@@ -137,7 +146,9 @@ const TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000;
137
146
  */
138
147
  function toDayTimestamp(date: ValidDateValue): number {
139
148
  if (typeof date === 'number') return date - TIMEZONE_OFFSET;
140
- if (typeof date === 'string') return toDate(date)!.getTime() - TIMEZONE_OFFSET;
149
+ if (typeof date === 'string') {
150
+ return toDate(date)!.getTime() - TIMEZONE_OFFSET;
151
+ }
141
152
  if (date instanceof Date) return date.getTime() - TIMEZONE_OFFSET;
142
153
  return Date.now() - TIMEZONE_OFFSET;
143
154
  }
@@ -149,5 +160,8 @@ function toDayTimestamp(date: ValidDateValue): number {
149
160
  * @returns 天数差,负数: day1 < day2
150
161
  */
151
162
  export function daysDiff(day1: ValidDateValue, day2: ValidDateValue): number {
152
- return Math.floor(toDayTimestamp(day1) / 8.64e7) - Math.floor(toDayTimestamp(day2) / 8.64e7);
163
+ return (
164
+ Math.floor(toDayTimestamp(day1) / 8.64e7) -
165
+ Math.floor(toDayTimestamp(day2) / 8.64e7)
166
+ );
153
167
  }
package/utils/price.d.ts CHANGED
@@ -20,5 +20,8 @@ interface FormatPriceResult {
20
20
  * 格式化价格
21
21
  * @param price 价格
22
22
  */
23
- export declare function formatPrice(price: number | string, option?: FormatPriceOption): FormatPriceResult;
23
+ export declare function formatPrice(
24
+ price: number | string,
25
+ option?: FormatPriceOption
26
+ ): FormatPriceResult;
24
27
  export {};
package/utils/price.js CHANGED
@@ -19,20 +19,25 @@ export function formatPrice(price, option) {
19
19
  price = -price;
20
20
  }
21
21
  const integer = Math.floor(price).toString();
22
- const decimalNum = Math.round(Number(price + 'e' + (option?.precision ?? 2))) % 100;
22
+ const decimalNum =
23
+ Math.round(Number(price + 'e' + (option?.precision ?? 2))) % 100;
23
24
  let decimal;
24
25
  if (option?.padDecimal ?? true) {
25
- decimal = '.' + decimalNum.toString().padStart(option?.precision ?? 2, '0');
26
+ decimal =
27
+ '.' + decimalNum.toString().padStart(option?.precision ?? 2, '0');
26
28
  } else {
27
- if (decimalNum === 0) decimal = '';
28
- else decimal = decimalNum.toString().slice(1);
29
+ if (decimalNum === 0) {
30
+ decimal = '';
31
+ } else {
32
+ decimal = decimalNum.toString().slice(1);
33
+ }
29
34
  }
30
35
  const formattedPrice = `${negative ? '-' : ''}${integer}.${decimal}`;
31
36
  return {
32
- price: formattedPrice,
37
+ price: formattedPrice, // 价格字符串
33
38
  negative,
34
- integer,
35
- decimal,
39
+ integer, // 整数部分
40
+ decimal, // 小数部分
36
41
  number: Number(formattedPrice),
37
42
  };
38
43
  }
package/utils/price.ts CHANGED
@@ -21,7 +21,10 @@ interface FormatPriceResult {
21
21
  * 格式化价格
22
22
  * @param price 价格
23
23
  */
24
- export function formatPrice(price: number | string, option?: FormatPriceOption): FormatPriceResult {
24
+ export function formatPrice(
25
+ price: number | string,
26
+ option?: FormatPriceOption
27
+ ): FormatPriceResult {
25
28
  if (isNaN(Number(price))) {
26
29
  return {
27
30
  price: '',
@@ -38,10 +41,12 @@ export function formatPrice(price: number | string, option?: FormatPriceOption):
38
41
  price = -price;
39
42
  }
40
43
  const integer = Math.floor(price).toString();
41
- const decimalNum = Math.round(Number(price + 'e' + (option?.precision ?? 2))) % 100;
44
+ const decimalNum =
45
+ Math.round(Number(price + 'e' + (option?.precision ?? 2))) % 100;
42
46
  let decimal: string;
43
47
  if (option?.padDecimal ?? true) {
44
- decimal = '.' + decimalNum.toString().padStart(option?.precision ?? 2, '0');
48
+ decimal =
49
+ '.' + decimalNum.toString().padStart(option?.precision ?? 2, '0');
45
50
  } else {
46
51
  if (decimalNum === 0) decimal = '';
47
52
  else decimal = decimalNum.toString().slice(1);
package/utils/round.js CHANGED
@@ -1,7 +1,10 @@
1
1
  export function round(val, precision = 0) {
2
2
  if (val.toString().indexOf('e') >= 0) {
3
3
  const exponential = val.toString().split('e');
4
- return Math.round(+`${exponential[0]}e${+exponential[1] + precision}`) / 10 ** precision;
4
+ return (
5
+ Math.round(+`${exponential[0]}e${+exponential[1] + precision}`) /
6
+ 10 ** precision
7
+ );
5
8
  }
6
9
  return Math.round(+`${val}e${precision}`) / 10 ** precision;
7
10
  }
package/utils/round.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  export function round(val: number, precision = 0): number {
2
2
  if (val.toString().indexOf('e') >= 0) {
3
3
  const exponential = val.toString().split('e');
4
- return Math.round(+`${exponential[0]}e${+exponential[1]! + precision}`) / 10 ** precision;
4
+ return (
5
+ Math.round(+`${exponential[0]}e${+exponential[1]! + precision}`) /
6
+ 10 ** precision
7
+ );
5
8
  }
6
9
  return Math.round(+`${val}e${precision}`) / 10 ** precision;
7
10
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="@dcloudio/types" />
2
1
  /** 胶囊按钮位置信息 */
3
2
  declare let menuButton: UniApp.GetMenuButtonBoundingClientRectRes | null;
4
3
  /** 胶囊按钮宽度,仅在 css 中使用,当有胶囊按钮时,表示胶囊按钮左边缘到屏幕右侧的宽度,否则为 `0px` */
@@ -1,10 +0,0 @@
1
- @use 'sass:list';
2
- @use 'sass:map';
3
- @use 'sass:meta';
4
- @use 'sass:string';
5
- @use '../var/theme' as *;
6
- @use './css-var' as *;
7
-
8
- @function UTILS__z-index($key) {
9
- @return map.get($z-index-maps, $key);
10
- }