dialog.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <data-template-dialog
  3. :visible.sync="selectorVisible"
  4. :data="dataTemplate"
  5. :dynamic-params="dynamicParams"
  6. :multiple="multiple"
  7. :value="selectorValue"
  8. :label-key="labelKey"
  9. :preview="false"
  10. type="dialog"
  11. @close="closeDialog"
  12. @action-event="handleSelectorActionEvent"
  13. />
  14. </template>
  15. <script>
  16. import { getByKey } from '@/api/platform/data/dataTemplate'
  17. import DataTemplateDialog from '@/business/platform/data/templaterender/preview'
  18. import { buildLabelTitle } from '@/business/platform/data/templaterender/utils'
  19. export default {
  20. components: {
  21. DataTemplateDialog
  22. },
  23. props: {
  24. visible: Boolean, // 是否可见
  25. value: [Object, Array],
  26. templateKey: { // 数据模版key
  27. type: String
  28. },
  29. dynamicParams: { // 动态参数
  30. type: Object
  31. },
  32. multiple: {
  33. type: Boolean,
  34. default: true
  35. },
  36. previousDataTemplate: {
  37. type: Object
  38. }
  39. },
  40. data () {
  41. return {
  42. dataTemplate: {},
  43. labelKey: '',
  44. valueKey: '',
  45. selectorVisible: false,
  46. selectorValue: this.multiple ? [] : {},
  47. cacheData: {},
  48. bindIdValue: ''
  49. }
  50. },
  51. watch: {
  52. visible: {
  53. handler: function (val, oldVal) {
  54. if (val) {
  55. this.loadTemplateData()
  56. } else {
  57. this.selectorVisible = val
  58. }
  59. },
  60. immediate: true
  61. },
  62. value: {
  63. handler (val, oldVal) {
  64. this.initData()
  65. },
  66. immediate: true
  67. }
  68. },
  69. methods: {
  70. loadTemplateData () {
  71. if (this.$utils.isEmpty(this.templateKey)) {
  72. return
  73. }
  74. getByKey({
  75. dataTemplateKey: this.templateKey
  76. }).then(response => {
  77. this.dataTemplate = this.$utils.parseData(response.data)
  78. this.initDataTemplate()
  79. this.selectorVisible = true
  80. }).catch(() => {
  81. })
  82. },
  83. initDataTemplate () {
  84. this.valueKey = this.dataTemplate.unique
  85. this.labelKey = buildLabelTitle(this.dataTemplate)
  86. },
  87. handleLabel (data) {
  88. const config = this.labelKey
  89. if (typeof config === 'function') {
  90. return config(data)
  91. } else if (typeof config === 'string') {
  92. return data[config]
  93. } else if (typeof config === 'undefined') {
  94. const dataProp = data['name']
  95. return dataProp === undefined ? '' : dataProp
  96. }
  97. },
  98. /**
  99. * 初始化数据
  100. */
  101. initData (init = true) {
  102. this.selectorValue = this.multiple ? [] : {}
  103. },
  104. // ===================事件处理=========
  105. closeDialog () {
  106. this.$emit('close', false)
  107. },
  108. handleSelectorActionEvent (buttonKey, data) {
  109. switch (buttonKey) {
  110. case 'ok':// 确定
  111. this.closeDialog()
  112. this.$emit('action-event', buttonKey, data)
  113. break
  114. case 'cleanClose': // 清空关闭
  115. this.closeDialog()
  116. this.selectorValue = this.multiple ? [] : {}
  117. this.$emit('action-event', buttonKey, this.selectorValue)
  118. break
  119. case 'cancel':// 取消
  120. this.closeDialog()
  121. this.selectorValue = this.multiple ? [] : {}
  122. break
  123. // TODO:自定义按钮事件处理
  124. }
  125. }
  126. }
  127. }
  128. </script>