Skip to content

Commit 1874a35

Browse files
committed
✨ 增加UserConfig顺序
1 parent 553b944 commit 1874a35

6 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/app/repo/scripts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface Config {
3535
max?: number;
3636
min?: number;
3737
rows?: number; // textarea行数
38+
index: number; // 配置项排序位置
3839
}
3940

4041
export type UserConfig = { [key: string]: { [key: string]: Config } };

src/pages/components/UserConfigPanel/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ const UserConfigPanel: React.FC<{
4545
onOk={() => {
4646
if (formRefs.current[tab]) {
4747
const saveValues = formRefs.current[tab].getFieldsValue();
48-
console.log("saveValues", saveValues);
4948
// 更新value
5049
const valueClient = new ValueClient(message);
5150
Object.keys(saveValues).forEach((key) => {
@@ -72,6 +71,10 @@ const UserConfigPanel: React.FC<{
7271
>
7372
{Object.keys(userConfig).map((itemKey) => {
7473
const value = userConfig[itemKey];
74+
const keys = Object.keys(value).sort((a, b) => {
75+
return (value[a].index || 0) - (value[b].index || 0);
76+
});
77+
console.log("keys", value, keys);
7578
return (
7679
<TabPane key={itemKey} title={itemKey}>
7780
<Form
@@ -86,7 +89,7 @@ const UserConfigPanel: React.FC<{
8689
formRefs.current[itemKey] = el;
8790
}}
8891
>
89-
{Object.keys(value).map((key) => (
92+
{keys.map((key) => (
9093
<FormItem key={key} label={value[key].title} field={`${itemKey}.${key}`}>
9194
{() => {
9295
const item = value[key];

src/pages/options/routes/script/ScriptEditor.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,10 @@ function ScriptEditor() {
405405
useEffect(() => {
406406
// 防止开发模式下重复初始化
407407
if (initRef.current) {
408-
return;
408+
// 恢复标题
409+
return () => {
410+
document.title = "Home - ScriptCat";
411+
};
409412
}
410413
initRef.current = true;
411414

src/pkg/utils/yaml.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export function parseUserConfig(code: string): UserConfig | undefined {
1313
const obj: UserConfig = parse(val);
1414
Object.keys(obj || {}).forEach((key) => {
1515
ret[key] = obj[key];
16+
Object.keys(ret[key] || {}).forEach((subKey, subIndex) => {
17+
ret[key][subKey].index = ret[key][subKey].index || subIndex; // 确保index存在
18+
});
1619
});
1720
});
1821
return ret;

src/template/scriptcat.d.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare interface Config {
1717
max?: number;
1818
min?: number;
1919
rows?: number; // textarea行数
20+
index: number; // 配置项排序位置
2021
}
2122

2223
declare type UserConfig = { [key: string]: { [key: string]: Config } };

src/types/scriptcat.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare interface Config {
1717
max?: number;
1818
min?: number;
1919
rows?: number; // textarea行数
20+
index: number; // 配置项排序位置
2021
}
2122

2223
declare type UserConfig = { [key: string]: { [key: string]: Config } };

0 commit comments

Comments
 (0)