Browse Source

Merge pull request 'dev' (#19) from dev into test

Reviewed-on: common/base_daoshi_vue_ts#19
test
姜鑫 3 years ago
parent
commit
515cfacf3c
  1. 2
      src/composables/useDay.ts
  2. 22
      src/composables/useGuideFilterShop.ts
  3. 2
      src/composables/useInitConfigAndMallInfo.ts
  4. 47
      src/composables/useParkingKeyboard.ts
  5. 4
      src/enums/index.ts
  6. 7
      src/http/http.ts
  7. 7
      src/i18n/lang/en.json
  8. 7
      src/i18n/lang/tw.json
  9. 7
      src/i18n/lang/zh.json
  10. 2
      src/plugins/index.ts
  11. 1
      src/store/root/actions.ts
  12. 2
      src/utils/utils.ts
  13. 27
      src/views/Guide/Guide.vue
  14. 12
      src/views/Guide/list.ts
  15. 2
      src/views/Nav/Nav.vue
  16. 54
      src/views/Parking/Parking.vue

2
src/composables/useDay.ts

@ -6,7 +6,7 @@ export const useDay = () => {
zh: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
en: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
tw: ['星期日', '星期壹', '星期二', '星期三', '星期四', '星期五', '星期六']
}
} as const
const date = ref(new Date())
const store = useStore()

22
src/composables/useGuideFilterShop.ts

@ -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 }
}

2
src/composables/useInitConfigAndMallInfo.ts

@ -21,6 +21,6 @@ export const useInitConfigAndMallInfo = async () => {
store.SET_BUILDING_LIST(buildingList)
store.SET_FACILITY_LIST(_facilityList.data)
} catch (error) {
Message({ text: '初始化数据失败', type: 'success' })
Message({ text: '获取数据失败', type: 'success' })
}
}

47
src/composables/useParkingKeyboard.ts

@ -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 }
}

4
src/enums/index.ts

@ -6,8 +6,8 @@ export enum ACTIVITY_TYPE {
}
export enum DEVICE {
window = 'windows',
android = 'android'
WINDOWS = 'windows',
ANDROID = 'android'
}
//卡片推荐类型

7
src/http/http.ts

@ -13,7 +13,7 @@ class Request {
constructor(config: CreateRequestConfig) {
this.instance = axios.create(config)
// * 初始化存放取消请求控制器Map
//取消请求控制器Map
this.abortControllerMap = new Map()
this.interceptorsObj = config.interceptors
// 拦截器执行顺序 接口请求 -> 实例请求 -> 全局请求 -> 实例响应 -> 全局响应 -> 接口响应
@ -31,7 +31,7 @@ class Request {
// 使用实例拦截器
this.instance.interceptors.request.use(this.interceptorsObj?.requestInterceptors, this.interceptorsObj?.requestInterceptorsCatch)
this.instance.interceptors.response.use(this.interceptorsObj?.responseInterceptors, this.interceptorsObj?.responseInterceptorsCatch)
// 全局响应拦截器保证最后执行
this.instance.interceptors.response.use(
(res: AxiosResponse) => {
const url = res.config.url || ''
@ -43,14 +43,13 @@ class Request {
}
request<T>(config: RequestConfig<T>): Promise<T> {
return new Promise((resolve, reject) => {
// 如果为单个请求设置拦截器,这里使用单个请求的拦截器
if (config.interceptors?.requestInterceptors) {
config = config.interceptors.requestInterceptors(config as any)
}
this.instance
.request<any, T>(config)
.then(res => {
// 如果为单个响应设置拦截器,这里使用单个响应的拦截器
// 如果为单个响应设置拦截器,使用单个响应的拦截器
if (config.interceptors?.responseInterceptors) {
res = config.interceptors.responseInterceptors(res)
}

7
src/i18n/lang/en.json

@ -1,5 +1,10 @@
{
"detail": "Detail",
"nav": "Navigate",
"energy": "Energy"
"energy": "Energy",
"replay": "Replay",
"pause": "Pause",
"play": "Play",
"speedUp": "Speed up",
"stopSpeedUp": "Stop acceleration"
}

7
src/i18n/lang/tw.json

@ -1,5 +1,10 @@
{
"detail": "詳情",
"nav": "導航",
"energy": "新能源"
"energy": "新能源",
"replay": "重播",
"pause": "暫停",
"play": "播放",
"speedUp": "加速",
"stopSpeedUp": "停止加速"
}

7
src/i18n/lang/zh.json

@ -1,5 +1,10 @@
{
"detail": "详情",
"nav": "导航",
"energy": "新能源"
"energy": "新能源",
"replay": "重播",
"pause": "暂停",
"play": "播放",
"speedUp": "加速",
"stopSpeedUp": "停止加速"
}

2
src/plugins/index.ts

@ -1,6 +1,6 @@
import { switchLanguage } from './switchLanguage'
import VueLazyLoad from 'vue3-lazyload'
import { App } from 'vue'
import type { App } from 'vue'
export function setupPlugins(app: App) {
app.use(switchLanguage).use(VueLazyLoad, {

1
src/store/root/actions.ts

@ -2,6 +2,7 @@ import { i18n } from '@/i18n'
import type { Language, State } from './state'
import type { Root } from '../key'
import type { CreateActions } from '../types'
export interface Actions {
SET_SHOP_LIST(list: Shop[]): void
SET_BUILDING_LIST(list: Building[]): void

2
src/utils/utils.ts

@ -120,7 +120,7 @@ export const formatDay = (date: Date, format: 'y.m.d' | 'y/m/d' | 'y-m-d' = 'y-m
//判断当前系统
export const isAndroid = () => {
const userAgent = navigator.userAgent
const agents = ['Android', 'iPhone', 'iPad']
const agents = ['Android', 'iPhone', 'iPad'] as const
return agents.some(item => userAgent.includes(item))
}

27
src/views/Guide/Guide.vue

@ -2,24 +2,15 @@
<div class="guide-container">Guide Page</div>
</template>
<script setup>
// import { shallowRef, toRefs } from 'vue'
// import { useStore } from '@/store/root'
// import { useGuideMapOperation } from '@/composables/useGuideMapOperation'
// import { useFacilityNav } from '@/composables/useFacilityNav'
<script setup lang="ts">
import { useStore } from '@/store/root'
import { useGuideMapOperation } from '@/composables/useGuideMapOperation'
import { useFacilityNav } from '@/composables/useFacilityNav'
import { useGuideFilterShop } from '@/composables/useGuideFilterShop'
// const store = useStore()
// const { currentBuildingFloorsList, shopList, currentFloor } = toRefs(store)
const store = useStore()
// const { switchFloor, handleMapIcon, list } = useGuideMapOperation()
// const { handleFacility } = useFacilityNav()
// const floorIdx = ref(-1) //
// const selectedShopList = shallowRef([]) //
// //
// function filterAboutCurrentInfo() {
// floorIdx.value = currentBuildingFloorsList.value.findIndex(item => item.name === currentFloor.value.floorName)
// selectedShopList.value = shopList.value.filter(item => item.floorName === currentFloor.value.floorName)
// }
const { floorIdx, selectedShopList, filterShopByFloorName, filterAboutCurrentInfo } = useGuideFilterShop() //
const { switchFloor, handleMapIcon, list, mapIdx } = useGuideMapOperation() //
const { handleFacility } = useFacilityNav() //
</script>

12
src/views/Guide/list.ts

@ -23,11 +23,11 @@ export const list: Item[] = [
nameEn: 'direction',
icon: require('@/assets/images/guide/direction.png'),
iconActive: require('@/assets/images/guide/direction_active.png')
},
{
name: MapControl.ACTIVITY_BRAND,
nameEn: 'activity',
icon: require('@/assets/images/guide/brand.svg'),
iconActive: require('@/assets/images/guide/brand_active.svg')
}
// {
// name: ACTIVITY_BRAND,
// nameEn: 'activity',
// icon: require('@/assets/images/guide/brand.svg'),
// iconActive: require('@/assets/images/guide/brand_active.svg')
// }
]

2
src/views/Nav/Nav.vue

@ -2,7 +2,7 @@
<div></div>
</template>
<script setup>
<script setup lang="ts">
// import { storeToRefs } from 'pinia'
// import { useStore } from '@/store/root'
// import { useMapNavControl } from '@/composables/useMapNavControl'

54
src/views/Parking/Parking.vue

@ -1,68 +1,22 @@
<template>
<PlateInput :list="plate" :search-method="searchMethod" :space-length="inputLength" @confirm="onConfirm" @handle-energy="handleEnergy">
<Loading v-if="loading" class="find-car-loading" fill="#fff" :size="20" />
<Loading v-if="loading" fill="#fff" :size="20" />
</PlateInput>
<PlateKeyboard @del="del" @handle-keyboard="handleKeyboard" />
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useFindCar } from '@/composables/useFindCar'
import { isZhWord, isUppercaseWord } from '@/utils/utils'
import { useParkingKeyboard } from '@/composables/useParkingKeyboard'
import PlateInput from '@/components/PlateInput/PlateInput.vue'
import PlateKeyboard from '@/components/PlateKeyboard/PlateKeyboard.vue'
import Loading from '@/base/Loading/Loading.vue'
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()
}
const { del, handleKeyboard, handleEnergy, inputLength, plate, plateToString, searchMethod, LICENSE } = useParkingKeyboard()
const { confirm, loading, showCarDetail, result } = useFindCar()
function onConfirm() {
plate.value = LICENSE
confirm(plateToString.value)
}
</script>
<style lang="scss" scoped>
.find-car-loading {
margin-right: 20px;
}
</style>

Loading…
Cancel
Save