-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
520 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference path="../global.d.ts"/> | ||
|
||
/* 字典数据库表字段 */ | ||
namespace Entity { | ||
|
||
interface Dict { | ||
id?: number | ||
pid?: number | ||
dictLabel?: string | ||
dictValue?: number | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<script setup lang="ts"> | ||
import { useBoolean } from '@/hooks' | ||
interface Props { | ||
modalName?: string | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
modalName: '', | ||
}) | ||
const emit = defineEmits<{ | ||
open: [] | ||
close: [] | ||
}>() | ||
const { bool: modalVisible, setTrue: showModal, setFalse: hiddenModal } = useBoolean(false) | ||
const { bool: submitLoading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false) | ||
const formDefault: Entity.Dict = { | ||
dictLabel: '', | ||
dictValue: -1, | ||
} | ||
const formModel = ref<Entity.Dict>({ ...formDefault }) | ||
type ModalType = 'add' | 'view' | 'edit' | ||
const modalType = shallowRef<ModalType>('add') | ||
const modalTitle = computed(() => { | ||
const titleMap: Record<ModalType, string> = { | ||
add: '添加', | ||
view: '查看', | ||
edit: '编辑', | ||
} | ||
return `${titleMap[modalType.value]}${props.modalName}` | ||
}) | ||
async function openModal(type: ModalType = 'add', data: any) { | ||
emit('open') | ||
modalType.value = type | ||
showModal() | ||
const handlers = { | ||
async add() { | ||
formModel.value = { ...formDefault } | ||
}, | ||
async view() { | ||
if (!data) | ||
return | ||
formModel.value = { ...data } | ||
}, | ||
async edit() { | ||
if (!data) | ||
return | ||
formModel.value = { ...data } | ||
}, | ||
} | ||
await handlers[type]() | ||
} | ||
function closeModal() { | ||
hiddenModal() | ||
endLoading() | ||
emit('close') | ||
} | ||
defineExpose({ | ||
openModal, | ||
}) | ||
const formRef = ref() | ||
async function submitModal() { | ||
const handlers = { | ||
async add() { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
window.$message.success('模拟新增成功') | ||
resolve(true) | ||
}, 2000) | ||
}) | ||
}, | ||
async edit() { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
window.$message.success('模拟编辑成功') | ||
resolve(true) | ||
}, 2000) | ||
}) | ||
}, | ||
async view() { | ||
return true | ||
}, | ||
} | ||
await formRef.value?.validate() | ||
startLoading() | ||
await handlers[modalType.value]() && closeModal() | ||
} | ||
const rules = { | ||
dictLabel: { | ||
required: true, | ||
message: '请输入字典名称', | ||
trigger: 'blur', | ||
}, | ||
aaa: { | ||
required: true, | ||
message: '请输入字典值', | ||
trigger: 'blur', | ||
}, | ||
} | ||
</script> | ||
|
||
<template> | ||
<n-modal | ||
v-model:show="modalVisible" | ||
:mask-closable="false" | ||
preset="card" | ||
:title="modalTitle" | ||
class="w-700px" | ||
:segmented="{ | ||
content: true, | ||
action: true, | ||
}" | ||
> | ||
<n-form ref="formRef" :rules="rules" label-placement="left" :model="formModel" :label-width="100" :disabled="modalType === 'view'"> | ||
<n-form-item label="字典名称" path="dictLabel"> | ||
<n-input v-model:value="formModel.dictLabel" /> | ||
</n-form-item> | ||
<n-form-item label="字典值" path="dictValue"> | ||
<n-input-number v-model:value="formModel.dictValue" /> | ||
</n-form-item> | ||
</n-form> | ||
<template #action> | ||
<n-space justify="center"> | ||
<n-button @click="closeModal"> | ||
取消 | ||
</n-button> | ||
<n-button type="primary" :loading="submitLoading" @click="submitModal"> | ||
提交 | ||
</n-button> | ||
</n-space> | ||
</template> | ||
</n-modal> | ||
</template> |
Oops, something went wrong.