template.data.ts 3.88 KB
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import {findDictItemByCode} from "/@/api/system/dict";
import {findMessageConfig} from "/@/api/message/config";
import {isMessage} from "/@/views/message/config/config.data";
import {h} from "vue";
import {Switch} from "ant-design-vue";
import {useMessage} from "/@/hooks/web/useMessage";
import {setMessageTemplateStatus} from "/@/api/message/template";

export const columns: BasicColumn[] = [
  {
    title: '模板名称',
    dataIndex: 'templateName',
    width: 200,
  },
  {
    title: '配置名称',
    dataIndex: 'messageConfig.configName',
    width: 200,
    slots: { customRender: 'config' },
  },
  {
    title: '模板编码',
    dataIndex: 'templateCode',
    width: 180,
  },
  {
    title: '签名信息',
    dataIndex: 'signName',
    width: 180,
  },
  {
    title:'模板用途',
    dataIndex:'templatePurposeDictText',
    width: 180,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 180,
    customRender: ({ record }) => {
      if (!Reflect.has(record, 'pendingStatus')) {
        record.pendingStatus = false;
      }
      return h(Switch, {
        checked: record.status === 1,
        checkedChildren: '已启用',
        unCheckedChildren: '已禁用',
        loading: record.pendingStatus,
        onChange(checked: boolean) {
          record.pendingStatus = true;
          const newStatus = checked ? 1 : 0;
          const { createMessage } = useMessage();
          setMessageTemplateStatus(record.id,record.templatePurpose,record.messageType,newStatus)
            .then(() => {
              record.status = newStatus;
              createMessage.success(`修改成功`);
            })
            .finally(() => {
              record.pendingStatus = false;
            });
        },
      });
    },
  },
  {
    title: '模板用途',
    dataIndex: 'templatePurpose',
    width: 180,
    ifShow:false
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'templateName',
    label: '模板名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'templateCode',
    label: '模板编码',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '主键',
    component:'Input',
    show:false,
  },
  {
    field: 'messageType',
    label: '消息类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api:findDictItemByCode,
      params:{
        dictCode:"message_type"
      },
      labelField:'itemText',
      valueField:'itemValue',
    },
  },
  {
    field: 'messageConfigId',
    label: '配置名称',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api:findMessageConfig,
      params:{
        messageType:({values}) => Reflect.get(values,'messageType')
      },
      immediate:true,
      labelField:'configName',
      valueField:'id',
    },
  },
  {
    field: 'templateName',
    label: '模板名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'templateCode',
    label: '模板编号',
    required: true,
    component: 'Input',
    ifShow:({values}) => isMessage(Reflect.get(values,'messageType')),
  },
  {
    field: 'signName',
    label: '签名',
    required:true,
    component: 'Input',
    ifShow:({values}) => isMessage(Reflect.get(values,'messageType')),
  },
  {
    field: 'templatePurpose',
    label: '模板用途',
    required: true,
    component: 'ApiSelect',
    helpMessage: ['用户登录、忘记密码模板平台只提供"code"参数', '初始密码设置平台提供"name"参数'],
    componentProps: {
      api:findDictItemByCode,
      params:{
        dictCode:"template_purpose"
      },
      labelField:'itemText',
      valueField:'itemValue',
    },
  },
];