pageHead.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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.thumb||adImg.image_src">
  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. console.log(adImg.value.thumb)
  245. console.log(101010)
  246. }
  247. }
  248. }
  249. }
  250. //4.获取广告 end ---------------------------------------->
  251. </script>
  252. <style lang="less" scoped>
  253. .userInfo11 {
  254. width: 100px;
  255. height: 80px;
  256. background-color: #fff;
  257. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  258. border-radius: 3px;
  259. position: absolute;
  260. top: 40px;
  261. right: 35px;
  262. font-size: 14px;
  263. z-index: 999;
  264. li {
  265. height: 40px;
  266. line-height: 40px;
  267. color: #333333;
  268. padding-left: 10px;
  269. }
  270. >li:hover {
  271. color: #028E21;
  272. }
  273. }
  274. .tips {
  275. padding: 20px 0;
  276. text-align: center;
  277. font-size: 20px;
  278. color: #40663B;
  279. font-weight: bold;
  280. img {
  281. width: 78px;
  282. height: 78px;
  283. vertical-align: middle;
  284. margin-right: 20px;
  285. p {
  286. line-height: 30px;
  287. }
  288. }
  289. p {
  290. line-height: 40px;
  291. }
  292. >p:first-child {
  293. margin-bottom: 30px;
  294. }
  295. }
  296. /* 页面头部 */
  297. header {
  298. width: 100%;
  299. height: 201px;
  300. font-size: 12px;
  301. font-family: PingFang SC-Regular;
  302. color: #666666;
  303. background: url("../../public/head/headtopbg.png") repeat-x;
  304. }
  305. .headerNav {
  306. width: 100%;
  307. height: 33px;
  308. line-height: 33px;
  309. }
  310. .headerNav .left>span {
  311. margin-right: 47px;
  312. }
  313. .headerNav .right {
  314. display: flex;
  315. margin-right: 10px;
  316. position: relative;
  317. button {
  318. font-size: 12px;
  319. color: #666666;
  320. border: none;
  321. background: none;
  322. cursor: pointer;
  323. }
  324. .login {
  325. width: 36px;
  326. height: 19px;
  327. color: #fff;
  328. border-radius: 4px;
  329. background-color: #028E21;
  330. margin-right: 15px;
  331. cursor: pointer;
  332. }
  333. .menu,
  334. .right-top-menu {
  335. display: flex;
  336. }
  337. .reg {
  338. margin-right: 20px;
  339. display: flex;
  340. align-items: center;
  341. justify-content: center;
  342. height: 33px;
  343. img {
  344. margin-right: 5px;
  345. }
  346. }
  347. }
  348. .headerNav .right {
  349. float: right;
  350. font-size: 12px;
  351. span {
  352. margin-right: 20px;
  353. }
  354. .home,
  355. .collection {
  356. display: inline-block;
  357. width: 16px;
  358. height: 16px;
  359. vertical-align: -3px;
  360. }
  361. .home {
  362. background-image: url("../../public/image/Iconly/Light/Home.png");
  363. }
  364. .collection {
  365. background-image: url("../../public/image/Iconly/Light/Star.png");
  366. }
  367. .exit {
  368. line-height: 30px;
  369. }
  370. // .exit:hover{
  371. // color: #028E21;
  372. // }
  373. }
  374. /* // 头部logo */
  375. .headerLogo {
  376. height: 185px;
  377. position: relative;
  378. //background: url("../../public/head/topBg.png") no-repeat center;
  379. .titlead {
  380. position: absolute;
  381. bottom: 33px;
  382. right: 26px;
  383. img {
  384. height: 120px;
  385. }
  386. }
  387. .inner {
  388. position: relative;
  389. height: 185px;
  390. }
  391. .inner>img {
  392. // width: 342px;
  393. height: 120px;
  394. margin-top: 33px;
  395. cursor: pointer;
  396. }
  397. /* // 搜索框部分 */
  398. .search {
  399. float: left;
  400. width: 440px;
  401. height: 40px;
  402. background-color: #fff;
  403. line-height: 40px;
  404. margin-left: 39px;
  405. margin: 71px 39px 48px;
  406. position: relative;
  407. em {
  408. display: inline-block;
  409. width: 30px;
  410. height: 30px;
  411. background: url("../../public/image/Iconly/Broken/Search.png") no-repeat;
  412. position: absolute;
  413. top: 5px;
  414. left: 15px;
  415. }
  416. input {
  417. float: left;
  418. width: 351px;
  419. height: 40px;
  420. border: none;
  421. outline: none;
  422. padding-left: 65px;
  423. box-sizing: border-box;
  424. border: 1px solid #028E21;
  425. border-right: none;
  426. border-radius: 4px 0px 0px 4px;
  427. }
  428. button {
  429. float: right;
  430. width: 89px;
  431. height: 40px;
  432. background-color: #028E21;
  433. border-radius: 0px 4px 4px 0px;
  434. border: none;
  435. font-size: 14px;
  436. color: #fff;
  437. font-family: PingFang SC, PingFang SC;
  438. font-weight: 500;
  439. }
  440. }
  441. /* // 右侧小图标 */
  442. .serve {
  443. float: right;
  444. height: 60px;
  445. margin-top: 60px;
  446. margin-right: 60px;
  447. >li {
  448. float: left;
  449. height: 64px;
  450. margin-left: 48px;
  451. }
  452. >li>a {
  453. display: inline-block;
  454. height: 64px;
  455. }
  456. >li img {
  457. width: 29px;
  458. height: 29px;
  459. padding: 8px 14px;
  460. }
  461. >li p {
  462. height: 28px;
  463. text-align: center;
  464. color: #666666;
  465. }
  466. }
  467. }
  468. </style>