index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // pages/test/index.js
  2. const app = getApp()
  3. import WxValidate from '../../utils/wxValidate'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '测试页面', leftArrow: true, useBar: true },
  10. // 主体高度
  11. infoHeight: '',
  12. // 图片
  13. img_url: [],
  14. // dialog弹框
  15. dialog: { title: '弹框标题', show: false, type: '1' },
  16. form: {}
  17. },
  18. initValidate() {
  19. const rules = { start_time: { required: true } }
  20. // 验证字段的提示信息,若不传则调用默认的信息
  21. const messages = { start_time: { required: '开始时间' } };
  22. this.WxValidate = new WxValidate(rules, messages)
  23. },
  24. // 跳转菜单
  25. tabPath(e) {
  26. let { route } = e.detail.detail;
  27. if (route) wx.redirectTo({ url: `/${route}` })
  28. },
  29. // 返回上一页
  30. back: function () {
  31. wx.navigateBack({ delta: 1 })
  32. },
  33. // 上传图片
  34. imgUpl: function (e) {
  35. const that = this;
  36. let data = that.data.img_url;
  37. data.push(e.detail)
  38. that.setData({ img_url: data })
  39. },
  40. // 删除图片
  41. imgDel: function (e) {
  42. const that = this;
  43. let list = that.data.img_url;
  44. let arr = list.filter((i, index) => index != e.detail.index)
  45. that.setData({ img_url: arr })
  46. },
  47. // 打开弹框
  48. toDialog: function () {
  49. const that = this;
  50. that.setData({ dialog: { title: '弹框标题', show: true, type: '1' } })
  51. },
  52. // 关闭弹框
  53. toClose: function () {
  54. const that = this;
  55. that.setData({ dialog: { title: '弹框标题', show: false, type: '1' } })
  56. },
  57. // 确认选择
  58. datetimeChange: function (e) {
  59. const that = this;
  60. that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
  61. },
  62. // 提交保存
  63. toSubmit: function (e) {
  64. const that = this;
  65. const params = e.detail.value;
  66. console.log(params);
  67. if (!this.WxValidate.checkForm(params)) {
  68. const error = this.WxValidate.errorList[0];
  69. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  70. return false
  71. } else {
  72. console.log(params);
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面加载
  77. */
  78. onLoad: async function (options) {
  79. const that = this;
  80. //验证规则函数
  81. that.initValidate();
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload: function () {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh: function () {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom: function () {
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage: function () {
  117. }
  118. })