index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <com-head
  3. :options="options"
  4. v-model="currentTypeId"
  5. notContent
  6. v-if="options.length"
  7. />
  8. <div class="body-layer media">
  9. <div class="body-head media-head">
  10. <el-button type="primary" class="btn" @click="handleUploadClick">
  11. 上传
  12. </el-button>
  13. <el-tabs
  14. v-model="subTabName"
  15. class="sub-tab"
  16. @tab-click="handleSubtabClick"
  17. >
  18. <el-tab-pane
  19. v-for="sub in subOptions"
  20. :label="sub.name"
  21. :name="sub.value"
  22. >
  23. <div class="media-list" v-if="files.length">
  24. <div v-for="file in files" class="cover" @click="handerPhotoEdit">
  25. <img :src="file.filesUrl" />
  26. <span class="title">{{ file.filesTitle }}</span>
  27. </div>
  28. </div>
  29. <el-empty v-else class="empty"></el-empty>
  30. </el-tab-pane>
  31. </el-tabs>
  32. </div>
  33. </div>
  34. </template>
  35. <script setup lang="ts">
  36. import { onMounted, ref, computed, watchEffect, watch } from "vue";
  37. import comHead from "@/components/head/index.vue";
  38. import { title, desc } from "@/store/system";
  39. import {
  40. CaseFile,
  41. CaseFileType,
  42. getCaseFileTypesQuery,
  43. getCaseFiles,
  44. delCaseFile,
  45. BoardType,
  46. } from "@/store/caseFile";
  47. import { getCaseInfo } from "@/store/case";
  48. import { RouteName, router } from "@/router";
  49. import { addCaseFile } from "../case/quisk";
  50. const caseId = computed(() => {
  51. const caseId = router.currentRoute.value.params.caseId;
  52. if (caseId) {
  53. return Number(caseId);
  54. }
  55. });
  56. const currentTypeId = ref<number>();
  57. const options = ref<{ name: string; value: number; childKey?: string }[]>([]);
  58. const subOptions = ref<{ name: string; value: number }[]>([]);
  59. const files = ref<CaseFile[]>([]);
  60. const subTabName = ref();
  61. const handleSubtabClick = (value: number) => {
  62. // console.log("handleSubtabClick", value);
  63. // currentTypeId.value = value;
  64. };
  65. const handleUploadClick = async () => {
  66. console.log("handleUploadClick");
  67. await addCaseFile({ caseId: caseId.value!, fileType: subTabName.value! });
  68. refresh();
  69. };
  70. const handerPhotoEdit = () => {
  71. console.log("handerPhotoEdit");
  72. };
  73. const initDefaultData = async () => {
  74. const data = await getCaseFileTypesQuery("library");
  75. const rootList = data.map((item) => {
  76. return {
  77. name: item.filesTypeName,
  78. value: item.filesTypeId,
  79. childKey: item.childKey,
  80. };
  81. });
  82. options.value = rootList;
  83. currentTypeId.value = rootList[0].value;
  84. const secondData = rootList[0].childKey
  85. ? await getCaseFileTypesQuery(rootList[0].childKey)
  86. : [];
  87. const secondList = secondData.map((item) => {
  88. return {
  89. name: item.filesTypeName,
  90. value: item.filesTypeId,
  91. };
  92. });
  93. subTabName.value = secondList[0].value;
  94. subOptions.value = secondList;
  95. };
  96. watchEffect(() => caseId.value && subTabName.value && refresh());
  97. watch(currentTypeId, async (nVal, oVal) => {
  98. if (oVal && nVal !== oVal) {
  99. //切换时
  100. const root = options.value.find((i) => i.value === nVal);
  101. if (root) {
  102. const secondData = root.childKey
  103. ? await getCaseFileTypesQuery(root.childKey)
  104. : [];
  105. const secondList = secondData.map((item) => {
  106. return {
  107. name: item.filesTypeName,
  108. value: item.filesTypeId,
  109. };
  110. });
  111. subTabName.value = secondList[0].value;
  112. subOptions.value = secondList;
  113. }
  114. // const data = await getCaseFileTypesQuery("library");
  115. }
  116. });
  117. const refreshRoot = async () => {
  118. console.log("refreshRoot");
  119. };
  120. const refresh = async () => {
  121. files.value = await getCaseFiles({
  122. caseId: caseId.value!,
  123. filesTypeId: subTabName.value,
  124. });
  125. };
  126. onMounted(async () => {
  127. const caseInfo = await getCaseInfo(caseId.value!);
  128. if (caseInfo) {
  129. title.value = (await getCaseInfo(caseId.value!)).caseTitle + " | 媒体库";
  130. desc.value = "";
  131. } else {
  132. console.error("该案件不存在!");
  133. router.replace({ name: RouteName.vrmodel });
  134. }
  135. console.log("caseId", caseId.value);
  136. initDefaultData();
  137. });
  138. </script>
  139. <style lang="scss" scoped>
  140. @import url("./index.scss");
  141. </style>