WxMpSelect.vue 938 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <el-select
  3. v-model="accountId"
  4. placeholder="请选择公众号"
  5. class="!w-240px"
  6. @change="accountChanged"
  7. >
  8. <el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
  9. </el-select>
  10. </template>
  11. <script lang="ts" setup name="WxMpSelect">
  12. import * as MpAccountApi from '@/api/mp/account'
  13. const accountId: Ref<number | undefined> = ref()
  14. const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
  15. const emit = defineEmits<{
  16. (e: 'change', id: number | undefined): void
  17. }>()
  18. onMounted(async () => {
  19. handleQuery()
  20. })
  21. const handleQuery = async () => {
  22. const data = await MpAccountApi.getSimpleAccountList()
  23. accountList.value = data
  24. // 默认选中第一个
  25. if (accountList.value.length > 0) {
  26. accountId.value = accountList.value[0].id
  27. emit('change', accountId.value)
  28. }
  29. }
  30. const accountChanged = () => {
  31. emit('change', accountId.value)
  32. }
  33. </script>