@jx3box/jx3box-editor 1.4.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Upload.vue +167 -167
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-editor",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Upload.vue CHANGED
@@ -53,187 +53,187 @@
53
53
  </template>
54
54
 
55
55
  <script>
56
- import axios from "axios";
57
- import { __cms } from "@jx3box/jx3box-common/data/jx3box.json";
58
- const API_Root = process.env.NODE_ENV === "production" ? __cms : "/";
59
- const API = API_Root + "api/cms/upload";
60
-
61
- import allow_types from "@jx3box/jx3box-common/data/conf";
62
- const imgtypes = ["jpg", "png", "gif", "bmp", "webp"];
63
-
64
- export default {
65
- name: "Upload",
66
- props: {
67
- text: {
68
- type: String,
69
- },
70
- onlyImage: {
71
- type: Boolean,
72
- },
73
- desc: {
74
- type: String,
75
- },
76
- accept: {
77
- type: String,
78
- },
79
- enable: {
80
- type: Boolean,
81
- default: true,
82
- },
56
+ import axios from "axios";
57
+ import { __cms } from "@jx3box/jx3box-common/data/jx3box.json";
58
+ const API_Root = process.env.NODE_ENV === "production" ? __cms : "/";
59
+ const API = API_Root + "api/cms/upload";
60
+
61
+ import allow_types from "@jx3box/jx3box-common/data/conf";
62
+ const imgtypes = ["jpg", "png", "gif", "bmp", "webp", "jpeg"];
63
+
64
+ export default {
65
+ name: "Upload",
66
+ props: {
67
+ text: {
68
+ type: String,
83
69
  },
84
- data: function() {
85
- return {
86
- API: API,
87
- dialogVisible: false,
88
- tip: this.desc || "一次最多同时上传10个文件(不超过5M),格式限常见的图片、文档、数据表及压缩包",
89
- btn_txt: this.text || "上传附件",
90
-
91
- fileList: [],
92
- selectedCount: 0,
93
- insertList: "",
94
-
95
- // accept: allow_types.accept,
96
- // sizeLimit: allow_types.sizeLimit,
97
- };
70
+ onlyImage: {
71
+ type: Boolean,
98
72
  },
99
- watch: {
100
- fileList: {
101
- deep: true,
102
- handler: function(newval) {
103
- this.$emit("update", newval);
104
- },
105
- },
106
- insertList: function(newval) {
107
- this.$emit("htmlUpdate", newval);
108
- },
73
+ desc: {
74
+ type: String,
109
75
  },
110
- computed: {
111
- buttonTXT: function() {
112
- return this.selectedCount ? "插 入" : "确 定";
76
+ accept: {
77
+ type: String,
78
+ },
79
+ enable: {
80
+ type: Boolean,
81
+ default: true,
82
+ },
83
+ },
84
+ data: function () {
85
+ return {
86
+ API: API,
87
+ dialogVisible: false,
88
+ tip: this.desc || "一次最多同时上传10个文件(不超过5M),格式限常见的图片、文档、数据表及压缩包",
89
+ btn_txt: this.text || "上传附件",
90
+
91
+ fileList: [],
92
+ selectedCount: 0,
93
+ insertList: "",
94
+
95
+ // accept: allow_types.accept,
96
+ // sizeLimit: allow_types.sizeLimit,
97
+ };
98
+ },
99
+ watch: {
100
+ fileList: {
101
+ deep: true,
102
+ handler: function (newval) {
103
+ this.$emit("update", newval);
113
104
  },
114
105
  },
115
- methods: {
116
- change: function(file, fileList) {
117
- if (file.status != "success") {
118
- // 判断大小
119
- // if (file.size > this.sizeLimit) {
120
- // this.$message.error("文件超出大小限制");
121
- // this.removeFile(fileList, file.uid);
122
- // return;
123
- // }
124
-
125
- // 分析文件类型
126
- let ext = file.name.split(".").pop();
127
- let is_img = imgtypes.includes(ext);
128
-
129
- if (this.onlyImage && !is_img) return;
130
-
131
- // 构建数据
132
- let fdata = new FormData();
133
- fdata.append("file", file.raw);
134
-
135
- // 异步上传
136
- axios
137
- .post(API, fdata, {
138
- headers: {
139
- "Content-Type": "multipart/form-data",
140
- },
141
- withCredentials: true,
142
- auth: {
143
- username: (localStorage && localStorage.getItem("token")) || "",
144
- password: "cms common request",
145
- },
146
- })
147
- .then((res) => {
148
- if (res.data.code) {
149
- this.$message({
150
- message: res.data.msg,
151
- type: "error",
152
- });
153
- return;
154
- }
155
- // 提醒
106
+ insertList: function (newval) {
107
+ this.$emit("htmlUpdate", newval);
108
+ },
109
+ },
110
+ computed: {
111
+ buttonTXT: function () {
112
+ return this.selectedCount ? "插 入" : "确 定";
113
+ },
114
+ },
115
+ methods: {
116
+ change: function (file, fileList) {
117
+ if (file.status != "success") {
118
+ // 判断大小
119
+ // if (file.size > this.sizeLimit) {
120
+ // this.$message.error("文件超出大小限制");
121
+ // this.removeFile(fileList, file.uid);
122
+ // return;
123
+ // }
124
+
125
+ // 分析文件类型
126
+ let ext = file.name.split(".").pop();
127
+ let is_img = imgtypes.includes(ext);
128
+
129
+ if (this.onlyImage && !is_img) return;
130
+
131
+ // 构建数据
132
+ let fdata = new FormData();
133
+ fdata.append("file", file.raw);
134
+
135
+ // 异步上传
136
+ axios
137
+ .post(API, fdata, {
138
+ headers: {
139
+ "Content-Type": "multipart/form-data",
140
+ },
141
+ withCredentials: true,
142
+ auth: {
143
+ username: (localStorage && localStorage.getItem("token")) || "",
144
+ password: "cms common request",
145
+ },
146
+ })
147
+ .then((res) => {
148
+ if (res.data.code) {
156
149
  this.$message({
157
- message: "上传成功",
158
- type: "success",
150
+ message: res.data.msg,
151
+ type: "error",
159
152
  });
160
-
161
- // 修改path
162
- file.url = res.data.data && res.data.data[0];
163
-
164
- // 额外赋值
165
- file.is_img = is_img;
166
- file.selected = true;
167
-
168
- // 修改状态加入仓库
169
- file.status = "success";
170
- this.fileList.push(file);
171
- this.selectedCount++;
172
- })
173
- .catch((err) => {
174
- if (err.response.data.code) {
175
- this.$message.error(`[${err.response.data.code}] ${err.response.data.message}`);
176
- } else {
177
- this.$message.error("请求异常");
178
- }
153
+ return;
154
+ }
155
+ // 提醒
156
+ this.$message({
157
+ message: "上传成功",
158
+ type: "success",
179
159
  });
160
+
161
+ // 修改path
162
+ file.url = res.data.data && res.data.data[0];
163
+
164
+ // 额外赋值
165
+ file.is_img = is_img;
166
+ file.selected = true;
167
+
168
+ // 修改状态加入仓库
169
+ file.status = "success";
170
+ this.fileList.push(file);
171
+ this.selectedCount++;
172
+ })
173
+ .catch((err) => {
174
+ if (err.response.data.code) {
175
+ this.$message.error(`[${err.response.data.code}] ${err.response.data.message}`);
176
+ } else {
177
+ this.$message.error("请求异常");
178
+ }
179
+ });
180
+ }
181
+ },
182
+ select: function (file) {
183
+ if (file.status == "success") {
184
+ this.$set(file, "selected", !file.selected);
185
+ file.selected ? this.selectedCount++ : this.selectedCount--;
186
+ }
187
+ },
188
+ buildHTML: function () {
189
+ let list = [];
190
+ this.fileList.forEach((file) => {
191
+ if (file.selected) {
192
+ file.is_img ? list.push(`<img src="${file.url}" />`) : list.push(`<a target="_blank" href="${file.url}">${file.name}</a>`);
180
193
  }
181
- },
182
- select: function(file) {
183
- if (file.status == "success") {
184
- this.$set(file, "selected", !file.selected);
185
- file.selected ? this.selectedCount++ : this.selectedCount--;
186
- }
187
- },
188
- buildHTML: function() {
189
- let list = [];
190
- this.fileList.forEach((file) => {
191
- if (file.selected) {
192
- file.is_img ? list.push(`<img src="${file.url}" />`) : list.push(`<a target="_blank" href="${file.url}">${file.name}</a>`);
193
- }
194
- });
195
- this.insertList = list.join(" \n");
196
- return this.insertList;
197
- },
198
- insert: function() {
199
- // 关闭窗口
200
- this.dialogVisible = false;
194
+ });
195
+ this.insertList = list.join(" \n");
196
+ return this.insertList;
197
+ },
198
+ insert: function () {
199
+ // 关闭窗口
200
+ this.dialogVisible = false;
201
201
 
202
- //为空不执行插入
203
- if (!this.selectedCount) return;
202
+ //为空不执行插入
203
+ if (!this.selectedCount) return;
204
204
 
205
- // 传递值
206
- this.$emit("insert", {
207
- list: this.fileList,
208
- html: this.buildHTML(),
209
- });
205
+ // 传递值
206
+ this.$emit("insert", {
207
+ list: this.fileList,
208
+ html: this.buildHTML(),
209
+ });
210
210
 
211
- //移除所有选择状态
212
- this.resetSelectStatus();
213
- },
214
- resetSelectStatus: function() {
215
- this.fileList.forEach((file, i) => {
216
- this.$set(this.fileList[i], "selected", false);
217
- });
218
- this.selectedCount = 0;
219
- },
220
- clear: function() {
221
- this.$refs.uploadbox.clearFiles();
222
- this.fileList = [];
223
- },
224
- removeFile: function(fileList, uid) {
225
- fileList.forEach((file, i) => {
226
- if (file.uid == uid) {
227
- fileList.splice(i, 1);
228
- }
229
- });
230
- },
211
+ //移除所有选择状态
212
+ this.resetSelectStatus();
213
+ },
214
+ resetSelectStatus: function () {
215
+ this.fileList.forEach((file, i) => {
216
+ this.$set(this.fileList[i], "selected", false);
217
+ });
218
+ this.selectedCount = 0;
219
+ },
220
+ clear: function () {
221
+ this.$refs.uploadbox.clearFiles();
222
+ this.fileList = [];
223
+ },
224
+ removeFile: function (fileList, uid) {
225
+ fileList.forEach((file, i) => {
226
+ if (file.uid == uid) {
227
+ fileList.splice(i, 1);
228
+ }
229
+ });
231
230
  },
232
- mounted: function() {},
233
- components: {},
234
- };
231
+ },
232
+ mounted: function () {},
233
+ components: {},
234
+ };
235
235
  </script>
236
236
 
237
237
  <style lang="less">
238
- @import "../assets/css/upload.less";
238
+ @import "../assets/css/upload.less";
239
239
  </style>