index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="main">
  3. <view class="wx">
  4. <view class="wx_1">
  5. <text class="iconfont icon-weixin"></text>
  6. </view>
  7. <view class="wx_2">
  8. <button size="mini" @tap="otherLogin()">微信信任登录</button>
  9. </view>
  10. <view class="wx_3">
  11. <checkbox-group @change="changeAgree">
  12. <label>
  13. <checkbox :checked="agree" />
  14. <text @tap.stop="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
  15. </label>
  16. </checkbox-group>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. // 用户协议
  26. agree: false,
  27. // 注册账号信息
  28. user: {},
  29. };
  30. },
  31. onShow: function() {
  32. const that = this;
  33. // 查询平台信息
  34. that.searchOpenids();
  35. },
  36. methods: {
  37. async searchOpenids() {
  38. const that = this;
  39. uni.getStorage({
  40. key: 'openid',
  41. success: function(res) {
  42. that.$set(that, `openid`, res.data);
  43. },
  44. fail: function(err) {
  45. uni.login({
  46. success: async function(res) {
  47. if (res.code) {
  48. const aee = await that.$app('/wechat/api/login/app',
  49. 'GET', {
  50. js_code: res.code,
  51. config: that.$config.wx_projectkey
  52. })
  53. if (aee.errcode == '0') {
  54. uni.setStorage({
  55. key: "openid",
  56. data: aee.data.openid
  57. })
  58. that.$set(that, `openid`, aee.data.openid);
  59. } else {
  60. uni.showToast({
  61. title: aee.errmsg,
  62. icon: 'none'
  63. })
  64. }
  65. } else {
  66. uni.showToast({
  67. title: res.errMsg,
  68. icon: 'none'
  69. })
  70. }
  71. }
  72. });
  73. }
  74. })
  75. },
  76. // 其他登录方式
  77. async otherLogin() {
  78. const that = this;
  79. let agree = that.agree;
  80. let openid = that.openid;
  81. if (agree) {
  82. if (openid) {
  83. const aee = await that.$api(`/login/wxapp/${openid}`, 'POST', {})
  84. if (aee.errcode == '0') {
  85. uni.reLaunch({
  86. url: `/pages/home/index`
  87. })
  88. } else {
  89. uni.showToast({
  90. title: aee.errmsg,
  91. icon: 'none'
  92. })
  93. }
  94. } else {
  95. uni.showToast({
  96. title: '系统更新中,请稍后再试!',
  97. icon: 'none'
  98. })
  99. }
  100. } else {
  101. uni.showToast({
  102. title: '请阅读并同意用户协议和隐私政策',
  103. icon: 'none'
  104. })
  105. }
  106. },
  107. // 同意隐私协议
  108. changeAgree() {
  109. const that = this;
  110. let agree = !that.agree
  111. that.$set(that, `agree`, agree);
  112. },
  113. // 查看隐私协议
  114. toAgree() {
  115. const that = this;
  116. uni.navigateTo({
  117. url: `/pagesHome/other/agree`
  118. })
  119. },
  120. },
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .main {
  125. display: flex;
  126. flex-direction: column;
  127. width: 100vw;
  128. height: 100vh;
  129. .wx {
  130. text-align: center;
  131. margin: 25vw 0 0 0;
  132. .wx_1 {
  133. margin: 0 0 5vw 0;
  134. .iconfont {
  135. color: var(--f35BColor);
  136. }
  137. text {
  138. font-size: 50px;
  139. }
  140. }
  141. .wx_2 {
  142. button {
  143. background: var(--f35BColor);
  144. color: var(--fffColor);
  145. font-size: var(--font16Size);
  146. }
  147. }
  148. .wx_3 {
  149. position: absolute;
  150. bottom: 10vw;
  151. text-align: center;
  152. font-size: 12px;
  153. }
  154. }
  155. }
  156. </style>