index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import OEmpty from '@/components/m-empty';
  2. import OHeader from '@/components/m-header';
  3. import OSearch from '@/components/m-search';
  4. import OSticky from '@/components/m-sticky';
  5. import request from '@/helpers/request';
  6. import { state } from '@/state';
  7. import { Cell, CellGroup, List } from 'vant';
  8. import { defineComponent, onMounted, reactive } from 'vue';
  9. import { useRoute, useRouter } from 'vue-router';
  10. import styles from './index.module.less';
  11. export default defineComponent({
  12. name: 'help-center',
  13. setup() {
  14. const route = useRoute();
  15. const router = useRouter();
  16. const form = reactive({
  17. isClick: false,
  18. list: [] as any,
  19. listState: {
  20. dataShow: true, // 判断是否有数据
  21. loading: false,
  22. finished: false
  23. },
  24. params: {
  25. keyword: null,
  26. status: true,
  27. page: 1,
  28. rows: 20
  29. }
  30. });
  31. const getList = async () => {
  32. try {
  33. if (form.isClick) return;
  34. form.isClick = true;
  35. const res = await request.post('/edu-app/open/helpCenterContent/page', {
  36. data: {
  37. ...form.params,
  38. catalogType: 'STUDENT'
  39. }
  40. });
  41. form.listState.loading = false;
  42. const result = res.data || {};
  43. // 处理重复请求数据
  44. if (form.list.length > 0 && result.current === 1) {
  45. return;
  46. }
  47. //
  48. form.list = form.list.concat(result.rows || []);
  49. form.listState.finished = result.current >= result.pages;
  50. form.params.page = result.current + 1;
  51. form.listState.dataShow = form.list.length > 0;
  52. form.isClick = false;
  53. } catch {
  54. form.listState.dataShow = false;
  55. form.listState.finished = true;
  56. form.isClick = false;
  57. }
  58. };
  59. const onSearch = (val: any) => {
  60. form.params.keyword = val;
  61. form.params.page = 1;
  62. form.list = [];
  63. form.listState.dataShow = true; // 判断是否有数据
  64. form.listState.loading = false;
  65. form.listState.finished = false;
  66. getList();
  67. };
  68. onMounted(() => {
  69. getList();
  70. });
  71. return () => (
  72. <div
  73. class={[
  74. styles.helpCenter,
  75. !form.listState.dataShow && 'emptyRootContainer'
  76. ]}>
  77. {route.query.platformType == 'ANALYSIS' ? null : (
  78. <OSticky position="top">
  79. <OHeader border={false} />
  80. <OSearch onSearch={onSearch} />
  81. </OSticky>
  82. )}
  83. {form.listState.dataShow ? (
  84. <List
  85. // v-model:loading={form.listState.loading}
  86. finished={form.listState.finished}
  87. finishedText=" "
  88. class={styles.container}
  89. onLoad={getList}
  90. immediateCheck={false}>
  91. {form.list.map((item: any) => (
  92. <Cell
  93. titleClass={[styles.title, 'van-ellipsis']}
  94. title={item.title}
  95. isLink
  96. onClick={() => {
  97. router.push({
  98. path: 'help-detail',
  99. query: {
  100. id: item.id
  101. }
  102. });
  103. }}></Cell>
  104. ))}
  105. </List>
  106. ) : (
  107. <div
  108. style={{
  109. height: `calc(100vh - var(--header-height))`
  110. }}>
  111. <OEmpty description="暂无数据" />
  112. </div>
  113. )}
  114. </div>
  115. );
  116. }
  117. });