pageHead.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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="mid" v-show="!showToken">
  14. <button class="login" @click="goLogin">登录</button>
  15. <NuxtLink to="/">
  16. <button class="reg">注册</button>
  17. </NuxtLink>
  18. <button class="changePwd">修改密码</button>
  19. </div>
  20. <div class="right">
  21. <el-popover placement="top-start" :width="100" trigger="hover" algin="center">
  22. <template #reference>
  23. <span v-show="showToken">
  24. <em class="iconfont icon-gerenzhongxin"></em>
  25. {{ username }}
  26. </span>
  27. </template>
  28. <p class="exit" @click="exit">退出</p>
  29. </el-popover>
  30. <span>
  31. <em class="home"></em>
  32. 设为首页
  33. </span>
  34. <span>
  35. <em class="collection"></em>
  36. 加入收藏
  37. </span>
  38. </div>
  39. </div>
  40. </nav>
  41. <!-- 头部logo -->
  42. <div class="headerLogo">
  43. <div class="inner">
  44. <img src="../../static/images/image 36@2x.png" alt="" class="left">
  45. <div class="search">
  46. <em></em>
  47. <input type="text" placeholder="输入关键词" v-model="keyword">
  48. <button @click="goSearch">搜索</button>
  49. </div>
  50. <ul class="serve">
  51. <li @click="goTopic">
  52. <NuxtLink to="/topic" target="_blank">
  53. <img src="../../static/images/huiyuan 1.png" alt="">
  54. <p>商圈</p>
  55. </NuxtLink>
  56. </li>
  57. <li @click="goAdvertising">
  58. <NuxtLink to="/advertising" target="_blank">
  59. <img src="../../static/images/lingquguanggao 1.png" alt="">
  60. <p>广告服务</p>
  61. </NuxtLink>
  62. </li>
  63. </ul>
  64. </div>
  65. </div>
  66. </header>
  67. </template>
  68. <script setup>
  69. import { ref, onMounted, watch } from 'vue'
  70. import { ElPopover } from 'element-plus'
  71. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  72. import { setTicket, removeTicket } from '@/store/useticketStore'
  73. // import { navigateTo } from '@nuxtjs/composables';
  74. const nuxtApp = useNuxtApp();
  75. const axios = nuxtApp.$axios;
  76. let ticket = ref('')
  77. let token = ref('')
  78. let route = useRoute()
  79. ticket.value = route.query.ticket
  80. token.value = route.query.admintoken
  81. if (ticket.value) {
  82. setTicket(ticket.value)
  83. }
  84. if (token.value) {
  85. setToken(token.value)
  86. }
  87. console.log('查询参数:', ticket.value);
  88. console.log('查询参数:', token.value);
  89. definePageMeta({
  90. middleware: 'auth'
  91. });
  92. let keyword = useState('keyword', () => '')
  93. let username = useState('username', () => '')
  94. let isDel = useState('isDel', () => 1)
  95. //点击登录按钮
  96. let goLogin = () => {
  97. isDel.value = 0
  98. token1.value = getToken()
  99. window.location.href = ("http://adminpre.bjzxtw.org.cn/#/login?backurl=http%3a%2f%2fnwpre.bjzxtw.org.cn%2f")
  100. token1.value = getToken()
  101. }
  102. //点击注册按钮
  103. // let goRegister = () => {
  104. // navigateTo('http://admindev.bjzxtw.org.cn/auth/login.php')
  105. // }
  106. //点击退出按钮
  107. let exit = () => {
  108. window.location.href = ('http://nwpre.bjzxtw.org.cn/')
  109. console.log('退出1111111111111111111111');
  110. isDel.value = 1
  111. token1.value = getToken()
  112. // const currentUrl = window.location.href;
  113. // console.log('currentUrl', currentUrl);
  114. // // 查找参数部分起始位置(?符号位置)
  115. // const index = currentUrl.indexOf('?');
  116. // if (index !== -1) {
  117. // // 截取去除参数后的URL
  118. // var newUrl = currentUrl.slice(0, index);
  119. // // 重新加载页面(赋值给location.href会触发页面刷新)
  120. // window.location.href = newUrl;
  121. // }
  122. axios.get(`http://adminpre.bjzxtw.org.cn/auth/logoutapi.php?token=${token}`).then(response => {
  123. console.log("退出登录", response);
  124. isDel.value = response.data.isDel
  125. })
  126. // window.location.href = (`http://admindev.bjzxtw.org.cn/auth/login.php`)
  127. removeToken()
  128. removeTicket()
  129. }
  130. //点击搜索按钮
  131. let goSearch = () => {
  132. navigateTo({
  133. path: '/primaryNavigation/newsList',
  134. query: {
  135. keyword: keyword.value
  136. }
  137. })
  138. }
  139. //点击广告服务
  140. // let goAdvertising = () => {
  141. // navigateTo('/advertising')
  142. // // if (getToken()) {
  143. // // navigateTo('/advertising')
  144. // // } else {
  145. // // window.location.href = ("http://admindev.bjzxtw.org.cn/auth/login.php?backurl=http%3a%2f%2faaa.letitgo.cn%2f")
  146. // // }
  147. // }
  148. //点击商圈
  149. // let goTopic = () => {
  150. // navigateTo('/topic')
  151. // // if (getToken()) {
  152. // // navigateTo('/topic')
  153. // // } else {
  154. // // window.location.href = ("http://admindev.bjzxtw.org.cn/auth/login.php?backurl=http%3a%2f%2faaa.letitgo.cn%2f")
  155. // // }
  156. // }
  157. //获取用户信息
  158. let getUserInfo = async () => {
  159. try {
  160. const response = await axios.get("/user/getUserInfo");
  161. console.log(response);
  162. username.value = response.data.real_name
  163. } catch (error) {
  164. console.error(error);
  165. }
  166. }
  167. let token1 = useState("token1", () => '')
  168. let showToken = useState("showToken", () => '')
  169. token1.value = getToken()
  170. watch(token1, (newval, oldval) => {
  171. console.log(newval, oldval);
  172. showToken.value = newval
  173. }, {
  174. deep: true,
  175. immediate: true,
  176. })
  177. onMounted(() => {
  178. //获取用户信息
  179. getUserInfo()
  180. })
  181. </script>
  182. <style lang="less" scoped>
  183. /* 页面头部 */
  184. header {
  185. width: 100%;
  186. height: 201px;
  187. font-size: 12px;
  188. font-family: PingFang SC-Regular;
  189. color: #666666;
  190. background: url("../../static/images/Group 1505.png") no-repeat;
  191. }
  192. .headerNav {
  193. width: 100%;
  194. height: 42px;
  195. line-height: 42px;
  196. background-color: #fff;
  197. }
  198. .headerNav .left>span {
  199. margin-right: 47px;
  200. }
  201. .headerNav .mid {
  202. float: left;
  203. margin-left: 100px;
  204. button {
  205. font-size: 12px;
  206. color: #666666;
  207. border: none;
  208. background-color: #fff;
  209. }
  210. .login {
  211. width: 36px;
  212. height: 19px;
  213. color: #fff;
  214. border-radius: 4px;
  215. background-color: #028E21;
  216. margin-right: 15px;
  217. }
  218. .reg {
  219. margin-right: 30px;
  220. }
  221. }
  222. .headerNav .right {
  223. span {
  224. margin-left: 26px;
  225. }
  226. .home,
  227. .collection {
  228. display: inline-block;
  229. width: 16px;
  230. height: 16px;
  231. vertical-align: -3px;
  232. }
  233. .home {
  234. background-image: url("../../static/images/Iconly/Light/Home.png");
  235. }
  236. .collection {
  237. background-image: url("../../static/images/Iconly/Light/Star.png");
  238. }
  239. }
  240. /* // 头部logo */
  241. .headerLogo {
  242. height: 156px;
  243. border-bottom: 3px solid #006616;
  244. .inner>img {
  245. width: 342px;
  246. height: 72px;
  247. margin-top: 51px;
  248. }
  249. /* // 搜索框部分 */
  250. .search {
  251. float: left;
  252. width: 440px;
  253. height: 40px;
  254. background-color: #fff;
  255. line-height: 40px;
  256. margin-left: 39px;
  257. margin: 71px 39px 48px;
  258. position: relative;
  259. em {
  260. display: inline-block;
  261. width: 30px;
  262. height: 30px;
  263. background: url("../../static/images/Iconly/Broken/Search.png") no-repeat;
  264. position: absolute;
  265. top: 5px;
  266. left: 15px;
  267. }
  268. input {
  269. float: left;
  270. width: 351px;
  271. height: 40px;
  272. border: none;
  273. outline: none;
  274. padding-left: 65px;
  275. box-sizing: border-box;
  276. border: 1px solid #028E21;
  277. border-right: none;
  278. border-radius: 4px 0px 0px 4px;
  279. }
  280. button {
  281. float: right;
  282. width: 89px;
  283. height: 40px;
  284. background-color: #028E21;
  285. border-radius: 0px 4px 4px 0px;
  286. border: none;
  287. font-size: 14px;
  288. color: #fff;
  289. font-family: PingFang SC, PingFang SC;
  290. font-weight: 500;
  291. }
  292. }
  293. /* // 右侧小图标 */
  294. .serve {
  295. float: right;
  296. height: 60px;
  297. margin-top: 60px;
  298. margin-right: 60px;
  299. >li {
  300. float: left;
  301. height: 64px;
  302. margin-left: 48px;
  303. }
  304. >li>a {
  305. display: inline-block;
  306. height: 64px;
  307. }
  308. >li img {
  309. width: 29px;
  310. height: 29px;
  311. padding: 8px 14px;
  312. }
  313. >li p {
  314. height: 28px;
  315. text-align: center;
  316. color: #666666;
  317. }
  318. }
  319. }
  320. </style>