Forráskód Böngészése

增加微信登录弹窗

ming 3 éve
szülő
commit
052b78f7da

+ 90 - 0
business/wx-login.vue

@@ -0,0 +1,90 @@
+<template>
+	<fs-modal v-model="modelValue" :showTitle="false" :showCancel="false" :showConfirm="false" :maskClickable="maskClickable">
+		<view style="padding: 20rpx;">
+			<view class="title bold" style="font-size: 18px;margin-bottom: 30rpx;">授权微信访问</view>
+			<view class="content" style="font-size: 15px;">
+				为了保护他人的隐私,授权后可查看对方的名片
+			</view>
+			<view class="wxlogin-btn">
+				<fs-button full round type="success" @click="getUserProfile" v-if="canIUseGetUserProfile">授权微信</fs-button>
+				<fs-button full round type="success" open-type="getUserInfo" @getuserinfo="getUserInfo" v-else>授权微信</fs-button>
+			</view>
+			<view class="footer">
+				<fs-checkbox-group v-model="checkboxArray" checkedColorType="primary">
+				  <fs-checkbox value="1">
+						<view class="sub">
+							同意<text @click="read('/modules/common/about/agreement')">《用户服务协议》</text>和<text @click="read('/modules/common/about/policy')">《隐私政策》</text>
+						</view>
+				  </fs-checkbox>
+				</fs-checkbox-group>
+			</view>
+		</view>
+	</fs-modal>
+</template>
+
+<script setup>
+import { ref } from 'vue'
+import { wxLogin } from '@/services/common'
+
+const props = defineProps({
+	modelValue: Boolean,
+	maskClickable: {
+		type: Boolean,
+		default: true
+	}
+})
+const emits = defineEmits(['update:modelValue', 'success'])
+
+const checkboxArray = ref(['1'])
+
+const canIUseGetUserProfile = ref(wx.getUserProfile ? true : false)
+const getUserProfile = () => {
+	if (!checkboxArray.value.length) {
+		return uni.showToast({
+			title: '请勾选用户协议和隐私政策',
+			icon: 'none'
+		})
+	}
+	
+	wx.getUserProfile({
+		desc: '用于完善会员资料',
+	}).then(res => {
+		login(res)
+	})
+}
+const getUserInfo = e => {
+	if (!checkboxArray.value.length) {
+		return uni.showToast({
+			title: '请先勾选用户协议和隐私政策',
+			icon: 'none'
+		})
+	}
+	
+	login(e)
+}
+
+const closeModal = () => {
+	emits('update:modelValue', false)
+}
+
+const login = data => {
+	wxLogin(data).then(() => {
+		closeModal()
+		emits('success')
+	}).catch(() => {
+		closeModal()
+	})
+}
+
+const read = url => {
+	uni.navigateTo({
+		url
+	})
+}
+</script>
+
+<style scoped>
+.wxlogin-btn{
+	margin: 30rpx 0;
+}
+</style>

+ 26 - 0
modules/common/about/agreement.vue

@@ -0,0 +1,26 @@
+<template>
+	<view class="wrap">
+		<rich-text :nodes="agreement"></rich-text>
+	</view>
+</template>
+
+<script setup>
+import { ref } from 'vue'
+import { getAgreement } from '@/services/common'
+
+const agreement = ref({})
+const fetchAgreement = () => {
+	getAgreement().then(res => {
+		agreement.value = res.data.content
+	})
+}
+fetchAgreement()
+</script>
+
+<style lang="scss" scoped>
+	.wrap {
+		min-height: 100vh;
+		background-color: #fff;
+		padding: 0 30rpx;
+	}
+</style>

+ 26 - 0
modules/common/about/policy.vue

@@ -0,0 +1,26 @@
+<template>
+	<view class="wrap">
+		<rich-text :nodes="policy"></rich-text>
+	</view>
+</template>
+
+<script setup>
+import { ref } from 'vue'
+import { getPolicy } from '@/services/common'
+
+const policy = ref({})
+const fetchPolicy = () => {
+	getPolicy().then(res => {
+		policy.value = res.data.content
+	})
+}
+fetchPolicy()
+</script>
+
+<style lang="scss" scoped>
+	.wrap {
+		min-height: 100vh;
+		background-color: #fff;
+		padding: 0 30rpx;
+	}
+</style>

+ 106 - 95
pages.json

@@ -20,96 +20,107 @@
 			}
 
 		}
-	],
-	"subPackages": [
-		{
-			"root": "modules/common",
-			"pages": [
-				{
-					"path": "login/login",
-					"style": {
-						"navigationBarTitleText": "登录",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "version",
-					"style": {
-						"navigationBarTitleText": "版本记录",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "feedback",
-					"style": {
-						"navigationBarTitleText": "意见反馈",
-						"enablePullDownRefresh": false
-					}
-				}, 
-				{
-					"path": "licensePlate/list",
-					"style": {
-						"navigationBarTitleText": "车辆管理",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "licensePlate/add",
-					"style": {
-						"navigationBarTitleText": "车辆管理",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "addrbook/list",
-					"style": {
-						"navigationBarTitleText": "通讯录",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "addrbook/detail",
-					"style": {
-						"navigationBarTitleText": "通讯录",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "address/list",
-					"style": {
-						"navigationBarTitleText": "地址管理",
-						"enablePullDownRefresh": false
-					}
-				},
-				{
-					"path": "address/add",
-					"style": {
-						"navigationBarTitleText": "地址管理",
-						"enablePullDownRefresh": false
-					}
-				}, 
-				{
-					"path": "notice",
-					"style": {
-						"navigationBarTitleText": "我的消息",
-						"enablePullDownRefresh": false
-					}
-				}, 
-				{
-					"path": "org",
-					"style": {
-						"navigationBarTitleText": "组织架构",
-						"enablePullDownRefresh": false
-					}
-				}
-			]
-		}
-	],
-	"preloadRule": {
-		"pages/my/my": {
-			"network": "all",
-			"packages": ["modules/common"]
-		}
+	],
+	"subPackages": [{
+		"root": "modules/common",
+		"pages": [{
+				"path": "login/login",
+				"style": {
+					"navigationBarTitleText": "登录",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "version",
+				"style": {
+					"navigationBarTitleText": "版本记录",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "feedback",
+				"style": {
+					"navigationBarTitleText": "意见反馈",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "licensePlate/list",
+				"style": {
+					"navigationBarTitleText": "车辆管理",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "licensePlate/add",
+				"style": {
+					"navigationBarTitleText": "车辆管理",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "addrbook/list",
+				"style": {
+					"navigationBarTitleText": "通讯录",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "addrbook/detail",
+				"style": {
+					"navigationBarTitleText": "通讯录",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "address/list",
+				"style": {
+					"navigationBarTitleText": "地址管理",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "address/add",
+				"style": {
+					"navigationBarTitleText": "地址管理",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "notice",
+				"style": {
+					"navigationBarTitleText": "我的消息",
+					"enablePullDownRefresh": false
+				}
+			},
+			{
+				"path": "org",
+				"style": {
+					"navigationBarTitleText": "组织架构",
+					"enablePullDownRefresh": false
+				}
+			}, {
+				"path": "about/policy",
+				"style": {
+					"navigationBarTitleText": "隐私政策",
+					"enablePullDownRefresh": false
+				}
+
+			}, {
+				"path": "about/agreement",
+				"style": {
+					"navigationBarTitleText": "用户协议",
+					"enablePullDownRefresh": false
+				}
+
+			}
+		]
+	}],
+	"preloadRule": {
+		"pages/my/my": {
+			"network": "all",
+			"packages": ["modules/common"]
+		}
 	},
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
@@ -117,18 +128,18 @@
 		"navigationBarBackgroundColor": "#F8F8F8",
 		"backgroundColor": "#F8F8F8"
 	},
-	"tabBar": {
+	"tabBar": {
 		"selectedColor": "#0063F5",
 		"list": [{
 				"pagePath": "pages/index/index",
-				"text": "首页",
-				"iconPath": "static/images/tabbar/home.png",
+				"text": "首页",
+				"iconPath": "static/images/tabbar/home.png",
 				"selectedIconPath": "static/images/tabbar/home-on.png"
 			},
 			{
 				"pagePath": "pages/my/my",
-				"text": "我的",
-				"iconPath": "static/images/tabbar/my.png",
+				"text": "我的",
+				"iconPath": "static/images/tabbar/my.png",
 				"selectedIconPath": "static/images/tabbar/my-on.png"
 			}
 		]

+ 5 - 1
pages/my/my.vue

@@ -89,6 +89,8 @@
 		<fs-gutter height="60rpx"></fs-gutter>
 		<fs-button round block @click="handleLogout">退出登录</fs-button>
 		<fs-gutter height="60rpx"></fs-gutter>
+		
+		<wx v-model="showLogin"></wx>
 	</view>
 </template>
 
@@ -96,9 +98,9 @@
 import { computed, ref } from 'vue'
 import useUser from '@/hooks/useUser'
 import userAvatar from '/static/images/user-avatar.png'
+import wx from '@/business/wx-login.vue'
 
 const userInfo = useUser()
-console.log(userInfo);
 const shortcutList = ref([
 	{
 		title: '我的访客',
@@ -110,6 +112,8 @@ const shortcutList = ref([
 	}
 ])
 
+const showLogin = ref(true)
+
 const handleLogout = () => {
 	store.dispatch('logout').then(res => {
 		console.log('logout')

+ 15 - 2
services/common.js

@@ -8,7 +8,12 @@ export function wxLogin(data) {
 		uni.login({
 		  provider: 'weixin',
 		  success: function (res) {
-		    http.post('user/wxlogin', { ...data, code: res.code }, {
+		    http.post('user/wxlogin', {
+					encryptedData: data.encryptedData,
+					ivStr: data.iv,
+					userInfo: JSON.stringify(data.userInfo),
+					code: res.code ,
+				}, {
 		    	isAuth: false,
 		    	loadingTitle: '登录中...'
 		    }).then(res => {
@@ -42,4 +47,12 @@ export function getVersionList(data) {
 // 通讯录
 export function getAddrbookList() {
 	return http.get('user/advice/list')
-}
+}
+
+// 协议、隐私
+export function getPolicy() {
+	return http.get('user/privacyPolicy')
+}
+export function getAgreement() {
+	return http.get('user/userServiceAgreement')
+}

+ 2 - 2
utils/config.js

@@ -1,8 +1,8 @@
-const baseUrl = process.env.NODE_ENV === 'development' ? 'https://saishi.sxidc.com' : 'https://zhswapi.sxidc.com'
+const baseUrl = process.env.NODE_ENV === 'development' ? 'http://johnny-ttj.vaiwan.com' : 'https://zhswapi.sxidc.com'
 
 const config = {
 	baseUrl,
-	apiBaseUrl: baseUrl + '/apiApp/1/',
+	apiBaseUrl: baseUrl + '/api/',
 	httpDefaultOption: {
 		showLoading: true,
 		isAuth: true,