jobinfo.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div id="jobinfo">
  3. <jobinfo-detail :info="site" :menuList="menu" :backColor="backColor" :Color="Color" :jobinfoInfo="jobInfo" :jobslist="jobList"></jobinfo-detail>
  4. </div>
  5. </template>
  6. <script>
  7. import jobinfoDetail from '@/components/jobinfo.vue';
  8. import { mapActions, mapState } from 'vuex';
  9. import _ from 'lodash';
  10. export default {
  11. metaInfo() {
  12. return {
  13. title: this.siteTitle ? this.siteTitle : '就业信息网',
  14. };
  15. },
  16. name: 'jobinfo',
  17. props: {},
  18. components: {
  19. jobinfoDetail,
  20. },
  21. data: () => ({
  22. backColor: '#0457c7',
  23. Color: '#0457c7',
  24. jobInfo: {},
  25. jobList: [],
  26. menu: [],
  27. site: {},
  28. siteTitle: '',
  29. }),
  30. async created() {
  31. await this.toGetSite(); //获取主站信息
  32. await this.loadMenu(); //获取菜单信息
  33. this.search();
  34. },
  35. computed: {},
  36. methods: {
  37. ...mapActions(['getSite', 'getMenu', 'getColumn', 'getPosts', 'getJobInfo']),
  38. async search() {
  39. //1直接拿着参数发送请求
  40. let result = await this.getJobInfo({ type: 'search', data: { id: this.$route.query.id } });
  41. if (`${result.errcode}` === '0') {
  42. //给this=>vue的实例下在中的list属性,赋予result.data的值
  43. this.$set(this, `jobInfo`, result.data);
  44. this.searchJobs();
  45. } else {
  46. this.$message.error(result.errmsg ? result.errmsg : 'error');
  47. }
  48. },
  49. async searchJobs() {
  50. let result;
  51. let jobIds = this.jobInfo.jobs.length > 0 ? this.jobInfo.jobs : [];
  52. let jobList = [];
  53. for (const item of jobIds) {
  54. result = await this.getPosts({ type: 'fetch', data: { id: item } });
  55. if (`${result.errcode}` === '0') {
  56. jobList.push(result.data);
  57. }
  58. }
  59. this.$set(this, `jobList`, jobList);
  60. },
  61. //站点信息
  62. async toGetSite() {
  63. let site = sessionStorage.getItem('site');
  64. if (site) {
  65. this.$set(this, `site`, JSON.parse(site));
  66. this.$set(this, `siteTitle`, this.site.name);
  67. } else {
  68. let result = await this.getSite({ type: 'search' });
  69. if (result.errcode === 0) {
  70. sessionStorage.setItem('site', JSON.stringify(result.data));
  71. if (_.get(result.data, `custom`)) {
  72. let item = result.custom;
  73. }
  74. this.$set(this, `site`, result.data);
  75. this.$set(this, `siteTitle`, this.site.name);
  76. }
  77. }
  78. },
  79. //菜单
  80. async loadMenu() {
  81. let menu = sessionStorage.getItem('menu');
  82. if (menu) {
  83. this.$set(this, `menu`, JSON.parse(menu));
  84. await this.finishedMenu();
  85. } else this.toGetMenu();
  86. },
  87. async toGetMenu() {
  88. let result = await this.getMenu({ type: `list` });
  89. if (result.errcode === 0) {
  90. sessionStorage.setItem('menu', JSON.stringify(result.data));
  91. this.$set(this, `menu`, result.data);
  92. this.finishedMenu();
  93. }
  94. },
  95. async finishedMenu() {
  96. let menus = JSON.parse(JSON.stringify(this.menu));
  97. for (const item of menus) {
  98. if (item.type === 'content') {
  99. item.path = `/detail/${item.content_id}`;
  100. } else if (item.type !== 'url') {
  101. let res = await this.completeMenu(item);
  102. item.children = res;
  103. }
  104. }
  105. this.$set(this, `menu`, menus);
  106. },
  107. async completeMenu(item) {
  108. let result = await this.getColumn({
  109. type: `list`,
  110. data: { parent_id: item.id },
  111. });
  112. if (result.errcode === 0) {
  113. let columns = result.data;
  114. for (const col of columns) {
  115. if (col.type === 'content') {
  116. col.path = `/detail/${col.content_id}`;
  117. } else if (col.type !== 'url') {
  118. col.path = `/newsList/menu/${col.id}?title=${col.title}`;
  119. if (col.parent.includes('党员')) {
  120. col.path = `/memberList/menu/${col.id}?title=${col.title}`;
  121. }
  122. }
  123. }
  124. return columns;
  125. }
  126. },
  127. },
  128. };
  129. </script>
  130. <style lang="less" scoped></style>