main.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
  3. <el-form-item label="公众号" prop="accountId">
  4. <!-- TODO 芋艿:需要将 el-form 和 el-select 解耦 -->
  5. <el-select
  6. v-model="accountId"
  7. placeholder="请选择公众号"
  8. class="!w-240px"
  9. @change="accountChanged()"
  10. >
  11. <el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <slot name="actions"></slot>
  16. </el-form-item>
  17. </el-form>
  18. </template>
  19. <script setup name="WxAccountSelect">
  20. import * as MpAccountApi from '@/api/mp/account'
  21. const accountId = ref()
  22. const accountList = ref([])
  23. const queryFormRef = ref()
  24. const emit = defineEmits(['change'])
  25. onMounted(() => {
  26. handleQuery()
  27. })
  28. const handleQuery = async () => {
  29. accountList.value = await MpAccountApi.getSimpleAccountList()
  30. // 默认选中第一个
  31. if (accountList.value.length > 0) {
  32. accountId.value = accountList.value[0].id
  33. emit('change', accountId.value)
  34. }
  35. }
  36. const accountChanged = () => {
  37. emit('change', accountId.value)
  38. }
  39. </script>