[dev]完善系统模块

This commit is contained in:
邹景立 2017-03-10 17:43:42 +08:00
parent abeb9f5772
commit b28798ff31
12 changed files with 371 additions and 87 deletions

View File

@ -62,9 +62,9 @@ class Node extends BasicAdmin {
$tmp = explode('/', $thr); $tmp = explode('/', $thr);
$one = $tmp[0]; $one = $tmp[0];
$two = "{$tmp[0]}/{$tmp[1]}"; $two = "{$tmp[0]}/{$tmp[1]}";
$nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => '']); $nodes[$one] = array_merge(isset($alias[$one]) ? $alias[$one] : ['node' => $one, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => '']);
$nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => $thr, 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $one]); $nodes[$two] = array_merge(isset($alias[$two]) ? $alias[$two] : ['node' => $two, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $one]);
$nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => $thr, 'is_menu' => 1, 'is_auth' => 0], ['pnode' => $two]); $nodes[$thr] = array_merge(isset($alias[$thr]) ? $alias[$thr] : ['node' => $thr, 'title' => '', 'is_menu' => 0, 'is_auth' => 0], ['pnode' => $two]);
} }
$this->assign('nodes', Tools::arr2table($nodes, 'node', 'pnode')); $this->assign('nodes', Tools::arr2table($nodes, 'node', 'pnode'));
} }
@ -75,15 +75,13 @@ class Node extends BasicAdmin {
public function save() { public function save() {
if ($this->request->isPost()) { if ($this->request->isPost()) {
$post = $this->request->post(); $post = $this->request->post();
foreach ($post as $key => $vo) { if (isset($post['name']) && isset($post['value'])) {
if (stripos($key, 'title_') !== 0) { $nameattr = explode('.', $post['name']);
continue; $field = array_shift($nameattr);
} $data = ['node' => join(',', $nameattr), $field => $post['value']];
$node = substr($key, strlen('title_'));
$data = ['node' => $node, 'title' => $vo, 'is_menu' => intval(!empty($post["menu_{$node}"])), 'is_auth' => intval(!empty($post["auth_{$node}"]))];
Data::save($this->table, $data, 'node'); Data::save($this->table, $data, 'node');
$this->success('参数保存成功!', '');
} }
$this->success('参数保存成功!', '');
} else { } else {
$this->error('访问异常,请重新进入...'); $this->error('访问异常,请重新进入...');
} }

View File

@ -15,6 +15,8 @@
namespace app\admin\controller; namespace app\admin\controller;
use controller\BasicAdmin; use controller\BasicAdmin;
use library\Data;
use think\Db;
/** /**
* 系统用户管理控制器 * 系统用户管理控制器
@ -25,10 +27,104 @@ use controller\BasicAdmin;
*/ */
class User extends BasicAdmin { class User extends BasicAdmin {
/**
* 指定当前数据表
* @var string
*/
protected $table = 'SystemUser'; protected $table = 'SystemUser';
public function index() { public function index() {
parent::_list($this->table); $this->title = '用户管理';
$db = Db::name($this->table)->where('is_deleted', '0');
parent::_list($db);
}
/**
* 用户添加
*/
public function add() {
return $this->_form($this->table, 'form');
}
/**
* 用户编辑
*/
public function edit() {
return $this->add();
}
/**
* 用户密码修改
*/
public function pass() {
if (in_array('10000', explode(',', $this->request->post('id')))) {
$this->error('系统超级账号禁止操作!');
}
if ($this->request->isGet()) {
return $this->_form($this->table, 'pass');
}
$data = $this->request->post();
if ($data['password'] !== $data['repassword']) {
$this->error('两次输入的密码不一致!');
}
if (Data::save($this->table, ['id' => $data['id'], 'password' => md5($data['password'])], 'id')) {
$this->success('密码修改成功,下次请使用新密码登录!', '');
} else {
$this->error('密码修改失败,请稍候再试!');
}
}
/**
* 表单数据默认处理
* @param type $data
*/
public function _form_filter(&$data) {
if ($this->request->isPost()) {
if (isset($data['id'])) {
unset($data['username']);
} elseif (Db::name($this->table)->where('username', $data['username'])->find()) {
$this->error('用户账号已经存在,请使用其它账号!');
}
}
}
/**
* 删除用户
*/
public function del() {
if (in_array('10000', explode(',', $this->request->post('id')))) {
$this->error('系统超级账号禁止删除!');
}
if (Data::update($this->table)) {
$this->success("用户删除成功!", '');
} else {
$this->error("用户删除失败,请稍候再试!");
}
}
/**
* 用户禁用
*/
public function forbid() {
if (in_array('10000', explode(',', $this->request->post('id')))) {
$this->error('系统超级账号禁止操作!');
}
if (Data::update($this->table)) {
$this->success("用户禁用成功!", '');
} else {
$this->error("用户禁用失败,请稍候再试!");
}
}
/**
* 用户禁用
*/
public function resume() {
if (Data::update($this->table)) {
$this->success("用户启用成功!", '');
} else {
$this->error("用户启用失败,请稍候再试!");
}
} }
} }

View File

@ -18,7 +18,7 @@
<div class="layui-form-item text-center"> <div class="layui-form-item text-center">
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if} {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
<button class="layui-btn"type='submit'>保存数据</button> <button class="layui-btn" type='submit'>保存数据</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button> <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
</div> </div>

View File

@ -1,12 +1,13 @@
{extend name='extra@admin/content' /} {extend name='extra@admin/content' /}
{block name="content"} {block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
<div class="text-right" style='margin-bottom:10px'>
<button data-modal='{:url("$classuri/add")}' data-title="添加权限" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加权限</button> <button data-modal='{:url("$classuri/add")}' data-title="添加权限" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加权限</button>
<button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除权限</button> <button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除权限</button>
</div> </div>
{/block}
{block name="content"}
<form onsubmit="return false;" data-auto="" method="POST"> <form onsubmit="return false;" data-auto="" method="POST">
<input type="hidden" value="resort" name="action"/> <input type="hidden" value="resort" name="action"/>
<table class="table table-hover"> <table class="table table-hover">

View File

@ -38,7 +38,7 @@
<div class="hr-line-dashed"></div> <div class="hr-line-dashed"></div>
<div class="layui-form-item text-center"> <div class="layui-form-item text-center">
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if} {if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
<button class="layui-btn"type='submit'>保存数据</button> <button class="layui-btn" type='submit'>保存数据</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button> <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
</div> </div>
<script> <script>

View File

@ -1,11 +1,13 @@
{extend name='extra@admin/content' /} {extend name='extra@admin/content' /}
{block name="content"} {block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
<div class="text-right" style='margin-bottom:10px'>
<button data-modal='{:url("$classuri/add")}' data-title="添加菜单" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加菜单</button> <button data-modal='{:url("$classuri/add")}' data-title="添加菜单" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加菜单</button>
<button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除菜单</button> <button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除菜单</button>
</div> </div>
{/block}
{block name="content"}
<form onsubmit="return false;" data-auto="" method="POST"> <form onsubmit="return false;" data-auto="" method="POST">
<input type="hidden" value="resort" name="action"/> <input type="hidden" value="resort" name="action"/>
@ -35,7 +37,7 @@
<input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/> <input name="_{$vo.id}" value="{$vo.sort}" class="list-sort-input"/>
</td> </td>
<td class='text-center'> <td class='text-center'>
<i style="font-size:18px;float:right" class="{$vo.icon}"></i> <i style="font-size:18px;" class="{$vo.icon}"></i>
</td> </td>
<td>{$vo.spl}{$vo.title}</td> <td>{$vo.spl}{$vo.title}</td>
<td class='visible-lg'>{$vo.url}</td> <td class='visible-lg'>{$vo.url}</td>

View File

@ -1,65 +1,73 @@
{extend name='extra@admin/content' /} {extend name='extra@admin/content' /}
{block name="content"} {block name="content"}
<table class="table table-hover">
<form onsubmit="return false;" action='{:url("$classuri/save")}' data-auto="true" method="POST"> <thead>
<tr>
<div class="text-right" style='margin-bottom:10px'> <th style="width:20px"></th>
<button type="submit" class='layui-btn layui-btn-small'><i class='fa fa-save'></i> 保存更改</button> <th class='text-left'>节点</th>
</div> <th class='text-left'></th>
<th class='text-left'></th>
<table class="table table-hover"> <th>&nbsp;</th>
<thead> </tr>
<tr> </thead>
<th class='text-left'>节点名称</th> <tbody>
<th class='text-left'>节点代码</th> {foreach $nodes as $key=>$vo}
<th class='text-left'><input data-none-auto="" data-check-target='.auth-check-box' type='checkbox'/> 权限控制</th> <tr>
<th class='text-left'><input data-none-auto="" data-check-target='.menu-check-box' type='checkbox'/> 可设为菜单</th> <td style="width:20px"></td>
</tr> <td class='text-left nowrap'>
</thead> {$vo.spl}{$vo.node}
<tbody> {if auth("$classuri/save")}
{foreach $nodes as $key=>$vo} &nbsp;<input class='layui-input layui-input-inline title-input' style='height:28px;line-height:28px;width:auto' name='title.{$vo.node}' value="{$vo.title}"/>
<tr> {/if}
<td class="text-left nowrap" style="width:250px"> </td>
{$vo.spl} &nbsp; <td class='text-left' style="width:100px">
<input class='layui-input layui-input-inline' style='height:28px;line-height:28px;width:auto' name='title.{$vo.node}' value="{$vo.title}"/> {if auth("$classuri/save")}
</td> <label>
<td class='text-left' style="width:250px">{$vo.spl}{$vo.node}</td> {if substr_count($vo['node'],'/')==2}
<td class='text-left' style="width:100px"> {notempty name='vo.is_auth'}
<label> <input name='is_auth.{$vo.node}' checked='checked' class="check-box" type='checkbox' value='1'/>
{if substr_count($vo['node'],'/')==2} {else /}
{notempty name='vo.is_auth'} <input name='is_auth.{$vo.node}' class="check-box" type='checkbox' value='1'/>
<input name='auth.{$vo.node}' checked='checked' class="auth-check-box" type='checkbox' value='1'/> {/notempty}
{else /} 权限控制
<input name='auth.{$vo.node}' class="auth-check-box" type='checkbox' value='1'/> </label>
{/notempty} {/if}
权限控制 {/if}
</label> </td>
{/if} <td class='text-left'>
</td> {if auth("$classuri/save")}
<td class='text-left'> <label>
{if substr_count($vo['node'],'/')==2} {if substr_count($vo['node'],'/')==2}
{notempty name='vo.is_menu'} {notempty name='vo.is_menu'}
<input name='menu.{$vo.node}' checked='checked' class='menu-check-box' type='checkbox' value='1'/> <input name='is_menu.{$vo.node}' checked='checked' class='check-box' type='checkbox' value='1'/>
{else/} {else/}
<input name='menu.{$vo.node}' class='menu-check-box' type='checkbox' value='1'/> <input name='is_menu.{$vo.node}' class='check-box' type='checkbox' value='1'/>
{/notempty} {/notempty}
可设为菜单 可设为菜单
{/if} {/if}
</td> </label>
</tr> {/if}
{/foreach} </td>
</tbody> <td></td>
</table> </tr>
<script> {/foreach}
$(function () { </tbody>
$('input[type=checkbox]').on('click', function () { </table>
var checked = !!this.checked; {if auth("$classuri/save")}
$('[name^="' + this.name + '"]').map(function () { <script>
this.checked = checked; $(function () {
}); $('input.title-input').on('blur', function () {
$.form.load('{:url("save")}', {name: this.name, value: this.value}, 'POST', function (ret) {
return false;
}); });
}); });
</script> $('input.check-box').on('click', function () {
</form> $.form.load('{:url("save")}', {name: this.name, value: this.checked ? 1 : 0}, 'POST', function (ret) {
return false;
});
});
});
</script>
{/if}
{/block} {/block}

View File

@ -0,0 +1,43 @@
<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="{:url()}" data-auto="true" method="post">
<div class="layui-form-item">
<label class="layui-form-label">用户账号</label>
<div class="layui-input-block">
{if $vo and $vo.username}
<input type="text" readonly="" disabled="" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input disabled">
{else/}
<input type="text" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input">
{/if}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">联系手机</label>
<div class="layui-input-block">
<input type="tel" name="phone" value='{$vo.phone|default=""}' pattern="^1[3-9][0-9]{9}$" title="请输入联系手机" placeholder="请输入联系手机" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">联系邮箱</label>
<div class="layui-input-block">
<input type="text" name="mail" value='{$vo.mail|default=""}' title="请输入联系邮箱" placeholder="请输入联系邮箱" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">用户描述</label>
<div class="layui-input-block">
<textarea placeholder="请输入用户描述" title="请输入用户描述" class="layui-textarea" name="desc">{$vo.desc|default=""}</textarea>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="layui-form-item text-center">
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
<button class="layui-btn" type='submit'>保存数据</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
</div>
</form>

View File

@ -0,0 +1,73 @@
{extend name='extra@admin/content' /}
{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
<button data-modal='{:url("$classuri/add")}' data-title="添加用户" class='layui-btn layui-btn-small'><i class='fa fa-plus'></i> 添加用户</button>
<button data-update data-field='delete' data-action='{:url("$classuri/del")}' class='layui-btn layui-btn-small layui-btn-danger'><i class='fa fa-remove'></i> 删除用户</button>
</div>
{/block}
{block name="content"}
<form onsubmit="return false;" data-auto="" method="POST">
<input type="hidden" value="resort" name="action"/>
<table class="table table-hover">
<thead>
<tr>
<th class='list-table-check-td'>
<input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
</th>
<th class='text-center'>用户账号</th>
<th class='text-center'>手机号</th>
<th class='text-center'>电子邮箱</th>
<th class='text-center'>登录次数</th>
<th class='text-center'>最后登录</th>
<th class='text-center'>状态</th>
<th class='text-center'>操作</th>
</tr>
</thead>
<tbody>
{foreach $list as $key=>$vo}
<tr>
<td class='list-table-check-td'>
<input class="list-check-box" value='{$vo.id}' type='checkbox'/>
</td>
<td class='text-center'>{$vo.username}</td>
<td class='text-center'>{$vo.phone|default="<span style='color:#ccc'>还没有设置手机号</span>"}</td>
<td class='text-center'>{$vo.mail|default="<span style='color:#ccc'>还没有设置邮箱</span>"}</td>
<td class='text-center'>{$vo.login_num|default="<span style='color:#ccc'>从未登录</span>"}</td>
<td class='text-center'>{$vo.login_at|default="<span style='color:#ccc'>从未登录</span>"}</td>
<td class='text-center'>
{if $vo.status eq 0}
<span>已禁用</span>
{elseif $vo.status eq 1}
<span style="color:#090">使用中</span>
{/if}
</td>
<td class='text-center nowrap'>
{if auth("$classuri/edit")}
<span class="text-explode">|</span>
<a data-modal='{:url("$classuri/edit")}?id={$vo.id}' href="javascript:void(0)">编辑</a>
{/if}
{if auth("$classuri/edit")}
<span class="text-explode">|</span>
<a data-modal='{:url("$classuri/pass")}?id={$vo.id}' href="javascript:void(0)">密码</a>
{/if}
{if $vo.status eq 1 and auth("$classuri/forbid")}
<span class="text-explode">|</span>
<a data-update="{$vo.id}" data-field='status' data-value='0'data-action='{:url("$classuri/forbid")}' href="javascript:void(0)">禁用</a>
{elseif auth("$classuri/resume")}
<span class="text-explode">|</span>
<a data-update="{$vo.id}" data-field='status' data-value='1' data-action='{:url("$classuri/resume")}' href="javascript:void(0)">启用</a>
{/if}
{if auth("$classuri/del")}
<span class="text-explode">|</span>
<a data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del")}' href="javascript:void(0)">删除</a>
{/if}
</td>
</tr>
{/foreach}
</tbody>
</table>
{if isset($page)}<p>{$page}</p>{/if}
</form>
{/block}

View File

@ -0,0 +1,36 @@
<form class="layui-form layui-box" style='padding:25px 30px 20px 0' action="{:url()}" data-auto="true" method="post">
<div class="layui-form-item">
<label class="layui-form-label">用户账号</label>
<div class="layui-input-block">
{if $vo and $vo.username}
<input type="text" readonly="" disabled="" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input disabled">
{else/}
<input type="text" name="username" value='{$vo.username|default=""}' required="required" title="请输入用户名称" placeholder="请输入用户名称" class="layui-input">
{/if}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">登录密码</label>
<div class="layui-input-block">
<input type="password" name="password" value='' pattern="^\S{1,}$" required="" title="请输入登录密码" placeholder="请输入登录密码" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">重复密码</label>
<div class="layui-input-block">
<input type="text" name="repassword" value='' pattern="^\S{1,}$" required="" title="请输入重复密码" placeholder="请输入重复密码" class="layui-input">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="layui-form-item text-center">
{if isset($vo['id'])}<input type='hidden' value='{$vo.id}' name='id'/>{/if}
<button class="layui-btn" type='submit'>保存数据</button>
<button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗?" data-close>取消编辑</button>
</div>
</form>

View File

@ -2,16 +2,10 @@
{if isset($title)} {if isset($title)}
<div class="ibox-title"> <div class="ibox-title">
<h5>{$title}</h5> <h5>{$title}</h5>
{block name="button"}{/block}
</div> </div>
{/if} {/if}
<div class="ibox-content fadeInUp animated"> <div class="ibox-content fadeInUp animated">
<div class="alert alert-success alert-dismissible" role="alert" style="border-radius:0">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<p style="font-size:18px;padding-bottom:10px">正在闭关Coding请随意看看!</p>
<p style="font-size:14px">Thank you so much.</p>
</div>
{if isset($alert)} {if isset($alert)}
<div class="alert alert-{$alert.type} alert-dismissible" role="alert" style="border-radius:0"> <div class="alert alert-{$alert.type} alert-dismissible" role="alert" style="border-radius:0">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> <button type="button" class="close" data-dismiss="alert" aria-label="Close">

View File

@ -11,18 +11,51 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/Think.Admin // | github开源项目https://github.com/zoujingli/Think.Admin
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\index\controller; namespace app\index\controller;
use library\Http;
use think\Controller; use think\Controller;
use think\Db; use think\Db;
class Index extends Controller { class Index extends Controller {
public function index() { public function index() {
$this->redirect('@admin'); $this->redirect('@admin');
$version = Db::query('select version() as ver'); $version = Db::query('select version() as ver');
$version = array_pop($version); $version = array_pop($version);
$this->assign('mysql_ver', $version['ver']); $this->assign('mysql_ver', $version['ver']);
return view(); return view();
} }
public function test() {
$DEVICE_NO = 'kdt1080126';
$key = '20585';
$content = "";
$content .= "^Q +http://weixin.qq.com/r/2Eg2LkzEKRFWrQhN9123";
$result = $this->sendSelfFormatOrderInfo($DEVICE_NO, $key, 1, $content);
var_dump($result);
}
function sendSelfFormatOrderInfo($device_no, $key, $times, $orderInfo) { // $times打印次数
$selfMessage = array(
'deviceNo' => $device_no,
'printContent' => $orderInfo,
'key' => $key,
'times' => $times
);
$url = "http://open.printcenter.cn:8080/addOrder";
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded ",
'method' => 'POST',
'content' => http_build_query($selfMessage),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
} }