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.

lr-language.js 4.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  3. * Copyright (c) 2013-2018 上海力软信息技术有限公司
  4. * 创建人:力软-前端开发组
  5. * 日 期:2018.05.10
  6. * 描 述:客户端语言包加载(菜单,tab条)
  7. */
  8. (function ($, learun) {
  9. "use strict";
  10. var type = 'no';
  11. var lgTypeList = {};
  12. var mainType = null;
  13. var isRead = {};
  14. var lgData = {};
  15. var storage = {
  16. get: function (name) {
  17. if (localStorage) {
  18. return JSON.parse(localStorage.getItem('lrlg_' + name)) || {};
  19. }
  20. else {
  21. return lgData[name] || {};
  22. }
  23. },
  24. set: function (name, data) {
  25. if (localStorage) {
  26. localStorage.setItem('lrlg_' + name, JSON.stringify(data));
  27. }
  28. else {
  29. lgData[name] = data;
  30. }
  31. }
  32. };
  33. learun.language = {
  34. getMainCode: function () {
  35. return mainType;
  36. },
  37. get: function (text, callback) {
  38. // 判断当前客户端的语言版本
  39. if (type != mainType) {
  40. // 判断当前语言包是否加载完成
  41. if (isRead[type] && isRead[mainType]) {
  42. var mdata = storage.get(mainType);
  43. var cdata = storage.get(type);
  44. callback(cdata.data[mdata.data[text]] || text);
  45. }
  46. else {
  47. setTimeout(function () {
  48. learun.language.get(text, callback);
  49. }, 200);
  50. }
  51. }
  52. else {
  53. callback(text);
  54. }
  55. },
  56. getSyn: function (text) {
  57. // 判断当前客户端的语言版本
  58. if (type != mainType) {
  59. var mdata = storage.get(mainType);
  60. var cdata = storage.get(type);
  61. return cdata.data[mdata.data[text]] || text;
  62. }
  63. else {
  64. return text;
  65. }
  66. }
  67. };
  68. $(function () {
  69. type = top.$.cookie('Learn_ADMS_V7_Language') || 'no';
  70. var $setting = $('#lr_lg_setting');
  71. if (type == 'no') {
  72. $setting.find('span').text('简体中文');
  73. }
  74. $setting.on('click', 'li>a', function () {
  75. var code = $(this).attr('data-value');
  76. top.$.cookie('Learn_ADMS_V7_Language', code, { path: "/" });
  77. location.reload();
  78. });
  79. // 获取当前语言类型
  80. learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGType/GetList', function (res) {
  81. if (res.code == 200) {
  82. var $ul = $setting.find('ul');
  83. $.each(res.data, function (_index, _item) {
  84. lgTypeList[_item.F_Code] = _item.F_Name;
  85. if (_item.F_IsMain == 1) {
  86. mainType = _item.F_Code;
  87. if (type == 'no') {
  88. type = mainType;
  89. top.$.cookie('Learn_ADMS_V7_Language', type, { path: "/" });
  90. }
  91. }
  92. isRead[_item.F_Code] = false;
  93. var html = '<li><a href="javascript:void(0);" data-value="' + _item.F_Code + '" >' + _item.F_Name + '</a></li>';
  94. $ul.append(html);
  95. });
  96. $setting.find('span').text(lgTypeList[type]);
  97. // 开始加载语言包,如果当前设置的语言不是主语言的话
  98. if (type != mainType) {
  99. // 加载主语言包和当前设置的语言包
  100. var mlgdata = storage.get(mainType);
  101. var lgdata = storage.get(type);
  102. learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGMap/GetLanguageByCode?typeCode=' + mainType + '&ver=' + mlgdata.ver + '&isMain=true', function (res) {
  103. if (res.code == 200) {
  104. if (res.info != 'no update') {
  105. storage.set(mainType, res.data);
  106. }
  107. }
  108. isRead[mainType] = true;
  109. });
  110. learun.httpAsyncGet(top.$.rootUrl + '/LR_LGManager/LGMap/GetLanguageByCode?typeCode=' + type + '&ver=' + lgdata.ver + '&isMain=false', function (res) {
  111. if (res.code == 200) {
  112. if (res.info != 'no update') {
  113. storage.set(type, res.data);
  114. }
  115. }
  116. isRead[type] = true;
  117. });
  118. }
  119. }
  120. });
  121. });
  122. })(window.jQuery, top.learun);