Skip to content

Commit

Permalink
feature: add 压缩图片
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Apr 3, 2022
1 parent f4131ae commit 3b51555
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@
},
"dependencies": {
"@element-plus/icons-vue": "^1.1.4",
"@logicflow/core": "^1.1.7",
"@logicflow/extension": "^1.1.7",
"@logicflow/core": "^1.1.11",
"@logicflow/extension": "^1.1.11",
"axios": "^0.26.1",
"echarts": "^5.3.1",
"element-plus": "^2.1.5",
"echarts": "^5.3.2",
"element-plus": "^2.1.8",
"es6-promise": "^4.2.8",
"i18next": "^21.6.14",
"image-conversion": "^2.1.1",
"intro.js": "^5.0.0",
"lodash-es": "^4.17.21",
"marked": "^4.0.12",
"mockjs": "^1.1.0",
"pinia": "^2.0.12",
"pinia": "^2.0.13",
"sortablejs": "^1.15.0",
"vue": "^3.2.31",
"vue-i18n": "^9.1.9",
Expand All @@ -56,10 +57,10 @@
"@types/marked": "^4.0.3",
"@types/node": "^17.0.23",
"@types/sortablejs": "^1.10.7",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"@vitejs/plugin-vue": "^2.2.4",
"@vitejs/plugin-vue-jsx": "^1.3.8",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@vitejs/plugin-vue": "^2.3.1",
"@vitejs/plugin-vue-jsx": "^1.3.9",
"@vue/compiler-sfc": "^3.2.31",
"@zougt/vite-plugin-theme-preprocessor": "^1.4.4",
"autoprefixer": "^10.4.4",
Expand All @@ -79,18 +80,18 @@
"lint-staged": "^12.3.7",
"postcss-html": "^1.3.0",
"postcss-import": "^14.1.0",
"prettier": "2.6.1",
"prettier": "2.6.2",
"pretty-quick": "^3.1.3",
"sass": "^1.49.9",
"sass": "^1.49.11",
"stylelint": "^14.6.1",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recess-order": "^3.0.0",
"stylelint-config-standard": "^25.0.0",
"stylelint-order": "^5.0.0",
"stylelint-scss": "^4.2.0",
"typescript": "^4.6.3",
"unplugin-element-plus": "^0.3.2",
"vite": "^2.8.6",
"unplugin-element-plus": "^0.3.4",
"vite": "^2.9.1",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-linter": "^1.2.0",
"vite-plugin-mock": "^2.9.6",
Expand Down
13 changes: 13 additions & 0 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { compress } from 'image-conversion';

// 文件流转化为base64
export function fileToBase64(file: File) {
return new Promise(function (resolve) {
Expand Down Expand Up @@ -76,3 +78,14 @@ export function pasteImage() {
}
});
}

//压缩图片
export function beforeAvatarUpload(file: File): Promise<Blob> {
return new Promise((resolve) => {
// 压缩到100KB,这里的100就是要压缩的大小,可自定义
compress(file, 0.4).then((res) => {
console.log(res);
resolve(res);
});
});
}

0 comments on commit 3b51555

Please sign in to comment.