上传头像裁剪
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
<div class="label">{{ $t('Home.logoutDevice') }}</div>
|
||||
<button class="logout-btn" @click="logout">{{ $t('Home.logout') }}</button>
|
||||
</div>
|
||||
<clip-dialog ref="clipDialogRef" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -41,6 +42,8 @@
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { uploadImage } from '@/api/upload'
|
||||
import { UpdateUserAvatar, getAvatarLimit } from '@/api/user'
|
||||
import clipDialog from '@/components/clipDialog.vue'
|
||||
import { fileToBase64, base64Tofile } from '../../../components/Canvas/tools/tools'
|
||||
const router = useRouter()
|
||||
const { locale } = useI18n()
|
||||
const userInfoStore = useUserInfoStore()
|
||||
@@ -50,6 +53,7 @@
|
||||
{ label: '中文', value: 'CHINESE_SIMPLIFIED' }
|
||||
])
|
||||
const remainingNum = ref(0)
|
||||
const clipDialogRef = ref<typeof clipDialog>()
|
||||
const changeLang = (value: string) => {
|
||||
locale.value = value
|
||||
localStorage.setItem('language', value)
|
||||
@@ -72,13 +76,17 @@
|
||||
const input = document.createElement('input')
|
||||
input.type = 'file'
|
||||
input.accept = 'image/png, image/jpeg, image/jpg'
|
||||
input.addEventListener('change', (e) => {
|
||||
input.addEventListener('change', async (e) => {
|
||||
const file = e.target.files[0]
|
||||
const formData = new FormData()
|
||||
formData.append('avatar', file)
|
||||
UpdateUserAvatar(formData).then((res) => {
|
||||
userInfoStore.updateUserInfo({avatar: res})
|
||||
getAvatarLimitNum()
|
||||
let base64Img = await fileToBase64(file)
|
||||
clipDialogRef.value?.open(base64Img).then((base64: string)=>{
|
||||
const fileData = base64Tofile(base64,file.name)
|
||||
const formData = new FormData()
|
||||
formData.append('avatar', fileData)
|
||||
UpdateUserAvatar(formData).then((res) => {
|
||||
userInfoStore.updateUserInfo({avatar: res})
|
||||
getAvatarLimitNum()
|
||||
})
|
||||
})
|
||||
})
|
||||
input.click()
|
||||
|
||||
Reference in New Issue
Block a user