Skip to content

Commit d4cd9f9

Browse files
committed
mp:初步实现【草稿】的前端新增
1 parent 0f68ead commit d4cd9f9

File tree

2 files changed

+105
-76
lines changed

2 files changed

+105
-76
lines changed

src/api/mp/draft.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,14 @@ export function getDraftPage(query) {
88
params: query
99
})
1010
}
11+
12+
// 创建草稿
13+
export function createDraft(accountId, articles) {
14+
return request({
15+
url: '/mp/draft/create?accountId=' + accountId,
16+
method: 'post',
17+
data: {
18+
articles
19+
}
20+
})
21+
}

src/views/mp/draft/index.vue

Lines changed: 94 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ SOFTWARE.
6060
</div>
6161
</div>
6262
<!-- 分页记录 -->
63-
<div v-if="list.length <=0 && !loading" class="el-table__empty-block">
63+
<div v-if="list.length <= 0 && !loading" class="el-table__empty-block">
6464
<span class="el-table__empty-text">暂无数据</span>
6565
</div>
6666
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
6767
@pagination="getList"/>
6868

6969
<!-- TODO 芋艿:位置调整 -->
70-
<el-dialog :title="operateMaterial === 'add'?'新建图文':'修改图文'"
70+
<el-dialog :title="operateMaterial === 'add' ? '新建图文' : '修改图文'"
7171
append-to-body
7272
:before-close="dialogNewsClose"
7373
:close-on-click-modal="false"
@@ -103,13 +103,13 @@ SOFTWARE.
103103
@click="downNews(index)">下移
104104
</el-button>
105105
<el-button type="mini" icon="el-icon-sort-up" @click="upNews(index)">上移</el-button>
106-
<el-button v-if="operateMaterial=='add'" type="mini" icon="el-icon-delete"
106+
<el-button v-if="operateMaterial=== 'add'" type="mini" icon="el-icon-delete"
107107
@click="minusNews(index)">删除
108108
</el-button>
109109
</div>
110110
</div>
111111
</div>
112-
<div class="news-main-plus" @click="plusNews" v-if="articlesAdd.length<8 && operateMaterial=='add'">
112+
<div class="news-main-plus" @click="plusNews" v-if="articlesAdd.length<8 && operateMaterial==='add'">
113113
<i class="el-icon-circle-plus icon-plus"></i>
114114
</div>
115115
</div>
@@ -121,40 +121,30 @@ SOFTWARE.
121121
v-if="hackResetEditor"/>
122122
</el-row>
123123
<br><br><br><br>
124+
<!-- 封面和摘要 -->
124125
<div class="input-tt">封面和摘要:</div>
125126
<div>
126127
<div class="thumb-div">
127128
<img class="material-img" v-if="articlesAdd[isActiveAddNews].thumbUrl"
128-
:src="articlesAdd[isActiveAddNews].thumbUrl" :class="isActiveAddNews == 0 ? 'avatar':'avatar1'">
129+
:src="articlesAdd[isActiveAddNews].thumbUrl" :class="isActiveAddNews === 0 ? 'avatar':'avatar1'">
129130
<i v-else class="el-icon-plus avatar-uploader-icon"
130131
:class="isActiveAddNews === 0 ? 'avatar':'avatar1'"></i>
131132
<div class="thumb-but">
132-
<el-upload
133-
:action="actionUrl"
134-
:headers="headers"
135-
multiple
136-
:limit="1"
137-
:on-success="handleUploadSuccess"
138-
:file-list="fileList"
139-
:before-upload="beforeThumbImageUpload"
140-
:data="uploadData">
141-
<el-button slot="trigger" size="mini" type="primary">
142-
本地上传
143-
</el-button>
144-
<el-button size="mini" type="primary"
145-
@click="openMaterial" style="margin-left: 5px">素材库选择
146-
</el-button>
147-
<div slot="tip" class="el-upload__tip">支持bmp/png/jpeg/jpg/gif格式,大小不超过2M</div>
133+
<el-upload :action="actionUrl" :headers="headers" multiple :limit="1" :file-list="fileList" :data="uploadData"
134+
:before-upload="beforeThumbImageUpload" :on-success="handleUploadSuccess">
135+
<el-button slot="trigger" size="mini" type="primary">本地上传</el-button>
136+
<el-button size="mini" type="primary" @click="openMaterial" style="margin-left: 5px">素材库选择</el-button>
137+
<div slot="tip" class="el-upload__tip">支持 bmp/png/jpeg/jpg/gif 格式,大小不超过 2M</div>
148138
</el-upload>
149139
</div>
150140
</div>
151141
<el-dialog title="选择图片" :visible.sync="dialogImageVisible" width="80%" append-to-body>
152-
<WxMaterialSelect :objData="{repType:'image'}"
153-
@selectMaterial="selectMaterial"></WxMaterialSelect>
142+
<WxMaterialSelect :objData="{repType:'image'}" @selectMaterial="selectMaterial" />
154143
</el-dialog>
155144
<el-input :rows="8" type="textarea" v-model="articlesAdd[isActiveAddNews].digest" placeholder="请输入摘要"
156145
class="digest" maxlength="120"></el-input>
157146
</div>
147+
<!-- 标题、作者、原文地址 -->
158148
<div class="input-tt">标题:</div>
159149
<el-input v-model="articlesAdd[isActiveAddNews].title" placeholder="请输入标题"></el-input>
160150
<div class="input-tt">作者:</div>
@@ -171,13 +161,12 @@ SOFTWARE.
171161
</template>
172162

173163
<script>
174-
// import {getPage, addObj, delObj, putObj, publish} from '@/api/wxmp/wxdraft'
175164
// import { getPage as getPage1 } from '@/api/wxmp/wxmaterial'
176165
// import WxEditor from '@/components/Editor/WxEditor.vue'
177166
import WxNews from '@/views/mp/components/wx-news/main.vue';
178167
import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
179168
import { getAccessToken } from '@/utils/auth'
180-
import { getDraftPage } from "@/api/mp/draft";
169+
import {createDraft, getDraftPage} from "@/api/mp/draft";
181170
import {getSimpleAccounts} from "@/api/mp/account";
182171
183172
export default {
@@ -208,31 +197,33 @@ export default {
208197
currentPage: 1, // 当前页数
209198
pageSize: 10 // 每页显示多少条
210199
},
211-
actionUrl: process.env.VUE_APP_BASE_API +'/wxmaterial/materialFileUpload',
200+
201+
// ========== 文件上传 ==========
202+
actionUrl: process.env.VUE_APP_BASE_API + "/admin-api/mp/material/upload-permanent", // 上传永久素材的地址
212203
headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部
213204
fileList: [],
214-
dialogVideoVisible: false,
215-
dialogNewsVisible: false,
216-
addMaterialLoading: false,
217205
uploadData: {
218-
"mediaType": 'image',
206+
"type": 'image', // TODO 芋艿:试试要不要换成 thumb
219207
"title": '',
220-
"introduction": ''
208+
"introduction": '',
209+
"accountId": 1,
221210
},
222-
articlesAdd: [
223-
{
224-
"title": '',
225-
"thumbMediaId": '',
226-
"author": '',
227-
"digest": '',
228-
"showCoverPic": '',
229-
"content": '',
230-
"contentSourceUrl": '',
231-
"needOpenComment": '',
232-
"onlyFansCanComment": '',
233-
"thumbUrl": ''
234-
}
235-
],
211+
212+
// ========== 草稿新建 or 修改 ==========
213+
dialogNewsVisible: false,
214+
addMaterialLoading: false, // 添加草稿的 loading 标识
215+
articlesAdd: [{
216+
"title": '',
217+
"thumbMediaId": '',
218+
"author": '',
219+
"digest": '',
220+
"showCoverPic": '',
221+
"content": '123', // TODO 芋艿:临时测试
222+
"contentSourceUrl": '',
223+
"needOpenComment": '',
224+
"onlyFansCanComment": '',
225+
"thumbUrl": '',
226+
}],
236227
isActiveAddNews: 0,
237228
dialogImageVisible: false,
238229
imageListData: [],
@@ -251,12 +242,18 @@ export default {
251242
// 默认选中第一个
252243
if (this.accounts.length > 0) {
253244
this.queryParams.accountId = this.accounts[0].id;
245+
this.setAccountId(this.accounts[0].id);
254246
}
255247
// 加载数据
256-
this.getList();
248+
// this.getList();
257249
})
258250
},
259251
methods: {
252+
/** 设置账号编号 */
253+
setAccountId(accountId) {
254+
this.queryParams.accountId = accountId;
255+
this.uploadData.accountId = accountId;
256+
},
260257
/** 查询列表 */
261258
getList() {
262259
// 如果没有选中公众号账号,则进行提示。
@@ -280,6 +277,20 @@ export default {
280277
this.loading = false
281278
})
282279
},
280+
/** 搜索按钮操作 */
281+
handleQuery() {
282+
this.queryParams.pageNo = 1
283+
this.getList()
284+
},
285+
/** 重置按钮操作 */
286+
resetQuery() {
287+
this.resetForm('queryForm')
288+
// 默认选中第一个
289+
if (this.accounts.length > 0) {
290+
this.setAccountId(this.accounts[0].id)
291+
}
292+
this.handleQuery()
293+
},
283294
284295
delMaterial(item){
285296
this.$confirm('此操作将永久删除该草稿, 是否继续?', '提示', {
@@ -386,12 +397,10 @@ export default {
386397
)
387398
this.isActiveAddNews = this.articlesAdd.length - 1
388399
},
389-
subNews(){
400+
subNews() {
390401
this.addMaterialLoading = true
391-
if(this.operateMaterial == 'add'){
392-
addObj({
393-
articles:this.articlesAdd
394-
}).then(response => {
402+
if(this.operateMaterial === 'add'){
403+
createDraft(this.queryParams.accountId, this.articlesAdd).then(response => {
395404
this.addMaterialLoading = false
396405
this.dialogNewsVisible = false
397406
if(response.code == 200){
@@ -410,12 +419,11 @@ export default {
410419
"thumbUrl":''
411420
}
412421
]
413-
this.queryParams.currentPage = 1
414-
this.getList(this.queryParams)
415-
}else{
422+
this.getList()
423+
} else {
416424
this.$message.error('新增图文出错:' + response.msg)
417425
}
418-
}).catch(() => {
426+
}).finally(() => {
419427
this.addMaterialLoading = false
420428
})
421429
}
@@ -452,11 +460,11 @@ export default {
452460
}
453461
},
454462
handleEditNews(item){
455-
this.hackResetEditor = false//销毁组件
463+
this.hackResetEditor = false // 销毁组件
456464
this.$nextTick(() => {
457-
this.hackResetEditor = true//重建组件
465+
this.hackResetEditor = true // 重建组件
458466
})
459-
if(this.operateMaterial == 'add'){
467+
if (this.operateMaterial == 'add') {
460468
this.isActiveAddNews = 0
461469
}
462470
this.operateMaterial = 'edit'
@@ -465,9 +473,9 @@ export default {
465473
this.dialogNewsVisible = true
466474
},
467475
handleAddNews(){
468-
this.hackResetEditor = false//销毁组件
476+
this.hackResetEditor = false // 销毁组件
469477
this.$nextTick(() => {
470-
this.hackResetEditor = true//重建组件
478+
this.hackResetEditor = true // 重建组件
471479
})
472480
if(this.operateMaterial == 'edit'){
473481
this.isActiveAddNews = 0
@@ -491,30 +499,40 @@ export default {
491499
},
492500
beforeThumbImageUpload(file){
493501
this.addMaterialLoading = true
494-
const isType = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif' || file.type === 'image/bmp' || file.type === 'image/jpg';
495-
const isLt = file.size / 1024 / 1024 < 2
502+
const isType = file.type === 'image/jpeg'
503+
|| file.type === 'image/png'
504+
|| file.type === 'image/gif'
505+
|| file.type === 'image/bmp'
506+
|| file.type === 'image/jpg';
496507
if (!isType) {
497508
this.$message.error('上传图片格式不对!')
509+
this.addMaterialLoading = false
510+
return false;
498511
}
512+
const isLt = file.size / 1024 / 1024 < 2
499513
if (!isLt) {
500-
this.$message.error('上传图片大小不能超过2M!')
514+
this.$message.error('上传图片大小不能超过 2M!')
515+
this.addMaterialLoading = false
516+
return false;
501517
}
502-
this.addMaterialLoading = false
503-
return isType && isLt;
518+
// 校验通过
519+
return true;
504520
},
505-
handleUploadSuccess(response, file, fileList){
506-
this.loading = false
507-
this.addMaterialLoading = false
508-
if(response.code == 200){
509-
this.dialogVideoVisible = false
510-
this.fileList = []
511-
this.uploadData.title = ''
512-
this.uploadData.introduction = ''
513-
this.articlesAdd[this.isActiveAddNews].thumbMediaId = response.data.mediaId
514-
this.articlesAdd[this.isActiveAddNews].thumbUrl = response.data.url
515-
}else{
521+
handleUploadSuccess(response, file, fileList) {
522+
this.addMaterialLoading = false // 关闭 loading
523+
if (response.code !== 0) {
516524
this.$message.error('上传出错:' + response.msg)
525+
return false;
517526
}
527+
528+
// 重置上传文件的表单
529+
this.fileList = []
530+
this.uploadData.title = ''
531+
this.uploadData.introduction = ''
532+
533+
// 设置草稿的封面字段
534+
this.articlesAdd[this.isActiveAddNews].thumbMediaId = response.data.mediaId
535+
this.articlesAdd[this.isActiveAddNews].thumbUrl = response.data.url
518536
},
519537
selectMaterial(item){
520538
this.dialogImageVisible = false

0 commit comments

Comments
 (0)