0d66f409a972a7bbaaffc33242d6865881a2aef4.svn-base 2.3 KB

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