提交 | 用户 | 时间
|
314507
|
1 |
<script lang="ts" setup> |
H |
2 |
import { PropType } from 'vue' |
|
3 |
import { propTypes } from '@/utils/propTypes' |
|
4 |
import { useDesign } from '@/hooks/web/useDesign' |
|
5 |
|
|
6 |
defineOptions({ name: 'ColorRadioPicker' }) |
|
7 |
|
|
8 |
const { getPrefixCls } = useDesign() |
|
9 |
|
|
10 |
const prefixCls = getPrefixCls('color-radio-picker') |
|
11 |
|
|
12 |
const props = defineProps({ |
|
13 |
schema: { |
|
14 |
type: Array as PropType<string[]>, |
|
15 |
default: () => [] |
|
16 |
}, |
|
17 |
modelValue: propTypes.string.def('') |
|
18 |
}) |
|
19 |
|
|
20 |
const emit = defineEmits(['update:modelValue', 'change']) |
|
21 |
|
|
22 |
const colorVal = ref(props.modelValue) |
|
23 |
|
|
24 |
watch( |
|
25 |
() => props.modelValue, |
|
26 |
(val: string) => { |
|
27 |
if (val === unref(colorVal)) return |
|
28 |
colorVal.value = val |
|
29 |
} |
|
30 |
) |
|
31 |
|
|
32 |
// 监听 |
|
33 |
watch( |
|
34 |
() => colorVal.value, |
|
35 |
(val: string) => { |
|
36 |
emit('update:modelValue', val) |
|
37 |
emit('change', val) |
|
38 |
} |
|
39 |
) |
|
40 |
</script> |
|
41 |
|
|
42 |
<template> |
|
43 |
<div :class="prefixCls" class="flex flex-wrap space-x-14px"> |
|
44 |
<span |
|
45 |
v-for="(item, i) in schema" |
|
46 |
:key="`radio-${i}`" |
|
47 |
:class="{ 'is-active': colorVal === item }" |
|
48 |
:style="{ |
|
49 |
background: item |
|
50 |
}" |
|
51 |
class="mb-5px h-20px w-20px cursor-pointer border-2px border-gray-300 rounded-2px border-solid text-center leading-20px" |
|
52 |
@click="colorVal = item" |
|
53 |
> |
|
54 |
<Icon v-if="colorVal === item" :size="16" color="#fff" icon="ep:check" /> |
|
55 |
</span> |
|
56 |
</div> |
|
57 |
</template> |
|
58 |
|
|
59 |
<style lang="scss" scoped> |
|
60 |
$prefix-cls: #{$namespace}-color-radio-picker; |
|
61 |
|
|
62 |
.#{$prefix-cls} { |
|
63 |
.is-active { |
|
64 |
border-color: var(--el-color-primary); |
|
65 |
} |
|
66 |
} |
|
67 |
</style> |