Skip to content

Commit

Permalink
feat: search interface title correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkontoask committed Feb 10, 2021
1 parent bffc9d6 commit 28d3a2f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Artist, { ArtistNameSpaced } from '@/pages/artist/module'
import Download, { DownloadNameSpaced } from '@/pages/download/module'
import LocalMusic, { LocalMusicNameSpaced } from '@/pages/music/module'
import Setting, { SettingNameSpaced } from '@/pages/setting/module'
import Search, { SearchNameSpaced } from '@/pages/search/module'
import Layout, { LayoutNameSpaced } from '@/layout/module'

export * from '@/pages/footer/module'
Expand All @@ -28,6 +29,7 @@ export * from '@/pages/list/module'
export * from '@/pages/artist/module'
export * from '@/pages/music/module'
export * from '@/pages/setting/module'
export * from '@/pages/search/module'
export * from '@/layout/module'

export {
Expand All @@ -44,6 +46,7 @@ export {
DownloadNameSpaced,
LocalMusicNameSpaced,
SettingNameSpaced,
SearchNameSpaced,
LayoutNameSpaced
}

Expand All @@ -61,7 +64,8 @@ const modules = {
[ArtistNameSpaced]: Artist,
[DownloadNameSpaced]: Download,
[LocalMusicNameSpaced]: LocalMusic,
[SettingNameSpaced]: Setting
[SettingNameSpaced]: Setting,
[SearchNameSpaced]: Search
}

export default modules
14 changes: 13 additions & 1 deletion src/pages/search/children/song.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { Table } from '@/components-business/table/index'
import { effectWords } from '../logic/index'
import { search } from '@/api/search'
import { playMusic } from '@/shared/music-shared'
import { Pagination, SearchType, SearchSuggest, ArrayItem } from '@/interface'
import {
Pagination,
SearchType,
SearchSuggest,
ArrayItem,
SearchMutations
} from '@/interface'
import { useSearchModule } from '@/modules'

type Songs = SearchSuggest['songs']

Expand All @@ -17,6 +24,7 @@ export const SearchSong = defineComponent({
total: 0,
slice: 0
})
const { useMutations } = useSearchModule()

const updateList = async (words: string) => {
if (words) {
Expand All @@ -31,6 +39,10 @@ export const SearchSong = defineComponent({
}
})
pagination.total = result.songCount
useMutations(
SearchMutations.SET_SEARCH_TITLE,
`找到 ${pagination.total} 首歌曲`
)
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/pages/search/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export const enum SearchType {
}

export interface SearchState {
songs: SongsDetail
searchTitle: string
}

export const enum SearchActions {}
export const enum SearchMutations {}
export const enum SearchMutations {
SET_SEARCH_TITLE = 'SET_SEARCH_TITLE'
}
19 changes: 19 additions & 0 deletions src/pages/search/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { actions, mutations } from './sage'
import { state } from './state'
import { uesModuleStore } from '@/hooks/index'
import { SearchActions, SearchMutations, SearchState } from '@/interface'

export const SearchNameSpaced = 'Search'

export const useSearchModule = () => {
return uesModuleStore<SearchState, {}, SearchActions, SearchMutations>(
SearchNameSpaced
)
}

export default {
namespaced: true,
state,
actions,
mutations
}
11 changes: 11 additions & 0 deletions src/pages/search/sage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MutationTree, ActionTree } from 'vuex'
import { RootState } from '@/store/index'
import { SearchMutations, SearchState } from '@/interface'

export const actions: ActionTree<SearchState, RootState> = {}

export const mutations: MutationTree<SearchState> = {
[SearchMutations.SET_SEARCH_TITLE](state, txt) {
state.searchTitle = txt
}
}
5 changes: 5 additions & 0 deletions src/pages/search/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SearchState } from '@/interface/index'

export const state: SearchState = {
searchTitle: ''
}
6 changes: 5 additions & 1 deletion src/pages/search/view/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import {
renderNavList
} from '@/components-business/secondary-bar/index'
import './search.less'
import { useSearchModule } from '@/modules'

export const Search = defineComponent({
name: 'Search',
setup() {
const { useState } = useSearchModule()
const state = useState()

const nav = renderNavList(contentRouter, Search.name)

return () => (
<MusicLayout
v-slots={{
title: () => <div>找到 {} 首歌曲</div>,
title: () => <div>{state.searchTitle}</div>,
head: () => <SecondaryBar nav={nav} size="small" />,
body: () => <RouterView />
}}
Expand Down

0 comments on commit 28d3a2f

Please sign in to comment.