index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. define([
  2. 'mixins/router',
  3. 'scripts/util',
  4. 'text!components/base_header/index.html',
  5. 'css!components/base_header/index.css'
  6. ], function (routerMixin, util, html) {
  7. return {
  8. mixins: [routerMixin],
  9. props: {
  10. publicData: {
  11. type: Object,
  12. default: function () {
  13. return {};
  14. }
  15. },
  16. userInfo: {
  17. type: Object,
  18. default: function () {
  19. return {
  20. avatar: ''
  21. };
  22. }
  23. }
  24. },
  25. data: function () {
  26. return {
  27. selected: 1,
  28. options: [
  29. {
  30. label: '专题',
  31. value: 1
  32. },
  33. {
  34. label: '资料',
  35. value: 2
  36. }
  37. ],
  38. searchValue: '',
  39. activeIndex: '1',
  40. active: 1,
  41. currentURL: window.location.pathname,
  42. categoryVisible: false,
  43. menuOn: -1,
  44. isUserPage: false,
  45. isHomePage: false,
  46. code_url: code_url
  47. };
  48. },
  49. created: function () {
  50. if (this.currentURL.includes('/web/index/index')) {
  51. this.isHomePage = true;
  52. } else if (this.currentURL.includes('/web/material/material_list') || this.currentURL.includes('/web/material/details')) {
  53. this.selected = 2;
  54. this.setSearchValue();
  55. } else if (this.currentURL.includes('/web/special/special_cate')) {
  56. this.setSearchValue();
  57. } else if (this.currentURL.includes('/web/my/index')) {
  58. this.isUserPage = true;
  59. }
  60. if (code_url) {
  61. this.code_url = code_url;
  62. }
  63. },
  64. methods: {
  65. goPage: function (page) {
  66. switch (page) {
  67. case 'home':
  68. window.location.assign(this.router.home);
  69. break;
  70. case 'member':
  71. case 'course':
  72. if (!this.userInfo.uid) {
  73. return this.$emit('login-open');
  74. }
  75. window.location.assign(this.router.user + '?activeName=' + page);
  76. break;
  77. }
  78. },
  79. onSearch: function (hot) {
  80. if (!hot && !this.searchValue) {
  81. return;
  82. }
  83. if (hot) {
  84. this.searchValue = hot;
  85. }
  86. if (this.currentURL.includes('/web/special/special_cate')) {
  87. if (this.selected === 1) {
  88. this.$emit('submit-search', this.searchValue);
  89. } else {
  90. window.location.assign(this.router.material_list + '?search=' + this.searchValue);
  91. }
  92. } else if (this.currentURL.includes('/web/material/material_list')) {
  93. if (this.selected === 2) {
  94. this.$emit('submit-search', this.searchValue);
  95. } else {
  96. window.location.assign(this.router.special_cate + '?search=' + this.searchValue);
  97. }
  98. } else {
  99. window.location.assign((this.selected === 1 ? this.router.special_cate : this.router.material_list) + '?search=' + this.searchValue);
  100. }
  101. },
  102. categoryMouseenter: function () {
  103. this.categoryMouse = true;
  104. this.categoryVisible = true;
  105. },
  106. categoryMouseleave: function () {
  107. this.categoryMouse = false;
  108. if (!(this.contentMouse || this.menuMouse)) {
  109. this.menuOn = -1;
  110. this.categoryVisible = false;
  111. }
  112. },
  113. menuMouseenter: function () {
  114. this.menuMouse = true;
  115. },
  116. menuMouseleave: function () {
  117. this.menuMouse = false;
  118. if (!(this.contentMouse || this.categoryMouse)) {
  119. this.menuOn = -1;
  120. this.categoryVisible = false;
  121. }
  122. },
  123. contentMouseenter: function () {
  124. this.contentMouse = true;
  125. },
  126. contentMouseleave: function () {
  127. this.contentMouse = false;
  128. if (!(this.menuMouse || this.categoryMouse)) {
  129. this.menuOn = -1;
  130. this.categoryVisible = false;
  131. }
  132. },
  133. setSearchValue: function () {
  134. var search = util.getParmas('search');
  135. if (search) {
  136. this.searchValue = search;
  137. }
  138. },
  139. // 收藏本站
  140. addFavorite: function () {
  141. try {
  142. window.external.addFavorite(window.location.origin + this.router.home, this.publicData.site_name);
  143. } catch (error) {
  144. try {
  145. window.sidebar.addPanel(this.publicData.site_name, window.location.origin + this.router.home, '');
  146. } catch (error) {
  147. this.$message('抱歉,您所使用的浏览器无法完成此操作,请使用Ctrl+D进行添加!');
  148. }
  149. }
  150. }
  151. },
  152. template: html
  153. };
  154. });