UNPKG

w-vue-middle

Version:

统一公共服务组件

494 lines (478 loc) 13.6 kB
/* * @Author: Jason Liu * @Date: 2023-02-01 13:24:33 * @Desc: */ const $datadevelopment = require('w-vue-middle/api/datadevelopment/standardModel'); const $datadevelopmentmain = require('w-vue-middle/api/datadevelopment'); const glSqlEditor = require('w-vue-middle/components/glSqlEditor').default; export default { name: 'joinDesign', components: { glSqlEditor }, props: { value: { type: Boolean, default: false, }, leftTable: { //左侧表 type: Object, default: { name: undefined, columns: [], }, }, rightTable: { //右侧表 type: Object, default: { name: undefined, columns: undefined, }, }, isNew: { //是否添加 type: Boolean, default: true, }, option: { type: Object, default: () => { return { conditions: [ { type: 0, left: { tableId: this.leftTable.id, columnName: undefined, //关联的字段名称 value: [], }, order: 0, relation: '=', //= > < >= <= != right: { tableId: this.rightTable.id, columnName: undefined, }, }, ], }; }, }, modelInfo: { type: Object, default: { id: undefined, code: undefined, name: undefined, desc: undefined, nickName: undefined, categoryId: undefined, //分类ID topicId: undefined, type: undefined, //类型 0 规范建模 1 维度建模 isPublic: 0, taskType: 'STREAMING', sourceDbId: undefined, //数据源ID sourceDbSchemaName: undefined, //SchemaName sourceType: 1, //来源类型 1 标准规范 2 数据源采集 }, }, }, data() { return { loading: false, show: this.value, joinType: 'leftjoin', type: 0, //关联的方式 关系配置方式:0 SQL自定配置模式:1 sql: undefined, relationType: [ { value: '=', label: $t('等于') }, { value: '>', label: $t('大于') }, { value: '<', label: $t('小于') }, { value: '>=', label: $t('大于等于') }, { value: '<=', label: $t('小于等于') }, { value: 'in', label: $t('包含') }, { value: 'notin', label: $t('不包含') }, { value: 'null', label: $t('空') }, { value: 'nunull', label: $t('非空') }, ], conditions: [ { type: 0, left: { tableId: this.leftTable.id, columnName: undefined, //关联的字段名称 }, order: 0, relation: '=', //= > < >= <= != right: { tableId: this.rightTable.id, columnName: undefined, }, }, ], tablemap: {}, source: { table: { columns: [], }, }, //来源表信息 target: { //目标表信息 table: { columns: [], }, }, tableOptions: [], //表关联信息 }; }, methods: { /** * @Author: Jason Liu * @description: 获取模型数据信息 */ getModelDetail() { this.tablemap = {}; return [ $datadevelopment.getModelDetail({ id: this.leftTable.id }).then((req) => { this.source.table = req.data.semanticMetadataVO; let tablemap = (this.tablemap[this.source.table.code] = []); this.source.table.columns = req.data.semanticFieldMetadataVOList.map((item) => { tablemap.push(item.code); let column = this.leftTable.columns.find((col) => { return col.columnName == item.code; }); if (!!column) { return { ...column, checked: true, }; } else { return { ...item, checked: false, columnName: item.code, }; } }); if (!this.source.table.columns) { this.source.table.columns = this.leftTable.columns || []; } return this.source.table; }), $datadevelopment.getModelDetail({ id: this.rightTable.id }).then((req) => { this.target.table = req.data.semanticMetadataVO; let tablemap = (this.tablemap[this.target.table.code] = []); this.target.table.columns = req.data.semanticFieldMetadataVOList.map((item) => { tablemap.push(item.code); if (this.rightTable.columns) { let column = this.rightTable.columns.find((col) => { return col.columnName == item.code; }); if (!!column) { return { ...column, checked: true, visible: true, }; } else { return { ...item, checked: this.rightTable.columns.length == 0, columnName: item.code, }; } } else { return { ...item, checked: true, visible: true, attr: 'S', //属性 columnName: item.code, }; } }); if (!this.target.table.columns) { this.target.table.columns = this.rightTable.columns || []; } return this.target.table; }), ]; }, /** * @Author: Jason Liu * @description: 获取采集表信息 */ getDbModelDetail() { return [ $datadevelopmentmain .collectionDataInfo( { collectType: 'column', // 采集类型:schema、table、column dsId: this.modelInfo.sourceDbId, schema: this.modelInfo.sourceDbSchemaName, tableName: this.leftTable.code, }, this.leftTable, ) .then((req) => { this.source.table = this.leftTable; this.source.table.columns = req.data.map((item) => { let column = this.leftTable.columns.find((col) => { return col.columnName == item.code; }); if (!!column) { return { ...column, checked: true, }; } else { return { ...item, checked: false, columnName: item.code, }; } }); return this.source.table; }), $datadevelopmentmain .collectionDataInfo( { collectType: 'column', // 采集类型:schema、table、column dsId: this.modelInfo.sourceDbId, schema: this.modelInfo.sourceDbSchemaName, tableName: this.rightTable.code, }, this.rightTable, ) .then((req) => { this.target.table = this.rightTable; this.target.table.columns = req.data.map((item) => { if (this.rightTable.columns) { let column = this.rightTable.columns.find((col) => { return col.columnName == item.code; }); if (!!column) { return { ...column, checked: true, }; } else { return { ...item, checked: false, columnName: item.code, }; } } else { return { ...item, checked: true, visible: true, columnName: item.code, }; } }); return this.target.table; }), ]; }, /** * @Author: Jason Liu * @description: 获取表格信息 */ getTableInfo() { this.conditions = [...this.option.conditions]; this.joinType = this.option.joinType; this.loading = true; this.tableOptions = []; let calls = []; if (this.modelInfo.sourceType == 2) { calls = this.getDbModelDetail(); } else { calls = this.getModelDetail(); } Promise.all(calls) .then((req) => { //TODO:表关联 this.tableOptions = req.map((table) => { return { value: table.id, label: table.name, children: table.columns.map((column) => { return { value: column.columnName, label: `${column.name}(${column.code})`, }; }), }; }); console.log(this.tableOptions); }) .finally(() => { this.loading = false; }); }, /** * @Author: Jason Liu * @description: 确定 */ fixed() { let verification = { //验证 pass: true, mase: undefined, }; //1、验证两边都选择了数据 let sourceColumns = this.source.table.columns.filter((col) => { //来源数据列 col._X_ROW_KEY = undefined; return col.checked; }); let targetColumns = this.target.table.columns.filter((col) => { //关联数据列 col._X_ROW_KEY = undefined; return col.checked; }); //检查是都都关联完毕 this.conditions.forEach((condition) => { if (condition.type == 2) { if (!condition.script) { verification.pass = false; verification.mase = $t('请设置关联脚本的内容'); } } else if (!condition.left.columnName || !condition.right.columnName) { verification.pass = false; verification.mase = $t('请确保关联条件均设置内容!'); } }); if (!sourceColumns.length || !targetColumns.length) { verification.pass = false; verification.mase = $t('请至少选择一条数据列保存!'); } if (verification.pass) { //3、返回更新数据 this.source.table.columns = sourceColumns; this.target.table.columns = targetColumns; this.$emit('change', { isNew: this.isNew, //是否新增 source: this.source.table, target: this.target.table, option: { sourceId: this.source.table.id, //来源ID targetId: this.target.table.id, //目标ID joinType: this.joinType, //关联类型 type: this.type, //关联的方式 关系配置方式:0 SQL自定配置模式:1 conditions: this.conditions, sqlStr: this.sql, }, }); this.show = false; } else { this.$message.warning(verification.mase); } }, /** * @Author: Jason Liu * @description: 删除关联 */ deleteCondition(i) { this.conditions.splice(i, 1); }, /** * @Author: Jason Liu * @description: 添加关联 */ addCondition() { this.conditions.push({ type: 0, //关联字段 left: { tableId: this.leftTable.id, columnName: undefined, //关联的字段名称 value: [], }, order: 0, relation: '=', //= > < >= <= != right: { tableId: this.rightTable.id, columnName: undefined, }, script: undefined, }); }, addConditionScript() { this.conditions.push({ type: 2, //关联逻辑 left: { tableId: undefined, //关联的表 columnName: undefined, //关联的字段名称 value: [], }, order: 0, relation: '=', //= > < >= <= != right: { tableId: undefined, columnName: undefined, }, script: undefined, }); }, /** * @Author: Jason Liu * @description: 添加关联 */ addConditionWhere() { this.conditions.push({ type: 1, //关联逻辑 left: { tableId: undefined, //关联的表 columnName: undefined, //关联的字段名称 value: [], }, order: 0, relation: '=', //= > < >= <= != right: { tableId: undefined, columnName: undefined, }, script: undefined, }); }, /** * @Author: Jason Liu * @description: 修改关联字段事件 */ changeConditionInfo(condition) { condition.left.tableId = condition.left.value[0]; condition.left.columnName = condition.left.value[1]; }, filter(inputValue, path) { return path.some( (option) => option.label.toLowerCase().indexOf(inputValue.toLowerCase()) > -1, ); }, }, watch: { value(val) { this.show = val; this.source = { table: { columns: [], }, }; //来源表信息 this.target = { //目标表信息 table: { columns: [], }, }; if (val) { this.getTableInfo(); } }, show(val) { this.$emit('input', val); }, }, };