en-head-img.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view>
  3. <view class="box" @click="isShowPop()">
  4. <image class="left" :src="value" 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" background-color="#fff">
  11. <view class="pop-box" @click="this.editImg(2)">使用相机拍一张</view>
  12. <view class="pop-box" @click="this.editImg(1)">从相册选择一张</view>
  13. </uni-popup>
  14. </view>
  15. </template>
  16. <script>
  17. import { upLoadingFileOss } from "@/common/js/upLoadingFile";
  18. import tools from '@/common/js/tools.js'
  19. export default {
  20. props:{
  21. label: {
  22. type: String,
  23. default: '标题'
  24. },
  25. value:{
  26. type: String,
  27. default: ''
  28. },
  29. },
  30. data(){
  31. return{}
  32. },
  33. methods:{
  34. isShowPop(){
  35. let isH5=false
  36. // #ifdef H5
  37. isH5=true
  38. // #endif
  39. if(isH5){
  40. this.editImg(1)
  41. }else{
  42. this.$refs.popup.open('bottom')
  43. }
  44. },
  45. editImg(type){
  46. uni.chooseImage({
  47. count: 1,
  48. sizeType: ["compressed", "camera"],
  49. sourceType: [type===1?"album":"camera"],
  50. success:(res)=>{
  51. if (res.errMsg == "chooseImage:ok"){
  52. tools.showLoading()
  53. this.upLoadOss(res.tempFiles[0].path)
  54. }else{
  55. tools.error('头像选择失败')
  56. }
  57. }
  58. })
  59. },
  60. upLoadOss(path){
  61. upLoadingFileOss(path).then((res)=>{
  62. if(res){
  63. this.value = res
  64. }else{
  65. tools.error('头像上传失败')
  66. }
  67. tools.hideLoading()
  68. }).catch(()=>{
  69. tools.hideLoading()
  70. })
  71. this.$refs.popup.close()
  72. },
  73. },
  74. }
  75. </script>
  76. <style scoped lang="scss">
  77. .box{
  78. width: 100%;
  79. height: 152rpx;
  80. background-color: #fff;
  81. display: flex;
  82. align-items: center;
  83. justify-content: space-between;
  84. image{
  85. width: 96rpx;
  86. height: 96rpx;
  87. border-radius: 50%;
  88. }
  89. .left{
  90. font-size: 32rpx;
  91. }
  92. .right{
  93. display: flex;
  94. align-items: center;
  95. text{
  96. font-size: 32rpx;
  97. color: #333;
  98. }
  99. image{
  100. width: 40rpx;
  101. height: 40rpx;
  102. }
  103. }
  104. }
  105. .pop-box{
  106. height: 130rpx;
  107. background-color: #fff;
  108. text-align: center;
  109. line-height: 130rpx;
  110. font-size: 30rpx;
  111. }
  112. </style>