pageHead.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <!-- 页面头部 -->
  3. <header>
  4. <!-- 顶部导航 -->
  5. <nav class="headerNav">
  6. <div class="inner">
  7. <div class="left">
  8. <span>欢迎加入三农市场网!</span>
  9. </div>
  10. <div class="right">
  11. <div class="menu">
  12. <button class="reg" @click="goTopic">
  13. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon1.png" alt="商圈">商圈
  14. </button>
  15. <button class="reg" @click="goAdvertising">
  16. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon2.png" alt="广告服务">广告服务
  17. </button>
  18. </div>
  19. <div class="right-top-menu">
  20. <button class="reg" @click="goLogin" v-show="!showToken">
  21. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="登录">登录
  22. </button>
  23. <button class="reg" @click="goRegister" v-show="!showToken">
  24. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon4.png" alt="注册">注册
  25. </button>
  26. <button class="reg" @click="userCenter" v-show="showToken">
  27. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/topicon3.png" alt="用户信息">{{ username }}
  28. </button>
  29. <button class="reg" @click="goSearch">
  30. <img src="http://img.bjzxtw.org.cn/master/bjzxtw/public/head/searchicon.png" alt="搜索">搜索
  31. </button>
  32. </div>
  33. <ul class="userInfo11" v-if="isShow">
  34. <li @click="gotosystem">个人中心</li>
  35. <li @click="exit">退出</li>
  36. </ul>
  37. </div>
  38. </div>
  39. </nav>
  40. <!-- 头部logo -->
  41. <div class="headerLogo">
  42. <div class="inner">
  43. <img :src="logo" :alt="webSiteName" class="left" @click="backHome">
  44. <div class="titlead" v-if="adImg">
  45. <a href="http://sannongdy.org.cn/" v-if="adImg.image_url==null" target="_blank" :title="adImg.place_name">
  46. <img :src="adImg.thumb" :alt="adImg.place_name" data-tag="imgurl.ad_tag">
  47. </a>
  48. <a :href="adImg.image_url" v-else :title="adImg.ad_name">
  49. <img :src="adImg.image_src" :alt="adImg.ad_name" data-tag="imgurl.ad_tag">
  50. </a>
  51. </div>
  52. </div>
  53. </div>
  54. <el-dialog v-model="dialogTableVisible" title="" width="800">
  55. <div class="tips">
  56. <p>
  57. <img src="../../public/topic/tips.png" alt="">
  58. 提示:注册请联系管理员操作!
  59. </p>
  60. <p>
  61. 联系电话:010-56019387
  62. </p>
  63. <p>
  64. QQ : 2909421493 、213552413
  65. </p>
  66. </div>
  67. </el-dialog>
  68. </header>
  69. </template>
  70. <script setup>
  71. //1.加载基本依赖 start ---------------------------------------->
  72. import { ref, watch, onMounted } from 'vue'
  73. import { ElDialog } from 'element-plus'
  74. import { getToken, setToken, removeToken } from '@/store/useCookieStore'
  75. import { setTicket, removeTicket } from '@/store/useticketStore'
  76. //网站地址
  77. const { $webUrl, $CwebUrl, $BwebUrl, $LoginWebUrl } = useNuxtApp()
  78. //1.加载基本依赖 end ---------------------------------------->
  79. //1.登录逻辑 start ---------------------------------------->
  80. let ticket = ref('')
  81. let token = ref('')
  82. let route = useRoute()
  83. //页面每次刷新先判断一下用户状态是否已经过期了
  84. //如果没有过期再储存token
  85. ticket.value = route.query.ticket
  86. token.value = route.query.admintoken
  87. if (ticket.value) {
  88. setTicket(ticket.value)
  89. }
  90. if (token.value) {
  91. setToken(token.value)
  92. }
  93. //搜索框
  94. let keyword = useState('keyword', () => '')
  95. //用户名
  96. let username = useState('username', () => '用户中心')
  97. //是否删除
  98. let isDel = useState('isDel', () => 1)
  99. //是否显示用户中心
  100. let isShow = useState('isShow', () => false)
  101. let token1 = useState("token1", () => '')
  102. let showToken = useState("showToken", () => '')
  103. token1.value = getToken()
  104. //检测登录状态
  105. let tokenStatus = ref('');
  106. tokenStatus.value = getToken()
  107. if (tokenStatus.value == undefined) {
  108. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  109. console.log('错误:未获取到用户token,如果在本地测试请忽略!');
  110. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  111. } else {
  112. console.log(tokenStatus.value);
  113. }
  114. //点击登录按钮
  115. let goLogin = () => {
  116. //开启线上登录模式 start---------------------------------------->
  117. isDel.value = 0
  118. token1.value = getToken()
  119. //王鹏
  120. //window.open($BwebUrl + "/auth/login.php?backurl=" + $CwebUrl, '_blank');
  121. //刘佳伟
  122. //window.open($LoginWebUrl + "/api/goLogin?backurl=" + $CwebUrl, '_blank');
  123. //党云龙
  124. window.open($BwebUrl + "/#/login?backurl=" + $CwebUrl, '_blank');
  125. //开启线上登录模式 end---------------------------------------->
  126. //开启本地登录模式 start---------------------------------------->
  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. //开启本地登录模式 end---------------------------------------->
  130. }
  131. let dialogTableVisible = ref(false)
  132. //点击注册按钮
  133. let goRegister = () => {
  134. dialogTableVisible.value = true
  135. }
  136. //点击用户中心
  137. let userCenter = () => {
  138. if (isShow.value) {
  139. isShow.value = false
  140. return
  141. } else {
  142. isShow.value = true
  143. return
  144. }
  145. }
  146. //2.登录逻辑 end ---------------------------------------->
  147. //3.跳转菜单逻辑 start ---------------------------------------->
  148. let gotosystem = () => {
  149. let url = $BwebUrl + '/#/login?userurl=' + $CwebUrl;
  150. //window.location.href = url;
  151. window.open(url, '_blank');
  152. }
  153. //点击退出按钮
  154. let exit = () => {
  155. window.location.href = $CwebUrl;
  156. isDel.value = 1
  157. token1.value = getToken()
  158. let tokendata = getToken()
  159. console.log("用户退出登录======token为:", tokendata)
  160. //王鹏
  161. //let url = $BwebUrl + '/auth/logout.php?backurl=' + $CwebUrl + '&admintoken=' + tokendata;
  162. //刘佳伟
  163. let url = $LoginWebUrl + '/api/logout?backurl=' + $CwebUrl + '&admintoken=' + tokendata;
  164. window.location.href = url;
  165. removeToken()
  166. removeTicket()
  167. }
  168. //点击返回首页
  169. let backHome = () => {
  170. window.location.href = $CwebUrl;
  171. }
  172. //点击搜索按钮
  173. let goSearch = () => {
  174. const route = `/search/search?keyword=${keyword.value}`;
  175. window.location.href = route;
  176. }
  177. // 点击广告服务
  178. let goAdvertising = () => {
  179. //本地启动广告服务
  180. //window.open('/advertising?activeName=1', '_blank');
  181. //线上启动
  182. if (getToken()) {
  183. window.open($CwebUrl + '/advertising?activeName=1', '_blank');
  184. } else {
  185. goLogin()
  186. }
  187. }
  188. //点击商圈
  189. let goTopic = () => {
  190. if (getToken()) {
  191. window.open($CwebUrl + '/topic', '_blank');
  192. } else {
  193. goLogin()
  194. }
  195. }
  196. //监听token状态
  197. watch(token1, (newval, oldval) => {
  198. //console.log(newval, oldval);
  199. showToken.value = newval
  200. }, {
  201. deep: true,
  202. immediate: true,
  203. })
  204. //获得网站logo
  205. const logo = ref("")
  206. const webSiteName = ref("")
  207. let getLogo = async () => {
  208. const responseStatus = await requestDataPromise('/web/getWebsiteHead', {
  209. method: 'GET',
  210. query: {},
  211. });
  212. logo.value = responseStatus.data.logo;
  213. webSiteName.value = responseStatus.data.website_name;
  214. }
  215. getLogo();
  216. //3.跳转菜单逻辑 end ---------------------------------------->
  217. //4.获取广告 start ---------------------------------------->
  218. let adImg = ref({})
  219. //4.获取广告 end ---------------------------------------->
  220. //5.获取登录状态 start ---------------------------------------->
  221. onMounted(async () => {
  222. //从客户端获取登录状态
  223. //从客户端阶段开始 持续查询登录状态
  224. let getLoginStatus = async () => {
  225. const { $webUrl, $CwebUrl } = useNuxtApp();
  226. const queryParams = new URLSearchParams({
  227. token: getToken()
  228. });
  229. let url = `${$webUrl}/api/loginStatus?${queryParams.toString()}`
  230. const responseStatus = await fetch(url, {
  231. method: 'GET',
  232. headers: {
  233. 'Content-Type': 'application/json',
  234. 'Userurl': $CwebUrl,
  235. //'token': getToken(),
  236. 'Origin': $CwebUrl
  237. }
  238. });
  239. const result = await responseStatus.json();
  240. console.log(result)
  241. if (result.code == 200) {
  242. if (result.data.isLogin == true) {
  243. console.log("用户已经登录!");
  244. showToken.value = true;
  245. } else {
  246. console.log("用户未登录!");
  247. showToken.value = false;
  248. //退出登录
  249. isShow.value = false;
  250. removeToken();
  251. removeTicket();
  252. }
  253. } else {
  254. console.log("用户已退出登录!");
  255. //退出登录
  256. isShow.value = false;
  257. showToken.value = false;
  258. removeToken();
  259. removeTicket();
  260. }
  261. }
  262. getLoginStatus();
  263. setInterval(getLoginStatus, 3000);
  264. //从客户端获取广告
  265. //从客户端获取行政职能部门 加快打开速度
  266. const { $webUrl, $CwebUrl } = useNuxtApp();
  267. //广告1
  268. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_top`
  269. const responseAd1 = await fetch(url, {
  270. headers: {
  271. 'Content-Type': 'application/json',
  272. 'Userurl': $CwebUrl,
  273. 'Origin': $CwebUrl
  274. }
  275. });
  276. const resultAd1 = await responseAd1.json();
  277. adImg.value = resultAd1.data[0];
  278. //从客户端获取用户名
  279. let userInfoUrl = `${$webUrl}/user/getUserInfo`
  280. const userInfoResponse = await fetch(userInfoUrl, {
  281. headers: {
  282. 'Content-Type': 'application/json',
  283. 'Userurl': $CwebUrl,
  284. 'Origin': $CwebUrl
  285. }
  286. });
  287. const userInfo = await userInfoResponse.json();
  288. if (userInfo.code == 200) {
  289. username.value = userInfo.data.nickname
  290. }
  291. })
  292. //5.获取登录状态 end ---------------------------------------->
  293. </script>
  294. <style lang="less" scoped>
  295. @import url('@/assets/css/public/head.less');
  296. </style>