11import { webview } from '@kit.ArkWeb';
22import { FULL_PERCENT } from '../model/TabStyle';
33import { TabSheets } from './TabSheetComponent';
4- import { TermController } from '../model/TermController ';
4+ import { TermModel } from '../model/TermModel ';
55import { common } from '@kit.AbilityKit';
66
77@Entry
88@Component
99struct Index {
10- @State tabArray: Array<TermController > = [new TermController(() => this.closeTab(0 ))];
10+ @State tabArray: Array<TermModel > = [new TermModel(id => this.closeTabAndTerm(id ))];
1111 @State focusIndex: number = 0;
1212 private controller: TabsController = new TabsController();
1313
1414 aboutToAppear(): void {
1515 webview.WebviewController.setWebDebuggingAccess(true)
1616 }
1717
18- closeTab(index: number): void {
18+ closeTabAndTerm(id: number): void {
19+
20+ let index = this.tabArray.findIndex(it => it.id === id)
21+
1922 if (this.tabArray.length > 1) {
2023
2124 let newArray = Array.from(this.tabArray)
2225
2326 const removed = newArray.splice(index, 1)[0];
24- removed.shutdown()
27+ removed.controller. shutdown()
2528
2629 this.tabArray = newArray;
2730 if (this.tabArray[index] === undefined) {
2831 this.focusIndex = index - 1;
29- } else if (this.tabArray[index] !== undefined && this.focusIndex !== index) {
32+ } else if (this.tabArray[index] !== undefined
33+ && this.focusIndex !== index) {
3034 this.focusIndex -= 1;
3135 }
36+
37+ focusControl.requestFocus('tabs')
3238 } else {
3339 (this.getUIContext().getHostContext() as common.UIAbilityContext)?.terminateSelf()
3440 }
@@ -39,7 +45,7 @@ struct Index {
3945 TabSheets({
4046 tabArray: $tabArray,
4147 focusIndex: $focusIndex,
42- closeTab: this.closeTab ,
48+ closeTabAndTerm: id => this.closeTabAndTerm(id) ,
4349 controller: this.controller
4450 })
4551
@@ -48,39 +54,19 @@ struct Index {
4854 .backgroundColor($r('sys.color.ohos_id_color_subheading_separator_dark'))
4955
5056 Tabs({ barPosition: BarPosition.Start, index: this.focusIndex, controller: this.controller }) {
51- ForEach(this.tabArray, (item: TermController , index: number) => {
57+ ForEach(this.tabArray, (item: TermModel , index: number) => {
5258 TabContent() {
5359 Column() {
54- Web({
55- src: $rawfile('term.html'),
56- controller: item.webviewController
57- })
58- .javaScriptProxy({
59- object: item,
60- name: 'native',
61- methodList: ['sendInput', 'resize', 'load'],
62- controller: item.webviewController,
63- asyncMethodList: [],
64- permission: `{
65- "javascriptProxyPermission": {
66- "urlPermissionList": [
67- {
68- "scheme": "resource",
69- "host": "rawfile",
70- "port": "",
71- "path": ""
72- }
73- ]
74- }
75- }`
76- })
77- .backgroundColor('#000')
78- .height(FULL_PERCENT)
60+ NodeContainer(item.view)
61+ .id('term-node-' + item.id)
62+ .width('100%')
63+ .height('100%')
7964 }
8065 .height(FULL_PERCENT)
8166 }
82- }, (item: TermController ) => 'term-' + item.id.toString())
67+ }, (item: TermModel ) => 'term-' + item.id.toString())
8368 }
69+ .id('tabs')
8470 .scrollable(false)
8571 .barHeight(0)
8672 .onChange((index: number) => {
0 commit comments