8 changed files with 85 additions and 71 deletions
@ -0,0 +1,22 @@ |
|||||
|
import { ref, shallowRef, toRefs } from 'vue' |
||||
|
import { useStore } from '@/store/root' |
||||
|
|
||||
|
export const useGuideFilterShop = () => { |
||||
|
const store = useStore() |
||||
|
const { shopList, currentBuildingFloorsList, currentFloor } = toRefs(store) |
||||
|
|
||||
|
const floorIdx = ref(-1) //楼层选中索引
|
||||
|
const selectedShopList = shallowRef<Shop[]>([]) //选中楼层的店铺列表
|
||||
|
|
||||
|
function filterShopByFloorName(floorName: string) { |
||||
|
selectedShopList.value = shopList.value.filter(item => item.floor === floorName) |
||||
|
} |
||||
|
|
||||
|
// //筛选当前楼层所需数据
|
||||
|
function filterAboutCurrentInfo() { |
||||
|
floorIdx.value = currentBuildingFloorsList.value.findIndex(item => item.floor === currentFloor.value.floor) |
||||
|
selectedShopList.value = shopList.value.filter(item => item.floor === currentFloor.value.floor) |
||||
|
} |
||||
|
|
||||
|
return { floorIdx, selectedShopList, filterShopByFloorName, filterAboutCurrentInfo } |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
import { ref, computed } from 'vue' |
||||
|
import { isZhWord, isUppercaseWord } from '@/utils/utils' |
||||
|
|
||||
|
export const useParkingKeyboard = () => { |
||||
|
const NOT_ENERGY_PLATE = 7 //非能源车牌长度
|
||||
|
const ENERGY_PLATE = 8 //能源车牌长度
|
||||
|
const SPACE_MAX_LENGTH = 6 //车位最大允许长度
|
||||
|
const LICENSE = ['苏', 'A'] //默认车牌前缀
|
||||
|
|
||||
|
const plate = ref(LICENSE.slice()) |
||||
|
const plateToString = computed(() => plate.value.join('')) |
||||
|
const searchMethod = ref<'车牌' | '车位'>('车牌') |
||||
|
const inputLength = computed(() => (searchMethod.value === '车牌' ? ENERGY_PLATE : SPACE_MAX_LENGTH)) |
||||
|
const isEnergy = ref(false) |
||||
|
function handleEnergy(energy: boolean) { |
||||
|
isEnergy.value = energy |
||||
|
if (!energy && plate.value.length === ENERGY_PLATE) { |
||||
|
plate.value.pop() |
||||
|
} |
||||
|
} |
||||
|
function handleKeyboard(value: string) { |
||||
|
if (searchMethod.value === '车牌') { |
||||
|
if (plate.value.length === 1 && isZhWord(value)) { |
||||
|
plate.value[0] = value |
||||
|
return |
||||
|
} |
||||
|
if ( |
||||
|
(!isEnergy.value && plate.value.length >= NOT_ENERGY_PLATE) || |
||||
|
(isEnergy.value && plate.value.length >= ENERGY_PLATE) || |
||||
|
(plate.value.length === 0 && !isZhWord(value)) || |
||||
|
(plate.value.length === 1 && !isUppercaseWord(value)) || |
||||
|
(plate.value.length >= 2 && plate.value.length < 6 && isZhWord(value)) |
||||
|
) { |
||||
|
return |
||||
|
} |
||||
|
} else if (plate.value.length >= SPACE_MAX_LENGTH) { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
plate.value.push(value) |
||||
|
} |
||||
|
function del() { |
||||
|
plate.value.pop() |
||||
|
} |
||||
|
|
||||
|
return { del, handleKeyboard, handleEnergy, inputLength, plate, plateToString, LICENSE, searchMethod } |
||||
|
} |
||||
Loading…
Reference in new issue