index.vue 867 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // console.log(res.code)
  11. vertify(res.code)
  12. }
  13. })
  14. })
  15. const vertify = async (code) => {
  16. const res = await myRequest({
  17. url: '/wanzai/api/wechat/vertify',
  18. data: {
  19. code
  20. }
  21. })
  22. // console.log(res)
  23. if (res.code == 200) {
  24. uni.setStorageSync('token', JSON.parse(res.message).token)
  25. uni.setStorageSync('userhead', JSON.parse(res.message).userhead)
  26. uni.setStorageSync('userInfo', JSON.parse(res.message).user[0])
  27. uni.redirectTo({
  28. url: '/pages/home/home'
  29. })
  30. } else {
  31. uni.redirectTo({
  32. url: '/pages/login/login'
  33. })
  34. }
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. .container {
  39. min-height: 100vh;
  40. background-color: #f8f8fa;
  41. }
  42. </style>