Ben Lin
2024-07-03 a745761147b17a42b4698250a170ef4c0fa0b09b
src/views/tigerprojects/system/lowcode/data.ts
@@ -1,79 +1,43 @@
/*
 * @Description: 通用低代码呈现页面主数据
 * @Author: Ben Lin
 * @version:
 * @version:
 * @Date: 2024-06-02 17:52:35
 * @LastEditors: your name
 * @LastEditTime: 2024-06-13 22:44:43
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-03 20:19:37
 */
import { ref } from 'vue';
import {
  DftGrpRelease,
  dftGrpActionItem,
  dftGrpOpenSelectItem,
  dftGrpGetSelectSuccess,
  dftGrpactionColumn,
} from './normal/basDefectGrp';
import { onChangeFns, rsGrpGetSelectSuccess, rsGrpOpenSelectItem } from './normal/basReasonGrp';
import { DeleteEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn, FormSchema } from '/@/components/Table';
import { ActionItem, 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 { useGo } from '/@/hooks/web/usePage';
import { goDetail, labelActionItem, labelGetSelectSuccess, labelOpenSelectItem } from './detail/basLabelVar';
import { Ref, unref } from 'vue';
import { getRouteData } from '/@/api/tigerapi/mes/router';
import { buildUUID } from '/@/utils/uuid';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
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: 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':
      const _d = dftGrpActionItem;
      _d[0].onClick = DftGrpRelease.bind(null, args, params);
      data = [...data, ..._d];
      params.cType.value = 'BIZ_MES_WO';
      params.formSchemas.value[params.cType.value] = getFormSchema(params.cType.value);
      params.useFormData.value = {
        forminfo: args[3]({
          labelWidth: 120,
          schemas: params.formSchemas.value[params.cType.value],
          actionColOptions: {
            span: 24,
          },
          showActionButtonGroup: false,
        }),
      };
      break;
      /* 标签模板 */
    case 'BAS_LABEL_TEMP':
      const _data = labelActionItem;
      _data[0].onClick = goDetail.bind(null, args[5], params['record'])
      data = [...data, ..._data];
      break;
  }
export function GetActionsData(params: {}, ...args) {
  let data = [] as ActionItem[];
  return data;
}
@@ -93,137 +57,6 @@
}
/**
 * @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();
    }
  });
}
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;
}
/* 弹出选择框选择成功 */
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
@@ -234,14 +67,14 @@
  if (!isNullOrEmpty(fnName)) {
    switch (entityName) {
      case 'BAS_REASON':
        onChangeFns[fnName](e);
        // onChangeFns[fnName](e);
        break;
      default:
        break;
        (e) => { };
        (e) => {};
    }
  } else {
    (e) => { };
    (e) => {};
  }
}
@@ -292,6 +125,7 @@
        ],
        tableName: 'BAS_ITEM',
        rowKey: 'ITEM_CODE',
        searchInfo: { TABLE_NAME: 'BAS_ITEM' },
      });
      break;
  }
@@ -308,18 +142,84 @@
    case 'BIZ_MES_WO':
      _formSchema = woformSchema;
      break;
    // case 'woinfo':
    //   _formSchema = woCfgformSchema;
    //   break;
    // case 'prodinfo':
    //   _formSchema = prodCfgformSchema;
    //   break;
    // case 'xxinfo':
    //   _formSchema = xxCfgformSchema;
    // break;
    default:
      break;
      (e) => { };
  }
  return _formSchema;
}
/**
 * @description: 工艺路线初始化
 * @param {*} lf
 * @return {*}
 */
export async function initRoute(lf, rotId, routeData, currlf) {
  currlf.value = unref(lf);
  //通过工艺路线ID获取图形数据,并渲染
  var _data = 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;
    var _data2: any[] = [];
    if (!isNullOrEmpty(data.value[item])) {
      _data2 = data.value[item].map((item) => {
        return item;
      });
    }
    _data2.push(d);
    data.value[item] = _data2;
  }
}
/* 高级表单公用方法 *********************************End */