im_pc_wev8-nw.js
77 KB
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
// 来自pc客户端登陆时,加载完成要做的操作
var pcWindowConfig = {
winMax: false,
shortcut: {
screenshot: null
}
};
var nwgui = window.require('nw.gui');
var node_path = window.require('path');
var appConfig = require(node_path.join(nwgui.__dirname, '/appConfig.json'));
var GLOBAL_INFOS = nwgui.global.GLOBAL_INFOS;
var focusFlag = false;
const _platform = {
Windows: /^win/i.test(process.platform),
OSX: /^darwin/i.test(process.platform),
Linux: /unix/i.test(process.platform)
};
const WindowPlatform = "xp"
//获取当前窗体对象
var currentWindow = nwgui.Window.get();
$(function () {
$('#pcOnTop').hide();//屏蔽窗口前置功能
$('#pc-accountswtichblock').hide();//屏蔽主次账号功能
// 设置ajax全局参数
$.ajaxSetup({
data: {
from: 'pc',
sessionkey: GLOBAL_INFOS.sessionKey,
language: PcMainUtils.userInfos.language
}
});
currentWindow.on('close', function (e) {
var config = PcSysSettingUtils.getConfig();
var noLongerRemind = config.mainPanel.noLongerRemind;
var alwaysQuit = config.mainPanel.alwaysQuit;
if (noLongerRemind) {
if (alwaysQuit) {
PcMainUtils.quitApp();
} else {
PcMainUtils.hiddenToTray();
}
} else {
if ($("#noLongerRemind").length < 1) {
currentWindow.show();
currentWindow.focus();
showQuitDialog();
}
}
e.preventDefault();
});
currentWindow.on('new-win-policy', function (frame, url, policy) {
policy.ignore();
nwgui.Shell.openExternal(url);
});
// 初始化托盘
TrayUtils.init();
//设置页面drag样式
$('#imMainbox').addClass('no-drag');
$('#imDefaultdiv').addClass('can-drag');
// 聊天左侧tabs,有tab的地方不能拖拽,无tab的可以拖拽
$('#imLeftdiv').addClass('can-drag');
$('#chatIMTabs').addClass('no-drag');
$('#imCenterdiv').addClass('no-drag');
$('.addressTitle').addClass('can-drag none-select');
// 初始化PC工具
PcMainUtils.init();
// 获取配置信息
PcSysSettingUtils.init(function () {
// 注册全局快捷键
PcGlobalShortcutUtils.init();
try{
var userConfig = PcSysSettingUtils.getConfig();
if(userConfig.mainPanel.saveLatestChats) {
userConfig.mainPanel.saveLatestChats = true
} else {
userConfig.mainPanel.saveLatestChats = false
}
}catch(err){
userConfig.mainPanel.saveLatestChats = false
}
});
// 窗口最小化
$('#pcMin').click(function () {
currentWindow.minimize();
});
// 窗口最大化
var isMainWinMax = false; // 主窗口是否是最大化
$('#pcMax').click(function () {
isMainWinMax = !isMainWinMax;
if (isMainWinMax) {
currentWindow.maximize();
isMainWinMax = true;
$('#imMainbox').removeClass('imMainbox-p5').addClass("imMainbox-p0");
} else {
//currentWindow.unmaximize();
currentWindow.resizeTo(1053, 627);
currentWindow.moveTo(300, 200);
isMainWinMax = false;
$('#imMainbox').removeClass('imMainbox-p0').addClass("imMainbox-p5");
}
try {
isMainWinMax ? $(this).removeClass('pc-imMaxBtn').addClass('pc-imMaxBtn-re').attr('title', '还原') : $(this).removeClass('pc-imMaxBtn-re').addClass('pc-imMaxBtn').attr('title', '最大化');
} catch (e) {
}
});
// 关闭窗口
$('#pcClose').click(function () {
var config = PcSysSettingUtils.getConfig();
var noLongerRemind = config.mainPanel.noLongerRemind;
var alwaysQuit = config.mainPanel.alwaysQuit;
if (noLongerRemind) {
if (alwaysQuit) {
PcMainUtils.quitApp();
} else {
PcMainUtils.hiddenToTray();
}
} else {
showQuitDialog();
}
});
//聊天窗口获得焦点
currentWindow.on('hide', function () {
currentWindow.blur();
});
currentWindow.on('show', function () {
currentWindow.focus();
});
currentWindow.on('focus', function () {
focusFlag = true;
if (currentWindow) {
var currentTab = getCurrentTab();
var chatWinid = $(currentTab).attr("_chatWinid");
try {
console.log('获取焦点');
//检测是否离线
// ServerExceptionHandling._exeAjax();
var chattype = chatWinid.substring(8, 9);
var targetid = chatWinid.substring(10, chatWinid.length);
client && client.reconnect();//激活后检查链接状态,如果断开重新连接
if(chattype == 7) return;
if(chattype == 8){
sendLocalCountMsg(targetid+"|private");
PrivateUtil.setConnverCache(targetid,false);
return;
}
sendLocalCountMsg(targetid);
ChatUtil.setCurDiscussInfo(targetid, chattype);
// 清理未读数
updateTotalMsgCount(targetid,false,chattype,0);
//消除窗口消息未读提醒
checkReadPosition(chatWinid);
} catch (e) {
console.log('error from pc_focus');
}
TrayUtils.setTrayCommon();
TrayUtils.restoreTray();
}
});
currentWindow.on('blur', function () {
focusFlag = false;
});
// 启动服务器状态监测
ServerExceptionHandling.start();
// 检测服务端版本
//DetectionOfUpgrade.start();
});
// 打开退出按钮确认对话框
function showQuitDialog() {
DragUtils.closeDrags();
var inhtml = '<div class="quitdialog none-select">';
inhtml += ' <div><input type="radio" name="confirmQuit" value="1"/>最小化到托盘</div>';
inhtml += ' <div style="padding-top: 5px;"><input type="radio" name="confirmQuit" value="2" checked="checked" />退出 </div>';
inhtml += ' <div class="noLongerRemind"><input type="checkbox" id="noLongerRemind" name="noLongerRemind" onclick="clickNoLongerRemind(this)" />记住选择,不再提醒</div>';
inhtml += '</div>';
var diag = new window.top.Dialog();
diag.Title = '退出';
diag.Width = 280;
diag.Height = 130;
diag.normalDialog = false;
diag.InnerHtml = inhtml;
diag.OKEvent = function () {
var confirmQuit = $('input[name="confirmQuit"]:checked').val();
var noLongerRemind = $('#noLongerRemind').is(':checked');
if (noLongerRemind) {
var userConfig = PcSysSettingUtils.getConfig();
userConfig.mainPanel.noLongerRemind = true;
userConfig.mainPanel.alwaysQuit = confirmQuit == 1 ? false : true;
PcSysSettingUtils.saveConfig(userConfig);
comfirmDialog(confirmQuit);
} else {
comfirmDialog(confirmQuit);
}
};
diag.CancelEvent = function () {
DragUtils.restoreDrags();
diag.close();
};
diag.show();
$('.quitdialog').jNice();
function comfirmDialog(cq) {
if (cq == 1) {
DragUtils.restoreDrags();
diag.closeManual();
setTimeout(function () {
PcMainUtils.hiddenToTray();
}, 100)
} else {
PcMainUtils.quitApp();
}
}
// 带上这个checkbox才能点,不知道为什么!!
function clickNoLongerRemind(obj) { }
}
// 打开设置对话框
function openSysSetting() {
DragUtils.closeDrags();
var diag = new window.top.Dialog();
diag.Title = '系统设置';
diag.Width = 570;
diag.Height = 420;
diag.normalDialog = false;
diag.ShowButtonRow = false;
diag.URL = '/social/im/SocialIMPcSysSetting.jsp?d=' + new Date().getTime();
diag.closeHandle = function () {
DragUtils.restoreDrags();
};
diag.show();
}
// 取消所有发送和接收文件夹
function stopDirSending() {
try {
PcSendDirUtils.cancelAllSend();
PcSendDirUtils.cancelAllReceive();
PcSendDirUtils.stopServer();
} catch (e) {
console.error("!!没有开启文件和文件夹传输功能!!");
}
}
// 工具
var PcMainUtils = {
userInfos: GLOBAL_INFOS.userInfos,
appPath: GLOBAL_INFOS.appPath,
platform: _platform,
localconfig: null,
pcUtils: null,
// 初始化
init: function () {
this.localconfig = window.require(node_path.join(GLOBAL_INFOS.appPath, '/localconfig.js'));
this.pcUtils = window.require(node_path.join(GLOBAL_INFOS.appPath, '/pcUtils.js'));
},
// 判断用户操作系统类型
isWindows: function () {
return this.platform.Windows;
},
isOSX: function () {
return this.platform.OSX;
},
isLinux: function () {
return this.platform.Linux;
},
getOSType: function () {
var osType = 1;
if (this.isOSX()) {
osType = 2;
} else if (this.isLinux()) {
osType = 3;
}
return osType;
},
// 阻塞程序numberMillis毫秒数
sleep: function (numberMillis) {
var now = new Date();
var exitTime = now.getTime() + numberMillis;
while (true) {
now = new Date();
if (now.getTime() > exitTime) return;
}
},
// 最小化到托盘
hiddenToTray: function () {
if (this.isWindows()) {
currentWindow.hide();
} else if (this.isOSX()) {
currentWindow.minimize();
}
},
// 退出前的一些列操作
beforeQuitApp:function(callback){
try {
// 取消所有下载
PcDownloadUtils.abortAllDl();
stopDirSending();
if (client) {
M_ISFORCEONLINE = true;
client.disconnect();
}
// 设置pc端为未登陆状态。
$.ajax({
async: false,
url: '/social/im/ServerStatus.jsp?p=logout',
timeout: 200
});
} catch (error) {
}
typeof callback ==="function" && callback();
},
// 退出程序
quitApp: function () {
this.beforeQuitApp();
nwgui.App.quit();
},
// 注销
logout: function () {
var _this = this;
_this.localconfig.setLogout(true, function () {
_this.quitApp();
});
},
// 判断路径是否是一个文件
isFile: function (filepath) {
const fs = window.require('fs');
var stats = fs.statSync(filepath);
return stats.isFile();
},
isExistFile: function (path, callback) {
const fs = window.require('fs');
fs.exists(path, callback);
},
getFinalFilePath : function (path, cb) {
var _this = this;
PcMainUtils.isExistFile(path, function (flag) {
if (flag) {
var newPath = "";
var fileName = node_path.basename(path);
var filePath = node_path.dirname(path);
var pre = fileName.substring(0, fileName.lastIndexOf('.'));
var last = fileName.substring(fileName.lastIndexOf('.'), fileName.length);
if (pre.lastIndexOf('(') != -1 && pre.lastIndexOf(')') != -1) {
var num = pre.substring(pre.lastIndexOf('(') + 1, pre.lastIndexOf(')'));
num = parseInt(num) + 1;
var preFirst = pre.substring(0, pre.lastIndexOf('('));
newPath = node_path.join(filePath, preFirst + '(' + num + ')' + last);
} else {
pre += '(1)';
newPath = node_path.join(filePath, pre + last);
}
_this.getFinalFilePath(newPath, cb);
} else {
cb(path);
}
});
},
// 获取用户配置信息,callback(error, config)
getSetting: function (callback) {
this.localconfig.get(GLOBAL_INFOS.userInfos,function(error,config){
typeof callback == "function" && callback(config);
});
},
// 保存用户配置信息
setSetting: function (config,callback) {
this.localconfig.set(GLOBAL_INFOS.userInfos,config,callback);
},
// 获得当前版本信息
getVersion: function () {
return this.pcUtils.getBuildVersion(GLOBAL_INFOS.appPath);
},
clearCache:function(callback){
//清理缓存的时候关闭图片浏览窗口
if (ImageViewPageUtil._currentTipWindow) {
ImageViewPageUtil._currentTipWindow.close();
}
var userConfig = PcSysSettingUtils.getConfig();
nwgui.App.unregisterGlobalHotKey(nwgui.Shortcut({ key: userConfig.shortcut.screenshot }));
nwgui.App.unregisterGlobalHotKey(nwgui.Shortcut({ key: userConfig.shortcut.openAndHideWin }));
nwgui.App.clearCache();
currentWindow.reload();
typeof callback =="function" && callback();
},
log :function(content){
},
// 根据判断构建版本是否支持 0 表示确定每个版本都支持, -1 表示都不支持
checkVersion: function (buildVersion, osxVersion) {
return false
}
};
// 获取文档宽高
var documentUtils = {
width: function () {
return $(document).width();
},
height: function () {
return $(document).height();
}
};
// 关闭和打开其他可拖拽属性。
// 打开一个对话框或者弹出操作层时,首先关闭页面其他可拖拽属性,在操作完成或关闭对话框时,再恢复可拖拽。
var DragUtils = {
_canDrags: null,
closeDrags: function () {
var $imSlideDiv = $('#imSlideDiv')
if (this._canDrags == null && $imSlideDiv.css('display') == 'none') {
this._canDrags = $('.can-drag');
this._canDrags.removeClass('can-drag');
}
},
restoreDrags: function () {
var $imSlideDiv = $('#imSlideDiv')
if (this._canDrags != null && $imSlideDiv.css('display') == 'none') {
this._canDrags.addClass('can-drag');
this._canDrags = null;
}
}
};
// 设置有未读消息时托盘图标闪动。
// 规则:只要有未读消息,就闪动图标。当没有未读时取消闪动。
var TrayUtils = {
_isBusying: false,
_isOffline: false,
_currentWin: currentWindow,
_username: M_USERNAME, // 用户名
init: function () {
this.setTrayTooltip('状态:在线');
this.setTrayCommon();
},
// 托盘图标变成正常
setTrayCommon:function(){
opener.TrayUtils.setTrayCommon();
},
hasUnreadMsg: function () {
var count = 0;
$('.msgcount').each(function (i) {
var c = $(this).html();
if (c != '') {
count += parseInt(c);
}
});
return count > 0;
},
flashingTray: function () {
if (!isCurrentWindowFocused()) {
this._currentWin.requestAttention(true);
}
if (!isCurrentWindowFocused() && this._isBusying == false) {
this._isBusying = true;
opener.TrayUtils.setTrayBusy();
}
},
restoreTray: function () {
if (this._isBusying) {
this._isBusying = false;
opener.TrayUtils.setTrayCommon();
}
if(this._isOffline) {
if(SOCIAL_GLOBAL.OnlineStatus.M_ONLINESTATUS[M_USERID]!=undefined){
try{
var status = SOCIAL_GLOBAL.OnlineStatus.M_ONLINESTATUS[M_USERID].pc;
if(status==undefined) status='online';
}catch(err){
var status = "online";
}
this.setTrayTooltip('状态:'+ONLINESTATUS[status]);
}else{
this.setTrayTooltip('状态:在线');
}
this._isOffline = false;
opener.TrayUtils.setTrayCommon();
}
},
offlineTray : function(){
if (!this._isOffline) {
this.setTrayTooltip('状态:离线');
this._isOffline = true;
this._isBusying = false;
opener.TrayUtils.setTrayOffline();
}
},
setTrayTooltip: function (msg) {
opener.TrayUtils.setToolTip('e-message-xp\r\n用户:' + this._username + '\r\n' + msg );
},
showTrayBalloon: function (title, content) {
var notif = showNotification(title, content);
setTimeout(function () {
notif.close();
}, 1200);
},
clickTrayShowWin:function(){
$('.imToptab').find('[_target="recent"]').click();
}
};
// 截屏工具
var ScreenshotUtils = {
/*
*是否是e-message截图获取到的图片
*/
isScreenshot:false,
// 执行截图
screenshot: function (obj) {
clearTimeout(ScreenshotUtils.pasteTimeout);
var flag = false;
nwgui.Clipboard.get().clear();
this.isScreenshot = true;
if(ChatUtil.isScreenShotMinimize == 1){
windowUtil._hide();
flag = true;
}
setTimeout(function(){
nwgui.Shell.openItem(node_path.join(GLOBAL_INFOS.appPath, '/extension/screenshot/CaptureImageTool.exe'));
if(flag){
setTimeout(function(){
windowUtil._show();
},2000);
}
ScreenshotUtils.pasteSetTimeout();
},400)
},
checkClipData:function(){
return !!nwgui.Clipboard.get().get('png');
},
timeOutCount:30,
pasteTimeout:null,
pasteSetTimeout:function(){
ScreenshotUtils.pasteTimeout = setTimeout(function(){
if(ScreenshotUtils.isScreenshot && ScreenshotUtils.checkClipData()){
clearTimeout(ScreenshotUtils.pasteTimeout);
ScreenshotUtils.timeOutCount = 30;
ScreenshotUtils.isScreenshot = false;
var $chatwin = ChatUtil.getCurChatwin();
if($chatwin.length > 0) {
var $chatContent = $chatwin.find('.chatcontent');
if($chatContent) {
$chatContent.focus();
document.execCommand('paste')
}
}
}else{
if(ScreenshotUtils.timeOutCount-->0){
ScreenshotUtils.pasteSetTimeout();
}
}
},1000);
},
};
// 提醒弹窗工具
var RemindTipUtils = {
showRemindTip: function (tipInfo) {
AppTipWindowUtil.showAppTipWindow(tipInfo);
}
};
// 判断当前窗口是否获取焦点,返回true标识获得焦点,否则返回false
function isCurrentWindowFocused() {
return focusFlag;
};
//图片全屏预览
var ImageReviewForPc = {
// 预览图片。imgIndex:第一个图片的下标。imgSrcArray:图片src数组。
show: function (imgIndex, imgSrcArray) {
ImageViewPageUtil.showImageViewWindow({ imgIndex: imgIndex, imgSrcArray: imgSrcArray });
},
// 关闭预览窗口
close: function () {
var win = ImageViewPageUtil._currentTipWindow;
if (win != null) {
win.close();
}
}
};
// 监测服务器是否异常并重连
var ServerExceptionHandling = {
// 配置参数
option: {
commonMonitoringTime: 1000 * 60 * 3, // 3分钟钟发送一次请求进行监测
reLinkTime: 1000 * 30, // 断线后,系统30秒钟进行一次重连
serverPage: GLOBAL_INFOS.currentHost + '/social/im/ServerStatus.jsp'
},
start: function () {
var _this = this;
$(document)
.ajaxSuccess(function (evt, request, settings) {
_this._handleSuccess(request.responseText);
})
.ajaxError(function (event, XMLHttpRequest, ajaxOptions, thrownError) {
console.info(thrownError);
});
},
_hasHandWorked: false, //是否触发了手工重连
handworkRelink: function () {
var _this = this;
_this._hasHandWorked = true;
ReconAnimationUtils.updateRelinkInfo(2, '正在尝试建立连接...');
$.ajax({
url: _this.option.serverPage + '?p=e&d=' + new Date().getTime(),
success: function (data) {
_this._handleSuccess(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
ReconAnimationUtils.updateRelinkInfo(3, '与服务器连接故障,请稍候重试');
}
});
},
// 设置定时监测
_isErroring: false, //是否检测到服务器故障
_monitoringHandle: null, //监测服务器状态定时器
_initMonitoring: function () {
var _this = this;
if (!_this._isErroring) {
_this._exeAjax();
clearInterval(_this._monitoringHandle);
_this._monitoringHandle = setInterval(function () {
_this._exeAjax();
console.log('检查服务器状态 ' + new Date());
}, _this.option.commonMonitoringTime);
}
},
_reLinking: false, //是否正在重连
_reLinkHandle: null, //正在重连定时器
_sysRelinkMsgShowHandle: null, //系统重连时提醒信息更新定时器
_initReLink: function () {
var _this = this;
_this._reLinking = true;
clearTimeout(_this._reLinkHandle);
_this._reLinkHandle = setTimeout(function () {
_this._exeAjax(); //第一次先执行一次
_this._reLinkHandle = setTimeout(arguments.callee, _this.option.reLinkTime);
}, _this.option.reLinkTime);
},
// 设置系统重连时信息展示
_setSysRelinkMsgShowHandle: function () {
var _this = this;
var time = 30;
var count = 1;
ReconAnimationUtils.updateRelinkInfo(0, '与服务器连接中断<br/><span>' + time + '</span>秒之后进行第<span>1</span>次连接');
time--;
_this._sysRelinkMsgShowHandle = setInterval(function () {
if (!_this._hasHandWorked) {
var mm = time;
if (time < 10) {
mm = '0' + time
}
var msg = '与服务器连接中断<br/><span>' + mm + '</span>秒之后进行第<span>' + count + '</span>次连接';
ReconAnimationUtils.updateRelinkInfo(0, msg);
time--;
if (time == 0) {
time = 30;
count++;
}
}
}, 1000);
},
_clearSysRelinkMsgShowHandle: function () {
clearInterval(this._sysRelinkMsgShowHandle);
this._sysRelinkMsgShowHandle = null;
},
// 执行服务器状态监测或重连
_exeAjax: function () {
var _this = this;
var serverUrl = _this.option.serverPage + '?d=' + new Date().getTime() + "&from=pc";
serverUrl += _this._isErroring ? '&p=e' : '&p=n';
$.ajax({
url: serverUrl,
success: function (data) {
_this._handleSuccess(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// _this._handleError();
console.info(thrownError);
}
});
},
// 通用ajax重连成功处理
_handleSuccess: function (data) {
var _this = this;
// 其他客户端上线,提示退出
if (!_this._isErroring && data == 'RepeatLanding') {
_this._isErroring = true;
M_ISFORCEONLINE = true;
DragUtils.closeDrags();
currentWindow.show();
Dialog.confirm('用户在其他地方登陆,点击重连重新登录', function () {
$.ajax({
global: false,
async: false,
url: _this.option.serverPage + '?d=' + new Date().getTime(),
data: {
from: 'pc',
sessionkey: GLOBAL_INFOS.sessionKey,
pcReLogin: 'true',
userid: M_USERID
},
success: function (data) {
M_ISFORCEONLINE = false;
client && client.reconnect();
DragUtils.restoreDrags();
_this._isErroring = false;
},
error: function () {
Dialog.alert('重连失败,服务器异常,请重新登录', function () {
PcMainUtils.logout();
});
}
});
}, function () {
PcMainUtils.quitApp();
}, null, null, true, null, '重连', '退出');
}
else if (!_this._isErroring && data == 'reConnectError') {
_this._isErroring = true;
DragUtils.closeDrags();
Dialog.alert('服务端重连异常,点击确定退出', function () {
PcMainUtils.quitApp();
});
}
else if (_this._reLinking && _this._isErroring) {
// 取消重连
clearInterval(_this._reLinkHandle);
_this._reLinking = false;
_this._reLinkHandle = null;
// 恢复状态
_this._clearSysRelinkMsgShowHandle();
_this._hasHandWorked = false;
// 恢复监测
_this._isErroring = false;
_this._initMonitoring();
TrayUtils.restoreTray();
// 关闭遮罩提示 TODO
ReconAnimationUtils.close();
// 恢复和融云的连接
M_ISFORCEONLINE = false;
client && client.reconnect();
currentWindow.requestAttention(true);
}
},
// 通用ajax错误处理
_handleError: function () {
var _this = this;
if (!_this._isErroring && !_this._reLinking) {
// 关闭监测
_this._isErroring = true;
clearInterval(_this._monitoringHandle);
_this._monitoringHandle = null;
TrayUtils.offlineTray();
// 打开遮罩提示 TODO
ReconAnimationUtils.showRelink();
// 设置信息提醒
_this._setSysRelinkMsgShowHandle();
// 开始重连
_this._initReLink();
// 关闭和融云的连接
M_ISFORCEONLINE = true;
client && client.disconnect();
currentWindow.requestAttention(true);
}
}
};
// 断线展示效果工具
var ReconAnimationUtils = {
_config: {
type_1: '/offline-1.png', //系统重连时图片
type_2: '/offline-2.png', //手工重连中图片
type_3: '/offline-3.png', //手工重连失败时图片
type_1_data: '',
type_2_data: '',
type_3_data: ''
},
// 打开重连界面效果
showRelink: function (reLinkcb) {
var html = '<div class="pc-recon can-drag">';
html += ' <div class="pc-recon-message no-drag">';
html += ' <div class="header">连接故障</div>';
html += ' <div class="center">';
html += ' <div class="center-img"><img src="" /></div>';
html += ' <div class="center-msg"></div>';
html += ' </div>';
html += ' <div class="footer">';
html += ' <input type="button" class="task-relink" value="重连" />';
html += ' <input type="button" class="task-close" value="退出" />';
html += ' </div>';
html += ' </div>';
html += '</div>';
$('body').append(html);
$('.pc-recon').css('width', documentUtils.width()).css('height', documentUtils.height());
$('.task-relink').click(function(){
if(typeof reLinkcb ==="function"){
reLinkcb();
}else{
ServerExceptionHandling.handworkRelink();
}
});
$('.task-close').click(function(){
PcMainUtils.quitApp();
});
this._config.type_1_data = LocalImagesUtils.getDataUrl(this._config.type_1);
this._config.type_2_data = LocalImagesUtils.getDataUrl(this._config.type_2);
this._config.type_3_data = LocalImagesUtils.getDataUrl(this._config.type_3);
$('.pc-recon').fadeIn(500);
},
// 更新中部文字提示内容
updateRelinkInfo : function(type, msg){
var _this = this;
if(type == 0) {
$('.center-img').find('img').attr('src', _this._config.type_1_data);
} else if(type == 2) {
$('.center-img').find('img').attr('src', _this._config.type_2_data);
$('.center-msg').addClass('center-msg-hand');
_this._setTaskRelinkStatus(false);
} else if(type == 3) {
$('.center-img').find('img').attr('src', _this._config.type_3_data);
$('.center-msg').addClass('center-msg-hand');
_this._setTaskRelinkStatus(true);
}
$('.center-msg').html(msg);
},
// 关闭重连
close: function(){
$('.pc-recon').fadeOut(1000, function(){
$(this).remove();
});
},
// 设置重试按钮的可操作状态
_setTaskRelinkStatus : function(flag){
var $taskBtn = $('.task-relink');
if(flag) {
$taskBtn.removeClass('pc-disabled').removeAttr('disabled');
} else {
$taskBtn.addClass('pc-disabled').attr('disabled', 'disabled');;
}
}
};
// 获得本地图片的工具类
var LocalImagesUtils = {
// imgFile为本地应用defaul_app/web_contents/images路径下的文件路径,
getDataUrl: function (imgFile) {
var localImagesDir = node_path.join(GLOBAL_INFOS.appPath, '/web_contents/images');
var nativeImage = 'file://' + localImagesDir + imgFile;
return nativeImage;
}
};
// 外部链接:首页、邮件、博客等的打开(调用本地浏览器打开url)
var PcExternalUtils = {
// urlType :连接类型
//0 站内链接(拼oa地址);1 站外链接(无需拼接);2 单点登录(暂时不管)
openUrlByLocalApp : function(url, urlType){
if(!url) return;
urlType = urlType || 0;
var finalUrl = null;
var querystring = window.require('querystring');
var host = GLOBAL_INFOS.currentHost;
var sessionkey = GLOBAL_INFOS.sessionKey;
if(urlType == 0) {
finalUrl = host + '/social/im/epcforword.jsp?';
finalUrl += 'from=pc&external=true&sessionkey=' + sessionkey;
finalUrl += '&url=' + querystring.escape(url);
}
else if(urlType == 1) {
if(url.substring(0, 4).toLowerCase() !== 'http') {
finalUrl = 'http://' + url;
} else {
finalUrl = url;
}
}
else if (urlType == 2) {
var newurl = '/interface/Entrance.jsp?id=' + querystring.escape(url)
finalUrl = host + '/social/im/epcforword.jsp?';
finalUrl += 'from=pc&external=true&sessionkey=' + sessionkey;
finalUrl += '&url=' + querystring.escape(newurl);
}
if(finalUrl) {
if(urlType != 1) {
ServerExceptionHandling._exeAjax(); //如果是打开内部链接,先发送服务器执行一次更新事件
}
setTimeout(function () {
var shell = nwgui.Shell;
shell.openExternal(finalUrl);
}, 200);
}
}
};
// 主聊天窗口任务栏进度展示工具
var ProgressBarUtils = {
_currentWin :currentWindow,
setPb : function(pb){
if(PcMainUtils.isWindows()){
this._currentWin.setProgressBar(pb);
}
},
endPb : function(){
if(PcMainUtils.isWindows()){
var _this = this;
_this._currentWin.setProgressBar(1.0);
setTimeout(function(){
_this._currentWin.setProgressBar(-1);
}, 500);
}
},
setToIndeterminateMode : function(){
if(PcMainUtils.isWindows()){
this._currentWin.setProgressBar(1.1);
}
},
setToNomal : function(){
if(PcMainUtils.isWindows()){
this._currentWin.setProgressBar(-1);
}
}
};
// PC下载工具
var PcDownloadUtils = {
creatNewDownload: function (data) {
var _this = this;
if (_this.eDownloadList[data.url]) {
return;
}
_this.startDownload(data);
},
eDownloadList : {}, // 正在下载的文件
eDownload : window.require('ding-download').Download,
imDownloader : null,
// 开始一个下载任务
startDownload : function(config){
console.log('启动一个新下载');
var _this = this;
try {
var dlUrl = config.url;
var filePath = config.filePath;
var querystring = window.require('querystring');
var fileid = querystring.parse(dlUrl.substring(dlUrl.indexOf('?') + 1))['fileid'];
var item = config.item;
var fileSize = (config.size == 0 || typeof config.size === "undefined") ? _this._getfileSize(fileid) : config.size;
TrayUtils.showTrayBalloon('正在下载文件...', filePath);
var sessionkey = GLOBAL_INFOS.sessionKey;
var finalUrl = dlUrl + '&from=pc&op=download&sessionkey=' + sessionkey;
var newDlObj = null;
try{
if(!_this.imDownloader){
_this.imDownloader = window.require('downloader');
}
newDlObj = new _this.imDownloader();
}catch (e){
newDlObj = null;
console.error(e);
}
if(newDlObj){//新下载组件
newDlObj.on('done', function(msg, status) {
// console.log('done===========',msg);
FileDownloadViewUtils.setButton(fileid, filePath,fileSize);
_this._endDownload(dlUrl, filePath);
FileDownloadViewUtils.updateViewProgressBar(fileid, 1);
if(status === 'aborted') {
TrayUtils.showTrayBalloon(social_i18n('Dltip9'), filePath);
FileDownloadViewUtils.updateViewProgressBar(fileid, -1);
FileDownloadViewUtils.restoreButton(fileid);
} else {
TrayUtils.showTrayBalloon(social_i18n('Dltip7'), filePath);
// 保存路径到服务端
_this.recordLastsavepath(fileid, filePath);
}
});
newDlObj.on('error', function(error) {
console.log('error===========',error);
if(error && error.code == 'EPERM'){
_this._endDownload(dlUrl, filePath);
_this.willdownload(item, false, true);
alert(social_i18n("Dltip11"));
}else{
_this._endDownload(dlUrl, filePath);
TrayUtils.showTrayBalloon(social_i18n('Dltip8'), filePath);
FileDownloadViewUtils.updateViewProgressBar(fileid, -1);
FileDownloadViewUtils.restoreButton(fileid);
}
});
newDlObj.on('progress', function(percent, currentsize, totalsize) {
console.log('progress============'+percent+' '+currentsize+' '+totalsize);
ProgressBarUtils.setPb(percent);
FileDownloadViewUtils.updateViewProgressBar(fileid, percent);
});
newDlObj.download(finalUrl, filePath, fileSize);
}else {
newDlObj = new _this.eDownload(finalUrl, filePath);
newDlObj.contentSize = parseInt(fileSize);
newDlObj.on('info', function(arg1){
//console.debug('fileid = ' + fileid + ' info = ' + arg1);
ProgressBarUtils.setToIndeterminateMode();
});
newDlObj.on('progress', function(arg1, arg2, arg3){
//console.log('progress = ' + arg1 + ' ' + arg2 + ' ' + arg3);
ProgressBarUtils.setPb(arg1);
FileDownloadViewUtils.updateViewProgressBar(fileid, arg1);
});
newDlObj.on('finish', function (arg1, arg2, arg3) {
//console.debug('fileid = ' + fileid + ' finish');
FileDownloadViewUtils.setButton(fileid, filePath);
_this._endDownload(dlUrl);
TrayUtils.showTrayBalloon('文件下载完成', filePath);
// 保存路径到服务端
_this.recordLastsavepath(fileid, filePath);
});
newDlObj.on('error', function (error) {
//console.debug('fileid = ' + fileid + ' error');
console.info(error);
// error
if (error && error.code == 'EPERM') {
alert("您没有该目录的操作权限");
_this._endDownload(dlUrl);
_this.willdownload(item, false, true);
} else {
_this._endDownload(dlUrl);
TrayUtils.showTrayBalloon('文件下载失败', filePath);
PcExternalUtils.openUrlByLocalApp(finalUrl,0);
FileDownloadViewUtils.updateViewProgressBar(fileid, -1);
FileDownloadViewUtils.restoreButton(fileid);
}
});
_this.eDownloadList[dlUrl] = { fileid: fileid, dlObj: newDlObj };
}
} catch (e) {
console.log(e);
_this._endDownload(config.url);
PcExternalUtils.openUrlByLocalApp(finalUrl,0);
}
},
// 取消所有下载
abortAllDl : function(){
var _this = this;
for(var p in _this.eDownloadList) {
_this.eDownloadList[p].dlObj.abort();
}
},
// 结束下载
_endDownload : function(dlUrl){
this._sendDlComplete(dlUrl);
delete this.eDownloadList[dlUrl];
delete this.DownloadItems[dlUrl];
ProgressBarUtils.endPb();
},
// 获取文件大小
_getfileSize : function(fileid){
var fileSize = $('div.accitem[_fileid="' + fileid + '"]').attr('_filesize');
if(typeof fileSize == 'undefined') {
$.ajax({
gloab: false,
async: false,
url : '/social/im/SocialImPcUtils.jsp',
data : {
method : 'getFileSize',
fileid : fileid
},
success : function(data){
data = $.trim(data);
fileSize = parseInt(data);
},
error : function(){
fileSize = 0;
}
});
}
return fileSize;
},
_sendDlComplete : function(dlUrl){
delete this.DownloadItems[dlUrl];
},
// 记录下载路径
recordLastsavepath: function(fileId, filePath){
var valuses=[M_USERID, fileId, filePath];
webSql.insert("insert into social_FileDownloadLog(userid, fileid, lastsavepath) values(?,?,?)",valuses);
DownloadSet[fileId] = filePath;
},
DownloadItems: {},
// 初始化下载设置
willdownload: function (item, isDefPath, isResetPath) {
var url = item.url;
var filename = item.filename;
var fileSize = item.totalbytes;
var _this = this;
if (_this.DownloadItems[url]) {
Dialog.alert('该文件正在下载');
return;
}
var downloadConfig = PcSysSettingUtils.getConfig().download;
var defaultDlPath = downloadConfig.defaultPath, nonePath = false;
if (!defaultDlPath || defaultDlPath == '') {
// 路径为空时,走else代码逻辑,并在点击确定时提示是否设置当前目录为默认下载目录
nonePath = true;
}
if (isDefPath && !nonePath && !isResetPath) {
// 如果配置了默认保存路径,那么不弹出保存对话框,直接保存文件到默认路径。
var fse = require('fs-extra');
var index = filename.lastIndexOf('.');
var name = PcMainUtils.isWindows() ? filename.substring(0, index) : filename;
var ext = filename.substring(index);
fse.ensureDir(defaultDlPath, function (err) {
if (err) {
console.error("当前默认路径已失效且没有创建文件夹权限,请重新设置默认文件传输路径", err)
_self.willdownload(item, isDefPath, true);
return true;
};
var dlObj = {
url: url,
filePath: node_path.join(defaultDlPath, filename),
ext: ext,
size: fileSize
};
// 检测文件是否存在
PcMainUtils.getFinalFilePath(dlObj.filePath, function(finalName){
if(finalName){
dlObj.filePath = finalName;
_this.creatNewDownload(dlObj);
_this.DownloadItems[url] = true;
}
});
});
} else {
var index = filename.lastIndexOf('.');
var name = PcMainUtils.isWindows() ? filename.substring(0, index) : filename;
var ext = filename.substring(index);
nwdialog.setContext(document.getElementById("downloadFrame").contentWindow.document);
nwdialog.saveFileDialog(filename, ext, function (filepn) {
if (filepn) {
var dlObj = {
url: url,
filePath: filepn,
ext: ext,
size: fileSize
};
_this.creatNewDownload(dlObj);
_this.DownloadItems[url] = true;
}
if (nonePath || isResetPath) {
Dialog.alert('请到右下角设置界面设置文件传输目录再使用此功能!');
}
})
}
}
};
// 下载文件时 进度条 及 按钮设置
var FileDownloadViewUtils = {
// 更新下载进度条
updateViewProgressBar : function(fileid, progress){
var $fileDiv = $('div.accitem[_fileid="' + fileid + '"]');
if($fileDiv.length > 0) {
var $pcFileDlBar = $fileDiv.find('.pc-fileDlBar');
if($pcFileDlBar.length > 0) {
var $barDiv = $pcFileDlBar.find('.progress-bar');
if (progress == 1) {
setTimeout(function(){
$pcFileDlBar.hide();
$barDiv.width('0%');
}, 300);
} else if(progress == -1) {
$pcFileDlBar.hide();
$barDiv.width('0%');
} else {
$pcFileDlBar.show();
var pro = progress.toFixed(2) * 100 + '%';
$barDiv.width(pro);
}
}
}
},
setButtonCon: function(container,fileid,filepath){
var _this = this;
var $fileBtn = container.hasClass("opdiv")? container: container.find('a.opdiv[_fileid="' + fileid + '"]');
var filename = $fileBtn.attr('_filename');
var optiondiv = $fileBtn.parent();
var opendir = $("<a>打开文件夹</a>");
var openfile = $("<a>打开文件</a>");
opendir.attr(
{
'id': 'pc-opendir' + fileid,
'class': 'opdir opdiv',
'_fileid':fileid,
'_filename':filename
}).css('cursor','pointer').click(function(){
_this.openFilepath(fileid, filepath, 0);
});
openfile.attr(
{
'id': 'pc-openfile' + fileid,
'class': 'opfile opdiv pc-openfile',
'_fileid': fileid,
'_filename': filename
}).click(function(){
_this.openFilepath(fileid, filepath, 1);
});
optiondiv.empty().append(openfile).append(opendir);
return container;
},
// 下载完成,设置'下载'按钮为'打开文件'和'打开文件夹'
setButton : function(fileid, filepath){
var _this = this;
var $fileBtn = $('a.opdiv[_fileid="' + fileid + '"]');
if($fileBtn.length == 0) {
return;
}
_this.setButtonCon($fileBtn, fileid, filepath);
},
// '打开文件','打开文件夹'按钮事件
openFilepath : function(fileid, filepath, openFile){
var _this = this;
const fs = require('fs');
fs.exists(filepath, function (exists) {
const shell = nwgui.Shell;
if(exists) {
if(openFile) {
shell.openItem(filepath);
} else {
shell.showItemInFolder(filepath);
}
} else {
if(openFile){
showImAlert('文件不存在,请重新下载');
}else{
showImConfirm('文件不存在,是否继续打开文件夹?', function(){
shell.showItemInFolder(filepath);
});
}
_this.restoreButton(fileid);
}
});
},
// 恢复按钮为'下载'
restoreButton : function(fileid){
var $fileBtn = $('a.opfile[_fileid="' + fileid + '"]');
var $fileDir = $('a.opdir[_fileid="' + fileid + '"]')
if($fileBtn.length > 0) {
$fileBtn.unbind('click').click(function(){
downAccFile(this, true);
}).html('接收');
}
if($fileDir.length > 0) {
$fileDir.unbind('click').click(function(){
downAccFile(this);
}).html('另存为');
}
}
};
RongErrorUtils = {
isErroring : false,
autoReCount : 3,
autoReHandle : null,
errorCount:3,//服务都正常,但是就是连接失败的情况
startRecon : function(){//连接失败就是检查端口
var _this = this;
if(!M_ISFORCEONLINE&&!_this.isErroring){
_this.isErroring=true;
NetworkListenerUtils._showHandleRelink();
}
},
reConTimeout : 5, // 重连间隔,5秒
reConHandle : null,
_config : {
type_1 : '/offline-1.png', //系统重连时图片
type_1_data: '',
},
// 打开重连界面效果
showRelink : function(){
var _this = this;
var html = '<div class="pc-recon can-drag">';
html += ' <div class="pc-recon-message no-drag">';
html += ' <div class="header">连接故障</div>';
html += ' <div class="center">';
html += ' <div class="center-img"><img src="" /></div>';
html += ' <div class="center-msg">连接e-message-xp服务器故障<br/><span id="rong-recon-s1">5</span>秒之后进行第<span id="rong-recon-s2">1</span>次连接</div>';
html += ' </div>';
html += ' <div class="footer">';
html += ' <input type="button" class="rong-task-close" value="退出" />';
html += ' </div>';
html += ' </div>';
html += '</div>';
$('body').append(html);
$('.pc-recon').css('width', documentUtils.width()).css('height', documentUtils.height());
$('.rong-task-close').click(function(){
PcMainUtils.quitApp();
});
_this._config.type_1_data = LocalImagesUtils.getDataUrl(this._config.type_1);
$('.center-img > img').attr('src', this._config.type_1_data);
var rtime = _this.reConTimeout;
var rcount = 1;
var $rongspn1 = $('#rong-recon-s1');
var $rongspn2 = $('#rong-recon-s2');
_this.reConHandle = setInterval(function(){
$rongspn1.html(--rtime);
if(rtime == 0) {
rtime = _this.reConTimeout;
$rongspn1.html(rtime);
$rongspn2.html(++rcount);
}
}, 1000);
$('.pc-recon').fadeIn(500);
},
close: function(){
clearInterval(this.reConHandle);
this.reConHandle = null;
this.isErroring = false;
this.errorCount = 3;
$('.pc-recon').fadeOut(1000, function(){
$(this).remove();
});
},
_exeReCon : function(){
try {
client && client.reconnect(); // 客户端重连
M_ISRECONNECT = false; // !!
console.info('尝试重连。。。');
} catch(e) {
console.info('重连错误');
console.info(e);
}
}
};
// 检测服务器版本
var DetectionOfUpgrade = {
detectionFrequency : 1000 * 60 * 60 * 5, //5小时检测一次服务器版本
nowVersion : null,
isReminding : false,
execHandle : null,
start : function(){
console.info('启动服务端版本监测定时器');
var _this = this;
_this.nowVersion = PcMainUtils.getVersion();
if(_this.nowVersion) {
_this.execHandle = setInterval(function(){
if(!_this.isReminding) {
_this.execDetection();
}
}, _this.detectionFrequency);
} else {
console.info('检测升级程序异常,未能启动');
}
},
execDetection : function(){
var _this = this;
console.info('检测服务端版本');
$.ajax({
url : '/social/im/ServerStatus.jsp?p=getVersion',
dataType : 'json',
success : function(data){
console.info(data);
var flag = true;
if(PcMainUtils.isWindows()) {
flag = _this.nowVersion.buildVersion == data.buildversion;
} else if(PcMainUtils.isOSX()) {
flag = _this.nowVersion.osxBuildVersion == data.osxBuildVersion;
}
if( !flag ) {
_this.isReminding = true;
clearInterval(_this.execHandle);
var obj = {
currentHost : GLOBAL_INFOS.currentHost,
sessionKey : GLOBAL_INFOS.sessionKey,
newBuildVersion : {
buildVersion : data.buildversion,
osxBuildVersion : data.osxBuildVersion
}
};
DragUtils.closeDrags();
Dialog.alert('检测到有新版本,点击确定进行升级', function(){
PcMainUtils.localconfig.setLogoutThenUpgrade(obj, function(){
PcMainUtils.logout();
});
});
}
}
});
}
};
// userConfig
var PcSysSettingUtils = {
_configs : null,
// 初始化配置信息
init : function(callback){
var _this = this;
var localconfig = nwgui.global.GLOBAL_INFOS.userConfig;
// 对本地特殊设置的处理
var autoLogin = localconfig.login.autoLogin;
$.post('/social/im/SocialImPcUtils.jsp', { method : 'getUserSysConfig', osType : PcMainUtils.getOSType() }, function(data){
if(data.isSuccess) {
_this._configs = $.extend(localconfig, data.config);
// 一些特殊值以客户端为准
_this._configs.login.autoLogin = localconfig.login.autoLogin;
} else {
_this._configs = localconfig;
}
// 对3版本未升级到4版本时的特殊处理
if(!_this._configs.msgAndRemind) {
_this._configs.msgAndRemind = {newMsg:false, wfRemind:true, mailRemind:true, audioSet:{all:false, persion:false, group:false, broadcast:false}};
}
if(!_this._configs.skin) {
_this._configs.skin = "default";
}
// 对本地特殊设置的处理
_this._configs.login.autoLogin = autoLogin;
//截图最小化设置
ChatUtil.isScreenShotMinimize = typeof _this._configs.isScreenShotMinimize ==='undefined'?0:_this._configs.isScreenShotMinimize;
//保存配置信息更改
_this.saveConfig(_this.getConfig());
typeof callback === 'function' && callback(_this._configs);
}, 'json');
},
// 获取当前配置信息
getConfig : function(callback){
if(this._configs == null) {
this.init(function(){
if(typeof callback == 'function')
callback();
});
PcMainUtils.sleep(500);
}
return this._configs;
},
// 保存配置信息
saveConfig: function (config, callback) {
var _this = this;
var cb = typeof callback === 'function' ? callback : function () { };
//保存到本地
PcMainUtils.setSetting(config);
_this._saveConfigToOA(callback); //保存到服务端
_this._configs = config;
},
_saveConfigToOA : function(callback){
var userConfig = JSON.stringify(this.getConfig());
$.post('/social/im/SocialImPcUtils.jsp', { method : 'saveUserSysConfig', osType : PcMainUtils.getOSType(), config : userConfig },function(){
typeof callback === 'function' && callback();
});
}
};
// 新消息到达直接打开窗口
function openWindowWhenNewMsg() {
var config = PcSysSettingUtils.getConfig();
if(config.msgAndRemind.newMsg && !isCurrentWindowFocused()) {
var win = currentWindow;
win.show();
win.focus();
}
}
/*-------------------------------- app start --------------------------------*/
/*-------------------------------- 消息提醒小窗口工具 start --------------------------------*/
var AppTipWindowUtil = {
_currentTipWindow: null,
_messageQueue: new Array(), // 提醒消息队列
_pushInQueue: function (args) {
this._messageQueue.unshift(args);
},
_popFromQueue: function () {
return this._messageQueue.pop();
},
// 初始化提醒窗口
initAppTipWindow: function (data) {
var primaryDisplay = nwgui.Screen.screens.length > 0 ? nwgui.Screen.screens[0] : null;
var winWidth = appConfig.windowSize.appTipWin.width;
var winHeight = appConfig.windowSize.appTipWin.height;
var offsetX = primaryDisplay.work_area.width - winWidth;
var offsetY = primaryDisplay.work_area.height - winHeight;
var _this = this;
var appTipWindowoption = {
width: winWidth,
height: winHeight,
x: offsetX - 20, // 额外加边距,
y: offsetY,
focus: true,
resizable: false,
frame: false,
transparent: GLOBAL_INFOS.isAeroGlassEnabled
};
var htmlFile = '/web_contents/remind/remind.html';
//document-start 不适用本地页面
appTipWindow = nwgui.Window.open(htmlFile, appTipWindowoption, function (win) {
win.window.remindData = data;
win.setShowInTaskbar(false);
win.setAlwaysOnTop(true);
if(GLOBAL_INFOS.isMinVersion){
win.window.opener = window;
}
win.on('loaded', function () {
_this._currentTipWindow = win.window;
});
win.on('closed', function (event) {
_this._currentTipWindow = null;
if (_this._messageQueue.length > 0) {
setTimeout(_this._executeShow(), 1000 * 3)
}
});
});
// 注册 打开工具栏快捷键
// registerWindowShortcut(appTipWindow);
},
// 打开提醒窗口
showAppTipWindow: function (args) {
var _this = this;
//加入消息
_this._pushInQueue(args);
if(!this._currentTipWindow&&_this._messageQueue.length == 1) {
_this._executeShow();
}
},
// 如果还有队列,3秒后打开下一条提醒。
showNextTip : function(){
var _this = this;
if(_this._messageQueue.length > 0) {
setTimeout(function(){
_this._executeShow();
}, 1000 * 3);
}
},
//展示消息,并去掉最后一个
_executeShow: function () {
var _this = this;
_this.initAppTipWindow(_this._popFromQueue());
}
};
/*-------------------------------- 消息提醒小窗口工具 end --------------------------------*/
var nwdialog = {
_context: typeof global.DOMDocument === 'undefined' ? document : global.DOMDocument,
setContext: function(context) {
this._context = context;
},
openFileDialog: function(filter, multiple, workdir, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'open-file-dialog';
node.style = 'display: none';
if (typeof filter === 'function') {
fn = filter;
} else if (typeof filter === 'string') {
node.setAttribute('accept', filter);
} else if (typeof filter === 'boolean' && filter === true) {
node.setAttribute('multiple', '');
} else if (this.isArray(filter)) {
node.setAttribute('accept', filter.join(','));
}
if (typeof multiple === 'function') {
fn = multiple;
} else if (typeof multiple === 'string') {
node.setAttribute('nwworkingdir', multiple);
} else if (typeof multiple === 'boolean' && multiple === true) {
node.setAttribute('multiple', '');
}
if (typeof workdir === 'function') {
fn = workdir;
} else if (typeof workdir === 'string') {
node.setAttribute('nwworkingdir', workdir);
}
this._context.body.appendChild(node);
node.addEventListener('change', function(e) {
fn(node.value);
node.remove();
});
node.click();
},
saveFileDialog: function(name, accept, directory, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'save-file-dialog';
node.style = 'display: none';
node.setAttribute('nwsaveas', '');
if (typeof name === 'function') {
fn = name;
} else if (typeof name === 'string') {
node.setAttribute('nwsaveas', name);
}
if (typeof accept === 'function') {
fn = accept;
} else if (typeof accept === 'string') {
node.setAttribute('accept', accept);
} else if (this.isArray(accept)) {
node.setAttribute('accept', accept.join(','));
}
if (typeof directory === 'function') {
fn = directory;
} else if (typeof directory === 'string') {
node.setAttribute('nwworkingdir', directory);
}
this._context.body.appendChild(node);
node.addEventListener('change', function() {
fn(node.value);
node.remove();
});
node.click();
},
folderBrowserDialog: function(workdir, callback) {
var fn = callback;
var node = this._context.createElement('input');
node.type = 'file';
node.id = 'folder-browser-dialog';
node.style = 'display: none';
node.nwdirectory= true;
if (typeof workdir === 'function') {
fn = workdir
} else if (typeof workdir === 'string') {
node.setAttribute('nwworkingdir', workdir);
}
this._context.body.appendChild(node);
node.addEventListener('change', function() {
fn(node.value);
node.remove();
});
node.click();
},
isArray: function(value) {
return Object.prototype.toString.call(value) === '[object Array]';
}
};
/*-------------------------------- 图片浏览窗口 start --------------------------------*/
var ImageViewPageUtil = {
_currentTipWindow: null,
initImageViewPage: function (imgInfos) {
var _this = this;
var screenSize = nwgui.Screen.screens.length > 0 ? nwgui.Screen.screens[0].bounds : null;
var imageViewWindowoption = {
width: Math.round(screenSize.width * 0.8),
height: Math.round(screenSize.height * 0.8),
focus: true,
position: 'center',
resizable: false,
frame: false,
transparent: GLOBAL_INFOS.isAeroGlassEnabled
};
var url = GLOBAL_INFOS.currentHost + '/social/im/imageReview-nw.jsp?from=pc&frompc=true';
nwgui.Window.open(url, imageViewWindowoption, function (win) {
win.on("document-start", function () {
_this._currentTipWindow = win;
if(GLOBAL_INFOS.isMinVersion){
win.window.opener = window;
}
})
win.on('closed', function (event) {
_this._currentTipWindow = null;
});
win.on('loaded', function () {
_this._currentTipWindow = win.window;
win.window.pluginImageViewHtmlFile(imgInfos);
});
});
},
showImageViewWindow: function (imgInfos) {
var _this = this;
if (_this._currentTipWindow == null) {
_this.initImageViewPage(imgInfos);
} else {
_this._currentTipWindow.pluginImageViewHtmlFile(imgInfos);
}
}
};
/*-------------------------------- 图片浏览窗口 end --------------------------------*/
//
// 全局快捷键相关
var GlobalShortMethods = {
SCREENSHOT: 'screenshot',
OPENDEVPTOOL: 'openDevpTool',
OPENANDHIDEWIN: 'openAndHideWin',
CLOSEALLCHATWIN: 'closeAllChatWin',
CLOSECHATWIN: 'closeChatWin'
};
var PcGlobalShortcutUtils = {
// 初始化
init: function () {
var _this = this;
var userConfig = PcSysSettingUtils.getConfig();
if (PcMainUtils.isWindows()) {
var screenshot = userConfig.shortcut.screenshot;
GlobalShortcutUtils.register(screenshot, screenshot, GlobalShortMethods.SCREENSHOT);
pcWindowConfig.shortcut.screenshot = screenshot;
_this.setScreenshotTitle();
}
var openAndHideWin = userConfig.shortcut.openAndHideWin;
GlobalShortcutUtils.register(openAndHideWin, openAndHideWin, GlobalShortMethods.OPENANDHIDEWIN);
},
setScreenshotTitle: function () {
if (PcMainUtils.isWindows() && pcWindowConfig.shortcut.screenshot) {
$('[type="screenshot_div"]').attr('title', '截图(' + pcWindowConfig.shortcut.screenshot + ')');
}
},
isRegistered: function (screenshotNew) {
return (GLOBAL_INFOS.userConfig.shortcut.screenshot == screenshotNew) || (GLOBAL_INFOS.userConfig.shortcut.openAndHideWin == screenshotNew);
},
// 执行注册,注册成返回true,冲突或失败返回false
execRegister : function(oldKey, newKey, execMethodName){
return GlobalShortcutUtils.register(oldKey, newKey, execMethodName);
}
};
/*-------------------------------- 注册快捷键 start --------------------------------*/
var shortCut = {
key: "CTRL+Q",
active: function () {
},
failed: function (msg) {
console.log(msg);
}
};
var GlobalShortcutUtils = {
// 注册快捷键
register: function (oldKey, newKey, methodName) {
try {
if (!methodName || !GlobalShortcutUtils[methodName] || !newKey) {
return false;
}
if (oldKey) {
this.unRegister(oldKey);
}
if (newKey) {
shortCut.key = newKey;
shortCut.active = function () {
GlobalShortcutUtils[methodName].apply(null, []);
};
nwgui.App.registerGlobalHotKey(nwgui.Shortcut(shortCut));
}
return true;
} catch (e) {
console.info(e);
return false;
}
},
// 移除快捷已被注册
unRegister: function (accelerator) {
nwgui.App.unregisterGlobalHotKey(nwgui.Shortcut({ key: accelerator }));
},
// 截图
screenshot: function () {
ScreenshotUtils.screenshot();
},
// 呼入和隐藏聊天窗口
openAndHideWin: function () {
var chatWin = currentWindow;
if (chatWin) {
if (focusFlag) {
chatWin.hide();
} else {
chatWin.show();
}
}
},
// 打开调试工具
openDevpTool: function () {
// 只有在sdk的情况有用
currentWindow.showDevTools();
},
// 关闭所有聊天窗口
closeAllChatWin: function() {
var chatWin = currentWindow;
if (chatWin) {
var chatWin = currentWindow;
if (chatWin &&focusFlag) {
ChatWinUtils.closeallchatwin();
}
}
},
// 关闭聊天窗口
closeChatWin: function() {
var chatWin = currentWindow;
if (chatWin &&focusFlag) {
ChatWinUtils.closeChatWin();
}
}
};
/*-------------------------------- 注册快捷键 end --------------------------------*/
// 抖动窗口
var ShakeWindowUtils = {
loginTime: new Date().getTime(),
lastShakeTime: {}, // 给不同的人抖动要单独计时
dwellTime: 1000 * 10, //抖动间隔,10秒钟
sendShakeMessage: function (obj) {
var _this = this;
var nowTime = new Date().getTime();
var $chatWin = ChatUtil.getchatwin(obj);
var toUserId = $chatWin.attr('_targetid');
if (!_this.lastShakeTime[toUserId] || (nowTime - _this.lastShakeTime[toUserId] > _this.dwellTime)) {
var msgid = IMUtil.guid();
var sendTime = new Date().getTime();
var data = {
pushType: 'weaver_shakeMsg',
objectName: 'FW:CustomMsg',
msgType: 6,
sendTime: sendTime,
targetid: toUserId,
targetType: 'FW:CustomMsg'
};
ChatUtil.sendIMMsg($chatWin.find(".chatSend"), data.msgType, data, function (msg) {
if (msg.issuccess == 1) {
_this.lastShakeTime[toUserId] = sendTime;
_this.shakeWindow(false);
_this._playShakeAudio();
} else {
ChatUtil.postNotice("发送了窗口抖动失败", obj);
}
});
} else {
IM_Ext.showMsg("抖动过频");
}
},
shakeWindow: function (showWindow, extraObj, senderInfo) {
var win = currentWindow;
if (showWindow) {
var pushType = extraObj.pushType;
if (pushType != 'weaver_shakeMsg') {
return;
}
var sendTime = extraObj.sendTime;
var senderUserid = senderInfo.userid;
if (sendTime - this.loginTime < 1000 * 60 * 60 * 24) {
win.show();
win.focus();
$('#conversation_' + senderUserid).click();
}
}
clearInterval(timer);
var i = 0;
var timer = setInterval(function () {
i++;
win.x = win.x + ((i % 2) > 0 ? -7 : 7);
//win.setBounds(tempBounds);
if (i >= 10) {
clearInterval(timer);
}
}, 60);
this._playShakeAudio();
},
_playShakeAudio: function () {
var playAudio = true;
// pc端,更具配置判断是否有提示音
var config = PcSysSettingUtils.getConfig();
if (config.msgAndRemind.audioSet.all) {
playAudio = false;
}
if (playAudio) {
var audio = document.getElementById('pcShakeWinAudio');
//audio.play();
}
}
};
/*-------------------------------- 桌面通知 气泡start --------------------------------*/
// NW.JS Notification气泡
var showNotification = function (title, body) {
// if (icon && icon.match(/^\./)) {
// icon = icon.replace('.', 'file://' + process.cwd());
// }
var notification = new Notification(title, { body: body });
notification.onclick = function () {
};
notification.onclose = function () {
};
notification.onshow = function () {
};
return notification;
}
/*-------------------------------- 桌面通知 气泡end --------------------------------*/
/*-------------------------------- app end --------------------------------*/
/*-------------------------------- 聊天窗口工具 --------------------------------*/
var ChatWinUtils = {
/*
*关闭所有会话窗口
*/
closeallchatwin:function(){
var self = this;
DragUtils.closeDrags();
var closeBtns = $('#chatIMTabs').find('.tabClostBtn');
var len = closeBtns.length;
if(len > 0) {
if(self.isShowing) return;
self.isShowing = true;
Dialog.confirm('是否关闭所有聊天窗口?', function(){
DragUtils.restoreDrags();
self.isShowing = false;
setTimeout(function(){
var BusyOptions = self.checkChatWinBusy();
if(BusyOptions.isBusy){
var busyWinIds = BusyOptions.busyWinIds;
var allWinIds = BusyOptions.allWinIds;
self.closeChatWinBatch(busyWinIds, allWinIds);
}else{
var allWinIds = BusyOptions.allWinIds;
while(allWinIds.length > 0) {
var nextWinId = allWinIds.pop();
self.closeChatWin(nextWinId, event);
self.isShowing = false;
}
}
}, 20);
}, function(){
self.isShowing = false;
});
}
},
/*
*关闭当前会话窗口
*/
closechatwin:function(){
var self = this;
DragUtils.closeDrags();
var closeBtns = $('#chatIMTabs').find('.tabClostBtn');
var len = closeBtns.length;
if(len > 0) {
if(self.isShowing) return;
self.isShowing = true;
Dialog.confirm('是否关闭所有聊天窗口?', function(){
DragUtils.restoreDrags();
self.isShowing = false;
setTimeout(function(){
var BusyOptions = self.checkChatWinBusy();
if(BusyOptions.isBusy){
var busyWinIds = BusyOptions.busyWinIds;
var allWinIds = BusyOptions.allWinIds;
self.closeChatWinBatch(busyWinIds, allWinIds);
}else{
var allWinIds = BusyOptions.allWinIds;
while(allWinIds.length > 0) {
var nextWinId = allWinIds.pop();
self.closeChatWin(nextWinId, event);
self.isShowing = false;
}
}
}, 20);
}, function(){
self.isShowing = false;
});
}
},
closeChatWinBatch: function(busyWinIds, allWinIds){
var self = this;
if(busyWinIds.length > 0) {
var nextWinId = busyWinIds.pop();
changeTabWin($('#chatIMTabs').find("[_chatwinid='"+nextWinId+"']").get(0));
IMUtil.removeArray(allWinIds, nextWinId);
self.isShowing = true;
PcMainUtils.showConfirm('当前窗口正在操作,是否强制关闭?', null, {
'confirm': function(){
self.closeChatWin(nextWinId, event);
self.isShowing = false;
self.closeChatWinBatch(busyWinIds,allWinIds);
},
'cancel': function(){
self.isShowing = false;
self.closeChatWinBatch(busyWinIds,allWinIds);
}
});
}else{
while(allWinIds.length > 0){
var winId = allWinIds.pop();
self.closeChatWin(winId, event);
}
}
},
// 关闭
closeChatWin: function(chatwinid, evt){
var tabObj = $('#chatIMTabs').find("[_chatwinid='"+chatwinid+"']");
closeTabWin(tabObj);
},
// 检查窗口正在上传文件
checkChatWinBusy: function(chatWinId){
var self = this;
var ret = {isBusy: false, busyWinIds: [], allWinIds: []};
if(chatWinId){
var isBusy = self._getBusyStatus(chatWinId);
ret = {isBusy: isBusy, busyWinIds: isBusy?[chatWinId]:[], allWinIds: [chatWinId]};
}else{
var chatwins = $('#chatIMdivBox').find('.chatWin');
for(var i = 0; i < chatwins.length; ++i){
var winid = $(chatwins[i]).attr('id');
var isBusy = self._getBusyStatus(winid);
if(isBusy){
ret.isBusy = true;
ret.busyWinIds.push(winid);
}
ret.allWinIds.push(winid);
}
}
return ret;
},
// 获取窗口状态
_getBusyStatus: function(chatWinId){
var isBusy = false;
if($('#'+chatWinId+'_SUC').children().length > 0) {
isBusy = true;
}
var chatcontentDiv = $('#'+chatWinId).find('.chatcontent');
if(chatcontentDiv.length > 0 && chatcontentDiv.html().length > 0) {
isBusy = true;
}
return isBusy;
},
// 检查窗口正在输入
checkChatWinTyping: function(obj){
var chatTabDiv = $(obj).closest('.chatIMTabItem');
var chatWinId = chatTabDiv.attr('_chatwinid');
var flag = false;
// 判断是否正在输入
var chatcontentDiv = $('#'+chatWinId).find('.chatcontent');
if(chatcontentDiv.length > 0 && chatcontentDiv.html().length > 0) {
flag = true;
}
return flag;
}
};
var windowUtil = {
_isAlwaysOnTopFlag: false,//标识
_currentWin: currentWindow,
_isAlwaysOnTop: function(){
return this._currentWin.isAlwaysOnTop;
},
_hide:function(){
this._currentWin.hide();
},
_show:function(){
this._currentWin.show();
}
}
/*-------------------------------- 重连工具start --------------------------------*/
/*
*网络监测工具
*/
var NetworkListenerUtils ={
_hostName:window.location.hostname,//oa地址
_hostPort:window.location.port==""?80:window.location.port,//oa端口
//打开手动重连
_showHandleRelink:function(){
ReconAnimationUtils.showRelink(this._handleConnect);
ReconAnimationUtils.updateRelinkInfo(3, '连接emessage故障');
},
//手动重连
_handleConnect:function(){
ReconAnimationUtils.updateRelinkInfo(2, '正在尝试建立连接...');
getTokenOfOpenfire(function(data){
if(!data == ""){
M_ISFORCEONLINE = false;
client && client.reconnect(function(info){
if(!info){
ReconAnimationUtils.updateRelinkInfo(3, '连接emessage故障');
}
});
}else{
ReconAnimationUtils.updateRelinkInfo(3, '连接emessage故障');
}
},function(){
ReconAnimationUtils.updateRelinkInfo(3, '连接emessage故障');
},function(){
ReconAnimationUtils.updateRelinkInfo(3, '连接emessage故障');
});
},
// 扫描主机端口连通性
_scan: function(succCb, failCb, host){
var _this = this;
var defaultTestIp = _this._hostName;
var defaultTestPort =_this._hostPort;
host = host?host:{};
var hostip = host.ip?host.ip:defaultTestIp;
var hostport = host.port?host.port:defaultTestPort;
var scan = window.nw.require('net-scan');
scan.port({
host: hostip,
ports: [hostport],
timeout: 2000
}, function(err, result) {
if(result.length ==1){
typeof succCb ==='function' && succCb();
}else{
typeof failCb ==='function' && failCb();
}
});
},
// 重连提示
_countDown: function(title, time, func) {
var _this = this;
var tips = title+"("+time+")";
ReconAnimationUtils.showRelink();
ReconAnimationUtils.updateRelinkInfo(1, tips);
TrayUtils.flashingTray();
setInterval(function(){
if(time>=0){
var msg = title+"("+time+")";
ReconAnimationUtils.updateRelinkInfo(1, msg);
time--;
}else{
func && func();
}
}, 1000);
}
}
/*-------------------------------- 重连工具end --------------------------------*/
/*-------------------------------- 聊天窗口工具 --------------------------------*/
//xp版本不做窗口分离
var WindowDepartUtil = {
isAllowWinDepart : function(){
return false;
},
tabIsNull : function(){
return false;
}
};