Commit 4080d2de9b93bf1050892936fca3103819512e64

Authored by YunaiV
1 parent bc870434

mp:初步实现【草稿】的前端新增

yudao-ui-admin/src/api/mp/draft.js
@@ -8,3 +8,14 @@ export function getDraftPage(query) { @@ -8,3 +8,14 @@ export function getDraftPage(query) {
8 params: query 8 params: query
9 }) 9 })
10 } 10 }
  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 +}
yudao-ui-admin/src/views/mp/draft/index.vue
@@ -60,14 +60,14 @@ SOFTWARE. @@ -60,14 +60,14 @@ SOFTWARE.
60 </div> 60 </div>
61 </div> 61 </div>
62 <!-- 分页记录 --> 62 <!-- 分页记录 -->
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">
64 <span class="el-table__empty-text">暂无数据</span> 64 <span class="el-table__empty-text">暂无数据</span>
65 </div> 65 </div>
66 <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" 66 <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
67 @pagination="getList"/> 67 @pagination="getList"/>
68 68
69 <!-- TODO 芋艿:位置调整 --> 69 <!-- TODO 芋艿:位置调整 -->
70 - <el-dialog :title="operateMaterial === 'add'?'新建图文':'修改图文'" 70 + <el-dialog :title="operateMaterial === 'add' ? '新建图文' : '修改图文'"
71 append-to-body 71 append-to-body
72 :before-close="dialogNewsClose" 72 :before-close="dialogNewsClose"
73 :close-on-click-modal="false" 73 :close-on-click-modal="false"
@@ -103,13 +103,13 @@ SOFTWARE. @@ -103,13 +103,13 @@ SOFTWARE.
103 @click="downNews(index)">下移 103 @click="downNews(index)">下移
104 </el-button> 104 </el-button>
105 <el-button type="mini" icon="el-icon-sort-up" @click="upNews(index)">上移</el-button> 105 <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"
107 @click="minusNews(index)">删除 107 @click="minusNews(index)">删除
108 </el-button> 108 </el-button>
109 </div> 109 </div>
110 </div> 110 </div>
111 </div> 111 </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'">
113 <i class="el-icon-circle-plus icon-plus"></i> 113 <i class="el-icon-circle-plus icon-plus"></i>
114 </div> 114 </div>
115 </div> 115 </div>
@@ -121,40 +121,30 @@ SOFTWARE. @@ -121,40 +121,30 @@ SOFTWARE.
121 v-if="hackResetEditor"/> 121 v-if="hackResetEditor"/>
122 </el-row> 122 </el-row>
123 <br><br><br><br> 123 <br><br><br><br>
  124 + <!-- 封面和摘要 -->
124 <div class="input-tt">封面和摘要:</div> 125 <div class="input-tt">封面和摘要:</div>
125 <div> 126 <div>
126 <div class="thumb-div"> 127 <div class="thumb-div">
127 <img class="material-img" v-if="articlesAdd[isActiveAddNews].thumbUrl" 128 <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'">
129 <i v-else class="el-icon-plus avatar-uploader-icon" 130 <i v-else class="el-icon-plus avatar-uploader-icon"
130 :class="isActiveAddNews === 0 ? 'avatar':'avatar1'"></i> 131 :class="isActiveAddNews === 0 ? 'avatar':'avatar1'"></i>
131 <div class="thumb-but"> 132 <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>
148 </el-upload> 138 </el-upload>
149 </div> 139 </div>
150 </div> 140 </div>
151 <el-dialog title="选择图片" :visible.sync="dialogImageVisible" width="80%" append-to-body> 141 <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" />
154 </el-dialog> 143 </el-dialog>
155 <el-input :rows="8" type="textarea" v-model="articlesAdd[isActiveAddNews].digest" placeholder="请输入摘要" 144 <el-input :rows="8" type="textarea" v-model="articlesAdd[isActiveAddNews].digest" placeholder="请输入摘要"
156 class="digest" maxlength="120"></el-input> 145 class="digest" maxlength="120"></el-input>
157 </div> 146 </div>
  147 + <!-- 标题、作者、原文地址 -->
158 <div class="input-tt">标题:</div> 148 <div class="input-tt">标题:</div>
159 <el-input v-model="articlesAdd[isActiveAddNews].title" placeholder="请输入标题"></el-input> 149 <el-input v-model="articlesAdd[isActiveAddNews].title" placeholder="请输入标题"></el-input>
160 <div class="input-tt">作者:</div> 150 <div class="input-tt">作者:</div>
@@ -171,13 +161,12 @@ SOFTWARE. @@ -171,13 +161,12 @@ SOFTWARE.
171 </template> 161 </template>
172 162
173 <script> 163 <script>
174 -// import {getPage, addObj, delObj, putObj, publish} from '@/api/wxmp/wxdraft'  
175 // import { getPage as getPage1 } from '@/api/wxmp/wxmaterial' 164 // import { getPage as getPage1 } from '@/api/wxmp/wxmaterial'
176 // import WxEditor from '@/components/Editor/WxEditor.vue' 165 // import WxEditor from '@/components/Editor/WxEditor.vue'
177 import WxNews from '@/views/mp/components/wx-news/main.vue'; 166 import WxNews from '@/views/mp/components/wx-news/main.vue';
178 import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue' 167 import WxMaterialSelect from '@/views/mp/components/wx-material-select/main.vue'
179 import { getAccessToken } from '@/utils/auth' 168 import { getAccessToken } from '@/utils/auth'
180 -import { getDraftPage } from "@/api/mp/draft"; 169 +import {createDraft, getDraftPage} from "@/api/mp/draft";
181 import {getSimpleAccounts} from "@/api/mp/account"; 170 import {getSimpleAccounts} from "@/api/mp/account";
182 171
183 export default { 172 export default {
@@ -208,31 +197,33 @@ export default { @@ -208,31 +197,33 @@ export default {
208 currentPage: 1, // 当前页数 197 currentPage: 1, // 当前页数
209 pageSize: 10 // 每页显示多少条 198 pageSize: 10 // 每页显示多少条
210 }, 199 },
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", // 上传永久素材的地址
212 headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部 203 headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部
213 fileList: [], 204 fileList: [],
214 - dialogVideoVisible: false,  
215 - dialogNewsVisible: false,  
216 - addMaterialLoading: false,  
217 uploadData: { 205 uploadData: {
218 - "mediaType": 'image', 206 + "type": 'image', // TODO 芋艿:试试要不要换成 thumb
219 "title": '', 207 "title": '',
220 - "introduction": '' 208 + "introduction": '',
  209 + "accountId": 1,
221 }, 210 },
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 + }],
236 isActiveAddNews: 0, 227 isActiveAddNews: 0,
237 dialogImageVisible: false, 228 dialogImageVisible: false,
238 imageListData: [], 229 imageListData: [],
@@ -251,12 +242,18 @@ export default { @@ -251,12 +242,18 @@ export default {
251 // 默认选中第一个 242 // 默认选中第一个
252 if (this.accounts.length > 0) { 243 if (this.accounts.length > 0) {
253 this.queryParams.accountId = this.accounts[0].id; 244 this.queryParams.accountId = this.accounts[0].id;
  245 + this.setAccountId(this.accounts[0].id);
254 } 246 }
255 // 加载数据 247 // 加载数据
256 - this.getList(); 248 + // this.getList();
257 }) 249 })
258 }, 250 },
259 methods: { 251 methods: {
  252 + /** 设置账号编号 */
  253 + setAccountId(accountId) {
  254 + this.queryParams.accountId = accountId;
  255 + this.uploadData.accountId = accountId;
  256 + },
260 /** 查询列表 */ 257 /** 查询列表 */
261 getList() { 258 getList() {
262 // 如果没有选中公众号账号,则进行提示。 259 // 如果没有选中公众号账号,则进行提示。
@@ -280,6 +277,20 @@ export default { @@ -280,6 +277,20 @@ export default {
280 this.loading = false 277 this.loading = false
281 }) 278 })
282 }, 279 },
  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 + },
283 294
284 delMaterial(item){ 295 delMaterial(item){
285 this.$confirm('此操作将永久删除该草稿, 是否继续?', '提示', { 296 this.$confirm('此操作将永久删除该草稿, 是否继续?', '提示', {
@@ -386,12 +397,10 @@ export default { @@ -386,12 +397,10 @@ export default {
386 ) 397 )
387 this.isActiveAddNews = this.articlesAdd.length - 1 398 this.isActiveAddNews = this.articlesAdd.length - 1
388 }, 399 },
389 - subNews(){ 400 + subNews() {
390 this.addMaterialLoading = true 401 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 => {
395 this.addMaterialLoading = false 404 this.addMaterialLoading = false
396 this.dialogNewsVisible = false 405 this.dialogNewsVisible = false
397 if(response.code == 200){ 406 if(response.code == 200){
@@ -410,12 +419,11 @@ export default { @@ -410,12 +419,11 @@ export default {
410 "thumbUrl":'' 419 "thumbUrl":''
411 } 420 }
412 ] 421 ]
413 - this.queryParams.currentPage = 1  
414 - this.getList(this.queryParams)  
415 - }else{ 422 + this.getList()
  423 + } else {
416 this.$message.error('新增图文出错:' + response.msg) 424 this.$message.error('新增图文出错:' + response.msg)
417 } 425 }
418 - }).catch(() => { 426 + }).finally(() => {
419 this.addMaterialLoading = false 427 this.addMaterialLoading = false
420 }) 428 })
421 } 429 }
@@ -452,11 +460,11 @@ export default { @@ -452,11 +460,11 @@ export default {
452 } 460 }
453 }, 461 },
454 handleEditNews(item){ 462 handleEditNews(item){
455 - this.hackResetEditor = false//销毁组件 463 + this.hackResetEditor = false // 销毁组件
456 this.$nextTick(() => { 464 this.$nextTick(() => {
457 - this.hackResetEditor = true//重建组件 465 + this.hackResetEditor = true // 重建组件
458 }) 466 })
459 - if(this.operateMaterial == 'add'){ 467 + if (this.operateMaterial == 'add') {
460 this.isActiveAddNews = 0 468 this.isActiveAddNews = 0
461 } 469 }
462 this.operateMaterial = 'edit' 470 this.operateMaterial = 'edit'
@@ -465,9 +473,9 @@ export default { @@ -465,9 +473,9 @@ export default {
465 this.dialogNewsVisible = true 473 this.dialogNewsVisible = true
466 }, 474 },
467 handleAddNews(){ 475 handleAddNews(){
468 - this.hackResetEditor = false//销毁组件 476 + this.hackResetEditor = false // 销毁组件
469 this.$nextTick(() => { 477 this.$nextTick(() => {
470 - this.hackResetEditor = true//重建组件 478 + this.hackResetEditor = true // 重建组件
471 }) 479 })
472 if(this.operateMaterial == 'edit'){ 480 if(this.operateMaterial == 'edit'){
473 this.isActiveAddNews = 0 481 this.isActiveAddNews = 0
@@ -491,30 +499,40 @@ export default { @@ -491,30 +499,40 @@ export default {
491 }, 499 },
492 beforeThumbImageUpload(file){ 500 beforeThumbImageUpload(file){
493 this.addMaterialLoading = true 501 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';
496 if (!isType) { 507 if (!isType) {
497 this.$message.error('上传图片格式不对!') 508 this.$message.error('上传图片格式不对!')
  509 + this.addMaterialLoading = false
  510 + return false;
498 } 511 }
  512 + const isLt = file.size / 1024 / 1024 < 2
499 if (!isLt) { 513 if (!isLt) {
500 - this.$message.error('上传图片大小不能超过2M!') 514 + this.$message.error('上传图片大小不能超过 2M!')
  515 + this.addMaterialLoading = false
  516 + return false;
501 } 517 }
502 - this.addMaterialLoading = false  
503 - return isType && isLt; 518 + // 校验通过
  519 + return true;
504 }, 520 },
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) {
516 this.$message.error('上传出错:' + response.msg) 524 this.$message.error('上传出错:' + response.msg)
  525 + return false;
517 } 526 }
  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
518 }, 536 },
519 selectMaterial(item){ 537 selectMaterial(item){
520 this.dialogImageVisible = false 538 this.dialogImageVisible = false