datasetMixin.js 3.3 KB

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