table-data.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import request from './request'
  2. import loadPinYinInit from '../../lib/ChineseHelper'
  3. import {
  4. formMethod
  5. } from './form-common'
  6. let Table = {
  7. ObtainTableTitle: function(data) {
  8. var tableName = data._props.widget.options.databaseName
  9. // console.log(data)
  10. // console.log(data._props.widget.options)
  11. var param = {
  12. tableName: tableName
  13. }
  14. //初始化表格数据
  15. formMethod().other('', 'admin-table/initializeHeader', param).then(res => {
  16. console.log(res)
  17. data.setTableColumn(res.data)
  18. })
  19. },
  20. // 通过配置获取表格数据
  21. ObtainTable: function(data) {
  22. //初始化表格数据
  23. var tableData = data._props.widget.options
  24. let params = {
  25. "limit": data.getWidgetRef(tableData.name).pageSize,
  26. "page": data.getWidgetRef(tableData.name).currentPage,
  27. }
  28. var str = data.getFormRef().getFormData(false)
  29. // 参数
  30. let paramList = []
  31. // 名称
  32. for (let i in str) {
  33. if (str[i] != '') {
  34. var code = ''
  35. var index = i.lastIndexOf("_")
  36. var field = index != -1 ? field = i.substring(index + 1, i.length) : field = i
  37. paramList.push({
  38. field,
  39. value: str[i],
  40. condition: data.getFormRef().getWidgetRef(i, false).field.options
  41. .screenOperator
  42. })
  43. }
  44. }
  45. params['paramList'] = paramList
  46. // let mingchen=this.getFormRef().getFieldValue('search_mingchen')
  47. // if(mingchen){
  48. // paramList.push({
  49. // field:'name',
  50. // value:mingchen,
  51. // condition:'like'
  52. // })
  53. // params['paramList'] =paramList
  54. // }
  55. formMethod().selectPage('', tableData.databaseName, params, tableData.databaseName + ':page')
  56. .then(res => {
  57. data.setTableData(res.data.records)
  58. data.setPagination({
  59. currentPage: parseInt(res.data.current),
  60. pageSize: parseInt(res.data.size),
  61. total: parseInt(res.data.total)
  62. })
  63. // return response
  64. })
  65. },
  66. ObtainTableButton: function(buttonName, rowIndex, row, that) {
  67. var options = that._props.widget.options
  68. console.log('=======》', buttonName, rowIndex, row, that)
  69. if (buttonName.indexOf('delete') != -1) {
  70. that.$confirm("是否删除,继续?", "提示", {
  71. confirmButtonText: "确定",
  72. cance1ButtonText: "取消",
  73. type: "warning"
  74. }).then(() => {
  75. formMethod().delete('', options.databaseName, row.id, options.databaseName + ':page')
  76. .then((res) => {
  77. if (res.code == 20000) {
  78. that.$message.success("删除成功") //----重新加载表数据
  79. that.handleOnCreated()
  80. }
  81. })
  82. // this,$message.success("删除成功")
  83. })
  84. } else if (buttonName.indexOf('edit') != -1) {
  85. // let form = that.getFormRef().getFormData(false)
  86. // let tableName = options.databaseName; //定义的表名
  87. // var paramList = []
  88. // for (let i in form) {
  89. // paramList.push({
  90. // condition: that.getFormRef().getWidgetRef(i, false)._props.field.options
  91. // .screenOperator,
  92. // field: i,
  93. // value: form[i]
  94. // })
  95. // }
  96. // var params = {
  97. // paramList
  98. // }
  99. // formMethod().select('', tableName, params, 'query:form')
  100. // .then(res => {
  101. // for (let i in form) {
  102. // that.getFormRef().setFieldValue(i, res.data[0][i])
  103. // }
  104. // })
  105. that.getFormRef().showDialog('edit', row, {
  106. operation: 'edit'
  107. })
  108. } else if (buttonName.indexOf('detail') != -1) {
  109. that.getFormRef().showDialog('detail', row)
  110. }
  111. },
  112. // 表单初始值
  113. OnDialogOpened: function(that) {
  114. // console.log(that)
  115. // that.getFormRef().getFormData()
  116. }
  117. }
  118. /**
  119. * 工具
  120. * @returns {{ConvertPinyin: (function(*=): string)}}
  121. */
  122. export function commonTable() {
  123. return Table
  124. }