inleft
2022-02-25 fc0c102554f509989dd74b199f298a67f266c3c8
commit | author | age
f5539f 1 <template>
1ad93b 2     <div>
I 3         <a-form-model ref="myForm" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="rules">
6bcd13 4             <a-form-model-item label="认证" prop="secret">
I 5                 <a-input v-model="form.secret" autocomplete='new-password' type="password" placeholder="口令">
6                     <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
7                 </a-input>
8             </a-form-model-item>
9
1ad93b 10             <a-form-model-item label="标题" prop="title">
f5539f 11                 <a-input v-model="form.title" placeholder="限 50字内" />
L 12             </a-form-model-item>
13
06ee76 14             <a-form-model-item label="模式切换" prop="common">
f5539f 15                 <a-switch v-model="form.online" />
4b854c 16                 <span class="myTip" v-if="form.online">
I 17                     由系统生成文件
18                 </span>
19                 <span class="myTip" v-else>
20                     本地文件上传
f5539f 21                 </span>
L 22             </a-form-model-item>
23
24
6bcd13 25             <a-form-model-item label="日志文件" v-show="!form.online">
I 26                 <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
f5539f 27                     :default-file-list="form.blogFileList">
L 28                     <a-button>
1ad93b 29                         <a-icon type="upload" /> 限 markdown/html
6bcd13 30                     </a-button>
I 31                 </a-upload> -->
32
33                 <a-upload :customRequest="customRequest" name="file" :showUploadList="true" @change="handleChange"
63f511 34                     :default-file-list="form.blogFileList" :beforeUpload="beforeUpload">
6bcd13 35
I 36                     <a-button>
37                         <a-icon type="upload" />限 markdown/html
f5539f 38                     </a-button>
L 39                 </a-upload>
40             </a-form-model-item>
41
63f511 42             <a-form-model-item label="日志内容" v-show="form.online">
f5539f 43                 <a-input v-model="form.content" type="textarea" placeholder="限10k字数" />
L 44             </a-form-model-item>
45
1ad93b 46             <a-form-model-item label="分类" prop="class">
6bcd13 47                 <a-select v-model="form.class" :allowClear="true" mode="default" placeholder="日志分类"
f5539f 48                     :getPopupContainer="getCalendarContainer()">
6bcd13 49
I 50                     <a-select-option v-for="(item,index) in this.blogArticleType" :key="index" :value="item.id">
51                         {{ item.typeName }}
f5539f 52                     </a-select-option>
6bcd13 53
f5539f 54                 </a-select>
L 55             </a-form-model-item>
56
1ad93b 57             <a-form-model-item label="额外设置">
f5539f 58                 <a-switch v-model="form.preference" />
L 59             </a-form-model-item>
60
61             <div v-show="form.preference" class="myBorder" style="padding:10px;">
1ad93b 62                 <a-form-model-item label="起个草稿">
f5539f 63                     <a-switch v-model="form.tempSave" />
L 64                     <span v-show="form.tempSave" class="myTip">
1ad93b 65                         临时存储,游客无法浏览
f5539f 66                     </span>
L 67                 </a-form-model-item>
68
4b854c 69                 <a-form-model-item label=" 日志类型">
f5539f 70                     <a-radio-group v-model="form.blogType">
c23efb 71                         <a-radio value="1">
1ad93b 72                             markdown
f5539f 73                         </a-radio>
c23efb 74                         <a-radio value="2">
1ad93b 75                             html
f5539f 76                         </a-radio>
L 77                     </a-radio-group>
78                 </a-form-model-item>
79
80
81                 <a-form-model-item label="标签">
82                     <template v-for="(tag, index) in tags">
83                         <a-tooltip v-if="tag.length > 20" :key="tag" :title="tag">
84                             <a-tag :key="tag" :closable="index !== 0" @close="() => handleClose(tag)">
85                                 {{ `${tag.slice(0, 20)}...` }}
86                             </a-tag>
87                         </a-tooltip>
1ad93b 88                         <a-tag v-else :key="tag" :closable="index >= 0" @close="() => handleClose(tag)">
f5539f 89                             {{ tag }}
L 90                         </a-tag>
91                     </template>
1ad93b 92
f5539f 93                     <a-input v-if="inputVisible" ref="input" type="text" size="small" :style="{ width: '78px' }"
L 94                         :value="inputValue" @change="handleInputChange" @blur="handleInputConfirm"
95                         @keyup.enter="handleInputConfirm" />
1ad93b 96
f5539f 97                     <a-tag v-else style="background: #fff; borderStyle: dashed;" @click="showInput">
L 98                         <a-icon type="plus" /> New Tag
99                     </a-tag>
1ad93b 100
f5539f 101                 </a-form-model-item>
L 102
103
104                 <a-form-model-item label="封面">
6bcd13 105                     <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" list-type="picture"
f5539f 106                         :default-file-list="form.coverFileList" class="upload-list-inline">
L 107                         <a-button>
108                             <a-icon type="upload" /> jpg/png/jpeg..
109                         </a-button>
6bcd13 110                     </a-upload> -->
I 111
112                     <a-upload :customRequest="customRequest" name="file" :showUploadList="true" list-type="picture"
c23efb 113                         @change="handleChangeCoverFile"
6bcd13 114                         :default-file-list="form.coverFileList">
I 115                         <a-button>
116                             <a-icon type="upload" />jpg/png/jpeg..
117                         </a-button>
f5539f 118                     </a-upload>
6bcd13 119                     <!-- <span class="myTip">
15bd39 120                         自动转码,可以传高清图
6bcd13 121                     </span> -->
f5539f 122                 </a-form-model-item>
L 123
124                 <a-form-model-item label="定时">
06ee76 125                     <a-date-picker v-model="form.publishDate" show-time type="datetime" placeholder="发布时间"
f5539f 126                         style="width: 100%;" :disabledDate="disabledDate"
L 127                         :getCalendarContainer="getCalendarContainer()" />
06ee76 128                 </a-form-model-item>
L 129
7b98c8 130                 <div v-bind:class="{'myBorder':form.top}" style="padding: 3px;margin-bottom: 10px;">
6bcd13 131                     <a-form-model-item label="置顶">
I 132                         <a-switch v-model="form.top" />
133                     </a-form-model-item>
f5539f 134
6bcd13 135                     <div v-show="form.top">
I 136                         <a-form-model-item label="权重">
7b98c8 137                             <a-slider v-model="form.sliderValue" :default-value="50" :step="5"
6bcd13 138                                 :getTooltipPopupContainer="getCalendarContainer()" />
I 139                             <span class="myTip">
140                                 越小越靠前
141                             </span>
142                         </a-form-model-item>
143                     </div>
144                 </div>
f5539f 145
L 146
1ad93b 147                 <div v-bind:class="{'myBorder':form.lock}" style="padding: 3px;">
f5539f 148
L 149                     <a-form-model-item label="加锁">
150                         <a-switch v-model="form.lock" />
151                         <span v-show="!form.lock" class="myTip">
152                             默认为公开
153                         </span>
154                     </a-form-model-item>
155
156                     <div v-show="form.lock ">
157                         <a-form-model-item label="阅读权限">
158                             <a-radio-group v-model="form.auth">
c23efb 159                                 <a-radio value="2">
f5539f 160                                     私人
L 161                                 </a-radio>
c23efb 162                                 <a-radio value="3">
f5539f 163                                     密码授权
L 164                                 </a-radio>
165                             </a-radio-group>
166                         </a-form-model-item>
167
fc0c10 168                         <a-form-model-item label="授权密码" v-show="form.auth==3">
7b98c8 169                             <a-input-password v-model="form.password" autocomplete='new-password' type="password"
6bcd13 170                                 placeholder="独立密码">
f5539f 171                                 <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
7b98c8 172                             </a-input-password>
f5539f 173                         </a-form-model-item>
L 174                     </div>
175
176                 </div>
177
178             </div>
179
180         </a-form-model>
181     </div>
182 </template>
183
184 <script>
185     import moment from "moment";
6bcd13 186     import {
I 187         sysFileInfoUpload
188     } from '../../api/fileManage.js';
63f511 189
6bcd13 190     import {
I 191         queryBlogArticleType
192     } from '../../api/blogArticleType.js'
63f511 193
I 194
f5539f 195     export default {
6bcd13 196         beforeMount() {
I 197             queryBlogArticleType({}).then((res) => {
198                 this.blogArticleType = res.data;
199             })
200         },
f5539f 201         data() {
06ee76 202
L 203             let validateContent = (rule, value, callback) => {
204                 if (this.form.online) {
205                     console.log("内容未填");
206                     this.$refs.myForm.validateField('content')
63f511 207                     if (this.form.content == null || this.form.content == "") {
I 208                         callback(new Error('内容未填'));
209                     }
06ee76 210                 } else {
L 211                     console.log("文件未传");
212                     this.$refs.myForm.validateField('blogFileList')
c23efb 213                     if (this.form.fileId == null) {
63f511 214                         callback(new Error('文件未传'));
I 215                     }
06ee76 216                 }
L 217                 callback();
218             };
219
f5539f 220             return {
6bcd13 221                 blogArticleType: [],
f5539f 222                 tags: [],
L 223                 inputVisible: false,
224                 inputValue: '',
225                 labelCol: {
1ad93b 226                     span: 7
f5539f 227                 },
L 228                 wrapperCol: {
1ad93b 229                     span: 13
f5539f 230                 },
L 231                 form: {
6bcd13 232                     secret: '',
06ee76 233                     online: false,
1ad93b 234                     preference: false,
f5539f 235                     title: '',
L 236                     content: '',
237                     class: [],
238                     tempSave: false,
c23efb 239                     blogType: "1",
f5539f 240                     publishDate: "",
L 241                     lock: false,
6bcd13 242                     top: false,
c23efb 243                     sliderValue:50,
I 244                     auth: 1,
f5539f 245                     password: "",
c23efb 246                     fileId: null,
I 247                     coverFile: null,
f5539f 248                     blogFileList: [],
1ad93b 249                     coverFileList: [],
f5539f 250                 },
1ad93b 251                 rules: {
I 252                     title: [{
253                             required: true,
254                             message: '标题不能为空',
255                             trigger: 'blur'
256                         },
257                         {
63f511 258                             min: 1,
1ad93b 259                             max: 50,
I 260                             message: '字数限制1~50',
261                             trigger: 'blur'
262                         },
263                     ],
6bcd13 264                     secret: [{
I 265                         required: true,
266                         message: '不正经的人..',
267                         trigger: 'blur'
268                     }],
06ee76 269                     common: [{
L 270                         validator: validateContent,
271                         trigger: []
272                     }],
63f511 273                     // content: [{
I 274                     //     max: 10,
275                     //     required: true,
276                     //     message: '至少填一下上传内容',
277                     //     trigger: 'blur'
278                     // }, ],
279                     // blogFileList: [{
280                     //     max: 1,
281                     //     required: true,
282                     //     message: '文件未上传',
283                     // }],
1ad93b 284                     class: [{
I 285                         required: true,
286                         message: '至少选一个分类',
287                         trigger: 'blur'
288                     }, ],
63f511 289
1ad93b 290                 }
f5539f 291             };
L 292         },
293         methods: {
6bcd13 294             beforeUpload(file, fileList) {
I 295                 return new Promise((resolve, reject) => {
c23efb 296                     if (this.form.fileId != null) {
6bcd13 297                         this.$message.error('这里最多上传一个文件');
I 298                         return reject(false);
299                     }
63f511 300                     // var testmsg=/^image\/(jpeg|png|jpg)$/.test(file.type)
I 301                     // // var testmsg=/^image\/(md|html|markdown)$/.test(file.type)
302                     // if (!testmsg) {
303                     //   this.$message.error('上传文件格式不对!');
304                     //   return reject(false);
305                     // }
306
307                     const isLt2M = file.size / 1024 / 1024 <= 2 //图片大小不超过2MB
308                     if (!isLt2M) {
309                         this.$message.error('上传文件大小不能超过 2M!');
310                         return reject(false);
311                     }
312                     return resolve(true)
313                 });
314
6bcd13 315             },
I 316             handleChange(info) {
317                 if (info.file.status !== 'uploading') {
318                     console.log(info.file, info.fileList);
319                 }
320                 if (info.file.status === 'done') {
c23efb 321                     this.form.fileId = info.file.response.data;
I 322                     this.$message.success(`${info.file.name} file uploaded successfully`);
323                 } else if (info.file.status === 'error') {
324                     this.$message.error(`${info.file.name} file upload failed.`);
325                 }
326             },
327             handleChangeCoverFile(info) {
328                 if (info.file.status !== 'uploading') {
329                     console.log(info.file, info.fileList);
330                 }
331                 if (info.file.status === 'done') {
332                     this.form.coverFile = info.file.response.data;
6bcd13 333                     this.$message.success(`${info.file.name} file uploaded successfully`);
I 334                 } else if (info.file.status === 'error') {
335                     this.$message.error(`${info.file.name} file upload failed.`);
336                 }
337             },
338             /**
339              * 上传文件
340              */
341             customRequest(option) {
342                 const formData = new FormData()
343                 formData.append('file', option.file)
344                 sysFileInfoUpload(formData).then((res) => {
345                     if (res.success) {
346                         this.$message.success('上传成功')
c23efb 347
6bcd13 348                         option.onSuccess(res, option.file)
I 349                     } else {
350                         this.$message.error('上传失败:' + res.message)
351                     }
352                 })
353             },
f5539f 354             disabledDate(current) {
L 355                 return current < moment().subtract(1, "day");
356             },
357             getCalendarContainer(trigger) {
358                 return trigger => trigger.parentNode;
359             },
360             handleClose(removedTag) {
361                 const tags = this.tags.filter(tag => tag !== removedTag);
1ad93b 362                 //console.log(tags);
f5539f 363                 this.tags = tags;
L 364             },
365
366             showInput() {
367                 this.inputVisible = true;
368                 this.$nextTick(function() {
369                     this.$refs.input.focus();
370                 });
371             },
372
373             handleInputChange(e) {
374                 this.inputValue = e.target.value;
375             },
376
377             handleInputConfirm() {
378                 const inputValue = this.inputValue;
379                 let tags = this.tags;
380                 if (inputValue && tags.indexOf(inputValue) === -1) {
381                     tags = [...tags, inputValue];
382                 }
1ad93b 383                 //console.log(tags);
f5539f 384                 Object.assign(this, {
L 385                     tags,
386                     inputVisible: false,
387                     inputValue: '',
388                 });
389             },
1ad93b 390
f5539f 391         },
L 392     };
393 </script>
394
395 <style lang="less">
1ad93b 396     @media screen and(max-width: 575px) {
I 397         .ant-form-item-label {
398             padding: 8px !important;
399         }
400     }
401
f5539f 402     .myTip {
L 403         font-size: 10px;
404         color: #999;
405     }
406
407     .myBorder {
408         border: 1px solid #999;
1ad93b 409         border-radius: 10px;
f5539f 410     }
L 411
412     .ant-upload-list-item-info {
413         a {
414             color: #999;
415         }
416     }
417
418     /* tile uploaded pictures */
419     .upload-list-inline>.ant-upload-list-item {
420         float: left;
421         width: 100px;
422         margin-right: 8px;
423     }
424
425     .upload-list-inline>.ant-upload-animate-enter {
426         animation-name: uploadAnimateInlineIn;
427     }
428
429     .upload-list-inline>.ant-upload-animate-leave {
430         animation-name: uploadAnimateInlineOut;
431     }
432 </style>