Browse Source

feat: 🚀 新增模块接口

pull/2/head
liyongle 3 years ago
parent
commit
12687332b6
  1. 34
      public/static/offline/JSON/getModuleList.json
  2. 46
      src/components/Menu/Menu.vue
  3. 22
      src/composables/useInitConfigAndMallInfo.ts
  4. 4
      src/http/api/home/index.ts
  5. 4
      src/store/root/actions.ts
  6. 4
      src/store/root/state.ts
  7. 4
      src/types/menu.d.ts
  8. 20
      src/views/Index/Middle.vue
  9. 2
      src/views/Parking/Parking.vue

34
public/static/offline/JSON/getModuleList.json

@ -0,0 +1,34 @@
{
"code": 200,
"msg": "操作成功",
"data": [
{
"moduleName": "主页",
"status": 0
},
{
"moduleName": "店铺导航",
"status": 0
},
{
"moduleName": "优惠与活动",
"status": 0
},
{
"moduleName": "会员专享",
"status": 0
},
{
"moduleName": "服务",
"status": 0
},
{
"moduleName": "停车与缴费",
"status": 1
},
{
"moduleName": "文化学院",
"status": 0
}
]
}

46
src/components/Menu/Menu.vue

@ -1,6 +1,12 @@
<template>
<div class="menu-container">
<div v-for="item in list" :key="item.title" class="menu-item" @click="changeMenu(item)">
<div
v-for="item in list"
:key="item.title"
:style="item.status === 1 ? 'display:none' : ''"
class="menu-item"
@click="changeMenu(item)"
>
<div class="top">
<img :src="current === item.path ? item.iconS : item.icon" alt="" />
<div v-if="current === item.path" class="ac"></div>
@ -11,78 +17,94 @@
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { ref, watch, toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useStatisticsModel } from '@/composables/useStatistics'
import { useRootStore } from '@/store/root'
type MenuItem = {
title: string
titleEn: string
icon: string
iconS: string
path: string
status: 0 | 1 // 0 1
}
const list: MenuItem[] = [
const list = ref<MenuItem[]>([
{
title: '主页',
titleEn: 'Home',
icon: require('@/assets/images/menu/home.png'),
iconS: require('@/assets/images/menu/homes.png'),
path: '/'
path: '/',
status: 0
},
{
title: '店铺导航',
titleEn: 'Brand',
icon: require('@/assets/images/menu/brand.png'),
iconS: require('@/assets/images/menu/brands.png'),
path: '/brand'
path: '/brand',
status: 0
},
{
title: '优惠与活动',
titleEn: 'Activity',
icon: require('@/assets/images/menu/activity.png'),
iconS: require('@/assets/images/menu/activitys.png'),
path: '/activity'
path: '/activity',
status: 0
},
{
title: '会员专享',
titleEn: 'Member',
icon: require('@/assets/images/menu/member.png'),
iconS: require('@/assets/images/menu/members.png'),
path: '/member'
path: '/member',
status: 0
},
{
title: '服务',
titleEn: 'Service',
icon: require('@/assets/images/menu/service.png'),
iconS: require('@/assets/images/menu/services.png'),
path: '/service'
path: '/service',
status: 0
},
{
title: '停车与缴费',
titleEn: 'Parking',
icon: require('@/assets/images/menu/parking.png'),
iconS: require('@/assets/images/menu/parkings.png'),
path: '/parking'
path: '/parking',
status: 0
},
{
title: '文化学院',
titleEn: 'School',
icon: require('@/assets/images/menu/school.png'),
iconS: require('@/assets/images/menu/schools.png'),
path: '/school'
path: '/school',
status: 0
},
{
title: '艺术',
titleEn: 'Art',
icon: require('@/assets/images/menu/art.png'),
iconS: require('@/assets/images/menu/arts.png'),
path: '/art'
path: '/art',
status: 0
}
]
])
const store = useRootStore()
const { menuList } = toRefs(store)
const router = useRouter()
const route = useRoute()
const current = ref('/')
menuList.value.forEach((item, index) => {
list.value[index].status = item.status
})
function changeMenu(item: MenuItem) {
router.push(item.path)
useStatisticsModel({ recordType: 1, moduleName: item.title })

22
src/composables/useInitConfigAndMallInfo.ts

@ -3,6 +3,7 @@ import { getConfig, getFacilitiesList, getWeather } from '@/http/api/base'
import { getShopAndBuildingList } from '@/http/api/shop'
import { getDeviceInfo } from '@/http/api/building'
import { getShopListByFloor, getShopListByIndustry, getBrandInfo } from '@/http/api/brand'
import { getModuleList } from '@/http/api/home'
import Message from '@/base/Message/Message'
export const useInitConfigAndMallInfo = async () => {
@ -11,15 +12,17 @@ export const useInitConfigAndMallInfo = async () => {
const store = useRootStore()
store.SET_CONFIG(_config.data)
const [_DeviceInfo, _shopAndBuilding, _facilityList, _weather, _shopListByFloor, _shopListByIndustry, _brandInfo] = await Promise.all([
getDeviceInfo(),
getShopAndBuildingList(),
getFacilitiesList(),
getWeather(),
getShopListByFloor(),
getShopListByIndustry(),
getBrandInfo()
])
const [_DeviceInfo, _shopAndBuilding, _facilityList, _weather, _shopListByFloor, _shopListByIndustry, _brandInfo, _menuList] =
await Promise.all([
getDeviceInfo(),
getShopAndBuildingList(),
getFacilitiesList(),
getWeather(),
getShopListByFloor(),
getShopListByIndustry(),
getBrandInfo(),
getModuleList()
])
const { shopList, buildingList } = _shopAndBuilding.data
store.SET_DEVICE(_DeviceInfo.data)
@ -30,6 +33,7 @@ export const useInitConfigAndMallInfo = async () => {
store.SET_SHOP_LIST_BY_INDUSTRY(_shopListByIndustry.data.list)
store.SET_FACILITY_LIST(_facilityList.data)
store.SET_WEATHER(_weather.data)
store.SET_MENU_LIST(_menuList.data)
} catch (error) {
Message({ text: '初始化数据失败', type: 'success' })
}

4
src/http/api/home/index.ts

@ -0,0 +1,4 @@
import { request } from '../../http'
//获取菜单开关
export const getModuleList = () => request<MenuType[]>({ url: `/JSON/getModuleList.json` })

4
src/store/root/actions.ts

@ -19,6 +19,7 @@ export interface Actions {
SET_MAP_STATUS(flag: boolean): void
SET_SHOW_DETAIL(flag: boolean): void
SET_SHOW_SEARCH(flag: boolean): void
SET_MENU_LIST(list: MenuType[]): void
}
export type GenActions = CreateActions<Root, State, Actions>
@ -68,5 +69,8 @@ export const actions: GenActions = {
},
SET_MAP_STATUS(flag) {
this.mapStatus = flag
},
SET_MENU_LIST(list) {
this.menuList = list
}
}

4
src/store/root/state.ts

@ -15,6 +15,7 @@ export interface State {
mapStatus: boolean //地图加载是否成功
device: Device //当前设备信息
shop: Shop //店铺信息
menuList: MenuType[] // 菜单信息
}
export const state = (): State => ({
@ -31,5 +32,6 @@ export const state = (): State => ({
config: {} as Config,
mapStatus: false,
device: {} as Device,
shop: {} as Shop
shop: {} as Shop,
menuList: []
})

4
src/types/menu.d.ts

@ -0,0 +1,4 @@
declare interface MenuType {
moduleName: string // 模块名称
status: 1 | 0 // 0 正常 1 关闭
}

20
src/views/Index/Middle.vue

@ -29,7 +29,10 @@
<script setup lang="ts">
import { useRouter } from 'vue-router'
import { toRefs } from 'vue'
import { useStatisticsModel } from '@/composables/useStatistics'
import { useRootStore } from '@/store/root'
import Message from '@/base/Message/Message'
const list = [
{
title: '店铺导航',
@ -61,9 +64,22 @@ const list = [
}
]
const router = useRouter()
const store = useRootStore()
const { menuList } = toRefs(store)
function go(path: string, moduleName: string) {
router.push(path)
useStatisticsModel({ recordType: 1, moduleName })
let isGo = true
for (const menu of menuList.value) {
if (menu.moduleName === moduleName) {
menu.status === 1 && (isGo = false)
break
}
}
if (isGo) {
router.push(path)
useStatisticsModel({ recordType: 1, moduleName })
} else {
Message({ text: '敬请期待', type: 'success' })
}
}
</script>

2
src/views/Parking/Parking.vue

@ -24,7 +24,7 @@
<EffectFade></EffectFade>
</div>
<h1 class="title">{{ switchLanguage(parkingInfo, 'title') }}</h1>
<ScrollView class="parking-scroll" scrollbar :list="switchLanguage(parkingInfo, 'content')">
<ScrollView class="parking-scroll" scrollbar :list="switchLanguage(parkingInfo, 'content')" :pull-up="false">
<div class="intro">{{ switchLanguage(parkingInfo, 'content') }}</div>
</ScrollView>
</div>

Loading…
Cancel
Save