homePage.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script setup>
  6. // 添加路由拦截
  7. import '@/interceptor/routeInterceptor.js'
  8. import { onLoad } from '@dcloudio/uni-app'
  9. import { defaultColor } from '@/static/js/theme.js'
  10. import { api_wechatLoginEncrypt } from "@/http/api.js"
  11. import { useWechatAuth } from '@/share/useWechatAuth.js'
  12. import { useLoginSuccess } from '@/share/useLoginSuccess.js'
  13. import { useSetTitle } from '@/share/useSetTitle.js'
  14. useSetTitle()
  15. const { wechatAuth } = useWechatAuth()
  16. const { loginSuccess } = useLoginSuccess()
  17. /**
  18. * 微信登录
  19. */
  20. function wechatLoginEncrypt() {
  21. const url = window.location.href.split("?");
  22. if (!url[1]) {
  23. wechatAuth();
  24. } else {
  25. const code = {
  26. code: url[1],
  27. type: 'user',
  28. };
  29. uni.showLoading({
  30. title: "登录中",
  31. mask: true,
  32. });
  33. api_wechatLoginEncrypt(code).then(res => {
  34. uni.hideLoading();
  35. if (res.state == 200) {
  36. loginSuccess(res.user);
  37. } else if (res.state == 501) {
  38. uni.showModal({
  39. title: '提示',
  40. content: '您的账号被删除,请联系管理员',
  41. showCancel: false,
  42. confirmColor: defaultColor,
  43. confirmText: '取消',
  44. });
  45. } else if (res.state == 403) {
  46. uni.reLaunch({
  47. url: `/pages/initBind/initBind?wechat=${res.wechat}`
  48. })
  49. } else {
  50. uni.showToast({
  51. icon: 'none',
  52. title: res.remarks || '请求数据失败!'
  53. });
  54. }
  55. });
  56. }
  57. }
  58. onLoad((option) => {
  59. uni.clearStorageSync();
  60. wechatLoginEncrypt();
  61. })
  62. </script>