Head.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div>
  3. <!-- 顶部导航 -->
  4. <nav class="headerNav">
  5. <div class="inner">
  6. <div class="left">
  7. <span>中农兴业网团</span>
  8. <span>旗下网站:
  9. <span>农业百强网站(政府类30强)</span>
  10. </span>
  11. <span class="ad">广告服务</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. <el-dialog v-model="dialogTableVisible" title="" width="800">
  50. <div class="tips">
  51. <p>
  52. <img src="../../public/topic/tips.png" alt="">
  53. 提示:注册请联系管理员操作!
  54. </p>
  55. <p>
  56. 联系电话:010-56019387
  57. </p>
  58. <p>
  59. QQ : 2909421493 、213552413
  60. </p>
  61. </div>
  62. </el-dialog>
  63. </div>
  64. </template>
  65. <script setup>
  66. import { ref, onMounted, watch } from 'vue'
  67. import { ElPopover, ElDialog } from 'element-plus'
  68. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  69. import { setTicket, removeTicket } from '@/store/useticketStore'
  70. // import { navigateTo } from '@nuxtjs/composables';
  71. const nuxtApp = useNuxtApp();
  72. console.log("===:", nuxtApp) // 输出: someValue
  73. const axios = nuxtApp.$axios;
  74. let ticket = ref('')
  75. let token = ref('')
  76. let route = useRoute()
  77. ticket.value = route.query.ticket
  78. token.value = route.query.admintoken
  79. if (ticket.value) {
  80. setTicket(ticket.value)
  81. }
  82. if (token.value) {
  83. setToken(token.value)
  84. }
  85. console.log('查询参数:', ticket.value);
  86. console.log('查询参数:', token.value);
  87. definePageMeta({
  88. middleware: 'auth'
  89. });
  90. let keyword = useState('keyword', () => '')
  91. let username = useState('username', () => '')
  92. let isDel = useState('isDel', () => 1)
  93. let isShow = useState('isShow', () => false)
  94. //点击登录按钮
  95. let goLogin = () => {
  96. isDel.value = 0
  97. token1.value = getToken()
  98. window.location.href = ("http://admindev.bjzxtw.org.cn/auth/login.php?backurl=http://nwdev.bjzxtw.org.cn")
  99. token1.value = getToken()
  100. }
  101. let dialogTableVisible = ref(false)
  102. //点击注册按钮
  103. let goRegister = () => {
  104. dialogTableVisible.value = true
  105. }
  106. let userCenter = () => {
  107. if(isShow.value){
  108. isShow.value = false
  109. return
  110. }else{
  111. isShow.value = true
  112. return
  113. }
  114. }
  115. let gotosystem = () => {
  116. window.location.href = ("http://admindev.bjzxtw.org.cn/#/login?userurl=http://nwdev.bjzxtw.org.cn")
  117. }
  118. //点击退出按钮
  119. let exit = () => {
  120. window.location.href = ('http://nwdev.bjzxtw.org.cn/')
  121. isDel.value = 1
  122. token1.value = getToken()
  123. // axios.get(`http://admindev.bjzxtw.org.cn/auth/logoutapi.php?token=${token}`).then(response => {
  124. // console.log("退出登录", response);
  125. // isDel.value = response.data.isDel
  126. // })
  127. window.location.href = (`http://admindev.bjzxtw.org.cn/auth/logout.php?backurl=http://nwdev.bjzxtw.org.cn&admintoken=${token1}`)
  128. removeToken()
  129. removeTicket()
  130. }
  131. //点击搜索按钮
  132. let goSearch = () => {
  133. const route = `/search/search?keyword=${keyword.value}`;
  134. window.open(route, '_blank');
  135. }
  136. // 点击广告服务
  137. let goAdvertising = () => {
  138. // window.location.href = ('http://localhost:3000/advertising?activeName=${1}')
  139. if (getToken()) {
  140. window.open(`http://nwdev.bjzxtw.org.cn/advertising?activeName=${1}`, '_blank');
  141. } else {
  142. goLogin()
  143. }
  144. }
  145. //点击商圈
  146. let goTopic = () => {
  147. // window.location.href = ('http://localhost:3000/topic')
  148. if (getToken()) {
  149. window.open('http://nwdev.bjzxtw.org.cn/topic', '_blank');
  150. } else {
  151. goLogin()
  152. }
  153. }
  154. //获取用户信息
  155. let getUserInfo = async () => {
  156. try {
  157. const response = await axios.get("/user/getUserInfo");
  158. console.log('获取用户信息', response);
  159. username.value = response.data.nickname
  160. } catch (error) {
  161. console.error(error);
  162. }
  163. }
  164. let token1 = useState("token1", () => '')
  165. let showToken = useState("showToken", () => '')
  166. token1.value = getToken()
  167. watch(token1, (newval, oldval) => {
  168. console.log(newval, oldval);
  169. showToken.value = newval
  170. }, {
  171. deep: true,
  172. immediate: true,
  173. })
  174. onMounted(() => {
  175. //获取用户信息
  176. getUserInfo()
  177. //获取登录状态
  178. getLoginStatus()
  179. })
  180. //检测登录状态
  181. //http://admindev.bjzxtw.org.cn/auth/loginstatus.php?token=XXXXXXXXXXXX
  182. let tokenStatus = ref('');
  183. tokenStatus.value = getToken()
  184. console.log(tokenStatus.value);
  185. //获取用户信息
  186. let getLoginStatus = async () => {
  187. try {
  188. const response = await axios.get(`http://nwdev.bjzxtw.org.cn/auth/loginstatus.php?token=${tokenStatus}`);
  189. console.log('登录状态', response);
  190. if (response.data.code == 200) {
  191. if(response.data.data.islogin == true){
  192. showToken.value = true
  193. }else{
  194. showToken.value = false
  195. exit()
  196. }
  197. } else if (response.data.code == 0) {
  198. //退出登录
  199. exit();
  200. }
  201. } catch (error) {
  202. console.error(error);
  203. }
  204. }
  205. </script>
  206. <style lang="less" scoped>
  207. // 广告页面头部
  208. .headerNav {
  209. width: 100%;
  210. height: 56px;
  211. line-height: 56px;
  212. border-bottom: 1px solid #E5E5E5;
  213. // background-color: red;
  214. }
  215. .headerNav .left>span {
  216. margin-right: 47px;
  217. color: #666666;
  218. }
  219. .headerNav .left>.ad {
  220. border-left: 1px solid #E5E5E5;
  221. padding-left: 45px;
  222. color: #333333;
  223. font-weight: 600px;
  224. }
  225. .headerNav .right {
  226. display: flex;
  227. margin-right: 10px;
  228. position: relative;
  229. button {
  230. font-size: 12px;
  231. color: #666666;
  232. border: none;
  233. background: none;
  234. cursor: pointer;
  235. }
  236. .login {
  237. width: 36px;
  238. height: 19px;
  239. color: #fff;
  240. border-radius: 4px;
  241. background-color: #028E21;
  242. margin-right: 15px;
  243. cursor: pointer;
  244. }
  245. .menu,
  246. .right-top-menu {
  247. display: flex;
  248. }
  249. .reg {
  250. margin-right: 20px;
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. height: 50px;
  255. img {
  256. margin-right: 5px;
  257. }
  258. }
  259. }
  260. .headerNav .right {
  261. float: right;
  262. font-size: 12px;
  263. // margin-top: 10px;
  264. span {
  265. margin-left: 26px;
  266. }
  267. .home,
  268. .collection {
  269. display: inline-block;
  270. width: 16px;
  271. height: 16px;
  272. vertical-align: -3px;
  273. }
  274. .exit {
  275. line-height: 30px;
  276. }
  277. }
  278. .userInfo11 {
  279. width: 100px;
  280. height: 80px;
  281. background-color: #fff;
  282. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  283. border-radius: 3px;
  284. position: absolute;
  285. top: 50px;
  286. right: 0;
  287. font-size: 14px;
  288. z-index: 999;
  289. li {
  290. height: 40px;
  291. line-height: 40px;
  292. color: #333333;
  293. padding-left: 10px;
  294. }
  295. >li:hover {
  296. color: #028E21;
  297. }
  298. }
  299. //提示信息
  300. .tips {
  301. padding: 20px 0;
  302. text-align: center;
  303. font-size: 20px;
  304. color: #40663B;
  305. font-weight: bold;
  306. img {
  307. width: 78px;
  308. height: 78px;
  309. vertical-align: middle;
  310. margin-right: 20px;
  311. p {
  312. line-height: 30px;
  313. }
  314. }
  315. p {
  316. line-height: 40px;
  317. }
  318. >p:first-child {
  319. margin-bottom: 30px;
  320. }
  321. }
  322. </style>