columns.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { h, Fragment } from "vue";
  2. import { ElButton, ElImage, ElUpload } from "element-plus";
  3. import {
  4. type PlusColumn,
  5. type FieldValues,
  6. PlusForm
  7. } from "plus-pro-components";
  8. import { fileToDataURL } from '@plus-pro-components/utils'
  9. export const useColumns = () => {
  10. const { pkg, lastBuildTime } = __APP_INFO__;
  11. const { version, engines } = pkg;
  12. const columns: PlusColumn[] = [
  13. {
  14. label: "WEB标题",
  15. width: 120,
  16. prop: "webTitle",
  17. valueType: "input",
  18. },
  19. {
  20. label: "LOGO",
  21. width: 120,
  22. prop: "logoBase64",
  23. valueType: 'img',
  24. renderField(value, onChange) {
  25. // 自定义上传
  26. const handleHttpRequest = async ({ file, onError, onSuccess }: any) => {
  27. try {
  28. onSuccess(file)
  29. } catch (error: any) {
  30. onError(error)
  31. }
  32. return file
  33. }
  34. return h(Fragment, [
  35. h(ElImage as any, {
  36. src: value,
  37. previewSrcList: [value],
  38. style: value
  39. ? {
  40. width: '60px',
  41. marginRight: '10px'
  42. }
  43. : {}
  44. }),
  45. h(
  46. ElUpload,
  47. {
  48. action: '',
  49. httpRequest: handleHttpRequest,
  50. onChange: async (data: any) => {
  51. const value = await fileToDataURL(data.raw)
  52. // 手动调用 renderField 的onChange 回调把值传给表单
  53. console.log('upload onchange', data, value)
  54. onChange(value)
  55. }
  56. },
  57. () => h(ElButton, () => '点击上传')
  58. )
  59. ])
  60. }
  61. },
  62. {
  63. label: "运营商",
  64. width: 200,
  65. prop: "owner",
  66. valueType: "input",
  67. },
  68. {
  69. label: "显示版权",
  70. width: 200,
  71. prop: "enableCopyright",
  72. valueType: "input"
  73. },
  74. {
  75. label: "更新周期(ms)",
  76. width: 200,
  77. prop: "scheduleInterval",
  78. valueType: "input"
  79. },
  80. ]
  81. return {
  82. columns,
  83. };
  84. }