ballotHeader.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div>
  3. <div class="header-container">
  4. <div class="header-content">
  5. <span class="active language">
  6. <span style="
  7. display: inline-block;
  8. width: 226px;
  9. height: 100%;
  10. position: relative;
  11. vertical-align: middle;
  12. margin-right: 20px;
  13. ">
  14. <img src="@/assets/img/home/LOGO2020-12-22.png" alt="" style="
  15. width: 80%;
  16. height: 70%;
  17. position: absolute;
  18. left: 50%;
  19. top: 50%;
  20. transform: translate(-50%, -50%);
  21. " />
  22. </span>
  23. <span class="cursor" @click="locale('zh')">{{
  24. $t('common.CN')
  25. }}</span>
  26. <span style="
  27. margin: 0 14px;
  28. display: inline-block;
  29. width: 2px;
  30. height: 14px;
  31. background: #f9f9f9;
  32. "></span>
  33. <span class="cursor" @click="locale('en')">EN</span>
  34. </span>
  35. <span class="active" style="float: right">
  36. <span style="margin-left: 20px" @click="toView(2, 'Register', '')" v-if="i == 1">
  37. <img src="@/assets/注册.png" style="height: 12px; width: 12px; margin-right: 4px" />{{
  38. $t('common.register') }}</span>
  39. <span style="margin-left: 20px" @click="toView(2, 'login', '')" v-if="i == 1"><img
  40. src="@/assets/登录.png" style="height: 12px; width: 12px; margin-right: 4px" />{{
  41. $t('common.login') }}</span>
  42. <i class="el-icon-s-custom" style="color: #fff; margin-right: -15px" v-if="i == 2 || i == 3"></i>
  43. <el-dropdown trigger="click" @command="handleCommand" style="margin-left: 20px"
  44. v-if="i == 2 || i == 3">
  45. <span class="el-dropdown-link">
  46. {{ $t('common.Usercenter') }}
  47. <i class="el-icon-arrow-down el-icon--right"></i>
  48. </span>
  49. <el-dropdown-menu slot="dropdown">
  50. <el-dropdown-item v-for="(item, index) in options" :key="index" :command="item">
  51. {{ $t(item.label) }}</el-dropdown-item>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. <i class="el-icon-message-solid" style="margin-left: 20px; color: #fff" v-if="i == 2 || i == 3"></i>
  55. <span @click="
  56. systemMessageNumToView(0, 'SystemMessage', '/SystemMessage')
  57. " v-if="i == 2 || i == 3">
  58. {{ $t('common.MessageNotification') }}(
  59. <span style="color: #ff0000">{{ systemMessageNum }} </span>)
  60. </span>
  61. <!-- <span-->
  62. <!-- style="margin-left: 20px;"-->
  63. <!-- @click="toView(2,'helpCenter')"-->
  64. <!-- >{{ $t('common.HelpCenter')}}</span>-->
  65. </span>
  66. </div>
  67. <div class="banner-container">
  68. <el-carousel :interval="5000" arrow="never">
  69. <el-carousel-item key="item1" style="height: 350px; width: 100%">
  70. <img @click="getNum" class="banner" src="@/assets/ballot/网站_画板 1.png" alt="" />
  71. <!-- <img class="logo1" v-show="$i18n.locale == 'zh'" src="@/assets/img/home/fengcheBlue.png" alt=""> -->
  72. <!-- <img class="logo1" v-show="$i18n.locale == 'en'" src="@/assets/img/home/enBlue.png" alt=""> -->
  73. </el-carousel-item>
  74. <!-- <el-carousel-item key="item2" style="height: 350px;">
  75. <img class="banner" src="@/assets/img/home/bannerFenche.jpg" alt="">
  76. <img class="logo1" v-show="$i18n.locale == 'zh'" src="@/assets/img/home/fengche.png" alt="">
  77. <img class="logo1" v-show="$i18n.locale == 'en'" src="@/assets/img/home/enYellow.png" alt="">
  78. </el-carousel-item> -->
  79. <!-- <el-carousel-item key="item3" style="height: 350px;">
  80. <img class="banner" src="@/assets/img/home/bannerTaiyang.png" alt="">
  81. <img class="logo1" v-show="$i18n.locale == 'zh'" src="@/assets/img/home/taiyang.png" alt="">
  82. <img class="logo1" v-show="$i18n.locale == 'en'" src="@/assets/img/home/enXing.png" alt="">
  83. </el-carousel-item> -->
  84. </el-carousel>
  85. <!-- <div class="banner-content">
  86. <img class="logo" src="@/assets/img/home/logo1.png" alt="">
  87. </div> -->
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <script>
  93. import Bus from '@/api/bus' //注意引入
  94. import { selectPushMsgNum, selectNoticeInfoNum } from '@/api/userCenter'
  95. export default {
  96. name: 'Headers',
  97. data() {
  98. return {
  99. arrowList: false,
  100. //消息通知消息类型
  101. messageType: 0,
  102. systemMessageNum: 0,
  103. i: '1',
  104. options: [
  105. {
  106. value: 'userCenterView',
  107. label: 'common.Usercenter',
  108. json: '',
  109. },
  110. {
  111. value: 'SystemMessage',
  112. label: 'common.MessageCenter',
  113. json: '/SystemMessage',
  114. },
  115. {
  116. value: 'myConcerns',
  117. label: 'common.ManagementCenter',
  118. json: '/myConcerns',
  119. },
  120. {
  121. value: 'information',
  122. label: 'common.MyAccount',
  123. json: '/information',
  124. },
  125. {
  126. value: 'loginOut',
  127. label: 'common.Logout',
  128. json: '',
  129. },
  130. ],
  131. }
  132. },
  133. mounted() {
  134. this.getInitData()
  135. this.getMessageNum()
  136. },
  137. methods: {
  138. getNum() {
  139. // this.$emit('getLoginNum', true)
  140. // this.$parent.getLogin()
  141. this.$router.push({ path: 'videoInfo1' })
  142. },
  143. getInitData() {
  144. debugger
  145. let locale = window.localStorage.getItem('locale')
  146. if (!locale) {
  147. window.localStorage.setItem('locale', 'en')
  148. }
  149. document.title = this.$t('common.GEIDcpTitleSeptember')
  150. this.$i18n.locale = locale
  151. console.log(
  152. window.localStorage.getItem('locale'),
  153. window.localStorage.getItem('userLogin')
  154. )
  155. //if (window.localStorage.getItem('userLogin')) {
  156. if (this.$Cookies.get('token') && this.$i18n.locale == 'zh') {
  157. return (this.i = 2)
  158. } else if (this.$i18n.locale == 'en' && this.$Cookies.get('token')) {
  159. return (this.i = 3)
  160. } else {
  161. return (this.i = 1)
  162. }
  163. debugger
  164. if (this.i != 1) {
  165. this.getMessageNum()
  166. }
  167. },
  168. getMessageNum() {
  169. if (this.i != 1) {
  170. this.messageType = 0
  171. this.systemMessageNum = 0
  172. let readStatus = 'unread'
  173. selectPushMsgNum(readStatus).then((res) => {
  174. if (res.data.page.totalCount > 0) {
  175. this.systemMessageNum =
  176. this.systemMessageNum + parseInt(res.data.page.totalCount)
  177. this.messageType = 1
  178. }
  179. })
  180. selectNoticeInfoNum(readStatus).then((res) => {
  181. if (res.data.page.totalCount > 0) {
  182. this.systemMessageNum =
  183. this.systemMessageNum + parseInt(res.data.page.totalCount)
  184. this.messageType = 2
  185. }
  186. })
  187. }
  188. },
  189. locale(lang) {
  190. this.$i18n.locale = lang
  191. let locale = window.localStorage.getItem('locale')
  192. if (locale) {
  193. window.localStorage.setItem('locale', lang)
  194. } else {
  195. window.localStorage['locale'] = lang
  196. }
  197. },
  198. getInitData() {
  199. let locale = window.localStorage.getItem('locale')
  200. let langdefaultLanguage = navigator.language || navigator.userLanguage //常规浏览器语言和IE浏览器
  201. langdefaultLanguage = langdefaultLanguage.substr(0, 2) //截取lang前2位字符
  202. if (langdefaultLanguage !== 'zh') {
  203. langdefaultLanguage = 'en'
  204. }
  205. if (!locale) {
  206. window.localStorage.setItem('locale', langdefaultLanguage)
  207. locale = langdefaultLanguage
  208. }
  209. this.$i18n.locale = locale
  210. console.log(
  211. window.localStorage.getItem('locale'),
  212. window.localStorage.getItem('userLogin')
  213. )
  214. //if (window.localStorage.getItem('userLogin')) {
  215. if (this.$Cookies.get('token') && this.$i18n.locale == 'zh') {
  216. return (this.i = 2)
  217. } else if (this.$i18n.locale == 'en' && this.$Cookies.get('token')) {
  218. return (this.i = 3)
  219. } else {
  220. return (this.i = 1)
  221. }
  222. },
  223. locale(lang) {
  224. this.$i18n.locale = lang
  225. let locale = window.localStorage.getItem('locale')
  226. if (locale) {
  227. window.localStorage.setItem('locale', lang)
  228. } else {
  229. window.localStorage['locale'] = lang
  230. }
  231. console.log(window.localStorage.getItem('locale'))
  232. },
  233. handleCommand(command) {
  234. if (command.value == 'loginOut') {
  235. sessionStorage.removeItem('pathReminder')
  236. this.loginOut()
  237. } else {
  238. this.toView(0, command.value, command.json)
  239. }
  240. },
  241. // 退出登录
  242. loginOut() {
  243. this.$confirm(
  244. this.$t('common.Thisoperationwilllogout') + '?',
  245. this.$t('common.Tips'),
  246. {
  247. confirmButtonText: this.$t('common.OK'),
  248. cancelButtonText: this.$t('common.cancel'),
  249. type: 'warning',
  250. }
  251. )
  252. .then(() => {
  253. // 退出的逻辑代码
  254. this.$store
  255. .dispatch('user/LOGOUT')
  256. .then(() => {
  257. // location.href = "/";
  258. this.$router.push({
  259. path: '/login',
  260. })
  261. })
  262. .catch((error) => {
  263. location.href = '/'
  264. })
  265. // this.toView(2,'login','')// 返回登录
  266. // window.localStorage.removeItem('token')
  267. window.sessionStorage.removeItem('token')
  268. // Cookies.remove('login');
  269. this.getInitData()
  270. })
  271. .catch(() => {
  272. this.$message({
  273. type: 'info',
  274. message: this.$t('common.Cancelled'),
  275. })
  276. })
  277. },
  278. systemMessageNumToView(num, router, json) {
  279. if (this.messageType == 2) {
  280. this.toView(0, 'notification', '/notification')
  281. } else {
  282. this.toView(0, 'SystemMessage', '/SystemMessage')
  283. }
  284. },
  285. toView(num, router, json) {
  286. this.$router.push({ name: router, query: { key: json } })
  287. // this.$store.state.router=router
  288. this.$store.commit('modify', router)
  289. // this.$router.push({name:'userCenterView'})
  290. // this.$store.state.router=router
  291. // this.$store.commit('modify', router)
  292. window.localStorage.setItem('router', router)
  293. if (num == 1) {
  294. let i = {
  295. label: '用户中心',
  296. value: 'userCenterView',
  297. }
  298. if (this.$Cookies.get('token')) {
  299. return (this.i = 2)
  300. } else if (this.$i18n.locale == 'en') {
  301. return (this.i = 3)
  302. } else {
  303. return (this.i = 1)
  304. }
  305. this.$nextTick(() => {
  306. Bus.$emit('title', i)
  307. })
  308. // this.BusChange(i)
  309. }
  310. },
  311. },
  312. }
  313. </script>
  314. <style scoped>
  315. * {
  316. box-sizing: border-box;
  317. }
  318. .header-container {
  319. width: 100%;
  320. background: #0e4891;
  321. }
  322. .header-content {
  323. width: 1200px;
  324. height: 60px;
  325. margin: 0 auto;
  326. color: #f9f9f9;
  327. font-weight: 400;
  328. font-size: 16px;
  329. line-height: 60px;
  330. }
  331. /* .language span{
  332. display: inline-block;
  333. height: 14px;
  334. }
  335. .language span:first-child{
  336. position: relative;
  337. }
  338. .language span:first-child::after{
  339. content: '';
  340. display: inline-block;
  341. width: 2px;
  342. height: 14px;
  343. background: #F9F9F9;
  344. position: absolute;
  345. top: 0;
  346. right: 0;
  347. } */
  348. .banner-container {
  349. position: relative;
  350. }
  351. /deep/ .el-carousel__button {
  352. width: 0px;
  353. height: 0px;
  354. display: none;
  355. }
  356. .banner-content {
  357. width: 1200px;
  358. height: 100%;
  359. position: absolute;
  360. top: 0;
  361. left: 50%;
  362. margin-left: -600px;
  363. }
  364. .logo {
  365. position: absolute;
  366. top: 27px;
  367. left: 0;
  368. }
  369. .header-container >>> .el-carousel__container {
  370. height: 350px;
  371. }
  372. .logo1 {
  373. width: 600px;
  374. position: absolute;
  375. top: 50%;
  376. left: 50%;
  377. transform: translate(-50%, -50%);
  378. }
  379. .banner {
  380. cursor: pointer;
  381. width: 100%;
  382. height: 100%;
  383. }
  384. .title {
  385. position: absolute;
  386. top: 60px;
  387. left: 450px;
  388. font-size: 30px;
  389. font-weight: 700;
  390. color: #fff;
  391. }
  392. .active span:hover {
  393. color: #ff0000;
  394. cursor: pointer;
  395. }
  396. .header-container /deep/ .el-dropdown {
  397. color: #f9f9f9;
  398. font-size: 16px;
  399. }
  400. </style>