slider.vue 3.1 KB

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