Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

custom-select-dic.vue 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!-- 字典数据选择器 -->
  2. <template>
  3. <u-input
  4. v-model="state.showName"
  5. :placeholder="placeholder"
  6. :type="disabled ? 'text' : 'select'"
  7. input-align='right'
  8. :disabled="disabled"
  9. @click="choose"/>
  10. <u-select
  11. v-model="showPopup"
  12. :list="state.dicList"
  13. @confirm="confirm"
  14. :valueName="props.valueName"
  15. :labelName="props.labelName"
  16. ></u-select>
  17. </template>
  18. <script setup lang="ts">
  19. import { reactive, watch, onMounted, ref } from 'vue'
  20. import { getDicWithType, getCodeName } from '@/datas/queryKey.js'
  21. const emits = defineEmits(['update:modelValue']);
  22. const props = defineProps({
  23. modelValue: {
  24. type: [String, Number],
  25. default: false
  26. },
  27. disabled: {
  28. type: Boolean,
  29. default: false
  30. },
  31. dicName: { // 字典名称
  32. type: String,
  33. default: ""
  34. },
  35. valueName: {
  36. type: String,
  37. default: "code"
  38. },
  39. labelName: {
  40. type: String,
  41. default: "name"
  42. },
  43. placeholder: {
  44. type: String,
  45. default: "请选择"
  46. }
  47. })
  48. const showPopup = ref(false)
  49. const state = reactive({
  50. showName: '',
  51. dicList: []
  52. })
  53. onMounted(() => {
  54. state.dicList = getDicWithType(props.dicName)
  55. if (props.modelValue) {
  56. state.showName = getCodeName(props.dicName, props.modelValue)
  57. }
  58. })
  59. watch(() => props.modelValue, (newValue) => {
  60. if (newValue) {
  61. state.showName = getCodeName(props.dicName, props.modelValue)
  62. } else {
  63. state.showName = ''
  64. }
  65. })
  66. const choose = (e) => {
  67. if (props.disabled) return
  68. showPopup.value = true
  69. }
  70. const confirm = (e) => {
  71. // state.showName = e.label
  72. emits('update:modelValue', e[0].value)
  73. }
  74. </script>
  75. <style>
  76. </style>