index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="home-page">
  3. <header>
  4. <Notice v-if="mainData.noticeContent" :content="mainData.noticeContent" />
  5. <Toolbar
  6. :isLogin="isLogin"
  7. :storageId="storageId"
  8. @contact-us="contactUsFn"
  9. />
  10. <HandleBar
  11. :isLogin="isLogin"
  12. :storageId="storageId"
  13. :storeList="storeList"
  14. @change-store="changeStoreFn"
  15. />
  16. <Category :tabs="categoryList" :tab-index="tabIndex" @change="changeTabsFn" />
  17. </header>
  18. <main class="app-main__content">
  19. <RouterView />
  20. </main>
  21. <LinkList v-if="mainData.linkList" :data="mainData.linkList" />
  22. <LevelMessage :open="mainData.msgOpen" :contact-us="mainData.contactUs" @close="mainData.msgOpen = false" />
  23. <a-float-button
  24. shape="circle"
  25. type="primary"
  26. :style="{
  27. right: '20px',
  28. bottom: '20px'
  29. }"
  30. @click="handleLevelMsg"
  31. >
  32. <template #icon>
  33. <MessageOutlined />
  34. </template>
  35. </a-float-button>
  36. <a-float-button
  37. v-if="showBackIcon"
  38. shape="circle"
  39. type="primary"
  40. :style="{
  41. right: '70px',
  42. bottom: '20px'
  43. }"
  44. @click="router.back()"
  45. >
  46. <template #icon>
  47. <ArrowLeftOutlined />
  48. </template>
  49. </a-float-button>
  50. </div>
  51. </template>
  52. <script setup lang="js">
  53. import Notice from './components/Notice.vue';
  54. import Toolbar from './components/Toolbar.vue';
  55. import HandleBar from './components/HandleBar.vue';
  56. import Category from './components/Category.vue';
  57. import LinkList from './components/LinkList.vue';
  58. import LevelMessage from './components/LevelMessage.vue';
  59. import { MessageOutlined, ArrowLeftOutlined } from '@ant-design/icons-vue';
  60. import { onMounted, computed, reactive } from 'vue';
  61. import { useRoute, useRouter } from 'vue-router';
  62. import { useUserStore } from '@/store/user';
  63. import { useHomeStore } from '@/store/home';
  64. import { useGoodsStore } from '@/store/goods';
  65. import { useCategoryStore } from '@/store/category';
  66. import { useStorageStore } from '@/store/storage';
  67. import { getNotice } from '@/api/common';
  68. import { getAmityList } from '@/api/home';
  69. const route = useRoute();
  70. const router = useRouter();
  71. const userStore = useUserStore();
  72. const homeStore = useHomeStore();
  73. const goodsStore = useGoodsStore();
  74. const categoryStore = useCategoryStore();
  75. const storageStore = useStorageStore();
  76. const tabIndex = computed(() => homeStore.tabIndex);
  77. const categoryList = computed(() => categoryStore.list);
  78. const isLogin = computed(() => {
  79. return userStore.userInfo != null
  80. });
  81. const showBackIcon = computed(() => route.path !== '/category');
  82. const storeList = computed(() => storageStore.list);
  83. const storageId = computed(() => storageStore.activedId);
  84. const mainData = reactive({
  85. linkList: [],
  86. noticeContent: '',
  87. disabled: false,
  88. msgOpen: false,
  89. contactUs: false
  90. })
  91. const changeTabsFn = async (newTabIndex) => {
  92. homeStore.changeTab(newTabIndex);
  93. goodsStore.resetParams();
  94. goodsStore.resetListData();
  95. if (showBackIcon.value) {
  96. router.back()
  97. }
  98. const tabCategoryId = categoryList.value[newTabIndex]?.categoryId;
  99. if (tabCategoryId) {
  100. await categoryStore.fetchChildListData({ type: '1', parentId: tabCategoryId });
  101. if (categoryStore.childList && categoryStore.childList.length > 0) {
  102. goodsStore.updateParams({
  103. categoryId: categoryStore.childList[0].categoryId || ''
  104. })
  105. goodsStore.fetchListData();
  106. }
  107. }
  108. }
  109. /**
  110. * 切换仓库, 切换仓库后需要将一切数据都重新加载,并且回到当前主页
  111. */
  112. const changeStoreFn = row => {
  113. storageStore.updateActivedId(row.storageId);
  114. window.location.href = '/';
  115. }
  116. const fetchNoticeData = async () => {
  117. const res = await getNotice();
  118. mainData.noticeContent = res.data || '';
  119. }
  120. // 获取友情链接
  121. const fetchgetAmityList = async () => {
  122. const res = await getAmityList()
  123. mainData.linkList = res.data || []
  124. }
  125. const handleLevelMsg = () => {
  126. mainData.msgOpen = true;
  127. mainData.contactUs = false;
  128. }
  129. const contactUsFn = () => {
  130. mainData.msgOpen = true;
  131. mainData.contactUs = true;
  132. }
  133. onMounted(async () => {
  134. await storageStore.fetchListData();
  135. // 判断本地存储仓库id是否存在
  136. if (storeList.value && storeList.value.length > 0) {
  137. if (storageStore.activedId) {
  138. const isExist = storeList.value.find(item => item.storageId == storageStore.activedId);
  139. if (!isExist) {
  140. storageStore.updateActivedId(storeList.value[0].storageId);
  141. }
  142. }
  143. fetchNoticeData();
  144. fetchgetAmityList();
  145. isLogin.value && userStore.fetchUserDetail();
  146. await categoryStore.fetchListData();
  147. const tabCategoryId = categoryList.value[tabIndex.value]?.categoryId;
  148. if (tabCategoryId) {
  149. await categoryStore.fetchChildListData({ type: '1', parentId: tabCategoryId });
  150. if (categoryStore.childList && categoryStore.childList.length > 0) {
  151. goodsStore.updateParams({
  152. categoryId: categoryStore.childList[0].categoryId || ''
  153. })
  154. goodsStore.fetchListData();
  155. }
  156. }
  157. }
  158. })
  159. </script>
  160. <style lang="less" scoped>
  161. .app-main__content {
  162. padding: 20px;
  163. }
  164. </style>