mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-07-07 08:41:12 +08:00
Compare commits
5 Commits
f4bda9cf4b
...
12c50de24b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12c50de24b | ||
|
|
f9d48e1495 | ||
|
|
b04ca63a87 | ||
|
|
3da4409270 | ||
|
|
5d5305a454 |
@ -94,10 +94,9 @@ class Auth extends Controller
|
||||
{
|
||||
$map = $this->_vali(['auth.require#id' => '权限ID不能为空!']);
|
||||
if (input('action') === 'get') {
|
||||
$admin = AdminService::instance();
|
||||
if ($this->app->isDebug()) $admin->clearCache();
|
||||
if ($this->app->isDebug()) AdminService::clearCache();
|
||||
$nodes = SystemNode::mk()->where($map)->column('node');
|
||||
$this->success('获取权限节点成功!', $admin->getTree($nodes));
|
||||
$this->success('获取权限节点成功!', AdminService::getTree($nodes));
|
||||
} elseif (input('action') === 'save') {
|
||||
[$post, $data] = [$this->request->post(), []];
|
||||
foreach ($post['nodes'] ?? [] as $node) {
|
||||
|
||||
@ -52,7 +52,7 @@ class Config extends Controller
|
||||
public function index()
|
||||
{
|
||||
$this->title = '系统参数配置';
|
||||
$this->super = AdminService::instance()->isSuper();
|
||||
$this->super = AdminService::isSuper();
|
||||
$this->version = ModuleService::instance()->getVersion();
|
||||
$this->fetch();
|
||||
}
|
||||
@ -81,11 +81,11 @@ class Config extends Controller
|
||||
if ($post['xpath'] !== 'admin' && file_exists($this->app->getBasePath() . $post['xpath'])) {
|
||||
$this->error("后台入口名称{$post['xpath']}已经存在应用!");
|
||||
}
|
||||
SystemService::instance()->setRuntime(null, [$post['xpath'] => 'admin']);
|
||||
SystemService::setRuntime(null, [$post['xpath'] => 'admin']);
|
||||
}
|
||||
// 修改网站 ICON 图标文件,替换 public/favicon.ico 文件
|
||||
if (preg_match('#^https?://#', $icon = $post['site_icon'] ?? '')) try {
|
||||
SystemService::instance()->setFavicon($icon);
|
||||
SystemService::setFavicon($icon);
|
||||
} catch (\Exception $exception) {
|
||||
trace_file($exception);
|
||||
$this->error($exception->getMessage());
|
||||
|
||||
@ -38,19 +38,18 @@ class Index extends Controller
|
||||
public function index()
|
||||
{
|
||||
/*! 根据运行模式刷新权限 */
|
||||
$debug = $this->app->isDebug();
|
||||
AdminService::instance()->apply($debug);
|
||||
AdminService::apply($this->app->isDebug());
|
||||
/*! 读取当前用户权限菜单树 */
|
||||
$this->menus = MenuService::instance()->getTree();
|
||||
$this->menus = MenuService::getTree();
|
||||
/*! 判断当前用户的登录状态 */
|
||||
$this->login = AdminService::instance()->isLogin();
|
||||
$this->login = AdminService::isLogin();
|
||||
/*! 菜单为空且未登录跳转到登录页 */
|
||||
if (empty($this->menus) && empty($this->login)) {
|
||||
$this->redirect(sysuri('admin/login/index'));
|
||||
} else {
|
||||
$this->title = '系统管理后台';
|
||||
$this->super = AdminService::instance()->isSuper();
|
||||
$this->theme = AdminService::instance()->getUserTheme();
|
||||
$this->super = AdminService::isSuper();
|
||||
$this->theme = AdminService::getUserTheme();
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
@ -66,12 +65,12 @@ class Index extends Controller
|
||||
public function theme()
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
$this->theme = AdminService::instance()->getUserTheme();
|
||||
$this->theme = AdminService::getUserTheme();
|
||||
$this->themes = Config::themes;
|
||||
$this->fetch();
|
||||
} else {
|
||||
$data = $this->_vali(['site_theme.require' => '主题名称不能为空!']);
|
||||
if (AdminService::instance()->setUserTheme($data['site_theme'])) {
|
||||
if (AdminService::setUserTheme($data['site_theme'])) {
|
||||
$this->success('主题配置保存成功!');
|
||||
} else {
|
||||
$this->error('主题配置保存失败!');
|
||||
@ -87,7 +86,7 @@ class Index extends Controller
|
||||
public function info($id = 0)
|
||||
{
|
||||
$this->_applyFormToken();
|
||||
if (AdminService::instance()->getUserId() === intval($id)) {
|
||||
if (AdminService::getUserId() === intval($id)) {
|
||||
SystemUser::mForm('admin@user/form', 'id', [], ['id' => $id]);
|
||||
} else {
|
||||
$this->error('只能修改自己的资料!');
|
||||
@ -116,7 +115,7 @@ class Index extends Controller
|
||||
public function pass($id = 0)
|
||||
{
|
||||
$this->_applyFormToken();
|
||||
if (AdminService::instance()->getUserId() !== intval($id)) {
|
||||
if (AdminService::getUserId() !== intval($id)) {
|
||||
$this->error('只能修改当前用户的密码!');
|
||||
}
|
||||
if ($this->app->request->isGet()) {
|
||||
|
||||
@ -40,15 +40,14 @@ class Login extends Controller
|
||||
public function index()
|
||||
{
|
||||
if ($this->app->request->isGet()) {
|
||||
if (AdminService::instance()->isLogin()) {
|
||||
if (AdminService::isLogin()) {
|
||||
$this->redirect(sysuri('admin/index/index'));
|
||||
} else {
|
||||
// 当前运行模式
|
||||
$system = SystemService::instance();
|
||||
$this->developMode = $system->checkRunMode();
|
||||
$this->developMode = SystemService::checkRunMode();
|
||||
// 后台背景处理
|
||||
$images = str2arr(sysconf('login_image') ?: '', '|') ?: [
|
||||
$system->uri('/static/theme/img/login/bg1.jpg'), $system->uri('/static/theme/img/login/bg2.jpg'),
|
||||
SystemService::uri('/static/theme/img/login/bg1.jpg'), SystemService::uri('/static/theme/img/login/bg2.jpg'),
|
||||
];
|
||||
$this->loginStyle = sprintf('style="background-image:url(%s)" data-bg-transition="%s"', $images[0], join(',', $images));
|
||||
// 登录验证令牌
|
||||
|
||||
@ -101,18 +101,18 @@ class Menu extends Controller
|
||||
if ($this->request->isGet()) {
|
||||
/* 清理权限节点 */
|
||||
if ($isDebug = $this->app->isDebug()) {
|
||||
AdminService::instance()->clearCache();
|
||||
AdminService::clearCache();
|
||||
}
|
||||
/* 选择自己上级菜单 */
|
||||
$vo['pid'] = $vo['pid'] ?? input('pid', '0');
|
||||
/* 读取系统功能节点 */
|
||||
$this->auths = [];
|
||||
$this->nodes = MenuService::instance()->getList($isDebug);
|
||||
foreach (NodeService::instance()->getMethods($isDebug) as $node => $item) {
|
||||
$this->nodes = MenuService::getList($isDebug);
|
||||
foreach (NodeService::getMethods($isDebug) as $node => $item) {
|
||||
if ($item['isauth'] && substr_count($node, '/') >= 2) {
|
||||
$this->auths[] = ['node' => $node, 'title' => $item['title']];
|
||||
}
|
||||
}
|
||||
/* 选择自己上级菜单 */
|
||||
$vo['pid'] = $vo['pid'] ?? input('pid', '0');
|
||||
/* 列出可选上级菜单 */
|
||||
$menus = SystemMenu::mk()->order('sort desc,id asc')->column('id,pid,icon,url,node,title,params', 'id');
|
||||
$this->menus = DataExtend::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'url' => '#', 'title' => '顶部菜单']]));
|
||||
|
||||
@ -143,7 +143,7 @@ class User extends Controller
|
||||
// 用户身份数据
|
||||
$this->bases = SystemBase::items('身份权限');
|
||||
// 用户权限管理
|
||||
$this->superName = AdminService::instance()->getSuperName();
|
||||
$this->superName = AdminService::getSuperName();
|
||||
$this->authorizes = SystemAuth::items();
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ class Plugs extends Controller
|
||||
*/
|
||||
public function optimize()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) {
|
||||
if (AdminService::isSuper()) {
|
||||
sysoplog('系统运维管理', '创建数据库优化任务');
|
||||
$this->_queue('优化数据库所有数据表', 'xadmin:database optimize');
|
||||
} else {
|
||||
|
||||
@ -96,7 +96,7 @@ class Queue extends Controller
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) try {
|
||||
if (AdminService::isSuper()) try {
|
||||
$message = $this->app->console->call('xadmin:queue', ['status'])->fetch();
|
||||
if (preg_match('/process.*?\d+.*?running/', $message)) {
|
||||
echo "<span class='color-green pointer' data-tips-text='{$message}'>已启动</span>";
|
||||
|
||||
@ -36,9 +36,9 @@ class Runtime extends Controller
|
||||
*/
|
||||
public function push()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) try {
|
||||
AdminService::instance()->clearCache();
|
||||
SystemService::instance()->pushRuntime();
|
||||
if (AdminService::isSuper()) try {
|
||||
AdminService::clearCache();
|
||||
SystemService::pushRuntime();
|
||||
sysoplog('系统运维管理', '刷新创建路由缓存');
|
||||
$this->success('网站缓存加速成功!', 'javascript:location.reload()');
|
||||
} catch (HttpResponseException $exception) {
|
||||
@ -56,9 +56,9 @@ class Runtime extends Controller
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) try {
|
||||
AdminService::instance()->clearCache();
|
||||
SystemService::instance()->clearRuntime();
|
||||
if (AdminService::isSuper()) try {
|
||||
AdminService::clearCache();
|
||||
SystemService::clearRuntime();
|
||||
sysoplog('系统运维管理', '清理网站日志缓存');
|
||||
$this->success('清空日志缓存成功!', 'javascript:location.reload()');
|
||||
} catch (HttpResponseException $exception) {
|
||||
@ -76,12 +76,12 @@ class Runtime extends Controller
|
||||
*/
|
||||
public function debug()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) if (input('state')) {
|
||||
SystemService::instance()->setRuntime('product');
|
||||
if (AdminService::isSuper()) if (input('state')) {
|
||||
SystemService::setRuntime('product');
|
||||
sysoplog('系统运维管理', '开发模式切换为生产模式');
|
||||
$this->success('已切换为生产模式!', 'javascript:location.reload()');
|
||||
} else {
|
||||
SystemService::instance()->setRuntime('debug');
|
||||
SystemService::setRuntime('debug');
|
||||
sysoplog('系统运维管理', '生产模式切换为开发模式');
|
||||
$this->success('已切换为开发模式!', 'javascript:location.reload()');
|
||||
} else {
|
||||
@ -98,7 +98,7 @@ class Runtime extends Controller
|
||||
*/
|
||||
public function editor()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) {
|
||||
if (AdminService::isSuper()) {
|
||||
$editor = input('editor', 'auto');
|
||||
sysconf('base.editor', $editor);
|
||||
sysoplog('系统运维管理', "切换编辑器为{$editor}");
|
||||
@ -114,7 +114,7 @@ class Runtime extends Controller
|
||||
*/
|
||||
public function config()
|
||||
{
|
||||
if (AdminService::instance()->isSuper()) try {
|
||||
if (AdminService::isSuper()) try {
|
||||
[$tmpdata, $newdata] = [[], []];
|
||||
foreach (SystemConfig::mk()->order('type,name asc')->cursor() as $item) {
|
||||
$tmpdata[$item['type']][$item['name']] = $item['value'];
|
||||
|
||||
@ -33,7 +33,7 @@ class Update extends Controller
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
if (!SystemService::instance()->checkRunMode()) {
|
||||
if (!SystemService::checkRunMode()) {
|
||||
$this->error('只允许访问本地或官方代码!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ class Upload extends Controller
|
||||
$file = SystemFile::mk()->data($this->_vali([
|
||||
'xkey.value' => $data['key'],
|
||||
'type.value' => $this->getType(),
|
||||
'uuid.value' => AdminService::instance()->getUserId(),
|
||||
'uuid.value' => AdminService::getUserId(),
|
||||
'name.require' => '名称不能为空!',
|
||||
'hash.require' => '哈希不能为空!',
|
||||
'xext.require' => '后缀不能为空!',
|
||||
@ -129,7 +129,7 @@ class Upload extends Controller
|
||||
'id.require' => '编号不能为空!',
|
||||
'hash.require' => '哈希不能为空!',
|
||||
]);
|
||||
$data['uuid'] = AdminService::instance()->getUserId();
|
||||
$data['uuid'] = AdminService::getUserId();
|
||||
$file = SystemFile::mk()->where($data)->findOrEmpty();
|
||||
if ($file->isEmpty()) $this->error('文件不存在!');
|
||||
if ($file->save(['status' => 2])) {
|
||||
@ -147,14 +147,14 @@ class Upload extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function modal()
|
||||
public function image()
|
||||
{
|
||||
SystemFile::mQuery()->layTable(function () {
|
||||
$this->title = '文件选择器';
|
||||
}, function (QueryHelper $query) {
|
||||
$query->where(['status' => 2])->order('id desc');
|
||||
$query->like('name,hash')->dateBetween('create_at');
|
||||
});
|
||||
}, realpath(__DIR__ . '/../../view/api/image.html'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -19,14 +19,14 @@ use think\App;
|
||||
|
||||
invoke(function (App $app) {
|
||||
/*! 非开发环境,清理限制文件 */
|
||||
if ($app->request->isGet() && !SystemService::instance()->checkRunMode()) {
|
||||
if ($app->request->isGet() && !SystemService::checkRunMode()) {
|
||||
@unlink("{$app->getBasePath()}admin/controller/api/Update.php");
|
||||
@unlink("{$app->getBasePath()}admin/route/demo.php");
|
||||
@rmdir("{$app->getBasePath()}admin/route");
|
||||
return;
|
||||
}
|
||||
/*! 演示环境禁止操作路由绑定 */
|
||||
if (SystemService::instance()->checkRunMode('demo')) {
|
||||
if (SystemService::checkRunMode('demo')) {
|
||||
$app->route->post('index/pass', function () {
|
||||
return json(['code' => 0, 'info' => '演示环境禁止修改用户密码!']);
|
||||
});
|
||||
@ -58,5 +58,4 @@ invoke(function (App $app) {
|
||||
return json(['code' => 0, 'info' => '演示环境禁止修改用户密码!']);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
65
app/admin/view/api/image.html
Normal file
65
app/admin/view/api/image.html
Normal file
@ -0,0 +1,65 @@
|
||||
<div class="image-dialog" id="ImageDialog">
|
||||
<div class="image-dialog-head">
|
||||
<div class="pull-right">
|
||||
<a data-file="one" data-type="jpg,png" class="layui-btn layui-btn-sm">上传图片</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="image-dialog-body upload-image-mdbox flex flex-wrap flex-align-start">
|
||||
<div class="image-dialog-item" v-for="x in items">
|
||||
<div class="uploadimage" :style="x.style"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.image-dialog-head {
|
||||
clear: both;
|
||||
height: 30px;
|
||||
padding: 10px 15px;
|
||||
}
|
||||
|
||||
.image-dialog-body {
|
||||
height: 500px;
|
||||
background: #efefef;
|
||||
padding-top: 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.image-dialog-item {
|
||||
margin-right: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.image-dialog-item .uploadimage {
|
||||
margin: 0
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
require(['vue'], function (vue) {
|
||||
new vue({
|
||||
el: '#ImageDialog',
|
||||
data: {
|
||||
page: 1,
|
||||
items: []
|
||||
},
|
||||
created: function () {
|
||||
this.loadPage();
|
||||
},
|
||||
methods: {
|
||||
loadPage: function () {
|
||||
var that = this;
|
||||
this.params = {page: this.page, output: 'layui.table'};
|
||||
$.form.load('{:url("image")}', this.params, 'get', function (ret) {
|
||||
that.items = that.items.concat(ret.data);
|
||||
that.items.forEach(function (item) {
|
||||
item.style = 'background-image:url(' + item.xurl + ')';
|
||||
});
|
||||
console.log(that.items)
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@ -550,7 +550,7 @@ $(function () {
|
||||
$.fn.uploadOneImage = function () {
|
||||
return this.each(function () {
|
||||
if ($(this).data('inited')) return true; else $(this).data('inited', true);
|
||||
var $in = $(this), $bt = $('<a data-file class="uploadimage transition"><span class="layui-icon">ဆ</span><span class="layui-icon"></span></a>').data('input', this);
|
||||
var $in = $(this), $bt = $('<a data-file="image" class="uploadimage transition"><span class="layui-icon">ဆ</span><span class="layui-icon"></span></a>').data('input', this);
|
||||
$bt.attr('data-size', $in.data('size') || 0).attr('data-type', $in.data('type') || 'png,jpg,gif,jpeg').find('span').on('click', function (event) {
|
||||
event.stopPropagation();
|
||||
if ($(this).index() === 0) $bt.attr('style', ''), $in.val(''); else $in.val() && $.previewImage(encodeURI($in.val()));
|
||||
@ -835,7 +835,10 @@ $(function () {
|
||||
|
||||
/*! 注册 data-file 事件行为 */
|
||||
onEvent('click', '[data-file]', function () {
|
||||
if ($(this).data('inited') !== true) (function (that) {
|
||||
// 上传图片,支持单图或多图选择,分别是 images|images
|
||||
if (typeof this.dataset.file === 'string' && /^images?$/.test(this.dataset.file)) {
|
||||
$.form.modal(tapiRoot + '/api.upload/image', this.dataset, '图片管理器')
|
||||
} else if ($(this).data('inited') !== true) (function (that) {
|
||||
that.uploadFile(undefined, function () {
|
||||
that.trigger('upload.start');
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user