pageHead.vue 17 KB

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