generateColItem.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {executeExpression, isExpression, extractExpression} from '../util/expression'
  2. export const generateColItemMixin = {
  3. props: ['config', 'element', 'model', 'rules', 'remote', 'blanks', 'display', 'edit', 'remoteOption', 'platform', 'preview', 'containerKey', 'dataSourceValue', 'eventFunction', 'printRead', 'isSubform', 'rowIndex', 'subName', 'subHideFields', 'subDisabledFields', 'isDialog', 'dialogName', 'group', 'fieldNode', 'isGroup'],
  4. data () {
  5. return {
  6. dataModels: this.model,
  7. hideCols: []
  8. }
  9. },
  10. computed: {
  11. currentOptions () {
  12. if (this.isSubform) {
  13. return {
  14. fieldNode: this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model,
  15. rowIndex: this.rowIndex,
  16. row: this.model
  17. }
  18. } else {
  19. return {
  20. fieldNode: this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model,
  21. }
  22. }
  23. },
  24. elementDisplay () {
  25. let curFullField = this.fieldNode ? this.fieldNode + '.' + this.element.model : this.element.model
  26. let curField = this.group ? this.group + '.' + this.element.model : this.element.model
  27. if (this.dynamicHideFields[curFullField] != undefined) {
  28. return !this.dynamicHideFields[curFullField]
  29. }
  30. if (this.dynamicHideFields[curField] != undefined) {
  31. return !this.dynamicHideFields[curField]
  32. }
  33. if (typeof this.element.options.hidden === 'boolean') {
  34. return !this.element.options.hidden
  35. } else {
  36. if (isExpression(this.element.options.hidden)) {
  37. return !executeExpression(extractExpression(this.element.options.hidden), this.currentOptions, this.formContext)
  38. }
  39. }
  40. return true
  41. }
  42. },
  43. inject: ['generateComponentInstance', 'deleteComponentInstance', 'dynamicHideFields', 'formContext'],
  44. mounted () {
  45. this.generateComponentInstance && this.generateComponentInstance(this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model, this)
  46. },
  47. beforeUnmount () {
  48. this.deleteComponentInstance && this.deleteComponentInstance(this.fieldNode ? `${this.fieldNode}.${this.element.model}` : this.element.model)
  49. },
  50. methods: {
  51. getColXS (options) {
  52. if (this.preview) {
  53. if (this.platform == 'pc') {
  54. return options.md
  55. }
  56. if (this.platform == 'pad') {
  57. return options.sm
  58. }
  59. if (this.platform == 'mobile') {
  60. return options.xs
  61. }
  62. } else {
  63. return options.xs
  64. }
  65. },
  66. getColSM (options) {
  67. if (this.preview) {
  68. if (this.platform == 'pc') {
  69. return options.md
  70. }
  71. if (this.platform == 'pad') {
  72. return options.sm
  73. }
  74. if (this.platform == 'mobile') {
  75. return options.xs
  76. }
  77. } else {
  78. return options.sm
  79. }
  80. },
  81. getColMD (options) {
  82. if (this.preview) {
  83. if (this.platform == 'pc') {
  84. return options.md
  85. }
  86. if (this.platform == 'pad') {
  87. return options.sm
  88. }
  89. if (this.platform == 'mobile') {
  90. return options.xs
  91. }
  92. } else {
  93. return options.md
  94. }
  95. },
  96. hideCol (index) {
  97. !this.hideCols.includes(index) && this.hideCols.push(index)
  98. },
  99. displayCol (index) {
  100. if (this.hideCols.includes(index)) {
  101. this.hideCols.splice(this.hideCols.indexOf(index), 1)
  102. }
  103. }
  104. },
  105. watch: {
  106. model: {
  107. deep: true,
  108. handler (val) {
  109. this.dataModels = val
  110. }
  111. }
  112. }
  113. }