Skip to content

Commit

Permalink
refactor: restructuring
Browse files Browse the repository at this point in the history
Use the interface file under pages to export the declaration and enum of each module
  • Loading branch information
Linkontoask committed Dec 24, 2020
1 parent 4d4be75 commit 5ed44c9
Show file tree
Hide file tree
Showing 70 changed files with 618 additions and 452 deletions.
6 changes: 3 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get } from '@/utils/http'
import { SongsDetail, SongInteface, Albums } from '@/interface/index'
import { SongsDetail, SongState, Albums } from '@/interface/index'

export const getSongUrl = async <T>(id: number | number[]): Promise<T> => {
const data = await get<{ data: T }>('/api/song/url', {
Expand All @@ -22,8 +22,8 @@ export const getSongDetail = async (

export const getPlayList = async (
id: number
): Promise<SongInteface.SongState['playlist']> => {
const data = await get<{ playlist: SongInteface.SongState['playlist'] }>(
): Promise<SongState['playlist']> => {
const data = await get<{ playlist: SongState['playlist'] }>(
'/api/playlist/detail',
{
id
Expand Down
15 changes: 15 additions & 0 deletions src/components-business/button/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.play-all {
display: flex;
align-items: center;
color: white;
background-color: var(--base-color);
span {
margin-left: 10px;
}
&:focus,
&:hover {
color: white;
background-color: var(--base-color-darken);
border-color: var(--base-color);
}
}
31 changes: 31 additions & 0 deletions src/components-business/button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { defineComponent, PropType } from 'vue'
import { Button } from 'ant-design-vue'
import { noop } from '@/utils'
import './index.less'

export const PlayAll = defineComponent({
name: 'PlayAll',
props: {
onClick: {
type: Function as PropType<() => void>,
default: noop
}
},
emits: ['click'],
setup(props, { emit }) {
return () => (
<Button
class="play-all"
shape="round"
v-slots={{
icon: () => <icon icon="play-copy" size={18} />
}}
onClick={() => {
emit('click')
}}
>
播放全部
</Button>
)
}
})
14 changes: 0 additions & 14 deletions src/components-business/secondary-list/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,6 @@
display: flex;
align-items: center;
margin-bottom: 10px;
.play-all {
display: flex;
align-items: center;
color: white;
background-color: var(--base-color);
span {
margin-left: 10px;
}
&:focus,
&:hover {
color: white;
border-color: var(--base-color);
}
}
button {
margin-right: 10px;
}
Expand Down
37 changes: 13 additions & 24 deletions src/components-business/secondary-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { Secondary } from '@/layout/secondary/secondary'
import { MoreThen } from '@/components/more-then/index'
import { Table } from '@/components-business/table'
import { FormatSource, ListFormat, SongsBase } from '@/interface/index'
import { formatTime, noop, download } from '@/utils/index'
import { formatTime, noop } from '@/utils/index'
import { getSongUrl } from '@/api/index'
import { RouterLink, useRouter } from 'vue-router'
import { Button } from 'ant-design-vue'
import { instance } from '@/components-business/fly/index'
import { uesModuleStore } from '@/hooks/index'
import { FooterInteface } from '@/pages/index'
import {
useDownloadModule,
DownloadActions,
useFooterModule,
FooterMutations
} from '@/modules/index'
import { DailyCard } from '@/components-business/song-list/daily'
import { PlayAll } from '@/components-business/button'
import dayjs from 'dayjs'
import './index.less'

Expand All @@ -27,9 +32,8 @@ const columns = [
align: 'center',
customRender: ({ text }: { text: ListFormat }) => {
const add = ref()
const { useState, useMutations } = uesModuleStore<
FooterInteface.FooterState
>('Footer')
const { useMutations } = useDownloadModule()
const { useState } = useFooterModule()
const state = useState()
return (
<div class="vh-center">
Expand All @@ -39,8 +43,7 @@ const columns = [
<ve-button
type="text"
onClick={async () => {
const url = await getSongUrl<SongsBase[]>(text.id)
download(url[0].url, text.name)
useMutations(DownloadActions.DOWNLOAD_MUSIC, text)
}}
>
<icon icon="icondownload" className="gay" size={22} />
Expand All @@ -67,10 +70,7 @@ const columns = [
url: data[0].url,
type: 'stack'
}
useMutations(
FooterInteface.FooterMutations.SET_PLAYLIST_TO_STACK,
[music]
)
useMutations(FooterMutations.SET_PLAYLIST_TO_STACK, [music])
}
}
}}
Expand Down Expand Up @@ -186,18 +186,7 @@ export const SecondaryList = defineComponent({
</i>
</div>
<div class="a-command-contanier">
<Button
class="play-all"
shape="round"
v-slots={{
icon: () => <icon icon="play-copy" size={18} />
}}
onClick={() => {
emit('playAll')
}}
>
播放全部
</Button>
<PlayAll onClick={() => emit('playAll')} />
<Button shape="round">收藏</Button>
<Button shape="round">下载</Button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components-business/table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, PropType, toRefs } from 'vue'
import { SongInteface } from '@/interface/index'
import { SongsDetail } from '@/interface/index'
import { Table as ATable } from 'ant-design-vue'
import { noop } from '@/utils/index'
import './index.less'
Expand All @@ -22,7 +22,7 @@ export const Table = defineComponent({
default: true
},
onDblClick: {
type: Function as PropType<(item: SongInteface.Tracks) => void>,
type: Function as PropType<(item: SongsDetail) => void>,
default: noop
},
rowClassName: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/swiper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
toRefs,
PropType
} from 'vue'
import { FindMusicInteface } from '@/interface/index'
import { Banners } from '@/interface/index'
import classnames from 'classnames'
import { useInternal } from '@/hooks/index'
import { Image } from '@/components/image/index'
Expand All @@ -21,15 +21,15 @@ const prefix = 'swiper'
export const Swiper = defineComponent({
props: {
banners: {
type: Object as PropType<FindMusicInteface.Banners[]>,
type: Object as PropType<Banners[]>,
required: true
},
running: {
type: Boolean as PropType<boolean>,
default: false
},
onClick: {
type: Function as PropType<(item: FindMusicInteface.Banners) => void>,
type: Function as PropType<(item: Banners) => void>,
default: noop
}
},
Expand Down Expand Up @@ -105,7 +105,7 @@ export const Swiper = defineComponent({
current.value <= 0 ? banners.value.length - 1 : current.value - 1
}

const handleClick = (item: FindMusicInteface.Banners) => {
const handleClick = (item: Banners) => {
emit('click', item)
}

Expand Down
8 changes: 5 additions & 3 deletions src/electron/event/ipc-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const importIpc = () => {
}

export const importIpcOrigin = () => {
return import('electron').then(v => {
return v.ipcRenderer
})
return import('electron').then(v => v.ipcRenderer)
}

export const importShell = () => {
return import('electron').then(v => v.shell)
}
8 changes: 7 additions & 1 deletion src/electron/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function isElectron() {
import { App } from '../main'

export const isElectron = () => {
// Renderer process
if (
typeof window !== 'undefined' &&
Expand Down Expand Up @@ -28,3 +30,7 @@ export function isElectron() {

return false
}

export const getAppPath = () => {
return App.getAppPath() || __dirname || process.env.PORTABLE_EXECUTABLE_DIR
}
4 changes: 2 additions & 2 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AUTH_MUTATIONS } from './../pages/auth/sage'
import { AuthNameSpaced, HeaderNameSpaced } from '@/modules'
import store from '@/store'
import { Mutations as HEADER_MUTATIONS } from '@/pages/header/sage'
import { HeaderMutations } from '@/interface'

export const isLogin = () => store.getters['Auth/isLogin']

Expand All @@ -13,5 +13,5 @@ export const hideAuth = () => {
}

export const setThemeColor = (color: string) => {
store.commit(`${HeaderNameSpaced}/${HEADER_MUTATIONS.SET_THEME_COLOR}`, color)
store.commit(`${HeaderNameSpaced}/${HeaderMutations.SET_THEME_COLOR}`, color)
}
5 changes: 2 additions & 3 deletions src/interface/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentPublicInstance, App } from 'vue'
import { FooterInteface, FindMusicInteface } from '@/pages/index'
import { FooterMutations, RecommendMutations } from '@/modules/index'

export interface Music extends ComponentPublicInstance {
$app: App
Expand Down Expand Up @@ -40,5 +40,4 @@ export interface FormatSource extends GlobalBase {
list: ListFormat[]
}

export type AllMutations = FooterInteface.FooterMutations &
FindMusicInteface.RecommendMutations
export type AllMutations = FooterMutations & RecommendMutations
32 changes: 31 additions & 1 deletion src/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,34 @@ export * from './service/albums'
export * from './service/artists'
export * from './service/songs'
export * from './service/avatar'
export { FindMusicInteface, SongInteface } from '../pages/index'
export {
RecommendMutations,
RecommendState,
RecommendActions,
Banners,
SongState,
SongActions,
ArtistsActions,
ArtistsMutations,
ArtistsState,
Artist,
SongListActions,
SongListMutations,
Pagination,
SongListState,
Tags,
Catlists,
TopListActions,
TopListMutations,
TopListState,
HeaderState,
SearchSuggest,
HeaderActions,
HeaderMutations,
Top,
ArtistState,
ArtistActions,
ArtistMutations,
Album,
Desc
} from '../pages/index'
10 changes: 4 additions & 6 deletions src/layout/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Footer } from '@/pages/footer/view/index'
import { useDrag, uesModuleStore } from '@/hooks/index'
import { State, Size, NAMESPACED } from './module'
import { RecommendNameSpaced } from '@/modules/index'
import { FindMusicInteface } from '@/interface/index'
import { RecommendMutations, RecommendState } from '@/interface/index'
import { Platform } from '@/config/build'
import './container.less'

Expand All @@ -29,9 +29,7 @@ export const Container = defineComponent({
const target = ref()

const { useState } = uesModuleStore<State>(NAMESPACED)
const RecommendStore = uesModuleStore<FindMusicInteface.RecommendState>(
RecommendNameSpaced
)
const RecommendStore = uesModuleStore<RecommendState>(RecommendNameSpaced)

const { screenSize } = toRefs(useState())

Expand All @@ -57,14 +55,14 @@ export const Container = defineComponent({
startCB() {
draging.value = true
RecommendStore.useMutations(
FindMusicInteface.RecommendMutations.SET_SWIPER_RINNING,
RecommendMutations.SET_SWIPER_RINNING,
false
)
},
stopCB() {
draging.value = false
RecommendStore.useMutations(
FindMusicInteface.RecommendMutations.SET_SWIPER_RINNING,
RecommendMutations.SET_SWIPER_RINNING,
true
)
}
Expand Down
15 changes: 12 additions & 3 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ import {
import Layout, { NAMESPACED as LayoutNameSpaced } from '@/layout/module'
import Header, { NAMESPACED as HeaderNameSpaced } from '@/pages/header/module'
import Footer, {
NAMESPACED as FooterNameSpaced,
FooterNameSpaced,
useFooterModule
} from '@/pages/footer/module'
import Main, { NAMESPACED as MainNameSpaced } from '@/pages/main/module'
import Auth, { NAMESPACED as AuthNameSpaced } from '@/pages/auth/module'
import Song, { NAMESPACED as SongNameSpaced } from '@/pages/list/module'
import Artist, { NAMESPACED as ArtistNameSpaced } from '@/pages/artist/module'
import Download, {
DownloadNameSpaced,
useDownloadModule
} from '@/pages/download/module'

export * from '@/pages/footer/module'
export * from '@/pages/news/children/module'
export * from '@/pages/download/module'

export {
useFooterModule,
useDownloadModule,
LayoutNameSpaced,
RecommendNameSpaced,
SongListNameSpaced,
Expand All @@ -32,7 +39,8 @@ export {
FooterNameSpaced,
AuthNameSpaced,
SongNameSpaced,
ArtistNameSpaced
ArtistNameSpaced,
DownloadNameSpaced
}

const modules = {
Expand All @@ -46,7 +54,8 @@ const modules = {
[MainNameSpaced]: Main,
[AuthNameSpaced]: Auth,
[SongNameSpaced]: Song,
[ArtistNameSpaced]: Artist
[ArtistNameSpaced]: Artist,
[DownloadNameSpaced]: Download
}

export default modules
Loading

0 comments on commit 5ed44c9

Please sign in to comment.