uploadPics.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.coverImage = article.imgs[0] && article.imgs[0].url
  26. article.filePath = article.imgs.map(i=>i.url).join(',')
  27. delete article.imgs
  28. icommunity.loadPubArticle({reqdata:article}, r => {
  29. wx.showToast({
  30. mask: true,
  31. title: '提交成功',
  32. success() {
  33. setTimeout(wx.navigateBack, 1300)
  34. }
  35. })
  36. })
  37. },
  38. inputTitle(e) {
  39. this.setData({
  40. ['article.articleTitle']: e.detail.value
  41. })
  42. },
  43. inputContent(e) {
  44. this.setData({
  45. ['article.articleContent']: e.detail.value
  46. })
  47. },
  48. clickImg(e) {
  49. this.data.article.imgs.splice(e.currentTarget.dataset.i, 1)
  50. this.setData({
  51. ['article.imgs']: this.data.article.imgs
  52. })
  53. },
  54. clickAddpic() {
  55. wx.chooseImage({
  56. count: 1,
  57. success: r => {
  58. icommunity.uploadPics(r.tempFilePaths[0], r => {
  59. wx.showToast({
  60. title: '上传成功!'
  61. })
  62. this.data.article.imgs.push(r)
  63. this.setData({
  64. ['article.imgs']: this.data.article.imgs
  65. })
  66. })
  67. },
  68. })
  69. },
  70. onLoad(args) {}
  71. })