index.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import { defineComponent, reactive, ref } from 'vue'
  2. import { Sticky, List, Popup, Icon } from 'vant'
  3. import Search from '@/components/col-search'
  4. import request from '@/helpers/request'
  5. import Item from './item'
  6. import SelectTag from '../search/select-tag'
  7. import { useRoute } from 'vue-router'
  8. import ColResult from '@/components/col-result'
  9. import styles from './index.module.less'
  10. import { state } from '@/state'
  11. import SelectSubject from '../search/select-subject'
  12. export default defineComponent({
  13. name: 'Album',
  14. props: {
  15. hideSearch: {
  16. type: Boolean,
  17. default: false
  18. },
  19. defauleParams: {
  20. type: Object,
  21. default: () => ({})
  22. }
  23. },
  24. setup({ hideSearch, defauleParams }, { expose }) {
  25. const route = useRoute()
  26. const tempParams: any = {}
  27. if (state.version) {
  28. tempParams.version = state.version || '' // 处理ios审核版本
  29. tempParams.platform =
  30. state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
  31. }
  32. // if (state.platformType === 'TEACHER') {
  33. tempParams.myself = false
  34. // }
  35. console.log({ ...defauleParams })
  36. const params = reactive({
  37. search: (route.query.search as string) || '',
  38. albumTagIds: route.query.tagids || '',
  39. page: 1,
  40. ...tempParams,
  41. ...defauleParams
  42. })
  43. const data = ref<any>(null)
  44. const loading = ref(false)
  45. const finished = ref(false)
  46. const isError = ref(false)
  47. const tagVisibility = ref(false)
  48. const onSearch = (value: string) => {
  49. params.page = 1
  50. params.search = value
  51. data.value = null
  52. FetchList()
  53. }
  54. const FetchList = async () => {
  55. if (loading.value) {
  56. return
  57. }
  58. loading.value = true
  59. isError.value = false
  60. try {
  61. const res = await request.post('/music/album/list', {
  62. prefix:
  63. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
  64. data: {
  65. ...params,
  66. idAndName: params.search
  67. }
  68. })
  69. if (data.value) {
  70. let result = (data.value?.rows || []).concat(res.data.rows || [])
  71. data.value.rows = result
  72. }
  73. data.value = data.value || res.data
  74. params.page = res.data.pageNo + 1
  75. finished.value = res.data.pageNo >= res.data.totalPage
  76. } catch (error) {
  77. isError.value = true
  78. }
  79. loading.value = false
  80. }
  81. const onComfirm = tags => {
  82. const d = Object.values(tags).flat().filter(Boolean).join(',')
  83. params.albumTagIds = d
  84. params.page = 1
  85. data.value = null
  86. FetchList()
  87. tagVisibility.value = false
  88. }
  89. const onComfirmSubject = item => {
  90. params.page = 1
  91. params.subjectIds = item.id
  92. subject.id = item.id
  93. subject.name = item.name
  94. data.value = null
  95. FetchList()
  96. subject.show = false
  97. }
  98. expose({
  99. onSearch,
  100. onComfirm,
  101. onComfirmSubject
  102. })
  103. const subject = reactive({
  104. show: false,
  105. name: '全部声部',
  106. id: ''
  107. })
  108. return () => {
  109. return (
  110. <>
  111. <List
  112. loading={loading.value}
  113. finished={finished.value}
  114. finished-text={
  115. data.value && data.value.rows.length ? '没有更多了' : ''
  116. }
  117. onLoad={FetchList}
  118. error={isError.value}
  119. >
  120. {!hideSearch && (
  121. <Sticky class={styles.sticky}>
  122. <Search
  123. modelValue={params.search}
  124. showAction
  125. onSearch={onSearch}
  126. onFilter={() => (tagVisibility.value = true)}
  127. filterDot={!!params.albumTagIds}
  128. v-slots={{
  129. left: () => (
  130. <div
  131. class={styles.label}
  132. onClick={() => (subject.show = true)}
  133. >
  134. {subject.name}
  135. <Icon
  136. classPrefix="iconfont"
  137. name="down"
  138. size={12}
  139. color="#333"
  140. />
  141. </div>
  142. )
  143. }}
  144. />
  145. </Sticky>
  146. )}
  147. {data.value && data.value.rows.length
  148. ? data.value.rows.map(item => <Item data={item} />)
  149. : !loading.value && (
  150. <ColResult
  151. tips="暂无专辑"
  152. classImgSize="SMALL"
  153. btnStatus={false}
  154. />
  155. )}
  156. </List>
  157. <Popup
  158. show={tagVisibility.value}
  159. round
  160. closeable
  161. position="bottom"
  162. style={{ height: '60%' }}
  163. teleport="body"
  164. onUpdate:show={val => (tagVisibility.value = val)}
  165. >
  166. <SelectTag
  167. defaultValue={route.query.tagids as string}
  168. onConfirm={onComfirm}
  169. onCancel={() => {}}
  170. />
  171. </Popup>
  172. <Popup
  173. show={subject.show}
  174. position="bottom"
  175. round
  176. closeable
  177. safe-area-inset-bottom
  178. onClose={() => (subject.show = false)}
  179. onClosed={() => (subject.show = false)}
  180. >
  181. <SelectSubject isReset onComfirm={onComfirmSubject} />
  182. </Popup>
  183. </>
  184. )
  185. }
  186. }
  187. })