@archbiz/element-ui 0.0.0-stage → 0.1.1
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/dist/element-ui.cjs +11 -0
- package/dist/element-ui.js +5518 -0
- package/dist/style.css +1 -0
- package/package.json +50 -4
- package/src/components/ab-checkbox.vue +51 -0
- package/src/components/ab-color-picker.vue +39 -0
- package/src/components/ab-detail/ab-detail.vue +285 -0
- package/src/components/ab-detail/index.js +1 -0
- package/src/components/ab-drawer/ab-drawer.vue +50 -0
- package/src/components/ab-drawer/index.js +3 -0
- package/src/components/ab-icon/ab-icon.vue +90 -0
- package/src/components/ab-icon/index.js +1 -0
- package/src/components/ab-input-number.vue +49 -0
- package/src/components/ab-input-range.vue +90 -0
- package/src/components/ab-radio.vue +51 -0
- package/src/components/ab-router-link.vue +46 -0
- package/src/components/ab-search/ab-search.vue +168 -0
- package/src/components/ab-search/index.js +4 -0
- package/src/components/ab-select.vue +107 -0
- package/src/components/ab-table/ab-table-column.vue +131 -0
- package/src/components/ab-table/ab-table-columns.vue +62 -0
- package/src/components/ab-table/ab-table-operate.vue +160 -0
- package/src/components/ab-table/ab-table.vue +316 -0
- package/src/components/ab-table/columns.js +90 -0
- package/src/components/ab-table/footer.js +77 -0
- package/src/components/ab-table/formatter.js +2 -0
- package/src/components/ab-table/index.js +8 -0
- package/src/components/ab-table/utils.js +36 -0
- package/src/components/ab-time-period.vue +116 -0
- package/src/components/ab-time-picker.vue +38 -0
- package/src/components/ab-toolbar/ab-toolbar.vue +102 -0
- package/src/components/ab-toolbar/index.js +1 -0
- package/src/components/ab-tree-select.vue +456 -0
- package/src/components/ab-upload-file.vue +277 -0
- package/src/components/index.js +27 -0
- package/src/core/ab-form.js +25 -0
- package/src/core/alias.js +36 -0
- package/src/core/config.js +65 -0
- package/src/core/form-render.js +256 -0
- package/src/core/options.js +25 -0
- package/src/hooks/use-cache.js +75 -0
- package/src/index.js +39 -0
- package/src/makers/datePicker.js +8 -0
- package/src/makers/frame.js +23 -0
- package/src/makers/index.js +23 -0
- package/src/makers/input.js +12 -0
- package/src/makers/select.js +8 -0
- package/src/makers/slider.js +7 -0
- package/src/makers/timePicker.js +8 -0
- package/src/makers/tree.js +10 -0
- package/src/makers/upload.js +20 -0
- package/src/parsers/checkbox.js +5 -0
- package/src/parsers/colorPicker.js +29 -0
- package/src/parsers/datePicker.js +24 -0
- package/src/parsers/frame.js +17 -0
- package/src/parsers/hidden.js +11 -0
- package/src/parsers/index.js +36 -0
- package/src/parsers/input.js +15 -0
- package/src/parsers/number.js +29 -0
- package/src/parsers/radio.js +5 -0
- package/src/parsers/select.js +15 -0
- package/src/parsers/slider.js +21 -0
- package/src/parsers/switch.js +11 -0
- package/src/parsers/text.js +25 -0
- package/src/parsers/timePicker.js +12 -0
- package/src/parsers/tree.js +37 -0
- package/src/parsers/upload.js +35 -0
- package/src/plugins/ab-detail.js +7 -0
- package/src/plugins/ab-drawer.js +7 -0
- package/src/plugins/ab-form.js +14 -0
- package/src/plugins/ab-search.js +7 -0
- package/src/plugins/ab-table.js +15 -0
- package/src/plugins/ab-toolbar.js +7 -0
- package/src/rule/defaults.js +187 -0
- package/src/rule/formatter.js +218 -0
- package/src/style/index.css +356 -0
- package/src/utils/formatter.js +188 -0
- package/src/utils/router-link.js +59 -0
- package/README.md +0 -3
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* theme color */
|
|
3
|
+
--el-color-primary: #1890ff;
|
|
4
|
+
--el-color-success: #13ce66;
|
|
5
|
+
--el-color-warning: #ffba00;
|
|
6
|
+
--el-color-danger: #ff4949;
|
|
7
|
+
|
|
8
|
+
--el-card-padding: 12px;
|
|
9
|
+
}
|
|
10
|
+
/* 默认滚动条 */
|
|
11
|
+
::-webkit-scrollbar {
|
|
12
|
+
width: 7px;
|
|
13
|
+
height: 7px;
|
|
14
|
+
}
|
|
15
|
+
::-webkit-scrollbar:horizontal {
|
|
16
|
+
height: 7px;
|
|
17
|
+
}
|
|
18
|
+
::-webkit-scrollbar:vertical {
|
|
19
|
+
height: 7px;
|
|
20
|
+
}
|
|
21
|
+
::-webkit-scrollbar-thumb {
|
|
22
|
+
background-color: rgba(0, 0, 0, 0.3); /* 滑块 */
|
|
23
|
+
border-radius: 4px;
|
|
24
|
+
}
|
|
25
|
+
::-webkit-scrollbar-track {
|
|
26
|
+
background-color: transparent; /* 背景 */
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.el-card .el-card__body {
|
|
30
|
+
padding: var(--el-card-padding);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/* uno */
|
|
34
|
+
.w-full {
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
.sticky {
|
|
38
|
+
position: sticky;
|
|
39
|
+
}
|
|
40
|
+
.top-0 {
|
|
41
|
+
top: 0;
|
|
42
|
+
}
|
|
43
|
+
.z-9 {
|
|
44
|
+
z-index: 9;
|
|
45
|
+
}
|
|
46
|
+
.flex {
|
|
47
|
+
display: flex;
|
|
48
|
+
}
|
|
49
|
+
.justify-end {
|
|
50
|
+
justify-content: flex-end;
|
|
51
|
+
}
|
|
52
|
+
.items-center {
|
|
53
|
+
align-items: center;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* 表单 */
|
|
57
|
+
|
|
58
|
+
.ab-form,
|
|
59
|
+
.ab-form .el-row {
|
|
60
|
+
width: 100%;
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: row;
|
|
63
|
+
flex-wrap: wrap;
|
|
64
|
+
}
|
|
65
|
+
.ab-form .el-form-item {
|
|
66
|
+
--el-form-item-margin-bottom: 6px;
|
|
67
|
+
margin-bottom: var(--el-form-item-margin-bottom) !important;
|
|
68
|
+
margin-right: 0 !important;
|
|
69
|
+
}
|
|
70
|
+
.ab-form .el-form-item.w-full {
|
|
71
|
+
display: flex;
|
|
72
|
+
}
|
|
73
|
+
.ab-form .ab-search__operates {
|
|
74
|
+
margin-left: auto;
|
|
75
|
+
}
|
|
76
|
+
.ab-form .ab-search__operates .el-form-item__content {
|
|
77
|
+
flex: 1 1 auto !important;
|
|
78
|
+
display: flex;
|
|
79
|
+
justify-content: flex-end;
|
|
80
|
+
}
|
|
81
|
+
.ab-form .force-newline {
|
|
82
|
+
flex-basis: 100%;
|
|
83
|
+
}
|
|
84
|
+
.ab-form .el-divider {
|
|
85
|
+
width: 100%;
|
|
86
|
+
flex-basis: 100%;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.ab-form .el-form-item .el-input,
|
|
90
|
+
.ab-form .el-form-item .el-input-number,
|
|
91
|
+
.ab-form .el-form-item .el-select,
|
|
92
|
+
.ab-form .el-form-item .el-date-editor,
|
|
93
|
+
.ab-form .el-form-item .el-color-picker,
|
|
94
|
+
.ab-form .el-form-item .el-color-picker__trigger,
|
|
95
|
+
.ab-form .el-form-item .el-cascader,
|
|
96
|
+
.ab-form .el-form-item .ab-upload-file {
|
|
97
|
+
width: 100%;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ab-form .el-form-item > .el-form-item__content {
|
|
101
|
+
flex: 0 0 var(--ab-field-width);
|
|
102
|
+
width: var(--ab-field-width);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.ab-form.is-preview .ab-clock,
|
|
106
|
+
.ab-form .ab-none,
|
|
107
|
+
.ab-form.is-preview
|
|
108
|
+
.el-form-item.is-required
|
|
109
|
+
> .el-form-item__label-wrap
|
|
110
|
+
> .el-form-item__label:before,
|
|
111
|
+
.ab-form.is-preview .el-form-item.is-required > .el-form-item__label:before {
|
|
112
|
+
display: none !important;
|
|
113
|
+
}
|
|
114
|
+
/* color picker */
|
|
115
|
+
.ab-form .el-color-picker__color-inner {
|
|
116
|
+
display: flex;
|
|
117
|
+
justify-content: flex-end;
|
|
118
|
+
align-items: center;
|
|
119
|
+
padding-right: 6px;
|
|
120
|
+
box-sizing: border-box;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.ab-form .el-form-item .el-color-picker__empty,
|
|
124
|
+
.ab-form .el-form-item .el-color-picker__icon {
|
|
125
|
+
left: initial;
|
|
126
|
+
right: 0;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.ab-form .el-form-item .ab-color-picker__readonly {
|
|
130
|
+
display: flex;
|
|
131
|
+
align-items: center;
|
|
132
|
+
width: 100%;
|
|
133
|
+
min-height: var(--el-component-size-small);
|
|
134
|
+
border-radius: 5px;
|
|
135
|
+
box-sizing: border-box;
|
|
136
|
+
padding: 0 12px;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.ab-router-link {
|
|
140
|
+
color: var(--el-color-primary);
|
|
141
|
+
display: flex;
|
|
142
|
+
align-items: center;
|
|
143
|
+
text-decoration: none;
|
|
144
|
+
}
|
|
145
|
+
/* .ab-router-link .ab-icon {
|
|
146
|
+
padding: 0 3px 0 0;
|
|
147
|
+
} */
|
|
148
|
+
|
|
149
|
+
.ab-router-link:hover {
|
|
150
|
+
text-decoration: underline;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.ab-wrap-right > .el-form-item__label {
|
|
154
|
+
display: flex;
|
|
155
|
+
justify-content: flex-end;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.ab-wrap-left > .el-form-item__label {
|
|
159
|
+
display: flex;
|
|
160
|
+
justify-content: flex-start;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.ab-wrap-top.el-form-item {
|
|
164
|
+
display: block;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.ab-wrap-top.el-form-item > .el-form-item__label {
|
|
168
|
+
display: block;
|
|
169
|
+
height: auto;
|
|
170
|
+
line-height: 22px;
|
|
171
|
+
margin-bottom: 8px;
|
|
172
|
+
text-align: left;
|
|
173
|
+
float: unset;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.el-form--large .ab-wrap-top.el-form-item > .el-form-item__label {
|
|
177
|
+
line-height: 22px;
|
|
178
|
+
margin-bottom: 12px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.el-form--default .ab-wrap-top.el-form-item > .el-form-item__label {
|
|
182
|
+
line-height: 22px;
|
|
183
|
+
margin-bottom: 8px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.el-form--small .ab-wrap-top.el-form-item > .el-form-item__label {
|
|
187
|
+
line-height: 20px;
|
|
188
|
+
margin-bottom: 4px;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.ab-form-footer {
|
|
192
|
+
margin-top: 12px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.ab-form.is-numbered {
|
|
196
|
+
counter-reset: q;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.ab-form.is-numbered .ab-form-title {
|
|
200
|
+
counter-increment: q;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.ab-form.is-numbered .ab-form-title::before {
|
|
204
|
+
content: counter(q) ". ";
|
|
205
|
+
color: var(--ab-number-color, inherit);
|
|
206
|
+
font-weight: 600;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.ab-form.is-numbered.is-number-chinese .ab-form-title::before {
|
|
210
|
+
content: counter(q, simp-chinese-informal) "、";
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.el-select-dropdown__item {
|
|
214
|
+
display: flex;
|
|
215
|
+
justify-content: space-between;
|
|
216
|
+
align-items: center;
|
|
217
|
+
padding: 0;
|
|
218
|
+
margin: 0 20px;
|
|
219
|
+
|
|
220
|
+
.p-option__left {
|
|
221
|
+
flex: 1 1 auto;
|
|
222
|
+
padding: 0 32px 0 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.p-option__right {
|
|
226
|
+
min-width: 60px;
|
|
227
|
+
flex: 0 0 auto;
|
|
228
|
+
text-align: right;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.ab-form .w-full .el-form-item__label {
|
|
233
|
+
flex: 0 0 auto;
|
|
234
|
+
}
|
|
235
|
+
.ab-form .w-full .el-form-item__content {
|
|
236
|
+
width: 100%;
|
|
237
|
+
flex: 1 1 auto;
|
|
238
|
+
}
|
|
239
|
+
.ab-form .w-full .el-upload {
|
|
240
|
+
width: 100%;
|
|
241
|
+
text-align: right;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* detail */
|
|
245
|
+
.ab-detail__header .ab-detail__title {
|
|
246
|
+
width: 50%;
|
|
247
|
+
}
|
|
248
|
+
.ab-detail__header .ab-detail__opr .el-row {
|
|
249
|
+
justify-content: flex-end;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* table */
|
|
253
|
+
.ab-table {
|
|
254
|
+
/* height: 100%; */
|
|
255
|
+
height: calc(100% - 40px);
|
|
256
|
+
}
|
|
257
|
+
/* table icon */
|
|
258
|
+
/* .ab-table .el-button .ab-icon {
|
|
259
|
+
margin-right: 6px;
|
|
260
|
+
} */
|
|
261
|
+
|
|
262
|
+
/* toolbar */
|
|
263
|
+
.ab-toolbar__title {
|
|
264
|
+
font-size: 1.6em;
|
|
265
|
+
}
|
|
266
|
+
.ab-toolbar .ab-form {
|
|
267
|
+
margin-right: 8px;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/* table */
|
|
271
|
+
.ab-detail__header,
|
|
272
|
+
.ab-detail__header .el-card__body {
|
|
273
|
+
width: 100%;
|
|
274
|
+
display: flex;
|
|
275
|
+
justify-content: space-between;
|
|
276
|
+
align-items: center;
|
|
277
|
+
/* border-bottom: #eeeeee 1px solid; */
|
|
278
|
+
padding-left: var(--el-card-padding);
|
|
279
|
+
/* padding: 0; */
|
|
280
|
+
margin: 0;
|
|
281
|
+
box-sizing: border-box;
|
|
282
|
+
}
|
|
283
|
+
.ab-detail__title {
|
|
284
|
+
flex: 1 1 auto;
|
|
285
|
+
white-space: nowrap;
|
|
286
|
+
}
|
|
287
|
+
.ab-detail__opr {
|
|
288
|
+
flex: 1 1 auto;
|
|
289
|
+
display: flex;
|
|
290
|
+
justify-content: flex-end;
|
|
291
|
+
align-items: center;
|
|
292
|
+
}
|
|
293
|
+
.ab-detail__form {
|
|
294
|
+
margin-top: 1em;
|
|
295
|
+
}
|
|
296
|
+
/* footer */
|
|
297
|
+
.ab-table .vxe-table--footer-wrapper .vxe-footer--column {
|
|
298
|
+
/* background-color: var(--el-color-primary-light-9); */
|
|
299
|
+
background-color: var(--vxe-ui-table-header-background-color);
|
|
300
|
+
color: var(--el-color-primary-dark-2);
|
|
301
|
+
font-weight: 700;
|
|
302
|
+
}
|
|
303
|
+
/* 表格:状态颜色 */
|
|
304
|
+
.ab-table .vxe-body--column,
|
|
305
|
+
.ab-table .vxe-cell .ab-icon {
|
|
306
|
+
&.warning {
|
|
307
|
+
color: var(--el-color-warning);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
&.success {
|
|
311
|
+
color: var(--el-color-success);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
&.info {
|
|
315
|
+
color: var(--el-color-info);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
&.danger {
|
|
319
|
+
color: var(--el-color-danger);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
&.primary {
|
|
323
|
+
color: var(--el-color-primary);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
.ab-table .vxe-cell .ab-icon {
|
|
327
|
+
margin: 0 0 0 6px;
|
|
328
|
+
}
|
|
329
|
+
/* 表格垂直居中 */
|
|
330
|
+
.ab-table .items-center .vxe-cell--wrapper {
|
|
331
|
+
display: flex;
|
|
332
|
+
align-items: center;
|
|
333
|
+
justify-content: flex-end;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* ab-table-operate 文字按钮语义色 */
|
|
337
|
+
.el-button--text.primary:not(.is-disabled) {
|
|
338
|
+
color: var(--el-color-primary, #409eff);
|
|
339
|
+
}
|
|
340
|
+
.el-button--text.success:not(.is-disabled) {
|
|
341
|
+
color: var(--el-color-success, #67c23a);
|
|
342
|
+
}
|
|
343
|
+
.el-button--text.warning:not(.is-disabled) {
|
|
344
|
+
color: var(--el-color-warning, #e6a23c);
|
|
345
|
+
}
|
|
346
|
+
.el-button--text.danger:not(.is-disabled) {
|
|
347
|
+
color: var(--el-color-danger, #ff4949);
|
|
348
|
+
}
|
|
349
|
+
.el-button--text.info:not(.is-disabled) {
|
|
350
|
+
color: var(--el-color-info, #909399);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/* 数字输入前后缀 */
|
|
354
|
+
.ab-input-number .el-input__inner {
|
|
355
|
+
text-align: right;
|
|
356
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
2
|
+
|
|
3
|
+
export function isFieldEmpty(val) {
|
|
4
|
+
return typeof val === "undefined" || val === "undefined" || val === "null" || val === null || val === "" || (typeof val === "number" && isNaN(val));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function valueCurrency(val) {
|
|
8
|
+
if (isFieldEmpty(val)) return val;
|
|
9
|
+
return new Intl.NumberFormat("zh-CN", { style: "currency", currency: "CNY" }).format(val);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function valueNumber(val) {
|
|
13
|
+
if (isFieldEmpty(val)) return val;
|
|
14
|
+
return (Math.round(val * 100) / 100).toLocaleString();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function valueInteger(val) {
|
|
18
|
+
if (isFieldEmpty(val)) return val;
|
|
19
|
+
return Math.round(val).toLocaleString();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function valueDecimal(val, len = 2) {
|
|
23
|
+
if (isFieldEmpty(val)) return val;
|
|
24
|
+
return (Math.round(val * 10 ** len) / 10 ** len).toLocaleString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function valueDecimal2(val) {
|
|
28
|
+
return valueDecimal(val, 2);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function valueArea(val) {
|
|
32
|
+
if (isFieldEmpty(val)) return val;
|
|
33
|
+
return valueNumber(val) + " m²";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function valueHours(val) {
|
|
37
|
+
if (isFieldEmpty(val)) return val;
|
|
38
|
+
return valueNumber(val) + " 小时";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function valuePercentByDecimal(val) {
|
|
42
|
+
if (isFieldEmpty(val)) return val;
|
|
43
|
+
return Math.round(val * 10000) / 100 + " %";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function valuePercentByNumber(val) {
|
|
47
|
+
if (isFieldEmpty(val)) return val;
|
|
48
|
+
return Math.round(val * 100) / 100 + " %";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function valuePercentByInteger(val) {
|
|
52
|
+
if (isFieldEmpty(val)) return val;
|
|
53
|
+
return Math.round(val * 100) / 100 + " %";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function valueTenThousand(val) {
|
|
57
|
+
if (isFieldEmpty(val)) return val;
|
|
58
|
+
return Math.round(val / 10000).toLocaleString() + " 万";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function toDate(val) {
|
|
62
|
+
if (val instanceof Date) return val;
|
|
63
|
+
if (typeof val === "number") return new Date(val);
|
|
64
|
+
if (typeof val === "string") {
|
|
65
|
+
const text = val.trim();
|
|
66
|
+
if (/^\d+$/.test(text)) return new Date(Number(text));
|
|
67
|
+
return new Date(text);
|
|
68
|
+
}
|
|
69
|
+
return new Date(val);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isoWeek(date) {
|
|
73
|
+
const target = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
|
|
74
|
+
const day = target.getUTCDay() || 7;
|
|
75
|
+
target.setUTCDate(target.getUTCDate() + 4 - day);
|
|
76
|
+
const yearStart = new Date(Date.UTC(target.getUTCFullYear(), 0, 1));
|
|
77
|
+
return {
|
|
78
|
+
year: target.getUTCFullYear(),
|
|
79
|
+
week: Math.ceil(((target - yearStart) / 86400000 + 1) / 7),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function valueDate(val, ft = "YYYY-MM-DD") {
|
|
84
|
+
if (val === null || val === undefined || val === "") return val;
|
|
85
|
+
const date = toDate(val);
|
|
86
|
+
if (isNaN(date.getTime())) return val;
|
|
87
|
+
const week = isoWeek(date);
|
|
88
|
+
const tokens = {
|
|
89
|
+
YYYY: String(date.getFullYear()),
|
|
90
|
+
MM: pad(date.getMonth() + 1),
|
|
91
|
+
DD: pad(date.getDate()),
|
|
92
|
+
HH: pad(date.getHours()),
|
|
93
|
+
mm: pad(date.getMinutes()),
|
|
94
|
+
ss: pad(date.getSeconds()),
|
|
95
|
+
Q: String(Math.floor(date.getMonth() / 3) + 1),
|
|
96
|
+
W: String(week.week),
|
|
97
|
+
GGGG: String(week.year),
|
|
98
|
+
};
|
|
99
|
+
return ft.replace(/YYYY|MM|DD|HH|mm|ss|Q|W|GGGG/g, (token) => tokens[token]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function valueTime(val, ft = "HH:mm") {
|
|
103
|
+
if (val === null || val === undefined || (Array.isArray(val) && !val.length)) return "";
|
|
104
|
+
if (typeof val === "string" && /^\d{1,2}:\d{2}/.test(val.trim())) return val.trim();
|
|
105
|
+
if (Array.isArray(val)) {
|
|
106
|
+
const [hour = 0, minute = 0] = val;
|
|
107
|
+
return `${pad(Number(hour))}:${pad(Number(minute))}`;
|
|
108
|
+
}
|
|
109
|
+
return valueDate(val, ft);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function optionsFormatter(options, value, field = "label", by) {
|
|
113
|
+
if (Array.isArray(value) && !value.length) return "";
|
|
114
|
+
let target = value;
|
|
115
|
+
if (Array.isArray(target)) target = target.map((item) => String(item).trim());
|
|
116
|
+
else if (target !== null && target !== undefined) target = String(target).trim();
|
|
117
|
+
if (!options || !options.length) return isFieldEmpty(target) ? "" : target;
|
|
118
|
+
|
|
119
|
+
const matchBy = (item) => {
|
|
120
|
+
if (!Array.isArray(by) || !by.length) return true;
|
|
121
|
+
return by.some((rule) => {
|
|
122
|
+
if (!rule || typeof rule !== "object") return true;
|
|
123
|
+
return Object.entries(rule).every(([key, expected]) => {
|
|
124
|
+
const actual = item ? item[key] : undefined;
|
|
125
|
+
if (expected === undefined || expected === null) return actual === expected;
|
|
126
|
+
if (Array.isArray(expected)) return expected.some((candidate) => String(actual) === String(candidate));
|
|
127
|
+
if (Array.isArray(actual)) return actual.some((candidate) => String(candidate) === String(expected));
|
|
128
|
+
return String(actual) === String(expected);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const matched = Array.isArray(target)
|
|
134
|
+
? options.filter((option) => target.includes(String(option.value)) && matchBy(option))
|
|
135
|
+
: options.filter((option) => (option.value === target || String(option.value) === String(target)) && matchBy(option));
|
|
136
|
+
|
|
137
|
+
if (matched.length) {
|
|
138
|
+
const labels = matched.map((option) => option[field]).filter((label) => label !== undefined && label !== null && label !== "");
|
|
139
|
+
return [...new Set(labels)].join("、");
|
|
140
|
+
}
|
|
141
|
+
return Array.isArray(target) || isFieldEmpty(target) ? "" : target;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const vxeDate = ({ cellValue } = {}, ft = "YYYY-MM-DD") => valueDate(cellValue, ft);
|
|
145
|
+
export const vxeDateTime = ({ cellValue } = {}, ft = "YYYY-MM-DD HH:mm") => valueDate(cellValue, ft);
|
|
146
|
+
export const vxeDateY = ({ cellValue } = {}, ft = "YYYY") => valueDate(cellValue, ft);
|
|
147
|
+
export const vxeDateQ = ({ cellValue } = {}, ft = "Q") => {
|
|
148
|
+
if (cellValue === null || cellValue === undefined || cellValue === "" || isNaN(toDate(cellValue).getTime())) return cellValue;
|
|
149
|
+
return `${valueDate(cellValue, "YYYY")}年${valueDate(cellValue, ft)}季度`;
|
|
150
|
+
};
|
|
151
|
+
export const vxeDateM = ({ cellValue } = {}, ft = "MM") => {
|
|
152
|
+
if (cellValue === null || cellValue === undefined || cellValue === "" || isNaN(toDate(cellValue).getTime())) return cellValue;
|
|
153
|
+
return `${valueDate(cellValue, "YYYY")}年 ${valueDate(cellValue, ft)}月`;
|
|
154
|
+
};
|
|
155
|
+
export const vxeDateW = ({ cellValue } = {}, ft = "W") => {
|
|
156
|
+
if (cellValue === null || cellValue === undefined || cellValue === "") return cellValue;
|
|
157
|
+
const formatted = typeof cellValue === "string" ? /^(\d{4})-(\d{1,2})(?:st|nd|rd|th|周)$/i.exec(cellValue) : null;
|
|
158
|
+
if (!formatted && isNaN(toDate(cellValue).getTime())) return cellValue;
|
|
159
|
+
const week = isoWeek(toDate(cellValue));
|
|
160
|
+
return `${formatted ? formatted[1] : week.year}年第${formatted ? formatted[2] : valueDate(cellValue, ft)}周`;
|
|
161
|
+
};
|
|
162
|
+
export const vxeTime = ({ cellValue } = {}, ft = "HH:mm") => valueTime(cellValue, ft);
|
|
163
|
+
export const vxeNumber = ({ cellValue, itemValue } = {}) => {
|
|
164
|
+
const value = cellValue === undefined || cellValue === null ? itemValue : cellValue;
|
|
165
|
+
return isFieldEmpty(value) ? value : valueNumber(value);
|
|
166
|
+
};
|
|
167
|
+
export const vxeInteger = ({ cellValue, itemValue } = {}) => {
|
|
168
|
+
const value = cellValue || itemValue;
|
|
169
|
+
return isFieldEmpty(value) ? value : valueInteger(value);
|
|
170
|
+
};
|
|
171
|
+
export const vxePercent = ({ cellValue } = {}) => (isFieldEmpty(cellValue) ? cellValue : valuePercentByDecimal(cellValue));
|
|
172
|
+
export const vxeMeter = ({ cellValue, itemValue } = {}) => {
|
|
173
|
+
const value = typeof cellValue === "undefined" || cellValue === null ? itemValue : cellValue;
|
|
174
|
+
return isFieldEmpty(value) ? value : valueNumber(value) + " m";
|
|
175
|
+
};
|
|
176
|
+
export const vxeArea = ({ cellValue, itemValue } = {}) => {
|
|
177
|
+
const value = typeof cellValue === "undefined" || cellValue === null ? itemValue : cellValue;
|
|
178
|
+
return isFieldEmpty(value) ? value : valueNumber(value) + " m²";
|
|
179
|
+
};
|
|
180
|
+
export const vxeDistanceM = ({ cellValue, itemValue } = {}) => {
|
|
181
|
+
const value = typeof cellValue === "undefined" || cellValue === null ? itemValue : cellValue;
|
|
182
|
+
return isFieldEmpty(value) ? value : valueNumber(value) + " m";
|
|
183
|
+
};
|
|
184
|
+
export const vxePercentByNumber = ({ cellValue } = {}) => (isFieldEmpty(cellValue) ? cellValue : valuePercentByNumber(cellValue));
|
|
185
|
+
export const vxeCurrency = ({ cellValue, itemValue } = {}) => {
|
|
186
|
+
const value = isFieldEmpty(cellValue) ? itemValue : cellValue;
|
|
187
|
+
return isFieldEmpty(value) ? value : valueCurrency(value);
|
|
188
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function isNamedLinkConfig(link) {
|
|
2
|
+
return typeof link === "object" && link !== null && "name" in link && typeof link.name === "string";
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function isRouterLinkConfig(link) {
|
|
6
|
+
return typeof link === "string" || typeof link === "function" || isNamedLinkConfig(link);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function toQueryValue(value) {
|
|
10
|
+
if (value === null || value === undefined || typeof value === "string" || typeof value === "number") return value;
|
|
11
|
+
return String(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function toParamValue(value) {
|
|
15
|
+
if (value === null || value === undefined) return undefined;
|
|
16
|
+
return typeof value === "string" || typeof value === "number" ? value : String(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function resolveRouterLink(link, value, row) {
|
|
20
|
+
if (value === null || value === undefined || value === "") return undefined;
|
|
21
|
+
|
|
22
|
+
if (typeof link === "function") {
|
|
23
|
+
return link(row);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (typeof link === "string") {
|
|
27
|
+
return { name: link, query: { id: toQueryValue(value) } };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isNamedLinkConfig(link)) return undefined;
|
|
31
|
+
|
|
32
|
+
const route = { name: link.name };
|
|
33
|
+
|
|
34
|
+
const query = link.query;
|
|
35
|
+
if (typeof query === "string") {
|
|
36
|
+
route.query = { [query]: toQueryValue(value) };
|
|
37
|
+
} else if (query) {
|
|
38
|
+
route.query = {};
|
|
39
|
+
Object.keys(query).forEach((key) => {
|
|
40
|
+
const field = query[key];
|
|
41
|
+
route.query[key] = toQueryValue(row[field]);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const params = link.params;
|
|
46
|
+
if (typeof params === "string") {
|
|
47
|
+
const param = toParamValue(value);
|
|
48
|
+
if (param !== undefined) route.params = { [params]: param };
|
|
49
|
+
} else if (params) {
|
|
50
|
+
route.params = {};
|
|
51
|
+
Object.keys(params).forEach((key) => {
|
|
52
|
+
const field = params[key];
|
|
53
|
+
const param = toParamValue(row[field]);
|
|
54
|
+
if (param !== undefined) route.params[key] = param;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return route;
|
|
59
|
+
}
|
package/README.md
DELETED