Skip to content

Commit 09f724c

Browse files
authored
Merge branch 'master' into Ts
2 parents ce269cb + c34d7a9 commit 09f724c

File tree

3 files changed

+157
-123
lines changed

3 files changed

+157
-123
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"vue-property-decorator": "^8.1.0",
1616
"vue-router": "^3.0.3",
1717
"vue-quill-editor": "^3.0.6",
18-
"vuex": "^3.0.1"
18+
"vue-quill-editor-upload": "^1.1.0",
19+
"vue-router": "^3.0.1",
1920
},
2021
"devDependencies": {
2122
"@vue/cli-plugin-babel": "^3.0.3",

src/views/Editor.vue

Lines changed: 152 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,170 @@
11
<template>
2-
<div>
3-
<el-row class="warp">
4-
5-
<!--
2+
<div>
3+
<el-row class="warp">
4+
<!--
65
Form 组件提供了表单验证的功能,只需要通过 rule 属性传入约定的验证规则,并 Form-Item 的 prop 属性设置为需校验的字段名即可。具体可以参考官网:http://element.eleme.io/#/zh-CN/component/form
7-
-->
8-
<el-col :span="24" class="warp-main">
9-
<el-form ref="infoForm" :model="infoForm" :rules="rules" label-width="120px">
10-
<el-form-item label="标题" prop="btitle">
11-
<el-input v-model="infoForm.btitle"></el-input>
12-
</el-form-item>
13-
14-
<el-form-item label="分类">
15-
<el-select v-model="infoForm.bcategory" placeholder="请选择文章分类">
16-
<el-option label="技术博文" value="技术博文"></el-option>
17-
</el-select>
18-
</el-form-item>
6+
-->
7+
<el-col :span="24" class="warp-main">
8+
<el-form ref="infoForm" :model="infoForm" :rules="rules" label-width="120px">
9+
<el-form-item label="标题" prop="btitle">
10+
<el-input v-model="infoForm.btitle"></el-input>
11+
</el-form-item>
1912

20-
<el-form-item label="作者" prop="bsubmitter">
21-
<el-input v-model="infoForm.bsubmitter"></el-input>
22-
</el-form-item>
23-
<!--使用编辑器
24-
-->
25-
<el-form-item label="详细" prop="bcontent">
26-
<div class="edit_container">
27-
<quill-editor v-model="infoForm.bcontent"
28-
ref="myQuillEditor"
29-
class="editer"
30-
:options="editorOption" @ready="onEditorReady($event)">
31-
</quill-editor>
32-
</div>
33-
</el-form-item>
13+
<el-form-item label="分类">
14+
<el-select v-model="infoForm.bcategory" placeholder="请选择文章分类">
15+
<el-option label="技术博文" value="技术博文"></el-option>
16+
</el-select>
17+
</el-form-item>
3418

35-
<el-form-item>
36-
<el-button type="primary" @click="onSubmit">确认提交</el-button>
37-
</el-form-item>
38-
</el-form>
39-
</el-col>
19+
<el-form-item label="作者" prop="bsubmitter">
20+
<el-input v-model="infoForm.bsubmitter"></el-input>
21+
</el-form-item>
22+
<!--使用编辑器
23+
-->
24+
<el-form-item label="详细" prop="bcontent">
25+
<div class="edit_container">
26+
<quill-editor
27+
v-model="infoForm.bcontent"
28+
ref="myQuillEditor"
29+
class="editer"
30+
:options="editorOption"
31+
@ready="onEditorReady($event)"
32+
></quill-editor>
33+
</div>
34+
</el-form-item>
4035

41-
42-
</el-row>
43-
</div>
36+
<el-form-item>
37+
<el-button type="primary" @click="onSubmit">确认提交</el-button>
38+
</el-form-item>
39+
</el-form>
40+
</el-col>
41+
</el-row>
42+
</div>
4443
</template>
4544

4645
<script>
47-
import {quillEditor} from "vue-quill-editor"; //调用编辑器
48-
// require styles
49-
import 'quill/dist/quill.core.css'
50-
import 'quill/dist/quill.snow.css'
51-
import 'quill/dist/quill.bubble.css'
46+
import { quillEditor } from "vue-quill-editor"; //调用编辑器
47+
import { quillRedefine } from "vue-quill-editor-upload"; // 上传图片
5248
49+
// require styles
50+
import "quill/dist/quill.core.css";
51+
import "quill/dist/quill.snow.css";
52+
import "quill/dist/quill.bubble.css";
5353
54-
export default {
55-
data() {
56-
return {
57-
infoForm: {
58-
btitle: "",
59-
bsubmitter: "",
60-
bcategory:"技术博文",
61-
bcontent: ""
62-
},
63-
editorOption: {},
64-
//表单验证
65-
rules: {
66-
btitle: [{required: true, message: "请输入标题", trigger: "blur"}],
67-
bcontent: [
68-
{required: true, message: "请输入详细内容", trigger: "blur"}
69-
]
70-
}
71-
};
72-
},
73-
computed: {
74-
editor() {
75-
return this.$refs.myQuillEditor.quill;
76-
}
54+
export default {
55+
data() {
56+
return {
57+
infoForm: {
58+
btitle: "",
59+
bsubmitter: "",
60+
bcategory: "技术博文",
61+
bcontent: ""
62+
},
63+
editorOption: {},
64+
//表单验证
65+
rules: {
66+
btitle: [{ required: true, message: "请输入标题", trigger: "blur" }],
67+
bcontent: [
68+
{ required: true, message: "请输入详细内容", trigger: "blur" }
69+
]
70+
}
71+
};
72+
},
73+
computed: {
74+
editor() {
75+
var quill=this.$refs.myQuillEditor.quill;
76+
var toolbar = quill.getModule('toolbar');
77+
toolbar.addHandler('image', imageUpload);
78+
return this.$refs.myQuillEditor.quill;
79+
}
80+
},
81+
created() {
82+
this.editorOption = quillRedefine({
83+
// 图片上传的设置
84+
uploadConfig: {
85+
action: "/images/Upload/Pic", // 必填参数 图片上传地址
86+
// 必选参数 res是一个函数,函数接收的response为上传成功时服务器返回的数据
87+
// 你必须把返回的数据中所包含的图片地址 return 回去
88+
res: respnse => {
89+
90+
console.log(respnse.response);
91+
return "/"+respnse.response;
7792
},
78-
mounted() {
79-
//初始化
93+
methods: "POST", // 可选参数 图片上传方式 默认为post
94+
name: "img", // 可选参数 文件的参数名 默认为img
95+
size: 500, // 可选参数 图片限制大小,单位为Kb, 1M = 1024Kb
96+
accept: "image/png, image/gif, image/jpeg, image/bmp, image/x-icon", // 可选参数 可上传的图片格式
97+
header: (xhr, formData) => {
98+
xhr.setRequestHeader('Authorization',"Bearer "+localStorage.Token);
99+
// formData: 表单对象
100+
// formData.append('Name', "laozhang")
80101
},
81-
methods: {
82-
onEditorReady(editor) {
83-
},
84-
onSubmit() {
85-
//提交
86-
//this.$refs.infoForm.validate,这是表单验证
87-
this.$refs.infoForm.validate(valid => {
88-
if (valid) {
89-
console.log(this.infoForm)
90-
var postPara=this.infoForm;
91-
this.$api.post("Blog", postPara, r => {
92-
debugger
93-
if(r.success){
94-
var id=r.response
95-
this.$notify({
96-
type: "success",
97-
message: "添加成功,感谢技术分享!",
98-
duration: 3000
99-
});
100-
this.$router.replace(`/content/${id}`);
101-
102-
}else{
103-
var errorMsg=r.msg
104-
this.$message({
105-
type: "error",
106-
message: errorMsg,
107-
showClose: true
108-
});
109-
110-
}
111-
this.list = r.data;
112-
this.page = r.page;
113-
this.TotalCount = r.pageCount;
114-
this.isShow = false;
115-
});
116-
}
117-
});
102+
start: () => {}, // 可选参数 接收一个函数 开始上传数据时会触发
103+
end: () => {}, // 可选参数 接收一个函数 上传数据完成(成功或者失败)时会触发
104+
success: () => {}, // 可选参数 接收一个函数 上传数据成功时会触发
105+
error: () => {} // 可选参数 接收一个函数 上传数据中断时会触发
106+
}
107+
});
108+
},
109+
mounted() {
110+
//初始化
111+
},
112+
methods: {
113+
onEditorReady(editor) {},
114+
onSubmit() {
115+
//提交
116+
//this.$refs.infoForm.validate,这是表单验证
117+
this.$refs.infoForm.validate(valid => {
118+
if (valid) {
119+
console.log(this.infoForm);
120+
var postPara = this.infoForm;
121+
this.$api.post("Blog", postPara, r => {
122+
debugger;
123+
if (r.success) {
124+
var id = r.response;
125+
this.$notify({
126+
type: "success",
127+
message: "添加成功,感谢技术分享!",
128+
duration: 3000
129+
});
130+
this.$router.replace(`/content/${id}`);
131+
} else {
132+
var errorMsg = r.msg;
133+
this.$message({
134+
type: "error",
135+
message: errorMsg,
136+
showClose: true
137+
});
118138
}
119-
},
120-
components: {
121-
//使用编辑器
122-
quillEditor
139+
this.list = r.data;
140+
this.page = r.page;
141+
this.TotalCount = r.pageCount;
142+
this.isShow = false;
143+
});
123144
}
124-
};
145+
});
146+
}
147+
},
148+
components: {
149+
//使用编辑器
150+
quillEditor,
151+
quillRedefine
152+
}
153+
};
125154
</script>
126155

127156
<style>
128-
.warp{
129-
background: #fff;
130-
padding-top: 20px;
131-
width: 75%;
132-
margin: 0 auto;
133-
}
134-
.ql-container.ql-snow,.ql-editor.ql-blank {
135-
min-height: 300px !important;
136-
}
137-
.el-form{
138-
padding-right: 80px !important;
139-
}
157+
.warp {
158+
background: #fff;
159+
padding-top: 20px;
160+
width: 75%;
161+
margin: 0 auto;
162+
}
163+
.ql-container.ql-snow,
164+
.ql-editor.ql-blank {
165+
min-height: 300px !important;
166+
}
167+
.el-form {
168+
padding-right: 80px !important;
169+
}
140170
</style>

vue.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ module.exports = {
4949
// 路径重写,
5050
"^/apb": "" // 替换target中的请求地址
5151
}
52+
},
53+
"/images": {
54+
target: "http://localhost:8081",
5255
}
5356
},
5457
before: app => {}

0 commit comments

Comments
 (0)