1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<template>
<div class="createPost-container">
<el-form ref="postForm" :model="postForm" :rules="rules" class="form-container">
<sticky :class-name="'sub-navbar '+postForm.status">
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="effectPush" v-if="isEdit && !is_effect">生效</el-button>
<el-button v-loading="loading" style="margin-left: 10px;" type="success" @click="submitForm" v-if="!is_effect">保存</el-button>
</sticky>
<div class="createPost-main-container">
<el-row>
<Warning v-if="isEdit"/>
<el-col :span="24">
<el-form-item style="margin-bottom: 40px;" prop="title">
<MDinput v-model="postForm.title" :maxlength="100" name="title" required >
推送标题
</MDinput>
</el-form-item>
<div class="postInfo-container">
<el-row>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送ID:" v-if="isEdit">
<el-input :rows="1" v-model="postForm.id" type="text" class="article-textarea"
style="width: 180px" disabled />
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="创建时间:" prop="create_time" v-if="isEdit">
<el-input :rows="1" v-model="postForm.create_time" type="text" class="article-textarea"
style="width: 199px" disabled v-if="isEdit"/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="创建用户:" v-if="isEdit">
<el-input :rows="1" v-model="postForm.creator_name" type="text" class="article-textarea"
style="width: 180px" disabled/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送落地:" prop="url" >
<el-select v-model="postForm.url" :placeholder="'协议:'" clearable
class="postInfo-container-item" style="width:230px">
<el-option v-for="item in URLOptions" :key="item.key" :label="item.display_name"
:value="item.key"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item label-width="80px" label="推送时间:" class="postInfo-container-item" prop="push_time" >
<el-date-picker
v-model="postForm.push_time"
type="datetime"
format="yyyy-MM-dd HH:mm:ss"
placeholder="选择日期时间"
style="width: 199px"
:picker-options="expireTimeOption"
/>
</el-form-item>
</el-col>
<el-col :span="8">
</el-col>
</el-row>
</div>
</el-col>
</el-row>
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送内容:" prop="content">
<el-input :rows="1" v-model="postForm.content" type="textarea" class="article-textarea" autosize placeholder="请输入内容" />
<span v-show="contentShortLength" class="word-counter">{{ contentShortLength }}字</span>
</el-form-item>
<div style="margin-bottom: 20px;">
<el-form-item style="margin-bottom: 40px;" label-width="75px" label="推送头像:" prop="icon" :disabled="is_effect">
<span v-model="uploadType"></span>
<Upload v-model="postForm.icon" :uploadType="uploadType" />
</el-form-item>
</div>
</div>
</el-form>
</div>
</template>
<script>
import Upload from '@/components/Upload/singleImage3'
import MDinput from '@/components/MDinput'
import Sticky from '@/components/Sticky' // 粘性header组件
import Warning from './Warning'
import { validateURL } from '@/utils/validate'
import { fetchPushDetail, CreatePush, EffectPushTask } from '@/api/push'
const defaultForm = {
status: 'draft',
title: '',
content: '',
icon: '',
push_time: '',
url: '',
creator_name: '',
}
export default {
name: 'PushDetail',
components: { MDinput, Upload, Sticky, Warning},
props: {
isEdit: {
type: Boolean,
default: false
}
},
data() {
const validateRequire = (rule, value, callback) => {
if (value === '') {
this.$message({
message: rule.field + '为必传项',
type: 'error'
})
callback(new Error(rule.field + '为必传项'))
} else {
callback()
}
}
return {
postForm: Object.assign({}, defaultForm),
loading: false,
userListOptions: [],
URLOptions: [
{'key': '1', 'display_name': '推送帖子'},
{'key': '2', 'display_name': '推送小组'},
],
expireTimeOption: {
disabledDate(date){
return date.getTime() <= Date.now() - 86400000;
}
},
rules: {
title: [{ validator: validateRequire, trigger: 'blur'}],
content: [{ validator: validateRequire, trigger: 'blur'}],
url: [{ validator: validateRequire, trigger: 'blur'}],
icon: [{ validator: validateRequire, trigger: 'blur'}],
push_time: [{ validator: validateRequire, trigger: 'blur'}],
},
tempRoute: {},
uploadType: 1, // 图片类型
is_effect: false,
}
},
computed: {
contentShortLength() {
return this.postForm.content.length
},
},
created() {
if (this.isEdit) {
const id = this.$route.params && this.$route.params.id
this.fetchData(id)
} else {
this.postForm = Object.assign({}, defaultForm)
}
this.tempRoute = Object.assign({}, this.$route)
},
methods: {
fetchData(id) {
fetchPushDetail(id).then(response => {
this.postForm = response.data.data.data
this.is_effect = Boolean(response.data.data.data.is_effect)
}).catch(err => {
console.log(err)
})
},
submitForm() {
this.$refs.postForm.validate(valid => {
if (valid) {
this.loading = true
this.postForm.creator_id = this.$store.getters.id // 创建用户ID
CreatePush(this.postForm).then(response => {
this.$notify({
title: '成功',
message: response.data.data.message,
type: 'success',
duration: 2000
})
setTimeout(() => {
this.$router.push('/push/list')
}, 1000)
}).catch(err => {
this.$notify({
title: '失败',
message: '操作失败',
type: 'danger',
duration: 2000
})
});
this.postForm.status = 'published'
this.loading = false
} else {
console.log('error submit!!')
return false
}
})
},
effectPush() {
if (this.postForm.push_time < Date.now()){
this.$message.error("推送时间已过期, 请重新设置!!");
return false
}
this.is_effect = Boolean(1);
const id = this.$route.params && this.$route.params.id
EffectPushTask(id).then(response => {
console.log(response.data.data.message)
this.$message({
message: response.data.data.message,
type: 'success'
})
this.$router.go(0)
}).catch(err => {
})
}
}
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.createPost-container {
position: relative;
.createPost-main-container {
padding: 40px 45px 20px 50px;
.postInfo-container {
position: relative;
@include clearfix;
margin-bottom: 10px;
.postInfo-container-item {
float: left;
}
}
.editor-container {
min-height: 500px;
margin: 0 0 30px;
.editor-upload-btn-container {
text-align: right;
margin-right: 10px;
.editor-upload-btn {
display: inline-block;
}
}
}
}
.word-counter {
width: 40px;
position: absolute;
right: -10px;
top: 0px;
}
}
</style>