slider.vue 4.9 KB

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