zzq 2024-06-03 16:37:40 +08:00
commit bfa1c35647
5 changed files with 137 additions and 14 deletions

View File

@ -94,7 +94,7 @@
/>
</FormItem>
<FormItem label="脚本" v-if="['Button'].includes(formConfig.currentItem.component)">
<a-button type="primary" size="mini" @click="handleButtonClick"> </a-button>
<a-button size="mini" @click="handleButtonClick"> </a-button>
</FormItem>
<FormItem

View File

@ -76,7 +76,6 @@
<a-space direction="vertical">
<a-button
v-model:value="formConfig.beforeSetData"
type="primary"
size="mini"
@click="handleBtnClick('beforeSetData')"
>
@ -84,7 +83,6 @@
</a-button>
<a-button
v-model:value="formConfig.afterValidateForm"
type="primary"
size="mini"
@click="handleBtnClick('afterValidateForm')"
>
@ -92,7 +90,6 @@
</a-button>
<a-button
v-model:value="formConfig.afterSaveEvent"
type="primary"
size="mini"
@click="handleBtnClick('afterSaveEvent')"
>
@ -100,7 +97,6 @@
</a-button>
<a-button
v-model:value="formConfig.changeDataEvent"
type="primary"
size="mini"
@click="handleBtnClick('changeDataEvent')"
>
@ -209,11 +205,9 @@
}
//
function handleSubmit() {
if (formContent.value.indexOf('=>') != -1) {
//
message.warning('脚本没有更新为最新的版本!');
if (!checkChinese(formContent.value)) {
message.warning('脚本的代码部分不能含有中文字符!');
return;
// } else if() {
}
if (btnClickEvent_now) {
if (btnClickEvent_now == 'beforeSetData') {
@ -228,6 +222,33 @@
}
closeModal();
}
function checkChinese(str) {
//
const lines = str.split('\n');
let flag = true;
//
for (const line of lines) {
// console.log
const consoleIndex = line.indexOf('console.log');
let partToCheck = line;
if (consoleIndex !== -1) {
partToCheck = line.substring(0, consoleIndex).trim(); // console.log
}
// '//'
const commentIndex = partToCheck.indexOf('//');
// '//''//'
partToCheck =
commentIndex !== -1 ? partToCheck.substring(0, commentIndex).trim() : partToCheck;
//
if (!/[\u4e00-\u9fa5]/.test(partToCheck)) {
flag = false;
}
}
return flag;
}
</script>
<style scoped>

View File

@ -14,7 +14,12 @@
<template v-if="tabsColumns.length > 1">
<a-tabs style="width: 100%" @change="tabsChange">
<a-tab-pane v-for="(colItem, index) in tabsColumns" :tab="colItem.label" :key="index">
<BasicForm ref="myDataBaseFormRef" @register="registerForm" />
<BasicForm
ref="myDataBaseFormRef"
@register="registerForm"
@click="codeClickFunction('beforeSetData', beforeSetData)"
@change="codeClickFunction('changeDataEvent', changeDataEvent)"
/>
</a-tab-pane>
</a-tabs>
</template>
@ -23,6 +28,8 @@
ref="myDataBaseFormRef"
@register="registerForm"
v-if="formModalVisible && tabsColumns.length < 1"
@click="codeClickFunction('beforeSetData', beforeSetData)"
@change="codeClickFunction('changeDataEvent', changeDataEvent)"
/>
<template v-for="(item, index) in cardLayout" :key="index">
<a-row style="width: 100%">
@ -44,6 +51,20 @@
</a-col>
</a-row>
</template>
<template v-for="(item, index) in buttonLayout" :key="index">
<a-row style="width: 100%">
<a-col :span="item?.colProps?.span || 24" style="padding: 10px">
<a-button
:type="item.componentProps.type"
:shape="item.componentProps.shape"
:size="item.componentProps.size"
@click="codeClickFunction('codeClick', item.componentProps.clickCode)"
>
{{ item.label }}
</a-button>
</a-col>
</a-row>
</template>
<a-table
class="sub-table"
:columns="subTableColumns"
@ -86,6 +107,7 @@
import { v4 as uuidv4 } from 'uuid';
import FormItem from './ShowFormModal/FormItem/index.vue';
import CallModalFormItem from './CallModalFormItem/index.vue';
// import FormRender from '@/views/demo/form-design/components/VFormCreate/components/FormRender.vue';
const emit = defineEmits(['success']);
@ -112,8 +134,21 @@
const scrollValue = ref();
const cardLayout = ref([]);
const createOrModifyList = ref([]);
//
const buttonLayout = ref([]);
//
const beforeSetData = ref('');
const afterValidateForm = ref('');
const afterSaveEvent = ref('');
const changeDataEvent = ref('');
const [registerModal, { setModalProps, closeModal }] = useModalInner((data: any) => {
console.log('daaaaa', data);
//
beforeSetData.value = data?.beforeSetData;
afterValidateForm.value = data?.afterValidateForm;
afterSaveEvent.value = data?.afterSaveEvent;
changeDataEvent.value = data?.changeDataEvent;
isUpdate.value = !!data?.isUpdate;
isDetail.value = !!data?.isDetail;
const arr: FormSchema[] = [];
@ -133,6 +168,9 @@
if (opt.component === 'Card') {
cardLayout.value.push(opt);
}
if (opt.component === 'Button') {
buttonLayout.value.push(opt);
}
if (['createuser', 'createtime', 'modifyuser', 'modifytime'].includes(opt.type)) {
createOrModifyList.value.push(opt);
}
@ -203,6 +241,9 @@
if (item.component === 'Card') {
cardLayout.value.push(item);
}
if (item.component === 'Button') {
buttonLayout.value.push(item);
}
if (['createuser', 'createtime', 'modifyuser', 'modifytime'].includes(item.type)) {
createOrModifyList.value.push(item);
}
@ -349,6 +390,8 @@
async function ModalSureClick() {
try {
const values = await validate();
//
codeClickFunction('afterValidateForm', afterValidateForm.value);
console.log('values', values);
let query = values;
let saveSubTableList = [];
@ -397,6 +440,9 @@
}
} finally {
setModalProps({ confirmLoading: false });
//
codeClickFunction('afterSaveEvent', afterSaveEvent.value);
closeFunc();
}
}
async function handleCreateFlow(processId) {
@ -420,7 +466,37 @@
return createMessage.error('保存草稿失败');
}
}
//
async function codeClickFunction(code, codeClick) {
try {
// utils
const { utils } = await import('./utils');
eval(codeClick);
} catch (e) {
switch (code) {
case 'codeClick':
createMessage.success('【按钮组件脚本】错误:' + e);
break;
case 'beforeSetData':
createMessage.success('【添加赋值前脚本】错误:' + e);
break;
case 'afterValidateForm':
createMessage.success('【添加校验后脚本】错误:' + e);
break;
case 'afterSaveEvent':
createMessage.success('【添加保存后脚本】错误:' + e);
break;
case 'changeDataEvent':
createMessage.success('【添加数据改变脚本】错误:' + e);
break;
default:
createMessage.success('【未知脚本】错误:' + e);
break;
}
}
}
const closeFunc = () => {
buttonLayout.value = [];
cardLayout.value = [];
createOrModifyList.value = [];
return true;

View File

@ -320,7 +320,7 @@
let chlidKey: any = ref();
if (val.type === 'chlid') {
getOutKeyList(params).then((res: Recordable) => {
console.log('ressss', res)
console.log('ressss', res);
if (res[0]) {
res[0].db_codecolumnsList.forEach((item) => {
if (item.isPrimaryKey == 1) {
@ -331,9 +331,9 @@
});
}
setTimeout(() => {
console.log('chlidKey', chlidKey.value)
console.log('chlidKey', chlidKey.value);
}, 500);
if (rel.formInfo.schemas.length > 1) {
rel.formInfo.schemas.forEach((item) => {
if (
@ -407,6 +407,10 @@
},
activeKey: 1,
status: 'Add',
beforeSetData: '',
afterValidateForm: '',
afterSaveEvent: '',
changeDataEvent: '',
});
const handleClickForm = (status) => {
@ -430,7 +434,7 @@
if (rows.length > 0) {
query.value.keyValue = rows[0][str.value];
}
console.log('config', config)
console.log('config', config);
switch (status) {
case 'Add':
btnList.value.forEach((element) => {
@ -447,6 +451,10 @@
query: query.value,
addParams: addParamsArr.value,
btnList: btnList.value,
beforeSetData: config.beforeSetData,
afterValidateForm: config.afterValidateForm,
afterSaveEvent: config.afterSaveEvent,
changeDataEvent: config.changeDataEvent,
};
if (haveMap.value) {
showFormModalData.value = toProps;
@ -481,6 +489,10 @@
recordChildren: formData.value,
query: query.value,
btnList: btnList.value,
beforeSetData: config.beforeSetData,
afterValidateForm: config.afterValidateForm,
afterSaveEvent: config.afterSaveEvent,
changeDataEvent: config.changeDataEvent,
};
if (haveMap.value) {
showFormModalData.value = toProps;
@ -649,6 +661,11 @@
unref(asyncExpandTreeRef)?.expandAll(true);
});
formConfig.value.schemas = formObj.formInfo.schemas;
//
formConfig.value.beforeSetData = formObj.formInfo.beforeSetData;
formConfig.value.afterValidateForm = formObj.formInfo.afterValidateForm;
formConfig.value.afterSaveEvent = formObj.formInfo.afterSaveEvent;
formConfig.value.changeDataEvent = formObj.formInfo.changeDataEvent;
});
}
//

View File

@ -0,0 +1,9 @@
// utils.ts
export const utils = {
add: function add(a: number, b: number): number {
return a + b;
},
subtract: function subtract(a: number, b: number): number {
return a - b;
},
};