yusijie
8 天以前 24f43454989b92a251d923e23948a9af83485931
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
 
var HModNameData = "";
var HLanguageType_Data = "";
document.addEventListener('click', function (event) {
    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 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);
        }
    }
}
 
//初始化页面加载数据  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());
    });
 
    //表格列数据
    var tableColData = [];
    const tableColDataList = document.querySelectorAll(".layui-table tr span");
    // 遍历元素并获取内容
    tableColDataList.forEach((dd, index) => {
        tableColData.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].innerText.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") {
                    if (data[i].HFieldCode != ".layui-table tr span") {
                        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]].innerText = document.querySelectorAll(data[i].HFieldCode)[indicesList[j]].innerText.replace(data[i].HFieldName, HTranslationText);
                    }
 
                }
            } else {
                if (data[i].HFieldCode != "select option" && data[i].HFieldCode != ".layui-table tr span") {
                    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-table tr span") {
                var indicesData = [];
                var currentIndex = -1;
                while ((currentIndex = tableColData.indexOf(data[i].HFieldName, currentIndex + 1)) !== -1) {
                    indicesData.push(currentIndex);
                }
                if (data[i].HFieldCode != "select option") {
                    for (var j = 0; j < indicesData.length; j++) {
                        document.querySelectorAll(data[i].HFieldCode)[indicesData[j]].innerHTML = document.querySelectorAll(data[i].HFieldCode)[indicesData[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;
}