@farris/cli 2.0.0-beta.7 → 2.0.0-beta.8
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/bin/index.js +2 -2
- package/lib/commands/build-components.js +21 -17
- package/lib/commands/build-components.js.map +1 -0
- package/lib/commands/build-css.js +30 -2
- package/lib/commands/build-css.js.map +1 -0
- package/lib/commands/build-lib.js +16 -6
- package/lib/commands/build-lib.js.map +1 -0
- package/lib/commands/build.js +11 -5
- package/lib/commands/build.js.map +1 -0
- package/lib/commands/create-app.js +2 -1
- package/lib/commands/create-app.js.map +1 -0
- package/lib/commands/dev-serve.js +3 -7
- package/lib/commands/dev-serve.js.map +1 -0
- package/lib/commands/preview-serve.js +1 -0
- package/lib/commands/preview-serve.js.map +1 -0
- package/lib/common/constant.js +1 -0
- package/lib/common/constant.js.map +1 -0
- package/lib/common/generate-app.js +1 -0
- package/lib/common/generate-app.js.map +1 -0
- package/lib/common/get-dependencies.js +1 -0
- package/lib/common/get-dependencies.js.map +1 -0
- package/lib/common/get-farris-config.js +3 -2
- package/lib/common/get-farris-config.js.map +1 -0
- package/lib/common/get-version.js +1 -0
- package/lib/common/get-version.js.map +1 -0
- package/lib/common/get-vite-config.js +16 -8
- package/lib/common/get-vite-config.js.map +1 -0
- package/lib/config/vite-app.js +10 -10
- package/lib/config/vite-app.js.map +1 -0
- package/lib/config/vite-common.js +21 -0
- package/lib/config/vite-common.js.map +1 -0
- package/lib/config/vite-component.js +30 -0
- package/lib/config/vite-component.js.map +1 -0
- package/lib/config/vite-lib.js +12 -20
- package/lib/config/vite-lib.js.map +1 -0
- package/lib/index.js +23 -1
- package/lib/index.js.map +1 -0
- package/lib/plugins/{gen-component-style.js → create-component-style.js} +6 -4
- package/lib/plugins/create-component-style.js.map +1 -0
- package/lib/plugins/create-package-json.js +34 -0
- package/lib/plugins/create-package-json.js.map +1 -0
- package/lib/plugins/dts.js +1 -0
- package/lib/plugins/dts.js.map +1 -0
- package/lib/plugins/html-system.js +1 -0
- package/lib/plugins/html-system.js.map +1 -0
- package/lib/plugins/replace.js +1 -0
- package/lib/plugins/replace.js.map +1 -0
- package/lib/plugins/systemjs-bundle.js +16 -0
- package/lib/plugins/systemjs-bundle.js.map +1 -0
- package/package.json +41 -38
- package/templates/lib/.eslintrc.cjs +15 -15
- package/templates/lib/.prettierrc.json +7 -7
- package/templates/lib/components/button/index.ts +7 -0
- package/templates/lib/components/button/src/button.component.tsx +84 -0
- package/templates/lib/components/button/src/button.props.ts +55 -0
- package/templates/lib/components/button/src/button.scss +179 -0
- package/templates/lib/components/common/index.ts +6 -0
- package/templates/lib/components/common/src/common.scss +4 -0
- package/templates/lib/components/common/src/compositions/index.ts +19 -0
- package/templates/lib/components/common/src/compositions/types.ts +6 -0
- package/templates/lib/components/common/src/compositions/use-bem/index.ts +46 -0
- package/templates/lib/components/common/src/compositions/use-click-away/index.ts +40 -0
- package/templates/lib/components/common/src/compositions/use-context/use-children-contexts.ts +40 -0
- package/templates/lib/components/common/src/compositions/use-context/use-parent-context.ts +24 -0
- package/templates/lib/components/common/src/compositions/use-event-listener/index.ts +45 -0
- package/templates/lib/components/common/src/compositions/use-expose/index.ts +9 -0
- package/templates/lib/components/common/src/compositions/use-lay-render/index.ts +17 -0
- package/templates/lib/components/common/src/compositions/use-link/index.ts +14 -0
- package/templates/lib/components/common/src/compositions/use-lock-scroll/index.ts +25 -0
- package/templates/lib/components/common/src/compositions/use-long-press/index.ts +141 -0
- package/templates/lib/components/common/src/compositions/use-momentum/index.ts +82 -0
- package/templates/lib/components/common/src/compositions/use-mount-component/index.ts +48 -0
- package/templates/lib/components/common/src/compositions/use-rect/index.ts +31 -0
- package/templates/lib/components/common/src/compositions/use-refs/index.ts +21 -0
- package/templates/lib/components/common/src/compositions/use-resize-observer/index.ts +85 -0
- package/templates/lib/components/common/src/compositions/use-resize-observer/utils.ts +37 -0
- package/templates/lib/components/common/src/compositions/use-scroll-parent/index.ts +42 -0
- package/templates/lib/components/common/src/compositions/use-touch/index.ts +82 -0
- package/templates/lib/components/common/src/compositions/use-touch-move/index.ts +120 -0
- package/templates/lib/components/common/src/entity/base-property.ts +129 -0
- package/templates/lib/components/common/src/entity/entity-schema.ts +274 -0
- package/templates/lib/components/common/src/entity/input-base-property.ts +285 -0
- package/templates/lib/components/common/src/style/animation/index.scss +150 -0
- package/templates/lib/components/common/src/style/base.scss +63 -0
- package/templates/lib/components/common/src/style/fonts/farris-mobile-icon.ttf +0 -0
- package/templates/lib/components/common/src/style/icon.scss +6 -0
- package/templates/lib/components/common/src/style/index.scss +4 -0
- package/templates/lib/components/common/src/style/mixins/bem.scss +204 -0
- package/templates/lib/components/common/src/style/mixins/border-radius.scss +13 -0
- package/templates/lib/components/common/src/style/mixins/ellipsis.scss +15 -0
- package/templates/lib/components/common/src/style/mixins/hairline.scss +113 -0
- package/templates/lib/components/common/src/style/mixins/index.scss +6 -0
- package/templates/lib/components/common/src/style/mixins/margin.scss +10 -0
- package/templates/lib/components/common/src/style/mixins/safe-area.scss +9 -0
- package/templates/lib/components/common/src/style/variables.scss +113 -0
- package/templates/lib/components/common/src/utils/index.ts +15 -0
- package/templates/lib/components/common/src/utils/src/common.ts +83 -0
- package/templates/lib/components/common/src/utils/src/date.ts +134 -0
- package/templates/lib/components/common/src/utils/src/dom/event.ts +37 -0
- package/templates/lib/components/common/src/utils/src/hook.ts +18 -0
- package/templates/lib/components/common/src/utils/src/number.ts +26 -0
- package/templates/lib/components/common/src/utils/src/query-filter.ts +40 -0
- package/templates/lib/components/common/src/utils/src/resove-asset.ts +33 -0
- package/templates/lib/components/common/src/utils/src/string.ts +18 -0
- package/templates/lib/components/common/src/utils/src/throttle.ts +41 -0
- package/templates/lib/components/common/src/utils/src/transition.ts +14 -0
- package/templates/lib/components/common/src/utils/src/type.ts +105 -0
- package/templates/lib/components/common/src/utils/src/use-appearance.ts +33 -0
- package/templates/lib/components/common/src/utils/src/with-install.ts +16 -0
- package/templates/lib/components/common/src/utils/src/with-register-designer.ts +16 -0
- package/templates/lib/components/common/src/utils/src/with-register.ts +16 -0
- package/templates/lib/components/common/types.ts +131 -0
- package/templates/lib/components/index.ts +0 -0
- package/templates/lib/farris.config.mjs +37 -16
- package/templates/lib/index.html +12 -12
- package/templates/lib/package.json +28 -28
- package/templates/lib/src/App.vue +80 -5
- package/templates/lib/src/components/TheButton.vue +3 -0
- package/templates/lib/src/main.ts +10 -9
- package/templates/lib/src/router/index.ts +23 -0
- package/templates/lib/src/views/AboutView.vue +15 -0
- package/templates/lib/src/views/HomeView.vue +9 -0
- package/templates/lib/tsconfig.json +19 -17
- package/templates/mobile/.eslintrc.cjs +15 -15
- package/templates/mobile/.prettierrc.json +7 -7
- package/templates/mobile/farris.config.mjs +1 -1
- package/templates/mobile/index.html +12 -12
- package/templates/mobile/package.json +28 -28
- package/templates/mobile/src/App.vue +80 -80
- package/templates/mobile/src/components/TheButton.vue +3 -3
- package/templates/mobile/src/main.ts +12 -12
- package/templates/mobile/src/router/index.ts +23 -23
- package/templates/mobile/src/views/AboutView.vue +15 -15
- package/templates/mobile/src/views/HomeView.vue +9 -9
- package/templates/mobile/tsconfig.json +17 -17
- package/templates/web/.eslintrc.cjs +15 -0
- package/templates/web/.prettierrc.json +8 -0
- package/templates/web/farris.config.mjs +24 -0
- package/templates/web/index.html +12 -0
- package/templates/web/package.json +29 -0
- package/templates/web/src/App.vue +80 -0
- package/templates/web/src/components/TheButton.vue +3 -0
- package/templates/web/src/main.ts +10 -0
- package/templates/web/src/router/index.ts +23 -0
- package/templates/web/src/views/AboutView.vue +15 -0
- package/templates/web/src/views/HomeView.vue +9 -0
- package/templates/web/tsconfig.json +18 -0
- package/templates/lib/packages/button/src/index.vue +0 -4
- package/templates/lib/packages/index.ts +0 -7
@@ -0,0 +1,13 @@
|
|
1
|
+
@mixin borderRadius($size, $position: '') {
|
2
|
+
@if ($position == 'top') {
|
3
|
+
border-radius: 0 0 $size $size;
|
4
|
+
} @else if($position == 'bottom') {
|
5
|
+
border-radius: $size $size 0 0;
|
6
|
+
} @else if($position == 'left') {
|
7
|
+
border-radius: 0 $size $size 0;
|
8
|
+
} @else if($position == 'right') {
|
9
|
+
border-radius: $size 0 0 $size;
|
10
|
+
} @else {
|
11
|
+
border-radius: $size
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
@mixin multi-ellipsis($lines) {
|
2
|
+
display: -webkit-box;
|
3
|
+
overflow: hidden;
|
4
|
+
text-overflow: ellipsis;
|
5
|
+
-webkit-line-clamp: $lines;
|
6
|
+
|
7
|
+
/* autoprefixer: ignore next */
|
8
|
+
-webkit-box-orient: vertical;
|
9
|
+
}
|
10
|
+
|
11
|
+
@mixin ellipsis {
|
12
|
+
overflow: hidden;
|
13
|
+
white-space: nowrap;
|
14
|
+
text-overflow: ellipsis;
|
15
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
@mixin scale-hairline-common($color, $top, $right, $bottom, $left) {
|
2
|
+
content: '';
|
3
|
+
position: absolute;
|
4
|
+
background-color: $color;
|
5
|
+
display: block;
|
6
|
+
z-index: 1;
|
7
|
+
top: $top;
|
8
|
+
right: $right;
|
9
|
+
bottom: $bottom;
|
10
|
+
left: $left;
|
11
|
+
}
|
12
|
+
|
13
|
+
@mixin hairline(
|
14
|
+
$direction,
|
15
|
+
$color: #ddd,
|
16
|
+
$radius: 0,
|
17
|
+
$type: solid,
|
18
|
+
) {
|
19
|
+
@if ($direction == 'top') {
|
20
|
+
border-top: 1px $type $color;
|
21
|
+
position: relative;
|
22
|
+
border-top: none;
|
23
|
+
&::before {
|
24
|
+
@include scale-hairline-common($color, 0, auto, auto, 0);
|
25
|
+
width: 100%;
|
26
|
+
height: 1px;
|
27
|
+
transform-origin: 50% 50%;
|
28
|
+
transform: scaleY(0.5);
|
29
|
+
}
|
30
|
+
} @else if ($direction == 'bottom') {
|
31
|
+
border-bottom: 1px $type $color;
|
32
|
+
position: relative;
|
33
|
+
border-bottom: none;
|
34
|
+
&::after {
|
35
|
+
@include scale-hairline-common($color, auto, auto, 0, 0);
|
36
|
+
width: 100%;
|
37
|
+
height: 1px;
|
38
|
+
transform-origin: 50% 100%;
|
39
|
+
transform: scaleY(0.5);
|
40
|
+
}
|
41
|
+
} @else if ($direction == 'left') {
|
42
|
+
border-left: 1px $type $color;
|
43
|
+
position: relative;
|
44
|
+
border-left: none;
|
45
|
+
&::before {
|
46
|
+
@include scale-hairline-common($color, 0, auto, auto, 0);
|
47
|
+
width: 1px;
|
48
|
+
height: 100%;
|
49
|
+
transform-origin: 100% 50%;
|
50
|
+
transform: scaleX(0.5);
|
51
|
+
}
|
52
|
+
} @else if ($direction == 'right') {
|
53
|
+
border-right: 1px $type $color;
|
54
|
+
position: relative;
|
55
|
+
border-right: none;
|
56
|
+
&::after {
|
57
|
+
@include scale-hairline-common($color, 0, 0, auto, auto);
|
58
|
+
width: 1px;
|
59
|
+
height: 100%;
|
60
|
+
background: $color;
|
61
|
+
transform-origin: 100% 50%;
|
62
|
+
transform: scaleX(0.5);
|
63
|
+
}
|
64
|
+
} @else if ($direction == 'all') {
|
65
|
+
border: 1px $type $color;
|
66
|
+
border-radius: $radius;
|
67
|
+
position: relative;
|
68
|
+
border: none;
|
69
|
+
&::before {
|
70
|
+
content: '';
|
71
|
+
position: absolute;
|
72
|
+
left: 0;
|
73
|
+
top: 0;
|
74
|
+
width: 200%;
|
75
|
+
height: 200%;
|
76
|
+
border: 1px $type $color;
|
77
|
+
border-radius: $radius * 2;
|
78
|
+
transform-origin: 0 0;
|
79
|
+
transform: scale(0.5);
|
80
|
+
box-sizing: border-box;
|
81
|
+
pointer-events: none;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
@mixin hairline-remove($position) {
|
87
|
+
@if $position == 'left' {
|
88
|
+
border-left: 0;
|
89
|
+
&:before {
|
90
|
+
display: none !important;
|
91
|
+
}
|
92
|
+
} @else if $position == 'right' {
|
93
|
+
border-right: 0;
|
94
|
+
&:after {
|
95
|
+
display: none !important;
|
96
|
+
}
|
97
|
+
} @else if $position == 'top' {
|
98
|
+
border-top: 0;
|
99
|
+
&:before {
|
100
|
+
display: none !important;
|
101
|
+
}
|
102
|
+
} @else if $position == 'bottom' {
|
103
|
+
border-bottom: 0;
|
104
|
+
&:after {
|
105
|
+
display: none !important;
|
106
|
+
}
|
107
|
+
} @else if $position == 'all' {
|
108
|
+
border: 0;
|
109
|
+
&:before {
|
110
|
+
display: none !important;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
@mixin safeArea($styleName) {
|
2
|
+
@if($styleName){
|
3
|
+
#{$styleName}: 0;
|
4
|
+
@supports ((bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom))) and (-webkit-overflow-scrolling: touch) {
|
5
|
+
#{$styleName}: constant(safe-area-inset-bottom);
|
6
|
+
#{$styleName}: env(safe-area-inset-bottom);
|
7
|
+
}
|
8
|
+
}
|
9
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
:root {
|
2
|
+
// Color Palette
|
3
|
+
--fm-black: #000;
|
4
|
+
--fm-white: #fff;
|
5
|
+
--fm-gray-1: #f2f3f5;
|
6
|
+
--fm-gray-2: #eee;
|
7
|
+
--fm-gray-3: #ddd;
|
8
|
+
--fm-gray-4: #ccc;
|
9
|
+
--fm-gray-5: #999;
|
10
|
+
--fm-gray-6: #666;
|
11
|
+
--fm-gray-7: #333;
|
12
|
+
--fm-red: #F24645;
|
13
|
+
--fm-red-light: #f9e8e8;
|
14
|
+
--fm-blue: #3A90FF;
|
15
|
+
--fm-blue-2: #65a7ff;
|
16
|
+
--fm-blue-light: #ecf2fe;
|
17
|
+
--fm-green: #5CC171;
|
18
|
+
--fm-green-2: #5AC1C3;
|
19
|
+
--fm-green-light: #e9f5ed;
|
20
|
+
--fm-orange: #FF9800;
|
21
|
+
--fm-orange-2: #FA6400;
|
22
|
+
--fm-orange-3: #FFB400;
|
23
|
+
--fm-orange-light: #faf0e1;
|
24
|
+
|
25
|
+
// Component Colors
|
26
|
+
--fm-primary-color: var(--fm-blue);
|
27
|
+
--fm-success-color: var(--fm-green);
|
28
|
+
--fm-danger-color: var(--fm-red);
|
29
|
+
--fm-warning-color: var(--fm-orange);
|
30
|
+
--fm-submit-color: var(--fm-green-2);
|
31
|
+
--fm-primary-color-light: var(--fm-blue-light);
|
32
|
+
--fm-success-color-light: var(--fm-green-light);
|
33
|
+
--fm-danger-color-light: var(--fm-red-light);
|
34
|
+
--fm-warning-color-light: var(--fm-orange-light);
|
35
|
+
--fm-text-color: var(--fm-gray-7);
|
36
|
+
--fm-text-color-light: var(--fm-gray-5);
|
37
|
+
--fm-active-color: var(--fm-gray-1);
|
38
|
+
--fm-disabled-color: var(--fm-gray-4);
|
39
|
+
--fm-readonly-color: var(--fm-gray-6);
|
40
|
+
--fm-active-opacity: 0.7;
|
41
|
+
--fm-readonly-opacity: 0.6;
|
42
|
+
--fm-disabled-opacity: 0.5;
|
43
|
+
--fm-background: var(--fm-gray-1);
|
44
|
+
--fm-background-white: var(--fm-white);
|
45
|
+
--fm-box-shadow-color: var(--fm-gray-1);
|
46
|
+
|
47
|
+
// Padding
|
48
|
+
--fm-padding-base: 4px;
|
49
|
+
--fm-padding-xs: 8px;
|
50
|
+
--fm-padding-sm: 12px;
|
51
|
+
--fm-padding-md: 16px;
|
52
|
+
--fm-padding-lg: 24px;
|
53
|
+
--fm-padding-xl: 32px;
|
54
|
+
--fm-padding-horizontal-xs: 0 var(--fm-padding-xs);
|
55
|
+
--fm-padding-horizontal-sm: 0 var(--fm-padding-sm);
|
56
|
+
--fm-padding-horizontal-md: 0 var(--fm-padding-md);
|
57
|
+
--fm-padding-horizontal-lg: 0 var(--fm-padding-lg);
|
58
|
+
|
59
|
+
// Margin
|
60
|
+
--fm-margin-base: 4px;
|
61
|
+
--fm-margin-xs: 8px;
|
62
|
+
--fm-margin-sm: 12px;
|
63
|
+
--fm-margin-md: 16px;
|
64
|
+
--fm-margin-lg: 24px;
|
65
|
+
--fm-margin-xl: 32px;
|
66
|
+
--fm-margin-horizontal-xs: 0 var(--fm-margin-xs);
|
67
|
+
--fm-margin-horizontal-sm: 0 var(--fm-margin-sm);
|
68
|
+
--fm-margin-horizontal-md: 0 var(--fm-margin-md);
|
69
|
+
--fm-margin-horizontal-lg: 0 var(--fm-margin-lg);
|
70
|
+
|
71
|
+
// Font
|
72
|
+
--fm-font-bold-light: 500;
|
73
|
+
--fm-font-bold: 600;
|
74
|
+
--fm-font-size: 16px;
|
75
|
+
--fm-line-height: 1.2;
|
76
|
+
|
77
|
+
--fm-font-size-xs: 10px;
|
78
|
+
--fm-font-size-sm: 12px;
|
79
|
+
--fm-font-size-md: 14px;
|
80
|
+
--fm-font-size-lg: 16px;
|
81
|
+
|
82
|
+
// Gradient Colors
|
83
|
+
--fm-gradient-blue: linear-gradient(-45deg,var(--fm-blue-2) 0%, var(--fm-blue) 100%);
|
84
|
+
--fm-gradient-orange: linear-gradient(-45deg,var(--fm-orange) 0%, var(--fm-orange-2) 100%);
|
85
|
+
|
86
|
+
/* stylelint-disable */
|
87
|
+
--fm-base-font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue',
|
88
|
+
Helvetica, Segoe UI, Arial, Roboto, 'PingFang SC', 'miui',
|
89
|
+
'Hiragino Sans GB', 'Microsoft Yahei', sans-serif;
|
90
|
+
--fm-price-font: avenir-heavy, 'PingFang SC', helvetica neue, arial,
|
91
|
+
sans-serif;
|
92
|
+
/* stylelint-enable */
|
93
|
+
|
94
|
+
// Animation
|
95
|
+
--fm-duration-base: 0.3s;
|
96
|
+
--fm-duration-fast: 0.2s;
|
97
|
+
--fm-ease-out: ease-out;
|
98
|
+
--fm-ease-in: ease-in;
|
99
|
+
|
100
|
+
// Border
|
101
|
+
--fm-noborder: none;
|
102
|
+
--fm-radius-sm: 2px;
|
103
|
+
--fm-radius-md: 4px;
|
104
|
+
--fm-radius-lg: 8px;
|
105
|
+
--fm-radius-max: 999px;
|
106
|
+
|
107
|
+
--fm-zindex-1: 9;
|
108
|
+
--fm-zindex-2: 10;
|
109
|
+
--fm-zindex-3: 99;
|
110
|
+
--fm-zindex-4: 100;
|
111
|
+
--fm-zindex-5: 999;
|
112
|
+
--fm-zindex-6: 1000;
|
113
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export * from './src/dom/event';
|
2
|
+
export * from './src/common';
|
3
|
+
export * from './src/hook';
|
4
|
+
export * from './src/number';
|
5
|
+
export * from './src/resove-asset';
|
6
|
+
export * from './src/throttle';
|
7
|
+
export * from './src/transition';
|
8
|
+
export * from './src/type';
|
9
|
+
export * from './src/date';
|
10
|
+
export * from './src/string';
|
11
|
+
export * from './src/use-appearance';
|
12
|
+
export * from './src/query-filter';
|
13
|
+
export * from './src/with-install';
|
14
|
+
export * from './src/with-register';
|
15
|
+
export * from './src/with-register-designer';
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { isDef, isNumeric, isObject } from './type';
|
2
|
+
|
3
|
+
export function noop() { }
|
4
|
+
|
5
|
+
export function addUnit(value: string | number) {
|
6
|
+
if (!isDef(value)) {
|
7
|
+
return undefined;
|
8
|
+
}
|
9
|
+
value = String(value);
|
10
|
+
return isNumeric(value) ? `${value}px` : value;
|
11
|
+
}
|
12
|
+
|
13
|
+
export const escapeHtml = (str: string) => {
|
14
|
+
if (str === null || str === undefined || str === '') {
|
15
|
+
return '';
|
16
|
+
}
|
17
|
+
return str
|
18
|
+
.replace(/&/g, '&')
|
19
|
+
.replace(/</g, '<')
|
20
|
+
.replace(/>/g, '>')
|
21
|
+
.replace(/"/g, '"')
|
22
|
+
.replace(/'/g, ''')
|
23
|
+
.replace(/\//g, '/');
|
24
|
+
};
|
25
|
+
|
26
|
+
export const unescapeHtml = (str: string) => {
|
27
|
+
if (str === null || str === undefined || str === '') {
|
28
|
+
return '';
|
29
|
+
}
|
30
|
+
return str
|
31
|
+
.replace(/&/g, '&')
|
32
|
+
.replace(/</g, '<')
|
33
|
+
.replace(/>/g, '>')
|
34
|
+
.replace(/"/g, '"')
|
35
|
+
.replace(/'/g, "'")
|
36
|
+
.replace(///g, '/');
|
37
|
+
};
|
38
|
+
|
39
|
+
export const getValue = (field: string, data: any, safe = false) => {
|
40
|
+
if (!data) {
|
41
|
+
return '';
|
42
|
+
}
|
43
|
+
let resultVal = '';
|
44
|
+
if (field.indexOf('.') === -1) {
|
45
|
+
resultVal = data[field];
|
46
|
+
} else {
|
47
|
+
resultVal = field.split('.').reduce((obj, key) => {
|
48
|
+
if (obj) {
|
49
|
+
return obj[key];
|
50
|
+
}
|
51
|
+
return null;
|
52
|
+
}, data);
|
53
|
+
}
|
54
|
+
|
55
|
+
if (safe) {
|
56
|
+
return escapeHtml(resultVal);
|
57
|
+
}
|
58
|
+
return resultVal;
|
59
|
+
};
|
60
|
+
|
61
|
+
export const setValue = (obj: Record<string, any>, field: string, val: any) => {
|
62
|
+
if(!obj || !field){
|
63
|
+
return;
|
64
|
+
}
|
65
|
+
if (field.indexOf('.') > 0) {
|
66
|
+
const fieldMap = field.split('.');
|
67
|
+
const target = fieldMap.slice(0, -1).reduce((record, fieldItem) => {
|
68
|
+
if(!isObject(record[fieldItem])) {
|
69
|
+
record[fieldItem] = {};
|
70
|
+
}
|
71
|
+
return record[fieldItem];
|
72
|
+
}, obj);
|
73
|
+
|
74
|
+
if (target) {
|
75
|
+
const targetField = fieldMap.pop();
|
76
|
+
if (targetField) {
|
77
|
+
target[targetField] = val;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
} else {
|
81
|
+
obj[field] = val;
|
82
|
+
}
|
83
|
+
};
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import { isArray, isString } from './type';
|
2
|
+
|
3
|
+
export const getDateRecord = (target: Date) => {
|
4
|
+
const year = target.getFullYear();
|
5
|
+
const month = target.getMonth() + 1;
|
6
|
+
const day = target.getDate();
|
7
|
+
const hours = target.getHours();
|
8
|
+
const minutes = target.getMinutes();
|
9
|
+
const seconds = target.getSeconds();
|
10
|
+
|
11
|
+
return {
|
12
|
+
year,
|
13
|
+
month,
|
14
|
+
day,
|
15
|
+
hours,
|
16
|
+
minutes,
|
17
|
+
seconds
|
18
|
+
};
|
19
|
+
};
|
20
|
+
|
21
|
+
export const getTimeRecord = (value: string | number[]) => {
|
22
|
+
const [hours, minutes, seconds] = isString(value)
|
23
|
+
? value.split(':').map((item) => Number(item))
|
24
|
+
: isArray(value)
|
25
|
+
? value
|
26
|
+
: [0, 0, 0];
|
27
|
+
|
28
|
+
return {
|
29
|
+
hours,
|
30
|
+
minutes,
|
31
|
+
seconds
|
32
|
+
};
|
33
|
+
};
|
34
|
+
|
35
|
+
export const isLeap = (year: number) => {
|
36
|
+
return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
|
37
|
+
};
|
38
|
+
|
39
|
+
export const formatTime = (
|
40
|
+
value: { hours: number; minutes: number; seconds: number },
|
41
|
+
format: string
|
42
|
+
) => {
|
43
|
+
const { hours, minutes, seconds } = value;
|
44
|
+
return format
|
45
|
+
.replace('HH', String(hours).padStart(2, '0'))
|
46
|
+
.replace('mm', String(minutes).padStart(2, '0'))
|
47
|
+
.replace('ss', String(seconds).padStart(2, '0'));
|
48
|
+
};
|
49
|
+
|
50
|
+
export const parseTime = (value: string) => {
|
51
|
+
const timeRegex = /^(\d{2}):(\d{2}):(\d{2})$/;
|
52
|
+
const match = value.match(timeRegex);
|
53
|
+
|
54
|
+
if (!match) {
|
55
|
+
throw new Error('Invalid time format');
|
56
|
+
}
|
57
|
+
|
58
|
+
const [_, hours, minutes, seconds] = match;
|
59
|
+
|
60
|
+
return new Date(0, 0, 0, parseInt(hours, 10), parseInt(minutes, 10), parseInt(seconds, 10));
|
61
|
+
};
|
62
|
+
|
63
|
+
export const formatDate = (value: Date, format: string) => {
|
64
|
+
const { year, month, day, hours, minutes, seconds } = getDateRecord(value);
|
65
|
+
return format
|
66
|
+
.replace('YYYY', String(year))
|
67
|
+
.replace('MM', String(month).padStart(2, '0'))
|
68
|
+
.replace('DD', String(day).padStart(2, '0'))
|
69
|
+
.replace('HH', String(hours).padStart(2, '0'))
|
70
|
+
.replace('mm', String(minutes).padStart(2, '0'))
|
71
|
+
.replace('ss', String(seconds).padStart(2, '0'));
|
72
|
+
};
|
73
|
+
|
74
|
+
export const parseDate = (value: string, format: string) => {
|
75
|
+
const [dateValue, timeValue] = value.split(' ');
|
76
|
+
const [dateFormat, timeFormat] = format.split(' ');
|
77
|
+
|
78
|
+
const dateRegex = /年|月|日|-|\//g;
|
79
|
+
|
80
|
+
const formatParts = dateFormat.replace(dateRegex, '-').split('-');
|
81
|
+
const formatMap = formatParts.reduce((map, part, index) => {
|
82
|
+
map[part] = index;
|
83
|
+
return map;
|
84
|
+
}, {} as Record<string, number>);
|
85
|
+
|
86
|
+
const dateValueParts = dateValue
|
87
|
+
.replace(dateRegex, '-')
|
88
|
+
.split('-')
|
89
|
+
.map((item) => Number(item));
|
90
|
+
|
91
|
+
const year = dateValueParts[formatMap.YYYY];
|
92
|
+
const month = dateValueParts[formatMap.MM] ? dateValueParts[formatMap.MM] - 1 : 0;
|
93
|
+
const day = dateValueParts[formatMap.DD] || 1;
|
94
|
+
|
95
|
+
const { hours, minutes, seconds } = getTimeRecord(timeValue);
|
96
|
+
|
97
|
+
// 创建Date对象
|
98
|
+
const parsedDate = new Date(year, month, day, hours, minutes, seconds);
|
99
|
+
|
100
|
+
// 检查是否有效日期
|
101
|
+
if (isNaN(parsedDate as any)) {
|
102
|
+
throw new Error('Invalid date format');
|
103
|
+
}
|
104
|
+
|
105
|
+
return parsedDate;
|
106
|
+
};
|
107
|
+
|
108
|
+
export const compareDate = (firstDate: Date, secondDate: Date) => {
|
109
|
+
return firstDate.getTime() - secondDate.getTime();
|
110
|
+
};
|
111
|
+
|
112
|
+
export const isEqualDate = (firstDate: Date, secondDate: Date) => {
|
113
|
+
const {
|
114
|
+
year: firstDateYear,
|
115
|
+
month: firstDateMonth,
|
116
|
+
day: firstDateDay
|
117
|
+
} = getDateRecord(firstDate);
|
118
|
+
const {
|
119
|
+
year: secondDateYear,
|
120
|
+
month: secondDateMonth,
|
121
|
+
day: secondDateDay
|
122
|
+
} = getDateRecord(secondDate);
|
123
|
+
|
124
|
+
return (
|
125
|
+
compareDate(
|
126
|
+
new Date(firstDateYear, firstDateMonth, firstDateDay),
|
127
|
+
new Date(secondDateYear, secondDateMonth, secondDateDay)
|
128
|
+
) === 0
|
129
|
+
);
|
130
|
+
};
|
131
|
+
|
132
|
+
export const isEqualDateTime = (firstDate: Date, secondDate: Date) => {
|
133
|
+
return compareDate(firstDate, secondDate) === 0;
|
134
|
+
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
export function stopPropagation(event: Event) {
|
2
|
+
event.stopPropagation();
|
3
|
+
}
|
4
|
+
|
5
|
+
export function preventDefault(event: Event, isStopPropagation?: boolean) {
|
6
|
+
/* istanbul ignore else */
|
7
|
+
if (typeof event.cancelable !== 'boolean' || event.cancelable) {
|
8
|
+
event.preventDefault();
|
9
|
+
}
|
10
|
+
|
11
|
+
if (isStopPropagation) {
|
12
|
+
stopPropagation(event);
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export function trigger(target: Element, type: string) {
|
17
|
+
const inputEvent = document.createEvent('HTMLEvents');
|
18
|
+
inputEvent.initEvent(type, true, true);
|
19
|
+
target.dispatchEvent(inputEvent);
|
20
|
+
}
|
21
|
+
|
22
|
+
// ios event没有path属性
|
23
|
+
export const initNodePath = (event: Event) => {
|
24
|
+
const path: any[] = [];
|
25
|
+
let currentElem: any = event.target;
|
26
|
+
while (currentElem) {
|
27
|
+
path.push(currentElem);
|
28
|
+
currentElem = currentElem.parentElement;
|
29
|
+
}
|
30
|
+
if (path.indexOf(window) === -1 && path.indexOf(document) === -1) {
|
31
|
+
path.push(document);
|
32
|
+
}
|
33
|
+
if (path.indexOf(window) === -1) {
|
34
|
+
path.push(window);
|
35
|
+
}
|
36
|
+
return path;
|
37
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { nextTick, onMounted, onActivated } from 'vue';
|
2
|
+
|
3
|
+
export function onMountedOrActivated(hook: () => any) {
|
4
|
+
let mounted: boolean;
|
5
|
+
|
6
|
+
onMounted(() => {
|
7
|
+
hook();
|
8
|
+
nextTick(() => {
|
9
|
+
mounted = true;
|
10
|
+
});
|
11
|
+
});
|
12
|
+
|
13
|
+
onActivated(() => {
|
14
|
+
if (mounted) {
|
15
|
+
hook();
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { trimExtraChar } from './string';
|
2
|
+
import { isDef } from './type';
|
3
|
+
|
4
|
+
export function formatToNumber(value: string, allowDot: boolean) {
|
5
|
+
value = isDef(value) ? value : '';
|
6
|
+
let regExp = /[^-0-9]/g;
|
7
|
+
value = trimExtraChar(value, '-', /-/g);
|
8
|
+
if (allowDot) {
|
9
|
+
value = trimExtraChar(value, '.', /\./g);
|
10
|
+
regExp = /[^-0-9.]/g;
|
11
|
+
} else {
|
12
|
+
value = value.split('.')[0];
|
13
|
+
}
|
14
|
+
return value.replace(regExp, '');
|
15
|
+
}
|
16
|
+
|
17
|
+
export function parseFloat(value: string | number, precision = 0) {
|
18
|
+
return Number.parseFloat(value ? String(value) : '0').toFixed(precision);
|
19
|
+
}
|
20
|
+
|
21
|
+
export function range(num: number, min: number, max: number): number {
|
22
|
+
return Math.min(Math.max(num, min), max);
|
23
|
+
}
|
24
|
+
export function random(min: number, max: number) {
|
25
|
+
return Math.round(Math.random() * (max - min) + min);
|
26
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
export enum FilterCompareType {
|
3
|
+
Equal = 0,
|
4
|
+
NotEqual = 1,
|
5
|
+
Greater = 2,
|
6
|
+
GreaterOrEqual = 3,
|
7
|
+
Less = 4,
|
8
|
+
LessOrEqual = 5,
|
9
|
+
Like = 6,
|
10
|
+
LikeStartWith = 7,
|
11
|
+
LikeEndWith = 8,
|
12
|
+
NotLike = 9,
|
13
|
+
NotLikeStartWith = 10,
|
14
|
+
NotLikeEndWith = 11,
|
15
|
+
Is = 12,
|
16
|
+
IsNot = 13,
|
17
|
+
In = 14,
|
18
|
+
NotIn = 15,
|
19
|
+
}
|
20
|
+
|
21
|
+
export enum FilterRelation {
|
22
|
+
Empty,
|
23
|
+
And,
|
24
|
+
Or,
|
25
|
+
}
|
26
|
+
|
27
|
+
export enum FilterExpressType {
|
28
|
+
Value = 0,
|
29
|
+
Expression = 1,
|
30
|
+
}
|
31
|
+
|
32
|
+
export interface FilterCondition {
|
33
|
+
FilterField: string
|
34
|
+
Compare: FilterCompareType
|
35
|
+
Value: string
|
36
|
+
Relation: FilterRelation
|
37
|
+
Expresstype: FilterExpressType
|
38
|
+
Lbracket: string
|
39
|
+
Rbracket: string
|
40
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
const getKebabCase = (str: string) => {
|
2
|
+
return str.replace(/[A-Z]/g, function (i) {
|
3
|
+
return "-" + i.toLowerCase();
|
4
|
+
});
|
5
|
+
};
|
6
|
+
const getCamelCase = (str: string) => {
|
7
|
+
return str.replace(/-([a-z])/g, function (all, i) {
|
8
|
+
return i.toUpperCase();
|
9
|
+
});
|
10
|
+
};
|
11
|
+
|
12
|
+
const hasOwn = (v: object, s: string)=> Object.prototype.hasOwnProperty.call(v, s);
|
13
|
+
|
14
|
+
export function resolveAsset (
|
15
|
+
assets: Record<string, any>,
|
16
|
+
id: string
|
17
|
+
): any {
|
18
|
+
/* istanbul ignore if */
|
19
|
+
if (typeof id !== 'string') {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
// check local registration variations first
|
23
|
+
if (hasOwn(assets, id)) {return assets[id];}
|
24
|
+
const camelizedId = getKebabCase(id);
|
25
|
+
if (hasOwn(assets, camelizedId)) {return assets[camelizedId];}
|
26
|
+
const PascalCaseId = getCamelCase(camelizedId);
|
27
|
+
if (hasOwn(assets, PascalCaseId)) {return assets[PascalCaseId];}
|
28
|
+
|
29
|
+
// fallback to prototype chain
|
30
|
+
const res = assets[id] || assets[camelizedId] || assets[PascalCaseId];
|
31
|
+
|
32
|
+
return res;
|
33
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export function trimExtraChar(value: string, char: string, regExp: RegExp) {
|
2
|
+
const index = value.indexOf(char);
|
3
|
+
|
4
|
+
if (index === -1) {
|
5
|
+
return value;
|
6
|
+
}
|
7
|
+
|
8
|
+
if (char === '-' && index !== 0) {
|
9
|
+
return value.slice(0, index);
|
10
|
+
}
|
11
|
+
|
12
|
+
return value.slice(0, index + 1) + value.slice(index).replace(regExp, '');
|
13
|
+
};
|
14
|
+
|
15
|
+
export function camelToKebabCase(camelStr: string) {
|
16
|
+
// 首字母转小写,其余每个大写字母前加下划线并转小写
|
17
|
+
return camelStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
18
|
+
}
|