fix conflicts

This commit is contained in:
RockYang
2024-03-12 18:03:24 +08:00
239 changed files with 602 additions and 452 deletions

View File

@@ -0,0 +1,19 @@
{
"name": "@gpt-vue/packages",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.7",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/uuid": "^9.0.8"
}
}

View File

@@ -0,0 +1,28 @@
import axios from "axios";
import tokenHandler from "./token";
const { _tokenData, refreshToken, setCurRequest } = tokenHandler();
const createInstance = (baseURL: string = (import.meta as any).env.VITE_PROXY_BASE_URL) => {
const instance = axios.create({
baseURL,
timeout: 10000,
withCredentials: true,
});
instance.interceptors.request.use((config) => {
if (config.url !== _tokenData.get("lastRequest")) {
refreshToken();
}
if (config.method === "post") {
setCurRequest(config.url);
config.headers["request-id"] = _tokenData.get("__token");
}
return config;
});
return instance;
}
export default createInstance;

View File

@@ -0,0 +1,13 @@
import { getUUID } from "../utils";
const _tokenData = new Map();
export default function tokenHandler() {
const refreshToken = () => {
_tokenData.set("__token", getUUID());
_tokenData.set("lastRequest", null);
};
const setCurRequest = (curRequest?: string) => {
_tokenData.set("lastRequest", curRequest);
};
return { _tokenData, refreshToken, setCurRequest };
}

14
new-ui/packages/type.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
export interface BaseResponse<T> {
code: number;
data?: T;
message?: string;
}
export interface ListResponse<T = Record<string, unknown>> {
items: T[];
page: number;
page_size: number;
total: number;
total_page: number
}

View File

@@ -0,0 +1,57 @@
import { v4 as uuidV4 } from "uuid";
export const getUUID = () => {
return uuidV4();
};
// 格式化日期
export function dateFormat(timestamp: number, format?: string) {
if (!timestamp) {
return '';
} else if (timestamp < 9680917502) {
timestamp = timestamp * 1000;
}
let year, month, day, HH, mm, ss;
let time = new Date(timestamp);
let timeDate;
year = time.getFullYear(); // 年
month = time.getMonth() + 1; // 月
day = time.getDate(); // 日
HH = time.getHours(); // 时
mm = time.getMinutes(); // 分
ss = time.getSeconds(); // 秒
month = month < 10 ? '0' + month : month;
day = day < 10 ? '0' + day : day;
HH = HH < 10 ? '0' + HH : HH; // 时
mm = mm < 10 ? '0' + mm : mm; // 分
ss = ss < 10 ? '0' + ss : ss; // 秒
switch (format) {
case 'yyyy':
timeDate = String(year);
break;
case 'yyyy-MM':
timeDate = year + '-' + month;
break;
case 'yyyy-MM-dd':
timeDate = year + '-' + month + '-' + day;
break;
case 'yyyy/MM/dd':
timeDate = year + '/' + month + '/' + day;
break;
case 'yyyy-MM-dd HH:mm:ss':
timeDate = year + '-' + month + '-' + day + ' ' + HH + ':' + mm + ':' + ss;
break;
case 'HH:mm:ss':
timeDate = HH + ':' + mm + ':' + ss;
break;
case 'MM':
timeDate = String(month);
break;
default:
timeDate = year + '-' + month + '-' + day + ' ' + HH + ':' + mm + ':' + ss;
break;
}
return timeDate;
}