config.data.ts 1.69 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { transformTime } from '/@/hooks/web/useDateToLocaleString';
import { isObject, isString } from '/@/utils/is';

export const columns: BasicColumn[] = [
  {
    title: '创建时间',
    dataIndex: 'createdTime',
    width: 200,
    format: (_text: string, record: Recordable) => {
      return transformTime(record.createdTime);
    },
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 200,
  },
  {
    title: '是否根链',
    dataIndex: 'root',
    slots: {
      customRender: 'root',
    },
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'textSearch',
    label: '名称',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请输入名称',
    },
  },
];

export const encode = (string: string) => {
  return encodeURIComponent(string);
};

export const exportJSONFile = (value: Recordable, name: string) => {
  const blob = new Blob([JSON.stringify(value, null, 2)], { type: 'text/json' });
  const objectURL = URL.createObjectURL(blob);
  const element = document.createElement('a');
  element.href = objectURL;
  element.download = `${name}.json`;
  element.style.display = 'none';
  document.body.appendChild(element);
  element.click();
  element.remove();
  URL.revokeObjectURL(objectURL);
};

export const paseJSON = (string: string) => {
  let data = null;
  let flag = false;
  try {
    if (!isString(string)) return { flag: false, data };
    data = JSON.parse(string);
    flag = true;
    if (!isObject(data)) flag = false;
  } catch (error) {}
  return { flag, data };
};

export enum RuleChainPermisssion {
  DETAIL = 'rule:chain:detail',
}