|
@@ -101,7 +101,8 @@
|
|
|
</div>
|
|
|
|
|
|
<Loading :visible="overlay"></Loading>
|
|
|
- <!-- <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false"></ImgCropper> -->
|
|
|
+ <!-- 图片裁剪 -->
|
|
|
+ <ImgCropper :visible="isShowCopper" :image="selectPic" :cropBoxResizable="true" @submit="handleHideCopper" :aspectRatio="1 / 1" @close="isShowCopper = false, selectPic = ''"></ImgCropper>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
@@ -145,55 +146,39 @@ const openFileInput = () => {
|
|
|
}
|
|
|
|
|
|
// 上传头像
|
|
|
-// const selectPic = ref('')
|
|
|
-// const isShowCopper = ref(false)
|
|
|
-// const handleUploadFile = async (e) => {
|
|
|
-// const file = e.target.files[0]
|
|
|
-// const reader = new FileReader()
|
|
|
-// reader.readAsDataURL(file)
|
|
|
-// reader.onload = () => {
|
|
|
-// selectPic.value = String(reader.result)
|
|
|
-// isShowCopper.value = true
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
+const selectPic = ref('')
|
|
|
+const isShowCopper = ref(false)
|
|
|
const handleUploadFile = async (e) => {
|
|
|
const file = e.target.files[0]
|
|
|
- if (!file) return
|
|
|
- overlay.value = true
|
|
|
- const formData = new FormData()
|
|
|
- formData.append('file', file)
|
|
|
- const { data } = await uploadFile(formData)
|
|
|
- if (!data) return overlay.value = false
|
|
|
- await updatePersonAvatar(data)
|
|
|
- setTimeout(async () => {
|
|
|
- await userStore.getUserBaseInfos(baseInfo.value.userId)
|
|
|
- getBasicInfo()
|
|
|
- overlay.value = false
|
|
|
- Snackbar.success(t('common.uploadSucMsg'))
|
|
|
- }, 1000)
|
|
|
+ const reader = new FileReader()
|
|
|
+ reader.readAsDataURL(file)
|
|
|
+ reader.onload = () => {
|
|
|
+ selectPic.value = String(reader.result)
|
|
|
+ isShowCopper.value = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// const handleHideCopper = (data) => {
|
|
|
-// isShowCopper.value = false
|
|
|
-// if (data) {
|
|
|
-// const { file } = data
|
|
|
-// if (!file) return
|
|
|
-// const formData = new FormData()
|
|
|
-// formData.append('file', file)
|
|
|
-// overlay.value = true
|
|
|
-// uploadFile(formData).then(async ({data}) => {
|
|
|
-// if (!data) return
|
|
|
-// await updatePersonAvatar(data)
|
|
|
-// setTimeout(async () => {
|
|
|
-// await userStore.getUserBaseInfos(baseInfo.value.userId)
|
|
|
-// getBasicInfo()
|
|
|
-// overlay.value = false
|
|
|
-// Snackbar.success(t('common.uploadSucMsg'))
|
|
|
-// }, 1000)
|
|
|
-// })
|
|
|
-// }
|
|
|
-// }
|
|
|
+// 图片裁剪
|
|
|
+const handleHideCopper = (data) => {
|
|
|
+ isShowCopper.value = false
|
|
|
+ if (data) {
|
|
|
+ const { file } = data
|
|
|
+ if (!file) return
|
|
|
+ const formData = new FormData()
|
|
|
+ formData.append('file', file)
|
|
|
+ overlay.value = true
|
|
|
+ uploadFile(formData).then(async ({data}) => {
|
|
|
+ if (!data) return
|
|
|
+ await updatePersonAvatar(data)
|
|
|
+ setTimeout(async () => {
|
|
|
+ await userStore.getUserBaseInfos(baseInfo.value.userId)
|
|
|
+ getBasicInfo()
|
|
|
+ overlay.value = false
|
|
|
+ Snackbar.success(t('common.uploadSucMsg'))
|
|
|
+ }, 1000)
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
const items = ref({
|
|
|
options: [
|