datasetMixin.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // import _ from 'lodash'
  2. import cloneDeep from 'lodash/cloneDeep'
  3. const datasetMixins = {
  4. props: {
  5. isEdit: {
  6. type: Boolean,
  7. default: false
  8. },
  9. datasetId: {
  10. type: String,
  11. default: null
  12. },
  13. datasetName: {
  14. type: String,
  15. default: ''
  16. },
  17. typeId: {
  18. type: String,
  19. default: ''
  20. },
  21. appCode: {
  22. type: String,
  23. default: ''
  24. }
  25. },
  26. data () {
  27. return {
  28. dataForm: {},
  29. dataPreviewList: [],
  30. structurePreviewList: [],
  31. structurePreviewListCopy: [],
  32. typeName: '',
  33. categoryData: [],
  34. current: 1,
  35. size: 10,
  36. totalCount: 0,
  37. fieldDescVisible: false,
  38. fieldsetVisible: false,
  39. tableLoading: false,
  40. saveLoading: false,
  41. saveText: '',
  42. typeSelect: [
  43. { value: 'String' },
  44. { value: 'Integer' },
  45. { value: 'Double' },
  46. { value: 'Long' },
  47. { value: 'Date' }
  48. ]
  49. }
  50. },
  51. methods: {
  52. /**
  53. * 使用字段名填充字段描述
  54. */
  55. fieldDescFill () {
  56. this.structurePreviewList.forEach(field => {
  57. if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
  58. field.fieldDesc = field.fieldName
  59. }
  60. })
  61. this.save('form')
  62. this.fieldDescVisible = false
  63. },
  64. /**
  65. * 打开字段描述编辑弹窗
  66. */
  67. fieldDescEdit () {
  68. this.fieldDescVisible = false
  69. this.fieldsetVisible = true
  70. },
  71. /**
  72. * 跳过字段描述编辑直接保存
  73. */
  74. toSave () {
  75. this.save('form', true)
  76. this.fieldDescVisible = false
  77. },
  78. /**
  79. * 取消编辑字段
  80. */
  81. cancelField () {
  82. this.structurePreviewListCopy = cloneDeep(this.structurePreviewList)
  83. this.fieldsetVisible = false
  84. },
  85. /**
  86. * 保存字段设置
  87. */
  88. setField () {
  89. this.structurePreviewList = cloneDeep(this.structurePreviewListCopy)
  90. this.fieldsetVisible = false
  91. },
  92. /**
  93. * 清空分类选择
  94. */
  95. clearType () {
  96. this.typeName = ''
  97. this.dataForm.typeId = ''
  98. },
  99. /**
  100. * 分类展开高亮
  101. * @param $event
  102. */
  103. setCurrentNode ($event) {
  104. if ($event) {
  105. const key = this.dataForm.typeId || null
  106. this.$refs.categorySelectTree.setCurrentKey(key)
  107. }
  108. },
  109. /**
  110. * 分类选择
  111. * @param value
  112. */
  113. selectParentCategory (value) {
  114. this.dataForm.typeId = value.id
  115. this.typeName = value.name
  116. this.$refs.selectParentName.blur()
  117. },
  118. goBack () {
  119. this.$emit('back')
  120. },
  121. // 每页大小改变触发
  122. sizeChangeHandle (value) {
  123. this.size = value
  124. this.current = 1
  125. this.datasetTest(false)
  126. },
  127. // 当前页数改变
  128. currentChangeHandle (value) {
  129. this.current = value
  130. this.datasetTest(false)
  131. },
  132. // 表头添加提示
  133. renderHeader (h, { column, index }) {
  134. const labelLong = column.label.length // 表头label长度
  135. const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义
  136. column.minWidth = labelLong * size < 120 ? 120 : labelLong * size // 根据label长度计算该表头最终宽度
  137. return h('span', { class: 'cell-content', style: { width: '100%' } }, [column.label])
  138. },
  139. openNewWindow (url) {
  140. window.open(url, '_blank')
  141. }
  142. }
  143. }
  144. export { datasetMixins }