main.vue 939 B

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