index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div>
  3. <div class="demo-image__preview">
  4. <el-image-viewer
  5. hide-on-click-modal
  6. @close="
  7. () => {
  8. showViewer = false;
  9. }
  10. "
  11. :initial-index="urlindex"
  12. v-if="showViewer"
  13. :url-list="initFileList"
  14. />
  15. </div>
  16. <div class="imgList flex justify-start flex-wrap">
  17. <div
  18. class="maskContainer previewBox my-2 mr-4"
  19. :style="{ width: width, height: height }"
  20. v-for="(item, index) in list"
  21. :key="index"
  22. >
  23. <div class="demo-image__preview h-full w-full">
  24. <el-image :src="urlFilter(item.filesUrl||item.mapUrl)" class="originalImg" fit="cover">
  25. <template #error>
  26. <div class="image-slot el-image__error">
  27. <el-icon :size="30"><VideoCameraFilled /></el-icon>
  28. </div>
  29. </template>
  30. </el-image>
  31. </div>
  32. <div class="mask">
  33. <div class="zoomInImg" v-if="TypeFilter(item.filesUrl) == '.mp4'" @click="showVideoView(item.filesUrl)">
  34. <el-icon color="#fff"><VideoPlay /></el-icon>
  35. </div>
  36. <div v-else class="zoomInImg" @click="showImgView(item.filesUrl||item.mapUrl)">
  37. <el-icon color="#fff"><zoom-in /></el-icon>
  38. </div>
  39. <div
  40. v-if="!edit"
  41. class="downloadImg"
  42. @click="handleItem('edit', item)"
  43. >
  44. <el-icon color="#fff"><Edit /></el-icon>
  45. </div>
  46. <div
  47. v-if="!deleteShow"
  48. class="downloadImg"
  49. @click="handleItem('delete', item)"
  50. >
  51. <el-icon color="red"><Delete /></el-icon>
  52. </div>
  53. <!-- <div v-if="!close" class="close" @click="handleItem('close', item)">
  54. <el-icon color="red"><CircleCloseFilled /></el-icon>
  55. </div> -->
  56. </div>
  57. </div>
  58. </div>
  59. <el-dialog v-model="visible.show" title="查看视频" width="500" @close="close">
  60. <video :src="visible.src" v-if="visible.show" ref="videoPlayer" style="width: 100%; height: 300px;" controls class="video-js">
  61. <source :src="visible.src" type="video/mp4">
  62. </video>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script setup>
  67. import { ref, defineEmits, watchEffect, computed } from "vue";
  68. import { router } from "@/router";
  69. import { ElMessage, ElMessageBox } from "element-plus";
  70. import fileImg from "@/assets/svg/file.svg";
  71. import { delCaseFile, } from "@/store/caseFile";
  72. import { caseOverviewDel, } from "@/store/case";
  73. const caseId = computed(() => {
  74. const caseId = router.currentRoute.value.params.caseId;
  75. if (caseId) {
  76. return Number(caseId);
  77. }
  78. });
  79. const emits = defineEmits(['handleItem']);
  80. const props = defineProps({
  81. width: {
  82. type: String,
  83. default: "66px",
  84. required: false,
  85. },
  86. height: {
  87. type: String,
  88. default: "66px",
  89. required: false,
  90. },
  91. edit: {
  92. type: Boolean,
  93. default: false,
  94. required: false,
  95. },
  96. delete: {
  97. type: Boolean,
  98. default: false,
  99. required: false,
  100. },
  101. deleteShow: {
  102. type: Boolean,
  103. default: false,
  104. required: false,
  105. },
  106. close: {
  107. type: Boolean,
  108. default: false,
  109. required: false,
  110. },
  111. list: {
  112. type: Array,
  113. default() {
  114. return [];
  115. }
  116. }
  117. });
  118. const visible = ref({
  119. show: false,
  120. src: "",
  121. });
  122. const deleteVal = ref(props.deleteShow);
  123. const videoPlayer = ref(null);
  124. const currSize = ref({ width: 0, height: 0 });
  125. const fileList = ref([".doc", ".docx", ".pdf", ".xls", ".xlsx"]);
  126. const initFileList = ref([
  127. "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg",
  128. "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
  129. "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
  130. // "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
  131. // "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
  132. // "https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg",
  133. // "https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg",
  134. ]);
  135. const urlFilter = (url) => {
  136. if (!url) return "";
  137. const fileType = url.substring(url.lastIndexOf(".")).toLowerCase();
  138. return fileList.value.includes(fileType) ? fileImg : url ;
  139. }
  140. const TypeFilter = (url) => {
  141. if (!url) return "";
  142. const fileType = url.substring(url.lastIndexOf(".")).toLowerCase();
  143. return fileType;
  144. }
  145. const verifySuffix = (imageName) => {
  146. const suffix = `(bmp|jpg|png|tif|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF|webp|jpeg)`
  147. const regular = new RegExp(`.*\.${suffix}`)
  148. return regular.test(imageName)
  149. }
  150. watchEffect(() => {
  151. if (props.list.length) {
  152. let newlist = props.list.map(item => item.filesUrl || item.fileUrl || item.mapUrl);
  153. initFileList.value = newlist.filter(item => {
  154. return verifySuffix(item)
  155. });
  156. }
  157. });
  158. const urlindex = ref("");
  159. const showViewer = ref(false);
  160. const previewList = ref([]);
  161. const showVideoView = (src) => {
  162. visible.value.show = true;
  163. visible.value.src = src;
  164. }
  165. const showImgView = (src) => {
  166. console.log(src, "showImgView", initFileList.value);
  167. const fileType = src.substring(src.lastIndexOf(".")).toLowerCase();
  168. urlindex.value = initFileList.value.findIndex((item) => item === src);
  169. console.log(fileType, fileList.value.includes(fileType), "urlFilter");
  170. if(fileList.value.includes(fileType)){
  171. window.open(window.location.origin + src);
  172. return;
  173. }
  174. // url.value = src;
  175. showViewer.value = true;
  176. // previewList.value = [src];
  177. };
  178. const handleItem = (type, item) => {
  179. if(type == 'delete'){
  180. del(item)
  181. return
  182. }
  183. emits("handleItem", type, item);
  184. };
  185. const close = () => {
  186. visible.value.show = false;
  187. videoPlayer.value && videoPlayer.value.pause();
  188. };
  189. const del = async (file) => {
  190. console.log(file, "file");
  191. ElMessageBox.confirm("确定删除?", "提示", {
  192. confirmButtonText: "确定",
  193. cancelButtonText: "取消",
  194. type: "warning",
  195. }).then(async () => {
  196. if(props.delete){//删除绘图
  197. await caseOverviewDel(file.id);
  198. }else{
  199. await delCaseFile({ caseId: caseId.value, filesId: file.filesId });
  200. }
  201. emits("handleItem", 'delete', file);
  202. ElMessage({
  203. type: "success",
  204. message: "删除成功",
  205. });
  206. });
  207. };
  208. </script>
  209. <style lang="scss" scoped>
  210. .maskContainer {
  211. position: relative;
  212. line-height: 0;
  213. width: 66px;
  214. height: 66px;
  215. padding: 7px;
  216. border: 1px solid #d9d9d9;
  217. &:hover {
  218. .mask {
  219. opacity: 1;
  220. }
  221. img {
  222. transform: scale(1.1);
  223. }
  224. }
  225. .mask {
  226. transition: all 0.5s;
  227. opacity: 0;
  228. position: absolute;
  229. top: 0;
  230. right: 0;
  231. bottom: 0;
  232. left: 0;
  233. background: rgba($color: #000000, $alpha: 0.3);
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. div {
  238. margin: 3px;
  239. }
  240. .close {
  241. position: absolute;
  242. right: 0;
  243. top: 0;
  244. }
  245. .svgBox {
  246. height: 40px;
  247. width: 40px;
  248. background: rgb(#000, 0.3);
  249. border-radius: 50%;
  250. margin: 10px;
  251. padding: 10px;
  252. cursor: pointer;
  253. }
  254. svg {
  255. // color: #fff;
  256. width: 14px;
  257. height: 14px;
  258. }
  259. }
  260. .originalImg {
  261. height: 100%;
  262. width: 100%;
  263. }
  264. }
  265. </style>