en-head-img.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view>
  3. <view class="box" @click="isShowPop(true)">
  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">
  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. },
  36. methods:{
  37. isShowPop(type){
  38. if(tools.getPlatform()==='H5'){
  39. this.editImg(1)
  40. }else{
  41. if(type){
  42. this.$refs.popup.open("bottom")
  43. }else {
  44. this.$refs.popup.close()
  45. }
  46. }
  47. },
  48. editImg(type){
  49. uni.chooseImage({
  50. count: 1,
  51. sizeType: ["compressed", "camera"],
  52. sourceType: [type===1?"album":"camera"],
  53. success:(res)=>{
  54. if (res.errMsg === "chooseImage:ok"){
  55. tools.showLoading()
  56. this.upLoadOss(res.tempFiles[0].path)
  57. }else{
  58. tools.error('头像选择失败')
  59. }
  60. }
  61. })
  62. },
  63. upLoadOss(path){
  64. upLoadingFileOss(path).then((res)=>{
  65. if(res){
  66. this.value = res
  67. }else{
  68. tools.error('头像上传失败')
  69. }
  70. tools.hideLoading()
  71. }).catch(()=>{
  72. tools.hideLoading()
  73. })
  74. this.$refs.popup.close()
  75. },
  76. },
  77. }
  78. </script>
  79. <style scoped lang="scss">
  80. .popup-block {
  81. border-radius: 20rpx 20rpx 0rpx 0rpx;
  82. overflow: hidden;
  83. background-color: #f5f5f5;
  84. .popup-row {
  85. height: 100rpx;
  86. background-color: #fff;
  87. text-align: center;
  88. line-height: 100rpx;
  89. border-bottom: 2rpx solid #f5f5f5;
  90. &:nth-child(2) {
  91. margin-bottom: 20rpx;
  92. }
  93. &:last-child {
  94. height: 112rpx;
  95. border: none;
  96. line-height: 112rpx;
  97. }
  98. &:active {
  99. background-color: rgb(244, 244, 244);
  100. }
  101. }
  102. }
  103. .box{
  104. width: 100%;
  105. height: 152rpx;
  106. background-color: #fff;
  107. display: flex;
  108. align-items: center;
  109. justify-content: space-between;
  110. image{
  111. width: 96rpx;
  112. height: 96rpx;
  113. border-radius: 50%;
  114. }
  115. .left{
  116. font-size: 32rpx;
  117. }
  118. .right{
  119. display: flex;
  120. align-items: center;
  121. text{
  122. font-size: 32rpx;
  123. color: #333;
  124. }
  125. image{
  126. width: 40rpx;
  127. height: 40rpx;
  128. }
  129. }
  130. }
  131. .pop-box{
  132. height: 130rpx;
  133. background-color: #fff;
  134. text-align: center;
  135. line-height: 130rpx;
  136. font-size: 30rpx;
  137. }
  138. </style>