|
@@ -8,7 +8,7 @@ import {
|
|
|
import { defineComponent, nextTick, onMounted, reactive, ref, watch } from 'vue'
|
|
|
import mitt from 'eventemitter3'
|
|
|
import Search from '@/components/col-search'
|
|
|
-import { useLocalStorage } from '@vueuse/core'
|
|
|
+import { useLocalStorage, useThrottleFn } from '@vueuse/core'
|
|
|
import styles from './index.module.less'
|
|
|
import classNames from 'classnames'
|
|
|
import { getRandomKey } from '../music'
|
|
@@ -17,12 +17,35 @@ import { SubjectEnum, useSubjectId } from '@/helpers/hooks'
|
|
|
import { state } from '@/state'
|
|
|
import TheSticky from '@/components/the-sticky'
|
|
|
import bgImg from '../../images/bg-image-search.png'
|
|
|
+import iconSearch from './icon-search.png'
|
|
|
import request from '@/helpers/request'
|
|
|
+import { browser } from '@/helpers/utils'
|
|
|
+import ColHeader from '@/components/col-header'
|
|
|
+import ColResult from '@/components/col-result'
|
|
|
+import { postMessage } from '@/helpers/native-message'
|
|
|
|
|
|
export const mitter = new mitt()
|
|
|
|
|
|
const selectTagRef = ref()
|
|
|
|
|
|
+export const openWebViewOrWeb = (url: string, callback: any) => {
|
|
|
+ if (browser().isApp) {
|
|
|
+ postMessage({
|
|
|
+ api: 'openWebView',
|
|
|
+ content: {
|
|
|
+ url: url, //`${location.origin}/tenant/#/music-album-detail/${item.id}`,
|
|
|
+ orientation: 1,
|
|
|
+ isHideTitle: false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // router.push({
|
|
|
+ // path: '/music-album-detail/' + item.id
|
|
|
+ // })
|
|
|
+ callback && callback()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
export default defineComponent({
|
|
|
name: 'MusicSearchHeader',
|
|
|
setup() {
|
|
@@ -57,7 +80,13 @@ export default defineComponent({
|
|
|
const words = useLocalStorage<string[]>('music-search', [])
|
|
|
const activeTab = ref('all')
|
|
|
|
|
|
- onBeforeRouteUpdate(() => {
|
|
|
+ if (route.path === '/music-songbook/result') {
|
|
|
+ keyword.value = route.query.search as string
|
|
|
+ tagids.value = ''
|
|
|
+ activeTab.value = 'all'
|
|
|
+ }
|
|
|
+
|
|
|
+ onBeforeRouteUpdate((to, form) => {
|
|
|
const getSubject: any = useSubjectId(SubjectEnum.SEARCH)
|
|
|
subject.name = getSubject.name || '全部声部'
|
|
|
subject.id = getSubject.id
|
|
@@ -71,6 +100,12 @@ export default defineComponent({
|
|
|
console.log(error)
|
|
|
}
|
|
|
}
|
|
|
+ if (to.path === '/music-songbook/result') {
|
|
|
+ keyword.value = to.query.search as string
|
|
|
+ console.log(keyword.value, 'value', route.query)
|
|
|
+ tagids.value = ''
|
|
|
+ activeTab.value = 'all'
|
|
|
+ }
|
|
|
return true
|
|
|
})
|
|
|
|
|
@@ -78,7 +113,33 @@ export default defineComponent({
|
|
|
mitter.emit('changeTab', val)
|
|
|
})
|
|
|
|
|
|
+ // 输入时搜索
|
|
|
+ const searchList = ref<any>([])
|
|
|
+ const onInputSearch = useThrottleFn(async (val: any) => {
|
|
|
+ try {
|
|
|
+ const { data } = await request.post('/api-student/music/sheet/search', {
|
|
|
+ hideLoading: true,
|
|
|
+ data: {
|
|
|
+ subjectId: subjects.id,
|
|
|
+ name: val,
|
|
|
+ rows: 10
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const tempMusics = data.musicNames || []
|
|
|
+ tempMusics.forEach((item: any, index: number) => {
|
|
|
+ if (index < 10) {
|
|
|
+ item.name = item.name.replace(val, `<span>${val}</span>`)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ searchList.value = tempMusics
|
|
|
+ searchResultStatus.value = keyword.value ? true : false
|
|
|
+ } catch {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }, 300)
|
|
|
+
|
|
|
const onSearch = val => {
|
|
|
+ console.log('object :>> ', val)
|
|
|
keyword.value = val
|
|
|
const indexOf = words.value.indexOf(val)
|
|
|
if (indexOf > -1) {
|
|
@@ -88,24 +149,21 @@ export default defineComponent({
|
|
|
words.value.unshift(val)
|
|
|
// console.log(words.value.length, 'words.value.length')
|
|
|
words.value.length = Math.min(words.value.length, 10)
|
|
|
- defaultClose()
|
|
|
+ if (route.path === '/music-songbook/search') defaultClose()
|
|
|
}
|
|
|
- mitter.emit('search', val)
|
|
|
- }
|
|
|
-
|
|
|
- // 输入时搜索
|
|
|
- const onInputSearch = async (val: any) => {
|
|
|
- console.log('测试', val)
|
|
|
- try {
|
|
|
- const { data } = await request.post('/api-student/music/sheet/search', {
|
|
|
- data: {
|
|
|
- subjectId: subjects.id,
|
|
|
- name: val
|
|
|
+ // mitter.emit('search', val)
|
|
|
+ if (route.path !== '/music-songbook/result') {
|
|
|
+ router.replace({
|
|
|
+ path: '/music-songbook/result',
|
|
|
+ query: {
|
|
|
+ search: val
|
|
|
}
|
|
|
})
|
|
|
- console.log(data, 'val')
|
|
|
- } catch {
|
|
|
- //
|
|
|
+ searchResultStatus.value = false
|
|
|
+ searchList.value = []
|
|
|
+ } else {
|
|
|
+ searchResultStatus.value = false
|
|
|
+ mitter.emit('search', val)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -175,20 +233,33 @@ export default defineComponent({
|
|
|
})
|
|
|
}
|
|
|
// 首先调用默认收起的方法
|
|
|
- defaultClose()
|
|
|
+ if (route.path === '/music-songbook/search') defaultClose()
|
|
|
|
|
|
return () => {
|
|
|
return (
|
|
|
<div class={styles.search}>
|
|
|
<div class={styles.sticky}>
|
|
|
<TheSticky position="top">
|
|
|
+ <ColHeader isFixed={false} background="transparent" title=" " />
|
|
|
<Search
|
|
|
modelValue={keyword.value}
|
|
|
background="transparent"
|
|
|
onInput={(val: any) => {
|
|
|
- onInputSearch(val)
|
|
|
+ keyword.value = val
|
|
|
+ if (val) {
|
|
|
+ onInputSearch(val)
|
|
|
+ } else {
|
|
|
+ searchList.value = []
|
|
|
+ searchResultStatus.value = false
|
|
|
+ if (route.path === '/music-songbook/result') {
|
|
|
+ router.replace('/music-songbook/search')
|
|
|
+ }
|
|
|
+ }
|
|
|
}}
|
|
|
onSearch={(val: any) => {
|
|
|
+ if (!val) return
|
|
|
+ keyword.value = val
|
|
|
+ console.log(val, 'val')
|
|
|
onSearch(val)
|
|
|
// searchResultStatus.value = true
|
|
|
}}
|
|
@@ -210,19 +281,22 @@ export default defineComponent({
|
|
|
)
|
|
|
}}
|
|
|
/>
|
|
|
- {/* {route.path === '/music-songbook/search' && (
|
|
|
- <Tabs
|
|
|
- color="var(--van-primary)"
|
|
|
- background="transparent"
|
|
|
- lineWidth={20}
|
|
|
- shrink
|
|
|
- v-model:active={activeTab.value}
|
|
|
- onChange={val => (activeTab.value = val)}
|
|
|
- >
|
|
|
- <Tab title="单曲" name="songe"></Tab>
|
|
|
- <Tab title="专辑" name="album"></Tab>
|
|
|
- </Tabs>
|
|
|
- )} */}
|
|
|
+ {route.path === '/music-songbook/result' &&
|
|
|
+ !searchResultStatus.value && (
|
|
|
+ <Tabs
|
|
|
+ color="var(--van-primary)"
|
|
|
+ background="transparent"
|
|
|
+ lineWidth={20}
|
|
|
+ shrink
|
|
|
+ class={styles.tagTabs}
|
|
|
+ v-model:active={activeTab.value}
|
|
|
+ onChange={val => (activeTab.value = val)}
|
|
|
+ >
|
|
|
+ <Tab title="综合" name="all"></Tab>
|
|
|
+ <Tab title="单曲" name="songe"></Tab>
|
|
|
+ <Tab title="专辑" name="album"></Tab>
|
|
|
+ </Tabs>
|
|
|
+ )}
|
|
|
</TheSticky>
|
|
|
<img class={styles.bgImg} src={bgImg} />
|
|
|
</div>
|
|
@@ -244,7 +318,10 @@ export default defineComponent({
|
|
|
round
|
|
|
class={[styles.searchKeyword, 'van-ellipsis']}
|
|
|
key={item}
|
|
|
- onClick={() => onSearch(item)}
|
|
|
+ onClick={() => {
|
|
|
+ keyword.value = item
|
|
|
+ onSearch(item)
|
|
|
+ }}
|
|
|
>
|
|
|
{item}
|
|
|
</Tag>
|
|
@@ -303,15 +380,44 @@ export default defineComponent({
|
|
|
class={[styles.searchResult]}
|
|
|
style={{ display: searchResultStatus.value ? 'block' : 'none' }}
|
|
|
>
|
|
|
- {/* <Popup
|
|
|
- v-model:show={searchResultStatus.value}
|
|
|
- position="top"
|
|
|
- teleport={document.querySelector('#searchHeader')}
|
|
|
- zIndex={99}
|
|
|
- overlay={false}
|
|
|
- >
|
|
|
- <>1212121212121212</>
|
|
|
- </Popup> */}
|
|
|
+ <div class={styles.searchGroups}>
|
|
|
+ {searchList.value.map((item: any) => (
|
|
|
+ <div
|
|
|
+ class={styles.searchItem}
|
|
|
+ onClick={() => {
|
|
|
+ if (item.type === 'ALBUM') {
|
|
|
+ openWebViewOrWeb(
|
|
|
+ `${location.origin}/tenant/#/music-album-detail/${item.id}`,
|
|
|
+ () => {
|
|
|
+ router.push({
|
|
|
+ path: '/music-album-detail/' + item.id
|
|
|
+ })
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ openWebViewOrWeb(
|
|
|
+ `${location.origin}/tenant/#/music-detail?id=${item.id}`,
|
|
|
+ () => {
|
|
|
+ router.push({
|
|
|
+ path: '/music-detail',
|
|
|
+ query: {
|
|
|
+ id: item.id
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <img src={iconSearch} class={styles.iconSearch} />
|
|
|
+ <span class={styles.rName} v-html={item.name}></span>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
+
|
|
|
+ {searchList.value.length <= 0 && (
|
|
|
+ <ColResult tips="暂无搜索结果" btnStatus={false} />
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|