田源
2025-01-16 404966637eda6881a0f17683c5aacc7c1c34aed8
Source/plt-web/plt-web-ui/src/views/modelingMenu/modeling/enumType/index.vue
@@ -1,117 +1,190 @@
<template>
  <basic-container>
    <avue-crud
      ref="userCrud"
      :data="tableData"
      :option="option"
      :table-loading="tableLoading"
      @on-load="getTableList"
      @refresh-change="handleRefresh"
      @search-change="handleSearch"
      @search-reset="handleReset"
      @selection-change="selectChange"
      @row-click="rowClickHandler"
    >
  <el-container>
    <el-main>
      <basic-container>
        <avue-crud
          ref="userCrud"
          :data="tableData"
          :option="option"
          :table-loading="tableLoading"
          @on-load="getTableList"
          @refresh-change="handleRefresh"
          @search-change="handleSearch"
          @search-reset="handleReset"
          @selection-change="selectChange"
          @row-click="rowClickHandler"
        >
      <template slot="menuLeft" slot-scope="scope">
        <el-button icon="el-icon-plus" size="small" type="primary" @click="rowSaveHandlerClick">创建</el-button>
        <el-button icon="el-icon-delete" plain size="small" type="danger" @click="allDelHandler">删除</el-button>
        <el-button icon="el-icon-view" plain size="small" type="primary" @click="chekView">查看使用范围</el-button>
        <el-button icon="el-icon-download" plain size="small" type="primary" @click="downloadTemplateHandler">下载导入模板
        </el-button>
        <el-button icon="el-icon-download" plain size="small" type="primary" @click="downloadHandler">导出</el-button>
        <el-button icon="el-icon-upload2" plain size="small" type="primary" @click="uploadUser">导入</el-button>
      </template>
          <template slot="menuLeft" slot-scope="scope">
            <el-button v-if="permissionList.addBtn" class="button-custom-icon" plain size="small" type="primary"
                       @click="rowSaveHandlerClick">
              <icon-show :name="permissionList.addBtn.source"></icon-show>
              创建
            </el-button>
            <el-button v-if="permissionList.delBtn" class="button-custom-icon" plain size="small" type="danger"
                       @click="allDelHandler">
              <icon-show :name="permissionList.delBtn.source"></icon-show>
              删除
            </el-button>
            <el-button v-if="permissionList.viewTheScopeBtn" class="button-custom-icon" plain size="small"
                       type="primary"
                       @click="chekView">
              <icon-show :name="permissionList.viewTheScopeBtn.source"></icon-show>
              查看使用范围
            </el-button>
            <el-button v-if="permissionList.downloadImportTemplateBtn" class="button-custom-icon" plain size="small"
                       type="primary" @click="downloadTemplateHandler">
              <icon-show :name="permissionList.downloadImportTemplateBtn.source"></icon-show>
              下载导入模板
            </el-button>
            <el-button v-if="permissionList.importBtn" class="button-custom-icon" plain size="small" type="primary"
                       @click="uploadUser">
              <icon-show :name="permissionList.importBtn.source"></icon-show>
              导入
            </el-button>
            <el-button v-if="permissionList.exportBtn" class="button-custom-icon" plain size="small" type="primary"
                       @click="downloadHandler">
              <icon-show :name="permissionList.exportBtn.source"></icon-show>
              导出
            </el-button>
          </template>
      <template slot="menu" slot-scope="scope">
        <el-button icon="el-icon-edit" size="small" type="text" @click="editBtnClick(scope.row)">编辑
        </el-button>
        <el-button icon="el-icon-delete" size="small" type="text" @click="rowDeleteHandler(scope.row)">删除
        </el-button>
      </template>
          <template slot="menu" slot-scope="scope">
            <el-button v-if="permissionList.editBtn" size="small" type="text"
                       @click="editBtnClick(scope.row)">
              <icon-show :name="permissionList.editBtn.source"></icon-show>
                编辑
            </el-button>
            <el-button v-if="permissionList.delBtn" size="small" type="text"
                       @click="rowDeleteHandler(scope.row)">
              <icon-show :name="permissionList.delBtn.source"></icon-show>
              删除
            </el-button>
          </template>
    </avue-crud>
    <!-- 创建编辑自定义对话框    -->
    <el-dialog
      v-dialogDrag
      v-loading="dialogLoading"
      :title="dialogType === 'add' ? ' 创建' : '编辑'"
      :visible.sync="dialogVisible"
      append-to-body="true"
      class="avue-dialog"
      width="70%"
      @close="dialogClose"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="名称:" prop="id">
              <el-input v-model="form.id"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标签:">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型:">
              <el-select v-model="form.enumValueDataType" placeholder="请选择类型">
                <el-option label="String" value="String"></el-option>
                <el-option label="Integer" value="Integer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="长度:">
              <el-input-number v-model="form.length" :max="999" :min="1" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <avue-crud
              ref="dialogCrud"
              :data="dialogData"
              :option="dialogOption"
              @row-save="rowSaveDialogHandler"
              @row-update="rowUpdateDialogHandler"
              @row-del="rowDeleteDialogHandler"
            >
            </avue-crud>
          </el-col>
        </el-row>
      </el-form>
        </avue-crud>
        <!-- 创建编辑自定义对话框    -->
        <el-dialog
          v-dialogDrag
          v-loading="dialogLoading"
          :title="dialogType === 'add' ? ' 创建' : '编辑'"
          :visible.sync="dialogVisible"
          append-to-body="true"
          class="avue-dialog"
          width="1000px"
          @close="dialogClose"
        >
          <el-form ref="form" :model="form" :rules="rules" label-width="100px" size="small">
            <el-row>
              <el-col :span="12">
                <el-form-item label="枚举名称:" prop="id">
                  <el-input v-model="form.id"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="标签:">
                  <el-input v-model="form.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="类型:">
                  <el-select v-model="form.enumValueDataType" placeholder="请选择类型" style="width: 376px;">
                    <el-option label="String" value="String"></el-option>
                    <el-option label="Integer" value="Integer"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="长度:">
                  <el-input-number v-model="form.length" :max="999" :min="1" label="描述文字"
                                   style="width: 376px;"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <avue-crud
                  ref="dialogCrud"
                  :data="dialogData"
                  :option="dialogOption"
                  @row-save="rowSaveDialogHandler"
                  @row-update="rowUpdateDialogHandler"
                  @row-del="rowDeleteDialogHandler"
                >
                </avue-crud>
              </el-col>
            </el-row>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button size="small" type="primary" @click="rowSaveHandler">确 定</el-button>
            <el-button size="small" @click="dialogVisible = false">取 消</el-button>
          </span>
        </el-dialog>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="rowSaveHandler">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
        <!-- 查看使用范围    -->
        <el-dialog
          v-dialogDrag
          v-loading="checkViewLoading"
          :visible.sync="checkViewVisible"
          append-to-body="true"
          class="avue-dialog"
          title="查看使用范围"
          width="60%"
        >
          <avue-crud
            ref="checkViewCrud"
            :data="checkViewData"
            :option="checkViewOption"
            @search-change="checkHandleSearch"
            @search-reset="checkHandleReset"
          >
          </avue-crud>
        </el-dialog>
    <!-- 查看使用范围    -->
    <el-dialog
      v-dialogDrag
      v-loading="checkViewLoading"
      :visible.sync="checkViewVisible"
      append-to-body="true"
      class="avue-dialog"
      title="查看使用范围"
      width="70%"
    >
      <avue-crud
        ref="checkViewCrud"
        :data="checkViewData"
        :option="checkViewOption"
        @search-change="checkHandleSearch"
        @search-reset="checkHandleReset"
      >
        <!--导入    -->
        <upload-file ref="upload" :fileType="upFileType" :fileUrl="fileUrl" :tipList="tipList" title="导入"
                     @updata="getTableList"></upload-file>
      </basic-container>
    </el-main>
      </avue-crud>
    </el-dialog>
    <el-aside width="35%">
      <basic-container>
        <el-descriptions :column="1" :labelStyle="{width:'150px'}" border size="medium" style="margin-bottom: 20px"
                         title="枚举信息">
          <el-descriptions-item>
            <template slot="label">
              名称
            </template>
            {{ this.lastItem.id }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              标签
            </template>
            {{ this.lastItem.name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              类型
            </template>
            {{ this.lastItem.enumValueDataType || 'String' }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              长度
            </template>
            <el-tag> {{ this.lastItem.length || 50 }}</el-tag>
          </el-descriptions-item>
    <!--导入    -->
    <upload-file ref="upload" :fileType="upFileType" :fileUrl="fileUrl" :tipList="tipList" title="导入"
                 @updata="getTableList"></upload-file>
  </basic-container>
        </el-descriptions>
        <p style="font-weight: bold">枚举项</p>
        <avue-crud
          :data="asideData"
          :option="asideOption"
        >
        </avue-crud>
      </basic-container>
    </el-aside>
  </el-container>
</template>
<script>
@@ -126,12 +199,40 @@
  downloadEnumTemplate
} from "@/api/modeling/enumType/api";
import func from "@/util/func";
import {mapGetters} from "vuex";
import {deleteUser} from "@/api/system/user/api";
export default {
  name: "index",
  data() {
    return {
      asideOption: {
        ...basicOption,
        addBtn: false,
        editBtn: false,
        menu: false,
        refreshBtn: false,
        selection: false,
        index: false,
        header: false,
        calcHeight: -40,
        column: [
          {
            label: '枚举项名称',
            prop: 'name',
            sortable: true,
          },
          {
            label: '枚举值',
            prop: 'value',
            sortable: true,
          },
          {
            label: '描述',
            prop: 'description',
          },
        ]
      },
      tipList: [
        "导入模板中标明红色字体的为必输项",
        "*注意*:第二行开始的数据为示例数据,导入前请将其删除,当导入的枚举下具备多个枚举项时,应按照示例enum2的写法",
@@ -175,13 +276,16 @@
      dialogData: [],
      dialogOption: {
        ...basicOption,
        calcHeight: 50,
        refreshBtn: false,
        selection: false,
        dialogWidth: 500,
        column: [
          {
            label: '枚举项名',
            prop: 'name',
            sortable: true,
            span: 24,
            rules: [
              {
                required: true,
@@ -194,6 +298,7 @@
            label: '枚举值',
            prop: 'value',
            sortable: true,
            span: 24,
            rules: [
              {
                required: true,
@@ -205,13 +310,13 @@
          {
            label: '描述',
            prop: 'description',
            sortable: true,
            span: 24
          },
        ]
      },
      rules: {
        id: [
          {required: true, message: '请输入枚举项名', trigger: 'blur'},
          {required: true, message: '请输入枚举名称', trigger: 'blur'},
          {validator: this.validateEnglishOnly, trigger: 'blur'}
        ],
      },
@@ -226,11 +331,12 @@
      tableData: [],
      option: {
        ...basicOption,
        calcHeight: -60,
        calcHeight: -40,
        searchMenuSpan: 8,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 160,
        column: [
          {
            label: '枚举名称',
@@ -247,12 +353,37 @@
            label: '返回类型',
            prop: 'enumValueDataTypeText',
            sortable: true,
            width: 130
          }
        ]
      },
      tableLoading: false,
      selectList: [],
      searchParams: {}
      searchParams: {},
      lastIndex: null
    }
  },
  created() {
    console.log(this.$route);
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission[this.$route.query.id].ADD, false),
        delBtn: this.vaildData(this.permission[this.$route.query.id].DELETE, false),
        editBtn: this.vaildData(this.permission[this.$route.query.id].EDIT, false),
        exportBtn: this.vaildData(this.permission[this.$route.query.id].EXPORT, false),
        importBtn: this.vaildData(this.permission[this.$route.query.id].IMPORT, false),
        downloadImportTemplateBtn: this.vaildData(this.permission[this.$route.query.id].DOWNLOAD, false),
        viewTheScopeBtn: this.vaildData(this.permission[this.$route.query.id].SEARCH, false),
      };
    },
    lastItem() {
      return this.selectList.length > 0 ? this.selectList[this.selectList.length - 1] : {};
    },
    asideData() {
      return this.selectList.length > 0 ? this.selectList[this.selectList.length - 1].items : [];
    }
  },
  methods: {
@@ -264,7 +395,6 @@
        this.tableData = data;
        this.tableLoading = false;
      }).catch(err => {
        this.$message.error(err)
      });
    },
@@ -295,7 +425,17 @@
    // 点击行
    rowClickHandler(row) {
      this.$refs.userCrud.toggleRowSelection(row);
      func.rowClickHandler(
        row,
        this.$refs.userCrud,
        this.lastIndex,
        (newIndex) => {
          this.lastIndex = newIndex;
        },
        () => {
          this.selectList = [row];
        }
      );
    },
    // 关闭对话框
@@ -330,7 +470,6 @@
      this.dialogData = row.items;
      this.dialogVisible = true;
      this.editRow = row;
      console.log(row);
    },
    // 删除按钮点击
@@ -386,67 +525,71 @@
          message: '已取消删除'
        });
      });
    },
    // 对话框枚举保存
    rowSaveHandler() {
      const lengthStatus = this.dialogData.some(item => item.value.length > this.form.length)
      if (lengthStatus) {
        this.$message.error('请检查枚举值是否超过最大长度!')
        return;
      }
      if (this.form.enumValueDataType === "Integer") {
        // 判断是否包含非数字字符
        const integerStatus = this.dialogData.some(item => {
          if (!/^\-?\d+$/.test(item.value)) {
            return true;
      const lengthStatus = this.dialogData.some(item => item.value.length > this.form.length);
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (lengthStatus) {
            this.$message.error('请检查枚举值是否超过最大长度!')
            return;
          }
        })
        // 判断是否是integer格式
        const integerNumStatus = this.dialogData.some(item => {
          let numValue = parseInt(item.value);
          if (isNaN(numValue) || !Number.isInteger(numValue)) {
            return true;
          if (this.form.enumValueDataType === "Integer") {
            // 判断是否包含非数字字符
            const integerStatus = this.dialogData.some(item => {
              if (!/^\-?\d+$/.test(item.value)) {
                return true;
              }
            })
            // 判断是否是integer格式
            const integerNumStatus = this.dialogData.some(item => {
              let numValue = parseInt(item.value);
              if (isNaN(numValue) || !Number.isInteger(numValue)) {
                return true;
              }
            })
            if (integerStatus || integerNumStatus) {
              this.$message.error('枚举值必须是Integer类型');
              return;
            }
          }
        })
        if (integerStatus || integerNumStatus) {
          this.$message.error('枚举值必须是Integer类型');
          return;
          if (this.dialogType === 'add') {
            let params = {
              ...this.form,
              items: this.dialogData
            }
            addEnumType(params).then(res => {
              if (res.data.code === 200) {
                this.$message.success(res.data.obj);
                this.dialogVisible = false;
                this.getTableList();
              }
            })
          } else if (this.dialogType === 'edit') {
            let params = {
              ...this.form,
              items: this.dialogData,
              oid: this.editRow.oid,
              ts: this.editRow.ts
            }
            updateEnumType(params).then(res => {
              if (res.data.code === 200) {
                this.$message.success(res.data.obj);
                this.dialogVisible = false;
                this.getTableList();
              }
            })
          }
        } else {
          return false;
        }
      }
      if (this.dialogType === 'add') {
        let params = {
          ...this.form,
          items: this.dialogData
        }
        addEnumType(params).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.dialogVisible = false;
            this.getTableList();
          }
        })
      } else if (this.dialogType === 'edit') {
        let params = {
          ...this.form,
          items: this.dialogData,
          oid: this.editRow.oid,
          ts: this.editRow.ts
        }
        updateEnumType(params).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.dialogVisible = false;
            this.getTableList();
          }
        })
      }
      });
    },
    // 枚举项新增
@@ -567,7 +710,6 @@
        func.downloadFileByBlobHandler(res);
        this.$message.success('导出成功');
      }).catch(err => {
        this.$message.error(err);
      })
    },
@@ -577,7 +719,6 @@
        func.downloadFileByBlobHandler(res);
        this.$message.success('下载成功');
      }).catch(err => {
        this.$message.error(err);
      })
    },