From faa6f1ae4ef8aa6231e34b1151537c7edabe39d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Sat, 11 Nov 2017 13:29:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/admin/public_signin.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/view/admin/public_signin.html b/view/admin/public_signin.html index ed49f8db..9e3be3f3 100644 --- a/view/admin/public_signin.html +++ b/view/admin/public_signin.html @@ -3,7 +3,7 @@ - 登录 | CmsWing 管理后台 + 登录 | {{config.setup.WEB_SITE_TITLE}} - 后台管理 -- Gitee From 0da59d454b1a9dc67c765fa8c617e75c31c8cb54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Mon, 18 Dec 2017 08:33:21 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/model.js | 2 +- .../ext/attachment/view/pc/admin_addapi.html | 180 +++++++++++------- src/controller/ext/mark/admin.js | 73 +++++++ src/controller/ext/mark/config.js | 49 +++++ src/controller/ext/mark/index.js | 60 ++++++ src/controller/ext/mark/model/demo.js | 6 + src/controller/ext/mark/service/demo.js | 13 ++ .../ext/mark/view/mobile/index_index.html | 33 ++++ .../ext/mark/view/pc/admin_index.html | 89 +++++++++ .../ext/mark/view/pc/index_index.html | 33 ++++ 10 files changed, 466 insertions(+), 72 deletions(-) create mode 100644 src/controller/ext/mark/admin.js create mode 100644 src/controller/ext/mark/config.js create mode 100644 src/controller/ext/mark/index.js create mode 100644 src/controller/ext/mark/model/demo.js create mode 100644 src/controller/ext/mark/service/demo.js create mode 100644 src/controller/ext/mark/view/mobile/index_index.html create mode 100644 src/controller/ext/mark/view/pc/admin_index.html create mode 100644 src/controller/ext/mark/view/pc/index_index.html diff --git a/src/config/model.js b/src/config/model.js index 657f8aee..9dd3afb8 100644 --- a/src/config/model.js +++ b/src/config/model.js @@ -16,7 +16,7 @@ module.exports = { mysql: { handle: mysql, // Adapter handle user: 'root', // 用户名 - password: 'root', // 密码 + password: '', // 密码 database: 'cmswing', // 数据库 host: '127.0.0.1', // host port: 3306, // 端口 diff --git a/src/controller/ext/attachment/view/pc/admin_addapi.html b/src/controller/ext/attachment/view/pc/admin_addapi.html index fa04f81d..bd97e841 100644 --- a/src/controller/ext/attachment/view/pc/admin_addapi.html +++ b/src/controller/ext/attachment/view/pc/admin_addapi.html @@ -3,8 +3,8 @@
@@ -12,21 +12,23 @@
-
- -
-
-
-
- +
+ +
+
+
+
+ 英文字母.比如 你的标识是biaoshi那么请求接口就是 /ext/attachment/adminfile/upload?type=biaoshi -
-
-
+
+
+
@@ -35,74 +37,110 @@ value="{{data.name}}" class="form-control">
- - 默认为file,不需要留给留空 - + + + 默认为file,不需要留给留空 +
-
- -
-
-
- -
- 200字以内 -
-
+
+ +
+
+
+
+ 200字以内
-
-
- -
-
-
- - -
-
- - 接口的类型
- 后台图片接口地址:/ext/attachment/adminfile/uploadpic?type=接口标识
- 后台文件接口地址:/ext/attachment/adminfile/upload?type=接口标识
- 前台图片接口地址:/ext/attachment/homefile/uploadpic?type=接口标识
- 前台文件接口地址:/ext/attachment/homefile/upload?type=接口标识
-
-
-
+
+
+
+
+ +
+
+
+ + +
+
+ + 开启后图片类型文件将添加水印
+
-
-
- -
-
-
-
-
- 输入接口返回规则,必填 , - ${id}图片id - ${url}图片地址,${name}图片名称,默认接口只返回 id - - -
-
+
+
+
+
+ +
+
+
+ +
+
+ + 文件相对于服务器的路径,有默认值,不需要请留空
+
-
- - - +
+
+
+
+ +
+
+
+ + +
+
+ + 接口的类型
+ 后台图片接口地址:/ext/attachment/adminfile/uploadpic?type=接口标识
+ 后台文件接口地址:/ext/attachment/adminfile/upload?type=接口标识
+ 前台图片接口地址:/ext/attachment/homefile/uploadpic?type=接口标识
+ 前台文件接口地址:/ext/attachment/homefile/upload?type=接口标识
+
+
+
+
+
+
+
+ +
+
+
+
+
+ + + 输入接口返回规则,必填 ,${id}图片id${url}图片地址,${name}图片名称,默认接口只返回 id + +
+
+
+
+
{%if data.id%} diff --git a/src/controller/ext/mark/admin.js b/src/controller/ext/mark/admin.js new file mode 100644 index 00000000..7b80c4c8 --- /dev/null +++ b/src/controller/ext/mark/admin.js @@ -0,0 +1,73 @@ +// +---------------------------------------------------------------------- +// | CmsWing [ 网站内容管理框架 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2015-2115 http://www.cmswing.com All rights reserved. +// +---------------------------------------------------------------------- +// | Author: arterli +// +---------------------------------------------------------------------- +// 本文件不能删除 +module.exports = class extends think.cmswing.extAdmin { + /** + * index action + * 插件管理入口 + * @return {Promise} [] + */ + async indexAction() { + // 分页列表实例 + + // -- 获取插件目录名 + // this.ext.ext; + + // -- 获取当前分类 + // await this.gettype() + + // -- model调用 + // const list = await this.extModel('demo').select(); + // const list2 = await this.extModel('demo').demo(); + // const list3 = await think.extModel('demo','demo').demo(); + + // -- 分页 + // const model = this.extModel('demo'); + // const data = await model.page(this.get('page')).countSelect(); // 获取分页数据 + // console.log(data); + // const html = this.pagination(data); // 调取分页 + // this.assign('pagerData', html); // 分页展示使用 + + // -- ext service + // 无参数类的实例化 + // const Ser1 = this.extService('demo'); + // const Ser1 = think.extService('demo','demo'); + // const ser1 = Ser1.bbb('bbb'); + // console.log(ser1); + // 有参数类的实例化 + // const Ser2 = this.extService('demo','demo','aaa','bbb'); + // const Ser2 = think.extService('demo','demo','aaa','bbb'); + // const ser2 = Ser2.aaa(); + // console.log(ser2); + // 入口模版渲染 + return this.extDisplay(); + } + + /** + * 添加 + * @returns {*} + */ + async addAction() { + // d + + } + + /** + * 修改 + */ + async editAction() { + + } + + /** + * 删除 + */ + async delAction() { + + } +}; diff --git a/src/controller/ext/mark/config.js b/src/controller/ext/mark/config.js new file mode 100644 index 00000000..1085731d --- /dev/null +++ b/src/controller/ext/mark/config.js @@ -0,0 +1,49 @@ +module.exports = { + ext: 'mark', // 插件目录,必须为英文 + name: '图片水印', // 插件名称 + description: '为图片添加水印', // 插件描述 + isadm: 1, // 是否有后台管理,1:有,0:没有,入口地址:'/ext/amrk/admin/index' + isindex: 0, // 是否需要前台访问,1:需要,0:不需要,入口地址:'/ext/amrk/index/index' + version: '1.0', // 版本号 + author: 'shp', // 作者 + table: [], // 插件包含的 数据库表,不包含表前缀,如:cmswing_ext_table 就是 table,多个['table','table_2']没有留空数组。 + sql: '', // 插件安装的时候会找个名字的sql文件导入,默认 插件目录名.sql; + hooks: [], // 挂载的钩子,数组格式,如['hooks1', 'hooks2'],不挂载留空:[] + setting: [ + { + '图片水印设置': [ + { + 'name': 'title', // 配置在表单中的键名 ,这个会是this.config('title') + 'label': '显示标题:', // 表单的文字 + 'type': 'text', // 表单的类型:text、radio、select + 'value': 'cmswing开发团队', // 表单的默认值 + 'html': '说明支持html' + }, + { + 'name': 'width', + 'label': '显示宽度:', + 'type': 'select', + 'options': {'1': '1格', '2': '2格', '4': '4格'}, + 'value': '2' + }, + { + 'name': 'display', + 'label': '是否显示:', + 'type': 'radio', + 'options': {'1': '显示', '0': '不显示'}, + 'value': '1' + } + ] + }, + { + '配置项二': [ + { + 'name': 'p2', + 'label': '1111', + 'type': 'text', + 'value': '1111' + } + ] + } + ] +}; \ No newline at end of file diff --git a/src/controller/ext/mark/index.js b/src/controller/ext/mark/index.js new file mode 100644 index 00000000..82922395 --- /dev/null +++ b/src/controller/ext/mark/index.js @@ -0,0 +1,60 @@ + +// +---------------------------------------------------------------------- +// | CmsWing [ 网站内容管理框架 ] +// +---------------------------------------------------------------------- +// | Copyright (c) 2015-2115 http://www.cmswing.com All rights reserved. +// +---------------------------------------------------------------------- +// | Author: arterli +// +---------------------------------------------------------------------- +/** + * 插件前台控制器 + * 如果插件有前台展示业务,写在这个控制器里面 + * 插件如需建立表务必遵循下面格式: + * 单表:表前缀_ext_插件目录名 + * 多表:表前缀_ext_插件目录名,表前缀_ext_插件目录名_分表1,表前缀_ext_插件目录名_分表2... + */ +module.exports = class extends think.cmswing.extIndex { + /** + * index action + * + * @return {Promise} [] + */ + + async indexAction() { + // -- 获取插件目录名 + // this.ext.ext; + + // -- 获取当前分类 + // await this.gettype() + + // -- model调用 + // const list = await this.extModel('demo').select(); + // const list2 = await this.extModel('demo').demo(); + // const list3 = await think.extModel('demo','demo').demo(); + + // -- 分页 + // const model = this.extModel('demo'); + // const data = await model.page(this.get('page')).countSelect(); // 获取分页数据 + // console.log(data); + // const html = this.pagination(data); // 调取分页 + // this.assign('pagerData', html); // 分页展示使用 + + // -- ext service + // 无参数类的实例化 + // const Ser1 = this.extService('demo'); + // const Ser1 = think.extService('demo','demo'); + // const ser1 = Ser1.bbb('bbb'); + // console.log(ser1); + // 有参数类的实例化 + // const Ser2 = this.extService('demo','demo','aaa','bbb'); + // const Ser2 = think.extService('demo','demo','aaa','bbb'); + // const ser2 = Ser2.aaa(); + // console.log(ser2); + + if (this.isMobile) { + return this.extDisplay('m'); + } else { + return this.extDisplay(); + } + } +}; diff --git a/src/controller/ext/mark/model/demo.js b/src/controller/ext/mark/model/demo.js new file mode 100644 index 00000000..422c1372 --- /dev/null +++ b/src/controller/ext/mark/model/demo.js @@ -0,0 +1,6 @@ +module.exports = class extends think.Model { + async demo() { + const list = await this.select(); + return list; + } +}; diff --git a/src/controller/ext/mark/service/demo.js b/src/controller/ext/mark/service/demo.js new file mode 100644 index 00000000..7fb9b82c --- /dev/null +++ b/src/controller/ext/mark/service/demo.js @@ -0,0 +1,13 @@ +module.exports = class extends think.Service { + constructor(key, secret) { + super(); + this.key = key; + this.secret = secret; + } + aaa() { + return `key:${this.key},secret:${this.secret}`; + } + bbb(bbb) { + return bbb; + } +}; diff --git a/src/controller/ext/mark/view/mobile/index_index.html b/src/controller/ext/mark/view/mobile/index_index.html new file mode 100644 index 00000000..bf09d501 --- /dev/null +++ b/src/controller/ext/mark/view/mobile/index_index.html @@ -0,0 +1,33 @@ + + + + +New ThinkJS Application + + + +
+
+

A New App Created By ThinkJS

+
+
+
+ mobile +
+
+ + \ No newline at end of file diff --git a/src/controller/ext/mark/view/pc/admin_index.html b/src/controller/ext/mark/view/pc/admin_index.html new file mode 100644 index 00000000..5a2fe39b --- /dev/null +++ b/src/controller/ext/mark/view/pc/admin_index.html @@ -0,0 +1,89 @@ +{% extends "view/admin/ext_admin.html" %} +{% block extadmin %} +
+
+ + +
+
+ +
+
+ + 全部 + + {%for t in type%} + + {{t.name}} + + {%endfor%} +
+
+ +
+ +
+ + + + + + + + + + + + + + + {% for item in list %} + + + + + + + + + + + + {% else %} + + + {% endfor %} + + +
排序网站名称网站logo分类链接类型状态操作
{{item.name}}{%if item.logo%}{%else%}无{%endif%}{{item.version}}{%if item.linktype ==1%}logo链接{%else%}文字链接{%endif%}{%if item.passed ==1%}已通过{%else%}待审核{%endif%} + + 修改 + 删除
+ +

这是后台插件模板的一个例子!

+
+
+ + +
+
+ +
+
+ 排序 + 删除 +
+
+ +
+ {{pagerData | safe}} +
+
+
+ +
+{% endblock %} diff --git a/src/controller/ext/mark/view/pc/index_index.html b/src/controller/ext/mark/view/pc/index_index.html new file mode 100644 index 00000000..dac84b33 --- /dev/null +++ b/src/controller/ext/mark/view/pc/index_index.html @@ -0,0 +1,33 @@ + + + + +New ThinkJS Application + + + +
+
+

A New App Created By ThinkJS

+
+
+
+ pc +
+
+ + \ No newline at end of file -- Gitee From c6a37f9c980556992e312aeecbe1f00ae51931eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Mon, 18 Dec 2017 15:24:10 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B0=B4=E5=8D=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=20=E5=89=8D=E5=8F=B0=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/controller/ext/mark/config.js | 66 ++++++----- src/controller/ext/mark/service/demo.js | 13 --- src/controller/ext/mark/service/mark.js | 53 +++++++++ view/ext/setting.html | 144 +++++++++++++++++++++++- 5 files changed, 232 insertions(+), 45 deletions(-) delete mode 100644 src/controller/ext/mark/service/demo.js create mode 100644 src/controller/ext/mark/service/mark.js diff --git a/package.json b/package.json index 89f502b9..ac484f82 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "dependencies": { "co-wechat-api": "^3.3.2", "gt3-sdk": "^2.0.0", + "images": "^3.0.1", "jimp": "^0.2.28", "lodash": "4.x.x", "moment": "^2.19.4", diff --git a/src/controller/ext/mark/config.js b/src/controller/ext/mark/config.js index 1085731d..5547694c 100644 --- a/src/controller/ext/mark/config.js +++ b/src/controller/ext/mark/config.js @@ -2,48 +2,60 @@ module.exports = { ext: 'mark', // 插件目录,必须为英文 name: '图片水印', // 插件名称 description: '为图片添加水印', // 插件描述 - isadm: 1, // 是否有后台管理,1:有,0:没有,入口地址:'/ext/amrk/admin/index' + isadm: 0, // 是否有后台管理,1:有,0:没有,入口地址:'/ext/amrk/admin/index' isindex: 0, // 是否需要前台访问,1:需要,0:不需要,入口地址:'/ext/amrk/index/index' version: '1.0', // 版本号 - author: 'shp', // 作者 + author: '孙会鹏', // 作者 table: [], // 插件包含的 数据库表,不包含表前缀,如:cmswing_ext_table 就是 table,多个['table','table_2']没有留空数组。 sql: '', // 插件安装的时候会找个名字的sql文件导入,默认 插件目录名.sql; hooks: [], // 挂载的钩子,数组格式,如['hooks1', 'hooks2'],不挂载留空:[] setting: [ { - '图片水印设置': [ + '水印设置': [ { - 'name': 'title', // 配置在表单中的键名 ,这个会是this.config('title') - 'label': '显示标题:', // 表单的文字 - 'type': 'text', // 表单的类型:text、radio、select - 'value': 'cmswing开发团队', // 表单的默认值 - 'html': '说明支持html' + 'name': 'mark', + 'label': '图片:', + 'type': 'pic', + 'value': '960', + 'html': '水印图片' }, { - 'name': 'width', - 'label': '显示宽度:', - 'type': 'select', - 'options': {'1': '1格', '2': '2格', '4': '4格'}, - 'value': '2' + 'name': 'right', + 'label': '右边距:', + 'type': 'text', + 'value': '10', + 'html': '只需要填写数字,列如:10' }, { - 'name': 'display', - 'label': '是否显示:', - 'type': 'radio', - 'options': {'1': '显示', '0': '不显示'}, - 'value': '1' - } - ] - }, - { - '配置项二': [ + 'name': 'bottom', + 'label': '下边距:', + 'type': 'text', + 'value': '10', + 'html': '只需要填写数字,列如:10' + }, { - 'name': 'p2', - 'label': '1111', + 'name': 'left', + 'label': '最小左边距:', 'type': 'text', - 'value': '1111' + 'value': '100', + 'html': '只需要填写数字,列如:100' + }, + { + 'name': 'top', + 'label': '最小上边距:', + 'type': 'text', + 'value': '100', + 'html': '只需要填写数字,列如:100' + }, + { + 'name': 'state', // 配置在表单中的键名 ,这个会是this.config('title') + 'label': '是否启用:', // 表单的文字 + 'type': 'radio', + 'options': {'1': '启用', '0': '禁用'}, + 'value': '0', + 'html': '选择启用后,符合条件的图片将会添加水印' } ] } ] -}; \ No newline at end of file +}; diff --git a/src/controller/ext/mark/service/demo.js b/src/controller/ext/mark/service/demo.js deleted file mode 100644 index 7fb9b82c..00000000 --- a/src/controller/ext/mark/service/demo.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = class extends think.Service { - constructor(key, secret) { - super(); - this.key = key; - this.secret = secret; - } - aaa() { - return `key:${this.key},secret:${this.secret}`; - } - bbb(bbb) { - return bbb; - } -}; diff --git a/src/controller/ext/mark/service/mark.js b/src/controller/ext/mark/service/mark.js new file mode 100644 index 00000000..2095ec47 --- /dev/null +++ b/src/controller/ext/mark/service/mark.js @@ -0,0 +1,53 @@ +var images = require('images'); +var path = require('path'); + +module.exports = class extends think.Service { + // 初始化构造函数 + constructor(...para) { + super(para); + // 白名单 + this.suffixs = ['png', 'jpg']; + // 边距 + this.edge = { + right: 10, + bottom: 10, + minLeft: 100, + minTop: 100 + }; + // 水印路径 + this.markpath = '/Users/zzu/Desktop/demo/mark.png'; + } + + // 添加水印 + mark(imgPath, option) { + try { + return this.draw(imgPath); + } catch (e) { + return false; + } + } + + // 绘制 + draw(imgPath) { + // 存在且是图片 + if (think.isFile(imgPath) && in_array(path.extname(imgPath), this.suffixs)) { + // 加载资源 + const sourceImg = images(imgPath); + const markImg = images(this.markpath); + // 计算水印位置 + const markX = sourceImg.width() - markImg.width() - this.edge.right; + const markY = sourceImg.height() - markImg.height() - this.edge.bottom; + // 判断最小范围 + if (markX < this.edge.minLeft || markY < this.edge.minTop) { + return false; + } + // 绘制水印 + images(sourceImg) + // 设置绘制的坐标位置,右下角距离 10px + .draw(markImg, markX, markY) + // 保存格式会自动识别 + .save(imgPath); + } + return true; + } +}; diff --git a/view/ext/setting.html b/view/ext/setting.html index 869ca625..ae5892af 100644 --- a/view/ext/setting.html +++ b/view/ext/setting.html @@ -8,7 +8,8 @@ {%for v in extConfig.setting%} {%set index = loop.index%} {% for ingredient, amount in v %} -
  • {{ingredient}}
  • +
  • {{ingredient}}
  • {% endfor %} {%endfor%} @@ -27,11 +28,140 @@ {%if input.type == 'text'%} {{forms.text(setting,label= input.label, name= input.name, value=input.value, html= input.html)}} {%elif input.type == 'radio'%} - {{forms.radio(setting,label=input.label, name=input.name, value=input.value, options=input.options,html=input.html)}} + {{forms.radio(setting,label=input.label, name=input.name, value=input.value, + options=input.options,html=input.html)}} {%elif input.type == 'select'%} - {{forms.select(setting,label=input.label, name= input.name, value=input.value, options=input.options,html=input.html)}} + {{forms.select(setting,label=input.label, name= input.name, value=input.value, + options=input.options,html=input.html)}} {%elif input.type == 'textarea'%} - {{forms.textarea(setting,label= input.label, name= input.name, value=input.value, html= input.html)}} + {{forms.textarea(setting,label= input.label, name= input.name, value=input.value, html= + input.html)}} + {%elif input.type == 'pic'%} +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    选择图片
    +
    +
    + this.config('ext.{{setting.ext}}.{{input.name}}') + {%if html%} + {{html|safe}} + {%endif%} +
    +
    +
    +
    + + + + {%endif%} {%endfor%}
    @@ -53,11 +183,15 @@
    -
    {% endblock %} +{% block style %} +{{ super() }} + +{% endblock%} {% block script%} +{{ super() }} {% endblock%} \ No newline at end of file -- Gitee From d82ab8b824f69e2fdb60e4d4dd04874dbbc8fdf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Mon, 18 Dec 2017 17:29:18 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B0=B4=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/ext/attachment/adminfile.js | 66 +++++++++++++------ src/controller/ext/attachment/homefile.js | 41 ++++++++---- src/controller/ext/editor/adminueditor.js | 3 +- src/controller/ext/editor/homeueditor.js | 3 +- src/controller/ext/editor/service/ueditor.js | 10 +++ src/controller/ext/mark/admin.js | 34 +--------- src/controller/ext/mark/service/mark.js | 30 ++++++--- .../ext/mark/view/pc/admin_index.html | 19 ------ view/ext/setting.html | 2 +- 9 files changed, 116 insertions(+), 92 deletions(-) diff --git a/src/controller/ext/attachment/adminfile.js b/src/controller/ext/attachment/adminfile.js index e637c6d9..76fbf265 100644 --- a/src/controller/ext/attachment/adminfile.js +++ b/src/controller/ext/attachment/adminfile.js @@ -16,21 +16,24 @@ module.exports = class extends think.Controller { return this.fail('非法操作!'); } } + constructor(ctx) { super(ctx); this.pdb = this.model('ext_attachment_pic'); this.fdb = this.model('ext_attachment_file'); } + /** - * 判断是否登录 - * @returns {boolean} - */ + * 判断是否登录 + * @returns {boolean} + */ async islogin() { // 判断是否登录 const user = await this.session('userInfo'); const res = think.isEmpty(user) ? false : user.uid; return res; } + /** * index action * @return {Promise} [] @@ -39,6 +42,7 @@ module.exports = class extends think.Controller { // auto render template file index_index.html return this.display(); } + // 上传文件 async uploadAction() { const file = think.extend({}, this.file('file')); @@ -93,7 +97,6 @@ module.exports = class extends think.Controller { const res = await this.fdb.add(data); return this.json({id: res, size: file.size}); } - // 上传图片 async uploadpicAction() { const type = this.get('type'); @@ -129,45 +132,48 @@ module.exports = class extends think.Controller { }; } } else { - const uploadPath = think.resource + '/upload/picture/' + dateformat('Y-m-d', new Date().getTime()); - think.mkdir(uploadPath); - if (think.isFile(filepath)) { - fs.renameSync(filepath, uploadPath + '/' + basename); - } else { - console.log('文件不存在!'); - } - file.path = uploadPath + '/' + basename; + // 默认路径 + const uploadPath = this.saveFile(filepath, 'picture', basename, att); + // 返回最新路径 + file.path = uploadPath.path + '/' + basename; if (think.isFile(file.path)) { data = { - path: '/upload/picture/' + dateformat('Y-m-d', new Date().getTime()) + '/' + basename, + path: uploadPath.root + '/' + basename, create_time: new Date().getTime(), status: 1 - }; + // 添加水印 + if (att.mark == 1) { + const mark = this.extService('mark', 'mark'); + mark.mark(file.path); + } } else { console.log('not exist'); } } + + // 添加文件并返回结果 const res = await this.pdb.add(data); const r = {id: res, url: await get_pic(res), name: (file.name).trim()}; let rr = {}; if (!think.isEmpty(att) && !think.isEmpty(att.rule)) { const match = att.rule.match(/\${(\S+?)\}/g); - console.log(match); + // console.log(match); const replace = []; for (let val of match) { val = val.replace(/(^\${)|(\}$)/g, ''); replace.push(r[val]); } - console.log(replace); + // console.log(replace); rr = str_replace(match, replace, att.rule); - console.log(rr); + // console.log(rr); if (att.rule.indexOf('{') === 0) { rr = JSON.parse(rr); } } return think.isEmpty(rr) ? this.json(res) : this.json(rr); } + // 获取七牛token async getqiniuuptokenAction() { const qiniu = this.extService('qiniu', 'attachment'); @@ -177,6 +183,26 @@ module.exports = class extends think.Controller { 'uptoken': uptoken }); } + // 转移文件 + saveFile(filepath, defpath, basename, attr) { + // 处理路径 + if (attr.path != null && !think.isEmpty(attr.path.trim())) { + defpath = attr.path.trim(); + }; + // 生成目录 + const rootpath = `/upload/${defpath}/${dateformat('Y-m-d', new Date().getTime())}`; + const uploadPath = `${think.resource}${rootpath}`; + think.mkdir(uploadPath); + // 转移文件 + if (think.isFile(filepath)) { + fs.renameSync(filepath, uploadPath + '/' + basename); + } + return { + path: uploadPath, + root: rootpath, + def: defpath + }; + } // 添加 async qiniuaddAction() { const post = this.post(); @@ -194,6 +220,7 @@ module.exports = class extends think.Controller { const res = await this.fdb.add(data); return this.json(res); } + // 删除七牛资源 async delqiniufileAction() { const id = this.get('id'); @@ -207,10 +234,11 @@ module.exports = class extends think.Controller { return this.fail('删除文件失败!'); } } + // 文件信息 - async fileinfoAction(){ + async fileinfoAction() { const res = await this.fdb.find(this.get('id')); - if(!think.isEmpty(res)){ + if (!think.isEmpty(res)) { res.time = this.moment(res.create_time).format('lll'); } return this.json(res); diff --git a/src/controller/ext/attachment/homefile.js b/src/controller/ext/attachment/homefile.js index ae12f26c..a0fb5f7b 100644 --- a/src/controller/ext/attachment/homefile.js +++ b/src/controller/ext/attachment/homefile.js @@ -126,21 +126,21 @@ module.exports = class extends think.cmswing.center { }; } } else { - const uploadPath = think.resource + '/upload/picture/' + dateformat('Y-m-d', new Date().getTime()); - think.mkdir(uploadPath); - if (think.isFile(filepath)) { - fs.renameSync(filepath, uploadPath + '/' + basename); - } else { - console.log('文件不存在!'); - } - file.path = uploadPath + '/' + basename; + // 默认路径 + const uploadPath = this.saveFile(filepath, 'picture', basename, att); + // 返回最新路径 + file.path = uploadPath.path + '/' + basename; if (think.isFile(file.path)) { data = { - path: '/upload/picture/' + dateformat('Y-m-d', new Date().getTime()) + '/' + basename, + path: uploadPath.root + '/' + basename, create_time: new Date().getTime(), status: 1 - }; + // 添加水印 + if (att.mark == 1) { + const mark = this.extService('mark', 'mark'); + mark.mark(file.path); + } } else { console.log('not exist'); } @@ -165,7 +165,26 @@ module.exports = class extends think.cmswing.center { } return think.isEmpty(rr) ? this.json(res) : this.json(rr); } - + // 转移文件 + saveFile(filepath, defpath, basename, attr) { + // 处理路径 + if (!think.isEmpty(attr.path.trim())) { + defpath = attr.path.trim(); + }; + // 生成目录 + const rootpath = `/upload/${defpath}/${dateformat('Y-m-d', new Date().getTime())}`; + const uploadPath = `${think.resource}${rootpath}`; + think.mkdir(uploadPath); + // 转移文件 + if (think.isFile(filepath)) { + fs.renameSync(filepath, uploadPath + '/' + basename); + } + return { + path: uploadPath, + root: rootpath, + def: defpath + }; + } // 获取七牛token async getqiniuuptokenAction() { const qiniu = this.extService('qiniu', 'attachment'); diff --git a/src/controller/ext/editor/adminueditor.js b/src/controller/ext/editor/adminueditor.js index 6d478dc1..9e3392fb 100644 --- a/src/controller/ext/editor/adminueditor.js +++ b/src/controller/ext/editor/adminueditor.js @@ -205,7 +205,8 @@ module.exports = class extends think.Controller { config = { pathFormat: this.config['imagePathFormat'], maxSize: this.config['imageMaxSize'], - allowFiles: this.config['imageAllowFiles'] + allowFiles: this.config['imageAllowFiles'], + mark: true }; fieldName = this.config['imageFieldName']; break; diff --git a/src/controller/ext/editor/homeueditor.js b/src/controller/ext/editor/homeueditor.js index d246d9f5..069fef83 100644 --- a/src/controller/ext/editor/homeueditor.js +++ b/src/controller/ext/editor/homeueditor.js @@ -177,7 +177,8 @@ module.exports = class extends think.Controller { config = { pathFormat: this.config['imagePathFormat'], maxSize: this.config['imageMaxSize'], - allowFiles: this.config['imageAllowFiles'] + allowFiles: this.config['imageAllowFiles'], + mark: true }; fieldName = this.config['imageFieldName']; break; diff --git a/src/controller/ext/editor/service/ueditor.js b/src/controller/ext/editor/service/ueditor.js index 43c76f6a..3f71c73d 100644 --- a/src/controller/ext/editor/service/ueditor.js +++ b/src/controller/ext/editor/service/ueditor.js @@ -65,6 +65,11 @@ module.exports = class extends think.Service { } // 移动文件 fs.renameSync(file.path, this.filePath); + // 添加水印 + if (this.config.mark == true) { + const mark = think.extService('mark', 'mark'); + mark.mark(this.filePath); + } if (think.isFile(this.filePath)) { this.stateInfo = 'SUCCESS'; } else { @@ -103,6 +108,11 @@ module.exports = class extends think.Service { // 移动文件 // fs.renameSync(img, this.filePath); fs.writeFileSync(this.filePath, img); + // 添加水印 + if (this.config.mark == true) { + const mark = think.extService('mark', 'mark'); + mark.mark(this.filePath); + } if (think.isFile(this.filePath)) { this.stateInfo = 'SUCCESS'; } else { diff --git a/src/controller/ext/mark/admin.js b/src/controller/ext/mark/admin.js index 7b80c4c8..c2a2c9d5 100644 --- a/src/controller/ext/mark/admin.js +++ b/src/controller/ext/mark/admin.js @@ -7,43 +7,15 @@ // +---------------------------------------------------------------------- // 本文件不能删除 module.exports = class extends think.cmswing.extAdmin { + constructor(ctx) { + super(ctx); + } /** * index action * 插件管理入口 * @return {Promise} [] */ async indexAction() { - // 分页列表实例 - - // -- 获取插件目录名 - // this.ext.ext; - - // -- 获取当前分类 - // await this.gettype() - - // -- model调用 - // const list = await this.extModel('demo').select(); - // const list2 = await this.extModel('demo').demo(); - // const list3 = await think.extModel('demo','demo').demo(); - - // -- 分页 - // const model = this.extModel('demo'); - // const data = await model.page(this.get('page')).countSelect(); // 获取分页数据 - // console.log(data); - // const html = this.pagination(data); // 调取分页 - // this.assign('pagerData', html); // 分页展示使用 - - // -- ext service - // 无参数类的实例化 - // const Ser1 = this.extService('demo'); - // const Ser1 = think.extService('demo','demo'); - // const ser1 = Ser1.bbb('bbb'); - // console.log(ser1); - // 有参数类的实例化 - // const Ser2 = this.extService('demo','demo','aaa','bbb'); - // const Ser2 = think.extService('demo','demo','aaa','bbb'); - // const ser2 = Ser2.aaa(); - // console.log(ser2); // 入口模版渲染 return this.extDisplay(); } diff --git a/src/controller/ext/mark/service/mark.js b/src/controller/ext/mark/service/mark.js index 2095ec47..9e32cf2e 100644 --- a/src/controller/ext/mark/service/mark.js +++ b/src/controller/ext/mark/service/mark.js @@ -6,33 +6,38 @@ module.exports = class extends think.Service { constructor(...para) { super(para); // 白名单 - this.suffixs = ['png', 'jpg']; + this.suffixs = ['.png', '.jpg']; // 边距 this.edge = { - right: 10, - bottom: 10, - minLeft: 100, - minTop: 100 + right: think.config('ext.mark.right'), + bottom: think.config('ext.mark.bottom'), + minLeft: think.config('ext.mark.left'), + minTop: think.config('ext.mark.top') }; // 水印路径 + this.markpic = think.config('ext.mark.mark'); + // 状态 + this.state = think.config('ext.mark.state'); this.markpath = '/Users/zzu/Desktop/demo/mark.png'; } // 添加水印 - mark(imgPath, option) { + async mark(imgPath, option) { try { return this.draw(imgPath); } catch (e) { + console.error(e); return false; } } // 绘制 - draw(imgPath) { + async draw(imgPath) { // 存在且是图片 - if (think.isFile(imgPath) && in_array(path.extname(imgPath), this.suffixs)) { + if (think.isFile(imgPath) && in_array(path.extname(imgPath), this.suffixs) && this.state == 1) { // 加载资源 const sourceImg = images(imgPath); + this.markpath = await this.GetPath(this.markpic); const markImg = images(this.markpath); // 计算水印位置 const markX = sourceImg.width() - markImg.width() - this.edge.right; @@ -47,7 +52,14 @@ module.exports = class extends think.Service { .draw(markImg, markX, markY) // 保存格式会自动识别 .save(imgPath); + return false; } - return true; + return false; + } + + // 获得水印路径 + async GetPath(pic){ + const path = await get_pic(pic); + return `${think.resource}/${path}`; } }; diff --git a/src/controller/ext/mark/view/pc/admin_index.html b/src/controller/ext/mark/view/pc/admin_index.html index 5a2fe39b..0ac51aa5 100644 --- a/src/controller/ext/mark/view/pc/admin_index.html +++ b/src/controller/ext/mark/view/pc/admin_index.html @@ -4,27 +4,8 @@
    -
    -
    - -
    -
    - - 全部 - - {%for t in type%} - - {{t.name}} - - {%endfor%} -
    -
    - -
    diff --git a/view/ext/setting.html b/view/ext/setting.html index ae5892af..be001bee 100644 --- a/view/ext/setting.html +++ b/view/ext/setting.html @@ -83,7 +83,7 @@ // swf文件路径 swf: '/static/admin/js/webuploader/Uploader.swf', // 文件接收服务端。 - server: '/ext/attachment/adminfile/uploadpic', + server: '/ext/attachment/adminfile/uploadpic?type={{setting.ext}}', // 选择文件的按钮。可选。 // 内部根据当前运行是创建,可能是input元素,也可能是flash. pick: { -- Gitee From 454bc3f071a22462fdf5a846dd73b289fc298eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=BC=9A=E9=B9=8F?= <1571360448@qq.com> Date: Mon, 18 Dec 2017 17:41:39 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=BF=98=E5=8E=9F=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/model.js b/src/config/model.js index 9dd3afb8..657f8aee 100644 --- a/src/config/model.js +++ b/src/config/model.js @@ -16,7 +16,7 @@ module.exports = { mysql: { handle: mysql, // Adapter handle user: 'root', // 用户名 - password: '', // 密码 + password: 'root', // 密码 database: 'cmswing', // 数据库 host: '127.0.0.1', // host port: 3306, // 端口 -- Gitee