MyHeader.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <header class="my-header">
  3. <div class="header-wrap">
  4. <ul class="wrap-item left">
  5. <li class="item home">
  6. <a
  7. :href="`${wwwURL}${dealDirect()}`"
  8. target="_blank"
  9. >{{ $t("hoolihome") }}</a>
  10. </li>
  11. </ul>
  12. <ul class="wrap-item right">
  13. <li class="item lang">
  14. <a
  15. class="lang-wrap"
  16. href="javascript:void(0);">
  17. <img
  18. :src="localeArr[currentLocaleIndex].img"
  19. class="flag">
  20. <span class="lang-select">{{ localeArr[currentLocaleIndex].name }}</span>
  21. <span class="iconfont icon-xiala"/>
  22. </a>
  23. <ul class="box lang-list">
  24. <li
  25. v-for="(item,index) in localeArr"
  26. :key="index"
  27. class="lang-item"
  28. @click="handleSelectLang(index)">
  29. <img
  30. :src="item.img"
  31. class="flag">
  32. <span class="text">{{ item.name }}</span>
  33. </li>
  34. </ul>
  35. </li>
  36. <li
  37. v-if="loginUserInfo.token"
  38. class="item login-yes">
  39. <a
  40. :href="`${wwwURL}/${locale}/user/settings`"
  41. target="_blank"
  42. class="user-name">{{ loginUserInfo.userName }}</a>
  43. <span class="mid">,</span>
  44. <span
  45. :class="{'btn':true,'logout':true,'lock':isLogoutLock}"
  46. @click="handleLogout">{{ $t("logout") }}</span>
  47. </li>
  48. <li
  49. v-else
  50. class="item login-no">
  51. <a
  52. href="javascript:void(0);"
  53. @click="handleShowView('LoginBySms', { report: 1 })">{{ $t("signIn") }}</a>
  54. <span>/</span>
  55. <a
  56. href="javascript:void(0);"
  57. @click="handleShowView('RegisterByMobile', { report: 2 })">{{ $t("signUp") }}</a>
  58. </li>
  59. </ul>
  60. </div>
  61. <common-login
  62. v-if="currentView.view"
  63. :view-model.sync="currentView"/>
  64. </header>
  65. </template>
  66. <script>
  67. import { php_api_user_login_out } from '~/common/apis.js'
  68. import CommonLogin from '~/components/login-register/CommonLogin'
  69. import { wwwURL } from '~/common/config.js'
  70. export default {
  71. components: {
  72. CommonLogin
  73. },
  74. data() {
  75. return {
  76. wwwURL,
  77. localeArr: [
  78. {
  79. id: '1',
  80. locale: 'cn',
  81. name: '简体中文',
  82. img: '//static.hoolihome.com/common/default/lang-cn.jpg'
  83. },
  84. {
  85. id: '2',
  86. locale: 'en',
  87. name: 'English',
  88. img: '//static.hoolihome.com/common/default/lang-en.jpg'
  89. }
  90. ],
  91. currentLocaleIndex: 0,
  92. locale: 'cn',
  93. loginUserInfo: {},
  94. currentView: {},
  95. isLogoutLock: false,
  96. beforeViewData: null
  97. }
  98. },
  99. created() {
  100. let { locale, loginUserInfo } = this.$store.state
  101. this.locale = locale
  102. this.loginUserInfo = loginUserInfo
  103. this.localeArr.some((val, i) => {
  104. if (val.locale === locale) {
  105. this.currentLocaleIndex = i
  106. return true
  107. }
  108. })
  109. },
  110. mounted() {
  111. this.getThirdInfo()
  112. },
  113. methods: {
  114. getThirdInfo() {
  115. const loginUserInfo = this.$Utils.MyCookie.getCookie('loginUserInfo')
  116. const thirdLoginInfo = this.$Utils.MyCookie.getCookie('thirdLoginInfo')
  117. if (loginUserInfo) return // 有登录信息 不操作
  118. if (!thirdLoginInfo) return
  119. let thirdInfo
  120. try {
  121. thirdInfo = JSON.parse(decodeURIComponent(thirdLoginInfo))
  122. } catch (error) {}
  123. if (!thirdInfo) return
  124. const thirdData = thirdInfo.info
  125. switch (thirdInfo.type) {
  126. case 'reg': {
  127. this.handleShowView('RegisterByMobile', {
  128. isBindSocialInfo: true
  129. })
  130. return
  131. }
  132. // case 'login': {
  133. // this.$Utils.MyCookie.deleteCookie('thirdLoginInfo', true)
  134. // this.$Utils.MyCookie.setCookie(
  135. // 'loginUserInfo',
  136. // encodeURIComponent(JSON.stringify(thirdData)),
  137. // 7,
  138. // true
  139. // )
  140. // location.reload()
  141. // return
  142. // }
  143. case 'error': {
  144. this.$Utils.MyCookie.deleteCookie('thirdLoginInfo', true)
  145. if (thirdData) {
  146. this.$alert(thirdData, this.$t('common.tips'))
  147. }
  148. return
  149. }
  150. }
  151. },
  152. dealDirect() {
  153. let { locale } = this.$store.state
  154. if (locale === 'cn') {
  155. let { fullPath } = this.$route
  156. if (fullPath.indexOf('/cn') === 0) {
  157. return '/cn'
  158. } else {
  159. return ''
  160. }
  161. } else {
  162. return `/${locale}`
  163. }
  164. },
  165. handleSelectLang(selectIndex) {
  166. let { locales } = this.$store.state
  167. let { fullPath } = this.$route
  168. let targetLang = this.localeArr[selectIndex].locale
  169. let routeLang = ''
  170. locales.some((val, index) => {
  171. if (fullPath.indexOf(`/${val}`) === 0) {
  172. routeLang = val
  173. return true
  174. }
  175. })
  176. if (routeLang) {
  177. if (targetLang === 'cn') {
  178. let url = fullPath.replace(`/${routeLang}`, '')
  179. window.location.href = url ? url : '/'
  180. } else {
  181. window.location.href = fullPath.replace(routeLang, targetLang)
  182. }
  183. } else {
  184. if (targetLang === 'cn') {
  185. window.location.reload()
  186. } else {
  187. window.location.href = `/${targetLang}${fullPath}`
  188. }
  189. }
  190. },
  191. handleShowView(view, params = {}) {
  192. if (params.report) {
  193. if (params.report === 1) {
  194. this.$hooliAnalysis.upload(
  195. {
  196. ec: this.$C.ENTRANCE_CODE.register
  197. },
  198. true
  199. )
  200. }
  201. if (params.report === 2) {
  202. this.$hooliAnalysis.upload({
  203. ec: this.$C.ENTRANCE_CODE.register,
  204. et: this.$C.EVENT_TYPE.click
  205. })
  206. }
  207. }
  208. delete params.report
  209. this.currentView = { view, params }
  210. },
  211. handleLogout() {
  212. this.isLogoutLock = true
  213. this.$axios
  214. .$post(php_api_user_login_out, {})
  215. .then(res => {
  216. this.$Utils.MyCookie.deleteCookie('loginUserInfo', true)
  217. window.location.reload()
  218. })
  219. .catch(e => {
  220. this.$Utils.MyCookie.deleteCookie('loginUserInfo', true)
  221. window.location.reload()
  222. })
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="less" scoped>
  228. .my-header {
  229. background-color: #303030;
  230. .header-wrap {
  231. position: relative;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. width: 1200px;
  236. height: 40px;
  237. margin: 0 auto;
  238. color: #ffffff;
  239. a {
  240. color: #ffffff;
  241. &:hover {
  242. color: #ed5f48;
  243. }
  244. }
  245. .wrap-item {
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. .item {
  250. height: 17px;
  251. line-height: 17px;
  252. font-size: 12px;
  253. font-family: PingFangSC-Medium;
  254. font-weight: 500;
  255. color: rgba(255, 255, 255, 1);
  256. }
  257. &.left {
  258. .home {
  259. margin-left: 5px;
  260. }
  261. }
  262. &.right {
  263. .item {
  264. position: relative;
  265. display: flex;
  266. height: 30px;
  267. align-items: center;
  268. margin-right: 40px;
  269. &:hover {
  270. .box {
  271. opacity: 1;
  272. filter: alpha(opacity=100);
  273. pointer-events: auto;
  274. transform: translate(-50%, 0) scale(1);
  275. }
  276. }
  277. .box {
  278. position: absolute;
  279. left: 50%;
  280. top: 30px;
  281. z-index: 1;
  282. transform: translateX(-50%);
  283. background-color: #ffffff;
  284. border-radius: 2px;
  285. box-shadow: 0px 12px 20px 0px rgba(0, 0, 0, 0.07);
  286. filter: alpha(opacity=0);
  287. opacity: 0;
  288. transition: all 500ms cubic-bezier(0.34, 1.21, 0.4, 1);
  289. transform-origin: 50% 0;
  290. transform: translate(-50%, 0) scale(0);
  291. }
  292. &.lang {
  293. .lang-wrap {
  294. display: flex;
  295. align-items: center;
  296. font-size: 14px;
  297. font-weight: 500;
  298. color: #ffffff;
  299. &:hover {
  300. opacity: 0.8;
  301. }
  302. .lang-select {
  303. margin-right: 3px;
  304. }
  305. .icon-xiala {
  306. font-size: 12px;
  307. }
  308. }
  309. .lang-list {
  310. width: 150px;
  311. .lang-item {
  312. display: flex;
  313. align-items: center;
  314. height: 42px;
  315. padding-left: 16px;
  316. font-size: 14px;
  317. font-family: Roboto-Regular;
  318. font-weight: 500;
  319. color: rgba(0, 0, 0, 1);
  320. text-align: center;
  321. cursor: pointer;
  322. &:hover {
  323. color: #ff523d;
  324. background-color: #f2f2f2;
  325. }
  326. }
  327. }
  328. .flag {
  329. width: 36px;
  330. margin-right: 10px;
  331. }
  332. }
  333. &.login-yes {
  334. margin-right: 5px;
  335. .user-name {
  336. cursor: pointer;
  337. color: #ff523d;
  338. font-family: PingFangSC-Regular;
  339. &:hover {
  340. opacity: 0.8;
  341. }
  342. }
  343. .logout {
  344. cursor: pointer;
  345. &:hover {
  346. color: #ff523d;
  347. }
  348. &.lock {
  349. pointer-events: none;
  350. }
  351. }
  352. }
  353. &.login-no {
  354. margin-right: 5px;
  355. }
  356. }
  357. }
  358. }
  359. }
  360. .layer-login-register {
  361. position: fixed;
  362. top: 0;
  363. right: 0;
  364. bottom: 0;
  365. left: 0;
  366. z-index: 9999;
  367. display: flex;
  368. justify-content: center;
  369. align-items: flex-start;
  370. background-color: rgba(0, 0, 0, 0.5);
  371. .layer-login-register-wrap {
  372. margin-top: 15%;
  373. }
  374. }
  375. }
  376. </style>