zs il y a 1 an
Parent
commit
00eabe6a8e
4 fichiers modifiés avec 56 ajouts et 68 suppressions
  1. 1 5
      pages.json
  2. 15 3
      pages/my/index.vue
  3. 29 32
      pagesHome/login/index.vue
  4. 11 28
      pagesMy/basic/index.vue

+ 1 - 5
pages.json

@@ -113,11 +113,7 @@
 				{
 					"path": "basic/index",
 					"style": {
-						"navigationBarTitleText": "我的信息",
-						"navigationBarBackgroundColor": "#F8F8F8",
-						"backgroundColor": "#F8F8F8",
-						"backgroundColorTop": "#F4F5F6",
-						"backgroundColorBottom": "#F4F5F6"
+						"navigationBarTitleText": "我的信息"
 					}
 				},
 				{

+ 15 - 3
pages/my/index.vue

@@ -2,10 +2,11 @@
 	<view class="content">
 		<view class="one">
 			<view class="left">
-				<u-avatar :text="user.name" shape="square" fontSize="40" randomBgColor></u-avatar>
+				<u-avatar :text="formatName(user.nickname)" shape="square" fontSize="20" randomBgColor></u-avatar>
 			</view>
 			<view class="right" @tap="toLogin">
-				<text>点击登录</text>
+				<text v-if="user._id">{{user.nickname||'证'}}</text>
+				<text v-else>点击登录</text>
 				<u-icon :bold="true" color="#000" name="arrow-right" top="2px" size="18"></u-icon>
 			</view>
 		</view>
@@ -28,7 +29,7 @@
 <script setup lang="ts">
 	import { getCurrentInstance, ref } from 'vue';
 	//该依赖已内置不需要单独安装
-	import { onLoad } from "@dcloudio/uni-app";
+	import { onShow, onLoad } from "@dcloudio/uni-app";
 	// 请求接口
 	const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
 	const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
@@ -40,6 +41,13 @@
 		await searchConfig();
 		await search();
 	})
+	onShow(() => {
+		searchUser();
+	})
+	// 用户信息
+	const searchUser = async () => {
+		user.value = uni.getStorageSync('user');
+	};
 	// config信息
 	const searchConfig = async () => {
 		config.value = uni.getStorageSync('config');
@@ -74,6 +82,9 @@
 			})
 		}
 	};
+	const formatName = (str) => {
+		if (str) return str.substr(0, 1) + new Array(str.length).join('');
+	};
 </script>
 <style lang="scss" scoped>
 	.content {
@@ -112,6 +123,7 @@
 			flex-direction: column;
 			padding: 2vw;
 			margin: 2vw;
+
 			.list {
 				display: flex;
 				justify-content: space-between;

+ 29 - 32
pagesHome/login/index.vue

@@ -108,14 +108,7 @@
 	// 查询
 	const search = async () => {
 		const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
-		if (res.errcode == '0') {
-			form.value = res.data
-		} else {
-			uni.showToast({
-				title: res.errmsg,
-				icon: 'none'
-			})
-		}
+		if (res.errcode == '0') form.value = res.data
 	};
 	// 开始验证
 	const formSubmit = () => {
@@ -123,30 +116,34 @@
 			if (openid.value) {
 				uForm.value.validate().then(async res => {
 					console.log(form.value);
-					// uni.getUserProfile({
-					// 	desc: '用于展示',
-					// 	success: async function (res) {
-					// 		let parmas = {
-					// 			openid: openid.value,
-					// 			nickname: res.userInfo.nickName + moment().valueOf()
-					// 		}
-					// 		const arr = await $api(`user`, 'POST', 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);
-					// 	}
-					// })
+					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);
+							}
+						})
+					}
 				}).catch(err => {
 					console.log(err, '校验失败');
 				})

+ 11 - 28
pagesMy/basic/index.vue

@@ -11,7 +11,8 @@
 				<view class="value icon">
 					<view class="title">头像</view>
 					<view class="label">
-						<u-avatar :text="form.name" shape="square" fontSize="40" randomBgColor></u-avatar>
+						<u-avatar :text="formatName(form.nickname||'证')" shape="square" fontSize="20"
+							randomBgColor></u-avatar>
 					</view>
 				</view>
 				<view class="remark">
@@ -30,11 +31,9 @@
 					</view>
 				</view>
 				<view class="value other">
-					<view class="title">性别</view>
+					<view class="title">身份证号码</view>
 					<view class="label">
-						<picker name="sex" @change="sexChange" :value="index" :range="sexList" range-key="dictLabel">
-							<view class="picker">{{form.sex||'请选择性别'}}</view>
-						</picker>
+						<input name="card" class="input" :value="form.card" placeholder="请输入身份证号码" />
 					</view>
 				</view>
 				<view class="value other">
@@ -57,51 +56,32 @@
 	import { onLoad } from "@dcloudio/uni-app";
 	// 请求接口
 	const $api = getCurrentInstance()?.appContext.config.globalProperties.$api;
-	const $config = getCurrentInstance()?.appContext.config.globalProperties.$config;
-	const $apifile = getCurrentInstance()?.appContext.config.globalProperties.$apifile;
 	// openid
 	const openid = computed(() => {
 		return uni.getStorageSync('openid');
 	})
 	// 基本信息
-	const config = ref({ logoUrl: '' });
+	const config = ref({ logo: '' });
 	// 用户信息
-	const form = ref({ icon: '', city: '', sex: '', nickname: '', phone: '' });
+	const form = ref({});
 	// 字典表
 	const sexList = ref([]);
 	onLoad(async () => {
-		await searchOther();
 		await searchConfig();
 		await search();
-		uni.$on('setCity', function (city) {
-			form.value.city = city
-		})
 	})
-	// 查询其他信息
-	const searchOther = async () => {
-		let res;
-	};
 	// config信息
 	const searchConfig = async () => {
 		config.value = uni.getStorageSync('config');
 	};
 	// 查询
 	const search = async () => {
-
-	};
-	// 处理字典表数据
-	const toData = (value, list) => {
-		if (value) return value = list[value].dictLabel
-	};
-	// 性别选择
-	const sexChange = (e) => {
-		const data = sexList.value[e.detail.value]
-		if (data) form.value.sex = data.dictLabel
+		const res = await $api(`login/wxapp/${openid.value}`, 'POST', {});
+		if (res.errcode == '0') form.value = res.data
 	};
 	// 保存
 	const formSubmit = async (e) => {
 		let data = e.detail.value;
-		data.icon = form.value.icon;
 		data = delEmptyQueryNodes(data);
 		console.log(data);
 	};
@@ -114,6 +94,9 @@
 		});
 		return obj;
 	};
+	const formatName = (str) => {
+		if (str) return str.substr(0, 1) + new Array(str.length).join('');
+	};
 </script>
 <style lang="scss" scoped>
 	.content {