list.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <FlexCol :padding="30">
  3. <FlexRow justify="space-between">
  4. <SearchBar
  5. v-model="searchText"
  6. placeholder="搜一搜"
  7. :innerStyle="{ width: querys.isView ? '600rpx' : '460rpx' }"
  8. @confirm="search"
  9. />
  10. <Button v-if="!querys.isView" type="primary" @click="newData">+ 新增</Button>
  11. </FlexRow>
  12. <Height :height="20" />
  13. <FlexCol :gap="20">
  14. <Touchable
  15. v-for="item in listLoader.list.value"
  16. :key="item.id"
  17. :gap="20"
  18. :padding="[15,20]"
  19. :radius="15"
  20. align="center"
  21. backgroundColor="white"
  22. direction="row"
  23. touchable
  24. @click="goDetail(item.id)"
  25. >
  26. <Image
  27. :src="item.image"
  28. defaultImage="https://mn.wenlvti.net/app_static/minnan/EmptyImage.png"
  29. failedImage="https://mn.wenlvti.net/app_static/minnan/EmptyImage.png"
  30. :showFailed="false"
  31. :width="100"
  32. :height="100"
  33. :radius="10"
  34. mode="aspectFill"
  35. round
  36. />
  37. <FlexCol>
  38. <H4 :size="36">{{ item.title }}</H4>
  39. <Text :size="23">{{ item.desc }}</Text>
  40. </FlexCol>
  41. </Touchable>
  42. </FlexCol>
  43. <SimplePageListLoader :loader="listLoader" :noEmpty="true">
  44. <template #empty>
  45. <Empty v-if="querys.isView" image="search" description="暂无数据,等待志愿者编写中..." />
  46. <Empty v-else image="search" description="这里还没有数据,快来编写完善吧!">
  47. <Height :height="40" />
  48. <Button type="primary" :text="`+ 新增${subTitle}数据`" @click="newData" />
  49. </Empty>
  50. </template>
  51. </SimplePageListLoader>
  52. <XBarSpace />
  53. </FlexCol>
  54. </template>
  55. <script setup lang="ts">
  56. import { ref } from 'vue';
  57. import { onPullDownRefresh } from '@dcloudio/uni-app';
  58. import { alert } from '@/components/dialog/CommonRoot';
  59. import { DataDateUtils } from '@imengyu/js-request-transform';
  60. import { useSimplePageListLoader } from '@/common/composeabe/SimplePageListLoader';
  61. import { useLoadQuerys } from '@/common/composeabe/LoadQuerys';
  62. import { useCollectStore } from '@/store/collect';
  63. import { useAuthStore } from '@/store/auth';
  64. import { navTo } from '@/components/utils/PageAction';
  65. import SimplePageListLoader from '@/common/components/SimplePageListLoader.vue';
  66. import VillageInfoApi from '@/api/inhert/VillageInfoApi';
  67. import Image from '@/components/basic/Image.vue';
  68. import Empty from '@/components/feedback/Empty.vue';
  69. import Button from '@/components/basic/Button.vue';
  70. import SearchBar from '@/components/form/SearchBar.vue';
  71. import FlexCol from '@/components/layout/FlexCol.vue';
  72. import FlexRow from '@/components/layout/FlexRow.vue';
  73. import Text from '@/components/basic/Text.vue';
  74. import Height from '@/components/layout/space/Height.vue';
  75. import H4 from '@/components/typography/H4.vue';
  76. import Touchable from '@/components/feedback/Touchable.vue';
  77. import XBarSpace from '@/components/layout/space/XBarSpace.vue';
  78. const subTitle = ref('');
  79. const searchText = ref('');
  80. const collectStore = useCollectStore();
  81. const authStore = useAuthStore();
  82. const listLoader = useSimplePageListLoader<{
  83. id: number,
  84. image: string,
  85. title: string,
  86. desc: string
  87. }, {
  88. villageId: number,
  89. villageVolunteerId: number,
  90. subType: string,
  91. subId: number,
  92. subKey: string,
  93. }>(8, async (page, pageSize, params) => {
  94. if (!params )
  95. throw new Error("未传入参数,当前页面需要参数");
  96. if (!params.subType)
  97. throw new Error("params.subType");
  98. if (!params.villageId)
  99. throw new Error("params.villageId");
  100. if (!params.villageVolunteerId)
  101. throw new Error("params.villageId");
  102. let res = await VillageInfoApi.getList(
  103. collectStore.getCollectModuleId(params.subType),
  104. params.subType,
  105. params.subKey ? params.subId : undefined,
  106. params.subKey,
  107. params.villageId,
  108. querys.value.isView && authStore.isAdmin ? undefined : params.villageVolunteerId,
  109. querys.value.catalogId,
  110. page,
  111. pageSize,
  112. )
  113. if (searchText.value)
  114. res = res.filter((p) => p.title.includes(searchText.value));
  115. const list = res.map((item) => {
  116. return {
  117. id: item.id,
  118. image: item.image,
  119. title: item.title,
  120. desc: DataDateUtils.formatDate(item.updatedAt, 'YYYY-MM-dd') + (
  121. authStore.isAdmin ? (' 投稿人:' + item.villageVolunteerName) : ''
  122. )
  123. }
  124. })
  125. return {
  126. list: list,
  127. total: list.length,
  128. };
  129. });
  130. function newData() {
  131. if (querys.value.isView) {
  132. alert({ title: '提示', content: "查看模式下不能新增数据" });
  133. return;
  134. }
  135. navTo('common', {
  136. id: -1,
  137. villageId: querys.value.villageId,
  138. villageVolunteerId: querys.value.villageVolunteerId,
  139. catalogId: querys.value.catalogId,
  140. subType: querys.value.subType,
  141. subId: querys.value.subId,
  142. });
  143. }
  144. function goDetail(id: number) {
  145. navTo('common', {
  146. id,
  147. villageId: querys.value.villageId,
  148. villageVolunteerId: querys.value.villageVolunteerId,
  149. catalogId: querys.value.catalogId,
  150. subType: querys.value.subType,
  151. subKey: querys.value.subKey,
  152. subId: querys.value.subId,
  153. subTitle: querys.value.subTitle,
  154. isView: querys.value.isView,
  155. });
  156. }
  157. function search() {
  158. listLoader.loadData(undefined, true);
  159. }
  160. const { querys } = useLoadQuerys({
  161. villageId: 0,
  162. villageVolunteerId: 0,
  163. catalogId: 0,
  164. subType: '',
  165. subKey: '',
  166. subId: 0,
  167. subTitle: '',
  168. isView: false,
  169. }, async (querys) => {
  170. if (querys.subTitle) {
  171. subTitle.value = querys.subTitle;
  172. uni.setNavigationBarTitle({ title: subTitle.value + '列表', })
  173. }
  174. listLoader.loadData(querys)
  175. });
  176. onPullDownRefresh(() => {
  177. listLoader.loadData(undefined, true);
  178. });
  179. defineExpose({
  180. onPageBack(name: string, param: any) {
  181. if (param && param.needRefresh)
  182. listLoader.loadData(undefined, true);
  183. }
  184. })
  185. </script>