|
@@ -59,7 +59,9 @@ export class PageCtrl extends ModuleControl<EditorModule> {
|
|
|
|
|
|
designData = {} as DesignTemp;
|
|
|
compPids = {} as Record<string, string>;
|
|
|
-
|
|
|
+ saveTimeout = null as any;
|
|
|
+ saveAssets = [] as any;
|
|
|
+ repectAssets = {} as any;
|
|
|
toJson() {
|
|
|
const out: any = {
|
|
|
_id: this.designData._id,
|
|
@@ -96,45 +98,89 @@ export class PageCtrl extends ModuleControl<EditorModule> {
|
|
|
get currStreamCard() {
|
|
|
return this.compMap[this.state.currStreamCardId];
|
|
|
}
|
|
|
-
|
|
|
get streamCardIds(): string[] {
|
|
|
return this.rootPage?.children.default || [];
|
|
|
}
|
|
|
|
|
|
async saveAssetsLocal(comp: DesignComp) {
|
|
|
- const { deviceCtrl, prjCtrl } = useCtx();
|
|
|
+ const { prjCtrl } = useCtx();
|
|
|
const assetUrl = comp.value.url;
|
|
|
if (!prjCtrl.isLocalUrl(assetUrl)) {
|
|
|
const assetsName = assetUrl.replace(/(.*\/)*((\S|\s)+\.*)(\?.*)?/g, "$2");
|
|
|
const assetKey = assetsName.replace(/\s/g, "");
|
|
|
const fpath = `queen5/assets/${assetsName}`;
|
|
|
if (this.store.filesCacheUrl[assetKey]) {
|
|
|
- comp.value.url = fpath;
|
|
|
+ if (!this.saveTimeout) {
|
|
|
+ set(comp, "value.url", fpath);
|
|
|
+ } else {
|
|
|
+ this.repectAssets[comp.id] = fpath;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
+ if (this.saveTimeout) {
|
|
|
+ clearTimeout(this.saveTimeout);
|
|
|
+ this.saveTimeout = null;
|
|
|
+ }
|
|
|
+ this.store.filesCacheUrl[assetKey] = "start";
|
|
|
+ this.saveAssets.push({ id: comp.id, url: comp.value.url });
|
|
|
|
|
|
- deviceCtrl.DownloadFile(
|
|
|
- comp.value.url,
|
|
|
+ this.saveTimeout = setTimeout(() => {
|
|
|
+ this.downLoadFiles();
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ downLoadFiles() {
|
|
|
+ const { deviceCtrl, prjCtrl } = useCtx();
|
|
|
+ const savePromises: any = this.saveAssets.map((item: any) => {
|
|
|
+ const assetUrl = item.url;
|
|
|
+ const assetsName = assetUrl.replace(/(.*\/)*((\S|\s)+\.*)(\?.*)?/g, "$2");
|
|
|
+ const assetKey = assetsName.replace(/\s/g, "");
|
|
|
+ const fpath = `queen5/assets/${assetsName}`;
|
|
|
+ return deviceCtrl.DownloadFile(
|
|
|
+ assetUrl,
|
|
|
prjCtrl.createPath(fpath),
|
|
|
60 * 10,
|
|
|
- (status: string, p: any) => {
|
|
|
+ (status: string) => {
|
|
|
if (status == "succ") {
|
|
|
- comp.value.url = fpath;
|
|
|
+ const comp = this.helper.findComp(item.id);
|
|
|
+ if (comp) {
|
|
|
+ comp.value.url = fpath;
|
|
|
+ }
|
|
|
+
|
|
|
if (prjCtrl.isOnlineUrl(assetUrl)) {
|
|
|
this.store.filesCacheUrl[assetKey] = assetUrl;
|
|
|
}
|
|
|
-
|
|
|
- this.localFilesCacheSave();
|
|
|
}
|
|
|
if (status == "error") {
|
|
|
- // this.store.filesCacheUrl[assetKey] = undefined;
|
|
|
+ if (this.store.filesCacheUrl[assetKey]) {
|
|
|
+ delete this.store.filesCacheUrl[assetKey];
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
- }
|
|
|
+ });
|
|
|
+ Promise.all(savePromises).then(() => {
|
|
|
+ clearTimeout(this.saveTimeout);
|
|
|
+ this.saveTimeout = null;
|
|
|
+ this.saveAssets = [];
|
|
|
+ this.localFilesCacheSave();
|
|
|
+ Object.keys(this.repectAssets).map((e) => {
|
|
|
+ const comp = this.helper.findComp(e);
|
|
|
+ if (comp) {
|
|
|
+ comp.value.url = this.repectAssets[e];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.repectAssets = {};
|
|
|
+ });
|
|
|
}
|
|
|
async localFilesCacheSave() {
|
|
|
const { deviceCtrl, prjCtrl } = useCtx();
|
|
|
+ Object.keys(this.store.filesCacheUrl).map((e) => {
|
|
|
+ if (this.store.filesCacheUrl[e] == "start") {
|
|
|
+ delete this.store.filesCacheUrl[e];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ debugger;
|
|
|
const ok = await deviceCtrl.WriteFileText(
|
|
|
`${prjCtrl.RootDir}/queen5/assets.cache.queen5`,
|
|
|
JSON.stringify(this.store.filesCacheUrl)
|