|
@@ -1,8 +1,12 @@
|
|
|
<template>
|
|
|
<view class="ezy-my-page">
|
|
|
- <img :src="userImg" alt="">
|
|
|
+ <view class="icon-title-navBar-box">
|
|
|
+ <view @click="handleBack" class="nav-bar-icon"></view>
|
|
|
+ <text class="nav-bar-title">更换头像</text>
|
|
|
+ </view>
|
|
|
+ <img style="height: 200px;width: 200px;;" :src="userImg" alt="">
|
|
|
|
|
|
- <view @click="openXiangce">相册</view>
|
|
|
+ <view @click="chooseImage">相册</view>
|
|
|
<view @click="handleBack">取消</view>
|
|
|
</view>
|
|
|
</template>
|
|
@@ -15,11 +19,12 @@
|
|
|
} from "@/utils/common";
|
|
|
import cacheManager from '@/utils/cacheManager.js';
|
|
|
import {
|
|
|
- myInfo,
|
|
|
+ getFilePolicy
|
|
|
} from '@/api/my.js'
|
|
|
import {
|
|
|
onLoad
|
|
|
} from '@dcloudio/uni-app';
|
|
|
+ import axios from 'axios';
|
|
|
import {
|
|
|
reactive,
|
|
|
ref
|
|
@@ -29,6 +34,89 @@
|
|
|
} from '@dcloudio/uni-app';
|
|
|
|
|
|
let userImg = ref(null);
|
|
|
+ let currentPlatform = ref(null);
|
|
|
+ const tempPath = ref('')
|
|
|
+ const checkAlbumPermission = async () => {
|
|
|
+ const status = await uni.getSetting()
|
|
|
+ if (!status.authSetting['scope.album']) {
|
|
|
+ await uni.authorize({
|
|
|
+ scope: 'scope.album'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const chooseImage = async () => {
|
|
|
+ try {
|
|
|
+ //await checkAlbumPermission()
|
|
|
+ uni.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ sourceType: ['album'], // 仅限相册选择:ml-citation{ref="1" data="citationList"}
|
|
|
+ success: (res) => {
|
|
|
+
|
|
|
+ uploadFile(res.tempFilePaths[0])
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('选择失败:', err)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (err) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '权限申请失败',
|
|
|
+ content: '请前往设置开启相册权限'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function uploadFile(filePath) {
|
|
|
+ const suffix = filePath.split('.').pop();
|
|
|
+ let req = {
|
|
|
+ prefix: 'resource/',
|
|
|
+ suffix: suffix
|
|
|
+ }
|
|
|
+ getFilePolicy(req).then(res => {
|
|
|
+ if (res.code === 0) {
|
|
|
+ const policyData = res.data;
|
|
|
+ console.log('policyData', policyData);
|
|
|
+ uni.uploadFile({
|
|
|
+ url: policyData.uploadUrl,
|
|
|
+ filePath: filePath,
|
|
|
+ name: 'file',
|
|
|
+ formData: {
|
|
|
+ key: policyData.key,
|
|
|
+ policy: policyData.policy,
|
|
|
+ OSSAccessKeyId: policyData.accessid,
|
|
|
+ signature: policyData.signature,
|
|
|
+ success_action_status: '200'
|
|
|
+ },
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ },
|
|
|
+ success(uploadRes) {
|
|
|
+ console.log('uploadRes', uploadRes);
|
|
|
+ if (uploadRes.statusCode === 200) {
|
|
|
+ userImg.value = `${policyData.downloadUrl}/${policyData.key}`;
|
|
|
+ uni.showToast({
|
|
|
+ title: '上传成功',
|
|
|
+ icon: 'success'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: '上传失败',
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ console.log('err', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
function handleBack() {
|
|
|
uni.redirectTo({
|
|
@@ -36,6 +124,11 @@
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ function openXiangce2() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
function openXiangce() {
|
|
|
|
|
|
}
|