作者 刘朕

首页分类管理开发,搜索内容选择分类方式调整

<?php
namespace app\admin\controller;
use app\common\controller\Backend;
/**
* 首页分类管理
*
* @icon fa fa-sort
*/
class Sort extends Backend
{
/**
* Sort模型对象
* @var \app\admin\model\Sort
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\Sort;
}
public function import()
{
parent::import();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
}
... ...
<?php
return [
'Name' => '名称',
'Weigh' => '排序'
];
... ...
<?php
namespace app\admin\model;
use think\Model;
class Sort extends Model
{
// 表名
protected $name = 'sort';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
// 追加属性
protected $append = [
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
}
... ...
<?php
namespace app\admin\validate;
use think\Validate;
class Sort extends Validate
{
/**
* 验证规则
*/
protected $rule = [
];
/**
* 提示消息
*/
protected $message = [
];
/**
* 验证场景
*/
protected $scene = [
'add' => [],
'edit' => [],
];
}
... ...
... ... @@ -4,11 +4,7 @@
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</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="1"}selected{/in}>{$vo}</option>
{/foreach}
</select>
<input id="c-type" data-rule="" data-source="sort/index" data-field="name" data-multiple="true" class="form-control selectpage" name="row[type]" type="text" value="">
</div>
</div>
... ...
... ... @@ -4,11 +4,7 @@
<label class="control-label col-xs-12 col-sm-2">{:__('Type')}:</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>
<input id="c-type" data-rule="" data-source="sort/index" data-field="name" data-multiple="true" class="form-control selectpage" name="row[type]" type="text" value="{$row.type|htmlentities}">
</div>
</div>
... ...
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<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">
<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="0">
</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 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">
<label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-weigh" data-rule="required" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|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-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('sort/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('sort/edit')}"
data-operate-del="{:$auth->check('sort/del')}"
width="100%">
</table>
</div>
</div>
</div>
</div>
</div>
... ...
... ... @@ -6,6 +6,7 @@ use app\admin\model\Hot;
use app\common\controller\Api;
use app\common\model\Popular;
use app\common\model\Search;
use app\common\model\Sort;
use think\Db;
use function fast\e;
... ... @@ -124,23 +125,70 @@ class Index extends Api
'code':'1',
'msg':'返回成功',
"data": {
"list":[
{
"id": 1,
"title": "", // 标题
"jump_type": 1, //是否跳转:1=跳转,2=不跳转
"weigh": 1 //排序
}
],
"disclaimer_content": 1,
"data": [
{
"id": 1,
"name": "火灾",
"weigh": 1,
"search": [
{
"id": 1,
"title": "自己家里着火怎么办?",
"weigh": 1,
"type": 1
},
{
"id": 2,
"title": "邻居家着火怎么办?",
"weigh": 2,
"type": 1
},
{
"id": 3,
"title": "高层着火怎么办?",
"weigh": 3,
"type": 1
},
{
"id": 4,
"title": "油锅起火怎么办?",
"weigh": 4,
"type": 1
},
{
"id": 5,
"title": "燃气泄漏怎么办",
"weigh": 5,
"type": 1
},
{
"id": 24,
"title": "1231321",
"weigh": 24,
"type": 1
}
]
}
],
"list":[
{
"id": 1,
"title": "", // 标题
"jump_type": 1, //是否跳转:1=跳转,2=不跳转
"weigh": 1 //排序
}
],
"disclaimer_content": 1,
}
})
*/
public function index_search()
{
$data = Sort::with(['search'])->order('weigh','ASC')->select();
$type = $this->request->param('type',1,'intval');
$list = Search::field('id,title,weigh')->where('type',$type)->order('weigh','ASC')->select();
$r = [
'data' => $data,
'list' => $list,
'disclaimer_content' => '本平台发布的内容仅作为应急科普知识分享,供用户了解并参考。如遇紧急情况,请服从现场救援人员指挥,并遵照医护等专业人员的指导。如用户因参考本平台内容从事某些行为而使自身或第三人受到人身或财产损失的,本平台不承担任任何责任。'
];
... ...
<?php
namespace app\common\model;
use think\Model;
class Sort extends Model
{
public function search()
{
return $this->hasMany('Search', 'type', 'id')->order('weigh','ASC'); // TODO: Change the autogenerated stub
}
}
\ No newline at end of file
... ...
... ... @@ -6000,7 +6000,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2021-12-29 11:31:31 <a href="./" target="_blank">应急管理后台</a>
Generated on 2022-03-07 11:50:40 <a href="./" target="_blank">应急管理后台</a>
</div>
</div>
... ...
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'sort/index' + location.search,
// add_url: 'sort/add',
edit_url: 'sort/edit',
// del_url: 'sort/del',
// multi_url: 'sort/multi',
// import_url: 'sort/import',
table: 'sort',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'weigh',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'name', title: __('Name'), operate: 'LIKE'},
{field: 'weigh', title: __('Weigh'), operate: false},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 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;
});
\ No newline at end of file
... ...