headerItem2.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. <template>
  2. <div>
  3. <div class="header1">
  4. <div class="header2">
  5. <div class="language">
  6. <span
  7. class="active"
  8. v-if="
  9. $store.state.router != 'ConferenceNetwork' &&
  10. $store.state.router != 'MeetingApplyForm'
  11. "
  12. >
  13. <span class="cursor" @click="locale('zh')">{{
  14. $t('common.CN')
  15. }}</span>
  16. <span
  17. style="
  18. margin: 0 14px;
  19. display: inline-block;
  20. width: 2px;
  21. height: 14px;
  22. background: #f9f9f9;
  23. "
  24. ></span>
  25. <span style="margin-right: 9px" class="cursor" @click="locale('en')"
  26. >EN</span
  27. >
  28. </span>
  29. <span class="active" style="float: right">
  30. <span
  31. class="cursor"
  32. style="margin-right: 12px"
  33. @click="toView(2, 'Register', '')"
  34. v-if="i == 1"
  35. ><img
  36. src="@/assets/注册.png"
  37. style="height: 12px; width: 12px; margin-right: 4px"
  38. />{{ $t('common.register') }}</span
  39. >
  40. <span
  41. class="cursor"
  42. style="margin-right: 12px"
  43. @click="toView(2, 'login', '')"
  44. v-if="i == 1"
  45. ><img
  46. src="@/assets/登录.png"
  47. style="height: 12px; width: 12px; margin-right: 4px"
  48. />{{ $t('common.login') }}</span
  49. >
  50. <!-- <span class="cursor" style="margin-right: 12px;" v-if="i==2 || i==3">{{ $t('common.OngoingProject')}}(<span style="color: #ff0000;">0</span>)</span> -->
  51. <!-- <span class="cursor" style="margin-right: 12px;" v-if="i==2 || i==3">{{ $t('common.MyAttention')}}(<span style="color: #ff0000;">0</span>)</span> -->
  52. <!-- <span class="cursor" style="margin-right: 12px;" v-if="i==2 || i==3">{{ $t('common.MyCollection')}}</span> -->
  53. <i
  54. class="el-icon-s-custom"
  55. style="color: #fff; margin-right: 4px"
  56. v-if="i == 2 || i == 3"
  57. ></i>
  58. <el-dropdown
  59. trigger="click"
  60. @command="handleCommand"
  61. v-if="i == 2 || i == 3"
  62. >
  63. <!-- <i class="el-icon-s-custom" style="color: #fff;"></i> -->
  64. <span
  65. style="margin-right: 9px; cursor: pointer; font-size: 16px"
  66. v-if="i == 2 || i == 3"
  67. >
  68. {{ $t('common.Usercenter') }}
  69. <i class="el-icon-arrow-down"></i>
  70. <el-dropdown-menu slot="dropdowns">
  71. <el-dropdown-item
  72. v-for="(item, index) in options"
  73. :key="index"
  74. :command="item"
  75. >{{ $t(item.label) }}
  76. <el-dropdown-menu slot="dropdowns">
  77. <el-dropdown-item
  78. v-for="(item, index) in options"
  79. :key="index"
  80. :command="item"
  81. >{{ $t(item.label) }}
  82. </el-dropdown-item>
  83. </el-dropdown-menu>
  84. </el-dropdown-item>
  85. </el-dropdown-menu>
  86. </span>
  87. </el-dropdown>
  88. <i
  89. class="el-icon-message-solid"
  90. style="margin-left: 20px; color: #fff"
  91. v-if="i == 2 || i == 3"
  92. ></i>
  93. <span
  94. class="cursor"
  95. @click="
  96. systemMessageNumToView(0, 'SystemMessage', '/SystemMessage')
  97. "
  98. style="margin-right: 12px"
  99. v-if="i == 2 || i == 3"
  100. >
  101. {{ $t('common.MessageNotification') }}
  102. ( <span style="color: #ff0000">{{ systemMessageNum }}</span> )
  103. </span>
  104. <!-- <span class="cursor" style="margin-right: 12px;" @click="toView(2,'customerService')">{{ $t('common.CustomerService')}}</span> -->
  105. <!-- <span class="cursor" style="margin-right: 12px;" @click="toView(2,'helpCenter')">{{ $t('common.HelpCenter')}}</span> -->
  106. </span>
  107. </div>
  108. <div class="logo">
  109. <img
  110. src="@/assets/img/home/LOGO2020-12-22.png"
  111. alt=""
  112. style="width: 260px"
  113. class="cursor"
  114. @click="toView(0, 'home')"
  115. />
  116. </div>
  117. <div class="title" v-show="searchLoad">
  118. <!-- <span class="cursor" style="font-family: Microsoft YaHei;font-size: 34px;">GEIDCP</span> -->
  119. <span style="float: left; width: 74%">
  120. <el-input
  121. :placeholder="$t('common.EnterContent')"
  122. class="input-with-select"
  123. v-model="homeItemTitle"
  124. maxlength="50"
  125. show-word-limit
  126. @keyup.enter.native="toViewChange('WholeStationSearch')"
  127. >
  128. <el-select v-model="select" slot="prepend">
  129. <el-option
  130. :label="$t('common.WholeStation')"
  131. value="all"
  132. ></el-option>
  133. <el-option
  134. :label="$t('common.Project')"
  135. value="project"
  136. ></el-option>
  137. <el-option
  138. :label="$t('common.Enterprise')"
  139. value="unit"
  140. ></el-option>
  141. <el-option
  142. :label="$t('common.News')"
  143. value="information"
  144. ></el-option>
  145. <el-option
  146. :label="$t('common.Events')"
  147. value="activity"
  148. ></el-option>
  149. <el-option
  150. :label="$t('common.Conference')"
  151. value="meeting"
  152. ></el-option>
  153. <el-option
  154. :label="$t('common.Publications')"
  155. value="journal"
  156. ></el-option>
  157. <el-option
  158. :label="$t('common.Country')"
  159. value="country"
  160. ></el-option>
  161. </el-select>
  162. <el-button
  163. slot="append"
  164. icon="el-icon-search"
  165. @click="toViewChange('WholeStationSearch')"
  166. ></el-button>
  167. </el-input>
  168. </span>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </template>
  174. <script>
  175. import Bus from '@/api/bus' //注意引入
  176. import { selectPushMsgNum, selectNoticeInfoNum } from '@/api/userCenter'
  177. export default {
  178. name: 'HeaderItem',
  179. props: ['selectShow'],
  180. data() {
  181. return {
  182. //消息通知消息类型
  183. messageType: 0,
  184. title: '项目资源',
  185. systemMessageNum: 0,
  186. homeItemTitle: '',
  187. select: 'all',
  188. searchLoad: true,
  189. i: '1',
  190. options: [
  191. {
  192. value: 'userCenterView',
  193. label: 'common.Usercenter',
  194. json: '',
  195. },
  196. {
  197. value: 'SystemMessage',
  198. label: 'common.MessageCenter',
  199. json: '/SystemMessage',
  200. },
  201. {
  202. value: 'myConcerns',
  203. label: 'common.ManagementCenter',
  204. json: '/myConcerns',
  205. },
  206. {
  207. value: 'information',
  208. label: 'common.BasicInformation',
  209. json: 'information',
  210. },
  211. {
  212. value: 'loginOut',
  213. label: 'common.Logout',
  214. json: '',
  215. },
  216. ],
  217. }
  218. },
  219. created() {
  220. Bus.$on('title', (val) => {
  221. this.title = val.label
  222. })
  223. // Bus.$on("serch", (val) => {
  224. // this.serch=val.label.substring(0,2)
  225. // });
  226. },
  227. watch: {
  228. '$route.path'() {
  229. this.getSearchLoad()
  230. },
  231. '$i18n.locale'() {
  232. if (this.$i18n.locale == 'en' && this.$Cookies.get('token')) {
  233. this.i = 3
  234. } else if (this.$i18n.locale == 'zh' && this.$Cookies.get('token')) {
  235. this.i = 2
  236. } else {
  237. this.i = 1
  238. }
  239. },
  240. },
  241. mounted() {
  242. this.getSearchLoad()
  243. this.getInitData()
  244. this.getMessageNum()
  245. },
  246. methods: {
  247. getMessageNum() {
  248. if (this.i != 1) {
  249. this.messageType = 0
  250. this.systemMessageNum = 0
  251. let readStatus = 'unread'
  252. selectPushMsgNum(readStatus).then((res) => {
  253. if (res.data.page.totalCount > 0) {
  254. this.systemMessageNum =
  255. this.systemMessageNum + parseInt(res.data.page.totalCount)
  256. this.messageType = 1
  257. }
  258. })
  259. selectNoticeInfoNum(readStatus).then((res) => {
  260. if (res.data.page.totalCount > 0) {
  261. this.systemMessageNum =
  262. this.systemMessageNum + parseInt(res.data.page.totalCount)
  263. this.messageType = 2
  264. }
  265. })
  266. }
  267. },
  268. getSearchLoad() {
  269. let router = this.$route.path
  270. this.searchLoad = true
  271. if (router == '/WholeStationSearch') {
  272. this.searchLoad = false
  273. this.$forceUpdate()
  274. }
  275. },
  276. getInitData() {
  277. let locale = window.localStorage.getItem('locale')
  278. if (!locale) {
  279. this.$store.commit('modify', router)
  280. window.localStorage.setItem('locale', 'en')
  281. }
  282. document.title = this.$t('common.GEIDcpTitleSeptember')
  283. this.$i18n.locale = locale
  284. console.log(
  285. window.localStorage.getItem('locale'),
  286. window.localStorage.getItem('userLogin')
  287. )
  288. //if (window.localStorage.getItem('userLogin')) {
  289. if (this.$Cookies.get('token') && this.$i18n.locale == 'zh') {
  290. return (this.i = 2)
  291. } else if (this.$i18n.locale == 'en' && this.$Cookies.get('token')) {
  292. return (this.i = 3)
  293. } else {
  294. return (this.i = 1)
  295. }
  296. },
  297. handleCommand(command) {
  298. if (command.value == 'loginOut') {
  299. sessionStorage.removeItem('pathReminder')
  300. this.loginOut()
  301. } else {
  302. this.toView(0, command.value, command.json)
  303. }
  304. },
  305. locale(lang) {
  306. this.$i18n.locale = lang
  307. let locale = window.localStorage.getItem('locale')
  308. if (locale) {
  309. window.localStorage.setItem('locale', lang)
  310. } else {
  311. window.localStorage['locale'] = lang
  312. }
  313. console.log(window.localStorage.getItem('locale'))
  314. this.$bus.emit('setLang', window.localStorage.getItem('locale'))
  315. },
  316. loginOut() {
  317. this.$confirm(
  318. this.$t('common.Thisoperationwilllogout') + '?',
  319. this.$t('common.Tips'),
  320. {
  321. confirmButtonText: this.$t('common.OK'),
  322. cancelButtonText: this.$t('common.cancel'),
  323. type: 'warning',
  324. }
  325. )
  326. .then(() => {
  327. // Cookies.remove('login');
  328. // let ss=Cookies.get('login');
  329. // debugger
  330. // 退出的逻辑代码
  331. this.$store
  332. .dispatch('user/LOGOUT')
  333. .then(() => {
  334. // location.href = "/";
  335. this.$router.push({
  336. path: '/login',
  337. })
  338. })
  339. .catch((error) => {
  340. location.href = '/'
  341. })
  342. // this.toView(2,'login','')// 返回登录
  343. // window.localStorage.removeItem('token')
  344. window.sessionStorage.removeItem('token')
  345. // debugger
  346. this.getInitData()
  347. })
  348. .catch(() => {
  349. this.$message({
  350. type: 'info',
  351. message: this.$t('common.Cancelled'),
  352. })
  353. })
  354. },
  355. toViewChange(router, json) {
  356. if (!this.homeItemTitle) {
  357. this.$message({
  358. message: this.$t('common.Theinputboxcannotbeempty'),
  359. type: 'warning',
  360. })
  361. } else {
  362. this.$store.commit('modify', router)
  363. window.localStorage.setItem('router', router)
  364. const { href } = this.$router.resolve({
  365. name: router,
  366. query: {
  367. select: this.select,
  368. input: this.homeItemTitle,
  369. },
  370. })
  371. window.open(href, '_blank')
  372. }
  373. },
  374. systemMessageNumToView(num, router, json) {
  375. if (this.messageType == 2) {
  376. this.toView(0, 'notification', '/notification')
  377. } else {
  378. this.toView(0, 'SystemMessage', '/SystemMessage')
  379. }
  380. },
  381. toView(num, router, json) {
  382. if (json) {
  383. this.$store.commit('modify', router)
  384. window.localStorage.setItem('router', router)
  385. this.$router.push({ name: router, query: { key: json } })
  386. } else {
  387. this.$store.commit('modify', router)
  388. window.localStorage.setItem('router', router)
  389. this.$router.push({ name: router })
  390. }
  391. if (num == 1) {
  392. let i = {
  393. label: '用户中心',
  394. value: 'userCenterView',
  395. }
  396. if (this.$Cookies.get('token')) {
  397. return (this.i = 2)
  398. } else if (this.$i18n.locale == 'en') {
  399. return (this.i = 3)
  400. } else {
  401. return (this.i = 1)
  402. }
  403. this.$nextTick(() => {
  404. Bus.$emit('title', i)
  405. })
  406. }
  407. },
  408. },
  409. }
  410. </script>
  411. <!-- Add "scoped" attribute to limit CSS to this component only -->
  412. <style scoped>
  413. body {
  414. margin: 0;
  415. padding: 0;
  416. }
  417. .header1 {
  418. /* width:1500px; */
  419. height: 170px;
  420. margin: auto;
  421. /* background: #2c558a; */
  422. /* background: url("../assets/img/home/banner2.jpg") no-repeat ; */
  423. /* animation: panoramic 10s linear infinite alternate; */
  424. }
  425. /* .header1:hover {
  426. animation-play-state: paused;
  427. } */
  428. /* @keyframes panoramic {
  429. to {
  430. background-position: 100% 0;
  431. }
  432. } */
  433. .header2 {
  434. width: 1200px;
  435. height: 170px;
  436. margin: auto;
  437. position: relative;
  438. /* background: skyblue; */
  439. }
  440. .language {
  441. line-height: 12px;
  442. color: #f9f9f9;
  443. font-weight: 400;
  444. font-size: 16px;
  445. padding-top: 15px;
  446. }
  447. .logo {
  448. position: absolute;
  449. top: 50px;
  450. left: 70px;
  451. /* width: 200px; */
  452. /* height: 55px; */
  453. margin-top: 15px;
  454. /* background-image: url(@/assets/logo.png); */
  455. }
  456. .title {
  457. margin-top: 15px;
  458. position: absolute;
  459. top: 60px;
  460. left: 605px;
  461. font-size: 27px;
  462. font-weight: 700;
  463. height: 50px;
  464. color: #fff;
  465. width: 705px;
  466. }
  467. @media (max-width: 1199px) {
  468. .title {
  469. width: 580px;
  470. }
  471. }
  472. .header1 >>> .el-input__inner {
  473. height: 50px !important;
  474. }
  475. .header1 >>> .el-input-group__prepend {
  476. background-color: #fff;
  477. color: #000;
  478. }
  479. .active span:hover {
  480. color: #ff0000;
  481. cursor: pointer;
  482. }
  483. .el-dropdown {
  484. color: #f9f9f9;
  485. font-size: 16px;
  486. }
  487. .header1 >>> .el-select {
  488. width: 88px;
  489. }
  490. </style>