| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | 'use strict';/** * * * @author Mai * @date * @version *//** * setting = { selector, stdType, treeSetting, spreadSetting, cellDoubleClick, page, }; */class stdLib {    constructor(setting) {        const self = this;        this.setting = setting;        this.obj = $(setting.selector + '-spread')[0];        this.stdType = setting.stdType;        this.treeSetting = setting.treeSetting;        this.spreadSetting = setting.spreadSetting;        this.spreadSetting.stdType = setting.stdType;        this.spread = SpreadJsObj.createNewSpread(this.obj);        SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);        SpreadJsObj.forbiddenSpreadContextMenu(setting.selector, this.spread);        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.node);            }        });        this.spread.getActiveSheet().bind(spreadNS.Events.TopRowChanged, function (e, info) {            SpreadJsObj.saveTopAndSelect(info.sheet, self.cacheKey.node);        });        this.pathTree = createNewPathTree('base', this.treeSetting);        this.cacheLib = [];        this.cacheKey = {            lib: this.setting.page + '-' + this.setting.tid + '-' + 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.node = this.setting.page + '-' + this.setting.tid + '-' + this.setting.stdType + '-' + listId;        const self = this;        const locateMemory = function () {            if (!reload) {                SpreadJsObj.loadTopAndSelect(self.spread.getActiveSheet(), self.cacheKey.node);            } else {                removeLocalCache(self.cacheKey.node);            }        };        const cacheData = this.cacheLib.find(function (lib) {            return lib.id === listId;        });        if (cacheData) {            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);            });        }    }}
 |