music-list.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 OFullRefresh from '@/components/o-full-refresh'
  8. import {
  9. Cell,
  10. CellGroup,
  11. DropdownItem,
  12. DropdownMenu,
  13. Icon,
  14. List,
  15. Popover,
  16. PullRefresh,
  17. Search,
  18. Sticky
  19. } from 'vant'
  20. import { defineComponent, reactive, ref, onMounted, nextTick, computed } from 'vue'
  21. import { useRoute, useRouter } from 'vue-router'
  22. import { getImage } from './images'
  23. import styles from './index.module.less'
  24. export default defineComponent({
  25. name: 'accompany-music-list',
  26. props: {
  27. musicTree: {
  28. type: Array,
  29. default: () => []
  30. }
  31. },
  32. setup(props, ctx) {
  33. const route = useRoute()
  34. const imgDefault = getImage('icon-music.svg')
  35. const data = reactive({
  36. loading: true,
  37. finished: false,
  38. refreshing: false,
  39. pagenation: {
  40. page: 1,
  41. rows: 20
  42. },
  43. value1: null,
  44. value2: null,
  45. PopoverOpen: false,
  46. list: [] as any,
  47. keyword: ''
  48. })
  49. const option1 = computed(() => {
  50. const v1: any = props.musicTree.find((n: any) => n.id == route.query.categorieid)
  51. // console.log('🚀 ~ v1', v1)
  52. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  53. const list = v1.musicSheetCategoriesList.map((m: any) => {
  54. if (!data.value1) {
  55. data.value1 = m.id
  56. data.value2 = null
  57. }
  58. return {
  59. text: m.name,
  60. value: m.id
  61. }
  62. })
  63. return list
  64. }
  65. return []
  66. })
  67. const option2 = computed(() => {
  68. const v1: any = props.musicTree.find((n: any) => n.id == route.query.categorieid)
  69. // console.log('🚀 ~ v1', v1)
  70. if (Array.isArray(v1?.musicSheetCategoriesList)) {
  71. const v2: any = v1.musicSheetCategoriesList.find((n: any) => n.id == data.value1)
  72. if (Array.isArray(v2?.musicSheetCategoriesList)) {
  73. const list = [{ text: '全部', value: null }].concat(
  74. v2.musicSheetCategoriesList.map((m: any) => {
  75. return {
  76. text: m.name,
  77. value: m.id
  78. }
  79. })
  80. )
  81. return list
  82. }
  83. }
  84. return [{ text: '全部', value: null }]
  85. })
  86. const getList = async () => {
  87. try {
  88. const res: any = await request.post(state.platformApi + '/musicSheet/page', {
  89. data: {
  90. ...data.pagenation,
  91. keyword: data.keyword
  92. // musicTag: data.value2 || data.value1
  93. }
  94. })
  95. if (Array.isArray(res?.data?.rows)) {
  96. data.list = [].concat(data.list, res.data.rows)
  97. data.pagenation.page += 1
  98. if (!res.data.rows.length) {
  99. data.finished = true
  100. }
  101. if (data.refreshing) {
  102. data.refreshing = false
  103. }
  104. } else {
  105. data.finished = true
  106. }
  107. } catch (error) {}
  108. nextTick(() => {
  109. data.loading = false
  110. })
  111. }
  112. const onRefresh = () => {
  113. console.log('下拉刷新')
  114. // 清空列表数据
  115. data.pagenation.page = 1
  116. data.finished = false
  117. data.loading = false
  118. data.list = []
  119. // 重新加载数据
  120. getList()
  121. }
  122. // 重置搜索
  123. const onSearch = () => {
  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. <OFullRefresh
  229. v-model:modelValue={data.refreshing}
  230. onRefresh={onRefresh}
  231. style="min-height: 100vh;"
  232. >
  233. <List
  234. loading-text=" "
  235. immediateCheck={false}
  236. v-model:loading={data.loading}
  237. v-model:finished={data.finished}
  238. finishedText="没有更多了"
  239. onLoad={() => {
  240. getList()
  241. }}
  242. >
  243. <CellGroup inset>
  244. {data.list.map((item: any) => {
  245. return (
  246. <Cell size="large" center title={item.musicSheetName} isLink onClick={() => openView(item)}>
  247. {{
  248. icon: () => (
  249. <Icon style={{ marginRight: '12px' }} size={40} name={imgDefault} />
  250. )
  251. }}
  252. </Cell>
  253. )
  254. })}
  255. </CellGroup>
  256. </List>
  257. </OFullRefresh>
  258. {!data.loading && !data.list.length && <OEmpty tips="空空如也" />}
  259. </div>
  260. )
  261. }
  262. })