addForum.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="index">
  3. <view class="nav">
  4. <text class="t1">取消</text>
  5. <text class="t2" @tap="post">发布话题</text>
  6. </view>
  7. <view class="content">
  8. <view class="item">
  9. <input
  10. class="input1"
  11. v-model="info.title"
  12. type="text"
  13. value=""
  14. placeholder="#输入您想创建的新话题#"
  15. placeholder-style="color: #999999;font-weight: 800;font-size: 30upx;"
  16. />
  17. </view>
  18. <view class="item"><textarea maxlength="-1" placeholder="对话题补充说明,可以获得更多解答" v-model="info.content" placeholder-style="color: #CCCCCC;" /></view>
  19. </view>
  20. <view class="img">
  21. <image :src="host + v" @tap="remove(i)" mode="" v-for="(v, i) in info.images" :key="i"></image>
  22. <image src="../../static/add.png" @tap="uploadImage" mode=""></image>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import helper from '../../common/helper.js';
  28. import api from '../../common/api.js';
  29. export default {
  30. data() {
  31. return {
  32. host: helper.host,
  33. info: {
  34. images: []
  35. },
  36. msg: ''
  37. };
  38. },
  39. methods: {
  40. remove(index) {
  41. uni.showModal({
  42. title: '操作提示',
  43. content: '确认要移除该图片吗',
  44. success: res => {
  45. if (res.confirm) {
  46. this.info.images.splice(this.index, 1);
  47. }
  48. }
  49. });
  50. },
  51. async post() {
  52. if (!this.info.title) {
  53. helper.toast('请输入话题标题');
  54. return false;
  55. }
  56. if (!this.info.content) {
  57. this.info.content = '';
  58. }
  59. let info = {
  60. title: this.info.title,
  61. content: this.info.content,
  62. images: this.info.images.join(',')
  63. };
  64. let res = await api.addMessage(info);
  65. helper.toast(res.msg);
  66. if (res.code == 1) {
  67. setTimeout(() => {
  68. uni.navigateBack({
  69. url: '/pages/forum/forum'
  70. });
  71. }, 1000);
  72. }
  73. },
  74. uploadImage() {
  75. uni.chooseImage({
  76. success: chooseImageRes => {
  77. const tempFilePaths = chooseImageRes.tempFilePaths;
  78. uni.uploadFile({
  79. url: helper.host + '/api/common/upload',
  80. filePath: tempFilePaths[0],
  81. name: 'file',
  82. formData: {
  83. token: helper.getUserToken()
  84. },
  85. success: uploadFileRes => {
  86. let res = JSON.parse(uploadFileRes.data);
  87. helper.toast(res.msg);
  88. if (res.code == 1) {
  89. this.info.images.push(res.data.url);
  90. }
  91. }
  92. });
  93. }
  94. });
  95. }
  96. }
  97. };
  98. </script>
  99. <style lang="scss" scoped>
  100. .pl {
  101. color: #999999;
  102. font-weight: 800;
  103. }
  104. .nav {
  105. padding: 30upx;
  106. display: flex;
  107. justify-content: space-between;
  108. .t1 {
  109. color: #dbdbdb;
  110. font-size: 30upx;
  111. }
  112. .t2 {
  113. color: #67ca58;
  114. font-size: 30upx;
  115. }
  116. }
  117. .item {
  118. border-bottom: 1px solid #eeeeee;
  119. padding: 30upx;
  120. }
  121. textarea {
  122. font-size: 26upx;
  123. }
  124. input {
  125. padding: 20upx 0;
  126. }
  127. // .pl {
  128. // color: #999999;
  129. // font-size: 28upx;
  130. // font-weight: 800;
  131. // }
  132. // .pl2 {
  133. // color: #cccccc;
  134. // font-size: 28upx;
  135. // }
  136. .img {
  137. padding: 30upx;
  138. image {
  139. width: 100upx;
  140. height: 100upx;
  141. margin-right: 20upx;
  142. }
  143. }
  144. </style>