Skip to content

Commit cbd01f3

Browse files
committed
feature:Compatible with previous json
1 parent cae87d3 commit cbd01f3

File tree

4 files changed

+122
-69
lines changed

4 files changed

+122
-69
lines changed

src/components/Check.vue

+114-66
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@
432432
bordered
433433
style="width: 100%;"
434434
item-layout="horizontal"
435+
:style="localListStyle"
435436
>
436437
<template #renderItem="{ item }">
437438
<a-list-item>
@@ -500,6 +501,7 @@
500501
bordered
501502
style="width: 100%;"
502503
item-layout="horizontal"
504+
:style="cloudListStyle"
503505
>
504506
<template #renderItem="{ item }">
505507
<a-list-item>
@@ -1135,7 +1137,8 @@ async function getModelList() {
11351137
spinning.value = true; // 开始加载动画
11361138
try {
11371139
const data = await fetchModelList(apiUrl.value, apiKey.value);
1138-
models.value = data.data.map((model) => model.id).sort();
1140+
// 需要去重 data.data
1141+
models.value = [...new Set(data.data.map((model) => model.id))].sort();
11391142
showModelModal.value = true;
11401143
} catch (error) {
11411144
console.error('Error in getModelList:', error);
@@ -1784,6 +1787,22 @@ const cloudPassword = ref('');
17841787
let cloudAuthHeader = ''; // 存储 Authorization 头的值
17851788
const cloudDataList = ref([]);
17861789
1790+
const localListStyle = computed(() => {
1791+
if (localCacheList.value.length > 4) {
1792+
return { maxHeight: '320px', overflowY: 'auto' };
1793+
} else {
1794+
return {};
1795+
}
1796+
});
1797+
1798+
const cloudListStyle = computed(() => {
1799+
if (cloudDataList.value.length > 5) {
1800+
return { maxHeight: '420px', overflowY: 'auto' };
1801+
} else {
1802+
return {};
1803+
}
1804+
});
1805+
17871806
// 本地缓存相关状态
17881807
const settingsApiUrl = ref('');
17891808
const settingsApiKey = ref('');
@@ -1907,39 +1926,42 @@ function importLocalCache() {
19071926
reader.onload = (event) => {
19081927
try {
19091928
const importedData = JSON.parse(event.target.result);
1910-
if (Array.isArray(importedData)) {
1911-
importedData.forEach((item) => {
1912-
// 规范化 URL
1913-
const importedUrl = normalizeUrl(item.url);
1914-
const importedSk = item.sk.trim();
1915-
1916-
// 查找是否有相同的 url 和 sk
1917-
const existingIndex = localCacheList.value.findIndex((existingItem) =>
1918-
normalizeUrl(existingItem.url) === importedUrl && existingItem.apiKey.trim() === importedSk
1919-
);
1920-
//随机两位数字
1921-
const id = Math.floor(Math.random() * 100);
1922-
const newItem = {
1923-
id: Date.now() + id,
1924-
url: item.url,
1925-
apiKey: item.sk,
1926-
name: `导入的配置 ${localCacheList.value.length + 1}`,
1927-
};
1928-
1929-
if (existingIndex !== -1) {
1930-
// 存在相同的配置,进行覆盖
1931-
localCacheList.value[existingIndex] = newItem;
1932-
} else {
1933-
// 不存在,添加新的配置
1934-
localCacheList.value.push(newItem);
1935-
}
1936-
});
1937-
1938-
localStorage.setItem('localCacheList', JSON.stringify(localCacheList.value));
1939-
message.success(t('DATA_IMPORTED'));
1940-
} else {
1941-
message.error(t('INVALID_IMPORT_FORMAT'));
1942-
}
1929+
// 将 importedData 规范为数组形式,方便统一处理
1930+
const dataArray = Array.isArray(importedData) ? importedData : [importedData];
1931+
1932+
dataArray.forEach((item) => {
1933+
// 兼容不同的字段名
1934+
const importedUrl = normalizeUrl(item.url || item.apiUrl || '');
1935+
const importedApiKey = (item.sk || item.apiKey || '').trim();
1936+
if (!importedUrl || !importedApiKey) {
1937+
// 如果缺少必要的字段,跳过该项
1938+
return;
1939+
}
1940+
// 查找是否有相同的 url 和 apiKey
1941+
const existingIndex = localCacheList.value.findIndex((existingItem) =>
1942+
normalizeUrl(existingItem.url) === importedUrl && existingItem.apiKey.trim() === importedApiKey
1943+
);
1944+
1945+
// 随机两位数字
1946+
const id = Date.now() + Math.floor(Math.random() * 100);
1947+
const newItem = {
1948+
id: id,
1949+
url: importedUrl,
1950+
apiKey: importedApiKey,
1951+
name: `导入的配置 ${localCacheList.value.length + 1}`,
1952+
};
1953+
1954+
if (existingIndex !== -1) {
1955+
// 存在相同的配置,进行覆盖
1956+
localCacheList.value[existingIndex] = newItem;
1957+
} else {
1958+
// 不存在,添加新的配置
1959+
localCacheList.value.push(newItem);
1960+
}
1961+
});
1962+
1963+
localStorage.setItem('localCacheList', JSON.stringify(localCacheList.value));
1964+
message.success(t('DATA_IMPORTED'));
19431965
} catch (error) {
19441966
message.error(t('IMPORT_PARSE_ERROR'));
19451967
console.error(error);
@@ -1950,6 +1972,7 @@ function importLocalCache() {
19501972
input.click();
19511973
}
19521974
1975+
19531976
function normalizeUrl(url) {
19541977
return url.replace(/\/+$/, '').toLowerCase();
19551978
}
@@ -2118,38 +2141,42 @@ function importCloudCache() {
21182141
reader.onload = (event) => {
21192142
try {
21202143
const importedData = JSON.parse(event.target.result);
2121-
if (Array.isArray(importedData)) {
2122-
importedData.forEach((item) => {
2123-
// 规范化 URL
2124-
const importedUrl = normalizeUrl(item.url);
2125-
const importedSk = item.sk.trim();
2126-
2127-
// 查找是否有相同的 url 和 sk
2128-
const existingIndex = cloudDataList.value.findIndex((existingItem) =>
2129-
normalizeUrl(existingItem.url) === importedUrl && existingItem.apiKey.trim() === importedSk
2130-
);
2131-
const id = Math.floor(Math.random() * 100);
2132-
2133-
const newItem = {
2134-
id: Date.now() + id,
2135-
url: item.url,
2136-
apiKey: item.sk,
2137-
name: `导入的配置 ${cloudDataList.value.length + 1}`,
2138-
};
2139-
2140-
if (existingIndex !== -1) {
2141-
// 存在相同的配置,进行覆盖
2142-
cloudDataList.value[existingIndex] = newItem;
2143-
} else {
2144-
// 不存在,添加新的配置
2145-
cloudDataList.value.push(newItem);
2146-
}
2147-
});
2148-
2149-
message.success(t('DATA_IMPORTED_PLEASE_SAVE'));
2150-
} else {
2151-
message.error(t('INVALID_IMPORT_FORMAT'));
2152-
}
2144+
// 将 importedData 规范为数组形式,方便统一处理
2145+
const dataArray = Array.isArray(importedData) ? importedData : [importedData];
2146+
2147+
dataArray.forEach((item) => {
2148+
// 兼容不同的字段名
2149+
const importedUrl = normalizeUrl(item.url || item.apiUrl || '');
2150+
const importedApiKey = (item.sk || item.apiKey || '').trim();
2151+
2152+
if (!importedUrl || !importedApiKey) {
2153+
// 如果缺少必要的字段,跳过该项
2154+
return;
2155+
}
2156+
// 查找是否有相同的 url 和 apiKey
2157+
const existingIndex = cloudDataList.value.findIndex((existingItem) =>
2158+
normalizeUrl(existingItem.url) === importedUrl && existingItem.apiKey.trim() === importedApiKey
2159+
);
2160+
// 随机两位数字
2161+
const id = Date.now() + Math.floor(Math.random() * 100);
2162+
2163+
const newItem = {
2164+
id: id,
2165+
url: importedUrl,
2166+
apiKey: importedApiKey,
2167+
name: `导入的配置 ${cloudDataList.value.length + 1}`,
2168+
};
2169+
2170+
if (existingIndex !== -1) {
2171+
// 存在相同的配置,进行覆盖
2172+
cloudDataList.value[existingIndex] = newItem;
2173+
} else {
2174+
// 不存在,添加新的配置
2175+
cloudDataList.value.push(newItem);
2176+
}
2177+
});
2178+
2179+
message.success(t('DATA_IMPORTED_PLEASE_SAVE'));
21532180
} catch (error) {
21542181
message.error(t('IMPORT_PARSE_ERROR'));
21552182
console.error(error);
@@ -3234,5 +3261,26 @@ body.light-mode {
32343261
.announcement-collapse li {
32353262
margin: 4px 0;
32363263
}
3264+
3265+
.ant-list-item {
3266+
min-height: 80px; /* 根据需要调整 */
3267+
}
3268+
3269+
/* 可选:自定义滚动条样式 */
3270+
.ant-list {
3271+
/* 滚动条样式(可根据需要调整或移除) */
3272+
scrollbar-width: thin;
3273+
scrollbar-color: rgba(0, 0, 0, 0.5) transparent;
3274+
}
3275+
3276+
.ant-list::-webkit-scrollbar {
3277+
width: 6px;
3278+
}
3279+
3280+
.ant-list::-webkit-scrollbar-thumb {
3281+
background-color: rgba(0, 0, 0, 0.2);
3282+
border-radius: 3px;
3283+
}
3284+
32373285
</style>
32383286

src/locales/en.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,8 @@
160160
"SEE_MORE_INTRODUCTION": "See More Introduction",
161161
"INTRODUCTION": "Introduction",
162162
"DETAIL_INTRODUCTION": "Detailed Introduction",
163-
"PLEASE_WAIT_FOR_TESTING": "Please wait for testing to complete before sharing."
163+
"PLEASE_WAIT_FOR_TESTING": "Please wait for testing to complete before sharing.",
164+
"PLEASE_ENTER_CLOUD_URL_AND_PASSWORD": "Please enter the cloud URL and password",
165+
"CLOUD_LOGIN_FAILED": "Cloud login failed"
166+
164167
}

src/locales/zh.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,7 @@
161161
"INTRODUCTION": "介绍",
162162
"DETAIL_INTRODUCTION": "详细介绍",
163163
"SEE_MORE_INTRODUCTION": "查看更多介绍",
164-
"PLEASE_WAIT_FOR_TESTING": "请等待测试完成后再分享。"
164+
"PLEASE_WAIT_FOR_TESTING": "请等待测试完成后再分享。",
165+
"PLEASE_ENTER_CLOUD_URL_AND_PASSWORD": "请输入云端URL和密码",
166+
"CLOUD_LOGIN_FAILED": "云端登录失败"
165167
}

src/utils/svg.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export function createSVGDataURL(results, title) {
533533
// 绘制其他模型
534534
if (processedData.otherModels.length > 0) {
535535
y += lineHeight; // 空行
536-
svgContent += drawText(col1X, y, "🚀 其他模型:", "16", "#FFA500", "bold");
536+
svgContent += drawText(col1X, y, "🚀 普通模型:", "16", "#FFA500", "bold");
537537
y += lineHeight;
538538

539539
processedData.otherModels.forEach((r) => {

0 commit comments

Comments
 (0)