金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.4 KiB

  1. <template>
  2. <view>
  3. <lf-nav title="发表" :showIcon="true" :backInquiry="backInquiry"></lf-nav>
  4. <view class="content">
  5. <!-- 文本输入 -->
  6. <textarea class="textarea" placeholder="这一刻的想法…" v-model="content"></textarea>
  7. <!-- 上传图片 -->
  8. <view class="my-images">
  9. <view class="my-image-item" @click="uploadImage" v-if="image_list.length < 6">
  10. <text class="lf-iconfont icon-jia my-image-item-after"></text>
  11. </view>
  12. <view class="my-image-item" v-for="(item, index) in image_list" :key="index" @click="lookImage(index)">
  13. <image :src="item" mode="aspectFill"></image>
  14. <view class="remove-image" @click.stop="removeInage(index)">
  15. <text class="lf-iconfont icon-shanchu"></text>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 发表按钮 -->
  20. <button class="my-btn" hover-class="lf-opacity">发表</button>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data(){
  27. return {
  28. image_list: [],
  29. image_count: 6,
  30. content: '',
  31. backInquiry: false
  32. }
  33. },
  34. watch: {
  35. content(val){
  36. if(String(val).length){
  37. this.backInquiry = true;
  38. }else{
  39. this.backInquiry = false;
  40. }
  41. }
  42. },
  43. onLoad(){
  44. },
  45. methods: {
  46. // 上传凭证图片
  47. uploadImage(){
  48. let current_count = this.image_count - this.image_list.length;
  49. if(current_count == 0) return;
  50. uni.chooseImage({
  51. count: current_count,
  52. complete: result => {
  53. if(result.errMsg == "chooseImage:fail cancel"){
  54. return; // 取消选择图片
  55. }
  56. let tempFiles = result.tempFiles;
  57. let image_list = [];
  58. let overstep = false;
  59. tempFiles.map(item => {
  60. // 上传的图片需小于10MB
  61. if(item.size < 10464788){
  62. image_list.push(item.path);
  63. }else{
  64. overstep = true;
  65. }
  66. })
  67. if(overstep){
  68. uni.showModal({
  69. title: '温馨提示',
  70. content: '您上传的图片含有超出10M大小的限制,请优化大小后再上传!',
  71. showCancel: false
  72. })
  73. }
  74. this.image_list.push(...image_list);
  75. }
  76. })
  77. },
  78. // 预览图片
  79. lookImage(current){
  80. if(this.image_list.length <= 0) return;
  81. this.$u.throttle(() => {
  82. uni.previewImage({
  83. urls: this.image_list,
  84. current: current
  85. });
  86. }, 500);
  87. },
  88. // 移除图片
  89. removeInage(current){
  90. this.image_list.splice(current, 1);
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped="scoped">
  96. .content{
  97. width: 750rpx;
  98. height: max-content;
  99. box-sizing: border-box;
  100. padding: 30rpx 32rpx;
  101. .textarea{
  102. width: 100%;
  103. height: 160rpx;
  104. }
  105. }
  106. .my-images{
  107. display: flex;
  108. flex-wrap: wrap;
  109. margin-top: 30rpx;
  110. margin-bottom: 18rpx;
  111. .my-image-item{
  112. width: 220rpx;
  113. height: 220rpx;
  114. background: #DDDDDD;
  115. position: relative;
  116. margin-right: 12rpx;
  117. &:nth-child(3n){
  118. margin-right: 0rpx;
  119. }
  120. &:nth-child(n+4){
  121. margin-top: 12rpx;
  122. }
  123. image{
  124. width: 100%;
  125. height: 100%;
  126. }
  127. .remove-image{
  128. position: absolute;
  129. right: -4rpx;
  130. top: -18rpx;
  131. color: #e74c3c;
  132. font-size: 40rpx;
  133. padding: 8rpx;
  134. }
  135. }
  136. .my-image-item-after{
  137. position: absolute;
  138. width: 100%;
  139. height: 100%;
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. font-size: 60rpx;
  144. color: #999999;
  145. }
  146. }
  147. .my-btn{
  148. margin-top: 30rpx;
  149. background-color: #15716E;
  150. color: #FFFFFF;
  151. }
  152. /deep/.textarea-placeholder{
  153. color: #999999;
  154. line-height: 1;
  155. vertical-align: middle;
  156. }
  157. </style>