432
432
bordered
433
433
style =" width : 100% ;"
434
434
item-layout =" horizontal"
435
+ :style =" localListStyle"
435
436
>
436
437
<template #renderItem =" { item } " >
437
438
<a-list-item >
500
501
bordered
501
502
style =" width : 100% ;"
502
503
item-layout =" horizontal"
504
+ :style =" cloudListStyle"
503
505
>
504
506
<template #renderItem =" { item } " >
505
507
<a-list-item >
@@ -1135,7 +1137,8 @@ async function getModelList() {
1135
1137
spinning .value = true ; // 开始加载动画
1136
1138
try {
1137
1139
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 ();
1139
1142
showModelModal .value = true ;
1140
1143
} catch (error) {
1141
1144
console .error (' Error in getModelList:' , error);
@@ -1784,6 +1787,22 @@ const cloudPassword = ref('');
1784
1787
let cloudAuthHeader = ' ' ; // 存储 Authorization 头的值
1785
1788
const cloudDataList = ref ([]);
1786
1789
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
+
1787
1806
// 本地缓存相关状态
1788
1807
const settingsApiUrl = ref (' ' );
1789
1808
const settingsApiKey = ref (' ' );
@@ -1907,39 +1926,42 @@ function importLocalCache() {
1907
1926
reader .onload = (event ) => {
1908
1927
try {
1909
1928
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' ));
1943
1965
} catch (error) {
1944
1966
message .error (t (' IMPORT_PARSE_ERROR' ));
1945
1967
console .error (error);
@@ -1950,6 +1972,7 @@ function importLocalCache() {
1950
1972
input .click ();
1951
1973
}
1952
1974
1975
+
1953
1976
function normalizeUrl (url ) {
1954
1977
return url .replace (/ \/ + $ / , ' ' ).toLowerCase ();
1955
1978
}
@@ -2118,38 +2141,42 @@ function importCloudCache() {
2118
2141
reader .onload = (event ) => {
2119
2142
try {
2120
2143
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' ));
2153
2180
} catch (error) {
2154
2181
message .error (t (' IMPORT_PARSE_ERROR' ));
2155
2182
console .error (error);
@@ -3234,5 +3261,26 @@ body.light-mode {
3234
3261
.announcement-collapse li {
3235
3262
margin : 4px 0 ;
3236
3263
}
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
+
3237
3285
</style >
3238
3286
0 commit comments