Browse Source

针对这个项目无法在网站非根目录下运行的问题,我大致上阅读了一遍你的项目代码,然后做出了相应改动,我在本地以及部署到服务器上测试过,均可以正常运行(不过对于部署在子目录的用户,可能需要更改一下项目.htaccess内的配置),你可以阅读一下这些改动,如果有问题的话可以留言,不过我不常上GitHub,如果想快速联系到我,可以给我发邮件(2291200076 at qq.com)感觉你这个项目还是挺实用的,希望能看到这个项目变得越来越好,继续加油!

pull/4/head
茁壮成长 4 years ago
parent
commit
2ef908a892
  1. 4
      controller/admin.php
  2. 4
      controller/login.php
  3. 14
      templates/admin/header.php
  4. 8
      templates/admin/left.php
  5. 32
      templates/admin/static/embed.js
  6. 2
      templates/default/index.php
  7. 8
      templates/default/static/embed.js

4
controller/admin.php

@ -64,7 +64,7 @@ if ($page == 'logout') {
//清除cookie //清除cookie
setcookie("key", $key, -(time()+7 * 24 * 60 * 60),"/"); setcookie("key", $key, -(time()+7 * 24 * 60 * 60),"/");
//跳转到首页 //跳转到首页
header('location:/'); header('location:'.dirname($_SERVER['PHP_SELF']));
exit; exit;
} }
@ -104,7 +104,7 @@ function check_auth($user,$password){
$cookie = $_COOKIE['key']; $cookie = $_COOKIE['key'];
//如果cookie的值和计算的key不一致,则没有权限 //如果cookie的值和计算的key不一致,则没有权限
if( $cookie != $key ){ if( $cookie != $key ){
exit("<h3>认证失败,请<a href = 'index.php?c=login'>重新登录</a></h3>"); exit("<h3>认证失败,请<a href = './index.php?c=login'>重新登录</a></h3>");
} }
} }

4
controller/login.php

@ -12,7 +12,9 @@ $cookie = $_COOKIE['key'];
//如果已经登录,直接跳转 //如果已经登录,直接跳转
if( $cookie == $key ){ if( $cookie == $key ){
header('location:index.php?c=admin'); $phpSelf = dirname($_SERVER['PHP_SELF']);
$phpSelf = ($phpSelf == "/" || $phpSelf == "\\") ? "" : $phpSelf;
header('location:'.$phpSelf.'/index.php?c=admin');
exit; exit;
} }

14
templates/admin/header.php

@ -10,14 +10,14 @@
<body class="layui-layout-body"> <body class="layui-layout-body">
<div class="layui-layout layui-layout-admin"> <div class="layui-layout layui-layout-admin">
<div class="layui-header"> <div class="layui-header">
<div class="layui-logo"><a href="/index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h1></a></div> <div class="layui-logo"><a href="./index.php?c=admin" style="color:#009688;"><h2>OneNav后台管理</h1></a></div>
<!-- 头部区域(可配合layui已有的水平导航) --> <!-- 头部区域(可配合layui已有的水平导航) -->
<ul class="layui-nav layui-layout-left"> <ul class="layui-nav layui-layout-left">
<li class="layui-nav-item"><a href="/"><i class="layui-icon layui-icon-home"></i> 前台首页</a></li> <li class="layui-nav-item"><a href="./"><i class="layui-icon layui-icon-home"></i> 前台首页</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=category_list"><i class="layui-icon layui-icon-list"></i> 分类列表</a></li> <li class="layui-nav-item"><a href="./index.php?c=admin&page=category_list"><i class="layui-icon layui-icon-list"></i> 分类列表</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=add_category"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加分类</a></li> <li class="layui-nav-item"><a href="./index.php?c=admin&page=add_category"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加分类</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=link_list"><i class="layui-icon layui-icon-link"></i> 我的链接</a></li> <li class="layui-nav-item"><a href="./index.php?c=admin&page=link_list"><i class="layui-icon layui-icon-link"></i> 我的链接</a></li>
<li class="layui-nav-item"><a href="/index.php?c=admin&page=add_link"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加链接</a></li> <li class="layui-nav-item"><a href="./index.php?c=admin&page=add_link"><i class="layui-icon layui-icon-add-circle-fine"></i> 添加链接</a></li>
</ul> </ul>
<ul class="layui-nav layui-layout-right"> <ul class="layui-nav layui-layout-right">
@ -27,7 +27,7 @@
<?php echo USER; ?> <?php echo USER; ?>
</a> </a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=logout">退出</a></dd> <dd><a href="./index.php?c=admin&page=logout">退出</a></dd>
</dl> </dl>
</li> </li>
</ul> </ul>

8
templates/admin/left.php

@ -5,8 +5,8 @@
<li class="layui-nav-item layui-nav-itemed"> <li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">分类管理</a> <a class="" href="javascript:;">分类管理</a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=category_list">分类列表</a></dd> <dd><a href="./index.php?c=admin&page=category_list">分类列表</a></dd>
<dd><a href="/index.php?c=admin&page=add_category">添加分类</a></dd> <dd><a href="./index.php?c=admin&page=add_category">添加分类</a></dd>
</dl> </dl>
</li> </li>
@ -15,8 +15,8 @@
<li class="layui-nav-item layui-nav-itemed"> <li class="layui-nav-item layui-nav-itemed">
<a class="" href="javascript:;">链接管理</a> <a class="" href="javascript:;">链接管理</a>
<dl class="layui-nav-child"> <dl class="layui-nav-child">
<dd><a href="/index.php?c=admin&page=link_list">我的链接</a></dd> <dd><a href="./index.php?c=admin&page=link_list">我的链接</a></dd>
<dd><a href="/index.php?c=admin&page=add_link">添加链接</a></dd> <dd><a href="./index.php?c=admin&page=add_link">添加链接</a></dd>
</dl> </dl>
</li> </li>

32
templates/admin/static/embed.js

@ -8,7 +8,7 @@ layui.use(['element','table','layer','form'], function(){
table.render({ table.render({
elem: '#category_list' elem: '#category_list'
,height: 500 ,height: 500
,url: 'index.php?c=api&method=category_list' //数据接口 ,url: './index.php?c=api&method=category_list' //数据接口
,page: true //开启分页 ,page: true //开启分页
,cols: [[ //表头 ,cols: [[ //表头
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'} {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
@ -48,7 +48,7 @@ layui.use(['element','table','layer','form'], function(){
//console.log(obj) //console.log(obj)
if(obj.event === 'del'){ if(obj.event === 'del'){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){ layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
$.post('/index.php?c=api&method=del_category',{'id':obj.data.id},function(data,status){ $.post('./index.php?c=api&method=del_category',{'id':obj.data.id},function(data,status){
if(data.code == 0){ if(data.code == 0){
obj.del(); obj.del();
@ -60,14 +60,14 @@ layui.use(['element','table','layer','form'], function(){
layer.close(index); layer.close(index);
}); });
} else if(obj.event === 'edit'){ } else if(obj.event === 'edit'){
window.location.href = '/index.php?c=admin&page=edit_category&id=' + obj.data.id; window.location.href = './index.php?c=admin&page=edit_category&id=' + obj.data.id;
} }
}); });
//渲染链接列表 //渲染链接列表
table.render({ table.render({
elem: '#link_list' elem: '#link_list'
,height: 520 ,height: 520
,url: 'index.php?c=api&method=link_list' //数据接口 ,url: './index.php?c=api&method=link_list' //数据接口
,page: true //开启分页 ,page: true //开启分页
,toolbar: '#linktool' ,toolbar: '#linktool'
,cols: [[ //表头 ,cols: [[ //表头
@ -123,7 +123,7 @@ layui.use(['element','table','layer','form'], function(){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){ layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
$.post('/index.php?c=api&method=del_link',{'id':data[i].id},function(data,status){ $.post('./index.php?c=api&method=del_link',{'id':data[i].id},function(data,status){
if(data.code == 0){ if(data.code == 0){
console.log(obj); console.log(obj);
obj.del(); obj.del();
@ -160,7 +160,7 @@ layui.use(['element','table','layer','form'], function(){
//console.log(obj) //console.log(obj)
if(obj.event === 'del'){ if(obj.event === 'del'){
layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){ layer.confirm('确认删除?',{icon: 3, title:'温馨提示!'}, function(index){
$.post('/index.php?c=api&method=del_link',{'id':obj.data.id},function(data,status){ $.post('./index.php?c=api&method=del_link',{'id':obj.data.id},function(data,status){
if(data.code == 0){ if(data.code == 0){
obj.del(); obj.del();
} }
@ -171,17 +171,17 @@ layui.use(['element','table','layer','form'], function(){
layer.close(index); layer.close(index);
}); });
} else if(obj.event === 'edit'){ } else if(obj.event === 'edit'){
window.location.href = '/index.php?c=admin&page=edit_link&id=' + obj.data.id; window.location.href = './index.php?c=admin&page=edit_link&id=' + obj.data.id;
} }
}); });
//登录 //登录
//添加链接 //添加链接
form.on('submit(login)', function(data){ form.on('submit(login)', function(data){
$.post('/index.php?c=login&check=login',data.field,function(data,status){ $.post('./index.php?c=login&check=login',data.field,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
window.location.href = '/index.php?c=admin'; window.location.href = './index.php?c=admin';
} }
else{ else{
layer.msg(data.err_msg, {icon: 5}); layer.msg(data.err_msg, {icon: 5});
@ -193,7 +193,7 @@ layui.use(['element','table','layer','form'], function(){
//添加分类目录 //添加分类目录
form.on('submit(add_category)', function(data){ form.on('submit(add_category)', function(data){
$.post('/index.php?c=api&method=add_category',data.field,function(data,status){ $.post('./index.php?c=api&method=add_category',data.field,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
layer.msg('已添加!', {icon: 1}); layer.msg('已添加!', {icon: 1});
@ -207,7 +207,7 @@ layui.use(['element','table','layer','form'], function(){
}); });
//修改分类目录 //修改分类目录
form.on('submit(edit_category)', function(data){ form.on('submit(edit_category)', function(data){
$.post('/index.php?c=api&method=edit_category',data.field,function(data,status){ $.post('./index.php?c=api&method=edit_category',data.field,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
layer.msg('已修改!', {icon: 1}); layer.msg('已修改!', {icon: 1});
@ -222,7 +222,7 @@ layui.use(['element','table','layer','form'], function(){
//添加链接 //添加链接
form.on('submit(add_link)', function(data){ form.on('submit(add_link)', function(data){
$.post('/index.php?c=api&method=add_link',data.field,function(data,status){ $.post('./index.php?c=api&method=add_link',data.field,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
layer.msg('已添加!', {icon: 1}); layer.msg('已添加!', {icon: 1});
@ -236,7 +236,7 @@ layui.use(['element','table','layer','form'], function(){
}); });
//识别链接信息 //识别链接信息
form.on('submit(get_link_info)', function(data){ form.on('submit(get_link_info)', function(data){
$.post('/index.php?c=api&method=get_link_info',data.field.url,function(data,status){ $.post('./index.php?c=api&method=get_link_info',data.field.url,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
console.log(data); console.log(data);
@ -250,7 +250,7 @@ layui.use(['element','table','layer','form'], function(){
}); });
//更新链接 //更新链接
form.on('submit(edit_link)', function(data){ form.on('submit(edit_link)', function(data){
$.post('/index.php?c=api&method=edit_link',data.field,function(data,status){ $.post('./index.php?c=api&method=edit_link',data.field,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
layer.msg('已更新!', {icon: 1}); layer.msg('已更新!', {icon: 1});
@ -265,7 +265,7 @@ layui.use(['element','table','layer','form'], function(){
//识别链接信息 //识别链接信息
form.on('submit(get_link_info)', function(data){ form.on('submit(get_link_info)', function(data){
//是用ajax异步加载 //是用ajax异步加载
$.post('/index.php?c=api&method=get_link_info',data.field.url,function(data,status){ $.post('./index.php?c=api&method=get_link_info',data.field.url,function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
console.log(data); console.log(data);
@ -284,7 +284,7 @@ layui.use(['element','table','layer','form'], function(){
function get_link_info() { function get_link_info() {
var url = $("#url").val(); var url = $("#url").val();
var index = layer.load(1); var index = layer.load(1);
$.post('/index.php?c=api&method=get_link_info',{url:url},function(data,status){ $.post('./index.php?c=api&method=get_link_info',{url:url},function(data,status){
//如果添加成功 //如果添加成功
if(data.code == 0) { if(data.code == 0) {
if(data.data.title != null) { if(data.data.title != null) {

2
templates/default/index.php

@ -43,7 +43,7 @@
c0.9,2.2,0.3,3.9,0.2,4.3c1,1.1,1.7,2.6,1.7,4.4c0,6.3-3.8,7.6-7.4,8c0.6,0.5,1.1,1.5,1.1,3c0,2.2,0,3.9,0,4.5 c0.9,2.2,0.3,3.9,0.2,4.3c1,1.1,1.7,2.6,1.7,4.4c0,6.3-3.8,7.6-7.4,8c0.6,0.5,1.1,1.5,1.1,3c0,2.2,0,3.9,0,4.5
c0,0.4,0.3,0.9,1.1,0.8c6.5-2.2,11.1-8.3,11.1-15.5C34.3,8.7,27,1.4,18,1.4z"></path> c0,0.4,0.3,0.9,1.1,0.8c6.5-2.2,11.1-8.3,11.1-15.5C34.3,8.7,27,1.4,18,1.4z"></path>
</svg> </svg>
<a href="/index.php?c=login" title = "登录OneNav" target="_blank" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">account_circle</i></a> <a href="./index.php?c=login" title = "登录OneNav" target="_blank" class="mdui-btn mdui-btn-icon"><i class="mdui-icon material-icons">account_circle</i></a>
</a> </a>
</div> </div>
</header> </header>

8
templates/default/static/embed.js

@ -79,20 +79,20 @@ function admin_menu() {
var link_id = $(this).attr('id'); var link_id = $(this).attr('id');
link_id = link_id.replace('id_',''); link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank'); var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=click&id='+link_id; tempwindow.location='./index.php?c=click&id='+link_id;
}}, }},
"edit": {name: "编辑", icon: "edit",callback:function(key,opt){ "edit": {name: "编辑", icon: "edit",callback:function(key,opt){
var link_id = $(this).attr('id'); var link_id = $(this).attr('id');
link_id = link_id.replace('id_',''); link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank'); var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=admin&page=edit_link&id='+link_id; tempwindow.location='./index.php?c=admin&page=edit_link&id='+link_id;
}}, }},
"delete": {name: "删除", icon: "delete",callback:function(){ "delete": {name: "删除", icon: "delete",callback:function(){
var link_id = $(this).attr('id'); var link_id = $(this).attr('id');
link_id = link_id.replace('id_',''); link_id = link_id.replace('id_','');
mdui.confirm('确认删除?', mdui.confirm('确认删除?',
function(){ function(){
$.post("index.php?c=api&method=del_link",{id:link_id},function(data,status){ $.post("./index.php?c=api&method=del_link",{id:link_id},function(data,status){
//如果删除成功,则移除元素 //如果删除成功,则移除元素
if(data.code == 0) { if(data.code == 0) {
$("#id_" + link_id).remove(); $("#id_" + link_id).remove();
@ -166,7 +166,7 @@ $.contextMenu({
var link_id = $(this).attr('id'); var link_id = $(this).attr('id');
link_id = link_id.replace('id_',''); link_id = link_id.replace('id_','');
var tempwindow=window.open('_blank'); var tempwindow=window.open('_blank');
tempwindow.location='index.php?c=click&id='+link_id; tempwindow.location='./index.php?c=click&id='+link_id;
}}, }},
"sep1": "---------", "sep1": "---------",
"qrcode": {name: "二维码", icon:"fa-qrcode",callback:function(data,status){ "qrcode": {name: "二维码", icon:"fa-qrcode",callback:function(data,status){

Loading…
Cancel
Save