@mptw/skylens-ui 1.4.95 → 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
|
@@ -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
|
});
|