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