index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import { Sticky, Cell, Tag, Icon, Popup, Tabs, Tab } from 'vant'
  2. import { defineComponent, onMounted, ref } from 'vue'
  3. import Search from '@/components/col-search'
  4. import { useLocalStorage } from '@vueuse/core'
  5. import AlbumItem from '../album/item'
  6. import AlbumList from '../album'
  7. import MusicItem from '../list/item'
  8. import MusicList from '../list'
  9. import styles from './index.module.less'
  10. import classNames from 'classnames'
  11. import request from '@/helpers/request'
  12. import SelectTag from './select-tag'
  13. import ColResult from '@/components/col-result'
  14. export default defineComponent({
  15. name: 'MusicSearch',
  16. setup() {
  17. const loading = ref(false)
  18. const keyword = ref('')
  19. const tagids = ref('')
  20. const albumRows = ref([])
  21. const sheetRows = ref([])
  22. const tagVisibility = ref(false)
  23. const words = useLocalStorage<string[]>('music-search', [])
  24. const activeTab = ref('album')
  25. const FetchList = async () => {
  26. // loading.value = true
  27. // try {
  28. // const res = await request.post(
  29. // '/api-student/music/sheet/albumAndSheetList',
  30. // {
  31. // data: {
  32. // albumRow: 3,
  33. // sheetRow: 10,
  34. // search: keyword.value,
  35. // musicTagIds: tagids.value
  36. // }
  37. // }
  38. // )
  39. // albumRows.value = res.data.musicAlbumList.rows
  40. // sheetRows.value = res.data.musicSheetList.rows
  41. // } catch (error) {}
  42. // loading.value = false
  43. }
  44. const onSearch = val => {
  45. keyword.value = val
  46. const indexOf = words.value.indexOf(val)
  47. if (indexOf > -1) {
  48. words.value.splice(indexOf, 1)
  49. }
  50. if (val) {
  51. words.value.unshift(val)
  52. words.value.length = Math.min(words.value.length, 5)
  53. }
  54. const activeRef = activeTab.value === 'album' ? albumList : musicList
  55. ;(activeRef.value as any).onSearch?.(val)
  56. // FetchList()
  57. }
  58. const onComfirm = tags => {
  59. const data = Object.values(tags).flat().filter(Boolean).join(',')
  60. tagids.value = data
  61. // FetchList()
  62. const activeRef = activeTab.value === 'album' ? albumList : musicList
  63. ;(activeRef.value as any).onComfirm?.(tags)
  64. tagVisibility.value = false
  65. }
  66. const albumList = ref(null)
  67. const musicList = ref(null)
  68. onMounted(() => {
  69. const activeRef = activeTab.value === 'album' ? albumList : musicList
  70. ;(activeRef.value as any).onSearch?.('')
  71. })
  72. return () => {
  73. return (
  74. <div class={styles.search}>
  75. <Sticky class={styles.sticky}>
  76. <Search
  77. modelValue={keyword.value}
  78. showAction
  79. autofocus
  80. onSearch={onSearch}
  81. onFilter={() => (tagVisibility.value = true)}
  82. filterDot={!!tagids.value}
  83. />
  84. <Tabs
  85. color="var(--van-primary)"
  86. background="transparent"
  87. lineWidth={20}
  88. shrink
  89. v-model:active={activeTab.value}
  90. onChange={val => (activeTab.value = val)}
  91. >
  92. <Tab title="专辑" name="album"></Tab>
  93. <Tab title="单曲" name="songe"></Tab>
  94. </Tabs>
  95. </Sticky>
  96. {words.value.length > 0 && (
  97. <div class={classNames(styles.keywords, 'van-hairline--bottom')}>
  98. <div class={styles.content}>
  99. {words.value.map(item => (
  100. <Tag
  101. round
  102. class={styles.searchKeyword}
  103. key={item}
  104. onClick={() => onSearch(item)}
  105. >
  106. {item}
  107. </Tag>
  108. ))}
  109. </div>
  110. <Icon
  111. class={styles.remove}
  112. name="delete-o"
  113. onClick={() => (words.value = [])}
  114. />
  115. </div>
  116. )}
  117. {/* {albumRows.value.length > 0 && (
  118. <>
  119. <Cell
  120. class={styles.title}
  121. title="专辑"
  122. is-link
  123. to={{
  124. path: '/music-album',
  125. query: {
  126. search: keyword.value,
  127. tagids: tagids.value
  128. }
  129. }}
  130. value="更多"
  131. />
  132. {albumRows.value.map(item => (
  133. <AlbumItem data={item} />
  134. ))}
  135. </>
  136. )} */}
  137. {/* <Cell
  138. class={styles.title}
  139. title="曲谱"
  140. is-link
  141. to={{
  142. path: '/music-list',
  143. query: {
  144. search: keyword.value,
  145. tagids: tagids.value
  146. }
  147. }}
  148. value="更多"
  149. /> */}
  150. {activeTab.value === 'album' ? (
  151. <AlbumList
  152. hideSearch
  153. ref={albumList}
  154. defauleParams={{
  155. search: keyword.value,
  156. tagids: tagids.value
  157. }}
  158. />
  159. ) : (
  160. <MusicList
  161. hideSearch
  162. ref={musicList}
  163. defauleParams={{
  164. search: keyword.value,
  165. tagids: tagids.value
  166. }}
  167. />
  168. )}
  169. {/* {sheetRows.value.map(item => (
  170. <MusicItem data={item} />
  171. ))} */}
  172. {/* {!loading.value && sheetRows.value.length === 0 && (
  173. <ColResult
  174. tips={activeTab.value === 'album' ? '暂无专辑' : '暂无曲目'}
  175. classImgSize="SMALL"
  176. btnStatus={false}
  177. />
  178. )} */}
  179. <Popup
  180. show={tagVisibility.value}
  181. round
  182. closeable
  183. position="bottom"
  184. style={{ height: '60%' }}
  185. teleport="body"
  186. onUpdate:show={val => (tagVisibility.value = val)}
  187. >
  188. <SelectTag onComfirm={onComfirm} onCancel={() => {}} />
  189. </Popup>
  190. </div>
  191. )
  192. }
  193. }
  194. })