huwhois 10 months ago
parent
commit
da9f8c6ebe

+ 13 - 0
app/common/model/SysMenu.php

@@ -78,4 +78,17 @@ class SysMenu extends Model
             'breadCrumb' => $breadCrumb
         ];
     }
+
+    /**
+     * 后台首页快捷方式
+     */
+    public static function getIndexButton()
+    {
+        return self::where('index_button', 1)->where('type', 1)->select();
+    }
+    
+    public static function getMenuList()
+    {
+        return self::where('type', 1)->select();
+    }
 }

+ 1 - 1
app/common/model/SysUser.php

@@ -64,7 +64,7 @@ class SysUser extends Base
 
         if (!$info) {
             SysLoginFail::saveFail($ip, $time);
-            return json(['code' => 2, 'msg' => '用户名/密码不正确']);
+            return json(['code' => 2, 'msg' => '用户名/密码不正确1']);
         }
 
         if (md5($password . $info->salt) != $info->password) {

+ 117 - 0
app/common/utils/ReUtils.php

@@ -0,0 +1,117 @@
+<?php
+
+declare(strict_types=1);
+
+namespace app\common\utils;
+
+use think\Response;
+use think\response\File;
+
+/**
+ * 返回操作 utils
+ *
+ * @version      0.0.1
+ * @author      by huwhois
+ * @time        20228/10
+ */
+class ReUtils
+{
+    /**
+     * 操作成功的返回
+     * @access protected
+     * @param  mixed $msg 提示信息
+     * @param  mixed $data 返回的数据
+     * @param  array $header 发送的Header信息
+     * @return void
+     */
+    public static function success($msg = 'success', array $header = [])
+    {
+        $result = [
+            'code' => 0,
+            'msg' => $msg,
+        ];
+
+        return Response::create($result, 'json')->header($header);
+    }
+
+    /**
+     * 操作成功的返回
+     * @access protected
+     * @param  mixed $msg 提示信息
+     * @param  array $header 发送的Header信息
+     * @return void
+     */
+    public static function error($msg = 'fail', $code = 1, string $type = '', array $header = [])
+    {
+        $result = [
+            'code' => $code,
+            'msg' => $msg,
+        ];
+
+        $type     = $type ?: 'json';
+
+        return Response::create($result, $type)->header($header);
+    }
+
+    /**
+     * 返回封装后的API数据到客户端
+     * @param mixed   $data   要返回的数据
+     * @param integer $code   返回的code
+     * @param mixed   $msg    提示信息
+     * @param string  $type   返回数据格式
+     * @param array   $header 发送的Header信息
+     * @return Response
+     */
+    public static function result($data, int $code = 0, $msg = '', string $type = '', array $header = []): Response
+    {
+        $result = [
+            'code' => $code,
+            'msg'  => $msg,
+            'data' => $data,
+        ];
+
+        $type     = $type ?: 'json';
+
+        return Response::create($result, $type)->header($header);
+    }
+
+    /**
+     * 获取\think\response\Download对象实例
+     * @param string $filename 要下载的文件
+     * @param string $name 下载文件显示名
+     * @return \think\response\File
+     */
+    public static function sendTempZip(string $filename, string $name = "")
+    {
+        $fp = fopen($filename, "r");
+
+        $file_size = filesize($filename); //获取文件的字节
+
+        $name = $name ?: basename($filename);
+
+        // halt($file_size);
+        //下载文件需要用到的头 
+        Header("Content-type: application/zip");
+        Header("Accept-Ranges: bytes");
+        Header("Accept-Length:" . $file_size);
+        Header("Content-Disposition: attachment; filename=$name");
+        $buffer = 1024 * 4; //设置一次读取的字节数,每读一取次,就输出数据(即返回给浏览器) 
+        $file_count = 0; //读取的总字节数 
+        //向浏览器返回数据 如果下载完成就停止输出,如果未下载完成就一直在输出。根据文件的字节大小判断是否下载完成
+        while (!feof($fp) && $file_count < $file_size) {
+
+            $file_con = fread($fp, $buffer);
+
+            $file_count += $buffer;
+
+            echo $file_con;
+        }
+
+        fclose($fp);
+
+        // 下载完成后删除压缩包,临时文件夹 
+        if ($file_count >= $file_size) {
+            unlink($filename);
+        }
+    }
+}

+ 36 - 0
app/sys/controller/Index.php

@@ -4,10 +4,14 @@ declare(strict_types=1);
 
 namespace app\sys\controller;
 
+use think\Exception;
 use think\facade\App;
 use think\facade\Db;
 use think\facade\Config;
 use think\facade\View;
+use app\common\model\SysMenu as SysMenuModel;
+use app\common\utils\ReUtils;
+
 
 class Index  extends Base
 {
@@ -28,11 +32,18 @@ class Index  extends Base
             'tp_version'         => App::version(),
         ];
 
+        // 快捷方式
+        $indexButton =  \app\common\model\SysMenu::getIndexButton();
+
+        $menuList = \app\common\model\SysMenu::getMenuList();
+
         View::assign([
             'config'        => $config,
             // 'user'          => $user,
             // 'message'       => $message ?? 0,
             // 'messageCatUrl' => $messageCatUrl,
+            'indexButton'   => $indexButton,
+            'menuList'      => $menuList,
             'indexTips'     => $this->getIndexTips(),
         ]);
         return View::fetch('index');
@@ -104,4 +115,29 @@ class Index  extends Base
     //         }
     //     }
     // }
+
+    public function saveIndexButton()
+    {
+        $param = $this->request->param();
+
+        $menuids = isset($param['checkbox']) ? $param['checkbox'] : [];
+
+        $ids = implode(',', $menuids);
+
+        $tablename = SysMenuModel::getTable();
+
+        $notinsql = "update " . $tablename . " set index_button=0 where id NOT IN (" . $ids . ");";
+
+        $insql = "update " . $tablename . " set index_button=1 where id IN (" . $ids . ");";
+
+        try {
+            Db::execute($notinsql);
+
+            Db::execute($insql);
+        } catch (Exception $e) {
+            return ReUtils::error();
+        }
+
+        return ReUtils::success();
+    }
 }

+ 1 - 1
app/sys/controller/SysUser.php

@@ -95,7 +95,7 @@ class SysUser extends Base
     public function isAvailable($id = null, $username = '')
     {
         if ($this->app->request->isAjax()) {
-            $data = $this->model->where('username', $username)->find();
+            $data = SysUserModel::where('username', $username)->find();
             if ($data && $data->id != $id) {
                 return ['code' => 2, 'msg'=>'用户名已存在, 请使用其他用户名'];
             } else {

+ 2 - 0
temp/.gitignore

@@ -0,0 +1,2 @@
+*
+!.gitignore

+ 0 - 58
temp/e963854841abf5dcb5dfdff21571a0fd.php

@@ -1,58 +0,0 @@
-<?php /*a:1:{s:37:"/web/www/blog_tp6/view/index/404.html";i:1660637901;}*/ ?>
-
-<!DOCTYPE html>
-<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
-
-<head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-  <meta name="viewport" content="width=device-width">
-  <meta name='robots' content='noindex,follow' />
-  <title>huwhois的博客</title>
-  <link rel="stylesheet" type="text/css" href="/static/lib/Hui-iconfont/1.0.8/iconfont.css" />
-  <style>
-    .page-404 {
-      color: #afb5bf;
-      padding-top: 60px;
-      padding-bottom: 90px;
-      text-align: center;
-    }
-
-    .page-404 .error-title {
-      font-size: 80px
-    }
-
-    .page-404 .error-title .iconfont {
-      font-size: 80px
-    }
-
-    .page-404 .error-description {
-      font-size: 24px
-    }
-
-    .page-404 .error-info {
-      font-size: 14px
-    }
-    
-    a {
-      text-decoration: none;
-      color: #5A98E0;
-    }
-
-    .ml-20 {
-      margin-left: 20px;
-    }
-  </style>
-</head>
-
-<body id="error-page">
-  <div class="page-404 text-c" style="margin-top:80px;">
-    <p class="error-title"><i class="Hui-iconfont va-m" style="font-size:80px">&#xe656;</i><span class="va-m">
-        404</span></p>
-    <p class="error-description"><?php echo (htmlentities($e->getMessage())) ? htmlentities($e->getMessage()) :  '不好意思,您访问的页面不存在~'; ?></p>
-    <p class="error-info">
-      您可以:<a href="javascript:;" onclick="history.go(-1)" class="c-primary">&lt; 返回上一页</a>
-      <span class="ml-20">|</span><a href="/" class="c-primary ml-20">去首页 &gt;</a></p>
-  </div>
-</body>
-
-</html>

+ 97 - 12
view/sys/index/index.html

@@ -15,21 +15,19 @@
                         </div>
                         <!-- /.card-header -->
                         <div class="card-body">
-                            <a class="btn btn-app" href="{:url('system/edit',['id'=>1])}">
+                            <!-- <a class="btn btn-app" href="{:url('system/edit',['id'=>1])}">
                                 <div><i class="Hui-iconfont">&#xe62e;</i></div>
                                 <span>系统设置</span>
+                            </a> -->
+                            {foreach $indexButton as $button}
+                            <a class="btn btn-app" href="/sys/{$button.url}">
+                                <div><i class="Hui-iconfont">{$button.icon|raw}</i></div>
+                                <span>{$button.name}</span>
                             </a>
-                            <a class="btn btn-app" href="{:url('advertise/index')}">
-                                <div><i class="Hui-iconfont">&#xe613;</i></div>
-                                <span>轮播图管理</span>
-                            </a>
-                            <a class="btn btn-app" href="{:url('article/index')}">
-                                <div><i class="Hui-iconfont">&#xe616;</i></div>
-                                <span>管理文章</span>
-                            </a>
-                            <a class="btn btn-app" href="{:url('category/index')}">
-                                <div><i class="Hui-iconfont">&#xe681;</i></div>
-                                <span>管理栏目</span>
+                            {/foreach}
+                            <a class="btn btn-app" onclick="addButton();">
+                                <div><i class="Hui-iconfont">&#xe600;</i></div>
+                                <span>管理快捷方式</span>
                             </a>
                         </div>
                         <div class="card-body">
@@ -199,6 +197,61 @@
         </div>
     </div>
 </article>
+<style>
+    #dialog {
+        position: fixed;
+        height: 360px;
+        width: 600px;
+        background: #FFFFFF;
+        z-index: 5;
+        left: 30%;
+        border: 1px solid gray;
+        top: 25%;
+        display: none;
+    }
+
+    #cancel {
+        border: 0px none #FFECEC;
+        background: #999999;
+        color: #FFFFFF;
+        padding: 5px 15px;
+        position: absolute;
+        top: 8px;
+        right: 100px;
+    }
+
+    #cancel:hover {
+        background: #AAAAAA;
+    }
+</style>
+<div id="dialog">
+    <div style="position: absolute;height: 40px;width: 100%;background: #FFFFFF;border-bottom: 1px solid gray;">
+        <span style="position: absolute;left: 10px;top: 10px;color: gray;" class="dialog-tilte">选择快捷方式</span>
+        <img src="/static/images/X.png"
+            style="height: 25px;width: 25px;position: absolute;right: 10px;top: 10px;cursor: pointer;"
+            onclick="f_cancel()" />
+    </div>
+    <div class="tab" style="margin-left:30px;margin-top:40px;">
+        <form id="form-save" method="post" action="">
+            <div class="row cl mt-20">
+                <div class="skin-minimal">
+                    {foreach $menuList as $value}
+                    <div class="check-box" style="width: 200px;">
+                        <input type="checkbox" id="checkbox-1" name="checkbox[]" value="{$value.id}" {if
+                            $value.index_button==1}checked{/if}>
+                        <label for="checkbox-1">{$value.name}</label>
+                    </div>
+                    {/foreach}
+                </div>
+            </div>
+            <div class="row cl" style="margin-top:10px;">
+                <div class="formControls col-sm-6 col-xs-8 col-sm-offset-4 col-xs-offset-4">
+                    <button type="button" class="btn btn-success radius" onclick="saveIndexButton()">保存</button>
+                </div>
+            </div>
+        </form>
+    </div>
+</div>
 
 <!--请在下方写此页面业务相关的脚本-->
 <script type="text/javascript">
@@ -253,5 +306,37 @@
         });
     }
 
+    /**
+     * 新增快捷方式
+     */
+     function addButton() {
+        $('#dialog').show();
+    }
+    function f_cancel() {
+        $('#dialog').hide();
+    }
+    function saveIndexButton() {
+        var data = $("#form-save").serializeArray();
+        $.ajax({
+            type: 'POST',
+            url: '{:url("/sys/index/saveIndexButton")}',
+            data: data,
+            dataType: 'json',
+            success: function (res) {
+                // console.log(res);
+                if (res.code == 0) {
+                    layer.msg(res.msg, { icon: 1, time: 500 }, function () {
+                        window.location.reload();
+                    });
+                } else {
+                    layer.msg(res.msg, {
+                        icon: 5,
+                        time: 1000
+                    });
+                    return false;
+                }
+            }
+        })
+    }
 </script>
 <!--请在上方写此页面业务相关的脚本-->