提交 515b61ea 编写于 作者: RedPig97's avatar RedPig97

add: 新增动态表格列功能

上级 899be349
import { Http,Util,Errorlog } from '@/utils'; import { Http,Util,Errorlog } from '@/utils';
import ControlService from '@/widgets/control-service'; import ControlService from '@/widgets/control-service';
import UtilService from '@/utilservice/util-service';
<#if appde??> <#if appde??>
import ${srfclassname('${appde.getCodeName()}')}Service from '@/service/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-service'; import ${srfclassname('${appde.getCodeName()}')}Service from '@/service/${srffilepath2(appde.getCodeName())}/${srffilepath2(appde.getCodeName())}-service';
</#if> </#if>
...@@ -36,6 +37,15 @@ export default class ${srfclassname('${ctrl.codeName}')}Service extends ControlS ...@@ -36,6 +37,15 @@ export default class ${srfclassname('${ctrl.codeName}')}Service extends ControlS
} }
</#if> </#if>
/**
* 工具服务对象
*
* @protected
* @type {UtilService}
* @memberof ${srfclassname('${ctrl.codeName}')}Service
*/
protected utilService: UtilService = new UtilService();
/** /**
* Creates an instance of ${srfclassname('${ctrl.codeName}')}Service. * Creates an instance of ${srfclassname('${ctrl.codeName}')}Service.
* *
......
...@@ -2134,16 +2134,42 @@ ${gridColumn.getName()} ...@@ -2134,16 +2134,42 @@ ${gridColumn.getName()}
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public setColState() { public setColState() {
const _data: any = localStorage.getItem('${ctrl.getPSAppDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}'); const viewParams: any = Util.deepCopy(this.viewparams);
if (_data) { Object.assign(viewParams,{utilServiceName: 'grid_dynaconfig', modelid: '${sys.getCodeName()?lower_case}_${app.getCodeName()?lower_case}_${view.getCodeName()?lower_case}_grid_${ctrl.getCodeName()?lower_case}'});
let columns = JSON.parse(_data); const post = this.service.loadModel('grid_dynaconfig', this.context, this.viewparams);
columns.forEach((col: any) => { post.then((response: any) => {
let column = this.allColumns.find((item) => Object.is(col.name, item.name)); if(response.status == 200 && response.data) {
if (column) { const columns = response.data;
Object.assign(column, col); columns.forEach((col: any) => {
} let column = this.allColumns.find((item) => Object.is(col.name, item.name));
}); if (column) {
} Object.assign(column, col);
}
});
} else {
this.getColStorage();
}
}).catch(() => {
this.getColStorage();
});
}
/**
* 获取列缓存
*
* @memberof MainBase
*/
public getColStorage() {
const _data: any = localStorage.getItem('${ctrl.getPSAppDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}');
if (_data) {
let columns = JSON.parse(_data);
columns.forEach((col: any) => {
let column = this.allColumns.find((item) => Object.is(col.name, item.name));
if (column) {
Object.assign(column, col);
}
});
}
} }
/** /**
...@@ -2152,6 +2178,18 @@ ${gridColumn.getName()} ...@@ -2152,6 +2178,18 @@ ${gridColumn.getName()}
* @memberof ${srfclassname('${ctrl.codeName}')}Base * @memberof ${srfclassname('${ctrl.codeName}')}Base
*/ */
public onColChange() { public onColChange() {
const viewParams: any = Util.deepCopy(this.viewparams);
Object.assign(viewParams,{utilServiceName: 'grid_dynaconfig', modelid: '${sys.getCodeName()?lower_case}_${app.getCodeName()?lower_case}_${view.getCodeName()?lower_case}_grid_${ctrl.getCodeName()?lower_case}', model: this.allColumns});
const post = this.service.saveModel('grid_dynaconfig', this.context, this.viewparams);
post.then((response: any) => {
if (response.status == 200) {
console.log('保存动态表格列模型成功!');
}
localStorage.setItem('dynaconfig_main_grid', JSON.stringify(this.allColumns));
}).catch(() => {
console.log('保存动态表格列模型失败!');
localStorage.setItem('dynaconfig_main_grid', JSON.stringify(this.allColumns));
});
localStorage.setItem('${ctrl.getPSAppDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}', JSON.stringify(this.allColumns)); localStorage.setItem('${ctrl.getPSAppDataEntity().getName()?lower_case}_${ctrl.getCodeName()?lower_case}_${ctrl.name}', JSON.stringify(this.allColumns));
} }
......
...@@ -20,6 +20,50 @@ import ${srfclassname('${aggAppDataEntity.getCodeName()}')}Service from '@/servi ...@@ -20,6 +20,50 @@ import ${srfclassname('${aggAppDataEntity.getCodeName()}')}Service from '@/servi
../@MACRO/SERVICE/SERVICE_HEADER.ts.ftl ../@MACRO/SERVICE/SERVICE_HEADER.ts.ftl
</#ibizinclude> </#ibizinclude>
/**
* 加载数据模型
*
* @param {string} serviceName
* @param {*} context
* @param {*} viewparams
* @memberof ${srfclassname('${ctrl.codeName}')}Service
*/
public loadModel(serviceName: string, context: any, viewparams: any) {
return new Promise((resolve: any, reject: any) => {
this.utilService.getService(serviceName).then((service: any) => {
service.loadModelData(JSON.stringify(context), viewparams).then((response: any) => {
resolve(response);
}).catch((response: any) => {
reject(response);
});
}).catch((response: any) => {
reject(response);
});
});
}
/**
* 保存数据模型
*
* @param {string} serviceName
* @param {*} context
* @param {*} viewparams
* @memberof ${srfclassname('${ctrl.codeName}')}Service
*/
public saveModel(serviceName: string, context: any, viewparams: any) {
return new Promise((resolve: any, reject: any) => {
this.utilService.getService(serviceName).then((service: any) => {
service.saveModel(JSON.stringify(context),'', viewparams).then((response: any) => {
resolve(response);
}).catch((response: any) => {
reject(response);
});
}).catch((response: any) => {
reject(response);
});
});
}
/** /**
* 备份原生数据 * 备份原生数据
* *
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册