zs 1 year ago
parent
commit
2297207ac2
4 changed files with 59 additions and 42 deletions
  1. 13 5
      pages/my/index.vue
  2. 5 4
      pagesHome/customer/index.vue
  3. 27 29
      pagesHome/login/index.vue
  4. 14 4
      pagesMy/basic/index.vue

+ 13 - 5
pages/my/index.vue

@@ -2,10 +2,11 @@
 	<view class="content">
 		<view class="one">
 			<view class="left">
-				<u-avatar :text="formatName(user.nickname)" shape="square" fontSize="20" randomBgColor></u-avatar>
+				<u-avatar :text="formatName(user.name||user.nickname)" shape="square" fontSize="20"
+					randomBgColor></u-avatar>
 			</view>
 			<view class="right" @tap="toLogin">
-				<text v-if="user._id">{{user.nickname||'证'}}</text>
+				<text v-if="user._id">{{user.name||user.nickname}}</text>
 				<text v-else>点击登录</text>
 				<u-icon :bold="true" color="#000" name="arrow-right" top="2px" size="18"></u-icon>
 			</view>
@@ -57,9 +58,16 @@
 	};
 	// 登录
 	const toLogin = () => {
-		uni.navigateTo({
-			url: `/pagesHome/login/index`
-		})
+		if (user.value._id) {
+			uni.navigateTo({
+				url: `/pagesMy/basic/index`
+			})
+		} else {
+			uni.navigateTo({
+				url: `/pagesHome/login/index`
+			})
+		}
+
 	};
 	// 公共跳转
 	const toCommon = (e) => {

+ 5 - 4
pagesHome/customer/index.vue

@@ -14,7 +14,7 @@
 							<image class="user-img" :src="config.logo&&config.logo.length>0?config.logo[0].url:''">
 							</image>
 							<!-- 文字 -->
-							<view class="message" v-if="item.msg_type =='0'">                           
+							<view class="message" v-if="item.msg_type =='0'">
 								<view class="msg-text">{{item.content}}</view>
 							</view>
 							<!-- 图像 -->
@@ -23,7 +23,8 @@
 							</view>
 						</view>
 						<view class="msg-m msg-right" v-else-if="item.speaker == user._id">
-							<u-avatar :text="formatName(user.nickname)" fontSize="22" randomBgColor></u-avatar>
+							<u-avatar :text="formatName(user.name||user.nickname)" fontSize="22"
+								randomBgColor></u-avatar>
 							<!-- 文字 -->
 							<view class="message" v-if="item.msg_type =='0'">
 								<view class="msg-text">{{item.content}}</view>
@@ -330,9 +331,9 @@
 						flex-direction: row;
 
 						.msg-text {
-							word-break: break-all;
 							margin-left: 16rpx;
-							background-color: #f1f1f1;
+							background-color: var(--f1Color);
+							;
 							border-radius: 0rpx 20rpx 20rpx 20rpx;
 						}
 

+ 27 - 29
pagesHome/login/index.vue

@@ -108,42 +108,40 @@
 	// 查询
 	const search = async () => {
 		const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
-		if (res.errcode == '0') form.value = res.data
+		if (res.errcode == '0') {
+			form.value = res.data
+			uni.setStorageSync('user', res.data);
+		}
 	};
 	// 开始验证
 	const formSubmit = () => {
 		if (agree.value) {
 			if (openid.value) {
 				uForm.value.validate().then(async res => {
-					console.log(form.value);
-					if (form.value._id) {
-
-					} else {
-						uni.getUserProfile({
-							desc: '用于展示',
-							success: async function (res) {
-								let parmas = {
-									openid: openid.value,
-									nickname: res.userInfo.nickName + moment().valueOf()
-								}
-								const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
-								if (arr.errcode == '0') {
-									uni.setStorageSync('user', arr.data);
-									uni.navigateBack({
-										delta: 1
-									})
-								} else {
-									uni.showToast({
-										title: arr.errmsg,
-										icon: 'error'
-									});
-								}
-							},
-							fail: function (err) {
-								console.log(err);
+					uni.getUserProfile({
+						desc: '用于展示',
+						success: async function (res) {
+							let parmas = {
+								openid: openid.value,
+								nickname: res.userInfo.nickName + moment().valueOf()
 							}
-						})
-					}
+							const arr = await $api(`user`, 'POST', { ...form.value, ...parmas });
+							if (arr.errcode == '0') {
+								uni.setStorageSync('user', arr.data);
+								uni.navigateBack({
+									delta: 1
+								})
+							} else {
+								uni.showToast({
+									title: arr.errmsg,
+									icon: 'error'
+								});
+							}
+						},
+						fail: function (err) {
+							console.log(err);
+						}
+					})
 				}).catch(err => {
 					console.log(err, '校验失败');
 				})

+ 14 - 4
pagesMy/basic/index.vue

@@ -77,13 +77,23 @@
 	// 查询
 	const search = async () => {
 		const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
-		if (res.errcode == '0') form.value = res.data
+		if (res.errcode == '0') {
+			form.value = res.data
+			uni.setStorageSync('user', res.data);
+		}
 	};
 	// 保存
 	const formSubmit = async (e) => {
-		let data = e.detail.value;
-		data = delEmptyQueryNodes(data);
-		console.log(data);
+		if (form.value._id) {
+			let data = e.detail.value;
+			data = delEmptyQueryNodes(data);
+			const res = await $api(`user/${form.value._id}`, 'POST', data);
+			if (res.errcode == '0') search();
+		} else {
+			uni.navigateTo({
+				url: `/pagesHome/login/index`
+			})
+		}
 	};
 	// 去除obj里为null的数据
 	const delEmptyQueryNodes = (obj = {}) => {