Bläddra i källkod

Merge branch '2025北京诚祥' of https://gogs.mtavip.com/wangguoyu/uniProject into 2025北京诚祥

tanxue 2 månader sedan
förälder
incheckning
52314d0002
2 ändrade filer med 86 tillägg och 4 borttagningar
  1. 1 1
      pages.json
  2. 85 3
      pages/client/my/myInfo.vue

+ 1 - 1
pages.json

@@ -146,7 +146,7 @@
 			"path" : "pages/client/my/myInfo",
 			"style" : 
 			{
-				"navigationBarTitleText" : ""
+				"navigationStyle": "custom"
 			}
 		}
 	],

+ 85 - 3
pages/client/my/myInfo.vue

@@ -8,8 +8,8 @@
 		<!-- 头像 -->
 		<view>
 			<uni-file-picker limit="1" :del-icon="false" disable-preview :imageStyles="imageStyles" :auto-upload="false"
-				file-mediatype="image">选择</uni-file-picker>
-
+				@select="handleSelect" file-mediatype="image">选择</uni-file-picker>
+			<view>图片地址:{{data.icon}}</view>
 		</view>
 		<!-- 姓名 -->
 		<view></view>
@@ -25,7 +25,11 @@
 </template>
 
 <script setup>
-	import * as myApi from "@/api/my.js"
+	import * as myApi from "@/api/my.js";
+	import {
+		getAliyunPolicy
+	} from "@/api/jiazheng.js"
+
 	import {
 		ref,
 		reactive
@@ -58,6 +62,84 @@
 		initPage();
 	})
 
+	function handleSelect(e) {
+		doUploadImage(e.tempFilePaths[0])
+	}
+
+
+	function doUploadImage(filePath) {
+		const loading = uni.showLoading({
+			title: '上传中...',
+			mask: true
+		});
+
+		try {
+			const suffix = filePath.split('.').pop();
+			let req = {
+				prefix: 'resource/',
+				suffix: suffix
+			}
+
+			getAliyunPolicy(req).then(res => {
+				if (res.code == 0) {
+					const policyData = res.data;
+					const formData = {
+						key: policyData.key,
+						policy: policyData.policy,
+						OSSAccessKeyId: policyData.accessid,
+						signature: policyData.signature,
+						success_action_status: '200',
+						file: {
+							name: policyData.key,
+							uri: filePath
+						}
+					};
+					uni.uploadFile({
+						url: policyData.uploadUrl,
+						filePath: filePath,
+						name: 'file',
+						formData: formData,
+						header: {
+							'Content-Type': 'multipart/form-data'
+						},
+						success(uploadRes) {
+							if (uploadRes.statusCode === 200) {
+								data.icon = `${policyData.downloadUrl}/${policyData.key}`;
+								uni.showToast({
+									title: '上传成功',
+									icon: 'success'
+								});
+							} else {
+								uni.showToast({
+									title: '上传失败',
+								});
+							}
+							uni.hideLoading();
+						},
+						fail(err) {
+							uni.showToast({
+								title: '上传失败',
+							});
+							uni.hideLoading();
+						}
+					});
+
+				} else {
+					uni.showToast({
+						title: '获取凭证失败',
+					});
+					uni.hideLoading();
+				}
+			})
+		} catch (error) {
+			uni.showToast({
+				title: '上传失败',
+				icon: 'none'
+			});
+			uni.hideLoading();
+		}
+	}
+
 	function handleUpdate() {
 		myApi.getUserUpdate({}).then(res => {
 			if (res.data) {