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