Ben Lin
2024-10-28 08abfcfea8247c394b2034cad59734846b403dd9
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/*
 * @Description: 通用低代码呈现页面主数据
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-02 17:52:35
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-10-23 23:01:49
 */
 
import { ActionItem, FormSchema, PopConfirm } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
import { woCustFn, woformSchema } from '/@/views/components/bizMesWo';
import { useModal } from '/@/components/Modal';
import { Ref, unref } from 'vue';
import { getRouteData, getWoRouteData } from '/@/api/tigerapi/mes/router';
import { buildUUID } from '/@/utils/uuid';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
import { DeleteEntity, getEntity } from '/@/api/tigerapi/system';
import { useGo } from '/@/hooks/web/usePage';
import { useQueryStore } from '/@/store/modules/queryInpage';
import { RouteRecordName } from 'vue-router';
 
const { t } = useI18n();
/**
 * @description: 低代码页面获取操作字段结构Json,如增加按钮及方法
 * 攻略:
 *  1. 另新建驼峰实体名.ts的文件,如:BAS_REASON.ts。以便区别不同页面的方法
 *  2. 替换主页面编辑按钮方法变为跳转到高级页面,方法中传入 { CODE: 主表记录的关键字段值,一般是XXX_CODE的值, ID: 当前记录的ID, Name: 'BAS_DEFECT'(跳转过去需要新增编辑的实体名), Title: `编辑不良代码组:${params['record']['DFTG_CODE']}`(定义tab页签的标题), pCode: 'DFTG_CODE'(主表的关键字段代码) }
 *     替换主页面新增按钮方法同上
 *  3. 在菜单管理新建一个高级页面。
 *  4. 配置高级页面,定义表单列 getFormSchema
 *  5. 初始化表格 GetBasicColumnAndInit
 *  6. 设置返回 getHomeUrl
 *  7. 设置标题 getTitle
 *  8. 设置新增时就默认的值 getKeyFieldValues
 *  9. 替换删除方法 GetActionsData
 * @param {*} params
 * @param {array} args
 * @return {*}
 */
export function GetActionsData(params: {}, ...args) {
  const data = [] as ActionItem[];
  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: 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',
        searchInfo: { TABLE_NAME: 'BAS_ITEM' },
      });
      break;
  }
}
 
/**
 * @description: 获取自定义弹出框中表单的结构
 * @param {string} type
 * @return {*}
 */
export function getFormSchema(type: string) {
  let _formSchema = [] as FormSchema[];
  switch (type) {
    case 'BIZ_MES_WO':
      _formSchema = woformSchema;
      break;
    default:
      break;
  }
  return _formSchema;
}
 
/**
 * @description: 工艺路线初始化
 * @param {*} lf
 * @return {*}
 */
export async function initRoute(lf, rotId, routeData, currlf, rotType) {
  currlf.value = unref(lf);
  //通过工艺路线ID获取图形数据,并渲染
  const _data = rotType == 'Wo' ? await getWoRouteData(rotId) : await getRouteData(rotId);
  console.log('组件已挂载', _data);
  if (_data.Data != null) {
    _data.Data.nodes.forEach((n) => {
      n.node.properties = JSON.parse(n.node.properties);
      n['node']['text']['value'] = n.NODE_NAME;
      routeData.value.nodes.push(n['node']);
    });
    console.log('111', routeData.value);
    _data.Data.edges.forEach((e) => {
      e.edge.properties = JSON.parse(e.edge.properties);
      routeData.value.edges.push(e.edge);
    });
    _data.Data.acts.forEach((act) => {
      act.node.properties = JSON.parse(act.node.properties);
      routeData.value.nodes.push(act.node);
    });
    unref(lf).render(routeData.value);
    // lf.graphModel.translateCenter();
    // lf.graphModel.fitView();
  }
}
 
/* 高级表单公用方法 *********************************Start */
 
/**
 * @description: 查询自定义方法,当在高级表单中的表格中查询时触发事件,并把{ type: type, data: data }传到父组件
 * @param {string} type 表格的名字,好确定是哪个表格要查询
 * @param {Ref} data 此表格的原数据
 * @param {*} emit dtl组件的事件,触发一个'search'事件
 * @return {*}
 */
export async function Search(type: string, data: Ref<any>, emit) {
  emit('search', { type: type, data: data });
}
 
/**
 * @description: 高级表单新增编辑方法
 * @param {Ref} data
 * @param {*} d
 * @param {*} u
 * @param {*} item
 * @param {*} updates
 * @return {*}
 */
export function EditOperation(data: Ref<any[]>, d, u, item, updates) {
  if (u.isUpdate) {
    //更新
    data.value[item] = updates;
  } else {
    //新增
    d.ID = buildUUID();
    d.CREATE_USER = useUserStore().getUserInfo.userId as string;
    d.UPDATE_TIME = formatToDateTime(new Date());
    d.UPDATE_USER = useUserStore().getUserInfo.userId as string;
    let _data2: any[] = [];
    if (!isNullOrEmpty(data.value[item])) {
      _data2 = data.value[item].map((item) => {
        return item;
      });
    }
    _data2.push(d);
    data.value[item] = _data2;
  }
}
 
/**
 * @description: 自定义删除方法
 * @param {Fn} args
 * @param {*} params
 * @return {*}
 */
export function custDel(args: Fn[], params: {}) {
  const name = params['name'];
  const useTables = args[1];
  if (!isNullOrEmpty(params['data'])) {
    const _data = params['data'].value[name].filter((item) => item['ID'] != params['record']['ID']);
    params['data'].value[name] = _data;
    useTables[name][1].setProps({
      dataSource: [],
    });
    useTables[name][1].setProps({
      dataSource: params['data'].value[name],
    });
    useTables[name][1].reload();
  } else {
    DeleteEntity(params['record'], params['entityName']).then((action) => {
      if (action.IsSuccessed) {
        useTables[name][1].reload();
      }
    });
  }
}
 
/* 高级表单公用方法 *********************************End */
 
/**
 * @description: 获取权限按钮列表
 * @param {*} params
 * @return {*}
 */
export function GenerateActionButton(params: any, buttons: Ref<[]>, openDrawer: Fn, reload: Fn) {
  const actionItem = [] as ActionItem[];
  buttons.value.map((x) => {
    if (x['BUTTON_TYPE'] == 1) {
      let url = '';
      let color = undefined as 'success' | 'error' | 'warning' | undefined;
      let _click = null as any;
      let _popConfirm = undefined as PopConfirm | undefined;
      let _tooltip = '';
      if (x['DO_METHOD'] == 'Edit') {
        url = 'clarity:note-edit-line';
        _tooltip = '编辑';
        _click = editRecord.bind(null, openDrawer, params);
      } else {
        _click = () => {};
        if (x['DO_METHOD'] == 'Delete') {
          url = 'ant-design:delete-outlined';
          color = 'error';
          _tooltip = '删除';
          _popConfirm = {
            title: '是否确认删除?',
            placement: 'left',
            confirm: deleteRecord.bind(null, reload, params),
          };
        }
      }
      actionItem.push({
        icon: isNullOrEmpty(x['ICON_URL']) ? url : x['ICON_URL'],
        tooltip: _tooltip,
        onClick: _click,
        color: color,
        popConfirm: _popConfirm,
        name: x['DO_METHOD'],
      });
    }
  });
  return actionItem;
}
 
/**
 * @description: 公用编辑方法
 * @param {Fn} fn
 * @param {*} params
 * @return {*}
 */
export 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: 跳转并根据传入的参数通过session传入
 * @param {string} path 跳转地址
 * @return {*}
 */
export function goByParams(path: string, params: {}, go) {
  if (path.split('/').length > 2 && path.split('/')[2] == 'LC') {
    getEntity({
      sqlcmd: `ASSEMBLY_NAME ='${path.split('/')[1]}'`,
      entityName: 'SYS_LOW_CODE',
      order: '',
    }).then((data) => {
      const searchForms = JSON.parse(data.Data.Items[0].SEARCH_FORM_JSON);
      const colSlots = [] as string[];
      for (const i in searchForms) {
        if (!isNullOrUnDef(searchForms[i]['colSlot'])) {
          colSlots.push('form-' + searchForms[i]['colSlot']);
        }
      }
 
      const _cruds = JSON.parse(data.Data.Items[0].FORM_JSON);
      const crudColSlots = [] as string[];
      for (const i in _cruds) {
        if (!isNullOrUnDef(_cruds[i]['colSlot'])) {
          crudColSlots.push(_cruds[i]['colSlot']);
        }
      }
      const id = {
        ID: path.split('/')[1],
        colSlots: colSlots,
        crudColSlots: crudColSlots,
        sName: `${path.split('/')[1]}_update`,
      };
      // 将对象转换为JSON字符串并保存到sessionStorage
      sessionStorage.removeItem(`${id.sName}_params`);
      sessionStorage.setItem(`${id.sName}_params`, encodeURI(JSON.stringify({ params: params })));
      go(`/${path.split('/')[1]}/${path.split('/')[2]}/${encodeURI(JSON.stringify(id))}`);
    });
  } else if (
    (path.split('/').length > 2 && path.split('/')[2] == 'High') ||
    path.split('/')[2] == 'CP'
  ) {
    const id = { sName: `${path.split('/')[1]}_update`, Name: path.split('/')[1], params: params };
    // 将对象转换为JSON字符串并保存到sessionStorage
    sessionStorage.removeItem(`${id.sName}_params`);
    sessionStorage.setItem(`${id.sName}_params`, encodeURI(JSON.stringify(id)));
    go(
      `/${path.split('/')[1]}/${path.split('/')[2]}/${encodeURI(JSON.stringify({ sName: id.sName, Name: id.Name }))}`,
    );
  } else {
    const id = { sName: `${path.split('/')[1]}_update`, params: params };
    // 将对象转换为JSON字符串并保存到sessionStorage
    sessionStorage.removeItem(`${id.sName}_params`);
    sessionStorage.setItem(`${id.sName}_params`, encodeURI(JSON.stringify(id)));
    go(`${path}/${encodeURI(JSON.stringify({ sName: id.sName }))}`);
  }
}
 
/**
 * @description: 调用api前,参数整理
 * @param {*} t
 * @return {*}
 */
export function SearchInfoFn(param: any, name: RouteRecordName | null | undefined, ByOrg: boolean) {
  const useQuery = useQueryStore();
  if (
    !isNullOrUnDef(useQuery.getCurSearchInfo) &&
    useQuery.getCurSearchInfo.some((q) => q.name == name)
  ) {
    const curSearchInfo = useQuery.getCurSearchInfo.filter((q) => q.name == name);
    const Keys = Object.getOwnPropertyNames(curSearchInfo[0].searchInfo);
    for (const k in Keys) {
      if (Keys[k] != 'page' && Keys[k] != 'pageSize') {
        param[Keys[k]] = curSearchInfo[0].searchInfo[Keys[k]];
      }
    }
    useQuery.setCurSearchInfo({ name: name, searchInfo: param });
  }
  if (isNullOrEmpty(param.option) && ByOrg) {
    param.option = {
      //根据据点查询,必需带这个参数
      UserId: useUserStore().getUserInfo.userId,
      ByOrg: true,
      CurOrg: useUserStore().getUserInfo.orgCode,
    };
  }
  return param;
}
 
/**
 * @description: 请求之后对返回值进行处理
 * @param {*} t
 * @return {*}
 */
export function afterFetchFn(t: any, name: RouteRecordName | null | undefined, f) {
  const useQuery = useQueryStore();
  if (
    !isNullOrUnDef(useQuery.getCurSearchInfo) &&
    useQuery.getCurSearchInfo.some((q) => q.name == name)
  ) {
    const curSearchInfo = useQuery.getCurSearchInfo.filter((q) => q.name == name);
    f.setFieldsValue(curSearchInfo[0].searchInfo);
  }
}