index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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
  21. ref="homeIndex"
  22. v-show="tabIndex === 0"
  23. :currentScrollTop="currentScrollTop"
  24. @goVillage="tabIndex = 1"
  25. @goDig="tabIndex = 2"
  26. />
  27. <VillageIndex
  28. v-if="tabIndex === 1"
  29. ref="villageIndex"
  30. showSwitch
  31. @goHome="tabIndex=0"
  32. @goMap="homeIndex?.goMap()"
  33. @goDiscover="tabIndex = 3"
  34. />
  35. <DigIndex v-show="tabIndex === 2" />
  36. <DiscoverIndex v-show="tabIndex === 3" @goVillage="tabIndex = 1" />
  37. <UserIndex v-show="tabIndex === 4" @goSubmit="tabIndex = 2" />
  38. <TabBar
  39. v-model:selectedTabIndex="tabIndex"
  40. fixed
  41. xbarSpace
  42. :innerStyle="{
  43. zIndex: 201,
  44. backgroundColor: '#ffead8',
  45. }"
  46. >
  47. <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" />
  48. <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" />
  49. <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" />
  50. <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" />
  51. <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" />
  52. </TabBar>
  53. </CommonRoot>
  54. <BackToTop
  55. ref="backToTop"
  56. customScrollValue
  57. :bottom="200"
  58. @click="handleScrollTop"
  59. @scroll="(v) => currentScrollTop = v"
  60. />
  61. </view>
  62. </template>
  63. <script setup lang="ts">
  64. import { onMounted, ref, watch } from 'vue';
  65. import { onPageScroll, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
  66. import { useTheme } from '@/components/theme/ThemeDefine';
  67. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  68. import { useVillageStore } from '@/store/village';
  69. import { useAuthStore } from '@/store/auth';
  70. import { useShareLink } from './home/composeabe/ShareLink';
  71. import { isDevEnv } from '@/common/config/AppCofig';
  72. import { navTo } from '@/components/utils/PageAction';
  73. import { waitTimeOut } from '@imengyu/imengyu-utils';
  74. import { injectAppConfiguration } from '@/api/system/useAppConfiguration';
  75. import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
  76. import NavBar from '@/components/nav/NavBar.vue';
  77. import TabBar from '@/components/nav/TabBar.vue';
  78. import TabBarItem from '@/components/nav/TabBarItem.vue';
  79. import DigIndex from './home/dig.vue';
  80. import UserIndex from './user/index.vue';
  81. import HomeIndex from './home/index.vue';
  82. import DiscoverIndex from './home/discover/index.vue';
  83. import VillageIndex from './home/village/index.vue';
  84. import CommonRoot from '@/components/dialog/CommonRoot.vue';
  85. import LightVillageApi from '@/api/light/LightVillageApi';
  86. import BackToTop from '@/components/feedback/BackToTop.vue';
  87. import OfficialApi from '@/api/light/OfficialApi';
  88. const tabIndex = ref(0);
  89. const themeContext = useTheme();
  90. const villageStore = useVillageStore();
  91. const authStore = useAuthStore();
  92. const appConfiguration = injectAppConfiguration();
  93. const { recommendUserId, setRecommendUserId } = useShareLink();
  94. const currentScrollTop = ref(0);
  95. const backToTop = ref<InstanceType<typeof BackToTop>>();
  96. const villageIndex = ref<InstanceType<typeof VillageIndex>>();
  97. const homeIndex = ref<InstanceType<typeof HomeIndex>>();
  98. const { querys } = useLoadQuerys({
  99. openLogin: false,
  100. villageId: 0,
  101. userId: 0,
  102. scene: '',
  103. }, (_querys) => {
  104. if (_querys.openLogin) {
  105. navTo('/pages/user/login');
  106. }
  107. if (_querys.scene) {
  108. const sp = _querys.scene.split(':');
  109. switch (sp[0]) {
  110. case 'invg':
  111. //处理从二维码进入村社情况
  112. if (sp.length >= 2)
  113. querys.value.villageId = Number(sp[1]);
  114. if (sp.length >= 3)
  115. setRecommendUserId(Number(sp[2]));
  116. break;
  117. case 'offical':
  118. //处理从推广文章返回跳转小程序点击量情况
  119. if (sp.length >= 3) {
  120. OfficialApi.traceOfficalLogApi('offical_card_clickback', {
  121. user_id: Number(sp[1]),
  122. wechat_content_id: Number(sp[2]),
  123. });
  124. setRecommendUserId(Number(sp[1]));
  125. }
  126. break;
  127. }
  128. }
  129. if (_querys.userId) {
  130. setRecommendUserId(Number(_querys.userId));
  131. }
  132. //普通分享进入村社情况
  133. if (querys.value.villageId) {
  134. loadShareVillageInfo();
  135. }
  136. });
  137. async function loadShareVillageInfo(id?: number) {
  138. try {
  139. const res = await LightVillageApi.getVillageDetails(id ?? querys.value.villageId as number);
  140. villageStore.setCurrentVillage(res);
  141. } catch (error) {
  142. console.error(error);
  143. return;
  144. }
  145. tabIndex.value = 1;
  146. }
  147. function getShareVillageInfo() {
  148. if (villageStore.currentVillage) {
  149. //分享村社信息
  150. const villageInfoInList = villageStore.myJoinedVillages.find(v => v.id === villageStore.currentVillage?.id);
  151. const myNickName = villageInfoInList?.villageNickname || authStore.userInfo?.nickname || authStore.userInfo?.username || '老友';
  152. return {
  153. title: `同乡 ${myNickName} 邀您回 ${villageStore.currentVillage.name} 看看,心系故土,携手共建美好家乡`,
  154. path: `/pages/index?scene=invg:${villageStore.currentVillage.id}:${authStore.userInfo?.id || 0}`,
  155. imageUrl: villageStore.currentVillage.image || appConfiguration.value.sharePost.villageDefault,
  156. }
  157. }
  158. return {
  159. title: '村社文化资源挖掘平台',
  160. path: '/pages/index?userId=' + (authStore.userId || 0),
  161. imageUrl: appConfiguration.value.sharePost.default,
  162. };
  163. }
  164. async function paySuccessAndRefresh() {
  165. try {
  166. uni.showLoading({
  167. title: '请稍后...',
  168. });
  169. tabIndex.value = 0;
  170. await villageStore.reloadVillageInfo();
  171. await waitTimeOut(100);
  172. tabIndex.value = 1;
  173. } catch (error) {
  174. console.error(error);
  175. return;
  176. } finally {
  177. uni.hideLoading();
  178. }
  179. }
  180. watch(tabIndex, () => {
  181. uni.setStorageSync('lastTabIndex', tabIndex.value);
  182. uni.pageScrollTo({ scrollTop: 0, duration: 0 });
  183. });
  184. onPageScroll((e) => {
  185. backToTop.value?.onScroll(e.scrollTop);
  186. });
  187. function handleScrollTop() {
  188. uni.pageScrollTo({ scrollTop: 0, duration: 300 });
  189. }
  190. defineExpose({
  191. onPageBack: (name: string, data: Record<string, unknown>) => {
  192. if (name === 'goVillage') {
  193. tabIndex.value = 1;
  194. if (data.id) {
  195. loadShareVillageInfo(data.id as number);
  196. }
  197. if (data.taskType) {
  198. setTimeout(() => {
  199. switch (data.taskType) {
  200. case 'collect':
  201. villageIndex.value?.goCollectPage();
  202. break;
  203. case 'post':
  204. break;
  205. case 'tree':
  206. villageIndex.value?.goTreePage();
  207. break;
  208. }
  209. }, 500);
  210. }
  211. } else if (name === 'paySuccessAndRefresh') {
  212. paySuccessAndRefresh();
  213. } else {
  214. villageIndex.value?.onPageBack(name, data);
  215. }
  216. }
  217. })
  218. onShareAppMessage(() => {
  219. return getShareVillageInfo();
  220. })
  221. onShareTimeline(() => {
  222. return getShareVillageInfo();
  223. })
  224. onMounted(() => {
  225. if (isDevEnv) {
  226. tabIndex.value = Number(uni.getStorageSync('lastTabIndex') ?? 0);
  227. }
  228. })
  229. </script>
  230. <style>
  231. .index {
  232. overflow-x: hidden;
  233. overflow-y: auto;
  234. }
  235. </style>