index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <FlexCol>
  3. <FlexCol :gap="20" :padding="[30,30,0,30]" :innerStyle="{
  4. marginTop: '-80px',
  5. backgroundImage: `url(${appConfiguration?.banners.homeTop})`,
  6. backgroundSize: '100% auto',
  7. backgroundRepeat: 'no-repeat',
  8. backgroundPosition: 'top center',
  9. backgroundColor: themeContext.resolveThemeColor('background.primary'),
  10. }">
  11. <FlexCol position="absolute" :left="30" :top="0" :right="30">
  12. <StatusBarSpace />
  13. <FlexRow justify="space-between" align="center">
  14. <Button
  15. @click="showCityPopup = true"
  16. icon="https://xy.wenlvti.net/app_static/images/home/IconSwitch.png"
  17. size="small"
  18. :text="currentCity"
  19. />
  20. <Image
  21. :src="appConfiguration?.banners.homeTitle"
  22. :width="140"
  23. :height="75"
  24. />
  25. <Width :width="150" />
  26. </FlexRow>
  27. </FlexCol>
  28. <Height height="150px" />
  29. <FlexCol :gap="20" align="center">
  30. <FlexRow justify="space-between" align="center" width="100%">
  31. <SearchBar
  32. v-model="searchKeywords"
  33. placeholder="搜索"
  34. :innerStyle="{
  35. backgroundColor: 'white',
  36. borderRadius: '20rpx',
  37. borderWidth: '1px',
  38. borderStyle: 'solid',
  39. borderColor: themeContext.resolveThemeColor('primary'),
  40. width: '630rpx',//490rpx
  41. }"
  42. @search="handleSearch"
  43. />
  44. <!-- <Button icon="ai-thinking" @click="handleGoAI" text="问AI" /> -->
  45. </FlexRow>
  46. <ImageSwiper
  47. :images="appConfiguration?.banners.home"
  48. :height="460"
  49. :width="700"
  50. radius="radius.md"
  51. :innerStyle="{
  52. border: '1px solid #fff',
  53. overflow: 'hidden',
  54. clipPath: 'ellipse(100% 90% at 50% 0%)'
  55. }"
  56. />
  57. </FlexCol>
  58. <LightMap
  59. small
  60. :city="currentCity"
  61. :lonlat="currentLocation.currentLonlat.value"
  62. @getCurrentLonlat="currentLocation.getCurrentExactLocation"
  63. @selectVillage="handleGoVillageDetails"
  64. @regionChanged="currentRegion=$event"
  65. >
  66. <NoticeBar
  67. v-if="currentNoticeContent"
  68. :content="currentNoticeContent"
  69. :innerStyle="{
  70. position: 'absolute',
  71. top: '20rpx',
  72. left: '20rpx',
  73. right: '20rpx',
  74. zIndex: 100,
  75. borderRadius: '30rpx',
  76. }"
  77. :textStyle="{
  78. fontSize: '26rpx',
  79. }"
  80. icon="https://xy.wenlvti.net/app_static/images/home/IconLightActive.png"
  81. :iconProps="{
  82. size: 34,
  83. }"
  84. textColor="#C9211F"
  85. backgroundColor="#D9492E10"
  86. />
  87. </LightMap>
  88. <FlexRow justify="space-between" :padding="[10, 16]" gap="gap.md">
  89. <Button
  90. icon="https://xy.wenlvti.net/app_static/images/home/IconSwitch.png"
  91. radius="radius.lg"
  92. :padding="[10, 30]"
  93. @click="showCityPopup = true"
  94. >
  95. 切换城市
  96. </Button>
  97. <Button
  98. icon="https://xy.wenlvti.net/app_static/images/home/IconFollow.png"
  99. radius="radius.lg" :padding="[10, 30]"
  100. @click="showMyFollowPopup = true"
  101. >
  102. 我的关注
  103. </Button>
  104. <Button
  105. icon="https://xy.wenlvti.net/app_static/images/home/IconLight.png"
  106. radius="radius.lg" :padding="[10, 30]"
  107. @click="handleLightVillage"
  108. >
  109. 点亮村社
  110. </Button>
  111. </FlexRow>
  112. <!-- <HomeTitle title="最新动态" />
  113. <Construction text="测试数据,没有接口!">
  114. <FlexCol gap="gap.lg">
  115. <FlexRow
  116. v-for="item in activityLoader.content.value" :key="item.id"
  117. backgroundColor="background.tertiary"
  118. radius="radius.md"
  119. :padding="[20, 30]"
  120. gap="gap.lg"
  121. align="center"
  122. >
  123. <Avatar
  124. :url="item.head"
  125. :size="80"
  126. :round="false"
  127. :radius="10"
  128. />
  129. <Text :text="item.content" fontConfig="contentText" :innerStyle="{ flex: 1 }" />
  130. </FlexRow>
  131. </FlexCol>
  132. </Construction> -->
  133. <HomeTitle title="乡村排名" showMore @moreClicked="navTo('/pages/home/village/rank/village', {
  134. regionId: currentRegion ?? undefined,
  135. })" />
  136. <VillageRankList :list="villageRankListLoader.content.value ?? []" :jumpToSingle="false" @goDetails="handleGoVillageDetails" />
  137. <HomeTitle title="志愿者排名" showMore :lightCount="3" @moreClicked="navTo('/pages/home/village/rank/volunteer', {
  138. regionId: currentRegion ?? undefined,
  139. })" />
  140. <VillageUserRankList
  141. :list="villageUserRankListLoader.content.value ?? []"
  142. scoreSuffix="积分"
  143. @goDetails="navTo('/pages/home/village/volunteer/detail', { id: $event.id })"
  144. />
  145. <HomeTitle title="精选记忆">
  146. <template #right>
  147. <Touchable
  148. :padding="[15, 20]"
  149. :innerStyle="{ marginRight: '20rpx' }"
  150. direction="row"
  151. center
  152. gap="gap.md"
  153. @click="handleGoPublish()"
  154. >
  155. <Icon name="https://xy.wenlvti.net/app_static/images/village/IconLargeHistory.png" :size="30" />
  156. <Text text="AI帮你写" fontConfig="contentText" />
  157. </Touchable>
  158. </template>
  159. </HomeTitle>
  160. <SimplePageListLoader :loader="recommendLoader">
  161. <MasonryGrid>
  162. <MasonryGridItem
  163. v-for="(item, i) in recommendLoader.list.value"
  164. :key="i"
  165. :width="340"
  166. >
  167. <IndexCommonImageItem
  168. :image="item.image"
  169. :title="item.title"
  170. :desc="item.content ?? ''"
  171. :userName="item.villageVolunteerName ?? ''"
  172. :likes="0"
  173. :isLike="false"
  174. @click="handleGoRecommendDetails(item)"
  175. />
  176. </MasonryGridItem>
  177. </MasonryGrid>
  178. </SimplePageListLoader>
  179. </FlexCol>
  180. <Height :height="200" />
  181. <Popup
  182. v-model:show="showCityPopup"
  183. closeable
  184. position="top"
  185. size="90vh"
  186. >
  187. <CitySelect @selectCity="handleSelectCity" />
  188. </Popup>
  189. <Popup
  190. v-model:show="showMyFollowPopup"
  191. closeable
  192. position="bottom"
  193. round
  194. size="80vh"
  195. >
  196. <VillageMyFollow @handleGoVillageDetails="handleGoRecommendDetails" />
  197. </Popup>
  198. <IntroClamTip ref="introClamTipRef" @apply="handleLightVillage" />
  199. </FlexCol>
  200. </template>
  201. <script setup lang="ts">
  202. import { onMounted, ref, watch } from 'vue';
  203. import { useTheme } from '@/components/theme/ThemeDefine';
  204. import { useSimpleDataLoader } from '@/components/composeabe/loader/SimpleDataLoader';
  205. import { useStorageVar } from '@/components/composeabe/StorageVar';
  206. import { useVillageStore } from '@/store/village';
  207. import { useGetCurrentLocation } from './composeabe/GetCurrentLocation';
  208. import { useAuthStore } from '@/store/auth';
  209. import { useRequireLogin } from '@/common/composeabe/RequireLogin';
  210. import { useOfficialAccount } from './composeabe/OfficialAccount';
  211. import { useUserTools } from '@/common/composeabe/UserTools';
  212. import { ArrayUtils, waitTimeOut } from '@imengyu/imengyu-utils';
  213. import { toast } from '@/components/utils/DialogAction';
  214. import { navTo } from '@/components/utils/PageAction';
  215. import { injectAppConfiguration } from '@/api/system/useAppConfiguration';
  216. import Image from '@/components/basic/Image.vue';
  217. import FlexCol from '@/components/layout/FlexCol.vue';
  218. import FlexRow from '@/components/layout/FlexRow.vue';
  219. import Height from '@/components/layout/space/Height.vue';
  220. import SearchBar from '@/components/form/SearchBar.vue';
  221. import Button from '@/components/basic/Button.vue';
  222. import HomeTitle from '@/common/components/parts/HomeTitle.vue';
  223. import VillageRankList from './components/VillageRankList.vue';
  224. import VillageUserRankList from './components/VillageUserRankList.vue';
  225. import Popup from '@/components/dialog/Popup.vue';
  226. import CitySelect from './components/CitySelect.vue';
  227. import VillageMyFollow from './components/VillageMyFollow.vue';
  228. import MapApi from '@/api/map/MapApi';
  229. import LightMap from './components/LightMap.vue';
  230. import NoticeBar from '@/components/display/NoticeBar.vue';
  231. import StatusBarSpace from '@/components/layout/space/StatusBarSpace.vue';
  232. import LightVillageApi, { VillageListItem } from '@/api/light/LightVillageApi';
  233. import type { CityItem } from '@/api/map/MapApi';
  234. import Width from '@/components/layout/space/Width.vue';
  235. import MasonryGrid from '@/components/layout/masonry/MasonryGrid.vue';
  236. import MasonryGridItem from '@/components/layout/masonry/MasonryGridItem.vue';
  237. import IndexCommonImageItem from '@/common/components/parts/IndexCommonImageItem.vue';
  238. import IntroClamTip from './village/dialogs/IntroClamTip.vue';
  239. import MemoryTimeOut from '@/components/composeabe/MemoryTimeOut';
  240. import Touchable from '@/components/feedback/Touchable.vue';
  241. import Icon from '@/components/basic/Icon.vue';
  242. import Text from '@/components/basic/Text.vue';
  243. import ImageSwiper from '@/common/components/parts/ImageSwiper.vue';
  244. import { useSimplePageListLoader } from '@/components/composeabe/loader/SimplePageListLoader';
  245. import VillageInfoApi, { type CommonInfoModel } from '@/api/inhert/VillageInfoApi';
  246. import SimplePageListLoader from '@/components/loader/SimplePageListLoader.vue';
  247. const emit = defineEmits(['goVillage']);
  248. const authStore = useAuthStore();
  249. const villageStore = useVillageStore();
  250. const themeContext = useTheme();
  251. const { requireLogin } = useRequireLogin();
  252. const { getIsVolunteer } = useUserTools();
  253. const searchKeywords = ref('');
  254. const showCityPopup = ref(false);
  255. const showMyFollowPopup = ref(false);
  256. const introClamTipRef = ref();
  257. const introClamTipTimeout = new MemoryTimeOut('IntroClamTip', 1000 * 3600 * 30);//30h
  258. const appConfiguration = injectAppConfiguration();
  259. const currentRegion = ref<number | null>(null);
  260. const { value: currentCity } = useStorageVar('currentCityName', '');
  261. const currentLocation = useGetCurrentLocation({
  262. onCityChanged: (city) => {
  263. currentCity.value = city;
  264. },
  265. });
  266. const currentNoticeContent = ref('目前厦门市已被点亮一个社区,刚刚小亮贡献了10个光源,让湖里区点亮了一个社区');
  267. const villageRankListLoader = useSimpleDataLoader(async () => {
  268. const res = await LightVillageApi.getVillageRankList({ region_id: currentRegion.value ?? undefined, num: 3 });
  269. return res.map((item, i) => ({
  270. image: item.image ?? '',
  271. title: item.name,
  272. rank: i + 1,
  273. id: item.id,
  274. }));
  275. });
  276. const villageUserRankListLoader = useSimpleDataLoader(async () => {
  277. const res = (await LightVillageApi.getVolunteerRankList({ region_id: currentRegion.value ?? undefined, num: 3 }))
  278. .map((item, i) => ({
  279. id: item.id,
  280. image: item.image ?? '',
  281. title: item.name,
  282. rank: i + 1,
  283. score: item.points,
  284. }));
  285. if (res.length >= 3) {
  286. //移动第一名到中间
  287. const first = res[0];
  288. ArrayUtils.removeAt(res, 0);
  289. ArrayUtils.insert(res, 1, first);
  290. }
  291. return res
  292. });
  293. const activityLoader = useSimpleDataLoader(async () => {
  294. return [
  295. {
  296. id: 1,
  297. head: 'https://mn.wenlvti.net/app_static/minnan/images/test/ImageTest1.png',
  298. content: '测试数据,没有接口!:福泽乡里 为全村加成+10%乡源果,可持续24小时',
  299. levelText: '一级',
  300. },
  301. {
  302. id: 2,
  303. head: 'https://mn.wenlvti.net/app_static/minnan/images/test/ImageTest2.png',
  304. content: '福泽乡里 为全村加成+10%乡源果,可持续24小时',
  305. levelText: '五级',
  306. },
  307. {
  308. id: 3,
  309. head: 'https://mn.wenlvti.net/app_static/minnan/images/test/ImageTest3.png',
  310. content: '福泽乡里 为全村加成+10%乡源果,可持续24小时',
  311. levelText: '十级',
  312. },
  313. ];
  314. });
  315. const recommendLoader = useSimplePageListLoader(20, async (page, pageSize) => {
  316. return await VillageInfoApi.getListForDiscover(page, pageSize);
  317. }, true);
  318. watch(currentRegion, async (newVal) => {
  319. await villageRankListLoader.reload();
  320. await villageUserRankListLoader.reload();
  321. });
  322. function handleGoRecommendDetails(item: CommonInfoModel) {
  323. navTo(`/pages/home/discover/details`, { id: item.id });
  324. }
  325. async function handleGoVillageDetails(item: VillageListItem) {
  326. showMyFollowPopup.value = false;
  327. const details = await LightVillageApi.getVillageDetails(item.id);
  328. villageStore.setCurrentVillage(details);
  329. await waitTimeOut(100);
  330. emit('goVillage')
  331. }
  332. async function handleChangedCity(city: string) {
  333. currentCity.value = city;
  334. try {
  335. const res = (await MapApi.simpleGetRegion(city)).requireData();
  336. currentLocation.currentLonlat.value = {
  337. longitude: Number(res.center.split(',')[0]),
  338. latitude: Number(res.center.split(',')[1]),
  339. };
  340. console.log('currentLocation.currentLonlat.value', currentLocation.currentLonlat.value);
  341. } catch (error) {
  342. console.error(error);
  343. return;
  344. }
  345. }
  346. function handleSelectCity(city: CityItem) {
  347. currentCity.value = city.name;
  348. showCityPopup.value = false;
  349. handleChangedCity(city.name);
  350. }
  351. function handleGoAI() {
  352. requireLogin(async () => {
  353. navTo('/pages/chat/index');
  354. }, '暂时需要登录后才能使用AI助手');
  355. }
  356. async function handleGoPublish() {
  357. requireLogin(async () => {
  358. navTo('/pages/chat/dependent/post/publish', { tag: '亮乡源' });
  359. }, '欢迎使用AI助手,登录后以便使用更多功能哦!');
  360. }
  361. async function handleLightVillage() {
  362. requireLogin(async () => navTo('/pages/home/light/submit-map', { city: currentCity.value }), '登录后才能点亮村社哦!');
  363. }
  364. function handleSearch() {
  365. if (!searchKeywords.value) {
  366. toast('请输入搜索关键词');
  367. return;
  368. }
  369. navTo('/pages/home/search/index', {
  370. region: currentRegion.value ?? 0,
  371. searchValue: searchKeywords.value,
  372. });
  373. }
  374. async function loadInfo() {
  375. //如果不是志愿者,则显示认领村庄提示
  376. const isVolunteer = await getIsVolunteer();
  377. if (!isVolunteer) {
  378. if (introClamTipTimeout.isTimeout()) {
  379. introClamTipRef.value?.show();
  380. introClamTipTimeout.recordTime();
  381. }
  382. }
  383. //加载我的关注村庄
  384. await villageStore.loadMyFollowVillages();
  385. await villageStore.loadMyJoinedVillages();
  386. if (villageStore.myFollowVillages.length > 0) {
  387. const currentVillage = villageStore.loadCurrentVillage();
  388. if (currentVillage) {
  389. villageStore.setCurrentVillage(villageStore.myFollowVillages.find(p => p.id === currentVillage) as VillageListItem || villageStore.myFollowVillages[0]);
  390. } else {
  391. villageStore.setCurrentVillage(villageStore.myFollowVillages[0] as VillageListItem);
  392. }
  393. }
  394. }
  395. watch(() => authStore.isLogged, async (newVal) => {
  396. if (newVal) {
  397. await loadInfo();
  398. }
  399. });
  400. onMounted(async () => {
  401. try {
  402. if (currentCity.value) {
  403. await currentLocation.setCurrentLocationWithCity(currentCity.value);
  404. } else {
  405. await currentLocation.getCurrentFuzzyLocation();
  406. }
  407. } catch (error) {
  408. console.error(error);
  409. toast('获取当前位置失败,您可以手动选择城市');
  410. }
  411. await loadInfo();
  412. });
  413. </script>