pageHead.vue 12 KB

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