Ben Lin
2024-06-14 509366a157059aeaf6daa2492cf32e108a8ca104
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *                               神兽保佑            永无BUG
 */
 
 
/*
 * @Description: 通用低代码呈现页面主数据
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-02 17:52:35
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-14 09:08:11
 */
 
import {
  DftGrpRelease,
  dftGrpOpenSelectItem,
  dftGrpGetSelectSuccess,
  dftGrpactionColumn,
  baseSchema,
  DftGrpEdit,
  searchSchema,
  defectBaseColumn,
} from './normal/basDefectGrp';
import { onChangeFns, rsGrpGetSelectSuccess, rsGrpOpenSelectItem } from './normal/basReasonGrp';
import { DeleteEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { isNullOrEmpty } from '/@/utils/is';
import { woCustFn, woformSchema } from '/@/views/components/bizMesWo';
import { useModal } from '/@/components/Modal';
import { goDetail, labelActionItem, labelGetSelectSuccess, labelOpenSelectItem } from './detail/basLabelVar';
import { buildUUID } from '/@/utils/uuid';
import { Tag } from 'ant-design-vue';
import { Ref, h } from 'vue';
 
const { t } = useI18n();
 
/**
 * @description: 低代码页面获取操作字段结构Json,如增加按钮及方法
 * @param {*} params
 * @param {array} args
 * @return {*}
 */
export function GetActionsData(params: {}, ...args: Fn[]) {
  let data = [
    {
      icon: 'clarity:note-edit-line',
      onClick: editRecord.bind(null, args[0], params),
    },
    {
      icon: 'ant-design:delete-outlined',
      color: 'error',
      popConfirm: {
        title: '是否确认删除?',
        placement: 'left',
        confirm: deleteRecord.bind(null, args[1], params),
      },
    },
  ] as ActionItem[];
  switch (params['entityName']) {
    /* 不良代码组 */
    case 'BAS_DEFECT_GRP':
      data[0].onClick = DftGrpEdit.bind(null, args, params);
      break;
    case 'BAS_DEFECT':
      break;
    /* 标签模板 */
    case 'BAS_LABEL_TEMP':
      const _data = labelActionItem;
      _data[0].onClick = goDetail.bind(null, args[5], params['record'])
      data = [...data, ..._data];
      break;
  }
  return data;
}
 
/**
 * @description: 获取新增按钮的行为
 * @param {string} type
 * @return {*}
 */
export function getCreateAction(type: string) {
  let data = { action: 'drawer', url: '', params: {} }; //drawer(打开左侧抽屉框) | go(跳转到新的页面)
  switch (type) {
    case 'BAS_DEFECT_GRP':
      data.action = 'go';
      data.url = 'BAS_DEFECT/High';
      data.params = { CODE: '0', ID: buildUUID(), Name: 'BAS_DEFECT', Title: '新增不良代码组', pageTitle: '不良代码组管理', pageContent: '这里可以添加和修改不良代码组和不良代码。' };
      break;
  }
  return data;
}
 
export function GetUseModalData(type: string) {
  let data = {};
  switch (type) {
    case 'BAS_DEFECT_GRP':
      data = {
        add: useModal(),
        set: useModal(),
        addRot: useModal(),
        setRot: useModal(),
      };
      break;
  }
  return data;
}
 
/**
 * @description: 公用编辑方法
 * @param {Fn} fn
 * @param {*} params
 * @return {*}
 */
function editRecord(fn: Fn, params: {}) {
  fn(true, params);
}
 
/**
 * @description: 公用删除方法
 * @param {Fn} fn
 * @param {*} params
 * @return {*}
 */
function deleteRecord(fn: Fn, params: {}) {
  console.log(params['record']);
  //删除
  DeleteEntity(params['record'], params['entityName']).then((action) => {
    if (action.IsSuccessed) {
      fn();
    }
  });
}
 
/**
 * @description: 获取操作列样式方法
 * @param {string} entityName
 * @return {*}
 */
export function GetActionColumn(entityName: string) {
  let data: BasicColumn = {};
  switch (entityName) {
    case 'BAS_DEFECT_GRP':
      data = dftGrpactionColumn;
      break;
    case 'BAS_LABEL_TEMP':
      data = {
        width: 120,
        title: '操作',
        dataIndex: 'action',
        slots: { customRender: 'action' },
        fixed: 'right',
      };
      break;
    default:
      data = {
        width: 80,
        title: '操作',
        dataIndex: 'action',
        slots: { customRender: 'action' },
        fixed: undefined,
      };
      break;
  }
  return data;
}
 
/**
 * @description: 打开弹出选择框选择成功后返回方法
 * @param {*} d
 * @param {*} u
 * @param {string} entityName
 * @return {*}
 */
export function GetSelectSuccess(d, u, entityName: string) {
  let data = {};
  switch (entityName) {
    case 'BAS_DEFECT_GRP':
      data = dftGrpGetSelectSuccess(d, u);
      break;
    case 'BAS_REASON_GRP':
      data = rsGrpGetSelectSuccess(d, u);
      break;
    case 'BAS_LABEL_PV':
      data = labelGetSelectSuccess(d, u);
      break;
    default:
      data = {
        ITEM_CODE: d.values['val'],
      };
      break;
  }
  return data;
}
 
/**
 * @description: 打开弹出选择框
 * @param {Fn} openItemModal
 * @param {string} entityName
 * @return {*}
 */
export function OpenSelectItem(openItemModal: Fn, entityName: string) {
  switch (entityName) {
    case 'BAS_DEFECT_GRP':
      dftGrpOpenSelectItem(openItemModal);
      break;
    case 'BAS_REASON_GRP':
      rsGrpOpenSelectItem(openItemModal);
      break;
    case 'BAS_LABEL_PV':
      labelOpenSelectItem(openItemModal);
      break;
    default:
      openItemModal(true, {
        title: '物料列表',
        schemas: [
          {
            field: 'ITEM_CODE',
            component: 'Input',
            label: '物料编码',
            colProps: {
              span: 12,
            },
          },
        ],
        ItemColumns: [
          {
            title: t('物料编码'),
            dataIndex: 'ITEM_CODE',
            resizable: true,
            sorter: true,
            width: 200,
          },
          {
            title: t('物料名称'),
            dataIndex: 'ITEM_NAME',
            resizable: true,
            sorter: true,
            width: 180,
          },
        ],
        tableName: 'BAS_ITEM',
        rowKey: 'ITEM_CODE',
      });
      break;
  }
}
 
/**
 * @description: Select 自定义onChange方法
 * @param {any} e
 * @param {string} fnName
 * @param {string} entityName
 * @return {*}
 */
export function custOnChange(e: any, fnName: string, entityName: string) {
  if (!isNullOrEmpty(fnName)) {
    switch (entityName) {
      case 'BAS_REASON':
        onChangeFns[fnName](e);
        break;
      default:
        break;
        (e) => { };
    }
  } else {
    (e) => { };
  }
}
 
/**
 * @description: 打开自定义弹出框方法
 * @return {*}
 */
export function OpenCustModal(
  openItemModal: Fn,
  entityName: string,
  slotName: string,
  others: Fn[],
  ...args
) {
  switch (entityName) {
    case 'BIZ_MES_WO':
    case 'BIZ_MES_WO_Config': //根据带入的名称打开不同的实体列表
      woCustFn(openItemModal, slotName, others, args);
      break;
    default: //默认打开物料列表
      openItemModal(true, {
        title: '物料列表',
        schemas: [
          {
            field: 'ITEM_CODE',
            component: 'Input',
            label: '物料编码',
            colProps: {
              span: 12,
            },
          },
        ],
        ItemColumns: [
          {
            title: t('物料编码'),
            dataIndex: 'ITEM_CODE',
            resizable: true,
            sorter: true,
            width: 200,
          },
          {
            title: t('物料名称'),
            dataIndex: 'ITEM_NAME',
            resizable: true,
            sorter: true,
            width: 180,
          },
        ],
        tableName: 'BAS_ITEM',
        rowKey: 'ITEM_CODE',
      });
      break;
  }
}
 
/**
 * @description: 获取自定义弹出框中表单的结构
 * @param {string} type
 * @return {*}
 */
export function getFormSchema(type: string) {
  let _formSchema = [] as FormSchema[];
  switch (type) {
    case 'BIZ_MES_WO':
      _formSchema = woformSchema;
      break;
    case 'BaseForm':
      _formSchema = baseSchema;
      break;
    case 'BAS_DEFECT':
      _formSchema = searchSchema;
      break;
    default:
      break;
  }
  return _formSchema;
}
 
/**
 * @description: 获取表格列
 * @param {string} entityName
 * @return {*}
 */
export function GetBasicColumnAndInit(entityName: string, ...args) {
  let data: BasicColumn[] = [];
  switch (entityName) {
    case 'BAS_DEFECT':
      data = defectBaseColumn;
      args[0].value[entityName] = getFormSchema(entityName);
      args[0].value['BaseForm'] = getFormSchema('BaseForm');
      args[1].value = {
        BaseForm: args[4]({
          labelWidth: 120,
          schemas: args[0].value['BaseForm'],
          actionColOptions: {
            span: 24,
          },
          showActionButtonGroup: false,
        }),
      };
      args[2].value = [
        { name: 'BaseForm', slots: [], preIcons: {}, title: '不良代码组信息' },
        // {
        //   name: 'prodinfo',
        //   slots: ['addRot', 'setRot'],
        //   preIcons: { addRot: 'search|svg', setRot: 'config|svg' },
        //   title: '产品信息',
        // },
        // { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '工艺信息' },
      ];
      break;
    default:
      break;
  }
  return data;
}