index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // import { PaperClipIcon } from '@heroicons/vue/solid'
  2. import { defineComponent, toRefs, reactive, onMounted, ref } from 'vue'
  3. import arrow from '@/views/home/images/moreArrow.png'
  4. import styles from './index.module.less'
  5. import albumItem from './modals/albumItem'
  6. import videoDetailItem from '@/components/videoDetailItem'
  7. import musicLIstItem from '@/components/musicLIstItem'
  8. import hotSearch from '@/components/hotSearch'
  9. import { Swiper, SwiperSlide } from 'swiper/vue'
  10. import { Navigation, Pagination, Scrollbar, A11y } from 'swiper'
  11. import request from '@/helpers/request'
  12. import silder from '@/components/silder'
  13. import searchInput from '@/components/searchInput'
  14. import banner from '@/components/banner'
  15. import titleDot from '@/views/home/images/titleDot.png'
  16. import 'swiper/css'
  17. import 'swiper/css/navigation'
  18. import 'swiper/css/pagination'
  19. import 'swiper/css/scrollbar'
  20. import pagination from '@/components/pagination'
  21. import { useRoute, useRouter } from 'vue-router'
  22. import { state as baseState } from '@/state'
  23. import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
  24. import { getUserType } from '@/helpers/utils'
  25. import ColEmpty from '@/components/col-empty'
  26. export default defineComponent({
  27. name: 'musicLibrary',
  28. components: {
  29. albumItem,
  30. videoDetailItem,
  31. musicLIstItem,
  32. hotSearch,
  33. silder,
  34. searchInput,
  35. pagination,
  36. ColEmpty,
  37. banner
  38. },
  39. setup() {
  40. const route = useRoute()
  41. let subjectId = 0
  42. const subjectIds = baseState.user.data?.subjectId || ''
  43. if (subjectIds) {
  44. subjectId = Number(subjectIds.split(',')[0])
  45. }
  46. // 判断是否在默认的声部
  47. const subjects: any = useSubjectId(SubjectEnum.SEARCH)
  48. subjectId = subjects.id || subjectId
  49. const state = reactive({
  50. albumList: [],
  51. musicList: [],
  52. tagTree: [],
  53. hideSearch: true,
  54. isshowData: false,
  55. pageInfo: {
  56. // 分页规则
  57. limit: 20, // 限制显示条数
  58. page: 1, // 当前页
  59. total: 0, // 总条数
  60. page_size: [5, 10, 20, 40, 50] // 选择限制显示条数
  61. },
  62. searchs: {
  63. musicTagIds: route.query.musicTagIds || '',
  64. search: route.query.search || '',
  65. subject: subjectId || ''
  66. }
  67. })
  68. const getMusicList = async () => {
  69. try {
  70. const { search, subject, ...more } = state.searchs
  71. const res = await request.post('/api-website/open/music/sheet/list', {
  72. data: {
  73. auditStatus: 'PASS',
  74. ...more,
  75. idAndName: search,
  76. subjectIds: subject,
  77. page: state.pageInfo.page,
  78. rows: state.pageInfo.limit,
  79. state: 1
  80. }
  81. })
  82. // state.musicList = res.data.rows
  83. state.musicList = res.data.rows.map(n => {
  84. if (typeof n.paymentType === 'string')
  85. n.paymentType = n.paymentType.split(',')
  86. return n
  87. })
  88. state.pageInfo.total = res.data.total
  89. if (state.pageInfo.total == 0) {
  90. state.isshowData = true
  91. } else {
  92. state.isshowData = false
  93. }
  94. } catch (e) {
  95. console.log(e)
  96. }
  97. }
  98. const getTagTree = async () => {
  99. try {
  100. const res = await request.get('/api-website/open/MusicTag/tree', {
  101. params: {
  102. type: 'MUSIC'
  103. }
  104. })
  105. const tree = res.data || []
  106. state.tagTree = [
  107. {
  108. name: '全部',
  109. id: '',
  110. isCheck: true
  111. },
  112. ...tree
  113. ] as any
  114. if (state.searchs.musicTagIds) {
  115. state.tagTree.forEach((tag: any) => {
  116. tag.isCheck = false
  117. if (tag.id == state.searchs.musicTagIds) {
  118. tag.isCheck = true
  119. }
  120. })
  121. }
  122. } catch (e) {
  123. console.log(e)
  124. }
  125. }
  126. const searchRust = (val: any) => {
  127. // const smallTag = (val || ([] as any)).filter(tag => tag < 0)
  128. const maxTag = (val || ([] as any)).filter(tag => tag > 0)
  129. state.searchs.musicTagIds = maxTag.join(',') as string
  130. startSearch(state.searchs)
  131. }
  132. const startSearch = (val: any) => {
  133. state.searchs = { ...state.searchs, ...val }
  134. getMusicList()
  135. }
  136. onMounted(() => {
  137. getTagTree()
  138. getMusicList()
  139. })
  140. return () => (
  141. <div>
  142. <banner></banner>
  143. <div class="bg-white">
  144. <div class={styles.w1200}>
  145. <div class={styles.section} style="padding-bottom: 0;">
  146. <div class={styles.tagList}>
  147. <div
  148. class={[styles.tagContainer, state.hideSearch && styles.hide]}
  149. >
  150. {state.tagTree.map((tag: any) => (
  151. <span
  152. class={[styles.tagItem, tag.isCheck && styles.active]}
  153. onClick={() => {
  154. state.tagTree.forEach((item: any) => {
  155. item.isCheck = false
  156. })
  157. tag.isCheck = true
  158. startSearch({ musicTagIds: tag.id })
  159. }}
  160. >
  161. {tag.name}
  162. </span>
  163. ))}
  164. </div>
  165. <div
  166. class={styles.wrapRight}
  167. onClick={() => {
  168. state.hideSearch = !state.hideSearch
  169. }}
  170. >
  171. <span>{state.hideSearch ? '更多' : '收起'}</span>
  172. <img
  173. class={[styles.arrow, !state.hideSearch && styles.active]}
  174. src={arrow}
  175. alt=""
  176. />
  177. </div>
  178. </div>
  179. <searchInput
  180. isWhile={false}
  181. type="search"
  182. showSearch
  183. placeholder="搜索你想练习的专辑"
  184. searchVal={{ ...state.searchs }}
  185. onStartSearch={(val: any) => {
  186. state.pageInfo.page = 1
  187. startSearch(val)
  188. }}
  189. ></searchInput>
  190. <div class={styles.hotSearch}>
  191. <hotSearch
  192. onSearchRust={(val: any) => searchRust(val)}
  193. onHotTag={(val: string) => {
  194. state.searchs.search = val
  195. getMusicList()
  196. }}
  197. type={''}
  198. isChiose={true}
  199. ></hotSearch>
  200. </div>
  201. {state.musicList && state.musicList.length > 0 && (
  202. <>
  203. <div
  204. class={[styles.section, styles.pb40]}
  205. style="padding-top: 0"
  206. >
  207. <div class={styles.musicList}>
  208. {state.musicList.map(item => {
  209. return <musicLIstItem item={item}></musicLIstItem>
  210. })}
  211. </div>
  212. </div>
  213. </>
  214. )}
  215. {state.isshowData && <ColEmpty></ColEmpty>}
  216. <pagination
  217. total={state.pageInfo.total}
  218. v-model:page={state.pageInfo.page}
  219. v-model:limit={state.pageInfo.limit}
  220. pageSizes={state.pageInfo.page_size}
  221. pagination={getMusicList}
  222. />
  223. </div>
  224. </div>
  225. </div>
  226. <silder></silder>
  227. </div>
  228. )
  229. }
  230. })