Skip to content

Commit

Permalink
fix: 模板更新
Browse files Browse the repository at this point in the history
  • Loading branch information
ixre committed Mar 7, 2023
1 parent a9ffa1a commit bde8cbd
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 63 deletions.
8 changes: 4 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"log"
"os"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -442,7 +442,7 @@ func (s *sessionImpl) findTemplates(opt *Options) (map[string]*CodeTemplate, err
}
err := filepath.Walk(opt.TplDir, func(path string, info os.FileInfo, err error) error {
// 如果模板名称以"_"开头,则忽略
if info != nil && !info.IsDir() && s.testFilePath(path, opt.ExcludePatterns) {
if info != nil && !info.IsDir() && s.testFilePath(path, info.Name(), opt.ExcludePatterns) {
tp, err := s.parseTemplate(path, opt.AttachCopyright)
if err != nil {
return errors.New("template:" + info.Name() + "-" + err.Error())
Expand All @@ -458,8 +458,8 @@ func (s *sessionImpl) findTemplates(opt *Options) (map[string]*CodeTemplate, err
}

// 验证文件名路径, 是否可以可以被作为模板生成代码
func (s *sessionImpl) testFilePath(path string, excludePatterns []string) bool {
if path[0] == '_' {
func (s *sessionImpl) testFilePath(path string, fileName string, excludePatterns []string) bool {
if fileName[0] == '_' || fileName[0] == '~' {
return false
}
if strings.HasSuffix(strings.ToUpper(path), "README.MD") {
Expand Down
2 changes: 1 addition & 1 deletion templates/go/restful/grpc_restful.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type {{$structName}} struct{

func ({{$p}} {{$structName}}) Routes(g *echo.Group) {
// {{.table.Name}} router
g.POST("/{{$namePath}}/paging",{{$p}}.paging{{$shortTitle}})
g.GET("/{{$namePath}}/paging",{{$p}}.paging{{$shortTitle}})
g.GET("/{{$namePath}}/:id",{{$p}}.get{{$shortTitle}})
g.GET("/{{$namePath}}",{{$p}}.query{{$shortTitle}})
g.POST("/{{$namePath}}",{{$p}}.create{{$shortTitle}})
Expand Down
2 changes: 1 addition & 1 deletion templates/go/restful/restful.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type {{$structName}} struct{

func ({{$p}} {{$structName}}) Routes(g *echo.Group) {
// {{.table.Name}} router
g.POST("/{{$namePath}}/paging",{{$p}}.paging{{$shortTitle}})
g.GET("/{{$namePath}}/paging",{{$p}}.paging{{$shortTitle}})
g.GET("/{{$namePath}}/:id",{{$p}}.get{{$shortTitle}})
g.GET("/{{$namePath}}",{{$p}}.query{{$shortTitle}})
g.POST("/{{$namePath}}",{{$p}}.create{{$shortTitle}})
Expand Down
24 changes: 24 additions & 0 deletions templates/java/spring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,27 @@ public class ReportDataSource {
}
}
```

示例SQL查询条件

```sql
SELECT COUNT(1) FROM wal_wallet_log l
WHERE l.wallet_id = {wallet_id}\n AND title LIKE '%{keyword}%'
#if { kind>0 }
AND kind = {kind}
#else
AND kind = 'else'
#fi

#if { kind = 0 }
AND kind = 0 + {kind}
#fi

#if {trade_no}
AND (trade_no IS NULL OR outer_no LIKE '%{trade_no}%')";
#fi
#if {check} AND (check = 1) #fi
#if {unchecked} AND (uncheck = {kind}) #fi
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!target:xml/mysql/{{.table.Prefix}}/{{substr_n .table.Name "_" 1}}_list.xml
#!target:query/{{.table.Prefix}}/{{substr_n .table.Name "_" 1}}_list.xml
<?xml version="1.0" encoding="utf-8" ?>
<ExportItemConfig>
<ColumnMapping>
Expand All @@ -8,13 +8,14 @@
<![CDATA[
SELECT * FROM {{.table.Name}}
WHERE {where}
ORDER BY {order_by} LIMIT {page_offset},{page_size}
ORDER BY {order_by}
LIMIT {{if eq .global.db "postgresql"}}{page_size} OFFSET {page_offset}{{else}}{page_offset},{page_size}{{end}}
]]>
</Query>
<Import><![CDATA[]]></Import>
<Total>
<![CDATA[
SELECT COUNT({{.table.Pk }}) FROM {{.table.Name}} WHERE {where}
SELECT COUNT(1) FROM {{.table.Name}} WHERE {where}
]]>
</Total>
</ExportItemConfig>
23 changes: 11 additions & 12 deletions templates/vue/curd/api.js.tpl → templates/vue/curd/_api.js.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!lang:ts#!name:API和定义文件
#!target:vue/{{name_path .table.Name}}/api.js
import {request} from '@/adapter'
import {request} from '@/utils/adapter'
{{$columns := .columns}}
{{$path := join .global.base_path (name_path .table.Name) "/"}}\

Expand All @@ -25,14 +25,14 @@ export const get{{.table.Title}} = (id, params = {}) => request({
})

export const query{{.table.Title}}List = (params = {}) => request({
url: '{{$path}}',
method: 'GET',
url: `{{$path}}`,
method: 'GET',
params: { ...params }
})

export const create{{.table.Title}} = (data = {}) => request({
url: '{{$path}}',
method: 'POST',
url: `{{$path}}`,
method: 'POST',
data
})

Expand All @@ -48,14 +48,13 @@ export const delete{{.table.Title}} = (id) => request({
})

export const batchDelete{{.table.Title}} = (arr = []) => request({
url: '{{$path}}',
method: 'DELETE',
url: `{{$path}}`,
method: 'DELETE',
data: arr
})

export const queryPaging{{.table.Title}} = (page = 0, size = 100, data = {}) => request({
url: '{{$path}}/paging',
method: 'POST',
params: { page, size },
data
export const queryPaging{{.table.Title}} = (page = 0, size = 100, params = {}) => request({
url: `{{$path}}/paging`,
method: 'GET',
params: { page, size,...params },
})
62 changes: 62 additions & 0 deletions templates/vue/curd/api.ts.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!lang:ts#!name:API和定义文件
#!target:vue/{{name_path .table.Name}}/api.ts
import request from '@/utils/request'
{{$columns := .columns}}
{{$path := join .global.base_path (name_path .table.Name) "/"}}\

// {{.table.Comment}}对象
export interface I{{.table.Title}} {
{{range $i,$c := .columns}}// {{$c.Comment}}
{{$c.Prop}}: {{type "ts" $c.Type}}{{if not (is_last $i $columns)}},{{end}}
{{end}}
}

export const default{{.table.Title}}:()=>I{{.table.Title}} = () => {
return {
{{range $i,$c := .columns}}
{{if eq $c.Render.Element "radio"}}{{$c.Prop}}: {{default "ts" $c.Type}} + 1,
{{else}}{{$c.Prop}}: {{default "ts" $c.Type}}{{if not (is_last $i $columns)}},{{end}}\
{{end}}{{end}}
}
}

export const get{{.table.Title}} = (id: any, params: any = {}) => request({
url: `{{$path}}/${id}`,
method: 'GET',
params: { ...params }
})

export const query{{.table.Title}}List = (params: any = {}) => request({
url: '{{$path}}',
method: 'GET',
params: { ...params }
})

export const create{{.table.Title}} = (data: any) => request({
url: '{{$path}}',
method: 'POST',
data
})

export const update{{.table.Title}} = (id: any, data: any) => request({
url: `{{$path}}/${id}`,
method: 'PUT',
data
})

export const delete{{.table.Title}} = (id: any) => request({
url: `{{$path}}/${id}`,
method: 'DELETE'
})

export const batchDelete{{.table.Title}} = (arr: any[]) => request({
url: '{{$path}}',
method: 'DELETE',
data: arr
})

export const queryPaging{{.table.Title}} = (page:number, size:number, params: any) => request({
url: '{{$path}}/paging',
method: 'GET',
params: { page, size,...params }
})
31 changes: 16 additions & 15 deletions templates/vue/curd/index.vue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="app-container mod-grid-container">
<!-- 查询和其他操作 -->
<div class="filter-container mod-grid-header">
<div class="it mod-grid-header-back" v-show="false">
<div class="it mod-grid-header-back" v-if="false">
<el-button class="filter-item" @click="handleBack">返回</el-button>
</div>
<div class="it mod-grid-header-filter">
Expand All @@ -28,23 +28,23 @@
</el-select>
</el-form-item>
<el-form-item class="filter-item">
<el-button v-permission="['admin']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
<el-button v-permission="['admin']" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
</el-form-item>
<el-form-item class="filter-item">
<el-button v-permission="['admin']" icon="el-icon-plus" @click="handleCreate">新增</el-button>
</el-form-item>
<el-form-item class="filter-item">
<el-button v-show="selectedRows.length > 0" v-permission="['admin']" type="danger" :loading="requesting" @click="handleDelete">删除</el-button>
</el-form-item>
</el-form>
</div>
<div class="it mod-grid-header-create">
<el-button v-permission="['admin']" class="filter-item" icon="el-icon-plus" @click="handleCreate">新增</el-button>
</div>
<div class="it mod-grid-header-del">
<el-button v-show="selectedRows.length > 0" v-permission="['admin']" class="filter-item" type="danger" @click="handleDelete">删除</el-button>
</div>
</div>
<div class="mod-grid-body">
<!-- 表单数据 -->
<el-table ref="table" v-loading="list.loading" :data="list.data" :height="tableHeight"
fit :highlight-current-row="false" row-key="{{$Pk}}" border
empty-text="暂无数据" @selection-change="handleSelectionChange">
<el-table-column align="center" type="selection" width="45" fixed="left"/>
<el-table-column align="center" type="selection" width="40" fixed="left"/>
<el-table-column type="index" width="50" label="序号"></el-table-column>
{{range $i,$c := .columns}} \
{{if ends_with $c.Name "_time"}} \
Expand Down Expand Up @@ -72,7 +72,7 @@
<el-table-column align="center" width="160" label="操作" fixed="right">
<template slot-scope="scope">
<el-button type="text" icon="el-icon-edit-outline" @click="handleEdit(scope.row)">编辑</el-button>
<el-button type="text" icon="el-icon-delete" v-loading="requesting" @click="handleDelete(scope)">删除</el-button>
<el-button type="text" icon="el-icon-delete" :loading="requesting && $index === scope.$index" @click="handleDelete(scope.$index,scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
Expand All @@ -94,7 +94,7 @@
import {onMounted, reactive, ref, nextTick} from "vue";
import {queryPaging{{$Class}},delete{{$Class}},batchDelete{{$Class}} } from './api';
import {{$Class}}Modal from './modal.vue';
import {Message,MessageBox,router,parseResult,formatColTime} from "@/adapter";
import {Message,MessageBox,router,parseResult,formatColTime} from "@/utils/adapter";
// {{.table.Comment}}数据映射类
class ListModel {
Expand All @@ -107,6 +107,7 @@ class ListModel {
let list = reactive({loading:false,total:0, page: 1, rows: 20,data:[]});
let dialog = reactive({title:"Form",params:0,modal: null});
let $index = ref(-1);
let requesting = ref(false);
let selectedIds = ref([]);
let selectedRows = ref([]);
Expand Down Expand Up @@ -138,7 +139,7 @@ onMounted(()=>{
queryPagingData();
nextTick(()=>{
const rec = table.value.$el.getBoundingClientRect();
tableHeight.value = document.body.clientHeight - rec.top - 30;
tableHeight.value = document.body.clientHeight - rec.top - 80;
})
})
Expand Down Expand Up @@ -189,17 +190,17 @@ const refresh = ({state = 0,close = true,data = {}})=>{
if(state)queryPagingData(data);
}
const handleDelete = ({$index,row}) => {
const handleDelete = (idx,row) => {
MessageBox.confirm('执行此操作数据无法恢复,是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
if(requesting.value)return;requesting.value=true;
if(requesting.value)return;requesting.value=true;$index.value = idx;
let ret = await (row && row.{{.table.Pk}}?
delete{{$Class}}(row.{{.table.Pk}}):
batchDelete{{$Class}}(selectedIds.value))
.finally(()=>requesting.value=false);
.finally(()=>requesting.value=false;$index.value = -1;);
let {errCode,errMsg} = parseResult(ret.data);
if (errCode === 0) {
Message.success({message:'删除成功',duration:2000,onClose:queryPagingData});
Expand Down
12 changes: 6 additions & 6 deletions templates/vue/curd/modal.vue.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</el-form-item>
{{end}}{{end}}
<el-container class="mod-form-bar">
<el-button @click="()=>callback({close: true})">取消</el-button>
<el-button v-loading="requesting" type="primary" @click="submitForm">提交</el-button>
<el-button @click="()=>cancelForm({close: true})">取消</el-button>
<el-button type="primary" :loading="requesting" @click="submitForm">提交</el-button>
</el-container>
</el-form>
</div>
Expand All @@ -47,8 +47,8 @@

<script setup>
import {onMounted,ref} from "vue";
import {{`{`}}{{$Class}},get{{$Class}},create{{$Class}},update{{$Class}} } from "./api"
import {Message,MessageBox,router,parseResult} from "@/adapter";
import {{`{`}}{{$Class}},default{{$Class}},get{{$Class}},create{{$Class}},update{{$Class}} } from "./api"
import {Message,MessageBox,router,parseResult} from "@/utils/adapter";
/** #! 定义属性,接收父组件的参数 */
const props = defineProps({
Expand All @@ -59,7 +59,7 @@ const props = defineProps({
const emit = defineEmits(['callback']);
const formRef = ref(null); /* #! formRef关联表单ref属性 */
let formData = ref(new {{$Class}}()); /** #! 表单数据 */
let formData = ref(default{{$Class}}()); /** #! 表单数据 */
let requesting = ref(false);
let isModal = props.value;
Expand Down Expand Up @@ -88,7 +88,7 @@ onMounted(()=>{
if(props.value)fetchFormData(props.value);
})
const callback = (arg)=> (isModal && emit("callback",arg)) || router.go(-1)
const cancelForm = (arg)=> (isModal && emit("callback",arg)) || router.go(-1)
const fetchFormData = async(id) =>{
try {
Expand Down
21 changes: 0 additions & 21 deletions templates/xml/export_pgsql.xml

This file was deleted.

0 comments on commit bde8cbd

Please sign in to comment.