ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
Source/plt-web/plt-web-ui/src/views/modelingMenu/modeling/attributePool/index.vue
@@ -1,13 +1,1242 @@
<template>
<p>属性池</p>
  <el-container>
    <el-main>
      <basic-container>
        <avue-crud
          ref="userCrud"
          :data="tableData"
          :option="option"
          :page.sync="page"
          :table-loading="tableLoading"
          @on-load="getTableList"
          @refresh-change="handleRefresh"
          @search-change="handleSearch"
          @search-reset="handleReset"
          @selection-change="selectChange"
          @row-click="rowClickHandler"
          @size-change="sizeChange"
          @current-change="currentChange"
        >
          <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="upLoadHandler">
              <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 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>
      </basic-container>
    </el-main>
    <!-- 右侧信息 -->
    <el-aside width="30%">
      <basic-container>
        <div style="height: 85vh; overflow-y: auto">
          <el-descriptions :column="1" :labelStyle="{width:'120px'}" border size="medium" title="属性项">
            <el-descriptions-item>
              <template slot="label">
                名称
              </template>
              <div>
                {{ lastItem.id }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                标签
              </template>
              <div>
                {{ lastItem.name }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                描述
              </template>
              <div>
                {{ lastItem.description }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                操作类型
              </template>
              {{ lastItem.attributeDataType }}
            </el-descriptions-item>
          </el-descriptions>
          <!-- 值域 -->
          <el-descriptions v-if="!isSpecialDataType" :column="1" :labelStyle="{width:'120px'}"
                           :title="lastItem.attributeDataType || 'VTString'"
                           border
                           class="margin-top" size="medium">
            <el-descriptions-item>
              <template slot="label">
                允许为空
              </template>
              <div>
                <el-tag :type="lastItem.nullableFlag ? 'success' : 'danger'">
                  {{ lastItem.nullableFlag ? '是' : '否' }}
                </el-tag>
              </div>
            </el-descriptions-item>
            <el-descriptions-item v-if="accuracy">
              <template slot="label">
                精度
              </template>
              精度
            </el-descriptions-item>
            <el-descriptions-item v-if="length">
              <template slot="label">
                长度
              </template>
              <div>
                {{ lastItem.attrLength }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                默认值
              </template>
              <div>
                {{ lastItem.defaultValue }}
              </div>
            </el-descriptions-item>
          </el-descriptions>
          <!--   VTString  -->
          <el-descriptions v-if="lastItem.attributeDataType === 'VTString' || !lastItem.attributeDataType"
                           :column="1" :labelStyle="{width:'120px'}" border class="margin-top" size="medium" title="值域">
            <el-descriptions-item>
              <template slot="label">
                当前类型
              </template>
              <div>
                {{ lastItem.version ? '链接类型' : '业务类型' }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                当前类型值
              </template>
              <div>
                {{ lastItem.version ? lastItem.linkTypeName : lastItem.btmTypeId }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item v-if="lastItem.version">
              <template slot="label">
                当前版本次
              </template>
              <div>
                {{ lastItem.version }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                使用枚举
              </template>
              <div>
                <el-tag :type="lastItem.enumId ? 'success' : 'danger'">
                  {{ lastItem.enumId ? '是' : '否' }}
                </el-tag>
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                当前枚举类型
              </template>
              <div>
                {{ lastItem.enumId }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                取值范围
              </template>
              <div>
                <el-tag v-for="item in rangeList" plain style="margin: 3px 10px 3px 0">{{ item }}</el-tag>
              </div>
            </el-descriptions-item>
          </el-descriptions>
          <!-- VTInteger && VTInteger  -->
          <el-descriptions
            v-if="lastItem.attributeDataType === 'VTInteger' || lastItem.attributeDataType === 'VTInteger'"
            :column="1" :labelStyle="{width:'120px'}" border class="margin-top" size="medium" title="值域">
            <el-descriptions-item>
              <template slot="label">
                使用枚举
              </template>
              <div>
                <el-tag :type="lastItem.enumId ? 'success' : 'danger'">
                  {{ lastItem.enumId ? '是' : '否' }}
                </el-tag>
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                枚举类型
              </template>
              <div>
                {{ lastItem.enumId }}
              </div>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                取值范围
              </template>
              <div>
                <el-tag v-for="item in rangeList" plain style="margin: 3px 10px 3px 0">{{ item }}</el-tag>
              </div>
            </el-descriptions-item>
          </el-descriptions>
          <!-- VTDouble -->
          <el-descriptions v-if="lastItem.attributeDataType === 'VTDouble'"
                           :column="1" :labelStyle="{width:'120px'}" border class="margin-top" size="medium" title="值域">
            <el-descriptions-item>
              <template slot="label">
                取值范围
              </template>
              <div>
                <el-tag v-for="item in rangeList" plain style="margin: 3px 10px 3px 0">{{ item }}</el-tag>
              </div>
            </el-descriptions-item>
          </el-descriptions>
          <!--      VTDate VTTime VTDateTime VTNote VTFilePath VTClob均不显示 VTBoolean不显示值域 只显示类型   -->
        </div>
      </basic-container>
    </el-aside>
    <!-- 新增对话框 -->
    <el-dialog
      v-dialogDrag
      v-loading="addLoading"
      :title="dialogTitle === 'add' ? '创建' : '编辑'"
      :visible.sync="addVisible"
      append-to-body="true"
      class="avue-dialog"
      width="1200px"
      @close="addEscHandler"
    >
      <div style="height: 550px;">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px" size="small" style="max-height: 600px;">
          <div class="addDialog">
            <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px">属性项</h3>
            <el-col :span="8">
              <el-form-item label="名称:" prop="id">
                <el-input v-model="form.id" :disabled="dialogTitle !== 'add'"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="标签:" prop="name">
                <el-input v-model="form.name"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="属性类型:" prop="attributeDataType">
                <el-select v-model="form.attributeDataType" placeholder="请选择属性类型" @change="attributeDataTypeChange">
                  <el-option v-for="item in typeSelectList" :label="item" :value="item"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="描述:" prop="description">
                <el-input v-model="form.description" :rows="2" type="textarea"></el-input>
              </el-form-item>
            </el-col>
            <!--  VTString   -->
            <div v-if="form.attributeDataType === 'VTString'" style="clear: both">
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px">{{
                  form.attributeDataType
                }}</h3>
              <el-col :span="8">
                <el-form-item label="长度:" prop="attrLength">
                  <el-input-number v-model="form.attrLength" :min="0" controls-position="right"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item v-if="form.enumSwitch" label="默认值:" prop="defaultValue">
                  <el-select v-model="form.defaultValue">
                    <el-option v-for="(item,index) in enumAddListChange" :key="index" :label="item.replace('=','')"
                               :value="item.replace('=','')"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-else label="默认值:" prop="defaultValue">
                  <el-input v-model="form.defaultValue"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="允许为空:" prop="nullableFlag">
                  <el-switch v-model="form.nullableFlag"></el-switch>
                </el-form-item>
              </el-col>
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px;clear: both">值域</h3>
              <el-col :span="8">
                <el-form-item label="当前值域类型:" prop="attributeSelectType">
                  <el-select v-model="form.attributeSelectType" placeholder="请选择属性类型"
                             @change="attributeSelectTypeChange">
                    <el-option label="业务类型" value="business"></el-option>
                    <el-option label="链接类型" value="link"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="选择参照类型:" prop="referValue">
                  <avue-input-tree key="businessReferValue" v-if="form.attributeSelectType === 'business'" default-expand-all :clearable="true" v-model="form.referValue" placeholder="请选择内容" :dic="businessData" @change="referValueChange"></avue-input-tree>
                  <avue-input-tree key="linkReferValue" v-else default-expand-all v-model="form.referValue" placeholder="请选择内容" :clearable="true" :dic="linkTypeData" @change="referValueChange"></avue-input-tree>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item v-show="form.attributeSelectType === 'link'" label="版本次:" prop="version">
                  <el-select v-model="form.version" placeholder="请选择版本次">
                    <el-option :value="1" label="当前版本次"></el-option>
                    <el-option :value="3" label="最新版本次"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <div v-show="showEnumSwitch" style="clear: both">
                <el-col :span="8">
                  <el-form-item label="使用枚举:" prop="enumSwitch">
                    <el-switch v-model="form.enumSwitch" @change="switchEnumChange"></el-switch>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item :label="form.enumSwitch ? '枚举选择:' : '添加值域:'" prop="enumSwitch">
                    <el-select v-if="form.enumSwitch" v-model="form.enumId" placeholder="请选择枚举类型"
                               @change="enumSelectChange">
                      <el-option v-for="(item,index) in attributeDataTypePickList" :key="index" :label="item.key"
                                 :value="item.key"></el-option>
                    </el-select>
                    <el-input v-if="!form.enumSwitch" v-model="form.enumAddValue"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item v-if="!form.enumSwitch" label-width="10px" labeldd="运算符:">
                    <div>
                      <el-button size="mini" @click="enumAddHandler"> =</el-button>
                    </div>
                  </el-form-item>
                </el-col>
                <el-col v-if="form.rangeValue && form.rangeValue.length>0" :span="24">
                  <el-form-item :label="form.enumSwitch ? '当前枚举值:' : '当前值域:'" prop="rangeValue">
                    <el-tag v-for="item in form.rangeValue.split('\n')" :key="item" :closable="!form.enumSwitch" plain
                            style="margin: 0 10px 5px 0" type="success" @close="handleRangeValueDel(item)">{{ item }}
                    </el-tag>
                    <el-input v-model="form.rangeValue" :readonly="form.enumSwitch" :rows="2"
                              style="width: 0;height:0;overflow: hidden"
                              type="textarea"></el-input>
                  </el-form-item>
                </el-col>
              </div>
            </div>
            <!--  VTInteger VTLong   -->
            <div v-else-if="form.attributeDataType === 'VTInteger' || form.attributeDataType === 'VTLong' "
                 style="clear: both">
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px">{{
                  form.attributeDataType
                }}</h3>
              <el-col :span="8">
                <el-form-item v-if="form.enumSwitch" label="默认值:" prop="defaultValue">
                  <el-select v-model="form.defaultValue">
                    <el-option v-for="(item,index) in enumAddListChange" :key="index" :label="item.replace('=','')"
                               :value="item.replace('=','')"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-else label="默认值:" prop="defaultValue">
                  <el-input-number v-model="form.defaultValue" controls-position="right"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="允许为空:" prop="nullableFlag">
                  <el-switch v-model="form.nullableFlag"></el-switch>
                </el-form-item>
              </el-col>
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px;clear: both">值域</h3>
              <el-col :span="8">
                <el-form-item label="使用枚举:" prop="enumSwitch">
                  <el-switch v-model="form.enumSwitch" @change="switchEnumChange"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item :label="form.enumSwitch ? '枚举选择:' : '添加值域:'" prop="enumSwitch">
                  <el-select v-if="form.enumSwitch" v-model="form.enumId" placeholder="请选择枚举类型"
                             @change="enumSelectChange">
                    <el-option v-for="(item,index) in attributeDataTypePickList" :key="index" :label="item.key"
                               :value="item.key"></el-option>
                  </el-select>
                  <el-input v-if="!form.enumSwitch" v-model="form.enumAddValue">
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item v-if="!form.enumSwitch" label-width="10px" labeldd="运算符:">
                  <div>
                    <el-button size="mini" @click="operationHandler('>')"> ></el-button>
                    <el-button size="mini" @click="operationHandler('<')"> <</el-button>
                    <el-button size="mini" @click="operationHandler('>=')"> >=</el-button>
                    <el-button size="mini" @click="operationHandler('<=')"> <=</el-button>
                    <el-button size="mini" @click="operationHandler('=')"> =</el-button>
                    <el-button size="mini" @click="operationHandler('!=')"> !=</el-button>
                    <el-button size="mini" @click="operationHandler('()')"> ([])</el-button>
                  </div>
                </el-form-item>
              </el-col>
              <el-col v-if="form.rangeValue && form.rangeValue.length>0" :span="24">
                <el-form-item :label="form.enumSwitch ? '当前枚举值:' : '当前值域:'" prop="rangeValue">
                  <el-tag v-for="item in form.rangeValue.split('\n')" :key="item" :closable="!form.enumSwitch" plain
                          style="margin: 0 10px 5px 0" type="success" @close="handleRangeValueDel(item)">{{ item }}
                  </el-tag>
                  <el-input v-model="form.rangeValue" :readonly="form.enumSwitch" :rows="2"
                            style="width: 0;height:0;overflow: hidden"
                            type="textarea"></el-input>
                </el-form-item>
              </el-col>
            </div>
            <!--   VTDouble    -->
            <div v-else-if="form.attributeDataType === 'VTDouble'" style="clear: both">
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px">{{
                  form.attributeDataType
                }}</h3>
              <el-col :span="8">
                <el-form-item label="精度:" prop="precisionLength">
                  <el-input-number v-model="form.precisionLength" :min="0" :precision="0" :step="1"
                                   controls-position="right"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="长度:" prop="scaleLength">
                  <el-input-number v-model="form.scaleLength" :min="0" :precision="0" :step="1"
                                   controls-position="right"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item v-if="form.enumSwitch" label="默认值:" prop="defaultValue">
                  <el-select v-model="form.defaultValue">
                    <el-option v-for="(item,index) in enumAddListChange" :key="index" :label="item.replace('=','')"
                               :value="item.replace('=','')"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item v-else label="默认值:" prop="defaultValue">
                  <el-input-number v-model="form.defaultValue" :precision="form.precisionLength"
                                   controls-position="right"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="允许为空:" prop="nullableFlag">
                  <el-switch v-model="form.nullableFlag"></el-switch>
                </el-form-item>
              </el-col>
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px;clear: both">值域</h3>
              <el-col :span="8">
                <el-form-item :label="form.enumSwitch ? '枚举选择:' : '添加值域:'" prop="enumAddValue">
                  <el-input v-model="form.enumAddValue"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="16">
                <el-form-item label="运算符:">
                  <div>
                    <el-button size="mini" @click="operationHandler('>')"> ></el-button>
                    <el-button size="mini" @click="operationHandler('<')"> <</el-button>
                    <el-button size="mini" @click="operationHandler('>=')"> >=</el-button>
                    <el-button size="mini" @click="operationHandler('<=')"> <=</el-button>
                    <el-button size="mini" @click="operationHandler('=')"> =</el-button>
                    <el-button size="mini" @click="operationHandler('!=')"> !=</el-button>
                    <el-button size="mini" @click="operationHandler('()')">([])</el-button>
                  </div>
                </el-form-item>
              </el-col>
              <el-col v-if="form.rangeValue && form.rangeValue.length>0" :span="24">
                <el-form-item :label="form.enumSwitch ? '当前枚举值:' : '当前值域:'" prop="rangeValue">
                  <el-tag v-for="item in form.rangeValue.split('\n')" :key="item" closable plain
                          style="margin: 0 10px 5px 0"
                          type="success" @close="handleRangeValueDel(item)">{{ item }}
                  </el-tag>
                  <el-input v-model="form.rangeValue" :rows="2" style="width: 0;height:0;overflow: hidden"
                            type="textarea"></el-input>
                </el-form-item>
              </el-col>
            </div>
            <div v-else-if="form.attributeDataType === 'VTBoolean'" style="clear: both">
              <h3 style="border-bottom: 1px solid #eee;margin: -10px 0 20px;line-height: 40px">{{
                  form.attributeDataType
                }}</h3>
              <el-col :span="8">
                <el-form-item label="默认值:" prop="defaultValue">
                  <el-select v-model="form.defaultValue">
                    <el-option label="false" value="false"></el-option>
                    <el-option label="true" value="true"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="允许为空:" prop="nullableFlag">
                  <el-switch v-model="form.nullableFlag"></el-switch>
                </el-form-item>
              </el-col>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="addSaveHandler">确 定</el-button>
        <el-button size="small" @click="addEscHandler">取 消</el-button>
      </span>
    </el-dialog>
    <!--导入    -->
    <upload-file ref="upload" :fileType="upFileType" :fileUrl="fileUrl" :tipList="tipList" title="导入"
                 @updata="getTableList"></upload-file>
    <!-- 查看使用范围 -->
    <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-container>
</template>
<script>
import {
  gridAttribute,
  getUsedAttributeList,
  getEnumMapByType,
  deleteAttributes,
  exportAttributes,
  downloadAttributeTemplate,
  getBizTypes,
  getAllLtName,
  addAttribute,
  updateAttribute
} from "@/api/modeling/attributePool/api";
import basicOption from '@/util/basic-option';
import {column} from "./option"
import func from "@/util/func";
import {mapGetters} from "vuex";
export default {
name: "index"
  name: "index",
  data() {
    return {
      rules: {
        id: [
          {required: true, message: '请输入名称', trigger: 'blur'},
          {pattern: /^[a-zA-Z]+$/, message: '只能输入英文字符', trigger: 'blur'}
        ]
      },
      dialogTitle: "",
      businessData: [],
      linkTypeData: [],
      tableData: [],
      option: {
        ...basicOption,
        searchMenuSpan: 8,
        calcHeight: -60,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        menuWidth: 160,
        column
      },
      tableLoading: false,
      page: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        pageSizes: [10, 30, 50, 100],
      },
      searchParams: {},
      selectList: [],
      checkViewData: [],
      checkViewDataSearch: [],
      checkViewVisible: false,
      checkViewLoading: false,
      checkViewOption: {
        ...basicOption,
        addBtn: false,
        menu: false,
        searchMenuSpan: 8,
        refreshBtn: false,
        selection: false,
        header: false,
        column: [
          {
            label: '名称',
            prop: 'attributeName',
            sortable: true,
          },
          {
            label: '来源',
            prop: 'source',
            sortable: true,
            search: true
          },
          {
            label: '说明',
            prop: 'desc',
          }
        ]
      },
      addVisible: false,
      addLoading: false,
      referValueDic:[],
      showEnumSwitch:false,
      form: {
        id: "",
        name: "",
        attributeDataType: "VTString",
        description: "",
        nullableFlag: true,
        attrLength: 50,
        precisionLength: 2,//精度
        scaleLength: 20,//长度
        enumFlag: false,
        enumId: "",
        enumSwitch: false,
        enumAddValue: "",
        range: "",
        attributeSelectType: "business",
        version: 1,
        defaultValue: "",
        referValue: "",
        btmTypeId: "",
        linkTypeName: "",
        rangeValue: [] //当前值域\当前枚举值
      },
      typeSelectList: ['VTString', 'VTInteger', 'VTLong', 'VTDouble', 'VTBoolean', 'VTDate', 'VTTime', 'VTDateTime', 'VTNote', 'VTFilePath', 'VTClob'],
      attributeDataTypePickList: [],
      enumAddListChange: [],
      tipList: [
        "属性名和属性类型为必填字段,并且属性名不可和系统中已有属性名重复",
        "当属性类型为VTString时属性长度列必填,为其他类型时不必填写",
        "取值范围列填写时请用英文 ; 分隔,不填写时默认使用当前选中的枚举的所有枚举项的值作为取值范围"
      ],
      upFileType: ['xls', 'xlsx'],
      fileUrl: 'api/attributeController/importAttributes',
      lastIndex: null
    }
  },
  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] : {};
    },
    isSpecialDataType() {
      // 定义一个包含所有需要比较的类型的数组
      const specialTypes = ['VTDate', 'VTTime', 'VTDateTime', 'VTNote', 'VTFilePath', 'VTClob'];
      // 判断 lastItem.attributeDataType 是否在这个数组中
      return specialTypes.includes(this.lastItem.attributeDataType);
    },
    rangeList() {
      if (this.lastItem.range) {
        return this.lastItem.range.split(';');
      }
    },
    accuracy() {
      return this.lastItem.attributeDataType === 'VTDouble';
    },
    length() {
      return this.lastItem.attributeDataType === 'VTString' || this.lastItem.attributeDataType === 'VTDoubule';
    },
    // 等于其中以下值 不展示枚举
    hideType() {
      return this.form.attributeDataType === 'VTNote' ||
        this.form.attributeDataType === 'VTDate' ||
        this.form.attributeDataType === 'VTTime' ||
        this.form.attributeDataType === 'VTClob' ||
        this.form.attributeDataType === 'VTDateTime' ||
        this.form.attributeDataType === 'VTFilePath';
    }
  },
  watch: {},
  methods: {
    //表格查询请求
    getTableList() {
      this.tableLoading = true;
      gridAttribute(this.page.currentPage, this.page.pageSize, this.searchParams).then(res => {
        const data = res.data.data;
        this.tableData = data;
        this.page.total = res.data.total;
        this.tableLoading = false;
      });
      //获取业务类型数据
      getBizTypes().then(res => {
        const data = res.data.data.map(item => ({
          label: item.name,
          value:item.name,
          desc:item.label
        }));
        this.businessData = data;
      })
      //获取链接类型数据
      getAllLtName().then(res => {
        const data = res.data.data.map(item => ({
          label: item,
          value:item
        }));
        this.linkTypeData = data;
      })
    },
    // 表格头部刷新
    handleRefresh() {
      this.getTableList();
    },
    // 搜索
    handleSearch(params, done) {debugger;
      this.searchParams = {
        "conditionMap[id]": "*" + params.id + "*"
      };
      this.getTableList()
      done();
    },
    // 重置搜索条件
    handleReset() {
      this.searchParams = {};
      this.getTableList();
    },
    // 选择框
    selectChange(row) {
      this.selectList = row;
    },
    // 点击行
    rowClickHandler(row) {
      func.rowClickHandler(
        row,
        this.$refs.userCrud,
        this.lastIndex,
        (newIndex) => {
          this.lastIndex = newIndex;
        },
        () => {
          this.selectList = [row];
        }
      );
    },
    // 条数
    sizeChange(val) {
      this.page.pageSize = val;
    },
    // 页码
    currentChange(val) {
      this.page.currentPage = val;
    },
    // 创建打开对话框
    rowSaveHandlerClick() {
      this.addVisible = true;
      this.dialogTitle = "add";
      this.getEnumMapByTypeHandler('VTString');
    },
    // 行删除
    rowDeleteHandler(row) {
      let params = {
        oid: row.oid,
        name: row.id,
        ts: row.ts
      };
      let data = [params];
      this.$confirm('您确定要删除当前的数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteAttributes(data).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.getTableList();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 多选删除
    allDelHandler() {
      if (this.selectList.length <= 0) {
        this.$message.error('请至少选择一条数据进行删除!')
        return;
      }
      let data = this.selectList.map(item => {
        return {
          oid: item.oid,
          name: item.id,
          ts: item.ts
        }
      })
      this.$confirm('您确定要删除所选择的数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteAttributes(data).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.getTableList();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 查看使用范围
    chekView() {
      if (this.selectList.length <= 0) {
        this.$message.warning('请至少选择一条数据');
        return;
      }
      if (this.selectList.length > 1) {
        this.$message.warning('只能选择一条数据进行查看');
        return;
      }
      getUsedAttributeList({attributeName: this.selectList[0].id}).then(res => {
        if (res.data.code === 200) {
          this.checkViewVisible = true;
          this.checkViewData = res.data.data;
          this.checkViewDataSearch = res.data.data;
        }
      })
    },
    // 查看使用范围查询
    checkHandleSearch(params, done) {
      const {source} = params;
      if (!params.source) {
        this.checkViewData = this.checkViewDataSearch;
        return done();
      }
      this.checkViewData = this.checkViewData.filter(item => {
        return item.source && item.source.includes(source);
      });
      done();
    },
    // 查看使用范围重置
    checkHandleReset() {
      this.checkViewData = this.checkViewDataSearch;
    },
    // 行编辑按钮
    editBtnClick(row) {
      this.dialogTitle = "edit";
      this.form = {...row};
      if (row.enumId) this.form.enumSwitch = true;
      this.form.rangeValue = row.range.replace(/;/g, '\n');
      if (row.btmTypeId) {
        this.form.attributeSelectType = 'business'
        this.form.referValue = row.btmTypeId;
      }
      if (row.linkTypeName) {
        this.form.attributeSelectType = 'link'
        this.form.referValue = row.linkTypeName;
      }
      if (!row.btmTypeId && !row.linkTypeName) {
        this.form.attributeSelectType = 'business'
        this.form.referValue = row.btmTypeId;
      }
      this.getEnumMapByTypeHandler(this.form.attributeDataType);
      this.addVisible = true;
      this.lastIndex = -1;//防止触发行点击事件后清除选中项
    },
    // 属性类型下拉框change
    attributeDataTypeChange(val) {
      this.form.rangeValue = null;
      this.form.nullableFlag = true;
      this.getEnumMapByTypeHandler(val);
      this.form.enumSwitch = false;
      if (val === 'VTBoolean') {
        this.form.defaultValue = 'false';
      } else {
        this.form.defaultValue = '';
      }
    },
    // 属性类型下拉框数据处理
    getEnumMapByTypeHandler(val) {
      const enumType = {
        VTString: 'String',
        VTInteger: 'Integer',
        VTLong: 'Integer',
      };
      if (enumType[val]) {
        const string = enumType[val];
        getEnumMapByType({enumType: string}).then(res => {
          const data = res.data.data;
          this.attributeDataTypePickList = data.flatMap(obj =>
            Object.entries(obj).map(([key, values]) => ({
              key: key,
              values: values
            }))
          );
        })
      }
    },
    // 使用枚举时 枚举选择下拉框change事件
    enumSelectChange(val) {
      const list = this.attributeDataTypePickList.find(item => item.key === val).values;
      this.form.rangeValue = list.join('\n');
      this.enumAddListChange = list;
      this.form.defaultValue = list[0].replace('=', '');
    },
    // 使用枚举switch滑块change事件
    switchEnumChange(status) {
      if (status) {
        this.form.enumId = this.attributeDataTypePickList[0].key;
        const list = this.attributeDataTypePickList[0].values;
        this.form.rangeValue = list.join('\n');
        this.enumAddListChange = list;
        this.form.defaultValue = list[0].replace('=', '');
      } else {
        this.form.defaultValue = "";
        this.form.rangeValue = "";
        this.enumAddListChange = [];
        this.enumId = "";
      }
    },
    // 不使用枚举 手动添加枚举值 VTString
    enumAddHandler() {
      // 检查和转换 this.form.range 为数组,同时排除空值
      let currentRangeArray = this.form.rangeValue ? this.form.rangeValue.split('\n').filter(item => item.trim() !== '') : [];
      let newValue = this.form.enumAddValue.trim();
      if (currentRangeArray.includes(newValue)) {
        this.$message.error('该值域规则已经存在!')
        return;
      }
      currentRangeArray.push(newValue);
      this.enumAddListChange = currentRangeArray;
      this.form.rangeValue = currentRangeArray.join('\n');
      this.form.enumAddValue = "";
    },
    // 不使用枚举 手动添加枚举值(多个运算符)
    operationHandler(val) {
      // 检查和转换 this.form.rangeValue 为数组,同时排除空值
      let currentRangeArray = this.form.rangeValue
        ? this.form.rangeValue.split('\n').filter(item => item.trim() !== '')
        : [];
      // 处理 '()' 运算符的情况
      if (val === '()') {
        let regex = /[,\[\]()]+/g;
        let firstValue = this.form.enumAddValue[0];
        let lastValue = this.form.enumAddValue[(this.form.enumAddValue.length - 1)];
        // 切割 enumAddValue 的逗号
        let values = this.form.enumAddValue.split(regex).map(item => item.trim()).filter(item => item !== "");
        // 检查是否有有效的值
        if (values.length < 2 || values.some(item => item === '')) {
          this.$message.error('请输入有效的值,并用逗号分隔!');
          return;
        }
        // 检查左边值是否小于右边值
        let leftValue = parseFloat(values[0]);
        let rightValue = parseFloat(values[1]);
        if (isNaN(leftValue) || isNaN(rightValue)) {
          this.$message.error('请输入有效的数字值!');
          return;
        }
        if (leftValue >= rightValue) {
          this.$message.error('左边的值不能大于或等于右边的值!');
          return;
        }
        // 构建 newValue 的形式 (值1,值2)
        let newValue = `${firstValue}${values.join(',')}${lastValue}`;
        // 检查新的值是否已存在
        if (currentRangeArray.includes(newValue)) {
          this.$message.error('该值域规则已经存在!');
          return;
        }
        // 添加新值到数组中
        currentRangeArray.push(newValue);
        this.enumAddListChange = currentRangeArray;
        this.form.rangeValue = currentRangeArray.join('\n');
        this.form.enumAddValue = "";
        return;
      }
      // 处理其他运算符
      const operatorMap = {
        '>': '>',
        '<': '<',
        '>=': '>=',
        '<=': '<=',
        '=': '=',
        '!=': '!='
      };
      if (isNaN(this.form.enumAddValue.trim())) {
        this.$message.error('请输入有效的数字值!');
        return;
      }
      // 创建新的值
      let newValue = operatorMap[val] + this.form.enumAddValue.trim();
      // 检查新的值是否已存在
      if (currentRangeArray.includes(newValue)) {
        this.$message.error('该值域规则已经存在!');
        return;
      }
      // 添加新值到数组中
      currentRangeArray.push(newValue);
      this.enumAddListChange = currentRangeArray;
      this.form.rangeValue = currentRangeArray.join('\n');
      this.form.enumAddValue = "";
    },
    //删除值域
    handleRangeValueDel(val) {
      let currentRangeArray = this.form.rangeValue ? this.form.rangeValue.split('\n').filter(item => item.trim() !== val) : [];
      this.enumAddListChange = currentRangeArray;
      this.form.rangeValue = currentRangeArray.join('\n');
    },
    // 值域类型切换
    attributeSelectTypeChange() {
      this.form.referValue = ''; // 切换值域类型 清空当前参照
      this.$forceUpdate(); // 强制更新form组件
    },
    //参照类型数据变化
    referValueChange(data){
      this.showEnumSwitch=!data.value;
    },
    // 关闭新增对话框
    addEscHandler() {
      this.addVisible = false;
      const form = {
        id: "",
        name: "",
        attributeDataType: "VTString",
        description: "",
        nullableFlag: true,
        attrLength: 50,
        precisionLength: 2,//精度
        scaleLength: 20,//长度
        enumFlag: false,
        enumId: "",
        enumSwitch: false,
        enumAddValue: "",
        range: "",
        attributeSelectType: "business",
        version: 1,
        defaultValue: "",//默认值
        referValue: null,
        btmTypeId: "",
        linkTypeName: "",
        rangeValue: ""
      };
      this.form = form;
      this.$refs.form.clearValidate(); // 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果
    },
    // 新增保存
    addSaveHandler() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if(this.form.attributeDataType === 'VTString'){
            if(!this.form.referValue){
              //参照类型没有值
            }else {
              this.form.enumSwitch=false;
              this.form.rangeValue=''
            }
          }
          this.form.range = this.form.rangeValue.length>0 ? this.form.rangeValue.replace(/\n/g, ';') : '';
          if (this.form.attributeSelectType === 'business') {
            this.form.btmTypeId = this.form.referValue;
            this.form.linkTypeName = "";
          } else {
            this.form.linkTypeName = this.form.referValue;
            this.form.btmTypeId = "";
          }
          if (this.dialogTitle === 'add') {
            addAttribute(this.form).then(res => {
              if (res.data.code === 200) {
                this.$message.success(res.data.obj);
                this.getTableList();
                this.addEscHandler();
              }
            })
          }
          if (this.dialogTitle === 'edit') {
            updateAttribute(this.form).then(res => {
              if (res.data.code === 200) {
                this.$message.success(res.data.obj);
                this.getTableList();
                this.addEscHandler();
              }
            })
          }
        } else {
          return false;
        }
      });
    },
    // 导入
    upLoadHandler() {
      this.$refs.upload.visible = true;
    },
    // 导出
    downLoadHandler() {
      if (this.selectList.length <= 0) {
        this.$message.warning('请至少选择一条数据进行导出');
        return;
      }
      let attrNames = this.selectList.map(item => item.id).join(',');
      exportAttributes({attrNames: attrNames}).then(res => {
        func.downloadFileByBlobHandler(res);
        this.$message.success('导出成功');
      }).catch(err => {
        this.$message.error(err);
      })
    },
    // 下载导入模板
    downloadTemplateHandler() {
      downloadAttributeTemplate().then(res => {
        func.downloadFileByBlobHandler(res);
        this.$message.success('下载成功');
      }).catch(err => {
        this.$message.error(err);
      })
    },
  }
}
</script>
<style scoped>
<style lang="scss" scoped>
::v-deep {
  .el-input-number--small {
    width: 100%;
  }
}
.margin-top {
  margin-top: 25px;
}
.left {
  width: 45%;
  height: 100%;
  margin-right: 60px;
}
.right {
  height: 100%;
  width: auto;
  margin-left: 60px;
}
.addDialogBottom {
  margin-top: 30px;
  width: 100%;
  display: flex;
  flex-direction: row;
}
.addDialogBottom > .el-divider--vertical {
  width: 1px;
  height: 70%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -20%);
}
</style>