index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div style="min-width: 1184px;" class="white-bgc">
  3. <!-- 导航栏 -->
  4. <Navbar />
  5. <div id="contentBox" ref="scrollBox">
  6. <!-- 轮播图 -->
  7. <Carousel :templateData="template" class="mb-10" style="max-height: 594.5px;" />
  8. <div class="default-width pb-10">
  9. <!-- 热门商品 -->
  10. <HotGoods :templateData="template" class="mb-10" />
  11. <!-- 积分兑换 -->
  12. <PointExchange :point="accountData.point" @login="handleLogin" />
  13. </div>
  14. </div>
  15. </div>
  16. <!-- 快速登录 -->
  17. <loginPage v-if="showLogin" @loginSuccess="loginSuccess" @close="loginClose"></loginPage>
  18. </template>
  19. <script setup>
  20. defineOptions({ name: 'mall-home-index'})
  21. import { ref, onMounted } from 'vue'
  22. import Navbar from '../components/navbar.vue'
  23. import Carousel from './components/carousel.vue'
  24. import HotGoods from './components/hotGoods.vue'
  25. import PointExchange from './pointExchange'
  26. import loginPage from '@/views/common/loginDialog.vue'
  27. import { useMallStore } from '@/store/mall'
  28. import { useUserStore } from '@/store/user'
  29. import Snackbar from '@/plugins/snackbar'
  30. import { useRouter } from 'vue-router'
  31. const router = useRouter()
  32. // 获取装修模版
  33. onMounted(async () => {
  34. await useMallStore().getMallDiyTemplate()
  35. })
  36. let template = ref(JSON.parse(localStorage.getItem('mallTemplate')) || {})
  37. useMallStore().$subscribe((mutation, state) => {
  38. if (state.template && Object.keys(state.template).length) template.value = state?.template
  39. })
  40. const userStore = useUserStore()
  41. let accountData = ref(JSON.parse(localStorage.getItem('userAccount')) || {})
  42. userStore.$subscribe((mutation, state) => {
  43. if (Object.keys(state.userAccount).length) accountData.value = state.userAccount
  44. })
  45. const showLogin = ref(false)
  46. const returnUrl = ref('')
  47. const handleLogin = (path) => {
  48. showLogin.value = true // 打开快速登录弹窗
  49. returnUrl.value = path
  50. }
  51. // 快速登录
  52. const loginSuccess = () => {
  53. showLogin.value = false
  54. Snackbar.success('登录成功')
  55. if (returnUrl.value) {
  56. router.push(returnUrl.value)
  57. setTimeout(() => {
  58. returnUrl.value = ''
  59. }, 1000)
  60. }
  61. }
  62. const loginClose = () => {
  63. showLogin.value = false
  64. Snackbar.warning('您已取消登录')
  65. }
  66. const handleSearch = (val) => {
  67. }
  68. </script>
  69. <style scoped lang="scss">
  70. </style>