|
|
@@ -170,6 +170,23 @@ module.exports = app => {
|
|
|
await this.analysisTemplate(result);
|
|
|
return result;
|
|
|
}
|
|
|
+ async getProjectCalcTmplSet () {
|
|
|
+ if (this.projectSet) return;
|
|
|
+ const defaultSet = { posCalc: { validCount: 50 }, cost: { validCount: 10 } };
|
|
|
+ const project = await this.ctx.service.project.getDataById(this.ctx.session.sessionProject.id);
|
|
|
+ if (!project.calc_tmpl_set) {
|
|
|
+ this.projectSet = defaultSet;
|
|
|
+ } else {
|
|
|
+ this.projectSet = JSON.parse(project.calc_tmpl_set);
|
|
|
+ for (const prop in defaultSet) {
|
|
|
+ if (this.projectSet[prop]) {
|
|
|
+ this.projectSet[prop] = this.ctx.helper._.assign(defaultSet[prop], this.projectSet[prop]);
|
|
|
+ } else {
|
|
|
+ this.projectSet[prop] = defaultSet[prop];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//-------------------------- 以下方法不可随意修改 --------------------------
|
|
|
// 根据列设置计算spreadjs配置相关,方法命名须严格按照【方法_类型】命名
|
|
|
@@ -360,8 +377,9 @@ module.exports = app => {
|
|
|
|
|
|
async _addTemplate(name, type, folder_id) {
|
|
|
if (ValidTemplateType.indexOf(type) < 0) throw '新增的模板类型非法';
|
|
|
+ await this.getProjectCalcTmplSet();
|
|
|
const count = await this.count({pid: this.ctx.session.sessionProject.id, type});
|
|
|
- if (count > this.TemplateRela[type].ValidCount) throw '已达模板使用上限';
|
|
|
+ if (count >= this.projectSet[type].validCount) throw '已达模板使用上限';
|
|
|
|
|
|
const relaConst = this.TemplateRela[type];
|
|
|
const insertData = {
|
|
|
@@ -501,6 +519,10 @@ module.exports = app => {
|
|
|
const org = await this.getDataById(id);
|
|
|
if (!org || org.pid !== this.ctx.session.sessionProject.id) throw '复制的模板不存在,请刷新后重试';
|
|
|
|
|
|
+ await this.getProjectCalcTmplSet();
|
|
|
+ const count = await this.count({pid: this.ctx.session.sessionProject.id, type});
|
|
|
+ if (count >= this.projectSet[org.type].validCount) throw '已达模板使用上限';
|
|
|
+
|
|
|
const insertData = {
|
|
|
id: this.uuid.v4(),
|
|
|
pid: this.ctx.session.sessionProject.id,
|