pageHead.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  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. window.open(url, '_blank');
  185. }
  186. //点击退出按钮
  187. let exit = () => {
  188. window.location.href = $CwebUrl;
  189. isDel.value = 1
  190. token1.value = getToken()
  191. let url = $BwebUrl + '/auth/logout.php?backurl=' + $CwebUrl + '&admintoken=' + token1;
  192. window.location.href = url;
  193. removeToken()
  194. removeTicket()
  195. }
  196. //点击返回首页
  197. let backHome = () => {
  198. window.location.href = $CwebUrl;
  199. }
  200. //点击搜索按钮
  201. let goSearch = () => {
  202. const route = `/search/search?keyword=${keyword.value}`;
  203. window.location.href = route;
  204. }
  205. // 点击广告服务
  206. let goAdvertising = () => {
  207. //本地启动广告服务
  208. //window.open('/advertising?activeName=1', '_blank');
  209. //线上启动
  210. if (getToken()) {
  211. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  212. } else {
  213. goLogin()
  214. }
  215. }
  216. //点击商圈
  217. let goTopic = () => {
  218. if (getToken()) {
  219. //window.open('http://nwpre.bjzxtw.org.cn/topic', '_blank');
  220. window.open($CwebUrl + '/topic', '_blank');
  221. } else {
  222. goLogin()
  223. }
  224. }
  225. //监听token状态
  226. watch(token1, (newval, oldval) => {
  227. console.log(newval, oldval);
  228. showToken.value = newval
  229. }, {
  230. deep: true,
  231. immediate: true,
  232. })
  233. //3.跳转菜单逻辑 end ---------------------------------------->
  234. //4.获取广告 start ---------------------------------------->
  235. //let adList = ref([]);
  236. let adImg = ref({})
  237. async function getAdData(){
  238. const adData = await requestDataPromise('/web/getWebsiteAdvertisement',{method:'GET',query:{'ad_tag':'INDEDX'}});
  239. for(let item of adData.data){
  240. if(item.ad_tag == 'SNZXWT_INDEDX_0001'){
  241. adImg.value = item;
  242. }
  243. }
  244. }
  245. getAdData();
  246. //4.获取广告 end ---------------------------------------->
  247. </script>
  248. <style lang="less" scoped>
  249. .userInfo11 {
  250. width: 100px;
  251. height: 80px;
  252. background-color: #fff;
  253. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  254. border-radius: 3px;
  255. position: absolute;
  256. top: 40px;
  257. right: 35px;
  258. font-size: 14px;
  259. z-index: 999;
  260. li {
  261. height: 40px;
  262. line-height: 40px;
  263. color: #333333;
  264. padding-left: 10px;
  265. }
  266. >li:hover {
  267. color: #028E21;
  268. }
  269. }
  270. .tips {
  271. padding: 20px 0;
  272. text-align: center;
  273. font-size: 20px;
  274. color: #40663B;
  275. font-weight: bold;
  276. img {
  277. width: 78px;
  278. height: 78px;
  279. vertical-align: middle;
  280. margin-right: 20px;
  281. p {
  282. line-height: 30px;
  283. }
  284. }
  285. p {
  286. line-height: 40px;
  287. }
  288. >p:first-child {
  289. margin-bottom: 30px;
  290. }
  291. }
  292. /* 页面头部 */
  293. header {
  294. width: 100%;
  295. height: 201px;
  296. font-size: 12px;
  297. font-family: PingFang SC-Regular;
  298. color: #666666;
  299. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/head/headtopbg.png") repeat-x;
  300. }
  301. .headerNav {
  302. width: 100%;
  303. height: 33px;
  304. line-height: 33px;
  305. }
  306. .headerNav .left>span {
  307. margin-right: 47px;
  308. }
  309. .headerNav .right {
  310. display: flex;
  311. margin-right: 10px;
  312. position: relative;
  313. button {
  314. font-size: 12px;
  315. color: #666666;
  316. border: none;
  317. background: none;
  318. cursor: pointer;
  319. }
  320. .login {
  321. width: 36px;
  322. height: 19px;
  323. color: #fff;
  324. border-radius: 4px;
  325. background-color: #028E21;
  326. margin-right: 15px;
  327. cursor: pointer;
  328. }
  329. .menu,
  330. .right-top-menu {
  331. display: flex;
  332. }
  333. .reg {
  334. margin-right: 20px;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. height: 33px;
  339. img {
  340. margin-right: 5px;
  341. }
  342. }
  343. }
  344. .headerNav .right {
  345. float: right;
  346. font-size: 12px;
  347. span {
  348. margin-right: 20px;
  349. }
  350. .home,
  351. .collection {
  352. display: inline-block;
  353. width: 16px;
  354. height: 16px;
  355. vertical-align: -3px;
  356. }
  357. .home {
  358. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  359. }
  360. .collection {
  361. background-image: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png");
  362. }
  363. .exit {
  364. line-height: 30px;
  365. }
  366. // .exit:hover{
  367. // color: #028E21;
  368. // }
  369. }
  370. /* // 头部logo */
  371. .headerLogo {
  372. height: 185px;
  373. position: relative;
  374. //background: url("../../public/head/topBg.png") no-repeat center;
  375. .titlead {
  376. position: absolute;
  377. bottom: 33px;
  378. right: 26px;
  379. img {
  380. width: 600px;
  381. height: 120px;
  382. }
  383. }
  384. .inner {
  385. position: relative;
  386. height: 185px;
  387. }
  388. .inner>img {
  389. // width: 342px;
  390. height: 120px;
  391. margin-top: 33px;
  392. cursor: pointer;
  393. }
  394. /* // 搜索框部分 */
  395. .search {
  396. float: left;
  397. width: 440px;
  398. height: 40px;
  399. background-color: #fff;
  400. line-height: 40px;
  401. margin-left: 39px;
  402. margin: 71px 39px 48px;
  403. position: relative;
  404. em {
  405. display: inline-block;
  406. width: 30px;
  407. height: 30px;
  408. background: url("http://img.bjzxtw.org.cn/master/bjzxtw/public/image/search.png") no-repeat;
  409. position: absolute;
  410. top: 5px;
  411. left: 15px;
  412. }
  413. input {
  414. float: left;
  415. width: 351px;
  416. height: 40px;
  417. border: none;
  418. outline: none;
  419. padding-left: 65px;
  420. box-sizing: border-box;
  421. border: 1px solid #028E21;
  422. border-right: none;
  423. border-radius: 4px 0px 0px 4px;
  424. }
  425. button {
  426. float: right;
  427. width: 89px;
  428. height: 40px;
  429. background-color: #028E21;
  430. border-radius: 0px 4px 4px 0px;
  431. border: none;
  432. font-size: 14px;
  433. color: #fff;
  434. font-family: PingFang SC, PingFang SC;
  435. font-weight: 500;
  436. }
  437. }
  438. /* // 右侧小图标 */
  439. .serve {
  440. float: right;
  441. height: 60px;
  442. margin-top: 60px;
  443. margin-right: 60px;
  444. >li {
  445. float: left;
  446. height: 64px;
  447. margin-left: 48px;
  448. }
  449. >li>a {
  450. display: inline-block;
  451. height: 64px;
  452. }
  453. >li img {
  454. width: 29px;
  455. height: 29px;
  456. padding: 8px 14px;
  457. }
  458. >li p {
  459. height: 28px;
  460. text-align: center;
  461. color: #666666;
  462. }
  463. }
  464. }
  465. </style>