page
Some checks failed
test / Run tests (push) Failing after 12s
build / Build (push) Failing after 21s
Some checks failed
test / Run tests (push) Failing after 12s
build / Build (push) Failing after 21s
This commit is contained in:
parent
fcd4682aff
commit
0a025f1b50
@ -92,12 +92,12 @@ export default defineConfig({
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "asset",
|
type: "asset/source",
|
||||||
test: /\.d\.ts$/,
|
test: /\.d\.ts$/,
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "asset",
|
type: "asset/source",
|
||||||
test: /\.tpl$/,
|
test: /\.tpl$/,
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
},
|
},
|
||||||
|
@ -91,6 +91,10 @@ export class ScriptDAO extends Repo<Script> {
|
|||||||
return super._save(val.uuid, val);
|
return super._save(val.uuid, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findByUUID(uuid: string) {
|
||||||
|
return this.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
getAndCode(uuid: string): Promise<ScriptAndCode | undefined> {
|
getAndCode(uuid: string): Promise<ScriptAndCode | undefined> {
|
||||||
return Promise.all([this.get(uuid), this.scriptCodeDAO.get(uuid)]).then(([script, code]) => {
|
return Promise.all([this.get(uuid), this.scriptCodeDAO.get(uuid)]).then(([script, code]) => {
|
||||||
if (!script || !code) {
|
if (!script || !code) {
|
||||||
@ -131,6 +135,10 @@ export class ScriptCodeDAO extends Repo<ScriptCode> {
|
|||||||
super("scriptCode");
|
super("scriptCode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findByUUID(uuid: string) {
|
||||||
|
return this.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
public save(val: ScriptCode) {
|
public save(val: ScriptCode) {
|
||||||
return super._save(val.uuid, val);
|
return super._save(val.uuid, val);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
Layout,
|
Layout,
|
||||||
Menu,
|
Menu,
|
||||||
Message,
|
|
||||||
Modal,
|
Modal,
|
||||||
Space,
|
Space,
|
||||||
Typography,
|
Typography,
|
||||||
@ -88,31 +87,31 @@ const MainLayout: React.FC<{
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
const el = document.getElementById("import-local");
|
const el = document.getElementById("import-local");
|
||||||
el!.onchange = (e: Event) => {
|
el!.onchange = (e: Event) => {
|
||||||
const scriptCtl = IoC.instance(ScriptController) as ScriptController;
|
// const scriptCtl = IoC.instance(ScriptController) as ScriptController;
|
||||||
try {
|
// try {
|
||||||
// 获取文件
|
// // 获取文件
|
||||||
// @ts-ignore
|
// // @ts-ignore
|
||||||
const file = e.target.files[0];
|
// const file = e.target.files[0];
|
||||||
// 实例化 FileReader对象
|
// // 实例化 FileReader对象
|
||||||
const reader = new FileReader();
|
// const reader = new FileReader();
|
||||||
reader.onload = async (processEvent) => {
|
// reader.onload = async (processEvent) => {
|
||||||
// 创建blob url
|
// // 创建blob url
|
||||||
const blob = new Blob(
|
// const blob = new Blob(
|
||||||
// @ts-ignore
|
// // @ts-ignore
|
||||||
[processEvent.target!.result],
|
// [processEvent.target!.result],
|
||||||
{
|
// {
|
||||||
type: "application/javascript",
|
// type: "application/javascript",
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
const url = URL.createObjectURL(blob);
|
// const url = URL.createObjectURL(blob);
|
||||||
await scriptCtl.importByUrl(url);
|
// await scriptCtl.importByUrl(url);
|
||||||
Message.success(t("import_local_success"));
|
// Message.success(t("import_local_success"));
|
||||||
};
|
// };
|
||||||
// 调用readerAsText方法读取文本
|
// // 调用readerAsText方法读取文本
|
||||||
reader.readAsText(file);
|
// reader.readAsText(file);
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
Message.error(`${t("import_local_failure")}: ${e}`);
|
// Message.error(`${t("import_local_failure")}: ${e}`);
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
el!.click();
|
el!.click();
|
||||||
}}
|
}}
|
||||||
|
@ -194,7 +194,7 @@ const Sider: React.FC = () => {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route index element={<ScriptList />} />
|
<Route index element={<ScriptList />} />
|
||||||
<Route path="/script/editor">
|
<Route path="/script/editor">
|
||||||
<Route path=":id" element={<ScriptEditor />} />
|
<Route path=":uuid" element={<ScriptEditor />} />
|
||||||
<Route path="" element={<ScriptEditor />} />
|
<Route path="" element={<ScriptEditor />} />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/subscribe" element={<SubscribeList />} />
|
<Route path="/subscribe" element={<SubscribeList />} />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Script, ScriptDAO } from "@App/app/repo/scripts";
|
import { Script, ScriptCodeDAO, ScriptDAO } from "@App/app/repo/scripts";
|
||||||
import CodeEditor from "@App/pages/components/CodeEditor";
|
import CodeEditor from "@App/pages/components/CodeEditor";
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
import { useNavigate, useParams, useSearchParams } from "react-router-dom";
|
||||||
@ -143,8 +143,7 @@ const popstate = () => {
|
|||||||
|
|
||||||
function ScriptEditor() {
|
function ScriptEditor() {
|
||||||
const scriptDAO = new ScriptDAO();
|
const scriptDAO = new ScriptDAO();
|
||||||
const scriptCtrl = IoC.instance(ScriptController) as ScriptController;
|
const scriptCodeDAO = new ScriptCodeDAO();
|
||||||
const runtimeCtrl = IoC.instance(RuntimeController) as RuntimeController;
|
|
||||||
const template = useSearchParams()[0].get("template") || "";
|
const template = useSearchParams()[0].get("template") || "";
|
||||||
const target = useSearchParams()[0].get("target") || "";
|
const target = useSearchParams()[0].get("target") || "";
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@ -167,6 +166,8 @@ function ScriptEditor() {
|
|||||||
uuid: string;
|
uuid: string;
|
||||||
selectSciptButtonAndTab: string;
|
selectSciptButtonAndTab: string;
|
||||||
}>();
|
}>();
|
||||||
|
const { uuid } = useParams();
|
||||||
|
|
||||||
const setShow = (key: visibleItem, show: boolean) => {
|
const setShow = (key: visibleItem, show: boolean) => {
|
||||||
Object.keys(visible).forEach((k) => {
|
Object.keys(visible).forEach((k) => {
|
||||||
visible[k] = false;
|
visible[k] = false;
|
||||||
@ -174,8 +175,6 @@ function ScriptEditor() {
|
|||||||
visible[key] = show;
|
visible[key] = show;
|
||||||
setVisible({ ...visible });
|
setVisible({ ...visible });
|
||||||
};
|
};
|
||||||
|
|
||||||
const { id } = useParams();
|
|
||||||
const save = (script: Script, e: editor.IStandaloneCodeEditor): Promise<Script> => {
|
const save = (script: Script, e: editor.IStandaloneCodeEditor): Promise<Script> => {
|
||||||
// 解析code生成新的script并更新
|
// 解析code生成新的script并更新
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -363,19 +362,17 @@ function ScriptEditor() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
scriptDAO.table
|
scriptDAO.all().then(async (scripts) => {
|
||||||
.orderBy("sort")
|
scripts.sort((a, b) => a.sort - b.sort);
|
||||||
.toArray()
|
|
||||||
.then((scripts) => {
|
|
||||||
setScriptList(scripts);
|
setScriptList(scripts);
|
||||||
// 如果有id则打开对应的脚本
|
// 如果有id则打开对应的脚本
|
||||||
if (id) {
|
if (uuid) {
|
||||||
const iId = parseInt(id, 10);
|
|
||||||
for (let i = 0; i < scripts.length; i += 1) {
|
for (let i = 0; i < scripts.length; i += 1) {
|
||||||
if (scripts[i].id === iId) {
|
if (scripts[i].uuid === uuid) {
|
||||||
|
const code = await scriptCodeDAO.findByUUID(uuid);
|
||||||
editors.push({
|
editors.push({
|
||||||
script: scripts[i],
|
script: scripts[i],
|
||||||
code: scripts[i].code,
|
code: code!.code,
|
||||||
active: true,
|
active: true,
|
||||||
hotKeys,
|
hotKeys,
|
||||||
isChanged: false,
|
isChanged: false,
|
||||||
@ -387,7 +384,7 @@ function ScriptEditor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!id) {
|
if (!uuid) {
|
||||||
emptyScript(template || "", hotKeys, target).then((e) => {
|
emptyScript(template || "", hotKeys, target).then((e) => {
|
||||||
editors.push(e);
|
editors.push(e);
|
||||||
setEditors([...editors]);
|
setEditors([...editors]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user