mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 新增加融洽第三方
This commit is contained in:
parent
2b26897cbf
commit
d307e10e3d
103
Application/Admin/Controller/ApiKeyController.class.php
Normal file
103
Application/Admin/Controller/ApiKeyController.class.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* @since 2017-04-22
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Controller;
|
||||
|
||||
|
||||
class ApiKeyController extends BaseController {
|
||||
|
||||
public function index() {
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function ajaxGetIndex() {
|
||||
$postData = I('post.');
|
||||
$start = $postData['start'] ? $postData['start'] : 0;
|
||||
$limit = $postData['length'] ? $postData['length'] : 20;
|
||||
$draw = $postData['draw'];
|
||||
$total = D('ApiStoreAuth')->count();
|
||||
$info = D('ApiStoreAuth')->limit($start, $limit)->select();
|
||||
$data = array(
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $total,
|
||||
'recordsFiltered' => $total,
|
||||
'data' => $info
|
||||
);
|
||||
$this->ajaxReturn($data, 'json');
|
||||
}
|
||||
|
||||
public function edit(){
|
||||
if( IS_GET ){
|
||||
$id = I('get.id');
|
||||
if( $id ){
|
||||
$detail = D('ApiStoreAuth')->where(array('id' => $id))->find();
|
||||
$this->assign('detail', $detail);
|
||||
$this->display('add');
|
||||
}else{
|
||||
$this->redirect('add');
|
||||
}
|
||||
}elseif( IS_POST ){
|
||||
$data = I('post.');
|
||||
$res = D('ApiStoreAuth')->where(array('id' => $data['id']))->save($data);
|
||||
if( $res === false ){
|
||||
$this->ajaxError('操作失败');
|
||||
}else{
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function add(){
|
||||
if( IS_POST ){
|
||||
$data = I('post.');
|
||||
$res = D('ApiStoreAuth')->add($data);
|
||||
if( $res === false ){
|
||||
$this->ajaxError('操作失败');
|
||||
}else{
|
||||
$this->ajaxSuccess('添加成功');
|
||||
}
|
||||
}else{
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
public function open(){
|
||||
if( IS_POST ){
|
||||
$id = I('post.id');
|
||||
if( $id ){
|
||||
D('ApiStoreAuth')->open(array('id' => $id));
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}else{
|
||||
$this->ajaxError('缺少参数');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if( IS_POST ){
|
||||
$id = I('post.id');
|
||||
if( $id ){
|
||||
D('ApiStoreAuth')->close(array('id' => $id));
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}else{
|
||||
$this->ajaxError('缺少参数');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function del(){
|
||||
if( IS_POST ){
|
||||
$id = I('post.id');
|
||||
if( $id ){
|
||||
D('ApiStoreAuth')->where(array('id' => $id))->delete();
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}else{
|
||||
$this->ajaxError('缺少参数');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
129
Application/Admin/Controller/ApiStoreController.class.php
Normal file
129
Application/Admin/Controller/ApiStoreController.class.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @since 2017/04/21 创建
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Controller;
|
||||
|
||||
|
||||
class ApiStoreController extends BaseController {
|
||||
public function index() {
|
||||
$keyArr = D('ApiStoreAuth')->select();
|
||||
$list = array_column($keyArr, 'name', 'id');
|
||||
$list[0] = '暂不绑定';
|
||||
$this->assign('list', $list);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function ajaxGetIndex() {
|
||||
$postData = I('post.');
|
||||
$start = $postData['start'] ? $postData['start'] : 0;
|
||||
$limit = $postData['length'] ? $postData['length'] : 20;
|
||||
$draw = $postData['draw'];
|
||||
$total = D('ApiStore')->count();
|
||||
$info = D('ApiStore')->limit($start, $limit)->select();
|
||||
$data = array(
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $total,
|
||||
'recordsFiltered' => $total,
|
||||
'data' => $info
|
||||
);
|
||||
$this->ajaxReturn($data, 'json');
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
if (IS_GET) {
|
||||
$id = I('get.id');
|
||||
if ($id) {
|
||||
$detail = D('ApiStore')->where(array('id' => $id))->find();
|
||||
$this->assign('detail', $detail);
|
||||
$keyArr = D('ApiStoreAuth')->select();
|
||||
$list = array_column($keyArr, 'name', 'id');
|
||||
$list[0] = '暂不绑定';
|
||||
$this->assign('list', $list);
|
||||
$this->display('add');
|
||||
} else {
|
||||
$this->redirect('add');
|
||||
}
|
||||
} elseif (IS_POST) {
|
||||
$data = I('post.');
|
||||
$res = D('ApiStore')->where(array('id' => $data['id']))->save($data);
|
||||
if ($res === false) {
|
||||
$this->ajaxError('操作失败');
|
||||
} else {
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function refresh() {
|
||||
$apiPath = dirname(THINK_PATH) . '/Application/Home/ApiStore/';
|
||||
$dir = opendir($apiPath);
|
||||
if ($dir) {
|
||||
$preData = array();
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
$filePath = $apiPath . $file;
|
||||
if (!is_dir($filePath)) {
|
||||
$prefix = 'Home\\ApiStore\\';
|
||||
$moduleName = str_replace('.class.php', '', $file);
|
||||
$reflection = new \ReflectionClass($prefix . $moduleName);
|
||||
if ($reflection->hasProperty('apiName')) {
|
||||
$data['name'] = $reflection->getStaticPropertyValue('apiName');
|
||||
} else {
|
||||
$data['name'] = '未定义';
|
||||
}
|
||||
$data['path'] = $prefix . $moduleName;
|
||||
$preDataPath[] = $prefix . $moduleName;
|
||||
$preData[] = $data;
|
||||
}
|
||||
}
|
||||
if (!$preData) {
|
||||
D('ApiStore')->execute('Truncate Table api_store');
|
||||
} else {
|
||||
$old = D('ApiStore')->select();
|
||||
$oldPath = array_column($old, 'path');
|
||||
$addArr = array_diff($preDataPath, $oldPath);
|
||||
$delArr = array_diff($oldPath, $preDataPath);
|
||||
if ($delArr) {
|
||||
D('ApiStore')->where(array('path' => array('in', $delArr)))->delete();
|
||||
}
|
||||
if ($addArr) {
|
||||
$addData = array();
|
||||
foreach ($preData as $item) {
|
||||
if (in_array($item['path'], $addArr)) {
|
||||
$addData[] = $item;
|
||||
}
|
||||
}
|
||||
D('ApiStore')->addAll($addData);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
|
||||
public function open() {
|
||||
if (IS_POST) {
|
||||
$id = I('post.id');
|
||||
if ($id) {
|
||||
D('ApiStore')->open(array('id' => $id));
|
||||
$this->ajaxSuccess('操作成功');
|
||||
} else {
|
||||
$this->ajaxError('缺少参数');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if (IS_POST) {
|
||||
$id = I('post.id');
|
||||
if ($id) {
|
||||
D('ApiStore')->close(array('id' => $id));
|
||||
$this->ajaxSuccess('操作成功');
|
||||
} else {
|
||||
$this->ajaxError('缺少参数');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
Application/Admin/Model/ApiStoreAuthModel.class.php
Normal file
20
Application/Admin/Model/ApiStoreAuthModel.class.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @since 2017-04-22
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Model;
|
||||
|
||||
|
||||
class ApiStoreAuthModel extends BaseModel {
|
||||
|
||||
public function open( $where ){
|
||||
return $this->where( $where )->save( array('status' => 1) );
|
||||
}
|
||||
|
||||
public function close( $where ){
|
||||
return $this->where( $where )->save( array('status' => 0) );
|
||||
}
|
||||
|
||||
}
|
13
Application/Admin/Model/ApiStoreModel.class.php
Normal file
13
Application/Admin/Model/ApiStoreModel.class.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @since 2017/04/19 创建
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Model;
|
||||
|
||||
|
||||
class ApiStoreModel extends BaseModel {
|
||||
|
||||
}
|
@ -12,4 +12,12 @@ use Think\Model;
|
||||
|
||||
class BaseModel extends Model {
|
||||
Protected $autoCheckFields = false;
|
||||
|
||||
public function open( $where ){
|
||||
return $this->where( $where )->save( array('status' => 1) );
|
||||
}
|
||||
|
||||
public function close( $where ){
|
||||
return $this->where( $where )->save( array('status' => 0) );
|
||||
}
|
||||
}
|
93
Application/Admin/View/ApiKey/add.html
Normal file
93
Application/Admin/View/ApiKey/add.html
Normal file
@ -0,0 +1,93 @@
|
||||
<extend name="Public/base" />
|
||||
<block name="main">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>秘钥管理 - 新增秘钥</legend>
|
||||
<div class="layui-field-box">
|
||||
<form class="layui-form" action="">
|
||||
<if condition="isset($detail['id'])">
|
||||
<input type="hidden" name="id" value="{$detail['id']}">
|
||||
</if>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">秘钥名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="name" required value="{:(isset($detail['name'])?$detail['name']:'')}" lay-verify="required" placeholder="请输入应用名称" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">AppId</label>
|
||||
<div class="layui-input-inline" style="width: 300px;">
|
||||
<input name="appId" value="{$detail['appId']}" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">AppSecret</label>
|
||||
<div class="layui-input-inline" style="width: 300px;">
|
||||
<input name="appSecret" value="{$detail['appSecret']}" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<if condition="isset($detail['id'])">
|
||||
<input type="hidden" name="id" value="{$detail['id']}">
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(formDemo)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("edit")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<else />
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(formDemo)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("add")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</if>
|
||||
</block>
|
160
Application/Admin/View/ApiKey/index.html
Normal file
160
Application/Admin/View/ApiKey/index.html
Normal file
@ -0,0 +1,160 @@
|
||||
<extend name="Public/base"/>
|
||||
<block name="main">
|
||||
<script type="text/javascript" src="__PUBLIC__/dataTable/jquery.dataTables.min.js"></script>
|
||||
<link rel="stylesheet" href="__PUBLIC__/css/dataTable.css">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>秘钥管理 - 秘钥列表</legend>
|
||||
<div class="layui-field-box">
|
||||
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon"></i> 新增</span>
|
||||
<table class="layui-table" id="list-admin" lay-even>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>秘钥名称</th>
|
||||
<th>AppId</th>
|
||||
<th>AppSecret</th>
|
||||
<th>秘钥状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<script>
|
||||
/**
|
||||
* 格式化时间戳
|
||||
* @param fmt
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
Date.prototype.Format = function (fmt) {
|
||||
var o = {
|
||||
"M+": this.getMonth() + 1, //月份
|
||||
"d+": this.getDate(), //日
|
||||
"h+": this.getHours(), //小时
|
||||
"m+": this.getMinutes(), //分
|
||||
"s+": this.getSeconds(), //秒
|
||||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||||
"S": this.getMilliseconds() //毫秒
|
||||
};
|
||||
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||||
for (var k in o)
|
||||
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
||||
return fmt;
|
||||
};
|
||||
|
||||
layui.use(['layer', 'form'], function () {
|
||||
$('.api-add').on('click', function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ['80%', '80%'],
|
||||
maxmin: true,
|
||||
content: '{:U("add")}'
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.edit', function () {
|
||||
var ownObj = $(this);
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ['80%', '80%'],
|
||||
maxmin: true,
|
||||
content: ownObj.attr('data-url') + '&id=' + ownObj.attr('data-id')
|
||||
});
|
||||
});
|
||||
$(document).on('click', '.confirm', function () {
|
||||
var ownObj = $(this);
|
||||
layer.confirm(ownObj.attr('data-info'), {
|
||||
btn: ['确定', '取消'] //按钮
|
||||
}, function () {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ownObj.attr('data-url'),
|
||||
data: {id: ownObj.attr('data-id')},
|
||||
success: function (msg) {
|
||||
if (msg.code == 1) {
|
||||
location.reload();
|
||||
} else {
|
||||
layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time: 1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var myFun = function (query) {
|
||||
query = query || '';
|
||||
return $('#list-admin').DataTable({
|
||||
dom: 'rt<"bottom"ifpl><"clear">',
|
||||
ordering: false,
|
||||
autoWidth: false,
|
||||
searching: false,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: '{:U("ajaxGetIndex")}' + query,
|
||||
type: 'POST',
|
||||
dataSrc: function (json) {
|
||||
if (json.code == 0) {
|
||||
parent.layer.msg(json.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time: 1500
|
||||
});
|
||||
} else {
|
||||
return json.data;
|
||||
}
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
"targets": 3,
|
||||
"render": function (data) {
|
||||
if (data == 1) {
|
||||
return '启用';
|
||||
} else {
|
||||
return '禁用';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets": 4,
|
||||
"render": function (data, type, row) {
|
||||
var returnStr = '';
|
||||
if (row.status == 1) {
|
||||
returnStr += '<span class="layui-btn layui-btn-warm confirm" ' +
|
||||
'data-id="' + row.id + '" data-info="你确定禁用当前秘钥么?" data-url="{:U(\'close\')}">禁用</span>';
|
||||
} else {
|
||||
returnStr += '<span class="layui-btn confirm" ' +
|
||||
'data-id="' + row.id + '" data-info="你确定启用当前秘钥么?" data-url="{:U(\'open\')}">启用</span>';
|
||||
}
|
||||
returnStr += '<span class="layui-btn edit layui-btn-normal" ' +
|
||||
'data-id="' + row.id + '" data-url="{:U(\'edit\')}">编辑</span>';
|
||||
returnStr += '<span class="layui-btn layui-btn-danger confirm" ' +
|
||||
'data-id="' + row.id + '" data-info="你确定删除当前商品么?" data-url="{:U(\'del\')}">删除</span>';
|
||||
return returnStr;
|
||||
}
|
||||
}
|
||||
],
|
||||
iDisplayLength: 20,
|
||||
aLengthMenu: [20, 30, 50],
|
||||
columns: [
|
||||
{"data": "name"},
|
||||
{"data": "appId"},
|
||||
{"data": "appSecret"},
|
||||
{"data": "status"},
|
||||
{"data": null}
|
||||
]
|
||||
});
|
||||
};
|
||||
var myTable = myFun();
|
||||
$('.sub').on("click", function () {
|
||||
myTable.destroy();
|
||||
myTable = myFun('&' + $('#form-admin-add').serialize());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</block>
|
99
Application/Admin/View/ApiStore/add.html
Normal file
99
Application/Admin/View/ApiStore/add.html
Normal file
@ -0,0 +1,99 @@
|
||||
<extend name="Public/base" />
|
||||
<block name="main">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>接口管理 - 接口编辑</legend>
|
||||
<div class="layui-field-box">
|
||||
<form class="layui-form" action="">
|
||||
<if condition="isset($detail['id'])">
|
||||
<input type="hidden" name="id" value="{$detail['id']}">
|
||||
</if>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">接口名称</label>
|
||||
<div class="layui-input-inline" style="width: 300px;">
|
||||
<input type="text" name="name" value="{$detail['name']}" readonly class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">接口路径</label>
|
||||
<div class="layui-input-inline" style="width: 300px;">
|
||||
<input type="text" name="path" value="{$detail['path']}" readonly class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">适配秘钥</label>
|
||||
<div class="layui-input-inline" style="width: 300px;">
|
||||
<select name="auth" lay-verify="">
|
||||
<volist name="list" id="vo">
|
||||
<option value="{$key}" {:($detail['auth'] == $key?'selected':'')}>{$vo}</option>
|
||||
</volist>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<if condition="isset($detail['id'])">
|
||||
<input type="hidden" name="id" value="{$detail['id']}">
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(formDemo)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("edit")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<else />
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(formDemo)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("add")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</if>
|
||||
</block>
|
152
Application/Admin/View/ApiStore/index.html
Normal file
152
Application/Admin/View/ApiStore/index.html
Normal file
@ -0,0 +1,152 @@
|
||||
<extend name="Public/base"/>
|
||||
<block name="main">
|
||||
<script type="text/javascript" src="__PUBLIC__/dataTable/jquery.dataTables.min.js"></script>
|
||||
<link rel="stylesheet" href="__PUBLIC__/css/dataTable.css">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>接口仓库 - 接口列表</legend>
|
||||
<div class="layui-field-box">
|
||||
<span class="layui-btn layui-btn-warm api-add"><i class="layui-icon">ဂ</i> 刷新</span>
|
||||
<table class="layui-table" id="list-admin" lay-even>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>接口名称</th>
|
||||
<th>接口路径</th>
|
||||
<th>适配秘钥</th>
|
||||
<th>接口状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<script>
|
||||
/**
|
||||
* 格式化时间戳
|
||||
* @param fmt
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
Date.prototype.Format = function (fmt) {
|
||||
var o = {
|
||||
"M+": this.getMonth() + 1, //月份
|
||||
"d+": this.getDate(), //日
|
||||
"h+": this.getHours(), //小时
|
||||
"m+": this.getMinutes(), //分
|
||||
"s+": this.getSeconds(), //秒
|
||||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||||
"S": this.getMilliseconds() //毫秒
|
||||
};
|
||||
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||||
for (var k in o)
|
||||
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
||||
return fmt;
|
||||
};
|
||||
|
||||
layui.use(['layer', 'form'], function () {
|
||||
$('.api-add').on('click', function () {
|
||||
var index = layer.load(0, {shade: [0.4, '#393D49']});
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: '{:U("refresh")}',
|
||||
success: function (msg) {
|
||||
if (msg.code == 1) {
|
||||
location.reload();
|
||||
} else {
|
||||
layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time: 1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
$(document).on('click', '.edit', function () {
|
||||
var ownObj = $(this);
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ['80%', '80%'],
|
||||
maxmin: true,
|
||||
content: ownObj.attr('data-url') + '&id=' + ownObj.attr('data-id')
|
||||
});
|
||||
});
|
||||
|
||||
var myFun = function (query) {
|
||||
query = query || '';
|
||||
return $('#list-admin').DataTable({
|
||||
dom: 'rt<"bottom"ifpl><"clear">',
|
||||
ordering: false,
|
||||
autoWidth: false,
|
||||
searching: false,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: '{:U("ajaxGetIndex")}' + query,
|
||||
type: 'POST',
|
||||
dataSrc: function (json) {
|
||||
if (json.code == 0) {
|
||||
parent.layer.msg(json.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time: 1500
|
||||
});
|
||||
} else {
|
||||
return json.data;
|
||||
}
|
||||
}
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
"targets": 2,
|
||||
"render": function (data) {
|
||||
return JSON.parse('<?php echo json_encode($list)?>')[data];
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets": 3,
|
||||
"render": function (data) {
|
||||
if (data == 1) {
|
||||
return '启用';
|
||||
} else {
|
||||
return '禁用';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets": 4,
|
||||
"render": function (data, type, row) {
|
||||
var returnStr = '';
|
||||
if (row.status == 1) {
|
||||
returnStr += '<span class="layui-btn layui-btn-warm confirm" ' +
|
||||
'data-id="' + row.id + '" data-info="你确定禁用当前SDK么?" data-url="{:U(\'close\')}">禁用</span>';
|
||||
} else {
|
||||
returnStr += '<span class="layui-btn confirm" ' +
|
||||
'data-id="' + row.id + '" data-info="你确定启用当前SDK么?" data-url="{:U(\'open\')}">启用</span>';
|
||||
}
|
||||
returnStr += '<span class="layui-btn edit layui-btn-normal" ' +
|
||||
'data-id="' + row.id + '" data-url="{:U(\'edit\')}">编辑</span>';
|
||||
return returnStr;
|
||||
}
|
||||
}
|
||||
],
|
||||
iDisplayLength: 20,
|
||||
aLengthMenu: [20, 30, 50],
|
||||
columns: [
|
||||
{"data": "name"},
|
||||
{"data": "path"},
|
||||
{"data": "auth"},
|
||||
{"data": "status"},
|
||||
{"data": null}
|
||||
]
|
||||
});
|
||||
};
|
||||
var myTable = myFun();
|
||||
$('.sub').on("click", function () {
|
||||
myTable.destroy();
|
||||
myTable = myFun('&' + $('#form-admin-add').serialize());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</block>
|
Loading…
x
Reference in New Issue
Block a user