first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
{extend name="../../base/view/common/base" /}
|
||||
<!-- 主体 -->
|
||||
{block name="body"}
|
||||
<form class="layui-form p-page">
|
||||
<h3 class="pb-2"><name></h3>
|
||||
<table class="layui-table layui-table-form">
|
||||
<tr>
|
||||
<td class="layui-td-gray"><name>名称<font>*</font></td>
|
||||
<td><input type="text" class="layui-input" name="title" placeholder="请输入<name>名称" lay-verify="required" lay-reqText="请输入<name>名称" value="{$detail.title|default=''}"></td>
|
||||
<td class="layui-td-gray">排序</td>
|
||||
<td><input type="text" name="sort" placeholder="请输入排序,数字" class="layui-input" value="{$detail.sort|default=''}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="pt-4">
|
||||
<input type="hidden" name="id" value="{$detail.id|default=0}"/>
|
||||
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</form>
|
||||
{/block}
|
||||
<!-- /主体 -->
|
||||
|
||||
<!-- 脚本 -->
|
||||
{block name="script"}
|
||||
<script>
|
||||
var moduleInit = ['tool'];
|
||||
|
||||
function gouguInit() {
|
||||
var form = layui.form, tool = layui.tool;
|
||||
//监听提交
|
||||
form.on('submit(webform)', function (data) {
|
||||
let callback = function (e) {
|
||||
layer.msg(e.msg);
|
||||
if (e.code == 0) {
|
||||
tool.sideClose(1000);
|
||||
}
|
||||
}
|
||||
let clickbtn = $(this);
|
||||
tool.post("/<module>/<controller>/add", data.field, callback,clickbtn);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
<!-- /脚本 -->
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Author 勾股工作室 <hdm58@qq.com>
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\<module>\controller;
|
||||
|
||||
use app\base\BaseController;
|
||||
use app\<module>\model\<Bmodel> as <Bmodel>Model;
|
||||
use app\<module>\validate\<Bcontroller>Validate;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Db;
|
||||
use think\facade\View;
|
||||
|
||||
class <Bcontroller> extends BaseController
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*/
|
||||
protected $model;
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(); // 调用父类构造函数
|
||||
$this->model = new <Bmodel>Model();
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据列表
|
||||
*/
|
||||
public function datalist()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
|
||||
return to_assign(0, '', $list);
|
||||
}
|
||||
else{
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/编辑
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$param = get_params();
|
||||
if (request()->isAjax()) {
|
||||
if (!empty($param['id']) && $param['id'] > 0) {
|
||||
try {
|
||||
validate(<Bcontroller>Validate::class)->scene('edit')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->edit($param);
|
||||
} else {
|
||||
try {
|
||||
validate(<Bcontroller>Validate::class)->scene('add')->check($param);
|
||||
} catch (ValidateException $e) {
|
||||
// 验证失败 输出错误信息
|
||||
return to_assign(1, $e->getError());
|
||||
}
|
||||
$this->model->add($param);
|
||||
}
|
||||
}else{
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
if ($id>0) {
|
||||
$detail = $this->model->getById($id);
|
||||
View::assign('detail', $detail);
|
||||
}
|
||||
return view();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function view($id)
|
||||
{
|
||||
$detail = $this->model->getById($id);
|
||||
if (!empty($detail)) {
|
||||
View::assign('detail', $detail);
|
||||
return view();
|
||||
}
|
||||
else{
|
||||
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del()
|
||||
{
|
||||
if (request()->isDelete()) {
|
||||
$param = get_params();
|
||||
$id = isset($param['id']) ? $param['id'] : 0;
|
||||
$type = isset($param['type']) ? $param['type'] : 0;
|
||||
$this->model->delById($id,$type);
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*/
|
||||
public function set()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$param = get_params();
|
||||
$res = $this->model->strict(false)->field('id,status')->update($param);
|
||||
if ($res) {
|
||||
if($param['status'] == 0){
|
||||
add_log('disable', $param['id'], $param);
|
||||
}
|
||||
else if($param['status'] == 1){
|
||||
add_log('recovery', $param['id'], $param);
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
else{
|
||||
return to_assign(0, '操作失败');
|
||||
}
|
||||
} else {
|
||||
return to_assign(1, "错误的请求");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
{extend name="../../base/view/common/base" /}
|
||||
<!-- 主体 -->
|
||||
{block name="body"}
|
||||
|
||||
<div class="p-page">
|
||||
<table class="layui-hide" id="table_<model>" lay-filter="table_<model>"></table>
|
||||
</div>
|
||||
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-group">
|
||||
<button class="layui-btn layui-btn-sm add-new" type="button">+ 添加<name></button>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
{/block}
|
||||
<!-- /主体 -->
|
||||
|
||||
<!-- 脚本 -->
|
||||
{block name="script"}
|
||||
<script>
|
||||
const moduleInit = ['tool'];
|
||||
function gouguInit() {
|
||||
var table = layui.table, tool = layui.tool;
|
||||
|
||||
layui.pageTable = table.render({
|
||||
elem: "#table_<model>"
|
||||
,title: '<name>列表'
|
||||
,toolbar: '#toolbarDemo'
|
||||
,url: "/<module>/<controller>/datalist"
|
||||
,page: false
|
||||
,limit: 999
|
||||
,cellMinWidth: 80
|
||||
,cols: [[
|
||||
{field:'id',width:80, title: 'ID号', align:'center'}
|
||||
,{field:'title',title: '类型名称'}
|
||||
,{field:'status', title: '状态',width:80,align:'center',templet: function(d){
|
||||
var html1='<span class="green">正常</span>';
|
||||
var html2='<span class="yellow">禁用</span>';
|
||||
if(d.status==1){
|
||||
return html1;
|
||||
}
|
||||
else{
|
||||
return html2;
|
||||
}
|
||||
}}
|
||||
,{width:100,title: '操作', align:'center',ignoreExport:true,templet: function(d){
|
||||
var html='';
|
||||
var btn='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>';
|
||||
var btn1='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disable">禁用</a>';
|
||||
var btn2='<a class="layui-btn layui-btn-xs" lay-event="open">启用</a>';
|
||||
if(d.status==1){
|
||||
html = '<div class="layui-btn-group">'+btn+btn1+'</div>';
|
||||
}
|
||||
else{
|
||||
html = '<div class="layui-btn-group">'+btn+btn2+'</div>';
|
||||
}
|
||||
return html;
|
||||
}}
|
||||
]]
|
||||
});
|
||||
|
||||
table.on('tool(table_<model>)',function (obj) {
|
||||
if(obj.event === 'edit'){
|
||||
add_cate(obj.data.id,obj.data.title);
|
||||
}
|
||||
if(obj.event === 'disable'){
|
||||
layer.confirm('确定要禁用该记录吗?', {icon: 3, title:'提示'}, function(index){
|
||||
let callback = function (e) {
|
||||
layer.msg(e.msg);
|
||||
if (e.code == 0) {
|
||||
layui.pageTable.reload();
|
||||
}
|
||||
}
|
||||
tool.post("/<module>/<controller>/set", {id:obj.data.id,status: 0}, callback);
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
if(obj.event === 'open'){
|
||||
layer.confirm('确定要启用该记录吗?', {icon: 3, title:'提示'}, function(index){
|
||||
let callback = function (e) {
|
||||
layer.msg(e.msg);
|
||||
if (e.code == 0) {
|
||||
layui.pageTable.reload();
|
||||
}
|
||||
}
|
||||
tool.post("/<module>/<controller>/set", {id:obj.data.id,status:1}, callback);
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('body').on('click','.add-new',function(){
|
||||
add_cate(0,'');
|
||||
});
|
||||
|
||||
function add_cate(id,val){
|
||||
var title = '新增类型';
|
||||
if(id>0){
|
||||
title = '编辑类型';
|
||||
}
|
||||
layer.prompt({
|
||||
title: title,
|
||||
value: val,
|
||||
yes: function(index, layero) {
|
||||
// 获取文本框输入的值
|
||||
var value = layero.find(".layui-layer-input").val();
|
||||
if (value) {
|
||||
let callback = function (e) {
|
||||
layer.msg(e.msg);
|
||||
if (e.code == 0) {
|
||||
layui.pageTable.reload();
|
||||
}
|
||||
}
|
||||
tool.post("/<module>/<controller>/add", {id: id,title: value}, callback);
|
||||
layer.close(index);
|
||||
} else {
|
||||
layer.msg('请填写类型名称');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{/block}
|
||||
<!-- /脚本 -->
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Author 勾股工作室 <hdm58@qq.com>
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
namespace app\<module>\model;
|
||||
use think\model;
|
||||
use think\facade\Db;
|
||||
class <Bmodel> extends Model
|
||||
{
|
||||
/**
|
||||
* 获取分页列表
|
||||
* @param $where
|
||||
* @param $param
|
||||
*/
|
||||
public function datalist($param=[],$where=[],$whereOr=[])
|
||||
{
|
||||
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
|
||||
$order = empty($param['order']) ? 'id desc' : $param['order'];
|
||||
try {
|
||||
$list = self::where($where)
|
||||
->where(function ($query) use($whereOr) {
|
||||
if (!empty($whereOr)){
|
||||
$query->whereOr($whereOr);
|
||||
}
|
||||
})->order($order)->paginate(['list_rows'=> $rows]);
|
||||
return $list;
|
||||
} catch(\Exception $e) {
|
||||
return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据
|
||||
* @param $param
|
||||
*/
|
||||
public function add($param)
|
||||
{
|
||||
$insertId = 0;
|
||||
try {
|
||||
$param['create_time'] = time();
|
||||
$insertId = self::strict(false)->field(true)->insertGetId($param);
|
||||
add_log('add', $insertId, $param);
|
||||
} catch(\Exception $e) {
|
||||
return to_assign(1, '操作失败,原因:'.$e->getMessage());
|
||||
}
|
||||
return to_assign(0,'操作成功',['return_id'=>$insertId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑信息
|
||||
* @param $param
|
||||
*/
|
||||
public function edit($param)
|
||||
{
|
||||
try {
|
||||
$param['update_time'] = time();
|
||||
self::where('id', $param['id'])->strict(false)->field(true)->update($param);
|
||||
add_log('edit', $param['id'], $param);
|
||||
} catch(\Exception $e) {
|
||||
return to_assign(1, '操作失败,原因:'.$e->getMessage());
|
||||
}
|
||||
return to_assign(0,'操作成功',['return_id'=>$param['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id获取信息
|
||||
* @param $id
|
||||
*/
|
||||
public function getById($id)
|
||||
{
|
||||
$info = self::find($id);
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除信息
|
||||
* @param $id
|
||||
* @param $type
|
||||
* @return array
|
||||
*/
|
||||
public function delById($id,$type=0)
|
||||
{
|
||||
if($type==0){
|
||||
//逻辑删除
|
||||
try {
|
||||
$param['delete_time'] = time();
|
||||
self::where('id', $id)->update(['delete_time'=>time()]);
|
||||
add_log('delete', $id);
|
||||
} catch(\Exception $e) {
|
||||
return to_assign(1, '操作失败,原因:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
else{
|
||||
//物理删除
|
||||
try {
|
||||
self::destroy($id);
|
||||
add_log('delete', $id);
|
||||
} catch(\Exception $e) {
|
||||
return to_assign(1, '操作失败,原因:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
return to_assign();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
* @Author 勾股工作室 <hdm58@qq.com>
|
||||
+-----------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
namespace app\<module>\validate;
|
||||
use think\Validate;
|
||||
use think\facade\Db;
|
||||
|
||||
class <Bcontroller>Validate extends Validate
|
||||
{
|
||||
// 自定义验证规则
|
||||
protected function checkOne($value,$rule,$data=[])
|
||||
{
|
||||
$id = isset($data['id'])?$data['id']:0;
|
||||
$count = Db::name('<Bmodel>')->where([['title','=',$data['title']],['id','<>',$id],['delete_time','=',0]])->count();
|
||||
return $count == 0 ? true : false;
|
||||
}
|
||||
|
||||
protected $rule = [
|
||||
'title' => 'require|checkOne',
|
||||
'id' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'title.require' => '名称不能为空',
|
||||
'title.checkOne' => '同样的名称已经存在',
|
||||
'id.require' => '缺少更新条件',
|
||||
];
|
||||
|
||||
protected $scene = [
|
||||
'add' => ['title'],
|
||||
'edit' => ['title', 'id'],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{extend name="../../base/view/common/base" /}
|
||||
<!-- 主体 -->
|
||||
{block name="body"}
|
||||
<div class="p-page">
|
||||
<h3 class="pb-2"><name>详情</h3>
|
||||
<table class="layui-table layui-table-form">
|
||||
<tr>
|
||||
<td class="layui-td-gray"><name>名称</td>
|
||||
<td>{$detail.title|default=''}"></td>
|
||||
<td class="layui-td-gray">排序</td>
|
||||
<td>{$detail.sort|default=0}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{/block}
|
||||
<!-- /主体 -->
|
||||
Reference in New Issue
Block a user