ImageActionList.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div :class="classes">
  3. <div class="image-view" v-for="(image, index) in data" :key="image.id">
  4. <div class="image-view-container">
  5. <h5 class="image-view-title">{{ image.title }}</h5>
  6. <div class="image-view-contain" :style="image.styles">
  7. <img
  8. :src="image.thumbSrc"
  9. :alt="image.title"
  10. @click="toReview(index)"
  11. />
  12. </div>
  13. <div class="image-view-actions" v-if="actions.length">
  14. <Button
  15. size="small"
  16. icon="md-refresh"
  17. @click="toRotate(image)"
  18. v-if="canRotate"
  19. ></Button>
  20. <Button
  21. size="small"
  22. type="primary"
  23. @click="toSaveRotate(image)"
  24. v-if="canRotate && image['deg']"
  25. >保存</Button
  26. >
  27. <Button
  28. :type="image.missing ? 'error' : 'default'"
  29. size="small"
  30. @click="toSignAbsent(image)"
  31. v-if="canAbsent"
  32. >缺考</Button
  33. >
  34. </div>
  35. </div>
  36. </div>
  37. <!-- image-preview -->
  38. <image-preview
  39. :class="imagePreviewCls"
  40. :image-list="data"
  41. :init-index="curImageIndex"
  42. :loop="loop"
  43. header-hide
  44. ref="ImagePreview"
  45. v-if="data.length"
  46. ></image-preview>
  47. </div>
  48. </template>
  49. <script>
  50. import { rotatePaper, absentPaper } from "@/api";
  51. import ImagePreview from "@/components/common/ImagePreview";
  52. export default {
  53. name: "image-action-list",
  54. components: { ImagePreview },
  55. props: {
  56. data: {
  57. type: Array,
  58. default() {
  59. return [];
  60. }
  61. },
  62. actions: {
  63. type: Array,
  64. default() {
  65. return [];
  66. }
  67. },
  68. columnNumber: {
  69. type: Number,
  70. default: 5
  71. },
  72. loop: {
  73. type: Boolean,
  74. default: false
  75. },
  76. imagePreviewCls: {
  77. type: String,
  78. default: ""
  79. }
  80. },
  81. data() {
  82. return {
  83. curImageIndex: 0,
  84. imageList: []
  85. };
  86. },
  87. computed: {
  88. classes() {
  89. return [
  90. "image-action-list",
  91. "image-view-list",
  92. `image-view-list-${this.columnNumber}`
  93. ];
  94. },
  95. canRotate() {
  96. return this.actions.includes("rotate");
  97. },
  98. canAbsent() {
  99. return this.actions.includes("absent");
  100. }
  101. },
  102. methods: {
  103. toRotate(image) {
  104. image.deg += 90;
  105. if (image.deg === 360) image.deg = 0;
  106. image.styles = {
  107. transform: `rotate(${image.deg}deg)`
  108. };
  109. },
  110. async toSaveRotate(image) {
  111. if (!image.deg) return;
  112. await rotatePaper(image.id, image.deg);
  113. this.$Message.success("保存成功!");
  114. },
  115. async toSignAbsent(image) {
  116. await absentPaper(image.id);
  117. image.missing = !image.missing;
  118. },
  119. toReview(index) {
  120. this.curImageIndex = index;
  121. this.$refs.ImagePreview.open();
  122. }
  123. }
  124. };
  125. </script>