msg.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. current: '1',
  7. dataUrl: [
  8. 'https://easy-mock.com/mock/5c9c6cad45252c38c9a09ca1/example/smallApp',
  9. 'https://easy-mock.com/mock/5c9c6cad45252c38c9a09ca1/example/smallApp'
  10. ],
  11. dataList: [],
  12. isHaveData: false,
  13. isHaveMore: true
  14. },
  15. changeTab: function({ detail }) {
  16. // tab切换
  17. this.setData({
  18. current: detail.key,
  19. dataList: []
  20. })
  21. // this.getDataList()
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. // this.getDataList()
  28. },
  29. getDataList: function() {
  30. var that = this
  31. wx.showLoading({
  32. title: '加载中',
  33. mask: true
  34. })
  35. wx.request({
  36. url: that.data.dataUrl[that.data.current - 1],
  37. method: 'get',
  38. dataType: 'json',
  39. success: function(res) {
  40. if (res.data.code == 0) {
  41. let list = res.data.data
  42. wx.hideLoading()
  43. list.map(item => {
  44. if (item.desc.length > 60) {
  45. item.isCut = true
  46. item.showText = '查看更多'
  47. item.cutDesc = item.desc.slice(0, 60) + '...'
  48. } else {
  49. item.cutDesc = item.desc
  50. }
  51. })
  52. that.setData({
  53. dataList: that.data.dataList.concat(list)
  54. })
  55. }
  56. }
  57. })
  58. },
  59. showAllDesc: function(e) {
  60. let newList = this.data.dataList
  61. newList.map(item => {
  62. if (item.showText == '查看更多') {
  63. item.cutDesc = item.desc
  64. item.showText = '收回'
  65. } else if (item.showText == '收回') {
  66. item.cutDesc = item.desc.slice(0, 60) + '...'
  67. item.showText = '查看更多'
  68. }
  69. })
  70. this.setData({
  71. dataList: newList
  72. })
  73. }
  74. })