index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Component({
  2. options: {
  3. multipleSlots: true,
  4. addGlobalClass: true
  5. },
  6. properties: {
  7. list: {
  8. type: Array
  9. },
  10. active: {
  11. type: Number,
  12. value: 0
  13. },
  14. onChenge: {
  15. type: Function
  16. },
  17. mode: {
  18. type: String,
  19. value: "default" //buts
  20. },
  21. safety: {
  22. type: Function,
  23. value: true
  24. }
  25. },
  26. lifetimes: {
  27. attached() {
  28. getApp().globalData.Language.getLanguagePackage(this)
  29. }
  30. },
  31. data: {
  32. startPoint: 0, //记录滑动的初始位置
  33. slipFlag: false, //定义 滑动事件 节流阀, 防止一次滑动触发多次滑动事件
  34. },
  35. methods: {
  36. tabsChenge(e) {
  37. const {
  38. index
  39. } = e.currentTarget.dataset;
  40. if (this.data.active == index) return;
  41. this.setData({
  42. active: index
  43. });
  44. this.setActive();
  45. },
  46. setActive() {
  47. this.triggerEvent("onChenge", this.data.active);
  48. },
  49. myTouchStart(e) {
  50. return;
  51. this.setData({
  52. slipFlag: true,
  53. startPoint: e.touches[0]
  54. })
  55. },
  56. myTouchMove(e) {
  57. return;
  58. let active = this.data.active;
  59. if (((this.data.startPoint.clientX - e.touches[e.touches.length - 1].clientX) > 80) && this.data.slipFlag) {
  60. if (active != this.data.list.length - 1) active++;
  61. this.setData({
  62. slipFlag: false,
  63. active
  64. })
  65. } else if (((this.data.startPoint.clientX - e.touches[e.touches.length - 1].clientX) < -80) && this.data.slipFlag) {
  66. if (active != 0) active--;
  67. this.setData({
  68. slipFlag: false,
  69. active
  70. })
  71. }
  72. this.setActive();
  73. },
  74. }
  75. })