| | |
| | | //确保DOM完全加载后再执行 |
| | | //document.addEventListener('DOMContentLoaded', function () { |
| | | // initFunction(); |
| | | //}); |
| | | //$(document).on('click', '.layui-btn', function () { |
| | | // initFunction(); |
| | | //}); |
| | | |
| | | |
| | | var HModNameData = ""; |
| | | var HLanguageType_Data = ""; |
| | | document.addEventListener('click', function (event) { |
| | | Btn(); |
| | | var data = localStorage.getItem("data"); |
| | | var data2 = JSON.parse(data); |
| | | if (HModNameData != "indexMenu") { |
| | | if (data == null || data2.HTranSlate != HLanguageType_Data) { |
| | | ClickFunction(2,HModNameData, HLanguageType_Data); |
| | | } else { |
| | | ClickFunction(2,HModNameData, data2.HTranSlate); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | function Lable() { |
| | | var Lable = document.querySelectorAll('.layui-form-label').length; |
| | | for (var i = 0; i < Lable; i++) { |
| | | console.log(document.querySelectorAll('.layui-form-label')[i].innerHTML); |
| | | |
| | | //点击事件触发的方法 |
| | | function ClickFunction(InitiaType,HModName,HLanguageType) { |
| | | var data = localStorage.getItem(HModName); |
| | | if (data != null) { |
| | | var data2 = JSON.parse(data) |
| | | if (HModName == "login") { |
| | | LoginDataShow(data2, HLanguageType); |
| | | } else { |
| | | ModelDataShow(InitiaType,data2, HLanguageType); |
| | | } |
| | | } |
| | | for (var i = 0; i < Lable; i++) { |
| | | document.querySelectorAll('.layui-form-label')[i].innerHTML = document.querySelectorAll('.layui-form-label')[i].textContent + "1"; |
| | | } |
| | | } |
| | | function initFunction() { |
| | | Btn(); |
| | | Lable(); |
| | | } |
| | | |
| | | function Btn() { |
| | | var Btn = document.querySelectorAll('button>text').length; |
| | | for (var i = 0; i < Btn; i++) { |
| | | console.log(document.querySelectorAll('button>text')[i].innerHTML); |
| | | } |
| | | for (var i = 0; i < Btn; i++) { |
| | | document.querySelectorAll('button>text')[i].innerHTML = document.querySelectorAll('button>text')[i].textContent + "1"; |
| | | //初始化页面加载数据 InitiaType 初始化 默认1 2=点击事件 |
| | | function initFunction(InitiaType,HModName, HLanguageType) { |
| | | HModNameData = HModName; |
| | | HLanguageType_Data = HLanguageType; |
| | | get_ReadConfigFile(InitiaType,HModName, HLanguageType); |
| | | } |
| | | |
| | | //登录页面 显示数据 |
| | | function LoginDataShow(data, HLanguageType) { |
| | | for (var i = 0; i < data.length; i++) { |
| | | var HTranslationText = ""; |
| | | |
| | | if (HLanguageType == 1) { |
| | | HTranslationText = data[i].HFieldName; |
| | | } else if (HLanguageType == 2) { |
| | | HTranslationText = data[i].HTranslationText_English; |
| | | } else if (HLanguageType == 3) { |
| | | HTranslationText = data[i].HTranslationText_Spain; |
| | | } |
| | | |
| | | if (data[i].HFieldModelType == "id") { |
| | | $("#" + data[i].HFieldCode).text(data[i].HFieldName) |
| | | } else if (data[i].HFieldModelType == "class") { |
| | | if (data[i].HFieldCode != "select option") { |
| | | var count = document.querySelectorAll(data[i].HFieldCode).length; |
| | | for (var j = 0; j < count; j++) { |
| | | document.querySelectorAll(data[i].HFieldCode)[j].innerText = data[i].HFieldName; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (data[i].HFieldModelType == "id") { |
| | | if ($("#" + data[i].HFieldCode).text().trim() == data[i].HFieldName) { |
| | | $("#" + data[i].HFieldCode).text(HTranslationText) |
| | | } |
| | | } else if (data[i].HFieldModelType == "class") { |
| | | if (data[i].HFieldCode != "select option") { |
| | | var count = document.querySelectorAll(data[i].HFieldCode).length; |
| | | for (var j = 0; j < count; j++) { |
| | | if (document.querySelectorAll(data[i].HFieldCode)[j].innerText.trim() == data[i].HFieldName) { |
| | | document.querySelectorAll(data[i].HFieldCode)[j].innerText = HTranslationText; |
| | | //break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //模块 显示数据 |
| | | function ModelDataShow(InitiaType, data, HLanguageType) { |
| | | //下拉框所有值 .layui-unselect dd |
| | | var OptionData = []; |
| | | const ddElementsOptionData = document.querySelectorAll(".layui-unselect dd"); |
| | | // 遍历元素并获取内容 |
| | | ddElementsOptionData.forEach((dd, index) => { |
| | | OptionData.push(dd.innerText.trim()); |
| | | }); |
| | | |
| | | //下拉框所有值 select option |
| | | var OptionList = []; |
| | | const ddElementsOptionList = document.querySelectorAll("select option"); |
| | | |
| | | // 遍历元素并获取内容 |
| | | ddElementsOptionList.forEach((dd, index) => { |
| | | OptionList.push(dd.innerText.trim()); |
| | | }); |
| | | |
| | | for (var i = 0; i < data.length; i++) { |
| | | var HTranslationText = ""; |
| | | |
| | | if (HLanguageType == 1) { |
| | | HTranslationText = data[i].HFieldName; |
| | | } else if (HLanguageType == 2) { |
| | | HTranslationText = data[i].HTranslationText_English; |
| | | } else if (HLanguageType == 3) { |
| | | HTranslationText = data[i].HTranslationText_Spain; |
| | | } |
| | | |
| | | if (data[i].HFieldModelType == "id") { |
| | | if ($("#" + data[i].HFieldCode).text().trim() == data[i].HFieldName) { |
| | | if (document.querySelectorAll("#" + data[i].HFieldCode)[0].innerHTML == data[i].HFieldName) { |
| | | document.querySelectorAll("#" + data[i].HFieldCode)[0].innerHTML = document.querySelectorAll("#" + data[i].HFieldCode)[0].innerHTML.replace(data[i].HFieldName.replace('*', ''), HTranslationText.replace('*', '')); |
| | | } else if (document.querySelectorAll("#" + data[i].HFieldCode)[0].innerText == data[i].HFieldName) { |
| | | document.querySelectorAll("#" + data[i].HFieldCode)[0].innerHTML = document.querySelectorAll("#" + data[i].HFieldCode)[0].innerHTML.replace(data[i].HFieldName.replace('*', ''), HTranslationText.replace('*', '')); |
| | | } else { |
| | | document.querySelectorAll("#" + data[i].HFieldCode)[0].innerText = document.querySelectorAll("#" + data[i].HFieldCode)[0].innerText.replace(data[i].HFieldName.replace('*', ''), HTranslationText.replace('*', '')); |
| | | } |
| | | } |
| | | } else if (data[i].HFieldModelType == "class") { |
| | | |
| | | if (InitiaType != 2) { |
| | | if (data[i].HFieldCode != "select option") { |
| | | var count = document.querySelectorAll(data[i].HFieldCode).length; |
| | | for (var j = 0; j < count; j++) { |
| | | if (document.querySelectorAll(data[i].HFieldCode)[j].innerText.trim() == data[i].HFieldName) { |
| | | document.querySelectorAll(data[i].HFieldCode)[j].innerHTML = document.querySelectorAll(data[i].HFieldCode)[j].innerHTML.replace(data[i].HFieldName, HTranslationText); |
| | | } |
| | | } |
| | | } else { |
| | | |
| | | //下拉框的所有值 |
| | | var indicesData = []; |
| | | var currentIndex = -1; |
| | | while ((currentIndex = OptionData.indexOf(data[i].HFieldName, currentIndex + 1)) !== -1) { |
| | | indicesData.push(currentIndex); |
| | | } |
| | | |
| | | for (var j = 0; j < indicesData.length; j++) { |
| | | document.querySelectorAll(".layui-unselect dd")[indicesData[j]].innerHTML = document.querySelectorAll(".layui-unselect dd")[indicesData[j]].innerHTML.replace(data[i].HFieldName, HTranslationText); |
| | | |
| | | } |
| | | |
| | | var indicesList = []; |
| | | currentIndex = -1; |
| | | while ((currentIndex = OptionList.indexOf(data[i].HFieldName, currentIndex + 1)) !== -1) { |
| | | indicesList.push(currentIndex); |
| | | } |
| | | |
| | | for (var j = 0; j < indicesList.length; j++) { |
| | | document.querySelectorAll(data[i].HFieldCode)[indicesList[j]].innerHTML = document.querySelectorAll(data[i].HFieldCode)[indicesList[j]].innerHTML.replace(data[i].HFieldName, HTranslationText); |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | if (data[i].HFieldCode != "select option") { |
| | | var count = document.querySelectorAll(data[i].HFieldCode).length; |
| | | for (var j = 0; j < count; j++) { |
| | | if (document.querySelectorAll(data[i].HFieldCode)[j].innerText.trim() == data[i].HFieldName) { |
| | | document.querySelectorAll(data[i].HFieldCode)[j].innerHTML = document.querySelectorAll(data[i].HFieldCode)[j].innerHTML.replace(data[i].HFieldName, HTranslationText); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //下拉框的默认值 |
| | | if (data[i].HFieldCode == ".layui-unselect input") { |
| | | var uncount = document.querySelectorAll(".layui-unselect input").length; |
| | | for (var j = 0; j < uncount; j++) { |
| | | if (document.querySelectorAll(".layui-unselect input")[j].placeholder.trim() == data[i].HFieldName) { |
| | | document.querySelectorAll(".layui-unselect input")[j].placeholder = document.querySelectorAll(".layui-unselect input")[j].placeholder.replace(data[i].HFieldName, HTranslationText); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //获取页面的所有标签id 对应要翻译的字段 |
| | | function SelectData() { |
| | | var DataList = ""; |
| | | |
| | | //#region 登录界面 自定义 类 FY_BT 为了统一 |
| | | //刷卡 字段可以获取 所以 不用自定义 |
| | | var logCount = document.querySelectorAll('.FY_BT').length; |
| | | for (var i = 0; i < logCount; i++) { |
| | | var id = document.querySelectorAll('.FY_BT')[i].id; |
| | | var data = document.querySelectorAll('.FY_BT')[i].innerText.trim(); |
| | | var type = "id"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | |
| | | //#endregion |
| | | |
| | | //文本标签的数据获取 通过id |
| | | var LableCount = document.querySelectorAll('.layui-form-label').length; |
| | | for (var i = 0; i < LableCount; i++) { |
| | | var id = document.querySelectorAll('.layui-form-label')[i].id; |
| | | var data = document.querySelectorAll('.layui-form-label')[i].innerText.trim(); |
| | | var type = "id"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | |
| | | //复选框标签的的数据获取 通过id |
| | | var CheckCount = document.querySelectorAll("input[type='checkbox']").length; |
| | | for (var i = 0; i < CheckCount; i++) { |
| | | var data = document.querySelectorAll("input[type='checkbox']")[i].title.trim(); |
| | | if (data != "") { |
| | | var id = document.querySelectorAll("input[type='checkbox']")[i].id; |
| | | var type = "id"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | |
| | | } |
| | | |
| | | //#region 单据页面 按钮的获取 |
| | | |
| | | //单据页面 标题标签获取 通过id |
| | | var BTCount = document.querySelectorAll('.layui-tab h1').length |
| | | for (var i = 0; i < BTCount; i++) { |
| | | if (document.querySelectorAll('.layui-tab h1')[i].innerText.trim() != '') { |
| | | var id = document.querySelectorAll('.layui-tab h1')[i].id; |
| | | var data = document.querySelectorAll('.layui-tab h1')[i].innerText.trim(); |
| | | var type = "id"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | } |
| | | |
| | | //#endregion |
| | | |
| | | //按钮标签的数据获取 通过id |
| | | //按钮标签的数据获取 通过class 例如 子表删除 他的id会变 |
| | | var BtnCount = document.querySelectorAll('.layui-btn').length; |
| | | for (var i = 0; i < BtnCount; i++) { |
| | | if (document.querySelectorAll('.layui-btn')[i].innerText.trim() != "") { |
| | | var id = document.querySelectorAll('.layui-btn')[i].id.trim(); |
| | | var type = ""; |
| | | if (id != "") { |
| | | type = "id"; |
| | | } else { |
| | | id = ".layui-btn"; |
| | | type = "class"; |
| | | } |
| | | var data = document.querySelectorAll('.layui-btn')[i].innerText.trim(); |
| | | |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | } |
| | | |
| | | //页签标签的数据获取 通过class |
| | | var YQCount = document.querySelectorAll('.layui-tab-title>li').length; |
| | | for (var i = 0; i < YQCount; i++) { |
| | | if (document.querySelectorAll('.layui-tab-title>li')[i].innerText.trim() != '') { |
| | | var id = ".layui-tab-title>li" |
| | | var data = document.querySelectorAll('.layui-tab-title>li')[i].innerText.trim(); |
| | | var type = "class"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | } |
| | | |
| | | //表格列标签的数据获取 通过class |
| | | var ColCount = document.querySelectorAll('.layui-table tr span').length |
| | | for (var i = 0; i < ColCount; i++) { |
| | | if (document.querySelectorAll('.layui-table tr span')[i].innerText.trim() != '') { |
| | | var id = ".layui-table tr span" |
| | | var data = document.querySelectorAll('.layui-table tr span')[i].innerText.trim(); |
| | | var type = "class"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | } |
| | | |
| | | //所有页面 下拉框的所有值 通过class |
| | | var ModelCount = document.querySelectorAll('select option').length |
| | | for (var i = 0; i < ModelCount; i++) { |
| | | if (document.querySelectorAll('select option')[i].innerText.trim() != '') { |
| | | var id = "select option" |
| | | var data = document.querySelectorAll('select option')[i].innerText.trim(); |
| | | var type = "class"; |
| | | DataList += id + "|" + data + "|" + type + "," |
| | | } |
| | | } |
| | | |
| | | |
| | | ////获取页面页签的标签 获取数据 通过 class |
| | | //var YMBQCount = document.querySelectorAll('.layui-tab-title li span').length |
| | | //for (var i = 0; i < YMBQCount; i++) { |
| | | // if (document.querySelectorAll('.layui-tab-title li span')[i].innerText.trim() != '') { |
| | | // var id = ".layui-tab-title li span" |
| | | // var data = document.querySelectorAll('.layui-tab-title li span')[i].innerText.trim(); |
| | | // var type = "class"; |
| | | // DataList += id + "|" + data + "|" + type + "," |
| | | // } |
| | | //} |
| | | |
| | | return DataList; |
| | | } |
| | | |
| | | |
| | | //查询当前页面的数据 |
| | | function Select(InitiaType,HModName, HLanguageType) { |
| | | var sWhere = " and HModuleCode in('" + HModName + "','GYModel') "; |
| | | //1 中文 2 英语 3 西班牙语 |
| | | if (HLanguageType == "1") { |
| | | return false; |
| | | } |
| | | |
| | | $.ajax({ |
| | | url: GetWEBURlLanguage() + '/Xt_grdAlignment_WMES/SelectMESLanguage', |
| | | type: "GET", |
| | | async: false, |
| | | data: { "sWhere": sWhere}, |
| | | success: function (data1) { |
| | | if (data1.data.length > data1.count) { |
| | | get_WriteConfigFile(HModName, data1.data); |
| | | //var data= |
| | | ClickFunction(InitiaType, HModName, HLanguageType); |
| | | |
| | | } else { |
| | | //保存当前页面的数据 |
| | | Save(HModName); |
| | | } |
| | | }, error: function () { |
| | | layer.alert("接口请求失败!", { icon: 5 }); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | |
| | | |
| | | //保存当前页面的数据 |
| | | function Save(HModName) { |
| | | var DataList = SelectData(); |
| | | DataList = DataList.substring(0, DataList.length - 1); |
| | | DataList += ";"+HModName; |
| | | $.ajax({ |
| | | url: GetWEBURlLanguage() + '/Xt_grdAlignment_WMES/SaveMESLanguage', |
| | | type: "Post", |
| | | async: false, |
| | | data: { "sMainSub": DataList}, |
| | | success: function (data1) { |
| | | if (data1.count != 0) { |
| | | |
| | | } else { |
| | | |
| | | } |
| | | }, error: function () { |
| | | layer.alert("接口请求失败!", { icon: 5 }); |
| | | } |
| | | }) |
| | | } |
| | | |
| | | //存储配置文件 |
| | | function get_WriteConfigFile(HModName, SqlDataList) { |
| | | //清空本地存储的数据 |
| | | localStorage.removeItem(HModName); |
| | | var data = []; |
| | | for (var i = 0; i < SqlDataList.length; i++) { |
| | | var HFieldCode = SqlDataList[i].HFieldCode; |
| | | var HFieldName = SqlDataList[i].HFieldName; |
| | | var HFieldModelType = SqlDataList[i].HFieldModelType; |
| | | var HTranslationText_English = SqlDataList[i].HTranslationText_English; |
| | | var HTranslationText_Spain = SqlDataList[i].HTranslationText_Spain; |
| | | |
| | | data.push({ HFieldCode: HFieldCode, HFieldName: HFieldName, HFieldModelType: HFieldModelType, HTranslationText_English: HTranslationText_English, HTranslationText_Spain: HTranslationText_Spain }) |
| | | } |
| | | |
| | | //本地存储 |
| | | localStorage.setItem(HModName, JSON.stringify(data)); |
| | | } |
| | | |
| | | //读取配置文件 |
| | | function get_ReadConfigFile(InitiaType,HModName, HLanguageType) { |
| | | //获取本地存储的数据 |
| | | var data = localStorage.getItem(HModName); |
| | | if (data == null) { |
| | | Select(InitiaType,HModName, HLanguageType); |
| | | } else { |
| | | ClickFunction(InitiaType,HModName,HLanguageType); |
| | | } |
| | | } |
| | | |
| | | //报错信息 通过代码查询 |
| | | //ErrorCode 报错信息 |
| | | //HLanguageType 翻译类型 |
| | | function get_MessageError(ErrorCode, HLanguageType) { |
| | | var result = ""; |
| | | var Message = ""; |
| | | |
| | | const match = ErrorCode.match(/\[(.*?)\]/); |
| | | if (match) { |
| | | result= match[1]; |
| | | } |
| | | if (result == "") { |
| | | return ErrorCode; |
| | | } |
| | | |
| | | $.ajax({ |
| | | url: GetWEBURlLanguage() + '/Xt_grdAlignment_WMES/SelectMessageError', |
| | | type: "get", |
| | | async: false, |
| | | data: { "ErrorCode": result }, |
| | | success: function (data1) { |
| | | |
| | | if (data1.count != 0) { |
| | | if (HLanguageType == 1) { |
| | | Message = data1.data[0].HErrorName; |
| | | } else if (HLanguageType == 2) { |
| | | Message = data1.data[0].HTranslationText_English; |
| | | } else if (HLanguageType == 3) { |
| | | Message = data1.data[0].HTranslationText_Spain; |
| | | } |
| | | } |
| | | }, error: function () { |
| | | layer.alert("接口请求失败!", { icon: 5 }); |
| | | } |
| | | }) |
| | | return Message; |
| | | } |
| | | |