avatar.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <!--头像剪裁上传(单张)-->
  2. <template>
  3. <view class="avatar">
  4. <image :src="ip + head" mode="widthFix" class="head" @click="show = true" v-if="head"></image>
  5. <image style="background-color: white" class="head" @click="show = true" v-else></image>
  6. <!--头像上传-->
  7. <u-popup :show="show" @close="show = false" round="15">
  8. <view class="ppopup">
  9. <view v-show="desc">
  10. <view class="form_group">
  11. <view class="lable">
  12. <text class="icon right">&#xe612;</text>
  13. <text>正确示范</text>
  14. </view>
  15. <view class="bz"><text>上传真实头像,更容易获得好感</text></view>
  16. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717489936671.jpg" mode="widthFix" class="avatar" style="border-radius: 5px"></image>
  17. </view>
  18. <view class="form_group">
  19. <view class="lable">
  20. <text class="icon error">&#xe634;</text>
  21. <text>不佳示范</text>
  22. </view>
  23. <view class="flex" style="margin-top: 5px">
  24. <view class="f">
  25. <view class="cdn">
  26. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717489842705.jpg" class="img"></image>
  27. <view class="desc">非人物照</view>
  28. </view>
  29. </view>
  30. <view class="f">
  31. <view class="cdn">
  32. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717489862536.jpg" class="img"></image>
  33. <view class="desc">五官遮挡</view>
  34. </view>
  35. </view>
  36. <view class="f">
  37. <view class="cdn">
  38. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717489936671.jpg" class="img" style="filter: blur(2px)"></image>
  39. <view class="desc">模糊不清</view>
  40. </view>
  41. </view>
  42. <view class="f">
  43. <view class="cdn">
  44. <image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717489876080.jpg" class="img"></image>
  45. <view class="desc">衣着不当</view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. <button class="btn" @click="chooseImage('camera ')">拍照</button>
  52. <button class="btn" @click="chooseImage('album')">从相册选择</button>
  53. </view>
  54. </u-popup>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. name: 'avatar',
  60. props: {
  61. value: {
  62. type: String
  63. },
  64. desc: {
  65. type: Boolean,
  66. default: true
  67. }
  68. },
  69. data() {
  70. return {
  71. show: false,
  72. head: this.value,
  73. ip: this.http.ip
  74. };
  75. },
  76. watch: {
  77. value(newValue) {
  78. this.head = newValue;
  79. }
  80. },
  81. mounted() {
  82. // 监听从裁剪页发布的事件,获得裁剪结果
  83. uni.$on('uAvatarCropper', path => {
  84. uni.showLoading({ title: '正在上传...', mask: true });
  85. // 上传到服务端
  86. uni.uploadFile({
  87. url: this.http.ip + '/app/common/upload',
  88. filePath: path,
  89. name: 'file',
  90. header: { Authorization: this.getUser().token },
  91. success: res => {
  92. let r = JSON.parse(res.data);
  93. if (r.code === 200) {
  94. this.head = r.fileName;
  95. this.$emit('input', r.fileName);
  96. } else {
  97. uni.hideLoading();
  98. uni.showModal({ content: r.msg, showCancel: false });
  99. }
  100. }
  101. });
  102. });
  103. },
  104. methods: {
  105. chooseImage(source) {
  106. this.show = false;
  107. uni.navigateTo({
  108. url: '/components/u-avatar-cropper/u-avatar-cropper?destWidth=300&rectWidth=200&fileType=jpg&source=' + source
  109. });
  110. }
  111. }
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. .avatar {
  116. .head {
  117. width: 55px;
  118. height: 55px;
  119. border-radius: 50%;
  120. }
  121. .ppopup {
  122. padding: 30px 20px 40px 20px;
  123. border-radius: 15px 15px 0px 0px;
  124. .right {
  125. font-size: 16px;
  126. padding-right: 5px;
  127. color: green;
  128. }
  129. .error {
  130. font-size: 16px;
  131. padding-right: 5px;
  132. color: orange;
  133. }
  134. .cdn {
  135. font-size: 13px;
  136. overflow: hidden;
  137. margin: 5px;
  138. .img {
  139. width: 60px;
  140. height: 60px;
  141. margin: 0 auto;
  142. margin-bottom: 3px;
  143. border-radius: 5px;
  144. }
  145. }
  146. .btn {
  147. margin-top: 20px;
  148. }
  149. }
  150. }
  151. </style>