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
| const App = {
| mixins: [sharedMixin],/////共用的方法/////
| data() {
| return {
| addBlogForm: {
| title: '',
| en_title: '',
| content: '',
| en_content: '',
| desc: '',
| en_desc: '',
| cover_img: '',
| },
| submitDisabled: false,// 按钮禁用
| };
| },
| mounted() {
| },
| created() {
| window.setHtmlValue = this.setHtmlValue;
| },
| methods: {
| /////获取富文本内容/////
| setHtmlValue(value, type = 1) {
| if (type == 1) {
| this.addBlogForm.content = value;
| } else {
| this.addBlogForm.en_content = value;
| }
| },
|
| /////上传图片成功后/////
| handleCoverImgSuccess(response, uploadFile) {
| if (response.code != 200) {
| this.$message({
| message: response.message,
| type: 'error',
| duration: 1500,
| });
| return false;
| }
| this.addBlogForm.cover_img = response.data.url;
| },
|
| /////上传图片之前/////
| beforeCoverImgUpload(rawFile) {
| // console.log(rawFile);
| if (rawFile.type !== 'image/jpeg') {
| this.$message({
| message: "图片格式错误",
| type: 'error',
| duration: 1500,
| center: true
| });
| return false;
| } else if (rawFile.size / 1024 / 1024 > 10) {
| this.$message({
| message: "图片大小过大",
| type: 'error',
| duration: 1500,
| center: true
| });
| return false;
| }
| return true;
| },
| /////保存/////
| onSubmit() {
| var that = this;
| that.submitDisabled = true;
| const loading = this.$loading({
| lock: true,
| text: '提交中',
| spinner: 'el-icon-loading',
| background: 'rgba(0, 0, 0, 0.2)'
| });
| let url = "/admin/blog/save_blog.html";
| postRequest(url, that.addBlogForm).then(res => {
| loading.close();
| if (res.data.code == 200) {
| that.$message({
| message: res.data.message,
| type: 'success',
| duration: 1000,
| center: true,
| onClose: function () {
| window.location.href = "/admin/blog/index.html";
| }
| });
| } else {
| that.submitDisabled = false;
| that.$message({
| message: res.data.message,
| type: 'error',
| duration: 1500,
| center: true
| });
| }
| });
| },
|
| }
| };
| const app = Vue.createApp(App);
| for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
| app.component(key, component)
| }
| app.use(ElementPlus, {
| locale: ElementPlusLocaleZhCn,
| });
| app.mount("#vue_item");
|
|