postmessage.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  5. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="发帖"></uni-nav-bar>
  6. <view class="post">
  7. <view class="post_title">
  8. <input type="text" placeholder="请输入标题" v-model="title" />
  9. </view>
  10. <view class="post_contert">
  11. <textarea v-model="mainbody" placeholder="请输入正文" />
  12. <view class="imgvideo_img">
  13. <view @click="gainimg" class="imgbg">
  14. <image :src="'http://static.yfpyx.com/bigdata_app'+'/image/afterSale/eee1e84bb85f6f6ff5c5866a3a42779.png'" mode="" v-if="!uploadingTF"></image>
  15. </view>
  16. <view class="uploading" v-if="uploadingTF">
  17. <u-icon name="close" class="delete" @click="deletes"></u-icon>
  18. <image :src="path" mode="" class="uploading" @click="examine(path)"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <button class="post_btn" @click="post">发布</button>
  23. </view>
  24. </view>
  25. <kps-image-cutter @ok="onok" @cancel="oncancle" :url="url" :fixed="false" :blob="false" :maxWidth="500" :maxHeight="500"></kps-image-cutter>
  26. </view>
  27. </template>
  28. <script>
  29. import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue";
  30. export default {
  31. components:{
  32. kpsImageCutter
  33. },
  34. data() {
  35. return {
  36. title:'',
  37. mainbody:'',
  38. uploadingTF:false,
  39. url:"",
  40. path:""
  41. }
  42. },
  43. methods: {
  44. async getPostmessage(data) { //发帖
  45. const res = await this.$myRequest({
  46. url: '/api/api_gateway?method=pest.pests.pests_new_idea',
  47. data:{
  48. title:data.title,
  49. content:data.content,
  50. img_urls:this.path
  51. }
  52. })
  53. console.log(res)
  54. },
  55. post(){
  56. if(this.title!=''&&this.mainbody!=''){
  57. let obj ={}
  58. obj.title=this.title
  59. obj.content=this.mainbody
  60. this.getPostmessage(obj)
  61. uni.navigateTo({
  62. url: './exchangeShare'
  63. })
  64. }
  65. },
  66. clickLeft(){
  67. uni.navigateTo({
  68. url: './exchangeShare'
  69. })
  70. },
  71. gainimg(){//添加图片
  72. uni.chooseImage({
  73. count: 1, //默认9
  74. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  75. sourceType: ['album','camera'], //从相册选择
  76. success: (res)=> {
  77. console.log(res)
  78. this.url = res.tempFilePaths[0]
  79. }
  80. });
  81. },
  82. onok(ev){
  83. console.log(ev)
  84. uni.uploadFile({
  85. url: 'http://182.92.193.64:8002/api/api_gateway?method=pest.pests.pests_img', //仅为示例,非真实的接口地址
  86. filePath: ev.path,
  87. name: 'img_file',
  88. formData: {
  89. 'user': 'test'
  90. },
  91. success: (uploadFileRes) => {
  92. console.log(JSON.parse(uploadFileRes.data).data.src)
  93. this.path = JSON.parse(uploadFileRes.data).data.src
  94. this.uploadingTF=true
  95. }
  96. });
  97. this.url = ''
  98. },
  99. oncancle(){
  100. },
  101. examine(url) {
  102. var imgarr =[]
  103. imgarr.push(url)
  104. console.log(imgarr)
  105. uni.previewImage({
  106. urls: imgarr
  107. });
  108. },
  109. deletes(){
  110. this.path = ""
  111. this.uploadingTF=false
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss">
  117. page{
  118. background-color: #F5F5F5;
  119. }
  120. .post {
  121. width: 100%;
  122. padding-top: 16rpx;
  123. .post_title {
  124. padding: 40rpx 20rpx;
  125. background-color: white;
  126. width: 100%;
  127. box-sizing: border-box;
  128. input {
  129. width: 90%;
  130. margin: 0 auto;
  131. }
  132. }
  133. .post_contert {
  134. margin-top: 16rpx;
  135. padding: 40rpx 20rpx;
  136. background-color: white;
  137. width: 100%;
  138. height: 660rpx;
  139. box-sizing: border-box;
  140. textarea{
  141. width: 90%;
  142. margin: 0 auto;
  143. }
  144. .imgvideo_img{
  145. width: 250rpx;
  146. height: 250rpx;
  147. border: 2rpx solid #57C878;
  148. margin-left: 40rpx;
  149. position: relative;
  150. top: 0;
  151. left: 0;
  152. .imgbg{
  153. width: 100%;
  154. height: 100%;
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. image{
  159. width: 50rpx;
  160. height: 50rpx;
  161. }
  162. }
  163. .uploading{
  164. width: 100%;
  165. height: 100%;
  166. .delete{
  167. width: 36rpx;
  168. height: 36rpx;
  169. background-color: #FF0000;
  170. border-radius: 50%;
  171. padding: 2px 2px;
  172. box-sizing: border-box;
  173. position: absolute;
  174. top: -18rpx;
  175. right: -18rpx;
  176. color: #FFFFFF;
  177. z-index: 10;
  178. }
  179. .uploading{
  180. width: 100%;
  181. height: 100%;
  182. position: absolute;
  183. top: 0;
  184. }
  185. }
  186. }
  187. }
  188. .post_btn{
  189. width: 90%;
  190. margin: 40rpx auto;
  191. background-color: #57C878;
  192. color: white;
  193. font-size: 32rpx;
  194. }
  195. }
  196. </style>