index.js 3.5 KB

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