Browse Source

feat: 首页美食、推荐轮播逻辑

潮流
jiannibang 4 years ago
parent
commit
3bda775305
  1. 2
      src/base/ScrollView/ScrollView.vue
  2. 6
      src/components/CarouselWithIntro/CarouselWithIntro.vue
  3. 4
      src/components/PublicComponent/Tabs.vue
  4. 6
      src/composables/useTime.js
  5. 8
      src/views/Guide/Guide.vue
  6. 12
      src/views/Index/Index.vue

2
src/base/ScrollView/ScrollView.vue

@ -49,8 +49,6 @@ const scrollDOMRef = ref(null)
const store = useStore() const store = useStore()
const languageRef = computed(() => store.language) const languageRef = computed(() => store.language)
const emits = defineEmits(['scroll'])
function _initScroll() { function _initScroll() {
if (!scrollDOMRef.value) { if (!scrollDOMRef.value) {
return return

6
src/components/CarouselWithIntro/CarouselWithIntro.vue

@ -24,7 +24,7 @@
</template> </template>
<script setup> <script setup>
import { ref, computed } from 'vue'
import { computed } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { useStore } from '@/store/root' import { useStore } from '@/store/root'
import EffectFade from '@/components/EffectFade/EffectFade.vue' import EffectFade from '@/components/EffectFade/EffectFade.vue'
@ -38,10 +38,6 @@ const props = defineProps({
const store = useStore() const store = useStore()
const { config } = storeToRefs(store) const { config } = storeToRefs(store)
const qr = computed(() => props.data.qrFileList ?? []) const qr = computed(() => props.data.qrFileList ?? [])
const showLoginDialog = ref(false)
const showLoginError = ref(false)
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

4
src/components/PublicComponent/Tabs.vue

@ -20,7 +20,7 @@ const goPage = item => {
} }
</script> </script>
<style lang="scss" scoped>
<style lang="scss" scoped>
.tabs { .tabs {
position: fixed; position: fixed;
top: 400px; top: 400px;
@ -79,4 +79,4 @@ const goPage = item => {
margin-left: 24px; margin-left: 24px;
} }
} }
</style>
</style>

6
src/composables/useTime.js

@ -7,6 +7,8 @@ export const useTime = () => {
const currentTime = computed(() => { const currentTime = computed(() => {
return `${date.value.getHours().toString().padStart(2, '0')}:${date.value.getMinutes().toString().padStart(2, '0')}` return `${date.value.getHours().toString().padStart(2, '0')}:${date.value.getMinutes().toString().padStart(2, '0')}`
}) })
const currentHour = computed(() => date.value.getHours())
const currentTimeMinute = computed(() => date.value.getMinutes())
const getDate = () => { const getDate = () => {
timer.value = setInterval(() => { timer.value = setInterval(() => {
date.value = new Date() date.value = new Date()
@ -17,6 +19,8 @@ export const useTime = () => {
onBeforeUnmount(() => clearInterval(timer.value)) onBeforeUnmount(() => clearInterval(timer.value))
return { return {
currentTime
currentTime,
currentHour,
currentTimeMinute
} }
} }

8
src/views/Guide/Guide.vue

@ -64,10 +64,10 @@
</template> </template>
<script setup> <script setup>
import { ref, watch, onBeforeUnmount, onMounted } from 'vue'
import { ref, watch, onBeforeUnmount } from 'vue'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { useStore } from '@/store/root' import { useStore } from '@/store/root'
import { list, RESET, DIRECTION, ACTIVITY_BRAND } from './list'
import { RESET, DIRECTION, ACTIVITY_BRAND } from './list'
import View from '@/layouts/View.vue' import View from '@/layouts/View.vue'
import { hideMapDialog } from '@/composables/useInitMap' import { hideMapDialog } from '@/composables/useInitMap'
import { getBrandListByFormat, getBrandListByFloor } from '@/http/brand/api' import { getBrandListByFormat, getBrandListByFloor } from '@/http/brand/api'
@ -97,7 +97,7 @@ try {
} }
getBrandListByFloor().then(({ data }) => { getBrandListByFloor().then(({ data }) => {
formatMap.value = data.list formatMap.value = data.list
.map(({ name, shopList }) => ({ name, format: Object.keys(shopList.reduce((acc, nxt) => ({ ...acc, [nxt.industryFatherName]: true }), {})).join('/') }))
.map(({ name, shopList: list }) => ({ name, format: Object.keys(list.reduce((acc, nxt) => ({ ...acc, [nxt.industryFatherName]: true }), {})).join('/') }))
.reduce((acc, nxt) => ({ ...acc, [nxt.name]: nxt.format }), {}) .reduce((acc, nxt) => ({ ...acc, [nxt.name]: nxt.format }), {})
}) })
getBrandListByFormat().then(({ data }) => { getBrandListByFormat().then(({ data }) => {
@ -195,8 +195,6 @@ onBeforeUnmount(() => {
clearTimeout(mapIconTimer.value) clearTimeout(mapIconTimer.value)
}) })
onMounted(() => {})
watch( watch(
[shopList, currentFloor], [shopList, currentFloor],
([_shopList, _currentFloor]) => { ([_shopList, _currentFloor]) => {

12
src/views/Index/Index.vue

@ -26,7 +26,7 @@
<div class="meta2">{{ bf }}</div> <div class="meta2">{{ bf }}</div>
<div class="bottom-right"></div> <div class="bottom-right"></div>
</div> </div>
<!-- <div class="food" @click="goPage({ title: '推荐美食', path: '/foods' })">
<div v-if="showFood" class="food" @click="goPage({ title: '推荐美食', path: '/foods' })">
<div class="title"> <div class="title">
<h1>推荐美食</h1> <h1>推荐美食</h1>
<h2>此时此刻美食正在等你</h2> <h2>此时此刻美食正在等你</h2>
@ -34,8 +34,8 @@
<div class="grid"> <div class="grid">
<img class="item" v-for="shop of foodList" :key="shop.id" :src="config.sourceUrl + shop.logoUrl" alt="" /> <img class="item" v-for="shop of foodList" :key="shop.id" :src="config.sourceUrl + shop.logoUrl" alt="" />
</div> </div>
</div> -->
<div class="rec" @click="goPage({ title: '品牌列表', path: '/brand' })">
</div>
<div v-else class="rec" @click="goPage({ title: '品牌列表', path: '/brand' })">
<div class="title"> <div class="title">
<h1>推荐品牌</h1> <h1>推荐品牌</h1>
<h2>心动之选拥抱美好生活</h2> <h2>心动之选拥抱美好生活</h2>
@ -77,16 +77,18 @@ import { getBrandList } from '@/http/brand/api'
import { getActivityList } from '@/http/api' import { getActivityList } from '@/http/api'
import View from '@/layouts/View.vue' import View from '@/layouts/View.vue'
import EffectFade from '@/components/EffectFade/EffectFade.vue' import EffectFade from '@/components/EffectFade/EffectFade.vue'
import { useTime } from '@/composables/useTime'
const router = useRouter() const router = useRouter()
const store = useStore() const store = useStore()
const { indexList, currentFloor, buildingList, shopList, sidebarList, selectedModule, config } = storeToRefs(store)
const { indexList, currentFloor, buildingList, shopList, sidebarList, config } = storeToRefs(store)
const guideDesc = ref('') const guideDesc = ref('')
const foodList = computed(() => shopList.value.filter(({ isSpecial }) => isSpecial).slice(0, 12) ?? []) const foodList = computed(() => shopList.value.filter(({ isSpecial }) => isSpecial).slice(0, 12) ?? [])
const hotRecommend = computed(() => indexList.value.hotSearch.slice(0, 5) ?? []) const hotRecommend = computed(() => indexList.value.hotSearch.slice(0, 5) ?? [])
const cardsList = computed(() => indexList.value.columnList ?? [])
const bf = computed(() => (buildingList.length > 1 ? currentFloor.value.building + '-' : '') + currentFloor.value.floor) const bf = computed(() => (buildingList.length > 1 ? currentFloor.value.building + '-' : '') + currentFloor.value.floor)
const activityList = ref([]) const activityList = ref([])
const { currentHour } = useTime()
const showFood = computed(() => (currentHour.value >= 11 && currentHour.value < 13) || (currentHour.value >= 17 && currentHour.value < 20))
getBrandList().then(({ data: { allShopNum, industryFatherList } }) => { getBrandList().then(({ data: { allShopNum, industryFatherList } }) => {
const spFormat = industryFatherList.find(({ isSpecial }) => isSpecial) const spFormat = industryFatherList.find(({ isSpecial }) => isSpecial)

Loading…
Cancel
Save