add addons

This commit is contained in:
toogee 2020-10-21 17:20:18 +08:00
parent 4f9c25ab3d
commit f1735768ff
10 changed files with 281 additions and 6 deletions

View File

@ -1,3 +1,4 @@
KeyAuth.php
Version.php
TimeLine.php
Plugins.php

View File

@ -0,0 +1,122 @@
<?php
namespace app\admin\controller;
use app\common\controller\AdminController;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
use think\facade\Config;
use think\exception\ValidateException;
use app\admin\model\Addons as AddonsModel;
use taoler\com\Files;
class Addons extends AdminController
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
if(Request::isAjax()){
var_dump(Files::getDirName('../addons/'));
}
return View::fetch();
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function add()
{
//添加版本
if(Request::isAjax()){
$data = Request::param();
$result = AddonsModel::create($data);
if($result){
$res = ['code'=>0,'msg'=>'添加成功'];
}else{
$res = ['code'=>-1,'msg'=>'添加失败'];
}
return json($res);
}
return View::fetch();
}
/**
* 编辑版本
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
$addons = AddonsModel::find($id);
if(Request::isAjax()){
$data = Request::only(['id','addons_name','addons_version','addons_auther','addons_resume','addons_price','addons_src']);
$result = $addons->where('id',$id)->save($data);
if($result){
$res = ['code'=>0,'msg'=>'编辑成功'];
}else{
$res = ['code'=>-1,'msg'=>'编辑失败'];
}
return json($res);
}
View::assign('addons',$addons);
return View::fetch();
}
/**
* 上传版本的zip资源
*
* @param
* @param int $id
* @return \think\Response
*/
public function uploadZip()
{
$id = Request::param();
$file = request()->file('file');
try {
validate(['file'=>'filesize:2048|fileExt:zip,rar,7z'])
->check(array($file));
$savename = \think\facade\Filesystem::disk('public')->putFile('addons',$file);
} catch (think\exception\ValidateException $e) {
echo $e->getMessage();
}
$upload = Config::get('filesystem.disks.public.url');
if($savename){
$name_path =str_replace('\\',"/",$upload.'/'.$savename);
$res = ['code'=>0,'msg'=>'插件上传成功','src'=>$name_path];
} else {
$res = ['code'=>-1,'msg'=>'上传错误'];
}
return json($res);
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
$version = AddonsModel::find($id);
$res = $version->delete();
if($res){
return json(['code'=>0,'msg'=>'删除成功']);
} else {
return json(['code'=>-1,'msg'=>'删除失败']);
}
}
}

View File

@ -1 +1,2 @@
Version.php
Plugins.php

View File

@ -1,3 +1,4 @@
/keyauth
/time_line
/version
/plugins

View File

@ -0,0 +1,125 @@
{extend name="public/base" /}
{block name="body"}
<div class="layui-fluid">
<div class="layui-card">
<div class="layui-card-header">插件管理</div>
<div class="layui-card-body">
<div style="padding-bottom: 10px;">
<!--button class="layui-btn layuiadmin-btn-admin" data-type="batchdel">删除</button-->
<button class="layui-btn layuiadmin-btn-admin" data-type="add">添加</button>
</div>
<table id="addons-list" lay-filter="addons-list"></table>
<script type="text/html" id="addons-tool">
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="install"><i class="layui-icon layui-icon-edit"></i>安装</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>卸载</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
</div>
</div>
</div>
{/block}
{block name="js"}
<script>
var addonsIndex = "{:url('Addons/index')}",
addonsDelete = "{:url('Addons/delete')}",
addonsEdit = "{:url('Addons/edit')}";
layui.config({
base: '/static/admin/' //静态资源所在路径
}).extend({
index: 'lib/index' //主入口模块
}).use(['index', 'addons','table','form','upload'], function(){
var $ = layui.jquery
,table = layui.table
,form = layui.form
,upload = layui.upload;
//事件
var active = {
batchdel: function(){
var checkStatus = table.checkStatus('addons-list')
,checkData = checkStatus.data; //得到选中的数据
if(checkData.length === 0){
return layer.msg('请选择数据');
}
layer.prompt({
formType: 1
,title: '敏感操作,请验证口令'
}, function(value, index){
layer.close(index);
layer.confirm('确定删除吗?', function(index) {
//执行 Ajax 后重载
/*
admin.req({
url: 'xxx'
//,……
});
*/
table.reload('addons-list');
layer.msg('已删除');
});
});
}
,add: function(){
layer.open({
type: 2
,title: '添加插件'
,content: 'add.html'
,area: ['400px', '620px']
,btn: ['确定', '取消']
,yes: function(index, layero){
var iframeWindow = window['layui-layer-iframe'+ index]
,submitID = 'LAY-addons-submit'
,submit = layero.find('iframe').contents().find('#'+ submitID);
//监听提交
iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
var field = data.field; //获取提交的字段
//提交 Ajax 成功后,静态更新表格中的数据
$.ajax({
type:"post",
url:"{:url('admin/Addons/add')}",
data:field,
daType:"json",
success:function (data){
if (data.code == 0) {
layer.msg(data.msg,{
icon:6,
time:2000
});
} else {
layer.open({
tiele:'添加失败',
content:data.msg,
icon:5,
anim:6
});
}
}
});
table.reload('addons-list'); //数据刷新
layer.close(index); //关闭弹层
});
submit.trigger('click');
}
});
}
}
$('.layui-btn.layuiadmin-btn-admin').on('click', function(){
var type = $(this).data('type');
active[type] ? active[type].call(this) : '';
});
});
</script>
{/block}

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{block name="title"}TaoLer后台管理模板系统{/block}</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
<link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
{block name="css"}{/block}
</head>
<body {if($Request.url=='/admin/index/index')}class="layui-layout-body"{/if}>
<a>无操作权限!</a>
<script src="/static/layui/jquery.min.js" charset="utf-8"></script>
<script src="/static/layui/layui.js"></script>
<script type="text/javascript" charset="utf-8">
</script>
</body>
</html>

View File

@ -33,7 +33,8 @@ class Auth
$admin_id = Session::get('admin_id'); //登录用户的id
if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) {
return json(['code'=>-1,'msg'=>'没有权限!']);
//return json(['code'=>-1,'msg'=>'没有权限!']);
return view('public/auth');
}
}

View File

@ -20,7 +20,8 @@ class Files
$arr[] = strtolower($value);
}
}
return array_merge(array_diff($arr, array('install')));
//return array_merge(array_diff($arr, array('install')));
return $arr;
}
}

View File

@ -0,0 +1,3 @@
plugins.js
version.js
appset.js

View File

@ -20,7 +20,7 @@ layui.define(['table', 'form','upload'], function(exports){
{field: 'addons_price',title: '价格(元)'},
{field: 'addons_status',title: '状态', width: 100},
{field: 'ctime',title: '时间', width: 150},
{title: '操作', width: 150, align:'center', fixed: 'right', toolbar: '#addons-tool'}
{title: '操作', width: 250, align:'center', fixed: 'right', toolbar: '#addons-tool'}
]]
,page: true
,limit: 10