btn.mjs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const queryFormBtnList = [
  2. {
  3. name: 'search',
  4. label: '搜索',
  5. type: 'primary',
  6. click: `() => {
  7. queryApi()
  8. }`,
  9. },
  10. {
  11. name: 'clear',
  12. label: '清空',
  13. type: 'warning',
  14. click: `() => {
  15. queryForm_Data.value = {}
  16. }`,
  17. },
  18. ]
  19. const tableRowBtnList = [
  20. {
  21. name: 'import',
  22. $import: true,
  23. label: '导入',
  24. type: 'primary',
  25. click: `async ({ file }: { file: File }) => {
  26. const res = await API_MAP['import']({ file })
  27. if(res.code === '1'){
  28. queryApi()
  29. ElMessage.success(res.msg)
  30. }
  31. }`,
  32. },
  33. {
  34. name: 'export',
  35. label: '导出',
  36. type: 'success',
  37. click: `() => {
  38. exportApi()
  39. }`,
  40. },
  41. {
  42. name: 'add',
  43. label: '新增',
  44. type: 'primary',
  45. click: `() => {
  46. whichDialogSubmit = 'add'
  47. dialogForm_Data.value = {}
  48. dialogVisible_addOrEdit.value = true
  49. }`,
  50. },
  51. {
  52. name: 'delete',
  53. label: '删除',
  54. type: 'danger',
  55. click: `async () => {
  56. await deleteApi(multipleSelection.value.map((item: TYPE_TABLE_FIELD)=>item[TABLE_KEY]))
  57. queryApi()
  58. }`,
  59. },
  60. ]
  61. const tableColBtnList = [
  62. {
  63. name: 'edit',
  64. label: '编辑',
  65. type: 'primary',
  66. click: `async (scope:{row:TYPE_TABLE_FIELD}) => {
  67. whichDialogSubmit = 'edit'
  68. const res = await detailApi(scope.row[TABLE_KEY])
  69. dialogForm_Data.value = (res.data.one_info)
  70. dialogVisible_addOrEdit.value = true
  71. }`,
  72. },
  73. {
  74. name: 'audit',
  75. label: '审核',
  76. type: 'primary',
  77. click: `(scope:{row:TYPE_TABLE_FIELD}) => {
  78. whichDialogSubmit = 'edit'
  79. dialogForm_Data.value = pick(scope.row, [\`\${TABLE_KEY}\`, ...Object.keys(dialogForm_Rules_audit)])
  80. dialogVisible_audit.value = true
  81. }`,
  82. },
  83. {
  84. name: 'detail',
  85. label: '详情',
  86. type: 'primary',
  87. click: `(scope:{row:TYPE_TABLE_FIELD}) => {
  88. router.push({ name:DetailName, params:{ [DetailParam]:scope.row[TABLE_KEY]} })
  89. }`,
  90. },
  91. {
  92. name: 'delete',
  93. label: '删除',
  94. type: 'primary',
  95. click: `async (scope:{row:TYPE_TABLE_FIELD}) => {
  96. await deleteApi(scope.row[TABLE_KEY])
  97. queryApi()
  98. }`,
  99. },
  100. ]
  101. const dialogFormBtnList = [
  102. {
  103. name: 'submit',
  104. label: '提交',
  105. type: 'primary',
  106. click: `async (formRefKey:string,extendData?:Partial<TYPE_TABLE_FIELD>) => {
  107. const isValid = await (instance?.refs[formRefKey] as FormInstance).validate((valid:boolean) => valid)
  108. if (isValid) {
  109. await API_MAP[whichDialogSubmit](<TYPE_TABLE_FIELD>({...dialogForm_Data.value,...extendData}))
  110. handleDialogFormBtn_cancel()
  111. queryApi()
  112. }
  113. }`,
  114. },
  115. {
  116. name: 'cancel',
  117. label: '取消',
  118. type: 'default',
  119. click: `(formRefKey?:string) => {
  120. dialogVisible_addOrEdit.value = false
  121. dialogVisible_audit.value = false
  122. }`,
  123. },
  124. ]
  125. export default {
  126. queryFormBtnList,
  127. tableColBtnList,
  128. tableRowBtnList,
  129. dialogFormBtnList,
  130. }