ImageOrientation.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div class="image-orientation">
  3. <div class="image-orient-cont">
  4. <img
  5. class="img-contain"
  6. :src="imageUrl"
  7. :style="contStyle"
  8. ref="editImage"
  9. />
  10. </div>
  11. <div class="image-orient-btns">
  12. <div
  13. class="image-orient-icon rotate-icon rotate-icon-left"
  14. title="逆时针旋转90度"
  15. @click="toRotate(0)"
  16. ></div>
  17. <div
  18. class="image-orient-icon rotate-icon rotate-icon-right"
  19. title="顺时针旋转90度"
  20. @click="toRotate(1)"
  21. ></div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. name: "image-orientation",
  28. props: {
  29. imageUrl: {
  30. type: String,
  31. require: true
  32. },
  33. curSetting: {
  34. type: Object,
  35. default() {
  36. return {};
  37. }
  38. }
  39. },
  40. data() {
  41. return {
  42. contStyle: {},
  43. picRotate: 0
  44. };
  45. },
  46. mounted() {
  47. const defImageRotate =
  48. (this.curSetting && this.curSetting.imageRotate) || 0;
  49. this.picRotate = defImageRotate;
  50. this.contStyle = {
  51. transform: `rotate(${this.picRotate}deg)`
  52. };
  53. this.$emit("on-ready");
  54. },
  55. methods: {
  56. toRotate(type) {
  57. if (type) {
  58. this.picRotate += 90;
  59. if (this.picRotate === 360) this.picRotate = 0;
  60. } else {
  61. if (this.picRotate === 0) this.picRotate = 360;
  62. this.picRotate -= 90;
  63. }
  64. this.contStyle = {
  65. transform: `rotate(${this.picRotate}deg)`
  66. };
  67. // this.coverBoxStyle.transform = this.contStyle.transform;
  68. },
  69. checkValid() {
  70. this.$emit("on-next", { imageRotate: this.picRotate });
  71. },
  72. pass() {
  73. this.$emit("on-next", { imageRotate: null });
  74. }
  75. }
  76. };
  77. </script>