表单设置bug修复

szh-new
lijingjia 7 months ago
parent de04f9144a
commit bc08b4917a

@ -212,22 +212,21 @@ export function useFormEvents({
return return
} }
const schema: FormSchema[] = [] const schema: FormSchema[] = []
unref(getSchema).forEach((val) => { updateData.forEach((item) => {
let _val let _val
updateData.forEach((item) => { unref(getSchema).forEach((val) => {
if (val.field === item.field) { if (item.field === val.field) {
_val = item _val = val
} }
}) })
if (_val !== undefined && val.field === _val.field) { if (_val !== undefined && item.field === _val.field) {
const newSchema = deepMerge(val, _val) const newSchema = deepMerge(_val, item)
schema.push(newSchema as FormSchema) schema.push(newSchema as FormSchema)
} else { } else {
schema.push(val) schema.push(_val)
} }
}) })
_setDefaultValue(schema) _setDefaultValue(schema)
schemaRef.value = uniqBy(schema, 'field') schemaRef.value = uniqBy(schema, 'field')
} }

@ -134,7 +134,7 @@
display: flex; display: flex;
height: 95%; height: 95%;
align-items: center; align-items: center;
justify-content: center;
> span { > span {
margin-left: 48px; margin-left: 48px;
font-size: 16px; font-size: 16px;

@ -0,0 +1,39 @@
/*
* @Description: hook
* @Author: lijj
* @Date: 2024-04-24 10:50:17
*/
// 获取表单更改过的字段接口
import { getFormSetInfoByModule } from '/@/views/baseinfo/formset/api'
// 接口
import { getColumnSetInfoByModule } from '/@/views/baseinfo/columnset/api'
// 引入表格权限信息包含id和name
import { permissionsInfo } from '/@/hooks/web/usePermission'
/**
* @description:
* @param {*} updateSchema (vben)
*/
export function updateFormField(updateSchema) {
getFormSetInfoByModule({ permissionId: permissionsInfo().permissionId }).then(res => {
if (res?.data?.content) {
const content = JSON.parse(res.data.content)
updateSchema(content.columns)
}
})
}
/**
* @description:
* @param {*} setColumns
*/
export function updateTableField(setColumns) {
getColumnSetInfoByModule({ permissionId: permissionsInfo().permissionId }).then(res => {
const { data } = res
if (data?.content) {
const txt = JSON.parse(data?.content)
setColumns(txt.columns)
}
})
}

@ -65,12 +65,11 @@
// //
import TableSet from './components/tableSet.vue' import TableSet from './components/tableSet.vue'
// //
import { getColumnSetList, editColumnSet, getColumnSetInfoByModule } from './api' import { getColumnSetList, editColumnSet } from './api'
// //
import { columns, searchFormSchema } from './columns' import { columns, searchFormSchema } from './columns'
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue'
// idname import { updateTableField } from '/@/hooks/component/costomForm'
import { permissionsInfo } from '/@/hooks/web/usePermission'
// //
const TableSetRef = ref() const TableSetRef = ref()
// boolean // boolean
@ -104,17 +103,11 @@
} }
const colData = ref({}) const colData = ref({})
provide('colData', colData) provide('colData', colData)
const [registerTable, { getForm, getPaginationRef, setColumns }] = useTable({ const [registerTable, { getForm, getPaginationRef, setColumns }] = useTable({
title: '可设置列表', title: '可设置列表',
api: async (p) => { api: async (p) => {
// //
getColumnSetInfoByModule({ permissionId: permissionsInfo().permissionId }).then(res => { updateTableField(setColumns)
const { data } = res
if (data?.content) {
const txt = JSON.parse(data?.content)
setColumns(txt.columns)
}
})
const res: API.DataResult = await getColumnSetList(p) const res: API.DataResult = await getColumnSetList(p)
return new Promise((resolve) => { return new Promise((resolve) => {
resolve({ data: [...res.data], total: res.count }) resolve({ data: [...res.data], total: res.count })

@ -1,3 +1,8 @@
<!--
* @Description:
* @Author: lijj
* @Date: 2024-04-22 09:04:38
-->
<template> <template>
<BasicModal <BasicModal
:use-wrapper="true" :use-wrapper="true"
@ -6,8 +11,7 @@
@register="registerModal" @register="registerModal"
@ok="handleSave" @ok="handleSave"
> >
{{ $attrs }} <ds-form v-if="getVisible" ref="FormDragRef" :content="content" />
<ds-form ref="FormDragRef" :content="content" />
<!--右下角按钮--> <!--右下角按钮-->
<template #footer> <template #footer>
<a-button <a-button
@ -48,17 +52,16 @@
// Emits // Emits
const emit = defineEmits(['success', 'register']) const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true) const isUpdate = ref(true)
const loading = ref(false)
const rowId = ref('') const rowId = ref('')
const content = ref({}) const content = ref({})
var postData = {} var postData = {}
const FormDragRef = ref() const FormDragRef = ref()
const { createMessage } = useMessage() const { createMessage } = useMessage()
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { const [registerModal, { setModalProps, closeModal, getVisible }] = useModalInner(async (data) => {
setModalProps({ confirmLoading: false, loading: true }) setModalProps({ confirmLoading: false, loading: true })
isUpdate.value = !!data?.isUpdate isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) { if (unref(isUpdate)) {
// setModalProps({ confirmLoading: true }); setModalProps({ confirmLoading: true });
rowId.value = data.record.id rowId.value = data.record.id
const res: API.DataResult = await getCodeGoodsTypeInfo({ id: unref(rowId) }) const res: API.DataResult = await getCodeGoodsTypeInfo({ id: unref(rowId) })
if (res.succeeded) { if (res.succeeded) {
@ -87,37 +90,6 @@
setModalProps({ confirmLoading: false, loading: false }) setModalProps({ confirmLoading: false, loading: false })
}) })
} }
// try {
// const values = await validate()
// console.log(values,111)
// setModalProps({ confirmLoading: true, loading: true })
// // TODO custom api
// console.log(values)
// // loading.value = true;
// const res: API.DataResult = await editCodeGoodsType(values)
// console.log(res)
// if (res.succeeded) {
// createMessage.success(res.message)
// emit('success')
// //
// if (!exit) {
// if (unref(isUpdate)) {
// await refresh()
// } else {
// rowId.value = res.data
// isUpdate.value = true
// await refresh()
// }
// }
// } else {
// createMessage.error(res.message)
// }
// ModalType.value = false
// exit && closeModal()
// } finally {
// // loading.value = false;
// setModalProps({ confirmLoading: false, loading: false })
// }
} }
async function refresh() { async function refresh() {
const res: API.DataResult = await getCodeGoodsTypeInfo({ id: unref(rowId) }) const res: API.DataResult = await getCodeGoodsTypeInfo({ id: unref(rowId) })

@ -177,11 +177,19 @@ import { FormSchema } from '/@/components/Table'
} }
// //
const validate = async () => { const validate = async () => {
const list = JSON.parse(JSON.stringify(formItems.list))
if (list && list.length) {
list.forEach(item => {
if (item?.options) {
delete item.options
}
})
}
if (!formDisable.value) { if (!formDisable.value) {
const flag = await new Promise((resolve) => { const flag = await new Promise((resolve) => {
form.value.validate() form.value.validate()
.then(() => { .then(() => {
return resolve(formItems.list) return resolve(list)
}) })
.catch(() => { .catch(() => {
return resolve(false) return resolve(false)
@ -189,7 +197,7 @@ import { FormSchema } from '/@/components/Table'
}) })
return flag return flag
} else { } else {
return formItems.list return list
} }
} }
watch( watch(

@ -3,6 +3,7 @@
v-bind="$attrs" v-bind="$attrs"
:use-wrapper="true" :use-wrapper="true"
:title="getTitle" :title="getTitle"
:form-schema="formSchema"
width="30%" width="30%"
@register="registerModal" @register="registerModal"
@ok="handleSave" @ok="handleSave"
@ -44,13 +45,14 @@
import { formSchema } from './columns' import { formSchema } from './columns'
import { ApiEdit, ApiInfo } from './api' import { ApiEdit, ApiInfo } from './api'
import { useMessage } from '/@/hooks/web/useMessage' import { useMessage } from '/@/hooks/web/useMessage'
import { updateFormField } from '/@/hooks/component/costomForm'
// Emits // Emits
const emit = defineEmits(['success', 'register']) const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true) const isUpdate = ref(true)
const loading = ref(false) const loading = ref(false)
const rowId = ref('') const rowId = ref('')
const { createMessage } = useMessage() const { createMessage } = useMessage()
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({ const [registerForm, { resetFields, setFieldsValue, validate, updateSchema }] = useForm({
labelWidth: 100, labelWidth: 100,
schemas: formSchema, schemas: formSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
@ -62,6 +64,7 @@
isUpdate.value = !!data?.isUpdate isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) { if (unref(isUpdate)) {
// setModalProps({ confirmLoading: true }); // setModalProps({ confirmLoading: true });
updateFormField(updateSchema)
rowId.value = data.record.id rowId.value = data.record.id
const res: API.DataResult = await ApiInfo({ id: unref(rowId) }) const res: API.DataResult = await ApiInfo({ id: unref(rowId) })
if (res.succeeded) { if (res.succeeded) {

Loading…
Cancel
Save