diff --git a/application/admin/controller/posts/Archives.php b/application/admin/controller/posts/Archives.php index 06d4eaf8..44d2f2a6 100644 --- a/application/admin/controller/posts/Archives.php +++ b/application/admin/controller/posts/Archives.php @@ -50,34 +50,36 @@ class Archives extends Backend /** * 读取栏目列表 */ - private function initForm() + private function initForm($siteId=null) { - //从总后台进入 - if ($this->auth->isSuperAdmin()){ + $where=$first_siteid=''; + if ($this->auth->isSuperAdmin()) { $sitelist = model('Sites')->all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + + //记住下拉列表中第一个网站的ID,添加文章时,只读取对应的栏目等信息 + if ($sitelist && $this->request->action()=='add') { + $first_siteid = $sitelist[0]['id']; + $where = ['site_id' => $first_siteid]; + } } - //从站点后台进入 else { $this->view->assign('siteList', null); $first_siteid = Session::get('user_site_id'); } + if (!is_null($siteId)) $first_siteid=$siteId; + $tree = Tree::instance(); - $tree->init(model('channel')->with('sites')->order('site_id asc,weigh desc,id desc')->select(), 'pid'); + $tree->init(model('channel')->with('sites')->where($where)->order('site_id asc,weigh desc,id desc')->select(), 'pid'); $this->channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); $channeldata = []; //0 => ['mode' => 'default','site_id'=>0, 'name' => __('None')]]; foreach ($this->channellist as $k => $v) { - if(isset($first_siteid) && !is_null($first_siteid) && $v['site_id']!=$first_siteid) { - //do nothing - }else { - $channeldata[$v['id']] = $v; - $channeldata[$v['id']]['disabled'] = 0; - $channeldata[$v['id']]['sitename'] = $v['sites']['name'] == '' ? __('Main site') : $v['sites']['name']; - if ($v['type'] != 'list') { - $channeldata[$v['id']]['disabled'] = 1; - } + $channeldata[$v['id']] = $v; + $channeldata[$v['id']]['disabled'] = 0; + $channeldata[$v['id']]['sitename'] = $v['sites']['name'] == '' ? __('Main site') : $v['sites']['name']; + if ($v['type'] != 'list') { + $channeldata[$v['id']]['disabled'] = 1; } } $this->view->assign("channelList", $channeldata); @@ -113,7 +115,7 @@ class Archives extends Backend ->where($where) //->where('site_id', Session::get('admin.siteid')) ->where('isDelete',0) - ->with('channel') + ->with('sites,channel') ->field('subtitle,content',true, $tablename) ->order($sort, $order) ->limit($offset, $limit) @@ -124,6 +126,7 @@ class Archives extends Backend return json($result); } $this->initForm(); + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -266,7 +269,7 @@ class Archives extends Backend } $this->error(__('Parameter %s can not be empty', '')); } - $this->initForm(); + $this->initForm($row->site_id); $channeldata = []; //0 => ['mode' => 'default','site_id'=>0, 'name' => __('None')]]; foreach ($this->channellist as $k => $v) { diff --git a/application/admin/controller/posts/Channel.php b/application/admin/controller/posts/Channel.php index e5fc2b16..669212c1 100644 --- a/application/admin/controller/posts/Channel.php +++ b/application/admin/controller/posts/Channel.php @@ -19,7 +19,6 @@ class Channel extends Backend { protected $model = null; - protected $channellist = []; protected $noNeedRight = ['check_element_available','getlist']; @@ -29,29 +28,33 @@ class Channel extends Backend $this->request->filter(['strip_tags']); $this->model = model('Channel'); - $tree = Tree::instance(); - $tree->init($this->model->order('weigh desc,id desc')->with('Sites')->with('archives')->select(), 'pid'); - - $this->channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); } - private function initForm(){ - //从总后台进入 + private function initForm($siteId=null) + { + $first_siteid=null; if ($this->auth->isSuperAdmin()){ $sitelist = Sites::all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + if ($sitelist && $this->request->action()=='add') { + $first_siteid = $sitelist[0]['id'] ; + } } - //从站点后台进入 else { $this->view->assign('siteList', null); + $first_siteid = Session::get('user_site_id'); } + if (!is_null($siteId)) $first_siteid=$siteId; + $where = ['site_id'=>$first_siteid]; - + $tree = Tree::instance(); + $tree->init($this->model->order('weigh desc,id desc')->where($where)->with('Sites,archives')->select(), 'pid'); + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); $channeldata = [0 => ['site_id'=>0, 'name' => __('None')]]; - foreach ($this->channellist as $k => $v) + foreach ($channellist as $k => $v) { - if(isset($first_siteid) && !is_null($first_siteid) && $v['site_id']!=$first_siteid) { + //添加&编辑页面, 排除非首选网站的栏目 + if(!is_null($first_siteid) && $v['site_id']!=$first_siteid) { //do nothing }else { $channeldata[$v['id']] = $v; @@ -76,7 +79,7 @@ class Channel extends Backend $this->view->assign("typeList", $this->model->getTypeList()); $this->view->assign("modelList", model('PostsModelx')->all()); - $ml = Seven::build_langs('row[lang]',null,['siteid'=>Session::get("admin.siteid")]); + $ml = Seven::build_langs('row[lang]',null,['siteid'=>$first_siteid]); $this->view->assign('multilanguage',$ml); } @@ -90,10 +93,18 @@ class Channel extends Backend { $search = $this->request->request("search"); //构造父类select列表选项数据 + + list($where, $sort, $order, $offset, $limit) = $this->buildparams(false, true); + + $tree = Tree::instance(); + $tree->init($this->model->order('weigh desc,id desc')->where($where)->with('Sites,archives')->select(), 'pid'); + + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + $list = []; if ($search) { - foreach ($this->channellist as $k => $v) + foreach ($channellist as $k => $v) { if (stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) { @@ -103,13 +114,18 @@ class Channel extends Backend } else { - $list = $this->channellist; + $list = $channellist; } $total = count($list); $result = array("total" => $total, "rows" => $list); return json($result); } + if ($this->auth->isSuperAdmin()){ + $sitelist = Sites::all(); + $this->view->assign('siteList', $sitelist); + } + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -177,7 +193,7 @@ class Channel extends Backend } $this->error(__('Parameter %s can not be empty', '')); } - $this->initForm(); + $this->initForm($row->site_id); $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'],['siteid'=>$row->site_id])); $this->view->assign("row", $row); return $this->view->fetch(); @@ -186,12 +202,15 @@ class Channel extends Backend /** - * 返回栏目列表,供Ajax调用 + * 返回栏目列表,供文章列表搜索框Ajax调用 */ public function getlist() { if($this->request->isAjax()){ - foreach ($this->channellist as $k => $v){ + $tree = Tree::instance(); + $channellist=$tree->init($this->model->order('weigh desc,id desc')->with('Sites,archives')->select(), 'pid'); + $channellist = $tree->getTreeList($tree->getTreeArray(0), 'name'); + foreach ($channellist as $k => $v){ $list[$v['id']]=$v['name']; } return json($list); diff --git a/application/admin/controller/posts/Page.php b/application/admin/controller/posts/Page.php index 40a65c01..ed8cb9c9 100644 --- a/application/admin/controller/posts/Page.php +++ b/application/admin/controller/posts/Page.php @@ -59,6 +59,7 @@ class Page extends Backend return json($result); } + $this->assignconfig('show_sitename', $this->auth->isSuperAdmin()); return $this->view->fetch(); } @@ -68,13 +69,12 @@ class Page extends Backend */ private function initForm() { - //从总后台进入 + $first_siteid=null; if ($this->auth->isSuperAdmin()){ $sitelist = Sites::all(); $this->view->assign('siteList', $sitelist); - $first_siteid = $sitelist?$sitelist[0]['id']:null; + $first_siteid=$sitelist?$sitelist[0]['id']:$first_siteid; } - //从站点后台进入 else { $this->view->assign('siteList', null); $first_siteid = \think\Session::get('user_site_id'); @@ -149,7 +149,7 @@ class Page extends Backend } $this->view->assign("row", $row); $this->initForm(); - $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'])); + $this->view->assign('multilanguage', Seven::build_langs('row[lang]',$row['lang'],['siteid'=>$row->site_id])); return $this->view->fetch(); } diff --git a/application/admin/view/posts/archives/index.html b/application/admin/view/posts/archives/index.html index abf96369..c9774211 100644 --- a/application/admin/view/posts/archives/index.html +++ b/application/admin/view/posts/archives/index.html @@ -11,8 +11,8 @@ {:__('Recyclebin')} diff --git a/application/admin/view/posts/channel/add.html b/application/admin/view/posts/channel/add.html index d718c396..5c4e15b5 100644 --- a/application/admin/view/posts/channel/add.html +++ b/application/admin/view/posts/channel/add.html @@ -57,7 +57,7 @@
- {foreach name="parentList" item="vo"} {/foreach} diff --git a/application/admin/view/posts/channel/edit.html b/application/admin/view/posts/channel/edit.html index 75ae4fac..64fa3c5e 100644 --- a/application/admin/view/posts/channel/edit.html +++ b/application/admin/view/posts/channel/edit.html @@ -36,7 +36,7 @@
{foreach name="modelList" item="vo"} - + {/foreach}
@@ -48,7 +48,7 @@
@@ -58,9 +58,9 @@
- {foreach name="parentList" item="vo"} - + {/foreach} diff --git a/application/admin/view/posts/channel/index.html b/application/admin/view/posts/channel/index.html index 7c836813..936c9452 100644 --- a/application/admin/view/posts/channel/index.html +++ b/application/admin/view/posts/channel/index.html @@ -14,6 +14,16 @@
  • {:__('Set to hidden')}
  • + {notempty name="siteList"} +
    + +
    + {/notempty}
    - {notempty name="siteList"} -
    - -
    - -
    -
    - {/notempty} -
    diff --git a/public/assets/js/backend/posts/archives.js b/public/assets/js/backend/posts/archives.js index 69c7d332..04663c0d 100644 --- a/public/assets/js/backend/posts/archives.js +++ b/public/assets/js/backend/posts/archives.js @@ -38,19 +38,24 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function [ {checkbox: true}, {field: 'id', title: __('id'), operate: false}, - {field: 'channel_id', title: __('Channel_id'),formatter: function (value, row, index) { + {field: 'site_id', title: __('Site_id'), visible:Config.show_sitename, + formatter: function (value, row, index) { + return row.sites==null?'':'' + row.sites.name + ''; + } + }, + {field: 'channel_id', title: __('Channel_id'),searchList: $.getJSON('posts/channel/getlist'), + formatter: function (value, row, index) { return row.channel==null?'':'' + row.channel.name + ''; - }, - searchList: $.getJSON('posts/channel/getlist') + } }, {field: 'type', title: __('type'), formatter: function (value,row,index){ return ''+value+''; }, operate:false }, - {field: 'title', align:'left', title: __('title'), operate: 'LIKE %...%', + {field: 'title', align:'left', title: __('title'), operate: 'LIKE %...%',placeholder: '关键字,模糊搜索', formatter: function(value,row, index){ return value + (row.cover==''?'' : ' '); }}, - {field: 'status', title: __('status'), searchList: {new: __('New'), normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status}, + {field: 'status', title: __('status'), searchList: {normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status}, {field: 'updatetime', title: __('updatetime'),operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime}, {field: 'views', title: __('Views'), operate:false}, {field: 'weigh', title: __('Weigh'), operate:false}, diff --git a/public/assets/js/backend/posts/channel.js b/public/assets/js/backend/posts/channel.js index fcfa9628..58b26d0e 100644 --- a/public/assets/js/backend/posts/channel.js +++ b/public/assets/js/backend/posts/channel.js @@ -24,29 +24,59 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin sortName: 'weigh', pagination: false, escape: false, - commonSearch: false, + commonSearch: true, search: false, columns: [ [ {checkbox: true}, - {field: 'id', title: __('Id')}, - {field: 'sites.name', title: __('Site_id')}, - {field: 'type', title: __('Type'), custom: {channel: 'info', list: 'success', redirect: 'primary'}, formatter: Table.api.formatter.flag}, - {field: 'name', title: __('Name'), align: 'left', formatter: Controller.api.formatter.catename}, - {field: 'diyname', title: __('Redirect'), formatter:function(value,row,index){ - return value==''? '' : ''; - }}, + {field: 'id', title: __('Id'),operate:false}, + {field: 'site_id', title: __('Site_id'), visible:Config.show_sitename, + formatter: function (value, row, index) { + return row.sites==null?'':'' + row.sites.name + ''; + } + }, + {field: 'type', title: __('Type'), searchList: {channel: __('Channel'), list: __('list'), redirect: __('Redirect')},custom: {channel: 'info', list: 'success', redirect: 'primary'}, formatter: Table.api.formatter.flag}, + {field: 'name', title: __('Name'), align: 'left', operate: 'LIKE %...%',placeholder: '关键字,模糊搜索', formatter: Controller.api.formatter.catename}, + {field: 'diyname', title: __('Redirect'), operate:false, + formatter:function(value,row,index){ + diyname = row['type']=='redirect' ? row['redirect'] : value==''? '': '/list/'+value+'.html'; + return diyname==''? '' : ''; + } + }, {field: 'flag', title: __('Flag'), operate: false, formatter: Table.api.formatter.flag}, - {field: 'weigh', title: __('Weigh'), visible:true}, - {field: 'archives.items', title: __('Items'), formatter:function(value,row,index){return (typeof value === 'number') ? value : 0;}}, - {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status}, + {field: 'weigh', title: __('Weigh'), visible:true,operate:false}, + {field: 'archives.items', title: __('Items'),operate:false, + formatter:function(value,row,index){ + return (typeof value === 'number') ? ''+ value +'' : 0; + }}, + {field: 'status', title: __('Status'), searchList: {normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); + $(document).on('change','#c-site_id', function(){ + var self = this; + if($(self).val()==0) return false; + var options = table.bootstrapTable('getOptions'); + options.pageNumber = 1; + options.queryParams = function (params) { + return { + sort: params.sort, + order: params.order, + filter: JSON.stringify({site_id: $(self).val()}), + op: JSON.stringify({site_id: '='}), + offset: params.offset, + limit: params.limit, + }; + }; + //Toastr.info("数据加载中,请稍候..."); + table.bootstrapTable('refresh'); + }); + // 为表格绑定事件 Table.api.bindevent(table); + Form.api.bindevent($("#formg")); }, add: function () { Controller.api.bindevent(); diff --git a/public/assets/js/backend/posts/page.js b/public/assets/js/backend/posts/page.js index b5f68ea0..4d0dba12 100644 --- a/public/assets/js/backend/posts/page.js +++ b/public/assets/js/backend/posts/page.js @@ -24,15 +24,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin [ {field: 'state', checkbox: true}, {field: 'id', title: __('Id'), operate: false}, - {field: 'site_id', title: __('Site_id'), operate: false, formatter:function(value,row,index){ - return value==0? '-': row.sites.name; - }}, + {field: 'site_id', title: __('Site_id'), + formatter: function (value, row, index) { + return row.sites==null?'':'' + row.sites.name + ''; + },visible:Config.show_sitename}, {field: 'title', title: __('Title'), align:'left', operate: 'LIKE %...%', placeholder: '关键字,模糊搜索', - formatter: function(value,row,index){ - return value + (row.image==''?'' : ''); - }}, + formatter: function(value,row,index){ + return value + (row.image==''?'' : ' '); + } + }, {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag, operate: false}, - {field: 'lang', title: __('lang'), formatter: Table.api.formatter.langs, operate: false}, + {field: 'lang', title: __('lang'), operate: false, + formatter: function(value,row,index){ + return __(value); + } + }, {field: 'views', title: __('Views'), operate: false}, //{field: 'comments', title: __('Comments'), operate: false}, {field: 'weigh', title: __('Weigh'), operate: false}, @@ -59,7 +65,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin bindevent: function () { $(document).on("change", "#c-site_id", function () { that=this; - Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (data) { + Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (r,data) { $("#language_choose").html(data.html); Form.api.bindevent($("#language_choose")); return false; diff --git a/public/assets/js/backend/posts/sites.js b/public/assets/js/backend/posts/sites.js index 1d3dde85..a02b5c39 100644 --- a/public/assets/js/backend/posts/sites.js +++ b/public/assets/js/backend/posts/sites.js @@ -25,12 +25,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function [ {checkbox: true}, {field: 'id', title: __('Id')}, - {field: 'username', title: __('User_id')}, - {field: 'name', title: __('name')}, - {field: 'domain', title: __('Domain')}, - {field: 'lang', title: __('Lang')}, - {field: 'status', title: __('Status'), formatter: Table.api.formatter.status}, - {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime}, + {field: 'username', title: __('User_id'), operate:false}, + {field: 'name', title: __('name'),operate: 'LIKE %...%',placeholder: '关键字,模糊搜索',}, + {field: 'domain', title: __('Domain'),operate: 'LIKE %...%',placeholder: '关键字,模糊搜索',}, + {field: 'lang', title: __('Lang'), operate:false}, + {field: 'status', title: __('Status'),searchList: {normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status}, + {field: 'createtime', title: __('Createtime'), operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"', formatter: Table.api.formatter.datetime}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ]