index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view>
  3. </view>
  4. </template>
  5. <script setup>
  6. import {
  7. onLoad
  8. } from "@dcloudio/uni-app"
  9. const APPKEY = '4AA7B3944BDF3739'
  10. const ocode = '1015730314'
  11. const URL = 'http://192.168.161.78:5173/#/pages/index/index'
  12. onLoad(() => {
  13. loginFilter()
  14. })
  15. const loginFilter = () => {
  16. const wxcode = uni.getStorageSync('wxcode')
  17. if (!wxcode) {
  18. const wxcode = getQueryString('wxcode')
  19. if (!wxcode) {
  20. getWxcodeURL()
  21. } else {
  22. uni.setStorageSync('wxcode', wxcode)
  23. uni.switchTab({
  24. url: "/pages/home/home"
  25. })
  26. }
  27. } else {
  28. uni.switchTab({
  29. url: "/pages/home/home"
  30. })
  31. }
  32. }
  33. const getWxcodeURL = () => {
  34. window.
  35. location.href =
  36. `https://open.wecard.qq.com/connect/oauth/authorize?app_key=${APPKEY}&response_type=code&scope=snsapi_base&ocode=${ocode}&redirect_uri=${encodeURIComponent(URL)}`
  37. }
  38. //获取当前URL指定参数
  39. const getQueryString = (name) => {
  40. // 获取URL
  41. let url = window.location.href;
  42. // 正则匹配URL
  43. let pattern = new RegExp("[?&]" + name + "=([^&]+)", "i");
  44. let matcher = pattern.exec(url);
  45. if (matcher == null || matcher.length < 1) {
  46. return false;
  47. }
  48. // 输出指定的参数值
  49. return decodeURIComponent(matcher[1]);
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. </style>