pageHead.vue 16 KB

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