feat: 表单按钮状态修改

This commit is contained in:
GAOANG
2024-04-24 10:47:28 +08:00
parent 2060e76da9
commit ca7479b889
3 changed files with 107 additions and 5 deletions

View File

@ -497,3 +497,37 @@ export function changeSchemaDisabled(schemas) {
});
return schemas;
}
// 辅助设置表单可以编辑
export function changeSchemaEnable(schemas) {
const layoutComponents = ['tab', 'grid', 'card'];
schemas?.map((info) => {
if (layoutComponents.includes(info.type!)) {
info.children?.map((childInfo) => {
childInfo.list.map((com) => {
if (layoutComponents.includes(com.type)) {
changeSchemaDisabled(childInfo.list);
} else {
com.dynamicDisabled = false;
}
});
});
} else if (info.type == 'table-layout') {
info.children?.map((childInfo) => {
childInfo.list.map((com) => {
com.children.map((el) => {
if (layoutComponents.includes(el.type) || el.type == 'table-layout') {
changeSchemaDisabled(com.children);
} else {
el.dynamicDisabled = false;
}
});
});
});
} else if (info.type == 'one-for-one') {
changeSchemaDisabled(info.componentProps.childSchemas);
} else {
info.dynamicDisabled = false;
}
});
return schemas;
}

View File

@ -1533,7 +1533,19 @@ ${hasTemplatePrint ? ' reactive ' : ''}
actionsList = actionsList.concat(editAndDelBtn);
}
}
return actionsList;
return filterAction(actionsList, record);
}
function filterAction(list, record) {
const result = list.filter((item)=> {
let conditions = item.tooltip !== '查看流转记录'
if (record.workflowData.enabled) {
conditions = conditions && item.tooltip !== '查看'
} else {
conditions = conditions && (item.tooltip === '查看' || item.tooltip === '删除')
}
return conditions
})
return result
}
`
: `

View File

@ -8,12 +8,18 @@
</slot>
关闭
</a-button>
<a-button v-if="mode != 'view'" type="primary" @click="handleSubmit">
<a-button v-for="item in buttonList" type="primary" @click="btnEventHandle(item.code)">
<slot name="icon">
<check-circle-outlined />
</slot>
{{ item.name }}
</a-button>
<!-- <a-button v-if="mode != 'read'" type="primary" @click="handleSubmit">
<slot name="icon">
<check-circle-outlined />
</slot>
确认
</a-button>
</a-button> -->
</a-space>
</div>
<component :is="dynamicComponent" ref="formRef" :fromPage="FromPageType.MENU" @form-mounted="onFormMounted" />
@ -23,13 +29,34 @@
<script setup>
import { useRouter } from 'vue-router';
import { FromPageType } from '/@/enums/workflowEnum';
import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent } from 'vue';
import { ref, computed, onMounted, onBeforeMount, nextTick, defineAsyncComponent, reactive } from 'vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
import { CheckCircleOutlined, StopOutlined, CloseOutlined } from '@ant-design/icons-vue';
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
import useEventBus from '/@/hooks/event/useEventBus';
import { edit } from '../generator/order/api';
// const buttonList = reactive([])
const allButtonList = [
{
"isUse": true,
"name": "编辑",
"code": "edit",
"isDefault": true
},
{
"isUse": true,
"name": "确认",
"code": "submit",
"isDefault": true
}
]
const btnEvent = {
edit: editForm,
submit: handleSubmit,
delete: deleteForm
}
const dynamicComponent = ref(null);
const formType = ref('2'); // 0 新建 1 修改 2 查看
const formRef = ref();
@ -59,11 +86,36 @@ if (hash.indexOf('createForm') > 0) {
} else if (hash.indexOf('viewForm') > 0) {
mode.value = 'view';
}
const type = ref('readonly')
const buttonList = computed(() => {
let buttonArr = []
if (mode.value === 'create') {
buttonArr = allButtonList.filter(item => item.name === '确认')
} else {
if (type.value === 'readonly') {
buttonArr = allButtonList.filter(item => item.name !== '确认')
} else {
buttonArr = allButtonList.filter(item => item.name !== '编辑')
}
}
return buttonArr;
});
dynamicComponent.value = defineAsyncComponent({
loader: () => import(`./../../views/${pathArr[0]}/${pathArr[1]}/components/Form.vue`)
});
function btnEventHandle(code) {
btnEvent[code]()
}
function editForm() {
type.value = 'edit'
setFormType()
}
function deleteForm() {
}
function onFormMounted(_formProps) {
formProps.value = _formProps;
setFormType();
@ -76,7 +128,11 @@ async function setFormType() {
}
await nextTick();
if (_mode === 'view') {
if (type.value === 'readonly') {
await formRef.value.setDisabledForm();
} else {
await formRef.value.setEnabledForm();
}
}
await formRef.value.setFormDataFromId(formId.value);
}