pageHead.vue 13 KB

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