You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.0 KiB

4 years ago
/*
* EasyCode EC管理后台(http://www.learun.cn)
* Copyright (c) 2019-present EC管理有限公司
* 创建人tobin
* 2018.05.10
* 客户端语言包加载菜单tab条
*/
(function ($, learun) {
"use strict";
var type = 'no';
var lgTypeList = {};
var mainType = null;
var isRead = {};
var lgData = {};
learun.language = {
getMainCode: function () {
return mainType;
},
get: function (text, callback) {
// 判断当前客户端的语言版本
if (mainType != null && type.toLowerCase() != mainType.toLowerCase()) {
// 判断当前语言包是否加载完成
if (isRead[type.toLowerCase()] && isRead[mainType.toLowerCase()]) {
var mdata = lgData[mainType];
var cdata = lgData[type];
callback(cdata[mdata[text]] || text);
}
else {
setTimeout(function () {
learun.language.get(text, callback);
}, 200);
}
}
else {
callback(text);
}
},
getSyn: function (text) {
// 判断当前客户端的语言版本
if (type != mainType) {
var mdata = storage.get(mainType);
var cdata = storage.get(type);
return cdata.data[mdata.data[text]] || text;
}
else {
return text;
}
}
};
$(function () {
type = top.$.cookie('lr_adms_core_lang') || 'no';
var $setting = $('#lr_lg_setting');
if (type == 'no') {
$setting.find('span').text('简体中文');
}
$setting.on('click', 'li>a', function () {
var code = $(this).attr('data-value');
top.$.cookie('lr_adms_core_lang', code, { path: "/" });
location.reload();
});
// 获取当前语言类型
learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGType/GetList', function (res) {
if (res.code == 200) {
var $ul = $setting.find('ul');
$.each(res.data, function (_index, _item) {
lgTypeList[_item.F_Code] = _item.F_Name;
if (_item.F_IsMain == 1) {
mainType = _item.F_Code;
if (type == 'no') {
type = mainType;
top.$.cookie('lr_adms_core_lang', type, { path: "/" });
}
}
isRead[_item.F_Code] = false;
var html = '<li><a href="javascript:void(0);" data-value="' + _item.F_Code + '" >' + _item.F_Name + '</a></li>';
$ul.append(html);
});
$setting.find('span').text(lgTypeList[type]);
// 开始加载语言包,如果当前设置的语言不是主语言的话
if (type.toLowerCase() != mainType.toLowerCase()) {
learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGMap/GetLanguageByCode?typeCode=' + mainType + '&isMain=true', function (res) {
if (res.code == 200) {
lgData[mainType] = res.data;
}
isRead[mainType.toLowerCase()] = true;
});
learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGMap/GetLanguageByCode?typeCode=' + type + '&isMain=false', function (res) {
if (res.code == 200) {
lgData[type] = res.data;
}
isRead[type.toLowerCase()] = true;
});
}
}
else {
$setting.hide();
}
});
});
})(window.jQuery, top.learun);