完善生成ListAll,加入uniapp部分页面

This commit is contained in:
xiangheng
2024-06-02 01:51:33 +08:00
parent d73b0472c6
commit 6966b3f4a4
8 changed files with 219 additions and 120 deletions

View File

@@ -173,7 +173,7 @@ func (genSrv generateService) ImportTable(tableNames []string) (e error) {
return nil
})
e = response.CheckErr(err, "ImportTable Transaction err")
return nil
return e
}
// SyncTable 同步表结构
@@ -256,7 +256,7 @@ func (genSrv generateService) SyncTable(id uint) (e error) {
return nil
})
e = response.CheckErr(err, "SyncTable Transaction err")
return nil
return e
}
// EditTable 编辑表结构
@@ -276,21 +276,21 @@ func (genSrv generateService) EditTable(editReq EditTableReq) (e error) {
if e = response.CheckErrDBNotRecord(err, "数据已丢失!"); e != nil {
return
}
if e = response.CheckErr(err, "EditTable First err"); e != nil {
if e = response.CheckErr(err, "查找数据失败"); e != nil {
return
}
response.Copy(&genTable, editReq)
err = genSrv.db.Transaction(func(tx *gorm.DB) error {
genTable.SubTableName = strings.Replace(editReq.SubTableName, config.Config.DbTablePrefix, "", 1)
txErr := tx.Save(&genTable).Error
if te := response.CheckErr(txErr, "EditTable Save GenTable err"); te != nil {
if te := response.CheckErr(txErr, "更新失败"); te != nil {
return te
}
for i := 0; i < len(editReq.Columns); i++ {
var col gen_model.GenTableColumn
response.Copy(&col, editReq.Columns[i])
txErr = tx.Save(&col).Error
if te := response.CheckErr(txErr, "EditTable Save GenTableColumn err"); te != nil {
if te := response.CheckErr(txErr, "更新失败"); te != nil {
return te
}
}

View File

@@ -21,7 +21,12 @@ type {{{ title (toCamelCase .ModuleName) }}}Handler struct {}
// @Param PageSize query int true "每页数量"
{{{- range .Columns }}}
{{{- if .IsQuery }}}
// @Param {{{ toCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- if eq .HtmlType "datetime" }}}
// @Param {{{ title (toCamelCase .ColumnName) }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ title (toCamelCase .ColumnName) }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- else }}}
// @Param {{{ toCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- end }}}
{{{- end }}}
{{{- end }}}
// @Success 200 {object} []{{{ title (toCamelCase .EntityName) }}}Resp "成功"
@@ -43,15 +48,24 @@ func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) List(c *gin.Context) {
// @Summary {{{ .FunctionName }}}列表-所有
// @Tags {{{ .ModuleName }}}-{{{ .FunctionName }}}
// @Produce json
{{{- range .Columns }}}
{{{- if .IsQuery }}}
{{{- if eq .HtmlType "datetime" }}}
// @Param {{{ title (toCamelCase .ColumnName) }}}Start query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
// @Param {{{ title (toCamelCase .ColumnName) }}}End query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- else }}}
// @Param {{{ toCamelCase .GoField }}} query {{{ .GoType }}} false "{{{ .ColumnComment }}}."
{{{- end }}}
{{{- end }}}
{{{- end }}}
// @Success 200 {object} []{{{ title (toCamelCase .EntityName) }}}Resp "成功"
// @Router /api/admin/{{{ .ModuleName }}}/listAll [get]
func (hd {{{ title (toCamelCase .ModuleName) }}}Handler) ListAll(c *gin.Context) {
//var listReq {{{ title (toCamelCase .EntityName) }}}ListReq
//if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
// return
//}
res, err := Service.ListAll()
var listReq {{{ title (toCamelCase .EntityName) }}}ListReq
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
return
}
res, err := Service.ListAll(listReq)
response.CheckAndRespWithData(c, res, err)
}

View File

@@ -79,10 +79,12 @@ func (service {{{ toCamelCase .EntityName }}}Service) List(page request.PageReq,
}, nil
}
// ListAll {{{ .FunctionName }}}列表
func (service {{{ toCamelCase .EntityName }}}Service) ListAll() (res []{{{ title (toCamelCase .EntityName) }}}Resp, e error) {
func (service {{{ toCamelCase .EntityName }}}Service) ListAll(listReq {{{ title (toCamelCase .EntityName) }}}ListReq) (res []{{{ title (toCamelCase .EntityName) }}}Resp, e error) {
dbModel := service.GetModel(listReq)
var modelList []model.{{{ title (toCamelCase .EntityName) }}}
err := service.db.Find(&modelList).Error
err := dbModel.Find(&modelList).Error
if e = response.CheckErr(err, "查询全部失败"); e != nil {
return
}

View File

@@ -0,0 +1,95 @@
<template>
<view class="page-content">
<uv-navbar leftText="" :placeholder="true" title="{{{.FunctionName}}}详情" autoBack>
<template v-slot:right>
<uv-icon name="edit-pen" size="20" @click="edit"></uv-icon>
</template>
</uv-navbar>
<uv-form labelPosition="left" :model="form">
{{{- range .Columns }}}
{{{- if .IsList }}}
<uv-form-item label="{{{.ColumnComment}}}" prop="{{{(toCamelCase .GoField)}}}" borderBottom>
{{{- if and (ne .DictType "") (or (eq .HtmlType "select") (eq .HtmlType "radio") (eq .HtmlType "checkbox")) }}}
<dict-value :options="dictData.{{{ .DictType }}}" :value="row.{{{ (toCamelCase .GoField) }}}" />
{{{- else if eq .HtmlType "imageUpload" }}}
<uv-image :src="$filePath(form.{{{(toCamelCase .GoField)}}})" width="100%"></uv-image>
{{{- else }}}
{{form.{{{(toCamelCase .GoField)}}}}}
{{{- end }}}
</uv-form-item>
{{{- end }}}
{{{- end }}}
</uv-form>
<uv-button
v-if="$perms('admin:{{{ .ModuleName }}}:edit')"
type="primary"
text="编辑"
customStyle="margin-top: 20rpx"
@click="edit"
></uv-button>
</view>
</template>
<script setup>
import {
reactive,
ref,
computed
} from "vue";
import {
onLoad,
onShow
} from "@dcloudio/uni-app";
import {
useDictOptions
} from "@/api/dict.js";
import {
{{{ .ModuleName }}}_detail
} from "@/api/{{{ .ModuleName }}}.js";
import {
toast,
alert,
toPath
} from "@/utils/utils";
let form = ref({});
onLoad((e) => {
console.log("onLoad", e);
getDetails(e.id);
});
onShow((e) => {
if (form.value?.id) {
getDetails(form.value.id);
}
});
function getDetails(id) {
{{{ .ModuleName }}}_detail(id).then((res) => {
if (res.code == 200) {
if (res?.result) {
form.value = res?.result
}
} else {
toast(res.message);
}
})
.catch((err) => {
toast(err.message||"网络错误");
});
}
function edit() {
toPath("/pages/{{{ .ModuleName }}}/edit", { id: form.value.id });
}
</script>
<style lang="scss" scoped>
.page-content {
padding: 10rpx 20rpx 300rpx;
}
</style>

View File

@@ -1,40 +1,25 @@
<template>
<view class="page-content">
<uv-form labelPosition="left" :model="form" :rules="rules" ref="formRef">
<uv-form-item label="IMEI" prop="imei" borderBottom>
<uv-input v-model="form.imei" border="surround">
</uv-input>
</uv-form-item>
<uv-form-item label="位置" prop="location" borderBottom>
<uv-input v-model="form.location" border="surround">
</uv-input>
</uv-form-item>
<uv-form-item label="关联表号" prop="meters" borderBottom>
<uv-textarea v-model="form.meters" border="surround"></uv-textarea>
</uv-form-item>
<uv-form-item label="卡1" prop="sim0" borderBottom>
<uv-input v-model="form.sim0" border="surround">
</uv-input>
</uv-form-item>
<uv-form-item label="卡2" prop="sim1" borderBottom>
<uv-input v-model="form.sim1" border="surround">
</uv-input>
</uv-form-item>
<uv-form-item label="备注" prop="remark" borderBottom>
<uv-textarea v-model="form.remark" border="surround"></uv-textarea>
<uv-form labelPosition="left" :model="form" :rules="formRules" ref="formRef">
{{{- range .Columns }}}
{{{- if .IsEdit }}}
<uv-form-item label="{{{ .ColumnComment }}}" prop="{{{ (toCamelCase .GoField) }}}" borderBottom>
{{{- if eq .HtmlType "input" }}}
<uv-input v-model="form.{{{ (toCamelCase .GoField) }}}" border="surround"></uv-input>
{{{- else if eq .HtmlType "number" }}}
<uv-number-box v-model="form.{{{ (toCamelCase .GoField) }}}" :min="-99999999" :max="99999999" :integer="true"></uv-number-box>
{{{- else if eq .HtmlType "textarea" }}}
<uv-textarea v-model="form.{{{ (toCamelCase .GoField) }}}" border="surround"></uv-textarea>
{{{- else if or (eq .HtmlType "checkbox") (eq .HtmlType "radio") (eq .HtmlType "select")}}}
<x-picker v-model="form.{{{ (toCamelCase .GoField) }}}" valueKey="value" labelKey="name" :columns="dictData.{{{ .DictType }}}"></x-picker>
{{{- end }}}
</uv-form-item>
{{{- end }}}
{{{- end }}}
<uv-button type="primary" text="提交" customStyle="margin-top: 20rpx"
@click="submit"></uv-button>
</uv-form>
</view>
</template>
@@ -47,57 +32,87 @@
import {
onLoad
} from "@dcloudio/uni-app";
import {
equipment_list,
equipment_edit,
} from "@/api/equipment.js";
import {
{{{ .ModuleName }}}_detail,
{{{ .ModuleName }}}_edit
} from "@/api/{{{ .ModuleName }}}.js";
import {
toast,
alert
} from "@/utils/utils";
let formRef = ref();
let form = ref({});
let rules = {};
let form = ref({
{{{- range .Columns }}}
{{{- if eq (toCamelCase .GoField) $.PrimaryKey }}}
{{{ $.PrimaryKey }}}: '',
{{{- else if .IsEdit }}}
{{{- if eq .HtmlType "checkbox" }}}
{{{ (toCamelCase .GoField) }}}: [],
{{{- else if eq .HtmlType "number" }}}
{{{ (toCamelCase .GoField) }}}: 0,
{{{- else }}}
{{{ (toCamelCase .GoField) }}}: '',
{{{- end }}}
{{{- end }}}
{{{- end }}}
});
const formRules = {
{{{- range .Columns }}}
{{{- if and .IsEdit .IsRequired }}}
{{{ (toCamelCase .GoField) }}}: [
{
required: true,
{{{- if or (eq .HtmlType "checkbox") (eq .HtmlType "datetime") (eq .HtmlType "radio") (eq .HtmlType "select") (eq .HtmlType "imageUpload") }}}
message: '请选择{{{ .ColumnComment }}}',
{{{- else }}}
message: '请输入{{{ .ColumnComment }}}',
{{{- end }}}
trigger: ['blur']
}
],
{{{- end }}}
{{{- end }}}
}
onLoad((e) => {
console.log("onLoad", e);
// form.value = e;
getDetails(e.id);
});
{{{- if ge (len .DictFields) 1 }}}
{{{- $dictSize := sub (len .DictFields) 1 }}}
const { dictData } = useDictData([{{{- range .DictFields }}}'{{{ . }}}'{{{- if ne (index $.DictFields $dictSize) . }}},{{{- end }}}{{{- end }}}])
{{{- end }}}
function getDetails(id) {
equipment_list({
id
})
.then((res) => {
if (res.code == 200) {
// form.value = e;
if (res?.result?.records?.length == 1) {
form.value = res?.result?.records[0];
}
}
})
.catch((err) => {});
{{{ .ModuleName }}}_detail(id).then((res) => {
if (res.code == 200) {
if (res?.result) {
form.value = res?.result
}
} else {
toast(res.message);
}
})
.catch((err) => {
toast(err.message||"网络错误");
});
}
function submit(item) {
console.log("submit", form);
equipment_edit(form.value).then((res) => {
if (res.code == 200) {
toast("编辑成功");
getDetails(form.value?.id);
} else {
toast(res.message);
}
});
formRef.value.validate().then(() => {
{{{ .ModuleName }}}_edit(form.value).then((res) => {
if (res.code == 200) {
toast("编辑成功");
getDetails(form.value?.id);
} else {
toast(res.message);
}
});
})
}
</script>

View File

@@ -33,9 +33,9 @@
:key="item.id"
clickable
show-arrow
:title="item.name"
:note="item.placedPostion+'('+item.placedName+')'"
:right-text="item.status == 1 ? '在线' : ''"
:title="item.id"
:note="item.id"
:right-text="item.id"
@click="toDetails(item)"
></uv-list-item>
</uv-list>
@@ -65,7 +65,7 @@ import {
onReachBottom,
onPageScroll,
} from "@dcloudio/uni-app";
import { equipment_list } from "@/api/equipment.js";
import { {{{ .ModuleName }}}_list } from "@/api/{{{ .ModuleName }}}.js";
import { usePaging } from "@/utils/usePaging";
import { toPath } from "@/utils/utils";
const queryParams = reactive({
@@ -74,7 +74,7 @@ const queryParams = reactive({
});
let fromSearch=ref(false);
onLoad((e) => {
console.log("equipment onLoad", e);
console.log("{{{ .ModuleName }}} onLoad", e);
if (e) {
for (const key in e) {
if (Object.hasOwnProperty.call(e, key)) {
@@ -86,7 +86,7 @@ onLoad((e) => {
getLists();
});
const { pager, getLists, NextPage, resetPage, resetParams } = usePaging({
fetchFun: equipment_list,
fetchFun: {{{ .ModuleName }}}_list,
params: queryParams,
});
let scrollTop = ref(0);
@@ -101,10 +101,10 @@ onReachBottom(() => {
});
function toDetails(item) {
toPath("/pages/equipment/details", { id: item.id });
toPath("/pages/{{{ .ModuleName }}}/details", { id: item.id });
}
function moreSearch() {
toPath("/pages/equipment/search");
toPath("/pages/{{{ .ModuleName }}}/search");
}
</script>

View File

@@ -2,14 +2,6 @@
<template>
<view class="page-content">
<uv-form labelPosition="left" labelWidth="80" :model="form" ref="formRef">
<!-- <uv-form-item label="所属产品" prop="productId" borderBottom>
<x-picker valueKey="id" labelKey="name" :columns="fotaProductList" v-model="form.productId"></x-picker>
</uv-form-item>
<uv-form-item label="所属产品" prop="groupId" borderBottom>
<x-picker valueKey="id" labelKey="name" :columns="showFotaGroupList" v-model="form.groupId"></x-picker>
</uv-form-item> -->
<uv-form-item label="在线状态" prop="status" borderBottom>
<x-picker valueKey="value" labelKey="label" :columns="dictData.devices_status"
v-model="form.status"></x-picker>
@@ -98,27 +90,6 @@
toPath("/pages/equipment/equipment", search);
}
// const fotaProductList = ref([]);
// const fotaGroupList = ref([]);
// const showFotaGroupList = computed(() => {
// return fotaGroupList.value.filter((item) => {
// if (form.value.productId === "") {
// return true;
// }
// return item.productId == form.value.productId;
// });
// });
// function getList() {
// product_listAll().then((r) => {
// fotaProductList.value = r.result;
// });
// group_listAll().then((r) => {
// fotaGroupList.value = r.result;
// });
// }
// getList();
</script>
<style lang="scss" scoped>

View File

@@ -168,6 +168,7 @@ func (tu templateUtil) GetTemplatePaths(genTpl string) []string {
"uniapp/api.ts.tpl",
"uniapp/edit.vue.tpl",
"uniapp/index.vue.tpl",
"uniapp/details.vue.tpl",
"uniapp/search.vue.tpl",
}
if genTpl == GenConstants.TplCrud {
@@ -222,10 +223,11 @@ func (tu templateUtil) GetFilePaths(tplCodeMap map[string]string, ModuleName str
"vue/index.vue.tpl": strings.Join([]string{"admin/src/views/", ModuleName, "/index.vue"}, ""), // "admin/src/views/%s/index.vue",
"vue/index-tree.vue.tpl": strings.Join([]string{"admin/src/views/", ModuleName, "/index-tree.vue"}, ""), // "admin/src/views/%s/index-tree.vue",
"uniapp/api.ts.tpl": strings.Join([]string{"uniapp/src/api/", ModuleName, ".ts"}, ""), // "admin/src/api/%s.ts",
"uniapp/edit.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/edit.vue"}, ""), // "uniapp/pages/%s/edit.vue",
"uniapp/index.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/index.vue"}, ""), // "uniapp/pages/%s/index.vue",
"uniapp/search.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/search.vue"}, ""), // "uniapp/pages/%s/index-tree.vue",
"uniapp/api.ts.tpl": strings.Join([]string{"uniapp/src/api/", ModuleName, ".ts"}, ""),
"uniapp/edit.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/edit.vue"}, ""),
"uniapp/index.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/index.vue"}, ""),
"uniapp/search.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/search.vue"}, ""),
"uniapp/details.vue.tpl": strings.Join([]string{"uniapp/pages/", ModuleName, "/details.vue"}, ""),
}
filePath := make(map[string]string)
for tplPath, tplCode := range tplCodeMap {