Skip to content

Commit f1ee723

Browse files
committed
🐛 修复userConfig默认值问题 #409
1 parent d0c2f3b commit f1ee723

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

src/app/service/service_worker/value.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,29 @@ export class ValueService {
2929
}
3030

3131
async getScriptValue(script: Script) {
32+
let data: { [key: string]: any } = {};
3233
const ret = await this.valueDAO.get(getStorageName(script));
33-
if (!ret) {
34-
return {};
34+
if (ret) {
35+
data = ret.data;
3536
}
36-
return ret.data;
37+
const newValues = data;
38+
// 和userconfig组装
39+
const { config } = script;
40+
if (config) {
41+
Object.keys(config).forEach((tabKey) => {
42+
const tab = config![tabKey];
43+
Object.keys(tab).forEach((key) => {
44+
// 动态变量
45+
if (tab[key].bind) {
46+
const bindKey = tab[key].bind!.substring(1);
47+
newValues[bindKey] = data[bindKey] === undefined ? undefined : data[bindKey];
48+
}
49+
newValues[`${tabKey}.${key}`] =
50+
data[`${tabKey}.${key}`] === undefined ? config![tabKey][key].default : data[`${tabKey}.${key}`];
51+
});
52+
});
53+
}
54+
return newValues;
3755
}
3856

3957
async setValue(uuid: string, key: string, value: any, sender: ValueUpdateSender) {

src/pages/options/routes/SubscribeList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from "react";
1+
import { useEffect, useRef, useState } from "react";
22
import Text from "@arco-design/web-react/es/Typography/text";
33
import { Button, Card, Input, Message, Popconfirm, Switch, Table, Tag, Tooltip } from "@arco-design/web-react";
44
import { Subscribe, SUBSCRIBE_STATUS_DISABLE, SUBSCRIBE_STATUS_ENABLE, SubscribeDAO } from "@App/app/repo/subscribe";

0 commit comments

Comments
 (0)