|
@@ -1,10 +1,10 @@
|
1
|
1
|
<template>
|
2
|
2
|
<div id="root">
|
3
|
3
|
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" label-width="150px" class="ruleForm">
|
4
|
|
- <el-form-item label="活动标题" prop="activityTitle">
|
5
|
|
- <el-input v-model="ruleForm.activityTitle" placeholder="15字以内"/>
|
|
4
|
+ <el-form-item label="活动标题" prop="announcementTitle">
|
|
5
|
+ <el-input v-model="ruleForm.announcementTitle" placeholder="15字以内"/>
|
6
|
6
|
</el-form-item>
|
7
|
|
- <el-form-item label="活动轮播图" prop="activityCarouselImg">
|
|
7
|
+ <el-form-item label="活动轮播图" prop="announcementCarouselImg">
|
8
|
8
|
<el-upload
|
9
|
9
|
:show-file-list="false"
|
10
|
10
|
:on-success="handleAvatarSuccess"
|
|
@@ -30,7 +30,7 @@
|
30
|
30
|
<i class="el-icon-plus"/>
|
31
|
31
|
</el-upload>
|
32
|
32
|
<el-dialog :visible.sync="dialogVisible">
|
33
|
|
- <img :src="announcementContentImg" width="100%" alt="">
|
|
33
|
+ <img :src="dialogImageUrl" width="100%" alt="">
|
34
|
34
|
</el-dialog>
|
35
|
35
|
</el-form-item>
|
36
|
36
|
<el-form-item label="权重值" prop="sort">
|
|
@@ -52,14 +52,16 @@ export default {
|
52
|
52
|
ruleForm: {
|
53
|
53
|
announcementTitle: '',
|
54
|
54
|
announcementCarouselImg: '', // 轮播图
|
55
|
|
- announcementContent: '', // 公告内容详细
|
56
|
|
- announcementContentImg: [], // 公告内容配图
|
|
55
|
+ announcementContent: '', // 内容详细
|
|
56
|
+ contentImg: [], // 内容配图
|
57
|
57
|
sort: 1, // 权重
|
58
|
58
|
status: '' // 状态 0 是已作废 1 是已发布 2 是草稿 3 是已修改
|
59
|
59
|
},
|
60
|
60
|
imageUrl: '', // 轮播图预览
|
|
61
|
+ dialogVisible: false, // 活动配图, 默认不显示 (以单张为单位)
|
|
62
|
+ dialogImageUrl: '', // 活动配图, 图片链接 (以单张为单位)
|
61
|
63
|
rules: {
|
62
|
|
- activityTitle: [
|
|
64
|
+ announcementTitle: [
|
63
|
65
|
{ required: true, message: '请输入活动名称', trigger: 'blur' },
|
64
|
66
|
{ min: 1, max: 15, message: '长度在 15 个字符以内', trigger: 'blur' }
|
65
|
67
|
],
|
|
@@ -83,18 +85,18 @@ export default {
|
83
|
85
|
})
|
84
|
86
|
this.$refs[formName].validate((valid) => {
|
85
|
87
|
if (valid) {
|
86
|
|
- if (this.ruleForm.announcementContent.length <= 0 && this.ruleForm.announcementContentImg.length <= 0) {
|
|
88
|
+ if (this.ruleForm.announcementContent.length <= 0 && this.ruleForm.contentImg.length <= 0) {
|
87
|
89
|
this.$message.error('活动内容描述 和 活动配图至少要存在一个!')
|
88
|
90
|
return false
|
89
|
91
|
}
|
90
|
92
|
this.ruleForm.status = 1 // 发布状态
|
91
|
|
- this.$store.dispatch('AddActivity', this.ruleForm).then((res) => {
|
|
93
|
+ this.$store.dispatch('AddAnnouncement', this.ruleForm).then((res) => {
|
92
|
94
|
if (res.code === '0') {
|
93
|
95
|
this.$message({
|
94
|
96
|
message: res.message,
|
95
|
97
|
type: 'success'
|
96
|
98
|
})
|
97
|
|
- this.$router.push({ name: 'activity-index' })
|
|
99
|
+ this.$router.push({ name: 'announcement-index' })
|
98
|
100
|
loading.close()
|
99
|
101
|
return
|
100
|
102
|
}
|
|
@@ -114,7 +116,7 @@ export default {
|
114
|
116
|
this.$refs[formName].resetFields()
|
115
|
117
|
},
|
116
|
118
|
handleAvatarSuccess(res, file) { // 轮播图上传回调
|
117
|
|
- this.ruleForm.activityCarouselImg = res.data[0]
|
|
119
|
+ this.ruleForm.announcementCarouselImg = res.data[0]
|
118
|
120
|
this.imageUrl = URL.createObjectURL(file.raw)
|
119
|
121
|
},
|
120
|
122
|
beforeAvatarUpload(file) { // 轮播图上传前操作
|
|
@@ -129,20 +131,20 @@ export default {
|
129
|
131
|
// }
|
130
|
132
|
// return isJPG && isLt2M
|
131
|
133
|
},
|
132
|
|
- handleRemove(file, fileList) { // 配图移除时
|
133
|
|
- this.ruleForm.announcementContentImg = []
|
|
134
|
+ handleRemove(file, fileList) { // 活动配图移除时
|
|
135
|
+ this.ruleForm.contentImg = []
|
134
|
136
|
for (let i = 0; i < fileList.length; i++) {
|
135
|
|
- this.ruleForm.announcementContentImg.push(fileList[i].response.data[0])
|
|
137
|
+ this.ruleForm.contentImg.push(fileList[i].response.data[0])
|
136
|
138
|
}
|
137
|
139
|
console.log(file, fileList)
|
138
|
140
|
},
|
139
|
|
- handlePictureCardPreview(file) { // 配图文件列表中已上传的文件时的钩子
|
140
|
|
- this.announcementContentImg = file.url
|
|
141
|
+ handlePictureCardPreview(file) { // 点击活动配图文件列表中已上传的文件时的钩子
|
|
142
|
+ this.dialogImageUrl = file.url
|
141
|
143
|
this.dialogVisible = true
|
142
|
144
|
},
|
143
|
145
|
handleSuccessContentImg(response, file, fileList) { // 活动配图上传成功时回调
|
144
|
146
|
const resImg = response.data[0]
|
145
|
|
- this.ruleForm.announcementContentImg.push(resImg)
|
|
147
|
+ this.ruleForm.contentImg.push(resImg)
|
146
|
148
|
console.log('上传活动配图成功时回调!')
|
147
|
149
|
},
|
148
|
150
|
sortHandleChange(value) { // 权重值
|