albumEdit.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // pages/albumEdit/albumEdit.js
  2. // import {
  3. // baseUrl
  4. // } from '../api/request'
  5. const baseUrl = "https://www.cqna.gov.cn/data/"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 基础地址
  12. baseUrl: baseUrl,
  13. // 默认归属日期
  14. vestingDate: '',
  15. // 默认作品年代
  16. pictureType: '',
  17. // 作品年代
  18. array: ['解放前', '解放后-80年代', '80年代-新世纪', '新世纪-千禧年'],
  19. // 图片
  20. img: ''
  21. },
  22. // 提交
  23. formSubmit(e) {
  24. if (e.detail.value.uploaderPhone == '') {
  25. wx.showToast({
  26. title: "作者电话不能为空",
  27. icon: "none",
  28. duration: 1500
  29. })
  30. } else if (!(/^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/.test(e.detail.value.uploaderPhone))) {
  31. wx.showToast({
  32. title: "请输入正确的电话号码",
  33. icon: "none",
  34. duration: 1500
  35. })
  36. } else if (e.detail.value.pictureTitle == '') {
  37. wx.showToast({
  38. title: "作品名称不能为空",
  39. icon: "none",
  40. duration: 1500
  41. })
  42. } else if (e.detail.value.pictureAuthor == '') {
  43. wx.showToast({
  44. title: "作品作者不能为空",
  45. icon: "none",
  46. duration: 1500
  47. })
  48. } else if (e.detail.value.vestingDate == '') {
  49. wx.showToast({
  50. title: "归属日期不能为空",
  51. icon: "none",
  52. duration: 1500
  53. })
  54. } else if (e.detail.value.pictureType == '') {
  55. wx.showToast({
  56. title: "作品年代不能为空",
  57. icon: "none",
  58. duration: 1500
  59. })
  60. } else if (e.detail.value.pictureDescription == '') {
  61. wx.showToast({
  62. title: "作品描述不能为空",
  63. icon: "none",
  64. duration: 1500
  65. })
  66. } else if (this.data.img == '') {
  67. wx.showToast({
  68. title: "我的作品不能为空",
  69. icon: "none",
  70. duration: 1500
  71. })
  72. } else {
  73. e.detail.value.isAnonymous = true ? 1 : 0;
  74. e.detail.value.isPublic = true ? 0 : 1;
  75. wx.uploadFile({
  76. url: this.data.baseUrl + '/yxna/uploadDocumet',
  77. filePath: this.data.img,
  78. name: "file",
  79. header: {
  80. "content-type": "multipart/form-data"
  81. },
  82. formData: e.detail.value,
  83. success: function (res) {
  84. let data = JSON.parse(res.data);
  85. if (data.result) {
  86. wx.showToast({
  87. title: "投稿成功",
  88. icon: "success",
  89. duration: 1500,
  90. success: res => {
  91. setTimeout(() => {
  92. wx.navigateBack({
  93. delta: 1
  94. });
  95. }, 1500)
  96. }
  97. })
  98. } else {
  99. wx.showToast({
  100. title: "投稿失败",
  101. icon: "none",
  102. duration: 2000
  103. })
  104. }
  105. },
  106. fail: function (err) {
  107. wx.showToast({
  108. title: "投稿失败",
  109. icon: "none",
  110. duration: 2000
  111. })
  112. },
  113. complete: function (result) {
  114. // console.log(result.errMsg)
  115. }
  116. })
  117. }
  118. },
  119. // 上传图片
  120. bindUpload: function (e) {
  121. var that = this
  122. wx.chooseMedia({
  123. count: 1,
  124. mediaType: ['image'],
  125. sizeType: ["original", "compressed"],
  126. sourceType: ["album"],
  127. success: function (res) {
  128. var tempFilePaths = res.tempFiles[0];
  129. if (tempFilePaths.size > 1024 * 1024 * 5) {
  130. wx.showToast({
  131. title: "图片过大",
  132. icon: "none",
  133. duration: 1500
  134. })
  135. } else {
  136. that.setData({
  137. img: tempFilePaths.tempFilePath
  138. })
  139. }
  140. }
  141. })
  142. },
  143. // 日期切换
  144. bindDateChange(e) {
  145. // console.log('picker发送选择改变,携带值为', e.detail.value)
  146. this.setData({
  147. vestingDate: e.detail.value
  148. })
  149. },
  150. // 作品年代切换
  151. bindPickerChange: function (e) {
  152. // console.log('picker发送选择改变,携带值为', e.detail.value)
  153. this.setData({
  154. pictureType: e.detail.value
  155. })
  156. },
  157. // 切换作者电话是否公开
  158. publicChange(e) {
  159. if (e.detail.value) {
  160. wx.showToast({
  161. title: "切换为公开",
  162. icon: "none",
  163. duration: 1500
  164. })
  165. } else {
  166. wx.showToast({
  167. title: "切换为不公开",
  168. icon: "none",
  169. duration: 1500
  170. })
  171. }
  172. },
  173. // 切换作者是否匿名
  174. anonymousChange(e) {
  175. if (e.detail.value) {
  176. wx.showToast({
  177. title: "切换为不匿名",
  178. icon: "none",
  179. duration: 1500
  180. })
  181. } else {
  182. wx.showToast({
  183. title: "切换为匿名",
  184. icon: "none",
  185. duration: 1500
  186. })
  187. }
  188. },
  189. /**
  190. * 生命周期函数--监听页面加载
  191. */
  192. onLoad(options) {
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady() {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow() {
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload() {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh() {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom() {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage() {
  228. return {
  229. title: '我要投稿'
  230. };
  231. }
  232. })