postmessage.vue 5.0 KB

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