pageHead.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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="goSearch">
  16. <img src="../../static/head/searchicon.png" alt="搜索">
  17. 搜索
  18. </button>
  19. <button class="reg" @click="goTopic">
  20. <img src="../../static/head/topicon1.png" alt="商圈">
  21. 商圈
  22. </button>
  23. <button class="reg" @click="goAdvertising">
  24. <img src="../../static/head/topicon2.png" alt="广告服务">
  25. 广告服务
  26. </button>
  27. </div>
  28. <div class="right-top-menu">
  29. <button class="reg" @click="goLogin" v-show="!showToken">
  30. <img src="../../static/head/topicon3.png" alt="登录">
  31. 登录
  32. </button>
  33. <button class="reg" @click="goRegister" v-show="!showToken">
  34. <img src="../../static/head/topicon4.png" alt="注册">
  35. 注册
  36. </button>
  37. <el-popover placement="top-start" :width="100" trigger="hover" algin="center">
  38. <template #reference>
  39. <span v-show="showToken">
  40. <em class="iconfont icon-gerenzhongxin"></em>
  41. {{ username }}
  42. </span>
  43. </template>
  44. <p class="exit" @click="gotosystem">个人中心</p>
  45. <p class="exit" @click="exit">退出</p>
  46. </el-popover>
  47. </div>
  48. </div>
  49. </div>
  50. </nav>
  51. <!-- 头部logo -->
  52. <div class="headerLogo">
  53. <div class="inner">
  54. <img src="../../static/image/logo1.png" alt="三农资讯网" class="left" @click="backHome">
  55. <div class="titlead">
  56. <a href="http://www.baidu.com">
  57. <img src="../../static/index/titlead.png" alt="">
  58. </a>
  59. </div>
  60. </div>
  61. </div>
  62. <el-dialog v-model="dialogTableVisible" title="" width="800">
  63. <div class="tips">
  64. <p>
  65. <img src="../../static/topic/tips.png" alt="">
  66. 提示:注册请联系管理员操作!
  67. </p>
  68. <p>
  69. 联系电话:010-56019387
  70. </p>
  71. <p>
  72. QQ : 2909421493 、213552413
  73. </p>
  74. </div>
  75. </el-dialog>
  76. </header>
  77. </template>
  78. <script setup>
  79. import { ref, onMounted, watch } from 'vue'
  80. import { ElPopover, ElDialog } from 'element-plus'
  81. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  82. import { setTicket, removeTicket } from '@/store/useticketStore'
  83. import { fa } from 'element-plus/es/locale/index.mjs';
  84. // import { navigateTo } from '@nuxtjs/composables';
  85. const nuxtApp = useNuxtApp();
  86. console.log("===:", nuxtApp) // 输出: someValue
  87. const axios = nuxtApp.$axios;
  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. console.log('查询参数:', ticket.value);
  100. console.log('查询参数:', token.value);
  101. definePageMeta({
  102. middleware: 'auth'
  103. });
  104. let keyword = useState('keyword', () => '')
  105. let username = useState('username', () => '')
  106. let isDel = useState('isDel', () => 1)
  107. //点击登录按钮
  108. let goLogin = () => {
  109. isDel.value = 0
  110. token1.value = getToken()
  111. // window.location.href = ("http://admindev.bjzxtw.org.cn/#/login?backurl=http%3a%2f%2fnwdev.bjzxtw.org.cn%2f")
  112. window.location.href = ("http://admindev.bjzxtw.org.cn/auth/login.php?backurl=http://nwdev.bjzxtw.org.cn")
  113. token1.value = getToken()
  114. // navigateTo.back()
  115. }
  116. let dialogTableVisible = ref(false)
  117. //点击注册按钮
  118. let goRegister = () => {
  119. dialogTableVisible.value = true
  120. }
  121. let gotosystem = () => {
  122. window.location.href = ("http://admindev.bjzxtw.org.cn/#/login?userurl=http://nwdev.bjzxtw.org.cn")
  123. // window.location.href = ("http://admindev.bjzxtw.org.cn/#/dashboard")
  124. }
  125. //点击退出按钮
  126. let exit = () => {
  127. window.location.href = ('http://nwdev.bjzxtw.org.cn/')
  128. // console.log('退出1111111111111111111111');
  129. isDel.value = 1
  130. token1.value = getToken()
  131. // const currentUrl = window.location.href;
  132. // console.log('currentUrl', currentUrl);
  133. // // 查找参数部分起始位置(?符号位置)
  134. // const index = currentUrl.indexOf('?');
  135. // if (index !== -1) {
  136. // // 截取去除参数后的URL
  137. // var newUrl = currentUrl.slice(0, index);
  138. // // 重新加载页面(赋值给location.href会触发页面刷新)
  139. // window.location.href = newUrl;
  140. // }
  141. // axios.get(`http://admindev.bjzxtw.org.cn/auth/logoutapi.php?token=${token}`).then(response => {
  142. // console.log("退出登录", response);
  143. // isDel.value = response.data.isDel
  144. // })
  145. window.location.href = (`http://admindev.bjzxtw.org.cn/auth/logout.php?backurl=http://nwdev.bjzxtw.org.cn&admintoken=${token1}`)
  146. removeToken()
  147. removeTicket()
  148. }
  149. let backHome = () => {
  150. // window.location.href = ('http://localhost:3000/')
  151. window.location.href = ('http://nwdev.bjzxtw.org.cn/')
  152. }
  153. //点击搜索按钮
  154. let goSearch = () => {
  155. // navigateTo({
  156. // path: '/search/search',
  157. // query: {
  158. // keyword: keyword.value
  159. // }
  160. // })
  161. const route = `/search/search?keyword=${keyword.value}`;
  162. window.open(route, '_blank');
  163. }
  164. // 点击广告服务
  165. let goAdvertising = () => {
  166. // window.open(`http://localhost:3000/advertising?activeName=${1}`, '_blank');
  167. if (getToken()) {
  168. window.open(`http://nwdev.bjzxtw.org.cn/advertising?activeName=${1}`, '_blank');
  169. } else {
  170. goLogin()
  171. }
  172. }
  173. //点击商圈
  174. let goTopic = () => {
  175. // window.open(`http://localhost:3000/topic`, '_blank');
  176. if (getToken()) {
  177. window.open('http://nwdev.bjzxtw.org.cn/topic', '_blank');
  178. } else {
  179. goLogin()
  180. }
  181. }
  182. //获取用户信息
  183. let getUserInfo = async () => {
  184. try {
  185. const response = await axios.get("/user/getUserInfo");
  186. console.log('获取用户信息', response);
  187. username.value = response.data.nickname
  188. } catch (error) {
  189. console.error(error);
  190. }
  191. }
  192. let token1 = useState("token1", () => '')
  193. let showToken = useState("showToken", () => '')
  194. token1.value = getToken()
  195. watch(token1, (newval, oldval) => {
  196. console.log(newval, oldval);
  197. showToken.value = newval
  198. }, {
  199. deep: true,
  200. immediate: true,
  201. })
  202. onMounted(() => {
  203. //获取用户信息
  204. getUserInfo()
  205. //获取登录状态
  206. getLoginStatus()
  207. })
  208. //检测登录状态
  209. //http://admindev.bjzxtw.org.cn/auth/loginstatus.php?token=XXXXXXXXXXXX
  210. let tokenStatus = ref('');
  211. tokenStatus.value = getToken()
  212. console.log(tokenStatus.value);
  213. //获取用户信息
  214. let getLoginStatus = async () => {
  215. try {
  216. const response = await axios.get(`http://nwdev.bjzxtw.org.cn/auth/loginstatus.php?token=${tokenStatus}`);
  217. console.log('登录状态', response);
  218. if(response.data.code == 200){
  219. }else if(response.data.code == 0){
  220. //退出登录
  221. exit();
  222. }
  223. } catch (error) {
  224. console.error(error);
  225. }
  226. }
  227. </script>
  228. <style lang="less" scoped>
  229. .tips {
  230. padding: 20px 0;
  231. text-align: center;
  232. font-size: 20px;
  233. color: #40663B;
  234. font-weight: bold;
  235. img {
  236. width: 78px;
  237. height: 78px;
  238. vertical-align: middle;
  239. margin-right: 20px;
  240. p {
  241. line-height: 30px;
  242. }
  243. }
  244. p {
  245. line-height: 40px;
  246. }
  247. >p:first-child {
  248. margin-bottom: 30px;
  249. }
  250. }
  251. /* 页面头部 */
  252. header {
  253. width: 100%;
  254. height: 201px;
  255. font-size: 12px;
  256. font-family: PingFang SC-Regular;
  257. color: #666666;
  258. background: url("../../static/head/headtopbg.png") repeat-x;
  259. }
  260. .headerNav {
  261. width: 100%;
  262. height: 33px;
  263. line-height: 33px;
  264. }
  265. .headerNav .left>span {
  266. margin-right: 47px;
  267. }
  268. .headerNav .right {
  269. display: flex;
  270. margin-right: 10px;
  271. button {
  272. font-size: 12px;
  273. color: #666666;
  274. border: none;
  275. background: none;
  276. cursor: pointer;
  277. }
  278. .login {
  279. width: 36px;
  280. height: 19px;
  281. color: #fff;
  282. border-radius: 4px;
  283. background-color: #028E21;
  284. margin-right: 15px;
  285. cursor: pointer;
  286. }
  287. .menu,
  288. .right-top-menu {
  289. display: flex;
  290. }
  291. .reg {
  292. margin-right: 20px;
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. height: 33px;
  297. img {
  298. margin-right: 5px;
  299. }
  300. }
  301. }
  302. .headerNav .right {
  303. float: right;
  304. font-size: 12px;
  305. span {
  306. margin-left: 26px;
  307. }
  308. .home,
  309. .collection {
  310. display: inline-block;
  311. width: 16px;
  312. height: 16px;
  313. vertical-align: -3px;
  314. }
  315. .home {
  316. background-image: url("../../static/image/Iconly/Light/Home.png");
  317. }
  318. .collection {
  319. background-image: url("../../static/image/Iconly/Light/Star.png");
  320. }
  321. .exit {
  322. line-height: 30px;
  323. }
  324. // .exit:hover{
  325. // color: #028E21;
  326. // }
  327. }
  328. /* // 头部logo */
  329. .headerLogo {
  330. height: 185px;
  331. position: relative;
  332. background: url("../../static/head/topBg.png") no-repeat center;
  333. .titlead {
  334. position: absolute;
  335. bottom: 54px;
  336. right: 134px;
  337. }
  338. .inner {
  339. position: relative;
  340. height: 185px;
  341. }
  342. .inner>img {
  343. width: 342px;
  344. height: 72px;
  345. margin-top: 51px;
  346. cursor: pointer;
  347. }
  348. /* // 搜索框部分 */
  349. .search {
  350. float: left;
  351. width: 440px;
  352. height: 40px;
  353. background-color: #fff;
  354. line-height: 40px;
  355. margin-left: 39px;
  356. margin: 71px 39px 48px;
  357. position: relative;
  358. em {
  359. display: inline-block;
  360. width: 30px;
  361. height: 30px;
  362. background: url("../../static/image/Iconly/Broken/Search.png") no-repeat;
  363. position: absolute;
  364. top: 5px;
  365. left: 15px;
  366. }
  367. input {
  368. float: left;
  369. width: 351px;
  370. height: 40px;
  371. border: none;
  372. outline: none;
  373. padding-left: 65px;
  374. box-sizing: border-box;
  375. border: 1px solid #028E21;
  376. border-right: none;
  377. border-radius: 4px 0px 0px 4px;
  378. }
  379. button {
  380. float: right;
  381. width: 89px;
  382. height: 40px;
  383. background-color: #028E21;
  384. border-radius: 0px 4px 4px 0px;
  385. border: none;
  386. font-size: 14px;
  387. color: #fff;
  388. font-family: PingFang SC, PingFang SC;
  389. font-weight: 500;
  390. }
  391. }
  392. /* // 右侧小图标 */
  393. .serve {
  394. float: right;
  395. height: 60px;
  396. margin-top: 60px;
  397. margin-right: 60px;
  398. >li {
  399. float: left;
  400. height: 64px;
  401. margin-left: 48px;
  402. }
  403. >li>a {
  404. display: inline-block;
  405. height: 64px;
  406. }
  407. >li img {
  408. width: 29px;
  409. height: 29px;
  410. padding: 8px 14px;
  411. }
  412. >li p {
  413. height: 28px;
  414. text-align: center;
  415. color: #666666;
  416. }
  417. }
  418. }
  419. </style>