Browse Source

refactor: ♻️ 代码重构

pull/1/head
jiangx 3 years ago
parent
commit
6829d9a82c
  1. 4
      src/composables/useActivityNav.ts
  2. 4
      src/composables/useFacilityNav.ts
  3. 21
      src/composables/usePage.ts

4
src/composables/useActivityNav.ts

@ -8,11 +8,13 @@ export const useActivityNav = () => {
const store = useRootStore()
const { shopList } = storeToRefs(store)
const NO_POINT_TYPE = -1
function nav(activity: Activity) {
let shop
if (activity.shopCode.length) {
shop = shopList.value.find(item => item.shopCode === activity?.shopCode)
} else if (activity.point > -1) {
} else if (activity.point > NO_POINT_TYPE) {
const { activityName, floorOrder, floor, point, fileUrl, activityId } = activity
shop = new Brand({ shopName: activityName, floorOrder, floor, logoUrl: fileUrl, yaxis: point, shopCode: activityId })
}

4
src/composables/useFacilityNav.ts

@ -8,11 +8,11 @@ export const useFacilityNav = () => {
function handleFacility({ abbreviation, customFacilityName, filePath, code }: Facility) {
const { floor, node } = window.Map_QM.pathIcon({ type: abbreviation })
const floorName = store.currentBuildingFloorsList.find(_floor => _floor.floorOrder === floor)?.floor
const floorName = store.currentBuildingFloorsList.find(_floor => _floor.floorOrder === floor)?.floor ?? ''
const shop = new Brand({
shopName: customFacilityName,
floorOrder: floor,
floor: floorName as string,
floor: floorName,
logoUrl: filePath,
yaxis: node,
shopCode: code

21
src/composables/usePage.ts

@ -1,12 +1,13 @@
import { ref, shallowRef, watch, toRaw, nextTick, onBeforeUnmount, type ShallowRef } from 'vue'
import { ref, shallowRef, watch, toRaw, nextTick, onBeforeUnmount } from 'vue'
import type { ShallowRef } from 'vue'
type PageList = { name: string; shopList: Shop[] }
/**
* @param {array} totalList
* @param {*} scroll
* @return {*} { scrollEnd, pageList, loaded }
*/
type PageList = { name: string; shopList: Shop[] }
export const usePage = (totalList: PageList[], scroll: ShallowRef<any>) => {
export const usePage = (totalList: ShallowRef<PageList[]>, scroll: any) => {
if (typeof Worker === 'undefined') {
alert('抱歉,当前运行环境不支持Web Worker API, 请升级浏览器版本')
}
@ -27,16 +28,10 @@ export const usePage = (totalList: PageList[], scroll: ShallowRef<any>) => {
function scrollEnd() {
worker.value?.postMessage('scrollEnd')
}
watch(
totalList,
newVal => {
const rawList = newVal.map(item => toRaw(item))
worker.value?.postMessage(rawList)
},
{
immediate: true
}
)
watch(totalList, newVal => {
const rawList = newVal.map(item => toRaw(item))
worker.value?.postMessage(rawList)
})
onBeforeUnmount(() => {
worker.value?.terminate()

Loading…
Cancel
Save