input_content.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. // pages/Input_content/input_content.js
  2. const app = getApp();
  3. const url = require('../../utils/const.js');
  4. const APIClient = require('../../utils/APIClient.js');
  5. const login = require('../../utils/loginSchedule.js');
  6. const utils = require('../../utils/util.js');
  7. const HOST = url.apiUrl;
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. tempFilePath: [],
  14. imgId: [],
  15. textValue: '',
  16. upload: true
  17. //type: '',
  18. //columnType: ''
  19. },
  20. /**
  21. * 获取输入框内容
  22. */
  23. bindKeyInput: function(e) {
  24. this.setData({
  25. textValue: e.detail.value
  26. })
  27. },
  28. /**
  29. * 图片上传
  30. */
  31. uploading: function () {
  32. const that = this;
  33. const length = that.data.tempFilePath.length;
  34. if(length < 2) {
  35. wx.chooseImage({
  36. count: 2, //最多可以选择的图片总数
  37. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  38. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  39. success: function (res) {
  40. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  41. var tempFilePaths = res.tempFilePaths;
  42. //启动上传等待中...
  43. wx.showToast({
  44. title: '正在上传...',
  45. icon: 'loading',
  46. mask: true,
  47. duration: 1000
  48. })
  49. for(let item of tempFilePaths){
  50. that.data.tempFilePath.push(item);
  51. }
  52. that.setData({
  53. tempFilePath: that.data.tempFilePath
  54. })
  55. wx.showModal({
  56. title: '上传提示',
  57. content: JSON.stringify(that.data.tempFilePath),
  58. showCancel: false,
  59. success: function (res) { }
  60. })
  61. var uploadImgCount = 0;
  62. for (var i = 0, h = tempFilePaths.length; i < h; i++) {
  63. //上传文件
  64. wx.uploadFile({
  65. url: HOST + '/cms/file/upload',
  66. filePath: tempFilePaths[i],
  67. name: 'uploadfile_ant',
  68. header: {
  69. "Content-Type": "multipart/form-data"
  70. },
  71. success: function (res) {
  72. uploadImgCount++;
  73. let data = JSON.parse(res.data);
  74. that.data.imgId.push(data.data.id)
  75. that.setData({
  76. imgId: that.data.imgId,
  77. })
  78. console.log(data)
  79. //如果是最后一张,则隐藏等待中
  80. if (uploadImgCount == tempFilePaths.length) {
  81. wx.hideToast();
  82. }
  83. },
  84. fail: function (res) {
  85. wx.hideToast();
  86. wx.showModal({
  87. title: '错误提示',
  88. content: '上传图片失败',
  89. showCancel: false,
  90. success: function (res) { }
  91. })
  92. }
  93. });
  94. }
  95. }
  96. });
  97. }else {
  98. this.setData({
  99. upload: false
  100. })
  101. }
  102. },
  103. //点击发送
  104. send: function() {
  105. const type = utils.getUrl().type;
  106. const columnType = utils.getUrl().columnType;
  107. const columnId = utils.column(columnType).columnId;
  108. const columnName = utils.column(columnType).columnName;
  109. if(this.data.imgId.length == 0 && type == 2){
  110. wx.showModal({
  111. title: '提示',
  112. content: '请上传分享的作品',
  113. success: function(res) {
  114. if (res.confirm) {
  115. console.log('用户点击确定')
  116. } else if (res.cancel) {
  117. console.log('用户点击取消')
  118. }
  119. }
  120. })
  121. return false;
  122. }
  123. let data = {
  124. "title": this.data.textValue,
  125. "type": type,
  126. "columnId": columnId,
  127. "columnType": columnType,
  128. "columnNames": columnName,
  129. };
  130. if(type == 2){
  131. data.imagesStrList = this.data.imgId
  132. }
  133. login.getOpenidSessionKey(function(res) {
  134. //console.log(res.data.data.uid);
  135. APIClient.getSendSchedule({
  136. uid: res.data.data.uid
  137. }, data).success(res => {
  138. console.log(res)
  139. if(res.data.success) {
  140. wx.redirectTo({
  141. url: utils.url(columnType)
  142. })
  143. }
  144. })
  145. }, function() {
  146. wx.showModal({
  147. title: '提示',
  148. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  149. showCancel: false,
  150. success: function (res) {
  151. if (res.confirm) {
  152. console.log('用户点击确定')
  153. } else if (res.cancel) {
  154. console.log('用户点击取消')
  155. }
  156. }
  157. })
  158. });
  159. },
  160. cancel: function() {
  161. wx.navigateBack({ changed: true });
  162. },
  163. /**
  164. * 图片预览
  165. */
  166. listenerButtonPreviewImage: function(e) {
  167. let index = e.target.dataset.index;
  168. let that = this;
  169. wx.previewImage({
  170. current: that.data.tempFilePath[index],
  171. urls: that.data.tempFilePath,
  172. //这根本就不走
  173. success: function(res) {
  174. //console.log(res);
  175. },
  176. //也根本不走
  177. fail: function() {
  178. //console.log('fail')
  179. }
  180. })
  181. },
  182. /**
  183. * 生命周期函数--监听页面加载
  184. */
  185. onLoad: function (options) {
  186. if(options.type == 2) {
  187. wx.setNavigationBarTitle({
  188. title: '作品分享'
  189. })
  190. }
  191. if(options.type == 1) {
  192. wx.setNavigationBarTitle({
  193. title: '答疑讨论'
  194. })
  195. }
  196. this.setData({
  197. type: options.type
  198. })
  199. },
  200. /**
  201. * 生命周期函数--监听页面初次渲染完成
  202. */
  203. onReady: function () {
  204. },
  205. /**
  206. * 生命周期函数--监听页面显示
  207. */
  208. onShow: function () {
  209. },
  210. /**
  211. * 生命周期函数--监听页面隐藏
  212. */
  213. onHide: function () {
  214. },
  215. /**
  216. * 生命周期函数--监听页面卸载
  217. */
  218. onUnload: function () {
  219. },
  220. /**
  221. * 页面相关事件处理函数--监听用户下拉动作
  222. */
  223. onPullDownRefresh: function () {
  224. },
  225. /**
  226. * 页面上拉触底事件的处理函数
  227. */
  228. onReachBottom: function () {
  229. },
  230. /**
  231. * 用户点击右上角分享
  232. */
  233. onShareAppMessage: function () {
  234. }
  235. })