shuishen
2023-12-15 10964ea959757a6cc2871ae769bd4687595eac80
src/views/tool/code.vue
@@ -1,45 +1,20 @@
<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :permission="permissionList"
               :page.sync="page"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               :before-open="beforeOpen"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
        <avue-crud :option="option" :table-loading="loading" :data="data" ref="crud" v-model="form"
            :permission="permissionList" :page.sync="page" @row-del="rowDel" @row-update="rowUpdate" @row-save="rowSave"
            :before-open="beforeOpen" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   v-if="permission.code_delete"
                   plain
                <el-button type="danger" size="small" icon="el-icon-delete" v-if="permission.code_delete" plain
                   @click="handleDelete">删 除
        </el-button>
        <el-button type="primary"
                   size="small"
                   plain
                   icon="el-icon-refresh"
                   @click="handleBuild">代码生成
                <el-button type="primary" size="small" plain icon="el-icon-refresh" @click="handleBuild">代码生成
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text"
                   size="small"
                   icon="el-icon-document-copy"
                   v-if="permission.code_edit"
                   class="none-border"
                   @click.stop="handleCopy(scope.row)">复制
                <el-button type="text" size="small" icon="el-icon-document-copy" v-if="permission.code_edit"
                    class="none-border" @click.stop="handleCopy(scope.row)">复制
        </el-button>
      </template>
    </avue-crud>
@@ -47,11 +22,11 @@
</template>
<script>
  import {getList, getCode, build, remove, add, update, copy} from "@/api/tool/code";
  import {getDetail as modelDetail, prototypeDetail} from "@/api/tool/model";
  import {templateDic} from "@/const/tool/model";
  import {validatenull} from "@/util/validate";
  import {mapGetters} from "vuex";
import { getList, getCode, build, remove, add, update, copy } from "@/api/tool/code"
import { getDetail as modelDetail, prototypeDetail } from "@/api/tool/model"
import { templateDic } from "@/const/tool/model"
import { validatenull } from "@/util/validate"
import { mapGetters } from "vuex"
  export default {
    data() {
@@ -76,7 +51,7 @@
          index: true,
          selection: true,
          labelWidth: 120,
          menuWidth: 300,
                menuWidth: 280,
          viewBtn: true,
          dialogClickModal: false,
          tabs: true,
@@ -391,71 +366,71 @@
          ]
        },
        data: []
      };
        }
    },
    watch: {
      'form.modelId'() {
        if (!validatenull(this.form.modelId)) {
          // 获取数据模型信息
          modelDetail(this.form.modelId).then(res => {
            const result = res.data;
                    const result = res.data
            if (result.success) {
              const {modelName, modelTable, modelCode} = result.data;
                        const { modelName, modelTable, modelCode } = result.data
              if (validatenull(this.form.tablePrefix)) {
                this.form.tablePrefix = modelTable.split("_")[0] + "_";
                            this.form.tablePrefix = modelTable.split("_")[0] + "_"
              }
              if (validatenull(this.form.tableName)) {
                this.form.tableName = modelTable;
                            this.form.tableName = modelTable
              }
              if (validatenull(this.form.codeName)) {
                this.form.codeName = modelName;
                            this.form.codeName = modelName
              }
              if (validatenull(this.form.serviceName)) {
                this.form.serviceName = `blade-${modelCode}`;
                            this.form.serviceName = `blade-${modelCode}`
              }
              if (validatenull(this.form.pkName)) {
                this.form.pkName = "id";
                            this.form.pkName = "id"
              }
              if (validatenull(this.form.packageName)) {
                this.form.packageName = `org.springblade.modules.${modelCode}`;
                            this.form.packageName = `org.springblade.modules.${modelCode}`
              }
              if (validatenull(this.form.subFkId) && !validatenull(this.form.tablePrefix)) {
                this.form.subFkId = modelTable.replace(this.form.tablePrefix, "") + "_id";
                            this.form.subFkId = modelTable.replace(this.form.tablePrefix, "") + "_id"
              }
              // 获取数据原型信息
              prototypeDetail(this.form.modelId).then(res => {
                const result = res.data;
                            const result = res.data
                if (result.success) {
                  const columnTreeId = this.findObject(this.option.group, "treeId");
                  const columnTreePid = this.findObject(this.option.group, "treePid");
                  const columnTreeName = this.findObject(this.option.group, "treeName");
                  columnTreeId.dicData = result.data;
                  columnTreePid.dicData = result.data;
                  columnTreeName.dicData = result.data;
                                const columnTreeId = this.findObject(this.option.group, "treeId")
                                const columnTreePid = this.findObject(this.option.group, "treePid")
                                const columnTreeName = this.findObject(this.option.group, "treeName")
                                columnTreeId.dicData = result.data
                                columnTreePid.dicData = result.data
                                columnTreeName.dicData = result.data
                }
              });
                        })
            }
          });
                })
        }
      },
      'form.templateType'() {
        // 模版类型
        const type = this.form.templateType;
            const type = this.form.templateType
        // 主子表字段显隐
        const columnSubModelId = this.findObject(this.option.group, "subModelId");
        const columnSubFkId = this.findObject(this.option.group, "subFkId");
        columnSubModelId.display = type === "sub";
        columnSubFkId.display = type === "sub";
            const columnSubModelId = this.findObject(this.option.group, "subModelId")
            const columnSubFkId = this.findObject(this.option.group, "subFkId")
            columnSubModelId.display = type === "sub"
            columnSubFkId.display = type === "sub"
        // 树表字段显隐
        const columnTreeId = this.findObject(this.option.group, "treeId");
        const columnTreePid = this.findObject(this.option.group, "treePid");
        const columnTreeName = this.findObject(this.option.group, "treeName");
        columnTreeId.display = type === "tree";
        columnTreePid.display = type === "tree";
        columnTreeName.display = type === "tree";
            const columnTreeId = this.findObject(this.option.group, "treeId")
            const columnTreePid = this.findObject(this.option.group, "treePid")
            const columnTreeName = this.findObject(this.option.group, "treeName")
            columnTreeId.display = type === "tree"
            columnTreePid.display = type === "tree"
            columnTreeName.display = type === "tree"
      }
    },
@@ -467,42 +442,42 @@
          viewBtn: this.vaildData(this.permission.code_view, false),
          delBtn: this.vaildData(this.permission.code_delete, false),
          editBtn: this.vaildData(this.permission.code_edit, false)
        };
            }
      },
      ids() {
        let ids = [];
            let ids = []
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
                ids.push(ele.id)
            })
            return ids.join(",")
      }
    },
    methods: {
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
                this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
                })
                done()
        }, error => {
          window.console.log(error);
          loading();
        });
                window.console.log(error)
                loading()
            })
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
                this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
                })
                done()
        }, error => {
          window.console.log(error);
          loading();
        });
                window.console.log(error)
                loading()
            })
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
@@ -511,37 +486,37 @@
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
                    return remove(row.id)
          })
          .then(() => {
            this.onLoad(this.page);
                    this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
                    })
                })
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
            this.query = {}
            this.onLoad(this.page)
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
            this.query = params
            this.page.currentPage = 1
            this.onLoad(this.page, params)
            done()
      },
      selectionChange(list) {
        this.selectionList = list;
            this.selectionList = list
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
            this.selectionList = []
            this.$refs.crud.toggleSelection()
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
                this.$message.warning("请选择至少一条数据")
                return
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
@@ -549,21 +524,21 @@
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
                    return remove(this.ids)
          })
          .then(() => {
            this.onLoad(this.page);
                    this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
                    })
                    this.$refs.crud.toggleSelection()
                })
      },
      handleBuild() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
                this.$message.warning("请选择至少一条数据")
                return
        }
        this.$confirm("是否生成选中模块的代码?", {
          title: "代码生成确认",
@@ -572,53 +547,53 @@
          type: "warning"
        })
          .then(() => {
            return build(this.ids);
                    return build(this.ids)
          })
          .then(() => {
            this.onLoad(this.page);
                    this.onLoad(this.page)
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
                    })
                    this.$refs.crud.toggleSelection()
                })
      },
      handleCopy(row) {
        copy(row.id).then(() => {
          this.onLoad(this.page);
                this.onLoad(this.page)
          this.$message({
            type: "success",
            message: "复制成功!"
          });
        });
                })
            })
      },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getCode(this.form.id).then(res => {
            this.form = res.data.data;
          });
                    this.form = res.data.data
                })
        }
        done();
            done()
      },
      currentChange(currentPage) {
        this.page.currentPage = currentPage;
            this.page.currentPage = currentPage
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize;
            this.page.pageSize = pageSize
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
            this.onLoad(this.page, this.query)
      },
      onLoad(page, params = {}) {
        this.loading = true;
            this.loading = true
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
                const data = res.data.data
                this.page.total = data.total
                this.data = data.records
                this.loading = false
                this.selectionClear()
            })
      }
    }
  };
}
</script>