index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script lang="ts" setup name="ModelSelector">
  2. import { getModelByList } from '@/api/model/modelApi'
  3. const props = withDefaults(defineProps<{
  4. modelValue: number
  5. }>(), {
  6. modelValue: 0,
  7. })
  8. const emit = defineEmits(['update:modelValue'])
  9. interface Model {
  10. modelId: number
  11. modelTitle: string
  12. }
  13. const modelId = computed({
  14. get: () => {
  15. return props.modelValue
  16. },
  17. set: (val) => {
  18. emit('update:modelValue', val)
  19. },
  20. })
  21. const state = reactive({
  22. loading: false,
  23. dataList: [] as Model[],
  24. })
  25. const getData = async () => {
  26. state.loading = true
  27. const { data } = await getModelByList({})
  28. state.loading = false
  29. state.dataList = data
  30. }
  31. onMounted(() => {
  32. getData ()
  33. })
  34. </script>
  35. <template>
  36. <el-select v-model="modelId" v-loading="state.loading" style="width: 100%" filterable placeholder="请选择数据模型" value-key="modelId">
  37. <el-option key="0" label="请选择" :value="0" disabled />
  38. <el-option
  39. v-for="item in state.dataList"
  40. :key="item.modelId"
  41. :label="item.modelTitle"
  42. :value="item.modelId"
  43. />
  44. </el-select>
  45. </template>