login.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <view class="body">
  3. <view class="con">
  4. <view class="ImgCon">
  5. <view>
  6. <image style="width: 20vw; height: 20vw; border-radius: 50%;" src="../../static/logo.jpg" mode="">
  7. </image>
  8. </view>
  9. <view>
  10. <p style="font-size: 1.15rem; color: grey; margin-top: 6vw;"> 持之以恒,信守承诺 </p>
  11. <p style="font-size: 0.75rem; color: grey; margin-top: 3vw;"> PERSEVERE AND KEEP PROMISE </p>
  12. </view>
  13. </view>
  14. <view style="margin-top: 5vh;">
  15. <button
  16. style="border-radius:60rpx; width:80vw; height: 80rpx; font-size: 4vw; line-height: 80rpx; padding-right: 10vw;"
  17. type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
  18. hover-class="btn-hover">一键登录</button>
  19. </view>
  20. <!-- <view @click="avatar">123123</view> -->
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. data: {
  29. code: '',
  30. }
  31. }
  32. },
  33. onLoad() {
  34. let that = this
  35. uni.login({
  36. provider: 'weixin',
  37. success(res) {
  38. that.data.code = res.code;
  39. console.log(res.code)
  40. }
  41. })
  42. that.getappid()
  43. },
  44. methods: {
  45. //获取appId
  46. getappid() {
  47. let that = this
  48. const res = uni.getAccountInfoSync()
  49. that.data.appid = res.miniProgram.appId
  50. },
  51. getPhoneNumber(e) {
  52. console.log(e)
  53. let that = this
  54. that.$api.loginApi(that.data, res => {
  55. if (res.code == 0) {
  56. if (res.data.bind == 0) {
  57. that.$api.loginBind({
  58. encryptedData: e.detail.encryptedData,
  59. iv: e.detail.iv,
  60. openid: res.data.openid
  61. }, res => {
  62. if (res.code == 0) {
  63. that.$db.set('tel',res.data.tel)
  64. that.$db.set('token', res.data.token)
  65. uni.navigateBack({
  66. delta:1
  67. })
  68. }
  69. })
  70. } else {
  71. that.$db.set('name',res.data.name)
  72. that.$db.set('tel',res.data.tel)
  73. that.$db.set('token', res.data.token)
  74. uni.navigateBack({
  75. delta:1
  76. })
  77. }
  78. }
  79. })
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped lang="scss">
  85. .body {
  86. width: 100vw;
  87. height: 99vh;
  88. box-sizing: border-box;
  89. padding: 0 2vw;
  90. .con {
  91. width: 100vw;
  92. height: 40vh;
  93. .ImgCon {
  94. width: 100vw;
  95. height: 40vh;
  96. display: flex;
  97. flex-direction: column;
  98. justify-content: center;
  99. align-items: center;
  100. }
  101. }
  102. }
  103. </style>