pageHead.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. <template>
  2. <header>
  3. <nav class="headerNav">
  4. <div class="inner">
  5. <div class="left">
  6. <span>
  7. <a href="http://znxyw.org.cn/" target="_blank">中农兴业网团</a>
  8. </span>
  9. <span>旗下网站:<span>农业百强网站(政府类30强)</span></span>
  10. </div>
  11. <div class="right">
  12. <div class="menu">
  13. <button class="reg" @click="goTopic">
  14. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon1.png" alt="商圈">商圈
  15. </button>
  16. <button class="reg" @click="goAdvertising">
  17. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon2.png" alt="广告服务">广告服务
  18. </button>
  19. </div>
  20. <div class="right-top-menu">
  21. <button class="reg" @click="goLogin" v-show="!showToken">
  22. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="登录">登录
  23. </button>
  24. <button class="reg" @click="goRegister" v-show="!showToken">
  25. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon4.png" alt="注册">注册
  26. </button>
  27. <button class="reg" @click="userCenter" v-show="showToken">
  28. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="用户信息">{{
  29. username }}
  30. </button>
  31. <button class="reg" @click="goSearch">
  32. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/searchicon.png" alt="搜索">搜索
  33. </button>
  34. </div>
  35. <ul class="userInfo11" v-if="isShow">
  36. <li @click="gotosystem">个人中心</li>
  37. <li @click="exit">退出</li>
  38. </ul>
  39. </div>
  40. </div>
  41. </nav>
  42. <div class="headerLogo">
  43. <div class="inner">
  44. <img :src="logo" :alt="webSiteName" class="left" @click="backHome">
  45. <div class="titlead" v-if="adImg">
  46. <a href="http://sannongdy.org.cn/" v-if="adImg.image_url == null" target="_blank"
  47. :title="adImg.introduce">
  48. <img :src="adImg.thumb" :alt="adImg.introduce" data-tag="imgurl.ad_tag" :id="adImg.ad_tag">
  49. </a>
  50. <a :href="adImg.image_url" v-else :title="adImg.introduce">
  51. <img :src="adImg.image_src" :alt="adImg.introduce" data-tag="imgurl.ad_tag" :id="adImg.ad_tag">
  52. </a>
  53. </div>
  54. </div>
  55. </div>
  56. <el-dialog v-model="dialogTableVisible" width="800">
  57. <div class="tips">
  58. <p>
  59. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/topic/tips.png"> 提示:注册请联系管理员操作!
  60. </p>
  61. <p>联系电话:010-56019387</p>
  62. <p>QQ : 2909421493 、213552413</p>
  63. </div>
  64. </el-dialog>
  65. </header>
  66. </template>
  67. <script setup>
  68. //1.加载基本依赖 start ---------------------------------------->
  69. import { ref, watch, onMounted } from 'vue'
  70. import { ElDialog } from 'element-plus'
  71. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  72. import { setTicket, removeTicket } from '@/store/useticketStore'
  73. //网站地址
  74. const { $webUrl, $CwebUrl, $BwebUrl, $LoginWebUrl } = useNuxtApp()
  75. //1.加载基本依赖 end ---------------------------------------->
  76. //1.登录逻辑 start ---------------------------------------->
  77. let ticket = ref('')
  78. let token = ref('')
  79. let route = useRoute()
  80. //页面每次刷新先判断一下用户状态是否已经过期了
  81. //如果没有过期再储存token
  82. ticket.value = route.query.ticket
  83. token.value = route.query.admintoken
  84. if (ticket.value) {
  85. setTicket(ticket.value)
  86. }
  87. if (token.value) {
  88. setToken(token.value)
  89. }
  90. //搜索框
  91. let keyword = useState('keyword', () => '')
  92. //用户名
  93. let username = useState('username', () => '用户中心')
  94. //是否删除
  95. let isDel = useState('isDel', () => 1)
  96. //是否显示用户中心
  97. let isShow = useState('isShow', () => false)
  98. let token1 = useState("token1", () => '')
  99. let showToken = useState("showToken", () => '')
  100. token1.value = getToken()
  101. //检测登录状态
  102. let tokenStatus = ref('');
  103. tokenStatus.value = getToken()
  104. if (tokenStatus.value == undefined) {
  105. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  106. console.log('错误:未获取到用户token,如果在本地测试请忽略!');
  107. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  108. } else {
  109. console.log(tokenStatus.value);
  110. }
  111. //点击登录按钮
  112. let goLogin = () => {
  113. //开启线上登录模式 start---------------------------------------->
  114. isDel.value = 0
  115. token1.value = getToken()
  116. //王鹏
  117. window.open($BwebUrl + "/auth/login.php?backurl=" + $CwebUrl, '_blank');
  118. //刘佳伟
  119. // window.open($LoginWebUrl + "/api/goLogin?backurl=" + $CwebUrl, '_blank');
  120. //开启线上登录模式 end---------------------------------------->
  121. //开启本地登录模式 start---------------------------------------->
  122. // window.location.href = $BwebUrl + "/auth/login.php?backurl=" + $CwebUrl;
  123. //"http://adminpre.bjzxtw.org.cn/auth/login.php?backurl=http://nwpre.bjzxtw.org.cn";
  124. //开启本地登录模式 end---------------------------------------->
  125. }
  126. let dialogTableVisible = ref(false)
  127. //点击注册按钮
  128. let goRegister = () => {
  129. dialogTableVisible.value = true
  130. }
  131. //点击用户中心
  132. let userCenter = () => {
  133. if (isShow.value) {
  134. isShow.value = false
  135. return
  136. } else {
  137. isShow.value = true
  138. return
  139. }
  140. }
  141. // 添加点击事件处理函数
  142. const handleClickOutside = (event) => {
  143. // 获取用户信息菜单元素
  144. const userInfoMenu = document.querySelector('.userInfo11');
  145. // 获取用户按钮元素
  146. const userButton = document.querySelector('.reg img[alt="用户信息"]')?.parentElement;
  147. // 如果点击的不是菜单本身且不是用户按钮,则隐藏菜单
  148. if (userInfoMenu &&
  149. !userInfoMenu.contains(event.target) &&
  150. !userButton?.contains(event.target)) {
  151. isShow.value = false;
  152. }
  153. }
  154. //2.登录逻辑 end ---------------------------------------->
  155. //3.跳转菜单逻辑 start ---------------------------------------->
  156. let gotosystem = () => {
  157. let url = $BwebUrl + '/#/login?userurl=' + $CwebUrl;
  158. //window.location.href = url;
  159. window.open(url, '_blank');
  160. }
  161. //点击退出按钮
  162. let exit = () => {
  163. window.location.href = $CwebUrl;
  164. isDel.value = 1
  165. token1.value = getToken()
  166. let tokendata = getToken()
  167. //王鹏
  168. let url = $BwebUrl + '/auth/logout.php?backurl=' + $CwebUrl + '&admintoken=' + tokendata;
  169. console.log("用户退出登录======token为:", tokendata,url)
  170. //刘佳伟
  171. // let url = $LoginWebUrl + '/api/logout?backurl=' + $CwebUrl + '&admintoken=' + tokendata;
  172. window.location.href = url;
  173. removeToken()
  174. removeTicket()
  175. }
  176. //点击返回首页
  177. let backHome = () => {
  178. window.location.href = $CwebUrl;
  179. }
  180. //点击搜索按钮
  181. let goSearch = () => {
  182. const route = `/search/search?keyword=${keyword.value}`;
  183. window.location.href = route;
  184. }
  185. // 点击广告服务
  186. let goAdvertising = () => {
  187. //本地启动广告服务
  188. //window.open('/advertising?activeName=1', '_blank');
  189. //线上启动
  190. if (getToken()) {
  191. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  192. } else {
  193. goLogin()
  194. }
  195. }
  196. //点击商圈
  197. let goTopic = () => {
  198. if (getToken()) {
  199. window.open($CwebUrl + '/topic', '_blank');
  200. } else {
  201. goLogin()
  202. }
  203. }
  204. //监听token状态
  205. watch(token1, (newval, oldval) => {
  206. //console.log(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. logo.value = responseStatus.data.logo;
  221. webSiteName.value = responseStatus.data.website_name;
  222. }
  223. getLogo();
  224. //3.跳转菜单逻辑 end ---------------------------------------->
  225. //4.获取广告 start ---------------------------------------->
  226. let adImg = ref({})
  227. //4.获取广告 end ---------------------------------------->
  228. //5.获取登录状态 start ---------------------------------------->
  229. // 在组件卸载时移除事件监听
  230. onUnmounted(() => {
  231. document.removeEventListener('click', handleClickOutside);
  232. })
  233. onMounted(async () => {
  234. //添加监听关闭个人中心菜单
  235. document.addEventListener('click', handleClickOutside);
  236. //从客户端获取登录状态
  237. //从客户端阶段开始 持续查询登录状态
  238. let getLoginStatus = async () => {
  239. const { $webUrl, $CwebUrl } = useNuxtApp();
  240. const queryParams = new URLSearchParams({
  241. token: getToken()
  242. });
  243. let url = `${$webUrl}/api/loginStatus?${queryParams.toString()}`
  244. const responseStatus = await fetch(url, {
  245. method: 'GET',
  246. headers: {
  247. 'Content-Type': 'application/json',
  248. 'Userurl': $CwebUrl,
  249. //'token': getToken(),
  250. 'Origin': $CwebUrl
  251. }
  252. });
  253. const result = await responseStatus.json();
  254. console.log(result)
  255. if (result.code == 200) {
  256. if (result.data.isLogin == true) {
  257. console.log("用户已经登录!");
  258. showToken.value = true;
  259. } else {
  260. console.log("用户未登录!");
  261. showToken.value = false;
  262. //退出登录
  263. isShow.value = false;
  264. removeToken();
  265. removeTicket();
  266. }
  267. } else {
  268. console.log("用户已退出登录!");
  269. //退出登录
  270. isShow.value = false;
  271. showToken.value = false;
  272. removeToken();
  273. removeTicket();
  274. }
  275. }
  276. getLoginStatus();
  277. setInterval(getLoginStatus, 3000);
  278. //从客户端获取广告
  279. //从客户端获取行政职能部门 加快打开速度
  280. const { $webUrl, $CwebUrl } = useNuxtApp();
  281. //广告1
  282. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_top`
  283. const responseAd1 = await fetch(url, {
  284. headers: {
  285. 'Content-Type': 'application/json',
  286. 'Userurl': $CwebUrl,
  287. 'Origin': $CwebUrl
  288. }
  289. });
  290. const resultAd1 = await responseAd1.json();
  291. adImg.value = resultAd1.data[0];
  292. //从客户端获取用户名
  293. let userInfoUrl = `${$webUrl}/user/getUserInfo`
  294. const userInfoResponse = await fetch(userInfoUrl, {
  295. headers: {
  296. 'Content-Type': 'application/json',
  297. 'Userurl': $CwebUrl,
  298. 'Origin': $CwebUrl
  299. }
  300. });
  301. const userInfo = await userInfoResponse.json();
  302. if (userInfo.code == 200) {
  303. username.value = userInfo.data.nickname
  304. }
  305. })
  306. //5.获取登录状态 end ---------------------------------------->
  307. </script>
  308. <style lang="less" scoped>
  309. .userInfo11 {
  310. width: 100px;
  311. height: 80px;
  312. background-color: #fff;
  313. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  314. border-radius: 3px;
  315. position: absolute;
  316. top: 40px;
  317. right: 35px;
  318. font-size: 14px;
  319. z-index: 999;
  320. li {
  321. height: 40px;
  322. line-height: 40px;
  323. color: #333333;
  324. padding-left: 10px;
  325. }
  326. >li:hover {
  327. color: #028E21;
  328. }
  329. }
  330. .tips {
  331. padding: 20px 0;
  332. text-align: center;
  333. font-size: 20px;
  334. color: #40663B;
  335. font-weight: bold;
  336. img {
  337. width: 78px;
  338. height: 78px;
  339. vertical-align: middle;
  340. margin-right: 20px;
  341. p {
  342. line-height: 30px;
  343. }
  344. }
  345. p {
  346. line-height: 40px;
  347. }
  348. >p:first-child {
  349. margin-bottom: 30px;
  350. }
  351. }
  352. /* 页面头部 */
  353. header {
  354. width: 100%;
  355. // height: 201px;
  356. font-size: 12px;
  357. font-family: PingFang SC-Regular;
  358. color: #666666;
  359. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  360. }
  361. .headerNav {
  362. width: 100%;
  363. height: 33px;
  364. line-height: 33px;
  365. }
  366. .headerNav .left>span {
  367. margin-right: 20px;
  368. a{
  369. color: #666666;
  370. }
  371. }
  372. .headerNav .right {
  373. display: flex;
  374. margin-right: 10px;
  375. position: relative;
  376. button {
  377. font-size: 12px;
  378. color: #666666;
  379. border: none;
  380. background: none;
  381. cursor: pointer;
  382. }
  383. .login {
  384. width: 36px;
  385. height: 19px;
  386. color: #fff;
  387. border-radius: 4px;
  388. background-color: #028E21;
  389. margin-right: 15px;
  390. cursor: pointer;
  391. }
  392. .menu,
  393. .right-top-menu {
  394. display: flex;
  395. }
  396. .reg {
  397. margin-right: 20px;
  398. display: flex;
  399. align-items: center;
  400. justify-content: center;
  401. height: 33px;
  402. img {
  403. margin-right: 5px;
  404. }
  405. }
  406. }
  407. .headerNav .right {
  408. float: right;
  409. font-size: 12px;
  410. span {
  411. margin-right: 20px;
  412. }
  413. .home,
  414. .collection {
  415. display: inline-block;
  416. width: 16px;
  417. height: 16px;
  418. vertical-align: -3px;
  419. }
  420. .home {
  421. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  422. }
  423. .collection {
  424. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  425. }
  426. .exit {
  427. line-height: 30px;
  428. }
  429. // .exit:hover{
  430. // color: #028E21;
  431. // }
  432. }
  433. /* // 头部logo */
  434. .headerLogo {
  435. height: 145px;
  436. position: relative;
  437. //background: url("../../public/head/topBg.png") no-repeat center;
  438. .titlead {
  439. position: absolute;
  440. bottom: 5px;
  441. right: 0;
  442. width: 830px;
  443. height: 120px;
  444. overflow: hidden;
  445. a {
  446. display: block;
  447. height: 110px;
  448. overflow: hidden;
  449. }
  450. img {
  451. width: 100%;
  452. height: 110px;
  453. }
  454. }
  455. .inner {
  456. position: relative;
  457. height: 145px;
  458. }
  459. .inner>img {
  460. // width: 342px;
  461. //height: 120px;
  462. margin-top: 22px;
  463. cursor: pointer;
  464. }
  465. /* // 搜索框部分 */
  466. .search {
  467. float: left;
  468. width: 440px;
  469. height: 40px;
  470. background-color: #fff;
  471. line-height: 40px;
  472. margin-left: 39px;
  473. margin: 71px 39px 48px;
  474. position: relative;
  475. em {
  476. display: inline-block;
  477. width: 30px;
  478. height: 30px;
  479. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  480. position: absolute;
  481. top: 5px;
  482. left: 15px;
  483. }
  484. input {
  485. float: left;
  486. width: 351px;
  487. height: 40px;
  488. border: none;
  489. outline: none;
  490. padding-left: 65px;
  491. box-sizing: border-box;
  492. border: 1px solid #028E21;
  493. border-right: none;
  494. border-radius: 4px 0px 0px 4px;
  495. }
  496. button {
  497. float: right;
  498. width: 89px;
  499. height: 40px;
  500. background-color: #028E21;
  501. border-radius: 0px 4px 4px 0px;
  502. border: none;
  503. font-size: 14px;
  504. color: #fff;
  505. font-family: PingFang SC, PingFang SC;
  506. font-weight: 500;
  507. }
  508. }
  509. /* // 右侧小图标 */
  510. .serve {
  511. float: right;
  512. height: 60px;
  513. margin-top: 60px;
  514. margin-right: 60px;
  515. >li {
  516. float: left;
  517. height: 64px;
  518. margin-left: 48px;
  519. }
  520. >li>a {
  521. display: inline-block;
  522. height: 64px;
  523. }
  524. >li img {
  525. width: 29px;
  526. height: 29px;
  527. padding: 8px 14px;
  528. }
  529. >li p {
  530. height: 28px;
  531. text-align: center;
  532. color: #666666;
  533. }
  534. }
  535. }
  536. </style>