pageHead.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. 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.data.islogin)
  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 if(result.data.code == 0){
  294. //退出登录
  295. isShow.value = false;
  296. removeToken();
  297. removeTicket();
  298. }
  299. }
  300. setInterval(getLoginStatus, 5000);
  301. //获取广告
  302. //从客户端获取行政职能部门 加快打开速度
  303. const { $webUrl, $CwebUrl } = useNuxtApp();
  304. //广告1
  305. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_top`
  306. const responseAd1 = await fetch(url, {
  307. headers: {
  308. 'Content-Type': 'application/json',
  309. 'Userurl': $CwebUrl,
  310. 'Origin': $CwebUrl
  311. }
  312. });
  313. const resultAd1 = await responseAd1.json();
  314. adImg.value = resultAd1.data[0];
  315. })
  316. //5.获取登录状态 end ---------------------------------------->
  317. </script>
  318. <style lang="less" scoped>
  319. .userInfo11 {
  320. width: 100px;
  321. height: 80px;
  322. background-color: #fff;
  323. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  324. border-radius: 3px;
  325. position: absolute;
  326. top: 40px;
  327. right: 35px;
  328. font-size: 14px;
  329. z-index: 999;
  330. li {
  331. height: 40px;
  332. line-height: 40px;
  333. color: #333333;
  334. padding-left: 10px;
  335. }
  336. >li:hover {
  337. color: #028E21;
  338. }
  339. }
  340. .tips {
  341. padding: 20px 0;
  342. text-align: center;
  343. font-size: 20px;
  344. color: #40663B;
  345. font-weight: bold;
  346. img {
  347. width: 78px;
  348. height: 78px;
  349. vertical-align: middle;
  350. margin-right: 20px;
  351. p {
  352. line-height: 30px;
  353. }
  354. }
  355. p {
  356. line-height: 40px;
  357. }
  358. >p:first-child {
  359. margin-bottom: 30px;
  360. }
  361. }
  362. /* 页面头部 */
  363. header {
  364. width: 100%;
  365. height: 201px;
  366. font-size: 12px;
  367. font-family: PingFang SC-Regular;
  368. color: #666666;
  369. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  370. }
  371. .headerNav {
  372. width: 100%;
  373. height: 33px;
  374. line-height: 33px;
  375. }
  376. .headerNav .left>span {
  377. margin-right: 47px;
  378. }
  379. .headerNav .right {
  380. display: flex;
  381. margin-right: 10px;
  382. position: relative;
  383. button {
  384. font-size: 12px;
  385. color: #666666;
  386. border: none;
  387. background: none;
  388. cursor: pointer;
  389. }
  390. .login {
  391. width: 36px;
  392. height: 19px;
  393. color: #fff;
  394. border-radius: 4px;
  395. background-color: #028E21;
  396. margin-right: 15px;
  397. cursor: pointer;
  398. }
  399. .menu,
  400. .right-top-menu {
  401. display: flex;
  402. }
  403. .reg {
  404. margin-right: 20px;
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. height: 33px;
  409. img {
  410. margin-right: 5px;
  411. }
  412. }
  413. }
  414. .headerNav .right {
  415. float: right;
  416. font-size: 12px;
  417. span {
  418. margin-right: 20px;
  419. }
  420. .home,
  421. .collection {
  422. display: inline-block;
  423. width: 16px;
  424. height: 16px;
  425. vertical-align: -3px;
  426. }
  427. .home {
  428. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  429. }
  430. .collection {
  431. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  432. }
  433. .exit {
  434. line-height: 30px;
  435. }
  436. // .exit:hover{
  437. // color: #028E21;
  438. // }
  439. }
  440. /* // 头部logo */
  441. .headerLogo {
  442. height: 185px;
  443. position: relative;
  444. //background: url("../../public/head/topBg.png") no-repeat center;
  445. .titlead {
  446. position: absolute;
  447. bottom: 33px;
  448. right: 0;
  449. width: 830px;
  450. height: 120px;
  451. overflow: hidden;
  452. a {
  453. display: block;
  454. width: 830px;
  455. height: 110px;
  456. overflow: hidden;
  457. }
  458. img {
  459. width: 100%;
  460. }
  461. }
  462. .inner {
  463. position: relative;
  464. height: 185px;
  465. }
  466. .inner>img {
  467. // width: 342px;
  468. //height: 120px;
  469. margin-top: 47px;
  470. cursor: pointer;
  471. }
  472. /* // 搜索框部分 */
  473. .search {
  474. float: left;
  475. width: 440px;
  476. height: 40px;
  477. background-color: #fff;
  478. line-height: 40px;
  479. margin-left: 39px;
  480. margin: 71px 39px 48px;
  481. position: relative;
  482. em {
  483. display: inline-block;
  484. width: 30px;
  485. height: 30px;
  486. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  487. position: absolute;
  488. top: 5px;
  489. left: 15px;
  490. }
  491. input {
  492. float: left;
  493. width: 351px;
  494. height: 40px;
  495. border: none;
  496. outline: none;
  497. padding-left: 65px;
  498. box-sizing: border-box;
  499. border: 1px solid #028E21;
  500. border-right: none;
  501. border-radius: 4px 0px 0px 4px;
  502. }
  503. button {
  504. float: right;
  505. width: 89px;
  506. height: 40px;
  507. background-color: #028E21;
  508. border-radius: 0px 4px 4px 0px;
  509. border: none;
  510. font-size: 14px;
  511. color: #fff;
  512. font-family: PingFang SC, PingFang SC;
  513. font-weight: 500;
  514. }
  515. }
  516. /* // 右侧小图标 */
  517. .serve {
  518. float: right;
  519. height: 60px;
  520. margin-top: 60px;
  521. margin-right: 60px;
  522. >li {
  523. float: left;
  524. height: 64px;
  525. margin-left: 48px;
  526. }
  527. >li>a {
  528. display: inline-block;
  529. height: 64px;
  530. }
  531. >li img {
  532. width: 29px;
  533. height: 29px;
  534. padding: 8px 14px;
  535. }
  536. >li p {
  537. height: 28px;
  538. text-align: center;
  539. color: #666666;
  540. }
  541. }
  542. }
  543. </style>