head.vue 9.3 KB

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