Przeglądaj źródła

新加更换头像功能 新加权限

Qukatie 8 godzin temu
rodzic
commit
71362fd1a2
4 zmienionych plików z 144 dodań i 26 usunięć
  1. 8 0
      api/views/personalInformation/index.js
  2. 2 2
      common/setting.js
  3. 9 2
      manifest.json
  4. 125 22
      pages/tabBar/center.vue

+ 8 - 0
api/views/personalInformation/index.js

@@ -68,4 +68,12 @@ export function corpPointsDetail(params) {
     method: 'get',
 	params
   })
+}
+//保存头像
+export function updateUserAvatar(data) {
+  return http.request({
+    url: '/blade-user/updateUserAvatar',
+    method: 'post',
+    data
+  })
 }

+ 2 - 2
common/setting.js

@@ -10,7 +10,7 @@ module.exports = {
 	version: '1.0.0',
 	// 开发环境接口Url
 	// devUrl: 'http://192.168.0.111:1080',
-	// devUrl: 'http://192.168.8.105:1080',
+	// devUrl: 'http://192.168.8.101:1080',
 	// devUrl: 'https://td.echepei.com/api', 
 	devUrl: 'https://lt.echepei.com/api',   // 鑫畅途的
 	// devUrl: 'http://jxy.natapp1.cc/api',
@@ -20,7 +20,7 @@ module.exports = {
 	// prodUrl: 'https://td.echepei.com/api',
 	// prodUrl: 'http://192.168.8.103:1080',
 	prodUrl: 'https://lt.echepei.com/api', // 鑫畅途的
-	// prodUrl: 'http://192.168.1.111:1080',
+	// prodUrl: 'http://192.168.8.101:1080',
 	// 后端数据的接收方式application/json;charset=UTF-8或者application/x-www-form-urlencoded;charset=UTF-8
 	contentType: 'application/json;charset=UTF-8',
 	// 后端返回状态码

+ 9 - 2
manifest.json

@@ -1,5 +1,5 @@
 {
-    "name" : "佳途轮胎销售中心",
+    "name" : "青岛鑫动力轮胎有限公司",
     "appid" : "__UNI__487FA21",
     "description" : "",
     "versionName" : "1.0.53",
@@ -125,7 +125,7 @@
     "quickapp" : {},
     /* 小程序特有相关 */
     "mp-weixin" : {
-        "appid" : "wx4b6355ee84e14865",
+        "appid" : "wxc0835a195725c6b0",
         "setting" : {
             "urlCheck" : false,
             "postcss" : true,
@@ -137,6 +137,12 @@
         "permission" : {
             "scope.userLocation" : {
                 "desc" : "你的位置信息将用于小程序位置接口的效果展示"
+            },
+            "scope.camera" : {
+                "desc" : "需要您的摄像头权限用于拍照上传头像"
+            },
+            "scope.album" : {
+                "desc" : "需要您的相册权限用于选择头像图片"
             }
         },
         "requiredPrivateInfos" : [
@@ -163,3 +169,4 @@
         }
     }
 }
+

+ 125 - 22
pages/tabBar/center.vue

@@ -3,17 +3,18 @@
 		<view style="background-color:#E75F37;height: 250rpx;">
 			<view style="padding: 33rpx;display: flex;align-items: center;">
 				<view class="">
-					<image src="/static/images/tabBar/head.png" style="width:100rpx;height: 100rpx;" mode="scaleToFill">
+					<image :src="userData.avatar||avatarUrl" style="width:100rpx;height: 100rpx;border-radius: 50%;"
+						mode="scaleToFill" @click="showActionSheet">
 					</image>
 				</view>
 				<view style="color:#fff;margin-left: 13rpx;font-size: 30rpx;font-weight: 500;">
-					{{name?name:''}}
+					{{userData.cname?userData.cname:''}}
 				</view>
 			</view>
 		</view>
 		<view class="card" style="height: 114rpx;">
 			<view style="display: flex;justify-content: space-around;align-items: center;height: 114rpx;">
-<!--				<text style="color:#818181;font-size: 24rpx;">
+				<!--				<text style="color:#818181;font-size: 24rpx;">
 					产生积分:
 					<text style="color:#FE8301;font-size: 26rpx;">
 						{{form.addPoints?form.addPoints:'0.00'}}
@@ -31,12 +32,12 @@
 						{{form.pointsBalance?form.pointsBalance:'0.00'}}
 					</text>
 				</text>
-        <text style="color:#818181;font-size: 24rpx;">
-          现金余额:
-          <text style="color:#FE8301;font-size: 26rpx;">
-            {{form.recoveredBalance?form.recoveredBalance:'0.00'}}
-          </text>
-        </text>
+				<text style="color:#818181;font-size: 24rpx;">
+					现金余额:
+					<text style="color:#FE8301;font-size: 26rpx;">
+						{{form.recoveredBalance?form.recoveredBalance:'0.00'}}
+					</text>
+				</text>
 			</view>
 		</view>
 		<view class="card" style="margin-top: 20rpx;height: 141rpx;">
@@ -51,7 +52,7 @@
 				<view style="display: flex;flex-direction:column;align-items: center;" @click="inIntegralMall">
 					<image src="/static/images/tabBar/280-2.png" style="width:40rpx;height: 40rpx;" mode="scaleToFill">
 					</image>
-					<view style="color: #414141;font-size: 26rpx;margin-top: 13rpx;" >积分商城
+					<view style="color: #414141;font-size: 26rpx;margin-top: 13rpx;">积分商城
 						<uni-icons type="right" size="13" color='#8A8A8A'></uni-icons>
 					</view>
 				</view>
@@ -158,12 +159,15 @@
 <script>
 	import {
 		details,
-		corpPointsDetail
+		corpPointsDetail,
+		updateUserAvatar
 	} from '@/api/views/personalInformation/index.js'
 	export default {
 		data() {
 			return {
-				name: null,
+				avatarUrl: '/static/images/tabBar/head.png',
+				tempFilePaths: [],
+				userData: {},
 				badgeList: [],
 				form: {},
 				adminShow: false,
@@ -174,17 +178,89 @@
 			if (uni.getStorageSync('userInfo').tenant_id == '000000') {
 				this.adminShow = true
 			}
-			details().then(res => {
-				this.name = res.data.cname
-				corpPointsDetail({
-					corpId: res.data.id
-				}).then(e => {
-					this.form = e.data
-          this.form.recoveredBalance = res.data.recoveredBalance
-				})
-			})
+			this.getUserData()
 		},
 		methods: {
+			getUserData() {
+				details().then(res => {
+					this.userData = res.data
+					corpPointsDetail({
+						corpId: res.data.id
+					}).then(e => {
+						this.form = e.data
+						this.form.recoveredBalance = res.data.recoveredBalance
+					})
+				})
+			},
+			showActionSheet() {
+				if (this.userData.checkStatus != '通过') {
+					uni.showToast({
+						title: "当前用户未授权,请联系客服",
+						icon: "none",
+						mask: true
+					});
+					return
+				}
+				uni.showActionSheet({
+					itemList: ['拍照', '从相册选择'],
+					success: (res) => {
+						if (res.tapIndex === 0) {
+							this.chooseMedia('camera')
+						} else {
+							this.chooseMedia('album')
+						}
+					}
+				})
+			},
+			chooseMedia(sourceType) {
+				uni.chooseMedia({
+					count: 1,
+					mediaType: ['image'],
+					sourceType: [sourceType],
+					sizeType: ['original', 'compressed'],
+					camera: 'front',
+					success: (res) => {
+						// this.avatarUrl = res.tempFiles[0].tempFilePath
+						this.tempFilePaths = res.tempFiles.map(file => file.tempFilePath)
+						this.uploadFiles()
+					},
+					fail: (err) => {
+						console.log(err)
+					},
+				})
+			},
+			uploadFiles() {
+				const uploadTasks = this.tempFilePaths.map((filePath, index) => {
+					return new Promise((resolve, reject) => {
+						uni.uploadFile({
+							url: 'https://lt.echepei.com/api/blade-resource/oss/endpoint/put-file',
+							filePath: filePath,
+							name: 'file',
+							header: {
+								'Blade-Auth': 'bearer ' + uni.getStorageSync('accessToken'),
+								appId: uni.getAccountInfoSync().miniProgram.appId
+							},
+							success: (uploadRes) => {
+								let obj = {
+									id: this.userData.userId,
+									avatar: JSON.parse(uploadRes.data).data.link
+								}
+								updateUserAvatar(obj).then(res => {
+									uni.showToast({
+										title: "上传成功",
+										icon: "none",
+										mask: true
+									});
+									this.getUserData()
+								})
+							},
+							fail: (err) => {
+								reject(err)
+							}
+						})
+					})
+				})
+			},
 			getUpdate() {
 				const updateManager = uni.getUpdateManager();
 				updateManager.onCheckForUpdate(function(res) {
@@ -289,6 +365,33 @@
 	}
 </script>
 <style lang="scss" scoped>
+	.action-sheet {
+		background: #fff;
+		border-radius: 24rpx 24rpx 0 0;
+		padding: 30rpx;
+	}
+
+	.action-item {
+		padding: 28rpx 0;
+		display: flex;
+		align-items: center;
+		justify-content: center;
+		border-bottom: 1rpx solid #f5f5f5;
+
+		text {
+			margin-left: 20rpx;
+			font-size: 30rpx;
+		}
+	}
+
+	.cancel-btn {
+		padding: 28rpx 0;
+		text-align: center;
+		color: #ff2442;
+		font-size: 30rpx;
+		margin-top: 20rpx;
+	}
+
 	.card {
 		position: relative;
 		margin: 0 32rpx;
@@ -325,4 +428,4 @@
 			color: #797979;
 		}
 	}
-</style>
+</style>