<template>
|
<div>
|
<BasicTable @register="registerTable">
|
<template #toolbar>
|
<a-button
|
type="primary"
|
@click="handleCreate(item['DO_METHOD'])"
|
:preIcon="item['ICON_URL']"
|
v-for="item in buttons.filter((m) => m['BUTTON_TYPE'] == 0)"
|
:key="item"
|
>
|
{{ item['FUNC_NAME'] }}
|
</a-button>
|
</template>
|
<template #action="{ record }">
|
<TableAction :actions="createActions(record)" />
|
</template>
|
<template #[item]="{ field }" v-for="item in colSlots" :key="item">
|
<!-- <template #form-BAS_REASON3aadd="{ field }"> -->
|
<a-button
|
v-if="field"
|
class="mt-1 ml-1"
|
size="small"
|
@click="handleSelectItem(item)"
|
preIcon="search|svg"
|
/>
|
<GeneralModal
|
@register="registerItemAdd"
|
@success="(d, u) => handleItemSuccess(d, u, item)"
|
/>
|
</template>
|
</BasicTable>
|
<Suspense>
|
<CustModal
|
@register="registerCust"
|
@success="custSuccess"
|
:type="cType"
|
:entityName="entityName"
|
@modalInner="getdtlSlots"
|
>
|
<!-- 用插槽自定义多表单 -->
|
<template #[item.name] v-for="item in dtlSlots" :key="item.name">
|
<BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]">
|
<!-- 用插槽自定义弹出选择框 -->
|
<template #[name]="{ field }" v-for="name in item.slots" :key="name">
|
<a-button
|
class="mt-1 ml-1"
|
size="small"
|
@click="handleCustClick(field)"
|
:preIcon="item.preIcons[name]"
|
/>
|
<GeneralModal
|
@register="useModalData[name][0]"
|
@success="(d, u) => handleEntSuccess(d, u, item.name)"
|
/>
|
</template>
|
</BasicForm>
|
<!-- 自定义内容 -->
|
<div class="h-full" style="height: 380px" v-if="isCustEl[item.name]">
|
<FlowChartView :data="routeData" @init="init" />
|
<RouteViewModal @register="registerRv" @success="RvItemSuccess" />
|
</div>
|
</template>
|
</CustModal>
|
</Suspense>
|
<normalDrawer @register="registerDrawer" @success="handleSuccess" />
|
</div>
|
</template>
|
<script lang="ts" setup>
|
import { Ref, inject, nextTick, onMounted, ref, unref, watch } from 'vue';
|
import { BasicTable, useTable, TableAction, BasicColumn, FormSchema } from '/@/components/Table';
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
import { useDrawer } from '/@/components/Drawer';
|
import GeneralModal from '/@/views/components/GeneralModal.vue';
|
import normalDrawer from '../normalDrawer.vue';
|
import CustModal from '/@/views/components/CustModal.vue';
|
import RouteViewModal from '/@/views/components/RouteViewModal.vue';
|
import { FlowChartView } from '/@/components/FlowChart';
|
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
|
import { useModal } from '/@/components/Modal';
|
import { useGo } from '/@/hooks/web/usePage';
|
import { DeleteEntity, getEntity, getListByPage } from '/@/api/tigerapi/system';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
|
import { getRoleButtons } from '/@/api/sys/menu';
|
import { useUserStore } from '/@/store/modules/user';
|
import { useRouter } from 'vue-router';
|
import { GenerateActionButton, initRoute, OpenCustModal } from '../data';
|
import LogicFlow from '@logicflow/core';
|
import { isFunction } from 'xe-utils';
|
|
const { t } = useI18n();
|
const { currentRoute } = useRouter();
|
const props = defineProps({
|
useTableData: { type: Object as PropType<{}>, default: { table: [] } },
|
crudColSlots: { type: Object as PropType<any> },
|
});
|
const objParams = inject('objParams') as Ref<any>;
|
const colSlots = ref(objParams.value['colSlots']);
|
const _columns = inject('_columns') as Ref<any[]>;
|
const _searchFormSchema = inject('_searchFormSchema') as Ref<any[]>;
|
const _crudFormSchema = inject('_crudFormSchema') as Ref<any[]>;
|
const buttons = ref<[]>(await getRoleButtons(currentRoute.value.meta.menuCode as string));
|
const isExistSql = inject('isExistSql') as Ref<string>;
|
const keyFieldValues = inject('keyFieldValues') as Ref<Recordable[]>;
|
const AuthOption = inject('AuthOption') as Ref<{}>;
|
const entityName = ref(objParams.value['ID']);
|
const go = useGo();
|
const [registerDrawer, { openDrawer }] = useDrawer();
|
const [registerItemAdd, { openModal: openItemModal }] = useModal();
|
const [registerRv, { openModal: openRvModal, closeModal: RvcloseModal }] = useModal();
|
const [registerCust, { openModal: openCustModal }] = useModal();
|
const cType = ref('');
|
const formSchemas = ref({}); //弹出框多表单结构
|
const routeData = ref({
|
nodes: [],
|
edges: [],
|
});
|
const selectVals = ref({});
|
const custImport = ref<any[]>([]);
|
const EntityCustFunction = ref([
|
{
|
ActionItem(params, data, ...args) {},
|
KeyFieldValues(val, id) {},
|
OpenSelectItem(openItemModal: Fn, ...args) {},
|
GetSelectSuccess(d, u, ...args) {},
|
GetUseForm(...args) {},
|
} as EntityCustFunctionType,
|
]);
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
custImport.value = await import(`../entityts/${objParams.value['ID']}.ts`);
|
} catch (e) {}
|
const [
|
{
|
ActionItem: nActionItem,
|
KeyFieldValues,
|
GetUseForm,
|
GetUseModals,
|
GetCustData,
|
OpenSelectItem: OpenSelectCust,
|
GetSelectSuccess,
|
},
|
ActionColumn,
|
] = isNullOrUnDef(custImport.value['default'])
|
? EntityCustFunction.value
|
: custImport.value['default']();
|
|
keyFieldValues.value = isNullOrUnDef(KeyFieldValues)
|
? {}
|
: KeyFieldValues(objParams.value['CODE'], objParams.value['ID']);
|
const dtlSlots = ref<any[]>([]);
|
const useformdata = GetUseForm && isFunction(GetUseForm) ? GetUseForm() : {};
|
const useFormData = ref<any>(useformdata);
|
/* 表单中插槽渲染按钮打开模态框useModal方法 */
|
const modals = GetUseModals && isFunction(GetUseModals) ? GetUseModals() : { useModalData: {} };
|
const useModalData = ref(modals['useModalData']);
|
/* 获取自定义数据 */
|
const custData = GetCustData && isFunction(GetCustData) ? GetCustData() : { isCustEl: {} };
|
const isCustEl = ref(custData['isCustEl']);
|
const [registerTable, { getForm, reload, setProps }] = useTable({
|
title: '列表信息',
|
api: getListByPage,
|
searchInfo: {
|
TABLE_NAME: objParams.value['ID'],
|
option:
|
AuthOption.value['BY_ORG'] == 'Y'
|
? {
|
//根据据点查询,必需带这个参数
|
UserId: useUserStore().getUserInfo.userId,
|
ByOrg: true,
|
CurOrg: useUserStore().getUserInfo.orgCode,
|
}
|
: '',
|
},
|
columns: _columns as unknown as BasicColumn[],
|
formConfig: {
|
labelWidth: 140,
|
schemas: _searchFormSchema as unknown as FormSchema[],
|
},
|
useSearchForm: true,
|
showTableSetting: true,
|
bordered: true,
|
canResize: true,
|
showIndexColumn: false,
|
actionColumn: ActionColumn, //自定义操作列
|
});
|
|
watch(
|
() => AuthOption.value,
|
(newVal, oldVal) => {
|
nextTick(() => {
|
if (!isNullOrEmpty(newVal.BY_ORG)) {
|
setProps({
|
searchInfo: {
|
TABLE_NAME: objParams.value['ID'],
|
option:
|
AuthOption.value['BY_ORG'] == 'Y'
|
? {
|
//根据据点查询,必需带这个参数
|
UserId: useUserStore().getUserInfo.userId,
|
ByOrg: true,
|
CurOrg: useUserStore().getUserInfo.orgCode,
|
}
|
: '',
|
},
|
});
|
reload();
|
}
|
});
|
},
|
{ deep: true, immediate: true },
|
);
|
|
onMounted(() => {});
|
|
const currlf = ref(null) as Ref<LogicFlow | null>;
|
/**
|
* @description: 工艺路线初始化
|
* @param {*} lf
|
* @return {*}
|
*/
|
async function init(lf, rotId) {
|
initRoute(lf, rotId, routeData, currlf);
|
}
|
|
/**
|
* @description: 生成列表中操作项的按钮
|
* @param {*} record
|
* @return {*}
|
*/
|
function createActions(record) {
|
const params = {
|
record,
|
isUpdate: true,
|
entityName: objParams.value['ID'],
|
formJson: _crudFormSchema.value,
|
cType,
|
dtlSlots,
|
formSchemas,
|
useModalData,
|
useFormData,
|
crudColSlots: objParams.value['crudColSlots'],
|
routeData,
|
currlf,
|
selectVals,
|
colSlots,
|
};
|
|
const actionItem = GenerateActionButton(params, buttons, openDrawer, reload);
|
if (isNullOrUnDef(custImport.value['default'])) {
|
return actionItem;
|
}
|
return nActionItem(
|
params,
|
actionItem,
|
openDrawer,
|
reload,
|
null,
|
useForm,
|
useModal,
|
go,
|
setProps,
|
openCustModal,
|
);
|
}
|
|
/**
|
* @description: 获取多表单插槽列表
|
* @param {*} d
|
* @return {*}
|
*/
|
function getdtlSlots(d, callback) {
|
dtlSlots.value = d;
|
callback();
|
// setTimeout(() => {
|
// callback();
|
// }, 100);
|
}
|
|
/**
|
* @description: 获取新增按钮的行为
|
* @return {*}
|
*/
|
function handleCreate(fnName: string) {
|
if (isNullOrUnDef(custImport.value['default'])) {
|
openDrawer(true, {
|
isUpdate: false,
|
entityName: entityName.value,
|
formJson: _crudFormSchema.value,
|
crudColSlots: objParams.value['crudColSlots'],
|
isExistSql: isExistSql.value,
|
});
|
} else {
|
const [{ CreateAction }] = custImport.value['default']();
|
const result = CreateAction(fnName);
|
switch (result.action) {
|
case 'go':
|
// 将对象转换为JSON字符串并保存到sessionStorage
|
sessionStorage.setItem(
|
`${result.params.Name}_params`,
|
encodeURI(JSON.stringify(result.params)),
|
);
|
go(
|
`/${result.url}/${encodeURI(JSON.stringify({ sName: result.params.Name, Name: result.params.Name }))}`,
|
);
|
break;
|
case 'drawer':
|
openDrawer(true, {
|
isUpdate: false,
|
entityName: entityName.value,
|
formJson: _crudFormSchema.value,
|
crudColSlots: objParams.value['crudColSlots'],
|
isExistSql: isExistSql.value,
|
});
|
break;
|
}
|
}
|
}
|
|
/**
|
* @description: 新增编辑返回成功方法
|
* @param {*} d
|
* @param {*} u
|
* @return {*}
|
*/
|
function handleSuccess(d, u) {
|
reload();
|
}
|
|
/**
|
* @description: 弹出选择框选择成功后事件
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleItemSuccess(d, u, item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
|
)
|
.then((m) => {
|
const [{ GetSelectSuccess: GetSelectSuccess2 }] = m.default();
|
getForm().setFieldsValue(GetSelectSuccess2(d, u));
|
})
|
.catch(() => {
|
getForm().setFieldsValue({
|
ITEM_CODE: d.values['val'],
|
});
|
});
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 弹出选择框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleSelectItem(item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(
|
`../entityts/${getForm().getFieldsValue()[`${item.replace(/form-/, '').replace(/add/, '')}PSelect_0`]}.ts`
|
)
|
.then((m) => {
|
const [{ OpenSelectItem }] = m.default();
|
OpenSelectItem(openItemModal);
|
})
|
.catch(() => {
|
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' },
|
});
|
});
|
} catch (e) {}
|
}
|
//弹出框确定返回
|
function custSuccess(d) {
|
reload();
|
}
|
|
/**
|
* @description: 各表单内弹出选择框选择成功后方法
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleEntSuccess(d, u, item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
var values = GetSelectSuccess(d, u);
|
selectVals.value = values; //保存弹出框选择的结果
|
let _val = {};
|
d.returnFieldName.map((x) => {
|
_val[x] = values[x];
|
});
|
useFormData.value[item][1].setFieldsValue(_val);
|
/* 针对工单的方法 */
|
if (d.returnFieldName.filter((x) => x == 'ROUTE_CODE') && item == 'prodinfo' ) {
|
routeData.value = {
|
nodes: [],
|
edges: [],
|
};
|
|
init(currlf, selectVals.value['ROUTE_CODE']);
|
const { transformModel, width, height } = unref(currlf).graphModel;
|
transformModel.focusOn(565, 200, width, height);
|
}
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 打开表单中的模态框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleCustClick(item) {
|
OpenSelectCust(
|
useModalData.value[item][1].openModal, //带入openModal方法
|
item,
|
openRvModal,
|
selectVals,
|
);
|
}
|
|
function RvItemSuccess(d, u) {
|
RvcloseModal();
|
}
|
</script>
|