music-list.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import OEmpty from '@/components/o-empty'
  2. import { postMessage } from '@/helpers/native-message'
  3. import request from '@/helpers/request'
  4. import { browser } from '@/helpers/utils'
  5. import { state } from '@/state'
  6. import { useRect } from '@vant/use'
  7. import {
  8. Cell,
  9. CellGroup,
  10. DropdownItem,
  11. DropdownMenu,
  12. Icon,
  13. List,
  14. Popover,
  15. PullRefresh,
  16. Search,
  17. Sticky
  18. } from 'vant'
  19. import { defineComponent, reactive, ref, onMounted, nextTick, computed } from 'vue'
  20. import { useRoute, useRouter } from 'vue-router'
  21. import { getImage } from './images'
  22. import styles from './index.module.less'
  23. export default defineComponent({
  24. name: 'accompany-music-list',
  25. props: {
  26. musicTree: {
  27. type: Array,
  28. default: () => []
  29. }
  30. },
  31. setup(props, ctx) {
  32. const route = useRoute()
  33. const imgDefault = getImage('icon-music.svg')
  34. const data = reactive({
  35. loading: true,
  36. finished: false,
  37. refreshing: false,
  38. pagenation: {
  39. page: 1,
  40. rows: 20
  41. },
  42. value1: null,
  43. value2: null,
  44. PopoverOpen: false,
  45. list: [] as any,
  46. keyword: ''
  47. })
  48. const option1 = computed(() => {
  49. const v1: any = props.musicTree.find((n: any) => n.id == route.query.categorieid)
  50. // console.log('🚀 ~ v1', v1)
  51. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  52. const list = v1.musicSheetCategoriesList.map((m: any) => {
  53. if (!data.value1) {
  54. data.value1 = m.id
  55. data.value2 = null
  56. }
  57. return {
  58. text: m.name,
  59. value: m.id
  60. }
  61. })
  62. return list
  63. }
  64. return []
  65. })
  66. const option2 = computed(() => {
  67. const v1: any = props.musicTree.find((n: any) => n.id == route.query.categorieid)
  68. // console.log('🚀 ~ v1', v1)
  69. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  70. const v2: any = v1.musicSheetCategoriesList.find((n: any) => n.id == data.value1)
  71. if (Array.isArray(v2?.musicSheetCategoriesList)) {
  72. const list = [{ text: '全部', value: null }].concat(
  73. v2.musicSheetCategoriesList.map((m: any) => {
  74. return {
  75. text: m.name,
  76. value: m.id
  77. }
  78. })
  79. )
  80. return list
  81. }
  82. }
  83. return [{ text: '全部', value: null }]
  84. })
  85. const getList = async () => {
  86. try {
  87. const res: any = await request.post(state.platformApi + '/musicSheet/page', {
  88. data: {
  89. ...data.pagenation,
  90. keyword: data.keyword
  91. // musicTag: data.value2 || data.value1
  92. }
  93. })
  94. if (Array.isArray(res?.data?.rows)) {
  95. data.list = [].concat(data.list, res.data.rows)
  96. data.pagenation.page += 1
  97. if (!res.data.rows.length) {
  98. data.finished = true
  99. }
  100. if (data.refreshing) {
  101. data.refreshing = false
  102. }
  103. } else {
  104. data.finished = true
  105. }
  106. } catch (error) {}
  107. nextTick(() => {
  108. data.loading = false
  109. })
  110. }
  111. const onRefresh = () => {
  112. console.log('下拉刷新')
  113. // 清空列表数据
  114. data.pagenation.page = 1
  115. data.finished = false
  116. data.loading = false
  117. data.list = []
  118. // 重新加载数据
  119. getList()
  120. }
  121. // 重置搜索
  122. const onSearch = () => {
  123. console.log(234)
  124. data.pagenation.page = 1
  125. data.finished = false
  126. data.loading = false
  127. data.list = []
  128. getList()
  129. }
  130. onMounted(() => {
  131. getList()
  132. })
  133. //进入云教练
  134. const openView = (item: any) => {
  135. let src = `${location.origin}/orchestra-music-score/?id=${item.id}`
  136. console.log("🚀 ~ 去云教练的src", src)
  137. postMessage({
  138. api: 'openAccompanyWebView',
  139. content: {
  140. url: src,
  141. orientation: 0,
  142. isHideTitle: true,
  143. statusBarTextColor: false,
  144. isOpenLight: true
  145. }
  146. })
  147. }
  148. const headeRef = ref()
  149. const headerData = reactive({
  150. height: 0
  151. })
  152. onMounted(() => {
  153. const rect = useRect(headeRef)
  154. headerData.height = rect.height
  155. })
  156. return () => (
  157. <div class={styles['accompany-music-list']}>
  158. <div class={styles.heade} ref={headeRef}>
  159. <DropdownMenu>
  160. <DropdownItem
  161. v-model:modelValue={data.value1}
  162. options={option1.value}
  163. onChange={() => onSearch()}
  164. ></DropdownItem>
  165. <DropdownItem
  166. v-model:modelValue={data.value2}
  167. options={option2.value as any}
  168. onChange={() => onSearch()}
  169. ></DropdownItem>
  170. </DropdownMenu>
  171. <div class={styles.filter}>
  172. <Search
  173. placeholder="请输入搜索关键词"
  174. background="#F8F8F8"
  175. shape="round"
  176. showAction={true}
  177. v-model:modelValue={data.keyword}
  178. >
  179. {{
  180. // label: () => (
  181. // <Popover
  182. // v-model:show={data.PopoverOpen}
  183. // actions={actions}
  184. // placement="bottom-start"
  185. // >
  186. // {{
  187. // reference: () => (
  188. // <div>
  189. // 长笛 <Icon name="arrow" />
  190. // </div>
  191. // )
  192. // }}
  193. // </Popover>
  194. // ),
  195. action: () => (
  196. <div class={styles.searchBtn} onClick={() => onSearch()}>
  197. 搜索
  198. </div>
  199. )
  200. }}
  201. </Search>
  202. </div>
  203. </div>
  204. {headerData.height && <div style={{height: headerData.height + 'px'}}></div>}
  205. <Cell
  206. center
  207. title="胜强测试"
  208. isLink
  209. onClick={() => {
  210. let src = `http://192.168.3.114:3000/orchestra-music-score/?id=1603573996544364546`
  211. console.log("🚀 ~ 去云教练的src", src)
  212. if (browser().isApp) {
  213. postMessage({
  214. api: 'openAccompanyWebView',
  215. content: {
  216. url: src,
  217. orientation: 0,
  218. isHideTitle: true,
  219. statusBarTextColor: false,
  220. isOpenLight: true
  221. }
  222. })
  223. } else {
  224. location.href = src
  225. }
  226. }}
  227. ></Cell>
  228. <PullRefresh v-model:modelValue={data.refreshing} onRefresh={onRefresh}>
  229. <List
  230. immediateCheck={false}
  231. v-model:loading={data.loading}
  232. v-model:finished={data.finished}
  233. finishedText="没有更多了"
  234. onLoad={() => {
  235. getList()
  236. }}
  237. >
  238. <CellGroup inset>
  239. {data.list.map((item: any) => {
  240. return (
  241. <Cell center title={item.musicSheetName} isLink onClick={() => openView(item)}>
  242. {{
  243. icon: () => (
  244. <Icon style={{ marginRight: '12px' }} size={40} name={imgDefault} />
  245. )
  246. }}
  247. </Cell>
  248. )
  249. })}
  250. </CellGroup>
  251. </List>
  252. </PullRefresh>
  253. {!data.loading && !data.list.length && <OEmpty tips="空空如也" />}
  254. </div>
  255. )
  256. }
  257. })