slider.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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", ".raw"],
  106. })
  107. );
  108. const coverUploadHandler = async () => {
  109. if (
  110. props.existsBgImage &&
  111. (await confirm("重新上传将替换当前图体,确定要上传吗?", "继续上传"))
  112. ) {
  113. // await cover.upload(file)
  114. }
  115. const input = document
  116. .querySelector("#coverupload")!
  117. .querySelector("input[type=file]") as HTMLInputElement;
  118. input.click();
  119. };
  120. watchEffect(async () => {
  121. if (cover.file) {
  122. const coverImage = (await coverImageSize(cover.file, 540, 390, false)) || cover.file;
  123. const data = await imageCropper({
  124. img: coverImage.blob,
  125. fixed: [coverImage.width, coverImage.height],
  126. });
  127. data && emit("selectImage", data);
  128. cover.removeFile();
  129. }
  130. });
  131. const imageLabel = reactive(
  132. useUpload({
  133. maxSize: maxFileSize,
  134. formats: [".jpg", ".png"],
  135. })
  136. );
  137. watchEffect(async () => {
  138. if (imageLabel.file) {
  139. emit("update:addShape", customImage, imageLabel.file);
  140. imageLabel.removeFile();
  141. // ElMessage.info("请前往右边画板选择为止单击添加图例");
  142. }
  143. });
  144. </script>
  145. <style scoped lang="scss">
  146. .df-slide-content {
  147. padding: 10px 24px;
  148. overflow-y: auto;
  149. height: 100%;
  150. h3 {
  151. font-size: 16px;
  152. font-weight: normal;
  153. margin: 20px 0;
  154. }
  155. }
  156. .def-image-set {
  157. display: flex;
  158. justify-content: space-between;
  159. > * {
  160. width: 45%;
  161. }
  162. }
  163. .df-shape-layout {
  164. display: grid;
  165. grid-template-columns: 1fr 1fr 1fr;
  166. gap: 16px;
  167. }
  168. .df-slide-shape {
  169. width: 88px;
  170. height: 88px;
  171. text-align: center;
  172. color: rgba(0, 0, 0, 0.85);
  173. cursor: pointer;
  174. transition: all 0.3s;
  175. display: flex;
  176. flex-direction: column;
  177. justify-content: center;
  178. align-items: center;
  179. img {
  180. width: 40px;
  181. height: 40px;
  182. flex: none;
  183. }
  184. p {
  185. margin: 10px 0 0;
  186. }
  187. &.active,
  188. &:hover {
  189. background-color: #f5f5f5;
  190. }
  191. }
  192. </style>
  193. <style>
  194. .def-image-set .el-upload {
  195. display: block;
  196. }
  197. </style>