inleft
2022-02-21 63f5119bcc714c36fe8db21e5461d73eb5a0eaa0
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">
L 71                         <a-radio value="Markdown">
1ad93b 72                             markdown
f5539f 73                         </a-radio>
L 74                         <a-radio value="Html">
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"
113                         :default-file-list="form.coverFileList">
114                         <a-button>
115                             <a-icon type="upload" />jpg/png/jpeg..
116                         </a-button>
f5539f 117                     </a-upload>
6bcd13 118                     <!-- <span class="myTip">
15bd39 119                         自动转码,可以传高清图
6bcd13 120                     </span> -->
f5539f 121                 </a-form-model-item>
L 122
123                 <a-form-model-item label="定时">
06ee76 124                     <a-date-picker v-model="form.publishDate" show-time type="datetime" placeholder="发布时间"
f5539f 125                         style="width: 100%;" :disabledDate="disabledDate"
L 126                         :getCalendarContainer="getCalendarContainer()" />
06ee76 127                 </a-form-model-item>
L 128
7b98c8 129                 <div v-bind:class="{'myBorder':form.top}" style="padding: 3px;margin-bottom: 10px;">
6bcd13 130                     <a-form-model-item label="置顶">
I 131                         <a-switch v-model="form.top" />
132                     </a-form-model-item>
f5539f 133
6bcd13 134                     <div v-show="form.top">
I 135                         <a-form-model-item label="权重">
7b98c8 136                             <a-slider v-model="form.sliderValue" :default-value="50" :step="5"
6bcd13 137                                 :getTooltipPopupContainer="getCalendarContainer()" />
I 138                             <span class="myTip">
139                                 越小越靠前
140                             </span>
141                         </a-form-model-item>
142                     </div>
143                 </div>
f5539f 144
L 145
1ad93b 146                 <div v-bind:class="{'myBorder':form.lock}" style="padding: 3px;">
f5539f 147
L 148                     <a-form-model-item label="加锁">
149                         <a-switch v-model="form.lock" />
150                         <span v-show="!form.lock" class="myTip">
151                             默认为公开
152                         </span>
153                     </a-form-model-item>
154
155                     <div v-show="form.lock ">
156                         <a-form-model-item label="阅读权限">
157                             <a-radio-group v-model="form.auth">
158                                 <a-radio value="private">
159                                     私人
160                                 </a-radio>
161                                 <a-radio value="password">
162                                     密码授权
163                                 </a-radio>
164                             </a-radio-group>
165                         </a-form-model-item>
166
167                         <a-form-model-item label="授权密码" v-show="form.auth=='password'">
7b98c8 168                             <a-input-password v-model="form.password" autocomplete='new-password' type="password"
6bcd13 169                                 placeholder="独立密码">
f5539f 170                                 <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
7b98c8 171                             </a-input-password>
f5539f 172                         </a-form-model-item>
L 173                     </div>
174
175                 </div>
176
177             </div>
178
179         </a-form-model>
180     </div>
181 </template>
182
183 <script>
184     import moment from "moment";
6bcd13 185     import {
I 186         sysFileInfoUpload
187     } from '../../api/fileManage.js';
63f511 188
6bcd13 189     import {
I 190         queryBlogArticleType
191     } from '../../api/blogArticleType.js'
63f511 192
I 193
f5539f 194     export default {
6bcd13 195         beforeMount() {
I 196             queryBlogArticleType({}).then((res) => {
197                 this.blogArticleType = res.data;
198             })
199         },
f5539f 200         data() {
06ee76 201
L 202             let validateContent = (rule, value, callback) => {
203                 if (this.form.online) {
204                     console.log("内容未填");
205                     this.$refs.myForm.validateField('content')
63f511 206                     if (this.form.content == null || this.form.content == "") {
I 207                         callback(new Error('内容未填'));
208                     }
06ee76 209                 } else {
L 210                     console.log("文件未传");
211                     this.$refs.myForm.validateField('blogFileList')
63f511 212                     if (this.form.blogFileList == null || this.form.blogFileList.length == 0) {
I 213                         callback(new Error('文件未传'));
214                     }
06ee76 215                 }
L 216                 callback();
217             };
218
f5539f 219             return {
6bcd13 220                 blogArticleType: [],
f5539f 221                 tags: [],
L 222                 inputVisible: false,
223                 inputValue: '',
224                 labelCol: {
1ad93b 225                     span: 7
f5539f 226                 },
L 227                 wrapperCol: {
1ad93b 228                     span: 13
f5539f 229                 },
L 230                 form: {
6bcd13 231                     secret: '',
06ee76 232                     online: false,
1ad93b 233                     preference: false,
f5539f 234                     title: '',
L 235                     content: '',
236                     class: [],
237                     tempSave: false,
238                     blogType: "Markdown",
239                     publishDate: "",
240                     lock: false,
6bcd13 241                     top: false,
f5539f 242                     auth: "private",
L 243                     password: "",
244                     blogFileList: [],
1ad93b 245                     coverFileList: [],
f5539f 246                 },
1ad93b 247                 rules: {
I 248                     title: [{
249                             required: true,
250                             message: '标题不能为空',
251                             trigger: 'blur'
252                         },
253                         {
63f511 254                             min: 1,
1ad93b 255                             max: 50,
I 256                             message: '字数限制1~50',
257                             trigger: 'blur'
258                         },
259                     ],
6bcd13 260                     secret: [{
I 261                         required: true,
262                         message: '不正经的人..',
263                         trigger: 'blur'
264                     }],
06ee76 265                     common: [{
L 266                         validator: validateContent,
267                         trigger: []
268                     }],
63f511 269                     // content: [{
I 270                     //     max: 10,
271                     //     required: true,
272                     //     message: '至少填一下上传内容',
273                     //     trigger: 'blur'
274                     // }, ],
275                     // blogFileList: [{
276                     //     max: 1,
277                     //     required: true,
278                     //     message: '文件未上传',
279                     // }],
1ad93b 280                     class: [{
I 281                         required: true,
282                         message: '至少选一个分类',
283                         trigger: 'blur'
284                     }, ],
63f511 285
1ad93b 286                 }
f5539f 287             };
L 288         },
289         methods: {
6bcd13 290             beforeUpload(file, fileList) {
I 291                 console.log(333);
292                 console.log(this.blogFileList);
293                 return new Promise((resolve, reject) => {
63f511 294                     if (fileList.length >= 2) {
6bcd13 295                         this.$message.error('这里最多上传一个文件');
I 296                         return reject(false);
297                     }
63f511 298                     // var testmsg=/^image\/(jpeg|png|jpg)$/.test(file.type)
I 299                     // // var testmsg=/^image\/(md|html|markdown)$/.test(file.type)
300                     // if (!testmsg) {
301                     //   this.$message.error('上传文件格式不对!');
302                     //   return reject(false);
303                     // }
304
305                     const isLt2M = file.size / 1024 / 1024 <= 2 //图片大小不超过2MB
306                     if (!isLt2M) {
307                         this.$message.error('上传文件大小不能超过 2M!');
308                         return reject(false);
309                     }
310                     return resolve(true)
311                 });
312
6bcd13 313             },
I 314             handleChange(info) {
315                 if (info.file.status !== 'uploading') {
316                     console.log(info.file, info.fileList);
317                 }
318                 if (info.file.status === 'done') {
319                     this.$message.success(`${info.file.name} file uploaded successfully`);
320                 } else if (info.file.status === 'error') {
321                     this.$message.error(`${info.file.name} file upload failed.`);
322                 }
323             },
324             /**
325              * 上传文件
326              */
327             customRequest(option) {
328                 const formData = new FormData()
329                 formData.append('file', option.file)
330                 sysFileInfoUpload(formData).then((res) => {
331                     if (res.success) {
332                         this.$message.success('上传成功')
333                         option.onSuccess(res, option.file)
334                     } else {
335                         this.$message.error('上传失败:' + res.message)
336                     }
337                 })
338             },
f5539f 339             disabledDate(current) {
L 340                 return current < moment().subtract(1, "day");
341             },
342             getCalendarContainer(trigger) {
343                 return trigger => trigger.parentNode;
344             },
345             handleClose(removedTag) {
346                 const tags = this.tags.filter(tag => tag !== removedTag);
1ad93b 347                 //console.log(tags);
f5539f 348                 this.tags = tags;
L 349             },
350
351             showInput() {
352                 this.inputVisible = true;
353                 this.$nextTick(function() {
354                     this.$refs.input.focus();
355                 });
356             },
357
358             handleInputChange(e) {
359                 this.inputValue = e.target.value;
360             },
361
362             handleInputConfirm() {
363                 const inputValue = this.inputValue;
364                 let tags = this.tags;
365                 if (inputValue && tags.indexOf(inputValue) === -1) {
366                     tags = [...tags, inputValue];
367                 }
1ad93b 368                 //console.log(tags);
f5539f 369                 Object.assign(this, {
L 370                     tags,
371                     inputVisible: false,
372                     inputValue: '',
373                 });
374             },
1ad93b 375
f5539f 376         },
L 377     };
378 </script>
379
380 <style lang="less">
1ad93b 381     @media screen and(max-width: 575px) {
I 382         .ant-form-item-label {
383             padding: 8px !important;
384         }
385     }
386
f5539f 387     .myTip {
L 388         font-size: 10px;
389         color: #999;
390     }
391
392     .myBorder {
393         border: 1px solid #999;
1ad93b 394         border-radius: 10px;
f5539f 395     }
L 396
397     .ant-upload-list-item-info {
398         a {
399             color: #999;
400         }
401     }
402
403     /* tile uploaded pictures */
404     .upload-list-inline>.ant-upload-list-item {
405         float: left;
406         width: 100px;
407         margin-right: 8px;
408     }
409
410     .upload-list-inline>.ant-upload-animate-enter {
411         animation-name: uploadAnimateInlineIn;
412     }
413
414     .upload-list-inline>.ant-upload-animate-leave {
415         animation-name: uploadAnimateInlineOut;
416     }
417 </style>