auth.vue 1.13 KB
<!--
 * @Date: 2022-08-29 13:55:31
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-03-25 15:10:43
 * @FilePath: /mlaj/src/views/auth.vue
 * @Description: 授权模块
-->
<template>
  <div />
</template>

<script setup>
import { onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { buildOAuthAuthorizeUrl } from '@/utils/oauthHashRestore'

const $route = useRoute()

onMounted(() => {
  // php需要先跳转链接获取openid
  /**
   * encodeURIComponent() 函数可把字符串作为 URI 组件进行编码。
   * 该方法不会对 ASCII 字母和数字进行编码,也不会对这些 ASCII 标点符号进行编码: - _ . ! ~ * ' ( ) 。
   * 其他字符(比如 :;/?:@&=+$,# 这些用于分隔 URI 组件的标点符号),都是由一个或多个十六进制的转义序列替换的。
   */
  const target_href = `${location.origin}${location.pathname}${String($route.query.href || '')}`
  const short_url = buildOAuthAuthorizeUrl(target_href, {
    is_dev: import.meta.env.DEV,
    test_openid: import.meta.env.VITE_OPENID,
  })
  if (!short_url) return
  location.href = short_url
})
</script>