fastadmin管理后台--带个人日程管理功能

按照国际惯例先放效果图

 

 核心代码:

schedule.js

define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pim/schedule/index' + location.search,
                    add_url: 'pim/schedule/add',
                    edit_url: 'pim/schedule/edit',
                    del_url: 'pim/schedule/del',
                    multi_url: 'pim/schedule/multi',
                    table: 'pim_schedule',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'operate', title: __('Operate'),
                            table: table,
                            buttons: [
                                {
                                    name: 'start',
                                    text: '',
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-play',
                                    url: 'pim/schedule/start',
                                    confirm: '是否开始?',
                                    refresh: true,
                                },
                                {
                                    name: 'finish',
                                    text: '',
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-restoreit',
                                    icon: 'fa fa-stop',
                                    url: 'pim/schedule/finish',
                                    confirm: '是否结束?',
                                    refresh: true,
                                }
                            ],
                            events: Table.api.events.operate,
                            // formatter: Table.api.formatter.operate
                            formatter: function(value,row,index){
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);

                                if(row.status == 0){
                                    $(table).data("operate-finish", null);
                                }else if(row.status == 1){
                                    $(table).data("operate-start", null);
                                }else if(row.status == 2){
                                    $(table).data("operate-start", null);
                                    $(table).data("operate-finish", null);
                                }

                                // $(table).data("operate-edit", null);
                                // $(table).data("operate-del", null);

                                that.table = table;
                                return Table.api.formatter.operate.call(that,value,row,index);
                            }
                        },
                        {field: 'title', title: __('Title'), align: 'left'},
                        {field: 'deadline', title: __('DeadLine'), align: 'center', formatter: Table.api.formatter.dateonly},
                        {field: 'stime', title: __('Stime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'etime', title: __('Etime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'costhours', title: __('CostHours') + '(' + __('Unit') + ')', formatter: function(value,row,index){
                            etime = new Date(row.etime.toString());
                            stime = new Date(row.stime.toString());

                            if(etime - stime < 0){
                                return __('Stime') + '或' + __('Etime') + '有误';
                            }else{
                                return ((etime - stime)/(1000*60*60)).toFixed(1);
                            }

                        }},
                        {field: 'attachfile', title: __('Attachfile'),
                            formatter:function(value,row,index){
                                if(row.attachfile == ''){
                                    return '';
                                }else{
                                    return "" + __('View') + "";
                                }
                            }
                        },
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"9":__('Status 9')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'weight', title: __('Weight')},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'pim/schedule/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'pim/schedule/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'pim/schedule/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});

controller--schedule.php

php

namespace app\admin\controller\pim;

use app\common\controller\Backend;

/**
 * 个人日程管理
 *
 * @icon fa fa-circle-o
 */
class Schedule extends Backend
{
    
    /**
     * Schedule模型对象
     * @var \app\admin\model\pim\Schedule
     */
    protected $model = null;

    protected $dataLimit = true;
    protected $dataLimitField = 'admin_id';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\pim\Schedule;
        $this->view->assign("statusList", $this->model->getStatusList());
    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */

    /**
     * 开始事务
     */
    public function start($ids = null){
        /* step1 从数据库里取得该条数据 */
        $row = $this->model->get($ids);
        if(!$row){
            $this->error(__("No results were found"));
        }

        /* step2 数据操作权限 */
        $adminIds = $this->getDataLimitAdminIds();
        if(is_array($adminIds)){
            if(!in_array($row[$this->dataLimitField], $adminIds)){
                $this->error(__("You have no permission"));
            }
        }

        /* step3 更新数据库 */
        if($this->request->isPost()){
            $row->status = 1;
            $row->stime = date('Y-m-d H:i:00');
            $row->save();
        }

        /* step4 返回处理结果 */
        $rst = array(
            'code' => 1,
            'msg' => '事务成功开始。',
            'data' => $row,
            'url' => '.',
            'wait' => 3
        );
        return json($rst);
    }

    /**
     * 结束事务
     */
    public function finish($ids = null){
        /* step1 从数据库里取得该条数据 */
        $row = $this->model->get($ids);
        if(!$row){
            $this->error(__("No results were found"));
        }

        /* step2 数据操作权限 */
        $adminIds = $this->getDataLimitAdminIds();
        if(is_array($adminIds)){
            if(!in_array($row[$this->dataLimitField], $adminIds)){
                $this->error(__("You have no permission"));
            }
        }

        /* step3 更新数据库 */
        if($this->request->isPost()){
            $row->status = 2;
            $row->etime = date('Y-m-d H:i:00');
            $row->save();
        }

        /* step4 返回处理结果 */
        $rst = array(
            'code' => 1,
            'msg' => '事务成功结束。',
            'data' => $row,
            'url' => '.',
            'wait' => 3
        );
        return json($rst);
    }
    

}

 新增数据表 fa_pim_schedule

 

 

完整源码+QQ:965794175

你可能感兴趣的:(fastadmin管理后台--带个人日程管理功能)