pageHead.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. <template>
  2. <header>
  3. <div class="headerContainer">
  4. <div class="headerBox">
  5. <div class="headerMain">
  6. <div class="headerBox_left">欢迎来到全国法制资讯发布中心!</div>
  7. <div class="headerBox_right">
  8. <NuxtLink @click="add_collect_fun()">收藏</NuxtLink>
  9. <span>|</span>
  10. <NuxtLink to="/">人员查询</NuxtLink>
  11. <span>|</span>
  12. <NuxtLink to="/">车辆查询</NuxtLink>
  13. <span>|</span>
  14. <NuxtLink to="/" @click="phone_close_fun">用户登录</NuxtLink>
  15. </div>
  16. </div>
  17. </div>
  18. <div class="logoBox">
  19. <div class="logoBox_left">
  20. <NuxtLink to="/">
  21. <img src="../../public/header/logo.png" alt="logo">
  22. </NuxtLink>
  23. </div>
  24. <div class="logoBox_right">
  25. <div class="logoBox_right_top">
  26. <NuxtLink to="http://www.mps.gov.cn/">公安部</NuxtLink>
  27. <NuxtLink to="http://www.court.gov.cn/">最高人民法院</NuxtLink>
  28. <NuxtLink to="http://www.spp.gov.cn/">最高人民检察院</NuxtLink>
  29. <NuxtLink to="http://www.moj.gov.cn/">司法部</NuxtLink>
  30. <NuxtLink to="http://www.ccdi.gov.cn/">中央纪委国家监委</NuxtLink>
  31. </div>
  32. <div class="logoBox_right_center">
  33. <h2>
  34. <NuxtLink to="/">全国法制资讯发布中心
  35. <span class=" ">
  36. 官网
  37. </span>
  38. </NuxtLink>
  39. </h2>
  40. </div>
  41. <div class="logoBox_right_bottom">
  42. <h4 class="g_text">
  43. <NuxtLink to="/">全国政务信息一体化应用平台</NuxtLink>
  44. </h4>
  45. <h4>
  46. <NuxtLink to="/">fzxfb.org.cn</NuxtLink>
  47. </h4>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </header>
  53. </template>
  54. <script setup>
  55. // 引入全局状态-HomePanel_out
  56. const panelVisible = useState('panelVisible')
  57. //1.加载基本依赖 start ---------------------------------------->
  58. import { ref, watch, onMounted } from 'vue'
  59. import { ElDialog, ElMessage } from 'element-plus'
  60. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  61. import { setTicket, removeTicket } from '@/store/useticketStore'
  62. //网站地址
  63. const { $webUrl, $CwebUrl, $BwebUrl, $LoginWebUrl } = useNuxtApp()
  64. //1.加载基本依赖 end ---------------------------------------->
  65. //1.登录逻辑 start ---------------------------------------->
  66. let ticket = ref('')
  67. let token = ref('')
  68. let route = useRoute()
  69. //页面每次刷新先判断一下用户状态是否已经过期了
  70. //如果没有过期再储存token
  71. ticket.value = route.query.ticket
  72. token.value = route.query.admintoken
  73. if (ticket.value) {
  74. setTicket(ticket.value)
  75. }
  76. if (token.value) {
  77. setToken(token.value)
  78. }
  79. //搜索框
  80. let keyword = useState('keyword', () => '')
  81. //用户名
  82. let username = useState('username', () => '用户中心')
  83. //是否删除
  84. let isDel = useState('isDel', () => 1)
  85. //是否显示用户中心
  86. let isShow = useState('isShow', () => false)
  87. let token1 = useState("token1", () => '')
  88. let showToken = useState("showToken", () => '')
  89. token1.value = getToken()
  90. //检测登录状态
  91. let tokenStatus = ref('');
  92. tokenStatus.value = getToken()
  93. if (tokenStatus.value == undefined) {
  94. console.log("-------------------------------------未获取到用户token")
  95. } else {
  96. console.log("--------------------------------已获取到用户token")
  97. }
  98. //点击登录按钮
  99. let goLogin = () => {
  100. //开启线上登录模式 start---------------------------------------->
  101. isDel.value = 0
  102. token1.value = getToken()
  103. window.open($BwebUrl + "/#/login?backurl=" + $CwebUrl, '_blank');
  104. //开启线上登录模式 end---------------------------------------->
  105. //开启本地登录模式 start---------------------------------------->
  106. // window.location.href = $BwebUrl + "/auth/login.php?backurl=" + $CwebUrl;
  107. //"http://adminpre.bjzxtw.org.cn/auth/login.php?backurl=http://nwpre.bjzxtw.org.cn";
  108. //开启本地登录模式 end---------------------------------------->
  109. }
  110. let dialogTableVisible = ref(false)
  111. let dialogTableVisible_phone = ref(false)
  112. //点击注册按钮
  113. let goRegister = () => {
  114. dialogTableVisible.value = true
  115. }
  116. //点击用户中心
  117. let userCenter = () => {
  118. if (isShow.value) {
  119. isShow.value = false
  120. return
  121. } else {
  122. isShow.value = true
  123. return
  124. }
  125. }
  126. // 添加点击事件处理函数
  127. const handleClickOutside = (event) => {
  128. // 获取用户信息菜单元素
  129. const userInfoMenu = document.querySelector('.userInfo11');
  130. // 获取用户按钮元素
  131. const userButton = document.querySelector('.reg img[alt="用户信息"]')?.parentElement;
  132. // 如果点击的不是菜单本身且不是用户按钮,则隐藏菜单
  133. if (userInfoMenu &&
  134. !userInfoMenu.contains(event.target) &&
  135. !userButton?.contains(event.target)) {
  136. isShow.value = false;
  137. }
  138. }
  139. //2.登录逻辑 end ---------------------------------------->
  140. //3.跳转菜单逻辑 start ---------------------------------------->
  141. let gotosystem = () => {
  142. let url = $BwebUrl + '/#/login?userurl=' + $CwebUrl;
  143. isShow.value = false;
  144. //window.location.href = url;
  145. window.open(url, '_blank');
  146. }
  147. //点击退出按钮
  148. let exit = () => {
  149. window.location.href = $CwebUrl;
  150. isDel.value = 1
  151. token1.value = getToken()
  152. isShow.value = false;
  153. let tokendata = getToken()
  154. let url = $LoginWebUrl + '/api/logout?backurl=' + $CwebUrl + '&admintoken=' + tokendata;
  155. window.location.href = url;
  156. removeToken()
  157. removeTicket()
  158. }
  159. //点击返回首页
  160. let backHome = () => {
  161. window.location.href = $CwebUrl;
  162. }
  163. //点击搜索按钮
  164. let goSearch = () => {
  165. const route = `/search/search?keyword=${keyword.value}`;
  166. window.location.href = route;
  167. }
  168. // 点击广告服务
  169. let goAdvertising = () => {
  170. // window.open('/advertising?activeName=1', '_blank');//测试
  171. //本地启动广告服务
  172. //线上启动
  173. if (getToken()) {
  174. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  175. } else {
  176. goLogin()
  177. }
  178. }
  179. //点击商圈
  180. let goTopic = () => {
  181. if (getToken()) {
  182. window.open($CwebUrl + '/topic', '_blank');
  183. } else {
  184. goLogin()
  185. }
  186. }
  187. //点击用户==手机版11
  188. let user_fun = () => {
  189. if (getToken()) {
  190. //已经登录
  191. goLogin()
  192. } else {
  193. //没有登录
  194. dialogTableVisible_phone.value = true
  195. return
  196. }
  197. }
  198. // 添加关闭对话框处理函数
  199. const phone_close_fun = () => {
  200. // 在这里可以添加关闭对话框前需要执行的逻辑
  201. dialogTableVisible_phone.value = false;
  202. // 确保对话框关闭
  203. goLogin()
  204. }
  205. // 监听token状态
  206. watch(token1, (newval, oldval) => {
  207. showToken.value = newval
  208. }, {
  209. deep: true,
  210. immediate: true,
  211. })
  212. // 获得网站logo
  213. const logo = ref("")
  214. const webSiteName = ref("")
  215. let getLogo = async () => {
  216. const responseStatus = await requestDataPromise('/web/getWebsiteHead', {
  217. method: 'GET',
  218. query: {},
  219. });
  220. if (responseStatus.code == 200) {
  221. logo.value = responseStatus.data.logo;
  222. webSiteName.value = responseStatus.data.website_name;
  223. } else if (responseStatus.code == 0) {
  224. window.location.href = $CwebUrl + '/404';
  225. }
  226. }
  227. getLogo();
  228. //3.跳转菜单逻辑 end ---------------------------------------->
  229. //4.获取广告 start ---------------------------------------->
  230. let adImg = ref({})
  231. //4.获取广告 end ---------------------------------------->
  232. //5.获取登录状态 start ---------------------------------------->
  233. // 在组件卸载时移除事件监听
  234. onUnmounted(() => {
  235. document.removeEventListener('click', handleClickOutside);
  236. })
  237. onMounted(async () => {
  238. //添加监听关闭个人中心菜单
  239. document.addEventListener('click', handleClickOutside);
  240. //从客户端获取登录状态
  241. //从客户端阶段开始 持续查询登录状态
  242. let getLoginStatus = async () => {
  243. //获得token
  244. const token = getToken();
  245. const { $webUrl, $CwebUrl } = useNuxtApp();
  246. if (token == undefined) {
  247. //如果没有获取到token 不访问后端获取在线状态
  248. console.log("没有获取到token!无需查询登录状态!")
  249. showToken.value = false;
  250. } else {
  251. //如果获取到了token 访问后端查询状态
  252. console.log("已获取到用户token,开始查询登录状态!")
  253. const queryParams = new URLSearchParams({
  254. token: getToken()
  255. });
  256. let url = `${$webUrl}/api/loginStatus?${queryParams.toString()}`
  257. const responseStatus = await fetch(url, {
  258. method: 'GET',
  259. headers: {
  260. 'Content-Type': 'application/json',
  261. 'Userurl': $CwebUrl,
  262. //'token': getToken(),
  263. 'Origin': $CwebUrl
  264. }
  265. });
  266. const result = await responseStatus.json();
  267. console.log(result)
  268. if (result.code == 200) {
  269. console.log("用户已经登录!");
  270. showToken.value = true;
  271. }
  272. if (result.code == -1) {
  273. isShow.value = false;
  274. showToken.value = false;
  275. removeToken();
  276. removeTicket();
  277. ElMessage.error('您没有权限登录该网站!')
  278. }
  279. if (result.code == -2) {
  280. isShow.value = false;
  281. showToken.value = false;
  282. removeToken();
  283. removeTicket();
  284. ElMessage.error('您已退出登录!')
  285. }
  286. }
  287. }
  288. getLoginStatus();
  289. setInterval(getLoginStatus, 3000);
  290. //从客户端获取广告
  291. //从客户端获取行政职能部门 加快打开速度
  292. const { $webUrl, $CwebUrl } = useNuxtApp();
  293. //广告1
  294. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_top`
  295. const responseAd1 = await fetch(url, {
  296. headers: {
  297. 'Content-Type': 'application/json',
  298. 'Userurl': $CwebUrl,
  299. 'Origin': $CwebUrl
  300. }
  301. });
  302. const resultAd1 = await responseAd1.json();
  303. adImg.value = resultAd1.data[0];
  304. //从客户端获取用户名
  305. let userInfoUrl = `${$webUrl}/user/getUserInfo`
  306. const userInfoResponse = await fetch(userInfoUrl, {
  307. headers: {
  308. 'Content-Type': 'application/json',
  309. 'Userurl': $CwebUrl,
  310. 'Origin': $CwebUrl
  311. }
  312. });
  313. const userInfo = await userInfoResponse.json();
  314. if (userInfo.code == 200) {
  315. username.value = userInfo.data.nickname
  316. }
  317. })
  318. // 收藏
  319. const add_collect_fun = () => {
  320. const url = window.location.href; // 获取当前页面 URL
  321. const title = document.title; // 获取当前页面标题
  322. try {
  323. // 尝试 IE 特有的方法
  324. if (window.external && window.external.addFavorite) {
  325. window.external.addFavorite(url, title);
  326. }
  327. // 尝试 Firefox 特有的方法 (window.sidebar.addPanel)
  328. else if (window.sidebar && window.sidebar.addPanel) {
  329. window.sidebar.addPanel(title, url, "");
  330. }
  331. // 如果都不支持,则提示用户手动操作 (Chrome, Edge, Safari 等)
  332. else {
  333. alert("您的浏览器不支持自动添加收藏。\n请使用键盘快捷键 Ctrl + D (Mac: Cmd + D) 手动收藏。");
  334. }
  335. } catch (e) {
  336. // 捕获异常,通常也是提示用户手动操作
  337. alert("您的浏览器不支持自动添加收藏。\n请使用键盘快捷键 Ctrl + D (Mac: Cmd + D) 手动收藏。");
  338. }
  339. }
  340. //5.获取登录状态 end ---------------------------------------->
  341. //点击手机
  342. // 添加全局状态
  343. // const panelVisible = useState('panelVisible', () => false)
  344. const togglePanel = () => {
  345. panelVisible.value = true
  346. }
  347. </script>
  348. <style lang="less" scoped>
  349. //自适应 start ---------------------------------------->
  350. //大于1400px
  351. .headerContainer {
  352. width: 100%;
  353. }
  354. .headerBox {
  355. width: 100%;
  356. height: 70PX;
  357. padding: 0px 20PX;
  358. background: rgba(14, 30, 230, .7);
  359. box-sizing: border-box;
  360. .headerMain {
  361. height: 70PX;
  362. .headerBox_left {
  363. float: left;
  364. font-size: 24PX;
  365. color: #fff;
  366. height: 70PX;
  367. line-height: 70PX;
  368. }
  369. .headerBox_right {
  370. float: right;
  371. height: 70PX;
  372. line-height: 70PX;
  373. a {
  374. float: left;
  375. height: 70PX;
  376. line-height: 70PX;
  377. font-size: 24PX;
  378. color: #fff;
  379. }
  380. span {
  381. float: left;
  382. height: 70PX;
  383. line-height: 70PX;
  384. color: #fff;
  385. font-size: 14PX;
  386. margin: 0 10PX;
  387. }
  388. }
  389. }
  390. }
  391. .logoBox {
  392. width: 1400PX;
  393. margin: 0 auto;
  394. overflow: hidden;
  395. .logoBox_left {
  396. width: 210PX;
  397. float: left;
  398. margin-top: 90PX;
  399. img {
  400. display: block;
  401. width: 100%;
  402. }
  403. }
  404. .logoBox_right {
  405. width: 80%;
  406. float: right;
  407. .logoBox_right_top {
  408. text-align: right;
  409. margin-top: 45PX;
  410. a {
  411. font-size: 26PX;
  412. color: #000;
  413. font-weight: bold;
  414. padding-left: 2%;
  415. }
  416. }
  417. .logoBox_right_center {
  418. margin: 10PX 0px;
  419. h2 {
  420. width: 100%;
  421. }
  422. a {
  423. font-size: 75PX;
  424. color: #d70048;
  425. font-weight: bold;
  426. }
  427. span {
  428. float: right;
  429. }
  430. }
  431. .logoBox_right_bottom {
  432. display: flex;
  433. align-items: center;
  434. justify-content: space-between;
  435. h4 {
  436. height: 40PX;
  437. line-height: 40PX;
  438. font-weight: normal;
  439. a {
  440. font-size: 24PX;
  441. color: #000;
  442. }
  443. }
  444. }
  445. }
  446. }
  447. @media screen and (max-width: 1400px) {
  448. .headerBox {
  449. height: 40px;
  450. padding: 0px 10px;
  451. .headerMain {
  452. height: 40px;
  453. .headerBox_left {
  454. font-size: 12px;
  455. height: 40px;
  456. line-height: 40px;
  457. }
  458. .headerBox_right {
  459. height: 40px;
  460. line-height: 40px;
  461. a {
  462. height: 40px;
  463. line-height: 40px;
  464. font-size: 12px;
  465. }
  466. span {
  467. height: 40px;
  468. line-height: 40px;
  469. font-size: 8px;
  470. margin: 0 10px;
  471. }
  472. }
  473. }
  474. }
  475. .logoBox {
  476. width: 100%;
  477. box-sizing: border-box;
  478. padding: 0px 10px;
  479. .logoBox_left {
  480. width: 110px;
  481. margin-top: 33px;
  482. }
  483. .logoBox_right {
  484. width: 80%;
  485. float: right;
  486. .logoBox_right_top {
  487. margin-top: 40px;
  488. a {
  489. font-size: 13px;
  490. padding-left: 2%;
  491. }
  492. }
  493. .logoBox_right_center {
  494. margin: 10px 0px;
  495. a {
  496. font-size: 37px;
  497. }
  498. }
  499. .logoBox_right_bottom {
  500. h4 {
  501. height: 40px;
  502. line-height: 40px;
  503. a {
  504. font-size: 12px;
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. //大于800px小于等于1400px
  512. @media screen and (min-width: 801px) and (max-width: 1400px) {}
  513. //小于等于800px
  514. @media screen and (max-width: 800px) {
  515. .headerContainer {
  516. width: 100%;
  517. margin-top: 80px;
  518. }
  519. .logoBox .logoBox_right .logoBox_right_center {
  520. margin-top: 30px;
  521. }
  522. .logoBox .logoBox_left {
  523. margin-top: 30px;
  524. }
  525. .logoBox .logoBox_right .logoBox_right_center a {
  526. font-size: 46px;
  527. }
  528. .logoBox_right_top {
  529. display: none;
  530. }
  531. .headerBox {
  532. display: none;
  533. }
  534. }
  535. @media screen and (min-width: 1401px) {}
  536. @media screen and (max-width: 1400px) {}
  537. @media screen and (min-width: 801px) and (max-width: 1400px) {}
  538. @media screen and (max-width: 900px) {}
  539. @media screen and (max-width: 800px) {}
  540. </style>