|
@@ -1,12 +1,22 @@
|
|
<template>
|
|
<template>
|
|
- <div :class="ui" class="ui-checkbox-group">
|
|
|
|
- <template v-for="item in checkboxDatas" :key="item.key">
|
|
|
|
- <el-checkbox :checked="item.checked" size="large" @change="onCheckboxChange($event, item)">{{ item.name }}
|
|
|
|
- </el-checkbox>
|
|
|
|
- </template>
|
|
|
|
|
|
+ <div :class="isFocus?'is-focus':''" class="hc-form-checkbox-group-box"
|
|
|
|
+ @keydown.shift.up="keyupShiftUp"
|
|
|
|
+ @keydown.shift.down="keyupShiftDown"
|
|
|
|
+ @keydown.shift.left="keyupShiftLeft"
|
|
|
|
+ @keydown.shift.right="keyupShiftRight">
|
|
|
|
+ <el-checkbox v-for="item in checkboxDatas" :key="item.key" :checked="item.checked"
|
|
|
|
+ @change="onCheckboxChange($event, item)">{{ item.name }}
|
|
|
|
+ </el-checkbox>
|
|
|
|
+ <input :id="keyname" class="hc-checkbox-group-input" @blur="handleBlur" @focus="handleFocus"/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
+<script>
|
|
|
|
+export default {
|
|
|
|
+ inheritAttrs: false,
|
|
|
|
+}
|
|
|
|
+</script>
|
|
|
|
+
|
|
<script setup>
|
|
<script setup>
|
|
import {ref, nextTick, watch} from 'vue'
|
|
import {ref, nextTick, watch} from 'vue'
|
|
import {ElCheckbox} from 'element-plus'
|
|
import {ElCheckbox} from 'element-plus'
|
|
@@ -74,7 +84,7 @@ const setModelVal = (val) => {
|
|
}
|
|
}
|
|
|
|
|
|
//事件
|
|
//事件
|
|
-const emit = defineEmits(['change'])
|
|
|
|
|
|
+const emit = defineEmits(['change', 'keydowns'])
|
|
|
|
|
|
//当绑定值变化时触发的事件
|
|
//当绑定值变化时触发的事件
|
|
const onCheckboxChange = (val, item) => {
|
|
const onCheckboxChange = (val, item) => {
|
|
@@ -98,4 +108,54 @@ const getCheckedValue = () => {
|
|
val: valString
|
|
val: valString
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//向上
|
|
|
|
+const keyupShiftUp = (e) => {
|
|
|
|
+ emit('keydowns', {type: 'up', name: {target: {id: props.keyname}}, key: props.keyname, e});
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//向下
|
|
|
|
+const keyupShiftDown = (e) => {
|
|
|
|
+ emit('keydowns', {type: 'down', name: {target: {id: props.keyname}}, key: props.keyname, e});
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//向左
|
|
|
|
+const keyupShiftLeft = (e) => {
|
|
|
|
+ emit('keydowns', {type: 'left', name: {target: {id: props.keyname}}, key: props.keyname, e});
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//向右
|
|
|
|
+const keyupShiftRight = (e) => {
|
|
|
|
+ emit('keydowns', {type: 'right', name: {target: {id: props.keyname}}, key: props.keyname, e});
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+//获得焦点
|
|
|
|
+const isFocus = ref(false)
|
|
|
|
+const handleFocus = () => {
|
|
|
|
+ isFocus.value = true
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//失去焦点
|
|
|
|
+const handleBlur = () => {
|
|
|
|
+ isFocus.value = false
|
|
|
|
+}
|
|
</script>
|
|
</script>
|
|
|
|
+
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
+.hc-form-checkbox-group-box {
|
|
|
|
+ position: relative;
|
|
|
|
+ width: 100%;
|
|
|
|
+ height: 100%;
|
|
|
|
+ border-radius: 4px;
|
|
|
|
+ transition: box-shadow 0.3s, background-color 0.3s;
|
|
|
|
+ &.is-focus, &:hover {
|
|
|
|
+ background-color: #eddac4;
|
|
|
|
+ box-shadow: 0 0 0 1.5px var(--el-color-primary) inset;
|
|
|
|
+ }
|
|
|
|
+ .hc-checkbox-group-input {
|
|
|
|
+ position: absolute;
|
|
|
|
+ z-index: -1;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+</style>
|