index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {
  2. NBreadcrumb,
  3. NBreadcrumbItem,
  4. NSpace,
  5. NTabPane,
  6. NTabs
  7. } from 'naive-ui';
  8. import { defineComponent, nextTick, reactive } from 'vue';
  9. import styles from './index.module.less';
  10. import icon_back from '../../xiaoku-music/images/icon_back.png';
  11. import { useRouter } from 'vue-router';
  12. import List from './components/list';
  13. import { api_knowledgeWikiCategoryType_page } from '../api';
  14. import TheEmpty from '/src/components/TheEmpty';
  15. // 164px 244px
  16. export default defineComponent({
  17. name: 'content-music',
  18. setup() {
  19. const tabValue = sessionStorage.getItem('content-music-tab');
  20. const router = useRouter();
  21. const state = reactive({
  22. tabValue: '',
  23. categoryList: [] as any,
  24. loading: false
  25. });
  26. const getCategoryList = async () => {
  27. state.loading = true;
  28. try {
  29. const { data } = await api_knowledgeWikiCategoryType_page({
  30. type: 'MUSIC',
  31. page: 1,
  32. rows: 99
  33. });
  34. state.categoryList = data.rows || [];
  35. if (state.categoryList.length) {
  36. nextTick(() => {
  37. state.tabValue = tabValue || 'name-' + state.categoryList[0].id;
  38. });
  39. }
  40. } catch {
  41. //
  42. }
  43. state.loading = false;
  44. };
  45. getCategoryList();
  46. return () => (
  47. <div class={styles.container}>
  48. <NSpace align="center" wrapItem={false} size={16}>
  49. <img
  50. style={{ cursor: 'pointer' }}
  51. src={icon_back}
  52. class={styles.iconBack}
  53. onClick={() => router.push({ path: '/' })}
  54. />
  55. <NBreadcrumb separator="">
  56. <NBreadcrumbItem>名曲鉴赏</NBreadcrumbItem>
  57. </NBreadcrumb>
  58. </NSpace>
  59. <div class={styles.wrap}>
  60. <div
  61. class={[
  62. styles.listWrap,
  63. !state.loading &&
  64. state.categoryList.length <= 0 &&
  65. styles.listWrapEmpty
  66. ]}>
  67. {!state.loading && state.categoryList.length <= 0 && (
  68. <TheEmpty description="暂无名曲鉴赏" />
  69. )}
  70. <NTabs
  71. defaultValue="myResources"
  72. paneClass={styles.paneTitle}
  73. justifyContent="center"
  74. paneWrapperClass={styles.paneWrapperContainer}
  75. v-model:value={state.tabValue}
  76. onUpdate:value={(val: any) => {
  77. console.log(val, 'val');
  78. sessionStorage.setItem('content-music-tab', val);
  79. }}>
  80. {state.categoryList.map((category: any) => (
  81. <NTabPane
  82. name={`name-${category.id}`}
  83. tab={category.name}
  84. // displayDirective="show:lazy"
  85. >
  86. <List
  87. categoryId={category.id}
  88. categoryChildList={category.childrenList}
  89. />
  90. </NTabPane>
  91. ))}
  92. </NTabs>
  93. </div>
  94. </div>
  95. </div>
  96. );
  97. }
  98. });