Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

custom-select-dic.vue 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. console.log(props.modelValue)
  56. if (props.modelValue || props.modelValue === 0) {
  57. state.showName = getCodeName(props.dicName, props.modelValue)
  58. console.log(state.showName)
  59. }
  60. })
  61. watch(() => props.modelValue, (newValue) => {
  62. if (newValue || newValue === 0) {
  63. state.showName = getCodeName(props.dicName, props.modelValue)
  64. } else {
  65. state.showName = ''
  66. }
  67. })
  68. const choose = (e) => {
  69. if (props.disabled) return
  70. showPopup.value = true
  71. }
  72. const confirm = (e) => {
  73. // state.showName = e.label
  74. emits('update:modelValue', e[0].value)
  75. }
  76. </script>
  77. <style>
  78. </style>