若依 uniapp 端代码生成

自己写了个若依App端的代码生成,给大家分享一下(本人菜鸟,如有错误请各位大佬指正)

效果:

树表

展示

树表 新增、修改

单表

展示:

单表(新增修改)

实现代码(用到了uni-ui)

在代码生成模块的resources中新建uniapp文件夹

uniapp(树表)uniapp-tree.vue.vm

<template>
  <view>
    <uni-nav-bar shadow left-icon="left" :fixed="true" :statusBar="true" :border="false"
                 v-if="hasPerimission(['${moduleName}:${businessName}:add'])"
                 rightText="+新增" @clickLeft="clickLeft" @clickRight="handleAdd"  title="${functionName}" />
    <uni-nav-bar shadow left-icon="left" :fixed="true" :statusBar="true" :border="false"
                 v-else
                 @clickLeft="clickLeft" title="${functionName}" />
    <ly-tree :tree-data="${businessName}List" :ready="!loading" node-key="${treeCode}"
             :hasPerimissionObject="hasPerimissionObject" @delete-click="handleDelete"
        #foreach($column in $columns)
            #set($field=$column.javaField)
            #if($column.insert && !$column.pk)
                #if(($column.usableColumn) || (!$column.superColumn))
                    #set($parentheseIndex=$column.columnComment.indexOf("("))
                    #if($parentheseIndex != -1)
                        #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                    #else
                        #set($comment=$column.columnComment)
                    #end
                    #set($dictType=$column.dictType)
                    #if($column.htmlType == "imageUpload")
             :showNodeIcon="true"
                    #end
                #end
            #end
        #end


             @add-click="handleAdd" @update-click="handleUpdate"  :props="props">
    </ly-tree>
    <!-- 普通弹窗 -->
    <uni-popup ref="popup" background-color="#fff" >
      <!-- 添加或修改${functionName}对话框 -->
      <uni-forms ref="form" :rules="rules" :modelValue="form" :label-width="120" class="margin-top">
          #foreach($column in $columns)
              #set($field=$column.javaField)
              #if($column.insert && !$column.pk)
                  #if(($column.usableColumn) || (!$column.superColumn))
                      #set($parentheseIndex=$column.columnComment.indexOf("("))
                      #if($parentheseIndex != -1)
                          #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                      #else
                          #set($comment=$column.columnComment)
                      #end
                      #set($dictType=$column.dictType)
                      #if("" != $treeParentCode && $column.javaField == $treeParentCode)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end  name="${field}">
                          <uni-data-picker v-model="form.${treeParentCode}" :localdata="${businessName}Options"
                                           popup-title="请选择${comment}" :map="{text:'${treeName}',value:'${treeCode}'}" />
                        </uni-forms-item>
                      #elseif($column.htmlType == "input")
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end  name="${field}">
                          <uni-easyinput v-model="form.${field}" placeholder="请输入${comment}" />
                        </uni-forms-item>
                      #elseif($column.htmlType == "imageUpload")
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <image-upload v-model="form.${field}"/>
                        </uni-forms-item>
                      #elseif($column.htmlType == "fileUpload")
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <file-upload v-model="form.${field}"/>
                        </uni-forms-item>
                      #elseif($column.htmlType == "editor")
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <my-editor v-model="form.${field}"/>
                        </uni-forms-item>
                      #elseif($column.htmlType == "select" && "" != $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <uni-data-picker placeholder="请选择${comment}"
                                           :localdata="dict.type.${dictType}"
                              #if($column.javaType == "Integer" || $column.javaType == "Long")
                                           :value="parseInt(dict.value)"
                              #else
                                           :value="dict.value"
                              #end
                                           v-model="form.${field}"
                                           :map="{text:'label',value:'value'}">
                          </uni-data-picker>
                        </uni-forms-item>
                      #elseif($column.htmlType == "select" && $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          请选择字典生成
                        </uni-forms-item>
                      #elseif($column.htmlType == "checkbox" && "" != $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <uni-data-checkbox multiple v-model="form.${field}" :localdata="dict.type.${dictType}"  :map="{text:'label',value:'value'}"></uni-data-checkbox>
                        </uni-forms-item>
                      #elseif($column.htmlType == "checkbox" && $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          请选择字典生成
                        </uni-forms-item>
                      #elseif($column.htmlType == "radio" && "" != $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <uni-data-checkbox v-model="form.${field}" :localdata="dict.type.${dictType}"  :map="{text:'label',value:'value'}"></uni-data-checkbox>
                        </uni-forms-item>
                      #elseif($column.htmlType == "radio" && $dictType)
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          请选择字典生成
                        </uni-forms-item>
                      #elseif($column.htmlType == "datetime")
                        <el-form-item label="${comment}" prop="${field}">
                          <el-date-picker clearable
                                          v-model="form.${field}"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="请选择${comment}">
                          </el-date-picker>
                        </el-form-item>
                      #elseif($column.htmlType == "textarea")
                        <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                          <uni-easyinput type="textarea" v-model="form.${field}" placeholder="请输入内容"></uni-easyinput>
                        </uni-forms-item>
                      #end
                  #end
              #end
          #end
          #if($table.sub)
            <el-divider content-position="center">${subTable.functionName}信息</el-divider>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
              </el-col>
            </el-row>
            <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
              <el-table-column type="selection" width="50" align="center" />
              <el-table-column label="序号" align="center" prop="index" width="50"/>
                #foreach($column in $subTable.columns)
                    #set($javaField=$column.javaField)
                    #set($parentheseIndex=$column.columnComment.indexOf("("))
                    #if($parentheseIndex != -1)
                        #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                    #else
                        #set($comment=$column.columnComment)
                    #end
                    #if($column.pk || $javaField == ${subTableFkclassName})
                    #elseif($column.list && $column.htmlType == "input")
                      <el-table-column label="$comment" prop="${javaField}" width="150">
                        <template slot-scope="scope">
                          <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" />
                        </template>
                      </el-table-column>
                    #elseif($column.list && $column.htmlType == "datetime")
                      <el-table-column label="$comment" prop="${javaField}" width="240">
                        <template slot-scope="scope">
                          <el-date-picker clearable v-model="scope.row.$javaField" type="date" value-format="yyyy-MM-dd" placeholder="请选择$comment" />
                        </template>
                      </el-table-column>
                    #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" != $column.dictType)
                      <el-table-column label="$comment" prop="${javaField}" width="150">
                        <template slot-scope="scope">
                          <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
                            <el-option
                                v-for="dict in dict.type.$column.dictType"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            ></el-option>
                          </el-select>
                        </template>
                      </el-table-column>
                    #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" == $column.dictType)
                      <el-table-column label="$comment" prop="${javaField}" width="150">
                        <template slot-scope="scope">
                          <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
                            <el-option label="请选择字典生成" value="" />
                          </el-select>
                        </template>
                      </el-table-column>
                    #end
                #end
            </el-table>
          #end
      </uni-forms>
      <button type="primary" @click="submitForm()">提交</button>
    </uni-popup>
  </view>
</template>

<script>
  import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
  export default {
    name: "${BusinessName}",
      #if(${dicts} != '')
        dicts: [${dicts}],
      #end
    data() {
      return {
        //   数据对应的属性
        props: {
          label: '${treeName}', // 指把数据中的‘personName’当做label也就是节点名称
          children: 'children',// 指把数据中的‘childs’当做children当做子节点数据
            #foreach($column in $columns)
                #set($field=$column.javaField)
                #if($column.insert && !$column.pk)
                    #if(($column.usableColumn) || (!$column.superColumn))
                        #set($parentheseIndex=$column.columnComment.indexOf("("))
                        #if($parentheseIndex != -1)
                            #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                        #else
                            #set($comment=$column.columnComment)
                        #end
                        #set($dictType=$column.dictType)
                        #if($column.htmlType == "imageUpload")
                          icon:'${field}'
                        #end
                    #end
                #end
            #end
        },
        //   权限
        hasPerimissionObject:{
          add: '${moduleName}:${businessName}:add',
          update: '${moduleName}:${businessName}:edit',
          delete: '${moduleName}:${businessName}:remove'
        },
        // 遮罩层
        loading: true,
        // 显示搜索条件
        showSearch: true,
        // ${functionName}表格数据
              ${businessName}List: [],
        // ${functionName}树选项
              ${businessName}Options: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否展开,默认全部展开
        isExpandAll: true,
        // 重新渲染表格状态
        refreshTable: true,
          #foreach ($column in $columns)
              #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
                  #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
                // $comment时间范围
                daterange${AttrName}: [],
              #end
          #end
        // 查询参数
        queryParams: {
            #foreach ($column in $columns)
                #if($column.query)
                        $column.javaField: null#if($foreach.count != $columns.size()),#end
                #end
            #end
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
            #foreach ($column in $columns)
                #if($column.required)
                    #set($parentheseIndex=$column.columnComment.indexOf("("))
                    #if($parentheseIndex != -1)
                        #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                    #else
                        #set($comment=$column.columnComment)
                    #end
                        $column.javaField: {
                    rules: [{ required: true, errorMessage: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
                    ]
                  }#if($foreach.count != $columns.size()),#end
                #end
            #end
        }
      };
    },
    onLoad() {
      this.getList();
    },
    // 下拉
    onPullDownRefresh() {
      this.${businessName}List = [];
      //调用获取数据方法
      this.getList();
      setTimeout(() => {
        //结束下拉刷新
        uni.stopPullDownRefresh();
      }, 200);
    },
    methods: {
      /** 返回 */
      clickLeft(){
        this.$tab.navigateBack();
      },
      // 弹窗开启
      toggle() {
        // open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
        this.$refs.popup.open("bottom")
      },
      /** 查询${functionName}列表 */
      getList() {
        this.loading = true;
          #foreach ($column in $columns)
              #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
                this.queryParams.params = {};
                  #break
              #end
          #end
          #foreach ($column in $columns)
              #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
                  #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
                if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
                  this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
                  this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
                }
              #end
          #end
        list${BusinessName}(this.queryParams).then(response => {
          this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
          this.loading = false;
        });
      },
      /** 转换${functionName}数据结构 */
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.${treeCode},
          label: node.${treeName},
          children: node.children
        };
      },
      /** 查询${functionName}下拉树结构 */
      getTreeselect() {
        list${BusinessName}().then(response => {
          this.${businessName}Options = [];
          const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
          data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
          this.${businessName}Options.push(data);
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
            #foreach ($column in $columns)
                #if($column.htmlType == "checkbox")
                        $column.javaField: []#if($foreach.count != $columns.size()),#end
                #else
                        $column.javaField: null#if($foreach.count != $columns.size()),#end
                #end
            #end
        };
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
          #foreach ($column in $columns)
              #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
                  #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
                this.daterange${AttrName} = [];
              #end
          #end
        this.handleQuery();
      },
      /** 新增按钮操作 */
      handleAdd(row) {
        this.reset();
        this.getTreeselect();
        if (row != null && row.${treeCode}) {
          this.form.${treeParentCode} = row.${treeCode};
        } else {
          this.form.${treeParentCode} = 0;
        }
        this.toggle();
        this.title = "添加${functionName}";
      },
      /** 展开/折叠操作 */
      toggleExpandAll() {
        this.refreshTable = false;
        this.isExpandAll = !this.isExpandAll;
        this.$nextTick(() => {
          this.refreshTable = true;
        });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.getTreeselect();
        if (row != null) {
          this.form.${treeParentCode} = row.${treeParentCode};
        }
        get${BusinessName}(row.${pkColumn.javaField}).then(response => {
          this.form = response.data;
            #foreach ($column in $columns)
                #if($column.htmlType == "checkbox")
                  this.form.$column.javaField = this.form.${column.javaField}.split(",");
                #end
            #end
          this.toggle();
          this.title = "修改${functionName}";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.#[[$]]#refs["form"].validate().then(res => {
          #foreach ($column in $columns)
          #if($column.htmlType == "checkbox")
          this.form.$column.javaField = this.form.${column.javaField}.join(",");
          #end
          #end
          #if($table.sub)
          this.form.${subclassName}List = this.${subclassName}List;
          #end
          if (this.form.${pkColumn.javaField} != null) {
            update${BusinessName}(this.form).then(response => {
              this.#[[$modal]]#.msgSuccess("修改成功");
              this.$refs.popup.close()
              this.getList();
            });
          } else {
            add${BusinessName}(this.form).then(response => {
              this.#[[$modal]]#.msgSuccess("新增成功");
              this.$refs.popup.close()
              this.getList();
            });
          }
        }).catch(err => {
          console.log('err', err);
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        this.#[[$modal]]#.confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?').then(function() {
          return del${BusinessName}(row.${pkColumn.javaField});
        }).then(() => {
          this.getList();
          this.#[[$modal]]#.msgSuccess("删除成功");
        }).catch(() => {});
      }
    }
  };
</script>
<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */
</style>

uniapp(单表展示)uniapp.vue.vm

<template>
  <view class="">
    <uni-nav-bar shadow left-icon="left" :fixed="true" :statusBar="true" :border="false"
                 v-if="hasPerimission(['${moduleName}:${businessName}:add'])"
                 rightText="+新增" @clickLeft="clickLeft" @clickRight="handleAdd"  title="${functionName}" />
    <uni-nav-bar shadow left-icon="left" :fixed="true" :statusBar="true" :border="false"
                 v-else
                 @clickLeft="clickLeft" title="${functionName}" />
    <view>
      <view v-for="(item, index) in ${businessName}List" >
        <uni-card>
            #foreach($column in $columns)
                #set($javaField=$column.javaField)
                #set($parentheseIndex=$column.columnComment.indexOf("("))
                #if($parentheseIndex != -1)
                    #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                #else
                    #set($comment=$column.columnComment)
                #end
                #if($column.list && $column.htmlType == "imageUpload")
                  <view class="flex">
                    <my-image v-model="item.$javaField"/>
                  </view>
                #elseif($column.list && "" != $column.dictType)
                    #if($column.htmlType == "checkbox")
                      <view class="flex">
                          ${comment}:
                        <dict-tag :options="dict.type.${column.dictType}" :value="item.${javaField} ? item.${javaField}.split(',') : []"/>
                      </view>
                    #else
                      <view class="flex">
                          ${comment}:
                        <dict-tag :options="dict.type.${column.dictType}" :value="item.${javaField}"/>

                      </view>
                    #end
                #elseif($column.list && "" != $javaField)
                  <view>
                      $comment:{{item.$javaField}}
                  </view>
                #end
            #end
          <view v-if="hasPerimission(['${moduleName}:${businessName}:edit'])">
            <button @click="handleUpdate(item.${pkColumn.javaField})" class="cu-btn round">修改</button>
          </view>
        </uni-card>
      </view>
      <uni-load-more iconType="circle" :status="status" />
    </view>

  </view>
</template>

<script>
import { list${BusinessName} } from "@/api/${moduleName}/${businessName}";

export default {
  name: "${BusinessName}",
#if(${dicts} != '')
  dicts: [${dicts}],
#end
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
#if($table.sub)
      // 子表选中数据
      checked${subClassName}: [],
#end
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 是否为最后一页
      lastPage: true,
      // 加载状态
      status: 'loading',
      // ${functionName}表格数据
      ${businessName}List: [],
#if($table.sub)
      // ${subTable.functionName}表格数据
      ${subclassName}List: [],
#end
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
      // $comment时间范围
      daterange${AttrName}: [],
#end
#end
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
#foreach ($column in $columns)
#if($column.query)
        $column.javaField: null#if($foreach.count != $columns.size()),#end
#end
#end
      },
    };
  },
  onShow() {
    this.handleQuery();
  },
    // 上拉
  onReachBottom() {
    if (this.lastPage) {

    } else {
      this.queryParams.pageNum++;
      //调用获取数据方法
      this.getList();
    }

  },
  // 下拉
  onPullDownRefresh() {
    this.resetQueryParams();
    this.${businessName}List = [];
    //调用获取数据方法
    this.getList();
    setTimeout(() => {
      //结束下拉刷新
      uni.stopPullDownRefresh();
    }, 200);
  },
  methods: {
    /** 查询${functionName}列表 */
    getList() {
      this.loading = true;
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
      this.queryParams.params = {};
#break
#end
#end
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
      if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
        this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
        this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
      }
#end
#end
      list${BusinessName}(this.queryParams).then(response => {
        this.${businessName}List = this.${businessName}List.concat(response.rows);
        this.total = response.total;
        this.lastPage = response.lastPage;
        this.loading = false;
        if (this.lastPage) {
          this.status = 'noMore';
        } else {
          this.status = 'more';
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 查询表单重置
    resetQueryParams(){
      this.queryParams = {
          pageNum: 1,
          pageSize: 5,
          #foreach ($column in $columns)
              #if($column.htmlType == "checkbox")
                      $column.javaField: []#if($foreach.count != $columns.size()),#end
              #else
                      $column.javaField: null#if($foreach.count != $columns.size()),#end
              #end
          #end
      };
    },
    // 表单重置
    reset() {
      this.form = {
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
        $column.javaField: []#if($foreach.count != $columns.size()),#end
#else
        $column.javaField: null#if($foreach.count != $columns.size()),#end
#end
#end
      };
#if($table.sub)
      this.${subclassName}List = [];
#end
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.${businessName}List = [];
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
      this.daterange${AttrName} = [];
#end
#end
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$tab.navigateTo("/pages/index");
    },
    /** 返回 */
    clickLeftBack(){
      this.$tab.navigateBack();
    },
    /** 修改按钮操作 */
    handleUpdate(id) {
      this.$tab.navigateTo("/pages/index");
    },
  }
};
</script>
<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */
</style>

uniapp(单表修改新增)modify.vue.vm

<template>
  <view class="">
    <uni-nav-bar shadow left-icon="left" :fixed="true" :statusBar="true" :border="false"
                 @clickLeft="clickLeft"  :title="title" />
    <!-- 添加或修改${functionName}对话框 -->
        <uni-forms ref="form" :rules="rules" :modelValue="form" :label-width="120">
            #foreach($column in $columns)
                #set($field=$column.javaField)
                #if($column.insert && !$column.pk)
                    #if(($column.usableColumn) || (!$column.superColumn))
                        #set($parentheseIndex=$column.columnComment.indexOf("("))
                        #if($parentheseIndex != -1)
                            #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                        #else
                            #set($comment=$column.columnComment)
                        #end
                        #set($dictType=$column.dictType)
                        #if($column.htmlType == "input")
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end  name="${field}">
                            <uni-easyinput v-model="form.${field}" placeholder="请输入${comment}" />
                          </uni-forms-item>
                        #elseif($column.htmlType == "imageUpload")
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <image-upload v-model="form.${field}"/>
                          </uni-forms-item>
                        #elseif($column.htmlType == "fileUpload")
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <file-upload v-model="form.${field}"/>
                          </uni-forms-item>
                        #elseif($column.htmlType == "editor")
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <my-editor v-model="form.${field}"/>
                          </uni-forms-item>
                        #elseif($column.htmlType == "select" && "" != $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <uni-data-picker placeholder="请选择${comment}"
                                             :localdata="dict.type.${dictType}"
                                #if($column.javaType == "Integer" || $column.javaType == "Long")
                                             :value="parseInt(dict.value)"
                                #else
                                             :value="dict.value"
                                #end
                                             v-model="form.${field}"
                                             :map="{text:'label',value:'value'}">
                            </uni-data-picker>
                          </uni-forms-item>
                        #elseif($column.htmlType == "select" && $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            请选择字典生成
                          </uni-forms-item>
                        #elseif($column.htmlType == "checkbox" && "" != $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <uni-data-checkbox multiple v-model="form.${field}" :localdata="dict.type.${dictType}"  :map="{text:'label',value:'value'}"></uni-data-checkbox>
                          </uni-forms-item>
                        #elseif($column.htmlType == "checkbox" && $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            请选择字典生成
                          </uni-forms-item>
                        #elseif($column.htmlType == "radio" && "" != $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <uni-data-checkbox v-model="form.${field}" :localdata="dict.type.${dictType}"  :map="{text:'label',value:'value'}"></uni-data-checkbox>
                          </uni-forms-item>
                        #elseif($column.htmlType == "radio" && $dictType)
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            请选择字典生成
                          </uni-forms-item>
                        #elseif($column.htmlType == "datetime")
                          <el-form-item label="${comment}" prop="${field}">
                            <el-date-picker clearable
                                            v-model="form.${field}"
                                            type="date"
                                            value-format="yyyy-MM-dd"
                                            placeholder="请选择${comment}">
                            </el-date-picker>
                          </el-form-item>
                        #elseif($column.htmlType == "textarea")
                          <uni-forms-item label="${comment}" #if($column.isRequired == "1") required #end name="${field}">
                            <uni-easyinput type="textarea" v-model="form.${field}" placeholder="请输入内容"></uni-easyinput>
                          </uni-forms-item>
                        #end
                    #end
                #end
            #end
            #if($table.sub)
              <el-divider content-position="center">${subTable.functionName}信息</el-divider>
              <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                  <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                  <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
                </el-col>
              </el-row>
              <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
                <el-table-column type="selection" width="50" align="center" />
                <el-table-column label="序号" align="center" prop="index" width="50"/>
                  #foreach($column in $subTable.columns)
                      #set($javaField=$column.javaField)
                      #set($parentheseIndex=$column.columnComment.indexOf("("))
                      #if($parentheseIndex != -1)
                          #set($comment=$column.columnComment.substring(0, $parentheseIndex))
                      #else
                          #set($comment=$column.columnComment)
                      #end
                      #if($column.pk || $javaField == ${subTableFkclassName})
                      #elseif($column.list && $column.htmlType == "input")
                        <el-table-column label="$comment" prop="${javaField}" width="150">
                          <template slot-scope="scope">
                            <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" />
                          </template>
                        </el-table-column>
                      #elseif($column.list && $column.htmlType == "datetime")
                        <el-table-column label="$comment" prop="${javaField}" width="240">
                          <template slot-scope="scope">
                            <el-date-picker clearable v-model="scope.row.$javaField" type="date" value-format="yyyy-MM-dd" placeholder="请选择$comment" />
                          </template>
                        </el-table-column>
                      #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" != $column.dictType)
                        <el-table-column label="$comment" prop="${javaField}" width="150">
                          <template slot-scope="scope">
                            <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
                              <el-option
                                  v-for="dict in dict.type.$column.dictType"
                                  :key="dict.value"
                                  :label="dict.label"
                                  :value="dict.value"
                              ></el-option>
                            </el-select>
                          </template>
                        </el-table-column>
                      #elseif($column.list && ($column.htmlType == "select" || $column.htmlType == "radio") && "" == $column.dictType)
                        <el-table-column label="$comment" prop="${javaField}" width="150">
                          <template slot-scope="scope">
                            <el-select v-model="scope.row.$javaField" placeholder="请选择$comment">
                              <el-option label="请选择字典生成" value="" />
                            </el-select>
                          </template>
                        </el-table-column>
                      #end
                  #end
              </el-table>
            #end
        </uni-forms>
        <button type="primary" @click="submitForm()">提交</button>
  </view>
</template>

<script>
import {  get${BusinessName},  add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";

export default {
  name: "${BusinessName}",
#if(${dicts} != '')
  dicts: [${dicts}],
#end
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
#if($table.sub)
      // 子表选中数据
      checked${subClassName}: [],
#end
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // ${functionName}表格数据
      ${businessName}List: [],
#if($table.sub)
      // ${subTable.functionName}表格数据
      ${subclassName}List: [],
#end
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
      // $comment时间范围
      daterange${AttrName}: [],
#end
#end
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
#foreach ($column in $columns)
#if($column.query)
        $column.javaField: null#if($foreach.count != $columns.size()),#end
#end
#end
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
#foreach ($column in $columns)
#if($column.required)
#set($parentheseIndex=$column.columnComment.indexOf("("))
#if($parentheseIndex != -1)
#set($comment=$column.columnComment.substring(0, $parentheseIndex))
#else
#set($comment=$column.columnComment)
#end
        $column.javaField: {
            rules: [{ required: true, errorMessage: "$comment不能为空", trigger: #if($column.htmlType == "select" || $column.htmlType == "radio")"change"#else"blur"#end }
        ]
  }#if($foreach.count != $columns.size()),#end
#end
#end
      }
    };
  },
  onLoad(options) {
    if (options.${pkColumn.javaField}) {
      this.handleUpdate(options)
    }else{
      this.handleAdd()
    }
  },
  methods: {
    /** 返回 */
    clickLeft(){
      this.$tab.navigateBack();
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
        $column.javaField: []#if($foreach.count != $columns.size()),#end
#else
        $column.javaField: null#if($foreach.count != $columns.size()),#end
#end
#end
      };
#if($table.sub)
      this.${subclassName}List = [];
#end
    },


    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.title = "添加${functionName}";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
      get${BusinessName}(${pkColumn.javaField}).then(response => {
        this.form = response.data;
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
        this.form.$column.javaField = this.form.${column.javaField}.split(",");
#end
#end
#if($table.sub)
        this.${subclassName}List = response.data.${subclassName}List;
#end
        this.open = true;
        this.title = "修改${functionName}";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.#[[$]]#refs["form"].validate().then(res => {
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
      this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end
#end
#if($table.sub)
      this.form.${subclassName}List = this.${subclassName}List;
#end
      if (this.form.${pkColumn.javaField} != null) {
          update${BusinessName}(this.form).then(response => {
              this.#[[$modal]]#.msgSuccess("修改成功");
              this.open = false;
              this.handleUpdate(this.form);
          });
      } else {
          add${BusinessName}(this.form).then(response => {
              this.#[[$modal]]#.msgSuccess("新增成功");
              this.open = false;
                setTimeout(() => {
                  //结束下拉刷新
                  this.clickLeft();
                }, 500);
          });
      }
      }).catch(err => {
        console.log('err', err);
      })

    },
  }
};
</script>
<style lang="scss">
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */
</style>

找到 VelocityUtils.java中的getTemplateList方法如下修改 这里只修改了预览

public static List<String> getTemplateList(String tplCategory, String tplWebType)
    {
        String useWebType = "vm/vue";
        if ("element-plus".equals(tplWebType))
        {
            useWebType = "vm/vue/v3";
        }
        List<String> templates = new ArrayList<String>();
        templates.add("vm/java/domain.java.vm");
        templates.add("vm/java/mapper.java.vm");
        templates.add("vm/java/service.java.vm");
        templates.add("vm/java/serviceImpl.java.vm");
        templates.add("vm/java/controller.java.vm");
        templates.add("vm/xml/mapper.xml.vm");
        templates.add("vm/sql/sql.vm");
        templates.add("vm/js/api.js.vm");

        if (GenConstants.TPL_CRUD.equals(tplCategory))
        {
            templates.add("vm/uniapp/uniapp.vue.vm");
            templates.add("vm/uniapp/modify.vue.vm");
            templates.add("vm/uniapp/details.vue.vm");
            templates.add(useWebType + "/index.vue.vm");
        }
        else if (GenConstants.TPL_TREE.equals(tplCategory))
        {
            templates.add("vm/uniapp/uniapp-tree.vue.vm");
            templates.add(useWebType + "/index-tree.vue.vm");
        }
        else if (GenConstants.TPL_SUB.equals(tplCategory))
        {
            templates.add(useWebType + "/index.vue.vm");
            templates.add("vm/java/sub-domain.java.vm");
        }
        return templates;
    }

  • 7
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值