11import React , { useMemo , useRef , useState } from 'react' ;
22import ReactDOM from 'react-dom' ;
3- import { IAppInstance , AppRenderer , SlotLocation , AppRenderer2 } from '@alipay/alex' ;
3+ import { IAppInstance , AppRenderer , SlotLocation , AppRenderer2 , KeepLive } from '@alipay/alex' ;
44import '@alipay/alex/languages/sql' ;
55import {
66 CompletionItemKind ,
@@ -9,12 +9,13 @@ import {
99 setMonacoEnvironment ,
1010} from '@alipay/alex-sql-service' ;
1111import { Button } from '@opensumi/ide-components' ;
12- import SqlPlugin from './sql.plugin' ;
12+ import SqlPlugin from './sql.plugin' ;
1313import { IEditor } from '@opensumi/ide-editor' ;
14- import { Popover , Radio } from 'antd' ;
14+ import { Popover , Radio , Menu } from 'antd' ;
1515import 'antd/dist/antd.css' ;
1616import odcTheme from '@alipay/alex/extensions/alex.odc-theme' ;
1717import { SQLRender } from './sqlRender' ;
18+ import { Tabs } from 'antd' ;
1819
1920setMonacoEnvironment ( ) ;
2021
@@ -24,15 +25,13 @@ const layoutConfig = {
2425 } ,
2526} ;
2627
27-
28-
2928const App = ( ) => {
30- const PluginID = 1
29+ const PluginID = '' ;
3130
3231 const SQLPlugin = useMemo ( ( ) => {
3332 return new SqlPlugin ( PluginID ) ;
3433 } , [ ] ) ;
35-
34+
3635 const [ fontValue , setFontValue ] = useState ( 16 ) ;
3736 const [ encoding , setEncoding ] = useState ( 'utf8' ) ;
3837 const [ editorNumber , setEditorNumber ] = useState ( 1 ) ;
@@ -62,9 +61,6 @@ const App = () => {
6261 ] ) ;
6362 }
6463
65-
66-
67-
6864 const onChangeFont = ( e ) => {
6965 setFontValue ( e . target . value ) ;
7066 updatePrefeence ( 'editor.fontSize' , e . target . value ) ;
@@ -79,29 +75,28 @@ const App = () => {
7975 setEditorNumber ( editorNumber + 1 ) ;
8076 }
8177
82-
8378 function format ( ) {
8479 SQLPlugin . commands ?. executeCommand ( 'editor.action.formatDocument' ) ;
8580 }
86-
81+
8782 function updatePrefeence ( perferenceName , value ) {
8883 // 设置首选项
8984 SQLPlugin . commands ?. executeCommand ( 'alex.setDefaultPreference' , perferenceName , value ) ;
9085 }
91-
86+
9287 async function addLine ( ) {
9388 const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
9489 editor ?. monacoEditor . trigger ( 'editor' , 'type' , { text : '\n' } ) ;
9590 }
96-
91+
9792 function openFile ( ) {
9893 /** COMMAND alex.sql.open
9994 * @param {string } uri - 文件uri
10095 * @param {string } content - 文件内容 无内容时创建并注入默认内容
10196 */
10297 SQLPlugin . commands ?. executeCommand ( 'alex.sql.open' , 'test1.sql' , '默认内容' ) ;
10398 }
104-
99+
105100 async function editor ( ) {
106101 const editor = ( await SQLPlugin . commands ?. executeCommand ( 'alex.sql.editor' ) ) as IEditor ;
107102 console . log ( editor ?. monacoEditor . getValue ( ) ) ;
@@ -122,12 +117,28 @@ const App = () => {
122117 </ Radio . Group >
123118 </ div >
124119 ) ;
120+ const items = [
121+ {
122+ label : 'Navigation One' ,
123+ key : '1' ,
124+ } ,
125+ {
126+ label : 'Navigation Two' ,
127+ key : '2' ,
128+ } ,
129+ ] ;
130+ const [ current , setCurrent ] = useState ( '1' ) ;
131+
132+ const menuCick = ( e ) => {
133+ console . log ( 'click ' , e ) ;
134+ setCurrent ( e . key ) ;
135+ } ;
125136
126137 return (
127138 < div style = { { height : '100%' , overflow : 'scroll' } } >
128139 < div style = { { height : '300px' } } >
129140 < div style = { { margin : '20px' } } >
130- < Button onClick = { ( ) => format ( ) } > 格式化</ Button >
141+ { /* <Button onClick={() => format()}>格式化</Button>
131142 <Button onClick={() => addLine()}>添加行</Button>
132143 <Button onClick={() => openFile()}>打开文件</Button>
133144 <Button onClick={() => editor()}>获取当前内容</Button>
@@ -137,9 +148,17 @@ const App = () => {
137148 </Popover>
138149 <Button onClick={() => changeTables()}>change suggest Tables</Button>
139150 <Button onClick={() => window.reset()}>reset </Button>
140- < Button onClick = { ( ) => editorNumberUpdate ( ) } > 添加编辑器</ Button >
151+ <Button onClick={() => editorNumberUpdate()}>添加编辑器</Button> */ }
152+ < Menu onClick = { menuCick } selectedKeys = { [ current ] } mode = "horizontal" items = { items } />
153+ < div style = { { display : `${ current === '1' ? 'block' : 'none' } ` } } >
154+ < SQLRender id = "1" />
155+ </ div >
156+ < div style = { { display : `${ current === '2' ? 'block' : 'none' } ` } } >
157+ < SQLRender id = "2" />
158+ </ div >
141159 </ div >
142- < AppRenderer2
160+
161+ { /* <AppRenderer2
143162 onLoad={(app) => {
144163 window.app = app;
145164 }}
@@ -316,23 +335,8 @@ const App = () => {
316335 },
317336 },
318337 }}
319- />
338+ /> */ }
320339 </ div >
321- { editorNumber > 1 ? (
322- < div >
323- < SQLRender />
324- </ div >
325- ) : null }
326- { editorNumber > 2 ? (
327- < div >
328- < SQLRender />
329- </ div >
330- ) : null }
331- { editorNumber > 3 ? (
332- < div >
333- < SQLRender />
334- </ div >
335- ) : null }
336340 </ div >
337341 ) ;
338342} ;
0 commit comments