diff --git a/application/wechat/controller/Article.php b/application/wechat/controller/Article.php deleted file mode 100644 index 48cbd0a95..000000000 --- a/application/wechat/controller/Article.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @date 2017/03/27 14:43 - */ -class Article extends BasicAdmin { - - public function index($p1Str, $p2Str, $p3Str, $dStr) { - list($x1, $y1) = explode(',', $p1Str); - list($x2, $y2) = explode(',', $p2Str); - list($x3, $y3) = explode(',', $p3Str); - list($d1, $d2, $d3) = explode(',', $dStr); - $va = (($d2 * $d2 - $d3 * $d3) - ($x2 * $x2 - $x3 * $x3) - ($y2 * $y2 - $y3 * $y3)) / 2; - $vb = (($d2 * $d2 - $d1 * $d1) - ($x2 * $x2 - $x1 * $x1) - ($y2 * $y2 - $y1 * $y1)) / 2; - $y_point = ($vb * ($x3 - $x2) - $va * ($x1 - $x2)) / (($y1 - $y2) * ($x3 - $x2) - ($y3 - $y2) * ($x1 - $x2)); - $x_point = ($va - $y_point * ($y3 - $y2)) / ($x3 - $x2); - return ['x' => $x_point, 'y' => $y_point]; - } -} diff --git a/application/wechat/controller/News.php b/application/wechat/controller/News.php index 3de6c681f..03b960204 100644 --- a/application/wechat/controller/News.php +++ b/application/wechat/controller/News.php @@ -15,6 +15,7 @@ namespace app\wechat\controller; use controller\BasicAdmin; use service\DataService; +use service\WechatService; use think\Db; /** @@ -32,23 +33,47 @@ class News extends BasicAdmin { */ protected $table = 'WechatNews'; + /** + * 添加图文 + * @return \think\response\View + */ public function add() { if ($this->request->isGet()) { - $this->assign('title', '新建图文'); - return view('form'); + return view('form', ['title' => '新建图文']); } if ($this->request->isPost()) { $data = $this->request->post(); if (($ids = $this->_apply_news_article($data['data'])) && !empty($ids)) { $post = ['article_id' => $ids, 'create_by' => session('user.id')]; - if (DataService::save($this->table, $post, 'id') !== FALSE) { - $this->success('图文添加成功!', url('@wechat/news')); + if (DataService::save($this->table, $post, 'id') !== false) { + $this->success('图文添加成功!', ''); } } $this->error('图文添加失败,请稍候再试!'); } } + /** + * 编辑图文 + * @return \think\response\View + */ + public function edit() { + $id = $this->request->get('id', ''); + if ($this->request->isGet()) { + empty($id) && $this->error('参数错误,请稍候再试!'); + return view('form', ['title' => '编辑图文', 'vo' => WechatService::getNewsById($id)]); + } + $data = $this->request->post(); + $ids = $this->_apply_news_article($data['data']); + if (!empty($ids)) { + $post = ['id' => $id, 'article_id' => $ids, 'create_by' => session('user.id')]; + if (false !== DataService::save('wechat_news', $post, 'id')) { + $this->success('图文更新成功!', ''); + } + } + $this->error('图文更新失败,请稍候再试!'); + } + /** * 图文更新操作 * @param array $data diff --git a/application/wechat/view/news.form.html b/application/wechat/view/news.form.html index ff896686c..166b33c81 100644 --- a/application/wechat/view/news.form.html +++ b/application/wechat/view/news.form.html @@ -1,245 +1,117 @@ {extend name='extra@admin/content' /} -{block name="style"} - -{/block} - {block name='content'} -
-
-
-
-
-
图文列表
-
-
-
-
- {if empty($vo['articles']) eq FALSE} - {foreach $vo.articles as $key=>$value} -
- -
- image -
- {$value.title} -
-
- {/foreach} - {else} -
-
- image -
- -
-
- {/if} -
- -
-
-
-
-
-
-
-
-
-
图文内容编辑
-
-
-
-
-
- -
-
-
- 标题 - - -
-
-
-
-
-
- 作者 - -
-
-
-
-
-
- -
-
-
- - -
-
-
-
- 上传图片 - 从图库中选择图片 -
-
- -
-
-

封面大图片建议尺寸:900像素 * 500像素

-
-
-
-
-
- -
-
-
-
- - -
-
-
-
- - -
-
-
-
-
-
- -
-
-
-
-
+ +
+
图文列表
+
+ {if empty($vo['articles']) eq false} + {foreach $vo.articles as $key=>$value} +
+ {$value.title}
+
+ {/foreach} + {else} +
+ +
+
+ {/if} +
+ + + +
+
图文内容编辑
+
+
+ +
+
+
+ 标题 + + +
+
+
+ +
+
+
+ 作者 + +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+ 上传图片 + 从图库中选择图片 +
+
+ +
+
+

封面大图片建议尺寸:900像素 * 500像素

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+ + {/block} @@ -248,10 +120,16 @@ $(function () { var editDdata = $.parseJSON('{$vo.articles|default=[]|json_encode}'); + for (var i in editDdata) { $('.news-item').eq(i).data('item', editDdata[i]); } + $('body').on('change', '.upload-image-box input', function () { + $('.news-item.active').css('background-image', 'url(' + this.value + ')'); + $(this).parent('.upload-image-box').css('background-image', 'url(' + this.value + ')'); + }); + require(['ueditor'], function () { /*! 实例富文本编辑器 */ @@ -259,8 +137,11 @@ /*! 默认编辑第一篇图文 */ editor = window.createEditor('[name="content"]', 'basic'); + editor.ready(function () { + var $form = $('form[name="news"]'); + // 表单验证 function verify(callback) { $form.validate(function (ret) { @@ -280,19 +161,22 @@ $('.news-item').map(function () { data.push($(this).data('item')); }); - $.form.load('__SELF__', {data: data}, "POST"); + $.form.load('__SELF__', {data: data}, "post"); }); }); + // 输入标题显示 $form.find('[name="title"]').on('keyup', function () { + console.log($preItem); if ($preItem) { - if (this.value.length > 0) { + if (('' + this.value).length > 0) { $preItem.find('.news-title').html(this.value).show(); } else { $preItem.find('.news-title').html(this.value).hide(); } } }); + /*! 显示编辑器 */ function showEditor() { var $item = $('.news-item.active'); @@ -322,23 +206,17 @@ } /*! jQuery事件绑定 */ - $('body').on('click', '.news-box .article-add', function () { + $('body').off('click', '.news-box .article-add').on('click', '.news-box .article-add', function () { /*! 添加新图文 */ - var $html = $('
image

'); + var $html = $('

'); $html.insertBefore(this).trigger('click'); if ($('.news-item').size() >= 7) { return $(this).hide(); } }).off('click', '.news-item').on('click', '.news-item', function () { - var self = this; - - function init() { - $(self).siblings().removeClass('active'); - $(self).addClass('active'); - showEditor(); - } - - $('.news-item.active').size() > 0 ? verify(init) : init.call(this); + /*! 列表选择 */ + $(this).addClass('active').siblings().removeClass('active'); + showEditor(); }).off('mouseleave').on('mouseleave', '.news-item', function () { /*! 隐藏删除按钮 */ $(this).find('.upload-multiple-close').addClass('hide'); @@ -359,4 +237,88 @@ }); }); +{/block} + +{block name="style"} + {/block} \ No newline at end of file