Skip to content

Commit 9ab7918

Browse files
committed
Vue3 重构:REVIEW 公众号消息,先不报错
1 parent f7f5704 commit 9ab7918

File tree

3 files changed

+73
-75
lines changed

3 files changed

+73
-75
lines changed

src/api/mp/message/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import request from '@/config/axios'
22

33
// 获得公众号消息分页
4-
export const getMessagePage = (query) => {
4+
export const getMessagePage = (query: PageParam) => {
55
return request.get({
66
url: '/mp/message/page',
77
params: query

src/types/auto-components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ declare module '@vue/runtime-core' {
5252
ElForm: typeof import('element-plus/es')['ElForm']
5353
ElFormItem: typeof import('element-plus/es')['ElFormItem']
5454
ElIcon: typeof import('element-plus/es')['ElIcon']
55+
ElImage: typeof import('element-plus/es')['ElImage']
5556
ElImageViewer: typeof import('element-plus/es')['ElImageViewer']
5657
ElInput: typeof import('element-plus/es')['ElInput']
5758
ElInputNumber: typeof import('element-plus/es')['ElInputNumber']

src/views/mp/message/index.vue

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
<template>
22
<ContentWrap>
3-
<doc-alert title="公众号消息" url="https://doc.iocoder.cn/mp/message/" />
4-
53
<!-- 搜索工作栏 -->
64
<el-form
5+
class="-mb-15px"
76
:model="queryParams"
87
ref="queryFormRef"
9-
size="small"
108
:inline="true"
11-
v-show="showSearch"
129
label-width="68px"
1310
>
1411
<el-form-item label="公众号" prop="accountId">
15-
<el-select v-model="queryParams.accountId" placeholder="请选择公众号">
12+
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
1613
<el-option
17-
v-for="item in accounts"
14+
v-for="item in accountList"
1815
:key="parseInt(item.id)"
1916
:label="item.name"
2017
:value="parseInt(item.id)"
2118
/>
2219
</el-select>
2320
</el-form-item>
2421
<el-form-item label="消息类型" prop="type">
25-
<el-select v-model="queryParams.type" placeholder="请选择消息类型" clearable size="small">
22+
<el-select v-model="queryParams.type" placeholder="请选择消息类型" class="!w-240px">
2623
<el-option
27-
v-for="dict in getDictOptions(DICT_TYPE.MP_MESSAGE_TYPE)"
24+
v-for="dict in getStrDictOptions(DICT_TYPE.MP_MESSAGE_TYPE)"
2825
:key="dict.value"
2926
:label="dict.label"
3027
:value="dict.value"
@@ -37,6 +34,7 @@
3734
placeholder="请输入用户标识"
3835
clearable
3936
:v-on="handleQuery"
37+
class="!w-240px"
4038
/>
4139
</el-form-item>
4240
<el-form-item label="创建时间" prop="createTime">
@@ -49,20 +47,18 @@
4947
start-placeholder="开始日期"
5048
end-placeholder="结束日期"
5149
:default-time="['00:00:00', '23:59:59']"
50+
class="!w-240px"
5251
/>
5352
</el-form-item>
5453
<el-form-item>
55-
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
56-
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
54+
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
55+
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
5756
</el-form-item>
5857
</el-form>
58+
</ContentWrap>
5959

60-
<!--todo 操作工具栏 -->
61-
<!-- <el-row :gutter="10" class="mb8">-->
62-
<!-- <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />-->
63-
<!-- </el-row>-->
64-
65-
<!-- 列表 -->
60+
<!-- 列表 -->
61+
<ContentWrap>
6662
<el-table v-loading="loading" :data="list">
6763
<el-table-column label="发送时间" align="center" prop="createTime" width="180">
6864
<template #default="scope">
@@ -81,37 +77,37 @@
8177
<template #default="scope">
8278
<!-- 【事件】区域 -->
8379
<div v-if="scope.row.type === 'event' && scope.row.event === 'subscribe'">
84-
<el-tag type="success" size="mini">关注</el-tag>
80+
<el-tag type="success">关注</el-tag>
8581
</div>
8682
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'unsubscribe'">
87-
<el-tag type="danger" size="mini">取消关注</el-tag>
83+
<el-tag type="danger">取消关注</el-tag>
8884
</div>
8985
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'CLICK'">
90-
<el-tag size="mini">点击菜单</el-tag>【{{ scope.row.eventKey }}】
86+
<el-tag>点击菜单</el-tag>【{{ scope.row.eventKey }}】
9187
</div>
9288
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'VIEW'">
93-
<el-tag size="mini">点击菜单链接</el-tag>【{{ scope.row.eventKey }}】
89+
<el-tag>点击菜单链接</el-tag>【{{ scope.row.eventKey }}】
9490
</div>
9591
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'scancode_waitmsg'">
96-
<el-tag size="mini">扫码结果</el-tag>【{{ scope.row.eventKey }}】
92+
<el-tag>扫码结果</el-tag>【{{ scope.row.eventKey }}】
9793
</div>
9894
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'scancode_push'">
99-
<el-tag size="mini">扫码结果</el-tag>【{{ scope.row.eventKey }}】
95+
<el-tag>扫码结果</el-tag>【{{ scope.row.eventKey }}】
10096
</div>
10197
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'pic_sysphoto'">
102-
<el-tag size="mini">系统拍照发图</el-tag>
98+
<el-tag>系统拍照发图</el-tag>
10399
</div>
104100
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'pic_photo_or_album'">
105-
<el-tag size="mini">拍照或者相册</el-tag>
101+
<el-tag>拍照或者相册</el-tag>
106102
</div>
107103
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'pic_weixin'">
108-
<el-tag size="mini">微信相册</el-tag>
104+
<el-tag>微信相册</el-tag>
109105
</div>
110106
<div v-else-if="scope.row.type === 'event' && scope.row.event === 'location_select'">
111-
<el-tag size="mini">选择地理位置</el-tag>
107+
<el-tag>选择地理位置</el-tag>
112108
</div>
113109
<div v-else-if="scope.row.type === 'event'">
114-
<el-tag type="danger" size="mini">未知事件类型</el-tag>
110+
<el-tag type="danger">未知事件类型</el-tag>
115111
</div>
116112
<!-- 【消息】区域 -->
117113
<div v-else-if="scope.row.type === 'text'">{{ scope.row.content }}</div>
@@ -127,7 +123,7 @@
127123
<wx-video-player :url="scope.row.mediaUrl" style="margin-top: 10px" />
128124
</div>
129125
<div v-else-if="scope.row.type === 'link'">
130-
<el-tag size="mini">链接</el-tag>:
126+
<el-tag>链接</el-tag>:
131127
<a :href="scope.row.url" target="_blank">{{ scope.row.title }}</a>
132128
</div>
133129
<div v-else-if="scope.row.type === 'location'">
@@ -150,19 +146,19 @@
150146
<wx-news :articles="scope.row.articles" />
151147
</div>
152148
<div v-else>
153-
<el-tag type="danger" size="mini">未知消息类型</el-tag>
149+
<el-tag type="danger">未知消息类型</el-tag>
154150
</div>
155151
</template>
156152
</el-table-column>
157153
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
158154
<template #default="scope">
159155
<el-button
160-
size="mini"
161-
type="text"
162-
icon="el-icon-edit"
156+
link
157+
type="primary"
163158
@click="handleSend(scope.row)"
164159
v-hasPermi="['mp:message:send']"
165-
>消息
160+
>
161+
消息
166162
</el-button>
167163
</template>
168164
</el-table-column>
@@ -182,81 +178,82 @@
182178
</el-dialog>
183179
</ContentWrap>
184180
</template>
185-
186181
<script setup lang="ts" name="MpMessage">
187-
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
188-
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
182+
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
183+
// import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
184+
// import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
189185
// import WxMsg from '@/views/mp/components/wx-msg/main.vue'
190-
import WxLocation from '@/views/mp/components/wx-location/main.vue'
191-
import WxMusic from '@/views/mp/components/wx-music/main.vue'
192-
import WxNews from '@/views/mp/components/wx-news/main.vue'
193-
import { getMessagePage } from '@/api/mp/message'
194-
import { getSimpleAccounts } from '@/api/mp/account'
195-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
186+
// import WxLocation from '@/views/mp/components/wx-location/main.vue'
187+
// import WxMusic from '@/views/mp/components/wx-music/main.vue'
188+
// import WxNews from '@/views/mp/components/wx-news/main.vue'
196189
import { parseTime } from '@/utils/formatTime'
197-
198-
// ========== CRUD 相关 ==========
199-
const loading = ref(false) // 遮罩层
200-
const showSearch = ref(true) // 显示搜索条件
201-
const total = ref(0) // 总条数
202-
const list = ref([]) // 粉丝消息列表
203-
const accounts = ref([]) // 公众号账号列表
204-
const open = ref(false) // 是否显示弹出层
205-
const userId = ref(0) // 操作的用户编号
190+
import * as MpAccountApi from '@/api/mp/account'
191+
import * as MpMessageApi from '@/api/mp/message'
206192
const message = useMessage() // 消息弹窗
207-
const queryFormRef = ref() // 搜索的表单
208193
194+
const loading = ref(true) // 列表的加载中
195+
const total = ref(0) // 列表的总页数
196+
const list = ref([]) // 列表的数据
209197
const queryParams = reactive({
210198
pageNo: 1,
211199
pageSize: 10,
212200
openid: null,
213201
accountId: null,
214202
type: null,
215203
createTime: []
216-
}) // 是否显示弹出层
204+
})
205+
const queryFormRef = ref() // 搜索的表单
206+
// TODO 芋艿:下面应该移除
207+
const open = ref(false) // 是否显示弹出层
208+
const userId = ref(0) // 操作的用户编号
209+
const accountList = ref<MpAccountApi.AccountVO[]>([]) // 公众号账号列表
217210
211+
/** 查询参数列表 */
218212
const getList = async () => {
219213
// 如果没有选中公众号账号,则进行提示。
220214
if (!queryParams.accountId) {
221-
message.error('未选中公众号,无法查询消息')
222-
return false
215+
await message.error('未选中公众号,无法查询消息')
216+
return
223217
}
224-
225-
loading.value = true
226-
// 执行查询
227-
getMessagePage(queryParams).then((data) => {
228-
console.log(data)
218+
try {
219+
loading.value = true
220+
const data = await MpMessageApi.getMessagePage(queryParams)
229221
list.value = data.list
230222
total.value = data.total
223+
} finally {
231224
loading.value = false
232-
})
225+
}
233226
}
234227
235-
const handleQuery = async () => {
228+
/** 搜索按钮操作 */
229+
const handleQuery = () => {
236230
queryParams.pageNo = 1
237231
getList()
238232
}
233+
234+
/** 重置按钮操作 */
239235
const resetQuery = async () => {
240236
queryFormRef.value.resetFields()
241237
// 默认选中第一个
242-
if (accounts.value.length > 0) {
243-
queryParams.accountId = accounts[0].id
238+
if (accountList.value.length > 0) {
239+
// @ts-ignore
240+
queryParams.accountId = accountList.value[0].id
244241
}
245242
handleQuery()
246243
}
247244
const handleSend = async (row) => {
248245
userId.value = row.userId
249246
open.value = true
250247
}
251-
onMounted(() => {
252-
getSimpleAccounts().then((response) => {
253-
accounts.value = response
254-
// 默认选中第一个
255-
if (accounts.value.length > 0) {
256-
queryParams.accountId = accounts.value[0]['id']
257-
}
258-
// 加载数据
259-
getList()
260-
})
248+
249+
/** 初始化 **/
250+
onMounted(async () => {
251+
accountList.value = await MpAccountApi.getSimpleAccountList()
252+
// 选中第一个
253+
if (accountList.value.length > 0) {
254+
// @ts-ignore
255+
queryParams.accountId = accountList.value[0].id
256+
}
257+
await getList()
261258
})
262259
</script>

0 commit comments

Comments
 (0)