postmessage.vue 5.3 KB

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