作者 郭文星

123

  1 +<?php
  2 +
  3 +namespace app\admin\controller;
  4 +
  5 +use app\common\controller\Backend;
  6 +
  7 +/**
  8 + * 轮播图管理
  9 + *
  10 + * @icon fa fa-image
  11 + */
  12 +class Image extends Backend
  13 +{
  14 +
  15 + /**
  16 + * Image模型对象
  17 + * @var \app\admin\model\Image
  18 + */
  19 + protected $model = null;
  20 +
  21 + public function _initialize()
  22 + {
  23 + parent::_initialize();
  24 + $this->model = new \app\admin\model\Image;
  25 + $this->view->assign("isShowList", $this->model->getIsShowList());
  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 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'Id' => 'ID',
  5 + 'Image' => '图片',
  6 + 'Is_show' => '是否显示',
  7 + 'Is_show 1' => '显示',
  8 + 'Is_show 0' => '不显示',
  9 + 'Createtime' => '创建时间'
  10 +];
  1 +<?php
  2 +
  3 +namespace app\admin\model;
  4 +
  5 +use think\Model;
  6 +
  7 +
  8 +class Image extends Model
  9 +{
  10 +
  11 +
  12 +
  13 +
  14 +
  15 + // 表名
  16 + protected $name = 'image';
  17 +
  18 + // 自动写入时间戳字段
  19 + protected $autoWriteTimestamp = 'integer';
  20 +
  21 + // 定义时间戳字段名
  22 + protected $createTime = 'createtime';
  23 + protected $updateTime = false;
  24 + protected $deleteTime = false;
  25 +
  26 + // 追加属性
  27 + protected $append = [
  28 + 'is_show_text'
  29 + ];
  30 +
  31 +
  32 +
  33 + public function getIsShowList()
  34 + {
  35 + return ['0' => __('Is_show 0'), '1' => __('Is_show 1')];
  36 + }
  37 +
  38 +
  39 + public function getIsShowTextAttr($value, $data)
  40 + {
  41 + $value = $value ? $value : (isset($data['is_show']) ? $data['is_show'] : '');
  42 + $list = $this->getIsShowList();
  43 + return isset($list[$value]) ? $list[$value] : '';
  44 + }
  45 +
  46 +
  47 +
  48 +
  49 +}
  1 +<?php
  2 +
  3 +namespace app\admin\validate;
  4 +
  5 +use think\Validate;
  6 +
  7 +class Image extends Validate
  8 +{
  9 + /**
  10 + * 验证规则
  11 + */
  12 + protected $rule = [
  13 + ];
  14 + /**
  15 + * 提示消息
  16 + */
  17 + protected $message = [
  18 + ];
  19 + /**
  20 + * 验证场景
  21 + */
  22 + protected $scene = [
  23 + 'add' => [],
  24 + 'edit' => [],
  25 + ];
  26 +
  27 +}
  1 +<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <div class="input-group">
  7 + <input id="c-image" class="form-control" size="50" name="row[image]" type="text">
  8 + <div class="input-group-addon no-border no-padding">
  9 + <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  10 + <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  11 + </div>
  12 + <span class="msg-box n-right" for="c-image"></span>
  13 + </div>
  14 + <ul class="row list-inline faupload-preview" id="p-image"></ul>
  15 + </div>
  16 + </div>
  17 + <div class="form-group" id="kevin-is_river_mng">
  18 + <label class="control-label col-xs-12 col-sm-2">{:__('Is_show')}:</label>
  19 + <div class="col-xs-12 col-sm-8">
  20 + {:build_radios('row[is_show]', ['1'=>__('是'), '0'=>__('否')])}
  21 + </div>
  22 + </div>
  23 +
  24 +
  25 + <div class="form-group layer-footer">
  26 + <label class="control-label col-xs-12 col-sm-2"></label>
  27 + <div class="col-xs-12 col-sm-8">
  28 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  29 + </div>
  30 + </div>
  31 +</form>
  1 +<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
  2 +
  3 + <div class="form-group">
  4 + <label class="control-label col-xs-12 col-sm-2">{:__('Image')}:</label>
  5 + <div class="col-xs-12 col-sm-8">
  6 + <div class="input-group">
  7 + <input id="c-image" class="form-control" size="50" name="row[image]" type="text" value="{$row.image|htmlentities}">
  8 + <div class="input-group-addon no-border no-padding">
  9 + <span><button type="button" id="faupload-image" class="btn btn-danger faupload" data-input-id="c-image" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-image"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  10 + <span><button type="button" id="fachoose-image" class="btn btn-primary fachoose" data-input-id="c-image" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  11 + </div>
  12 + <span class="msg-box n-right" for="c-image"></span>
  13 + </div>
  14 + <ul class="row list-inline faupload-preview" id="p-image"></ul>
  15 + </div>
  16 + </div>
  17 +
  18 + <div class="form-group" id="kevin-is_river_mng">
  19 + <label class="control-label col-xs-12 col-sm-2">{:__('Is_show')}:</label>
  20 + <div class="col-xs-12 col-sm-8">
  21 + {:build_radios('row[is_show]', [ '1'=>__('是'),'0'=>__('否')],$row['is_show'])}
  22 + </div>
  23 + </div>
  24 +
  25 + <div class="form-group layer-footer">
  26 + <label class="control-label col-xs-12 col-sm-2"></label>
  27 + <div class="col-xs-12 col-sm-8">
  28 + <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
  29 + </div>
  30 + </div>
  31 +</form>
  1 +<div class="panel panel-default panel-intro">
  2 + {:build_heading()}
  3 +
  4 + <div class="panel-body">
  5 + <div id="myTabContent" class="tab-content">
  6 + <div class="tab-pane fade active in" id="one">
  7 + <div class="widget-body no-padding">
  8 + <div id="toolbar" class="toolbar">
  9 + <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
  10 + <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('image/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
  11 + <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('image/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
  12 + <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('image/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
  13 +
  14 +
  15 +
  16 +
  17 +
  18 + </div>
  19 + <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
  20 + data-operate-edit="{:$auth->check('image/edit')}"
  21 + data-operate-del="{:$auth->check('image/del')}"
  22 + width="100%">
  23 + </table>
  24 + </div>
  25 + </div>
  26 +
  27 + </div>
  28 + </div>
  29 +</div>
  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: 'image/index' + location.search,
  9 + add_url: 'image/add',
  10 + edit_url: 'image/edit',
  11 + del_url: 'image/del',
  12 + multi_url: 'image/multi',
  13 + import_url: 'image/import',
  14 + table: 'image',
  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: 'id', title: __('Id')},
  29 + {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  30 + {field: 'is_show', title: __('Is_show'), searchList: {"0":__('Is_show 0'),"1":__('Is_show 1')}, formatter: Table.api.formatter.normal},
  31 + {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  32 + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  33 + ]
  34 + ]
  35 + });
  36 +
  37 + // 为表格绑定事件
  38 + Table.api.bindevent(table);
  39 + },
  40 + add: function () {
  41 + Controller.api.bindevent();
  42 + },
  43 + edit: function () {
  44 + Controller.api.bindevent();
  45 + },
  46 + api: {
  47 + bindevent: function () {
  48 + Form.api.bindevent($("form[role=form]"));
  49 + }
  50 + }
  51 + };
  52 + return Controller;
  53 +});