configureRules.vue 15 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
<route lang="yaml">
  name: configureRules //标签管理
  </route>

<script lang="ts" setup name="configureRules">
import { ref } from "vue";
import useUserStore from "@/store/modules/user";
import { getBizRuleConfigDetail, getNewDataTypeList, saveBizRuleConfig, } from '@/api/modules/dataInventory'
const { proxy } = getCurrentInstance() as any;
const router = useRouter();
const route = useRoute();
const fullPath = route.fullPath;
const userStore = useUserStore();
const bizRuleConfigData = ref<any>()
const getBizRuleConfigDetailData = async () => {
  tableFieldsLoading.value = true
  const params = {
    tableGuid: router.currentRoute.value.query.tableGuid,
    execGuid: router.currentRoute.value.query.execGuid
  }
  const res: any = await getBizRuleConfigDetail(params)
  if (res.code === proxy.$passCode) {
    bizRuleConfigData.value = res.data
    // 每条数据添加一个isEdit: false 属性,用于判断是否进入编辑模式
    bizRuleConfigData.value.forEach((item: any) => {
      item.isEdit = false
    })
    tableData.value = bizRuleConfigData.value
    tableFieldsLoading.value = false
  } else {
    proxy.$message.error(res.msg)
  }
}
// 获取字段类型
const fieldData = ref<any>([]);
const getFieldTypeData = async () => {
  const params = {
    dictType: "字段类型"
  }
  const res: any = await getNewDataTypeList(params);
  if (res.code == proxy.$passCode) {
    fieldData.value = res.data || [];
  } else {
    proxy.$ElMessage.error(res.msg);
  }
}

onMounted(async () => {
  await getFieldTypeData()
  await getBizRuleConfigDetailData()
})


const tableData1 = ref([
  {
    databaseChName: router.currentRoute.value.query.databaseChName,
    tableName: router.currentRoute.value.query.tableName,
    tableChName: router.currentRoute.value.query.tableChName,
    description: router.currentRoute.value.query.description,
  },
])
// 表格数据
const tableData = ref()

// 配置哪些字段可编辑
const editableFields = {
  fieldName: true, // 字段中文名可编辑
  length: true, // 长度可编辑
  isUnique: true, // 数据是否唯一可编辑
  fieldPrecision: true, // 精度可编辑
  dictionaryGuid: true, // 关联字典可编辑
}

const tableFieldsLoading = ref(false)
// 当前选中的行
const selectedRows = ref([]);

// 监听选中行变化
const selectionFieldsChange = (selection) => {
  selectedRows.value = selection;
};

// 上移操作
const moveUp = () => {
  if (selectedRows.value.length === 0) {
    proxy.$message.warning("请选择数据!");
    return;
  }
  selectedRows.value.forEach((row: any) => {
    const index = tableData.value.findIndex((item) => item.guid === row.guid);
    if (index > 0) {
      [tableData.value[index - 1], tableData.value[index]] = [
        tableData.value[index],
        tableData.value[index - 1],
      ];
    }
  });
};

// 下移操作
const moveDown = () => {
  if (selectedRows.value.length === 0) {
    proxy.$message.warning("请选择数据!");
    return;
  }
  // 倒序遍历选中行
  [...selectedRows.value].reverse().forEach((row: any) => {
    const index = tableData.value.findIndex((item) => item.guid === row.guid);
    if (index < tableData.value.length - 1) {
      [tableData.value[index], tableData.value[index + 1]] = [
        tableData.value[index + 1],
        tableData.value[index],
      ];
    }
  });
};

// 编辑行
const editRow = (row) => {
  if (row.fieldLengthCondition) {
    const arr = row.fieldLengthCondition.split('#')
    row.lengthSymbol = arr[0]
    row.lengthValue = arr[1]
  }
  if (row.fieldValueRange) {
    const arr = row.fieldValueRange.split('#')
    row.rangeStart = arr[0]
    row.rangeEnd = arr[1]
  }
  row.isEdit = true; // 进入编辑模式

};

// 保存数据
const saveRow = (row) => {
  if (row.lengthSymbol && row.lengthValue) {
    row.fieldLengthCondition = row.lengthSymbol + '#' + row.lengthValue
  }
  if (row.rangeStart && row.rangeEnd) {
    row.fieldValueRange = row.rangeStart + '#' + row.rangeEnd
  }
  row.isEdit = false
}

// 删除行
const deleteRow = (index) => {
  tableData.value.splice(index, 1)
}
// 批量删除功能
const batchDelete = () => {
  selectedRows.value.forEach((row: any) => {
    const index = tableData.value.findIndex((item) => item.id === row.id);
    if (index !== -1) tableData.value.splice(index, 1);
  });
  selectedRows.value = [];
};
const data = [
  {
    value: '1',
    label: 'Level one 1',
    children: [
      {
        value: '1-1',
        label: 'Level two 1-1',
        children: [
          {
            value: '1-1-1',
            label: 'Level three 1-1-1',
          },
        ],
      },
    ],
  },
  {
    value: '2',
    label: 'Level one 2',
    children: [
      {
        value: '2-1',
        label: 'Level two 2-1',
        children: [
          {
            value: '2-1-1',
            label: 'Level three 2-1-1',
          },
        ],
      },
      {
        value: '2-2',
        label: 'Level two 2-2',
        children: [
          {
            value: '2-2-1',
            label: 'Level three 2-2-1',
          },
        ],
      },
    ],
  },
  {
    value: '3',
    label: 'Level one 3',
    children: [
      {
        value: '3-1',
        label: 'Level two 3-1',
        children: [
          {
            value: '3-1-1',
            label: 'Level three 3-1-1',
          },
        ],
      },
      {
        value: '3-2',
        label: 'Level two 3-2',
        children: [
          {
            value: '3-2-1',
            label: 'Level three 3-2-1',
          },
        ],
      },
    ],
  },
]

const loading = ref(false)
const saveData = async () => {
  loading.value = true
  /**入参
   * "guid": "string",
    "fieldGuid": "string",
    "fieldLengthCondition": "string",
    "fieldPrecision": 0,
    "dictionaryGuid": "string",
    "isUnique": "string",
    "isNotNull": "string",
    "fieldValueRange": "string"
   */
  const inParams = [] as any
  tableData.value.forEach((item: any) => {
    const obj = {
      fieldGuid: item.fieldGuid,
      execGuid: router.currentRoute.value.query.execGuid,
      fieldLengthCondition: item.fieldLengthCondition,
      fieldPrecision: item.fieldPrecision,
      dictionaryGuid: item.dictionaryGuid,
      isUnique: item.isUnique,
      isNotNull: item.isRequired,
      fieldValueRange: item.fieldValueRange
    }
    inParams.push(obj)
  })

  console.log('finalParams', inParams)
  const res: any = await saveBizRuleConfig(inParams)
  if (res.code === proxy.$passCode) {
    loading.value = false
    proxy.$message.success('修改配置规则成功!')
    userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
    router.push({
      name: 'classifyGradeCatalogue'
    });
  } else {
    loading.value = false
    proxy.$message.error(res.msg)
  }
}


const cancel = () => {
  proxy.$openMessageBox("当前页面尚未保存,确定放弃修改吗?", () => {
    userStore.setTabbar(userStore.tabbar.filter((tab: any) => tab.fullPath !== fullPath));
    router.push({
      name: 'classifyGradeCatalogue'
    });
  }, () => {
    proxy.$ElMessage.info("已取消");
  });
}

</script>
<template>
  <div class="configure-rules">
    <div class="table_panel_wrap">
      <el-table :data="tableData1" :highlight-current-row="true" stripe border height="100%" row-key="guid"
        tooltip-effect="light" :style="{
          width: '100%',
          'max-height': 'calc(100% - 16px)',
          display: 'inline-block',
        }">
        <el-table-column prop="databaseChName" label="数据源" width="180" />
        <el-table-column prop="tableName" label="表名称" width="180" />
        <el-table-column prop="tableChName" label="数据库表" width="280" />
        <el-table-column prop="description" label="描述" width="180" show-overflow-tooltip />
      </el-table>
    </div>
    <div class="btn-area">
      <el-button @click="moveUp">上移</el-button>
      <el-button @click="moveDown">下移</el-button>
      <el-button @click="batchDelete">批量删除</el-button>
    </div>
    <div class="bottom_table">
      <el-table :data="tableData" v-loading="tableFieldsLoading" :highlight-current-row="true" stripe border
        height="100%" row-key="guid" @selection-change="selectionFieldsChange" tooltip-effect="light" :style="{
          width: '100%',
          'max-height': 'calc(100% - 16px)',
          display: 'inline-block',
        }">
        <el-table-column type="selection" :width="32" align="center" />
        <!-- 排序列(不可编辑) -->
        <el-table-column type="index" label="排序" width="80" align="center" />
        <!-- 字段中文名(不可编辑)fieldChName -->
        <el-table-column prop="fieldChName" label="字段中文名" width="120" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.fieldChName ? scope.row.fieldChName : '--' }}
          </template>
        </el-table-column>
        <!-- 字段英文名(不可编辑) -->
        <el-table-column prop="fieldName" label="字段英文名" width="120" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.fieldName ? scope.row.fieldName : '--' }}
          </template>
        </el-table-column>
        <!-- 分类(不可编辑)classifyName -->
        <el-table-column prop="classifyName" label="分类" width="80" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.classifyName ? scope.row.classifyName : '--' }}
          </template>
        </el-table-column>
        <!-- 分级(不可编辑) -->
        <el-table-column prop="gradeDetailName" label="分级" width="80" align="center" show-overflow-tooltip>
          <template #default="scope">
            {{ scope.row.gradeDetailName ? scope.row.gradeDetailName : '--' }}
          </template>
        </el-table-column>
        <!-- 字段类型fieldType (不可编辑) -->
        <el-table-column prop="fieldType" label="字段类型" width="120" align="center">
          <template #default="scope">
            {{

              fieldData ? (fieldData.find((item: any) => item.value === scope.row.fieldType)?.label || '--')
                : '--'
            }}
          </template>
        </el-table-column>

        <!-- 长度列  fieldLengthCondition: '>#10',-->
        <el-table-column prop="fieldLengthCondition" label="长度" width="240" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit">{{ scope.row.fieldLengthCondition
              ? scope.row.fieldLengthCondition.replace('#', '') : '--' }}</span>
            <div v-else>
              <el-select v-model="scope.row.lengthSymbol" placeholder="请选择" style="width: 50%;margin-right: 8px;">
                <el-option label="大于" value=">"></el-option>
                <el-option label="等于" value="="></el-option>
                <el-option label="小于" value="<"></el-option>
              </el-select>
              <el-input v-model="scope.row.lengthValue" placeholder="请输入" style="width: 45%;" />
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="fieldPrecision" label="精度" width="120" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit || !editableFields.fieldPrecision">{{
              scope.row.fieldPrecision ? scope.row.fieldPrecision : '--' }}</span>
            <el-input v-else v-model="scope.row.fieldPrecision" placeholder="请输入精度" />
          </template>
        </el-table-column>

        <!-- 关联字典(可编辑)el-tree-select 形式下拉形式 -->
        <el-table-column prop="dictionaryGuid" label="关联字典" width="150" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit || !editableFields.dictionaryGuid">{{ scope.row.isDict ? scope.row.isDict :
              '--' }}</span>
            <el-tree-select v-else v-model="scope.row.isDict" :data="data" placeholder="请选择" />
          </template>
        </el-table-column>

        <!-- 数据是否唯一(可编辑) -->
        <el-table-column prop="isUnique" label="数据是否唯一" width="150" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit || !editableFields.isUnique">{{ scope.row.isUnique ? scope.row.isUnique : '--'
              }}</span>
            <el-select v-else v-model="scope.row.isUnique" placeholder="请选择">
              <el-option label="是" value="Y" />
              <el-option label="否" value="N" />
            </el-select>
          </template>
        </el-table-column>
        <!-- 是否必填(可编辑) -->
        <el-table-column prop="isRequired" label="是否必填" width="120" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit">{{ scope.row.isRequired ? scope.row.isRequired : '--' }}</span>
            <el-select v-else v-model="scope.row.isRequired" placeholder="请选择">
              <el-option label="是" value="Y" />
              <el-option label="否" value="N" />
            </el-select>
          </template>
        </el-table-column>

        <!-- 字段取值范围 fieldValueRange(可编辑)-->
        <el-table-column prop="fieldValueRange" label="字段取值范围" width="260" align="center">
          <template #default="scope">
            <!-- 非编辑模式,展示取值范围 -->
            <span v-if="!scope.row.isEdit">
              {{ scope.row.fieldValueRange
                ? scope.row.fieldValueRange.replace('#', '-') : '--' }}
            </span>
            <!-- 编辑模式,显示两个输入框 -->
            <div v-else style="display: flex; gap: 5px; align-items: center;">
              <el-input v-model="scope.row.rangeStart" placeholder="最小值" style="width: 45%;" type="number" />
              <span>-</span>
              <el-input v-model="scope.row.rangeEnd" placeholder="最大值" style="width: 45%;" type="number" />
            </div>
          </template>
        </el-table-column>

        <!-- 操作列 -->
        <el-table-column label="操作" width="100" align="center" fixed="right">
          <template #default="scope">
            <span class="text_btn" v-if="!scope.row.isEdit" @click="editRow(scope.row)">编辑</span>
            <span class="text_btn" v-else @click="saveRow(scope.row)">保存</span>
            <el-divider direction="vertical" />
            <span class="text_btn" @click="deleteRow(scope.$index)">删除</span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="botton_btn">
      <el-button type="primary" @click="saveData" :loading="loading">保存</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>
  </div>


</template>

<style lang="scss" scoped>
.configure-rules {
  padding: 16px;
  height: 100%;

  .table_panel_wrap {
    width: 100%;
    height: auto;
    overflow: visible;
  }


  .btn-area {
    margin-top: 12px;
  }

  :deep(.bottom_table) {
    margin-top: 12px;
    height: calc(100% - 150px);
    overflow-y: auto;

    .el-table td.el-table__cell {
      padding: 2px 0;
      height: 36px;
    }
  }
}
</style>