更新功能
This commit is contained in:
@@ -33,4 +33,17 @@ class Admin extends BaseController {
|
||||
$this->data['config'] = $config;
|
||||
}
|
||||
|
||||
protected function success($msg, $url){
|
||||
$this->data['code'] = 0;
|
||||
$this->data['msg'] = $msg;
|
||||
$this->data['url'] = $url->__toString();
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
protected function error($msg, $url){
|
||||
$this->data['code'] = 1;
|
||||
$this->data['msg'] = $msg;
|
||||
$this->data['url'] = $url->__toString();
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,19 @@ class Client extends Admin{
|
||||
public function add(ClientModel $client){
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->param();
|
||||
$result = $client->validate(true)->save($data);
|
||||
$result = $client->save($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('成功添加', url('client/index'));
|
||||
return $this->success('成功添加', url('/admin/client/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
}else{
|
||||
$info['appid'] = rand_string(10, 1); //八位数字appid
|
||||
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
||||
$data = array(
|
||||
$this->data['data'] = array(
|
||||
'info' => $info
|
||||
);
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -57,15 +58,20 @@ class Client extends Admin{
|
||||
public function edit(ClientModel $client){
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->param();
|
||||
$result = $client->validate(true)->save($data, array('id'=>$request->param('id')));
|
||||
if (!isset($data['id']) || !$data['id']) {
|
||||
return $this->error('非法操作!');
|
||||
}
|
||||
|
||||
$result = $client->where(array('id'=>$data['id']))->save($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('修改添加', url('client/index'));
|
||||
return $this->success('修改成功', url('/admin/client/index'));
|
||||
}else{
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
}else{
|
||||
$info = $client->where('id', $this->request->param('id'))->find();
|
||||
$data = array(
|
||||
$this->data['template'] = "add";
|
||||
$this->data['data'] = array(
|
||||
'info' => $info
|
||||
);
|
||||
return $this->data;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
</header>
|
||||
<div class="main-box-body clearfix">
|
||||
<form method="post" class="form form-horizontal">
|
||||
<form method="post" class="form form-horizontal" role="ajax">
|
||||
<div class="form-group">
|
||||
<label class="col-md-2 control-label">客户端名称</label>
|
||||
<div class="col-md-10">
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<h2>{$meta_title|default='新功能'}</h2>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<a class="btn btn-primary" href="{:url('add')}">新 增</a>
|
||||
<button class="btn btn-danger ajax-post confirm" url="{:url('del')}" target-form="ids">删 除</button>
|
||||
<a class="btn btn-primary" href="{:url('/admin/client/add')}">新 增</a>
|
||||
<button class="btn btn-danger ajax-post confirm" url="{:url('/admin/client/del')}" target-form="ids">删 除</button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="main-box-body clearfix">
|
||||
@@ -15,6 +15,7 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="30"><input class="checkbox check-all" type="checkbox"></th>
|
||||
<th>ID</th>
|
||||
<th>名称</th>
|
||||
<th>APPID</th>
|
||||
@@ -27,6 +28,7 @@
|
||||
<tbody>
|
||||
{volist name="list" id="item"}
|
||||
<tr>
|
||||
<td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
|
||||
<td>{$item['id']}</td>
|
||||
<td>{$item['title']}</td>
|
||||
<td>{$item['appid']}</td>
|
||||
@@ -34,8 +36,8 @@
|
||||
<td>{$item['create_time']}</td>
|
||||
<td>{$item['update_time']}</td>
|
||||
<td>
|
||||
<a href="{:url('client/edit?id='.$item['id'])}">编辑</a>
|
||||
<a href="{:url('client/del?id='.$item['id'])}" class="ajax-post confirm">删除</a>
|
||||
<a href="{:url('/admin/client/edit', array('id'=>$item['id']))}">编辑</a>
|
||||
<a href="{:url('/admin/client/del', array('id'=>$item['id']))}" class="ajax-post confirm">删除</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
@@ -46,3 +48,8 @@
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="script"}
|
||||
<script type="text/javascript">
|
||||
var isLoadModule = true;
|
||||
</script>
|
||||
{/block}
|
||||
@@ -8,7 +8,7 @@
|
||||
</div>
|
||||
</header>
|
||||
<div class="main-box-body clearfix">
|
||||
<form method="post" class="form form-horizontal">
|
||||
<form method="post" class="form form-horizontal" role="ajax">
|
||||
<div class="form-group">
|
||||
<label class="col-lg-2 control-label">配置标识</label>
|
||||
<div class="col-lg-10">
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade in active" id="tab-home">
|
||||
<form method="post" class="form form-horizontal" role="form">
|
||||
<form method="post" class="form form-horizontal" role="ajax">
|
||||
{volist name="list" id="item"}
|
||||
<div class="form-group">
|
||||
<label for="inputEmail1" class="col-lg-2 control-label">{$item['title']}</label>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
</header>
|
||||
<div class="main-box-body clearfix">
|
||||
<form method="post" class="form form-horizontal" action="edit">
|
||||
<form method="post" class="form form-horizontal" action="edit" role="ajax">
|
||||
<div class="tabs-wrapper">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#pc" data-toggle="tab">PC端模板</a></li>
|
||||
|
||||
@@ -58,7 +58,7 @@ return [
|
||||
// 指定从服务器序号
|
||||
'slave_no' => '',
|
||||
// 是否严格检查字段是否存在
|
||||
'fields_strict' => true,
|
||||
'fields_strict' => false,
|
||||
// 是否需要进行SQL性能分析
|
||||
'sql_explain' => false,
|
||||
// 是否需要断线重连
|
||||
|
||||
@@ -23,8 +23,8 @@ require.config({
|
||||
"nanoscroller":"/static/libs/nanoscroller/jquery.nanoscroller.min",
|
||||
"slimscroll":"/static/js/jquery.slimscroll.min",
|
||||
"bootstrap":"/static/libs/bootstrap/js/bootstrap.min",
|
||||
'bootstrap-table-commonsearch': 'bootstrap-table-commonsearch',
|
||||
'bootstrap-table-template': 'bootstrap-table-template',
|
||||
'bootstrap-table-commonsearch': '/static/js/bootstrap-table-commonsearch',
|
||||
'bootstrap-table-template': '/static/js/bootstrap-table-template',
|
||||
//
|
||||
// 以下的包从bower的libs目录加载
|
||||
'jquery': '/static/libs/jquery/dist/jquery.min',
|
||||
@@ -129,7 +129,7 @@ require.config({
|
||||
|
||||
require(['jquery', 'sent'], function($, Sent){
|
||||
$(function($) {
|
||||
require(['backend', 'backend-init', 'addons'], function (Backend, undefined, Addons) {
|
||||
require(['backend', 'addons'], function (Backend, Addons) {
|
||||
// 避免目录冲突
|
||||
require.config({baseUrl: '/static/admin/js/module/'});
|
||||
|
||||
|
||||
@@ -23,12 +23,45 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
|
||||
init: function () {
|
||||
|
||||
//绑定表单提交事件
|
||||
if($('form[role=ajax]').length > 0){
|
||||
require(['form'], function(Form){
|
||||
Form.api.bindevent($("form"));
|
||||
})
|
||||
}
|
||||
|
||||
//绑定ajax请求事件
|
||||
if($('.ajax-post').length > 0){
|
||||
$('.ajax-post').on('click', function(e){
|
||||
Sent.events.onAjaxRequest(this, e, 'post');
|
||||
})
|
||||
}
|
||||
|
||||
if($('.ajax-get').length > 0){
|
||||
$('.ajax-post').on('click', function(e){
|
||||
Sent.events.onAjaxRequest(this, e, 'get');
|
||||
})
|
||||
}
|
||||
|
||||
//公共代码
|
||||
//配置Toastr的参数
|
||||
Toastr.options = Sent.config.toastr;
|
||||
},
|
||||
|
||||
events: {
|
||||
//ajax请求
|
||||
onAjaxRequest: function(obj, event, type){
|
||||
event.preventDefault();
|
||||
var url = $(obj).attr('href') ? $(obj).attr('href') : $(obj).attr('url');
|
||||
if ($(obj).hasClass('confirm')) {
|
||||
Layer.confirm('您确定需要'+$(obj).text()+'?', function(index){
|
||||
Sent.api.ajax({type:type, url: url});
|
||||
layer.close(index);
|
||||
})
|
||||
}else{
|
||||
Sent.api.ajax({type:type, url: url});
|
||||
}
|
||||
},
|
||||
//请求成功的回调
|
||||
onAjaxSuccess: function (ret, onAjaxSuccess) {
|
||||
var data = typeof ret.data !== 'undefined' ? ret.data : null;
|
||||
@@ -85,6 +118,11 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
} else {
|
||||
Sent.events.onAjaxError(ret, error);
|
||||
}
|
||||
if (ret.url) {
|
||||
setTimeout(function(){
|
||||
window.location.href = ret.url;
|
||||
}, 3000);
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
index && Layer.close(index);
|
||||
@@ -249,19 +287,60 @@ define(['jquery', 'toastr','layer'], function($, Toastr, Layer){
|
||||
},
|
||||
toastr: Toastr,
|
||||
layer: Layer
|
||||
},
|
||||
lang: function () {
|
||||
var args = arguments,
|
||||
string = args[0],
|
||||
i = 1;
|
||||
string = string.toLowerCase();
|
||||
//string = typeof Lang[string] != 'undefined' ? Lang[string] : string;
|
||||
if (typeof Lang !== 'undefined' && typeof Lang[string] !== 'undefined') {
|
||||
if (typeof Lang[string] == 'object')
|
||||
return Lang[string];
|
||||
string = Lang[string];
|
||||
} else if (string.indexOf('.') !== -1 && false) {
|
||||
var arr = string.split('.');
|
||||
var current = Lang[arr[0]];
|
||||
for (var i = 1; i < arr.length; i++) {
|
||||
current = typeof current[arr[i]] != 'undefined' ? current[arr[i]] : '';
|
||||
if (typeof current != 'object')
|
||||
break;
|
||||
}
|
||||
if (typeof current == 'object')
|
||||
return current;
|
||||
string = current;
|
||||
} else {
|
||||
string = args[0];
|
||||
}
|
||||
return string.replace(/%((%)|s|d)/g, function (m) {
|
||||
// m is the matched format, e.g. %s, %d
|
||||
var val = null;
|
||||
if (m[2]) {
|
||||
val = m[2];
|
||||
} else {
|
||||
val = args[i];
|
||||
// A switch statement so that the formatter can be extended. Default is %s
|
||||
switch (m) {
|
||||
case '%d':
|
||||
val = parseFloat(val);
|
||||
if (isNaN(val)) {
|
||||
val = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return val;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if($('form').length > 0){
|
||||
require(['form'], function(Form){
|
||||
Form.api.bindevent($("form"));
|
||||
})
|
||||
}
|
||||
//将Layer暴露到全局中去
|
||||
window.Layer = Layer;
|
||||
//将Toastr暴露到全局中去
|
||||
window.Toastr = Toastr;
|
||||
//将Fast渲染至全局
|
||||
//将语言方法暴露到全局中去
|
||||
window.__ = Sent.lang;
|
||||
//将Sent渲染至全局
|
||||
window.Sent = Sent;
|
||||
|
||||
Sent.init(); //默认初始化执行的代码
|
||||
|
||||
Reference in New Issue
Block a user