login.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <view class="normal-login-container">
  3. <view class="logo-content align-center justify-center flex">
  4. <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
  5. </image>
  6. <text class="title">登录</text>
  7. </view>
  8. <view class="" style="margin-top: 5%;">
  9. <uni-row>
  10. <uni-col :span="20" offset="2">
  11. <view class="action-btn">
  12. <button @click="handleWxMiniLogin" class="login-btn cu-btn block bg-blue lg round"
  13. type="primary" :style="{backgroundColor: themeColor}">一键登录</button>
  14. </view>
  15. </uni-col>
  16. </uni-row>
  17. </view>
  18. <view class="xieyi text-center" style="margin-top: 5%;">
  19. <text class="text-grey1">登录即代表同意</text>
  20. <text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
  21. <text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. getCodeImg
  29. } from '@/api/login'
  30. export default {
  31. data() {
  32. return {
  33. globalConfig: getApp().globalData.config,
  34. loginForm: {
  35. code: "",
  36. appid: ""
  37. },
  38. themeColor:getApp().globalData.config.appInfo.themeColor
  39. }
  40. },
  41. created() {},
  42. methods: {
  43. // 隐私协议
  44. handlePrivacy() {
  45. let site = this.globalConfig.appInfo.agreements[0]
  46. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  47. },
  48. // 用户协议
  49. handleUserAgrement() {
  50. let site = this.globalConfig.appInfo.agreements[1]
  51. this.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`)
  52. },
  53. // 登录成功后,处理函数
  54. loginSuccess(result) {
  55. // 设置用户信息
  56. this.$store.dispatch('GetMiniAppUserInfo').then(res => {
  57. this.$tab.reLaunch('/pages/index')
  58. })
  59. this.$tab.reLaunch('/pages/index')
  60. },
  61. //一键登录
  62. handleWxMiniLogin() {
  63. this.$modal.loading("登录中,请耐心等待...")
  64. const accountInfo = uni.getAccountInfoSync()
  65. uni.login({
  66. provider: 'weixin',
  67. success: (res) => {
  68. this.loginForm.code = res.code;
  69. this.loginForm.appid = accountInfo.miniProgram.appId;
  70. this.$store.dispatch('WxMiniLogin', this.loginForm).then(() => {
  71. this.$modal.closeLoading()
  72. this.loginSuccess()
  73. }).catch(() => {
  74. if (this.captchaEnabled) {
  75. this.getCode()
  76. }
  77. })
  78. }
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style lang="scss">
  85. page {
  86. background-color: #ffffff;
  87. }
  88. .normal-login-container {
  89. width: 100%;
  90. .logo-content {
  91. width: 100%;
  92. font-size: 21px;
  93. text-align: center;
  94. padding-top: 15%;
  95. image {
  96. border-radius: 4px;
  97. }
  98. .title {
  99. margin-left: 10px;
  100. }
  101. }
  102. .login-form-content {
  103. text-align: center;
  104. margin: 20px auto;
  105. margin-top: 15%;
  106. width: 80%;
  107. .input-item {
  108. margin: 20px auto;
  109. background-color: #f5f6f7;
  110. height: 45px;
  111. border-radius: 20px;
  112. .icon {
  113. font-size: 38rpx;
  114. margin-left: 10px;
  115. color: #999;
  116. }
  117. .input {
  118. width: 100%;
  119. font-size: 14px;
  120. line-height: 20px;
  121. text-align: left;
  122. padding-left: 15px;
  123. }
  124. }
  125. .login-btn {
  126. margin-top: 40px;
  127. height: 45px;
  128. }
  129. .reg {
  130. margin-top: 15px;
  131. }
  132. .xieyi {
  133. color: #333;
  134. margin-top: 20px;
  135. }
  136. .login-code {
  137. height: 38px;
  138. float: right;
  139. .login-code-img {
  140. height: 38px;
  141. position: absolute;
  142. margin-left: 10px;
  143. width: 200rpx;
  144. }
  145. }
  146. }
  147. }
  148. </style>