CollectModuleList.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. :enable="typeof item.enable === 'string' ? canCollect(item.enable) : item.enable"
  18. @click="handleClick(item)"
  19. />
  20. </FlexCol>
  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 { TaskMenuDef, type TaskMenuDefGoForm, type TaskMenuDefItem } from '../forms/tasks';
  28. import { alert } from '@/components/utils/DialogAction';
  29. import { getVillageInfoForm } from '../forms/forms';
  30. import { navTo } from '@/components/utils/PageAction';
  31. import { TaskRootDef } from '../forms/tasks';
  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. const { goForm } = useTaskEntryForm();
  37. const { canCollect, getCollectModuleInternalNameById } = useCollectStore();
  38. const props = defineProps<{
  39. villageId: number,
  40. villageVolunteerId: number,
  41. taskName: string,
  42. taskTitle: string,
  43. taskPid: number,
  44. }>();
  45. async function loadList() {
  46. const { villageId, taskName, taskPid } = props;
  47. if (taskName) {
  48. currentTaskDefItems.value = TaskMenuDef[taskName].list.concat();
  49. currentTaskBanner.value = TaskMenuDef[taskName].banner;
  50. } else {
  51. currentTaskDefItems.value = TaskRootDef
  52. }
  53. if (taskPid >= 0) {
  54. const res = (await VillageApi.getCatalogList(villageId, taskPid));
  55. if (res.length === 0)
  56. return;
  57. currentTaskDefItems.value = res
  58. .map(item => {
  59. try {
  60. const collectModuleInternalName = getCollectModuleInternalNameById(item.collectModuleId);
  61. if (!collectModuleInternalName && item.collectModuleId)
  62. throw new Error('不存在定义的表单数据');
  63. const formDefine = collectModuleInternalName ? getVillageInfoForm(collectModuleInternalName, -1) : undefined;
  64. return {
  65. ...item,
  66. enable: true,
  67. catalogItem: item,
  68. goForm: collectModuleInternalName ? [
  69. collectModuleInternalName,
  70. -1,
  71. formDefine?.[2].typeName,
  72. collectModuleInternalName === 'overview' ? 'common' : undefined,
  73. item.title
  74. ] as TaskMenuDefGoForm : undefined,
  75. onClick: () => {
  76. if (item.haschild) {
  77. navTo('/pages/dig/forms/task', {
  78. ...props,
  79. taskName: '',
  80. taskTitle: item.title,
  81. taskPid: item.id,
  82. })
  83. } else {
  84. alert({
  85. title: item.title,
  86. content: '不存在定义的表单数据',
  87. })
  88. }
  89. }
  90. }
  91. } catch (e) {
  92. return {
  93. ...item,
  94. desc: '' + e,
  95. enable: false,
  96. }
  97. }
  98. });
  99. }
  100. }
  101. watch(() => props.taskPid, loadList);
  102. onMounted(loadList);
  103. const currentTaskDefItems = ref<TaskMenuDefItem[]>([]);
  104. const currentTaskBanner = ref('');
  105. const handleClick = (item: TaskMenuDefItem) => {
  106. if (!item.enable) {
  107. uni.showToast({
  108. title: '您没有完成任务的权限,如需要请联系管理员',
  109. icon: 'none',
  110. duration: 2000
  111. });
  112. return;
  113. }
  114. if (item.goForm instanceof Array) {
  115. goForm(...item.goForm);
  116. return;
  117. }
  118. else if (item.goForm) {
  119. navTo('/pages/dig/forms/task', {
  120. ...props,
  121. taskName: item.goForm.name,
  122. taskTitle: item.title,
  123. taskPid: (item as any).id,
  124. })
  125. return;
  126. }
  127. if (item.onClick) {
  128. item.onClick();
  129. }
  130. }
  131. </script>