handleRow.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. export default {
  2. props: {
  3. /**
  4. * @description 管理列
  5. */
  6. rowHandle: {
  7. /* type: Object,
  8. default: null */
  9. }
  10. },
  11. computed: {
  12. rowHandleDisplayButtonnumber () {
  13. if (!this.rowHandle) return 2
  14. return this.rowHandle.buttonNumber || 2
  15. },
  16. rowHandleDisplay () {
  17. return this.rowHandle.effect === 'display'
  18. },
  19. rowHandleActions () {
  20. if (!this.rowHandle || !this.rowHandle.actions) return null
  21. if (this.rowHandleDisplay) {
  22. return this.rowHandle.actions.length >= this.rowHandleDisplayButtonnumber ? this.rowHandle.actions.slice(0, this.rowHandleDisplayButtonnumber) : this.rowHandle.actions
  23. } else {
  24. return this.rowHandle.actions
  25. }
  26. },
  27. rowHandleMoreActions () {
  28. return this.rowHandle && this.rowHandle.actions.length >= this.rowHandleDisplayButtonnumber ? this.rowHandle.actions.slice(this.rowHandleDisplayButtonnumber, this.rowHandle.actions.length) : null
  29. },
  30. rowHandleDefaultWidth () {
  31. if (this.rowHandleDisplay) {
  32. return this.rowHandleDisplayButtonnumber * 70 + 50
  33. } else {
  34. return this.$i18n.locale === 'en' ? 75 : 50
  35. }
  36. }
  37. },
  38. methods: {
  39. /**
  40. * 是否有按钮
  41. * @param {*} row 行的数据
  42. * @param {*} data
  43. */
  44. hasRowHandleActions (row, data) {
  45. if (!this.rowHandleActions) return false
  46. for (let i = 0; i < this.rowHandleActions.length; i++) {
  47. if (this.handleActionHidden(this.rowHandleActions[i].hidden, row, data)) {
  48. return true
  49. }
  50. }
  51. return false
  52. },
  53. /**
  54. * 处理按钮隐藏,显示
  55. */
  56. handleActionHidden (hidden = false, row, data) {
  57. let isHidden = !hidden
  58. if (typeof hidden === 'boolean') {
  59. isHidden = !hidden
  60. } else if (typeof hidden === 'function') {
  61. isHidden = !hidden.call(this, row, data)
  62. }
  63. return isHidden
  64. }
  65. }
  66. }