| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- import { defineComponent, reactive, ref } from 'vue'
- import { Sticky, List, Popup, Icon } from 'vant'
- import Search from '@/components/col-search'
- import request from '@/helpers/request'
- import Item from './item'
- import SelectTag from '../search/select-tag'
- import { useRoute } from 'vue-router'
- import ColResult from '@/components/col-result'
- import styles from './index.module.less'
- import { state } from '@/state'
- import SelectSubject from '../search/select-subject'
- export default defineComponent({
- name: 'Album',
- props: {
- hideSearch: {
- type: Boolean,
- default: false
- },
- defauleParams: {
- type: Object,
- default: () => ({})
- }
- },
- setup({ hideSearch, defauleParams }, { expose }) {
- const route = useRoute()
- const tempParams: any = {}
- if (state.version) {
- tempParams.version = state.version || '' // 处理ios审核版本
- tempParams.platform =
- state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
- }
- // if (state.platformType === 'TEACHER') {
- tempParams.myself = false
- // }
- console.log({ ...defauleParams })
- const params = reactive({
- search: (route.query.search as string) || '',
- albumTagIds: route.query.tagids || '',
- page: 1,
- ...tempParams,
- ...defauleParams
- })
- const data = ref<any>(null)
- const loading = ref(false)
- const finished = ref(false)
- const isError = ref(false)
- const tagVisibility = ref(false)
- 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
- try {
- const res = await request.post('/music/album/list', {
- prefix:
- state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
- data: {
- ...params,
- idAndName: params.search
- }
- })
- if (data.value) {
- let 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
- }
- const onComfirm = tags => {
- const d = Object.values(tags).flat().filter(Boolean).join(',')
- params.albumTagIds = d
- params.page = 1
- data.value = null
- FetchList()
- tagVisibility.value = false
- }
- const onComfirmSubject = item => {
- params.page = 1
- params.subjectIds = item.id
- subject.id = item.id
- subject.name = item.name
- data.value = null
- FetchList()
- subject.show = false
- }
- expose({
- onSearch,
- onComfirm,
- onComfirmSubject
- })
- const subject = reactive({
- show: false,
- name: '全部声部',
- id: ''
- })
- return () => {
- return (
- <>
- <List
- loading={loading.value}
- finished={finished.value}
- finished-text={
- data.value && data.value.rows.length ? '没有更多了' : ''
- }
- onLoad={FetchList}
- error={isError.value}
- >
- {!hideSearch && (
- <Sticky class={styles.sticky}>
- <Search
- modelValue={params.search}
- showAction
- onSearch={onSearch}
- onFilter={() => (tagVisibility.value = true)}
- filterDot={!!params.albumTagIds}
- v-slots={{
- left: () => (
- <div
- class={styles.label}
- onClick={() => (subject.show = true)}
- >
- {subject.name}
- <Icon
- classPrefix="iconfont"
- name="down"
- size={12}
- color="#333"
- />
- </div>
- )
- }}
- />
- </Sticky>
- )}
- {data.value && data.value.rows.length
- ? data.value.rows.map(item => <Item data={item} />)
- : !loading.value && (
- <ColResult
- tips="暂无专辑"
- classImgSize="SMALL"
- btnStatus={false}
- />
- )}
- </List>
- <Popup
- show={tagVisibility.value}
- round
- closeable
- position="bottom"
- style={{ height: '60%' }}
- teleport="body"
- onUpdate:show={val => (tagVisibility.value = val)}
- >
- <SelectTag
- defaultValue={route.query.tagids as string}
- onConfirm={onComfirm}
- onCancel={() => {}}
- />
- </Popup>
- <Popup
- show={subject.show}
- position="bottom"
- round
- closeable
- safe-area-inset-bottom
- onClose={() => (subject.show = false)}
- onClosed={() => (subject.show = false)}
- >
- <SelectSubject isReset onComfirm={onComfirmSubject} />
- </Popup>
- </>
- )
- }
- }
- })
|