labelRelationship.data.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { BasicColumn, FormSchema } from '@/components/Table';
  2. import { useI18n } from '@/hooks/web/useI18n';
  3. import { formatToDateTime } from '@/utils/dateUtil';
  4. import { updateLabelRelationship } from '@/api/wechat/labelRelationship';
  5. import { Switch } from 'ant-design-vue';
  6. import { h } from 'vue';
  7. const { t } = useI18n();
  8. export const columns: BasicColumn[] = [
  9. {
  10. title: t('wechat.labelRelationship.labelId'),
  11. dataIndex: 'labelId',
  12. width: 100,
  13. },
  14. {
  15. title: t('wechat.labelRelationship.contactId'),
  16. dataIndex: 'contactId',
  17. width: 100,
  18. },
  19. {
  20. title: t('wechat.labelRelationship.contact'),
  21. dataIndex: 'contact',
  22. width: 100,
  23. },
  24. {
  25. title: t('wechat.labelRelationship.label'),
  26. dataIndex: 'label',
  27. width: 100,
  28. },
  29. {
  30. title: t('common.status'),
  31. dataIndex: 'status',
  32. width: 50,
  33. customRender: ({ record }) => {
  34. if (!Reflect.has(record, 'pendingStatus')) {
  35. record.pendingStatus = false;
  36. }
  37. return h(Switch, {
  38. checked: record.status === 1,
  39. checkedChildren: t('common.on'),
  40. unCheckedChildren: t('common.off'),
  41. loading: record.pendingStatus,
  42. onChange(checked, _) {
  43. record.pendingStatus = true;
  44. const newStatus = checked ? 1 : 2;
  45. updateLabelRelationship({ id: record.id, status: newStatus })
  46. .then(() => {
  47. record.status = newStatus;
  48. })
  49. .finally(() => {
  50. record.pendingStatus = false;
  51. });
  52. },
  53. });
  54. },
  55. },
  56. {
  57. title: t('common.createTime'),
  58. dataIndex: 'createdAt',
  59. width: 70,
  60. customRender: ({ record }) => {
  61. return formatToDateTime(record.createdAt);
  62. },
  63. },
  64. ];
  65. export const searchFormSchema: FormSchema[] = [
  66. ];
  67. export const formSchema: FormSchema[] = [
  68. {
  69. field: 'id',
  70. label: 'ID',
  71. component: 'Input',
  72. show: false,
  73. },
  74. {
  75. field: 'labelId',
  76. label: t('wechat.labelRelationship.labelId'),
  77. component: 'InputNumber',
  78. required: true,
  79. },
  80. {
  81. field: 'contactId',
  82. label: t('wechat.labelRelationship.contactId'),
  83. component: 'InputNumber',
  84. required: true,
  85. },
  86. {
  87. field: 'contact',
  88. label: t('wechat.labelRelationship.contact'),
  89. component: 'Input',
  90. required: true,
  91. },
  92. {
  93. field: 'label',
  94. label: t('wechat.labelRelationship.label'),
  95. component: 'Input',
  96. required: true,
  97. },
  98. {
  99. field: 'status',
  100. label: t('wechat.labelRelationship.status'),
  101. component: 'RadioButtonGroup',
  102. defaultValue: 1,
  103. componentProps: {
  104. options: [
  105. { label: t('common.on'), value: 1 },
  106. { label: t('common.off'), value: 2 },
  107. ],
  108. },
  109. },
  110. ];