pageHead.vue 13 KB

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