Skip to content

Commit 0502eb1

Browse files
committed
mp:增加发送【图文】消息
1 parent 5030aa5 commit 0502eb1

File tree

5 files changed

+81
-86
lines changed

5 files changed

+81
-86
lines changed

src/api/mp/freePublish.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import request from '@/utils/request'
2+
3+
// 获得公众号素材分页
4+
export function getFreePublishPage(query) {
5+
return request({
6+
url: '/mp/free-publish/page',
7+
method: 'get',
8+
params: query
9+
})
10+
}

src/views/mp/components/wx-material-select/main.vue

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</el-table>
4949
<!-- 分页组件 -->
5050
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
51-
@pagination="getMaterialPage"/>
51+
@pagination="getPage"/>
5252
</div>
5353
<div v-else-if="objData.type === 'video'">
5454
<!-- 列表 -->
@@ -78,41 +78,32 @@
7878
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
7979
@pagination="getMaterialPage"/>
8080
</div>
81-
<div v-else-if="objData.type == 'news'">
81+
<div v-else-if="objData.type === 'news'">
8282
<div class="waterfall" v-loading="loading">
83-
<div class="waterfall-item" v-for="item in list" :key="item.mediaId" v-if="item.content && item.content.articles">
84-
<WxNews :objData="item.content.articles"></WxNews>
83+
<div class="waterfall-item" v-for="item in list" :key="item.mediaId" v-if="item.content && item.content.newsItem">
84+
<wx-news :articles="item.content.newsItem" />
8585
<el-row class="ope-row">
86-
<el-button size="mini" type="success" @click="selectMaterial(item)">选择<i class="el-icon-circle-check el-icon--right"></i></el-button>
86+
<el-button size="mini" type="success" @click="selectMaterial(item)">
87+
选择<i class="el-icon-circle-check el-icon--right"></i>
88+
</el-button>
8789
</el-row>
8890
</div>
8991
</div>
90-
<div v-if="list.length <=0 && !loading" class="el-table__empty-block">
92+
<!-- 分页组件 -->
93+
<div v-if="list.length <= 0 && !loading" class="el-table__empty-block">
9194
<span class="el-table__empty-text">暂无数据</span>
9295
</div>
93-
<span slot="footer" class="dialog-footer">
94-
<el-pagination
95-
@size-change="sizeChange"
96-
:current-page.sync="page.currentPage"
97-
:page-sizes="[10, 20]"
98-
:page-size="page.pageSize"
99-
layout="total, sizes, prev, pager, next, jumper"
100-
:total="page.total"
101-
class="pagination"
102-
>
103-
</el-pagination>
104-
</span>
96+
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
97+
@pagination="getMaterialPage"/>
10598
</div>
10699
</template>
107100

108101
<script>
109-
110-
// import { tableOptionVoice } from '@/const/crud/wxmp/wxmaterial_voice'
111-
// import { tableOptionVideo } from '@/const/crud/wxmp/wxmaterial_video'
112102
import WxNews from '@/views/mp/components/wx-news/main.vue';
113103
import WxVoicePlayer from '@/views/mp/components/wx-voice-play/main.vue';
114104
import WxVideoPlayer from '@/views/mp/components/wx-video-play/main.vue';
115105
import { getMaterialPage } from "@/api/mp/material";
106+
import {getFreePublishPage} from "@/api/mp/freePublish";
116107
117108
export default {
118109
name: "wxMaterialSelect",
@@ -143,56 +134,40 @@
143134
queryParams: {
144135
pageNo: 1,
145136
pageSize: 10,
137+
accountId: this.objData.accountId,
146138
},
147139
// tableOptionVoice: tableOptionVoice,
148140
// tableOptionVideo: tableOptionVideo,
149141
}
150142
},
151143
created() {
152-
this.getPage(this.page)
144+
this.getPage()
153145
},
154146
methods:{
155-
selectMaterial(item){
147+
selectMaterial(item) {
156148
this.$emit('selectMaterial', item)
157149
},
158-
getPage(page, params) {
150+
getPage() {
159151
this.loading = true
160-
if(this.objData.type == 'news'){ // 【图文】
161-
if(this.newsType == '1'){
162-
getPageNews(Object.assign({
163-
current: page.currentPage,
164-
size: page.pageSize,
165-
appId:this.appId,
166-
}, params)).then(response => {
167-
let tableData = response.data.items
168-
tableData.forEach(item => {
169-
item.mediaId = item.articleId
170-
item.content.articles = item.content.newsItem
171-
})
172-
this.list = tableData
173-
this.page.total = response.data.totalCount
174-
this.page.currentPage = page.currentPage
175-
this.page.pageSize = page.pageSize
176-
this.loading = false
177-
})
178-
}else if(this.newsType == '2'){
179-
getPageNewsDraft(Object.assign({
180-
current: page.currentPage,
181-
size: page.pageSize,
182-
appId:this.appId,
183-
}, params)).then(response => {
184-
let tableData = response.data.items
185-
tableData.forEach(item => {
186-
item.mediaId = item.mediaId
187-
item.content.articles = item.content.newsItem
188-
})
189-
this.list = tableData
190-
this.page.total = response.data.totalCount
191-
this.page.currentPage = page.currentPage
192-
this.page.pageSize = page.pageSize
193-
this.loading = false
152+
if (this.objData.type === 'news' && this.newsType === '1') { // 【图文】+ 【已发布】
153+
this.getFreePublishPage();
154+
} else if (this.objData.type === 'news' && this.newsType === '2') { // 【图文】+ 【草稿】
155+
getPageNewsDraft(Object.assign({
156+
current: page.currentPage,
157+
size: page.pageSize,
158+
appId:this.appId,
159+
}, params)).then(response => {
160+
let tableData = response.data.items
161+
tableData.forEach(item => {
162+
item.mediaId = item.mediaId
163+
item.content.articles = item.content.newsItem
194164
})
195-
}
165+
this.list = tableData
166+
this.page.total = response.data.totalCount
167+
this.page.currentPage = page.currentPage
168+
this.page.pageSize = page.pageSize
169+
this.loading = false
170+
})
196171
} else { // 【素材】
197172
this.getMaterialPage();
198173
}
@@ -208,20 +183,20 @@
208183
this.loading = false
209184
})
210185
},
211-
sizeChange(val) {
212-
this.page.currentPage = 1
213-
this.page.pageSize = val
214-
this.getPage(this.page)
215-
},
216-
currentChange(val) {
217-
this.page.currentPage = val
218-
this.getPage(this.page)
219-
},
220-
/**
221-
* 刷新回调
222-
*/
223-
refreshChange(page) {
224-
this.getPage(this.page)
186+
getFreePublishPage() {
187+
getFreePublishPage(this.queryParams).then(response => {
188+
// 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面
189+
response.data.list.forEach(item => {
190+
const newsItem = item.content.newsItem;
191+
newsItem.forEach(article => {
192+
article.picUrl = article.thumbUrl;
193+
})
194+
})
195+
this.list = response.data.list
196+
this.total = response.data.total
197+
}).finally(() => {
198+
this.loading = false
199+
})
225200
}
226201
}
227202
};

src/views/mp/components/wx-msg/main.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,23 @@ import { getUser } from "@/api/mp/user";
155155
if (!this.objData) {
156156
return;
157157
}
158-
if (this.objData.type === 'news') {
159-
this.objData.content.articles = [this.objData.content.articles[0]]
158+
// 公众号限制:客服消息,公众号只允许发送一条
159+
if (this.objData.type === 'news'
160+
&& this.objData.articles.length > 1) {
161+
this.objData.articles = [this.objData.articles[0]]
160162
this.$message({
161163
showClose: true,
162-
message: '图文消息条数限制在1条以内,已默认发送第一条',
164+
message: '图文消息条数限制在 1 条以内,已默认发送第一条',
163165
type: 'success'
164166
})
165167
}
168+
169+
// 执行发送
166170
this.sendLoading = true
167171
sendMessage(Object.assign({
168172
userId: this.userId
169173
}, {
170-
...this.objData,
171-
// content: this.objData.repContent,
172-
// TODO 芋艿:临时适配,保证可用
174+
...this.objData
173175
})).then(response => {
174176
this.sendLoading = false
175177
// 添加到消息列表,并滚动

src/views/mp/components/wx-news/main.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
articles: {
4242
type: Array // title - 标题;description - 描述;picUrl - 图片连接;url - 跳转链接
4343
}
44-
}
44+
},
45+
created() {
46+
console.log(this.articles)
47+
},
4548
};
4649
</script>
4750

src/views/mp/components/wx-reply/main.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,20 @@
118118
</el-row>
119119
</el-row>
120120
</el-tab-pane>
121+
<!-- 类型 5:图文 -->
121122
<el-tab-pane name="news">
122123
<span slot="label"><i class="el-icon-news"></i> 图文</span>
123124
<el-row>
124-
<div class="select-item" v-if="objData.content">
125-
<WxNews :objData="objData.content.articles"></WxNews>
125+
<div class="select-item" v-if="objData.articles">
126+
<wx-news :articles="objData.articles" />
126127
<el-row class="ope-row">
127-
<el-button type="danger" icon="el-icon-delete" circle @click="deleteObj"></el-button>
128+
<el-button type="danger" icon="el-icon-delete" circle @click="deleteObj" />
128129
</el-row>
129130
</div>
131+
<!-- 选择素材 -->
130132
<div v-if="!objData.content">
131133
<el-row style="text-align: center">
132-
<el-col :span="24" class="col-select2">
134+
<el-col :span="24">
133135
<el-button type="success" @click="openMaterial">{{newsType === '1' ? '选择已发布图文' : '选择草稿箱图文'}}<i class="el-icon-circle-check el-icon--right"></i></el-button>
134136
</el-col>
135137
</el-row>
@@ -369,7 +371,10 @@
369371
// 创建 tempObjItem 对象,并设置对应的值
370372
let tempObjItem = {}
371373
tempObjItem.type = this.objData.type;
372-
if (this.objData.type === 'music') { // 音乐需要特殊处理,因为选择的是图片的缩略图
374+
if (this.objData.type === 'news') {
375+
tempObjItem.articles = item.content.newsItem
376+
this.objData.articles = item.content.newsItem
377+
} else if (this.objData.type === 'music') { // 音乐需要特殊处理,因为选择的是图片的缩略图
373378
tempObjItem.thumbMediaId = item.mediaId
374379
this.objData.thumbMediaId = item.mediaId
375380
tempObjItem.thumbMediaUrl = item.url
@@ -431,7 +436,7 @@
431436
},
432437
deleteObj() {
433438
if (this.objData.type === 'news') {
434-
this.objData.articles = []
439+
this.$delete(this.objData, 'articles');
435440
} else if(this.objData.type === 'image') {
436441
this.objData.mediaId = null
437442
this.objData.url = null

0 commit comments

Comments
 (0)