mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-26 20:57:11 +08:00
chore(generator): 优化代码生成模板
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
:title="title"
|
:title="title"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
:esc-to-close="false"
|
:esc-to-close="false"
|
||||||
:modal-style="{ maxWidth: '520px' }"
|
:width="width >= 600 ? 600 : '100%'"
|
||||||
width="90%"
|
|
||||||
@before-ok="save"
|
@before-ok="save"
|
||||||
@close="reset"
|
@close="reset"
|
||||||
>
|
>
|
||||||
@@ -25,6 +24,7 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const dataId = ref('')
|
const dataId = ref('')
|
||||||
|
const visible = ref(false)
|
||||||
const isUpdate = computed(() => !!dataId.value)
|
const isUpdate = computed(() => !!dataId.value)
|
||||||
const title = computed(() => (isUpdate.value ? '修改${businessName}' : '新增${businessName}'))
|
const title = computed(() => (isUpdate.value ? '修改${businessName}' : '新增${businessName}'))
|
||||||
const formRef = ref<InstanceType<typeof GiForm>>()
|
const formRef = ref<InstanceType<typeof GiForm>>()
|
||||||
@@ -34,15 +34,11 @@ const { <#list dictCodes as dictCode>${dictCode}<#if dictCode_has_next>,</#if></
|
|||||||
</#if>
|
</#if>
|
||||||
|
|
||||||
const options: Options = {
|
const options: Options = {
|
||||||
form: {},
|
form: { size: 'large' },
|
||||||
btns: { hide: true }
|
btns: { hide: true },
|
||||||
}
|
}
|
||||||
|
|
||||||
const { form, resetForm } = useForm({
|
const columns: Columns = reactive([
|
||||||
// todo 待补充
|
|
||||||
})
|
|
||||||
|
|
||||||
const columns = computed<Columns<typeof form>>(() => [
|
|
||||||
<#list fieldConfigs as fieldConfig>
|
<#list fieldConfigs as fieldConfig>
|
||||||
<#if fieldConfig.showInForm>
|
<#if fieldConfig.showInForm>
|
||||||
{
|
{
|
||||||
@@ -69,7 +65,7 @@ const columns = computed<Columns<typeof form>>(() => [
|
|||||||
<#elseif fieldConfig.formType = 'SELECT'>
|
<#elseif fieldConfig.formType = 'SELECT'>
|
||||||
type: 'select',
|
type: 'select',
|
||||||
<#elseif fieldConfig.formType = 'RADIO'>
|
<#elseif fieldConfig.formType = 'RADIO'>
|
||||||
type: 'radio-group'
|
type: 'radio-group',
|
||||||
</#if>
|
</#if>
|
||||||
<#if fieldConfig.dictCode?? && fieldConfig.dictCode != ''>
|
<#if fieldConfig.dictCode?? && fieldConfig.dictCode != ''>
|
||||||
options: ${fieldConfig.dictCode},
|
options: ${fieldConfig.dictCode},
|
||||||
@@ -82,29 +78,16 @@ const columns = computed<Columns<typeof form>>(() => [
|
|||||||
</#list>
|
</#list>
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const { form, resetForm } = useForm({
|
||||||
|
// todo 待补充
|
||||||
|
})
|
||||||
|
|
||||||
// 重置
|
// 重置
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
formRef.value?.formRef?.resetFields()
|
formRef.value?.formRef?.resetFields()
|
||||||
resetForm()
|
resetForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
const visible = ref(false)
|
|
||||||
// 新增
|
|
||||||
const onAdd = () => {
|
|
||||||
reset()
|
|
||||||
dataId.value = ''
|
|
||||||
visible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改
|
|
||||||
const onUpdate = async (id: string) => {
|
|
||||||
reset()
|
|
||||||
dataId.value = id
|
|
||||||
const res = await get${classNamePrefix}(id)
|
|
||||||
Object.assign(form, res.data)
|
|
||||||
visible.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -124,5 +107,21 @@ const save = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
const onAdd = async () => {
|
||||||
|
reset()
|
||||||
|
dataId.value = ''
|
||||||
|
visible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改
|
||||||
|
const onUpdate = async (id: string) => {
|
||||||
|
reset()
|
||||||
|
dataId.value = id
|
||||||
|
const { data } = await get${classNamePrefix}(id)
|
||||||
|
Object.assign(form, data)
|
||||||
|
visible.value = true
|
||||||
|
}
|
||||||
|
|
||||||
defineExpose({ onAdd, onUpdate })
|
defineExpose({ onAdd, onUpdate })
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-drawer v-model:visible="visible" title="${businessName}详情" :width="width >= 580 ? 580 : '100%'" :footer="false">
|
<a-drawer v-model:visible="visible" title="${businessName}详情" :width="width >= 600 ? 600 : '100%'" :footer="false">
|
||||||
<a-descriptions :column="2" size="large" class="general-description">
|
<a-descriptions :column="2" size="large" class="general-description">
|
||||||
<#list fieldConfigs as fieldConfig>
|
<#list fieldConfigs as fieldConfig>
|
||||||
<a-descriptions-item label="${fieldConfig.comment}">{{ dataDetail?.${fieldConfig.fieldName} }}</a-descriptions-item>
|
<a-descriptions-item label="${fieldConfig.comment}">{{ dataDetail?.${fieldConfig.fieldName} }}</a-descriptions-item>
|
||||||
@@ -13,29 +13,30 @@
|
|||||||
</a-drawer>
|
</a-drawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script setup lang="ts">
|
||||||
import { useWindowSize } from '@vueuse/core'
|
import { useWindowSize } from '@vueuse/core'
|
||||||
import { type ${classNamePrefix}DetailResp, get${classNamePrefix} } from '@/apis/${apiModuleName}/${apiName}'
|
import { type ${classNamePrefix}DetailResp, get${classNamePrefix} } from '@/apis/${apiModuleName}/${apiName}'
|
||||||
|
|
||||||
const { width } = useWindowSize()
|
const { width } = useWindowSize()
|
||||||
|
|
||||||
const visible = ref(false)
|
|
||||||
const dataId = ref('')
|
const dataId = ref('')
|
||||||
const dataDetail = ref<${classNamePrefix}DetailResp>()
|
const dataDetail = ref<${classNamePrefix}DetailResp>()
|
||||||
|
const visible = ref(false)
|
||||||
|
|
||||||
// 查询详情
|
// 查询详情
|
||||||
const getDataDetail = async () => {
|
const getDataDetail = async () => {
|
||||||
const res = await get${classNamePrefix}(dataId.value)
|
const { data } = await get${classNamePrefix}(dataId.value)
|
||||||
dataDetail.value = res.data
|
dataDetail.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
// 打开详情
|
// 打开
|
||||||
const onDetail = async (id: string) => {
|
const onOpen = async (id: string) => {
|
||||||
dataId.value = id
|
dataId.value = id
|
||||||
await getDataDetail()
|
await getDataDetail()
|
||||||
visible.value = true
|
visible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({ onDetail })
|
defineExpose({ onOpen })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|||||||
@@ -83,13 +83,13 @@
|
|||||||
</#list>
|
</#list>
|
||||||
<template #action="{ record }">
|
<template #action="{ record }">
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-link v-permission="['${apiModuleName}:${apiName}:list']" title="查看" @click="onDetail(record)">查看</a-link>
|
<a-link v-permission="['${apiModuleName}:${apiName}:detail']" title="详情" @click="onDetail(record)">详情</a-link>
|
||||||
<a-link v-permission="['${apiModuleName}:${apiName}:update']" title="修改" @click="onUpdate(record)">修改</a-link>
|
<a-link v-permission="['${apiModuleName}:${apiName}:update']" title="修改" @click="onUpdate(record)">修改</a-link>
|
||||||
<a-link
|
<a-link
|
||||||
v-permission="['${apiModuleName}:${apiName}:delete']"
|
v-permission="['${apiModuleName}:${apiName}:delete']"
|
||||||
status="danger"
|
status="danger"
|
||||||
:disabled="record.disabled"
|
:disabled="record.disabled"
|
||||||
title="删除"
|
:title="record.disabled ? '不可删除' : '删除'"
|
||||||
@click="onDelete(record)"
|
@click="onDelete(record)"
|
||||||
>
|
>
|
||||||
删除
|
删除
|
||||||
@@ -106,12 +106,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ${classNamePrefix}AddModal from './${classNamePrefix}AddModal.vue'
|
import ${classNamePrefix}AddModal from './${classNamePrefix}AddModal.vue'
|
||||||
import ${classNamePrefix}DetailDrawer from './${classNamePrefix}DetailDrawer.vue'
|
import ${classNamePrefix}DetailDrawer from './${classNamePrefix}DetailDrawer.vue'
|
||||||
import { type ${classNamePrefix}Resp, type ${classNamePrefix}Query, delete${classNamePrefix}, export${classNamePrefix}, list${classNamePrefix} } from '@/apis/${apiModuleName}'
|
import { type ${classNamePrefix}Resp, type ${classNamePrefix}Query, delete${classNamePrefix}, export${classNamePrefix}, list${classNamePrefix} } from '@/apis/${apiModuleName}/${apiName}'
|
||||||
import type { TableInstanceColumns } from '@/components/GiTable/type'
|
import type { TableInstanceColumns } from '@/components/GiTable/type'
|
||||||
import { useDownload, useTable } from '@/hooks'
|
import { useDownload, useTable } from '@/hooks'
|
||||||
|
import { useDict } from '@/hooks/app'
|
||||||
import { isMobile } from '@/utils'
|
import { isMobile } from '@/utils'
|
||||||
import has from '@/utils/has'
|
import has from '@/utils/has'
|
||||||
import { useDict } from '@/hooks/app'
|
|
||||||
|
|
||||||
defineOptions({ name: '${classNamePrefix}' })
|
defineOptions({ name: '${classNamePrefix}' })
|
||||||
|
|
||||||
@@ -125,7 +125,7 @@ const queryForm = reactive<${classNamePrefix}Query>({
|
|||||||
${fieldConfig.fieldName}: undefined,
|
${fieldConfig.fieldName}: undefined,
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
sort: ['createTime,desc']
|
sort: ['id,desc']
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -191,7 +191,7 @@ const onUpdate = (record: ${classNamePrefix}Resp) => {
|
|||||||
const ${classNamePrefix}DetailDrawerRef = ref<InstanceType<typeof ${classNamePrefix}DetailDrawer>>()
|
const ${classNamePrefix}DetailDrawerRef = ref<InstanceType<typeof ${classNamePrefix}DetailDrawer>>()
|
||||||
// 详情
|
// 详情
|
||||||
const onDetail = (record: ${classNamePrefix}Resp) => {
|
const onDetail = (record: ${classNamePrefix}Resp) => {
|
||||||
${classNamePrefix}DetailDrawerRef.value?.onDetail(record.id)
|
${classNamePrefix}DetailDrawerRef.value?.onOpen(record.id)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user