This commit is contained in:
taoser 2020-11-01 18:13:05 +08:00
parent a648b85411
commit c0f7fe512f
17 changed files with 277 additions and 58 deletions

View File

@ -71,7 +71,7 @@
//搜索角色
form.on('select(LAY-user-adminrole-type)', function(data){
console.log(data);
$.ajax({
type:"post",
url:"{:url('admin/AuthGroup/list')}",

57
app/common/lib/Msg.php Normal file
View File

@ -0,0 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | 状态提示
// +----------------------------------------------------------------------
namespace app\common\lib;
use think\facade\Lang;
class Msg
{
public static function getCode($strCode){
//状态配置
$res = [
'success' => 1,
'error' => 0,
];
foreach($res as $k => $v){
if($k == $strCode){
return $res = $v;
}
}
//return $res;
}
public static function getMsg($strMsg){
//状态配置
$res = [
'add_success' => Lang::get('add success'),
'add_error' => Lang::get('add error'),
'edit_success' => Lang::get('edit success'),
'edit_error' => Lang::get('edit error'),
];
foreach($res as $k => $v){
if($k == $strMsg){
return $res = $v;
}
}
//$res;
}
public static function show($strCode,$strMsg,$url)
{
$res = [
'code' => self::getCode($strCode),
'msg' => self::getMsg($strMsg),
'url' => $url,
];
return json($res);
}
}

View File

@ -14,6 +14,8 @@ use taoler\com\Message;
use app\common\model\Cate;
use app\common\model\User;
use app\common\model\Collection;
use think\facade\Lang;
use app\common\lib\Msg;
class Article extends BaseController
{
@ -250,7 +252,9 @@ class Article extends BaseController
$link = (string) url('article/detail',['id'=> $aid]);
//清除文章tag缓存
Cache::tag('tagArtDetail')->clear();
return json(['code'=>1,'msg'=>'发布成功','url'=> $link]);
//return json(['code'=>1,'msg'=>'发布成功','url'=> $link]);
return json(['code'=>Msg::getCode('success'),'msg'=>Msg::getMsg('add_success'),'url'=> $link]);
} else {
$this->error($result);
}
@ -322,7 +326,10 @@ class Article extends BaseController
//删除缓存显示编辑后内容
Cache::delete('article_'.$id);
$link = (string) url('article/detail',['id'=> $id]);
return json(['code'=>0,'msg'=>'修改成功','url'=> $link]);
//return json(['code'=>0,'msg'=>'修改成功','url'=> $link]);
return Msg::show('error','edit_success',$link);
} else {
$this->error($result);
}

View File

@ -10,6 +10,7 @@ use app\common\model\Article;
use app\common\model\User;
use app\common\model\Cate;
use app\common\model\Comment;
use think\facade\Cookie;
class Index extends BaseController
{
@ -121,7 +122,6 @@ class Index extends BaseController
//搜索功能
public function search()
{
//$this->showUser();
//全局查询条件
$map = []; //所有的查询条件封装到数组中
//条件1
@ -163,4 +163,24 @@ class Index extends BaseController
}
public function select()
{
$lang = input('language');
//dump($lang);
switch ($lang) {
case 'cn':
Cookie::set('think_lang','zh-cn');
break;
case 'en':
Cookie::set('think_lang','en-us');
break;
case 'tw':
Cookie::set('think_lang','zh-tw');
break;
default:
break;
}
}
}

View File

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 状态提示
// +----------------------------------------------------------------------
namespace app\index\controler;
use app\common\controller\BaseController;
use think\facade\Cookie;
class Lang extends BaseController
{
public function select()
{
$lang = input('language');
//dump($lang);
switch ($lang) {
case 'cn':
Cookie::set('think_lang','zh-cn');
break;
case 'en':
Cookie::set('think_lang','en-us');
break;
case 'tw':
Cookie::set('think_lang','zh-tw');
break;
default:
break;
}
}
}

36
app/index/lang/en-us.php Normal file
View File

@ -0,0 +1,36 @@
<?php
return [
//menu
'index' => 'index',
'home_page' => 'home page',
'user_center' => 'center',
'set_info' => 'set info',
'my_message' => 'message',
'my_page' => 'my page',
'login' => 'login',
'logout' => 'logout',
'register' => 'register',
'discuss' => 'discuss',
'case' => 'case',
'timeline' => 'timeline',
//帖子
'add_post' => 'add post',
'my_collection' => 'my collection',
'all' => 'all',
'over' => 'over',
'hot' => 'hot',
'top' => 'top',
'go_sign' => 'go sign',
'more_post' => 'more post',
'friendly_link' => 'friendly link',
//message
'add success' => 'add success!',
'add error' => 'add error',
'edit success' => 'articel edit success',
'edit error' => 'articel edit error',
];

39
app/index/lang/zh-cn.php Normal file
View File

@ -0,0 +1,39 @@
<?php
return [
//menu
'index' => 'index',
'home_page' => '首页',
'user_center' => '用户中心',
'set_info' => '设置',
'my_message' => '我的消息',
'my_page' => '我的主页',
'login' => '登录',
'logout' => '退出',
'register' => '注册',
'discuss' => '讨论',
'case' => '案例',
'timeline' => '框架日志',
//帖子
'add_post' => '添加帖子',
'my_collection' => '我的收藏',
'all' => '综合',
'over' => '已结',
'hot' => '热贴',
'top' => '精贴',
'go_sign' => '去签到',
'more_post' => '更多帖子',
'friendly_link' => '友情链接',
'hello thinkphp' => '欢迎使用ThinkPHP',
'data type error' => '数据类型错误',
'add success' => '添加成功!',
'add error' => '添加失败',
'edit success' => '修改成功',
'edit error' => '修改失败',
];

9
app/index/lang/zh-tw.php Normal file
View File

@ -0,0 +1,9 @@
<?php
return [
'data type error' => '数据类型错误',
'add success' => '添加成功',
'add error' => '添加失敗',
'edit success' => '修改成功',
'edit error' => '修改失敗',
];

View File

@ -4,7 +4,7 @@ return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
\think\middleware\LoadLangPack::class,
// Session初始化
\think\middleware\SessionInit::class
];

View File

@ -17,35 +17,32 @@ class Auth
*/
public function handle($request, \Closure $next)
{
$response = $next($request);
//后置中间件获取应用控制器方法
$app = app('http')->getName();
$controller = $request->controller();
$action = $request->action();
$path = app('http')->getName().'/'.stristr($request->pathinfo(),".html",true);
//登陆后检验权限
if (Session::has('admin_id')) {
// 排除权限
$not_check = ['admin/Login/index','admin/Index/index','admin/Index/home','admin/Set/info','admin/Set/password','admin/User/logout'];
//没有登录及当前非登录页重定向登录页
if(!Session::has('admin_id') && $path !== 'admin/login/index' && !stristr($request->pathinfo(),"captcha.html") )
{
return redirect((string) url('admin/login/index'));
}
if (!in_array($app . '/' . $controller . '/' . $action, $not_check)) {
$auth = new UserAuth();
$admin_id = Session::get('admin_id'); //登录用户的id
//登陆后无法访问登录页
if(Session::has('admin_id') && $path == 'admin/login/index'){
return redirect((string) url('admin/index/index'));
}
if (!$auth->check($app . '/' . $controller . '/' . $action, $admin_id) && $admin_id != 1) {
//return json(['code'=>-1,'msg'=>'没有权限!']);
return view('public/auth');
}
}
// 排除公共权限
$not_check = ['admin/login/index','admin/index/index','admin/index/home','admin/Set/info','admin/Set/password','admin/Admin/logout','admin/captcha'];
} else {
//排除登录页和验证码及退出登录后被重定向
if($controller !== 'Login' && !stristr($request->pathinfo(),"captcha.html") && $action !== 'logout')
{
//非登录重定向
return redirect((string) url('admin/login/index'));
if (!in_array($path, $not_check)) {
$auth = new UserAuth();
$admin_id = Session::get('admin_id'); //登录用户的id
if (!$auth->check($path, $admin_id) && $admin_id != 1) {
return view('public/auth');
//return json(['status'=>-1,'msg'=>'没有权限!']);
//return response("<script> alert('没有权限!'); </script>");
}
}
return $response;
return $next($request);
}
}

View File

@ -7,7 +7,7 @@ return [
// 默认语言
'default_lang' => env('lang.default_lang', 'zh-cn'),
// 允许的语言列表
'allow_lang_list' => [],
'allow_lang_list' => ['zh-cn', 'en-us', 'zh-tw'],
// 多语言自动侦测变量名
'detect_var' => 'lang',
// 是否使用Cookie记录

View File

@ -17,8 +17,8 @@
<!--置顶文章-->
<div class="fly-panel">
<div class="fly-panel-title fly-filter">
<a>置顶</a>
<a href="#signin" class="layui-hide-sm layui-show-xs-block fly-right" id="LAY_goSignin" style="color: #FF5722;">去签到</a>
<a>{:lang('top')}</a>
<a href="#signin" class="layui-hide-sm layui-show-xs-block fly-right" id="LAY_goSignin" style="color: #FF5722;">{:lang('go_sign')}</a>
</div>
<ul class="fly-list">
{volist name="artTop" id="top" empty="还没有推荐"}
@ -36,7 +36,7 @@
</ul>
<div style="text-align: center">
<div class="laypage-main">
<a href="{:url('article/cate',['ename'=>'all'])}" class="laypage-next">更多帖子</a>
<a href="{:url('article/cate',['ename'=>'all'])}" class="laypage-next">{:lang('more_post')}</a>
</div>
</div>
</div>
@ -101,10 +101,12 @@
{block name="script"}
<script>
layui.use(['form', 'layer'], function() {
var form = layui.form;
var layer = layui.layer;
var $ = layui.jquery;
var jifenname = "金币";
var uid = "{:session('user_id')}";
if (uid != '') {
$.get("{:url('sign/todayData')}", function(data) {
@ -208,6 +210,17 @@
content: signlisturl,
});
});
//监听语音选择提交
form.on('select(language)', function(data){
var data = data.value;
console.log(data);
$.post("{:url('index/select')}",{language:data},function(result){
});
return false;
});
});
$('#friend-link').on('click', function(){

View File

@ -2,7 +2,7 @@
<div class="layui-container">
<ul class="layui-clear">
<li class="layui-hide-xs {if ($Request.param.ename =='' && $Request.param.id =='')} layui-this {/if}" >
<a href="/">首页</a>
<a href="/">{:lang('home')}</a>
</li>
{volist name="cateList" id="cate"}
<li {if condition="$cate.ename eq $Request.param.ename"} class="layui-this" {/if}>
@ -11,17 +11,17 @@
{/volist}
<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>
{if session('?user_id')}
<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('user/post')}">我发表的贴</a></li>
<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('user/post#collection')}">我收藏的贴</a></li>
<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('user/post')}">{:lang('add_post')}</a></li>
<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="{:url('user/post#collection')}">{:lang('my_collection')}</a></li>
{/if}
</ul>
<div class="fly-column-right layui-hide-xs">
<span class="fly-search"><i class="layui-icon">&#xe615;</i></span>
<a href="{:url('article/add')}" class="layui-btn" >发表新帖</a>
<a href="{:url('article/add')}" class="layui-btn" >{:lang('add_post')}</a>
</div>
<div class="layui-hide-sm layui-show-xs-block" style="margin-top: -10px; padding-bottom: 10px; text-align: center;">
<a href="javascript:void(0)" class="layui-btn" id="add_post">发表新帖</a>
<a href="javascript:void(0)" class="layui-btn" id="add_post">{:lang('add_post')}</a>
</div>
</div>
</div>

View File

@ -1,11 +1,11 @@
<div class="fly-panel-title fly-filter">
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all' ,'type' => ''])} " {if condition="$type eq ''" } class="layui-this" {/if} >综合</a>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all' ,'type' => ''])} " {if condition="$type eq ''" } class="layui-this" {/if} >{:lang('all')}</a>
<span class="fly-mid"></span>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'jie'])} " {if condition="$type eq 'jie'" } class="layui-this" {/if} >已结</a>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'jie'])} " {if condition="$type eq 'jie'" } class="layui-this" {/if} >{:lang('over')}</a>
<span class="fly-mid"></span>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'top'])} " {if condition="$type eq 'top'" } class="layui-this" {/if} >热帖</a>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'top'])} " {if condition="$type eq 'top'" } class="layui-this" {/if} >{:lang('top')}</a>
<span class="fly-mid"></span>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'hot'])} " {if condition="$type eq 'hot'" } class="layui-this" {/if} >精贴</a>
<a href="{:url('article/cate',['ename' => $Request.param.ename ?:'all','type' => 'hot'])} " {if condition="$type eq 'hot'" } class="layui-this" {/if} >{:lang('hot')}</a>
<!--span class="fly-filter-right layui-hide-xs"><a href="" class="layui-this">按最新</a>
<span class="fly-mid"></span><a href="">按热议</a></span-->

View File

@ -1,5 +1,5 @@
<div class="fly-panel fly-link html5plus-hide">
<h3 class="fly-panel-title">友情链接</h3>
<h3 class="fly-panel-title">{:lang('friendly_link')}</h3>
<dl class="fly-panel-main">
{volist name="flinks" id="vo"}
<dd><a href="{$vo.slid_href}" target="_blank">{$vo.slid_name}</a><dd>

View File

@ -5,13 +5,13 @@
</a>
<ul class="layui-nav fly-nav layui-hide-xs">
<li class="layui-nav-item layui-this">
<a href="/"><i class="iconfont icon-jiaoliu"></i>交流</a>
<a href="/"><i class="iconfont icon-jiaoliu"></i>{:lang('discuss')}</a>
</li>
<li class="layui-nav-item">
<a href="case/case.html"><i class="iconfont icon-iconmingxinganli"></i>案例</a>
<a href="case/case.html"><i class="iconfont icon-iconmingxinganli"></i>{:lang('case')}</a>
</li>
<li class="layui-nav-item">
<a href="{:url('doc/timeline')}" target="_blank"><i class="iconfont icon-ui"></i>框架</a>
<a href="{:url('doc/timeline')}" target="_blank"><i class="iconfont icon-ui"></i>{:lang('timeline')}</a>
</li>
</ul>
@ -19,7 +19,7 @@
{if session('?user_id')}
{if($Request.action=='user')}
<li class="layui-nav-item">
<a href="/">前台首页</a>
<a href="/">{:lang('home_page')}</a>
</li>
{/if}
<li class="layui-nav-item">
@ -31,13 +31,13 @@
</a>
<dl class="layui-nav-child">
<dd><a href="{:url('user/index')}"><i class="layui-icon">&#xe612;</i>用户中心</a></dd>
<dd><a href="{:url('user/set')}"><i class="layui-icon">&#xe620;</i>基本设置</a></dd>
<dd><a href="{:url('user/index')}"><i class="layui-icon">&#xe612;</i>{:lang('user_center')}</a></dd>
<dd><a href="{:url('user/set')}"><i class="layui-icon">&#xe620;</i>{:lang('set_info')}</a></dd>
<hr>
<dd><a href="{:url('user/message')}"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>我的消息</a></dd>
<dd><a href="{:url('user/home',['id'=>session('user_id')])}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>我的主页</a></dd>
<dd><a href="{:url('user/message')}"><i class="iconfont icon-tongzhi" style="top: 4px;"></i>{:lang('my_message')}</a></dd>
<dd><a href="{:url('user/home',['id'=>session('user_id')])}"><i class="layui-icon" style="margin-left: 2px; font-size: 22px;">&#xe68e;</i>{:lang('my_page')}</a></dd>
<hr style="margin: 5px 0;">
<dd><a data-url="{:url('user/logout')}" location-url="{:url('index/index')}" href="javascript:void(0)" class="logi_logout" style="text-align: center;">退出</a></dd>
<dd><a data-url="{:url('user/logout')}" location-url="{:url('index/index')}" href="javascript:void(0)" class="logi_logout" style="text-align: center;">{:lang('logout')}</a></dd>
</dl>
</li>
{else /}
@ -47,11 +47,20 @@
<a class="iconfont icon-touxiang layui-hide-xs" href="{:url('login/index')}"></a>
</li>
<li class="layui-nav-item">
<a href="{:url('login/index')}">登入</a>
<a href="{:url('login/index')}">{:lang('login')}</a>
</li>
<li class="layui-nav-item">
<a href="{:url('login/reg')}">注册</a>
<a href="{:url('login/reg')}">{:lang('register')}</a>
</li>
<li class="layui-nav-item">
<form class="layui-form" style="width:100px;color:black;padding: 0;">
<select name="language" lay-filter="language" lay-verify="">
<option value="cn" selected>中文简体</option>
<option value="tw" >中文繁体</option>
<option value="en" >英文</option>
</select>
</form>
</li>
<!--li class="layui-nav-item layui-hide-xs">
<a href="" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" title="QQ登入" class="iconfont icon-qq"></a>
</li>

View File

@ -1,5 +1,3 @@
<script src="/static/layui/jquery.min.js" charset="utf-8"></script>
<script src="/static/layui/layui.js" charset="utf-8"></script>
<script>
var messageNums = "{:url('index/Message/nums')}",
messageRead = "{:url('index/Message/read')}",
@ -10,3 +8,5 @@ var messageNums = "{:url('index/Message/nums')}",
textImgUpload = "{:url('index/article/textImgUpload')}",
searchUrl = "{:url('index/search')}";
</script>
<script src="/static/layui/jquery.min.js" charset="utf-8"></script>
<script src="/static/layui/layui.js" charset="utf-8"></script>