ExtBoolean.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <style scoped lang="scss">
  2. .text {
  3. display: inline-block;
  4. padding: 3px 6px;
  5. font-size: 11px;
  6. font-weight: 600;
  7. line-height: 1;
  8. height: 20px;
  9. text-align: center;
  10. white-space: nowrap;
  11. vertical-align: baseline;
  12. border-radius: 10px;
  13. margin-top: 3px;
  14. width: auto;
  15. color: #FF5722;
  16. border: 1px solid #FF5722;
  17. }
  18. .true-text {
  19. color: #5FB878;
  20. border: 1px solid #5FB878;
  21. }
  22. </style>
  23. <template>
  24. <div>
  25. <span v-if="disabled" class="text" :class="{'true-text':props.modelValue==true}">{{ props.modelValue ? '是' : '否' }}</span>
  26. <el-select v-else
  27. transfer
  28. :multiple="false"
  29. clearable
  30. @change="handleChange"
  31. style="width: 100%"
  32. :placeholder="placeholder"
  33. v-model="state.model">
  34. <el-option label="是" :value="true"><el-text type="success">是</el-text></el-option>
  35. <el-option label="否" :value="false"><el-text type="danger">否</el-text></el-option>
  36. </el-select>
  37. </div>
  38. </template>
  39. <script setup lang="ts" name="ExtBoolean">
  40. import {reactive, onMounted, watch} from 'vue';
  41. //数据字典的布尔值类型的下拉选择组件
  42. const props = defineProps({
  43. modelValue: {
  44. type: Boolean
  45. },
  46. disabled: {
  47. type: Boolean,
  48. default: false
  49. },
  50. placeholder: {
  51. type: String,
  52. default: '请选择'
  53. },
  54. tips: {
  55. type: String
  56. }
  57. })
  58. const state = reactive({
  59. model: false,
  60. })
  61. onMounted(() => {
  62. state.model = props.modelValue;
  63. })
  64. watch(() => props.modelValue, (val, oldVal) => {
  65. console.log('ExtBoolean watch modelValue', val, oldVal)
  66. state.model = props.modelValue;
  67. })
  68. const emit = defineEmits(['on-change', 'update:modelValue']);
  69. const handleChange = () => {
  70. console.log(state.model)
  71. emit('update:modelValue', state.model)
  72. emit('on-change', state.model)
  73. }
  74. </script>