车间能级提升-智能设备管理系统
朱桂飞
2025-01-09 3e8f7f239bedae0b4f04a1ac6bd443ba6298f73c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<script setup lang="ts">
import { computed, type PropType } from 'vue';
 
import {
  Input,
  type RadioChangeEvent,
  RadioGroup,
  Select,
} from 'ant-design-vue';
 
import { tagSelectOptions } from '#/components/dict';
 
/**
 * 需要禁止透传
 * 不禁止会有奇怪的bug 会绑定到selectType上
 * TODO: 未知原因 有待研究
 */
defineOptions({ inheritAttrs: false });
 
defineEmits<{ deselect: [] }>();
 
const options = [
  { label: '默认颜色', value: 'default' },
  { label: '自定义颜色', value: 'custom' },
] as const;
 
/**
 * 主要是加了const报错
 */
const computedOptions = computed(
  () => options as unknown as { label: string; value: string }[],
);
 
type SelectType = (typeof options)[number]['value'];
 
const selectType = defineModel('selectType', {
  default: 'default',
  type: String as PropType<SelectType>,
});
 
/**
 * color必须为hex颜色或者undefined
 */
const color = defineModel('value', {
  default: undefined,
  type: String as PropType<string | undefined>,
});
 
function handleSelectTypeChange(e: RadioChangeEvent) {
  // 必须给默认hex颜色 不能为空字符串
  color.value = e.target.value === 'custom' ? '#000000' : undefined;
}
</script>
 
<template>
  <div class="flex flex-1 items-center gap-[6px]">
    <RadioGroup
      v-model:value="selectType"
      :options="computedOptions"
      button-style="solid"
      option-type="button"
      @change="handleSelectTypeChange"
    />
    <Select
      v-if="selectType === 'default'"
      v-model:value="color"
      :allow-clear="true"
      :options="tagSelectOptions()"
      class="flex-1"
      placeholder="请选择标签样式"
      @deselect="$emit('deselect')"
    />
    <Input
      v-if="selectType === 'custom'"
      v-model:value="color"
      class="flex-1"
      disabled
    >
      <template #addonAfter>
        <input v-model="color" class="rounded-lg" type="color" />
      </template>
    </Input>
  </div>
</template>