index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2022-12-08 13:53:21
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-02-24 12:06:56
  7. 字典类型选择
  8. -->
  9. <template>
  10. <div>
  11. <el-select
  12. v-model="dictId"
  13. class="m-2"
  14. :disabled="disabled"
  15. placeholder="请选择"
  16. style="width: 100%"
  17. @change="changeDists"
  18. >
  19. <el-option
  20. v-for="item in list"
  21. :key="Number(item.id)"
  22. :label="item.name"
  23. :value="Number(item.value)"
  24. />
  25. </el-select>
  26. </div>
  27. </template>
  28. <script setup>
  29. import { getDictList } from './api/index'
  30. const emit = defineEmits(['select-dicts'])
  31. const props = defineProps({
  32. keys: {
  33. type: Array,
  34. default: function () {
  35. return []
  36. },
  37. },
  38. disabled: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. value: {
  43. type: [String, Number],
  44. default: '',
  45. },
  46. })
  47. const dictId = ref() //id
  48. const list = ref([])
  49. watch(
  50. () => props.value,
  51. () => {
  52. if (props.value) {
  53. dictId.value = props.value
  54. console.log(list.value, ' list.value')
  55. }
  56. }
  57. )
  58. const dictsSetting = localStorage.getItem('dictsSetting')
  59. const dicts = dictsSetting ? JSON.parse(dictsSetting) : false
  60. if (dicts) {
  61. console.log(props.keys, 'props.keys')
  62. dicts.map((item) => {
  63. if (item.code == props.keys) {
  64. list.value = item.detail
  65. }
  66. })
  67. // dictId.value = list[0].value
  68. } else {
  69. getDictList({ key: props.keys }).then((res) => {
  70. list.value = res.data
  71. })
  72. }
  73. const changeDists = () => {
  74. emit('select-dicts', dictId.value)
  75. }
  76. </script>