Skip to content

Commit

Permalink
#feat 支持在右上角选取多语言
Browse files Browse the repository at this point in the history
  • Loading branch information
magicblack committed Jun 11, 2024
1 parent b0bab28 commit aaa2275
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
12 changes: 12 additions & 0 deletions application/admin/controller/System.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,17 @@ public function configseo()
return $this->fetch('admin@system/configseo');
}

public function configlang(){
$param = input();
$config_new['app']['lang'] = $param['lang'];
$config_old = config('maccms');
$config_new = array_merge($config_old, $config_new);

$res = mac_arr2file(APP_PATH . 'extra/maccms.php', $config_new);
if ($res === false) {
return $this->error(lang('save_err'));
}
return json(['code' => 1, 'msg' => 'ok']);
}

}
39 changes: 39 additions & 0 deletions application/admin/view/index/index.html
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{include file="../../../application/admin/view/public/head" /}

<?php
$langs = glob('./application/lang/*.php');
foreach ($langs as $k => &$v) {
$v = str_replace(['./application/lang/','.php'],['',''],$v);
}
?>
<style type="text/css">
.hs-iframe{width:100%;height:100%;}
.layui-tab-content {top: 41px; position: absolute; bottom: 0; width: 100%; padding: 0; }
Expand Down Expand Up @@ -47,6 +53,15 @@
{/volist}
</ul>
<ul class="layui-nav layui-layout-right" lay-filter="">
<li class="layui-nav-item layui-hide-xs"></li>
<div class="layui-input-inline" >
<select id="languageSelect" class="w150" name="app[lang]">
{volist name="langs" id="vo"}
<option value="{$vo}" {if condition="$config['app']['lang'] eq $vo"}selected {/if}>{$vo}</option>
{/volist}
</select>
</div>
</li>
<li class="layui-nav-item layui-hide-xs">
<a href="javascript:void(0);">{:lang('opt')}&nbsp;&nbsp;</a>
<dl class="layui-nav-child">
Expand Down Expand Up @@ -153,6 +168,30 @@
</script>

<script type="text/javascript">
$(document).ready(function(){
$('#languageSelect').change(function(){
var selectedLang = $(this).val();
$.ajax({
url: "{:url('system/configlang')}",
type: "post",
dataType: "json",
data: {'lang': selectedLang},
beforeSend: function () {

},
error:function(r){
layer.msg("configedit error",{time:1800});
},
success: function (r) {
layer.msg(r.msg,{time:1800});
},
complete: function () {
location.reload();
}
});
});
});

layui.use(['element', 'layer'], function() {
var $ = layui.jquery, element = layui.element, layer = layui.layer;
$('.layui-tab-content').height($(window).height() - 145);
Expand Down

0 comments on commit aaa2275

Please sign in to comment.