|
@@ -341,6 +341,34 @@ const SpreadJsObj = {
|
|
|
this._initSheetHeader(sheet);
|
|
|
this.endMassOperation(sheet);
|
|
|
},
|
|
|
+ _rememberColWidth: function (sheet) {
|
|
|
+ sheet.bind(spreadNS.Events.ColumnWidthChanged, function (e, info) {
|
|
|
+ if (!info.sheet.zh_setting) return;
|
|
|
+ const setting = info.sheet.zh_setting;
|
|
|
+ if (!setting.localCache || !setting.localCache.key) return;
|
|
|
+ if (!setting.localCache.colWidthCache) return;
|
|
|
+ const cache = setting.localCache.colWidthCache;
|
|
|
+
|
|
|
+ for (const col of info.colList) {
|
|
|
+ const colSetting = setting.cols[col];
|
|
|
+ if (colSetting && colSetting.field)
|
|
|
+ cache[colSetting.field] = info.sheet.getColumnWidth(col);
|
|
|
+ }
|
|
|
+ setLocalCache(setting.localCache.key + '-colWidth', JSON.stringify(cache));
|
|
|
+ });
|
|
|
+ },
|
|
|
+ _loadCacheSetting: function (sheet, setting) {
|
|
|
+ if (!setting.localCache || !setting.localCache.key) return;
|
|
|
+ if (setting.localCache.colWidth) {
|
|
|
+ const cache = getLocalCache(setting.localCache.key + '-colWidth');
|
|
|
+ setting.localCache.colWidthCache = cache ? JSON.parse(cache) : {};
|
|
|
+ for (const prop in setting.localCache.colWidthCache) {
|
|
|
+ const col = _.find(setting.cols, {field: prop});
|
|
|
+ if (col) col.width = setting.localCache.colWidthCache[prop];
|
|
|
+ }
|
|
|
+ this._rememberColWidth(sheet);
|
|
|
+ }
|
|
|
+ },
|
|
|
/**
|
|
|
* 初始化sheet, 设置sheet.zh_setting, 并初始化表头
|
|
|
* @param {GC.Spread.Sheets.Worksheet} sheet
|
|
@@ -348,6 +376,7 @@ const SpreadJsObj = {
|
|
|
*/
|
|
|
initSheet: function (sheet, setting) {
|
|
|
this.beginMassOperation(sheet);
|
|
|
+ this._loadCacheSetting(sheet, setting);
|
|
|
setting.pos = sheet.getParent().pos;
|
|
|
if (!setting.tree) setting.tree = {};
|
|
|
sheet.zh_setting = setting;
|