综合办公系统
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.

uv-swipe-action.vue 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="uv-swipe-action">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. import mpMixin from '@/uni_modules/uv-ui-tools/libs/mixin/mpMixin.js'
  8. import mixin from '@/uni_modules/uv-ui-tools/libs/mixin/mixin.js'
  9. import props from './props.js';
  10. /**
  11. * SwipeAction 滑动单元格
  12. * @description 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作
  13. * @tutorial https://www.uvui.cn/components/swipeAction.html
  14. * @property {Boolean} autoClose 是否自动关闭其他swipe按钮组
  15. * @event {Function(index)} click 点击组件时触发
  16. * @example <uv-swipe-action><uv-swipe-action-item :rightOptions="options1" ></uv-swipe-action-item></uv-swipe-action>
  17. */
  18. export default {
  19. name: 'uv-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的变量,都是子组件uv-swipe-action-item需要用到的,由于头条小程序的兼容性差异,子组件无法实时监听父组件参数的变化
  31. // 所以需要手动通知子组件,这里返回一个parentData变量,供watch监听,在其中去通知每一个子组件重新从父组件(uv-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. // 判断子组件(uv-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>