uni-list-item-upload.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view>
  3. <uni-nav-bar
  4. status-bar = true
  5. fixed = true
  6. left-icon="arrowthinleft"
  7. background-color="#03b6b3"
  8. color="#ffffff"
  9. @clickLeft="navigateBack">
  10. <text slot="default" style="text-align: center; flex: 1; font-size: 18px; font-weight: bold;">照片</text>
  11. <button slot="right" @click="handleClick" size="mini" style="height: 30px; color: #FFFFFF; background-color: #1e9694; padding: 0 10px">确定</button>
  12. </uni-nav-bar>
  13. <view class="file-container">
  14. <view class="file-view" @click="upLoadImg">
  15. <image v-if="imageUrl" :src="websiteUrl+imageUrl" mode=""></image>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. Authorization: {},
  25. imageUrl: ''
  26. }
  27. },
  28. mounted() {
  29. this.upLoadImg();
  30. },
  31. methods: {
  32. upLoadImg(){
  33. this.Authorization.Authorization = 'Bearer ' + uni.getStorageSync('Auth-Token');
  34. uni.chooseImage({
  35. success: (chooseImageRes) => {
  36. const tempFilePaths = chooseImageRes.tempFilePaths;
  37. uni.uploadFile({
  38. url: this.uploadUrl,
  39. // url: 'http://10.0.1.160:7000/meeting/upload/file/',
  40. // url: 'http://localhost:8080/api/meeting/upload/file/',
  41. filePath: tempFilePaths[0],
  42. name: 'upload',
  43. header: this.Authorization,
  44. formData: {
  45. 'user': 'test'
  46. },
  47. success: (uploadFileRes) => {
  48. console.log('uploadFileRes', uploadFileRes);
  49. this.imageUrl = JSON.parse(uploadFileRes.data).data.path;
  50. this.$emit('input', this.imageUrl);
  51. },
  52. fail:(error) => {
  53. console.log(error)
  54. }
  55. });
  56. }
  57. });
  58. },
  59. handleClick(){
  60. const eventChannel = this.getOpenerEventChannel()
  61. eventChannel.emit('acceptImageUrl', {url: this.imageUrl});
  62. uni.navigateBack()
  63. },
  64. navigateBack(){
  65. uni.navigateBack()
  66. }
  67. }
  68. }
  69. </script>
  70. <style scoped>
  71. .file-container{
  72. width: 100vw;
  73. height: calc(100vh - 44px);
  74. background-color: #333333;
  75. position: relative;
  76. }
  77. .file-view {
  78. /* 照片比例 5:7 */
  79. width: 90vw;
  80. height: 126vw;
  81. background: #FFFFFF;
  82. position: absolute;
  83. top: 50%;
  84. left: 50%;
  85. transform: translate(-50%, -50%);
  86. border: 1px dashed #333333;
  87. }
  88. .file-view::after{
  89. content: '+';
  90. position: absolute;
  91. top: 50%;
  92. left: 50%;
  93. font-size: 160rpx;
  94. color: #666;
  95. transform: translate(-50%, -50%);
  96. }
  97. .file-view image{
  98. position: absolute;
  99. width: 100%;
  100. height: 100%;
  101. top: 0;
  102. left: 0;
  103. z-index: 9;
  104. }
  105. </style>