publish.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template name="publish">
  2. <view class="cu-modal show">
  3. <view class="cu-dialog">
  4. <view class="cu-bar bg-white justify-end">
  5. <view class="content">{{title}}</view>
  6. <view class="action" @tap="hideModal">
  7. <text class="cuIcon-close text-red"></text>
  8. </view>
  9. </view>
  10. <view class="padding-xls">
  11. <view class="publish-wrap bg-white">
  12. <view class="input-box padding-sm">
  13. <textarea class="area-top" placeholder="写点啥..." maxlength="10000" v-model="content"></textarea>
  14. </view>
  15. <view class="cu-form-group img-box" v-if="is_upload">
  16. <view class="next-title">上传图片(最多{{total}}张)</view>
  17. <view class="margin-none margin-left">
  18. <view class="grid col-5 grid-square flex-sub padding-top-lg">
  19. <view class="bg-img" v-for="(item,index) in pic" :key="index">
  20. <image :src="item" mode="aspectFill" @tap="Dever.viewPic(pic, item)" class="img-item"></image>
  21. <image src="@/static/img/publish/img_close.png" @tap.stop="del" :data-index="index" mode="widthFix" class="close-img"></image>
  22. </view>
  23. <view class="add-img" @tap="choose" v-if="pic.length<total">
  24. <text class='cuIcon-add link-color'></text>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="cu-bar bg-white">
  32. <view class="action margin-0 flex-sub text-green" @tap="hideModal" v-if="is_upload" style="display: none;">
  33. <text class="cuIcon-moneybag"></text>藏点钱
  34. </view>
  35. <view class="action margin-0 flex-sub text-green solid-left" @tap="save">发布</view>
  36. <view class="action margin-0 flex-sub solid-left" @tap="hideModal">取消</view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. name : 'publish',
  44. props: {
  45. title : '',
  46. cate_id : null,
  47. type : null,
  48. type_id : 0,
  49. to_id : 0,
  50. to_uid : 0,
  51. index : 0,
  52. is_upload : true,
  53. seconds : 0,
  54. api : {
  55. type : String,
  56. default : 'app/community/?l=api.add'
  57. },
  58. playtime : 0,
  59. },
  60. data() {
  61. return {
  62. pic : [],
  63. content : '',
  64. upload : 'img',
  65. total : 9,
  66. };
  67. },
  68. mounted() {
  69. // 初始化上传数据
  70. this.Dever.getUpload().data = {};
  71. this.Dever.getUpload().data[this.upload] = [];
  72. this.pic = [];
  73. },
  74. methods: {
  75. // 保存数据
  76. save : function() {
  77. var self = this;
  78. var data = {};
  79. data.content = this.content;
  80. if (this.pic.length > 0) {
  81. data.pic = this.pic.join(',');
  82. }
  83. if (this.cate_id) {
  84. data.cate_id = this.cate_id;
  85. }
  86. if (this.seconds) {
  87. data.seconds = this.seconds;
  88. }
  89. data.playtime = this.playtime;
  90. data.type = this.type;
  91. data.type_id = this.type_id;
  92. data.to_id = this.to_id;
  93. data.to_uid = this.to_uid;
  94. if (this.Dever.config.code) {
  95. data.code = this.Dever.config.code;
  96. }
  97. this.Dever.post(this.api, data, function(t) {
  98. self.getRefresh(data.content);
  99. });
  100. },
  101. // 选择图片
  102. choose: function() {
  103. var self = this;
  104. var upload = this.Dever.upload(this.upload, this.total, function(type, img) {
  105. self.pic = img;
  106. });
  107. },
  108. // 删除图片
  109. del : function(e) {
  110. var self = this;
  111. self.pic.splice(e.currentTarget.dataset.index, 1)
  112. },
  113. hideModal : function() {
  114. this.$emit('hideModal');
  115. },
  116. getRefresh : function(content) {
  117. this.$emit('getRefresh', this.cate_id, this.type, this.type_id, content);
  118. }
  119. }
  120. }
  121. </script>
  122. <style lang="less" scoped>
  123. .textarea-placeholder {
  124. text-align: left;;
  125. }
  126. .grid.grid-square {
  127. overflow: visible;
  128. }
  129. .margin-left {
  130. width: 100%;
  131. font-size: 13px;
  132. line-height: 21px;
  133. margin-left: -60rpx;
  134. }
  135. .publish-wrap {
  136. .input-box {
  137. .area-top {
  138. width: 100%;
  139. box-shadow: inset 0 -1px 0 0 #ECECEC;
  140. min-height: 280rpx;
  141. text-align: left;
  142. }
  143. }
  144. .img-box {
  145. padding: 30rpx;
  146. display: flex;
  147. flex-direction: column;
  148. margin-top: 20rpx;
  149. margin-bottom: 160rpx;
  150. .next-title {
  151. width: 100%;
  152. font-size: 36rpx;
  153. color: var(--mainColor);
  154. }
  155. .font-red {
  156. color: #ff0000;
  157. }
  158. .img-wrap {
  159. width: 100%;
  160. font-size: 28rpx;
  161. line-height: 44rpx;
  162. color: #999999;
  163. margin: 20rpx 0;
  164. }
  165. .add-img {
  166. left: 60rpx;
  167. border: 4rpx dashed #999;
  168. font-size: 40rpx;
  169. }
  170. }
  171. .bottom-btn {
  172. position: fixed;
  173. bottom: 0;
  174. width: 100%;
  175. padding: 20rpx 0;
  176. .btn {
  177. border-radius: 40rpx;
  178. display: flex;
  179. align-items: center;
  180. justify-content: center;
  181. color: #FFFFFF;
  182. border: 1rpx solid var(--activeColor);
  183. background-color: var(--activeColor);
  184. box-shadow: 0 1px 10px 0px var(--activeColor);
  185. width: 400rpx;
  186. height: 80rpx;
  187. }
  188. }
  189. }
  190. .bg-img {
  191. overflow: visible !important;
  192. .img-item {
  193. border-radius: 20rpx;
  194. }
  195. .close-img {
  196. position: absolute;
  197. width: 36rpx !important;
  198. top: -18rpx;
  199. right: -18rpx;
  200. }
  201. }
  202. </style>