Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 记录了当前模型的索引值, 修复了切换模型后刷新还是从第一个模型开始展示
- Loading branch information
Showing
7 changed files
with
78 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { StoreModelInfo } from '../types/common.js'; | ||
import { ModelOptions } from '../types/model.js'; | ||
|
||
export class Store { | ||
setModelInfo(value: StoreModelInfo): void { | ||
const finalValue = JSON.stringify(value); | ||
|
||
localStorage.setItem('OML2D_MODEL_INFO', finalValue); | ||
} | ||
|
||
getModuleInfo(modelOptions: ModelOptions[]): StoreModelInfo { | ||
const key = this.getModelDataKey(modelOptions); | ||
|
||
const value = JSON.parse(localStorage.getItem('OML2D_MODEL_INFO') as string) as StoreModelInfo; | ||
|
||
if (value?.key === key) { | ||
return value; | ||
} | ||
} | ||
|
||
getModelDataKey(modelOptions: ModelOptions[]): string { | ||
const keys = modelOptions?.map((item: ModelOptions): string => { | ||
return item.path; | ||
}); | ||
|
||
return keys.join(); | ||
} | ||
|
||
updateModelInfo(modelOptions: ModelOptions[], currentIndex: number): void { | ||
const key = this.getModelDataKey(modelOptions); | ||
|
||
this.setModelInfo({ key, currentIndex }); | ||
} | ||
|
||
getModelCurrentIndex(modelOptions: ModelOptions[]): number { | ||
return this.getModuleInfo(modelOptions)?.currentIndex || 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters