slider.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <div class="df-slide-content">
  3. <h3>{{ fileDesc[type] }}</h3>
  4. <div class="def-image-set">
  5. <el-button type="primary" @click="emit('trackImage')" ghost>
  6. 设置{{ fileDesc[type] }}</el-button
  7. >
  8. <el-upload
  9. :multiple="false"
  10. :limit="1"
  11. :show-file-list="false"
  12. :http-request="() => {}"
  13. :disabled="!!cover.percentage"
  14. :before-upload="cover.upload"
  15. :accept="cover.accept"
  16. :file-list="cover.fileList"
  17. >
  18. <el-button
  19. ghost
  20. type="primary"
  21. :class="{ dispable: cover.percentage }"
  22. :style="{ width: '100%' }"
  23. >
  24. {{ cover.percentage ? "文件上传中" : "上传" + fileDesc[type] }}
  25. </el-button>
  26. </el-upload>
  27. </div>
  28. <h3>标注</h3>
  29. <div class="df-shape-layout">
  30. <div
  31. v-for="label in labels"
  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. <h3>图例</h3>
  42. <el-upload
  43. :multiple="false"
  44. :limit="1"
  45. :show-file-list="false"
  46. :http-request="() => {}"
  47. :disabled="!!imageLabel.percentage"
  48. :before-upload="imageLabel.upload"
  49. :accept="imageLabel.accept"
  50. :file-list="imageLabel.fileList"
  51. >
  52. <el-button
  53. ghost
  54. type="primary"
  55. :class="{ dispable: imageLabel.percentage }"
  56. :style="{ width: '100%' }"
  57. >
  58. {{ imageLabel.percentage ? "文件上传中" : "上传图例" }}
  59. </el-button>
  60. </el-upload>
  61. <div class="df-shape-layout">
  62. <div
  63. v-for="label in images"
  64. :key="label"
  65. class="df-slide-shape"
  66. @click="emit('update:addShape', label)"
  67. :class="{ active: addShape === label }"
  68. >
  69. <img :src="shapes[label]" />
  70. <p>{{ metas[label].desc }}</p>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script setup lang="ts">
  76. import { metas, labels, images, shapes, MetaShapeType, customImage } from "./board";
  77. import { BoardType } from "@/store/caseFile";
  78. import { maxFileSize } from "@/constant/caseFile";
  79. import { useUpload } from "@/hook/upload";
  80. import { reactive, watchEffect } from "vue";
  81. import { imageCropper } from "@/view/system/quisk";
  82. import { coverImageSize } from "@/util/image-rotate";
  83. import { uploadFile } from "@/store/system";
  84. import { ElMessage } from "element-plus";
  85. defineProps<{
  86. type: BoardType;
  87. addShape: MetaShapeType | null;
  88. }>();
  89. const fileDesc = {
  90. [BoardType.scene]: "户型图",
  91. [BoardType.map]: "方位图",
  92. };
  93. const emit = defineEmits<{
  94. (e: "update:addShape", val: MetaShapeType | null, data?: any): void;
  95. (e: "trackImage"): void;
  96. (e: "selectImage", val: Blob): void;
  97. }>();
  98. const cover = reactive(
  99. useUpload({
  100. maxSize: maxFileSize,
  101. formats: [".jpg", ".png"],
  102. })
  103. );
  104. watchEffect(async () => {
  105. if (cover.file) {
  106. const coverImage = (await coverImageSize(cover.file, 540, 390, false)) || cover.file;
  107. const data = await imageCropper({
  108. img: coverImage.blob,
  109. fixed: [coverImage.width, coverImage.height],
  110. });
  111. data && emit("selectImage", data);
  112. cover.removeFile();
  113. }
  114. });
  115. const imageLabel = reactive(
  116. useUpload({
  117. maxSize: maxFileSize,
  118. formats: [".jpg", ".png"],
  119. })
  120. );
  121. watchEffect(async () => {
  122. if (imageLabel.file) {
  123. emit("update:addShape", customImage, imageLabel.file);
  124. imageLabel.removeFile();
  125. ElMessage.info("请前往右边画板选择为止单击添加图例");
  126. }
  127. });
  128. </script>
  129. <style scoped lang="scss">
  130. .df-slide-content {
  131. padding: 10px 24px;
  132. overflow-y: auto;
  133. height: 100%;
  134. h3 {
  135. font-size: 16px;
  136. font-weight: normal;
  137. margin: 20px 0;
  138. }
  139. }
  140. .def-image-set {
  141. display: flex;
  142. justify-content: space-between;
  143. > * {
  144. width: 45%;
  145. }
  146. }
  147. .df-shape-layout {
  148. display: grid;
  149. grid-template-columns: 1fr 1fr 1fr;
  150. gap: 16px;
  151. }
  152. .df-slide-shape {
  153. width: 88px;
  154. height: 88px;
  155. text-align: center;
  156. color: rgba(0, 0, 0, 0.85);
  157. cursor: pointer;
  158. transition: all 0.3s;
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: center;
  162. align-items: center;
  163. img {
  164. width: 40px;
  165. height: 40px;
  166. flex: none;
  167. }
  168. p {
  169. margin: 10px 0 0;
  170. }
  171. &.active,
  172. &:hover {
  173. background-color: #f5f5f5;
  174. }
  175. }
  176. </style>
  177. <style>
  178. .def-image-set .el-upload {
  179. display: block;
  180. }
  181. </style>