详情小程序
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.5 KiB

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