fix: 模态弹窗函数优化
This commit is contained in:
parent
217b020344
commit
21199a3d3a
|
|
@ -3,8 +3,8 @@
|
||||||
:maskClosable="false"
|
:maskClosable="false"
|
||||||
width="650px"
|
width="650px"
|
||||||
destroyOnClose
|
destroyOnClose
|
||||||
v-model:visible="visible"
|
visible
|
||||||
:title="props.title"
|
:title="props.data?.id ? '编辑' : '新增'"
|
||||||
@ok="handleSave"
|
@ok="handleSave"
|
||||||
@cancel="handleCancel"
|
@cancel="handleCancel"
|
||||||
okText="确定"
|
okText="确定"
|
||||||
|
|
@ -39,31 +39,23 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { saveRule , modify } from '@/api/rule-engine/instance';
|
import { saveRule, modify } from '@/api/rule-engine/instance';
|
||||||
import { getImage } from '@/utils/comm';
|
import { getImage } from '@/utils/comm';
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
const emit = defineEmits(['success']);
|
const emit = defineEmits(['success', 'closeSave']);
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
title: {
|
data: {
|
||||||
type: String,
|
type: Object,
|
||||||
default: '',
|
|
||||||
},
|
},
|
||||||
isAdd: {
|
|
||||||
type: Number,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const productList = ref<Record<string, any>[]>([]);
|
|
||||||
const loading = ref<boolean>(false);
|
|
||||||
const visible = ref<boolean>(false);
|
|
||||||
const formRef = ref();
|
|
||||||
let id = ref<string>();
|
|
||||||
const modelRef = reactive({
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const productList = ref<Record<string, any>[]>([]);
|
||||||
|
const loading = ref<boolean>(false);
|
||||||
|
const formRef = ref();
|
||||||
|
let id = ref<string>();
|
||||||
|
const modelRef = ref();
|
||||||
|
modelRef.value = props.data
|
||||||
const rules = {
|
const rules = {
|
||||||
name: [
|
name: [
|
||||||
{
|
{
|
||||||
|
|
@ -76,15 +68,8 @@ const rules = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.isAdd,
|
|
||||||
() => {},
|
|
||||||
{ immediate: true, deep: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
visible.value = false;
|
emit('closeSave');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
|
@ -92,26 +77,24 @@ const handleSave = () => {
|
||||||
.validate()
|
.validate()
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
if (props.isAdd === 1) {
|
if (!modelRef.value?.id) {
|
||||||
let resp = await saveRule(modelRef);
|
let resp = await saveRule(modelRef.value);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
message.success('操作成功!');
|
message.success('操作成功!');
|
||||||
|
emit('closeSave');
|
||||||
emit('success');
|
emit('success');
|
||||||
formRef.value.resetFields();
|
} else {
|
||||||
visible.value = false;
|
message.error('操作失败');
|
||||||
}else{
|
|
||||||
message.error('操作失败')
|
|
||||||
}
|
}
|
||||||
}else if(props.isAdd === 2) {
|
} else {
|
||||||
let resp = await modify(id,modelRef);
|
let resp = await modify(modelRef.value?.id, modelRef.value);
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
if (resp.status === 200) {
|
if (resp.status === 200) {
|
||||||
message.success('操作成功!');
|
message.success('操作成功!');
|
||||||
|
emit('closeSave');
|
||||||
emit('success');
|
emit('success');
|
||||||
formRef.value.resetFields();
|
} else {
|
||||||
visible.value = false;
|
|
||||||
}else{
|
|
||||||
message.error('操作失败!');
|
message.error('操作失败!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,19 +103,4 @@ const handleSave = () => {
|
||||||
console.log('error', err);
|
console.log('error', err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const show = (data: any) => {
|
|
||||||
if (props.isAdd === 1) {
|
|
||||||
modelRef.name = '';
|
|
||||||
modelRef.description = '';
|
|
||||||
} else if (props.isAdd === 2) {
|
|
||||||
modelRef.name = data?.name;
|
|
||||||
modelRef.description = data?.description;
|
|
||||||
id = data.id
|
|
||||||
}
|
|
||||||
visible.value = true;
|
|
||||||
};
|
|
||||||
defineExpose({
|
|
||||||
show: show,
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -127,17 +127,16 @@
|
||||||
</JProTable>
|
</JProTable>
|
||||||
<!-- 新增、编辑 -->
|
<!-- 新增、编辑 -->
|
||||||
<Save
|
<Save
|
||||||
ref="saveRef"
|
:data="current"
|
||||||
:isAdd="isAdd"
|
|
||||||
:title="title"
|
|
||||||
@success="refresh"
|
@success="refresh"
|
||||||
|
v-if="visiable"
|
||||||
|
@close-save="closeSave"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</page-container>
|
</page-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import JTable from '@/components/Table';
|
|
||||||
import type { InstanceItem } from './typings';
|
import type { InstanceItem } from './typings';
|
||||||
import {
|
import {
|
||||||
queryList,
|
queryList,
|
||||||
|
|
@ -151,10 +150,7 @@ import { message } from 'ant-design-vue';
|
||||||
import Save from './Save/index.vue';
|
import Save from './Save/index.vue';
|
||||||
import { SystemConst } from '@/utils/consts';
|
import { SystemConst } from '@/utils/consts';
|
||||||
const params = ref<Record<string, any>>({});
|
const params = ref<Record<string, any>>({});
|
||||||
let isAdd = ref<number>(0);
|
let visiable = ref(false);
|
||||||
let title = ref<string>('');
|
|
||||||
let saveRef = ref();
|
|
||||||
let currentForm = ref();
|
|
||||||
const tableRef = ref<Record<string, any>>({});
|
const tableRef = ref<Record<string, any>>({});
|
||||||
const query = {
|
const query = {
|
||||||
columns: [
|
columns: [
|
||||||
|
|
@ -219,6 +215,7 @@ const columns = [
|
||||||
scopedSlots: true,
|
scopedSlots: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
const current = ref();
|
||||||
const getActions = (
|
const getActions = (
|
||||||
data: Partial<Record<string, any>>,
|
data: Partial<Record<string, any>>,
|
||||||
type?: 'card' | 'table',
|
type?: 'card' | 'table',
|
||||||
|
|
@ -236,11 +233,8 @@ const getActions = (
|
||||||
|
|
||||||
icon: 'EditOutlined',
|
icon: 'EditOutlined',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
title.value = '编辑';
|
current.value = data;
|
||||||
isAdd.value = 2;
|
visiable.value = true;
|
||||||
nextTick(() => {
|
|
||||||
saveRef.value.show(data);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -309,11 +303,11 @@ const getActions = (
|
||||||
return actions;
|
return actions;
|
||||||
};
|
};
|
||||||
const add = () => {
|
const add = () => {
|
||||||
isAdd.value = 1;
|
current.value = {
|
||||||
title.value = '新增';
|
name:'',
|
||||||
nextTick(() => {
|
description:''
|
||||||
saveRef.value.show(currentForm.value);
|
},
|
||||||
});
|
visiable.value = true
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* 刷新数据
|
* 刷新数据
|
||||||
|
|
@ -329,6 +323,9 @@ const openRuleEditor = (item: any) => {
|
||||||
`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${item.id}`,
|
`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${item.id}`,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
const closeSave = () =>{
|
||||||
|
visiable.value = false;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
</style>
|
</style>
|
||||||
Loading…
Reference in New Issue