pageHead.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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 } 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 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. </script>
  260. <style lang="less" scoped>
  261. .userInfo11 {
  262. width: 100px;
  263. height: 80px;
  264. background-color: #fff;
  265. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  266. border-radius: 3px;
  267. position: absolute;
  268. top: 40px;
  269. right: 35px;
  270. font-size: 14px;
  271. z-index: 999;
  272. li {
  273. height: 40px;
  274. line-height: 40px;
  275. color: #333333;
  276. padding-left: 10px;
  277. }
  278. >li:hover {
  279. color: #028E21;
  280. }
  281. }
  282. .tips {
  283. padding: 20px 0;
  284. text-align: center;
  285. font-size: 20px;
  286. color: #40663B;
  287. font-weight: bold;
  288. img {
  289. width: 78px;
  290. height: 78px;
  291. vertical-align: middle;
  292. margin-right: 20px;
  293. p {
  294. line-height: 30px;
  295. }
  296. }
  297. p {
  298. line-height: 40px;
  299. }
  300. >p:first-child {
  301. margin-bottom: 30px;
  302. }
  303. }
  304. /* 页面头部 */
  305. header {
  306. width: 100%;
  307. height: 201px;
  308. font-size: 12px;
  309. font-family: PingFang SC-Regular;
  310. color: #666666;
  311. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  312. }
  313. .headerNav {
  314. width: 100%;
  315. height: 33px;
  316. line-height: 33px;
  317. }
  318. .headerNav .left>span {
  319. margin-right: 47px;
  320. }
  321. .headerNav .right {
  322. display: flex;
  323. margin-right: 10px;
  324. position: relative;
  325. button {
  326. font-size: 12px;
  327. color: #666666;
  328. border: none;
  329. background: none;
  330. cursor: pointer;
  331. }
  332. .login {
  333. width: 36px;
  334. height: 19px;
  335. color: #fff;
  336. border-radius: 4px;
  337. background-color: #028E21;
  338. margin-right: 15px;
  339. cursor: pointer;
  340. }
  341. .menu,
  342. .right-top-menu {
  343. display: flex;
  344. }
  345. .reg {
  346. margin-right: 20px;
  347. display: flex;
  348. align-items: center;
  349. justify-content: center;
  350. height: 33px;
  351. img {
  352. margin-right: 5px;
  353. }
  354. }
  355. }
  356. .headerNav .right {
  357. float: right;
  358. font-size: 12px;
  359. span {
  360. margin-right: 20px;
  361. }
  362. .home,
  363. .collection {
  364. display: inline-block;
  365. width: 16px;
  366. height: 16px;
  367. vertical-align: -3px;
  368. }
  369. .home {
  370. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  371. }
  372. .collection {
  373. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  374. }
  375. .exit {
  376. line-height: 30px;
  377. }
  378. // .exit:hover{
  379. // color: #028E21;
  380. // }
  381. }
  382. /* // 头部logo */
  383. .headerLogo {
  384. height: 185px;
  385. position: relative;
  386. //background: url("../../public/head/topBg.png") no-repeat center;
  387. .titlead {
  388. position: absolute;
  389. bottom: 33px;
  390. right: 0;
  391. width: 830px;
  392. height: 120px;
  393. overflow: hidden;
  394. a {
  395. display: block;
  396. width: 830px;
  397. height: 110px;
  398. overflow: hidden;
  399. }
  400. img {
  401. width: 100%;
  402. }
  403. }
  404. .inner {
  405. position: relative;
  406. height: 185px;
  407. }
  408. .inner>img {
  409. // width: 342px;
  410. //height: 120px;
  411. margin-top: 47px;
  412. cursor: pointer;
  413. }
  414. /* // 搜索框部分 */
  415. .search {
  416. float: left;
  417. width: 440px;
  418. height: 40px;
  419. background-color: #fff;
  420. line-height: 40px;
  421. margin-left: 39px;
  422. margin: 71px 39px 48px;
  423. position: relative;
  424. em {
  425. display: inline-block;
  426. width: 30px;
  427. height: 30px;
  428. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  429. position: absolute;
  430. top: 5px;
  431. left: 15px;
  432. }
  433. input {
  434. float: left;
  435. width: 351px;
  436. height: 40px;
  437. border: none;
  438. outline: none;
  439. padding-left: 65px;
  440. box-sizing: border-box;
  441. border: 1px solid #028E21;
  442. border-right: none;
  443. border-radius: 4px 0px 0px 4px;
  444. }
  445. button {
  446. float: right;
  447. width: 89px;
  448. height: 40px;
  449. background-color: #028E21;
  450. border-radius: 0px 4px 4px 0px;
  451. border: none;
  452. font-size: 14px;
  453. color: #fff;
  454. font-family: PingFang SC, PingFang SC;
  455. font-weight: 500;
  456. }
  457. }
  458. /* // 右侧小图标 */
  459. .serve {
  460. float: right;
  461. height: 60px;
  462. margin-top: 60px;
  463. margin-right: 60px;
  464. >li {
  465. float: left;
  466. height: 64px;
  467. margin-left: 48px;
  468. }
  469. >li>a {
  470. display: inline-block;
  471. height: 64px;
  472. }
  473. >li img {
  474. width: 29px;
  475. height: 29px;
  476. padding: 8px 14px;
  477. }
  478. >li p {
  479. height: 28px;
  480. text-align: center;
  481. color: #666666;
  482. }
  483. }
  484. }
  485. </style>