From 91abae8898d5d4b301a236e5f9c6a3f78fc69900 Mon Sep 17 00:00:00 2001 From: xingyu Date: Wed, 21 Dec 2022 16:10:28 +0800 Subject: [PATCH] refactor: cropper --- yudao-dependencies/pom.xml | 2 +- yudao-ui-admin-vue3/package.json | 6 +- yudao-ui-admin-vue3/pnpm-lock.yaml | 87 +++--- .../src/api/system/user/profile.ts | 2 +- .../src/components/Cropper/index.ts | 4 + .../components/Cropper/src/CopperModal.vue | 256 ++++++++++++++++++ .../src/components/Cropper/src/Cropper.vue | 190 +++++++++++++ .../components/Cropper/src/CropperAvatar.vue | 125 +++++++++ .../src/components/Cropper/src/types.ts | 8 + yudao-ui-admin-vue3/src/config/axios/index.ts | 2 +- yudao-ui-admin-vue3/src/locales/en.ts | 14 + yudao-ui-admin-vue3/src/locales/zh-CN.ts | 14 + .../views/Profile/components/UserAvatar.vue | 252 ++--------------- 13 files changed, 686 insertions(+), 276 deletions(-) create mode 100644 yudao-ui-admin-vue3/src/components/Cropper/index.ts create mode 100644 yudao-ui-admin-vue3/src/components/Cropper/src/CopperModal.vue create mode 100644 yudao-ui-admin-vue3/src/components/Cropper/src/Cropper.vue create mode 100644 yudao-ui-admin-vue3/src/components/Cropper/src/CropperAvatar.vue create mode 100644 yudao-ui-admin-vue3/src/components/Cropper/src/types.ts diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index ca662cb40c..db4f5af63d 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -24,7 +24,7 @@ 1.2.15 3.5.2 - 3.5.2 + 3.5.3 3.6.0 3.18.0 diff --git a/yudao-ui-admin-vue3/package.json b/yudao-ui-admin-vue3/package.json index b96f1a52a6..6b551fa35f 100644 --- a/yudao-ui-admin-vue3/package.json +++ b/yudao-ui-admin-vue3/package.json @@ -25,12 +25,13 @@ }, "dependencies": { "@iconify/iconify": "^3.0.1", - "@vueuse/core": "^9.7.0", + "@vueuse/core": "^9.8.2", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.10", "@zxcvbn-ts/core": "^2.1.0", "animate.css": "^4.1.1", "axios": "^1.2.1", + "cropperjs": "^1.5.13", "crypto-js": "^4.1.1", "dayjs": "^1.11.7", "echarts": "^5.4.1", @@ -46,7 +47,6 @@ "qs": "^6.11.0", "url": "^0.11.0", "vue": "3.2.45", - "vue-cropper": "^1.0.3", "vue-i18n": "9.2.2", "vue-router": "^4.1.6", "vue-types": "^5.0.1", @@ -104,7 +104,7 @@ "vite-plugin-svg-icons": "^2.0.1", "vite-plugin-vue-setup-extend": "^0.4.0", "vite-plugin-windicss": "^1.8.10", - "vue-tsc": "^1.0.14", + "vue-tsc": "^1.0.16", "windicss": "^3.5.6" }, "engines": { diff --git a/yudao-ui-admin-vue3/pnpm-lock.yaml b/yudao-ui-admin-vue3/pnpm-lock.yaml index 498d41f818..df512f52f6 100644 --- a/yudao-ui-admin-vue3/pnpm-lock.yaml +++ b/yudao-ui-admin-vue3/pnpm-lock.yaml @@ -18,7 +18,7 @@ specifiers: '@vitejs/plugin-legacy': ^3.0.1 '@vitejs/plugin-vue': ^4.0.0 '@vitejs/plugin-vue-jsx': ^3.0.0 - '@vueuse/core': ^9.7.0 + '@vueuse/core': ^9.8.2 '@wangeditor/editor': ^5.1.23 '@wangeditor/editor-for-vue': ^5.1.10 '@zxcvbn-ts/core': ^2.1.0 @@ -26,6 +26,7 @@ specifiers: autoprefixer: ^10.4.13 axios: ^1.2.1 consola: ^2.15.3 + cropperjs: ^1.5.13 crypto-js: ^4.1.1 dayjs: ^1.11.7 echarts: ^5.4.1 @@ -72,10 +73,9 @@ specifiers: vite-plugin-vue-setup-extend: ^0.4.0 vite-plugin-windicss: ^1.8.10 vue: 3.2.45 - vue-cropper: ^1.0.3 vue-i18n: 9.2.2 vue-router: ^4.1.6 - vue-tsc: ^1.0.14 + vue-tsc: ^1.0.16 vue-types: ^5.0.1 vxe-table: ^4.3.7 web-storage-cache: ^1.1.1 @@ -84,12 +84,13 @@ specifiers: dependencies: '@iconify/iconify': 3.0.1 - '@vueuse/core': 9.7.0_vue@3.2.45 + '@vueuse/core': 9.8.2_vue@3.2.45 '@wangeditor/editor': 5.1.23 '@wangeditor/editor-for-vue': 5.1.12_3apfu3xbp6awzuex7ed3sbrv6y '@zxcvbn-ts/core': 2.1.0 animate.css: 4.1.1 axios: 1.2.1 + cropperjs: 1.5.13 crypto-js: 4.1.1 dayjs: 1.11.7 echarts: registry.npmmirror.com/echarts/5.4.1 @@ -105,7 +106,6 @@ dependencies: qs: 6.11.0 url: 0.11.0 vue: 3.2.45 - vue-cropper: 1.0.5 vue-i18n: 9.2.2_vue@3.2.45 vue-router: 4.1.6_vue@3.2.45 vue-types: 5.0.1_vue@3.2.45 @@ -163,7 +163,7 @@ devDependencies: vite-plugin-svg-icons: 2.0.1_vite@4.0.2 vite-plugin-vue-setup-extend: 0.4.0_vite@4.0.2 vite-plugin-windicss: registry.npmmirror.com/vite-plugin-windicss/1.8.10_vite@4.0.2 - vue-tsc: 1.0.14_typescript@4.9.4 + vue-tsc: 1.0.16_typescript@4.9.4 windicss: 3.5.6 packages: @@ -1079,44 +1079,44 @@ packages: nanoid: registry.npmmirror.com/nanoid/3.3.4 dev: false - /@volar/language-core/1.0.14: - resolution: {integrity: sha512-j1tMQgw0qCV2amM4qDJNG/zc0yj3ay8HoWNt05IaiCPsULtSSpF/9+F6Izvn0DF7nWOd6MUHTxaQAeZwLfr56Q==} + /@volar/language-core/1.0.16: + resolution: {integrity: sha512-IGnOxWTs4DZ81TDcmxBAkCBxs97hUblwcjpBsTx/pOGGaSSDQRJPn0wL8NYTybEObU0i7lhEpKZ+0vJfdIy1Kg==} dependencies: - '@volar/source-map': 1.0.14 + '@volar/source-map': 1.0.16 '@vue/reactivity': 3.2.45 muggle-string: 0.1.0 dev: true - /@volar/source-map/1.0.14: - resolution: {integrity: sha512-8pHCbEWHWaSDGb/FM9zRIW1lY1OAo16MENVSQGCgTwz7PWf3Gw6WW3TFVKCtzaFhLjPH0i5e9hALy7vBPbSHoA==} + /@volar/source-map/1.0.16: + resolution: {integrity: sha512-PKjzmQcg8QOGC/1V9tmGh2jcy6bKLhkW5bGidElSr83iDbCzLvldt2/La/QlDxaRCHYLT0MeyuGJBZIChB1dYQ==} dependencies: muggle-string: 0.1.0 dev: true - /@volar/typescript/1.0.14: - resolution: {integrity: sha512-67qcjjz7KGFhMCG9EKMA9qJK3BRGQecO4dGyAKfMfClZ/PaVoKfDvJvYo89McGTQ8SeczD48I9TPnaJM0zK8JQ==} + /@volar/typescript/1.0.16: + resolution: {integrity: sha512-Yov+n4oO3iYnuMt9QJAFpJabfTRCzc7KvjlAwBaSuZy+Gc/f9611MgtqAh5/SIGmltFN8dXn1Ijno8ro8I4lyw==} dependencies: - '@volar/language-core': 1.0.14 + '@volar/language-core': 1.0.16 dev: true - /@volar/vue-language-core/1.0.14: - resolution: {integrity: sha512-grJ4dQ7c/suZmBBmZtw2O2XeDX+rtgpdBtHxMug1NMPRDxj5EZ9WGphWtGnMQj8RyVgpz9ByvV5GbQjk4/wfBw==} + /@volar/vue-language-core/1.0.16: + resolution: {integrity: sha512-sQ/aW1Vuiyy4OQuh2lthyYicruM3qh9VSk/aDh8/bFvM8GoohHZqVpMN3LYldEJ9eT/rN6u4xmYP54vc/EjX4Q==} dependencies: - '@volar/language-core': 1.0.14 - '@volar/source-map': 1.0.14 + '@volar/language-core': 1.0.16 + '@volar/source-map': 1.0.16 '@vue/compiler-dom': 3.2.45 '@vue/compiler-sfc': 3.2.45 '@vue/reactivity': 3.2.45 '@vue/shared': 3.2.45 - minimatch: 5.1.0 + minimatch: 5.1.2 vue-template-compiler: 2.7.14 dev: true - /@volar/vue-typescript/1.0.14: - resolution: {integrity: sha512-2P0QeGLLY05fDTu8GqY8SR2+jldXRTrkQdD2Nc0sVOjMJ7j3RYYY0wJyZ9hCBDuxV4Micc6jdB8nKS0yxQgNvA==} + /@volar/vue-typescript/1.0.16: + resolution: {integrity: sha512-M018Ulg/o2FVktAdlr5b/z4K69bYzekxNUA1o39y5Ur6CObc/o+5eDCCS7gIYijWnx9iNKkSQpWWWblJFv7kHQ==} dependencies: - '@volar/typescript': 1.0.14 - '@volar/vue-language-core': 1.0.14 + '@volar/typescript': 1.0.16 + '@volar/vue-language-core': 1.0.16 dev: true /@vue/compiler-core/3.2.45: @@ -1196,24 +1196,24 @@ packages: /@vue/shared/3.2.45: resolution: {integrity: sha512-Ewzq5Yhimg7pSztDV+RH1UDKBzmtqieXQlpTVm2AwraoRL/Rks96mvd8Vgi7Lj+h+TH8dv7mXD3FRZR3TUvbSg==} - /@vueuse/core/9.7.0_vue@3.2.45: - resolution: {integrity: sha512-/AGY/t7jJPxCyRoVTygNKoroTiCvRaaZIW+yeSlBCnI7QRpQ9cvXNTdNaSl3GvSyFbn83+XwZwEZvI1OpQfeGw==} + /@vueuse/core/9.8.2_vue@3.2.45: + resolution: {integrity: sha512-aWiCmcYIpPt7xjuqYiceODEMHchDYthrJ4AqI+FXPZrR23PZOqdiktbUVyQl2kGlR3H4i9UJ/uimQrwhz9UouQ==} dependencies: '@types/web-bluetooth': 0.0.16 - '@vueuse/metadata': 9.7.0 - '@vueuse/shared': 9.7.0_vue@3.2.45 + '@vueuse/metadata': 9.8.2 + '@vueuse/shared': 9.8.2_vue@3.2.45 vue-demi: 0.13.11_vue@3.2.45 transitivePeerDependencies: - '@vue/composition-api' - vue dev: false - /@vueuse/metadata/9.7.0: - resolution: {integrity: sha512-M7WsAgw28FNtTH0bzsGuHEtJOPJqPpyeHS6PHq+8UesLgNjZ9waMAntiUrgUQlxt09M4i2lH7y9sRi0jkfeXGA==} + /@vueuse/metadata/9.8.2: + resolution: {integrity: sha512-N4E/BKS+9VsUeD4WLVRU1J2kCOLh+iikBcMtipFcTyL204132vDYHs27zLAVabJYGnhC0dIVGdhg9pbOZiY2TQ==} dev: false - /@vueuse/shared/9.7.0_vue@3.2.45: - resolution: {integrity: sha512-pwmt1y3TJ2s5KqWmkv9ZKEV59GwuZQZk8XLiU+hGswz0jej318ozbea9E4A/A50ksyM26swSFr7sZ9llNPsZHg==} + /@vueuse/shared/9.8.2_vue@3.2.45: + resolution: {integrity: sha512-ACjrPQzowd5dnabNJt9EoGVobco9/ENiA5qP53vjiuxndlJYuc/UegwhXC7KdQbPX4F45a50+45K3g1wNqOzmA==} dependencies: vue-demi: 0.13.11_vue@3.2.45 transitivePeerDependencies: @@ -2019,6 +2019,10 @@ packages: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} dev: true + /cropperjs/1.5.13: + resolution: {integrity: sha512-by7jKAo73y5/Do0K6sxdTKHgndY0NMjG2bEdgeJxycbcmHuCiMXqw8sxy5C5Y5WTOTcDGmbT7Sr5CgKOXR06OA==} + dev: false + /cross-spawn/7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} @@ -2319,7 +2323,7 @@ packages: '@popperjs/core': /@sxzz/popperjs-es/2.11.7 '@types/lodash': 4.14.189 '@types/lodash-es': 4.17.6 - '@vueuse/core': 9.7.0_vue@3.2.45 + '@vueuse/core': 9.8.2_vue@3.2.45 async-validator: 4.2.5 dayjs: 1.11.7 escape-html: 1.0.3 @@ -3831,6 +3835,13 @@ packages: brace-expansion: 2.0.1 dev: true + /minimatch/5.1.2: + resolution: {integrity: sha512-bNH9mmM9qsJ2X4r2Nat1B//1dJVcn3+iBLa3IgqJ7EbGaDNepL9QSHOxN4ng33s52VMMhhIfgCYDk3C4ZmlDAg==} + engines: {node: '>=10'} + dependencies: + brace-expansion: 2.0.1 + dev: true + /minimist-options/4.1.0: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} @@ -5461,10 +5472,6 @@ packages: fsevents: 2.3.2 dev: true - /vue-cropper/1.0.5: - resolution: {integrity: sha512-D4XXdqWmMWRLOIV9LIh7/mkH6OBOMQDFbRjwntkxmAtxOtwpC9U5ZZ6lSXw5F5cbd4g8znDjk6MuCwIL+fZSrA==} - dev: false - /vue-demi/0.13.11_vue@3.2.45: resolution: {integrity: sha512-IR8HoEEGM65YY3ZJYAjMlKygDQn25D5ajNFNoKh9RSDMQtlzCxtfQjdQgv9jjK+m3377SsJXY8ysq8kLCZL25A==} engines: {node: '>=12'} @@ -5526,14 +5533,14 @@ packages: he: 1.2.0 dev: true - /vue-tsc/1.0.14_typescript@4.9.4: - resolution: {integrity: sha512-HeqtyxMrSRUCnU5nxB0lQc3o7zirMppZ/V6HLL3l4FsObGepH3A3beNmNehpLQs0Gt7DkSWVi3CpVCFgrf+/sQ==} + /vue-tsc/1.0.16_typescript@4.9.4: + resolution: {integrity: sha512-yZaiJBbcKR1rSLhiF9KryAFH7R63po+N/invr2EAHGXxMzZksE5j1zyQKvrYiqK47ZHLAlCR+re/PHqWp/UzTg==} hasBin: true peerDependencies: typescript: '*' dependencies: - '@volar/vue-language-core': 1.0.14 - '@volar/vue-typescript': 1.0.14 + '@volar/vue-language-core': 1.0.16 + '@volar/vue-typescript': 1.0.16 typescript: 4.9.4 dev: true diff --git a/yudao-ui-admin-vue3/src/api/system/user/profile.ts b/yudao-ui-admin-vue3/src/api/system/user/profile.ts index eb3de0f5f7..e78424cc42 100644 --- a/yudao-ui-admin-vue3/src/api/system/user/profile.ts +++ b/yudao-ui-admin-vue3/src/api/system/user/profile.ts @@ -73,5 +73,5 @@ export const updateUserPwdApi = (oldPassword: string, newPassword: string) => { // 用户头像上传 export const uploadAvatarApi = (data) => { - return request.put({ url: '/system/user/profile/update-avatar', data }) + return request.upload({ url: '/system/user/profile/update-avatar', data: data }) } diff --git a/yudao-ui-admin-vue3/src/components/Cropper/index.ts b/yudao-ui-admin-vue3/src/components/Cropper/index.ts new file mode 100644 index 0000000000..8fcc61830c --- /dev/null +++ b/yudao-ui-admin-vue3/src/components/Cropper/index.ts @@ -0,0 +1,4 @@ +import CropperImage from './src/Cropper.vue' +import CropperAvatar from './src/CropperAvatar.vue' + +export { CropperImage, CropperAvatar } diff --git a/yudao-ui-admin-vue3/src/components/Cropper/src/CopperModal.vue b/yudao-ui-admin-vue3/src/components/Cropper/src/CopperModal.vue new file mode 100644 index 0000000000..a2c50f6b03 --- /dev/null +++ b/yudao-ui-admin-vue3/src/components/Cropper/src/CopperModal.vue @@ -0,0 +1,256 @@ + + + diff --git a/yudao-ui-admin-vue3/src/components/Cropper/src/Cropper.vue b/yudao-ui-admin-vue3/src/components/Cropper/src/Cropper.vue new file mode 100644 index 0000000000..2e38e06d06 --- /dev/null +++ b/yudao-ui-admin-vue3/src/components/Cropper/src/Cropper.vue @@ -0,0 +1,190 @@ + + + diff --git a/yudao-ui-admin-vue3/src/components/Cropper/src/CropperAvatar.vue b/yudao-ui-admin-vue3/src/components/Cropper/src/CropperAvatar.vue new file mode 100644 index 0000000000..a960afcfe1 --- /dev/null +++ b/yudao-ui-admin-vue3/src/components/Cropper/src/CropperAvatar.vue @@ -0,0 +1,125 @@ + + + diff --git a/yudao-ui-admin-vue3/src/components/Cropper/src/types.ts b/yudao-ui-admin-vue3/src/components/Cropper/src/types.ts new file mode 100644 index 0000000000..bcad3b4509 --- /dev/null +++ b/yudao-ui-admin-vue3/src/components/Cropper/src/types.ts @@ -0,0 +1,8 @@ +import type Cropper from 'cropperjs' + +export interface CropendResult { + imgBase64: string + imgInfo: Cropper.Data +} + +export type { Cropper } diff --git a/yudao-ui-admin-vue3/src/config/axios/index.ts b/yudao-ui-admin-vue3/src/config/axios/index.ts index c2a3344bf6..e6c6af8d77 100644 --- a/yudao-ui-admin-vue3/src/config/axios/index.ts +++ b/yudao-ui-admin-vue3/src/config/axios/index.ts @@ -44,7 +44,7 @@ export default { }, upload: async (option: any) => { option.headersType = 'multipart/form-data' - const res = await request({ method: 'PUT', ...option }) + const res = await request({ method: 'POST', ...option }) return res as unknown as Promise } } diff --git a/yudao-ui-admin-vue3/src/locales/en.ts b/yudao-ui-admin-vue3/src/locales/en.ts index af7a9314f9..9733d9c933 100644 --- a/yudao-ui-admin-vue3/src/locales/en.ts +++ b/yudao-ui-admin-vue3/src/locales/en.ts @@ -426,5 +426,19 @@ export default { cfPwdMsg: 'Please Enter Confirm Password', diffPwd: 'The Passwords Entered Twice No Match' } + }, + cropper: { + selectImage: 'Select Image', + uploadSuccess: 'Uploaded success!', + modalTitle: 'Avatar upload', + okText: 'Confirm and upload', + btn_reset: 'Reset', + btn_rotate_left: 'Counterclockwise rotation', + btn_rotate_right: 'Clockwise rotation', + btn_scale_x: 'Flip horizontal', + btn_scale_y: 'Flip vertical', + btn_zoom_in: 'Zoom in', + btn_zoom_out: 'Zoom out', + preview: 'Preivew' } } diff --git a/yudao-ui-admin-vue3/src/locales/zh-CN.ts b/yudao-ui-admin-vue3/src/locales/zh-CN.ts index 4c4c471548..71e2c3427a 100644 --- a/yudao-ui-admin-vue3/src/locales/zh-CN.ts +++ b/yudao-ui-admin-vue3/src/locales/zh-CN.ts @@ -419,5 +419,19 @@ export default { pwdRules: '长度在 6 到 20 个字符', diffPwd: '两次输入密码不一致' } + }, + cropper: { + selectImage: '选择图片', + uploadSuccess: '上传成功', + modalTitle: '头像上传', + okText: '确认并上传', + btn_reset: '重置', + btn_rotate_left: '逆时针旋转', + btn_rotate_right: '顺时针旋转', + btn_scale_x: '水平翻转', + btn_scale_y: '垂直翻转', + btn_zoom_in: '放大', + btn_zoom_out: '缩小', + preview: '预览' } } diff --git a/yudao-ui-admin-vue3/src/views/Profile/components/UserAvatar.vue b/yudao-ui-admin-vue3/src/views/Profile/components/UserAvatar.vue index 4e80faf217..e6c0a2895d 100644 --- a/yudao-ui-admin-vue3/src/views/Profile/components/UserAvatar.vue +++ b/yudao-ui-admin-vue3/src/views/Profile/components/UserAvatar.vue @@ -1,245 +1,37 @@ -