columns.tsx 1.9 KB

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