list.vue 4.4 KB

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