main.js 2.54 KB
/*
 * @Date: 2025-03-20 20:36:36
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-06-20 10:00:51
 * @FilePath: /mlaj/src/main.js
 * @Description: 文件描述
 */
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import axios from '@/utils/axios';
import 'vant/lib/index.css'
import '@vant/touch-emulator';

/* import the fontawesome core */
import { library } from '@fortawesome/fontawesome-svg-core'
/* import font awesome icon component */
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
/* import specific icons */
import { faCirclePause, faCirclePlay, faPlay, faPause, faBackwardStep, faForwardStep, faVolumeUp, faRedo, faRepeat, faList, faChevronDown, faVolumeOff, faXmark, faFileAlt, faTimes, faEye, faFilePdf, faExternalLinkAlt, faSpinner, faExclamationCircle, faDownload, faVenus, faMars, faMagnifyingGlassPlus, faMagnifyingGlassMinus } from '@fortawesome/free-solid-svg-icons'

/* add icons to the library */
library.add(faCirclePause, faCirclePlay, faPlay, faPause, faBackwardStep, faForwardStep, faVolumeUp, faRedo, faRepeat, faList, faChevronDown, faVolumeOff, faXmark, faFileAlt, faTimes, faEye, faFilePdf, faExternalLinkAlt, faSpinner, faExclamationCircle, faDownload, faVenus, faMars, faMagnifyingGlassPlus, faMagnifyingGlassMinus )

if (!Array.prototype.at) {
  Array.prototype.at = function(n) {
    n = Math.trunc(n) || 0;
    if (n < 0) n += this.length;
    if (n < 0 || n >= this.length) return undefined;
    return this[n];
  };
}

const app = createApp(App)
// 屏蔽警告信息
app.config.warnHandler = () => null;

app.config.globalProperties.$http = axios; // 关键语句
app.component('font-awesome-icon', FontAwesomeIcon)
/**
 * @function restoreHashAfterOAuth
 * @description 前端复原 OAuth 回跳的 hash 路由位置:当 URL 中存在 ret_hash 参数且当前无 hash 时,将其拼回地址栏。
 * @returns {void}
 */
function restoreHashAfterOAuth() {
    const url = new URL(window.location.href);
    const ret_hash = url.searchParams.get('ret_hash');
    if (ret_hash && !window.location.hash) {
        // 删除 ret_hash,保留其他查询参数
        url.searchParams.delete('ret_hash');
        const base = url.toString().split('#')[0];
        const new_url = base + ret_hash;
        // 使用 replaceState 避免再次刷新与历史记录污染
        window.history.replaceState(null, '', new_url);
    }
}

// 在安装路由前进行一次 hash 复原,确保初始路由正确
restoreHashAfterOAuth()
app.use(router)
app.mount('#app')