Browse Source

fix

main
cobb 3 years ago
parent
commit
bf112cf3f6
  1. 54
      src/components/HelloWorld.vue

54
src/components/HelloWorld.vue

@ -93,6 +93,7 @@ function toCamelCase(str) {
); );
} }
function titleCase(str) { function titleCase(str) {
const newStr = str.slice(0, 1).toUpperCase() + str.slice(1); const newStr = str.slice(0, 1).toUpperCase() + str.slice(1);
return newStr; return newStr;
@ -103,6 +104,16 @@ function lowerCase(str) {
return newStr; return newStr;
} }
// t_usert_
function rmPrefix(str) {
if (str.indexOf('_') > -1) {
var ss = str.split('_')
return ss[1]
}
return str
}
function typeMap(str) { function typeMap(str) {
const kv = { const kv = {
integer: "int64", integer: "int64",
@ -216,8 +227,9 @@ export default {
this.schemaKey = Date.now(); this.schemaKey = Date.now();
}, },
handleRouteOutput(v) { handleRouteOutput(v) {
const tableName = toCamelCase(v.title);
const lowTableName = v.title;
const title = rmPrefix(v.title);
const tableName = toCamelCase(title);
const lowTableName = title
const Output = ` const Output = `
{ {
${lowTableName} := admin.Group("${lowTableName}") ${lowTableName} := admin.Group("${lowTableName}")
@ -230,8 +242,9 @@ export default {
return Output; return Output;
}, },
handleJsApi(v) { handleJsApi(v) {
const tableName = toCamelCase(v.title);
const lowTableName = v.title;
const title = rmPrefix(v.title);
const tableName = toCamelCase(title);
const lowTableName = title
const Output = ` const Output = `
import request from '@/utils/request'; import request from '@/utils/request';
export function get${tableName}(data) { export function get${tableName}(data) {
@ -278,7 +291,8 @@ export default {
return Output; return Output;
}, },
handleApiOutput(v) { handleApiOutput(v) {
const tableName = toCamelCase(v.title);
const title = rmPrefix(v.title);
const tableName = toCamelCase(title);
const apiOutput = ` const apiOutput = `
package api package api
@ -289,6 +303,7 @@ export default {
"Carp/internal/app/service" "Carp/internal/app/service"
"Carp/pkg/errors" "Carp/pkg/errors"
"Carp/pkg/utils" "Carp/pkg/utils"
"Carp/pkg/utils/excelize"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/wire" "github.com/google/wire"
@ -340,20 +355,22 @@ export default {
return return
} }
if req.Export { if req.Export {
file := resp.(*xlsx.File)
ginplus.ResExcel(c, file, "导出信息列表")
f, _ := excelize.Excelize(resp,
excelize.ColumnFilter("create_time", excelize.FilterTimestamp),
)
ginplus.ResExcel(c, f, "导出信息列表")
return return
} }
ginplus.ResPage(c, resp) ginplus.ResPage(c, resp)
} }
func (l *${tableName}Api) Delete${tableName}(c *gin.Context) { func (l *${tableName}Api) Delete${tableName}(c *gin.Context) {
var req schema.Ids
var req schema.IDResult
if err := ginplus.ParseJSON(c, &req); err != nil { if err := ginplus.ParseJSON(c, &req); err != nil {
ginplus.ResError(c, err) ginplus.ResError(c, err)
return return
} }
if err := l.${tableName}Service.Del${tableName}(c.Request.Context(), req.IDs...); err != nil {
if err := l.${tableName}Service.Del${tableName}(c.Request.Context(), req.ID); err != nil {
ginplus.ResError(c, err) ginplus.ResError(c, err)
return return
} }
@ -363,8 +380,9 @@ export default {
return apiOutput; return apiOutput;
}, },
handleServiceOutput(v) { handleServiceOutput(v) {
const title = rmPrefix(v.title);
const tableName = toCamelCase(title);
const properties = v.properties; const properties = v.properties;
const tableName = toCamelCase(v.title);
var primary = ``; var primary = ``;
Object.keys(properties).forEach(function (key) { Object.keys(properties).forEach(function (key) {
const o = properties[key]; const o = properties[key];
@ -380,7 +398,6 @@ export default {
"Carp/internal/app/model" "Carp/internal/app/model"
"Carp/internal/app/schema" "Carp/internal/app/schema"
"Carp/pkg/errors" "Carp/pkg/errors"
"Carp/pkg/utils/excelize"
"context" "context"
"encoding/json" "encoding/json"
@ -399,12 +416,6 @@ export default {
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }
if req.Export {
rst, _ := excelize.Excelize(l,
excelize.ColumnFilter("create_time", excelize.FilterTimestamp),
)
return rst, nil
}
pagination := &schema.PaginationResult{ pagination := &schema.PaginationResult{
Count: cnt, Count: cnt,
List: l, List: l,
@ -424,15 +435,12 @@ export default {
} }
func (a *${tableName}Service) Del${tableName}(ctx context.Context, ${primaryLower} ...int64) error { func (a *${tableName}Service) Del${tableName}(ctx context.Context, ${primaryLower} ...int64) error {
var l []model.${tableName}
_, err := a.${tableName}.Q().${primary}In(${primaryLower}...).List(ctx, &l)
var o model.${tableName}
err := a.${tableName}.Q().${primary}(${primaryLower}).One(ctx, &o)
if err != nil { if err != nil {
return err return err
} }
for _, d := range l {
a.${tableName}.Delete(ctx, d.${primary})
}
return nil
return a.${tableName}.Delete(ctx, o.${primary})
} }
func (a *${tableName}Service) Create${tableName}(ctx context.Context, r *model.${tableName}) error { func (a *${tableName}Service) Create${tableName}(ctx context.Context, r *model.${tableName}) error {

Loading…
Cancel
Save