123
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
const baseUrl = '/api'
|
||||
|
||||
export const domainList = 'https://dk-1257812345.cos.ap-nanjing.myqcloud.com/domain.txt';
|
||||
|
||||
|
||||
export function getDomainList(){
|
||||
return http.request({
|
||||
url: domainList,
|
||||
method: 'GET'
|
||||
},
|
||||
{
|
||||
withToken: false,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: sendSmsRegister
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';
|
||||
import {useUserStore} from "@/store/modules/user";
|
||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||
|
||||
export const constantRouter: Array<RouteRecordRaw> = [
|
||||
{
|
||||
@@ -235,6 +236,7 @@ const router = createRouter({
|
||||
|
||||
// @ts-ignore
|
||||
router.beforeEach((to, from, next) => {
|
||||
domainStoreWidthOut().refreshDomain();
|
||||
if (to.meta.title) { // 判断是否有标题
|
||||
document.title = to.meta.title as string;
|
||||
}
|
||||
|
||||
37
src/store/modules/domain.ts
Normal file
37
src/store/modules/domain.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {defineStore} from 'pinia';
|
||||
import {store} from '@/store';
|
||||
import {getDomainList} from "@/api/login";
|
||||
|
||||
export interface IDomain{
|
||||
domain: string[]
|
||||
}
|
||||
|
||||
export const domainStore = defineStore({
|
||||
id: 'domain',
|
||||
state: (): IDomain => ({
|
||||
domain: []
|
||||
}),
|
||||
getters:{
|
||||
getDomain(): string[] {
|
||||
return this.domain
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setDomain() {
|
||||
getDomainList().then(response => {
|
||||
if(response && response.data){
|
||||
this.domain = response.data.split(',')
|
||||
}
|
||||
})
|
||||
},
|
||||
refreshDomain(){
|
||||
if(!this.domain || this.domain.length == 0){
|
||||
this.setDomain()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export function domainStoreWidthOut() {
|
||||
return domainStore(store);
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import { setObjToUrlParams } from '@/utils/urlUtils';
|
||||
import { RequestOptions, Result, CreateAxiosOptions } from './types';
|
||||
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||
import {domainList} from "@/api/login";
|
||||
|
||||
const urlPrefix = '';
|
||||
|
||||
@@ -38,6 +40,10 @@ const transform: AxiosTransform = {
|
||||
isReturnNativeResponse,
|
||||
} = options;
|
||||
|
||||
if(res.request.responseURL.includes(domainList)){
|
||||
return res;
|
||||
}
|
||||
|
||||
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
|
||||
if (isReturnNativeResponse) {
|
||||
return res;
|
||||
@@ -122,16 +128,22 @@ const transform: AxiosTransform = {
|
||||
// 请求之前处理config
|
||||
beforeRequestHook: (config, options) => {
|
||||
const { apiUrl, joinPrefix, joinParamsToUrl, formatDate, joinTime = true, urlPrefix } = options;
|
||||
|
||||
const isUrlStr = isUrl(config.url as string);
|
||||
|
||||
if (!isUrlStr && joinPrefix) {
|
||||
config.url = `${urlPrefix}${config.url}`;
|
||||
}
|
||||
|
||||
if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||
config.url = `${apiUrl}${config.url}`;
|
||||
if(!isUrlStr){
|
||||
let domain = domainStoreWidthOut().getDomain;
|
||||
if(domain && domain.length > 0){
|
||||
let domainUrl = domain[Math.floor((Math.random()*domain.length))];
|
||||
config.url = domainUrl + config.url;
|
||||
}else if(apiUrl && isString(apiUrl)){
|
||||
config.url = `${apiUrl}${config.url}`;
|
||||
}
|
||||
}
|
||||
// if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||
// config.url = `${apiUrl}${config.url}`;
|
||||
// }
|
||||
const params = config.params || {};
|
||||
const data = config.data || false;
|
||||
if (config.method?.toUpperCase() === RequestEnum.GET) {
|
||||
|
||||
Reference in New Issue
Block a user