duomeiticaiji.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <el-scrollbar style="width: 100%; height: 100%">
  3. <div class="media-container">
  4. <CameraUpload
  5. @reset-select="clickReset"
  6. @upload-finish="finish"
  7. @delete-all="clickDeleteAll"
  8. />
  9. <div
  10. v-for="(item, index) in medias.filter((item: any) => item.filePath)"
  11. :key="index"
  12. class="media-item"
  13. @click="item.isSelected = !item.isSelected"
  14. >
  15. <i-ep-delete
  16. v-show="item.isSelected"
  17. class="check"
  18. color="#ff4d4f"
  19. size="20px"
  20. />
  21. <img :src="getImgurl(item)" alt="" class="img-box" object-fit="cover" />
  22. </div>
  23. </div>
  24. </el-scrollbar>
  25. </template>
  26. <script lang="ts" setup>
  27. import { useProcessStore } from "@/store";
  28. import { addMedia, deleteMedias, pageMedias } from "@/api/prosteps/medias";
  29. import CameraUpload from "@/components/Upload/CameraUpload.vue";
  30. const proStore = useProcessStore();
  31. const medias = ref<any>([]);
  32. defineOptions({
  33. name: "Wuliaocaiji",
  34. });
  35. const input = ref("");
  36. const finish = (value: string) => {
  37. addMedia({
  38. filePath: value,
  39. operationMediaId: proStore.odersData.operationId,
  40. processId: proStore.scanInfo.id,
  41. seqNo: proStore.scanInfo.seqNo,
  42. }).then((res) => {
  43. getListData();
  44. });
  45. };
  46. onMounted(() => {
  47. getListData();
  48. });
  49. const getListData = () => {
  50. pageMedias(
  51. proStore.odersData.operationId,
  52. proStore.scanInfo.id,
  53. proStore.scanInfo.seqNo
  54. ).then((res) => {
  55. medias.value = res.data.records || [];
  56. });
  57. };
  58. const getImgurl = (item: any) => {
  59. let url = import.meta.env.VITE_APP_UPLOAD_URL + item.filePath;
  60. return url;
  61. };
  62. const clickReset = () => {
  63. medias.value.forEach((item: any) => {
  64. item.isSelected = false;
  65. });
  66. };
  67. const clickDeleteAll = () => {
  68. let ids = medias.value
  69. .filter((item: any) => item.isSelected)
  70. .map((item: any) => item.id);
  71. ids &&
  72. ids.length > 0 &&
  73. deleteMedias(ids).then(() => {
  74. getListData();
  75. });
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. .media-container {
  80. width: 100%;
  81. display: grid;
  82. /*行间距*/
  83. grid-row-gap: 24px;
  84. /*列间距*/
  85. grid-column-gap: 24px;
  86. /*每3行有2个行间距,所以每个格子的宽高都要减去(24*2) / 3 */
  87. //grid-template-columns: repeat(4, calc(33.33% - 16px));
  88. //grid-template-rows: repeat(4, calc(33.33% - 16px));
  89. grid-template-columns: 1fr 1fr 1fr 1fr;
  90. overflow-y: auto;
  91. }
  92. .media-item {
  93. width: 292px;
  94. height: 292px;
  95. flex-shrink: 0;
  96. margin-bottom: 49px;
  97. border: 1px solid #ccc;
  98. border-radius: 16px 16px 16px 16px;
  99. overflow: hidden;
  100. position: relative;
  101. .img-box {
  102. width: 292px;
  103. height: 292px;
  104. }
  105. .check {
  106. position: absolute;
  107. top: 20px;
  108. right: 20px;
  109. }
  110. }
  111. </style>
  112. @/api/prosteps/medias