addArticle.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <view class="left" @click="onBack()">
  5. <image class="icon" src="../../static/me/arrow_right.png" mode="widthFix" />
  6. </view>
  7. <view class="title">
  8. 发布动态
  9. </view>
  10. <view class="right">
  11. <view class="btn" @click="submitData">发布</view>
  12. </view>
  13. </view>
  14. <view class="list_info">
  15. <view class="area">
  16. <textarea class="content" v-model="content" placeholder="请输入内容..."></textarea>
  17. </view>
  18. <view class="item_tag">
  19. <view class="tag" v-for="(item,index) in list">
  20. <image class="logo" :src="item" mode="aspectFill"></image>
  21. <image class="close" src="../../static/me/close2.png" mode="widthFix" @click="delImg(item)" />
  22. </view>
  23. <view class="tagAdd" @click="upload">
  24. <image class="add" src="../../static/me/icon_add.png" mode="widthFix" />
  25. </view>
  26. </view>
  27. <view class="tips">*最多上传{{maxImageCount}}张图片</view>
  28. <view class="blankHeight"></view>
  29. </view>
  30. <!-- 提示框 -->
  31. <DialogBox ref="DialogBox"></DialogBox>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. components: {},
  37. data() {
  38. return {
  39. title: '',
  40. sel: 1,
  41. list_tag: [
  42. 'xx', 'ff', 'vv'
  43. ],
  44. content: '',
  45. list: [],
  46. maxImageCount: 6
  47. }
  48. },
  49. onLoad() {},
  50. onShow() {
  51. // this.loadData();
  52. },
  53. methods: {
  54. onBack() {
  55. uni.navigateBack()
  56. },
  57. chkSel() {
  58. if (this.sel == 1) {
  59. this.sel = 0;
  60. } else {
  61. this.sel = 1;
  62. }
  63. },
  64. loadData() {
  65. },
  66. submitData() {
  67. let str = "";
  68. if (this.list.length > 6) {
  69. uni.showToast({
  70. title: "最多上传6张图片",
  71. icon: 'none'
  72. });
  73. return;
  74. }
  75. if (this.list != null) {
  76. for (var i = 0; i < this.list.length; i++) {
  77. str += this.list[i] + "|";
  78. }
  79. }
  80. if (str == "") {
  81. if (this.content == "") {
  82. uni.showToast({
  83. title: "请输入内容",
  84. icon: 'none'
  85. });
  86. return;
  87. }
  88. }
  89. uni.request({
  90. url: this.$apiHost + '/Article/add',
  91. data: {
  92. uuid: getApp().globalData.uuid,
  93. content: this.content,
  94. imgs: str,
  95. },
  96. method: 'POST',
  97. header: {
  98. 'Content-Type': 'application/x-www-form-urlencoded',
  99. 'sign': getApp().globalData.headerSign
  100. },
  101. dataType: 'json',
  102. success: (res) => {
  103. console.log("----", res.data);
  104. uni.showToast({
  105. title: res.data.str,
  106. icon: 'none'
  107. });
  108. if (res.data.success == "yes") {
  109. this.list = [];
  110. this.content = "";
  111. setTimeout(function() {
  112. uni.navigateBack()
  113. }, 800);
  114. }
  115. }
  116. });
  117. },
  118. delImg(img) {
  119. if (this.list != null) {
  120. let list2 = [];
  121. for (var i = 0; i < this.list.length; i++) {
  122. if (img != this.list[i]) {
  123. list2.push(this.list[i]);
  124. }
  125. }
  126. this.list = list2;
  127. }
  128. },
  129. upload() {
  130. console.log("----upload");
  131. var that = this;
  132. if (this.list.length >= this.maxImageCount) {
  133. uni.showToast({
  134. title: `最多上传${this.maxImageCount}张图片`,
  135. icon: 'none'
  136. });
  137. return;
  138. }
  139. let count = this.maxImageCount - this.list.length
  140. uni.chooseImage({
  141. count,
  142. sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
  143. sourceType: ['album', 'camera'], //从相册、相机选择
  144. extension: ['.png', '.jpeg', '.jpg'],
  145. success: function(res) {
  146. console.log('res:', res)
  147. uni.showLoading({})
  148. if (res.tempFilePaths.length > 0) {
  149. for (var i = 0; i < res.tempFilePaths.length; i++) {
  150. const tempFilePaths = res.tempFilePaths[i];
  151. console.log('tempFilePaths:', tempFilePaths);
  152. // 图片上传
  153. const uploadTask = uni.uploadFile({
  154. url: that.$apiHost + '/Xweb/upload_img?skey=' + that.skey,
  155. filePath: tempFilePaths,
  156. name: 'file',
  157. success: function(uploadFileRes) {
  158. let resdata = JSON.parse(uploadFileRes.data)
  159. // console.log('Success11:', uploadFileRes);
  160. // console.log('Success21:', resdata);
  161. if (resdata.success == 'yes') {
  162. that.list.push(resdata.url);
  163. // _self.avator = resdata.url;
  164. }
  165. },
  166. fail: function(uploadFileFail) {
  167. console.log('Error:', uploadFileFail.data);
  168. },
  169. complete: () => {
  170. console.log('Complete:');
  171. if (i >= res.tempFilePaths.length - 1) {
  172. uni.hideLoading()
  173. }
  174. }
  175. });
  176. }
  177. setTimeout(function() {
  178. uni.hideLoading()
  179. }, 20000);
  180. }
  181. },
  182. error: function(e) {
  183. console.log(e);
  184. }
  185. });
  186. },
  187. }
  188. }
  189. </script>
  190. <style scoped lang="scss">
  191. @import 'addArticle.scss';
  192. </style>