resolve refresh

This commit is contained in:
Cjsah 2024-06-16 10:51:12 +08:00
parent 96a3b6b802
commit 94aaee8d9b
No known key found for this signature in database
GPG Key ID: C7B4744DF32A9C6A
2 changed files with 19 additions and 13 deletions

View File

@ -1,14 +1,25 @@
import axios from "axios";
const SECOND = 1000;
export const baseUrl = () => {
return localStorage.getItem("remoteIp");
};
const remoteIp = ref(localStorage.getItem("remoteIp"));
const ajax = axios.create({
// baseURL: import.meta.env.VITE_API || location.origin,
timeout: 120 * SECOND,
});
ajax.interceptors.request.use((config) => {
config.baseURL = remoteIp.value;
return config;
});
export default ajax;
export const setRemoteIp = (ip) => {
remoteIp.value = ip;
localStorage.setItem("remoteIp", ip);
};
export const baseUrl = () => {
return remoteIp.value;
};

View File

@ -91,7 +91,7 @@ import githubUrl from "@/assets/imgs/github.png";
import { useLoading } from "@/hooks/loading";
import { Search } from "@element-plus/icons-vue";
import API from "@api";
import ajax from "@/api/axios.js";
import { baseUrl, setRemoteIp } from "@/api/axios.js";
const store = useBookStore();
const { connectStatus, connectType, newConnect, shelf } = storeToRefs(store);
@ -164,15 +164,15 @@ const searchBook = () => {
};
const ipInput = reactive({
ip: "",
ip: baseUrl(),
disable: true,
});
const toggleIpConfig = () => {
ipInput.ip = localStorage.getItem("remoteIp");
ipInput.ip = baseUrl();
ipInput.disable = !ipInput.disable;
};
const setIP = () => {
localStorage.setItem("remoteIp", ipInput.ip);
setRemoteIp(ipInput.ip);
ipInput.disable = true;
loadShelf();
};
@ -212,11 +212,6 @@ const toDetail = (bookUrl, bookName, bookAuthor, chapterIndex, chapterPos) => {
onMounted(() => {
//
let readingRecentStr = localStorage.getItem("readingRecent");
ipInput.ip = localStorage.getItem("remoteIp");
ajax.interceptors.request.use((config) => {
config.baseURL = ipInput.ip;
return config;
});
if (readingRecentStr != null) {
readingRecent.value = JSON.parse(readingRecentStr);
if (typeof readingRecent.value.chapterIndex == "undefined") {