ExtBoolean.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <style scoped lang="scss">
  2. .text {
  3. display: inline-block;
  4. padding: 5px 6px 1px 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: 2px;
  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 ? trueLabel : falseLabel }}</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">{{ trueLabel }}</el-text></el-option>
  35. <el-option label="否" :value="false"><el-text type="danger">{{ falseLabel }}</el-text></el-option>
  36. </el-select>
  37. </div>
  38. </template>
  39. <script setup lang="ts" name="ExtBoolean">
  40. import {reactive, onMounted, watch, computed} from 'vue';
  41. import u from '/@/utils/u';
  42. //数据字典的布尔值类型的下拉选择组件
  43. const props = defineProps({
  44. modelValue: {
  45. type: Boolean
  46. },
  47. disabled: {
  48. type: Boolean,
  49. default: false
  50. },
  51. placeholder: {
  52. type: String,
  53. default: '请选择'
  54. },
  55. tips: {
  56. type: String
  57. }
  58. })
  59. const state = reactive({
  60. model: false,
  61. })
  62. const trueLabel = computed(() => u.fmt.fmtDict('1', 'yes_no'));
  63. const falseLabel = computed(() => u.fmt.fmtDict('0', 'yes_no'));
  64. onMounted(() => {
  65. state.model = props.modelValue;
  66. })
  67. watch(() => props.modelValue, (val, oldVal) => {
  68. //console.log('ExtBoolean watch modelValue', val, oldVal)
  69. state.model = props.modelValue;
  70. })
  71. const emit = defineEmits(['on-change', 'update:modelValue']);
  72. const handleChange = () => {
  73. //console.log(state.model)
  74. emit('update:modelValue', state.model)
  75. emit('on-change', state.model)
  76. }
  77. </script>