main.vue 956 B

12345678910111213141516171819202122232425262728293031323334353637
  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. const handleQuery = async () => {
  17. accountList.value = await MpAccountApi.getSimpleAccountList()
  18. // 默认选中第一个
  19. if (accountList.value.length > 0) {
  20. account.id = accountList.value[0].id
  21. emit('change', account.id, account.name)
  22. }
  23. }
  24. const onChanged = () => {
  25. emit('change', account.id, account.name)
  26. }
  27. /** 初始化 */
  28. onMounted(() => {
  29. handleQuery()
  30. })
  31. </script>