mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-09 13:03:37 +08:00
refactor: webui 跟进 Onebot 配置重构
This commit is contained in:
parent
966a00f41e
commit
17ed3692d0
@ -3,23 +3,26 @@ import { SettingItem } from "./components/SettingItem";
|
|||||||
import { SettingButton } from "./components/SettingButton";
|
import { SettingButton } from "./components/SettingButton";
|
||||||
import { SettingSwitch } from "./components/SettingSwitch";
|
import { SettingSwitch } from "./components/SettingSwitch";
|
||||||
import { SettingSelect } from "./components/SettingSelect";
|
import { SettingSelect } from "./components/SettingSelect";
|
||||||
import { OB11Config, OB11ConfigWrapper } from "./components/WebUiApiOB11Config"
|
import { OB11Config, OB11ConfigWrapper } from "./components/WebUiApiOB11Config";
|
||||||
async function onSettingWindowCreated(view: Element) {
|
async function onSettingWindowCreated(view: Element) {
|
||||||
const isEmpty = (value: any) => value === undefined || value === undefined || value === '';
|
const isEmpty = (value: any) =>
|
||||||
await OB11ConfigWrapper.Init(localStorage.getItem('auth') as string);
|
value === undefined || value === undefined || value === "";
|
||||||
|
await OB11ConfigWrapper.Init(localStorage.getItem("auth") as string);
|
||||||
let ob11Config: OB11Config = await OB11ConfigWrapper.GetOB11Config();
|
let ob11Config: OB11Config = await OB11ConfigWrapper.GetOB11Config();
|
||||||
const setOB11Config = (key: string, value: any) => {
|
const setOB11Config = (key: string, value: any) => {
|
||||||
const configKey = key.split('.');
|
const configKey = key.split(".");
|
||||||
if (configKey.length === 2) {
|
if (configKey.length === 2) {
|
||||||
ob11Config[configKey[1]] = value;
|
ob11Config[configKey[1]] = value;
|
||||||
|
} else if (configKey.length === 3) {
|
||||||
|
ob11Config[configKey[1]][configKey[2]] = value;
|
||||||
}
|
}
|
||||||
OB11ConfigWrapper.SetOB11Config(ob11Config);
|
OB11ConfigWrapper.SetOB11Config(ob11Config);
|
||||||
}
|
};
|
||||||
|
|
||||||
const parser = new DOMParser();
|
const parser = new DOMParser();
|
||||||
const doc = parser.parseFromString(
|
const doc = parser.parseFromString(
|
||||||
[
|
[
|
||||||
'<div>',
|
"<div>",
|
||||||
`<setting-section id="napcat-error">
|
`<setting-section id="napcat-error">
|
||||||
<setting-panel><pre><code></code></pre></setting-panel>
|
<setting-panel><pre><code></code></pre></setting-panel>
|
||||||
</setting-section>`,
|
</setting-section>`,
|
||||||
@ -27,271 +30,341 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('V1.3.5', 'napcat-update-button', 'secondary'),
|
SettingButton("V1.3.5", "napcat-update-button", "secondary")
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'启用 HTTP 服务',
|
"启用 HTTP 服务",
|
||||||
undefined,
|
undefined,
|
||||||
SettingSwitch('ob11.http.enable', ob11Config.http.enable, { 'control-display-id': 'config-ob11-httpPort' }),
|
SettingSwitch("ob11.http.enable", ob11Config.http.enable, {
|
||||||
|
"control-display-id": "config-ob11-http.port",
|
||||||
|
})
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'HTTP 服务监听端口',
|
"HTTP 服务监听端口",
|
||||||
undefined,
|
undefined,
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.httpPort" type="number" min="1" max="65534" value="${ob11Config.httpPort}" placeholder="${ob11Config.httpPort}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.http.port" type="number" min="1" max="65534" value="${ob11Config.http.port}" placeholder="${ob11Config.http.port}" /></div>`,
|
||||||
'config-ob11-httpPort',
|
"config-ob11-http.port",
|
||||||
ob11Config.http.enable,
|
ob11Config.http.enable
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'启用 HTTP 心跳',
|
"启用 HTTP 心跳",
|
||||||
undefined,
|
undefined,
|
||||||
SettingSwitch('ob11.http.enableHeart', ob11Config.http.enableHeart, {
|
SettingSwitch("ob11.http.enableHeart", ob11Config.http.enableHeart, {
|
||||||
'control-display-id': 'config-ob11-enableHttpHeart',
|
"control-display-id": "config-ob11-HTTP.enableHeart",
|
||||||
}),
|
})
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'启用 HTTP 事件上报',
|
"启用 HTTP 事件上报",
|
||||||
undefined,
|
undefined,
|
||||||
SettingSwitch('ob11.http.enablePost', ob11Config.http.enablePost, {
|
SettingSwitch("ob11.http.enablePost", ob11Config.http.enablePost, {
|
||||||
'control-display-id': 'config-ob11-httpPostUrls',
|
"control-display-id": "config-ob11-http.postUrls",
|
||||||
}),
|
})
|
||||||
),
|
),
|
||||||
`<div class="config-host-list" id="config-ob11-httpPostUrls" ${ob11Config.http.enablePost ? '' : 'is-hidden'}>
|
`<div class="config-host-list" id="config-ob11-http.postUrls" ${
|
||||||
|
ob11Config.http.enablePost ? "" : "is-hidden"
|
||||||
|
}>
|
||||||
<setting-item data-direction="row">
|
<setting-item data-direction="row">
|
||||||
<div>
|
<div>
|
||||||
<setting-text>HTTP 事件上报密钥</setting-text>
|
<setting-text>HTTP 事件上报密钥</setting-text>
|
||||||
</div>
|
</div>
|
||||||
<div class="q-input">
|
<div class="q-input">
|
||||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.http.secret" type="text" value="${ob11Config.http.secret
|
<input id="config-ob11-http.secret" class="q-input__inner" data-config-key="ob11.http.secret" type="text" value="${
|
||||||
}" placeholder="未设置" />
|
ob11Config.http.secret
|
||||||
|
}" placeholder="未设置" />
|
||||||
</div>
|
</div>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<setting-item data-direction="row">
|
<setting-item data-direction="row">
|
||||||
<div>
|
<div>
|
||||||
<setting-text>HTTP 事件上报地址</setting-text>
|
<setting-text>HTTP 事件上报地址</setting-text>
|
||||||
</div>
|
</div>
|
||||||
<setting-button id="config-ob11-httpPostUrls-add" data-type="primary">添加</setting-button>
|
<setting-button id="config-ob11-http.postUrls-add" data-type="primary">添加</setting-button>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<div id="config-ob11-httpPostUrls-list"></div>
|
<div id="config-ob11-http.postUrls-list"></div>
|
||||||
</div>`,
|
</div>`,
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'启用正向 WebSocket 服务',
|
"启用正向 WebSocket 服务",
|
||||||
undefined,
|
undefined,
|
||||||
SettingSwitch('ob11.enableWs', ob11Config.enableWs, { 'control-display-id': 'config-ob11-wsPort' }),
|
SettingSwitch("ob11.ws.enable", ob11Config.ws.enable, {
|
||||||
|
"control-display-id": "config-ob11-ws.port",
|
||||||
|
})
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'正向 WebSocket 服务监听端口',
|
"正向 WebSocket 服务监听端口",
|
||||||
undefined,
|
undefined,
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.wsPort" type="number" min="1" max="65534" value="${ob11Config.wsPort}" placeholder="${ob11Config.wsPort}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.ws.port" type="number" min="1" max="65534" value="${ob11Config.ws.port}" placeholder="${ob11Config.ws.port}" /></div>`,
|
||||||
'config-ob11-wsPort',
|
"config-ob11-ws.port",
|
||||||
ob11Config.enableWs,
|
ob11Config.ws.enable
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'启用反向 WebSocket 服务',
|
"启用反向 WebSocket 服务",
|
||||||
undefined,
|
undefined,
|
||||||
SettingSwitch('ob11.enableWsReverse', ob11Config.enableWsReverse, {
|
SettingSwitch("ob11.reverseWs.enable", ob11Config.reverseWs.enable, {
|
||||||
'control-display-id': 'config-ob11-wsReverseUrls',
|
"control-display-id": "config-ob11-reverseWs.urls",
|
||||||
}),
|
})
|
||||||
),
|
),
|
||||||
`<div class="config-host-list" id="config-ob11-wsReverseUrls" ${ob11Config.enableWsReverse ? '' : 'is-hidden'}>
|
`<div class="config-host-list" id="config-ob11-reverseWs.urls" ${
|
||||||
|
ob11Config.reverseWs.enable ? "" : "is-hidden"
|
||||||
|
}>
|
||||||
<setting-item data-direction="row">
|
<setting-item data-direction="row">
|
||||||
<div>
|
<div>
|
||||||
<setting-text>反向 WebSocket 监听地址</setting-text>
|
<setting-text>反向 WebSocket 监听地址</setting-text>
|
||||||
</div>
|
</div>
|
||||||
<setting-button id="config-ob11-wsReverseUrls-add" data-type="primary">添加</setting-button>
|
<setting-button id="config-ob11-reverseWs.urls-add" data-type="primary">添加</setting-button>
|
||||||
</setting-item>
|
</setting-item>
|
||||||
<div id="config-ob11-wsReverseUrls-list"></div>
|
<div id="config-ob11-reverseWs.urls-list"></div>
|
||||||
</div>`,
|
</div>`,
|
||||||
SettingItem(
|
SettingItem(
|
||||||
' WebSocket 服务心跳间隔',
|
" WebSocket 服务心跳间隔",
|
||||||
'控制每隔多久发送一个心跳包,单位为毫秒',
|
"控制每隔多久发送一个心跳包,单位为毫秒",
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.heartInterval" type="number" min="1000" value="${ob11Config.heartInterval}" placeholder="${ob11Config.heartInterval}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="ob11.heartInterval" type="number" min="1000" value="${ob11Config.heartInterval}" placeholder="${ob11Config.heartInterval}" /></div>`
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'Access token',
|
"Access token",
|
||||||
undefined,
|
undefined,
|
||||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.token" type="text" value="${ob11Config.token}" placeholder="未设置" /></div>`,
|
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.token" type="text" value="${ob11Config.token}" placeholder="未设置" /></div>`
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'新消息上报格式',
|
"新消息上报格式",
|
||||||
'如客户端无特殊需求推荐保持默认设置,两者的详细差异可参考 <a href="javascript:LiteLoader.api.openExternal(\'https://github.com/botuniverse/onebot-11/tree/master/message#readme\');">OneBot v11 文档</a>',
|
"如客户端无特殊需求推荐保持默认设置,两者的详细差异可参考 <a href=\"javascript:LiteLoader.api.openExternal('https://github.com/botuniverse/onebot-11/tree/master/message#readme');\">OneBot v11 文档</a>",
|
||||||
SettingSelect(
|
SettingSelect(
|
||||||
[
|
[
|
||||||
{ text: '消息段', value: 'array' },
|
{ text: "消息段", value: "array" },
|
||||||
{ text: 'CQ码', value: 'string' },
|
{ text: "CQ码", value: "string" },
|
||||||
],
|
],
|
||||||
'ob11.messagePostFormat',
|
"ob11.messagePostFormat",
|
||||||
ob11Config.messagePostFormat,
|
ob11Config.messagePostFormat
|
||||||
),
|
)
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'音乐卡片签名地址',
|
"音乐卡片签名地址",
|
||||||
undefined,
|
undefined,
|
||||||
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.musicSignUrl" type="text" value="${ob11Config.musicSignUrl}" placeholder="未设置" /></div>`,
|
`<div class="q-input" style="width:210px;"><input class="q-input__inner" data-config-key="ob11.musicSignUrl" type="text" value="${ob11Config.musicSignUrl}" placeholder="未设置" /></div>`,
|
||||||
'ob11.musicSignUrl',
|
"ob11.musicSignUrl"
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
"",
|
||||||
|
undefined,
|
||||||
|
SettingButton("保存", "config-ob11-save", "primary")
|
||||||
),
|
),
|
||||||
SettingItem('', undefined, SettingButton('保存', 'config-ob11-save', 'primary')),
|
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'上报 Bot 自身发送的消息',
|
"上报 Bot 自身发送的消息",
|
||||||
'上报 event 为 message_sent',
|
"上报 event 为 message_sent",
|
||||||
SettingSwitch('ob11.reportSelfMessage', ob11Config.reportSelfMessage),
|
SettingSwitch("ob11.reportSelfMessage", ob11Config.reportSelfMessage)
|
||||||
)
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem('GitHub 仓库', `https://github.com/NapNeko/NapCatQQ`, SettingButton('点个星星', 'open-github')),
|
SettingItem(
|
||||||
SettingItem('NapCat 文档', ``, SettingButton('看看文档', 'open-docs')),
|
"GitHub 仓库",
|
||||||
SettingItem('Telegram 群', `https://t.me/+nLZEnpne-pQ1OWFl`, SettingButton('进去逛逛', 'open-telegram')),
|
`https://github.com/NapNeko/NapCatQQ`,
|
||||||
SettingItem('QQ 群', `545402644`, SettingButton('我要进去', 'open-qq-group')),
|
SettingButton("点个星星", "open-github")
|
||||||
|
),
|
||||||
|
SettingItem("NapCat 文档", ``, SettingButton("看看文档", "open-docs")),
|
||||||
|
SettingItem(
|
||||||
|
"Telegram 群",
|
||||||
|
`https://t.me/+nLZEnpne-pQ1OWFl`,
|
||||||
|
SettingButton("进去逛逛", "open-telegram")
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
"QQ 群",
|
||||||
|
`545402644`,
|
||||||
|
SettingButton("我要进去", "open-qq-group")
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
'</div>',
|
"</div>",
|
||||||
].join(''),
|
].join(""),
|
||||||
'text/html',
|
"text/html"
|
||||||
)
|
);
|
||||||
|
|
||||||
// 外链按钮
|
// 外链按钮
|
||||||
doc.querySelector('#open-github')?.addEventListener('click', () => {
|
doc.querySelector("#open-github")?.addEventListener("click", () => {
|
||||||
window.open("https://napneko.github.io/", '_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");
|
||||||
})
|
});
|
||||||
doc.querySelector('#open-qq-group')?.addEventListener('click', () => {
|
doc.querySelector("#open-qq-group")?.addEventListener("click", () => {
|
||||||
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.com/NapNeko/NapCatQQ')
|
window.open("https://github.com/NapNeko/NapCatQQ");
|
||||||
})
|
});
|
||||||
// 生成反向地址列表
|
// 生成反向地址列表
|
||||||
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any = {}) => {
|
const buildHostListItem = (
|
||||||
|
type: string,
|
||||||
|
host: string,
|
||||||
|
index: number,
|
||||||
|
inputAttrs: any = {}
|
||||||
|
) => {
|
||||||
const dom = {
|
const dom = {
|
||||||
container: document.createElement('setting-item'),
|
container: document.createElement("setting-item"),
|
||||||
input: document.createElement('input'),
|
input: document.createElement("input"),
|
||||||
inputContainer: document.createElement('div'),
|
inputContainer: document.createElement("div"),
|
||||||
deleteBtn: document.createElement('setting-button'),
|
deleteBtn: document.createElement("setting-button"),
|
||||||
}
|
};
|
||||||
dom.container.classList.add('setting-host-list-item')
|
dom.container.classList.add("setting-host-list-item");
|
||||||
dom.container.dataset.direction = 'row'
|
dom.container.dataset.direction = "row";
|
||||||
Object.assign(dom.input, inputAttrs)
|
Object.assign(dom.input, inputAttrs);
|
||||||
dom.input.classList.add('q-input__inner')
|
dom.input.classList.add("q-input__inner");
|
||||||
dom.input.type = 'url'
|
dom.input.type = "url";
|
||||||
dom.input.value = host
|
dom.input.value = host;
|
||||||
dom.input.addEventListener('input', () => {
|
dom.input.addEventListener("input", () => {
|
||||||
ob11Config[type][index] = dom.input.value
|
ob11Config[type.split(".")[0]][type.split(".")[-1]][index] =
|
||||||
})
|
dom.input.value;
|
||||||
|
});
|
||||||
|
|
||||||
dom.inputContainer.classList.add('q-input')
|
dom.inputContainer.classList.add("q-input");
|
||||||
dom.inputContainer.appendChild(dom.input)
|
dom.inputContainer.appendChild(dom.input);
|
||||||
|
|
||||||
dom.deleteBtn.innerHTML = '删除'
|
dom.deleteBtn.innerHTML = "删除";
|
||||||
dom.deleteBtn.dataset.type = 'secondary'
|
dom.deleteBtn.dataset.type = "secondary";
|
||||||
dom.deleteBtn.addEventListener('click', () => {
|
dom.deleteBtn.addEventListener("click", () => {
|
||||||
ob11Config[type].splice(index, 1)
|
ob11Config[type.split(".")[0]][type.split(".")[-1]].splice(index, 1);
|
||||||
initReverseHost(type)
|
initReverseHost(type);
|
||||||
})
|
});
|
||||||
|
|
||||||
dom.container.appendChild(dom.inputContainer)
|
dom.container.appendChild(dom.inputContainer);
|
||||||
dom.container.appendChild(dom.deleteBtn)
|
dom.container.appendChild(dom.deleteBtn);
|
||||||
|
|
||||||
return dom.container
|
return dom.container;
|
||||||
}
|
};
|
||||||
const buildHostList = (hosts: string[], type: string, inputAttr: any = {}) => {
|
const buildHostList = (
|
||||||
const result: HTMLElement[] = []
|
hosts: string[],
|
||||||
|
type: string,
|
||||||
|
inputAttr: any = {}
|
||||||
|
) => {
|
||||||
|
const result: HTMLElement[] = [];
|
||||||
|
|
||||||
hosts.forEach((host, index) => {
|
hosts.forEach((host, index) => {
|
||||||
result.push(buildHostListItem(type, host, index, inputAttr))
|
result.push(buildHostListItem(type, host, index, inputAttr));
|
||||||
})
|
});
|
||||||
|
|
||||||
return result
|
return result;
|
||||||
}
|
};
|
||||||
const addReverseHost = (type: string, doc: Document = document, inputAttr: any = {}) => {
|
const addReverseHost = (
|
||||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`);
|
type: string,
|
||||||
hostContainerDom?.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr));
|
doc: Document = document,
|
||||||
ob11Config[type].push('');
|
inputAttr: any = {}
|
||||||
}
|
) => {
|
||||||
|
const hostContainerDom = doc.body.querySelector(
|
||||||
|
`#config-ob11-${type}-list`
|
||||||
|
);
|
||||||
|
hostContainerDom?.appendChild(
|
||||||
|
buildHostListItem(
|
||||||
|
type,
|
||||||
|
"",
|
||||||
|
ob11Config[type.split(".")[0]][type.split(".")[-1]].length,
|
||||||
|
inputAttr
|
||||||
|
)
|
||||||
|
);
|
||||||
|
ob11Config[type.split(".")[0]][type.split(".")[-1]].push("");
|
||||||
|
};
|
||||||
const initReverseHost = (type: string, doc: Document = document) => {
|
const initReverseHost = (type: string, doc: Document = document) => {
|
||||||
const hostContainerDom = doc.body?.querySelector(`#config-ob11-${type}-list`);
|
const hostContainerDom = doc.body?.querySelector(
|
||||||
|
`#config-ob11-${type}-list`
|
||||||
|
);
|
||||||
if (hostContainerDom) {
|
if (hostContainerDom) {
|
||||||
[...hostContainerDom.childNodes].forEach((dom) => dom.remove());
|
[...hostContainerDom.childNodes].forEach((dom) => dom.remove());
|
||||||
buildHostList(ob11Config[type], type).forEach((dom) => {
|
buildHostList(
|
||||||
|
ob11Config[type.split(".")[0]][type.split(".")[-1]],
|
||||||
|
type
|
||||||
|
).forEach((dom) => {
|
||||||
hostContainerDom?.appendChild(dom);
|
hostContainerDom?.appendChild(dom);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
initReverseHost('httpPostUrls', doc);
|
initReverseHost("http.postUrls", doc);
|
||||||
initReverseHost('wsReverseUrls', doc);
|
initReverseHost("reverseWs.urls", doc);
|
||||||
|
|
||||||
doc
|
doc
|
||||||
.querySelector('#config-ob11-httpPostUrls-add')
|
.querySelector("#config-ob11-http.postUrls-add")
|
||||||
?.addEventListener('click', () =>
|
?.addEventListener("click", () =>
|
||||||
addReverseHost('httpPostUrls', document, { placeholder: '如:http://127.0.0.1:5140/onebot' }),
|
addReverseHost("http.postUrls", document, {
|
||||||
)
|
placeholder: "如:http://127.0.0.1:5140/onebot",
|
||||||
|
})
|
||||||
|
);
|
||||||
doc
|
doc
|
||||||
.querySelector('#config-ob11-wsReverseUrls-add')
|
.querySelector("#config-ob11-reverseWs.urls-add")
|
||||||
?.addEventListener('click', () =>
|
?.addEventListener("click", () =>
|
||||||
addReverseHost('wsReverseUrls', document, { placeholder: '如:ws://127.0.0.1:5140/onebot' }),
|
addReverseHost("reverseWs.urls", document, {
|
||||||
)
|
placeholder: "如:ws://127.0.0.1:5140/onebot",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
doc.querySelector('#config-ffmpeg-select')?.addEventListener('click', () => {
|
doc.querySelector("#config-ffmpeg-select")?.addEventListener("click", () => {
|
||||||
//选择ffmpeg
|
//选择ffmpeg
|
||||||
})
|
});
|
||||||
|
|
||||||
doc.querySelector('#config-open-log-path')?.addEventListener('click', () => {
|
doc.querySelector("#config-open-log-path")?.addEventListener("click", () => {
|
||||||
//打开日志
|
//打开日志
|
||||||
})
|
});
|
||||||
|
|
||||||
// 开关
|
// 开关
|
||||||
doc.querySelectorAll('setting-switch[data-config-key]').forEach((dom: Element) => {
|
doc
|
||||||
dom.addEventListener('click', () => {
|
.querySelectorAll("setting-switch[data-config-key]")
|
||||||
const active = dom.getAttribute('is-active') == undefined;
|
.forEach((dom: Element) => {
|
||||||
//@ts-ignore 扩展
|
dom.addEventListener("click", () => {
|
||||||
setOB11Config(dom.dataset.configKey, active)
|
const active = dom.getAttribute("is-active") == undefined;
|
||||||
if (active) dom.setAttribute('is-active', '')
|
//@ts-ignore 扩展
|
||||||
else dom.removeAttribute('is-active')
|
setOB11Config(dom.dataset.configKey, active);
|
||||||
//@ts-ignore 等待修复
|
if (active) dom.setAttribute("is-active", "");
|
||||||
if (!isEmpty(dom.dataset.controlDisplayId)) {
|
else dom.removeAttribute("is-active");
|
||||||
//@ts-ignore 等待修复
|
//@ts-ignore 等待修复
|
||||||
const displayDom = document.querySelector(`#${dom.dataset.controlDisplayId}`)
|
if (!isEmpty(dom.dataset.controlDisplayId)) {
|
||||||
if (active) displayDom?.removeAttribute('is-hidden')
|
//@ts-ignore 等待修复
|
||||||
else displayDom?.setAttribute('is-hidden', '')
|
const displayDom = document.querySelector(
|
||||||
}
|
`#${dom.dataset.controlDisplayId}`
|
||||||
})
|
);
|
||||||
})
|
if (active) displayDom?.removeAttribute("is-hidden");
|
||||||
|
else displayDom?.setAttribute("is-hidden", "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 输入框
|
// 输入框
|
||||||
doc
|
doc
|
||||||
.querySelectorAll('setting-item .q-input input.q-input__inner[data-config-key]')
|
.querySelectorAll(
|
||||||
|
"setting-item .q-input input.q-input__inner[data-config-key]"
|
||||||
|
)
|
||||||
.forEach((dom: Element) => {
|
.forEach((dom: Element) => {
|
||||||
dom.addEventListener('input', () => {
|
dom.addEventListener("input", () => {
|
||||||
const Type = dom.getAttribute('type')
|
const Type = dom.getAttribute("type");
|
||||||
//@ts-ignore 等待修复
|
//@ts-ignore 等待修复
|
||||||
const configKey = dom.dataset.configKey
|
const configKey = dom.dataset.configKey;
|
||||||
const configValue = Type === 'number' ? (parseInt((dom as HTMLInputElement).value) >= 1 ? parseInt((dom as HTMLInputElement).value) : 1) : (dom as HTMLInputElement).value
|
const configValue =
|
||||||
|
Type === "number"
|
||||||
|
? parseInt((dom as HTMLInputElement).value) >= 1
|
||||||
|
? parseInt((dom as HTMLInputElement).value)
|
||||||
|
: 1
|
||||||
|
: (dom as HTMLInputElement).value;
|
||||||
|
|
||||||
setOB11Config(configKey, configValue)
|
setOB11Config(configKey, configValue);
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// 下拉框
|
// 下拉框
|
||||||
doc.querySelectorAll('ob-setting-select[data-config-key]').forEach((dom: Element) => {
|
doc
|
||||||
//@ts-ignore 等待修复
|
.querySelectorAll("ob-setting-select[data-config-key]")
|
||||||
dom?.addEventListener('selected', (e: CustomEvent) => {
|
.forEach((dom: Element) => {
|
||||||
//@ts-ignore 等待修复
|
//@ts-ignore 等待修复
|
||||||
const configKey = dom.dataset.configKey
|
dom?.addEventListener("selected", (e: CustomEvent) => {
|
||||||
const configValue = e.detail.value
|
//@ts-ignore 等待修复
|
||||||
setOB11Config(configKey, configValue);
|
const configKey = dom.dataset.configKey;
|
||||||
})
|
const configValue = e.detail.value;
|
||||||
})
|
setOB11Config(configKey, configValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// 保存按钮
|
// 保存按钮
|
||||||
doc.querySelector('#config-ob11-save')?.addEventListener('click', () => {
|
doc.querySelector("#config-ob11-save")?.addEventListener("click", () => {
|
||||||
OB11ConfigWrapper.SetOB11Config(ob11Config);
|
OB11ConfigWrapper.SetOB11Config(ob11Config);
|
||||||
alert('保存成功');
|
alert("保存成功");
|
||||||
})
|
});
|
||||||
doc.body.childNodes.forEach((node) => {
|
doc.body.childNodes.forEach((node) => {
|
||||||
view.appendChild(node)
|
view.appendChild(node);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
export { onSettingWindowCreated };
|
export { onSettingWindowCreated };
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user