input_content.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. var uploadImgCount = 0;
  56. for (var i = 0, h = tempFilePaths.length; i < h; i++) {
  57. //上传文件
  58. wx.uploadFile({
  59. url: HOST + '/cms/file/upload',
  60. filePath: tempFilePaths[i],
  61. name: 'uploadfile_ant',
  62. header: {
  63. "Content-Type": "multipart/form-data"
  64. },
  65. success: function (res) {
  66. uploadImgCount++;
  67. let data = JSON.parse(res.data);
  68. that.data.imgId.push(data.data.id)
  69. that.setData({
  70. imgId: that.data.imgId,
  71. })
  72. console.log(data)
  73. //如果是最后一张,则隐藏等待中
  74. if (uploadImgCount == tempFilePaths.length) {
  75. wx.hideToast();
  76. }
  77. },
  78. fail: function (res) {
  79. wx.hideToast();
  80. wx.showModal({
  81. title: '错误提示',
  82. content: '上传图片失败',
  83. showCancel: false,
  84. success: function (res) { }
  85. })
  86. }
  87. });
  88. }
  89. }
  90. });
  91. }else {
  92. this.setData({
  93. upload: false
  94. })
  95. }
  96. },
  97. //点击发送
  98. send: function() {
  99. const type = utils.getUrl().type;
  100. const columnType = utils.getUrl().columnType;
  101. const columnId = utils.column(columnType).columnId;
  102. const columnName = utils.column(columnType).columnName;
  103. if(this.data.imgId.length == 0 && type == 2){
  104. wx.showModal({
  105. title: '提示',
  106. content: '请上传分享的作品',
  107. success: function(res) {
  108. if (res.confirm) {
  109. console.log('用户点击确定')
  110. } else if (res.cancel) {
  111. console.log('用户点击取消')
  112. }
  113. }
  114. })
  115. return false;
  116. }
  117. let data = {
  118. "title": this.data.textValue,
  119. "type": type,
  120. "columnId": columnId,
  121. "columnType": columnType,
  122. "columnNames": columnName,
  123. };
  124. if(type == 2){
  125. data.imagesStrList = this.data.imgId
  126. }
  127. login.getOpenidSessionKey(function(res) {
  128. //console.log(res.data.data.uid);
  129. APIClient.getSendSchedule({
  130. uid: res.data.data.uid
  131. }, data).success(res => {
  132. console.log(res)
  133. if(res.data.success) {
  134. wx.redirectTo({
  135. url: utils.url(columnType)
  136. })
  137. }
  138. })
  139. }, function() {
  140. wx.showModal({
  141. title: '提示',
  142. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  143. showCancel: false,
  144. success: function (res) {
  145. if (res.confirm) {
  146. console.log('用户点击确定')
  147. } else if (res.cancel) {
  148. console.log('用户点击取消')
  149. }
  150. }
  151. })
  152. });
  153. },
  154. cancel: function() {
  155. wx.navigateBack({ changed: true });
  156. },
  157. /**
  158. * 图片预览
  159. */
  160. listenerButtonPreviewImage: function(e) {
  161. let index = e.target.dataset.index;
  162. let that = this;
  163. wx.previewImage({
  164. current: that.data.tempFilePath[index],
  165. urls: that.data.tempFilePath,
  166. //这根本就不走
  167. success: function(res) {
  168. //console.log(res);
  169. },
  170. //也根本不走
  171. fail: function() {
  172. //console.log('fail')
  173. }
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面加载
  178. */
  179. onLoad: function (options) {
  180. if(options.type == 2) {
  181. wx.setNavigationBarTitle({
  182. title: '作品展示'
  183. })
  184. }
  185. if(options.type == 1) {
  186. wx.setNavigationBarTitle({
  187. title: '答疑讨论'
  188. })
  189. }
  190. this.setData({
  191. type: options.type
  192. })
  193. },
  194. /**
  195. * 生命周期函数--监听页面初次渲染完成
  196. */
  197. onReady: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面显示
  201. */
  202. onShow: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面隐藏
  206. */
  207. onHide: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面卸载
  211. */
  212. onUnload: function () {
  213. },
  214. /**
  215. * 页面相关事件处理函数--监听用户下拉动作
  216. */
  217. onPullDownRefresh: function () {
  218. },
  219. /**
  220. * 页面上拉触底事件的处理函数
  221. */
  222. onReachBottom: function () {
  223. },
  224. /**
  225. * 用户点击右上角分享
  226. */
  227. onShareAppMessage: function () {
  228. }
  229. })