@mptw/skylens-ui 1.4.94 → 1.4.96
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/components/SLCheckbox.vue +41 -21
- package/package.json +1 -1
- package/utils/index.ts +5 -6
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
.checkbox(:class='[checkboxClass, { inactive: !interactive }]')
|
|
3
3
|
input(
|
|
4
4
|
type='checkbox',
|
|
5
|
-
:id='uid',
|
|
6
5
|
:checked='isChecked',
|
|
7
6
|
:value='value',
|
|
8
7
|
:disabled='disabled',
|
|
9
|
-
@change='onChanged'
|
|
10
8
|
)
|
|
11
|
-
label(:
|
|
9
|
+
label(:class='{ "is-check-some": isCheckSome }', @click='onClickedLabel')
|
|
12
10
|
SLIcon.icon-square(:icon='falseIcon')
|
|
13
11
|
SLIcon.icon-check-square(:icon='trueIcon')
|
|
14
12
|
SLIcon.icon-minus-square(icon='minus-square')
|
|
@@ -18,6 +16,7 @@
|
|
|
18
16
|
|
|
19
17
|
<script lang="ts">
|
|
20
18
|
import { isEqual } from "lodash-es";
|
|
19
|
+
import type IInputOption from "~ui/interface/IInputOption";
|
|
21
20
|
import { getUID } from "~ui/utils";
|
|
22
21
|
|
|
23
22
|
export default defineComponent({
|
|
@@ -69,10 +68,18 @@ export default defineComponent({
|
|
|
69
68
|
type: Boolean,
|
|
70
69
|
default: true,
|
|
71
70
|
},
|
|
71
|
+
options: {
|
|
72
|
+
type: Array as PropType<IInputOption[] | undefined>,
|
|
73
|
+
default: () => undefined,
|
|
74
|
+
},
|
|
75
|
+
lastCheckValue: {
|
|
76
|
+
type: [Number, String, Boolean, Object],
|
|
77
|
+
default: null,
|
|
78
|
+
},
|
|
72
79
|
},
|
|
73
|
-
emits: ["update:modelValue"],
|
|
80
|
+
emits: ["update:modelValue", 'update:lastCheckValue'],
|
|
74
81
|
setup(props, { emit }) {
|
|
75
|
-
const { size, disabled, modelValue, trueValue, falseValue, value } =
|
|
82
|
+
const { size, disabled, modelValue, trueValue, falseValue, value, options, lastCheckValue } =
|
|
76
83
|
toRefs(props);
|
|
77
84
|
const uid = ref<string | undefined>(undefined);
|
|
78
85
|
|
|
@@ -94,29 +101,42 @@ export default defineComponent({
|
|
|
94
101
|
return modelValue.value === trueValue.value;
|
|
95
102
|
});
|
|
96
103
|
|
|
97
|
-
function
|
|
104
|
+
function onClickedLabel(e: MouseEvent) {
|
|
98
105
|
if (disabled.value) {
|
|
99
106
|
return;
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
const isChecked = (e.target as HTMLInputElement).checked;
|
|
103
|
-
|
|
104
109
|
if (Array.isArray(modelValue.value)) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
const valueSet: Set<any> = new Set(modelValue.value);
|
|
111
|
+
|
|
112
|
+
const lastCheckIndex = lastCheckValue.value === null || lastCheckValue.value === undefined || !options.value ? -1 : options.value.findIndex((o) => isEqual(o.value, lastCheckValue.value));
|
|
113
|
+
const currentCheckIndex = options.value?.findIndex((o) => isEqual(o.value, value.value)) || -1;
|
|
114
|
+
|
|
115
|
+
if (!options.value || lastCheckIndex === -1 || lastCheckIndex === currentCheckIndex || !e.shiftKey) {
|
|
116
|
+
if (isChecked.value) {
|
|
117
|
+
valueSet.delete(value.value);
|
|
118
|
+
emit("update:lastCheckValue", null);
|
|
119
|
+
} else {
|
|
120
|
+
valueSet.add(value.value);
|
|
121
|
+
emit('update:lastCheckValue', value.value);
|
|
122
|
+
}
|
|
109
123
|
} else {
|
|
110
|
-
|
|
124
|
+
emit("update:lastCheckValue", null);
|
|
125
|
+
const start = lastCheckIndex < currentCheckIndex ? lastCheckIndex : currentCheckIndex;
|
|
126
|
+
const end = lastCheckIndex < currentCheckIndex ? currentCheckIndex : lastCheckIndex;
|
|
127
|
+
options.value.slice(start, end + 1).forEach((o) => {
|
|
128
|
+
if (o.disabled) return;
|
|
129
|
+
valueSet.add(o.value);
|
|
130
|
+
});
|
|
111
131
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
} else {
|
|
115
|
-
emit(
|
|
116
|
-
"update:modelValue",
|
|
117
|
-
isChecked ? trueValue.value : falseValue.value
|
|
118
|
-
);
|
|
132
|
+
emit("update:modelValue", Array.from(valueSet.values()));
|
|
133
|
+
return;
|
|
119
134
|
}
|
|
135
|
+
|
|
136
|
+
emit(
|
|
137
|
+
"update:modelValue",
|
|
138
|
+
isChecked ? trueValue.value : falseValue.value
|
|
139
|
+
);
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
onMounted(() => {
|
|
@@ -127,7 +147,7 @@ export default defineComponent({
|
|
|
127
147
|
uid,
|
|
128
148
|
checkboxClass,
|
|
129
149
|
isChecked,
|
|
130
|
-
|
|
150
|
+
onClickedLabel,
|
|
131
151
|
};
|
|
132
152
|
},
|
|
133
153
|
});
|
package/package.json
CHANGED
package/utils/index.ts
CHANGED
|
@@ -353,6 +353,11 @@ export const numberToLocaleString = (value: number | null, { NaNString = '' } =
|
|
|
353
353
|
export const toFixed = (value: number | null, fixedTo: number = 0, { NaNString = '', unsign = false, unit = '' } = {}, toNumber = false) => {
|
|
354
354
|
if (value === null || isNaN(value)) {
|
|
355
355
|
return NaNString || '';
|
|
356
|
+
} else if (toNumber) {
|
|
357
|
+
if (unsign) {
|
|
358
|
+
return Number(Number(Math.abs(value)).toFixed(fixedTo));
|
|
359
|
+
}
|
|
360
|
+
return Number(Number(value).toFixed(fixedTo));
|
|
356
361
|
} else {
|
|
357
362
|
let formatedValue = '';
|
|
358
363
|
if (unsign) {
|
|
@@ -364,15 +369,9 @@ export const toFixed = (value: number | null, fixedTo: number = 0, { NaNString =
|
|
|
364
369
|
const valueParts = formatedValue.split('.');
|
|
365
370
|
|
|
366
371
|
if (valueParts[1]) {
|
|
367
|
-
if (toNumber) {
|
|
368
|
-
return Number(`${Number(valueParts[0])}.${valueParts[1]}`);
|
|
369
|
-
}
|
|
370
372
|
return `${Number(valueParts[0]).toLocaleString()}.${valueParts[1]}${unit}`;
|
|
371
373
|
}
|
|
372
374
|
|
|
373
|
-
if (toNumber) {
|
|
374
|
-
return Number(valueParts[0]);
|
|
375
|
-
}
|
|
376
375
|
return `${Number(valueParts[0]).toLocaleString()}${unit}`;
|
|
377
376
|
}
|
|
378
377
|
}
|