art.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // pages/art/art.js
  2. const app = getApp()
  3. const util = require('../../utils/util.js');
  4. const APIClient = require('../../utils/APIClient.js');
  5. const login = require('../../utils/loginSchedule.js');
  6. /**
  7. * productionData 分项data
  8. * questionsData 疑问data
  9. * courseData 科目信息
  10. * num1 分享得值
  11. * num2 科目得值
  12. * position 定位id值
  13. * questionsdian 点的显示
  14. * list 更改后时间的值
  15. * lessonListHeight 定义高度
  16. * previewHeight 定义高度
  17. * productionMore和questionsMore展开是否显示
  18. * strategy 更改<br>
  19. * 其他的页面组件就看这个就行了 基本上都是都是一样的
  20. */
  21. Page({
  22. data: {
  23. productionData: {},
  24. questionsData: {},
  25. courseData: {},
  26. num1: 0,
  27. num2: 0,
  28. position: '',
  29. questionsdian: '',
  30. list: [],
  31. lessonListHeight: '',
  32. previewHeight: '',
  33. productionMore: '',
  34. questionsMore: '',
  35. wxObjectives: [],
  36. shareImgSrc: ''
  37. },
  38. /* 区分答疑和分享 */
  39. distinction: function(type, columnId, pageNo, pageSize, success) {
  40. login.getOpenidSessionKey(function(res) {
  41. //console.log(res.data.data.uid);
  42. APIClient.getProductionSchedule({
  43. uid: res.data.data.uid
  44. }, {
  45. "type": type,
  46. "category": columnId,
  47. "pageNo": pageNo,
  48. "pageSize": pageSize
  49. }).success(success)
  50. }, function() {
  51. wx.showModal({
  52. title: '提示',
  53. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  54. showCancel: false,
  55. success: function (res) {
  56. if (res.confirm) {
  57. console.log('用户点击确定')
  58. } else if (res.cancel) {
  59. console.log('用户点击取消')
  60. }
  61. }
  62. })
  63. });
  64. },
  65. /*点击加载更多*/
  66. onMyEvent: function(e){
  67. let type = e.currentTarget.dataset.type;
  68. const columnId = util.column('6').columnId;
  69. if(type == 1) {
  70. this.data.num1++
  71. this.setData({
  72. num1: this.data.num1
  73. })
  74. this.distinction(type, columnId, 1, 5*this.data.num1, res => {
  75. if(res.data.success) {
  76. console.log(res.data.data)
  77. this.setData({
  78. questionsData: res.data.data,
  79. })
  80. if(res.data.data) {
  81. this.setData({
  82. questionsdian: util.replyNo(res.data.data.list)
  83. })
  84. if(5*this.data.num1 > res.data.data.totalSize) {
  85. this.setData({
  86. questionsMore: ''
  87. })
  88. }
  89. }
  90. }
  91. });
  92. }
  93. if(type == 2) {
  94. this.data.num2++
  95. this.setData({
  96. num: this.data.num2
  97. })
  98. this.distinction(type, columnId, 1, 5*this.data.num2, res => {
  99. if(res.data.success) {
  100. console.log(res.data.data)
  101. this.setData({
  102. productionData: res.data.data,
  103. })
  104. if(5*this.data.num2 > res.data.data.totalSize) {
  105. this.setData({
  106. productionMore: ''
  107. })
  108. }
  109. }
  110. });
  111. }
  112. },
  113. /*点击定位*/
  114. location: function (e) {
  115. const position = e.currentTarget.dataset.id;
  116. console.log(position)
  117. this.setData({
  118. position: position
  119. })
  120. },
  121. onLoad: function (options) {
  122. const columnId = util.column('6').columnId;
  123. /* 分享 */
  124. this.distinction(2, columnId, 1, 2, res => {
  125. if(res.data.success) {
  126. console.log(res.data.data)
  127. this.setData({
  128. productionData: res.data.data
  129. })
  130. if(res.data.data) {
  131. if(res.data.data.totalSize > 2) {
  132. this.setData({
  133. productionMore: true
  134. })
  135. }
  136. }
  137. }
  138. });
  139. /* 答疑 */
  140. this.distinction(1, columnId, 1, 2, res => {
  141. if(res.data.success) {
  142. console.log(res.data.data)
  143. this.setData({
  144. questionsData: res.data.data
  145. })
  146. if(res.data.data) {
  147. this.setData({
  148. questionsdian: util.replyNo(res.data.data.list)
  149. })
  150. if(res.data.data.totalSize > 2) {
  151. this.setData({
  152. questionsMore: true
  153. })
  154. }
  155. }
  156. }
  157. });
  158. /*科目信息*/
  159. login.getOpenidSessionKey((res) => {
  160. APIClient.getEachSchedule({
  161. uid: res.data.data.uid
  162. }, {
  163. "category": 6
  164. }).success((res) => {
  165. const lessonListLength = res.data.data.lessonPage.list.length;
  166. const previewLength = util.preview(res.data.data.lessonPage.list).length;
  167. console.log(res)
  168. if(lessonListLength > 4) {
  169. this.setData({
  170. lessonListHeight: 280
  171. })
  172. }
  173. if(previewLength > 4){
  174. this.setData({
  175. previewHeight: 280
  176. })
  177. }
  178. this.setData({
  179. courseData: res.data.data,
  180. list: util.studyPageTime(res.data.data.lessonPage.list),
  181. wxObjectives: util.strategy(res.data.data.weekCourseConfig.wxObjectives)
  182. })
  183. })
  184. }, function() {
  185. wx.showModal({
  186. title: '提示',
  187. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除小学王者班后再次扫码进入,允许授权后可正常使用',
  188. showCancel: false,
  189. success: function (res) {
  190. if (res.confirm) {
  191. console.log('用户点击确定')
  192. } else if (res.cancel) {
  193. console.log('用户点击取消')
  194. }
  195. }
  196. })
  197. });
  198. },
  199. onShow: function () {
  200. //2. canvas绘制文字和图片
  201. const ctx = wx.createCanvasContext('myCanvas');
  202. var imgPath = '../image/bg_1.png'
  203. ctx.setFillStyle('red')
  204. ctx.fillRect(10, 10, 150, 75)
  205. ctx.drawImage(imgPath, 30, 10, 60, 60);
  206. ctx.setFontSize(12)
  207. ctx.setFillStyle('#6F6F6F')
  208. ctx.fillText('妖妖灵', 10, 10)
  209. ctx.draw();
  210. },
  211. keep: function () {
  212. wx.canvasToTempFilePath({
  213. x: 0,
  214. y: 0,
  215. width: 600,
  216. height: 800,
  217. destWidth: 600,
  218. destHeight:800,
  219. canvasId: 'myCanvas',
  220. success: (res) => {
  221. console.log('canvas'+res.tempFilePath);
  222. this.setData({
  223. shareImgSrc : res.tempFilePath
  224. })
  225. },
  226. fail:function (res) {
  227. console.log(res)
  228. }
  229. })
  230. wx.saveImageToPhotosAlbum({
  231. filePath:this.data.shareImgSrc,
  232. success(res) {
  233. wx.showModal({
  234. title: '存图成功',
  235. content: '图片成功保存到相册了,去发朋友圈',
  236. showCancel:false,
  237. confirmText:'好哒',
  238. confirmColor:'#72B9C3',
  239. success: function(res) {
  240. if (res.confirm) {
  241. console.log('用户点击确定');
  242. }
  243. //that.hideShareImg()
  244. }
  245. })
  246. }
  247. })
  248. },
  249. /* 转发*/
  250. onShareAppMessage: function (ops) {
  251. if (ops.from === 'button') {
  252. // 来自页面内转发按钮
  253. console.log(ops.target)
  254. }
  255. const postId = ops.target.dataset.postid;
  256. return {
  257. title: '小学王者班',
  258. path: `pages/transmit/transmit?ind=7&postId=${postId}`,
  259. success: function (res) {
  260. // 转发成功
  261. console.log("转发成功:" + JSON.stringify(res));
  262. },
  263. fail: function (res) {
  264. // 转发失败
  265. console.log("转发失败:" + JSON.stringify(res));
  266. }
  267. }
  268. },
  269. })