postmessage.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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" class="require" />
  9. </view>
  10. <view class="post_contert">
  11. <textarea class="require" 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="'http://www.hnyfwlw.com:8006/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. console.log(this.title,this.mainbody)
  73. if(!this.title){
  74. uni.showToast({
  75. title: "请输入标题",
  76. icon: "none"
  77. })
  78. return
  79. }
  80. if(this.mainbody==''){
  81. uni.showToast({
  82. title: "请输入正文",
  83. icon: "none"
  84. })
  85. return
  86. }
  87. if(this.title!=''&&this.mainbody!=''){
  88. let obj ={}
  89. obj.title=this.title
  90. obj.content=this.mainbody
  91. this.getPostmessage(obj)
  92. }
  93. },
  94. clickLeft(){
  95. uni.navigateTo({
  96. url: './exchangeShare'
  97. })
  98. },
  99. gainimg(){//添加图片
  100. uni.chooseImage({
  101. count: 1, //默认9
  102. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  103. sourceType: ['album','camera'], //从相册选择
  104. success: (res)=> {
  105. console.log(res)
  106. this.url = res.tempFilePaths[0]
  107. }
  108. });
  109. },
  110. onok(ev){
  111. console.log(ev)
  112. this.toloadTF = true
  113. uni.uploadFile({
  114. url: 'http://114.115.147.140:8002/api/api_gateway?method=pest.pests.pests_img', //仅为示例,非真实的接口地址
  115. filePath: ev.path,
  116. name: 'img_file',
  117. formData: {
  118. 'user': 'test'
  119. },
  120. success: (uploadFileRes) => {
  121. console.log(ev.path)
  122. console.log(JSON.parse(uploadFileRes.data).data.src)
  123. this.path = JSON.parse(uploadFileRes.data).data.src
  124. this.uploadingTF=true
  125. this.toloadTF = false
  126. }
  127. });
  128. this.url = ''
  129. },
  130. oncancle(){
  131. },
  132. examine(url) {
  133. var imgarr =[]
  134. imgarr.push(url)
  135. console.log(imgarr)
  136. uni.previewImage({
  137. urls: imgarr
  138. });
  139. },
  140. deletes(){
  141. this.path = ""
  142. this.uploadingTF=false
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .require {
  149. position: relative;
  150. padding-left: 10rpx;
  151. &::before {
  152. content: '*';
  153. line-height: 1;
  154. color: #f00;
  155. position:absolute;
  156. left: 0rpx;
  157. top: 10rpx;
  158. }
  159. }
  160. </style>
  161. <style lang="scss">
  162. page{
  163. background-color: #F5F5F5;
  164. }
  165. .post {
  166. width: 100%;
  167. padding-top: 16rpx;
  168. .post_title {
  169. padding: 40rpx 20rpx;
  170. background-color: white;
  171. width: 100%;
  172. box-sizing: border-box;
  173. input {
  174. width: 90%;
  175. margin: 0 auto;
  176. }
  177. }
  178. .post_contert {
  179. margin-top: 16rpx;
  180. padding: 40rpx 20rpx;
  181. background-color: white;
  182. width: 100%;
  183. height: 700rpx;
  184. box-sizing: border-box;
  185. textarea{
  186. width: 90%;
  187. margin: 0 auto;
  188. }
  189. .imgvideo_img_title{
  190. width: 90%;
  191. margin: 20rpx auto;
  192. font-size: 32rpx;
  193. color: grey;
  194. }
  195. .imgvideo_img{
  196. width: 250rpx;
  197. height: 250rpx;
  198. border: 2rpx solid #57C878;
  199. margin-left: 40rpx;
  200. position: relative;
  201. top: 0;
  202. left: 0;
  203. .imgbg{
  204. width: 100%;
  205. height: 100%;
  206. display: flex;
  207. justify-content: center;
  208. align-items: center;
  209. image{
  210. width: 50rpx;
  211. height: 50rpx;
  212. }
  213. }
  214. .toload{
  215. width: 100%;
  216. height: 100%;
  217. position: absolute;
  218. top: 0;
  219. }
  220. .uploading{
  221. width: 100%;
  222. height: 100%;
  223. .delete{
  224. width: 36rpx;
  225. height: 36rpx;
  226. background-color: #FF0000;
  227. border-radius: 50%;
  228. padding: 2px 2px;
  229. box-sizing: border-box;
  230. position: absolute;
  231. top: -18rpx;
  232. right: -18rpx;
  233. color: #FFFFFF;
  234. z-index: 10;
  235. }
  236. .uploading{
  237. width: 100%;
  238. height: 100%;
  239. position: absolute;
  240. top: 0;
  241. }
  242. }
  243. }
  244. }
  245. .post_btn{
  246. width: 90%;
  247. margin: 40rpx auto;
  248. background-color: #57C878;
  249. color: white;
  250. font-size: 32rpx;
  251. }
  252. }
  253. </style>