index.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue'
  2. import { Sticky, List, Popup, Icon, Switch } 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, useRouter } from 'vue-router'
  8. import ColResult from '@/components/col-result'
  9. import styles from './index.module.less'
  10. import { getRandomKey, musicBuy } from '../music'
  11. import { state } from '@/state'
  12. import SelectSubject from '../search/select-subject'
  13. import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
  14. import Song from '../component/song'
  15. import ColHeader from '@/components/col-header'
  16. import { useRect } from '@vant/use'
  17. const noop = () => {
  18. //
  19. }
  20. export default defineComponent({
  21. name: 'MusicList',
  22. props: {
  23. hideSearch: {
  24. type: Boolean,
  25. default: false
  26. },
  27. defauleParams: {
  28. type: Object,
  29. default: () => ({})
  30. },
  31. onItemClick: {
  32. type: Function,
  33. default: noop
  34. },
  35. teacherId: {
  36. type: String || Number,
  37. default: ''
  38. },
  39. myself: {
  40. type: Boolean,
  41. default: false
  42. }
  43. },
  44. setup(
  45. { hideSearch, defauleParams, onItemClick, teacherId, myself },
  46. { expose }
  47. ) {
  48. const subjects: any = useSubjectId(SubjectEnum.SEARCH)
  49. // 判断是否已有数据
  50. if (!subjects.id) {
  51. const users = state.user.data
  52. const subjectId = users.subjectId
  53. ? Number(users.subjectId.split(',')[0])
  54. : ''
  55. const subjectName = users.subjectName
  56. ? users.subjectName.split(',')[0]
  57. : ''
  58. if (subjectId) {
  59. useSubjectId(
  60. SubjectEnum.SEARCH,
  61. JSON.stringify({
  62. id: subjectId,
  63. name: subjectName
  64. }),
  65. 'set'
  66. )
  67. }
  68. }
  69. localStorage.setItem('behaviorId', getRandomKey())
  70. const route = useRoute()
  71. // const router = useRouter()
  72. const tempParams: any = {}
  73. if (state.version) {
  74. tempParams.version = state.version || '' // 处理ios审核版本
  75. tempParams.platform =
  76. state.platformType === 'STUDENT' ? 'ios-student' : 'ios-teacher'
  77. }
  78. // 判断是否在搜索页面用过
  79. if (!hideSearch) {
  80. const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
  81. tempParams.subjectIds = getSubject.id
  82. }
  83. //
  84. const params = reactive({
  85. search: (route.query.search as string) || '',
  86. // exquisiteFlag: 1,
  87. musicTagIds: route.query.tagids || '',
  88. page: 1,
  89. ...defauleParams,
  90. ...tempParams
  91. })
  92. const data = ref<any>(null)
  93. const loading = ref(false)
  94. const finished = ref(false)
  95. const isError = ref(false)
  96. const tagVisibility = ref(false)
  97. const exquisiteFlag = ref(false)
  98. const apiSuffix = ref(
  99. state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  100. )
  101. const onSearch = (value: string) => {
  102. params.page = 1
  103. params.search = value
  104. data.value = null
  105. FetchList()
  106. }
  107. const FetchList = async () => {
  108. if (loading.value) {
  109. return
  110. }
  111. loading.value = true
  112. isError.value = false
  113. const tempParams = {
  114. ...params,
  115. idAndName: params.search,
  116. createBy: teacherId,
  117. myself: false
  118. }
  119. // if (state.platformType === 'TEACHER') {
  120. // }
  121. if (!myself) {
  122. tempParams.myself = false
  123. }
  124. try {
  125. const res = await request.post(`${apiSuffix.value}/music/sheet/list`, {
  126. data: tempParams
  127. })
  128. if (data.value) {
  129. const result = (data.value?.rows || []).concat(res.data.rows || [])
  130. data.value.rows = result
  131. }
  132. data.value = data.value || res.data
  133. params.page = res.data.pageNo + 1
  134. finished.value = res.data.pageNo >= res.data.totalPage
  135. } catch (error) {
  136. isError.value = true
  137. }
  138. loading.value = false
  139. }
  140. const onComfirm = tags => {
  141. const tempTags: any = {}
  142. // 单独处理乐谱类型
  143. for (const tag in tags) {
  144. if (Number(tag) === -1) {
  145. exquisiteFlag.value = tags[tag][0] ? true : false
  146. } else {
  147. tempTags[tag] = tags[tag]
  148. }
  149. }
  150. const d = Object.values(tempTags).flat().filter(Boolean).join(',')
  151. params.musicTagIds = d
  152. params.page = 1
  153. data.value = null
  154. FetchList()
  155. tagVisibility.value = false
  156. }
  157. const onComfirmSubject = item => {
  158. params.page = 1
  159. params.subjectIds = item.id
  160. subject.id = item.id
  161. subject.name = item.name
  162. data.value = null
  163. useSubjectId(
  164. SubjectEnum.SEARCH,
  165. JSON.stringify({
  166. id: item.id,
  167. name: item.name
  168. }),
  169. 'set'
  170. )
  171. FetchList()
  172. subject.show = false
  173. }
  174. const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
  175. const subject = reactive({
  176. show: false,
  177. name: getSubject.name || '全部声部',
  178. id: getSubject.id || ''
  179. })
  180. expose({
  181. onSearch,
  182. onComfirm,
  183. onComfirmSubject
  184. })
  185. return () => (
  186. <>
  187. {!hideSearch && (
  188. <Sticky class={styles.sticky}>
  189. <Search
  190. showAction
  191. onSearch={onSearch}
  192. onFilter={() => (tagVisibility.value = true)}
  193. filterDot={!!params.musicTagIds}
  194. v-slots={{
  195. left: () => (
  196. <div
  197. class={styles.label}
  198. onClick={() => (subject.show = true)}
  199. >
  200. {subject.name}
  201. <Icon
  202. classPrefix="iconfont"
  203. name="down"
  204. size={12}
  205. color="#333"
  206. />
  207. </div>
  208. )
  209. }}
  210. />
  211. </Sticky>
  212. )}
  213. <List
  214. loading={loading.value}
  215. finished={finished.value}
  216. finished-text={
  217. data.value && data.value.rows.length ? '没有更多了' : ''
  218. }
  219. onLoad={FetchList}
  220. error={isError.value}
  221. >
  222. {data.value && data.value.rows.length ? (
  223. <div class={styles.alumnList}>
  224. <Song
  225. list={data.value.rows}
  226. onDetail={(item: any) => {
  227. if (onItemClick === noop) {
  228. musicBuy(item)
  229. } else {
  230. onItemClick?.(item)
  231. }
  232. }}
  233. />
  234. </div>
  235. ) : (
  236. !loading.value && (
  237. <ColResult
  238. tips="暂无曲目"
  239. classImgSize="SMALL"
  240. btnStatus={false}
  241. />
  242. )
  243. )}
  244. </List>
  245. <Popup
  246. show={tagVisibility.value}
  247. round
  248. closeable
  249. position="bottom"
  250. style={{ height: '60%' }}
  251. teleport="body"
  252. onUpdate:show={val => (tagVisibility.value = val)}
  253. >
  254. <SelectTag
  255. exquisiteFlag
  256. onConfirm={onComfirm}
  257. onCancel={() => {
  258. //
  259. }}
  260. defaultValue={route.query.tagids as string}
  261. />
  262. </Popup>
  263. {/* 声部弹框 */}
  264. <Popup
  265. show={subject.show}
  266. position="bottom"
  267. round
  268. closeable
  269. safe-area-inset-bottom
  270. onClose={() => (subject.show = false)}
  271. onClosed={() => (subject.show = false)}
  272. >
  273. <SelectSubject
  274. isReset
  275. type="MUSIC"
  276. searchParams={subject}
  277. onComfirm={onComfirmSubject}
  278. />
  279. </Popup>
  280. </>
  281. )
  282. }
  283. })