You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.1 KiB

5 months ago
  1. <template>
  2. <view class="u-swipe-action">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. import { props } from './props';
  8. import { mpMixin } from '../../libs/mixin/mpMixin';
  9. import { mixin } from '../../libs/mixin/mixin';
  10. /**
  11. * SwipeAction 滑动单元格
  12. * @description 该组件一般用于左滑唤出操作菜单的场景用的最多的是左滑删除操作
  13. * @tutorial https://ijry.github.io/uview-plus/components/swipeAction.html
  14. * @property {Boolean} autoClose 是否自动关闭其他swipe按钮组
  15. * @event {Function(index)} click 点击组件时触发
  16. * @example <u-swipe-action><u-swipe-action-item :rightOptions="options1" ></u-swipe-action-item></u-swipe-action>
  17. */
  18. export default {
  19. name: 'u-swipe-action',
  20. mixins: [mpMixin, mixin, props],
  21. data() {
  22. return {}
  23. },
  24. provide() {
  25. return {
  26. swipeAction: this
  27. }
  28. },
  29. computed: {
  30. // 这里computed的变量,都是子组件u-swipe-action-item需要用到的,由于头条小程序的兼容性差异,子组件无法实时监听父组件参数的变化
  31. // 所以需要手动通知子组件,这里返回一个parentData变量,供watch监听,在其中去通知每一个子组件重新从父组件(u-swipe-action-item)
  32. // 拉取父组件新的变化后的参数
  33. parentData() {
  34. return [this.autoClose]
  35. }
  36. },
  37. watch: {
  38. // 当父组件需要子组件需要共享的参数发生了变化,手动通知子组件
  39. parentData() {
  40. if (this.children.length) {
  41. this.children.map(child => {
  42. // 判断子组件(u-swipe-action-item)如果有updateParentData方法的话,就就执行(执行的结果是子组件重新从父组件拉取了最新的值)
  43. typeof(child.updateParentData) === 'function' && child.updateParentData()
  44. })
  45. }
  46. },
  47. },
  48. created() {
  49. this.children = []
  50. },
  51. methods: {
  52. closeOther(child) {
  53. if (this.autoClose) {
  54. // 历遍所有的单元格,找出非当前操作中的单元格,进行关闭
  55. this.children.map((item, index) => {
  56. if (child !== item) {
  57. item.closeHandler()
  58. }
  59. })
  60. }
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. </style>