2023-01-18 16:23:39 +08:00
|
|
|
<template>
|
|
|
|
<div>
|
2024-04-22 23:08:40 +08:00
|
|
|
<n-modal
|
|
|
|
v-model:show="showModal"
|
|
|
|
:mask-closable="false"
|
|
|
|
:show-icon="false"
|
|
|
|
preset="dialog"
|
|
|
|
transform-origin="center"
|
|
|
|
:title="formValue.@{.pk.TsName} > 0 ? '编辑@{.tableComment} #' + formValue.@{.pk.TsName} : '添加@{.tableComment}'"
|
|
|
|
:style="{
|
|
|
|
width: dialogWidth,
|
|
|
|
}"
|
|
|
|
>
|
|
|
|
<n-scrollbar style="max-height: 87vh" class="pr-5">
|
|
|
|
<n-spin :show="loading" description="请稍候...">
|
2023-12-29 20:08:00 +08:00
|
|
|
<n-form
|
|
|
|
ref="formRef"
|
2024-04-22 23:08:40 +08:00
|
|
|
:model="formValue"
|
|
|
|
@{ if eq .options.Step.HasRules true }:rules="rules"@{end}
|
2023-12-29 20:08:00 +08:00
|
|
|
:label-placement="settingStore.isMobile ? 'top' : 'left'"
|
|
|
|
:label-width="100"
|
|
|
|
class="py-4"
|
|
|
|
>
|
2024-04-22 23:08:40 +08:00
|
|
|
<n-grid cols="1 s:1 m:@{.options.PresetStep.FormGridCols} l:@{.options.PresetStep.FormGridCols} xl:@{.options.PresetStep.FormGridCols} 2xl:@{.options.PresetStep.FormGridCols}" responsive="screen">
|
|
|
|
@{.formItem}
|
|
|
|
</n-grid>
|
2023-12-29 20:08:00 +08:00
|
|
|
</n-form>
|
2024-04-22 23:08:40 +08:00
|
|
|
</n-spin>
|
|
|
|
</n-scrollbar>
|
|
|
|
<template #action>
|
|
|
|
<n-space>
|
|
|
|
<n-button @click="closeForm"> 取消 </n-button>
|
|
|
|
<n-button type="info" :loading="formBtnLoading" @click="confirmForm"> 确定 </n-button>
|
|
|
|
</n-space>
|
|
|
|
</template>
|
|
|
|
</n-modal>
|
2023-01-18 16:23:39 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2024-04-22 23:08:40 +08:00
|
|
|
@{.script.import} import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
2023-01-18 16:23:39 +08:00
|
|
|
import { useMessage } from 'naive-ui';
|
|
|
|
import { adaModalWidth } from '@/utils/hotgo';
|
|
|
|
|
2023-12-29 20:08:00 +08:00
|
|
|
const emit = defineEmits(['reloadTable']);
|
2023-01-18 16:23:39 +08:00
|
|
|
const message = useMessage();
|
2023-12-29 20:08:00 +08:00
|
|
|
const settingStore = useProjectSettingStore();
|
|
|
|
const loading = ref(false);
|
|
|
|
const showModal = ref(false);
|
|
|
|
const formValue = ref<State>(newState(null));
|
|
|
|
const formRef = ref<any>({});
|
2023-01-18 16:23:39 +08:00
|
|
|
const formBtnLoading = ref(false);
|
2024-04-22 23:08:40 +08:00
|
|
|
const dialogWidth = computed(() => {
|
|
|
|
return adaModalWidth(840);
|
|
|
|
});
|
|
|
|
|
|
|
|
function openModal(state: State) {
|
|
|
|
showModal.value = true;
|
|
|
|
@{ if eq .options.Step.IsTreeTable true }
|
|
|
|
// 加载关系树选项
|
|
|
|
loadTreeOption();
|
|
|
|
@{end}
|
|
|
|
// 新增
|
|
|
|
if (!state || state.@{.pk.TsName} < 1) {
|
|
|
|
formValue.value = newState(state);
|
|
|
|
@{ if eq .options.Step.HasMaxSort true }
|
|
|
|
loading.value = true;
|
|
|
|
MaxSort()
|
|
|
|
.then((res) => {
|
|
|
|
formValue.value.sort = res.sort;
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});@{end}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 编辑
|
|
|
|
loading.value = true;
|
|
|
|
View({ @{.pk.TsName}: state.@{.pk.TsName} })
|
|
|
|
.then((res) => {
|
|
|
|
formValue.value = res;
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
loading.value = false;
|
|
|
|
});
|
|
|
|
}
|
2023-01-18 16:23:39 +08:00
|
|
|
|
|
|
|
function confirmForm(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
formBtnLoading.value = true;
|
|
|
|
formRef.value.validate((errors) => {
|
|
|
|
if (!errors) {
|
2023-12-29 20:08:00 +08:00
|
|
|
Edit(formValue.value).then((_res) => {
|
2023-01-18 16:23:39 +08:00
|
|
|
message.success('操作成功');
|
|
|
|
setTimeout(() => {
|
2024-04-22 23:08:40 +08:00
|
|
|
closeForm();
|
2023-01-18 16:23:39 +08:00
|
|
|
emit('reloadTable');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
message.error('请填写完整信息');
|
|
|
|
}
|
|
|
|
formBtnLoading.value = false;
|
2024-04-10 14:07:20 +08:00
|
|
|
loading.value = false;
|
2023-01-18 16:23:39 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeForm() {
|
2023-12-29 20:08:00 +08:00
|
|
|
showModal.value = false;
|
|
|
|
loading.value = false;
|
2023-01-18 16:23:39 +08:00
|
|
|
}
|
|
|
|
|
2023-12-29 20:08:00 +08:00
|
|
|
defineExpose({
|
|
|
|
openModal,
|
|
|
|
});
|
2023-01-18 16:23:39 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less"></style>
|
2024-04-22 23:08:40 +08:00
|
|
|
|