pageHead.vue 17 KB

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