刘光辉
119 分钟以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { defHttp } from '#/api/request';
 
export type FieldScope = 'GLOBAL' | 'TEMPLATE';
export type FieldVersionStatus = 'CANCELLED' | 'DRAFT' | 'PRE_RELEASE' | 'PUBLISHED';
export type FieldDataType = 'CHECKBOX' | 'DATE' | 'DATETIME' | 'DECIMAL' | 'SELECT' | 'TEXT' | 'TEXTAREA';
export type FieldBatchMode = 'BATCH_SHARED' | 'RECORD_PRIVATE';
export type FieldReadSource = 'LIMS_TASK' | 'NONE' | 'SYSTEM';
export type FieldEnabled = 'disabled' | 'enabled';
 
export interface FieldBinding {
  read: {
    property?: string;
    propertyRevision?: number;
    source: FieldReadSource;
  };
  write: {
    target: 'ELN_RECORD';
  };
}
 
export interface FieldVersionRule {
  binding: FieldBinding;
  danwei?: string;
  kongjianPeizhi?: Record<string, unknown>;
  piciMoshi: FieldBatchMode;
  recommendedCheckboxGroupCode?: string;
  recommendedCheckboxMaxSelected?: null | number;
  recommendedCheckboxMinSelected?: number;
  shifouBitian: 0 | 1;
  shujuLeixing: FieldDataType;
  ziduanMingcheng: string;
}
 
export interface FieldPageQuery {
  bizEnabled?: FieldEnabled;
  currentPage: number;
  keyword?: string;
  mubanBianhao?: string;
  pageSize: number;
  zuoyongFanwei?: FieldScope;
}
 
export interface FieldListItem {
  bizEnabled: FieldEnabled;
  dangqianBanbenHao?: number;
  dangqianZiduanBanbenId?: string;
  gengxinShijian?: string;
  id: string;
  mubanBianhao?: string;
  mubanYinyongShu: number;
  ziduanBianma: string;
  ziduanMingcheng?: string;
  zuixinFabuBanbenHao?: number;
  zuoyongFanwei: FieldScope;
}
 
export interface FieldVersion extends FieldVersionRule {
  banbenHao: number;
  bizStatus: FieldVersionStatus;
  chuangjianShijian?: string;
  gengxinShijian?: string;
  id: string;
  ziduanDingyiId: string;
  zuofeiYuanyin?: string;
}
 
export interface FieldDetail {
  beizhu?: string;
  bizEnabled: FieldEnabled;
  dangqianZiduanBanbenId?: string;
  id: string;
  mubanBianhao?: string;
  versions: FieldVersion[];
  ziduanBianma: string;
  zuoyongFanwei: FieldScope;
}
 
export interface ProviderProperty {
  dataType: FieldDataType;
  enabled: boolean;
  label: string;
  property: string;
  propertyRevision?: number;
  readOnly: boolean;
  source: Exclude<FieldReadSource, 'NONE'>;
}
 
export interface FieldPagination {
  currentPage: number;
  pageSize: number;
  total: number;
}
 
export interface FieldPage {
  list: FieldListItem[];
  pagination: FieldPagination;
}
 
export interface CreateFieldParams extends FieldVersionRule {
  beizhu?: string;
  zuoyongFanwei: 'GLOBAL';
}
 
export interface CreateFieldVersionParams {
  sourceVersionId: string;
}
 
export interface SwitchCurrentVersionParams {
  reason: string;
  versionId: string;
}
 
interface ApiResult<T> {
  code: number;
  data: T;
  msg?: string;
}
 
const FIELD_CATALOG_PREFIX = '/api/eln/fieldCatalog';
 
export function getFieldPage(data: FieldPageQuery) {
  return defHttp.get<ApiResult<FieldPage>>({ data, url: FIELD_CATALOG_PREFIX });
}
 
export function createField(data: CreateFieldParams) {
  return defHttp.post<ApiResult<FieldDetail>>({ data, url: FIELD_CATALOG_PREFIX });
}
 
export function getFieldDetail(id: string) {
  return defHttp.get<ApiResult<FieldDetail>>({ url: `${FIELD_CATALOG_PREFIX}/${id}` });
}
 
export function getProviderProperties(source: Exclude<FieldReadSource, 'NONE'>) {
  return defHttp.get<ApiResult<ProviderProperty[]>>({ data: { source }, url: `${FIELD_CATALOG_PREFIX}/providerProperties` });
}
 
export function suggestFieldCode(text: string) {
  return defHttp.post<ApiResult<{ code: string }>>({ data: { text }, url: `${FIELD_CATALOG_PREFIX}/codeSuggestions` });
}
 
export function createFieldVersion(fieldId: string, data: CreateFieldVersionParams) {
  return defHttp.post<ApiResult<FieldVersion>>({ data, url: `${FIELD_CATALOG_PREFIX}/${fieldId}/versions` });
}
 
export function updateFieldVersion(versionId: string, data: FieldVersionRule) {
  return defHttp.put<ApiResult<FieldVersion>>({ data, url: `${FIELD_CATALOG_PREFIX}/versions/${versionId}` });
}
 
export function preReleaseFieldVersion(versionId: string) {
  return defHttp.post<ApiResult<void>>({ url: `${FIELD_CATALOG_PREFIX}/versions/${versionId}/preRelease` });
}
 
export function publishFieldVersion(versionId: string) {
  return defHttp.post<ApiResult<void>>({ url: `${FIELD_CATALOG_PREFIX}/versions/${versionId}/publish` });
}
 
export function cancelFieldVersion(versionId: string, reason: string) {
  return defHttp.post<ApiResult<void>>({ data: { reason }, url: `${FIELD_CATALOG_PREFIX}/versions/${versionId}/cancel` });
}
 
export function switchCurrentFieldVersion(fieldId: string, data: SwitchCurrentVersionParams) {
  return defHttp.post<ApiResult<void>>({ data, url: `${FIELD_CATALOG_PREFIX}/${fieldId}/currentVersion` });
}
 
export function promoteFieldToGlobal(fieldId: string, reason: string) {
  return defHttp.post<ApiResult<void>>({ data: { reason }, url: `${FIELD_CATALOG_PREFIX}/${fieldId}/promoteGlobal` });
}
 
export function enableField(fieldId: string, reason: string) {
  return defHttp.post<ApiResult<void>>({ data: { reason }, url: `${FIELD_CATALOG_PREFIX}/${fieldId}/enable` });
}
 
export function disableField(fieldId: string, reason: string) {
  return defHttp.post<ApiResult<void>>({ data: { reason }, url: `${FIELD_CATALOG_PREFIX}/${fieldId}/disable` });
}