123
This commit is contained in:
1
public/domain.txt
Normal file
1
public/domain.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
https://baidu.com,https://jingdong.com
|
||||||
@@ -2,12 +2,9 @@ import { http } from '@/utils/http/axios';
|
|||||||
|
|
||||||
const baseUrl = '/api'
|
const baseUrl = '/api'
|
||||||
|
|
||||||
export const domainList = 'https://dk-1257812345.cos.ap-nanjing.myqcloud.com/domain.txt';
|
|
||||||
|
|
||||||
|
|
||||||
export function getDomainList(){
|
export function getDomainList(){
|
||||||
return http.request({
|
return http.request({
|
||||||
url: domainList,
|
url: 'domain.txt',
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';
|
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';
|
||||||
import {useUserStore} from "@/store/modules/user";
|
import {useUserStore} from "@/store/modules/user";
|
||||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||||
|
import {getDomainList} from "@/api/login";
|
||||||
|
|
||||||
export const constantRouter: Array<RouteRecordRaw> = [
|
export const constantRouter: Array<RouteRecordRaw> = [
|
||||||
{
|
{
|
||||||
@@ -235,8 +236,15 @@ const router = createRouter({
|
|||||||
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
domainStoreWidthOut().refreshDomain();
|
const dsw = domainStoreWidthOut()
|
||||||
|
if (!dsw.getDomain || dsw.getDomain.length == 0) {
|
||||||
|
const response = await getDomainList()
|
||||||
|
if (response && response.data) {
|
||||||
|
const domain = response.data.split(',')
|
||||||
|
dsw.setDomain(domain)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (to.meta.title) { // 判断是否有标题
|
if (to.meta.title) { // 判断是否有标题
|
||||||
document.title = to.meta.title as string;
|
document.title = to.meta.title as string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {defineStore} from 'pinia';
|
import {defineStore} from 'pinia';
|
||||||
import {store} from '@/store';
|
import {store} from '@/store';
|
||||||
import {getDomainList} from "@/api/login";
|
|
||||||
|
|
||||||
export interface IDomain{
|
export interface IDomain{
|
||||||
domain: string[]
|
domain: string[]
|
||||||
@@ -17,18 +16,25 @@ export const domainStore = defineStore({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
setDomain() {
|
// async setDomain() {
|
||||||
getDomainList().then(response => {
|
// let response = await getDomainList();
|
||||||
if(response && response.data){
|
// if (response && response.data) {
|
||||||
this.domain = response.data.split(',')
|
// this.domain = response.data.split(',')
|
||||||
}
|
// }
|
||||||
})
|
// // getDomainList().then(response => {
|
||||||
|
// // if(response && response.data){
|
||||||
|
// // this.domain = response.data.split(',')
|
||||||
|
// // }
|
||||||
|
// // })
|
||||||
|
// },
|
||||||
|
setDomain(domain: string[]): void {
|
||||||
|
this.domain = domain
|
||||||
},
|
},
|
||||||
refreshDomain(){
|
// refreshDomain(){
|
||||||
if(!this.domain || this.domain.length == 0){
|
// if(!this.domain || this.domain.length == 0){
|
||||||
this.setDomain()
|
// this.setDomain().then()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { RequestOptions, Result, CreateAxiosOptions } from './types';
|
|||||||
|
|
||||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||||
import {domainList} from "@/api/login";
|
|
||||||
|
|
||||||
const urlPrefix = '';
|
const urlPrefix = '';
|
||||||
|
|
||||||
@@ -40,7 +39,9 @@ const transform: AxiosTransform = {
|
|||||||
isReturnNativeResponse,
|
isReturnNativeResponse,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
if(res.request.responseURL.includes(domainList)){
|
console.log(res.request.responseURL.endsWith('domain.txt'))
|
||||||
|
console.log(res.request.responseURL)
|
||||||
|
if(res.request.responseURL.includes('domain.txt')){
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,12 +135,18 @@ const transform: AxiosTransform = {
|
|||||||
}
|
}
|
||||||
if(!isUrlStr){
|
if(!isUrlStr){
|
||||||
let domain = domainStoreWidthOut().getDomain;
|
let domain = domainStoreWidthOut().getDomain;
|
||||||
if(domain && domain.length > 0){
|
if(config.url && config.url.endsWith("domain.txt")){
|
||||||
|
return config
|
||||||
|
}else if(domain && domain.length > 0){
|
||||||
let domainUrl = domain[Math.floor((Math.random()*domain.length))];
|
let domainUrl = domain[Math.floor((Math.random()*domain.length))];
|
||||||
config.url = domainUrl + config.url;
|
config.url = domainUrl + config.url;
|
||||||
}else if(apiUrl && isString(apiUrl)){
|
}else if(apiUrl && isString(apiUrl)){
|
||||||
config.url = `${apiUrl}${config.url}`;
|
config.url = `${apiUrl}${config.url}`;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
if(config.url && config.url.endsWith("domain.txt")){
|
||||||
|
return config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
// if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||||
// config.url = `${apiUrl}${config.url}`;
|
// config.url = `${apiUrl}${config.url}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user