-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_id.vue
179 lines (163 loc) · 5.42 KB
/
_id.vue
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
<template>
<div class="new-post">
<div class="new-post-in">
<div class="new-post-title">
新建博客
</div>
<a-row class="new-post-form">
<a-col :xs="24" :xl="12">
<a-spin :spinning="loading">
<a-form-model ref="FormModel" :rules="rules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-form-model-item label="文章标题" prop="title">
<a-input v-model="form.title" placeholder="请输入文章标题"/>
</a-form-model-item>
<a-form-model-item label="文章内容" prop="content" v-show="switchCheck">
<div class="quill-editor"
:content="form.content"
@change="onEditorChange($event)"
@blur="onEditorBlur($event)"
@focus="onEditorFocus($event)"
@ready="onEditorReady($event)"
v-quill:myQuillEditor="editorOption">
</div>
</a-form-model-item>
<a-form-model-item label="文章内容" prop="content1" v-show="!switchCheck">
<a-textarea v-model="form.content1" :rows="12">
</a-textarea>
</a-form-model-item>
<!-- <a-form-model-item label="切换输入格式">
<a-switch v-model="switchCheck"></a-switch>
</a-form-model-item>-->
<a-form-model-item>
<div class="button-wrapper">
<a-button type="primary" @click="onSubmit" :loading="loading">
保存
</a-button>
<NuxtLink to="/posts">
<a-button style="margin-left: 20px">
取消
</a-button>
</NuxtLink>
</div>
</a-form-model-item>
</a-form-model>
</a-spin>
</a-col>
</a-row>
</div>
</div>
</template>
<script lang="ts">
import {Vue, Component, Ref} from 'vue-property-decorator';
import {FormModel} from 'ant-design-vue';
@Component({
layout: 'GlobalLayout'
})
export default class EditPost extends Vue {
@Ref('FormModel') FormModel!: FormModel;
switchCheck = false
loading = false
form: FormInterface = {
id: 0,
title: '',
content: '',
content1: '',
};
get rules(){
return this.switchCheck ? {
title: [{required: true, message: '请输入文章标题', trigger: 'blur'}],
content: [{required: true, message: '请输入文章内容', trigger: 'blur'}],
} : {
title: [{required: true, message: '请输入文章标题', trigger: 'blur'}],
content1: [{required: true, message: '请输入文章内容', trigger: 'blur'}],
}
}
labelCol: SpaceColInterface = {span: 2};
wrapperCol: SpaceColInterface = {span: 22};
content: '<p>I am Example</p>'
editorOption = {
// some quill options
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // 加粗,斜体,下划线,删除线
['blockquote', 'code-block'], //引用,代码块
[{ 'header': 1 }, { 'header': 2 }], // 几级标题
[{ 'list': 'ordered'}, { 'list': 'bullet' }], // 有序列表,无序列表
[{ 'script': 'sub'}, { 'script': 'super' }], // 下角标,上角标
[{ 'indent': '-1'}, { 'indent': '+1' }], // 缩进
[{ 'size': ['small', false, 'large', 'huge'] }], // 字体大小
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],// 标题
[{ 'color': [] }, { 'background': [] }], // 颜色选择
[{ 'align': [false,'center','right','justify'] }], // 居中
['clean'] // 清除样式
]
}
}
created(){
this.$axios.get(`/api/posts/${this.$route.params.id}`).then(response=>{
const dataIn = response.data.data
if (response.data.data){
this.form.id = dataIn.id
this.form.title = dataIn.title
this.form.content1 = dataIn.content
}
})
}
onSubmit(){
this.FormModel.validate(valid => {
if (valid) {
this.loading = true
this.$axios.put(`/api/posts/${this.$route.params.id}`,{
id: this.form.id,
title: this.form.title,
content: this.switchCheck ? this.form.content : this.form.content1
}).then(response=>{
this.$message.success(response.data.message || '保存成功')
this.$router.push({path: '/posts'});
}).catch(error=>{
this.$message.error(error.response.data.message || '保存失败')
}).finally(()=>{
this.loading = false
})
}
})
}
onEditorBlur(editor) {
}
onEditorFocus(editor) {
}
onEditorReady(editor) {
}
onEditorChange({ editor, html, text }) {
this.form.content = html
}
}
</script>
<style scoped lang="scss">
.new-post{
padding: 0 32px;
.new-post-in{
padding: 24px;
background: #fff;
border-radius: 10px;
box-sizing: border-box;
height: calc(100vh - 132px);
overflow: auto;
@media (max-width: 1199px) {
height: calc(100vh - 202px);
}
.new-post-title{
font-family: PingFangSC-Medium, sans-serif;
font-size: 16px;
color: #233167;
}
.new-post-form{
padding: 24px 0 0 0;
}
.quill-editor {
height: 200px;
overflow-y: auto;
}
}
}
</style>