index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. form: {
  8. imgList: []
  9. },
  10. // 弹框
  11. dialog: { title: '弹框标题', show: false, type: '1' },
  12. // 日期时间选择
  13. dateform: {},
  14. // 选项卡
  15. tabs: {
  16. active: 'a',
  17. menu: [
  18. { title: '选项卡一', active: 'a' },
  19. { title: '选项卡二', active: 'b' },
  20. { title: '选项卡三', active: 'c' },
  21. { title: '选项卡四', active: 'd' },
  22. { title: '选项卡五', active: 'e' },
  23. ],
  24. },
  25. // 富文本
  26. content: ''
  27. },
  28. // 上传图片
  29. imgUpl: function (e) {
  30. const that = this;
  31. let data = that.data.form[e.detail.name];
  32. data.push(e.detail.data)
  33. that.setData({ [`form.${e.detail.name}`]: data })
  34. },
  35. // 删除图片
  36. imgDel: function (e) {
  37. const that = this;
  38. let data = that.data.form[e.detail.name];
  39. let arr = data.filter((i, index) => index != e.detail.data.index)
  40. that.setData({ [`form.${e.detail.name}`]: arr })
  41. },
  42. // 打开弹框
  43. toDialog: function () {
  44. const that = this;
  45. that.setData({ dialog: { title: '弹框标题', show: true, type: '1' } })
  46. },
  47. // 关闭弹框
  48. toClose: function () {
  49. const that = this;
  50. that.setData({ dialog: { title: '弹框标题', show: false, type: '1' } })
  51. },
  52. // 日期时间选择
  53. datetimeChange: function (e) {
  54. const that = this;
  55. that.setData({ [`dateform.${e.detail.name}`]: e.detail.datetime });
  56. },
  57. // 选择选项卡
  58. tabsChange: function (e) {
  59. const that = this;
  60. const { title, active } = e.detail;
  61. that.setData({ 'tabs.active': active });
  62. },
  63. // 监听富文本输入
  64. bindInput: function (e) {
  65. const that = this;
  66. const { html, text, name } = e.detail;
  67. that.setData({ [`${name}`]: html })
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad(options) {
  73. const that = this;
  74. that.search()
  75. },
  76. async search() {
  77. const res = await app.$api('news', 'GET', {});
  78. console.log(res);
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow() {
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide() {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload() {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh() {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom() {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage() {
  114. }
  115. })