index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div id="index">
  3. <index-detail
  4. :info="site"
  5. :newsList="newsList"
  6. :backColor="backColor"
  7. :Color="Color"
  8. :noticeList="noticeList"
  9. :recruitList="jobinfoList"
  10. :companyList="corpList"
  11. :nativeList="linkList"
  12. :menuList="menu"
  13. ></index-detail>
  14. </div>
  15. </template>
  16. <script>
  17. import indexDetail from '@/components/index.vue';
  18. import { mapActions, mapState } from 'vuex';
  19. import _ from 'lodash';
  20. export default {
  21. metaInfo() {
  22. return {
  23. title: this.siteTitle ? this.siteTitle : '就业信息网',
  24. };
  25. },
  26. name: 'index',
  27. props: {},
  28. components: {
  29. indexDetail,
  30. },
  31. data: () => ({
  32. info: {
  33. src: require('@/assets/logo.png'),
  34. phone: '0431-12345678',
  35. banner: require('@/assets/banner.png'),
  36. address: '办公地址:长春市经济技术开发区金川街151号吉林省高等学校毕业生就业指导中心2楼一站式办公大厅',
  37. email: '邮编:130012',
  38. gongjiao: '公交线路:乘坐120路、227路、20路、260路、80路、130路、281路、154路、190路、125路公交北方市场下车,北方市场南门南行200米。',
  39. mobile: '业务咨询电话:0431-84657570 0431-84657571;',
  40. date: '办公时间:周一至周五,法定假日不对外办公。',
  41. footTitle: '吉ICP备09006292号-1 Copyright 2013 版权所有 吉林省高等学校毕业生就业指导中心 All Rights Reserved',
  42. },
  43. site: {}, //站点信息
  44. siteTitle: {}, //站点标题
  45. menu: [], //菜单
  46. modules: [], //模块
  47. newsList: [], //新闻模块
  48. noticeList: [], //公告模块
  49. self1List: [], //自定义模块现在没用
  50. self2List: [], //自定义模块现在没用
  51. jobinfoList: [], //招聘信息
  52. linkList: [], //网站导航
  53. corpList: [], //招聘企业
  54. backColor: '#0457c7',
  55. Color: '#0457c7',
  56. }),
  57. async created() {
  58. await this.toGetSite(); //获取主站信息
  59. this.loadMenu(); //获取菜单信息
  60. this.toGetModule(); //获取模块信息
  61. this.toGetJobInfo(); //获取招聘信息
  62. this.toGetLinks(); //招聘信息+网站链接
  63. this.self();
  64. },
  65. computed: {},
  66. methods: {
  67. ...mapActions(['getSite', `getMenu`, 'getColumn', 'getModule', 'getNews', 'getJobInfo', 'getPosts', 'getLink']),
  68. //站点信息
  69. async toGetSite() {
  70. let site = sessionStorage.getItem('site');
  71. if (!site) {
  72. let result = await this.getSite({ type: 'search' });
  73. if (result.errcode === 0) {
  74. sessionStorage.setItem('site', JSON.stringify(result.data));
  75. if (_.get(result.data, `custom`)) {
  76. let item = result.custom;
  77. }
  78. this.$set(this, `site`, result.data);
  79. this.$set(this, `siteTitle`, this.site.name);
  80. }
  81. } else {
  82. this.$set(this, `site`, JSON.parse(site));
  83. this.$set(this, `siteTitle`, this.site.name);
  84. let arr = this.site;
  85. if (arr.custom) {
  86. let item = arr.custom;
  87. }
  88. }
  89. },
  90. //菜单
  91. async loadMenu() {
  92. let menu = sessionStorage.getItem('menu');
  93. if (menu) {
  94. this.$set(this, `menu`, JSON.parse(menu));
  95. this.finishedMenu();
  96. return;
  97. } else this.toGetMenu();
  98. },
  99. async toGetMenu() {
  100. let result = await this.getMenu({ type: `list` });
  101. if (result.errcode === 0) {
  102. sessionStorage.setItem('menu', JSON.stringify(result.data));
  103. this.$set(this, `menu`, result.data);
  104. this.finishedMenu();
  105. }
  106. },
  107. async finishedMenu() {
  108. let menus = JSON.parse(JSON.stringify(this.menu));
  109. for (const item of menus) {
  110. if (item.type === 'content') {
  111. item.path = `/info/detail?id=${item.content_id}`;
  112. } else if (item.type !== 'url') {
  113. let res = await this.completeMenu(item);
  114. item.children = res;
  115. }
  116. }
  117. this.$set(this, `menu`, menus);
  118. },
  119. async completeMenu(item) {
  120. let result = await this.getColumn({
  121. type: `list`,
  122. data: { parent_id: item.id },
  123. });
  124. if (result.errcode === 0) {
  125. let columns = result.data;
  126. for (const col of columns) {
  127. if (col.type === 'content') {
  128. col.path = `/detail/${col.content_id}`;
  129. } else if (col.type !== 'url') {
  130. col.path = `/newsList/menu/${col.id}?title=${col.title}`;
  131. }
  132. }
  133. return columns;
  134. }
  135. },
  136. //模块
  137. async loadModule() {
  138. let modules = sessionStorage.getItem('modules');
  139. if (modules) {
  140. this.$set(this, `modules`, JSON.parse(modules));
  141. return;
  142. }
  143. this.toGetMenu();
  144. },
  145. async toGetModule() {
  146. let result = await this.getModule({ type: `list` });
  147. if (result.errcode === 0) {
  148. sessionStorage.setItem('modules', JSON.stringify(result.data));
  149. this.$set(this, `modules`, result.data);
  150. this.finishedModule();
  151. }
  152. },
  153. async finishedModule() {
  154. let modules = JSON.parse(JSON.stringify(this.modules));
  155. for (const item of modules) {
  156. if (`${item.is_use}` === `0`) {
  157. let res = await this.completeModules(item);
  158. item.children = res;
  159. }
  160. }
  161. for (const item of modules) {
  162. this.$set(this, `${item.category}List`, item);
  163. }
  164. this.$set(this, `modules`, modules);
  165. },
  166. async completeModules(item) {
  167. let result = await this.getColumn({
  168. type: `list`,
  169. data: { parent_id: item.id },
  170. });
  171. if (result.errcode === 0) {
  172. let columns = result.data;
  173. for (const col of columns) {
  174. if (col.type === `bugList`) {
  175. col.path = `/newsList/module/${col.content_id}`;
  176. col.children = await this.completeColumn(col);
  177. } else if (col.type === `column`) {
  178. col.path = `/newsList/module/${col.id}`;
  179. col.children = await this.completeColumn(col);
  180. } else if (col.type === `content`) {
  181. col.path = `/detail/${col.content_id}`;
  182. }
  183. }
  184. return columns;
  185. }
  186. },
  187. async completeColumn(item) {
  188. let data = { skip: 0, limit: 8 };
  189. if (item.type === `bugList`) {
  190. data.news_type = `0`;
  191. data.parent_id = item.content_id;
  192. } else {
  193. data.news_type = `1`;
  194. data.parent_id = item.id;
  195. }
  196. let result = await this.getNews({ type: 'bugList', data: data });
  197. if (result.errcode === 0) {
  198. return result.data;
  199. }
  200. },
  201. //获取招聘信息
  202. async toGetJobInfo() {
  203. let result = await this.getJobInfo({ type: 'list', data: { limit: 8 } });
  204. if (`${result.errcode}` === '0') {
  205. for (const item of result.data) {
  206. if (!item.jobs || !(item.jobs.length > 0)) continue;
  207. let jobs = [];
  208. for (let job of item.jobs) {
  209. let jobInfo = await this.toGetPosts(job);
  210. jobs.push(jobInfo);
  211. }
  212. item.jobs = jobs;
  213. }
  214. this.$set(this, 'jobinfoList', result.data);
  215. } else {
  216. this.$message.error(result.errmsg ? result.errmsg : 'error');
  217. }
  218. },
  219. async toGetPosts(id) {
  220. let result = await this.getPosts({ type: 'fetch', data: { id: id } });
  221. if (result.errcode === 0) return result.data;
  222. },
  223. //招聘单位+网站链接
  224. async toGetLinks() {
  225. let { links = [], corps = [] } = await this.getLink();
  226. // this.$set(this, `linkList`, links);
  227. this.$set(this, `corpList`, corps);
  228. },
  229. // 网站导航linkList
  230. async self() {
  231. let res = await this.$axios.$get('/linkList.json');
  232. this.$set(this, `linkList`, res);
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="less" scoped></style>