pageHead.vue 17 KB

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