diff --git a/components/avatar_uploader/avatar_cropper.vue b/components/avatar_uploader/avatar_cropper.vue new file mode 100644 index 0000000..b7829d8 --- /dev/null +++ b/components/avatar_uploader/avatar_cropper.vue @@ -0,0 +1,506 @@ + + + + + diff --git a/pages.json b/pages.json index 5b042c5..decdad5 100644 --- a/pages.json +++ b/pages.json @@ -467,6 +467,18 @@ "group": "通用" } }, + { + "path": "avatarCrop", + "style": { + "navigationBarTitleText": "裁剪头像", + "navigationStyle": "custom" + }, + "meta": { + "sync": true, + "title": "裁剪头像", + "group": "通用" + } + }, { "path": "richtext", "style": { diff --git a/pages/public/avatarCrop.vue b/pages/public/avatarCrop.vue new file mode 100644 index 0000000..964b7b9 --- /dev/null +++ b/pages/public/avatarCrop.vue @@ -0,0 +1,124 @@ + + + + + diff --git a/pages/public/setting.vue b/pages/public/setting.vue index 5ed9086..beb666d 100644 --- a/pages/public/setting.vue +++ b/pages/public/setting.vue @@ -30,7 +30,6 @@ import { ref, computed, reactive, onMounted } from 'vue'; import AuthUtil from '@/sheep/api/member/auth'; import card_list from '@/components/card_list/card_list.vue'; - import { baseUrl } from '@/sheep/config'; import UserApi from '@/sheep/api/member/user'; const appInfo = computed(() => sheep.$store('app').info); const isLogin = computed(() => sheep.$store('user').isLogin); @@ -178,35 +177,27 @@ const upImg = () => { uni.chooseImage({ - count: 1, //默认9 - sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 - success: function (res) { - const tempFilePaths = res.tempFilePaths; - const tempFiles = res.tempFiles; - let resSize = tempFiles[0].size; - if (resSize > 1048576) { + count: 1, + sizeType: ['original', 'compressed'], + success: (res) => { + const filePath = res?.tempFilePaths?.[0] || ''; + const size = res?.tempFiles?.[0]?.size; + if (typeof size === 'number' && size > 1048576) { uni.showToast({ title: '上传图片大小不能超过1MB', - icon: 'error', + icon: 'none', }); return; } - const token = uni.getStorageSync('token') ? uni.getStorageSync('token') : undefined; - let tenant_id = uni.getStorageSync('tenant-id'); - uni.uploadFile({ - url: baseUrl + '/app-api/infra/file/upload', //仅为示例,非真实的接口地址 - filePath: tempFilePaths[0], - name: 'file', - formData: { - directory: 'head', - 'tenant-id': tenant_id, - token: token, - }, - header: {}, - success: (uploadFileRes) => { - let url = JSON.parse(uploadFileRes.data).data; - upData({ - avatar: url, + if (!filePath) return; + uni.navigateTo({ + url: `/pages/public/avatarCrop?src=${encodeURIComponent(filePath)}`, + success: (navRes) => { + const eventChannel = navRes?.eventChannel; + if (!eventChannel) return; + eventChannel.on('success', ({ url }) => { + if (!url) return; + upData({ avatar: url }); }); }, });