|
@@ -8,14 +8,9 @@
|
|
|
* @version
|
|
|
*/
|
|
|
|
|
|
-// setting = {
|
|
|
-// selector,
|
|
|
-// stdType,
|
|
|
-// treeSetting,
|
|
|
-// spreadSetting,
|
|
|
-// cellDoubleClick,
|
|
|
-// page,
|
|
|
-// };
|
|
|
+/**
|
|
|
+ * setting = { selector, stdType, treeSetting, spreadSetting, cellDoubleClick, page, };
|
|
|
+ */
|
|
|
|
|
|
class stdLib {
|
|
|
constructor(setting) {
|
|
@@ -32,26 +27,41 @@ class stdLib {
|
|
|
this.spread.getActiveSheet().bind(spreadNS.Events.CellDoubleClick, setting.cellDoubleClick);
|
|
|
this.spread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
|
|
|
if (!info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
|
|
|
- SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey);
|
|
|
+ SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey.node);
|
|
|
}
|
|
|
});
|
|
|
this.spread.getActiveSheet().bind(spreadNS.Events.TopRowChanged, function (e, info) {
|
|
|
- SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey);
|
|
|
+ SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey.node);
|
|
|
});
|
|
|
this.pathTree = createNewPathTree('base', this.treeSetting);
|
|
|
this.cacheLib = [];
|
|
|
+ this.cacheKey = {
|
|
|
+ lib: this.setting.page + '-' + this.setting.stdType,
|
|
|
+ };
|
|
|
$('select', setting.selector).change(function () {
|
|
|
self.loadLib(parseInt(this.value), true);
|
|
|
});
|
|
|
+ this._loadCacheLib();
|
|
|
+ }
|
|
|
+
|
|
|
+ _loadCacheLib() {
|
|
|
+ let libId = getLocalCache(this.cacheKey.lib);
|
|
|
+ if (libId) {
|
|
|
+ $('select', this.setting.selector).val(libId);
|
|
|
+ this.loadLib(parseInt(libId));
|
|
|
+ } else {
|
|
|
+ this.loadLib(parseInt($('select', this.setting.selector).val()));
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
loadLib (listId, reload = false) {
|
|
|
- this.cacheKey = this.setting.page + '-' + this.setting.stdType + '-' + listId;
|
|
|
+ this.cacheKey.node = this.setting.page + '-' + this.setting.stdType + '-' + listId;
|
|
|
const self = this;
|
|
|
const locateMemory = function () {
|
|
|
if (!reload) {
|
|
|
- SpreadJsObj.loadTopAndSelect(self.spread.getActiveSheet(), self.cacheKey);
|
|
|
+ SpreadJsObj.loadTopAndSelect(self.spread.getActiveSheet(), self.cacheKey.node);
|
|
|
} else {
|
|
|
- removeLocalCache(self.cacheKey);
|
|
|
+ removeLocalCache(self.cacheKey.node);
|
|
|
}
|
|
|
};
|
|
|
const cacheData = this.cacheLib.find(function (lib) {
|
|
@@ -61,12 +71,14 @@ class stdLib {
|
|
|
this.pathTree.loadDatas(cacheData.data);
|
|
|
SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), 'tree', this.pathTree);
|
|
|
locateMemory();
|
|
|
+ setLocalCache(this.cacheKey.lib, listId);
|
|
|
} else {
|
|
|
postData('/std-lib/get-data', {stdType: this.stdType, list_id: listId}, function (data) {
|
|
|
self.cacheLib.push({id: listId, data: data});
|
|
|
self.pathTree.loadDatas(data);
|
|
|
SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'tree', self.pathTree);
|
|
|
locateMemory();
|
|
|
+ setLocalCache(self.cacheKey.lib, listId);
|
|
|
});
|
|
|
}
|
|
|
}
|