1
0

slider.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="df-slide-content">
  3. <h3>户型图</h3>
  4. <div class="def-image-set">
  5. <el-button type="primary" @click="emit('trackImage')" ghost>
  6. 设置{{ BoardTypeDesc[type] }}</el-button
  7. >
  8. <el-upload
  9. :multiple="false"
  10. :limit="1"
  11. :show-file-list="false"
  12. :disabled="!!percentage"
  13. :before-upload="upload"
  14. :accept="accept"
  15. :file-list="[]"
  16. >
  17. <el-button
  18. ghost
  19. type="primary"
  20. :class="{ dispable: percentage }"
  21. :style="{ width: '100%' }"
  22. >
  23. {{ percentage ? "文件上传中" : "上传" + BoardTypeDesc[type] }}
  24. </el-button>
  25. </el-upload>
  26. </div>
  27. <template v-for="typeShapes in typesShapes">
  28. <h3>{{ typeShapes.name }}</h3>
  29. <div class="df-shape-layout">
  30. <div
  31. v-for="label in typeShapes.shapes"
  32. :key="label"
  33. class="df-slide-shape"
  34. @click="emit('update:addShape', label)"
  35. :class="{ active: addShape === label }"
  36. >
  37. <img :src="shapes[label]" />
  38. <p>{{ metas[label].desc }}</p>
  39. </div>
  40. </div>
  41. </template>
  42. </div>
  43. </template>
  44. <script setup lang="ts">
  45. import { metas, labels, images, shapes, MetaShapeType } from "./board";
  46. import { BoardType } from "@/store/caseFile";
  47. import { BoardTypeDesc, OtherFormats, maxFileSize } from "@/constant/caseFile";
  48. import { useUpload } from "@/hook/upload";
  49. import { watchEffect } from "vue";
  50. import { imageCropper } from "@/view/system/quisk";
  51. import { fixImageSize } from "@/util/image-rotate";
  52. defineProps<{
  53. type: BoardType;
  54. addShape: MetaShapeType | null;
  55. }>();
  56. const typesShapes = [
  57. { name: "标注", shapes: labels },
  58. { name: "图例", shapes: images },
  59. ];
  60. const emit = defineEmits<{
  61. (e: "update:addShape", val: MetaShapeType | null): void;
  62. (e: "trackImage"): void;
  63. (e: "selectImage", val: Blob): void;
  64. }>();
  65. const { percentage, upload, file, removeFile, accept } = useUpload({
  66. maxSize: maxFileSize,
  67. formats: [".jpg", ".jpeg", ".png", ".svg"],
  68. });
  69. watchEffect(async () => {
  70. if (file.value) {
  71. const newFile = (await fixImageSize(file.value, 500, 500)) || file.value;
  72. const data = await imageCropper({ img: newFile, fixed: [500, 500] });
  73. data && emit("selectImage", data);
  74. removeFile();
  75. }
  76. });
  77. </script>
  78. <style scoped lang="scss">
  79. .df-slide-content {
  80. padding: 10px 24px;
  81. overflow-y: auto;
  82. height: 100%;
  83. h3 {
  84. font-size: 16px;
  85. font-weight: normal;
  86. margin: 20px 0;
  87. }
  88. }
  89. .def-image-set {
  90. display: flex;
  91. justify-content: space-between;
  92. > * {
  93. width: 45%;
  94. }
  95. }
  96. .df-shape-layout {
  97. display: grid;
  98. grid-template-columns: 1fr 1fr 1fr;
  99. gap: 16px;
  100. }
  101. .df-slide-shape {
  102. width: 88px;
  103. height: 88px;
  104. text-align: center;
  105. color: rgba(0, 0, 0, 0.85);
  106. cursor: pointer;
  107. transition: all 0.3s;
  108. display: flex;
  109. flex-direction: column;
  110. justify-content: center;
  111. align-items: center;
  112. img {
  113. width: 40px;
  114. height: 40px;
  115. flex: none;
  116. }
  117. p {
  118. margin: 10px 0 0;
  119. }
  120. &.active,
  121. &:hover {
  122. background-color: #f5f5f5;
  123. }
  124. }
  125. </style>
  126. <style>
  127. .def-image-set .el-upload {
  128. display: block;
  129. }
  130. </style>