Skip to content

Commit c7b296a

Browse files
committed
refactor: 抽离WxMpSelect组件
1 parent a5cb7a5 commit c7b296a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
12+
<script lang="ts" setup name="WxMpSelect">
13+
import * as MpAccountApi from '@/api/mp/account'
14+
15+
const accountId: Ref<number | undefined> = ref()
16+
const accountList: Ref<MpAccountApi.AccountVO[]> = ref([])
17+
18+
const emit = defineEmits<{
19+
(e: 'change', id: number | undefined): void
20+
}>()
21+
22+
onMounted(async () => {
23+
handleQuery()
24+
})
25+
26+
const handleQuery = async () => {
27+
const data = await MpAccountApi.getSimpleAccountList()
28+
accountList.value = data
29+
// 默认选中第一个
30+
if (accountList.value.length > 0) {
31+
accountId.value = accountList.value[0].id
32+
emit('change', accountId.value)
33+
}
34+
}
35+
36+
const accountChanged = () => {
37+
emit('change', accountId.value)
38+
}
39+
</script>

0 commit comments

Comments
 (0)