main.vue 1.1 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. <el-select
  5. v-model="accountId"
  6. placeholder="请选择公众号"
  7. class="!w-240px"
  8. @change="accountChanged()"
  9. >
  10. <el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item>
  14. <slot name="actions"></slot>
  15. </el-form-item>
  16. </el-form>
  17. </template>
  18. <script setup name="WxAccountSelect">
  19. import * as MpAccountApi from '@/api/mp/account'
  20. const accountId = ref()
  21. const accountList = ref([])
  22. const queryFormRef = ref()
  23. const emit = defineEmits(['change'])
  24. onMounted(async () => {
  25. handleQuery()
  26. })
  27. const handleQuery = async () => {
  28. const data = await MpAccountApi.getSimpleAccountList()
  29. accountList.value = data
  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>