作者 开飞机的舒克

后台优化

1 -<?php  
2 -  
3 -namespace app\admin\controller\data;  
4 -  
5 -use app\common\controller\Backend;  
6 -  
7 -/**  
8 - * 数据大屏管理  
9 - *  
10 - * @icon fa fa-circle-o  
11 - */  
12 -class Screen extends Backend  
13 -{  
14 -  
15 - /**  
16 - * Screen模型对象  
17 - * @var \app\admin\model\data\Screen  
18 - */  
19 - protected $model = null;  
20 -  
21 - public function _initialize()  
22 - {  
23 - parent::_initialize();  
24 - $this->model = new \app\admin\model\data\Screen;  
25 - $this->view->assign("isViewList", $this->model->getIsViewList());  
26 - }  
27 -  
28 -  
29 -  
30 - /**  
31 - * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法  
32 - * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑  
33 - * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改  
34 - */  
35 -  
36 -  
37 - /**  
38 - * 查看  
39 - */  
40 - public function index()  
41 - {  
42 - //当前是否为关联查询  
43 - $this->relationSearch = false;  
44 - //设置过滤方法  
45 - $this->request->filter(['strip_tags', 'trim']);  
46 - if ($this->request->isAjax()) {  
47 - //如果发送的来源是Selectpage,则转发到Selectpage  
48 - if ($this->request->request('keyField')) {  
49 - return $this->selectpage();  
50 - }  
51 - list($where, $sort, $order, $offset, $limit) = $this->buildparams();  
52 -  
53 - $list = $this->model  
54 -  
55 - ->where($where)  
56 - ->order($sort, $order)  
57 - ->paginate($limit);  
58 -  
59 - foreach ($list as $row) {  
60 - $row->visible(['id','title','campus_id','images','starttime','endtime','is_view']);  
61 -  
62 - }  
63 -  
64 - $result = array("total" => $list->total(), "rows" => $list->items());  
65 -  
66 - return json($result);  
67 - }  
68 - return $this->view->fetch();  
69 - }  
70 -  
71 -}  
1 -<?php  
2 -  
3 -namespace app\admin\model\data;  
4 -  
5 -use think\Model;  
6 -  
7 -  
8 -class Screen extends Model  
9 -{  
10 -  
11 -  
12 -  
13 -  
14 -  
15 - // 表名  
16 - protected $name = 'data_screen';  
17 -  
18 - // 自动写入时间戳字段  
19 - protected $autoWriteTimestamp = 'integer';  
20 -  
21 - // 定义时间戳字段名  
22 - protected $createTime = 'createtime';  
23 - protected $updateTime = 'updatetime';  
24 - protected $deleteTime = false;  
25 -  
26 - // 追加属性  
27 - protected $append = [  
28 - 'starttime_text',  
29 - 'endtime_text',  
30 - 'is_view_text'  
31 - ];  
32 -  
33 -  
34 -  
35 - public function getIsViewList()  
36 - {  
37 - return ['0' => __('Is_view 0'), '1' => __('Is_view 1')];  
38 - }  
39 -  
40 -  
41 - public function getStarttimeTextAttr($value, $data)  
42 - {  
43 - $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');  
44 - return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;  
45 - }  
46 -  
47 -  
48 - public function getEndtimeTextAttr($value, $data)  
49 - {  
50 - $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');  
51 - return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;  
52 - }  
53 -  
54 -  
55 - public function getIsViewTextAttr($value, $data)  
56 - {  
57 - $value = $value ? $value : (isset($data['is_view']) ? $data['is_view'] : '');  
58 - $list = $this->getIsViewList();  
59 - return isset($list[$value]) ? $list[$value] : '';  
60 - }  
61 -  
62 - protected function setStarttimeAttr($value)  
63 - {  
64 - return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);  
65 - }  
66 -  
67 - protected function setEndtimeAttr($value)  
68 - {  
69 - return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);  
70 - }  
71 -  
72 -  
73 -}  
1 -define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {  
2 -  
3 - var Controller = {  
4 - index: function () {  
5 - // 初始化表格参数配置  
6 - Table.api.init({  
7 - extend: {  
8 - index_url: 'data/screen/index' + location.search,  
9 - add_url: 'data/screen/add',  
10 - edit_url: 'data/screen/edit',  
11 - del_url: 'data/screen/del',  
12 - multi_url: 'data/screen/multi',  
13 - import_url: 'data/screen/import',  
14 - table: 'data_screen',  
15 - }  
16 - });  
17 -  
18 - var table = $("#table");  
19 -  
20 - // 初始化表格  
21 - table.bootstrapTable({  
22 - url: $.fn.bootstrapTable.defaults.extend.index_url,  
23 - pk: 'id',  
24 - sortName: 'id',  
25 - columns: [  
26 - [  
27 - {checkbox: true},  
28 - {field: 'title', title: __('Title'), operate: 'LIKE'},  
29 - {field: 'campus_id', title: __('Campus_id')},  
30 - {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},  
31 - {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},  
32 - {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},  
33 - {field: 'is_view', title: __('Is_view'), searchList: {"0":__('Is_view 0'),"1":__('Is_view 1')}, formatter: Table.api.formatter.normal},  
34 - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}  
35 - ]  
36 - ]  
37 - });  
38 -  
39 - // 为表格绑定事件  
40 - Table.api.bindevent(table);  
41 - },  
42 - add: function () {  
43 - Controller.api.bindevent();  
44 - },  
45 - edit: function () {  
46 - Controller.api.bindevent();  
47 - },  
48 - api: {  
49 - bindevent: function () {  
50 - Form.api.bindevent($("form[role=form]"));  
51 - }  
52 - }  
53 - };  
54 - return Controller;  
55 -});