mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
fix: webui getConfig
This commit is contained in:
parent
78bad4842b
commit
6702024805
@ -8,6 +8,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
const isEmpty = (value: any) => value === undefined || value === undefined || value === '';
|
const isEmpty = (value: any) => value === undefined || value === undefined || value === '';
|
||||||
let ob11Config: OB11Config = await OB11ConfigWrapper.GetOB11Config();
|
let ob11Config: OB11Config = await OB11ConfigWrapper.GetOB11Config();
|
||||||
const setOB11Config = (key: string, value: any) => {
|
const setOB11Config = (key: string, value: any) => {
|
||||||
|
console.log(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
@ -19,9 +20,9 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
</setting-section>`,
|
</setting-section>`,
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">正在检查 Napcat 更新</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('请稍候', 'napcat-update-button', 'secondary'),
|
SettingButton('V1.3.0', 'napcat-update-button', 'secondary'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@ -102,40 +102,55 @@ const SettingSelect = (items, configKey, configValue) => {
|
|||||||
</ob-setting-select>`;
|
</ob-setting-select>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebUiApiWrapper {
|
class WebUiApiOB11ConfigWrapper {
|
||||||
token = "";
|
retCredential = "";
|
||||||
async setOB11Config(config) {
|
async Init(Credential) {
|
||||||
|
this.retCredential = Credential;
|
||||||
}
|
}
|
||||||
async getOB11Config() {
|
async GetOB11Config() {
|
||||||
return {
|
let ConfigResponse = await fetch("/api/OB11Config/GetConfig", {
|
||||||
httpHost: "",
|
method: "POST",
|
||||||
httpPort: 3e3,
|
headers: {
|
||||||
httpPostUrls: [],
|
"Authorization": "Bearer " + this.retCredential,
|
||||||
httpSecret: "",
|
"Content-Type": "application/json"
|
||||||
wsHost: "",
|
}
|
||||||
wsPort: 3e3,
|
});
|
||||||
wsReverseUrls: [],
|
if (ConfigResponse.status == 200) {
|
||||||
enableHttp: false,
|
let ConfigResponseJson = await ConfigResponse.json();
|
||||||
enableHttpHeart: false,
|
if (ConfigResponseJson.code == 0) {
|
||||||
enableHttpPost: false,
|
return ConfigResponseJson?.data;
|
||||||
enableWs: false,
|
}
|
||||||
enableWsReverse: false,
|
}
|
||||||
messagePostFormat: "array",
|
return {};
|
||||||
reportSelfMessage: false,
|
}
|
||||||
enableLocalFile2Url: false,
|
async SetOB11Config(config) {
|
||||||
debug: false,
|
let ConfigResponse = await fetch(
|
||||||
heartInterval: 6e4,
|
"/api/OB11Config/SetConfig",
|
||||||
token: "",
|
{
|
||||||
musicSignUrl: ""
|
method: "POST",
|
||||||
};
|
headers: {
|
||||||
|
"Authorization": "Bearer " + this.retCredential,
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(config)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (ConfigResponse.status == 200) {
|
||||||
|
let ConfigResponseJson = await ConfigResponse.json();
|
||||||
|
if (ConfigResponseJson.code == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const WebUiApi = new WebUiApiWrapper();
|
const OB11ConfigWrapper = new WebUiApiOB11ConfigWrapper();
|
||||||
|
|
||||||
async function onSettingWindowCreated(view) {
|
async function onSettingWindowCreated(view) {
|
||||||
const isEmpty = (value) => value === void 0 || value === void 0 || value === "";
|
const isEmpty = (value) => value === void 0 || value === void 0 || value === "";
|
||||||
let ob11Config = await WebUiApi.getOB11Config();
|
let ob11Config = await OB11ConfigWrapper.GetOB11Config();
|
||||||
const setOB11Config = (key, value) => {
|
const setOB11Config = (key, value) => {
|
||||||
|
console.log(key, value);
|
||||||
};
|
};
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(
|
const doc = parser.parseFromString(
|
||||||
@ -146,9 +161,9 @@ async function onSettingWindowCreated(view) {
|
|||||||
</setting-section>`,
|
</setting-section>`,
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">正在检查 Napcat 更新</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
void 0,
|
void 0,
|
||||||
SettingButton("请稍候", "napcat-update-button", "secondary")
|
SettingButton("V1.3.0", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
@ -261,8 +276,8 @@ async function onSettingWindowCreated(view) {
|
|||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem("GitHub 仓库", `https://github.com/`, SettingButton("点个星星", "open-github")),
|
SettingItem("GitHub 仓库", `https://github.com/NapNeko/NapCatQQ`, SettingButton("点个星星", "open-github")),
|
||||||
SettingItem("NapCat 文档", `https://`, SettingButton("看看文档", "open-docs")),
|
SettingItem("NapCat 文档", ``, SettingButton("看看文档", "open-docs")),
|
||||||
SettingItem("Telegram 群", `https://t.me/+nLZEnpne-pQ1OWFl`, SettingButton("进去逛逛", "open-telegram")),
|
SettingItem("Telegram 群", `https://t.me/+nLZEnpne-pQ1OWFl`, SettingButton("进去逛逛", "open-telegram")),
|
||||||
SettingItem("QQ 群", `545402644`, SettingButton("我要进去", "open-qq-group"))
|
SettingItem("QQ 群", `545402644`, SettingButton("我要进去", "open-qq-group"))
|
||||||
]),
|
]),
|
||||||
@ -271,7 +286,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
"text/html"
|
"text/html"
|
||||||
);
|
);
|
||||||
doc.querySelector("#open-github")?.addEventListener("click", () => {
|
doc.querySelector("#open-github")?.addEventListener("click", () => {
|
||||||
window.open("https://github.com/", "_blank");
|
window.open("https://napneko.github.io/", "_blank");
|
||||||
});
|
});
|
||||||
doc.querySelector("#open-telegram")?.addEventListener("click", () => {
|
doc.querySelector("#open-telegram")?.addEventListener("click", () => {
|
||||||
window.open("https://t.me/+nLZEnpne-pQ1OWFl");
|
window.open("https://t.me/+nLZEnpne-pQ1OWFl");
|
||||||
@ -280,7 +295,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
window.open("https://qm.qq.com/q/bDnHRG38aI");
|
window.open("https://qm.qq.com/q/bDnHRG38aI");
|
||||||
});
|
});
|
||||||
doc.querySelector("#open-docs")?.addEventListener("click", () => {
|
doc.querySelector("#open-docs")?.addEventListener("click", () => {
|
||||||
window.open("https://github.io/");
|
window.open("https://github.com/NapNeko/NapCatQQ");
|
||||||
});
|
});
|
||||||
const buildHostListItem = (type, host, index, inputAttrs = {}) => {
|
const buildHostListItem = (type, host, index, inputAttrs = {}) => {
|
||||||
const dom = {
|
const dom = {
|
||||||
@ -335,7 +350,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
doc.querySelectorAll("setting-switch[data-config-key]").forEach((dom) => {
|
doc.querySelectorAll("setting-switch[data-config-key]").forEach((dom) => {
|
||||||
dom.addEventListener("click", () => {
|
dom.addEventListener("click", () => {
|
||||||
const active = dom.getAttribute("is-active") === void 0;
|
const active = dom.getAttribute("is-active") === void 0;
|
||||||
setOB11Config(dom.dataset.configKey);
|
setOB11Config(dom.dataset.configKey, active);
|
||||||
if (active)
|
if (active)
|
||||||
dom.setAttribute("is-active", "");
|
dom.setAttribute("is-active", "");
|
||||||
else
|
else
|
||||||
@ -352,18 +367,20 @@ async function onSettingWindowCreated(view) {
|
|||||||
doc.querySelectorAll("setting-item .q-input input.q-input__inner[data-config-key]").forEach((dom) => {
|
doc.querySelectorAll("setting-item .q-input input.q-input__inner[data-config-key]").forEach((dom) => {
|
||||||
dom.addEventListener("input", () => {
|
dom.addEventListener("input", () => {
|
||||||
const Type = dom.getAttribute("type");
|
const Type = dom.getAttribute("type");
|
||||||
dom.dataset.configKey;
|
const configKey = dom.dataset.configKey;
|
||||||
Type === "number" ? parseInt(dom.value) >= 1 ? parseInt(dom.value) : 1 : dom.value;
|
const configValue = Type === "number" ? parseInt(dom.value) >= 1 ? parseInt(dom.value) : 1 : dom.value;
|
||||||
|
setOB11Config(configKey, configValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
doc.querySelectorAll("ob-setting-select[data-config-key]").forEach((dom) => {
|
doc.querySelectorAll("ob-setting-select[data-config-key]").forEach((dom) => {
|
||||||
dom?.addEventListener("selected", (e) => {
|
dom?.addEventListener("selected", (e) => {
|
||||||
dom.dataset.configKey;
|
const configKey = dom.dataset.configKey;
|
||||||
e.detail.value;
|
const configValue = e.detail.value;
|
||||||
|
setOB11Config(configKey, configValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
doc.querySelector("#config-ob11-save")?.addEventListener("click", () => {
|
doc.querySelector("#config-ob11-save")?.addEventListener("click", () => {
|
||||||
WebUiApi.setOB11Config(ob11Config);
|
OB11ConfigWrapper.SetOB11Config(ob11Config);
|
||||||
alert("保存成功");
|
alert("保存成功");
|
||||||
});
|
});
|
||||||
doc.body.childNodes.forEach((node) => {
|
doc.body.childNodes.forEach((node) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user