en-head-img.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view>
  3. <view class="box" @click="isShowPop(true)">
  4. <image class="left" :src="headImg" mode="aspectFill"></image>
  5. <view class="right">
  6. <text>{{label}}</text>
  7. <image src="@/static/img/toRight.png" mode=""></image>
  8. </view>
  9. </view>
  10. <uni-popup ref="popup" type="bottom">
  11. <view class="popup-block">
  12. <view class="popup-row" @click="editImg(1)">拍照</view>
  13. <view class="popup-row" @click="editImg(2)">从手机里面选择</view>
  14. <view class="popup-row" @click="isShowPop(false)">取消</view>
  15. </view>
  16. </uni-popup>
  17. </view>
  18. </template>
  19. <script>
  20. import { upLoadingFileOss } from "@/common/js/upLoadingFile";
  21. import tools from '@/common/js/tools.js'
  22. export default {
  23. props:{
  24. label: {
  25. type: String,
  26. default: '标题'
  27. },
  28. value:{
  29. type: String,
  30. default: ''
  31. },
  32. },
  33. data(){
  34. return{
  35. headImg:''
  36. }
  37. },
  38. watch:{
  39. 'headImg':function (){
  40. this.$emit('input',this.headImg)
  41. }
  42. },
  43. mounted() {
  44. this.headImg=this.value
  45. },
  46. methods:{
  47. isShowPop(type){
  48. if(tools.getPlatform()==='H5'){
  49. this.editImg(1)
  50. }else{
  51. if(type){
  52. this.$refs.popup.open("bottom")
  53. }else {
  54. this.$refs.popup.close()
  55. }
  56. }
  57. },
  58. editImg(type){
  59. uni.chooseImage({
  60. count: 1,
  61. sizeType: ["compressed", "camera"],
  62. sourceType: [type===1?"album":"camera"],
  63. success:(res)=>{
  64. if (res.errMsg === "chooseImage:ok"){
  65. tools.showLoading()
  66. this.upLoadOss(res.tempFiles[0].path)
  67. }else{
  68. tools.error('头像选择失败')
  69. }
  70. }
  71. })
  72. },
  73. upLoadOss(path){
  74. upLoadingFileOss(path).then((res)=>{
  75. if(res){
  76. this.headImg = res
  77. }else{
  78. tools.error('头像上传失败')
  79. }
  80. tools.hideLoading()
  81. }).catch(()=>{
  82. tools.hideLoading()
  83. })
  84. this.$refs.popup.close()
  85. },
  86. },
  87. }
  88. </script>
  89. <style scoped lang="scss">
  90. .popup-block {
  91. border-radius: 20rpx 20rpx 0rpx 0rpx;
  92. overflow: hidden;
  93. background-color: #f5f5f5;
  94. .popup-row {
  95. height: 100rpx;
  96. background-color: #fff;
  97. text-align: center;
  98. line-height: 100rpx;
  99. border-bottom: 2rpx solid #f5f5f5;
  100. &:nth-child(2) {
  101. margin-bottom: 20rpx;
  102. }
  103. &:last-child {
  104. height: 112rpx;
  105. border: none;
  106. line-height: 112rpx;
  107. }
  108. &:active {
  109. background-color: rgb(244, 244, 244);
  110. }
  111. }
  112. }
  113. .box{
  114. width: 100%;
  115. height: 152rpx;
  116. background-color: #fff;
  117. display: flex;
  118. align-items: center;
  119. justify-content: space-between;
  120. image{
  121. width: 96rpx;
  122. height: 96rpx;
  123. border-radius: 50%;
  124. }
  125. .left{
  126. font-size: 32rpx;
  127. }
  128. .right{
  129. display: flex;
  130. align-items: center;
  131. text{
  132. font-size: 32rpx;
  133. color: #333;
  134. }
  135. image{
  136. width: 40rpx;
  137. height: 40rpx;
  138. }
  139. }
  140. }
  141. .pop-box{
  142. height: 130rpx;
  143. background-color: #fff;
  144. text-align: center;
  145. line-height: 130rpx;
  146. font-size: 30rpx;
  147. }
  148. </style>