index.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. import {
  2. computed,
  3. defineComponent,
  4. nextTick,
  5. onMounted,
  6. reactive,
  7. ref
  8. } from 'vue'
  9. import {
  10. List,
  11. DropdownMenu,
  12. DropdownItem,
  13. Tag,
  14. Image,
  15. Button,
  16. Cell,
  17. Radio,
  18. RadioGroup
  19. } from 'vant'
  20. import { postMessage } from '@/helpers/native-message'
  21. import Search from '@/components/col-search'
  22. import request from '@/helpers/request'
  23. import { useRoute, useRouter } from 'vue-router'
  24. import ColResult from '@/components/col-result'
  25. import styles from './index.module.less'
  26. import { getRandomKey } from '../music'
  27. import { openDefaultWebView, state as baseState, state } from '@/state'
  28. import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
  29. import Song from '../component/song'
  30. import ColHeader from '@/components/col-header'
  31. import bgImg from '../../images/bg.png'
  32. import TheSticky from '@/components/the-sticky'
  33. import dayjs from 'dayjs'
  34. import { browser, getHttpOrigin } from '@/helpers/utils'
  35. const noop = () => {
  36. //
  37. }
  38. export default defineComponent({
  39. name: 'MusicList',
  40. props: {
  41. teacherId: {
  42. type: String || Number,
  43. default: ''
  44. },
  45. myself: {
  46. type: Boolean,
  47. default: false
  48. }
  49. },
  50. setup({ onItemClick }, { expose }) {
  51. localStorage.setItem('behaviorId', getRandomKey())
  52. const route = useRoute()
  53. const router = useRouter()
  54. //
  55. const subjectType = route.query.subjectType || ''
  56. let title = ''
  57. if (subjectType === 'SUBJECT') {
  58. title = '基础云练'
  59. } else if (subjectType === 'MUSIC') {
  60. title = '独奏云练'
  61. } else if (subjectType === 'ENSEMBLE') {
  62. title = '合奏云练'
  63. }
  64. const params = reactive({
  65. keyword: (route.query.search as string) || '',
  66. subjectType: subjectType,
  67. page: 1,
  68. subjectId: null,
  69. albumId: route.query.albumId,
  70. albumName: '',
  71. level: '',
  72. type: '',
  73. title: title
  74. })
  75. const data = ref<any>(null)
  76. const loading = ref(false)
  77. const finished = ref(false)
  78. const isError = ref(false)
  79. const searchObj = ref<any>({})
  80. const searchRef = ref()
  81. const albumRef = ref()
  82. const albumRecord = ref<any>([])
  83. const apiSuffix = ref(
  84. baseState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  85. )
  86. const onSearch = (value: string) => {
  87. params.page = 1
  88. params.keyword = value
  89. data.value = null
  90. FetchList()
  91. }
  92. const FetchList = async () => {
  93. loading.value = true
  94. isError.value = false
  95. const tempParams = {
  96. ...params
  97. }
  98. try {
  99. const res = await request.post(
  100. `${apiSuffix.value}/tenantAlbumMusic/page`,
  101. {
  102. data: tempParams
  103. }
  104. )
  105. if (data.value?.rows?.length > 0 && res.data.pageNo === 1) {
  106. return
  107. }
  108. if (data.value) {
  109. const result = (data.value?.rows || []).concat(res.data.rows || [])
  110. data.value.rows = result
  111. }
  112. data.value = data.value || res.data
  113. params.page = res.data.pageNo + 1
  114. finished.value = res.data.pageNo >= res.data.totalPage
  115. } catch (error) {
  116. isError.value = true
  117. }
  118. loading.value = false
  119. }
  120. const getSelectCondition = async () => {
  121. const { data } = await request.post(
  122. `${apiSuffix.value}/tenantAlbumMusic/selectCondition`,
  123. {
  124. data: {
  125. subjectType: params.subjectType,
  126. tenantAlbumId: params.albumId
  127. }
  128. }
  129. )
  130. searchObj.value = data || {}
  131. }
  132. const getAlbumRecordPage = async () => {
  133. isError.value = false
  134. try {
  135. const { data } = await request.post('/userTenantAlbumRecord/list', {
  136. prefix:
  137. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
  138. data: {
  139. page: 1,
  140. rows: 999
  141. }
  142. })
  143. console.log(data)
  144. albumRecord.value = data || []
  145. if (albumRecord.value.length > 0) {
  146. const albumCatchType = localStorage.getItem(
  147. 'albumCatch' + subjectType
  148. )
  149. if (albumCatchType) {
  150. const item = albumRecord.value.find(
  151. (item: any) => item.tenantAlbumId == albumCatchType
  152. )
  153. if (item) {
  154. params.albumId = item.tenantAlbumId
  155. params.albumName = item.tenantAlbumName
  156. } else {
  157. params.albumId = albumRecord.value[0].tenantAlbumId
  158. params.albumName = albumRecord.value[0].tenantAlbumName
  159. }
  160. } else {
  161. params.albumId = albumRecord.value[0].tenantAlbumId
  162. params.albumName = albumRecord.value[0].tenantAlbumName
  163. }
  164. }
  165. } catch (error) {
  166. isError.value = true
  167. }
  168. }
  169. const isSearchStatus = computed(() => {
  170. const obj = searchObj.value
  171. let status = false
  172. if (obj.subjects && obj.subjects.length > 0) {
  173. status = true
  174. }
  175. if (obj.levelList && obj.levelList.length > 0) {
  176. status = true
  177. }
  178. if (obj.typeList && obj.typeList.length > 0) {
  179. status = true
  180. }
  181. return status
  182. })
  183. onMounted(async () => {
  184. // SUBJECT: '基础云练',
  185. // MUSIC: '独奏云练',
  186. // ENSEMBLE: '合奏云练'
  187. loading.value = true
  188. //await getAlbumRecordPage()
  189. await getSelectCondition()
  190. if (params.albumId) {
  191. await FetchList()
  192. } else {
  193. loading.value = false
  194. }
  195. })
  196. return () => {
  197. return (
  198. <>
  199. <div class={styles.sticky}>
  200. <TheSticky>
  201. <ColHeader
  202. hideHeader={false}
  203. background="transparent"
  204. isFixed={false}
  205. border={false}
  206. title={title}
  207. color="#131415"
  208. >
  209. {/* {{
  210. right: () =>
  211. albumRecord.value.length > 1 &&
  212. params.albumId && (
  213. <DropdownMenu class={styles.albumSearchSection}>
  214. <DropdownItem
  215. titleClass={styles.albumSearchTitle}
  216. title={params.albumName}
  217. ref={albumRef}
  218. >
  219. <div
  220. class={styles.albumSearchResult}
  221. style={{ maxHeight: '45vh', overflowY: 'auto' }}
  222. >
  223. {albumRecord.value.map((item: any) => (
  224. <Cell
  225. border={false}
  226. class={[
  227. styles.albumSearchCell,
  228. item.tenantAlbumId === params.albumId &&
  229. styles.albumSearchCellActive
  230. ]}
  231. center
  232. onClick={async () => {
  233. localStorage.setItem(
  234. 'albumCatch' + subjectType,
  235. item.tenantAlbumId
  236. )
  237. params.albumId = item.tenantAlbumId
  238. params.albumName = item.tenantAlbumName
  239. params.subjectId = null
  240. params.level = ''
  241. params.type = ''
  242. await getSelectCondition()
  243. params.page = 1
  244. data.value = null
  245. await FetchList()
  246. albumRef.value?.toggle()
  247. }}
  248. >
  249. {{
  250. icon: () => (
  251. <Image
  252. src={item.tenantAlbumCoverImg}
  253. class={styles.albumLogo}
  254. />
  255. ),
  256. title: () => (
  257. <div class={styles.albumContent}>
  258. <h2>{item.tenantAlbumName}</h2>
  259. <p>
  260. 到期时间:
  261. {dayjs(item.endTime).format(
  262. 'YYYY-MM-DD'
  263. )}
  264. </p>
  265. </div>
  266. ),
  267. 'right-icon': () => (
  268. <div class={styles.iconSelect}></div>
  269. )
  270. }}
  271. </Cell>
  272. ))}
  273. </div>
  274. </DropdownItem>
  275. </DropdownMenu>
  276. )
  277. }} */}
  278. </ColHeader>
  279. <Search
  280. placeholder={'请输入曲谱关键词'}
  281. class={styles.search}
  282. modelValue={params.keyword}
  283. onInput={(val: any) => {
  284. params.keyword = val
  285. }}
  286. onSearch={onSearch}
  287. type="tenant"
  288. background="transparent"
  289. inputBackground="transparent"
  290. // leftIcon={iconSearch}
  291. v-slots={{
  292. left: () =>
  293. isSearchStatus.value && (
  294. <DropdownMenu>
  295. <DropdownItem
  296. class="searchOther"
  297. // teleport="body"
  298. titleClass={
  299. params.subjectId || params.type || params.level
  300. ? styles.titleActive
  301. : ''
  302. }
  303. title="筛选"
  304. ref={searchRef}
  305. >
  306. <div
  307. class={styles.searchResult}
  308. style={{ maxHeight: '45vh', overflowY: 'auto' }}
  309. >
  310. {searchObj.value.subjects &&
  311. searchObj.value.subjects.length > 0 && (
  312. <>
  313. <div class={styles.searchTitle}>声部</div>
  314. <div
  315. class={[
  316. styles['radio-group'],
  317. styles.radio,
  318. styles['organ-radio']
  319. ]}
  320. >
  321. {searchObj.value.subjects.map(
  322. (subject: any) => {
  323. const isActive =
  324. subject.id === params.subjectId
  325. const type = isActive
  326. ? 'primary'
  327. : 'default'
  328. return (
  329. <Tag
  330. size="large"
  331. plain={isActive}
  332. type={type}
  333. round
  334. onClick={() => {
  335. params.subjectId = subject.id
  336. }}
  337. >
  338. {subject.name}
  339. </Tag>
  340. )
  341. }
  342. )}
  343. </div>
  344. </>
  345. )}
  346. {searchObj.value.levelList &&
  347. searchObj.value.levelList.length > 0 && (
  348. <>
  349. <div class={styles.searchTitle}>级别</div>
  350. <div
  351. class={[
  352. styles['radio-group'],
  353. styles.radio,
  354. styles['organ-radio']
  355. ]}
  356. >
  357. {searchObj.value.levelList.map(
  358. (subject: any) => {
  359. const isActive =
  360. subject.id === params.level
  361. const type = isActive
  362. ? 'primary'
  363. : 'default'
  364. return (
  365. <Tag
  366. size="large"
  367. plain={isActive}
  368. type={type}
  369. round
  370. onClick={() => {
  371. params.level = subject.id
  372. }}
  373. >
  374. {subject.value}
  375. </Tag>
  376. )
  377. }
  378. )}
  379. </div>
  380. </>
  381. )}
  382. {searchObj.value.typeList &&
  383. searchObj.value.typeList.length > 0 && (
  384. <>
  385. <div class={styles.searchTitle}>类型</div>
  386. <div
  387. class={[
  388. styles['radio-group'],
  389. styles.radio,
  390. styles['organ-radio']
  391. ]}
  392. >
  393. {searchObj.value.typeList.map(
  394. (subject: any) => {
  395. const isActive =
  396. subject.id === params.type
  397. const type = isActive
  398. ? 'primary'
  399. : 'default'
  400. return (
  401. <Tag
  402. size="large"
  403. plain={isActive}
  404. type={type}
  405. round
  406. onClick={() => {
  407. params.type = subject.id
  408. }}
  409. >
  410. {subject.value}
  411. </Tag>
  412. )
  413. }
  414. )}
  415. </div>
  416. </>
  417. )}
  418. </div>
  419. <div class={['btnGroup', 'btnMore']}>
  420. <Button
  421. class={styles.resetting}
  422. type="primary"
  423. plain
  424. round
  425. onClick={() => {
  426. params.subjectId = null
  427. params.level = ''
  428. params.type = ''
  429. }}
  430. >
  431. 重 置
  432. </Button>
  433. <Button
  434. class={styles.confirm}
  435. type="primary"
  436. color="linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%)"
  437. round
  438. block
  439. onClick={() => {
  440. params.page = 1
  441. data.value = null
  442. FetchList()
  443. searchRef.value?.toggle()
  444. }}
  445. >
  446. 确 认
  447. </Button>
  448. </div>
  449. </DropdownItem>
  450. </DropdownMenu>
  451. )
  452. }}
  453. />
  454. </TheSticky>
  455. <img class={styles.bgImg} src={bgImg} />
  456. </div>
  457. <div class={styles.alumnList}>
  458. <List
  459. loading={loading.value}
  460. finished={finished.value}
  461. finished-text={data.value && data.value.rows.length ? '' : ''}
  462. onLoad={FetchList}
  463. error={isError.value}
  464. immediateCheck={false}
  465. >
  466. {data.value && data.value.rows.length ? (
  467. <Song
  468. showTitleImg
  469. list={data.value.rows}
  470. onDetail={(item: any) => {
  471. if (browser().isApp) {
  472. const url = `${getHttpOrigin()}/tenant/#/music-detail?id=${item.id}&subjectType=${subjectType}&tenantAlbumId=${item.tenantAlbumId}`
  473. postMessage({
  474. api: 'openWebView',
  475. content: {
  476. url,
  477. orientation: 1,
  478. isHideTitle: false
  479. }
  480. })
  481. } else {
  482. router.push({
  483. path: '/music-detail',
  484. query: {
  485. subjectType,
  486. id: item.id,
  487. tenantAlbumId: item.tenantAlbumId
  488. }
  489. })
  490. }
  491. }}
  492. />
  493. ) : (
  494. !loading.value && (
  495. <ColResult
  496. tips="暂无曲目"
  497. classImgSize="CERT"
  498. btnStatus={false}
  499. />
  500. )
  501. )}
  502. </List>
  503. </div>
  504. </>
  505. )
  506. }
  507. }
  508. })