WxMpSelect.vue 1.0 KB

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. <!-- TODO @芋艿:WxMpSelect 改成 WxAccountSelect,然后挪到现有的 wx-account-select 包下 -->
  7. <script lang="ts" setup name="WxMpSelect">
  8. import * as MpAccountApi from '@/api/mp/account'
  9. const account: MpAccountApi.AccountVO = reactive({
  10. id: undefined,
  11. name: ''
  12. })
  13. const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
  14. const emit = defineEmits<{
  15. (e: 'change', id?: number, name?: string): void
  16. }>()
  17. onMounted(() => {
  18. handleQuery()
  19. })
  20. const handleQuery = async () => {
  21. accountList.value = await MpAccountApi.getSimpleAccountList()
  22. // 默认选中第一个
  23. if (accountList.value.length > 0) {
  24. account.id = accountList.value[0].id
  25. emit('change', account.id, account.name)
  26. }
  27. }
  28. const onChanged = () => {
  29. emit('change', account.id, account.name)
  30. }
  31. </script>