From 0d2ef312228e6ef6636a7d06a63715f27e79ea06 Mon Sep 17 00:00:00 2001 From: tensent Date: Wed, 25 Mar 2020 17:08:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common.php | 8 +- app/controller/Front.php | 24 ++ app/controller/Upload.php | 24 ++ app/controller/admin/Channel.php | 21 +- app/controller/admin/Form.php | 64 +++-- app/controller/admin/Index.php | 4 +- app/controller/admin/User.php | 5 +- app/http/form/Factory.php | 42 ++++ app/http/form/Form.php | 33 +++ app/http/form/factory/Checkbox.php | 26 ++ app/http/form/factory/Text.php | 22 ++ app/http/form/template/checkbox.html | 6 + app/http/form/template/editor.html | 7 + app/http/form/template/images.html | 47 ++++ app/http/form/template/select.html | 5 + app/http/form/template/text.html | 1 + app/http/form/template/textarea.html | 1 + app/model/Form.php | 48 +++- app/model/FormAttr.php | 90 ++++--- app/model/Member.php | 2 +- app/ueditor.json | 94 +++++++ composer.json | 4 +- config/addons.php | 17 ++ config/log.php | 2 +- extend/com/Datatable.php | 275 +++++++++++++++++++++ extend/com/Ueditor.php | 354 +++++++++++++++++++++++++++ public/template/front/form.html | 50 ++++ route/app.php | 2 + view/admin/channel/add.html | 1 + view/admin/channel/edit.html | 6 +- view/admin/channel/index.html | 24 +- view/admin/form/attr.html | 8 +- view/admin/form/index.html | 19 +- view/admin/public/edit.html | 4 +- view/admin/public/header.html | 2 +- 35 files changed, 1212 insertions(+), 130 deletions(-) create mode 100644 app/controller/Upload.php create mode 100644 app/http/form/Factory.php create mode 100644 app/http/form/Form.php create mode 100644 app/http/form/factory/Checkbox.php create mode 100644 app/http/form/factory/Text.php create mode 100644 app/http/form/template/checkbox.html create mode 100644 app/http/form/template/editor.html create mode 100644 app/http/form/template/images.html create mode 100644 app/http/form/template/select.html create mode 100644 app/http/form/template/text.html create mode 100644 app/http/form/template/textarea.html create mode 100644 app/ueditor.json create mode 100644 config/addons.php create mode 100644 extend/com/Datatable.php create mode 100644 extend/com/Ueditor.php create mode 100644 public/template/front/form.html create mode 100644 view/admin/channel/add.html diff --git a/app/common.php b/app/common.php index d290aabe..9bf894da 100755 --- a/app/common.php +++ b/app/common.php @@ -23,9 +23,13 @@ function is_administrator() { return true; } -function hook() {} +function form($field = [], $data = []) { + return \app\http\form\Form::render($field, $data); +} -function widget() {} +function parse_field_bind(){ + +} /** * 获取客户端IP地址 diff --git a/app/controller/Front.php b/app/controller/Front.php index cfbf1d18..6b07df75 100644 --- a/app/controller/Front.php +++ b/app/controller/Front.php @@ -8,8 +8,32 @@ // +---------------------------------------------------------------------- namespace app\controller; +use \app\model\Form; + + class Front extends Base { public function index() { return $this->fetch(); } + + public function form(){ + if($this->request->isAjax()){ + + }else{ + $id = $this->request->param('id'); + $name = $this->request->param('name'); + + $map = []; + + $map[] = ['id', '=', $id]; + + $info = Form::where($map)->find(); + + + $this->data = [ + 'info' => $info + ]; + return $this->fetch(); + } + } } diff --git a/app/controller/Upload.php b/app/controller/Upload.php new file mode 100644 index 00000000..05e86683 --- /dev/null +++ b/app/controller/Upload.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- +namespace app\controller; + +use think\facade\Session; + +class Upload extends Base { + + public $data = ['data' => [], 'code' => 0, 'msg' => '']; + + protected function initialize() { + } + + public function ueditor(){ + $data = new \com\Ueditor(Session::get('userInfo.uid')); + echo $data->output(); + } +} \ No newline at end of file diff --git a/app/controller/admin/Channel.php b/app/controller/admin/Channel.php index 0438ed22..f1256952 100644 --- a/app/controller/admin/Channel.php +++ b/app/controller/admin/Channel.php @@ -48,7 +48,7 @@ class Channel extends Admin { */ public function editable($name = null, $value = null, $pk = null) { if ($name && ($value != null || $value != '') && $pk) { - model('Channel')->where(array('id' => $pk))->setField($name, $value); + ChannelM::where(array('id' => $pk))->update([$name => $value]); } } @@ -58,10 +58,9 @@ class Channel extends Admin { */ public function add() { if ($this->request->isPost()) { - $Channel = model('Channel'); $data = $this->request->post(); if ($data) { - $id = $Channel->save($data); + $id = ChannelM::save($data); if ($id) { return $this->success('新增成功', url('index')); //记录行为 @@ -70,21 +69,23 @@ class Channel extends Admin { return $this->error('新增失败'); } } else { - $this->error($Channel->getError()); + $this->error('新增失败'); } } else { $pid = input('pid', 0); //获取父导航 if (!empty($pid)) { - $parent = db('Channel')->where(array('id' => $pid))->field('title')->find(); + $parent = ChannelM::where(array('id' => $pid))->field('title')->find(); $this->assign('parent', $parent); } - $pnav = db('Channel')->where(array('pid' => '0'))->select(); - $this->assign('pnav', $pnav); - $this->assign('pid', $pid); - $this->assign('info', null); - $this->setMeta('新增导航'); + $pnav = ChannelM::where(array('pid' => '0'))->select(); + + $this->data = [ + 'pnav' => $pnav, + 'pid' => $pid, + 'info' => ['pid' => $pid] + ]; return $this->fetch('edit'); } } diff --git a/app/controller/admin/Form.php b/app/controller/admin/Form.php index 6be170e5..3ee4ad1f 100644 --- a/app/controller/admin/Form.php +++ b/app/controller/admin/Form.php @@ -10,6 +10,7 @@ namespace app\controller\admin; use app\controller\Admin; use app\model\Form as FormM; +use app\model\FormAttr; /** * @title 自定义表单 @@ -37,44 +38,40 @@ class Form extends Admin { /** * @title 添加表单 */ - public function add(\think\Request $request) { + public function add() { if ($this->request->isPost()) { - $result = $this->model->validate('Form')->save($request->post()); + $result = FormM::create($this->request->post()); if (false !== $result) { - return $this->success('添加成功!', url('admin/form/index')); + return $this->success('添加成功!', url('/admin/form/index')); } else { return $this->error($this->model->getError()); } } else { - $data = array( - 'keyList' => $this->model->addField, + $this->data = array( + 'keyList' => (new FormM())->addField, ); - $this->assign($data); - $this->setMeta('添加表单'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } /** * @title 编辑表单 */ - public function edit(\think\Request $request) { + public function edit() { if ($this->request->isPost()) { - $result = $this->model->validate('Form')->save($request->post(), array('id' => $request->post('id'))); + $result = FormM::update($this->request->post(), array('id' => $this->request->param('id'))); if (false !== $result) { - return $this->success('修改成功!', url('admin/form/index')); + return $this->success('修改成功!', url('/admin/form/index')); } else { return $this->error($this->model->getError()); } } else { - $info = $this->model->where('id', $request->param('id'))->find(); - $data = array( + $info = FormM::where('id', $this->request->param('id'))->find(); + $this->data = array( 'info' => $info, - 'keyList' => $this->model->editField, + 'keyList' => (new FormM())->editField, ); - $this->assign($data); - $this->setMeta('编辑表单'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } @@ -155,17 +152,18 @@ class Form extends Admin { * @title 表单字段 */ public function attr($form_id = '') { - $map = array(); + $map = []; $order = "id desc"; - $list = $this->Fattr->where($map)->order($order)->paginate(25); - $data = array( + $map[] = ['form_id', '=', $form_id]; + + $list = FormAttr::where($map)->order($order)->paginate(25); + + $this->data = array( 'list' => $list, 'form_id' => $form_id, 'page' => $list->render(), ); - $this->setMeta('表单字段'); - $this->assign($data); return $this->fetch(); } @@ -179,23 +177,18 @@ class Form extends Admin { } if ($this->request->isPost()) { $data = $this->request->post(); - $result = $this->Fattr->save($data); + $result = FormAttr::create($data); if (false !== $result) { return $this->success('添加成功!', url('admin/form/attr?form_id='.$form_id)); }else{ return $this->error($this->Fattr->getError()); } }else{ - $info = array( - 'form_id' => $form_id + $this->data = array( + 'info' => ['form_id' => $form_id], + 'keyList' => $this->getField() ); - $data = array( - 'info' => $info, - 'keyList' => $this->field - ); - $this->assign($data); - $this->setMeta('添加字段'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } @@ -247,18 +240,19 @@ class Form extends Admin { } protected function getField(){ + $config = \think\facade\Cache::get('system_config_data'); return array( array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'), array('name' => 'form_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'), array('name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'type' => 'text'), array('name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'), - array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $this->attr, 'help' => ''), + array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $config['config_type_list'], 'help' => ''), array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'), array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'), array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'), array('name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'), - array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => array('1' => '始终显示', '2' => '新增显示', '3' => '编辑显示', '0' => '不显示'), 'value' => 1), - array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array('0' => '否', '1' => '是')), + array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => [['key'=>'1', 'label' => '始终显示'], ['key' => '2', 'label' => '新增显示'], ['key' => '3', 'label' => '编辑显示'], ['key' => '0', 'label' => '不显示']], 'value' => 1), + array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array(['key'=>'0', 'label' => '否'], ['key'=>'1', 'label' => '是'])), ); } /** diff --git a/app/controller/admin/Index.php b/app/controller/admin/Index.php index 344bf536..eaa268fc 100755 --- a/app/controller/admin/Index.php +++ b/app/controller/admin/Index.php @@ -72,9 +72,9 @@ class Index extends Admin { $clear = input('post.clear/a', array()); foreach ($clear as $key => $value) { if ($value == 'cache') { - \think\Cache::clear(); // 清空缓存数据 + \think\facade\Cache::clear(); // 清空缓存数据 } elseif ($value == 'log') { - \think\Log::clear(); + \think\facade\Log::clear(); } } return $this->success("更新成功!", url('/admin/index/index')); diff --git a/app/controller/admin/User.php b/app/controller/admin/User.php index 1cc87e00..273f9329 100644 --- a/app/controller/admin/User.php +++ b/app/controller/admin/User.php @@ -67,12 +67,10 @@ class User extends Admin { } else { $info = $this->getUserinfo(); - $data = array( + $this->data = array( 'info' => $info, 'keyList' => $model->editfield, ); - $this->assign($data); - $this->setMeta("编辑用户"); return $this->fetch('public/edit'); } } @@ -216,7 +214,6 @@ class User extends Admin { return $this->error($user->getError()); } } else { - $this->setMeta('修改密码'); return $this->fetch(); } } diff --git a/app/http/form/Factory.php b/app/http/form/Factory.php new file mode 100644 index 00000000..da630204 --- /dev/null +++ b/app/http/form/Factory.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- +namespace app\http\form; + +use think\facade\View; + +/** + * @title 后台中间件 + */ +class Factory { + + protected $field = []; + protected $data = []; + + public function __construct($field, $data){ + $this->field = $field; + $this->data = $data; + $this->parseValue(); + } + + public function display($template = 'show', $data = []){ + View::config([ + 'view_path' => dirname(__file__) . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR + ]); + View::assign($data); + return View::fetch('/' . $template, $this->field); + } + + protected function parseValue(){ + $this->field['value'] = isset($this->data[$this->field['name']]) ? $this->data[$this->field['name']] : ''; + } + + public function show(){ + return $this->display($this->field['type']); + } +} \ No newline at end of file diff --git a/app/http/form/Form.php b/app/http/form/Form.php new file mode 100644 index 00000000..910da40f --- /dev/null +++ b/app/http/form/Form.php @@ -0,0 +1,33 @@ + +// +---------------------------------------------------------------------- +namespace app\http\form; + +use think\facade\View; + +/** + * @title 后台中间件 + */ +class Form { + + public static function render($field, $data){ + if (in_array($field['type'], ['string', 'text'])) { + $field['type'] = 'text'; + } + + $class = "app\\http\\form\\factory\\" . ucfirst($field['type']); + + if (class_exists($class)) { + $elem = new $class($field, $data); + }else{ + $elem = new \app\http\form\Factory($field, $data); + } + + return $elem->show(); + } +} \ No newline at end of file diff --git a/app/http/form/factory/Checkbox.php b/app/http/form/factory/Checkbox.php new file mode 100644 index 00000000..0c4bd89f --- /dev/null +++ b/app/http/form/factory/Checkbox.php @@ -0,0 +1,26 @@ + +// +---------------------------------------------------------------------- +namespace app\http\form\factory; + +use think\facade\View; + +/** + * @title 后台中间件 + */ +class Checkbox extends \app\http\form\Factory { + + public function show(){ + return $this->display('checkbox'); + } + + protected function parseValue(){ + $this->field['value'] = isset($this->data[$this->field['name']]) ? $this->data[$this->field['name']] : []; + } + +} \ No newline at end of file diff --git a/app/http/form/factory/Text.php b/app/http/form/factory/Text.php new file mode 100644 index 00000000..b4432c82 --- /dev/null +++ b/app/http/form/factory/Text.php @@ -0,0 +1,22 @@ + +// +---------------------------------------------------------------------- +namespace app\http\form\factory; + +use think\facade\View; + +/** + * @title 后台中间件 + */ +class Text extends \app\http\form\Factory { + + public function show(){ + return $this->display('text'); + } + +} \ No newline at end of file diff --git a/app/http/form/template/checkbox.html b/app/http/form/template/checkbox.html new file mode 100644 index 00000000..5c71589f --- /dev/null +++ b/app/http/form/template/checkbox.html @@ -0,0 +1,6 @@ +{volist name="option" id="item"} +
+ + +
+{/volist} \ No newline at end of file diff --git a/app/http/form/template/editor.html b/app/http/form/template/editor.html new file mode 100644 index 00000000..ebe5212b --- /dev/null +++ b/app/http/form/template/editor.html @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/app/http/form/template/images.html b/app/http/form/template/images.html new file mode 100644 index 00000000..07e71116 --- /dev/null +++ b/app/http/form/template/images.html @@ -0,0 +1,47 @@ +
+
上传图片
+ {if isset($value) && $value} + + {else/} + + {/if} +
+ {if $value} + {php} + $images = get_cover($value); + {/php} +
  • +
    + + + 上传时间:{$images['create_time']} +
    +
    +
    + +
    +
  • + {/if} +
    +
    + \ No newline at end of file diff --git a/app/http/form/template/select.html b/app/http/form/template/select.html new file mode 100644 index 00000000..855755ea --- /dev/null +++ b/app/http/form/template/select.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/http/form/template/text.html b/app/http/form/template/text.html new file mode 100644 index 00000000..8510d113 --- /dev/null +++ b/app/http/form/template/text.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/http/form/template/textarea.html b/app/http/form/template/textarea.html new file mode 100644 index 00000000..660868c6 --- /dev/null +++ b/app/http/form/template/textarea.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/model/Form.php b/app/model/Form.php index 44fae7c8..457be463 100644 --- a/app/model/Form.php +++ b/app/model/Form.php @@ -9,6 +9,11 @@ namespace app\model; +use think\facade\Config; +use phpspirit\dbskeleton\mysql\TableModel; +use phpspirit\dbskeleton\mysql\ColumnModel; +use phpspirit\dbskeleton\Factory; + /** * 表单 */ @@ -22,17 +27,40 @@ class Form extends \think\Model { 'update_time' => 'integer', ); - public $addField = array( - array('name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''), - array('name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''), - ); + public $addField = [ + ['name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''], + ['name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''], + ['name' => 'logo', 'title' => '显示Logo', 'type' => 'images', 'help' => ''], + ['name' => 'cover', 'title' => 'banner图片', 'type' => 'images', 'help' => ''], + ['name' => 'content', 'title' => '内容', 'type' => 'editor', 'help' => ''], + ]; - public $editField = array( - array('name' => 'id', 'title' => 'ID', 'type' => 'hidden', 'help' => ''), - array('name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''), - array('name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''), - array('name' => 'list_grid', 'title' => '列表定义', 'type' => 'textarea', 'help' => ''), - ); + public $editField = [ + ['name' => 'id', 'title' => 'ID', 'type' => 'hidden', 'help' => ''], + // ['name' => 'name', 'title' => '标识', 'type' => 'text', 'help' => ''], + ['name' => 'title', 'title' => '标题', 'type' => 'text', 'help' => ''], + ['name' => 'logo', 'title' => '显示Logo', 'type' => 'images', 'help' => ''], + ['name' => 'cover', 'title' => 'banner图片', 'type' => 'images', 'help' => ''], + ['name' => 'content', 'title' => '内容', 'type' => 'editor', 'help' => ''], + ['name' => 'list_grid', 'title' => '列表定义', 'type' => 'textarea', 'help' => ''], + ]; + + public static function onAfterInsert($model){ + $data = $model->getData(); + $mysql = Config::get('database.connections.mysql'); + $tablemodel = (new TableModel())->setCharset('utf8mb4') //设置编码 + ->setEngine('MyISAM') //设置引擎 + ->setTablename($mysql['prefix'] . 'form_' . $data['name']) //设置表名 + ->setComment($data['title']); //表备注 + + $id = (new ColumnModel())->setType('int')->setLen(11)->setName('id')->setIsPk(true)->setIncrement(true)->setComment('自增长'); + + $dbskeleton = Factory::instance('mysql', $mysql['hostname'] . ':' . $mysql['hostport'], $mysql['database'], $mysql['username'], $mysql['password']); + $dbskeleton->createTable($tablemodel, [$id]); + + $dbskeleton->addColumn($tablemodel, (new ColumnModel())->setType('int')->setLen(11)->setName('create_time')->setIsPk(false)->setIncrement(false)->setComment('创建时间')); + $dbskeleton->addColumn($tablemodel, (new ColumnModel())->setType('int')->setLen(11)->setName('update_time')->setIsPk(false)->setIncrement(false)->setComment('更新时间')); + } // protected static function init() { // self::beforeInsert(function ($event) { diff --git a/app/model/FormAttr.php b/app/model/FormAttr.php index ab5ed987..a031f8a3 100644 --- a/app/model/FormAttr.php +++ b/app/model/FormAttr.php @@ -6,51 +6,75 @@ // +---------------------------------------------------------------------- // | Author: molong // +---------------------------------------------------------------------- - namespace app\model; +use think\facade\Config; +use phpspirit\dbskeleton\mysql\TableModel; +use phpspirit\dbskeleton\mysql\ColumnModel; +use phpspirit\dbskeleton\Factory; + /** * 设置模型 */ -class FormAttr { +class FormAttr extends \think\Model{ protected $type = array( 'id' => 'integer', ); - protected static function init() { - self::afterInsert(function ($data) { - if ($data['form_id']) { - $name = db('Form')->where('id', $data['form_id'])->value('name'); - $db = new \com\Datatable(); - $attr = $data->toArray(); - $model_attr = array( - 'form_id' => $data['form_id'], - 'attr_id' => $data->id, - 'group_id' => 0, - 'is_add_table' => 1, - 'is_show' => $data['is_show'], - 'is_must' => $data['is_must'], - 'sort' => 0, - ); - $attr['after'] = db('FormAttr')->where('name', '<>', $data['name'])->where('form_id', $data['form_id'])->order('id desc')->value('name'); - return $db->columField('form_' . strtolower($name), $attr)->query(); - } - }); - self::beforeUpdate(function ($data) { - $attr = $data->toArray(); - $attr['action'] = 'CHANGE'; - $attr['oldname'] = db('FormAttr')->where('id', $attr['id'])->value('name'); - if ($attr['id']) { - $name = db('Form')->where('id', $attr['form_id'])->value('name'); - $db = new \com\Datatable(); - return $db->columField('form_' . strtolower($name), $attr)->query(); - } else { - return false; - } - }); + protected static function onAfterInsert($model){ + $data = $model->getData(); + $mysql = Config::get('database.connections.mysql'); + + $dbskeleton = Factory::instance('mysql', $mysql['hostname'] . ':' . $mysql['hostport'], $mysql['database'], $mysql['username'], $mysql['password']); + $field = (new ColumnModel())->setType('int') + ->setLen($data['length']) + ->setName($data['name']) + ->setComment($data['title']); + $dbskeleton->addColumn($tablemodel, ); + } + protected static function onBeforeUpdate($model){ + $data = $model->getData(); + $mysql = Config::get('database.connections.mysql'); + + $dbskeleton = Factory::instance('mysql', $mysql['hostname'] . ':' . $mysql['hostport'], $mysql['database'], $mysql['username'], $mysql['password']); + } + + // protected static function init() { + // self::afterInsert(function ($data) { + // if ($data['form_id']) { + // $name = db('Form')->where('id', $data['form_id'])->value('name'); + // $db = new \com\Datatable(); + // $attr = $data->toArray(); + // $model_attr = array( + // 'form_id' => $data['form_id'], + // 'attr_id' => $data->id, + // 'group_id' => 0, + // 'is_add_table' => 1, + // 'is_show' => $data['is_show'], + // 'is_must' => $data['is_must'], + // 'sort' => 0, + // ); + // $attr['after'] = db('FormAttr')->where('name', '<>', $data['name'])->where('form_id', $data['form_id'])->order('id desc')->value('name'); + // return $db->columField('form_' . strtolower($name), $attr)->query(); + // } + // }); + // self::beforeUpdate(function ($data) { + // $attr = $data->toArray(); + // $attr['action'] = 'CHANGE'; + // $attr['oldname'] = db('FormAttr')->where('id', $attr['id'])->value('name'); + // if ($attr['id']) { + // $name = db('Form')->where('id', $attr['form_id'])->value('name'); + // $db = new \com\Datatable(); + // return $db->columField('form_' . strtolower($name), $attr)->query(); + // } else { + // return false; + // } + // }); + // } + protected function getTypeTextAttr($value, $data) { $type = config('config_type_list'); $type_text = explode(',', $type[$data['type']]); diff --git a/app/model/Member.php b/app/model/Member.php index 4af43947..f1e15b43 100644 --- a/app/model/Member.php +++ b/app/model/Member.php @@ -45,7 +45,7 @@ class Member extends Model { } protected function getAccessTokenAttr($value, $data) { - $token = ['data' => ['uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password'], 'department' => $data['department']]]; + $token = ['data' => ['uid' => $data['uid'], 'username' => $data['username'], 'password' => $data['password']]]; return JWTAuth::builder($token); //参数为用户认证的信息,请自行添加 } diff --git a/app/ueditor.json b/app/ueditor.json new file mode 100644 index 00000000..45488a31 --- /dev/null +++ b/app/ueditor.json @@ -0,0 +1,94 @@ +/* 前后端通信相关的配置,注释只允许使用多行方式 */ +{ + /* 上传图片配置项 */ + "imageActionName": "uploadimage", /* 执行上传图片的action名称 */ + "imageFieldName": "upfile", /* 提交的图片表单名称 */ + "imageMaxSize": 2048000, /* 上传大小限制,单位B */ + "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */ + "imageCompressEnable": true, /* 是否压缩图片,默认是true */ + "imageCompressBorder": 1600, /* 图片压缩最长边限制 */ + "imageInsertAlign": "none", /* 插入的图片浮动方式 */ + "imageUrlPrefix": "", /* 图片访问路径前缀 */ + "imagePathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */ + /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */ + /* {time} 会替换成时间戳 */ + /* {yyyy} 会替换成四位年份 */ + /* {yy} 会替换成两位年份 */ + /* {mm} 会替换成两位月份 */ + /* {dd} 会替换成两位日期 */ + /* {hh} 会替换成两位小时 */ + /* {ii} 会替换成两位分钟 */ + /* {ss} 会替换成两位秒 */ + /* 非法字符 \ : * ? " < > | */ + /* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */ + + /* 涂鸦图片上传配置项 */ + "scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */ + "scrawlFieldName": "upfile", /* 提交的图片表单名称 */ + "scrawlPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + "scrawlMaxSize": 2048000, /* 上传大小限制,单位B */ + "scrawlUrlPrefix": "", /* 图片访问路径前缀 */ + "scrawlInsertAlign": "none", + + /* 截图工具上传 */ + "snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */ + "snapscreenPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + "snapscreenUrlPrefix": "", /* 图片访问路径前缀 */ + "snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */ + + /* 抓取远程图片配置 */ + "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"], + "catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */ + "catcherFieldName": "source", /* 提交的图片列表表单名称 */ + "catcherPathFormat": "./uploads/editor/image", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + "catcherUrlPrefix": "", /* 图片访问路径前缀 */ + "catcherMaxSize": 2048000, /* 上传大小限制,单位B */ + "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */ + + /* 上传视频配置 */ + "videoActionName": "uploadvideo", /* 执行上传视频的action名称 */ + "videoFieldName": "upfile", /* 提交的视频表单名称 */ + "videoPathFormat": "./uploads/editor/video", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + "videoUrlPrefix": "", /* 视频访问路径前缀 */ + "videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */ + "videoAllowFiles": [ + ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", + ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上传视频格式显示 */ + + /* 上传文件配置 */ + "fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */ + "fileFieldName": "upfile", /* 提交的文件表单名称 */ + "filePathFormat": "./uploads/editor/file", /* 上传保存路径,可以自定义保存路径和文件名格式 */ + "fileUrlPrefix": "", /* 文件访问路径前缀 */ + "fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */ + "fileAllowFiles": [ + ".png", ".jpg", ".jpeg", ".gif", ".bmp", + ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", + ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", + ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", + ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml" + ], /* 上传文件格式显示 */ + + /* 列出指定目录下的图片 */ + "imageManagerActionName": "listimage", /* 执行图片管理的action名称 */ + "imageManagerListPath": "./uploads/editor/image/", /* 指定要列出图片的目录 */ + "imageManagerListSize": 20, /* 每次列出文件数量 */ + "imageManagerUrlPrefix": "", /* 图片访问路径前缀 */ + "imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */ + "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */ + + /* 列出指定目录下的文件 */ + "fileManagerActionName": "listfile", /* 执行文件管理的action名称 */ + "fileManagerListPath": "./uploads/editor/file/", /* 指定要列出文件的目录 */ + "fileManagerUrlPrefix": "", /* 文件访问路径前缀 */ + "fileManagerListSize": 20, /* 每次列出文件数量 */ + "fileManagerAllowFiles": [ + ".png", ".jpg", ".jpeg", ".gif", ".bmp", + ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", + ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid", + ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso", + ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml" + ] /* 列出的文件类型 */ + +} \ No newline at end of file diff --git a/composer.json b/composer.json index 2cbf3682..8e2c34d7 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,9 @@ "topthink/think-captcha": "^3.0", "sent/think-jwt": "^1.0", "xin/helper": "^1.0", - "sent/tree": "^1.0" + "sent/tree": "^1.0", + "lotofbadcode/phpspirit_dbskeleton": "^1.0", + "sent/think-addons": "^1.0" }, "require-dev": { "symfony/var-dumper": "^4.2" diff --git a/config/addons.php b/config/addons.php new file mode 100644 index 00000000..b040d076 --- /dev/null +++ b/config/addons.php @@ -0,0 +1,17 @@ + +// +---------------------------------------------------------------------- + +return [ + 'autoload' => true, + 'hooks' => [], + 'route' => [], + 'service' => [], +]; \ No newline at end of file diff --git a/config/log.php b/config/log.php index ea24ff9d..587e96de 100755 --- a/config/log.php +++ b/config/log.php @@ -27,7 +27,7 @@ return [ // 独立日志级别 'apart_level' => [], // 最大日志文件数量 - 'max_files' => 0, + 'max_files' => 30, // 使用JSON格式记录 'json' => false, // 日志处理 diff --git a/extend/com/Datatable.php b/extend/com/Datatable.php new file mode 100644 index 00000000..635cb336 --- /dev/null +++ b/extend/com/Datatable.php @@ -0,0 +1,275 @@ + +// +---------------------------------------------------------------------- +namespace com; + +use think\facade\Config; +use think\facade\Db; + +/** + * 数据库管理类 + * @author colin + */ +class Datatable { + + protected $table; /*数据库操作的表*/ + protected $fields = array(); /*数据库操作字段*/ + protected $charset = 'utf8'; /*数据库操作字符集*/ + public $prefix = ''; /*数据库操作表前缀*/ + protected $model_table_prefix = ''; /*模型默认创建的表前缀*/ + protected $engine_type = 'MyISAM'; /*数据库引擎*/ + protected $key = 'id'; /*数据库主键*/ + public $sql = ''; /*最后生成的sql语句*/ + protected $typeAlist = array( + "text" => "VARCHAR", + "string" => "VARCHAR", + "password" => "VARCHAR", + "textarea" => "TEXT", + "bool" => "INT", + "select" => "INT", + "num" => "INT", + "decimal" => "DECIMAL", + "tags" => "VARCHAR", + "datetime" => "INT", + "date" => "INT", + "editor" => "TEXT", + "bind" => "INT", + "image" => "INT", + "images" => "VARCHAR", + "attach" => "VARCHAR", + ); + + /** + * 初始化数据库信息 + * @author colin + */ + public function __construct() { + //创建DB对象 + $this->prefix = Config::get('database.prefix'); + $this->model_table_prefix = Config::get('model_table_prefix'); + } + + /** + * @title 初始化表 + * @description 初始化创建表 + * @Author molong + * @DateTime 2017-06-11 + * @param string $table 表名 + * @return void 空 + */ + public function initTable($table = '', $comment = '', $pk = 'id') { + $this->table = $this->getTablename($table, true); + + $sql = $this->generateField($pk, 'int', 11, '', '主键', true); + + $primary = $pk ? "PRIMARY KEY (`" . $pk . "`)" : ''; + $generatesql = $sql . ','; + + $create = "CREATE TABLE IF NOT EXISTS `" . $this->table . "`(" + . $generatesql + . $primary + . ") ENGINE=" . $this->engine_type . " AUTO_INCREMENT=1 DEFAULT CHARSET=" . $this->charset . " ROW_FORMAT=DYNAMIC COMMENT='" . $comment . "';"; + $this->sql = $create; + return $this; + } + + /** + * 快速创建ID字段 + * @var length 字段的长度 + * @var comment 字段的描述 + * @author colin + */ + public function generateField($key = '', $type = '', $length = 11, $default = '', $comment = '主键', $is_auto_increment = false) { + if ($key && $type) { + $auto_increment = $is_auto_increment ? 'AUTO_INCREMENT' : ''; + $field_type = $length ? $type . '(' . $length . ')' : $type; + $signed = in_array($type, array('int', 'float', 'double')) ? 'signed' : ''; + $comment = $comment ? "COMMENT '" . $comment . "'" : ""; + $default = $default ? "DEFAULT '" . $default . "'" : ""; + $sql = "`{$key}` {$field_type} {$signed} NOT NULL {$default} $auto_increment {$comment}"; + } + return $sql; + } + + /** + * 追加字段 + * @var $table 追加字段的表名 + * @var $attr 属性列表 + * @var $is_more 是否为多条同时插入 + * @author colin + */ + public function columField($table, $attr = array()) { + $field_attr['table'] = $table ? $this->getTablename($table, true) : $this->table; + $field_attr['name'] = $attr['name']; + $field_attr['type'] = $attr['type'] ? $this->typeAlist[$attr['type']] : 'varchar'; + if (intval($attr['length']) && $attr['length']) { + $field_attr['length'] = "(" . $attr['length'] . ")"; + } else { + $field_attr['length'] = ""; + } + $field_attr['is_null'] = $attr['is_must'] ? 'NOT NULL' : 'NULL'; + $field_attr['default'] = $attr['value'] != '' ? 'DEFAULT "' . $attr['value'] . '"' : ''; + + $field_attr['comment'] = (isset($attr['remark']) && $attr['remark']) ? $attr['remark'] : $attr['title']; + $field_attr['after'] = (isset($attr['after']) && $attr['after']) ? ' AFTER `' . $attr['after'] . '`' : ' AFTER `id`'; + $field_attr['action'] = (isset($attr['action']) && $attr['action']) ? $attr['action'] : 'ADD'; + //确认表是否存在 + + if ($field_attr['action'] == 'ADD') { + $this->sql = "ALTER TABLE `{$field_attr['table']}` ADD `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}' {$field_attr['after']}"; + } elseif ($field_attr['action'] == 'CHANGE') { + $field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : ''; + + $this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'"; + } + return $this; + } + + /** + * 删除字段 + * @var $table 追加字段的表名 + * @var $field 字段名 + * @author colin + */ + public function delField($table, $field) { + $table = $table ? $this->getTablename($table, true) : $this->table; + $this->sql = "ALTER TABLE `$table` DROP `$field`"; + return $this; + } + + /** + * 删除数据表 + * @var $table 追加字段的表名 + * @author colin + */ + public function delTable($table) { + $table = $table ? $this->getTablename($table, true) : $this->table; + $this->sql = "DROP TABLE `$table`"; + return $this; + } + + /** + * 结束表 + * @var $engine_type 数据库引擎 + * @var $comment 表注释 + * @var $charset 数据库编码 + * @author colin + */ + public function endTable($comment, $engine_type = null, $charset = null) { + if (null != $charset) { + $this->charset = $charset; + } + if (null != $engine_type) { + $this->engine_type = $engine_type; + } + $end = "ENGINE=" . $this->engine_type . " AUTO_INCREMENT=1 DEFAULT CHARSET=" . $this->charset . " ROW_FORMAT=DYNAMIC COMMENT='" . $comment . "';"; + $this->sql .= ")" . $end; + return $this; + } + + /** + * 创建动作 + * @return int 0 + * @author colin + */ + public function create() { + $res = Db::execute($this->sql); + return $res !== false; + } + + /** + * create的别名 + * @return int 0 + * @author colin + */ + public function query() { + return $this->create(); + } + + /** + * 获取最后生成的sql语句 + * @author colin + */ + public function getLastSql() { + return $this->sql; + } + + /** + * 获取指定的表名 + * @var $table 要获取名字的表名 + * @var $prefix 获取表前缀? 默认为不获取 false + * @author colin + */ + public function getTablename($table, $prefix = false) { + if (false == $prefix) { + $this->table = $this->model_table_prefix . $table; + } else { + $this->table = $this->prefix . $this->model_table_prefix . $table; + } + return $this->table; + } + + /** + * 获取指定表名的所有字段及详细信息 + * @var $table 要获取名字的表名 可以为sent_tengsu_photo、tengsu_photo、photo + * @author colin + */ + public function getFields($table) { + if (false == $table) { + $table = $this->table; //为空调用当前table + } else { + $table = $table; + } + $patten = "/\./"; + if (!preg_match_all($patten, $table)) { + //匹配_ + $patten = "/_+/"; + if (!preg_match_all($patten, $table)) { + $table = $this->prefix . $this->model_table_prefix . $table; + } else { + //匹配是否包含表前缀,如果是 那么就是手动输入 + $patten = "/$this->prefix/"; + if (!preg_match_all($patten, $table)) { + $table = $this->prefix . $table; + } + } + } + $sql = "SHOW FULL FIELDS FROM $table"; + return Db::query($sql); + } + + /** + * 确认表是否存在 + * @var $table 表名 可以为sent_tengsu_photo、tengsu_photo、photo + * @author colin + * @return boolen + */ + public function CheckTable($table) { + //获取表名 + $this->table = $this->getTablename($table, true); + $result = Db::execute("SHOW TABLES LIKE '%$this->table%'"); + return $result; + } + + /** + * 确认字段是否存在 + * @var $table 表名 可以为sent_tengsu_photo、tengsu_photo、photo + * @var $field 字段名 要检查的字段名 + * @author colin + * @return boolen + */ + public function CheckField($table, $field) { + //检查字段是否存在 + $table = $this->getTablename($table, true); + if (!Db::query("Describe $table $field")) { + return false; + } else { + return true; + } + } +} \ No newline at end of file diff --git a/extend/com/Ueditor.php b/extend/com/Ueditor.php new file mode 100644 index 00000000..2ada55eb --- /dev/null +++ b/extend/com/Ueditor.php @@ -0,0 +1,354 @@ +uid = session('user_auth.uid'); + } + + //导入设置 + $this->config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(app()->getAppPath() . "ueditor.json")), true); + + $action = htmlspecialchars($_GET['action']); + + switch ($action) { + case 'config': + $result = json_encode($this->config); + break; + + case 'uploadimage': + $config = array( + "pathFormat" => $this->config['imagePathFormat'], + "maxSize" => $this->config['imageMaxSize'], + "allowFiles" => $this->config['imageAllowFiles'], + ); + $fieldName = $this->config['imageFieldName']; + $result = $this->uploadFile($config, $fieldName); + break; + + case 'uploadscrawl': + $config = array( + "pathFormat" => $this->config['scrawlPathFormat'], + "maxSize" => $this->config['scrawlMaxSize'], + "allowFiles" => $this->config['scrawlAllowFiles'], + "oriName" => "scrawl.png", + ); + $fieldName = $this->config['scrawlFieldName']; + $result = $this->uploadBase64($config, $fieldName); + break; + + case 'uploadvideo': + $config = array( + "pathFormat" => $this->config['videoPathFormat'], + "maxSize" => $this->config['videoMaxSize'], + "allowFiles" => $this->config['videoAllowFiles'], + ); + $fieldName = $this->config['videoFieldName']; + $result = $this->uploadFile($config, $fieldName); + break; + + case 'uploadfile': + // default: + $config = array( + "pathFormat" => $this->config['filePathFormat'], + "maxSize" => $this->config['fileMaxSize'], + "allowFiles" => $this->config['fileAllowFiles'], + ); + $fieldName = $this->config['fileFieldName']; + $result = $this->uploadFile($config, $fieldName); + break; + + case 'listfile': + $config = array( + 'allowFiles' => $this->config['fileManagerAllowFiles'], + 'listSize' => $this->config['fileManagerListSize'], + 'path' => $this->config['fileManagerListPath'], + ); + $result = $this->listFile($config); + break; + + case 'listimage': + $config = array( + 'allowFiles' => $this->config['imageManagerAllowFiles'], + 'listSize' => $this->config['imageManagerListSize'], + 'path' => $this->config['imageManagerListPath'], + ); + $result = $this->listFile($config); + break; + + case 'catchimage': + $config = array( + "pathFormat" => $this->config['catcherPathFormat'], + "maxSize" => $this->config['catcherMaxSize'], + "allowFiles" => $this->config['catcherAllowFiles'], + "oriName" => "remote.png", + ); + $fieldName = $this->config['catcherFieldName']; + $result = $this->saveRemote($config, $fieldName); + break; + + default: + $result = json_encode(array( + 'state' => 'wrong require', + )); + break; + + } + + if (isset($_GET["callback"])) { + if (preg_match("/^[\w_]+$/", $_GET["callback"])) { + $this->output = htmlspecialchars($_GET["callback"]) . '(' . $result . ')'; + } else { + $this->output = json_encode(array( + 'state' => 'callback参数不合法', + )); + } + } else { + $this->output = $result; + } + } + + /** + * + * 输出结果 + * @param data 数组数据 + * @return 组合后json格式的结果 + */ + public function output() { + return $this->output; + } + + /** + * 上传文件方法 + * + */ + private function uploadFile($config, $fieldName) { + $file = request()->file('upfile'); + if (is_array($config['allowFiles'])) { + $config['allowFiles'] = str_replace('.', '', implode(',', $config['allowFiles'])); + }else{ + $config['allowFiles'] = ''; + } + $info = $file->validate(array('size'=>$config['maxSize'], 'ext'=>$config['allowFiles']))->move($config['pathFormat'], true, false); + + if ($info) { + $data = array( + 'state' => "SUCCESS", + 'url' => str_replace("\\", '/', substr($info->getPathname(), 1)), + 'title' => $info->getSaveName(), + 'original' => $info->getFilename(), + 'type' => '.' . $info->getExtension(), + 'size' => $info->getSize(), + ); + } else { + $data = array( + "state" => $file->getError(), + ); + } + return json_encode($data); + } + + /** + * + * Enter description here ... + */ + private function uploadBase64($config, $fieldName) { + $data = array(); + + $base64Data = $_POST[$fieldName]; + $img = base64_decode($base64Data); + $path = $this->getFullPath($config['pathFormat']); + + if (strlen($img) > $config['maxSize']) { + $data['states'] = 'too large'; + return json_encode($data); + } + + $rootpath = $this->rootpath; + + //替换随机字符串 + $imgname = uniqid() . '.png'; + $filename = $path . $imgname; + + if (\Think\Storage::put($rootpath, $filename, $img)) { + $data = array( + 'state' => 'SUCCESS', + 'url' => $rootpath . $filename, + 'title' => $imgname, + 'original' => 'scrawl.png', + 'type' => '.png', + 'size' => strlen($img), + + ); + } else { + $data = array( + 'state' => 'cant write', + ); + } + return json_encode($data); + } + + /** + * 列出文件夹下所有文件,如果是目录则向下 + */ + private function listFile($config) { + $allowFiles = substr(str_replace(".", "|", join("", $config['allowFiles'])), 1); + $size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $config['listSize']; + $start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0; + $end = $start + $size; + + $rootpath = $this->rootpath; + + $path = $config['path']; + $files = \Think\Storage::listFile($rootpath, $path, $allowFiles); + //return $files; + if (!count($files)) { + return json_encode(array( + "state" => "no match file", + "list" => array(), + "start" => $start, + "total" => count($files), + )); + } + + /* 获取指定范围的列表 */ + $len = count($files); + for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--) { + $list[] = $files[$i]; + } + //倒序 + //for ($i = $end, $list = array(); $i < $len && $i < $end; $i++){ + // $list[] = $files[$i]; + //} + + /* 返回数据 */ + $result = json_encode(array( + "state" => "SUCCESS", + "list" => $list, + "start" => $start, + "total" => count($files), + )); + + return $result; + } + + /** + * + * Enter description here ... + */ + private function saveRemote($config, $fieldName) { + $list = array(); + if (isset($_POST[$fieldName])) { + $source = $_POST[$fieldName]; + } else { + $source = $_GET[$fieldName]; + } + foreach ($source as $imgUrl) { + $upload = new \org\Upload(); + + $imgUrl = htmlspecialchars($imgUrl); + $imgUrl = str_replace("&", "&", $imgUrl); + + //http开头验证 + if (strpos($imgUrl, "http") !== 0) { + $data = array('state' => '不是http链接'); + return json_encode($data); + } + //格式验证(扩展名验证和Content-Type验证) + $fileType = strtolower(strrchr($imgUrl, '.')); + if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) { + $data = array("state" => "错误文件格式"); + return json_encode($data); + } + + //打开输出缓冲区并获取远程图片 + ob_start(); + $context = stream_context_create( + array('http' => array( + 'follow_location' => false, // don't follow redirects + )) + ); + readfile($imgUrl, false, $context); + $img = ob_get_contents(); + ob_end_clean(); + preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m); + + $path = $this->getFullPath($config['pathFormat']); + if (strlen($img) > $config['maxSize']) { + $data['states'] = 'too large'; + return json_encode($data); + } + + $rootpath = $this->rootpath; + + $imgname = uniqid() . '.png'; + $filename = $path . $imgname; + + $oriName = $m ? $m[1] : ""; + + if (\Think\Storage::put($rootpath, $filename, $img)) { + array_push($list, array( + "state" => 'SUCCESS', + "url" => \Think\Storage::getPath($rootpath, $filename), + "size" => strlen($img), + "title" => $imgname, + "original" => $oriName, + "source" => htmlspecialchars($imgUrl), + )); + } else { + array_push($list, array('state' => '文件写入失败')); + } + } + + /* 返回抓取数据 */ + return json_encode(array( + 'state' => count($list) ? 'SUCCESS' : 'ERROR', + 'list' => $list, + )); + } + + /** + * 规则替换命名文件 + * @param $path + * @return string + */ + private function getFullPath($path) { + //替换日期事件 + $t = time(); + $d = explode('-', date("Y-y-m-d-H-i-s")); + $format = $path; + $format = str_replace("{yyyy}", $d[0], $format); + $format = str_replace("{yy}", $d[1], $format); + $format = str_replace("{mm}", $d[2], $format); + $format = str_replace("{dd}", $d[3], $format); + $format = str_replace("{hh}", $d[4], $format); + $format = str_replace("{ii}", $d[5], $format); + $format = str_replace("{ss}", $d[6], $format); + $format = str_replace("{uid}", $this->uid, $format); + + return $format; + } + + private function format_exts($exts) { + $data = array(); + foreach ($exts as $key => $value) { + $data[] = ltrim($value, '.'); + } + return $data; + } + +} \ No newline at end of file diff --git a/public/template/front/form.html b/public/template/front/form.html new file mode 100644 index 00000000..d9ee2275 --- /dev/null +++ b/public/template/front/form.html @@ -0,0 +1,50 @@ + + + + +{$info['title']} + + + +
    + + + + +
    +
    + {$info['content']|raw} +
    +
    +
    +
    立即注册
    +
    +
    +
    +
    教师
    +
    +
    +
    +
    + + +
    + + \ No newline at end of file diff --git a/route/app.php b/route/app.php index 5e0a12c6..974a2cda 100755 --- a/route/app.php +++ b/route/app.php @@ -16,7 +16,9 @@ Route::rule('lists', 'Front/lists'); Route::rule('detail-:id', 'Front/detail'); Route::rule('category', 'Front/category'); Route::rule('topic-:id', 'Front/topic'); +Route::rule('form/:id/:name', 'Front/form'); Route::rule('front/:function', 'Front/:function'); +Route::rule('upload/:function', 'Upload/:function'); Route::group('admin', function () { Route::rule('/', 'admin.Index/index'); diff --git a/view/admin/channel/add.html b/view/admin/channel/add.html new file mode 100644 index 00000000..bdf2ca30 --- /dev/null +++ b/view/admin/channel/add.html @@ -0,0 +1 @@ +{$formHtml|raw} \ No newline at end of file diff --git a/view/admin/channel/edit.html b/view/admin/channel/edit.html index 385bd74a..de73e073 100644 --- a/view/admin/channel/edit.html +++ b/view/admin/channel/edit.html @@ -47,8 +47,8 @@ @@ -59,7 +59,7 @@
    (是否新窗口打开链接) diff --git a/view/admin/channel/index.html b/view/admin/channel/index.html index a466a386..8e15e15d 100644 --- a/view/admin/channel/index.html +++ b/view/admin/channel/index.html @@ -9,18 +9,18 @@

    {$meta_title}

    - 新 增 - - + 新 增 + +
    @@ -46,13 +46,13 @@ {$list['id']} {$list['level_show']} - {$list['title']} - + {$list['title']} + {$list['url']} - {$list['sort']} + {$list['sort']} {if $list['status']} {$list.status|get_status_title} @@ -61,9 +61,9 @@ {/if} - 编辑 - {$list.status|show_status_op} - 删除 + 编辑 + {$list.status|show_status_op} + 删除 {/volist} @@ -94,7 +94,7 @@ $(function() { } if(url != undefined && url != ''){ - window.location.href = url + '/ids/' + param; + window.location.href = url + '?ids=' + param; } }); $.fn.editable.defaults.mode = 'popup'; diff --git a/view/admin/form/attr.html b/view/admin/form/attr.html index e2d4247e..4d7fe6a5 100644 --- a/view/admin/form/attr.html +++ b/view/admin/form/attr.html @@ -6,9 +6,9 @@

    {$meta_title}

    @@ -35,8 +35,8 @@ {$item['length']} {$item['value']} - 编辑 - 删除 + 编辑 + 删除 {/volist} diff --git a/view/admin/form/index.html b/view/admin/form/index.html index d0f3a9a3..a7686ba1 100644 --- a/view/admin/form/index.html +++ b/view/admin/form/index.html @@ -9,8 +9,8 @@

    {$meta_title}

    - 新 增 - + 新 增 +
    @@ -36,10 +36,10 @@ {$item['id']} {$item['name']} - {$item['title']} + {$item['title']} - {$item.create_time|time_format} + {$item['create_time']} {if $item['status']} @@ -49,11 +49,12 @@ {/if} - 字段 - {$item['status']|show_status_op} - 编辑 - 删除 - 数据 + 字段 + {$item['status_text']} + 编辑 + 删除 + 数据 + 浏览 {/volist} diff --git a/view/admin/public/edit.html b/view/admin/public/edit.html index bf42681c..65cd464d 100644 --- a/view/admin/public/edit.html +++ b/view/admin/public/edit.html @@ -44,7 +44,7 @@
    - {:widget('common/Form/show',array($field,$info))} + {:form($field, $info)}
    {$field['help']|default=''}
    @@ -62,7 +62,7 @@
    - {:widget('common/Form/show',array($field,$info))} + {:form($field, $info)}
    {$field['help']|default=''}
    diff --git a/view/admin/public/header.html b/view/admin/public/header.html index d0c7da30..9aca6c77 100644 --- a/view/admin/public/header.html +++ b/view/admin/public/header.html @@ -13,7 +13,7 @@