index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <header class="header">
  3. <div class="container clearfix">
  4. <div class="logo logo--no" v-if="header.companyLogo">
  5. <img
  6. style="cursor: pointer; width: 162px; height: 33px"
  7. :src="$tools.splitImgHost(header.companyLogo)"
  8. alt=""
  9. @click="go('/')"
  10. />
  11. </div>
  12. <h1 class="logo" v-else @click="go('/')"></h1>
  13. <nav class="nav">
  14. <ul class="list">
  15. <li v-for="(item, index) in showNav(header.Nav)" :key="index">
  16. <a v-if="item.name == '首页'" @click="go('/index')">首页</a>
  17. <a v-if="item.name == '走进祥粤'" @click="go('/about')">走进祥粤</a>
  18. <a v-if="item.name == '课程'" @click="go('/course-list')">课程</a>
  19. <a v-if="item.name == '直播'" @click="go('/live-list')">直播</a>
  20. <a v-if="item.name == '题库'" @click="go('/bank-list')">题库</a>
  21. </li>
  22. </ul>
  23. </nav>
  24. <div class="userinfo" v-if="userInfo">
  25. <a class="msg" @click="go('/person-center/my-message')">
  26. <i class="pi" v-if="msgCount > 0"></i>
  27. <i class="el-icon-message-solid icon"></i>
  28. </a>
  29. <el-dropdown @command="handleCommand">
  30. <span
  31. class="el-dropdown-link"
  32. @click="go('/person-center/my-course')"
  33. style="margin-left: 10px; cursor: pointer"
  34. >
  35. <img
  36. style="width: 24px; vertical-align: middle"
  37. :src="
  38. userInfo
  39. ? userInfo.avatar
  40. ? $tools.splitImgHost(userInfo.avatar, true)
  41. : '@/assets/qrcode.png'
  42. : ''
  43. "
  44. alt=""
  45. />
  46. <span>{{ userInfo && userInfo.realname }}</span>
  47. </span>
  48. <el-dropdown-menu slot="dropdown">
  49. <el-dropdown-item command="1">我的课程</el-dropdown-item>
  50. <el-dropdown-item command="2">我的题库</el-dropdown-item>
  51. <el-dropdown-item command="3">个人中心</el-dropdown-item>
  52. <el-dropdown-item command="4">退出登录</el-dropdown-item>
  53. </el-dropdown-menu>
  54. </el-dropdown>
  55. </div>
  56. <div class="userinfo" v-else>
  57. <div class="text-list" v-if="!userInfo">
  58. <a @click="go('/login', { state: 1 })">登录</a>
  59. <a @click="go('/login', { state: 2 })">注册</a>
  60. </div>
  61. </div>
  62. <div class="search">
  63. <div class="search__select">
  64. <select v-model="type">
  65. <option value="1">课程</option>
  66. <option value="2">题库</option>
  67. <option value="6">直播</option>
  68. </select>
  69. </div>
  70. <div class="search__input">
  71. <input type="text" v-model="searchKey" autocomplete="off" />
  72. <input
  73. type="password"
  74. autocomplete="new-password"
  75. style="display: none"
  76. />
  77. </div>
  78. <el-button type="primary" @click="search" class="search__btn"
  79. >搜索</el-button
  80. >
  81. </div>
  82. </div>
  83. </header>
  84. </template>
  85. <script>
  86. import { mapGetters, mapMutations } from "vuex";
  87. export default {
  88. name: "Header",
  89. data() {
  90. return {
  91. searchKey: "",
  92. type: "1",
  93. showBox: false,
  94. timer: null,
  95. };
  96. },
  97. computed: {
  98. ...mapGetters(["header", "userInfo", "msgCount"]),
  99. showNav: function () {
  100. return function (list) {
  101. var newList = [];
  102. if (list) {
  103. newList = list.filter((item) => {
  104. return item.status === 1;
  105. });
  106. }
  107. return newList;
  108. };
  109. },
  110. },
  111. mounted() {
  112. if (this.$tools.isLogin()) {
  113. this.getMsgCount();
  114. }
  115. },
  116. methods: {
  117. ...mapMutations(["getMsgCount"]),
  118. handleCommand(command) {
  119. switch (command) {
  120. case "1":
  121. this.go("/person-center/my-course");
  122. break;
  123. case "2":
  124. this.go("/person-center/my-bank");
  125. break;
  126. case "3":
  127. this.go("/person-center/my-info");
  128. break;
  129. case "4":
  130. this.$tools.exit();
  131. break;
  132. default:
  133. break;
  134. }
  135. },
  136. go(path, query) {
  137. this.$router.push({
  138. path,
  139. query,
  140. });
  141. },
  142. search() {
  143. if (!this.searchKey.trim()) {
  144. this.$message({
  145. type: "warning",
  146. duration: 2000,
  147. message: "请输入搜索内容",
  148. });
  149. return;
  150. }
  151. let type = this.type;
  152. let path = this.$route.path;
  153. if (path == "/bank-list") {
  154. //在题库列表页面直接传参
  155. if (type == "2") {
  156. this.$emit("search", this.searchKey);
  157. } else if (type == "6") {
  158. this.$router.push({
  159. path: "/live-list",
  160. query: {
  161. searchKey: this.searchKey,
  162. },
  163. });
  164. } else {
  165. this.$router.push({
  166. path: "/course-list",
  167. query: {
  168. searchKey: this.searchKey,
  169. },
  170. });
  171. }
  172. } else if (path == "/course-list") {
  173. //在课程列表页面直接传参
  174. if (type == "1") {
  175. this.$emit("search", this.searchKey);
  176. } else if (type == "6") {
  177. this.$router.push({
  178. path: "/live-list",
  179. query: {
  180. searchKey: this.searchKey,
  181. },
  182. });
  183. } else {
  184. this.$router.push({
  185. path: "/bank-list",
  186. query: {
  187. searchKey: this.searchKey,
  188. },
  189. });
  190. }
  191. } else if (path == "/live-list") {
  192. //在课程列表页面直接传参
  193. if (type == "6") {
  194. this.$emit("search", this.searchKey);
  195. } else if (type == "1") {
  196. this.$router.push({
  197. path: "/course-list",
  198. query: {
  199. searchKey: this.searchKey,
  200. },
  201. });
  202. } else {
  203. this.$router.push({
  204. path: "/bank-list",
  205. query: {
  206. searchKey: this.searchKey,
  207. },
  208. });
  209. }
  210. } else {
  211. //根据类型跳转题库或者列表页面
  212. console.log(type);
  213. if (type == "1") {
  214. this.$router.push({
  215. path: "/course-list",
  216. query: {
  217. searchKey: this.searchKey,
  218. },
  219. });
  220. } else if (type == "6") {
  221. this.$router.push({
  222. path: "/live-list",
  223. query: {
  224. searchKey: this.searchKey,
  225. },
  226. });
  227. } else {
  228. this.$router.push({
  229. path: "/bank-list",
  230. query: {
  231. searchKey: this.searchKey,
  232. },
  233. });
  234. }
  235. }
  236. },
  237. mouseover() {
  238. clearTimeout(this.timer);
  239. this.showBox = true;
  240. },
  241. mouseLeave() {
  242. clearTimeout(this.timer);
  243. this.timer = setTimeout(() => {
  244. this.showBox = false;
  245. }, 500);
  246. },
  247. },
  248. };
  249. </script>
  250. <!-- Add "scoped" attribute to limit CSS to this component only -->
  251. <style scoped lang="scss">
  252. .header {
  253. position: relative;
  254. background: #fff;
  255. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.04);
  256. .container {
  257. height: 80px;
  258. .logo {
  259. margin-top: 23px;
  260. float: left;
  261. cursor: pointer;
  262. width: 162px;
  263. height: 33px;
  264. background: url("~@/assets/logo.png") no-repeat center;
  265. &--no {
  266. background: none;
  267. }
  268. }
  269. .nav {
  270. float: left;
  271. margin-top: 30px;
  272. .list {
  273. margin-left: 146px;
  274. display: flex;
  275. li {
  276. margin: 0 20px;
  277. a {
  278. color: #333;
  279. }
  280. a:hover {
  281. color: #3f8dfd;
  282. }
  283. }
  284. }
  285. }
  286. .search {
  287. float: right;
  288. margin-top: 20px;
  289. width: 324px;
  290. background: #fafbfc;
  291. border: 1px solid #3f8dfd;
  292. border-radius: 8px;
  293. display: flex;
  294. overflow: hidden;
  295. &__select {
  296. width: 76px;
  297. border-right: 1px solid #fff;
  298. select {
  299. text-align: center;
  300. width: 100%;
  301. height: 100%;
  302. border: 0;
  303. outline: none;
  304. }
  305. }
  306. &__input {
  307. flex: 1;
  308. input {
  309. width: 100%;
  310. height: 100%;
  311. }
  312. }
  313. &__btn {
  314. padding: 0;
  315. text-align: center;
  316. width: 80px;
  317. height: 40px;
  318. line-height: 40px;
  319. font-size: 14px;
  320. border-radius: 0;
  321. }
  322. }
  323. .userinfo {
  324. margin-top: 30px;
  325. float: right;
  326. white-space: nowrap;
  327. a {
  328. display: inline-block;
  329. margin-left: 20px;
  330. vertical-align: middle;
  331. &.msg {
  332. position: relative;
  333. margin-top: 2px;
  334. .icon {
  335. font-size: 20px;
  336. color: #3f8dfd;
  337. }
  338. .pi {
  339. display: inline-block;
  340. width: 10px;
  341. height: 10px;
  342. background: #ff3b30;
  343. border: 1px solid #ffffff;
  344. border-radius: 10px;
  345. position: absolute;
  346. top: 0;
  347. right: 0;
  348. }
  349. }
  350. &.name {
  351. position: relative;
  352. z-index: 99;
  353. img {
  354. width: 24px;
  355. vertical-align: middle;
  356. }
  357. .modal-box {
  358. width: 162px;
  359. background: #ffffff;
  360. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.1);
  361. border-radius: 8px;
  362. position: absolute;
  363. top: 55px;
  364. left: -40px;
  365. li {
  366. margin-left: 10px;
  367. border-bottom: 1px solid #eeeeee;
  368. height: 40px;
  369. line-height: 40px;
  370. cursor: pointer;
  371. padding-left: 5px;
  372. &:hover {
  373. background: #eeeeee;
  374. color: #3f8dfd;
  375. }
  376. &:nth-last-of-type(1) {
  377. border: 0;
  378. }
  379. }
  380. }
  381. }
  382. }
  383. }
  384. .text-list {
  385. margin-top: 30px;
  386. text-align: right;
  387. font-size: 0;
  388. a {
  389. display: inline-block;
  390. margin: 0;
  391. color: #3f8dfd;
  392. font-size: 14px;
  393. padding: 0 14px;
  394. &:nth-last-of-type(1) {
  395. padding-right: 0;
  396. border-left: 1px solid #3f8dfd;
  397. }
  398. }
  399. }
  400. }
  401. }
  402. .fade-enter,
  403. .fade-leave-to {
  404. opacity: 0;
  405. height: 0;
  406. }
  407. .fade-enter-to,
  408. .fade-leave {
  409. opacity: 1;
  410. height: 122px;
  411. }
  412. .fade-enter-active,
  413. .fade-leave-active {
  414. transition: all 0.3s;
  415. }
  416. </style>