index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. define([
  2. 'require',
  3. 'store/index',
  4. 'api/merchant',
  5. 'scripts/util',
  6. 'text!./index.html',
  7. 'css!./index.css'
  8. ], function (require, store, merchantApi, util, html) {
  9. return {
  10. props: {
  11. publicData: {
  12. type: Object,
  13. default: function () {
  14. return {};
  15. }
  16. },
  17. userInfo: {
  18. type: Object,
  19. default: function () {
  20. return {
  21. avatar: ''
  22. };
  23. }
  24. }
  25. },
  26. data: function () {
  27. return {
  28. selected: 1,
  29. options: [
  30. {
  31. label: '专题',
  32. value: 1
  33. },
  34. {
  35. label: '资料',
  36. value: 2
  37. }
  38. ],
  39. searchValue: '',
  40. activeIndex: '1',
  41. active: 1,
  42. currentURL: window.location.pathname,
  43. URLSearch: window.location.search,
  44. categoryVisible: false,
  45. menuOn: -1,
  46. pageName: false,
  47. code_url: code_url,
  48. sharedState: store.state,
  49. applyStatus: null,
  50. applyVisible: false,
  51. failMessage: '',
  52. applyStatusIcon: [
  53. require.toUrl('./images/1.png'),
  54. require.toUrl('./images/2.png'),
  55. require.toUrl('./images/2.png')
  56. ]
  57. };
  58. },
  59. created: function () {
  60. for (var key in this.$router) {
  61. if (Object.hasOwnProperty.call(this.$router, key)) {
  62. if (this.$router[key].indexOf(this.currentURL) !== -1) {
  63. this.pageName = key;
  64. }
  65. }
  66. }
  67. if (['material_list', 'material_detail', 'special_cate'].indexOf(this.pageName) !== -1) {
  68. this.setSearchValue();
  69. }
  70. if (['material_list', 'material_detail'].indexOf(this.pageName) !== -1) {
  71. this.selected = 2;
  72. }
  73. if (code_url) {
  74. this.code_url = code_url;
  75. }
  76. },
  77. methods: {
  78. goPage: function (page) {
  79. var vm = this;
  80. var params = '';
  81. // 判断路由结构
  82. if (Array.isArray(page)) {
  83. if (page[1].constructor.toString().indexOf('Object') !== -1) {
  84. params = Object.keys(page[1]).map(function (key) {
  85. return key + '=' + page[1][key];
  86. }).join('&');
  87. }
  88. page = page[0];
  89. }
  90. // 判断是否登录
  91. if (page !== 'home' && (!this.userInfo || !this.userInfo.uid)) {
  92. return store.setLoginAction(true);
  93. }
  94. // 讲师申请状态
  95. if (page === 'teacher_apply') {
  96. if (this.userInfo && this.userInfo.business) {
  97. window.open('/merchant/index.html');
  98. return false;
  99. }
  100. merchantApi.is_apply().then(function (res) {
  101. if (res.data == null) {
  102. window.location.assign(vm.$router[page] + (params ? '?' + params : ''));
  103. } else {
  104. if (res.data.status === null) {
  105. window.location.assign(vm.$router[page] + (params ? '?' + params : ''));
  106. } else {
  107. if (res.data.status === 2) {
  108. window.location.assign(vm.$router[page] + (params ? '?' + params : ''));
  109. } else {
  110. vm.applyStatus = res.data.status;
  111. vm.applyVisible = true;
  112. if (res.data.status === -1) {
  113. vm.failMessage = res.data.fail_message;
  114. }
  115. }
  116. }
  117. }
  118. });
  119. return false;
  120. }
  121. window.location.assign(this.$router[page] + (params ? '?' + params : ''));
  122. },
  123. onSearch: function (hot) {
  124. if (!hot && !this.searchValue) {
  125. return;
  126. }
  127. if (hot) {
  128. this.searchValue = hot;
  129. }
  130. if (this.currentURL.includes('/web/special/special_cate')) {
  131. if (this.selected === 1) {
  132. this.$emit('submit-search', this.searchValue);
  133. } else {
  134. window.location.assign(this.$router.material_list + '?search=' + this.searchValue);
  135. }
  136. } else if (this.currentURL.includes('/web/material/material_list')) {
  137. if (this.selected === 2) {
  138. this.$emit('submit-search', this.searchValue);
  139. } else {
  140. window.location.assign(this.$router.special_cate + '?search=' + this.searchValue);
  141. }
  142. } else {
  143. window.location.assign((this.selected === 1 ? this.$router.special_cate : this.$router.material_list) + '?search=' + this.searchValue);
  144. }
  145. },
  146. categoryMouseenter: function () {
  147. this.categoryMouse = true;
  148. this.categoryVisible = true;
  149. },
  150. categoryMouseleave: function () {
  151. this.categoryMouse = false;
  152. if (!(this.contentMouse || this.menuMouse)) {
  153. this.menuOn = -1;
  154. this.categoryVisible = false;
  155. }
  156. },
  157. menuMouseenter: function () {
  158. this.menuMouse = true;
  159. },
  160. menuMouseleave: function () {
  161. this.menuMouse = false;
  162. if (!(this.contentMouse || this.categoryMouse)) {
  163. this.menuOn = -1;
  164. this.categoryVisible = false;
  165. }
  166. },
  167. contentMouseenter: function () {
  168. this.contentMouse = true;
  169. },
  170. contentMouseleave: function () {
  171. this.contentMouse = false;
  172. if (!(this.menuMouse || this.categoryMouse)) {
  173. this.menuOn = -1;
  174. this.categoryVisible = false;
  175. }
  176. },
  177. setSearchValue: function () {
  178. var search = util.getParmas('search');
  179. if (search) {
  180. this.searchValue = search;
  181. }
  182. },
  183. // 收藏本站
  184. addFavorite: function () {
  185. try {
  186. window.external.addFavorite(window.location.origin + this.$router.home, this.publicData.site_name);
  187. } catch (error) {
  188. try {
  189. window.sidebar.addPanel(this.publicData.site_name, window.location.origin + this.$router.home, '');
  190. } catch (error) {
  191. this.$message('抱歉,您所使用的浏览器无法完成此操作,请使用Ctrl+D进行添加!');
  192. }
  193. }
  194. },
  195. loginOpen: function () {
  196. store.setLoginAction(true);
  197. },
  198. goApply: function () {
  199. window.location.assign(this.$router.teacher_apply);
  200. }
  201. },
  202. template: html
  203. };
  204. });