mp:增加发送【图文】消息

This commit is contained in:
YunaiV 2023-01-12 23:57:17 +08:00
parent 5901ab6664
commit 02ccf52d6c
8 changed files with 91 additions and 87 deletions

View File

@ -19,6 +19,14 @@ tenant-id: {{adminTenentId}}
"content": "我是内容",
"contentSourceUrl": "https://www.iocoder.cn",
"thumbMediaId": "r6ryvl6LrxBU0miaST4Y-pIcmK-zAAId-9TGgy-DrSLhjVuWbuT3ZBjk9K1yQ0Dn"
},
{
"title": "我是标题 2",
"author": "我是作者 2",
"digest": "我是摘要 2",
"content": "我是内容 2",
"contentSourceUrl": "https://www.iocoder.cn",
"thumbMediaId": "r6ryvl6LrxBU0miaST4Y-pIcmK-zAAId-9TGgy-DrSLhjVuWbuT3ZBjk9K1yQ0Dn"
}
]
}

View File

@ -5,7 +5,7 @@ Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
### 请求 /mp/free-publish/submit 接口 => 成功
POST {{baseUrl}}/mp/free-publish/submit?accountId=1&mediaId=r6ryvl6LrxBU0miaST4Y-pEm50d1qKxNPkZVzrRZthSJHKCgiylCf4tARZfybZ_O
POST {{baseUrl}}/mp/free-publish/submit?accountId=1&mediaId=r6ryvl6LrxBU0miaST4Y-vilmd7iS51D8IPddxflWrau0hIQ2ovY8YanO5jlgUcM
Content-Type: application/json
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}

View File

@ -44,6 +44,7 @@ public class MpFreePublishController {
} catch (WxErrorException e) {
throw exception(FREE_PUBLISH_LIST_FAIL, e.getError().getErrorMsg());
}
// todo 芋艿需要查询对应的缩略图不然前端无法展示
// 返回分页
return success(new PageResult<>(publicationRecords.getItems(), publicationRecords.getTotalCount().longValue()));

View File

@ -0,0 +1,10 @@
import request from '@/utils/request'
// 获得公众号素材分页
export function getFreePublishPage(query) {
return request({
url: '/mp/free-publish/page',
method: 'get',
params: query
})
}

View File

@ -48,7 +48,7 @@
</el-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getMaterialPage"/>
@pagination="getPage"/>
</div>
<div v-else-if="objData.type === 'video'">
<!-- 列表 -->
@ -78,41 +78,32 @@
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getMaterialPage"/>
</div>
<div v-else-if="objData.type == 'news'">
<div v-else-if="objData.type === 'news'">
<div class="waterfall" v-loading="loading">
<div class="waterfall-item" v-for="item in list" :key="item.mediaId" v-if="item.content && item.content.articles">
<WxNews :objData="item.content.articles"></WxNews>
<div class="waterfall-item" v-for="item in list" :key="item.mediaId" v-if="item.content && item.content.newsItem">
<wx-news :articles="item.content.newsItem" />
<el-row class="ope-row">
<el-button size="mini" type="success" @click="selectMaterial(item)">选择<i class="el-icon-circle-check el-icon--right"></i></el-button>
<el-button size="mini" type="success" @click="selectMaterial(item)">
选择<i class="el-icon-circle-check el-icon--right"></i>
</el-button>
</el-row>
</div>
</div>
<div v-if="list.length <=0 && !loading" class="el-table__empty-block">
<!-- 分页组件 -->
<div v-if="list.length <= 0 && !loading" class="el-table__empty-block">
<span class="el-table__empty-text">暂无数据</span>
</div>
<span slot="footer" class="dialog-footer">
<el-pagination
@size-change="sizeChange"
:current-page.sync="page.currentPage"
:page-sizes="[10, 20]"
:page-size="page.pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="page.total"
class="pagination"
>
</el-pagination>
</span>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getMaterialPage"/>
</div>
</template>
<script>
// import { tableOptionVoice } from '@/const/crud/wxmp/wxmaterial_voice'
// import { tableOptionVideo } from '@/const/crud/wxmp/wxmaterial_video'
import WxNews from '@/views/mp/components/wx-news/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 { getMaterialPage } from "@/api/mp/material";
import {getFreePublishPage} from "@/api/mp/freePublish";
export default {
name: "wxMaterialSelect",
@ -143,56 +134,40 @@
queryParams: {
pageNo: 1,
pageSize: 10,
accountId: this.objData.accountId,
},
// tableOptionVoice: tableOptionVoice,
// tableOptionVideo: tableOptionVideo,
}
},
created() {
this.getPage(this.page)
this.getPage()
},
methods:{
selectMaterial(item){
selectMaterial(item) {
this.$emit('selectMaterial', item)
},
getPage(page, params) {
getPage() {
this.loading = true
if(this.objData.type == 'news'){ //
if(this.newsType == '1'){
getPageNews(Object.assign({
current: page.currentPage,
size: page.pageSize,
appId:this.appId,
}, params)).then(response => {
let tableData = response.data.items
tableData.forEach(item => {
item.mediaId = item.articleId
item.content.articles = item.content.newsItem
})
this.list = tableData
this.page.total = response.data.totalCount
this.page.currentPage = page.currentPage
this.page.pageSize = page.pageSize
this.loading = false
if (this.objData.type === 'news' && this.newsType === '1') { // +
this.getFreePublishPage();
} else if (this.objData.type === 'news' && this.newsType === '2') { // + 稿
getPageNewsDraft(Object.assign({
current: page.currentPage,
size: page.pageSize,
appId:this.appId,
}, params)).then(response => {
let tableData = response.data.items
tableData.forEach(item => {
item.mediaId = item.mediaId
item.content.articles = item.content.newsItem
})
}else if(this.newsType == '2'){
getPageNewsDraft(Object.assign({
current: page.currentPage,
size: page.pageSize,
appId:this.appId,
}, params)).then(response => {
let tableData = response.data.items
tableData.forEach(item => {
item.mediaId = item.mediaId
item.content.articles = item.content.newsItem
})
this.list = tableData
this.page.total = response.data.totalCount
this.page.currentPage = page.currentPage
this.page.pageSize = page.pageSize
this.loading = false
})
}
this.list = tableData
this.page.total = response.data.totalCount
this.page.currentPage = page.currentPage
this.page.pageSize = page.pageSize
this.loading = false
})
} else { //
this.getMaterialPage();
}
@ -208,20 +183,20 @@
this.loading = false
})
},
sizeChange(val) {
this.page.currentPage = 1
this.page.pageSize = val
this.getPage(this.page)
},
currentChange(val) {
this.page.currentPage = val
this.getPage(this.page)
},
/**
* 刷新回调
*/
refreshChange(page) {
this.getPage(this.page)
getFreePublishPage() {
getFreePublishPage(this.queryParams).then(response => {
// thumbUrl picUrl wx-news
response.data.list.forEach(item => {
const newsItem = item.content.newsItem;
newsItem.forEach(article => {
article.picUrl = article.thumbUrl;
})
})
this.list = response.data.list
this.total = response.data.total
}).finally(() => {
this.loading = false
})
}
}
};

View File

@ -155,21 +155,23 @@ import { getUser } from "@/api/mp/user";
if (!this.objData) {
return;
}
if (this.objData.type === 'news') {
this.objData.content.articles = [this.objData.content.articles[0]]
//
if (this.objData.type === 'news'
&& this.objData.articles.length > 1) {
this.objData.articles = [this.objData.articles[0]]
this.$message({
showClose: true,
message: '图文消息条数限制在1条以内已默认发送第一条',
message: '图文消息条数限制在 1 条以内,已默认发送第一条',
type: 'success'
})
}
//
this.sendLoading = true
sendMessage(Object.assign({
userId: this.userId
}, {
...this.objData,
// content: this.objData.repContent,
// TODO
...this.objData
})).then(response => {
this.sendLoading = false
//

View File

@ -41,7 +41,10 @@
articles: {
type: Array // title - description - picUrl - url -
}
}
},
created() {
console.log(this.articles)
},
};
</script>

View File

@ -118,18 +118,20 @@
</el-row>
</el-row>
</el-tab-pane>
<!-- 类型 5图文 -->
<el-tab-pane name="news">
<span slot="label"><i class="el-icon-news"></i> 图文</span>
<el-row>
<div class="select-item" v-if="objData.content">
<WxNews :objData="objData.content.articles"></WxNews>
<div class="select-item" v-if="objData.articles">
<wx-news :articles="objData.articles" />
<el-row class="ope-row">
<el-button type="danger" icon="el-icon-delete" circle @click="deleteObj"></el-button>
<el-button type="danger" icon="el-icon-delete" circle @click="deleteObj" />
</el-row>
</div>
<!-- 选择素材 -->
<div v-if="!objData.content">
<el-row style="text-align: center">
<el-col :span="24" class="col-select2">
<el-col :span="24">
<el-button type="success" @click="openMaterial">{{newsType === '1' ? '选择已发布图文' : '选择草稿箱图文'}}<i class="el-icon-circle-check el-icon--right"></i></el-button>
</el-col>
</el-row>
@ -369,7 +371,10 @@
// tempObjItem
let tempObjItem = {}
tempObjItem.type = this.objData.type;
if (this.objData.type === 'music') { //
if (this.objData.type === 'news') {
tempObjItem.articles = item.content.newsItem
this.objData.articles = item.content.newsItem
} else if (this.objData.type === 'music') { //
tempObjItem.thumbMediaId = item.mediaId
this.objData.thumbMediaId = item.mediaId
tempObjItem.thumbMediaUrl = item.url
@ -431,7 +436,7 @@
},
deleteObj() {
if (this.objData.type === 'news') {
this.objData.articles = []
this.$delete(this.objData, 'articles');
} else if(this.objData.type === 'image') {
this.objData.mediaId = null
this.objData.url = null