head.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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="goSearch">
  16. <img src="../../static/head/searchicon.png" alt="搜索">
  17. 搜索
  18. </button>
  19. <button class="reg" @click="goTopic">
  20. <img src="../../static/head/topicon1.png" alt="商圈">
  21. 商圈
  22. </button>
  23. <button class="reg" @click="goAdvertising">
  24. <img src="../../static/head/topicon2.png" alt="广告服务">
  25. 广告服务
  26. </button>
  27. </div>
  28. <div class="right-top-menu">
  29. <button class="reg" @click="goLogin" v-show="!showToken">
  30. <img src="../../static/head/topicon3.png" alt="登录">
  31. 登录
  32. </button>
  33. <button class="reg" @click="goRegister" v-show="!showToken">
  34. <img src="../../static/head/topicon4.png" alt="注册">
  35. 注册
  36. </button>
  37. <button class="reg" @click="userCenter" v-show="showToken">
  38. <img src="../../static/head/topicon3.png" alt="用户信息">
  39. {{ username }}
  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="../../static/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. } else if (response.data.code == 0) {
  192. //退出登录
  193. exit();
  194. }
  195. } catch (error) {
  196. console.error(error);
  197. }
  198. }
  199. </script>
  200. <style lang="less" scoped>
  201. // 广告页面头部
  202. .headerNav {
  203. width: 100%;
  204. height: 56px;
  205. line-height: 56px;
  206. border-bottom: 1px solid #E5E5E5;
  207. // background-color: red;
  208. }
  209. .headerNav .left>span {
  210. margin-right: 47px;
  211. color: #666666;
  212. }
  213. .headerNav .left>.ad {
  214. border-left: 1px solid #E5E5E5;
  215. padding-left: 45px;
  216. color: #333333;
  217. font-weight: 600px;
  218. }
  219. .headerNav .right {
  220. display: flex;
  221. margin-right: 10px;
  222. position: relative;
  223. button {
  224. font-size: 12px;
  225. color: #666666;
  226. border: none;
  227. background: none;
  228. cursor: pointer;
  229. }
  230. .login {
  231. width: 36px;
  232. height: 19px;
  233. color: #fff;
  234. border-radius: 4px;
  235. background-color: #028E21;
  236. margin-right: 15px;
  237. cursor: pointer;
  238. }
  239. .menu,
  240. .right-top-menu {
  241. display: flex;
  242. }
  243. .reg {
  244. margin-right: 20px;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. height: 50px;
  249. img {
  250. margin-right: 5px;
  251. }
  252. }
  253. }
  254. .headerNav .right {
  255. float: right;
  256. font-size: 12px;
  257. // margin-top: 10px;
  258. span {
  259. margin-left: 26px;
  260. }
  261. .home,
  262. .collection {
  263. display: inline-block;
  264. width: 16px;
  265. height: 16px;
  266. vertical-align: -3px;
  267. }
  268. .exit {
  269. line-height: 30px;
  270. }
  271. }
  272. .userInfo11 {
  273. width: 100px;
  274. height: 80px;
  275. background-color: #fff;
  276. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  277. border-radius: 3px;
  278. position: absolute;
  279. top: 50px;
  280. right: 0;
  281. font-size: 14px;
  282. z-index: 999;
  283. li {
  284. height: 40px;
  285. line-height: 40px;
  286. color: #333333;
  287. padding-left: 10px;
  288. }
  289. >li:hover {
  290. color: #028E21;
  291. }
  292. }
  293. //提示信息
  294. .tips {
  295. padding: 20px 0;
  296. text-align: center;
  297. font-size: 20px;
  298. color: #40663B;
  299. font-weight: bold;
  300. img {
  301. width: 78px;
  302. height: 78px;
  303. vertical-align: middle;
  304. margin-right: 20px;
  305. p {
  306. line-height: 30px;
  307. }
  308. }
  309. p {
  310. line-height: 40px;
  311. }
  312. >p:first-child {
  313. margin-bottom: 30px;
  314. }
  315. }
  316. </style>