pageHead.vue 13 KB

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