index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 { RouteName, router } from "@/router";
  48. import { addCaseFile } from "../case/quisk";
  49. const caseId = computed(() => {
  50. const caseId = router.currentRoute.value.params.caseId;
  51. if (caseId) {
  52. return Number(caseId);
  53. }
  54. });
  55. const currentTypeId = ref<number>();
  56. const options = ref<{ name: string; value: number; childKey?: string }[]>([]);
  57. const subOptions = ref<{ name: string; value: number }[]>([]);
  58. const files = ref<CaseFile[]>([]);
  59. const subTabName = ref();
  60. const handleSubtabClick = (value: number) => {
  61. // console.log("handleSubtabClick", value);
  62. // currentTypeId.value = value;
  63. };
  64. const handleUploadClick = async () => {
  65. console.log("handleUploadClick");
  66. await addCaseFile({ caseId: caseId.value!, fileType: subTabName.value! });
  67. refresh();
  68. };
  69. const handerPhotoEdit = () => {
  70. console.log("handerPhotoEdit");
  71. };
  72. const initDefaultData = async () => {
  73. const data = await getCaseFileTypesQuery("library");
  74. const rootList = data.map((item) => {
  75. return {
  76. name: item.filesTypeName,
  77. value: item.filesTypeId,
  78. childKey: item.childKey,
  79. };
  80. });
  81. options.value = rootList;
  82. currentTypeId.value = rootList[0].value;
  83. const secondData = rootList[0].childKey
  84. ? await getCaseFileTypesQuery(rootList[0].childKey)
  85. : [];
  86. const secondList = secondData.map((item) => {
  87. return {
  88. name: item.filesTypeName,
  89. value: item.filesTypeId,
  90. };
  91. });
  92. subTabName.value = secondList[0].value;
  93. subOptions.value = secondList;
  94. };
  95. watchEffect(() => caseId.value && subTabName.value && refresh());
  96. watch(currentTypeId, async (nVal, oVal) => {
  97. if (oVal && nVal !== oVal) {
  98. //切换时
  99. const root = options.value.find((i) => i.value === nVal);
  100. if (root) {
  101. const secondData = root.childKey
  102. ? await getCaseFileTypesQuery(root.childKey)
  103. : [];
  104. const secondList = secondData.map((item) => {
  105. return {
  106. name: item.filesTypeName,
  107. value: item.filesTypeId,
  108. };
  109. });
  110. subTabName.value = secondList[0].value;
  111. subOptions.value = secondList;
  112. }
  113. // const data = await getCaseFileTypesQuery("library");
  114. }
  115. });
  116. const refreshRoot = async () => {
  117. console.log("refreshRoot");
  118. };
  119. const refresh = async () => {
  120. files.value = await getCaseFiles({
  121. caseId: caseId.value!,
  122. filesTypeId: subTabName.value,
  123. });
  124. };
  125. onMounted(async () => {
  126. title.value = " xxxx | 媒体库";
  127. desc.value = "";
  128. console.log("caseId", caseId.value);
  129. initDefaultData();
  130. });
  131. </script>
  132. <style lang="scss" scoped>
  133. @import url("./index.scss");
  134. </style>