index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <view class="index" :style="{
  3. backgroundImage: tabIndex === 4 ?
  4. `url('https://xy.wenlvti.net/app_static/images/mine/TopBanner.png')`
  5. : `url('https://xy.wenlvti.net/app_static/images/home/BannerHome.png')`,
  6. backgroundRepeat: 'no-repeat',
  7. backgroundSize: '100% auto',
  8. backgroundPosition: 'top center',
  9. backgroundColor: themeContext.resolveThemeColor('background.primary'),
  10. }">
  11. <CommonRoot>
  12. <StatusBarSpace backgroundColor="transparent" />
  13. <NavBar
  14. :titleScroll="false"
  15. backgroundColor="transparent"
  16. textColor="whweixinite"
  17. align="left"
  18. :zIndex="200"
  19. />
  20. <HomeIndex v-show="tabIndex === 0" @goVillage="tabIndex = 1" @goDig="tabIndex = 2" />
  21. <VillageIndex v-if="tabIndex === 1" showSwitch ref="villageIndex" @goHome="tabIndex=0" />
  22. <DigIndex v-show="tabIndex === 2" />
  23. <DiscoverIndex v-show="tabIndex === 3" @goVillage="tabIndex = 1" />
  24. <UserIndex v-show="tabIndex === 4" @goSubmit="tabIndex = 2" />
  25. <TabBar
  26. v-model:selectedTabIndex="tabIndex"
  27. fixed
  28. xbarSpace
  29. :innerStyle="{
  30. zIndex: 201,
  31. backgroundColor: '#ffead8',
  32. }"
  33. >
  34. <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconHome.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconHomeActive.png" text="首页" :iconSize="70" />
  35. <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconVillage.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconVillageActive.png" text="乡源" :iconSize="70" />
  36. <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDig.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDigActive.png" text="挖掘" :iconSize="70" />
  37. <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDiscover.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconDiscoverActive.png" text="发现" :iconSize="70" />
  38. <TabBarItem icon="https://xy.wenlvti.net/app_static/images/tabs/TabIconMine.png" activeIcon="https://xy.wenlvti.net/app_static/images/tabs/TabIconMineActive.png" text="我的" :iconSize="70" />
  39. </TabBar>
  40. </CommonRoot>
  41. </view>
  42. </template>
  43. <script setup lang="ts">
  44. import { onMounted, ref, watch } from 'vue';
  45. import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
  46. import { useTheme } from '@/components/theme/ThemeDefine';
  47. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  48. import { useVillageStore } from '@/store/village';
  49. import { useAuthStore } from '@/store/auth';
  50. import { isDevEnv } from '@/common/config/AppCofig';
  51. import { navTo } from '@/components/utils/PageAction';
  52. import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
  53. import NavBar from '@/components/nav/NavBar.vue';
  54. import TabBar from '@/components/nav/TabBar.vue';
  55. import TabBarItem from '@/components/nav/TabBarItem.vue';
  56. import DigIndex from './home/dig.vue';
  57. import UserIndex from './user/index.vue';
  58. import HomeIndex from './home/index.vue';
  59. import DiscoverIndex from './home/discover/index.vue';
  60. import VillageIndex from './home/village/index.vue';
  61. import CommonRoot from '@/components/dialog/CommonRoot.vue';
  62. import LightVillageApi from '@/api/light/LightVillageApi';
  63. import { waitTimeOut } from '@imengyu/imengyu-utils';
  64. import { injectAppConfiguration } from '@/api/system/useAppConfiguration';
  65. const tabIndex = ref(0);
  66. const themeContext = useTheme();
  67. const villageStore = useVillageStore();
  68. const authStore = useAuthStore();
  69. const appConfiguration = injectAppConfiguration();
  70. const villageIndex = ref<InstanceType<typeof VillageIndex>>();
  71. const { querys } = useLoadQuerys({
  72. openLogin: false,
  73. villageId: 0,
  74. userId: 0,
  75. }, (querys) => {
  76. if (querys.openLogin) {
  77. navTo('/pages/user/login');
  78. }
  79. if (querys.villageId) {
  80. loadShareVillageInfo();
  81. }
  82. if (querys.userId) {
  83. villageStore.setShareFromVillageUserId(querys.userId);
  84. }
  85. });
  86. async function loadShareVillageInfo(id?: number) {
  87. try {
  88. const res = await LightVillageApi.getVillageDetails(id ?? querys.value.villageId as number);
  89. villageStore.setCurrentVillage(res);
  90. } catch (error) {
  91. console.error(error);
  92. return;
  93. }
  94. tabIndex.value = 1;
  95. }
  96. function getShareVillageInfo() {
  97. if (villageStore.currentVillage) {
  98. //分享村社信息
  99. const villageInfoInList = villageStore.myJoinedVillages.find(v => v.id === villageStore.currentVillage?.id);
  100. const myNickName = villageInfoInList?.villageNickname || authStore.userInfo?.nickname || authStore.userInfo?.username || '老友';
  101. return {
  102. title: `同乡 ${myNickName} 邀您回 ${villageStore.currentVillage.name} 看看,心系故土,携手共建美好家乡`,
  103. path: `/pages/index?villageId=${villageStore.currentVillage.id}&userId=${authStore.userInfo?.id || 0}`,
  104. imageUrl: villageStore.currentVillage.image || appConfiguration.value.sharePost.villageDefault,
  105. }
  106. }
  107. return {
  108. title: '村社文化资源挖掘平台',
  109. path: '/pages/index',
  110. imageUrl: appConfiguration.value.sharePost.default,
  111. };
  112. }
  113. async function paySuccessAndRefresh() {
  114. try {
  115. uni.showLoading({
  116. title: '请稍后...',
  117. });
  118. tabIndex.value = 0;
  119. await villageStore.reloadVillageInfo();
  120. await waitTimeOut(100);
  121. tabIndex.value = 1;
  122. } catch (error) {
  123. console.error(error);
  124. return;
  125. } finally {
  126. uni.hideLoading();
  127. }
  128. }
  129. watch(tabIndex, () => {
  130. uni.setStorageSync('lastTabIndex', tabIndex.value);
  131. uni.pageScrollTo({ scrollTop: 0, duration: 0 });
  132. });
  133. defineExpose({
  134. onPageBack: (name: string, data: Record<string, unknown>) => {
  135. if (name === 'goVillage') {
  136. tabIndex.value = 1;
  137. if (data.id) {
  138. loadShareVillageInfo(data.id as number);
  139. }
  140. if (data.taskType) {
  141. setTimeout(() => {
  142. switch (data.taskType) {
  143. case 'collect':
  144. villageIndex.value?.goCollectPage();
  145. break;
  146. case 'post':
  147. break;
  148. case 'tree':
  149. villageIndex.value?.goTreePage();
  150. break;
  151. }
  152. }, 500);
  153. }
  154. } else if (name === 'paySuccessAndRefresh') {
  155. paySuccessAndRefresh();
  156. } else {
  157. villageIndex.value?.onPageBack(name, data);
  158. }
  159. }
  160. })
  161. onShareAppMessage(() => {
  162. return getShareVillageInfo();
  163. })
  164. onShareTimeline(() => {
  165. return getShareVillageInfo();
  166. })
  167. onMounted(() => {
  168. if (isDevEnv) {
  169. tabIndex.value = Number(uni.getStorageSync('lastTabIndex') ?? 0);
  170. }
  171. })
  172. </script>