useTable.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { ref } from 'vue'
  2. import { ElMessage } from 'element-plus'
  3. import { GeneralDataReception, Query } from '@/api/webApi'
  4. import { IdType } from '../type'
  5. const tableHeader = ref<any>([])
  6. const tableData = ref<any>([])
  7. const msgId = ref<any>('')
  8. const getTable = async (id: IdType, dataContent) => {
  9. try {
  10. const { code, returnData, message } = await Query({
  11. id: id,
  12. needPage: 1,
  13. dataContent: [...dataContent],
  14. })
  15. if (code == 0 && returnData) {
  16. const { columnSet, listValues, submitID } = returnData
  17. console.log(submitID)
  18. tableHeader.value = columnSet
  19. tableData.value = listValues
  20. msgId.value = submitID
  21. return {
  22. tableHeader,
  23. tableData,
  24. msgId,
  25. }
  26. } else {
  27. ElMessage.error(message)
  28. return {
  29. tableHeader,
  30. tableData,
  31. msgId,
  32. }
  33. }
  34. } catch (err: any) {
  35. return {
  36. tableHeader,
  37. tableData,
  38. msgId,
  39. }
  40. }
  41. }
  42. const dataChange = async (id: IdType, event: IdType, data) => {
  43. const obj = Object.assign(data, { event })
  44. const { code, message } = await GeneralDataReception({
  45. serviceId: id,
  46. dataContent: JSON.stringify(obj),
  47. })
  48. return {
  49. code,
  50. message,
  51. }
  52. }
  53. export default { getTable, dataChange }