66 Input ,
77 Layout ,
88 Menu ,
9+ Message ,
910 Modal ,
1011 Space ,
1112 Typography ,
@@ -18,6 +19,7 @@ import "./index.css";
1819import { useAppDispatch , useAppSelector } from "@App/pages/store/hooks" ;
1920import { selectThemeMode , setDarkMode } from "@App/pages/store/features/config" ;
2021import { RiFileCodeLine , RiImportLine , RiPlayListAddLine , RiTerminalBoxLine , RiTimerLine } from "react-icons/ri" ;
22+ import { scriptClient } from "@App/pages/store/features/script" ;
2123
2224const MainLayout : React . FC < {
2325 children : ReactNode ;
@@ -48,7 +50,12 @@ const MainLayout: React.FC<{
4850 title = { t ( "import_link" ) }
4951 visible = { importVisible }
5052 onOk = { async ( ) => {
51- setImportVisible ( false ) ;
53+ try {
54+ await scriptClient . importByUrl ( importRef . current ! . dom . value ) ;
55+ setImportVisible ( false ) ;
56+ } catch ( e ) {
57+ Message . error ( `${ t ( "import_link_failure" ) } : ${ e } ` ) ;
58+ }
5259 } }
5360 onCancel = { ( ) => {
5461 setImportVisible ( false ) ;
@@ -87,31 +94,30 @@ const MainLayout: React.FC<{
8794 onClick = { ( ) => {
8895 const el = document . getElementById ( "import-local" ) ;
8996 el ! . onchange = ( e : Event ) => {
90- // const scriptCtl = IoC.instance(ScriptController) as ScriptController;
91- // try {
92- // // 获取文件
93- // // @ts -ignore
94- // const file = e.target.files[0];
95- // // 实例化 FileReader对象
96- // const reader = new FileReader();
97- // reader.onload = async (processEvent) => {
98- // // 创建blob url
99- // const blob = new Blob(
100- // // @ts -ignore
101- // [processEvent.target!.result],
102- // {
103- // type: "application/javascript",
104- // }
105- // );
106- // const url = URL.createObjectURL(blob);
107- // await scriptCtl.importByUrl(url);
108- // Message.success(t("import_local_success"));
109- // };
110- // // 调用readerAsText方法读取文本
111- // reader.readAsText(file);
112- // } catch (error) {
113- // Message.error(`${t("import_local_failure")}: ${e}`);
114- // }
97+ try {
98+ // 获取文件
99+ // @ts -ignore
100+ const file = e . target . files [ 0 ] ;
101+ // 实例化 FileReader对象
102+ const reader = new FileReader ( ) ;
103+ reader . onload = async ( processEvent ) => {
104+ // 创建blob url
105+ const blob = new Blob (
106+ // @ts -ignore
107+ [ processEvent . target ! . result ] ,
108+ {
109+ type : "application/javascript" ,
110+ }
111+ ) ;
112+ const url = URL . createObjectURL ( blob ) ;
113+ await scriptClient . importByUrl ( url ) ;
114+ Message . success ( t ( "import_local_success" ) ) ;
115+ } ;
116+ // 调用readerAsText方法读取文本
117+ reader . readAsText ( file ) ;
118+ } catch ( error ) {
119+ Message . error ( `${ t ( "import_local_failure" ) } : ${ e } ` ) ;
120+ }
115121 } ;
116122 el ! . click ( ) ;
117123 } }
0 commit comments