pageHead.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <header>
  3. <nav class="headerNav">
  4. <div class="inner">
  5. <div class="left">
  6. <span>中农兴业网团</span>
  7. <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" v-if="logo">
  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" :title="adImg.place_name">
  45. </a>
  46. <a :href="adImg.image_url" v-else>
  47. <img :src="adImg.image_src" :title="adImg.ad_name">
  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. // window.open('/topic', '_blank');
  212. if (getToken()) {
  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. console.log('网站logo:', responseStatus);
  235. logo.value = responseStatus.data.website_head.logo;
  236. webSiteName.value = responseStatus.data.website_head.website_name;
  237. }
  238. getLogo();
  239. //3.跳转菜单逻辑 end ---------------------------------------->
  240. //4.获取广告 start ---------------------------------------->
  241. //let adList = ref([]);
  242. let adImg = ref({})
  243. async function getAdData(){
  244. const adData = await requestDataPromise('/web/getWebsiteAdvertisement',{method:'GET',query:{'ad_tag':'xcw_top'}});
  245. if(adData.code == 200){
  246. for(let item of adData.data){
  247. if(item.ad_tag == 'xcw_top'){
  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. </script>
  261. <style lang="less" scoped>
  262. .userInfo11 {
  263. width: 100px;
  264. height: 80px;
  265. background-color: #fff;
  266. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  267. border-radius: 3px;
  268. position: absolute;
  269. top: 40px;
  270. right: 35px;
  271. font-size: 14px;
  272. z-index: 999;
  273. li {
  274. height: 40px;
  275. line-height: 40px;
  276. color: #333333;
  277. padding-left: 10px;
  278. }
  279. >li:hover {
  280. color: #028E21;
  281. }
  282. }
  283. .tips {
  284. padding: 20px 0;
  285. text-align: center;
  286. font-size: 20px;
  287. color: #40663B;
  288. font-weight: bold;
  289. img {
  290. width: 78px;
  291. height: 78px;
  292. vertical-align: middle;
  293. margin-right: 20px;
  294. p {
  295. line-height: 30px;
  296. }
  297. }
  298. p {
  299. line-height: 40px;
  300. }
  301. >p:first-child {
  302. margin-bottom: 30px;
  303. }
  304. }
  305. /* 页面头部 */
  306. header {
  307. width: 100%;
  308. height: 180px;
  309. font-size: 12px;
  310. font-family: PingFang SC-Regular;
  311. color: #666666;
  312. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  313. }
  314. .headerNav {
  315. width: 100%;
  316. height: 33px;
  317. line-height: 33px;
  318. }
  319. .headerNav .left>span {
  320. margin-right: 20px;
  321. }
  322. .headerNav .right {
  323. display: flex;
  324. margin-right: 10px;
  325. position: relative;
  326. button {
  327. font-size: 12px;
  328. color: #666666;
  329. border: none;
  330. background: none;
  331. cursor: pointer;
  332. }
  333. .login {
  334. width: 36px;
  335. height: 19px;
  336. color: #fff;
  337. border-radius: 4px;
  338. background-color: #028E21;
  339. margin-right: 15px;
  340. cursor: pointer;
  341. }
  342. .menu,
  343. .right-top-menu {
  344. display: flex;
  345. }
  346. .reg {
  347. margin-right: 20px;
  348. display: flex;
  349. align-items: center;
  350. justify-content: center;
  351. height: 33px;
  352. img {
  353. margin-right: 5px;
  354. }
  355. }
  356. }
  357. .headerNav .right {
  358. float: right;
  359. font-size: 12px;
  360. span {
  361. margin-right: 20px;
  362. }
  363. .home,
  364. .collection {
  365. display: inline-block;
  366. width: 16px;
  367. height: 16px;
  368. vertical-align: -3px;
  369. }
  370. .home {
  371. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  372. }
  373. .collection {
  374. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  375. }
  376. .exit {
  377. line-height: 30px;
  378. }
  379. // .exit:hover{
  380. // color: #028E21;
  381. // }
  382. }
  383. /* // 头部logo */
  384. .headerLogo {
  385. height: 145px;
  386. position: relative;
  387. //background: url("../../public/head/topBg.png") no-repeat center;
  388. .titlead {
  389. position: absolute;
  390. bottom: 14px;
  391. right: 26px;
  392. width: 830px;
  393. height: 110px;
  394. overflow: hidden;
  395. a {
  396. display: block;
  397. width: 830px;
  398. height: 110px;
  399. overflow: hidden;
  400. }
  401. img {
  402. width: 100%;
  403. height:110px;
  404. }
  405. }
  406. .inner {
  407. position: relative;
  408. height: 145px;
  409. }
  410. .inner>img {
  411. width: 297px;
  412. height: 110px;
  413. margin-top: 20px;
  414. cursor: pointer;
  415. }
  416. /* // 搜索框部分 */
  417. .search {
  418. float: left;
  419. width: 440px;
  420. height: 40px;
  421. background-color: #fff;
  422. line-height: 40px;
  423. margin-left: 39px;
  424. margin: 71px 39px 48px;
  425. position: relative;
  426. em {
  427. display: inline-block;
  428. width: 30px;
  429. height: 30px;
  430. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  431. position: absolute;
  432. top: 5px;
  433. left: 15px;
  434. }
  435. input {
  436. float: left;
  437. width: 351px;
  438. height: 40px;
  439. border: none;
  440. outline: none;
  441. padding-left: 65px;
  442. box-sizing: border-box;
  443. border: 1px solid #028E21;
  444. border-right: none;
  445. border-radius: 4px 0px 0px 4px;
  446. }
  447. button {
  448. float: right;
  449. width: 89px;
  450. height: 40px;
  451. background-color: #028E21;
  452. border-radius: 0px 4px 4px 0px;
  453. border: none;
  454. font-size: 14px;
  455. color: #fff;
  456. font-family: PingFang SC, PingFang SC;
  457. font-weight: 500;
  458. }
  459. }
  460. /* // 右侧小图标 */
  461. .serve {
  462. float: right;
  463. height: 60px;
  464. margin-top: 60px;
  465. margin-right: 60px;
  466. >li {
  467. float: left;
  468. height: 64px;
  469. margin-left: 48px;
  470. }
  471. >li>a {
  472. display: inline-block;
  473. height: 64px;
  474. }
  475. >li img {
  476. width: 29px;
  477. height: 29px;
  478. padding: 8px 14px;
  479. }
  480. >li p {
  481. height: 28px;
  482. text-align: center;
  483. color: #666666;
  484. }
  485. }
  486. }
  487. </style>