diff --git a/package.json b/package.json index 55cc77d7..400f44be 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "ts-loader": "^8.0.6", "typescript": "^4.0.3", "url-loader": "^4.1.1", - "v-easy-components": "2.0.0-beta.9", + "v-easy-components": "^2.0.0-beta.10", "vue-cli-plugin-electron-builder": "~2.0.0-rc.4" }, "gitHooks": { diff --git a/src/components/swiper/index.tsx b/src/components/swiper/index.tsx index 545f059a..8aab6ec0 100644 --- a/src/components/swiper/index.tsx +++ b/src/components/swiper/index.tsx @@ -8,7 +8,7 @@ import { } from 'vue' import { FindMusicInteface } from '@/interface/index' import classnames from 'classnames' -import { useInternal } from '@/utils/hook' +import { useInternal } from '@/hooks/index' import './index.less' const prefix = 'swiper' diff --git a/src/utils/hook.ts b/src/hooks/hook.ts similarity index 72% rename from src/utils/hook.ts rename to src/hooks/hook.ts index be36a58c..9020c465 100644 --- a/src/utils/hook.ts +++ b/src/hooks/hook.ts @@ -1,4 +1,5 @@ -import { on, off } from './index' +import { useStore } from 'vuex' +import { on, off } from '@/utils/index' interface InternalHook { startInternal: () => void @@ -27,24 +28,12 @@ export const useInternal = (ms: number, cb: () => void): InternalHook => { } } -export const dragHook = (container: HTMLElement, target: HTMLElement) => { - // const boxClient = { - // w: document.documentElement.offsetWidth, - // h: document.documentElement.offsetHeight - // } - +export const useDrag = (container: HTMLElement, target: HTMLElement) => { const cache = { x: 0, y: 0 } - // const containerClient = { - // grapX: container.offsetLeft, - // grapY: container.offsetTop, - // w: container.offsetWidth, - // h: container.offsetHeight - // } - let clickPosition: { x: number y: number @@ -81,15 +70,6 @@ export const dragHook = (container: HTMLElement, target: HTMLElement) => { requestAnimationFrame(() => { container.style.transform = `matrix(1, 0, 0, 1, ${left}, ${top}) translateZ(0)` }) - // if (left >= 0 && left + containerClient.w <= boxClient.w) { - - // } - // if (top >= 0 && top + containerClient.h <= boxClient.h) { - // requestAnimationFrame(() => { - // cache.y = top - // container.style.transform = `matrix(1, 0, 0, 1, ${cache.x}, ${cache.y})` - // }) - // } } } @@ -112,3 +92,21 @@ export const dragHook = (container: HTMLElement, target: HTMLElement) => { stop } } + +export function uesModuleStore(NAMESPACED: string) { + const store = useStore() + const useActions = (type: string, payload: string) => { + return store.dispatch(NAMESPACED + '/' + type, payload) + } + const useState = (): S => { + return store.state[NAMESPACED] + } + const useMutations = (type: string, payload: string): void => { + store.commit(NAMESPACED + '/' + type, payload) + } + return { + useActions: useActions, + useMutations: useMutations, + useState: useState + } +} diff --git a/src/hooks/index.tsx b/src/hooks/index.tsx index 9d45b1ea..a912c511 100644 --- a/src/hooks/index.tsx +++ b/src/hooks/index.tsx @@ -1,3 +1,4 @@ +export * from './hook' import { inject, provide } from 'vue' import { useRoute, useRouter } from 'vue-router' import { useStore } from 'vuex' diff --git a/src/layout/container.tsx b/src/layout/container.tsx index 8c759af7..3c119242 100644 --- a/src/layout/container.tsx +++ b/src/layout/container.tsx @@ -1,11 +1,18 @@ -import { defineComponent, nextTick, ComponentPublicInstance, ref } from 'vue' +import { + defineComponent, + nextTick, + ComponentPublicInstance, + ref, + toRefs, + onMounted, + watch +} from 'vue' import { Header } from '@/pages/header/view/index' import { Main } from '@/pages/main/view/index' import { Footer } from '@/pages/footer/view/index' -import { mapState } from './module' import { ENV } from '@/interface/app' -import { State, Size } from './state' -import { dragHook } from '@/utils/hook' +import { useDrag, uesModuleStore } from '@/hooks/index' +import { State, Size, NAMESPACED } from './module' import './container.less' const { VUE_APP_PLATFORM } = window as ENV @@ -13,49 +20,45 @@ const { VUE_APP_PLATFORM } = window as ENV export const Container = defineComponent({ name: 'Container', setup() { - return { - start: ref(), - stop: ref() - } - }, - computed: { - ...mapState(['screenSize']) - }, - watch: { - screenSize(v) { + const startDrag = ref() + const stopDrag = ref() + const container = ref() + const target = ref() + + const { useState } = uesModuleStore(NAMESPACED) + + const { screenSize } = toRefs(useState()) + + watch(screenSize, v => { if (v === Size.MD) { - this?.start() + startDrag.value() } else { - this?.stop() + stopDrag.value() } - } - }, - mounted() { - if (VUE_APP_PLATFORM === 'browser') { - nextTick(() => { - const { container, target } = this.$refs - const { start, stop } = dragHook( - container as HTMLElement, - (target as ComponentPublicInstance).$el + }) + + onMounted(() => { + if (VUE_APP_PLATFORM === 'browser') { + const { start, stop } = useDrag( + container.value as HTMLElement, + (target.value as ComponentPublicInstance).$el ) - this.start = start - this.stop = stop - }) - } - }, - render(this: State) { - const { screenSize } = this - return ( + startDrag.value = start + stopDrag.value = stop + } + }) + + return () => (
-
+
diff --git a/src/pages/footer/view/index.tsx b/src/pages/footer/view/index.tsx index 3185c1c4..3b42f638 100644 --- a/src/pages/footer/view/index.tsx +++ b/src/pages/footer/view/index.tsx @@ -1,24 +1,23 @@ -import { defineComponent } from 'vue' -import { mapMutations, LayoutActions, mapState } from '@/layout/module' +import { defineComponent, toRefs } from 'vue' +import { NAMESPACED, State, LayoutActions } from '@/layout/module' +import { uesModuleStore } from '@/hooks/index' import './index.less' export const Footer = defineComponent({ name: 'Footer', - computed: { - ...mapState(['rebackSize']) - }, - methods: { - ...mapMutations({ - changeWindowSize: LayoutActions.CHANGE_WINDOW_SIZE - }) - }, - render() { - return ( + setup() { + const { useState, useMutations } = uesModuleStore(NAMESPACED) + + const { rebackSize } = toRefs(useState()) + + return () => (