You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <v-dialog @click:outside="cancelCropImage" content-class="mb-15" scrollable width="70%" v-model="isCropImageDialogActive" style="z-index:500">
  3. <v-card class="border-radius-20 pt-12 cropper-card-height">
  4. <v-spacer class="d-flex justify-end">
  5. <v-btn icon @click="cancelCropImage" class="me-15 mb-9">
  6. <v-icon>
  7. mdi-close
  8. </v-icon>
  9. </v-btn>
  10. </v-spacer>
  11. <v-spacer class="d-flex justify-center pb-15">
  12. <cropper
  13. class="cropper"
  14. ref="cropper"
  15. :src="cropImagePreview"
  16. :stencil-component="$options.components.CircleStencil"
  17. />
  18. </v-spacer>
  19. <v-spacer class="d-flex justify-center justify-sm-end mb-11">
  20. <v-btn class="me-3" width="110px" @click="cancelCropImage" text color="primary">
  21. {{ $t("userProfile.cropReset") }}
  22. </v-btn>
  23. <v-btn class="me-15 border-radius-16" width="110px" @click="cropImage" color="primary">
  24. {{ $t("userProfile.crop") }}
  25. </v-btn>
  26. </v-spacer>
  27. </v-card>
  28. </v-dialog>
  29. </template>
  30. <script>
  31. import { CircleStencil, Cropper } from 'vue-advanced-cropper';
  32. import 'vue-advanced-cropper/dist/style.css';
  33. export default {
  34. name: "cropImageDialog",
  35. components: {
  36. CircleStencil, Cropper
  37. },
  38. data() {
  39. return {
  40. };
  41. },
  42. props: {
  43. isCropImageDialogActive: {
  44. type: Boolean,
  45. required: true,
  46. default: false,
  47. },
  48. cropImagePreview: {
  49. type: String,
  50. required: true,
  51. default: '',
  52. },
  53. },
  54. methods: {
  55. cancelCropImage() {
  56. // const deleteFile = this.cropImagePreview.split('/')
  57. // const filename = deleteFile.pop()
  58. // this.$axios.delete(`/users/images?filename=${filename}`)
  59. // .then(response => {})
  60. // .catch(error => console.log(error))
  61. this.$emit('close-crop-dialog')
  62. },
  63. cropImage() {
  64. // const result = this.$refs.cropper.getResult()
  65. // console.log(result);
  66. // const resultSplit = result.image.src.split('/')
  67. // console.log(resultSplit);
  68. // const fileDetails = resultSplit[resultSplit.length-1].split('.')
  69. // const fileURL = result.canvas.toDataURL('image/'+fileDetails[1])
  70. // const file = this.dataURLtoFile(fileURL,fileDetails[0]+'.'+fileDetails[1])
  71. // const payload = new FormData()
  72. // payload.append('file',file)
  73. this.$emit('upload-image-success')
  74. // this.$axios
  75. // .post(
  76. // `/trending/api/Members/UploadAvatar`
  77. // )
  78. // .then((response) => {
  79. // //console.log(JSON.stringify(response));
  80. // if(response && response.data && response.data.DATA && response.data.DATA.rel){
  81. // let data = response.data.DATA.rel
  82. // if(data){
  83. // const pictureURL = data;
  84. // console.log("change pic:" + pictureURL);
  85. // this.$emit('upload-image-success');
  86. // }
  87. // }
  88. // })
  89. // .catch((error) => {
  90. // console.log(error);
  91. // });
  92. },
  93. dataURLtoFile(dataurl, filename) {
  94. let arr = dataurl.split(','),
  95. mime = arr[0].match(/:(.*?);/)[1],
  96. bstr = atob(arr[1]),
  97. n = bstr.length,
  98. u8arr = new Uint8Array(n);
  99. while(n--){
  100. u8arr[n] = bstr.charCodeAt(n);
  101. }
  102. return new File([u8arr], filename, {type:mime});
  103. },
  104. },
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .cropper {
  109. width: 85%;
  110. @media screen and (max-width: 600px) {
  111. min-height: 164px;
  112. }
  113. @media screen and (min-width: 600px) and (max-width: 960px) {
  114. min-height: 303px;
  115. }
  116. @media screen and (min-width: 961px) {
  117. min-height: 538px;
  118. }
  119. }
  120. .cropper-card-height {
  121. @media screen and (max-width: 600px) {
  122. min-height: 515px;
  123. }
  124. @media screen and (min-width: 600px) and (max-width: 960px) {
  125. min-height: 717px;
  126. }
  127. @media screen and (min-width: 961px) {
  128. min-height: 900px;
  129. }
  130. }
  131. .vue-advanced-cropper{
  132. height: 600px !important;
  133. }
  134. .vue-advanced-cropper__stretcher{
  135. height: 600px !important;
  136. }
  137. .vue-advanced-cropper__boundaries{
  138. height: 600px !important;
  139. }
  140. .vue-advanced-cropper__foreground{
  141. height: 600px !important;
  142. }
  143. .vue-advanced-cropper__image-wrapper{
  144. height: 600px !important;
  145. }
  146. .vue-advanced-cropper__background{
  147. height: 600px !important;
  148. }
  149. //裁切
  150. .vue-circle-stencil .vue-circle-stencil--movable{
  151. height: 400px !important;
  152. }
  153. .vue-bounding-box .vue-circle-stencil__bounding-box{
  154. height: 400px !important;
  155. }
  156. .vue-preview__wrapper{
  157. height: 400px !important;
  158. }
  159. </style>