index.vue 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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('userhead', JSON.parse(res.message).userhead)
  25. uni.setStorageSync('userInfo', JSON.parse(res.message).user[0])
  26. uni.redirectTo({
  27. url: '/pages/home/home'
  28. })
  29. } else {
  30. uni.redirectTo({
  31. url: '/pages/login/login'
  32. })
  33. }
  34. }
  35. </script>
  36. <style lang="scss" scoped>
  37. .container {
  38. min-height: 100vh;
  39. background-color: #f8f8fa;
  40. }
  41. </style>