music-list.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. const Authorization = sessionStorage.getItem('Authorization') || ''
  136. const dev = /(localhost|192)/.test(location.host)
  137. console.log(dev, 'https://ponline.colexiu.com')
  138. let src = `${
  139. dev ? `http://192.168.3.114:3000` : location.origin
  140. }/orchestra-music-score/#/?id=${item.id}&Authorization=${Authorization}`
  141. postMessage({
  142. api: 'openAccompanyWebView',
  143. content: {
  144. url: src,
  145. orientation: 0,
  146. isHideTitle: true,
  147. statusBarTextColor: false,
  148. isOpenLight: true
  149. }
  150. })
  151. }
  152. const headeRef = ref()
  153. const headerData = reactive({
  154. height: 0
  155. })
  156. onMounted(() => {
  157. const rect = useRect(headeRef)
  158. headerData.height = rect.height
  159. })
  160. return () => (
  161. <div class={styles['accompany-music-list']}>
  162. <div class={styles.heade} ref={headeRef}>
  163. <DropdownMenu>
  164. <DropdownItem
  165. v-model:modelValue={data.value1}
  166. options={option1.value}
  167. onChange={() => onSearch()}
  168. ></DropdownItem>
  169. <DropdownItem
  170. v-model:modelValue={data.value2}
  171. options={option2.value as any}
  172. onChange={() => onSearch()}
  173. ></DropdownItem>
  174. </DropdownMenu>
  175. <div class={styles.filter}>
  176. <Search
  177. placeholder="请输入搜索关键词"
  178. background="#F8F8F8"
  179. shape="round"
  180. showAction={true}
  181. v-model:modelValue={data.keyword}
  182. >
  183. {{
  184. // label: () => (
  185. // <Popover
  186. // v-model:show={data.PopoverOpen}
  187. // actions={actions}
  188. // placement="bottom-start"
  189. // >
  190. // {{
  191. // reference: () => (
  192. // <div>
  193. // 长笛 <Icon name="arrow" />
  194. // </div>
  195. // )
  196. // }}
  197. // </Popover>
  198. // ),
  199. action: () => (
  200. <div class={styles.searchBtn} onClick={() => onSearch()}>
  201. 搜索
  202. </div>
  203. )
  204. }}
  205. </Search>
  206. </div>
  207. </div>
  208. <Cell
  209. center
  210. title="无别(【冥加】会员,测试"
  211. isLink
  212. onClick={() => {
  213. const origin = /(localhost|192)/.test(location.host)
  214. ? 'http://192.168.3.114:3000'
  215. : location.origin
  216. let src = `${origin}/orchestra-music-score/?id=1603573996544364546&Authorization=${sessionStorage.getItem(
  217. 'Authorization'
  218. )}`
  219. if (browser().isApp) {
  220. postMessage({
  221. api: 'openAccompanyWebView',
  222. content: {
  223. url: src,
  224. orientation: 0,
  225. isHideTitle: true,
  226. statusBarTextColor: false,
  227. isOpenLight: true
  228. }
  229. })
  230. } else {
  231. location.href = src
  232. }
  233. }}
  234. ></Cell>
  235. <PullRefresh v-model:modelValue={data.refreshing} onRefresh={onRefresh}>
  236. <List
  237. immediateCheck={false}
  238. v-model:loading={data.loading}
  239. v-model:finished={data.finished}
  240. finishedText="没有更多了"
  241. onLoad={() => {
  242. getList()
  243. }}
  244. >
  245. <CellGroup inset>
  246. {data.list.map((item: any) => {
  247. return (
  248. <Cell center title={item.musicSheetName} isLink onClick={() => openView(item)}>
  249. {{
  250. icon: () => (
  251. <Icon style={{ marginRight: '12px' }} size={40} name={imgDefault} />
  252. )
  253. }}
  254. </Cell>
  255. )
  256. })}
  257. </CellGroup>
  258. </List>
  259. </PullRefresh>
  260. {!data.loading && !data.list.length && <OEmpty tips="空空如也" />}
  261. </div>
  262. )
  263. }
  264. })