|
@@ -1,10 +1,312 @@
|
|
|
+import { DataType, TableType } from "@/enum";
|
|
|
+import { ColumnItem, TableItemType } from "@/type";
|
|
|
+
|
|
|
/**
|
|
|
* 创建uuid
|
|
|
- * */
|
|
|
+ * */
|
|
|
export function uuid() {
|
|
|
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
|
var r = (Math.random() * 16) | 0,
|
|
|
v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
|
return v.toString(16);
|
|
|
});
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+export const createTable = (tableType: TableType, parentId?: string): TableItemType => {
|
|
|
+ const tableId = uuid();
|
|
|
+ const tableColumnList: ColumnItem[] = [];
|
|
|
+ if(tableType === TableType.FlowTable) {
|
|
|
+ // 创建流程表预定义字段
|
|
|
+ const list = createFlowPredefinedFields(tableId, !!parentId);
|
|
|
+ tableColumnList.push(...list);
|
|
|
+ } else {
|
|
|
+ // 创建业务表预定义字段
|
|
|
+ tableColumnList.push(...createBasePredefinedField(tableId));
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ isTable: true,
|
|
|
+ table: {
|
|
|
+ aliasName: "newtable",
|
|
|
+ creationTime: "",
|
|
|
+ creatorUserId: "",
|
|
|
+ displayOrder: true,
|
|
|
+ id: tableId,
|
|
|
+ isDeleted: false,
|
|
|
+ langDescription: "",
|
|
|
+ langName: "",
|
|
|
+ parentBusinessTableId: parentId || "",
|
|
|
+ schemaName: "new_table",
|
|
|
+ type: 1,
|
|
|
+ updateTime: "",
|
|
|
+ openSync: false,
|
|
|
+ style: {
|
|
|
+ // 随机颜色
|
|
|
+ color: "#" + Math.floor(Math.random() * 0x666666).toString(16),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ tableColumnList,
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建字段
|
|
|
+ * @param tableId 表id
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+export const createColumn = (tableId?: string): ColumnItem => {
|
|
|
+ return {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ maxLength: 100,
|
|
|
+ precision: 0,
|
|
|
+ scale: 0,
|
|
|
+ isRequired: false,
|
|
|
+ isUnique: false,
|
|
|
+ isPreDefined: false,
|
|
|
+ defaultValue: "",
|
|
|
+ displayOrder: 0,
|
|
|
+ businessTableId: tableId || "",
|
|
|
+ memo: "",
|
|
|
+ whereInputType: "",
|
|
|
+ whereInputContent: "",
|
|
|
+ charset: "",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "" },
|
|
|
+ { name: "en", value: "" },
|
|
|
+ ],
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建基础表预定义字段
|
|
|
+ */
|
|
|
+export const createBasePredefinedField = (tableId: string): ColumnItem[] => {
|
|
|
+ return [
|
|
|
+ // id
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "id",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 1,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "Id" },
|
|
|
+ { name: "en", value: "Id" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 创建时间
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "creation_time",
|
|
|
+ type: DataType.DateTime,
|
|
|
+ displayOrder: 9001,
|
|
|
+ maxLength: 0,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ defaultValue: "<%SystemDate%>",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "创建时间" },
|
|
|
+ { name: "en", value: "CreationTime" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 创建者
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "creation_user",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 9002,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ defaultValue: "<%UserId%>",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "创建人" },
|
|
|
+ { name: "en", value: "CreationUser" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 更新时间
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "update_time",
|
|
|
+ type: DataType.DateTime,
|
|
|
+ displayOrder: 9003,
|
|
|
+ maxLength: 0,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ defaultValue: "<%SystemDate%>",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "更新时间" },
|
|
|
+ { name: "en", value: "UpdateTime" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 更新者
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "update_user",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 9004,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ defaultValue: "<%UserId%>",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "更新人" },
|
|
|
+ { name: "en", value: "UpdateUser" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 删除时间
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "delete_time",
|
|
|
+ type: DataType.DateTime,
|
|
|
+ displayOrder: 9005,
|
|
|
+ maxLength: 0,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "删除时间" },
|
|
|
+ { name: "en", value: "DeleteTime" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 删除人
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "delete_user",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 9006,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ defaultValue: "<%UserId%>",
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "删除人" },
|
|
|
+ { name: "en", value: "DeleteUser" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 删除状态
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "is_deleted",
|
|
|
+ type: DataType.Bit,
|
|
|
+ displayOrder: 9007,
|
|
|
+ maxLength: 0,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "删除状态" },
|
|
|
+ { name: "en", value: "IsDeleted" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ];
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * 创建流程表预定义字段
|
|
|
+ */
|
|
|
+export const createFlowPredefinedFields = (
|
|
|
+ tableId: string,
|
|
|
+ isMainTable: boolean
|
|
|
+) => {
|
|
|
+ return [
|
|
|
+ // id
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "id",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 1,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "Id" },
|
|
|
+ { name: "en", value: "Id" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ // 任务id
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "TaskId",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 2,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "任务Id" },
|
|
|
+ { name: "en", value: "TaskId" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ...(isMainTable
|
|
|
+ ? [
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "snNumber",
|
|
|
+ type: DataType.Nvarchar,
|
|
|
+ displayOrder: 3,
|
|
|
+ maxLength: 50,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "单号" },
|
|
|
+ { name: "en", value: "SnNumber" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "taskStatus",
|
|
|
+ type: DataType.Int,
|
|
|
+ displayOrder: 4,
|
|
|
+ maxLength: 0,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "任务状态" },
|
|
|
+ { name: "en", value: "TaskStatus" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "creationTime",
|
|
|
+ type: DataType.DateTime,
|
|
|
+ displayOrder: 5,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: true,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "创建时间" },
|
|
|
+ { name: "en", value: "CreationTime" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ : [
|
|
|
+ {
|
|
|
+ id: uuid(),
|
|
|
+ schemaName: "gridOrder",
|
|
|
+ type: DataType.Int,
|
|
|
+ displayOrder: 3,
|
|
|
+ businessTableId: tableId,
|
|
|
+ isRequired: false,
|
|
|
+ isPreDefined: true,
|
|
|
+ langNameList: [
|
|
|
+ { name: "zh-CN", value: "序号" },
|
|
|
+ { name: "en", value: "GridOrder" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ]),
|
|
|
+ ];
|
|
|
+};
|