Vue_US/src/views/mp/components/wx-account-select/main.vue

37 lines
939 B
Vue
Raw Normal View History

<template>
2023-04-14 15:15:01 +08:00
<el-select v-model="account.id" placeholder="请选择公众号" class="!w-240px" @change="onChanged">
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</template>
2023-04-14 15:15:01 +08:00
<script lang="ts" setup name="WxAccountSelect">
import * as MpAccountApi from '@/api/mp/account'
2023-04-14 15:15:01 +08:00
const account: MpAccountApi.AccountVO = reactive({
id: undefined,
name: ''
})
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
const emit = defineEmits<{
(e: 'change', id?: number, name?: string): void
}>()
2023-04-11 23:28:59 +08:00
onMounted(() => {
handleQuery()
})
const handleQuery = async () => {
2023-04-11 23:28:59 +08:00
accountList.value = await MpAccountApi.getSimpleAccountList()
// 默认选中第一个
if (accountList.value.length > 0) {
2023-04-14 15:15:01 +08:00
account.id = accountList.value[0].id
emit('change', account.id, account.name)
}
}
2023-04-14 15:15:01 +08:00
const onChanged = () => {
emit('change', account.id, account.name)
}
</script>