inleft
2022-02-25 fc0c102554f509989dd74b199f298a67f266c3c8
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
427
428
429
430
431
432
<template>
    <div>
        <a-form-model ref="myForm" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="rules">
            <a-form-model-item label="认证" prop="secret">
                <a-input v-model="form.secret" autocomplete='new-password' type="password" placeholder="口令">
                    <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
                </a-input>
            </a-form-model-item>
 
            <a-form-model-item label="标题" prop="title">
                <a-input v-model="form.title" placeholder="限 50字内" />
            </a-form-model-item>
 
            <a-form-model-item label="模式切换" prop="common">
                <a-switch v-model="form.online" />
                <span class="myTip" v-if="form.online">
                    由系统生成文件
                </span>
                <span class="myTip" v-else>
                    本地文件上传
                </span>
            </a-form-model-item>
 
 
            <a-form-model-item label="日志文件" v-show="!form.online">
                <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
                    :default-file-list="form.blogFileList">
                    <a-button>
                        <a-icon type="upload" /> 限 markdown/html
                    </a-button>
                </a-upload> -->
 
                <a-upload :customRequest="customRequest" name="file" :showUploadList="true" @change="handleChange"
                    :default-file-list="form.blogFileList" :beforeUpload="beforeUpload">
 
                    <a-button>
                        <a-icon type="upload" />限 markdown/html
                    </a-button>
                </a-upload>
            </a-form-model-item>
 
            <a-form-model-item label="日志内容" v-show="form.online">
                <a-input v-model="form.content" type="textarea" placeholder="限10k字数" />
            </a-form-model-item>
 
            <a-form-model-item label="分类" prop="class">
                <a-select v-model="form.class" :allowClear="true" mode="default" placeholder="日志分类"
                    :getPopupContainer="getCalendarContainer()">
 
                    <a-select-option v-for="(item,index) in this.blogArticleType" :key="index" :value="item.id">
                        {{ item.typeName }}
                    </a-select-option>
 
                </a-select>
            </a-form-model-item>
 
            <a-form-model-item label="额外设置">
                <a-switch v-model="form.preference" />
            </a-form-model-item>
 
            <div v-show="form.preference" class="myBorder" style="padding:10px;">
                <a-form-model-item label="起个草稿">
                    <a-switch v-model="form.tempSave" />
                    <span v-show="form.tempSave" class="myTip">
                        临时存储,游客无法浏览
                    </span>
                </a-form-model-item>
 
                <a-form-model-item label=" 日志类型">
                    <a-radio-group v-model="form.blogType">
                        <a-radio value="1">
                            markdown
                        </a-radio>
                        <a-radio value="2">
                            html
                        </a-radio>
                    </a-radio-group>
                </a-form-model-item>
 
 
                <a-form-model-item label="标签">
                    <template v-for="(tag, index) in tags">
                        <a-tooltip v-if="tag.length > 20" :key="tag" :title="tag">
                            <a-tag :key="tag" :closable="index !== 0" @close="() => handleClose(tag)">
                                {{ `${tag.slice(0, 20)}...` }}
                            </a-tag>
                        </a-tooltip>
                        <a-tag v-else :key="tag" :closable="index >= 0" @close="() => handleClose(tag)">
                            {{ tag }}
                        </a-tag>
                    </template>
 
                    <a-input v-if="inputVisible" ref="input" type="text" size="small" :style="{ width: '78px' }"
                        :value="inputValue" @change="handleInputChange" @blur="handleInputConfirm"
                        @keyup.enter="handleInputConfirm" />
 
                    <a-tag v-else style="background: #fff; borderStyle: dashed;" @click="showInput">
                        <a-icon type="plus" /> New Tag
                    </a-tag>
 
                </a-form-model-item>
 
 
                <a-form-model-item label="封面">
                    <!-- <a-upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" list-type="picture"
                        :default-file-list="form.coverFileList" class="upload-list-inline">
                        <a-button>
                            <a-icon type="upload" /> jpg/png/jpeg..
                        </a-button>
                    </a-upload> -->
 
                    <a-upload :customRequest="customRequest" name="file" :showUploadList="true" list-type="picture"
                        @change="handleChangeCoverFile"
                        :default-file-list="form.coverFileList">
                        <a-button>
                            <a-icon type="upload" />jpg/png/jpeg..
                        </a-button>
                    </a-upload>
                    <!-- <span class="myTip">
                        自动转码,可以传高清图
                    </span> -->
                </a-form-model-item>
 
                <a-form-model-item label="定时">
                    <a-date-picker v-model="form.publishDate" show-time type="datetime" placeholder="发布时间"
                        style="width: 100%;" :disabledDate="disabledDate"
                        :getCalendarContainer="getCalendarContainer()" />
                </a-form-model-item>
 
                <div v-bind:class="{'myBorder':form.top}" style="padding: 3px;margin-bottom: 10px;">
                    <a-form-model-item label="置顶">
                        <a-switch v-model="form.top" />
                    </a-form-model-item>
 
                    <div v-show="form.top">
                        <a-form-model-item label="权重">
                            <a-slider v-model="form.sliderValue" :default-value="50" :step="5"
                                :getTooltipPopupContainer="getCalendarContainer()" />
                            <span class="myTip">
                                越小越靠前
                            </span>
                        </a-form-model-item>
                    </div>
                </div>
 
 
                <div v-bind:class="{'myBorder':form.lock}" style="padding: 3px;">
 
                    <a-form-model-item label="加锁">
                        <a-switch v-model="form.lock" />
                        <span v-show="!form.lock" class="myTip">
                            默认为公开
                        </span>
                    </a-form-model-item>
 
                    <div v-show="form.lock ">
                        <a-form-model-item label="阅读权限">
                            <a-radio-group v-model="form.auth">
                                <a-radio value="2">
                                    私人
                                </a-radio>
                                <a-radio value="3">
                                    密码授权
                                </a-radio>
                            </a-radio-group>
                        </a-form-model-item>
 
                        <a-form-model-item label="授权密码" v-show="form.auth==3">
                            <a-input-password v-model="form.password" autocomplete='new-password' type="password"
                                placeholder="独立密码">
                                <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
                            </a-input-password>
                        </a-form-model-item>
                    </div>
 
                </div>
 
            </div>
 
        </a-form-model>
    </div>
</template>
 
<script>
    import moment from "moment";
    import {
        sysFileInfoUpload
    } from '../../api/fileManage.js';
 
    import {
        queryBlogArticleType
    } from '../../api/blogArticleType.js'
 
 
    export default {
        beforeMount() {
            queryBlogArticleType({}).then((res) => {
                this.blogArticleType = res.data;
            })
        },
        data() {
 
            let validateContent = (rule, value, callback) => {
                if (this.form.online) {
                    console.log("内容未填");
                    this.$refs.myForm.validateField('content')
                    if (this.form.content == null || this.form.content == "") {
                        callback(new Error('内容未填'));
                    }
                } else {
                    console.log("文件未传");
                    this.$refs.myForm.validateField('blogFileList')
                    if (this.form.fileId == null) {
                        callback(new Error('文件未传'));
                    }
                }
                callback();
            };
 
            return {
                blogArticleType: [],
                tags: [],
                inputVisible: false,
                inputValue: '',
                labelCol: {
                    span: 7
                },
                wrapperCol: {
                    span: 13
                },
                form: {
                    secret: '',
                    online: false,
                    preference: false,
                    title: '',
                    content: '',
                    class: [],
                    tempSave: false,
                    blogType: "1",
                    publishDate: "",
                    lock: false,
                    top: false,
                    sliderValue:50,
                    auth: 1,
                    password: "",
                    fileId: null,
                    coverFile: null,
                    blogFileList: [],
                    coverFileList: [],
                },
                rules: {
                    title: [{
                            required: true,
                            message: '标题不能为空',
                            trigger: 'blur'
                        },
                        {
                            min: 1,
                            max: 50,
                            message: '字数限制1~50',
                            trigger: 'blur'
                        },
                    ],
                    secret: [{
                        required: true,
                        message: '不正经的人..',
                        trigger: 'blur'
                    }],
                    common: [{
                        validator: validateContent,
                        trigger: []
                    }],
                    // content: [{
                    //     max: 10,
                    //     required: true,
                    //     message: '至少填一下上传内容',
                    //     trigger: 'blur'
                    // }, ],
                    // blogFileList: [{
                    //     max: 1,
                    //     required: true,
                    //     message: '文件未上传',
                    // }],
                    class: [{
                        required: true,
                        message: '至少选一个分类',
                        trigger: 'blur'
                    }, ],
 
                }
            };
        },
        methods: {
            beforeUpload(file, fileList) {
                return new Promise((resolve, reject) => {
                    if (this.form.fileId != null) {
                        this.$message.error('这里最多上传一个文件');
                        return reject(false);
                    }
                    // var testmsg=/^image\/(jpeg|png|jpg)$/.test(file.type)
                    // // var testmsg=/^image\/(md|html|markdown)$/.test(file.type)
                    // if (!testmsg) {
                    //   this.$message.error('上传文件格式不对!');
                    //   return reject(false);
                    // }
 
                    const isLt2M = file.size / 1024 / 1024 <= 2 //图片大小不超过2MB
                    if (!isLt2M) {
                        this.$message.error('上传文件大小不能超过 2M!');
                        return reject(false);
                    }
                    return resolve(true)
                });
 
            },
            handleChange(info) {
                if (info.file.status !== 'uploading') {
                    console.log(info.file, info.fileList);
                }
                if (info.file.status === 'done') {
                    this.form.fileId = info.file.response.data;
                    this.$message.success(`${info.file.name} file uploaded successfully`);
                } else if (info.file.status === 'error') {
                    this.$message.error(`${info.file.name} file upload failed.`);
                }
            },
            handleChangeCoverFile(info) {
                if (info.file.status !== 'uploading') {
                    console.log(info.file, info.fileList);
                }
                if (info.file.status === 'done') {
                    this.form.coverFile = info.file.response.data;
                    this.$message.success(`${info.file.name} file uploaded successfully`);
                } else if (info.file.status === 'error') {
                    this.$message.error(`${info.file.name} file upload failed.`);
                }
            },
            /**
             * 上传文件
             */
            customRequest(option) {
                const formData = new FormData()
                formData.append('file', option.file)
                sysFileInfoUpload(formData).then((res) => {
                    if (res.success) {
                        this.$message.success('上传成功')
 
                        option.onSuccess(res, option.file)
                    } else {
                        this.$message.error('上传失败:' + res.message)
                    }
                })
            },
            disabledDate(current) {
                return current < moment().subtract(1, "day");
            },
            getCalendarContainer(trigger) {
                return trigger => trigger.parentNode;
            },
            handleClose(removedTag) {
                const tags = this.tags.filter(tag => tag !== removedTag);
                //console.log(tags);
                this.tags = tags;
            },
 
            showInput() {
                this.inputVisible = true;
                this.$nextTick(function() {
                    this.$refs.input.focus();
                });
            },
 
            handleInputChange(e) {
                this.inputValue = e.target.value;
            },
 
            handleInputConfirm() {
                const inputValue = this.inputValue;
                let tags = this.tags;
                if (inputValue && tags.indexOf(inputValue) === -1) {
                    tags = [...tags, inputValue];
                }
                //console.log(tags);
                Object.assign(this, {
                    tags,
                    inputVisible: false,
                    inputValue: '',
                });
            },
 
        },
    };
</script>
 
<style lang="less">
    @media screen and(max-width: 575px) {
        .ant-form-item-label {
            padding: 8px !important;
        }
    }
 
    .myTip {
        font-size: 10px;
        color: #999;
    }
 
    .myBorder {
        border: 1px solid #999;
        border-radius: 10px;
    }
 
    .ant-upload-list-item-info {
        a {
            color: #999;
        }
    }
 
    /* tile uploaded pictures */
    .upload-list-inline>.ant-upload-list-item {
        float: left;
        width: 100px;
        margin-right: 8px;
    }
 
    .upload-list-inline>.ant-upload-animate-enter {
        animation-name: uploadAnimateInlineIn;
    }
 
    .upload-list-inline>.ant-upload-animate-leave {
        animation-name: uploadAnimateInlineOut;
    }
</style>