From 4ad5e23b977b96338c9c1fe083c713928524eefe Mon Sep 17 00:00:00 2001 From: toogee Date: Mon, 2 Nov 2020 21:54:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AF=AD=E8=A8=80=E5=8C=85?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=92=8Cjs=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/Language.php | 30 ++++++++++++++++++++++++++++ app/common/lib/Msg.php | 1 + app/index/controller/Index.php | 26 ++++++++++-------------- app/index/lang/en-us.php | 9 ++++++--- app/index/lang/zh-cn.php | 12 ++++++++--- public/static/res/mods/index.js | 13 ++++++------ view/taoler/index/public/footer.html | 2 +- view/taoler/index/public/header.html | 6 ++---- 8 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 app/common/controller/Language.php diff --git a/app/common/controller/Language.php b/app/common/controller/Language.php new file mode 100644 index 0000000..04dd42c --- /dev/null +++ b/app/common/controller/Language.php @@ -0,0 +1,30 @@ + Lang::get('add error'), 'edit_success' => Lang::get('edit success'), 'edit_error' => Lang::get('edit error'), + 'illegal_request' => Lang::get('illegal request'), ]; diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index fc09cf2..360092f 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -11,6 +11,7 @@ use app\common\model\User; use app\common\model\Cate; use app\common\model\Comment; use think\facade\Cookie; +use app\common\lib\Msg; class Index extends BaseController { @@ -163,23 +164,16 @@ class Index extends BaseController } - public function select() + public function language() { - $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; + if(request()->isPost()){ + $language = new \app\common\controller\Language; + $lang = $language->select(input('language')); + if($lang){ + return json(['code'=>0,'msg'=>'']); + } + }else { + return json(['code'=>Msg::get('error'),'msg'=>Msg::getMsg('illegal_request')]); } } diff --git a/app/index/lang/en-us.php b/app/index/lang/en-us.php index fd27a80..fe5c168 100644 --- a/app/index/lang/en-us.php +++ b/app/index/lang/en-us.php @@ -1,6 +1,11 @@ 'language', + 'chinese' => '中文简体', + 'english' => 'english', + //menu 'index' => 'Index', 'home page' => 'Home page', @@ -48,9 +53,6 @@ return [ 'ads area' => 'Ads area', 'enclosure' => 'enclosure', 'download files' => 'Download files', - - - //message 'add' => 'add', @@ -60,4 +62,5 @@ return [ 'add error' => 'add error', 'edit success' => 'articel edit success', 'edit error' => 'articel edit error', + 'illegal_request' => 'illegal request', ]; \ No newline at end of file diff --git a/app/index/lang/zh-cn.php b/app/index/lang/zh-cn.php index 885ad0c..5c29112 100644 --- a/app/index/lang/zh-cn.php +++ b/app/index/lang/zh-cn.php @@ -1,7 +1,12 @@ 'language', + 'chinese' => '中文简体', + 'english' => 'english', + + //menu 'index' => 'index', 'home page' => '首页', 'user center' => '用户中心', @@ -16,7 +21,7 @@ return [ 'case' => '案例', 'timeline' => '框架日志', - //帖子 + //帖子 'title color' => '颜色', 'add_post' => '添加帖子', 'my collection' => '我的收藏', @@ -48,12 +53,13 @@ return [ 'ads area' => '广告区', 'enclosure' => '附件', 'download files' => '下载文件', - + //message 'add' => '添加', 'delete' => '删除', 'add success' => '添加成功!', 'add error' => '添加失败', 'edit success' => '修改成功', 'edit error' => '修改失败', + 'illegal request' => '非法请求', ]; \ No newline at end of file diff --git a/public/static/res/mods/index.js b/public/static/res/mods/index.js index 197a6e7..11a50b9 100644 --- a/public/static/res/mods/index.js +++ b/public/static/res/mods/index.js @@ -851,12 +851,13 @@ layui.define(['layer', 'laytpl', 'form', 'element', 'upload', 'util'], function( }); }); - - //监听语音选择提交 - form.on('select(language)', function(data){ - var data = data.value; - $.post(langUrl,{language:data},function(result){ - location.reload(); + //监听语音选择提交 + $('#language').on('change',function(){ + var data = $(this).val(); + $.post(langUrl,{language:data},function(res){ + if(res.code == 0){ + location.reload(); + } }); return false; }); diff --git a/view/taoler/index/public/footer.html b/view/taoler/index/public/footer.html index 58ff334..39645ae 100644 --- a/view/taoler/index/public/footer.html +++ b/view/taoler/index/public/footer.html @@ -18,6 +18,6 @@ var messageNums = "{:url('index/Message/nums')}", websearch = "{:url('index/index/search')}", textImgUpload = "{:url('index/article/textImgUpload')}", searchUrl = "{:url('index/search')}"; - langUrl = "{:url('index/select')}"; + langUrl = "{:url('index/language')}"; diff --git a/view/taoler/index/public/header.html b/view/taoler/index/public/header.html index f1a3bfa..0931a37 100644 --- a/view/taoler/index/public/header.html +++ b/view/taoler/index/public/header.html @@ -53,13 +53,11 @@ {:lang('register')}
  • -
    - - + -