CollectModuleList.vue 4.2 KB

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