refactor: 【草稿,素材】应用【公众号选择器】组件

(cherry picked from commit e035eb2618)
This commit is contained in:
dhb52 2023-04-10 00:25:45 +08:00 committed by shizhong
parent e480b68c08
commit 6b33f8c74f
2 changed files with 85 additions and 147 deletions

View File

@ -3,31 +3,13 @@
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChanged(accountId)">
class="-mb-15px" <template #actions>
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
<el-button type="primary" plain @click="handleAdd" v-hasPermi="['mp:draft:create']"> <el-button type="primary" plain @click="handleAdd" v-hasPermi="['mp:draft:create']">
<Icon icon="ep:plus" />新增 <Icon icon="ep:plus" />新增
</el-button> </el-button>
</el-form-item> </template>
</el-form> </WxAccountSelect>
</ContentWrap> </ContentWrap>
<!-- 列表 --> <!-- 列表 -->
@ -35,7 +17,7 @@
<div class="waterfall" v-loading="loading"> <div class="waterfall" v-loading="loading">
<template v-for="item in list" :key="item.articleId"> <template v-for="item in list" :key="item.articleId">
<div class="waterfall-item" v-if="item.content && item.content.newsItem"> <div class="waterfall-item" v-if="item.content && item.content.newsItem">
<wx-news :articles="item.content.newsItem" /> <WxNews :articles="item.content.newsItem" />
<!-- 操作按钮 --> <!-- 操作按钮 -->
<el-row class="ope-row"> <el-row class="ope-row">
<el-button <el-button
@ -239,7 +221,7 @@
</div> </div>
<!--富文本编辑器组件--> <!--富文本编辑器组件-->
<el-row> <el-row>
<wx-editor <WxEditor
v-model="articlesAdd[isActiveAddNews].content" v-model="articlesAdd[isActiveAddNews].content"
:account-id="uploadData.accountId" :account-id="uploadData.accountId"
v-if="hackResetEditor" v-if="hackResetEditor"
@ -258,14 +240,15 @@
import WxEditor from '@/views/mp/components/wx-editor/WxEditor.vue' import WxEditor from '@/views/mp/components/wx-editor/WxEditor.vue'
import WxNews from '@/views/mp/components/wx-news/main.vue' import WxNews from '@/views/mp/components/wx-news/main.vue'
import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue' import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import { getAccessToken } from '@/utils/auth' import { getAccessToken } from '@/utils/auth'
import * as MpAccountApi from '@/api/mp/account'
import * as MpDraftApi from '@/api/mp/draft' import * as MpDraftApi from '@/api/mp/draft'
import * as MpFreePublishApi from '@/api/mp/freePublish' import * as MpFreePublishApi from '@/api/mp/freePublish'
const message = useMessage() //
// API // API
// import drafts from './mock' // import drafts from './mock'
const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
const total = ref(0) // const total = ref(0) //
const list = ref([]) // const list = ref([]) //
@ -274,8 +257,6 @@ const queryParams = reactive({
pageSize: 10, pageSize: 10,
accountId: undefined accountId: undefined
}) })
const queryFormRef = ref() //
const accountList = ref([]) //
// ========== ========== // ========== ==========
const materialSelectRef = ref() const materialSelectRef = ref()
@ -298,16 +279,11 @@ const operateMaterial = ref('add')
const articlesMediaId = ref('') const articlesMediaId = ref('')
const hackResetEditor = ref(false) const hackResetEditor = ref(false)
/** 初始化 **/ /** 侦听公众号变化 **/
onMounted(async () => { const accountChanged = (accountId) => {
accountList.value = await MpAccountApi.getSimpleAccountList() setAccountId(accountId)
// getList()
if (accountList.value.length > 0) { }
// @ts-ignore
queryParams.accountId = accountList.value[0].id
}
await getList()
})
// ======================== ======================== // ======================== ========================
/** 设置账号编号 */ /** 设置账号编号 */
@ -341,26 +317,6 @@ const getList = async () => {
} }
} }
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
//
if (queryParams.accountId) {
setAccountId(queryParams.accountId)
}
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
handleQuery()
}
// ======================== /稿 ======================== // ======================== /稿 ========================
/** 新增按钮操作 */ /** 新增按钮操作 */
const handleAdd = () => { const handleAdd = () => {

View File

@ -1,28 +1,7 @@
<template> <template>
<!-- 搜索工作栏 --> <!-- 搜索工作栏 -->
<ContentWrap> <ContentWrap>
<el-form <WxAccountSelect @change="(accountId) => accountChange(accountId)" />
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="68px"
>
<el-form-item label="公众号" prop="accountId">
<el-select v-model="queryParams.accountId" placeholder="请选择公众号" class="!w-240px">
<el-option
v-for="item in accountList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" />搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" />重置</el-button>
</el-form-item>
</el-form>
</ContentWrap> </ContentWrap>
<ContentWrap> <ContentWrap>
@ -30,7 +9,7 @@
<!-- tab 1图片 --> <!-- tab 1图片 -->
<el-tab-pane name="image"> <el-tab-pane name="image">
<template #label> <template #label>
<span><Icon icon="ep:picture" />图片</span> <span> <Icon icon="ep:picture" />图片 </span>
</template> </template>
<div class="add_but" v-hasPermi="['mp:material:upload-permanent']"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-upload <el-upload
@ -81,7 +60,7 @@
<!-- tab 2语音 --> <!-- tab 2语音 -->
<el-tab-pane name="voice"> <el-tab-pane name="voice">
<template #label> <template #label>
<span><Icon icon="ep:microphone" />语音</span> <span> <Icon icon="ep:microphone" />语音 </span>
</template> </template>
<div class="add_but" v-hasPermi="['mp:material:upload-permanent']"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-upload <el-upload
@ -110,9 +89,15 @@
<WxVoicePlayer :url="scope.row.url" /> <WxVoicePlayer :url="scope.row.url" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="上传时间" align="center" prop="createTime" width="180"> <el-table-column
label="上传时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180"
>
<template #default="scope"> <template #default="scope">
<span>{{ formatDate(scope.row.createTime) }}</span> <span>{{ scope.row.createTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
@ -144,7 +129,7 @@
<!-- tab 3视频 --> <!-- tab 3视频 -->
<el-tab-pane name="video"> <el-tab-pane name="video">
<template #label> <template #label>
<span><Icon icon="ep:video-play" /> 视频</span> <span> <Icon icon="ep:video-play" /> 视频 </span>
</template> </template>
<div class="add_but" v-hasPermi="['mp:material:upload-permanent']"> <div class="add_but" v-hasPermi="['mp:material:upload-permanent']">
<el-button type="primary" plain @click="handleAddVideo">新建视频</el-button> <el-button type="primary" plain @click="handleAddVideo">新建视频</el-button>
@ -211,16 +196,22 @@
<WxVideoPlayer :url="scope.row.url" /> <WxVideoPlayer :url="scope.row.url" />
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="上传时间" align="center" prop="createTime" width="180"> <el-table-column
label="上传时间"
align="center"
:formatter="dateFormatter"
prop="createTime"
width="180"
>
<template #default="scope"> <template #default="scope">
<span>{{ formatDate(scope.row.createTime) }}</span> <span>{{ scope.row.createTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" fixed="right"> <el-table-column label="操作" align="center" fixed="right">
<template #default="scope"> <template #default="scope">
<el-button type="primary" link plain @click="handleDownload(scope.row)" <el-button type="primary" link plain @click="handleDownload(scope.row)">
><Icon icon="ep:download" />下载</el-button <Icon icon="ep:download" />下载
> </el-button>
<el-button <el-button
type="primary" type="primary"
link link
@ -248,16 +239,19 @@
<script setup name="MpMaterial"> <script setup name="MpMaterial">
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue' import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue'
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue' import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue'
import { getSimpleAccountList } from '@/api/mp/account' import WxAccountSelect from '@/views/mp/components/wx-account-select/main.vue'
import { getMaterialPage, deletePermanentMaterial } from '@/api/mp/material' // import * as MpAccountApi from '@/api/mp/account'
import { getAccessToken } from '@/utils/auth' import * as MpMaterialApi from '@/api/mp/material'
import { formatDate } from '@/utils/formatTime' import * as authUtil from '@/utils/auth'
import { dateFormatter } from '@/utils/formatTime'
const BASE_URL = import.meta.env.VITE_BASE_URL
const message = useMessage() const message = useMessage()
const queryFormRef = ref() const BASE_URL = import.meta.env.VITE_BASE_URL
const actionUrl = BASE_URL + '/admin-api/mp/material/upload-permanent'
const headers = { Authorization: 'Bearer ' + authUtil.getAccessToken() }
// const queryFormRef = ref()
const uploadFormRef = ref() const uploadFormRef = ref()
const uploadVideoRef = ref() const uploadVideoRef = ref()
@ -276,8 +270,6 @@ const queryParams = reactive({
permanent: true permanent: true
}) })
const actionUrl = BASE_URL + '/admin-api/mp/material/upload-permanent'
const headers = { Authorization: 'Bearer ' + getAccessToken() }
const fileList = ref([]) const fileList = ref([])
const uploadData = reactive({ const uploadData = reactive({
type: 'image', type: 'image',
@ -294,20 +286,11 @@ const uploadRules = reactive({
introduction: [{ required: true, message: '请输入描述', trigger: 'blur' }] introduction: [{ required: true, message: '请输入描述', trigger: 'blur' }]
}) })
// /** 侦听公众号变化 **/
const accountList = ref([]) const accountChange = (accountId) => {
setAccountId(accountId)
onMounted(() => { getList()
getSimpleAccountList().then((data) => { }
accountList.value = data
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
//
getList()
})
})
// ======================== ======================== // ======================== ========================
/** 设置账号编号 */ /** 设置账号编号 */
@ -317,7 +300,7 @@ const setAccountId = (accountId) => {
} }
/** 查询列表 */ /** 查询列表 */
const getList = () => { const getList = async () => {
// //
if (!queryParams.accountId) { if (!queryParams.accountId) {
message.error('未选中公众号,无法查询草稿箱') message.error('未选中公众号,无法查询草稿箱')
@ -325,17 +308,16 @@ const getList = () => {
} }
loading.value = true loading.value = true
getMaterialPage({ try {
...queryParams, const data = await MpMaterialApi.getMaterialPage({
type: type.value ...queryParams,
}) type: type.value
.then((data) => {
list.value = data.list
total.value = data.total
})
.finally(() => {
loading.value = false
}) })
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
} }
/** 搜索按钮操作 */ /** 搜索按钮操作 */
@ -348,31 +330,23 @@ const handleQuery = () => {
getList() getList()
} }
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
//
if (accountList.value.length > 0) {
setAccountId(accountList.value[0].id)
}
handleQuery()
}
const handleTabChange = (tabName) => { const handleTabChange = (tabName) => {
// type // type
uploadData.type = tabName uploadData.type = tabName
// tab
list.value = []
total.value = 0
// //
handleQuery() handleQuery()
} }
// ======================== ======================== // ======================== ========================
const beforeImageUpload = (file) => { const beforeImageUpload = (file) => {
const isType = const isType = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/jpg'].includes(
file.type === 'image/jpeg' || file.type
file.type === 'image/png' || )
file.type === 'image/gif' ||
file.type === 'image/bmp' ||
file.type === 'image/jpg'
if (!isType) { if (!isType) {
message.error('上传图片格式不对!') message.error('上传图片格式不对!')
return false return false
@ -387,11 +361,7 @@ const beforeImageUpload = (file) => {
} }
const beforeVoiceUpload = (file) => { const beforeVoiceUpload = (file) => {
const isType = const isType = ['audio/mp3', 'audio/wma', 'audio/wav', 'audio/amr'].includes(file.type)
file.type === 'audio/mp3' ||
file.type === 'audio/wma' ||
file.type === 'audio/wav' ||
file.type === 'audio/amr'
const isLt = file.size / 1024 / 1024 < 2 const isLt = file.size / 1024 / 1024 < 2
if (!isType) { if (!isType) {
message.error('上传语音格式不对!') message.error('上传语音格式不对!')
@ -411,11 +381,13 @@ const beforeVideoUpload = (file) => {
message.error('上传视频格式不对!') message.error('上传视频格式不对!')
return false return false
} }
const isLt = file.size / 1024 / 1024 < 10 const isLt = file.size / 1024 / 1024 < 10
if (!isLt) { if (!isLt) {
message.error('上传视频大小不能超过 10M!') message.error('上传视频大小不能超过 10M!')
return false return false
} }
addMaterialLoading.value = true addMaterialLoading.value = true
return true return true
} }
@ -475,7 +447,7 @@ const resetVideo = () => {
// ======================== ======================== // ======================== ========================
const handleDelete = async (item) => { const handleDelete = async (item) => {
await message.confirm('此操作将永久删除该文件, 是否继续?') await message.confirm('此操作将永久删除该文件, 是否继续?')
await deletePermanentMaterial(item.id) await MpMaterialApi.deletePermanentMaterial(item.id)
message.alertSuccess('删除成功') message.alertSuccess('删除成功')
} }
</script> </script>
@ -486,40 +458,50 @@ const handleDelete = async (item) => {
width: 100%; width: 100%;
column-gap: 10px; column-gap: 10px;
column-count: 5; column-count: 5;
margin-top: 10px; /* 芋道源码:增加 10px避免顶着上面 */ margin-top: 10px;
/* 芋道源码:增加 10px避免顶着上面 */
} }
.waterfall-item { .waterfall-item {
padding: 10px; padding: 10px;
margin-bottom: 10px; margin-bottom: 10px;
break-inside: avoid; break-inside: avoid;
border: 1px solid #eaeaea; border: 1px solid #eaeaea;
} }
.material-img { .material-img {
width: 100%; width: 100%;
} }
p { p {
line-height: 30px; line-height: 30px;
} }
@media (min-width: 992px) and (max-width: 1300px) { @media (min-width: 992px) and (max-width: 1300px) {
.waterfall { .waterfall {
column-count: 3; column-count: 3;
} }
p { p {
color: red; color: red;
} }
} }
@media (min-width: 768px) and (max-width: 991px) { @media (min-width: 768px) and (max-width: 991px) {
.waterfall { .waterfall {
column-count: 2; column-count: 2;
} }
p { p {
color: orange; color: orange;
} }
} }
@media (max-width: 767px) { @media (max-width: 767px) {
.waterfall { .waterfall {
column-count: 1; column-count: 1;
} }
} }
/*瀑布流样式*/ /*瀑布流样式*/
</style> </style>