pageHead.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  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. let url = $BwebUrl + '/api/loginStatus' //刘佳伟
  160. const responseStatus = await requestDataWebUrl( url, {
  161. method: 'GET',
  162. query: {
  163. 'token': tokenStatus
  164. },
  165. });
  166. console.log('登录状态', responseStatus);
  167. if(responseStatus.data.code == 200){
  168. if(responseStatus.data.data.islogin == true){
  169. showToken.value = true
  170. }else{
  171. showToken.value = false
  172. exit()
  173. }
  174. }else if(responseStatus.data.code == 0){
  175. //退出登录
  176. exit();
  177. }
  178. }
  179. getLoginStatus();
  180. //2.登录逻辑 end ---------------------------------------->
  181. //3.跳转菜单逻辑 start ---------------------------------------->
  182. let gotosystem = () => {
  183. let url = $BwebUrl + '/#/login?userurl=' + $CwebUrl;
  184. window.location.href = url;
  185. }
  186. //点击退出按钮
  187. let exit = () => {
  188. window.location.href = $CwebUrl;
  189. isDel.value = 1
  190. token1.value = getToken()
  191. let url = $BwebUrl + '/auth/logout.php?backurl=' + $CwebUrl + '&admintoken=' + token1;
  192. window.location.href = url;
  193. removeToken()
  194. removeTicket()
  195. }
  196. //点击返回首页
  197. let backHome = () => {
  198. window.location.href = $CwebUrl;
  199. }
  200. //点击搜索按钮
  201. let goSearch = () => {
  202. const route = `/search/search?keyword=${keyword.value}`;
  203. window.open(route, '_blank');
  204. }
  205. // 点击广告服务
  206. let goAdvertising = () => {
  207. if (getToken()) {
  208. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  209. } else {
  210. goLogin()
  211. }
  212. }
  213. //点击商圈
  214. let goTopic = () => {
  215. if (getToken()) {
  216. //window.open('http://nwpre.bjzxtw.org.cn/topic', '_blank');
  217. window.open($CwebUrl + '/topic', '_blank');
  218. } else {
  219. goLogin()
  220. }
  221. }
  222. //监听token状态
  223. watch(token1, (newval, oldval) => {
  224. console.log(newval, oldval);
  225. showToken.value = newval
  226. }, {
  227. deep: true,
  228. immediate: true,
  229. })
  230. //3.跳转菜单逻辑 end ---------------------------------------->
  231. //4.获取广告 start ---------------------------------------->
  232. //let adList = ref([]);
  233. let adImg = ref({})
  234. async function getAdData(){
  235. const adData = await requestDataPromise('/web/getWebsiteAdvertisement',{method:'GET',query:{'ad_tag':'INDEDX'}});
  236. for(let item of adData.data){
  237. if(item.ad_tag == 'SNZXWT_INDEDX_0001'){
  238. adImg.value = item;
  239. }
  240. }
  241. }
  242. getAdData();
  243. //4.获取广告 end ---------------------------------------->
  244. </script>
  245. <style lang="less" scoped>
  246. .userInfo11 {
  247. width: 100px;
  248. height: 80px;
  249. background-color: #fff;
  250. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  251. border-radius: 3px;
  252. position: absolute;
  253. top: 40px;
  254. right: 35px;
  255. font-size: 14px;
  256. z-index: 999;
  257. li {
  258. height: 40px;
  259. line-height: 40px;
  260. color: #333333;
  261. padding-left: 10px;
  262. }
  263. >li:hover {
  264. color: #028E21;
  265. }
  266. }
  267. .tips {
  268. padding: 20px 0;
  269. text-align: center;
  270. font-size: 20px;
  271. color: #40663B;
  272. font-weight: bold;
  273. img {
  274. width: 78px;
  275. height: 78px;
  276. vertical-align: middle;
  277. margin-right: 20px;
  278. p {
  279. line-height: 30px;
  280. }
  281. }
  282. p {
  283. line-height: 40px;
  284. }
  285. >p:first-child {
  286. margin-bottom: 30px;
  287. }
  288. }
  289. /* 页面头部 */
  290. header {
  291. width: 100%;
  292. height: 201px;
  293. font-size: 12px;
  294. font-family: PingFang SC-Regular;
  295. color: #666666;
  296. background: url("../../public/head/headtopbg.png") repeat-x;
  297. }
  298. .headerNav {
  299. width: 100%;
  300. height: 33px;
  301. line-height: 33px;
  302. }
  303. .headerNav .left>span {
  304. margin-right: 47px;
  305. }
  306. .headerNav .right {
  307. display: flex;
  308. margin-right: 10px;
  309. position: relative;
  310. button {
  311. font-size: 12px;
  312. color: #666666;
  313. border: none;
  314. background: none;
  315. cursor: pointer;
  316. }
  317. .login {
  318. width: 36px;
  319. height: 19px;
  320. color: #fff;
  321. border-radius: 4px;
  322. background-color: #028E21;
  323. margin-right: 15px;
  324. cursor: pointer;
  325. }
  326. .menu,
  327. .right-top-menu {
  328. display: flex;
  329. }
  330. .reg {
  331. margin-right: 20px;
  332. display: flex;
  333. align-items: center;
  334. justify-content: center;
  335. height: 33px;
  336. img {
  337. margin-right: 5px;
  338. }
  339. }
  340. }
  341. .headerNav .right {
  342. float: right;
  343. font-size: 12px;
  344. span {
  345. margin-right: 20px;
  346. }
  347. .home,
  348. .collection {
  349. display: inline-block;
  350. width: 16px;
  351. height: 16px;
  352. vertical-align: -3px;
  353. }
  354. .home {
  355. background-image: url("../../public/image/Iconly/Light/Home.png");
  356. }
  357. .collection {
  358. background-image: url("../../public/image/Iconly/Light/Star.png");
  359. }
  360. .exit {
  361. line-height: 30px;
  362. }
  363. // .exit:hover{
  364. // color: #028E21;
  365. // }
  366. }
  367. /* // 头部logo */
  368. .headerLogo {
  369. height: 185px;
  370. position: relative;
  371. //background: url("../../public/head/topBg.png") no-repeat center;
  372. .titlead {
  373. position: absolute;
  374. bottom: 33px;
  375. right: 26px;
  376. img {
  377. height: 120px;
  378. }
  379. }
  380. .inner {
  381. position: relative;
  382. height: 185px;
  383. }
  384. .inner>img {
  385. // width: 342px;
  386. height: 120px;
  387. margin-top: 33px;
  388. cursor: pointer;
  389. }
  390. /* // 搜索框部分 */
  391. .search {
  392. float: left;
  393. width: 440px;
  394. height: 40px;
  395. background-color: #fff;
  396. line-height: 40px;
  397. margin-left: 39px;
  398. margin: 71px 39px 48px;
  399. position: relative;
  400. em {
  401. display: inline-block;
  402. width: 30px;
  403. height: 30px;
  404. background: url("../../public/image/Iconly/Broken/Search.png") no-repeat;
  405. position: absolute;
  406. top: 5px;
  407. left: 15px;
  408. }
  409. input {
  410. float: left;
  411. width: 351px;
  412. height: 40px;
  413. border: none;
  414. outline: none;
  415. padding-left: 65px;
  416. box-sizing: border-box;
  417. border: 1px solid #028E21;
  418. border-right: none;
  419. border-radius: 4px 0px 0px 4px;
  420. }
  421. button {
  422. float: right;
  423. width: 89px;
  424. height: 40px;
  425. background-color: #028E21;
  426. border-radius: 0px 4px 4px 0px;
  427. border: none;
  428. font-size: 14px;
  429. color: #fff;
  430. font-family: PingFang SC, PingFang SC;
  431. font-weight: 500;
  432. }
  433. }
  434. /* // 右侧小图标 */
  435. .serve {
  436. float: right;
  437. height: 60px;
  438. margin-top: 60px;
  439. margin-right: 60px;
  440. >li {
  441. float: left;
  442. height: 64px;
  443. margin-left: 48px;
  444. }
  445. >li>a {
  446. display: inline-block;
  447. height: 64px;
  448. }
  449. >li img {
  450. width: 29px;
  451. height: 29px;
  452. padding: 8px 14px;
  453. }
  454. >li p {
  455. height: 28px;
  456. text-align: center;
  457. color: #666666;
  458. }
  459. }
  460. }
  461. </style>