Browse Source

Update list.tsx

lex 2 years ago
parent
commit
e4e7d0d157
1 changed files with 129 additions and 1 deletions
  1. 129 1
      src/views/music/list/list.tsx

+ 129 - 1
src/views/music/list/list.tsx

@@ -1,3 +1,131 @@
+import { List } from 'vant'
 import { defineComponent } from 'vue'
 
-export default defineComponent({})
+export default defineComponent({
+  name: 'list',
+  data() {
+    return {}
+  },
+  setup(this, props, ctx) {
+    const subjects: any = useSubjectId(SubjectEnum.SEARCH)
+    // 判断是否已有数据
+    if (!subjects.id) {
+      const users = state.user.data
+      const subjectId = users.subjectId
+        ? Number(users.subjectId.split(',')[0])
+        : ''
+      const subjectName = users.subjectName
+        ? users.subjectName.split(',')[0]
+        : ''
+      if (subjectId) {
+        useSubjectId(
+          SubjectEnum.SEARCH,
+          JSON.stringify({
+            id: subjectId,
+            name: subjectName
+          }),
+          'set'
+        )
+      }
+    }
+
+    localStorage.setItem('behaviorId', getRandomKey())
+    const route = useRoute()
+    // const router = useRouter()
+    const tempParams: any = {}
+    if (state.version) {
+      tempParams.version = state.version || '' // 处理ios审核版本
+      tempParams.platform =
+        state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
+    }
+    // 判断是否在搜索页面用过
+    if (!hideSearch) {
+      const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
+      tempParams.subjectIds = getSubject.id
+    }
+    //
+    const params = reactive({
+      search: (route.query.search as string) || '',
+      exquisiteFlag: 1,
+      musicTagIds: route.query.tagids || '',
+      page: 1,
+      ...defauleParams,
+      ...tempParams
+    })
+    const data = ref<any>(null)
+    const loading = ref(false)
+    const finished = ref(false)
+    const isError = ref(false)
+    const tagVisibility = ref(false)
+    const apiSuffix = ref(
+      state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
+    )
+
+    const onSearch = (value: string) => {
+      params.page = 1
+      params.search = value
+      data.value = null
+      FetchList()
+    }
+
+    const FetchList = async () => {
+      if (loading.value) {
+        return
+      }
+      loading.value = true
+      isError.value = false
+      const tempParams = {
+        ...params,
+        idAndName: params.search,
+        createBy: teacherId
+      }
+      // if (state.platformType === 'TEACHER') {
+      tempParams.myself = false
+      // }
+
+      try {
+        const res = await request.post(`${apiSuffix.value}/music/sheet/list`, {
+          data: tempParams
+        })
+        if (data.value) {
+          const result = (data.value?.rows || []).concat(res.data.rows || [])
+          data.value.rows = result
+        }
+        data.value = data.value || res.data
+        params.page = res.data.pageNo + 1
+        finished.value = res.data.pageNo >= res.data.totalPage
+      } catch (error) {
+        isError.value = true
+      }
+      loading.value = false
+    }
+    return () => (
+      <List
+        loading={loading.value}
+        finished={finished.value}
+        finished-text={data.value && data.value.rows.length ? '没有更多了' : ''}
+        onLoad={FetchList}
+        error={isError.value}
+      >
+        {data.value && data.value.rows.length ? (
+          <div class={styles.alumnList}>
+            <Song
+              list={data.value.rows}
+              onDetail={(item: any) => {
+                if (onItemClick === noop) {
+                  musicBuy(item)
+                } else {
+                  onItemClick?.(item)
+                }
+              }}
+            />
+          </div>
+        ) : (
+          !loading.value && (
+            <ColResult tips="暂无曲目" classImgSize="SMALL" btnStatus={false} />
+          )
+        )}
+      </List>
+    )
+  }
+})