Browse Source

refactor: ♻️ 修改代码

pull/1/head
jiangx 3 years ago
parent
commit
95fc76ff84
  1. 9
      src/composables/useMapNavControl.ts
  2. 40
      src/composables/useRequest.ts

9
src/composables/useMapNavControl.ts

@ -1,6 +1,9 @@
import { ref, nextTick, onBeforeUnmount } from 'vue'
export const useMapNavControl = () => {
const SPEED_NORMAL = 6
const SPEED_FAST = 10
const replay = ref(false) //重播
const pause = ref(false) //暂停
const speedUp = ref(false) //加速
@ -8,7 +11,7 @@ export const useMapNavControl = () => {
//重播
function handleReplay() {
window.Map_QM.util.changePlaySpeed(6)
window.Map_QM.util.changePlaySpeed(SPEED_NORMAL)
replay.value = true
pause.value = false
speedUp.value = false
@ -37,7 +40,7 @@ export const useMapNavControl = () => {
speedUp.value = !speedUp.value
window.Map_QM.pathStop(true)
nextTick(() => {
speedUp.value ? window.Map_QM.util.changePlaySpeed(10) : window.Map_QM.util.changePlaySpeed(6)
speedUp.value ? window.Map_QM.util.changePlaySpeed(SPEED_FAST) : window.Map_QM.util.changePlaySpeed(SPEED_NORMAL)
})
}
@ -48,7 +51,7 @@ export const useMapNavControl = () => {
onBeforeUnmount(() => {
clearTimeout(replayTimer.value)
replayTimer.value = null
window.Map_QM.util.changePlaySpeed(6)
window.Map_QM.util.changePlaySpeed(SPEED_NORMAL)
})
return { replay, pause, speedUp, handleReplay, togglePause, handleSpeedUp, resetPause }

40
src/composables/useRequest.ts

@ -1,40 +0,0 @@
import { ref } from 'vue'
import { HTTP_CODE } from '@/enums'
import type { Response } from '@/http/http'
/**
* @template ReturnData
* @template Params http请求中需要向后台发送的参数
* @param {} asyncFn
* @param {Params} [query]
* @example1
* type Result = {"activity": "Do yoga","type": "recreational" "accessibility": 0.9}
type Query = { participants: number }
* const getConfig = (data: Query) => request({ url: 'https://www.boredapi.com/api/activity' })
const { loaded, result, error } = useRequest<Result, Query>(getConfig, { participants: 1 })
@example2
*const getConfig = () => request({ url: 'static/offline/JSON/config.json' })
const { loaded, result, error } = useRequest<Result>(getConfig)
*/
export const useRequest = <ReturnData = any, Params = any>(asyncFn: (params?: Params) => Promise<Response<ReturnData>>, query?: Params) => {
const error = ref()
const result = ref<ReturnData>()
const loaded = ref(false)
asyncFn(query)
.then(({ code, data, msg }) => {
if (code === HTTP_CODE.ERR_OK) {
result.value = data
} else {
error.value = msg
}
})
.catch(err => {
error.value = err
})
.finally(() => {
loaded.value = true
})
return { result, loaded, error }
}
Loading…
Cancel
Save