pageHead.vue 13 KB

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