From d4befc6896f2130de3a59e59443d9966bb51fe01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Wed, 18 Oct 2017 12:18:41 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=20=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E6=9D=BF=E6=97=B6=E5=87=BA=E9=94=99=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/admin/template.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/controller/admin/template.js b/src/controller/admin/template.js index 8f567355..8532dede 100644 --- a/src/controller/admin/template.js +++ b/src/controller/admin/template.js @@ -309,11 +309,19 @@ module.exports = class extends think.cmswing.admin { } const templateFile = `${temppath}${data.controller}${this.config('view.nunjucks.sep')}${data.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); - const res = await this.model('temp').add(data); - if (!think.isEmpty(res)) { - fs.writeFileSync(templateFile, data.html); - return this.success({name: '添加成功!'}); - } + let model = this.model('temp'); + return await model.transaction(async()=>{ + let res = await model.add(data); + if (!think.isEmpty(res)) { + try{ + fs.writeFileSync(templateFile, data.html); + }catch (e){ + await model.rollback(); + return this.fail('模板创建失败!'); + } + return this.success({name: '添加成功!'}); + } + }); } else { const type = this.get('type'); const temptype = this.get('temptype'); -- Gitee From 836b6226bdaa806b36946efbb4e9dace3c54868c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Wed, 18 Oct 2017 12:24:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=20=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E6=9D=BF=E6=97=B6=E5=87=BA=E9=94=99=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/admin/template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/admin/template.js b/src/controller/admin/template.js index 8532dede..91462cdc 100644 --- a/src/controller/admin/template.js +++ b/src/controller/admin/template.js @@ -310,7 +310,7 @@ module.exports = class extends think.cmswing.admin { const templateFile = `${temppath}${data.controller}${this.config('view.nunjucks.sep')}${data.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); let model = this.model('temp'); - return await model.transaction(async()=>{ + return model.transaction(async()=>{ let res = await model.add(data); if (!think.isEmpty(res)) { try{ -- Gitee From 30cf3a223d7122932c7a24b531580ed01a14c9f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Wed, 18 Oct 2017 14:41:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=20=20=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E9=87=8D=E5=A4=8D=E6=97=B6=E6=8F=90=E7=A4=BA=20=20=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=20=E8=B7=B3=E8=BD=AC=E5=88=B0=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B5=E9=9D=A2=20=E4=BF=AE=E5=A4=8D=20=20?= =?UTF-8?q?=20=E6=A8=A1=E6=9D=BF=E5=88=A0=E9=99=A4=E6=97=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/admin/template.js | 15 +++++++++++++-- view/admin/template_add.html | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/controller/admin/template.js b/src/controller/admin/template.js index 91462cdc..171287b9 100644 --- a/src/controller/admin/template.js +++ b/src/controller/admin/template.js @@ -310,6 +310,17 @@ module.exports = class extends think.cmswing.admin { const templateFile = `${temppath}${data.controller}${this.config('view.nunjucks.sep')}${data.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); let model = this.model('temp'); + + // 检查是否重复 + let cond ={}; + think.extend(cond,data); + delete cond.html; + delete cond.temptype; + delete cond.name; + let empty = await model.where(cond).find(); + if(!think.isEmpty(empty)){ + return this.fail('模板已存在!'); + } return model.transaction(async()=>{ let res = await model.add(data); if (!think.isEmpty(res)) { @@ -319,7 +330,7 @@ module.exports = class extends think.cmswing.admin { await model.rollback(); return this.fail('模板创建失败!'); } - return this.success({name: '添加成功!'}); + return this.success({name: '添加成功!',id:res}); } }); } else { @@ -366,7 +377,7 @@ module.exports = class extends think.cmswing.admin { } else { temppath = `${think.ROOT_PATH}/view/${temp.module}/`; } - const templateFile = `${temppath}${temp.controller}${think.config('view', undefined, 'topic').file_depr}${temp.action}${this.config('view.file_ext')}`; + const templateFile = `${temppath}${temp.controller}${this.config('view.nunjucks.sep')}${temp.action}${this.config('view.nunjucks.extname')}`; // console.log(templateFile); if (think.isFile(templateFile)) { fs.unlinkSync(templateFile); diff --git a/view/admin/template_add.html b/view/admin/template_add.html index 186d82d2..413f564b 100644 --- a/view/admin/template_add.html +++ b/view/admin/template_add.html @@ -149,7 +149,7 @@ confirmButtonColor: "#DD6B55", confirmButtonText: "OK", }, function () { - location.reload(); + location.href= "/admin/template/edit?id="+res.data.id; }); }else { swal(res.errmsg,"",'warning') -- Gitee From c0f0e0b7e293ba600cb3e917109ab3ab9200dab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Wed, 18 Oct 2017 17:29:06 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=20=20=E6=A0=8F?= =?UTF-8?q?=E7=9B=AE=E5=88=A0=E9=99=A4=E6=97=B6,=E5=AD=90=E9=9B=86?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E4=B8=8D=E5=88=A0=E9=99=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/admin/channel.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/controller/admin/channel.js b/src/controller/admin/channel.js index df7626a8..c035f5a8 100644 --- a/src/controller/admin/channel.js +++ b/src/controller/admin/channel.js @@ -84,8 +84,17 @@ module.exports = class extends think.cmswing.admin { if (think.isEmpty(id)) { this.fail('请选择要操作的数据!'); } + let channel = this.model('channel'); + let loca = 0; + do{ + let list = await channel.where({pid:id[loca]}).field('id').select(); + for(let _id of list) + id.push(_id.id); + loca++; + }while (loca < id.length); + // 开始删除 const map = {id: ['IN', id]}; - const res = await this.model('channel').where(map).delete(); + const res = await channel.where(map).delete(); if (res) { await this.model('cmswing/action').log('update_channel', 'channel', id, this.user.uid, this.ip, this.ctx.url);// 记录行为 this.cache('get_channel_cache', null);// 更新频道缓存信息 -- Gitee