feat: 更改 token 获取规则

This commit is contained in:
Huangzhe
2025-05-23 11:40:26 +08:00
parent 58a372fdfe
commit cbf569b299

View File

@@ -5,6 +5,7 @@ import { showToast } from 'vant';
// import { A_COMMON_CLEAR_TOKEN } from '@/stores/constance/constance.common.js';
import * as config from '@/config';
// import { useRoute } from 'vue-router';
// import {proxyUrl} from config.default
// const NODE_ENV = import.meta.env.VITE_APP_ENV;
const baseURL = config.default.proxyUrl;
@@ -26,13 +27,20 @@ service.interceptors.request.use(
config.headers.Accept = 'application/json';
}
let plantToken = localStorage.getItem('plantToken');
const params = new URLSearchParams(new URL(window.location.href).search);
// 如果 token 不存在, 试图尝试让用户输入 token ,然后放入本地 token 内容中
// 仅限开发环境中
// if (!plantToken && !import.meta.env.PROD) {
if (!plantToken) {
plantToken = prompt('token 不存在,请输入 plant token');
if (!plantToken && params.get('apptoken')) {
// console.log(params.get('apptoken'));
// alert(params.get('apptoken'));
// plantToken = prompt('token 不存在,请输入 plant token');
plantToken = params.get('apptoken');
plantToken && localStorage.setItem('plantToken', plantToken);
}
config.headers.Authorization = `${plantToken}`;
config.headers.Source = 1;
// if (!config.headers.remoteIp) {