uploadPics.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {
  2. icommunity
  3. } from '../../../api/api.js';
  4. const app = getApp()
  5. Page({
  6. data: {
  7. article: {
  8. fileType: 1,
  9. imgs: []
  10. },
  11. imgUrl: app.globalData.imgUrl,
  12. },
  13. clickUpload() {
  14. if (!this.data.article.articleTitle) {
  15. return wx.showToast({
  16. title: '请输入标题'
  17. })
  18. }
  19. if (this.data.article.imgs.length <= 0) {
  20. return wx.showToast({
  21. title: '请添加图片'
  22. })
  23. }
  24. let {article} = this.data
  25. article.filePath = article.imgs.map(i=>i.url).join(',')
  26. delete article.imgs
  27. icommunity.loadPubArticle({reqdata:article}, r => {
  28. wx.showToast({
  29. mask: true,
  30. title: '提交成功',
  31. success() {
  32. setTimeout(wx.navigateBack, 1800)
  33. }
  34. })
  35. })
  36. },
  37. inputTitle(e) {
  38. this.setData({
  39. ['article.articleTitle']: e.detail.value
  40. })
  41. },
  42. inputContent(e) {
  43. this.setData({
  44. ['article.articleContent']: e.detail.value
  45. })
  46. },
  47. clickImg(e) {
  48. this.data.article.imgs.splice(e.currentTarget.dataset.i, 1)
  49. this.setData({
  50. ['article.imgs']: this.data.article.imgs
  51. })
  52. },
  53. clickAddpic() {
  54. wx.chooseImage({
  55. count: 1,
  56. success: r => {
  57. icommunity.uploadPics(r.tempFilePaths[0], r => {
  58. wx.showToast({
  59. title: '上传成功!'
  60. })
  61. this.data.article.imgs.push(r)
  62. this.setData({
  63. ['article.imgs']: this.data.article.imgs
  64. })
  65. })
  66. },
  67. })
  68. },
  69. onLoad(args) {}
  70. })