index.js
71.4 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
dayjs.extend(dayjs_plugin_localizedFormat)
dayjs.extend(dayjs_plugin_relativeTime)
const { toRefs, nextTick, toRef } = Vue
function compareTimeArray(obj1, obj2, key, sort) {
const val1 = obj1[key]
const val2 = obj2[key]
let result = 0
if (dayjs(val1).isBefore(dayjs(val2))) {
result = sort === 0 ? -1 : 0
} else if (dayjs(val1).isAfter(dayjs(val2))) {
result = sort === 0 ? 0 : -1
}
return result
}
const app = Vue.createApp({
setup() {
const baseNode = ref(window.config.VUE_BASE_NODE)
const deviceType = ref(judgTerminal() === 1 ? 'ad' : 'ios')
const time = ref('')
const recordTime = ref()
const channelId = ref()
const loginTime = ref()
const statrTime = ref(dayjs())
const subjectList = ref([])
const channelList = ref([])
const suggestedList = ref([])
const voteOtions = ref([])
const canSeeBtnOne = ref(true)
const canSeeBtnTwo = ref(true)
const hasReadCount = ref(true)
const networkStatus = ref(1) // 0 无网络 1 wifi 2,3,4,5 无wifi状态
const networkSwitch = ref(2) // 1 允许 2 不允许
const browseCnt = ref('0') // 外部音频点击暂停次数
const audioState = ref(0) // 外部音频点击暂停次数
const loadlmageOnlyWifiSwitch = ref(window.config.VUE_BASE_NODE === 'dev' ? '2' : '0') // 1 仅wifi加载图片 2 都可以加载图片
const showClook = ref(false)
const optionList = ref([])
const clookStatusSee = ref(false)
const clookCancelBtnActive = ref(false)
const clookBtnActive = ref(false)
const hasHeadLink = ref(false)
const voteInit = ref(false)
const isPageLeave = ref(false)
const hasInit = ref(false)
const shareOpen = ref(false)
const isOwer = ref(false)
const isRmh = ref(null)
const isNewspaper = ref(null)
const browseStr = ref('')
const state = reactive({
clientHeight: 0,
appFontSize: 'normalsize',
// appFontSize: 'Large',
// appFontSize: 'large',
// appFontSize: 'small',
//投票id
darkMode: darkMode,
voteId: null,
relId: null,
contentId: null,
sourcePage: '2',
//环境
environment: 'sit',
showShare: false,
//请求头
appHeader: shallowMerge({
system: judgTerminal() === 1 ? 'Android' : 'ios'
}, window.config.VUE_BASE_HEADER),
initialRes: {},
originDataSource: {},
//此details对接口返回的数据进行了二次改造,属性的添加和属性值的转换
details: {
rmhInfo: null,
author: [],
newLinkObject: {},
//投票信息
voteInfo: {},
endTimePoint: false,
yes: {},
no: {},
slideShows: {},
//片头跳转
headLinkdata: ''
},
initClockStatus: false,
shareNewPoster: true,
voteState: {
// status: 1,
// optionId: '7323',
status: 0,
optionId: ''
},
creatorID: null,
curIndex: 0,
bcIndex: 0,
Doing: false,
isLogined: 0, // 0 未登录 1 已登录
isSub: false,
isSubClose: false,
seeEmailSub: false,
strategy: {},
emailVal: '',
deviceId: '',
userId: '',
aboutUserName: '',
agreementURL: '',
recomList: []
})
const timeLine = reactive({
title: '',
topicId: '',
topicType: '',
pageId: '',
linkUrl: '',
slideColor: '#ED2800',
data: []
})
const actieInfo = reactive({
show: false,
id: -1,
title: '',
type: '',
linkUrl: '',
coverUrl: ''
})
const {
initEditorStr,
refreshEditorStr
} = useEditorContent(
toRef(state, 'details'),
networkStatus,
audioState,
loadlmageOnlyWifiSwitch,
recordTime
)
recordTime.value = dayjs()
changeContentHtmlHeight({ str: '.skeleton-loading' })
try {
sendNative('jsCall_currentPageOperate', {
operateType: '48'
}, () => {
})
} catch (e) {}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 工具函数
*/
const errorResponse = () => clearInterval(time.value)
const removeHtmlStr = (str) => {
if (!str) return str
return str.replace(/<br\s*\/?>/g, '')
}
function shallowMergeObj(target, ...sources) {
const newTarget = deepCopy(target)
sources.forEach(source => {
for (let key in source) {
if (source.hasOwnProperty(key)) {
newTarget[key] = source[key]
}
}
})
return newTarget
}
// 模拟App加载错误
function changeAppError() {
console.log(null.replace(/<img(.*?)src="(.*?)"(.*?)>/g, '<img$1src="" data-src="$2"$3>'))
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 主流程
*/
if (window.config.VUE_BASE_NODE === 'dev') {
mountedFun(() => {
if (!window.config.VUE_CONTENT_CONFIG && !window.config.devApp) {
requestDev()
}
})
} else {
mountedFun(() => {})
}
function mountedFun(callbakc) {
if (!slow) {
fast = true
if (callbakc) callbakc()
}
}
function requestDev(devApp) {
state.clientHeight = document.documentElement.getBoundingClientRect().height
clientHeight = state.clientHeight
time.value = setInterval(() => {
if (window.config.initLoad) {
state.darkMode = darkMode
document.querySelector('#app').style.overflowY = 'auto'
document
.querySelector('html')
.setAttribute('dark-mode', darkMode === 'dark')
appFontSize = state.appFontSize
setRemUnit(state.appFontSize)
// document.documentElement.setAttribute('data-size', state.appFontSize)
state.environment = window.config.VUE_BASE_HEADER.environment
// channelId.value = 2038
// state.relId = 500005771692
state.contentId = 30046970836
contentId = state.contentId
clearInterval(time.value)
setTimeout(() => {
initData(devApp ? window.config.VUE_CONTENT_CONFIG : {}, state.contentId, devApp)
}, devApp ? 10 : 0)
}
}, 10)
}
const requestApp = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
requestDev(true)
return
}
document.querySelector('.error-block').style.display = 'none'
setRemUnit()
/* config数据是由H5预埋,App加载完成后 app主动传递的方法名请求数据 */
const config = window.config.VUE_CONTENT_CONFIG
try {
const data =
typeof config === 'object' ? config : JSON.parse(config)
const dataJson = handleAppData(config)
if (dataJson) {
state.sourcePage = dataJson.sourcePage
clearInterval(time.value)
// console.log(`详情接口完成:${dayjs().format('HH:mm:ss:SSS')} - ${dayjs()
// .diff(recordTime.value, 'millisecond')} - ${dayjs()
// .diff(firstTime, 'millisecond')}`)
recordTime.value = dayjs()
changeContentHtmlHeight({ str: 'body', type: 'init' })
const netError = dataJson.netError
contentId = dataJson.contentId
state.contentId = dataJson.contentId
channelId.value = dataJson.channelId
if (netError == 0) {
// 异步获取App公共信息
try {
sendNative('jsCall_getAppPublicInfo', {}, header => {
// app返回的数据
const headerObj =
typeof header === 'object' ? header : JSON.parse(header)
state.appHeader = deepCopy(headerObj)
//通用设备imei
state.deviceId = state.appHeader.device_id
state.userId = state.appHeader.userId
// App服务协议
state.agreementURL = state.appHeader.agreementURL
//0:无网 1:Wi-Fi 2:2G 3:3G 4:4G 5:5G
// networkStatus.value = state.appHeader.networkStatus
//prod、sit、dev、uat
state.environment = state.appHeader.environment
})
} catch (e) {
}
try {
getClickStatus(() => {})
} catch (e) {}
try {
if (data.dataExt) {
hasAppLoginExtra = true
const extraData = typeof data.dataExt === 'object'
? data.dataExt
: JSON.parse(data.dataExt)
darkMode = extraData ? extraData.darkMode || darkMode : darkMode
state.darkMode = darkMode
document
.querySelector('html')
.setAttribute('dark-mode', darkMode === 'dark')
state.appFontSize = extraData ? extraData.fontSizes : ''
state.clientHeight = extraData ? extraData.clientHeight : ''
clientHeight = state.clientHeight
// document.documentElement.setAttribute('data-size', state.appFontSize)
appFontSize = state.appFontSize
setRemUnit(state.appFontSize)
state.cnsTraceId = extraData ? extraData.cnsTraceId : ''
state.creatorID = extraData ? extraData.creatorId : ''
state.isLogined = extraData ? extraData.isLogin : ''
// 0:无网 1:WiFi 2:2G 3:3G 4:4G 5:5G
networkStatus.value = extraData ? extraData.networkStatus || 1 : 1
loadlmageOnlyWifiSwitch.value = extraData && extraData.loadImageOnlyWifiSwitch
? extraData.loadImageOnlyWifiSwitch
: '0'
}
} catch (e) {
}
// 处理详情
mainProcessProgress['3'] = {
status:'success',
message: '准备调用:initData方法'
}
initData(handleAppDetails(dataJson.responseMap), dataJson.contentId)
} else {
errorResponse()
errorBlock(
'./image/no_net.svg',
'网络出小差了,请检查网络后重试',
true
)
}
} else {
errorResponse()
errorBlock(
'./image/no_net.svg',
'网络出小差了,请检查网络后重试',
true
)
}
} catch (e) { }
}
const initData = async (res, id, devApp) => {
/**判断是否为本地开发环境,是的话初始化数据,不是的话通过app提供的方法,h5发送数据给app**/
if (window.config.VUE_BASE_NODE === 'dev') {
if (devApp || window.config.devApp) {
const details = res.data ? res.data.length > 0 ? res.data[0] : {} : {}
mainProcessProgress['1'] = {
status:'success',
message: 'App给到的数据',
appData: res
}
hasDetails = true
mainProcessProgress['4'] = {
status:'success',
message: '准备调用:handleArticle方法'
}
handleArticle(details)
return
}
const response = await axiosRequest({
url: '/content/zh/c/content/detail',
methot: 'get',
appStatus: false,
// isMock: true,
// weakNetwork: true,1
// mockTimeOut: 10,
//环境
environment: state.environment,
//接口前缀
prefix: '/api/rmrb-bff-display-zh',
//给接口传的数据
params: {
contentId: id,
relId: state.relId
},
//请求头信息
headers: state.appHeader
})
// console.log(`详情接口完成:${dayjs().format('HH:mm:ss:SSS')} - ${dayjs()
// .diff(recordTime.value, 'millisecond')} - ${dayjs().diff(dayjs(firstTime), 'millisecond')}`)
recordTime.value = dayjs()
if (response.success) {
if (response.data) {
const details = response.data.length > 0 ? response.data[0] : {}
mainProcessProgress['1'] = {
status:'success',
message: 'App给到的数据',
appData: response
}
hasDetails = true
mainProcessProgress['4'] = {
status:'success',
message: '准备调用:handleArticle方法'
}
handleArticle(details)
} else {
errorResponse()
errorBlock(
'./image/content_fail.svg',
'内容找不到了'
)
}
} else {
errorResponse()
errorBlock(
'./image/content_fail.svg',
'获取内容失败,请重试',
true
)
}
} else {
if ([ 200, '0' ].includes(res.code) > 0) {
if (res.data) {
const details = res.data.length > 0 ? res.data[0] : {}
hasDetails = true
// 获取用户登录状态
if (hasAppLoginExtra) {
mainProcessProgress['4'] = {
status:'success',
message: '准备调用:handleArticle方法'
}
handleArticle(details)
} else {
// const nowDate = dayjs()
// console.log('获取app登录状态开始:')
try {
sendNative('jsCall_getAppLoginAuthInfo', {}, res => {
// console.log('获取app登录状态结束:', `${dayjs()
// .diff(nowDate, 'millisecond')}`)
// 获取登录状态响应
const loginStatusResponse =
typeof res === 'object' ? res : JSON.parse(res)
state.creatorID = loginStatusResponse && loginStatusResponse.creatorID
state.isLogined =
loginStatusResponse && loginStatusResponse.isLogined
mainProcessProgress['4'] = {
status:'success',
message: '准备调用:handleArticle方法'
}
handleArticle(details)
})
} catch (e) { }
}
} else {
errorResponse()
errorBlock(
'./image/content_fail.svg',
'内容找不到了'
)
}
} else {
errorResponse()
errorBlock(
'./image/content_fail.svg',
'获取内容失败,请重试',
true
)
}
}
}
const handleArticle = (details) => {
if (Object.keys(details).length === 0) {
errorResponse()
errorBlock(
'./image/content_fail.svg',
'获取内容失败,请重试'
)
return
}
contentId = state.contentId
isRmh.value = !!details.rmhInfo
isNewspaper.value = details.isNewspaper
if (!details.rmhInfo) {
browseCntChange(details)
}
state.showShare = true
state.details = deepCopy(details)
state.originDataSource = deepCopy(details)
if (window.config.VUE_BASE_NODE === 'dev') {
mainProcessProgress['5'] = {
status:'success',
message: '准备调用:initApp方法'
}
initApp(details)
} else {
mainProcessProgress['5'] = {
status:'success',
message: '准备调用:initApp方法'
}
initApp(details)
try {
// H5传递数据至App
sendNative(
'jsCall_receiveH5Data',
{ dataSource: '1', dataJson: JSON.stringify(state.originDataSource) },
() => {
}
)
} catch (e) { }
}
}
const initApp = data => {
getOthersStatus(data, () => {
if (data.authorList && data.authorList.length > 0) {
//authorList:图文【撰稿人,对应p端创建人名称;人民号内容为空】
const authorList = deepCopy(data.authorList).filter(item => item.authorName) || []
state.details.author = []
authorList.forEach(el => {
if (el.authorName) {
const modifiedString = el.authorName.replace(/\s+/g, ',')
const authorNameList = modifiedString.split(',')
if (authorNameList.length > 1) {
authorNameList.forEach(name => state.details.author.push(name))
} else {
state.details.author.push(el.authorName)
}
}
})
}
if (data.newLinkObject && data.newLinkObject.newsTitle) {
// state.details.newLinkObject.newsTitle = data.newLinkObject.newsTitle.replace(/ /g, ' ')
// state.details.newLinkObject.newsTitle = data.newLinkObject.newsTitle.replace(/—/g, '<span class="global-line"></span>')
hasHeadLink.value = true
}
if (data.newsShortTitle) {
// state.details.newsShortTitle = data.newsShortTitle.replace(/ /g, ' ')
// state.details.newsShortTitle = data.newsShortTitle.replace(/—/g, '<span class="global-line"></span>')
}
if (data.newsTitle) {
// state.details.newsTitle = data.newsTitle.replace(/ /g, ' ')
// state.details.newsTitle = data.newsTitle.replace(/—/g, '<span class="global-line"></span>')
}
if (data.newsDownTitle) {
// state.details.newsDownTitle = data.newsDownTitle.replace(/—/g, '—')
// state.details.newsDownTitle = data.newsDownTitle.replace(/—/g, '<span class="global-line"></span>')
}
if (data.newIntroduction) {
// state.details.newIntroduction = data.newIntroduction.replace(/—/g, '—')
// state.details.newIntroduction = data.newIntroduction.replace(/—/g, '<span class="global-line"></span>')
}
// 首次发布时间:publishTime
state.details.publishTime = data.publishTime
? dayjs(data.publishTime).format('YYYY年MM月DD HH:mm')
: ''
subjectList.value = data.subjectList
? data.subjectList.map(el => el.name).filter(el => el)
: []
channelList.value = data.channelList
? data.channelList.map(el => el.channelName).filter(el => el)
: []
// headLinkdata:片头跳转
state.details.headLinkdata =
data.newLinkObject && data.newLinkObject.headLinkdata
? data.newLinkObject.headLinkdata
: ''
shareOpen.value = state.details.shareInfo ? state.details.shareInfo.shareOpen == 1 : false
hasInit.value = true
if (pageError) {
changeAppError()
}
mainProcessProgress['7'] = {
status:'success',
message: '准备调用:initEditorStr方法'
}
initEditorStr(isNewspaper.value)
})
}
const getClickStatus = (callback) => {
if (window.config.VUE_BASE_NODE === 'dev') {
} else {
try {
sendNative(
'jsCall_getArticleDetailBussinessData',
{
//写死为1
getSharePosterShowNew: '1',
getLoadImageOnlyWifiSwitch: '1',
getPlayVideoOnCellularNetworkSwitch: '1'
},
res => {
let objNvtSwt = res ? res : {}
let lastObjNvtSwt =
typeof objNvtSwt === 'object'
? objNvtSwt
: JSON.parse(objNvtSwt)
// loadlmageOnlyWifiSwitch.value = lastObjNvtSwt.loadImageOnlyWifiSwitch
state.shareNewPoster = lastObjNvtSwt.sharePosterShowNew == '1'
networkSwitch.value =
lastObjNvtSwt.playVideoOnCellularNetworkSwitch // 蜂窝数据播放 1 允许 2 不允许
callback && callback()
}
)
} catch (e) { }
}
}
const browseCntChange = (details) => {
if (details.viewCount) {
browseStr.value = ''
browseCnt.value = details.viewCount ? `${handleNum(details.viewCount)}` : '0'
if (browseCnt.value && ![ '0', 'undefined', 'null' ].includes(browseCnt.value)) {
hasReadCount.value = true
browseStr.value = `浏览量${browseCnt.value}`
} else {
hasReadCount.value = false
}
} else {
hasReadCount.value = false
}
nextTick(() => {
if (
document.querySelector('.skeleton-loading').classList.contains('active') &&
!document.querySelector('#app').classList.contains('fixed')
) {
changeContentHtmlHeight()
}
})
}
const getOthersStatus = (data, callBack) => {
if (data.voteInfo) {
if (state.isLogined == 1) {
if (data.voteInfo && data.voteInfo.voteId) {
handleVoteData(data)
voteStatus(data.voteInfo.voteId, null, () => {
setTimeout(() => {
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
}, 100)
})
}
} else {
handleVoteData(data)
voteInit.value = true
handleVoteList()
setTimeout(() => {
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
}, 100)
}
}
if (data.rmhInfo) {
// 人民号信息
state.details.rmhInfo = data.rmhInfo
//人民号信息人民号姓名存在则赋值给details.rmhName
state.details.rmhName = data.rmhInfo.rmhName
? data.rmhInfo.rmhName
: ''
//rmhId:人民号id
state.details.rmhId = data.rmhInfo.rmhId ? data.rmhInfo.rmhId : ''
//rmhId:人民号加v头像
state.details.authIcon = data.rmhInfo.authIcon ? data.rmhInfo.authIcon : ''
//userId:用户id
state.details.userId = data.rmhInfo.userId ? data.rmhInfo.userId : ''
//userType:用户类型 1:普通用户,2:创作者 3:矩阵号 4:运营子账号 5:内容源账号
state.details.userType = data.rmhInfo.userType
? data.rmhInfo.userType
: ''
//rmhHeadUrl:人民号头像
state.details.rmhHeadUrl = data.rmhInfo.rmhHeadUrl
? data.rmhInfo.rmhHeadUrl
: ''
//rmhDesc:描述
state.details.rmhDesc = data.rmhInfo.rmhDesc
? data.rmhInfo.rmhDesc
: ''
if (state.isLogined == 1) {
// 已登录
if (window.config.VUE_BASE_NODE === 'dev') {
showClook.value = true
} else {
clookStatus(true) // 查"关注"状态 , 更新按钮上的文字
}
} else {
showClook.value = true
}
}
if (data.topicInfo) {
timeLine.title = data.topicInfo.title
timeLine.topicId = data.topicInfo.topicId
timeLine.topicType = data.topicInfo.topicType
timeLine.pageId = data.topicInfo.pageId
timeLine.linkUrl = data.topicInfo.linkUrl
timeLine.slideColor = data.topicInfo.slideColor || '#ED2800'
if (data.topicInfo.slideShows) {
timeLine.data = data.topicInfo.slideShows.filter(item => item.publishTime && item.newsTitle).map(item => {
item.dateTimeStr = dayjs(item.publishTime).format('MM月DD日 HH:mm')
return item
}).sort((a, b) => compareTimeArray(a, b, 'publishTime', 1))
}
}
if (data.activityInfos) {
Object.assign(actieInfo, data.activityInfos ? data.activityInfos[0] : {})
if (actieInfo.title) { actieInfo.show = true }
}
mainProcessProgress['6'] = {
status:'success',
message: '准备调用:getOthersStatus回调方法'
}
if (callBack) callBack()
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 页面交互
*/
const reload = () => {
// 页面重新加载
errorStatus = false
clearData()
pageReloadChange()
loadingBlock(true)
changeContentHtmlHeight({ str: '.skeleton-loading' })
if (window.config.VUE_BASE_NODE === 'dev') {
initData({}, state.contentId)
} else {
try {
sendNative(
'jsCall_currentPageOperate',
{
operateType: '22'
},
(res) => {}
)
} catch (e) {
}
}
}
// 跳转人民号主页
const skipCustomerNumberPage = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
} else {
if (state.details.rmhInfo.banControl == 1) {
// 该账号已封禁,不予访问
toast('该账号已封禁,不予访问')
return
}
window.config.VUE_APP_LOGIN = ''
try {
isPageLeave.value = true
sendNative(
'jsCall_appInnerLinkMethod',
{
appInnerLink: `rmrbapp://rmrb.app/openwith?type=owner_page&subType=${state.details.userType}&contentId=${state.details.userId}&creatorId=${state.details.rmhId}&skipType=1`
}
)
} catch (e) { isPageLeave.value = false }
}
}
// 点击协议提示字跳转到协议页面,调取App内链方法
const inptClick = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
} else {
try {
sendNative('jsCall_appInnerLinkMethod', {
//参考conflence内链文档
//skipType =3跳转H5页面链接(APP内部打开)
appInnerLink: `rmrbapp://rmrb.app/openwith?type=h5&url=${state.agreementURL}&skipType=3`
})
} catch (e) { }
}
}
// 片头跳转
const moreInformationClick = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
console.log(state.details.newLinkObject)
} else {
// let linkUrl = ''
// const jumpUrl = state.details.newLinkObject.jumpUrl
// const newsObjectType = state.details.newLinkObject.newsObjectType
// if (jumpUrl) {
// linkUrl = `rmrbapp://rmrb.app/openwith?type=h5&url=${encodeURIComponent(jumpUrl)}&skipType=3`
// } else {
// switch (newsObjectType) {
// case 8:
// break
// }
// }
try {
sendNative(
'jsCall_receiveH5Data',
{
dataSource: '6',
dataJson: JSON.stringify(state.details.newLinkObject)
}
)
} catch (e) { }
}
}
// 分享
const openShare = (sharePlatform) => {
const shareInfo = state.details.shareInfo
if (shareInfo && shareInfo.shareUrl) {
try {
sendNative(
//H5调用此方法,启动客户端分享弹窗
'jsCall_openAppShare',
{
//分享类型:1.文字类型分享 2.网页类型分享
type: '2',
//是否显示分享:1 显示分享按钮 0 不显示
isShowShare: 1,
//分享标题(当type为2时可用)
title: shareInfo.shareTitle,
//分享描述(当type为2时可用 )
description: shareInfo.shareSummary,
//分享链接(当type为2时可用 )
webpageUrl: shareInfo.shareUrl,
//分享图标链接(当type为2时可用,分享小icon需小于64k )
imageUrl: shareInfo.shareCoverUrl,
//分享的内容Id:活动ID、视频ID等
contentId: state.details.newsId,
//1.facebook 2.twitter 3.微信 4.微信朋友圈 5.微博 6.系统分享 7. 弹框App全分享 8.海报分享
sharePlatform
},
() => { }
)
} catch (e) {
}
}
}
// 跳转时间轴专题
const openMoreTimeLine = () => {
sendNative(
'jsCall_appInnerLinkMethod',
{
appInnerLink: `rmrbapp://rmrb.app/openwith?type=topic&subType=h5&pageId=${timeLine.pageId}&url=${encodeURIComponent(
timeLine.linkUrl)}&skipType=1`
}
)
}
// 活动跳转
const openActiveLink = () => {
try {
sendNative(
'jsCall_appInnerLinkMethod',
{
appInnerLink: `rmrbapp://rmrb.app/openwith?type=h5&url=${encodeURIComponent(actieInfo.linkUrl)}&skipType=3`
}
)
} catch (e) {
}
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 关注交互
*/
const clookBtn = () => {
// 人民号关注
if (window.config.VUE_BASE_NODE === 'dev') {
if (clookBtnActive.value) {
return
}
clookBtnActive.value = true
setTimeout(() => {
showClook.value = false
clookStatusSee.value = false
clookBtnActive.value = false
followTypePoint({
type: 1,
followPDUserId: state.details.rmhId,
followUserName: state.details.rmhName,
channelId: channelId.value,
newsType: state.details.newsType,
newsId: state.details.newsId,
newsTitle: state.details.newsTitle,
sceneId: state.details.sceneId,
itemId: state.details.itemId,
subSceneId: state.details.subSceneId,
cnsTraceId: state.cnsTraceId,
isNewspaper: isNewspaper.value,
duration: dayjs().diff(statrTime.value, 'second')
})
}, 1000)
return
}
if (clookBtnActive.value) {
return
}
if (state.isLogined == 1) {
clookCancelBtnActive.value = false
clookBtnActive.value = true
}
getUserLoginStatus(loginId => {
if (loginId == 0) {
// 0 未登录
setAppLogin()
checkAppLoginStatu('follow')
return
} else {
// 1 已登录 直接走 关注接口
showClook.value = false
clookBtnHandel(1)
}
})
}
// 人民号取消关注
const clookCancelBtn = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
if (clookCancelBtnActive.value) {
return
}
clookCancelBtnActive.value = true
setTimeout(() => {
showClook.value = true
clookStatusSee.value = true
clookCancelBtnActive.value = false
followTypePoint({
type: 0,
cancelFollowPDUseId: state.details.rmhId,
cancelFollowUserName: state.details.rmhName,
channelId: channelId.value,
newsType: state.details.newsType,
newsId: state.details.newsId,
newsTitle: state.details.newsTitle,
sceneId: state.details.sceneId,
itemId: state.details.itemId,
subSceneId: state.details.subSceneId,
cnsTraceId: state.cnsTraceId,
isNewspaper: isNewspaper.value,
duration: dayjs().diff(statrTime.value, 'second')
})
}, 1000)
return
}
if (clookCancelBtnActive.value) {
return
}
if (state.isLogined == 1) {
clookBtnActive.value = false
clookCancelBtnActive.value = true
}
getUserLoginStatus(loginId => {
if (loginId == 0) {
// 0 未登录
setAppLogin()
checkAppLoginStatu('follow')
return
} else {
// 1 已登录 直接走 取消关注接口
showClook.value = true
clookBtnHandel(0)
}
})
}
// 人民号关注、取消关注接口调用
const clookBtnHandel = async (status) => {
if (window.config.VUE_BASE_NODE === 'dev') {
const response = await axiosRequest({
url: '/interact/zh/c/attention/operation',
methot: 'post',
appStatus: false,
environment: state.environment,
prefix: '/api/rmrb-interact',
data: {
status,
attentionUserId: `${state.details.userId}`,
attentionUserType: `${state.details.userType}`,
attentionCreatorId: `${state.details.rmhId}`
},
headers: state.appHeader,
showError: false
})
if (response.success) {
}
} else {
try {
sendNative(
'jsCall_callAppService',
{
method: 'post',
url: '/api/rmrb-interact/interact/zh/c/attention/operation',
parameters: {
status,
attentionUserId: `${state.details.userId}`,
attentionUserType: `${state.details.userType}`,
attentionCreatorId: `${state.details.rmhId}`
}
},
res => {
const response = typeof res === 'object' ? res : JSON.parse(res)
const netError = response.netError
if (netError == 0) {
try {
const responseMap =
typeof response.responseMap === 'object'
? response.responseMap
: JSON.parse(response.responseMap)
const success = responseMap.success
const params = {
type: status,
channelId: channelId.value,
newsType: state.details.newsType,
newsId: state.details.newsId,
newsTitle: state.details.newsTitle,
sceneId: state.details.sceneId,
itemId: state.details.itemId,
subSceneId: state.details.subSceneId,
cnsTraceId: state.cnsTraceId,
isNewspaper: isNewspaper.value,
duration: dayjs().diff(statrTime.value, 'second')
}
if (status == 1) {
params.followPDUserId = state.details.rmhId
params.followUserName = state.details.rmhName
} else if (status == 0) {
params.cancelFollowPDUseId = state.details.rmhId
params.cancelFollowUserName = state.details.rmhName
}
if (success) {
// 关注成功
if (status == 1) {
try {
sendNative('jsCall_pointLevelOperate', {
operateType: '6'
}, () => {
})
} catch (e) {}
followTypePoint(params)
clookStatus() // 调关注状态查询,更新按钮上的文字
try {
sendNative('jsCall_currentPageOperate', {
operateType: '24',
creatorId: `${state.details.rmhId}`,
followStatus: '1'
}, () => {})
} catch (e) {}
} else if (status == 0) {
// 取消关注成功
followTypePoint(params)
clookStatus() // 调关注状态查询,更新按钮上的文字
try {
sendNative('jsCall_currentPageOperate', {
operateType: '24',
creatorId: `${state.details.rmhId}`,
followStatus: '0'
}, () => {})
} catch (e) {}
}
}
} catch (e) { }
} else {
toast('网络出小差了,请检查网络后重试')
}
}
)
} catch (e) { }
}
}
// 查询关注状态 initStatus(判断是不是第一次进入以及关注页面返回)
const clookStatus = async (initStatus) => {
if (window.config.VUE_BASE_NODE === 'dev') {
const response = await axiosRequest({
url: '/interact/zh/c/batchAttention/status',
methot: 'post',
appStatus: false,
environment: state.environment,
prefix: '/api/rmrb-interact',
data: {
creatorIds: [ { creatorId: `${state.details.rmhId}` } ]
},
headers: state.appHeader,
showError: false
})
if (response.success) {
clookStatusSee.value = response.data[0].status == '1' ? false : true // '1' 是已关注 '0'是未关注
}
} else {
if (state.creatorID == state.details.rmhId) {
isOwer.value = true
clookStatusSee.value = false
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
return
}
try {
sendNative(
'jsCall_callAppService',
{
method: 'post',
url: '/api/rmrb-interact/interact/zh/c/batchAttention/status',
parameters: {
//userId为用户id
creatorIds: [ { creatorId: `${state.details.rmhId}` } ]
}
},
res => {
const statusResponse =
typeof res === 'object' ? res : JSON.parse(res)
const netError = statusResponse.netError
const statusResponseMap =
typeof statusResponse.responseMap === 'object'
? statusResponse.responseMap
: JSON.parse(statusResponse.responseMap)
if (netError == 0) {
try {
const code = statusResponseMap.code
const data = statusResponseMap.data
if ([ 200, '0' ].includes(code)) {
if (data) {
if (data[0].status == '1') {
state.initClockStatus = !initStatus
} else {
state.initClockStatus = false
}
if (state.creatorID == state.details.rmhId) {
isOwer.value = true
clookStatusSee.value = false
} else {
clookStatusSee.value = data[0].status == '1' ? false : true // '1' 是已关注 '0'是未关注
}
clookBtnActive.value = false
clookCancelBtnActive.value = false
} else {
clookStatusSee.value = true // '1' 是已关注 '0'是未关注
state.initClockStatus = false
clookBtnActive.value = false
clookCancelBtnActive.value = false
}
}
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
} catch (e) { }
} else {
toast('网络出小差了,请检查网络后重试')
}
}
)
} catch (e) { }
}
}
// 监听页面离开状态用于判断关注信息
const queryPageLeaveStatus = () => {
let objEvt = window.config.VUE_APP_LOGIN
? window.config.VUE_APP_LOGIN
: ''
let lastObjEvt =
typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt)
if (lastObjEvt && lastObjEvt.event == '1') {
// changeContentHtmlHeight({ report: true })
}
if (lastObjEvt && lastObjEvt.event == '1' && !loginTime.value && isPageLeave.value) {
isPageLeave.value = false
setTimeout(() => {
clookStatus(true) // 调关注状态查询,更新按钮上的文字
}, 200)
}
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 投票交互
*/
const wheelFun = (vid, nid, type, index) => {
// 轮训查询是否从登录页回到图文详情
loginTime.value = setInterval(() => {
try {
let objEvt = window.config.VUE_APP_LOGIN
? window.config.VUE_APP_LOGIN
: ''
let lastObjEvt =
typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt)
if (lastObjEvt && lastObjEvt.event == '1') {
if (window.config.VUE_BASE_NODE === 'dev') {
clearInterval(loginTime.value)
loginTime.value = null
if (type === 'vote') {
state.isLogined = 1
refreshVotes(nid, 0, () => {
voteStatus(vid, index, () => {
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
})
})
} else if (type === 'follow') {
clookStatus() // 调关注状态查询,更新按钮上的文字
}
} else {
getUserLoginStatus(loginId => {
clearInterval(loginTime.value)
loginTime.value = null
if (loginId == 1) {
// 由登录页面进到了主页面
if (type === 'vote') {
refreshVotes(nid, 0, () => {
voteStatus(vid, index, () => {
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
})
})
} else if (type === 'follow') {
clookStatus() // 调关注状态查询,更新按钮上的文字
}
} else {
clookBtnActive.value = false
clookCancelBtnActive.value = false
}
})
}
}
} catch (e) { }
}, 20)
}
// 开启轮训查询
const checkAppLoginStatu = (type, index) => wheelFun(state.voteId, state.details.newsId, type, index)
// 开始投票
const goVote = (voteId, optionId, index) => {
if (!state.details.endTimePoint) {
if (window.config.VUE_BASE_NODE === 'dev') {
}
toast('投票已过期')
return
}
window.config.VUE_APP_LOGIN = '' // 由于页面加载就会给 '1' ,所以点投票先清空,否则会影响后面的轮巡判断
if (window.config.VUE_BASE_NODE === 'dev') {
const optionInfo = optionList.value.find(item => item.optionId == optionId)
normalClickTypePoint({
channelId: channelId.value,
newsType: state.details.newsType,
newsId: state.details.newsId,
newsTitle: state.details.newsTitle,
sceneId: state.details.sceneId,
itemId: state.details.itemId,
subSceneId: state.details.subSceneId,
voteOption: `${optionId}`,
voteContent: optionInfo ? optionInfo.summary : '',
cnsTraceId: state.cnsTraceId,
isNewspaper: isNewspaper.value,
duration: dayjs().diff(statrTime.value, 'second')
})
// 模拟去登录
state.voteId = voteId
setTimeout(() => {
const event = {
event: '1'
}
window.config.VUE_APP_LOGIN = JSON.stringify(event)
}, 100)
checkAppLoginStatu('vote', index)
} else {
if (state.isLogined == 1) {
// 已登录 直接去投票
if (state.Doing) {
return
} else {
try {
sendNative('jsCall_currentPageOperate', {
operateType: '47'
}, () => {})
} catch (e) {}
state.Doing = true
setVote(voteId, optionId, index)
}
} else {
state.voteId = voteId
setAppLogin()
checkAppLoginStatu('vote')
}
}
}
// 用户投票
const setVote = async (vID, oID, index) => {
if (window.config.VUE_BASE_NODE === 'dev') {} else {
try {
sendNative(
'jsCall_callAppService',
{
method: 'post',
url: '/api/rmrb-contact/contact/zh/c/vote/submit',
parameters: { voteId: `${vID}`, optionId: oID }
},
res => {
const vtSubmitResponse =
typeof res === 'object' ? res : JSON.parse(res)
const netError = vtSubmitResponse && vtSubmitResponse.netError
const vtSubmitResponseMap =
typeof vtSubmitResponse.responseMap === 'object'
? vtSubmitResponse.responseMap
: JSON.parse(vtSubmitResponse.responseMap)
if (netError == 0) {
try {
const code = vtSubmitResponseMap.code
const newId = state.details.newsId
if ([ 200, '0' ].includes(code)) {
const optionInfo = optionList.value.find(item => item.optionId == oID)
try {
normalClickTypePoint({
channelId: channelId.value,
newsType: state.details.newsType,
newsId: state.details.newsId,
newsTitle: state.details.newsTitle,
sceneId: state.details.sceneId,
itemId: state.details.itemId,
subSceneId: state.details.subSceneId,
voteOption: `${oID}`,
voteContent: optionInfo ? optionInfo.summary : '',
cnsTraceId: state.cnsTraceId,
isNewspaper: isNewspaper.value,
duration: dayjs().diff(statrTime.value, 'second')
})
} catch (e) {
}
try {
sendNative('jsCall_currentPageOperate', {
operateType: '48'
}, () => {
})
} catch (e) {}
toast('投票成功')
// 刷新投票状态
refreshVotes(newId, 0, () => {
voteStatus(vID, index, () => {
nextTick(() => {
if (document.querySelector('.skeleton-loading').classList.contains('active')) {
changeContentHtmlHeight()
}
})
}) // 投票前 投票后
})
state.Doing = false
} else {
toast(vtSubmitResponseMap.message)
}
} catch (e) { }
} else {
toast('网络出小差了,请检查网络后重试')
}
}
)
} catch (e) { }
}
}
// 刷新投票状态
const refreshVotes = async (eq, id, callback) => {
if (window.config.VUE_BASE_NODE === 'dev') {
setTimeout(() => {
const refResponse = {
netError: 0,
responseMap: {
code: '0',
data: [
{
voteInfo: shallowMergeObj(state.originDataSource.voteInfo, {
options: voteOtions.value
})
}
]
}
}
const refResponseMap =
typeof refResponse.responseMap === 'object'
? refResponse.responseMap
: JSON.parse(refResponse.responseMap)
if (refResponseMap.data && refResponseMap.code) {
const code = refResponseMap.code
const data = refResponseMap.data[0]
if ([ 200, '0' ].includes(code) && data) {
if (Object.keys(data).length > 0) {
handleVoteData(data)
if (callback) callback()
}
} else {
toast('网络出小差了,请检查网络后重试')
}
} else {
toast('网络出小差了,请检查网络后重试')
}
}, 100)
} else {
try {
const reLInfo = state.details.reLInfo ? {
relType: state.details.reLInfo.relType,
relId: state.details.reLInfo.relId
} : {}
sendNative(
'jsCall_callAppService',
{
method: 'get',
url: '/api/rmrb-bff-display-zh/content/zh/c/content/detail',
parameters: {
contentId: eq,
...reLInfo
}
},
(res) => {
try {
const refResponse =
typeof res === 'object' ? res : JSON.parse(res)
const netError = refResponse.netError
if (netError == 0) {
const refResponseMap =
typeof refResponse.responseMap === 'object'
? refResponse.responseMap
: JSON.parse(refResponse.responseMap)
if (refResponseMap.data && refResponseMap.code) {
const code = refResponseMap.code
const data = refResponseMap.data[0]
if ([ 200, '0' ].includes(code) && data) {
if (Object.keys(data).length > 0) {
handleVoteData(data)
if (callback) callback()
}
} else {
toast('网络出小差了,请检查网络后重试')
}
} else {
toast('网络出小差了,请检查网络后重试')
}
} else {
toast('网络出小差了,请检查网络后重试')
}
} catch (e) {
logInfo('error', e)
}
}
)
} catch (e) { }
}
}
// 用户投票状态查询
const voteStatus = async (vId, index, callBack) => {
if (window.config.VUE_BASE_NODE === 'dev') {
voteInit.value = true
state.voteState.optionId = voteOtions.value[0].optionId
state.voteState.status = 1 // 决定是投票前0 还是 投票后1
nextTick(() => handleVoteList())
if (state.details.voteInfo.style === 1) {
// 展示对 √
if (index) {
state.bcIndex = index
}
} else {
if (index) {
state.curIndex = index
}
}
if (callBack) callBack()
} else {
try {
sendNative(
'jsCall_callAppService',
{
method: 'get',
url: '/api/rmrb-contact/contact/zh/c/vote/queryStatus',
parameters: { voteId: vId }
},
res => {
const voteStatusResponse =
typeof res === 'object' ? res : JSON.parse(res)
const netError = voteStatusResponse.netError
const vtStatusResponseMap =
typeof voteStatusResponse.responseMap === 'object'
? voteStatusResponse.responseMap
: JSON.parse(voteStatusResponse.responseMap)
if (netError == 0) {
try {
const code = vtStatusResponseMap.code
const data = vtStatusResponseMap.data
if ([ 200, '0' ].includes(code) && data) {
if (Object.keys(data).length > 0) {
try {
voteInit.value = true
state.voteState.status = data.status // 决定是投票前0 还是 投票后1
state.voteState.optionId = data.optionId // 返回的是 被投票项的 optionId ,没投就是 ''
nextTick(() => handleVoteList())
} catch (e) {
}
if (state.details.voteInfo.style === 1) {
// 展示对 √
if (index) {
state.bcIndex = index
}
} else {
if (index) {
state.curIndex = index
}
}
if (callBack) callBack()
}
} else {
toast(vtStatusResponseMap.message)
}
} catch (e) { }
} else {
toast('网络出小差了,请检查网络后重试')
}
}
)
} catch (e) { }
}
}
// 处理投票List给页面使用
const handleVoteList = () => {
const tots = voteOtions.value.length
? voteOtions.value.reduce((x, i) => x + i.totalVotes, 0)
: 0
let datsArr = voteOtions.value.length
? voteOtions.value.map(ep => {
ep.votesBf = tots > 0 ? parseInt(ep.totalVotes / tots * 100) : 0
return ep
})
: []
if (tots != 0) { // 这里面的作用,让投票结果百分数之和恰好为 100%
let bfTols = 0
let bfMax = datsArr[0].votesBf
let index = 0
let bfgDiff = 0
for (let i = 0; i < datsArr.length; i++) {
bfTols += datsArr[i].votesBf
if (bfMax < datsArr[i].votesBf) {
bfMax = datsArr[i].votesBf
index = i
}
}
bfgDiff = bfTols - 100
if (bfgDiff > 0) {
datsArr[index].votesBf = bfMax - bfgDiff
} else if (bfgDiff < 0) {
datsArr[index].votesBf = bfMax + Math.abs(bfgDiff)
} else {}
} else {
if (datsArr.length > 0 && state.details.voteInfo && state.details.voteInfo.style === 1) {
if (datsArr[0].votesBf === 0 && datsArr[1].votesBf === 0) {
datsArr = datsArr.map(item => {
return shallowMergeObj(item, {
votesBf: 50
})
})
}
}
}
datsArr = deepCopy(datsArr).map((item, index) => {
oneWidth = state.details.voteInfo.style == 1 && index === 0
? datsArr[index + 1].votesBf == 0 && item.votesBf == 0
? 50
: (item.votesBf == 0 ? 8 : datsArr[index + 1].votesBf == 0 ? 92 : item.votesBf)
: 0
twoWidth = state.details.voteInfo.style == 1 && index === 1
? datsArr[index - 1].votesBf == 0 && item.votesBf == 0
? 50
: (item.votesBf == 0 ? 8 : datsArr[index - 1].votesBf == 0 ? 92 : item.votesBf)
: 0
if ((state.isLogined != 1 || state.voteState.status === 0)) {
oneWidth = 50
twoWidth = 50
}
const voteAnimate = document.getElementById('voteAnimate')
if (oneWidth && index === 0 && state.details.voteInfo.style == 1) {
const oneCssStr = `@keyframes voteProgressIn {
0% {
width: calc(50% - 0.5px);
}
100% {
width: calc(${oneWidth}% - 0.5px);
}
}`
jqHtml(voteAnimate, { type: 'set', str: jqHtml(voteAnimate, { type: 'get' }) + oneCssStr })
}
if (twoWidth && index === 1 && state.details.voteInfo.style == 1) {
const twoCssStr = `@keyframes voteProgressInTwo {
0% {
width: calc(50% - 0.5px);
}
100% {
width: calc(${twoWidth}% - 0.5px);
}
}`
jqHtml(voteAnimate, { type: 'set', str: jqHtml(voteAnimate, { type: 'get' }) + twoCssStr })
}
const oneStyle = {
width: `calc(${oneWidth}%)`,
clipPath: `polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%)`,
'-webkit-clip-path': `polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%)`,
color: item.wordColor || undefined,
background: item.backColor || undefined
}
const twoStyle = {
width: `calc(${twoWidth}%)`,
clipPath: `polygon(12px 0, 100% 0, 100% 100%, 0 100%)`,
'-webkit-clip-path': `polygon(12px 0, 100% 0, 100% 100%, 0 100%)`,
color: item.wordColor || undefined,
background: item.backColor || undefined
}
return shallowMergeObj(item, {
oneStyle: shallowMergeObj(oneStyle, {
width: `50%`
}),
oneStyleFront: shallowMergeObj(oneStyle, {
width: 'calc(50% + 2.5px)'
}),
oneStyleAfter: {
width: `calc(50%)`,
background: item.backColor,
clipPath: `polygon(0 0, 100% 0, calc(100% - 4px) 100%, 0 100%)`,
'-webkit-clip-path': `polygon(0 0, 100% 0, calc(100% - 4px) 100%, 0 100%)`
},
twoStyle: shallowMergeObj(twoStyle, {
width: `50%`
}),
twoStyleFront: shallowMergeObj(twoStyle, {
width: 'calc(50% + 2.5px)'
}),
twoStyleAfter: {
width: `calc(50%)`,
background: item.backColor,
clipPath: `polygon(4px 0, 100% 0, 100% 100%, 0 100%)`,
'-webkit-clip-path': `polygon(4px 0, 100% 0, 100% 100%, 0 100%)`
}
})
})
optionList.value = deepCopy(datsArr)
}
// 将投票相关信息处理成多个本地变量
const handleVoteData = (data) => {
state.details.voteInfo = data.voteInfo
// 投票信息结束时间为空endTimePoint则为false,否则结束时间大于当前时间endTimePoint则为data.voteInfo.endTime,否则endTimePoint为Close
state.details.endTimePoint = data.voteInfo.endTime === '' || !data.voteInfo.endTime
? true
: (data.voteInfo.endTime - Date.now()) > 0
? true
: false
voteOtions.value = data.voteInfo.options ? Array.isArray(data.voteInfo.options)
? data.voteInfo.options
: [] : []
//投票信息选项存在且投票信息选项标题存在,则把投票信息选项标题赋值给yes
state.details.yes = data.voteInfo.options && data.voteInfo.options[0]
//投票信息选项存在且投票信息选项排序存在,则把投票信息选项排序赋值给no
state.details.no = data.voteInfo.options && data.voteInfo.options[1]
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 动态监听App传参
*/
const pageReloadChange = () => {
// 监听App复用模版
if (window.config.VUE_BASE_NODE === 'dev') {
if (pageLoadOutTime || hasDetails) {
return
}
firstTime = new Date()
pageLoadOutTime = null
hasDetails = false
checkPageLoadingTimeOut()
} else {
try {
const objEvt = window.config.PAGERELOAD ? window.config.PAGERELOAD : ''
const pageReloadInfo = typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt)
if (pageReloadInfo && pageReloadInfo.event == '7') { // 复用重新进入
if (pageLoadOutTime || hasDetails) {
return
}
document.querySelector('.error-block').style.display = 'none'
darkMode = pageReloadInfo.darkMode || darkMode
state.darkMode = darkMode
document
.querySelector('html')
.setAttribute('dark-mode', darkMode === 'dark')
firstTime = new Date()
pageLoadOutTime = null
hasDetails = false
checkPageLoadingTimeOut()
}
} catch (e) {
}
}
}
// 监听改变软件字体大小
const changeAppFontSize = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
const fontSizes = 'Large'
state.appFontSize = fontSizes
appFontSize = state.appFontSize
setRemUnit(state.appFontSize)
} else {
try {
const objEvt = window.config.APP_FONT_SIZE ? window.config.APP_FONT_SIZE : ''
const appFontSizeEvent = objEvt ? typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt) : undefined
if (appFontSizeEvent && appFontSizeEvent.event == '10') {
const fontSizes = appFontSizeEvent.fontSizes
state.appFontSize = fontSizes
appFontSize = state.appFontSize
setRemUnit(state.appFontSize)
// setTimeout(() => {
// if (currentVideo.el && currentVideo.videoUrl) {
// const player = currentVideo.el
// const width = player.parentNode.getBoundingClientRect().width
// const height = player.parentNode.getBoundingClientRect().height
// const top = player.parentNode.offsetTop
// const left = player.parentNode.getBoundingClientRect().left
// const videoLandscape = width > height ? '1' : (width < height ? '2' : '')
//
// // logInfo('视频播放', width, height, left, top)
//
// if (window.config.VUE_BASE_NODE === 'dev') {
// console.log('视频播放', width, height, left, top)
// }
//
// try {
// sendNative(
// 'jsCall_currentPageOperate',
// {
// operateType: '49',
// positionLeft: `${left}`,
// positionTop: `${top}`,
// positionWidth: `${width}`,
// positionHeight: `${height}`,
// videoLandscape: `${videoLandscape}`,
// videoUrl: `${currentVideo.videoUrl}`
// },
// res => {
// }
// )
// } catch (e) {}
// }
// }, 0)
}
} catch (e) {
}
}
}
// 监听改变软件皮肤模式
const changeDarkMode = () => {
try {
const objEvt = window.config.DARK_MODE ? window.config.DARK_MODE : ''
const appDarkMode = objEvt ? typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt) : undefined
if (appDarkMode && appDarkMode.event == '9') {
darkMode = appDarkMode.darkMode || darkMode
state.darkMode = darkMode
document
.querySelector('html')
.setAttribute('dark-mode', darkMode == 'dark')
}
} catch (e) {
}
}
const changeState = () => {
const stateObj = window.config.VUE_STATE
if (stateObj) {
const key = stateObj.key
const value = stateObj.value
state[key] = value
}
}
// 监听网络状态
const changeNetworkStatus = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
networkStatus.value = window.config.VUE_APP_NETWORK
} else {
const objNvt = window.config.VUE_APP_NETWORK ? window.config.VUE_APP_NETWORK : {}
const lastObjNvtNetwork = typeof objNvt === 'object' ? objNvt : JSON.parse(objNvt)
networkStatus.value = lastObjNvtNetwork.networkStatus
}
}
// 监听媒体播放状态
const changeMediaPlayStatus = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
} else {
try {
const objEvt = window.config.MEDIAPLAY ? window.config.MEDIAPLAY : ''
const mediaPlayInfo = typeof objEvt === 'object' ? objEvt : JSON.parse(objEvt)
if (mediaPlayInfo && mediaPlayInfo.event == '5') { // 音频播放
audioState.value += 1
}
} catch (e) { }
}
}
// 退出图文详情页关闭音频播放
const quitGraphicDetailPageEvent = () => {
if (window.config.VUE_BASE_NODE === 'dev') {
} else {
try {
const objQvt = window.config.VUE_APP_LOGIN ? window.config.VUE_APP_LOGIN : ''
const lastObjQvt = typeof objQvt === 'object' ? objQvt : JSON.parse(objQvt)
if (lastObjQvt && (lastObjQvt.event == '2' || lastObjQvt.event == '4')) {
const _editor36 = document.querySelectorAll('.preview-audio-player')
const coverAudioList = document.querySelectorAll('.preview-audio-player-cover')
if (_editor36) {
_editor36.forEach((item, _) => {
const audioStylePlay = item.querySelector('.audio-play-icon')
const audioStylePause = item.querySelector('.audio-pause-icon')
const item_audio = item.querySelector('[class^="audio-block"]')
if (item_audio) {
item_audio.pause()
audioStylePause.style.display = 'none'
audioStylePlay.style.display = 'block'
}
})
}
if (coverAudioList) {
coverAudioList.forEach((item, _) => {
const audioStylePlay = item.querySelector('.audio-play-icon')
const audioStylePause = item.querySelector('.audio-pause-icon')
const item_audio = item.querySelector('[class^="audio-block"]')
if (item_audio) {
item_audio.pause()
audioStylePause.style.display = 'none'
audioStylePlay.style.display = 'block'
}
})
}
}
} catch (e) { }
}
}
/**
* @Author gx12358
* @DateTime 2024/7/5
* @lastTime 2024/7/5
* @description 与App交互方法
*/
const setAppLogin = () => {
// 未登录时执行,拉起app登录
try {
sendNative(
'jsCall_appInnerLinkMethod',
{
appInnerLink:
'rmrbapp://rmrb.app/openwith?type=app&subType=login&skipType=2'
},
res => { }
)
} catch (e) { }
}
// 获取用户登录状态
const getUserLoginStatus = (callback) => {
try {
sendNative('jsCall_getAppLoginAuthInfo', {}, res => {
const loginStatusResponse =
typeof res === 'object' ? res : JSON.parse(res)
state.isLogined =
loginStatusResponse && loginStatusResponse.isLogined
if (callback !== undefined) {
callback(state.isLogined)
}
})
} catch (e) { }
}
const sendParams = callback => {
sendNative(
'jsCall_receiveH5Data',
{ dataSource: '1', dataJson: JSON.stringify(state.originDataSource) },
callback
)
}
// 推荐每项的点击事件
const recommondItemClick = index => {
sendNative('jsCall_receiveH5Data', {
dataSource: '2',
dataJson: JSON.stringify(state.recomList[index])
})
}
// 页面离开的时候初始化
const clearData = () => {
clearTimeout(pageLoadOutTime)
document.querySelector('.error-block').style.display = 'none'
jqHtml('#newsContent', { type: 'set', str: '' })
loadingBlock(true)
document.querySelector('.skeleton-loading').classList.add('active')
appBlock(false)
mainProcessProgress = {}
time.value = ''
deviceType.value = judgTerminal() === 1 ? 'ad' : 'ios'
statrTime.value = dayjs()
loginTime.value = null
channelId.value = null
recordTime.value = dayjs()
canSeeBtnTwo.value = true
canSeeBtnOne.value = true
isOwer.value = false
hasReadCount.value = true
isRmh.value = null
isNewspaper.value = false
voteInit.value = false
showClook.value = false
optionList.value = []
subjectList.value = []
channelList.value = []
suggestedList.value = []
voteOtions.value = []
networkStatus.value = 4
networkSwitch.value = 2
audioState.value = 0
browseCnt.value = '0'
browseStr.value = ''
loadlmageOnlyWifiSwitch.value = window.config.VUE_BASE_NODE === 'dev' ? '2' : '0'
clookStatusSee.value = false
clookCancelBtnActive.value = false
clookBtnActive.value = false
hasHeadLink.value = false
isPageLeave.value = false
hasInit.value = false
shareOpen.value = false
hasAppLoginExtra = false
Object.assign(state, {
clientHeight: 0,
appFontSize: state.appFontSize,
//投票id
voteId: null,
contentId: null,
sourcePage: '2',
//模式
//环境
environment: 'sit',
showShare: false,
//请求头
appHeader: shallowMerge({
system: judgTerminal() === 1 ? 'Android' : 'ios'
}, window.config.VUE_BASE_HEADER),
initialRes: {},
originDataSource: {},
//此details对接口返回的数据进行了二次改造,属性的添加和属性值的转换
details: {
rmhInfo: null,
author: [],
newLinkObject: {},
//投票信息
voteInfo: {},
endTimePoint: false,
yes: {},
no: {},
slideShows: {},
//片头跳转
headLinkdata: ''
},
initClockStatus: false,
shareNewPoster: false,
voteState: {
status: 0,
optionId: 0
},
creatorID: null,
curIndex: 0,
bcIndex: 0,
Doing: false,
isLogined: 0, // 0 未登录 1 已登录
isSub: false,
isSubClose: false,
seeEmailSub: false,
strategy: {},
emailVal: '',
deviceId: '',
userId: '',
aboutUserName: '',
agreementURL: '',
recomList: []
})
Object.assign(timeLine, {
title: '',
topicId: '',
topicType: '',
pageId: '',
linkUrl: '',
slideColor: '#ED2800',
data: []
})
Object.assign(actieInfo, {
show: false,
id: -1,
title: '',
type: '',
linkUrl: '',
coverUrl: ''
})
refreshEditorStr()
hasDetails = false
pageLoadOutTime = null
changeContentHtmlHeight()
startShowArticle = false
}
// 模拟App页面离开的时候初始化
const mockAppClearData = () => {
clearData()
setTimeout(() => {
mockAppRequestDetails()
})
}
return Object.assign({
isRmh,
isNewspaper,
isOwer,
deviceType,
browseCnt,
browseStr,
baseNode,
actieInfo,
voteInit,
hasHeadLink,
canSeeBtnOne,
canSeeBtnTwo,
subjectList,
channelList,
suggestedList,
voteOtions,
optionList,
showClook,
clookStatusSee,
timeLine,
shareOpen,
hasReadCount,
clookBtnActive,
clookCancelBtnActive,
pageReloadChange,
requestApp,
clearData,
mockAppClearData,
inptClick,
removeHtmlStr,
moreInformationClick,
recommondItemClick,
clookBtn,
clookCancelBtn,
skipCustomerNumberPage,
goVote,
openShare,
sendParams,
changeNetworkStatus,
changeMediaPlayStatus,
openMoreTimeLine,
queryPageLeaveStatus,
quitGraphicDetailPageEvent,
openActiveLink,
reload,
changeAppFontSize,
changeDarkMode,
changeState,
changeAppError
}, toRefs(state))
}
})
app.mount('#app')
app.config.errorHandler = (err) => {
const ev = handleJsError('vue-errorHandler', err, err.message)
h5ErrorPage(ev, err)
}