From fddace1ec7d3f5c2c95665c5dec5ff46da286790 Mon Sep 17 00:00:00 2001 From: lishuang Date: Sat, 2 Jan 2021 22:44:05 +0800 Subject: [PATCH] Refine the variable scope. --- src/common/model/global/Moon.ts | 3 --- src/pages/matter/List.tsx | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/common/model/global/Moon.ts b/src/common/model/global/Moon.ts index 52c95b0..a2c4cbf 100644 --- a/src/common/model/global/Moon.ts +++ b/src/common/model/global/Moon.ts @@ -16,9 +16,6 @@ export default class Moon { //全局唯一的偏好设置 preference: Preference = new Preference() - //全局上传通道 - uploadMatters: Matter[] = []; - //全局的一个store对象 private static singleton: Moon | null = null diff --git a/src/pages/matter/List.tsx b/src/pages/matter/List.tsx index 1be3fdc..ba11617 100644 --- a/src/pages/matter/List.tsx +++ b/src/pages/matter/List.tsx @@ -60,8 +60,7 @@ export default class List extends TankComponent { matter = new Matter(); //准备新建的文件。 newMatter = new Matter(); - //准备上传的一系列文件 - uploadMatters = Moon.getSingleton().uploadMatters; + //当前选中的文件 selectedMatters: Matter[] = []; //搜索的文字 @@ -87,6 +86,9 @@ export default class List extends TankComponent { //上传错误日志 uploadErrorLogs: [string, string, string][] = []; + //准备上传的一系列文件 + static uploadMatters: Matter[] = []; + //持有全局唯一的实例。 static instance: List | null = null @@ -146,10 +148,7 @@ export default class List extends TankComponent { }; componentDidMount() { - // 将全局上传数组重新绑定到当前视图 - this.uploadMatters.forEach((matter) => { - matter.reactComponent = this; - }); + //刷新一下列表 if (this.user.role === UserRole.ADMINISTRATOR) { this.pager.getFilter("userUuid")!.visible = true; @@ -390,17 +389,17 @@ export default class List extends TankComponent { m.file = file; m.httpUpload( () => { - const index = this.uploadMatters.findIndex((matter) => matter === m); - this.uploadMatters.splice(index, 1); + const index = List.uploadMatters.findIndex((matter) => matter === m); + List.uploadMatters.splice(index, 1); List.instance!.refresh(); }, (msg: string) => { - this.updateUI(); + List.instance!.updateUI(); SafeUtil.safeCallback(errHandle)(msg); } ); - this.uploadMatters.push(m); + List.uploadMatters.push(m); } }; @@ -527,7 +526,6 @@ export default class List extends TankComponent { pager, director, selectedMatters, - uploadMatters, dragEnterCount, } = this; return ( @@ -648,7 +646,7 @@ export default class List extends TankComponent { {Children.toArray( - uploadMatters.map((m) => ) + List.uploadMatters.map((m) => ) )} {pager.data.length ? (