张含笑
2025-11-06 8ba2dc1126a4abdf96e2d92b365a3295c3b15025
feat:头像
1 files modified
58 ■■■■ changed files
src/subPackages/userDetail/infos/index.vue 58 ●●●● patch | view | raw | blame | history
src/subPackages/userDetail/infos/index.vue
@@ -34,13 +34,18 @@
</template>
<script setup>
    import {getEnvObj, getWebViewUrl} from "@/utils/index.js";
    import {
        getEnvObj,
        getWebViewUrl
    } from "@/utils/index.js";
    import {
        getUserInfo,
        updateInfo,
        updatePassword
    } from '@/api/user/index.js';
    import {useUserStore} from "@/store/index.js";
    import {
        useUserStore
    } from "@/store/index.js";
    const userInfo = ref({
        id: '',
        avatar: '',
@@ -100,9 +105,16 @@
        getUserInfoData();
    };
    const {VITE_API_BASE_URL} = getEnvObj()
    const {
        VITE_API_BASE_URL
    } = getEnvObj()
    function uploadUtil(options) {
      const {formData, file, url} = options
        const {
            formData,
            filePath,
            url
        } = options;
     
      return new Promise((resolve, reject) => {
        let accessToken = useUserStore()?.$state?.userInfo?.access_token;
@@ -110,8 +122,10 @@
        uni.uploadFile({
          url: `${VITE_API_BASE_URL}${url}`,
          name: 'file',
          header: {'Blade-Auth': 'bearer ' + accessToken},
          file,
                header: {
                    'Blade-Auth': 'bearer ' + accessToken
                },
                filePath: filePath,
          formData,
          success: (res) => {
            const resData = JSON.parse(res.data)
@@ -133,7 +147,29 @@
      uni.chooseImage({
        count: 1, 
        success: (res) => {
          const tempFilePaths = res.tempFiles[0];
                //     const tempFilePaths = res.tempFiles[0];
                //  const a = tempFilePaths.name? tempFilePaths.name : tempFilePaths.path
                const tempFile = res.tempFiles[0]; // 获取文件对象
                // 1. 获取文件路径(兼容不同端的路径字段)
                const filePath = tempFile.path || tempFile.tempFilePath;
                if (!filePath) {
                    uni.showToast({
                        title: '获取文件路径失败',
                        icon: 'none'
                    });
                    return;
                }
                let fileName = tempFile.name;
                if (!fileName) {
                    const pathWithoutProtocol = filePath.replace(/^file:\/\//, '');
                    fileName = pathWithoutProtocol.split('/').pop() || 'unknown.png';
                }
                console.log('filePath', filePath)
          // 显示加载中
          uni.showLoading({
            title: '上传中...'
@@ -141,9 +177,9 @@
         
          // 上传文件
          uploadUtil({
            file: tempFilePaths,
                    filePath: filePath,
            formData: {
              fileName: tempFilePaths.name,
                        fileName: fileName,
              sn: 'avatar_upload' 
            },
            url: '/blade-resource/oss/endpoint/put-file'
@@ -221,9 +257,11 @@
        background: #FFFFFF;
        border-radius: 12rpx;
        box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
        .detailCon {
            padding: 0 24rpx;
        }
        .orderRow {
            display: flex;
            justify-content: space-between;
@@ -239,6 +277,7 @@
                color: #222324;
                white-space: nowrap;
            }
            ::v-deep .u-input {
                border: none !important;
                background: transparent !important;
@@ -261,6 +300,7 @@
        position: absolute;
        bottom:150rpx;
    }
    .u-button:first-child{
        margin-right: 30rpx;
    }