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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
| <template> <div class="write" v-show="show_page"> <div class="_2v5v5"> <div class="_3zibT"> <router-link to="/">回首页</router-link> </div> <div class="_1iZMb" @click.stop=""> <div class="_33Zlg" @click="collection_form=!collection_form"><i class="fa fa-plus"></i><span>新建文集</span></div> <div class="_2G97m"> <form class="M8J6Q" :class="collection_form?'_2a1Rp':'_1mU5v'"> <input type="text" placeholder="请输入文集名..." v-model="collection_name" class="_1CtV4"> <button type="submit" class="dwU8Q _3zXcJ _3QfkW" @click.prevent="create_collection"> <span>提 交</span> </button> <button type="button" class="vIzwB _3zXcJ" @click="collection_form=false"><span>取 消</span></button> </form> </div> </div> <ul class="_3MbJ4 _3t059"> <li class="_3DM7w" :class="{'_31PCv': (key === collection_key)}" :title="collection.name" v-for="(collection,key) in collections" :key="key" @click="select_collection(key)"> <div class="_3P4JX _2VLy-" v-if="key === collection_key" @click.stop="collection_option"> <i class="fa fa-gear"></i> <span> <ul class="_2V8zt _3FcHm _2w9pn" :class="{'NvfK4': show_collection_option}"> <li class="_2po2r cRfUr" @click="edit_collection"> <span class=""><i class="fa fa-pencil-square-o _22XWG"></i>修改文集</span> </li> <li class="_2po2r cRfUr" @click="del_collection"> <span class=""><i class="fa fa-trash-o _22XWG"></i>删除文集</span> </li> </ul> </span> </div> <span>{{ collection.name }}</span> </li> </ul> <div style="height: 50px;"></div> <div role="button" class="h-5Am"> <span class="ant-dropdown-trigger"><i class="fa fa-bars"></i><span>设置</span></span> <span class="Yv5Zx">遇到问题<i class="fa fa-question-circle-o"></i></span> </div> </div> <div class="rQQG7"> <div class="_3revO _2mnPN"> <div class="_3br9T"> <div> <div class="_1GsW5" @click="create_article(false)"><i class="fa fa-plus-circle"></i><span> 新建文章</span></div> <ul class="_2TxA-"> <li class="_25Ilv" :class="{_33nt7: key === article_key}" :title="article.name" v-for="article,key in article_list" :key="key" @click="article_key = key"> <i class="_13kgp" :class="{_2m93u: article.is_public}"></i> <div class="_3P4JX poOXI" v-if="key === article_key" @click.stop="article_menu"> <i class="fa fa-gear"></i> <span> <ul class="_2V8zt _3FcHm _2w9pn" :class="{NvfK4: show_article_menu}"> <li class="_2po2r cRfUr" title="" @click="publish_article(true)" v-if="!article.is_public"> <span class=""><i class="fa fa-share _22XWG"></i>直接发布</span></li> <li class="_2po2r cRfUr" title="" @click="publish_article(false)" v-else><span class=""><i class="fa fa-lock _22XWG"></i>设为私密</span></li> <li class="_2po2r cRfUr" title="" v-if="!article.is_public" @click="time_dialog_visible = true"> <span class=""><i class="fa fa-clock-o _22XWG"></i>定时发布</span> </li> <li class="_2po2r cRfUr" title=""><span class="_20tIi"><i class="iconfont ic-paid _22XWG"></i>发布为付费文章</span></li> <li class="_2po2r cRfUr" title=""><span class=""><i class="iconfont ic-set _22XWG"></i>设置发布样式</span></li> <li class="_3nZXj _2_WAp _3df2u _2po2r cRfUr" title=""><span class=""><i class="fa fa-folder-open _22XWG"></i>移动文章 <div class="_3x4X_"> <ul class="_2KzJx oGKRI _3DXDE _2w9pn"> <li class="_2po2r cRfUr" :title="collection.name" v-for="collection,key in collections" :key="key" v-if="key !== collection_key" @click="move_article(key)"> <span class="">{{ collection.name }}</span> </li> </ul> </div> </span> </li> <li class="_2po2r cRfUr" title=""><span class=""><i class="fa fa-history _22XWG"></i>历史版本</span></li> <li class="_2po2r cRfUr" title="" @click="del_article"><span class=""><i class="fa fa-trash-o _22XWG"></i>删除文章</span></li> <li class="_2po2r cRfUr" title=""><span class=""><i class="fa fa-ban _22XWG"></i>设置禁止转载</span></li> </ul> </span> </div> <span class="NariC">{{ article.name }}</span> <span class="hLzJv">{{ article.content }}</span> <span class="_29C-V">字数: {{ article.content?article.content.length:0 }}</span> </li> </ul> <div class="_2cVn3" @click="create_article(true)"><i class="fa fa-plus"></i><span> 在下方新建文章</span></div> </div> </div> </div> <input type="text" class="_24i7u" value="2020-01-12" v-show="show_editor"> <div id="editor" v-show="show_editor"> <mavon-editor style="height: 100%" v-model="editorContent" :ishljs="true" ref=md @imgAdd="imgAdd" @imgDel="imgDel" ></mavon-editor> <el-dialog title="选择定时发文的时间:" :visible.sync="time_dialog_visible" width="20%"> <el-date-picker v-model="schedule_datetime" type="datetime" placeholder="选择日期时间" align="center" :picker-options="pickerOptions1"> </el-date-picker> <span slot="footer" class="dialog-footer"> <el-button @click="time_dialog_visible = false">取 消</el-button> <el-button type="primary" @click="shedule_publish_article">确 定</el-button> </span> </el-dialog> </div> </div> </div> </template> <script> import {mavonEditor} from 'mavon-editor' import 'mavon-editor/dist/css/index.css'
export default { name: "Write", data() { return { editorContent: "", img_file: [], collection_form: false, show_page: false, token: '', collections: [], collection_key: 0, collection_name: '', show_collection_option: false, article_list: [], article_key: 0, show_article_menu: false, show_editor: true, time_dialog_visible: false, schedule_datetime: '', pickerOptions1: { disabledDate(time) { return time.getTime() < Date.now(); }, shortcuts: [{ text: '今天', onClick(picker) { picker.$emit('pick', new Date()); } }, { text: '明天', onClick(picker) { const date = new Date(); date.setTime(date.getTime() + 3600 * 1000 * 24); picker.$emit('pick', date); } }, { text: '一周后', onClick(picker) { const date = new Date(); date.setTime(date.getTime() + 3600 * 1000 * 24 * 7); picker.$emit('pick', date); } }] }, value1: '', value2: '', } }, watch: { editorContent() { console.log(this.editorContent) } }, mounted() { document.querySelector("#editor").style.height = document.documentElement.clientHeight - document.querySelector("._24i7u").clientHeight + "px"; document.onclick = () => { this.collection_form = false; this.show_collection_option = false; this.show_article_menu = false; }; }, created() { this.token = this.$settings.check_login(this); this.show_page = !!this.token; this.show_page && this.get_collections(); }, components: { mavonEditor }, methods: { get_collections() { this.$axios.get(`${this.$settings.Host}/article/collections/`, { headers: { Authorization: `jwt ${this.token}` } }).then(response => { this.collections = response.data; // 因为 axios 发送的是异步请求,所以需要把 get_article 方法写到这里 // 这样才能确保在获取到 collection 之后去获取文章内容 this.get_atricle(); }).catch(errors => { this.$settings.clear_user_info(); this.show_page = false; this.$settings.check_login(); }) }, create_collection() { if (!this.collection_name) { this.$message.error('文集名不能为空!'); return } this.$axios.post(`${this.$settings.Host}/article/collections/`, {name: this.collection_name}, { headers: { Authorization: `jwt ${this.token}` } }).then(response => { this.collections.unshift(response.data); this.collection_form = false; this.$message.success('创建成功!') }).catch(errors => { this.$message.error('对不起,创建失败,请稍后重试!') }) }, edit_collection() { this.$prompt('请输入新文集名', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', inputValue: this.collections[this.collection_key].name, inputPattern: /.+/, inputErrorMessage: '内容不能为空!' }).then(({value}) => { let collection_id = this.collections[this.collection_key].id; this.$axios.put(`${this.$settings.Host}/article/collections/${collection_id}/`, { name: value, }, { headers: { Authorization: `jwt ${this.token}`, } }).then(response => { this.collections[this.collection_key].name = response.data.name; this.$message({ type: 'success', message: '文集名已改为:' + value }); }).catch(errors => { this.$message.error('修改失败,请稍后重试!') }); }).catch(() => { this.$message({ type: 'info', message: '取消输入' }); }); }, del_collection() { let collection_id = this.collections[this.collection_key].id; this.$confirm(`此操作将永久删除文集 ${this.collections[this.collection_key].name},是否继续?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.$axios.delete(`${this.$settings.Host}/article/collections/${collection_id}/`, { headers: { Authorization: `jwt ${this.token}`, } }).then(response => { this.collections.splice(this.collection_key, 1); this.$message.info('删除成功!'); }).catch(errors => { this.$message.error('删除失败,请稍后重试!'); }) }).catch(() => { this.$message({ type: 'info', message: '已取消删除' }); }); }, select_collection(key) { this.collection_key = key; this.get_atricle(); }, collection_option() { this.show_collection_option = !this.show_collection_option; this.show_article_menu = false; }, article_menu() { this.show_article_menu = !this.show_article_menu; this.show_collection_option = false; }, get_atricle() { this.$axios.get(`${this.$settings.Host}/article/article/`, { params: { 'collection_id': this.collections[this.collection_key].id, }, headers: { Authorization: `jwt ${this.token}` } }).then(response => { this.article_list = response.data; this.article_key = 0; this.show_editor = !!response.data.length; }).catch(errors => { this.$message.error('获取文章信息失败,请稍后再试!') }) }, create_article(position) { this.$axios.post(`${this.$settings.Host}/article/article/`, { collection: this.collections[this.collection_key].id, position: position, }, { headers: { Authorization: `jwt ${this.token}` } }).then(response => { if (position) { this.article_list.push(response.data) } else { this.article_list.unshift(response.data) } this.show_editor = !!this.article_list.length; }).catch(errors => { this.$message.error('添加文章失败,请稍后重试!') }) }, del_article() { let article_id = this.article_list[this.article_key].id; this.$confirm(`此操作将永久删除文章 ${this.article_list[this.article_key].name},是否继续?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.$axios.delete(`${this.$settings.Host}/article/article/${article_id}/`, { params: { collection_id: this.collections[this.collection_key].id }, headers: { Authorization: `jwt ${this.token}`, } }).then(response => { this.article_list.splice(this.article_key, 1); this.show_editor = !!this.article_list.length; this.$message.info('删除成功!'); }).catch(errors => { this.$message.error('删除失败,请稍后重试!'); }) }).catch(() => { this.$message({ type: 'info', message: '已取消删除' }); }); }, publish_article(is_public) { this.$axios.put(`${this.$settings.Host}/article/article/publish/`, { 'article_id': this.article_list[this.article_key].id, 'is_public': is_public, }, { headers: { Authorization: `jwt ${this.token}` } }).then(response => { this.article_list[this.article_key].is_public = is_public; if (is_public) { this.$message.success('发布成功!'); } else { this.$message.success('成功设为私密!') } }).catch(errors => { this.$message.error('发布失败,请稍后再试!') }) }, move_article(key) { this.$axios.put(`${this.$settings.Host}/article/article/move/`, { 'collection_id': this.collections[key].id, 'article_id': this.article_list[this.article_key].id, }, { headers: { Authorization: `jwt ${this.token}` } }).then(response => { this.article_list.splice(this.article_key, 1); this.article_key = 0; this.$message.success('文章移动成功!'); this.show_editor = !!this.article_list.length; }).catch(errors => { this.$message.error('文章移动失败,请稍后重试!') }) }, shedule_publish_article() { this.$axios.put(`${this.$settings.Host}/article/schedule/publish/`, { pub_date: this.schedule_datetime, article_id: this.article_list[this.article_key].id, }, { headers: { Authorization: `jwt ${this.token}` } }).then(response=>{ this.$message.success('定时发布成功!'); }).catch(errors=>{ this.$message.error('定时发送失败,请稍后重试!') }); this.schedule_datetime = ''; this.time_dialog_visible = false }, // 绑定@imgAdd event imgAdd(pos, $file) { // 添加文件 }, imgDel(pos) { // 删除文件 } }, } </script>
|