Vue3 重构:REVIEW 图文发表记录

This commit is contained in:
YunaiV 2023-03-26 23:31:41 +08:00
parent 708aef3e10
commit f5177337cb
2 changed files with 51 additions and 52 deletions

View File

@ -1,37 +1,36 @@
<template> <template>
<content-wrap>
<doc-alert title="公众号图文" url="https://doc.iocoder.cn/mp/article/" />
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<content-wrap>
<el-form <el-form
class="-mb-15px"
:model="queryParams" :model="queryParams"
ref="queryFormRef" ref="queryFormRef"
size="small"
:inline="true" :inline="true"
v-show="showSearch"
label-width="68px" label-width="68px"
> >
<el-form-item label="公众号" prop="accountId"> <el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号"> <el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option <el-option
v-for="item in accounts" v-for="item in accountList"
:key="parseInt(item.id)" :key="item.id"
:label="item.name" :label="item.name"
:value="parseInt(item.id)" :value="item.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" :icon="Search" @click="handleQuery">搜索</el-button> <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button :icon="Refresh" @click="resetQuery">重置</el-button> <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</content-wrap>
<!-- 列表 --> <!-- 列表 -->
<content-wrap>
<div class="waterfall" v-loading="loading"> <div class="waterfall" v-loading="loading">
<div <div
v-show="item.content && item.content.newsItem"
class="waterfall-item" class="waterfall-item"
v-show="item.content && item.content.newsItem"
v-for="item in list" v-for="item in list"
:key="item.articleId" :key="item.articleId"
> >
@ -40,11 +39,12 @@
<el-row justify="center" class="ope-row"> <el-row justify="center" class="ope-row">
<el-button <el-button
type="danger" type="danger"
:icon="Delete"
circle circle
@click="handleDelete(item)" @click="handleDelete(item)"
v-hasPermi="['mp:free-publish:delete']" v-hasPermi="['mp:free-publish:delete']"
/> >
<Icon icon="ep:delete" />
</el-button>
</el-row> </el-row>
</div> </div>
</div> </div>
@ -61,25 +61,21 @@
<script setup lang="ts" name="freePublish"> <script setup lang="ts" name="freePublish">
import { getFreePublishPage, deleteFreePublish } from '@/api/mp/freePublish' import { getFreePublishPage, deleteFreePublish } from '@/api/mp/freePublish'
import { getSimpleAccounts } from '@/api/mp/account' import * as MpAccountApi from '@/api/mp/account'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import { Delete, Search, Refresh } from '@element-plus/icons-vue'
const message = useMessage() // const message = useMessage() //
const queryParams = reactive({ const loading = ref(true) //
total: 0, //
currentPage: 1, //
pageNo: 1, //
accountId: undefined, //
queryParamsSize: 10 //
})
const loading = ref(false) //
const showSearch = ref(true) //
const total = ref(0) // const total = ref(0) //
const list = ref([]) // const list = ref([]) //
const accounts = ref([]) // const queryParams = reactive({
currentPage: 1, //
pageNo: 1, //
accountId: undefined //
})
const queryFormRef = ref() // const queryFormRef = ref() //
const accountList = ref<MpAccountApi.AccountVO[]>([]) //
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
// //
@ -87,6 +83,7 @@ const getList = async () => {
message.error('未选中公众号,无法查询已发表图文') message.error('未选中公众号,无法查询已发表图文')
return false return false
} }
// TODO await
loading.value = true loading.value = true
getFreePublishPage(queryParams) getFreePublishPage(queryParams)
.then((data) => { .then((data) => {
@ -106,18 +103,20 @@ const getList = async () => {
loading.value = false loading.value = false
}) })
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
const handleQuery = async () => { const handleQuery = () => {
queryParams.pageNo = 1 queryParams.pageNo = 1
getList() getList()
} }
/** 重置按钮操作 */ /** 重置按钮操作 */
const resetQuery = async () => { const resetQuery = () => {
queryFormRef.value.resetFields() queryFormRef.value.resetFields()
// //
if (accounts.value.length > 0) { if (accountList.value.length > 0) {
queryParams.accountId = accounts[0].id // @ts-ignore
queryParams.accountId = accountList.value[0].id
} }
handleQuery() handleQuery()
} }
@ -125,6 +124,7 @@ const resetQuery = async () => {
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (item) => { const handleDelete = async (item) => {
{ {
// TODO await
const articleId = item.articleId const articleId = item.articleId
const accountId = queryParams.accountId const accountId = queryParams.accountId
message message
@ -140,19 +140,16 @@ const handleDelete = async (item) => {
} }
} }
onMounted(() => { onMounted(async () => {
getSimpleAccounts().then((response) => { accountList.value = await MpAccountApi.getSimpleAccountList()
accounts.value = response //
// if (accountList.value.length > 0) {
if (accounts.value.length > 0) { // @ts-ignore
queryParams.accountId = accounts.value[0]['id'] queryParams.accountId = accountList.value[0].id
} }
// await getList()
getList()
})
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.pagination { .pagination {
float: right; float: right;

View File

@ -12,9 +12,9 @@
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px"> <el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option <el-option
v-for="item in accountList" v-for="item in accountList"
:key="parseInt(item.id)" :key="item.id"
:label="item.name" :label="item.name"
:value="parseInt(item.id)" :value="item.id"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
@ -60,11 +60,13 @@
<!-- 列表 --> <!-- 列表 -->
<ContentWrap> <ContentWrap>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="发送时间" align="center" prop="createTime" width="180"> <el-table-column
<template #default="scope"> label="发送时间"
<span>{{ parseTime(scope.row.createTime) }}</span> align="center"
</template> prop="createTime"
</el-table-column> width="180"
:formatter="dateFormatter"
/>
<el-table-column label="消息类型" align="center" prop="type" width="80" /> <el-table-column label="消息类型" align="center" prop="type" width="80" />
<el-table-column label="发送方" align="center" prop="sendFrom" width="80"> <el-table-column label="发送方" align="center" prop="sendFrom" width="80">
<template #default="scope"> <template #default="scope">
@ -180,13 +182,13 @@
</template> </template>
<script setup lang="ts" name="MpMessage"> <script setup lang="ts" name="MpMessage">
import { DICT_TYPE, getStrDictOptions } from '@/utils/dict' import { DICT_TYPE, getStrDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
// import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue' // import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue' import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
// import WxMsg from '@/views/mp/components/wx-msg/main.vue' // import WxMsg from '@/views/mp/components/wx-msg/main.vue'
import WxLocation from '@/views/mp/components/wx-location/main.vue' import WxLocation from '@/views/mp/components/wx-location/main.vue'
// import WxMusic from '@/views/mp/components/wx-music/main.vue' // import WxMusic from '@/views/mp/components/wx-music/main.vue'
// import WxNews from '@/views/mp/components/wx-news/main.vue' // import WxNews from '@/views/mp/components/wx-news/main.vue'
import { parseTime } from '@/utils/formatTime'
import * as MpAccountApi from '@/api/mp/account' import * as MpAccountApi from '@/api/mp/account'
import * as MpMessageApi from '@/api/mp/message' import * as MpMessageApi from '@/api/mp/message'
const message = useMessage() // const message = useMessage() //