作者 何书鹏
1 个管道 的构建 通过 耗费 2 秒

模板管理

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 尺寸信息管理
*
* @icon fa fa-circle-o
*/
class SizeTemplate extends Backend
{
/**
* StyleTemplate模型对象
* @var \app\admin\model\StyleTemplate
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\StyleTemplate;
$this->view->assign("typeList", $this->model->getTypeList());
$this->assignconfig('typeList', $this->model->getTypeList());
}
public function import()
{
parent::import();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage,则转发到Selectpage
if ($this->request->request('keyField'))
{
return $this->selectpage();
}
$list = $this->model
->where('type','size')
->select();
foreach ($list as $row) {
$row->visible(['id','name','type','updatetime']);
}
$list = collection($list)->toArray();
$result = array("total" => count($list), "rows" => $list);
return json($result);
}
return $this->view->fetch();
}
}
... ...
... ... @@ -50,17 +50,8 @@ class StyleTemplate extends Backend
{
return $this->selectpage();
}
$search = $this->request->request("search");
$type = $this->request->request("type");
$where = [];
if(!empty($search)){
$where['name'] = ['like','%'.$search.'%'];
}
if(!empty($type) && $type != 'all'){
$where['type'] = $type;
}
$list = $this->model
->where($where)
->where('type','style')
->select();
foreach ($list as $row) {
$row->visible(['id','name','type','updatetime']);
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<!-- <div class="form-group">
<label for="c-type" class="control-label col-xs-12 col-sm-2">{:__('模板类型')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value=""}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div> -->
<input id="c-type" name="row[type]" type="hidden" value="size">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<!-- <div class="form-group">
<label for="c-type" class="control-label col-xs-12 col-sm-2">{:__('模板类型')}:</label>
<div class="col-xs-12 col-sm-8">
<select id="c-type" data-rule="required" class="form-control selectpicker" name="row[type]">
{foreach name="typeList" item="vo"}
<option value="{$key}" {in name="key" value="$row.type"}selected{/in}>{$vo}</option>
{/foreach}
</select>
</div>
</div> -->
<input id="c-type" name="row[type]" type="hidden" value="size">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-name" data-rule="required" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}">
</div>
</div>
<div class="form-group layer-footer">
<label class="control-label col-xs-12 col-sm-2"></label>
<div class="col-xs-12 col-sm-8">
<button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
<button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
</div>
</div>
</form>
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<!-- <div class="panel-heading">
<ul class="nav nav-tabs">
<li class="active"><a href="#all" data-toggle="tab">{:__('All')}</a></li>
{foreach name="typeList" item="vo"}
<li><a href="#{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div> -->
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('style_template/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
</div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('style_template/edit')}"
data-operate-del="{:$auth->check('style_template/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<!-- <div class="form-group">
<label for="c-type" class="control-label col-xs-12 col-sm-2">{:__('模板类型')}:</label>
<div class="col-xs-12 col-sm-8">
... ... @@ -10,7 +10,8 @@
</select>
</div>
</div>
</div> -->
<input id="c-type" name="row[type]" type="hidden" value="style">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<!-- <div class="form-group">
<label for="c-type" class="control-label col-xs-12 col-sm-2">{:__('模板类型')}:</label>
<div class="col-xs-12 col-sm-8">
... ... @@ -10,7 +10,8 @@
</select>
</div>
</div>
</div> -->
<input id="c-type" name="row[type]" type="hidden" value="style">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
<div class="panel panel-default panel-intro">
{:build_heading()}
<div class="panel-heading">
<!-- <div class="panel-heading">
<ul class="nav nav-tabs">
<li class="active"><a href="#all" data-toggle="tab">{:__('All')}</a></li>
{foreach name="typeList" item="vo"}
<li><a href="#{$key}" data-toggle="tab">{$vo}</a></li>
{/foreach}
</ul>
</div>
</div> -->
<div class="panel-body">
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade active in" id="one">
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'size_template/index' + location.search,
add_url: 'size_template/add',
edit_url: 'size_template/edit',
del_url: 'size_template/del',
multi_url: 'size_template/multi',
import_url: 'size_template/import',
table: 'style_template',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
pagination: false,
commonSearch: false,
search: false,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'type', title: __('模板类型'), operate: false, searchList: Config.typeList, formatter: Table.api.formatter.label},
{field: 'name', title: __('Name')},
{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
//操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
{
field: 'operate',
width: "150px",
title: __('Operate'),
table: table,
events: Table.api.events.operate,
buttons: [
{
name: 'addtabs',
title: __('规格列表'),
classname: 'btn btn-xs btn-warning btn-addtabs',
icon: 'fa fa-list',
url: 'style/index?style_template_id={id}'
}
],
formatter: function (value, row, index) {
var that = $.extend({}, this);
var table = $(that.table).clone(true);
if(row.type == 'size'){
$(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
}
that.table = table;
return Table.api.formatter.operate.call(that, value, row, index);
}
},
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
//绑定TAB事件
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
// var options = table.bootstrapTable(tableOptions);
var typeStr = $(this).attr("href").replace('#', '');
var options = table.bootstrapTable('getOptions');
options.pageNumber = 1;
options.queryParams = function (params) {
// params.filter = JSON.stringify({type: typeStr});
params.type = typeStr;
console.log(params);
return params;
};
table.bootstrapTable('refresh', {});
return false;
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});
\ No newline at end of file
... ...
... ... @@ -42,7 +42,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
buttons: [
{
name: 'addtabs',
title: __('格列表'),
title: __('格列表'),
classname: 'btn btn-xs btn-warning btn-addtabs',
icon: 'fa fa-list',
url: 'style/index?style_template_id={id}'
... ...