login.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <!-- 登录 -->
  3. <view style="padding: 0 44rpx;background-color: #fff;height: 100vh;overflow: hidden;">
  4. <view class="" style="text-align: center; margin-top: 156rpx">
  5. <image src="../../static/images/logo.png" style="width: 350rpx; height: 350rpx" mode=""></image>
  6. </view>
  7. <button open-type="getPhoneNumber" class="login-btn" @getphonenumber="tologin">
  8. 微信授权登录
  9. </button>
  10. <!-- <view>
  11. <u--input placeholder="请输入内容" border="surround" v-model="mobile"></u--input>
  12. <u--input placeholder="请输入内容" border="surround" v-model="code"></u--input>
  13. </view> -->
  14. <!-- <button @click="submit">登录</button> -->
  15. <view class="" style="margin-top: 42rpx; display: flex">
  16. <u-checkbox-group v-model="checkboxValue1" placement="column" @change="checkboxChange">
  17. <u-checkbox shape="circle" :customStyle="{ marginBottom: '8px' }" :name="1">
  18. </u-checkbox>
  19. </u-checkbox-group>
  20. <text class="fontYin">我已阅读并同意</text>
  21. <text class="fontYin" style="color: #f83224">《用户协议》</text>
  22. <text class="fontYin">和</text>
  23. <text class="fontYin" style="color: #f83224">《隐私协议》</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. login
  30. } from "../../network/api/homeApi.js";
  31. export default {
  32. data() {
  33. return {
  34. mobile: "",
  35. code: "",
  36. checkboxValue1: false,
  37. changea: []
  38. };
  39. },
  40. methods: {
  41. //微信登录
  42. tologin(e) {
  43. if (this.changea.length > 0) {
  44. if (e.detail.code) {
  45. var phoneCode = e.detail.code
  46. uni.login({
  47. success: (code) => {
  48. uni.$u.http.post('/api/wxmini/login', {
  49. code: code.code
  50. }).then((res) => {
  51. console.log(res);
  52. if (res == 10011) {
  53. uni.$u.http.post('/api/wxmini/mobile', {
  54. code: phoneCode
  55. }).then((res) => {
  56. uni.$u.http.post('/api/register', {
  57. wx_code: code
  58. .code, // 是 String 微信登录时候的code
  59. mobile: res.mobile // 是 String 手机号码
  60. }).then((res) => {
  61. uni.setStorageSync('token', res.token)
  62. setTimeout(() => {
  63. uni.switchTab({
  64. url: '/pages/index/index'
  65. })
  66. }, 800)
  67. }).catch(() => {
  68. })
  69. }).catch(() => {
  70. })
  71. } else {
  72. uni.setStorageSync('token', res.token)
  73. this.$u.toast('登录成功')
  74. setTimeout(() => {
  75. uni.switchTab({
  76. url: '/pages/index/index'
  77. })
  78. }, 800)
  79. }
  80. }).catch(() => {})
  81. }
  82. })
  83. }
  84. } else {
  85. this.$u.toast('请勾选隐私协议')
  86. }
  87. },
  88. checkboxChange(n) {
  89. console.log("change", n);
  90. this.changea = n
  91. },
  92. submit() {
  93. // login({ mobile: "13000000000", password: "123456" }).then((res) => {
  94. // console.log(res);
  95. // if (res.data.code == 10000) {
  96. // uni.setStorage({
  97. // key: "token",
  98. // data: res.data.data.token,
  99. // success: function () {
  100. // uni.switchTab({
  101. // url: "../index/index",
  102. // });
  103. // },
  104. // });
  105. // }
  106. // });
  107. uni.$u.http.post('/api/login', {
  108. mobile: "13000000000",
  109. password: "123456"
  110. }).then((res) => {
  111. uni.setStorageSync('token', res.token)
  112. uni.switchTab({
  113. url: '/pages/index/index'
  114. })
  115. }).catch((error) => {
  116. console.log(error);
  117. })
  118. },
  119. },
  120. };
  121. </script>
  122. <style lang="scss" scoped>
  123. page {
  124. background-color: #ffffff !important;
  125. height: 100vh;
  126. }
  127. .login-btn {
  128. width: 662rpx;
  129. height: 96rpx;
  130. background: #f83224;
  131. box-shadow: 0rpx 16rpx 40rpx -12rpx rgba(255, 21, 21, 0.5);
  132. border-radius: 48rpx;
  133. font-family: PingFangSC, PingFang SC;
  134. font-weight: 500;
  135. font-size: 32rpx;
  136. color: #ffffff;
  137. line-height: 96rpx;
  138. text-align: center;
  139. font-style: normal;
  140. }
  141. .fontYin {
  142. font-family: PingFangSC, PingFang SC;
  143. font-weight: 400;
  144. font-size: 24rpx;
  145. color: #666666;
  146. line-height: 34rpx;
  147. text-align: left;
  148. font-style: normal;
  149. }
  150. </style>