AvatarModal.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <a-modal
  3. title="修改头像"
  4. :visible="visible"
  5. :maskClosable="false"
  6. :confirmLoading="confirmLoading"
  7. :width="800"
  8. @cancel="cancelHandel">
  9. <a-row>
  10. <a-col :xs="24" :md="12" :style="{height: '350px'}">
  11. <vue-cropper
  12. ref="cropper"
  13. :img="options.img"
  14. :info="true"
  15. :autoCrop="options.autoCrop"
  16. :autoCropWidth="options.autoCropWidth"
  17. :autoCropHeight="options.autoCropHeight"
  18. :fixedBox="options.fixedBox"
  19. @realTime="realTime"
  20. >
  21. </vue-cropper>
  22. </a-col>
  23. <a-col :xs="24" :md="12" :style="{height: '350px'}">
  24. <div class="avatar-upload-preview">
  25. <img :src="previews.url" :style="previews.img"/>
  26. </div>
  27. </a-col>
  28. </a-row>
  29. <template slot="footer">
  30. <a-button key="back" @click="cancelHandel">取消</a-button>
  31. <a-button key="submit" type="primary" :loading="confirmLoading" @click="okHandel">保存</a-button>
  32. </template>
  33. </a-modal>
  34. </template>
  35. <script>
  36. // import { VueCropper } from 'vue-cropper'
  37. export default {
  38. /*
  39. components: {
  40. VueCropper
  41. },
  42. */
  43. data () {
  44. return {
  45. visible: false,
  46. id: null,
  47. confirmLoading: false,
  48. options: {
  49. img: '/avatar2.jpg',
  50. autoCrop: true,
  51. autoCropWidth: 200,
  52. autoCropHeight: 200,
  53. fixedBox: true
  54. },
  55. previews: {}
  56. }
  57. },
  58. methods: {
  59. edit (id) {
  60. this.visible = true
  61. this.id = id
  62. /* 获取原始头像 */
  63. },
  64. close () {
  65. this.id = null
  66. this.visible = false
  67. },
  68. cancelHandel () {
  69. this.close()
  70. },
  71. okHandel () {
  72. const vm = this
  73. vm.confirmLoading = true
  74. setTimeout(() => {
  75. vm.confirmLoading = false
  76. vm.close()
  77. vm.$message.success('上传头像成功')
  78. }, 2000)
  79. },
  80. realTime (data) {
  81. this.previews = data
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="less" scoped>
  87. .avatar-upload-preview {
  88. position: absolute;
  89. top: 50%;
  90. transform: translate(50%, -50%);
  91. width: 180px;
  92. height: 180px;
  93. border-radius: 50%;
  94. box-shadow: 0 0 4px #ccc;
  95. overflow: hidden;
  96. img {
  97. width: 100%;
  98. height: 100%;
  99. }
  100. }
  101. </style>