appLogin.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="container-mine">
  3. <!-- <navbar ref="navbar" :config="config"></navbar> -->
  4. <uv-navbar title="登录" placeholder bgColor="#F9F9F9" @leftClick="goBack"></uv-navbar>
  5. <view class="top">
  6. <view class="title">手机号一键登录</view>
  7. <view class="tig">首次登录将为您注册</view>
  8. </view>
  9. <view class="body">
  10. <view class="btnBox">
  11. <uv-button type="primary" custom-style="background:#FF6600;border-color:#FF6600;" hover-class="hoverClass" @click="login">一键登录</uv-button>
  12. </view>
  13. </view>
  14. <view class="loginBox">
  15. <!-- <u-divider half-width="50" @click="toOtherLogin">切换其它登录方式</u-divider> -->
  16. <uv-button class="otherClass" custom-style="background:#fff;border:none" @click="toOtherLogin">切换其它登录方式</uv-button>
  17. </view>
  18. <view class="agreementCls">
  19. <uv-checkbox-group size="26rpx" v-model="checked">
  20. <uv-checkbox shape="circle" active-color="#56CBD9" name="1">
  21. <view>
  22. 我已阅读同意 <text @click.stop="goAgreement('user_protocol')">《服务协议》</text>和<text @click.stop="goAgreement('privacy_protocol')">《隐私政策》</text>
  23. </view>
  24. </uv-checkbox>
  25. </uv-checkbox-group>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. data () {
  32. return {
  33. mobile: '',
  34. checked: [],
  35. osVersion: "",
  36. platform: "",
  37. isInstallWx: true, //是否安装微信
  38. isInstallZfb: true, //是否安装支付宝
  39. isOneClickLogin: false
  40. }
  41. },
  42. onLoad () {
  43. uni.removeStorageSync('shop')
  44. // 先判断 系统版本
  45. uni.getSystemInfo({
  46. success: (res) => {
  47. this.osVersion = res.osVersion.split('.')[0]
  48. this.platform = res.platform;
  49. }
  50. })
  51. // #ifdef APP || APP-PLUS
  52. plus.push.getClientInfoAsync((info) => {
  53. let cid = info["clientid"];
  54. console.log('cid', cid)
  55. uni.setStorageSync('cid', cid)
  56. this.cid = cid
  57. });
  58. uni.preLogin({
  59. provider: 'univerify',
  60. success: (res) => { //预登录成功
  61. // 显示一键登录选项
  62. console.log('预登录===>', res)
  63. if (res.errMsg == 'preLogin:ok') {
  64. this.isOneClickLogin = true
  65. this.$nextTick(() => {
  66. this.checked = ['1']
  67. this.oneClickLogin()
  68. })
  69. }
  70. },
  71. fail: (fail) => { // 预登录失败
  72. // 不显示一键登录选项(或置灰)
  73. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  74. console.log(fail)
  75. this.preError(fail)
  76. // this.$u.toast(fail.errMsg);
  77. }
  78. })
  79. // #endif
  80. },
  81. methods: {
  82. login () {
  83. if (this.checked.length <= 0) {
  84. uni.showToast({
  85. title: '请阅读并同意相关协议',
  86. duration: 1500,
  87. icon: "none"
  88. });
  89. return
  90. }
  91. this.oneClickLogin()
  92. },
  93. goAgreement (val) {
  94. uni.navigateTo({
  95. url: "/pages/protocol/index?code=" + val
  96. })
  97. },
  98. // 一键登录
  99. oneClickLogin () {
  100. uni.login({
  101. provider: 'univerify',
  102. univerifyStyle: {
  103. fullScreen: true
  104. },
  105. success: res => {
  106. console.log('res==>', res)
  107. if (res.errMsg == 'login:ok') {
  108. const authResult = res.authResult
  109. // 在得到access_token后,通过callfunction调用云函数
  110. uniCloud.callFunction({
  111. name: 'getYGPhoneNumber', // 你的云函数名称
  112. data: {
  113. 'access_token': authResult.access_token, // 客户端一键登录接口返回的access_token
  114. 'openid': authResult.openid // 客户端一键登录接口返回的openid
  115. }
  116. }).then(data => {
  117. console.log('data===>', data)
  118. const dataVal = data.result
  119. this.oneLogin({
  120. mobile: dataVal.phoneNumber,
  121. cid: this.cid
  122. })
  123. // 登录成功,可以关闭一键登录授权界面了
  124. }).catch(err => {
  125. uni.closeAuthView()
  126. // 处理错误
  127. console.log('errr===>', err)
  128. uni.showToast({
  129. title: err,
  130. duration: 1500,
  131. icon: "none"
  132. });
  133. // this.$u.toast(err);
  134. })
  135. }
  136. },
  137. fail: fail => {
  138. uni.closeAuthView()
  139. console.log('fail===>', fail)
  140. // this.$u.toast(fail);
  141. uni.showToast({
  142. title: fail,
  143. duration: 1500,
  144. icon: "none"
  145. });
  146. }
  147. })
  148. },
  149. preError (fail) {
  150. const {
  151. code,
  152. errMsg
  153. } = fail
  154. if (code == 30005) {
  155. if (fail.metadata) {
  156. if (fail.metadata.status == 102001) {
  157. uni.showToast({
  158. title: "请保证数据流量开启",
  159. duration: 1500,
  160. icon: "none"
  161. });
  162. return
  163. }
  164. uni.showToast({
  165. title: fail.metadata.message,
  166. duration: 1500,
  167. icon: "none"
  168. });
  169. } else {
  170. // this.$u.toast("请检查手机是否有SIM卡、是否启用数据流量")
  171. uni.showToast({
  172. title: "请检查手机是否有SIM卡、是否启用数据流量",
  173. duration: 1500,
  174. icon: "none"
  175. });
  176. }
  177. }
  178. },
  179. oneLogin (data) {
  180. this.$yghttp.post('/user/login/mobile', data).then(res => {
  181. if (res && res.code == 200) {
  182. // this.$u.toast('登录成功');
  183. uni.showToast({
  184. title: "登录成功",
  185. duration: 1500,
  186. });
  187. uni.setStorageSync('apiToken', res.data.token);
  188. uni.closeAuthView()
  189. setTimeout(() => {
  190. uni.switchTab({
  191. url: "/pages/tabtar/home"
  192. });
  193. }, 500)
  194. } else {
  195. // this.$u.toast('登录失败');
  196. uni.showToast({
  197. icon: "none",
  198. title: "登录失败",
  199. duration: 1500,
  200. });
  201. }
  202. })
  203. },
  204. onBackPress () {
  205. uni.switchTab({
  206. url: "pages/tabtar/home"
  207. })
  208. return true
  209. },
  210. toOtherLogin () {
  211. uni.navigateTo({
  212. url: '/pages/login/otherLogin'
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style>
  219. page {
  220. background-color: #f9f9f9;
  221. }
  222. </style>
  223. <style lang="scss" scoped>
  224. ::v-deep .hx-navbar__icon {
  225. color: #303133 !important;
  226. }
  227. ::v-deep .u-divider {
  228. background-color: #f9f9f9 !important;
  229. }
  230. .lgoin-nav {
  231. width: 100%;
  232. background-color: #fff;
  233. position: fixed;
  234. left: 0;
  235. right: 0;
  236. top: 0;
  237. z-index: 0;
  238. }
  239. .top {
  240. text-align: center;
  241. padding: 50rpx 0 100rpx;
  242. font-size: 28rpx;
  243. .title {
  244. font-size: 60rpx;
  245. margin-bottom: 10rpx;
  246. font-weight: 700;
  247. }
  248. .tig {
  249. font-size: 30rpx;
  250. }
  251. }
  252. .body {
  253. margin: auto;
  254. width: 615rpx;
  255. margin-bottom: 30rpx;
  256. .inpBox {
  257. background: #fff;
  258. border-radius: 20rpx;
  259. padding: 20rpx 30rpx;
  260. display: flex;
  261. }
  262. image {
  263. width: 36rpx;
  264. height: 44rpx;
  265. margin-right: 30rpx;
  266. }
  267. .uni-input {
  268. height: 40rpx;
  269. .uni-input-placeholder {
  270. color: #bebebe;
  271. }
  272. }
  273. .login-btn {
  274. background-color: #4095e5;
  275. color: #fff;
  276. margin-top: 100rpx;
  277. }
  278. }
  279. .agreementCls {
  280. position: absolute;
  281. bottom: 200rpx;
  282. width: 100%;
  283. // padding: 0 30rpx;
  284. font-size: 26rpx;
  285. display: flex;
  286. justify-content: center;
  287. align-items: center;
  288. flex-wrap: wrap;
  289. ::v-deep .u-checkbox__label {
  290. margin-right: 0rpx;
  291. font-size: 26rpx;
  292. }
  293. text {
  294. color: #56cbd9;
  295. }
  296. ::v-deep .uv-checkbox-group--row {
  297. justify-content: center;
  298. }
  299. }
  300. .loginBox {
  301. // width: 100%;
  302. width: 615rpx;
  303. margin: auto;
  304. .loginBox_b {
  305. width: 615rpx;
  306. display: flex;
  307. justify-content: space-around;
  308. margin: auto;
  309. margin-top: 60rpx;
  310. > view {
  311. text-align: center;
  312. image {
  313. width: 82rpx;
  314. height: 82rpx;
  315. border-radius: 50%;
  316. }
  317. > view {
  318. font-size: 26rpx;
  319. color: #333333;
  320. }
  321. }
  322. }
  323. }
  324. .btnBox {
  325. width: 100%;
  326. margin-top: 60rpx;
  327. }
  328. .u-btn {
  329. width: 615rpx;
  330. border-radius: 10rpx;
  331. background: #ff6600;
  332. font-size: 30rpx;
  333. font-weight: 700;
  334. margin: auto;
  335. font-family: Microsoft YaHei, Microsoft YaHei-Bold;
  336. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  337. }
  338. .hoverClass {
  339. background: linear-gradient(6deg, #56d9ee 0%, #3ebcd0 100%) #3c66d9;
  340. }
  341. .otherClass {
  342. margin-top: 50rpx;
  343. color: #909399;
  344. font-weight: normal;
  345. font-size: 30rpx;
  346. background: #fff;
  347. border-color: #4095e5;
  348. }
  349. </style>