index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. id: '',
  30. // 类型
  31. type: '',
  32. };
  33. },
  34. onLoad: async function(e) {
  35. const that = this;
  36. that.$set(that, `id`, e && e.id || '');
  37. that.$set(that, `type`, e && e.type || '');
  38. that.search();
  39. },
  40. onShow: function() {
  41. const that = this;
  42. // 查询平台信息
  43. that.searchOpenids();
  44. },
  45. methods: {
  46. // 查询
  47. async search() {
  48. const that = this;
  49. },
  50. async searchOpenids() {
  51. const that = this;
  52. uni.getStorage({
  53. key: 'openid',
  54. success: function(res) {
  55. that.$set(that, `openid`, res.data);
  56. },
  57. fail: function(err) {
  58. uni.login({
  59. success: async function(res) {
  60. if (res.code) {
  61. const aee = await that.$app('/wechat/api/login/app',
  62. 'GET', {
  63. js_code: res.code,
  64. config: that.$config.wx_projectkey
  65. })
  66. if (aee.errcode == '0') {
  67. uni.setStorage({
  68. key: "openid",
  69. data: aee.data.openid
  70. })
  71. that.$set(that, `openid`, aee.data.openid);
  72. } else {
  73. uni.showToast({
  74. title: aee.errmsg,
  75. icon: 'none'
  76. })
  77. }
  78. } else {
  79. uni.showToast({
  80. title: res.errMsg,
  81. icon: 'none'
  82. })
  83. }
  84. }
  85. });
  86. }
  87. })
  88. },
  89. // 其他登录方式
  90. async otherLogin() {
  91. const that = this;
  92. let agree = that.agree;
  93. let openid = that.openid;
  94. if (agree) {
  95. if (openid) {
  96. const aee = await that.$api(`/login/wxapp/${openid}`, 'POST', {})
  97. if (aee.errcode == '0') {
  98. uni.reLaunch({
  99. url: `/pages/home/index`
  100. })
  101. } else {
  102. uni.showToast({
  103. title: aee.errmsg,
  104. icon: 'none'
  105. })
  106. }
  107. } else {
  108. uni.showToast({
  109. title: '系统更新中,请稍后再试!',
  110. icon: 'none'
  111. })
  112. }
  113. } else {
  114. uni.showToast({
  115. title: '请阅读并同意用户协议和隐私政策',
  116. icon: 'none'
  117. })
  118. }
  119. },
  120. // 同意隐私协议
  121. changeAgree() {
  122. const that = this;
  123. let agree = !that.agree
  124. that.$set(that, `agree`, agree);
  125. },
  126. // 查看隐私协议
  127. toAgree() {
  128. const that = this;
  129. uni.navigateTo({
  130. url: `/pagesHome/other/agree`
  131. })
  132. },
  133. },
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .main {
  138. display: flex;
  139. flex-direction: column;
  140. width: 100vw;
  141. height: 100vh;
  142. .wx {
  143. text-align: center;
  144. margin: 25vw 0 0 0;
  145. .wx_1 {
  146. margin: 0 0 5vw 0;
  147. .iconfont {
  148. color: var(--f35BColor);
  149. }
  150. text {
  151. font-size: 50px;
  152. }
  153. }
  154. .wx_2 {
  155. button {
  156. background: var(--f35BColor);
  157. color: var(--fffColor);
  158. font-size: var(--font16Size);
  159. }
  160. }
  161. .wx_3 {
  162. position: absolute;
  163. bottom: 10vw;
  164. text-align: center;
  165. font-size: 12px;
  166. }
  167. }
  168. }
  169. </style>