index.vue 771 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <view class="container"></view>
  3. </template>
  4. <script setup>
  5. import { onLoad } from '@dcloudio/uni-app'
  6. import { myRequest } from '@/utils/api.js'
  7. onLoad(() => {
  8. uni.login({
  9. success: (res) => {
  10. vertify(res.code)
  11. }
  12. })
  13. })
  14. const vertify = async (code) => {
  15. const res = await myRequest({
  16. url: '/wanzai/api/wechat/vertify',
  17. data: {
  18. code
  19. }
  20. })
  21. // console.log(res)
  22. if (res.code == 200) {
  23. uni.setStorageSync('token', JSON.parse(res.message).token)
  24. uni.setStorageSync('userInfo', JSON.parse(res.message).user[0])
  25. uni.redirectTo({
  26. url: '/pages/home/home'
  27. })
  28. } else {
  29. uni.redirectTo({
  30. url: '/pages/login/login'
  31. })
  32. }
  33. }
  34. </script>
  35. <style lang="scss" scoped>
  36. .container {
  37. min-height: 100vh;
  38. background-color: #f8f8fa;
  39. }
  40. </style>