PreviewImages.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!--
  2. # @Date: 2024-10-11 14:37:11
  3. # @Author: WANGKANG
  4. # @Blog:
  5. # @Email:
  6. # @Filepath: src\views\demo\components\PreviewImages.vue
  7. # @Description: PreviewImages.vue
  8. # Copyright 2024 WANGKANG, All Rights Reserved.
  9. -->
  10. <template>
  11. <el-dialog
  12. v-model="dialogVisible"
  13. :title="'预览 - 共' + currentImageUrls.length + '张 当前第' + (imageIdx + 1) + '张'"
  14. width="80%"
  15. @open="handleOpen"
  16. :before-close="handleClose"
  17. >
  18. <el-form :inline="true">
  19. <el-form-item label="帧率">
  20. <el-select v-model="imageFps" placeholder="选择帧率" style="width: 200px" @change="changeFps">
  21. <el-option label="0" value="0"></el-option>
  22. <el-option label="5" value="5"></el-option>
  23. <el-option label="15" value="15"></el-option>
  24. <el-option label="30" value="30"></el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item label="跳转至">
  28. <el-input v-model="newImageIdx" type="number" style="width: 100px"/>
  29. <el-button type="primary" @click="confirmNewImageIdx" style="margin-left: 10px">确认</el-button>
  30. </el-form-item>
  31. </el-form>
  32. <div class="image-dialog">
  33. <el-image :src="currentImageUrls[imageIdx]" style="width: 40%"></el-image>
  34. </div>
  35. <div class="image-dialog-btn" v-if="imageFps == 0">
  36. <el-button type="primary" @click="pre_picture" :disabled="imageIdx <= 0">上一个</el-button>
  37. <el-button type="primary" @click="next_picture" :disabled="imageIdx >= currentImageUrls.length - 1">下一个</el-button>
  38. </div>
  39. </el-dialog>
  40. </template>
  41. <script setup lang="ts">
  42. import {ElMessageBox} from "element-plus";
  43. import {ref, watch} from "vue";
  44. const props = defineProps({
  45. visible: {
  46. type: Boolean, //接受的数据类型
  47. default: false //接受默认数据
  48. },
  49. urls: {
  50. type: Array,
  51. default: ()=>[]
  52. }
  53. })
  54. watch(() => props.visible, (val) => {
  55. dialogVisible.value = val
  56. })
  57. const handleOpen = () => {
  58. currentImageUrls.value = props.urls
  59. imageIdx.value = 0
  60. }
  61. const dialogVisible = ref(false)
  62. const imageFps = ref(0)
  63. const intervalChangeFps: any = ref()
  64. const imageIdx = ref(0)
  65. const currentImageUrls = ref<any[]>([])
  66. const newImageIdx = ref()
  67. const handleClose = (done: () => void) => {
  68. console.log('handleClose')
  69. if (intervalChangeFps.value) {
  70. clearInterval(intervalChangeFps.value)
  71. }
  72. done()
  73. }
  74. const confirmNewImageIdx = () => {
  75. const val = parseInt(newImageIdx.value)
  76. if (val > 0 && val <= currentImageUrls.value.length) {
  77. imageIdx.value = val - 1
  78. } else {
  79. ElMessageBox.alert('跳转索引有误,请检查!')
  80. }
  81. }
  82. const changeFps = () => {
  83. console.log('changeFps')
  84. if (intervalChangeFps.value) {
  85. clearInterval(intervalChangeFps.value)
  86. }
  87. if (imageFps.value == 0) {
  88. return
  89. }
  90. intervalChangeFps.value = setInterval(() => {
  91. next_picture()
  92. }, 1000 / imageFps.value)
  93. }
  94. const next_picture = () => {
  95. if (imageIdx.value <= currentImageUrls.value.length - 1) {
  96. imageIdx.value += 1
  97. }
  98. }
  99. const pre_picture = () => {
  100. if (imageIdx.value > 0) {
  101. imageIdx.value -= 1
  102. }
  103. }
  104. </script>
  105. <style scoped lang="scss">
  106. .image-dialog {
  107. display: flex;
  108. justify-content: center;
  109. .el-image {
  110. margin-right: 20px;
  111. margin-bottom: 20px;
  112. }
  113. }
  114. .image-dialog-btn {
  115. display: flex;
  116. justify-content: center;
  117. margin-top: 20px;
  118. }
  119. </style>