diff --git a/src/assets/scripts/uploadImageFile.js b/src/assets/scripts/uploadImageFile.js
deleted file mode 100644
index 081b4b1..0000000
--- a/src/assets/scripts/uploadImageFile.js
+++ /dev/null
@@ -1,35 +0,0 @@
-import fileApi from "../../api/file";
-
-export function uploadImgFile(file) {
- return new Promise((resolve, reject) => {
- const checkImageResult = isImageIllegal(file);
- if (checkImageResult) {
- reject(checkImageResult);
- return;
- }
-
- const base64Reader = new FileReader();
- base64Reader.readAsDataURL(file);
- base64Reader.onload = function () {
- const base64Content = this.result.split(",").pop();
- fileApi
- .fileUpload(base64Content, file)
- .then((res) => {
- resolve(res);
- })
- .catch((err) => {
- reject(err);
- });
- };
- });
-}
-
-export function isImageIllegal(file) {
- if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name)) {
- return "请上传 JPG/PNG/GIF 格式的图片";
- }
- if (file.size > 5 * 1024 * 1024) {
- return "由于公众号限制,图片大小不能超过 5.0M";
- }
- return false;
-}
diff --git a/src/assets/scripts/util.js b/src/assets/scripts/util.js
index 7d5a5fe..d1d974f 100644
--- a/src/assets/scripts/util.js
+++ b/src/assets/scripts/util.js
@@ -263,3 +263,33 @@ export function createTable({ data, rows, cols }) {
return table;
}
+
+export const toBase64 = (file) =>
+ new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.readAsDataURL(file);
+ reader.onload = () => resolve(reader.result.split(",").pop());
+ reader.onerror = (error) => reject(error);
+ });
+
+export function checkImage(file) {
+ // check filename suffix
+ const isValidSuffix = /\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(file.name);
+ if (!isValidSuffix) {
+ return {
+ ok: false,
+ msg: "请上传 JPG/PNG/GIF 格式的图片",
+ };
+ }
+
+ // check file size
+ const maxSize = 5;
+ const isLt5M = file.size / 1024 / 1024 <= maxSize;
+ if (!isLt5M) {
+ return {
+ ok: false,
+ msg: `由于公众号限制,图片大小不能超过 ${maxSize}M`,
+ };
+ }
+ return { ok: true };
+}
diff --git a/src/components/CodemirrorEditor/header.vue b/src/components/CodemirrorEditor/header.vue
index 27b62e1..b73844b 100644
--- a/src/components/CodemirrorEditor/header.vue
+++ b/src/components/CodemirrorEditor/header.vue
@@ -48,7 +48,7 @@
diff --git a/src/components/CodemirrorEditor/rightClickMenu.vue b/src/components/CodemirrorEditor/rightClickMenu.vue
index 46c8923..00d9e08 100644
--- a/src/components/CodemirrorEditor/rightClickMenu.vue
+++ b/src/components/CodemirrorEditor/rightClickMenu.vue
@@ -19,7 +19,6 @@