index.vue 2.2 KB

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