WxMpSelect.vue 912 B

1234567891011121314151617181920212223242526272829303132333435363738
  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(() => {
  19. handleQuery()
  20. })
  21. const handleQuery = async () => {
  22. accountList.value = await MpAccountApi.getSimpleAccountList()
  23. // 默认选中第一个
  24. if (accountList.value.length > 0) {
  25. accountId.value = accountList.value[0].id
  26. emit('change', accountId.value)
  27. }
  28. }
  29. const accountChanged = () => {
  30. emit('change', accountId.value)
  31. }
  32. </script>