pageHead.vue 13 KB

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