Commit 658b119b authored by wangjiangze's avatar wangjiangze

增加中心配置功能

parent d5a5ba04
<?php
class CenterConfigAction extends CommonAction{
//管理
public function index(){
$op = I('op');
if($op=="getjson"){
$model = D("SystemConfig");
$userInfo = $_SESSION["_USER_INFO"];
$inputs = I();
$list = $model->getList("list",$userInfo,$inputs);
$count = $model->getList("count",$userInfo,$inputs);
$total = $count[0]["count"];
echo "{\"total\":\"".$total."\",\"rows\":".json_encode($list)."}";
}else{
$this->display();
}
}
//添加
public function add(){
$userInfo = $_SESSION["_USER_INFO"];
$id = I('id','',int)?I('id','',int):0;
$model = D("SystemConfig");
if($id){
$info =$model->where("id = $id")->find();
$this->info = $info;
}
$this->display();
}
//添加处理
public function addHandle(){
$model = D("SystemConfig");
$id = I('id','',int);
$data['name'] = I("name");
$data['k'] = I("k");
$data['v'] = I("v");
$data['remark'] = I("remark");
$data['status'] = I("status");
if($id){
$data['id'] = $id;
$data["updatetime"]=date('Y-m-d H:i:s');
$r = $model->save($data);
if($r){
echo 'true';
}else{
echo 'false';
}
}else{
$data["addtime"]=date('Y-m-d H:i:s');
$id = $model->add($data);
if($id){
echo 'true';
}else{
echo 'false';
}
}
}
//删除处理
public function deleteHandle(){
if(D("SystemConfig")->where("id=".I("id","",int))->save(array('status'=>2))){
echo 'true';
}else{
echo 'false';
}
}
//ajax修改状态
public function updateStatusAjaxHandle(){
$model = D("SystemConfig");
$data = $_POST;
$data['updatetime'] = date('Y-m-d H:i:s');
if($model->save($data)){
echo 'true';
}else{
echo 'false';
}
}
}
<?php
class SystemConfigModel extends RelationModel{
protected $tableName = 'sh_system_config'; //重新定义表名
public function getList($queryType,$userInfo,$inputs){
$p=$inputs["page"]?$inputs["page"]:1;
$n=$inputs["rows"]?$inputs["rows"]:10;
$limit = "limit ".($p-1)*$n.",".$n;
$sort="";
if($inputs["sort"])
$sort = "order by ".$inputs["sort"]." ".$inputs["order"];
//=============
$searchField = $inputs["searchField"]?$inputs["searchField"]:'name';
$searchValue = $inputs["searchValue"]?$inputs["searchValue"]:'';
$searchSp = $inputs["searchSp"]?$inputs["searchSp"]:0;
if($searchValue){
$where = " and (`name` like '%".$searchValue."%' or `k` like '%".$searchValue."%') ";
}
$model = new Model();
//======================
$fields = "count(id) count";
//返回列表(limit分页)
if($queryType=="list"){
$where .= $sort." ".$limit;
$fields = " *,case `status` when 1 then '<font color=red>禁用</font>' when 2 then '<font color=red>删除</font>' when 0 then '<font color=green>启用</font>' end as `status` ";
}
$sql = "select ".$fields." from sh_system_config where 1=1 ".$where.";";
// echo $sql;
return $model->query($sql);
}
}
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中心配置添加/修改</title>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap3.3.7/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap3.3.7/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.3.4/plugins/jquery.validatebox.extend.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.3.4/locale/easyui-lang-{$language}.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.3.4/themes/icon.css">
<link rel="stylesheet" href="__PUBLIC__/js/bootstrap3.3.7/bootstrap.min.css">
<style>
body{padding:20px}
</style>
</head>
<body>
<form class="form-horizontal" role="form" id="ff" action="{:U('/System/CenterConfig/addHandle')}" method="POST">
<input name="id" type="hidden" value="{$info.id}"/>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">配置名称</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputEmail3" placeholder="请输入配置名称" value="{$info.name}" name="name">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">配置键</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputEmail3" placeholder="请输入配置键" name="k" value="{$info.k}">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">配置值</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="inputEmail3" placeholder="请输入配置值" name="v" value="{$info.v}">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">备注</label>
<div class="col-sm-9">
<textarea class="form-control" rows="3" name="remark">{$info.remark}</textarea>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">状态</label>
<div class="col-sm-9">
<label class="radio-inline">
<input type="radio" name="status" id="optionsRadios4" value="1"> 禁用
</label>
<label class="radio-inline">
<input type="radio" name="status" id="optionsRadios4" value="0" checked="checked"> 启用
</label>
</div>
</div>
<div class="btnSystem col-sm-5 control-label">
<input name="" type="button" class="btn btn-success" value="确定" onclick="submitForm()" {:buttonAuth('System','CenterConfig','addhandle')}/>  
<input name="" type="reset" class="btn btn-warning" value="取消" onclick="parentDialog.close();"/>  
</div>
</form>
<script type="text/javascript">
function submitForm(){
var sp_id = $("select[name='sp_id'] option:selected").val();
var name_v = $("input[name='name']").val();
var code_v = $("input[name='type_code']").val();
if(sp_id==0){
alert("请选择合作方");return;
}
if(!name_v){
alert("请输入配置名称");return;
}
if(!code_v){
alert("请输入配置类型code");return;
}
$('#ff').form('submit', {
url:'/System/CenterConfig/addHandle/',
onSubmit: function(){
var isValid = $(this).form('validate');//触发form内的所有validatebox验证,并返回true/false
if(!isValid)
$('#tab').tabs('select',0);
return isValid;
},
success:function(data){
if(data=='true'){
$.messager.confirm('友情提示', '操作成功! 是否关闭窗口?', function(r){
if (r){
parentDialog.CancelEvent();
}
});
}else
$.messager.alert('友情提示','操作失败','info');
}
});
}
$().ready(function(){
<if condition="$info">
$("select[name='sp_id'] option[value='{$info.sp_id}']").attr("selected",true);
$("input[name='status'][value='{$info.status}']").attr("checked",true);
</if>
});
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中心配置管理</title>
<link href="__PUBLIC__/css/style_frame.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.3.4/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/jquery-easyui-1.3.4/themes/icon.css">
<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/jquery-easyui-1.3.4/locale/easyui-lang-{$language}.js"></script>
<script type="text/javascript" src="__PUBLIC__/newVsdn/js/zDialog/zDrag.js"></script>
<script type="text/javascript" src="__PUBLIC__/newVsdn/js/zDialog/zDialog.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common/functions.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common/md5.js"></script>
<link href="__PUBLIC__/newVsdn/css/style_frame.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!--搜索和按钮 开始 -->
<div class="searchSystem clearfix">
<div class="layui-tab-content">
<div class="layui-tab-item layui-show">
<div class="hyperchanne clearfix">
<form name="searchform" method="post" action="" id ="searchform">
<input type="hidden" name="op" value="getjson">
<div class="inputBox">
<input class="input" type="text" placeholder="配置名称/配置键" name="searchValue">
</div>
<input id="submit_search" name="" type="button" value="查询" class="btn_go_s btn_orange" />
</form>
</div><!--hyperchanne end-->
<div class="">
<ul class="operationBox">
<li class="add">
<a href="javascript:;" onclick="add()" class="on"><span></span>新增</a>
</li>
</ul>
</div><!--mainBox end-->
</div>
</div>
</div>
<!--搜索和按钮 结束-->
<table id="dg" title=""
data-options="
iconCls: 'icon-edit',
singleSelect: true,
url: '/System/CenterConfig/index/',
method: 'post',
pagination: true,
pageList:[15,30,45,60],
rownumbers: true,
sortName:'id',
sortOrder:'asc',
queryParams: form2Json('searchform'),
fitColumns: true,
height:'auto',
onRowContextMenu : onRowContextMenu
">
<thead>
<tr>
<th data-options="field:'name',width:30" sortable="true">配置名称</th>
<th data-options="field:'k',width:30">配置键</th>
<th data-options="field:'v',width:60">配置值</th>
<th data-options="field:'remark',width:40">备注</th>
<th data-options="field:'addtime',width:20" sortable="true">创建时间</th>
<th data-options="field:'updatetime',width:20" sortable="true">更新时间</th>
<th data-options="field:'status'" sortable="true" align="center">状态</th>
<th field="action" align="center" formatter="InputAction">操作</th>
</tr>
</thead>
</table>
<div id="mm1" class="easyui-menu" style="width:120px;display: none">
<div iconCls="icon-edit" id="menuEdit" onclick="edit()" {:buttonAuth('System','CenterConfig','add')}>编辑</div>
<div iconCls="icon-cancel" id="menuDel" onclick="del()" {:buttonAuth('System','CenterConfig','deletehandle')}>删除</div>
<div class="menu-sep"></div>
<div iconCls="icon-stop" id="menuStop" onclick="enable(1)" {:buttonAuth('System','CenterConfig','updateStatusAjaxHandle')}>禁用</div>
<div iconCls="icon-start" id="menuStart" onclick="enable(0)" {:buttonAuth('System','CenterConfig','updateStatusAjaxHandle')}>启用</div>
</div>
<div id="mm2" class="easyui-menu" style="width:120px;display: none">
<div iconCls="icon-edit" id="menuEdit" onclick="edit()" {:buttonAuth('System','CenterConfig','add')}>编辑</div>
<div iconCls="icon-cancel" id="menuDel" onclick="del()" {:buttonAuth('System','CenterConfig','deletehandle')}>删除</div>
<div class="menu-sep"></div>
<div iconCls="icon-stop" id="menuStop" onclick="enable(1)" {:buttonAuth('System','CenterConfig','updateStatusAjaxHandle')}>禁用</div>
<div iconCls="icon-start" id="menuStart" onclick="enable(0)" {:buttonAuth('System','CenterConfig','updateStatusAjaxHandle')}>启用</div>
</div>
<script type="text/javascript">
function onRowContextMenu(e, rowIndex, rowData){
e.preventDefault();
$('#dg').datagrid('unselectAll');
$('#dg').datagrid('selectRow', rowIndex);
$('#mm2').menu('show', {
left:e.pageX,
top:e.pageY
});
}
function InputAction(value, row, index) {
return'<a href="javascript:void(0)" id="mb' + index + '" class="easyui-menubutton" menu="#mm1" iconCls="icon-list" onmouseover="setSelectRow(' + index + ')">'+this.title+'</a>';
}
function setSelectRow(index) {
$('#dg').datagrid('unselectAll');
$('#dg').datagrid('selectRow', index);
}
//初始化菜单按钮
$(function(){
$('#dg').datagrid({
onLoadSuccess: function (data) {
for (i = 0; i < $('#dg').datagrid('getRows').length; i++) {
$('#mb' + i).menubutton();
}
}
})
});
//禁用启用
function enable(status){
var row = $('#dg').datagrid('getSelected');
if (row){
var msg='启用';
if(status==1)
msg='禁用'
$.messager.confirm('操作确认', '确认['+msg+']该记录?', function(r){
if (r){
$.post("/System/CenterConfig/updateStatusAjaxHandle/", {id:row.id,status:status},
function(data){
$('#dg').datagrid('reload');
});
}
});
}else{
$.messager.alert('提示', '请选择要操作的记录!','info');
}
}
function add(){
pop(800,450,true,'dg','datagrid','/System/CenterConfig/add/')
}
function edit(){
var row = $('#dg').datagrid('getSelected');
if (row){
pop(800,450,true,'dg','datagrid','/System/CenterConfig/add/id/'+row.id);
}else{
$.messager.alert('提示', '请选择要操作的记录!','info');
}
}
function del(){
var row = $('#dg').datagrid('getSelected');
if (row){
$.messager.confirm('操作确认', '确认[删除]该记录?', function(r){
if (r){
$.post("/System/CenterConfig/deleteHandle/", {id:row.id},
function(data){
$('#dg').datagrid('reload');
});
}
});
}else{
$.messager.alert('提示', '请选择要操作的记录!','info');
}
}
$("#submit_search").click(function () {
$('#dg').datagrid({ queryParams: form2Json("searchform") }); //点击搜索
});
/**
* JQuery扩展方法,用户对JQuery EasyUI的DataGrid控件进行操作。
*/
$.fn.extend({
/**
* 修改DataGrid对象的默认大小,以适应页面宽度。
*
* @param heightMargin
* 高度对页内边距的距离。
* @param widthMargin
* 宽度对页内边距的距离。
* @param minHeight
* 最小高度。
* @param minWidth
* 最小宽度。
*
*/
resizeDataGrid : function(heightMargin, widthMargin, minHeight, minWidth) {
var height = $(document.body).height() - heightMargin;
var width = $(document.body).width() - widthMargin;
height = height < minHeight ? minHeight : height;
width = width < minWidth ? minWidth : width;
$(this).datagrid('resize', {
//height : height,
width : width
});
}
});
$(function() {
// datagrid数据表格ID
var datagridId = 'dg';
// 第一次加载时自动变化大小
$('#' + datagridId).resizeDataGrid(0, 10, 0, 0);
// 当窗口大小发生变化时,调整DataGrid的大小
$(window).resize(function() {
$('#' + datagridId).resizeDataGrid(0, 10, 0, 0);
});
});
</script>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment