更新记录
1.0.0(2024-01-06)
下载此版本
图片裁切1.0
平台兼容性
uni-app
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
× |
√ |
- |
- |
- |
× |
- |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
√ |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
其他
<template>
<view>
<image v-if="avatar" class="avatar" :src="avatar" />
<button v-else @click="chooseAvatar">选择图片</button>
<img-crop
v-if="chooseAvatarUrl"
:url="chooseAvatarUrl"
:width="200"
:height="200"
@cancel="chooseAvatarUrl = ''"
@success="updateAvatar"
/>
</view>
</template>
<script lang="ts" setup>
import ImgCrop from '@/components/img-crop/img-crop.vue';
import { ref } from 'vue';
const avatar = ref('');
const chooseAvatarUrl = ref('');
async function chooseAvatar() {
// #ifdef MP-WEIXIN
uni.chooseMedia({
count: 1,
mediaType: ['image'],
success({ tempFiles }) {
chooseAvatarUrl.value = tempFiles[0].tempFilePath;
},
});
// #endif
// #ifndef MP-WEIXIN
const { tempFilePaths } = await uni.chooseImage({ count: 1 });
chooseAvatarUrl.value = tempFilePaths[0];
// #endif
}
async function updateAvatar(filePath: string) {
chooseAvatarUrl.value = '';
const { data } = await uni.uploadFile({
url: `${import.meta.env.VITE_BASE_URL}/api/resources/upload`,
header: {
Authorization: `Bearer Token`,
},
formData: { type: 'avatar' },
name: 'file',
filePath,
});
const res = JSON.parse(data);
avatar.value = res.data.url;
}
</script>