pageHead.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <!-- 页面头部 -->
  3. <header>
  4. <!-- 顶部导航 -->
  5. <nav class="headerNav">
  6. <div class="inner">
  7. <div class="left">
  8. <span>中农兴业网团</span>
  9. <span>旗下网站:
  10. <span>农业百强网站(政府类30强)</span>
  11. </span>
  12. </div>
  13. <div class="right">
  14. <div class="menu">
  15. <button class="reg" @click="goTopic">
  16. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon1.png" alt="商圈">
  17. 商圈
  18. </button>
  19. <button class="reg" @click="goAdvertising">
  20. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon2.png" alt="广告服务">
  21. 广告服务
  22. </button>
  23. </div>
  24. <div class="right-top-menu">
  25. <button class="reg" @click="goLogin" v-show="!showToken">
  26. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="登录">
  27. 登录
  28. </button>
  29. <button class="reg" @click="goRegister" v-show="!showToken">
  30. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon4.png" alt="注册">
  31. 注册
  32. </button>
  33. <button class="reg" @click="userCenter" v-show="showToken">
  34. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="用户信息">
  35. {{ username }}
  36. </button>
  37. <button class="reg" @click="goSearch">
  38. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/searchicon.png" alt="搜索">
  39. 搜索
  40. </button>
  41. </div>
  42. <ul class="userInfo11" v-if="isShow">
  43. <li @click="gotosystem">个人中心</li>
  44. <li @click="exit">退出</li>
  45. </ul>
  46. </div>
  47. </div>
  48. </nav>
  49. <!-- 头部logo -->
  50. <div class="headerLogo">
  51. <div class="inner">
  52. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/image/logo1.png" alt="三农资讯网" class="left" @click="backHome">
  53. <div class="titlead" v-if="adImg">
  54. <a href="http://www.baidu.com" title="三农资讯网_广告位1" v-if="adImg.image_url==null" target="_blank">
  55. <img :src="adImg.thumb" alt="三农资讯网_广告位1">
  56. </a>
  57. <a :href="adImg.image_url" title="三农资讯网_广告位1" v-else>
  58. <img :src="adImg.image_src" alt="三农资讯网_广告位1">
  59. </a>
  60. </div>
  61. </div>
  62. </div>
  63. <el-dialog v-model="dialogTableVisible" title="" width="800">
  64. <div class="tips">
  65. <p>
  66. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/topic/tips.png" alt="">
  67. 提示:注册请联系管理员操作!
  68. </p>
  69. <p>
  70. 联系电话:010-56019387
  71. </p>
  72. <p>
  73. QQ : 2909421493 、213552413
  74. </p>
  75. </div>
  76. </el-dialog>
  77. </header>
  78. </template>
  79. <script setup>
  80. //1.加载基本依赖 start ---------------------------------------->
  81. import { ref, onMounted, watch } from 'vue'
  82. import { ElPopover, ElDialog } from 'element-plus'
  83. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  84. import { setTicket, removeTicket } from '@/store/useticketStore'
  85. const { $webUrl, $CwebUrl, $BwebUrl} = useNuxtApp()
  86. //1.加载基本依赖 end ---------------------------------------->
  87. //1.登录逻辑 start ---------------------------------------->
  88. let ticket = ref('')
  89. let token = ref('')
  90. let route = useRoute()
  91. ticket.value = route.query.ticket
  92. token.value = route.query.admintoken
  93. if (ticket.value) {
  94. setTicket(ticket.value)
  95. }
  96. if (token.value) {
  97. setToken(token.value)
  98. }
  99. definePageMeta({
  100. middleware: 'auth'
  101. });
  102. //搜索框
  103. let keyword = useState('keyword', () => '')
  104. //用户名
  105. let username = useState('username', () => '用户中心')
  106. //是否删除
  107. let isDel = useState('isDel', () => 1)
  108. //是否显示用户中心
  109. let isShow = useState('isShow', () => false)
  110. let token1 = useState("token1", () => '')
  111. let showToken = useState("showToken", () => '')
  112. token1.value = getToken()
  113. //检测登录状态
  114. let tokenStatus = ref('');
  115. tokenStatus.value = getToken()
  116. console.log(tokenStatus.value);
  117. //点击登录按钮
  118. let goLogin = () => {
  119. isDel.value = 0
  120. token1.value = getToken()
  121. window.open($BwebUrl + "/auth/login.php?backurl=" + $CwebUrl, '_blank');
  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. token1.value = getToken()
  125. // navigateTo.back()
  126. }
  127. let dialogTableVisible = ref(false)
  128. //点击注册按钮
  129. let goRegister = () => {
  130. dialogTableVisible.value = true
  131. }
  132. //点击用户中心
  133. let userCenter = () => {
  134. if(isShow.value){
  135. isShow.value = false
  136. return
  137. }else{
  138. isShow.value = true
  139. return
  140. }
  141. }
  142. //获取用户登录信息
  143. let getUserInfo = async () => {
  144. const responseStatus = await requestDataPromise('/user/getUserInfo', {
  145. method: 'GET',
  146. query: {},
  147. });
  148. console.log('用户信息:', responseStatus);
  149. //如果能拿到信息,就赋值给username
  150. if(responseStatus.code==200){
  151. username.value = responseStatus.data.nickname
  152. }
  153. }
  154. getUserInfo();
  155. //获取登录状态
  156. let getLoginStatus = async () => {
  157. //let url = $BwebUrl + '/auth/loginstatus.php' //王鹏
  158. let url = $webUrl + '/api/loginStatus' //刘佳伟
  159. const responseStatus = await requestDataWebUrl( url, {
  160. method: 'GET',
  161. query: {
  162. 'token': tokenStatus
  163. },
  164. });
  165. console.log('登录状态', responseStatus);
  166. if(responseStatus.data.code == 200){
  167. if(responseStatus.data.data.islogin == true){
  168. showToken.value = true
  169. }else{
  170. showToken.value = false
  171. exit()
  172. }
  173. }else if(responseStatus.data.code == 0){
  174. //退出登录
  175. exit();
  176. }
  177. }
  178. //getLoginStatus();
  179. //2.登录逻辑 end ---------------------------------------->
  180. //3.跳转菜单逻辑 start ---------------------------------------->
  181. let gotosystem = () => {
  182. let url = $BwebUrl + '/#/login?userurl=' + $CwebUrl;
  183. window.location.href = url;
  184. }
  185. //点击退出按钮
  186. let exit = () => {
  187. window.location.href = $CwebUrl;
  188. isDel.value = 1
  189. token1.value = getToken()
  190. let url = $BwebUrl + '/auth/logout.php?backurl=' + $CwebUrl + '&admintoken=' + token1;
  191. window.location.href = url;
  192. removeToken()
  193. removeTicket()
  194. }
  195. //点击返回首页
  196. let backHome = () => {
  197. window.location.href = $CwebUrl;
  198. }
  199. //点击搜索按钮
  200. let goSearch = () => {
  201. const route = `/search/search?keyword=${keyword.value}`;
  202. window.location.href = route;
  203. }
  204. // 点击广告服务
  205. let goAdvertising = () => {
  206. //本地启动广告服务
  207. //window.open('/advertising?activeName=1', '_blank');
  208. //线上启动
  209. if (getToken()) {
  210. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  211. } else {
  212. goLogin()
  213. }
  214. }
  215. //点击商圈
  216. let goTopic = () => {
  217. if (getToken()) {
  218. //window.open('http://nwpre.bjzxtw.org.cn/topic', '_blank');
  219. window.open($CwebUrl + '/topic', '_blank');
  220. } else {
  221. goLogin()
  222. }
  223. }
  224. //监听token状态
  225. watch(token1, (newval, oldval) => {
  226. console.log(newval, oldval);
  227. showToken.value = newval
  228. }, {
  229. deep: true,
  230. immediate: true,
  231. })
  232. //3.跳转菜单逻辑 end ---------------------------------------->
  233. //4.获取广告 start ---------------------------------------->
  234. //let adList = ref([]);
  235. let adImg = ref({})
  236. async function getAdData(){
  237. const adData = await requestDataPromise('/web/getWebsiteAdvertisement',{method:'GET',query:{'ad_tag':'INDEDX'}});
  238. for(let item of adData.data){
  239. if(item.ad_tag == 'SNZXWT_INDEDX_0001'){
  240. adImg.value = item;
  241. }
  242. }
  243. }
  244. getAdData();
  245. //4.获取广告 end ---------------------------------------->
  246. </script>
  247. <style lang="less" scoped>
  248. .userInfo11 {
  249. width: 100px;
  250. height: 80px;
  251. background-color: #fff;
  252. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  253. border-radius: 3px;
  254. position: absolute;
  255. top: 40px;
  256. right: 35px;
  257. font-size: 14px;
  258. z-index: 999;
  259. li {
  260. height: 40px;
  261. line-height: 40px;
  262. color: #333333;
  263. padding-left: 10px;
  264. }
  265. >li:hover {
  266. color: #028E21;
  267. }
  268. }
  269. .tips {
  270. padding: 20px 0;
  271. text-align: center;
  272. font-size: 20px;
  273. color: #40663B;
  274. font-weight: bold;
  275. img {
  276. width: 78px;
  277. height: 78px;
  278. vertical-align: middle;
  279. margin-right: 20px;
  280. p {
  281. line-height: 30px;
  282. }
  283. }
  284. p {
  285. line-height: 40px;
  286. }
  287. >p:first-child {
  288. margin-bottom: 30px;
  289. }
  290. }
  291. /* 页面头部 */
  292. header {
  293. width: 100%;
  294. height: 201px;
  295. font-size: 12px;
  296. font-family: PingFang SC-Regular;
  297. color: #666666;
  298. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  299. }
  300. .headerNav {
  301. width: 100%;
  302. height: 33px;
  303. line-height: 33px;
  304. }
  305. .headerNav .left>span {
  306. margin-right: 47px;
  307. }
  308. .headerNav .right {
  309. display: flex;
  310. margin-right: 10px;
  311. position: relative;
  312. button {
  313. font-size: 12px;
  314. color: #666666;
  315. border: none;
  316. background: none;
  317. cursor: pointer;
  318. }
  319. .login {
  320. width: 36px;
  321. height: 19px;
  322. color: #fff;
  323. border-radius: 4px;
  324. background-color: #028E21;
  325. margin-right: 15px;
  326. cursor: pointer;
  327. }
  328. .menu,
  329. .right-top-menu {
  330. display: flex;
  331. }
  332. .reg {
  333. margin-right: 20px;
  334. display: flex;
  335. align-items: center;
  336. justify-content: center;
  337. height: 33px;
  338. img {
  339. margin-right: 5px;
  340. }
  341. }
  342. }
  343. .headerNav .right {
  344. float: right;
  345. font-size: 12px;
  346. span {
  347. margin-right: 20px;
  348. }
  349. .home,
  350. .collection {
  351. display: inline-block;
  352. width: 16px;
  353. height: 16px;
  354. vertical-align: -3px;
  355. }
  356. .home {
  357. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  358. }
  359. .collection {
  360. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  361. }
  362. .exit {
  363. line-height: 30px;
  364. }
  365. // .exit:hover{
  366. // color: #028E21;
  367. // }
  368. }
  369. /* // 头部logo */
  370. .headerLogo {
  371. height: 185px;
  372. position: relative;
  373. //background: url("../../public/head/topBg.png") no-repeat center;
  374. .titlead {
  375. position: absolute;
  376. bottom: 33px;
  377. right: 26px;
  378. img {
  379. width: 600px;
  380. height: 120px;
  381. }
  382. }
  383. .inner {
  384. position: relative;
  385. height: 185px;
  386. }
  387. .inner>img {
  388. // width: 342px;
  389. height: 120px;
  390. margin-top: 33px;
  391. cursor: pointer;
  392. }
  393. /* // 搜索框部分 */
  394. .search {
  395. float: left;
  396. width: 440px;
  397. height: 40px;
  398. background-color: #fff;
  399. line-height: 40px;
  400. margin-left: 39px;
  401. margin: 71px 39px 48px;
  402. position: relative;
  403. em {
  404. display: inline-block;
  405. width: 30px;
  406. height: 30px;
  407. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  408. position: absolute;
  409. top: 5px;
  410. left: 15px;
  411. }
  412. input {
  413. float: left;
  414. width: 351px;
  415. height: 40px;
  416. border: none;
  417. outline: none;
  418. padding-left: 65px;
  419. box-sizing: border-box;
  420. border: 1px solid #028E21;
  421. border-right: none;
  422. border-radius: 4px 0px 0px 4px;
  423. }
  424. button {
  425. float: right;
  426. width: 89px;
  427. height: 40px;
  428. background-color: #028E21;
  429. border-radius: 0px 4px 4px 0px;
  430. border: none;
  431. font-size: 14px;
  432. color: #fff;
  433. font-family: PingFang SC, PingFang SC;
  434. font-weight: 500;
  435. }
  436. }
  437. /* // 右侧小图标 */
  438. .serve {
  439. float: right;
  440. height: 60px;
  441. margin-top: 60px;
  442. margin-right: 60px;
  443. >li {
  444. float: left;
  445. height: 64px;
  446. margin-left: 48px;
  447. }
  448. >li>a {
  449. display: inline-block;
  450. height: 64px;
  451. }
  452. >li img {
  453. width: 29px;
  454. height: 29px;
  455. padding: 8px 14px;
  456. }
  457. >li p {
  458. height: 28px;
  459. text-align: center;
  460. color: #666666;
  461. }
  462. }
  463. }
  464. </style>