configureRules.vue 14.1 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
<route lang="yaml">
  name: configureRules //标签管理
  </route>

<script lang="ts" setup name="configureRules">
import { ref } from "vue";
import router from "@/router";
import { getBizRuleConfigDetail, updateBizRuleConfig } from '@/api/modules/dataInventory'

const { proxy } = getCurrentInstance() as any;
const bizRuleConfigData = ref<any>()
const getBizRuleConfigDetailData = async () => {
  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
  } else {
    proxy.$message.error(res.msg)
  }
}

onMounted(() => {
  getBizRuleConfigDetailData()
})


const tableData1 = ref([
  {
    cgDirName: router.currentRoute.value.query.cgDirName,
    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) => {
  console.log('selection', selection)
  selectedRows.value = selection;
};

// 上移功能
const moveUp = () => {
  // 1. 找到选中行在 tableData 中的索引
  const selectedIds = selectedRows.value.map((row: any) => row.id);

  // 2. 遍历选中行,按顺序上移
  for (let i = 0; i < tableData.value.length; i++) {
    const currentRow = tableData.value[i];

    // 如果当前行被选中,且不是第一行,则交换位置
    if (selectedIds.includes(currentRow.id) && i > 0) {
      const previousRow = tableData.value[i - 1];

      // 如果上一行没有被选中,交换位置
      if (!selectedIds.includes(previousRow.id)) {
        [tableData.value[i], tableData.value[i - 1]] = [tableData.value[i - 1], tableData.value[i]];
      }
    }
  }
};

// 下移功能
const moveDown = () => {
  // 1. 找到选中行在 tableData 中的索引
  const selectedIds = selectedRows.value.map((row: any) => row.id);

  // 2. 遍历选中行,倒序下移
  for (let i = tableData.value.length - 1; i >= 0; i--) {
    const currentRow = tableData.value[i];

    // 如果当前行被选中,且不是最后一行,则交换位置
    if (selectedIds.includes(currentRow.id) && i < tableData.value.length - 1) {
      const nextRow = tableData.value[i + 1];

      // 如果下一行没有被选中,交换位置
      if (!selectedIds.includes(nextRow.id)) {
        [tableData.value[i], tableData.value[i + 1]] = [tableData.value[i + 1], tableData.value[i]];
      }
    }
  }
};

// 编辑行
const editRow = (row) => {
  if (!row.isEdit) {
    const [symbol, value] = row.fieldLengthCondition.split('#');
    row.lengthSymbol = symbol; // 初始化符号部分
    row.lengthValue = value; // 初始化数值部分
    row.isEdit = true; // 进入编辑模式
  }
};

// 保存数据
const saveRow = (row) => {
  row.fieldLengthCondition = `${row.lengthSymbol}#${row.lengthValue}`;
  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 saveData = async () => {

  /**入参
   * "guid": "string",
    "fieldGuid": "string",
    "fieldLengthCondition": "string",
    "fieldPrecision": 0,
    "dictionaryGuid": "string",
    "isUnique": "string",
    "isNotNull": "string",
    "fieldValueRange": "string"
   */
  const params = tableData.value.map((item: any) => {
    return {
      guid: item.guid,
      fieldGuid: item.fieldGuid,
      fieldLengthCondition: item.fieldLengthCondition,
      fieldPrecision: item.fieldPrecision,
      dictionaryGuid: item.dictionaryGuid,
      isUnique: item.isUnique,
      isNotNull: item.isNotNull,
      fieldValueRange: item.fieldValueRange
    }
  })
  const res: any = await updateBizRuleConfig(params)
  if (res.code === proxy.$passCode) {
    proxy.$message.success('修改配置规则成功!')
    router.back()
  } else {
    proxy.$message.error(res.msg)
  }
}

const cancel = () => {
  router.back()
}

</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="cgDirName" 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="fieldName" label="字段中文名" width="120">
          <template #default="scope">
            {{ scope.row.fieldName ? scope.row.fieldName : '--' }}
          </template>
        </el-table-column>
        <!-- 字段英文名(不可编辑) -->
        <el-table-column prop="fieldEnglish" label="字段英文名" width="120">
          <template #default="scope">
            {{ scope.row.fieldEnglish ? scope.row.fieldEnglish : '--' }}
          </template>
        </el-table-column>
        <!-- 分类(不可编辑)classifyName -->
        <el-table-column prop="fieldEnglish" label="分类" width="120">
          <template #default="scope">
            {{ scope.row.fieldEnglish ? scope.row.fieldEnglish : '--' }}
          </template>
        </el-table-column>
        <!-- 分级(不可编辑) -->
        <el-table-column prop="gradeDetailName" label="分级" width="120" align="center">
          <template #default="scope">
            {{ scope.row.gradeDetailName ? scope.row.gradeDetailName : '--' }}
          </template>
        </el-table-column>
        <!-- 字段类型fieldType (不可编辑) -->
        <el-table-column prop="fieldType" label="字段类型" width="150" align="center">
          <template #default="scope">
            {{ scope.row.fieldType ? scope.row.fieldType : '--' }}
          </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 || '--' }}</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="240" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit">{{ scope.row.fieldPrecision || '--' }}</span>
            <div v-else>
              <el-select v-model="scope.row.fieldPrecision" placeholder="请选择" style="width: 50%;margin-right: 8px;">
                <el-option label="<=500" value="<=500"></el-option>
                <el-option label=">500" value=">500"></el-option>
              </el-select>
              <el-input v-model="scope.row.precisionValue" placeholder="请输入" style="width: 45%;" />
            </div>
          </template>
        </el-table-column> -->
        <!-- 精度(可编辑)fieldPrecision -->
        <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="150" align="center">
          <template #default="scope">
            <span v-if="!scope.row.isEdit">{{ scope.row.fieldValueRange ? scope.row.fieldValueRange : '--' }}</span>
            <el-input v-else v-model="scope.row.fieldValueRange" placeholder="请输入字段取值范围" />
          </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">保存</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>