cropper.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div class="cropper-wrapper" v-if="visible">
  3. <section class="cropper-main">
  4. <vueCropper
  5. ref="cropper"
  6. :img="img"
  7. :autoCrop = "autoCrop"
  8. :canScale = "true"
  9. :fixed = "true"
  10. :fixedNumber = "fixedNumber"
  11. ></vueCropper>
  12. </section>
  13. <footer class="cropper-f">
  14. <button @click="close">{{$t('public.cancel')}}</button>
  15. <button @click="submit">{{$t('public.complete')}}</button>
  16. </footer>
  17. </div>
  18. </template>
  19. <script>
  20. import { VueCropper } from 'vue-cropper'
  21. export default {
  22. name: 'cropper',
  23. props: {
  24. visible: Boolean,
  25. img: null
  26. },
  27. components: {
  28. VueCropper
  29. },
  30. computed: {
  31. },
  32. data () {
  33. return {
  34. autoCrop: true,
  35. fixedNumber: [1, 1]
  36. }
  37. },
  38. methods: {
  39. close () {
  40. this.$emit('close')
  41. },
  42. submit () {
  43. this.$refs.cropper.getCropBlob((data) => {
  44. this.$emit('cropper', data)
  45. })
  46. }
  47. },
  48. mounted () {
  49. }
  50. }
  51. </script>
  52. <style lang="scss" scoped>
  53. .cropper-wrapper{
  54. position: absolute;
  55. left: 0;
  56. top: 0;
  57. width: 100%;
  58. height: 100%;
  59. background-color: rgba(0, 0, 0, .9);
  60. display: flex;
  61. flex-direction: column;
  62. z-index: 99;
  63. .cropper-main{
  64. height: 0;
  65. flex: 1;
  66. }
  67. .cropper-f{
  68. display: flex;
  69. height: px2rem(128);
  70. padding: 0 px2rem(48);
  71. justify-content: space-between;
  72. align-items: center;
  73. button{
  74. -webkit-appearance: none;
  75. outline: none;
  76. border: none;
  77. padding: 0;
  78. background-color: transparent;
  79. font-size: px2rem(32);
  80. font-weight: bold;
  81. color: #fff;
  82. }
  83. }
  84. .vue-cropper{
  85. background-image: none;
  86. }
  87. }
  88. </style>