<!--
|
* @Description: file content
|
* @Author: Ben Lin
|
* @version:
|
* @Date: 2024-06-24 23:44:31
|
* @LastEditors: Ben Lin
|
* @LastEditTime: 2024-07-23 20:48:29
|
-->
|
<template>
|
<Card :title="GetTitle(props.configType)['configTitle']">
|
<BasicForm @register="registerForm">
|
<template #[item]="{ field }" v-for="item in GetCrudColSlots()" :key="item">
|
<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>
|
</BasicForm>
|
</Card>
|
</template>
|
<script lang="ts" setup>
|
import { Ref, inject, nextTick, onMounted, ref, unref, watch } from 'vue';
|
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
import { Card } from 'ant-design-vue';
|
import { useModal } from '/@/components/Modal';
|
import GeneralModal from '/@/views/components/GeneralModal.vue';
|
import { useI18n } from '/@/hooks/web/useI18n';
|
import { isNullOrUnDef } from '/@/utils/is';
|
import { EntityCustFunctionType } from '/@/api/tigerapi/model/basModel';
|
|
const { t } = useI18n();
|
const emit = defineEmits(['success', 'register']);
|
const props = defineProps({
|
configType: { type: String },
|
});
|
const [registerItemAdd, { openModal: openItemModal }] = useModal();
|
const objParams = inject('objParams') as Ref<any>;
|
const custImport = ref<any[]>([]);
|
const EntityCustFunction = ref([
|
{
|
GetCrudForm(type: string | undefined) {},
|
GetCrudColSlots(val, id) {},
|
OpenSelectItem(openItemModal: Fn, ...args) {},
|
GetSelectSuccess(d, u, ...args) {},
|
GetTitle(type: string | undefined) {},
|
nodeChange(params: {
|
resetFields: any;
|
setFieldsValue: any;
|
objParams: Ref<any>;
|
selectedNodes: Ref<any[]>;
|
}) {},
|
SubmitFunc(values: Recordable<any>, type: string, emit) {},
|
} as EntityCustFunctionType,
|
]);
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
custImport.value = await import(`../entityts/${objParams.value['Name']}.ts`);
|
} catch (e) {}
|
const [
|
{
|
GetCrudForm,
|
GetCrudColSlots,
|
nodeChange,
|
OpenSelectItem,
|
GetSelectSuccess,
|
GetTitle,
|
SubmitFunc,
|
},
|
] = isNullOrUnDef(custImport.value['default'])
|
? EntityCustFunction.value
|
: custImport.value['default']();
|
|
let formSchema: FormSchema[] = GetCrudForm(props.configType);
|
const [registerForm, { resetFields, setFieldsValue, validate, setProps }] = useForm({
|
labelWidth: 120,
|
schemas: formSchema,
|
actionColOptions: {
|
offset: 8,
|
span: 24,
|
},
|
wrapperCol: {
|
span: 15,
|
},
|
showActionButtonGroup: true,
|
submitButtonOptions: {
|
text: '保存',
|
},
|
submitFunc: customSubmitFunc,
|
});
|
|
/* 注入选中节点数据 */
|
const selectedNodes = inject('selectedNodes') as Ref<any>;
|
watch(
|
() => selectedNodes.value,
|
(newVal, oldVal) => {
|
nextTick(() => {
|
/* 节点切换事件 */
|
nodeChange({ resetFields, setFieldsValue, objParams, selectedNodes });
|
formSchema = GetCrudForm(selectedNodes.value[0].type);
|
setProps({
|
schemas: []
|
});
|
setProps({
|
schemas: formSchema
|
});
|
});
|
},
|
{ deep: true, immediate: true },
|
);
|
|
onMounted(() => {
|
/* 节点切换事件 */
|
nodeChange({ resetFields, setFieldsValue, objParams, selectedNodes });
|
});
|
|
async function customSubmitFunc() {
|
try {
|
const values = await validate();
|
SubmitFunc(values,props.configType, emit);
|
// values.AUTH_PROD = useUserStore().getUserInfo.prodCode;
|
// values.FACTORY = useUserStore().getUserInfo.prodCode;
|
// const apiAction = SaveEntity(values, true, 'MES_PROD_ACTION');
|
// apiAction.then((action) => {
|
// if (action.IsSuccessed) {
|
// emit('success');
|
// }
|
// });
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 点击打开弹出选择列表框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleSelectItem(item) {
|
OpenSelectItem(openItemModal, item);
|
}
|
|
/**
|
* @description: 弹出选择框选择成功后返回
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleItemSuccess(d, u, item) {
|
setFieldsValue(GetSelectSuccess(d, u, item));
|
}
|
</script>
|