Skip to content

Commit

Permalink
添加注释细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
tangllty committed Dec 21, 2023
1 parent efccb8e commit b4a876a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 39 deletions.
36 changes: 30 additions & 6 deletions tang-generator/src/main/resources/vm/vue/index.ts.vm
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import request from '@/utils/request'
import { ${ClassName}Query, ${ClassName}Form } from './types'

// 查询${classComment}列表
/**
* 查询${classComment}列表
*
* @param queryParams 查询参数
*/
export const list$ClassName = (queryParams: ${ClassName}Query) => {
return request({
url: '/$moduleName/$businessName/list',
Expand All @@ -10,15 +14,23 @@ export const list$ClassName = (queryParams: ${ClassName}Query) => {
})
}

// 查询${classComment}信息
/**
* 查询${classComment}信息
*
* @param $primaryKey ${classComment}主键
*/
export const get$ClassName = ($primaryKey: number) => {
return request({
url: '/$moduleName/$businessName/' + $primaryKey,
method: 'get'
})
}

// 添加${classComment}信息
/**
* 添加${classComment}信息
*
* @param data ${classComment}信息
*/
export const add$ClassName = (data: ${ClassName}Form) => {
return request({
url: '/$moduleName/$businessName',
Expand All @@ -27,7 +39,11 @@ export const add$ClassName = (data: ${ClassName}Form) => {
})
}

// 修改${classComment}信息
/**
* 修改${classComment}信息
*
* @param data ${classComment}信息
*/
export const edit$ClassName = (data: ${ClassName}Form) => {
return request({
url: '/$moduleName/$businessName',
Expand All @@ -36,15 +52,23 @@ export const edit$ClassName = (data: ${ClassName}Form) => {
})
}

// 删除${classComment}信息
/**
* 删除${classComment}信息
*
* @param $primaryKey ${classComment}主键
*/
export const delete$ClassName = ($primaryKey: number) => {
return request({
url: '/$moduleName/$businessName/' + $primaryKey,
method: 'delete'
})
}

// 批量删除${classComment}信息
/**
* 批量删除${classComment}信息
*
* @param ${primaryKey}s ${classComment}主键数组
*/
export const delete${ClassName}s = (${primaryKey}s: number[]) => {
return request({
url: '/$moduleName/$businessName',
Expand Down
82 changes: 55 additions & 27 deletions tang-generator/src/main/resources/vm/vue/index.vue.vm
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,28 @@ const { $dictTypeVar } = proxy.$dict($dictTypeParams)
#end

const state = reactive({
// 遮罩层
loading: false,
// 选中数据
/** 遮罩层 */
loading: false as boolean,
/** 选中数据 */
$primaryKey: 0 as number,
// 选中数据数组
/** 选中数据数组 */
${primaryKey}s: [] as number[],
// 总条数
total: 0,
// ${classComment}数据
/** 总条数 */
total: 0 as number,
/** ${classComment}数据 */
${className}List: [] as ${ClassName}[],
// 查询参数
/** 查询参数 */
queryParams: {
pageNum: 1,
pageSize: 10
} as ${ClassName}Query,
// ${classComment}对话框
/** ${classComment}对话框 */
${className}Dialog: {
title: '',
type: '',
visible: false
} as Dialog,
// ${classComment}表单
/** ${classComment}表单 */
${className}Form: {} as ${ClassName}Form
})

Expand All @@ -307,13 +307,17 @@ const ${className}RuleFormRef = ref<FormInstance>()
const ${className}QueryFormRef = ref<FormInstance>()
const ${className}Rules = reactive<FormRules>({
#foreach ($column in $columnList)
#if ($column.javaField != $primaryKey)
$column.javaField: [
{ required: true, message: '${column.columnComment}不能为空', trigger: 'blur' },
],
#end
#end
})

// 查询${classComment}列表
/**
* 查询${classComment}列表
*/
const handleList = async () => {
state.loading = true
const res: any = await list${ClassName}(state.queryParams)
Expand All @@ -322,7 +326,9 @@ const handleList = async () => {
state.loading = false
}

// 添加${classComment}信息
/**
* 添加${classComment}信息
*/
const handleAdd = () => {
state.${className}Form = {} as ${ClassName}Form

Expand All @@ -333,8 +339,12 @@ const handleAdd = () => {
}
}

// 修改${classComment}信息
const handleEdit = async (row: any) => {
/**
* 修改${classComment}信息
*
* @param row ${classComment}信息
*/
const handleEdit = async (row: $ClassName) => {
let $primaryKey = state.$primaryKey
if (row.$primaryKey) {
$primaryKey = row.$primaryKey
Expand All @@ -350,69 +360,87 @@ const handleEdit = async (row: any) => {
}

#set($dollar = '$')
// 删除${classComment}信息
const handleDelete = async (row: any) => {
/**
* 删除${classComment}信息
*
* @param row ${classComment}信息
*/
const handleDelete = async (row: $ClassName) => {
try {
await proxy.$confirm('确认删除"' + row.$primaryKey + '"${classComment}信息吗?', '提示', {
type: 'warning'
})
await delete${ClassName}(row.$primaryKey)
proxy.${dollar}message.success("删除${classComment}信息成功")
proxy.${dollar}message.success('删除${classComment}信息成功')
await handleList()
} catch (error) {
console.log(error)
}
}

// 批量删除${classComment}信息
/**
* 批量删除${classComment}信息
*/
const handleDeletes = async () => {
try {
await proxy.$confirm('确认删除"' + state.${primaryKey}s + '"${classComment}信息吗?', '提示', {
type: 'warning'
})
await delete${ClassName}s(state.${primaryKey}s)
proxy.${dollar}message.success("删除${classComment}信息成功")
proxy.${dollar}message.success('删除${classComment}信息成功')
await handleList()
} catch (error) {
console.log(error)
}
}

// 重置表单
/**
* 重置表单
*/
const resetQuery = async () => {
${className}QueryFormRef.value?.resetFields()
await handleList()
}

// 关闭对话框
/**
* 关闭${classComment}对话框
*/
const close${ClassName}Dialog = () => {
state.${className}Dialog.visible = false
${className}RuleFormRef.value?.clearValidate()
${className}RuleFormRef.value?.resetFields()
}

// 多选框
const handleSelectionChange = (selection: any) => {
state.${primaryKey}s = selection.map((item: any) => item.$primaryKey)
/**
* 选中数据
*
* @param selection 选中数据
*/
const handleSelectionChange = (selection: ${ClassName}[]) => {
state.${primaryKey}s = selection.map((item: $ClassName) => item.$primaryKey)
if (selection.length === 1) {
state.$primaryKey = ${primaryKey}s.value[0]
}
}

// 提交表单
/**
* 提交表单
*
* @param formEl 表单实例
*/
const submitForm = async (formEl: FormInstance | undefined) => {
if (!formEl) return
try {
await formEl.validate()
if (${className}Dialog.value.type == 'add') {
await add${ClassName}(state.${className}Form)
proxy.${dollar}message.success("添加${classComment}信息成功")
proxy.${dollar}message.success('添加${classComment}信息成功')
close${ClassName}Dialog()
await handleList()
}
if (${className}Dialog.value.type == 'edit') {
await edit${ClassName}(state.${className}Form)
proxy.${dollar}message.success("修改${classComment}信息成功")
proxy.${dollar}message.success('修改${classComment}信息成功')
close${ClassName}Dialog()
await handleList()
}
Expand Down
18 changes: 12 additions & 6 deletions tang-generator/src/main/resources/vm/vue/types.ts.vm
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ${classComment}对象
/**
* ${classComment}对象
*/
export interface $ClassName {
#foreach($column in $columnList)
#if ($column.javaType == 'Integer')
Expand All @@ -10,13 +12,15 @@ export interface $ClassName {
#if ($column.javaType == 'String')
$column.javaField: string
#end
#if ($column.javaType == 'Date')
#if ($column.javaType == 'LocalDateTime')
$column.javaField: Date
#end
#end
}

// ${classComment}表单对象
/**
* ${classComment}表单对象
*/
export interface ${ClassName}Form {
#foreach($column in $columnList)
#if ($column.javaType == 'Integer')
Expand All @@ -28,13 +32,15 @@ export interface ${ClassName}Form {
#if ($column.javaType == 'String')
$column.javaField: string
#end
#if ($column.javaType == 'Date')
#if ($column.javaType == 'LocalDateTime')
$column.javaField: Date
#end
#end
}

// ${classComment}查询参数
/**
* ${classComment}查询参数
*/
export interface ${ClassName}Query extends PageQuery {
#foreach($column in $columnList)
#if ($column.javaType == 'Integer')
Expand All @@ -46,7 +52,7 @@ export interface ${ClassName}Query extends PageQuery {
#if ($column.javaType == 'String')
$column.javaField: string
#end
#if ($column.javaType == 'Date')
#if ($column.javaType == 'LocalDateTime')
$column.javaField: Date
#end
#end
Expand Down

0 comments on commit b4a876a

Please sign in to comment.