ConfirmProtocol.vue
6.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<template>
<view class="protocol">
<view class="protocol-loginBtn flexC" @click="login">{{ [1].includes(props.loginState) ? '一键登录' : '登录' }}</view>
<view class="flexA protocol-xieyi flexC">
<view v-if="isConfirmProtocol === false" @click="isConfirmProtocol = true" class="protocol-checkBox"></view>
<image class="protocol-check flexC" v-else src="/static/images/checked.png" mode="aspectFill" @click="isConfirmProtocol = false"></image>
<text style="margin-left: 16rpx">
我已阅读并同意
<text class="bluetext" @click="proxy.$h.jumpUrl(`/pages/login/agreement?title=用户协议&type=1`)">《用户协议》</text>
和
<text class="bluetext" @click="proxy.$h.jumpUrl(`/pages/login/agreement?title=隐私政策&type=2`)">《隐私政策》</text>
</text>
</view>
</view>
<u-modal :show="showMessage" :title="message">
<view class="slot-content" style="width: 300rpx">
<view class="flexA" style="height: 30vh">{{ message }}</view>
</view>
</u-modal>
</template>
<script setup lang="ts">
import { ref, getCurrentInstance, ComponentPublicInstance } from 'vue'
import { DebounceBy } from '@/utils/debounceBy'
import { doctorPhoneEasyLogin } from '../../../api'
import { doctorPhoneEasyLoginType } from '../../../types'
import UseSetCidHandler from '@/hooks/useSetCidHandler'
interface IProps {
loginState: number
}
const props = defineProps<IProps>()
const { proxy } = getCurrentInstance() as { proxy: ComponentPublicInstance }
const emit = defineEmits(['login'])
const isConfirmProtocol = ref<Boolean>(false)
const login = DebounceBy(() => (isConfirmProtocol.value ? emit('login', props.loginState) : uni.$u.toast('请先同意协议')), 1500)
const message = ref({})
const showMessage = ref<boolean>(false)
const oneClickLoginHandler = () => {
// uni.chooseLocation({
// success: function (res) {
// console.log('位置名称:' + res.name)
// console.log('详细地址:' + res.address)
// console.log('纬度:' + res.latitude)
// console.log('经度:' + res.longitude)
// }
// })
// uniCloud
// .callFunction({
// name: 'oneclicklogin', // 你的云函数名称
// data: {
// access_token: 'bm1mYjQ0MGFkODcwMmU0OWM1YjUzODFhYzY5NmQ0YWYxY3wwNjM1fDN8djJ8M3w0MjYwNzgwM2FkMTUzMmY1YWNkZDUxN2Y1YzIwNTZlZg==', // 客户端一键登录接口返回的access_token
// openid: '100gtc_244041310f9634388fe309834f34e77838' // 客户端一键登录接口返回的openid
// }
// })
// .then(res => {
// console.log(res, 'callFunction res')
// message.value = JSON.stringify(res)
// showMessage.value = true
// // res.result = {
// // code: '',
// // message: ''
// // }
// })
// .catch(err => {
// console.log(err, 'callFunction err')
// message.value = JSON.stringify(err)
// showMessage.value = true
// // 处理错误
// })
// uniCloud
// .callFunction({
// name: 'oneclicklogin', // 你的云函数名称
// data: {
// access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
// openid: res.authResult.openid // 客户端一键登录接口返回的openid
// }
// })
// .then(res => {
// console.log(res, 'callFunction res')
// message.value = JSON.stringify(res)
// showMessage.value = true
// // res.result = {
// // code: '',
// // message: ''
// // }
// })
// .catch(err => {
// console.log(err, 'callFunction err')
// message.value = JSON.stringify(err)
// showMessage.value = true
// // 处理错误
// })
uni.login({
provider: 'univerify',
univerifyStyle: {
fullScreen: true,
backgroundImage: 'static/images/bg.png',
icon: {
path: 'static/images/logo.png', // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
width: '60px', //图标宽度 默认值:60px
height: '60px' //图标高度 默认值:60px
},
authButton: {
normalColor: '#06b8d3', // 授权按钮正常状态背景颜色 默认值:#3479f5
textColor: '#ffffff', // 授权按钮文字颜色 默认值:#ffffff
title: '一键登录', // 授权按钮文案 默认值:“本机号码一键登录”
borderRadius: '24px' // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
},
otherLoginButton: {
visible: false
}
},
async success(res) {
// 登录成功
console.log(res, '成功')
try {
const { result } = await doctorPhoneEasyLogin({ ...res.authResult, cid: uni.getStorageSync('cid') || '' })
uni.closeAuthView()
console.log(result, '一键登录')
// message.value = JSON.stringify(result)
// showMessage.value = true
// setTimeout(() => {
uni.setStorageSync('token', result.token)
uni.setStorageSync('UserInfo', result.userInfo)
setTimeout(() => {
uni.$u.toast('登录成功')
}, 1000)
uni.reLaunch({ url: '/pages/index/index' })
// }, 800)
} catch (error) {
uni.$u.toast(error)
setTimeout(() => {
uni.closeAuthView()
}, 1000)
}
},
fail(res) {
uni.$u.toast('网络错误')
console.log(res, '失败')
console.log(res.errMsg)
}
})
}
defineExpose({ oneClickLoginHandler })
</script>
<style lang="scss" scoped>
.protocol {
&-xieyi {
margin: 44rpx auto 0;
}
&-check {
width: 30rpx;
height: 30rpx;
border-radius: 50%;
border: 1rpx solid transparent;
}
&-checkBox {
width: 30rpx;
height: 30rpx;
border-radius: 50%;
border: 1rpx solid #999;
}
&-loginBtn {
width: 602rpx;
height: 108rpx;
border-radius: 57rpx;
background: #05b8d2;
margin: 94rpx auto 0;
color: #fff;
font-size: 34rpx;
font-weight: 700;
}
}
</style>