en-head-img.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. <text class="iconfont">&#xe62b;</text>
  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 "@/service/upLoadingFile";
  21. import tools from '@/service/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. @import url("../../../static/css/en-common.css");
  91. .popup-block {
  92. border-radius: 20rpx 20rpx 0rpx 0rpx;
  93. overflow: hidden;
  94. background-color: #f5f5f5;
  95. .popup-row {
  96. height: 100rpx;
  97. background-color: #fff;
  98. text-align: center;
  99. line-height: 100rpx;
  100. border-bottom: 2rpx solid #f5f5f5;
  101. &:nth-child(2) {
  102. margin-bottom: 20rpx;
  103. }
  104. &:last-child {
  105. height: 112rpx;
  106. border: none;
  107. line-height: 112rpx;
  108. }
  109. &:active {
  110. background-color: rgb(244, 244, 244);
  111. }
  112. }
  113. }
  114. .box{
  115. width: 100%;
  116. height: 152rpx;
  117. background-color: #fff;
  118. display: flex;
  119. align-items: center;
  120. justify-content: space-between;
  121. padding: 0;
  122. image{
  123. width: 96rpx;
  124. height: 96rpx;
  125. border-radius: 50%;
  126. }
  127. .left{
  128. font-size: 32rpx;
  129. }
  130. .right{
  131. display: flex;
  132. align-items: center;
  133. text{
  134. font-size: 32rpx;
  135. color: #333;
  136. }
  137. }
  138. }
  139. .pop-box{
  140. height: 130rpx;
  141. background-color: #fff;
  142. text-align: center;
  143. line-height: 130rpx;
  144. font-size: 30rpx;
  145. }
  146. </style>