CollectModuleList.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <FlexCol>
  3. <Image
  4. v-if="currentTaskBanner"
  5. :src="currentTaskBanner"
  6. :radius="20"
  7. :width="690"
  8. mode="widthFix"
  9. />
  10. <FlexCol :gap="20">
  11. <TaskList
  12. v-for="item in currentTaskDefItems"
  13. :key="item.title"
  14. :icon="item.icon"
  15. :title="item.title"
  16. :desc="item.desc"
  17. :extra="item.extra"
  18. :goButtonText="isView ? '查看' : '去采集'"
  19. :enable="typeof item.enable === 'string' ? canCollect(item.enable) : item.enable"
  20. @click="handleClick(item)"
  21. />
  22. </FlexCol>
  23. </FlexCol>
  24. </template>
  25. <script setup lang="ts">
  26. import { onMounted, ref, watch } from 'vue';
  27. import { useCollectStore } from '@/store/collect';
  28. import { useTaskEntryForm } from '../forms/composeable/TaskEntryForm';
  29. import { type TaskMenuDefGoForm, type TaskMenuDefItem } from '../forms/tasks';
  30. import { alert } from '@/components/utils/DialogAction';
  31. import { getVillageInfoForm } from '../forms/forms';
  32. import { navTo } from '@/components/utils/PageAction';
  33. import FlexCol from '@/components/layout/FlexCol.vue';
  34. import Image from '@/components/basic/Image.vue';
  35. import TaskList from '../components/TaskList.vue';
  36. import VillageApi from '@/api/inhert/VillageApi';
  37. import { useAuthStore } from '@/store/auth';
  38. import { waitTimeOut } from '@imengyu/imengyu-utils';
  39. const { goForm, goPreviewForm } = useTaskEntryForm();
  40. const authStore = useAuthStore();
  41. const { canCollect, canCollectCatalog, getCollectModuleInternalNameById, collectableCatalogs } = useCollectStore();
  42. const props = withDefaults(defineProps<{
  43. villageId: number,
  44. villageVolunteerId: number,
  45. taskTitle: string,
  46. taskPid: number,
  47. isView?: boolean,
  48. }>(), {
  49. isView: false,
  50. });
  51. async function loadList() {
  52. await waitTimeOut(400);
  53. const res = (await VillageApi.getCatalogList(
  54. props.villageId,
  55. authStore.isAdmin ? undefined : props.villageVolunteerId,
  56. props.taskPid
  57. ));
  58. if (res.length === 0)
  59. return;
  60. currentTaskDefItems.value = res
  61. .map(item => {
  62. try {
  63. const collectModuleInternalName = getCollectModuleInternalNameById(item.collectModuleId);
  64. const formDefine = collectModuleInternalName ? getVillageInfoForm(collectModuleInternalName, -1) : undefined;
  65. return {
  66. ...item,
  67. extra: authStore.isAdmin && item.total >= 0 ? `已采编 ${item.total}` : '',
  68. enable: canCollectCatalog(item.id) || collectModuleInternalName,
  69. catalogItem: item,
  70. goForm: !item.haschild && collectModuleInternalName ? [
  71. collectModuleInternalName,
  72. item.typeId ?? -1,
  73. formDefine?.[2].typeName,
  74. collectModuleInternalName === 'overview' ? 'common' : undefined,
  75. item.title,
  76. item.id
  77. ] as TaskMenuDefGoForm : undefined,
  78. onClick: () => {
  79. if (item.haschild) {
  80. navTo('/pages/dig/forms/task', {
  81. ...props,
  82. taskTitle: item.title,
  83. taskPid: item.id,
  84. isView: props.isView,
  85. })
  86. } else {
  87. alert({
  88. title: item.title,
  89. content: '您暂无权限采集该板块',
  90. })
  91. }
  92. }
  93. }
  94. } catch (e) {
  95. return {
  96. ...item,
  97. desc: '' + (e instanceof Error ? e.message : e),
  98. enable: false,
  99. }
  100. }
  101. });
  102. }
  103. watch(() => props.taskPid, loadList);
  104. onMounted(loadList);
  105. const currentTaskDefItems = ref<TaskMenuDefItem[]>([]);
  106. const currentTaskBanner = ref('');
  107. const handleClick = (item: TaskMenuDefItem) => {
  108. if (!item.enable && !authStore.isAdmin) {
  109. uni.showToast({
  110. title: '您没有完成任务的权限,如需要请联系管理员',
  111. icon: 'none',
  112. duration: 2000
  113. });
  114. return;
  115. }
  116. if (item.goForm instanceof Array) {
  117. if (props.isView)
  118. goPreviewForm(...item.goForm);
  119. else
  120. goForm(...item.goForm);
  121. return;
  122. }
  123. else if (item.goForm) {
  124. navTo('/pages/dig/forms/task', {
  125. ...props,
  126. taskTitle: item.title,
  127. taskPid: (item as any).id,
  128. isView: props.isView,
  129. })
  130. return;
  131. }
  132. if (item.onClick) {
  133. item.onClick();
  134. }
  135. }
  136. </script>