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'
|
||||
|
||||
export const domainList = 'https://dk-1257812345.cos.ap-nanjing.myqcloud.com/domain.txt';
|
||||
|
||||
|
||||
export function getDomainList(){
|
||||
return http.request({
|
||||
url: domainList,
|
||||
url: 'domain.txt',
|
||||
method: 'GET'
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router';
|
||||
import {useUserStore} from "@/store/modules/user";
|
||||
import {domainStoreWidthOut} from "@/store/modules/domain";
|
||||
import {getDomainList} from "@/api/login";
|
||||
|
||||
export const constantRouter: Array<RouteRecordRaw> = [
|
||||
{
|
||||
@@ -235,8 +236,15 @@ const router = createRouter({
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
router.beforeEach((to, from, next) => {
|
||||
domainStoreWidthOut().refreshDomain();
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
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) { // 判断是否有标题
|
||||
document.title = to.meta.title as string;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {defineStore} from 'pinia';
|
||||
import {store} from '@/store';
|
||||
import {getDomainList} from "@/api/login";
|
||||
|
||||
export interface IDomain{
|
||||
domain: string[]
|
||||
@@ -17,18 +16,25 @@ export const domainStore = defineStore({
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setDomain() {
|
||||
getDomainList().then(response => {
|
||||
if(response && response.data){
|
||||
this.domain = response.data.split(',')
|
||||
}
|
||||
})
|
||||
// async setDomain() {
|
||||
// let response = await getDomainList();
|
||||
// if (response && response.data) {
|
||||
// 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(){
|
||||
if(!this.domain || this.domain.length == 0){
|
||||
this.setDomain()
|
||||
}
|
||||
}
|
||||
// refreshDomain(){
|
||||
// if(!this.domain || this.domain.length == 0){
|
||||
// this.setDomain().then()
|
||||
// }
|
||||
// }
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ 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 = '';
|
||||
|
||||
@@ -40,7 +39,9 @@ const transform: AxiosTransform = {
|
||||
isReturnNativeResponse,
|
||||
} = 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;
|
||||
}
|
||||
|
||||
@@ -134,12 +135,18 @@ const transform: AxiosTransform = {
|
||||
}
|
||||
if(!isUrlStr){
|
||||
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))];
|
||||
config.url = domainUrl + config.url;
|
||||
}else if(apiUrl && isString(apiUrl)){
|
||||
config.url = `${apiUrl}${config.url}`;
|
||||
}
|
||||
}else{
|
||||
if(config.url && config.url.endsWith("domain.txt")){
|
||||
return config
|
||||
}
|
||||
}
|
||||
// if (!isUrlStr && apiUrl && isString(apiUrl)) {
|
||||
// config.url = `${apiUrl}${config.url}`;
|
||||
|
||||
Reference in New Issue
Block a user