generator.ts 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import axios from 'axios';
import qs from 'query-string';

const BASE_URL = '/tool/generator';

export interface TableRecord {
  tableName: string;
  comment?: string;
  engine: string;
  charset: string;
  createTime?: string;
12
  isConfiged: boolean;
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
}

export interface TableParam {
  tableName?: string;
}

export interface TableListRes {
  list: TableRecord[];
  total: number;
}

export function listTable(params: TableParam) {
  return axios.get<TableListRes>(`${BASE_URL}/table`, {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}
32

33
export interface FieldConfigRecord {
34 35 36 37 38 39 40 41
  tableName: string;
  columnName: string;
  columnType: string;
  fieldName: string;
  fieldType: string;
  comment: string;
  isRequired: boolean;
  showInList: boolean;
42
  showInForm: boolean;
43 44 45
  showInQuery: boolean;
  formType: string;
  queryType: string;
46
  createTime?: string;
47 48
}

49 50
export function listFieldConfig(tableName: string, requireSync: boolean) {
  return axios.get<FieldConfigRecord[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`);
51 52
}

53 54 55 56 57 58 59 60 61
export interface GenConfigRecord {
  tableName: string;
  moduleName: string;
  packageName: string;
  frontendPath: string;
  businessName: string;
  author: string;
  tablePrefix: string;
  isOverride: boolean;
62 63
  createTime?: string;
  updateTime?: string;
64 65
}

66
export function getGenConfig(tableName: string) {
67
  return axios.get<GenConfigRecord>(`${BASE_URL}/config/${tableName}`);
68
}
69 70 71

export interface GeneratorConfigRecord {
  genConfig: GenConfigRecord;
72
  fieldConfigs: FieldConfigRecord[];
73 74 75
}

export function saveConfig(tableName: string, req: GeneratorConfigRecord) {
76
  return axios.post(`${BASE_URL}/config/${tableName}`, req);
77
}
78 79 80 81

export function generate(tableName: string) {
  return axios.post(`${BASE_URL}/${tableName}`);
}