Просмотр исходного кода

faet: 数据集组件代码合并

wu.jian2 2 лет назад
Родитель
Сommit
8d505be6b7

+ 24 - 12
data-room-ui/packages/DataSetManagement/src/CategroyEditForm.vue

@@ -45,7 +45,7 @@
 </template>
 
 <script>
-import { addOrUpdateTree } from 'packages/js/utils/datasetConfigService'
+import { categoryAdd, categoryUpdate } from 'packages/js/utils/datasetConfigService'
 export default {
   name: 'CategroyEditForm',
   props: {
@@ -56,7 +56,7 @@ export default {
   },
   data () {
     return {
-      tableName: '',
+      type: 'dataset',
       dataForm: {
         id: '',
         name: '',
@@ -129,18 +129,30 @@ export default {
             id: id,
             name: this.dataForm.name,
             parentId: parentId,
-            tableName: this.tableName,
+            type: this.type,
             moduleCode: this.appCode
           }
-          addOrUpdateTree(params).then((r) => {
-            this.$message.success('保存成功')
-            this.cancel()
-            try {
-              this.$parent.init()
-            } catch (error) {
-              this.$parent.initLazyOrgTree()
-            }
-          })
+          if (id) {
+            categoryUpdate(params).then((r) => {
+              this.$message.success('保存成功')
+              this.cancel()
+              try {
+                this.$parent.init()
+              } catch (error) {
+                this.$parent.initLazyOrgTree()
+              }
+            })
+          } else {
+            categoryAdd(params).then((r) => {
+              this.$message.success('保存成功')
+              this.cancel()
+              try {
+                this.$parent.init()
+              } catch (error) {
+                this.$parent.initLazyOrgTree()
+              }
+            })
+          }
         } else {
           return false
         }

+ 314 - 325
data-room-ui/packages/DataSetManagement/src/CustomEditForm.vue

@@ -1,7 +1,7 @@
 <!-- eslint-disable vue/no-parsing-error -->
 <template>
   <div
-    v-loading="saveloading"
+    v-loading="saveLoading"
     class="inner-container"
     :element-loading-text="saveText"
   >
@@ -163,8 +163,7 @@
               />
               <div class="bs-codemirror-bottom-text">
                 示例:
-                <strong v-if="dataForm.curingType == '3'">call 存储过程名称(<span style="color: red;">${参数名称}</span>,?)</strong>
-                <strong v-else><br>
+                <strong><br>
                   1、常规使用 select * from table where table_field = <span style="color: red;">${参数名称}</span><br>
                   2、标签使用
                   <el-tooltip
@@ -183,7 +182,7 @@
             <div style="text-align: center; padding: 16px 0;">
               <el-button
                 type="primary"
-                @click="buildParams"
+                @click="buildParamsAndRun"
               >
                 解析并运行
               </el-button>
@@ -243,11 +242,11 @@
               <div class="field-wrap bs-field-wrap bs-scrollbar">
                 <div
                   v-for="field in structurePreviewList"
-                  :key="field.columnName"
+                  :key="field.fieldName"
                   class="field-item"
                   @click="fieldsetVisible = true"
                 >
-                  <span>{{ field.columnName }}</span>&nbsp;<span
+                  <span>{{ field.fieldName }}</span>&nbsp;<span
                     v-show="field.fieldDesc"
                     style="color: #909399;"
                   >({{
@@ -376,13 +375,13 @@
                 <el-table-column
                   align="center"
                   show-overflow-tooltip
-                  prop="columnName"
+                  prop="fieldName"
                   label="字段值"
                 />
                 <el-table-column
                   align="center"
                   show-overflow-tooltip
-                  prop="columnType"
+                  prop="fieldType"
                   label="字段类型"
                 />
                 <el-table-column
@@ -502,13 +501,13 @@
             <el-table-column
               align="left"
               show-overflow-tooltip
-              prop="columnName"
+              prop="fieldName"
               label="字段值"
             />
             <el-table-column
               align="center"
               show-overflow-tooltip
-              prop="columnType"
+              prop="fieldType"
               label="字段类型"
             />
             <el-table-column
@@ -734,8 +733,15 @@
 </template>
 
 <script>
-import { nameCheckRepeat, sqlTest, datasetAdd, datasetUpdate, getDatasetInfo, getDatasetTypeList } from 'packages/js/utils/datasetConfigService'
-import { datasourcePage } from 'packages/js/utils/dataSourceService'
+import {
+  nameCheckRepeat,
+  datasetAdd,
+  datasetUpdate,
+  datasetExecuteTest,
+  getCategoryTree,
+  getDataset
+} from 'packages/js/utils/datasetConfigService'
+import { datasourceList } from 'packages/js/utils/dataSourceService'
 import { codemirror } from 'vue-codemirror'
 import 'codemirror/mode/sql/sql.js'
 import 'codemirror/theme/nord.css'
@@ -787,30 +793,22 @@ export default {
         id: '',
         name: '',
         typeId: '',
-        code: '',
-        curingType: '2',
+        datasetType: 'custom',
         remark: '',
+        // 以下为config配置
         sourceId: '',
         sqlProcess: 'select ',
-        script: '',
         paramsList: [],
-        paramConfig: '',
-        cacheCoherence: null,
-        fieldDesc: '',
-        fieldJson: '',
-        processType: '2'
+        fieldDesc: {},
+        fieldList: [],
+        script: '',
+        cacheCoherence: null
       },
       rules: {
         name: [
           { required: true, message: '请输入数据集名称', trigger: 'blur' },
           { validator: validateName, trigger: 'blur' }
         ],
-        // typeId: [
-        //   {required: true, message: '请选择分组', trigger: 'blur'}
-        // ],
-        curingType: [
-          { required: true, message: '请选择固化形式', trigger: 'blur' }
-        ],
         sourceId: [
           { required: true, message: '请选择数据源', trigger: 'blur' }
         ]
@@ -832,17 +830,13 @@ export default {
       structurePreviewListCopy: [],
       msg: '',
       exception: '',
-      typeSelect: [{
-        value: 'String'
-      }, {
-        value: 'Integer'
-      }, {
-        value: 'Double'
-      }, {
-        value: 'Long'
-      }, {
-        value: 'Date'
-      }],
+      typeSelect: [
+        { value: 'String' },
+        { value: 'Integer' },
+        { value: 'Double' },
+        { value: 'Long' },
+        { value: 'Date' }
+      ],
       typeName: '',
       categoryData: [],
       passTest: false, // 通过测试
@@ -853,7 +847,7 @@ export default {
       fieldsetVisible: false,
       paramsVisible: false,
       tableLoading: false,
-      saveloading: false,
+      saveLoading: false,
       saveText: '',
       tableNameList: [],
       paramsListCopy: [],
@@ -870,6 +864,7 @@ export default {
     }
   },
   watch: {
+    // 一旦sql、脚本、参数发生变化,将通过测试置为false
     checkPass: {
       handler (value) {
         this.passTest = false
@@ -881,17 +876,112 @@ export default {
     this.init()
   },
   methods: {
-    // 打开参数配置
+    /**
+     * 初始化
+     * 1.获取分类树
+     * 2.获取数据源列表
+     * 3.如果是编辑,获取数据集详情
+     */
+    async init () {
+      // 获取分类树
+      this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
+      // 如果传入了分类id,需要设置分类id和名称
+      if (this.typeId) {
+        this.dataForm.typeId = this.typeId
+        this.$nextTick(() => {
+          try {
+            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+          } catch (error) {
+            console.error(error)
+          }
+        })
+      }
+      // 获取数据源列表
+      this.getDataSource()
+      if (!this.datasetId) {
+        return
+      }
+      // 获取详情
+      getDataset(this.datasetId).then(res => {
+        this.dataForm.id = res.id
+        this.dataForm.name = res.name
+        this.dataForm.typeId = res.typeId
+        this.dataForm.remark = res.remark
+        this.dataForm.datasetType = res.datasetType
+        this.dataForm.moduleCode = res.moduleCode
+        this.dataForm.editable = res.editable
+        this.dataForm.sourceId = res.sourceId
+        // config 配置
+        this.dataForm.sqlProcess = res.config.sqlProcess
+        this.dataForm.paramsList = res.config.paramsList ? res.config.paramsList : []
+        this.dataForm.fieldDesc = res.config.fieldDesc
+        this.dataForm.fieldList = res.config.fieldList
+        this.dataForm.cacheCoherence = res.config.cacheCoherence
+        // 使用传入的数据集名称 ?
+        this.dataForm.name = this.datasetName
+        this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
+        if (this.dataForm.typeId) {
+          this.$nextTick(() => {
+            try {
+              this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+            } catch (error) {
+              console.error(error)
+            }
+          })
+        }
+        this.datasetTest(false)
+      })
+    },
+    /**
+     * 获取数据源列表
+     */
+    getDataSource () {
+      const params = {
+        sourceName: '',
+        sourceType: '',
+        moduleCode: this.appCode
+      }
+      datasourceList(params).then(data => {
+        this.sourceList = data
+      })
+    },
+    /**
+     * 打开参数配置弹窗
+     */
     openParamsConfig () {
       this.isTest = false
       this.paramsVisible = true
     },
-    // 取消操作
+    /**
+     * 删除参数配置
+     * @param {*} index
+     */
+    delRow (index) {
+      this.paramsListCopy.splice(index, 1)
+    },
+    /**
+     * 新增参数配置
+     */
+    addParam () {
+      this.paramsListCopy.push({
+        name: '',
+        type: '',
+        value: '',
+        status: 1,
+        require: 0,
+        remark: ''
+      })
+    },
+    /**
+     * 取消编辑参数
+     */
     cancelParam () {
       this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
       this.paramsVisible = false
     },
-    // 设置SQL参数
+    /**
+     * 保存参数设置
+     */
     setParam () {
       this.dataForm.paramsList = _.cloneDeep(this.paramsListCopy)
       if (this.isTest) {
@@ -899,79 +989,52 @@ export default {
       }
       this.paramsVisible = false
     },
-    // 取消操作
+    /**
+     * 使用字段名填充字段描述
+     */
+    fieldDescFill () {
+      this.structurePreviewList.forEach(field => {
+        if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
+          field.fieldDesc = field.fieldName
+        }
+      })
+      this.save('form')
+      this.fieldDescVisible = false
+    },
+    /**
+     * 打开字段描述编辑弹窗
+     */
+    fieldDescEdit () {
+      this.fieldDescVisible = false
+      this.fieldsetVisible = true
+    },
+    /**
+     * 跳过字段描述编辑直接保存
+     */
+    toSave () {
+      this.save('form', true)
+      this.fieldDescVisible = false
+    },
+    /**
+     * 取消编辑字段
+     */
     cancelField () {
       this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
       this.fieldsetVisible = false
     },
-    // 设置输出字段
+    /**
+     * 保存字段设置
+     */
     setField () {
       this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
       this.fieldsetVisible = false
     },
-    // 每页大小改变触发
-    sizeChangeHandle (value) {
-      this.size = value
-      this.current = 1
-      if (this.dataForm.processType === '2') {
-        this.datasetTest(false)
-      }
-    },
-    // 当前页数改变
-    currentChangeHandle (value) {
-      this.current = value
-      if (this.dataForm.processType === '2') {
-        this.datasetTest(false)
-      }
-    },
-    // 表视图切换,sql加工相关信息置空
-    curingTypeChoose (value) {
-      if (value === '3') {
-        if (this.dataForm.sqlProcess === 'select ') {
-          this.dataForm.sqlProcess = 'call '
-        }
-      } else {
-        if (this.dataForm.sqlProcess === 'call ') {
-          this.dataForm.sqlProcess = 'select '
-        }
-      }
-      if ((!['select ', 'call '].includes(this.dataForm.sqlProcess) && this.dataForm.sqlProcess !== '') || this.dataForm.sourceId !== '' || this.dataForm.paramsList.length > 0) {
-        this.$confirm('结果固化形式切换,表和视图处理情况不同,建议清空sql加工配置数据,是否清空数据?', '提示', {
-          confirmButtonText: '是',
-          cancelButtonText: '否',
-          type: 'warning',
-          customClass: 'bs-el-message-box'
-        }).then(() => {
-          this.curingTypeChooseClear(value)
-        }).catch(() => {
-        })
-      } else {
-        this.curingTypeChooseClear(value)
-      }
-    },
-    curingTypeChooseClear (value) {
-      // 数据源id置空
-      this.dataForm.sourceId = ''
-      // sql脚本置空
-      this.dataForm.sqlProcess = value === '3' ? 'call ' : 'select '
-      this.passTest = false
-      // 参数配置信息置空
-      this.dataForm.paramsList = []
-      this.paramsListCopy = []
-      if (this.dataForm.id !== '') {
-        getDatasetInfo(this.datasetId).then(data => {
-          if (data.curingType === this.dataForm.curingType) {
-            this.dataForm.sourceId = data.sourceId
-            this.dataForm.sqlProcess = data.sqlProcess
-            this.dataForm.paramsList = data.paramConfig !== '' ? JSON.parse(data.paramConfig) : []
-            this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
-            this.passTest = true
-          }
-        })
-      }
-    },
-    // 保存
-    save (formName, nochecktosave = false) {
+    /**
+     * 保存
+     * @param formName 表单名称
+     * @param noCheckToSave 是否不检查直接保存
+     */
+    save (formName, noCheckToSave = false) {
       if (this.passTest === false) {
         this.$message.error('请确保数据集SQL加工脚本不为空且测试通过')
         return
@@ -980,7 +1043,7 @@ export default {
         this.$message.warning('该自助数据集未生成输出字段,请重新检查')
         return
       }
-      if (!nochecktosave) {
+      if (!noCheckToSave) {
         const temp = this.structurePreviewList.some(item => {
           return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
         }) // true-存在为空
@@ -993,9 +1056,9 @@ export default {
       let hasChinese = false // 判断有无中文
       let ChineseCode = ''
       for (let i = 0; i < this.structurePreviewList.length; i++) {
-        if (chineseRegex.test(this.structurePreviewList[i].columnName)) {
+        if (chineseRegex.test(this.structurePreviewList[i].fieldName)) {
           hasChinese = true
-          ChineseCode = this.structurePreviewList[i].columnName
+          ChineseCode = this.structurePreviewList[i].fieldName
           break
         }
       }
@@ -1014,88 +1077,72 @@ export default {
         this.saveFun(formName)
       }
     },
+    /**
+     * 保存数据集
+     * @param formName
+     */
     saveFun (formName) {
       this.$refs[formName].validate((valid) => {
-        if (valid) {
-          if (this.dataForm.paramsList.length > 0) {
-            const names = this.dataForm.paramsList.map(value => value.name)
-            const namesSet = new Set(names)
-            if (namesSet.size !== names.length) {
-              this.$message.error('参数名称不能重复,请重新输入')
-              return
-            }
-          }
-          this.dataForm.paramConfig = this.dataForm.paramsList.length !== 0 ? JSON.stringify(this.dataForm.paramsList) : ''
-          const columnMap = {}
-          if (this.structurePreviewList.length > 0) {
-            this.structurePreviewList.forEach(r => {
-              columnMap[r.columnName] = r.fieldDesc
-            })
-            this.dataForm.fieldDesc = JSON.stringify(columnMap)
-          }
-          this.dataForm.fieldJson = this.structurePreviewList.length ? JSON.stringify(this.structurePreviewList) : ''
-          this.saveloading = true
-          this.saveText = '正在保存...'
-          if (this.dataForm.id === '') {
-            datasetAdd({
-              ...this.dataForm,
-              moduleCode: this.appCode,
-              editable: this.appCode ? 1 : 0
-            }).then(res => {
-              this.$message.success('保存成功')
-              this.$parent.init(false)
-              this.$parent.setType = null
-              this.saveloading = false
-              this.saveText = ''
-            }).catch(() => {
-              this.saveloading = false
-              this.saveText = ''
-            })
-          } else {
-            datasetUpdate({
-              ...this.dataForm,
-              moduleCode: this.appCode,
-              editable: this.appCode ? 1 : 0
-            }).then(res => {
-              this.$message.success('保存成功')
-              this.$parent.init(false)
-              this.$parent.setType = null
-              this.saveloading = false
-              this.saveText = ''
-            }).catch(() => {
-              this.saveloading = false
-              this.saveText = ''
-            })
-          }
-          this.saveloading = false
-          this.saveText = ''
-        } else {
+        if (!valid) {
           return false
         }
-      })
-    },
-    // 字段值填充
-    fieldDescFill () {
-      this.structurePreviewList.forEach(field => {
-        if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
-          field.fieldDesc = field.columnName
+        // 校验参数名称是否重复
+        if (this.dataForm.paramsList.length > 0) {
+          const names = this.dataForm.paramsList.map(value => value.name)
+          const namesSet = new Set(names)
+          if (namesSet.size !== names.length) {
+            this.$message.error('参数名称不能重复,请重新输入')
+            return
+          }
+        }
+        // 设置字段描述
+        const columnMap = {}
+        if (this.structurePreviewList.length > 0) {
+          this.structurePreviewList.forEach(r => {
+            columnMap[r.fieldName] = r.fieldDesc
+          })
+          this.dataForm.fieldDesc = columnMap
+        }
+        this.dataForm.fieldList = this.structurePreviewList
+        this.saveLoading = true
+        this.saveText = '正在保存...'
+        const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
+        const datasetParams = {
+          id: this.dataForm.id,
+          name: this.dataForm.name,
+          typeId: this.dataForm.typeId,
+          datasetType: 'custom',
+          remark: this.dataForm.remark,
+          sourceId: this.dataForm.sourceId,
+          moduleCode: this.appCode,
+          editable: this.appCode ? 1 : 0,
+          config: {
+            className: 'com.gccloud.dataset.entity.config.CustomDataSetConfig',
+            sourceId: this.dataForm.sourceId,
+            sqlProcess: this.dataForm.sqlProcess,
+            paramsList: this.dataForm.paramsList,
+            fieldList: this.dataForm.fieldList,
+            fieldDesc: this.dataForm.fieldDesc
+          }
         }
+        datasetSave(datasetParams).then(res => {
+          this.$message.success('保存成功')
+          this.$parent.init(false)
+          this.$parent.setType = null
+          this.saveLoading = false
+          this.saveText = ''
+        }).catch(() => {
+          this.saveLoading = false
+          this.saveText = ''
+        })
+        this.saveLoading = false
+        this.saveText = ''
       })
-      this.save('form')
-      this.fieldDescVisible = false
-    },
-    // 进入编辑
-    fieldDescEdit () {
-      this.fieldDescVisible = false
-      this.fieldsetVisible = true
-    },
-    // 继续保存
-    toSave () {
-      this.save('form', true)
-      this.fieldDescVisible = false
     },
-    // 获取参数配置-解析并运行
-    buildParams () {
+    /**
+     * 解析并运行数据集
+     */
+    buildParamsAndRun () {
       this.isTest = true
       const reg = /\${(.*?)}/g
       const paramNames = [...new Set([...this.dataForm.sqlProcess.matchAll(reg)].map(item => item[1]))]
@@ -1124,7 +1171,10 @@ export default {
         this.datasetTest()
       }
     },
-    // 数据集测试
+    /**
+     * 数据集测试
+     * @param val
+     */
     datasetTest (val = true) {
       if (this.dataForm.sourceId === '') {
         this.$message.error('请选择数据源')
@@ -1146,172 +1196,111 @@ export default {
       if (val === true) {
         this.current = 1
       }
-      this.saveloading = true
-      sqlTest({
-        datasetId: this.dataForm.id,
-        sqlProcess: this.dataForm.sqlProcess,
-        script: this.dataForm.script,
-        paramConfig: this.dataForm.paramsList.length !== 0 ? JSON.stringify(this.dataForm.paramsList) : '',
-        sourceId: this.dataForm.sourceId,
-        current: this.current,
+      this.saveLoading = true
+
+      const executeParams = {
+        dataSourceId: this.dataForm.sourceId,
+        script: this.dataForm.sqlProcess,
+        params: this.dataForm.paramsList,
+        dataSetType: 'custom',
         size: this.size,
-        curingType: this.dataForm.curingType,
-        dataSetCode: this.dataForm.code,
-        processType: '2'
-      }).then(res => {
-        if (res.code === 500) {
-          this.$message.error('数据查询失败:' + res.msg)
-          this.exception = res.exception
-          this.msg = res.msg
-          this.passTest = false
-        } else {
-          this.dataPreviewList = res.dataMap.dataPreview
-          this.structurePreviewList = res.dataMap.structurePreview
-          // 输出字段描述合并
-          this.structurePreviewList.forEach(item => {
-            const field = this.structurePreviewListCopy.find(_item => _item.columnName === item.columnName)
-            if (field) {
-              item.fieldDesc = field.fieldDesc
-            }
-          })
-          this.structurePreviewList.forEach(item => {
-            if (!item.hasOwnProperty('orderNum')) {
-              this.$set(item, 'orderNum', 0)
-            }
-            if (!item.hasOwnProperty('sourceTable')) {
-              this.$set(item, 'sourceTable', '')
-            }
-            if (!item.hasOwnProperty('fieldDesc')) {
-              this.$set(item, 'fieldDesc', '')
-            }
-          })
-          this.totalCount = res.totalCount
-          this.tableNameList = res.tableNameList
-          if (this.tableNameList && this.tableNameList.length === 1) {
-            this.structurePreviewList.forEach(item => {
-              item.sourceTable = this.tableNameList[0]
-            })
+        current: this.current
+      }
+      datasetExecuteTest(executeParams).then(res => {
+        this.dataPreviewList = res.data.list
+        this.structurePreviewList = res.structure
+        // 输出字段描述合并
+        this.structurePreviewList.forEach(field => {
+          const fieldInfo = this.dataForm.fieldList.find(item => item.fieldName === field.fieldName)
+          if (fieldInfo) {
+            field.fieldDesc = fieldInfo.fieldDesc
+            field.orderNum = fieldInfo.orderNum
+            field.sourceTable = fieldInfo.sourceTable
           }
-          this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-          this.dataForm.cacheCoherence = res.cacheCoherence
-          let paramsNameCheck = false
-          this.dataForm.paramsList.forEach(param => {
-            const checkList = this.structurePreviewList.filter(item => item.columnName === param.name)
-            if (checkList.length) {
-              paramsNameCheck = true
-              param.name = ''
-            }
+        })
+        this.structurePreviewList.forEach(item => {
+          if (!item.hasOwnProperty('orderNum')) {
+            this.$set(item, 'orderNum', 0)
+          }
+          if (!item.hasOwnProperty('sourceTable')) {
+            this.$set(item, 'sourceTable', '')
+          }
+          if (!item.hasOwnProperty('fieldDesc')) {
+            this.$set(item, 'fieldDesc', '')
+          }
+        })
+        this.totalCount = res.data.totalCount
+        this.tableNameList = res.tableNameList
+        // 如果只有一个表,自动填充字段表名
+        if (this.tableNameList && this.tableNameList.length === 1) {
+          this.structurePreviewList.forEach(item => {
+            item.sourceTable = this.tableNameList[0]
           })
-          if (paramsNameCheck) {
-            this.$message.warning('参数名称不可以与字段名相同!')
-            this.passTest = false
-          } else {
-            if (val) this.$message.success('测试成功')
-            this.exception = ''
-            this.msg = ''
-            this.passTest = true
+        }
+        this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
+        let paramsNameCheck = false
+        this.dataForm.paramsList.forEach(param => {
+          const checkList = this.structurePreviewList.filter(item => item.fieldName === param.name)
+          if (checkList.length) {
+            paramsNameCheck = true
+            param.name = ''
           }
+        })
+        if (paramsNameCheck) {
+          this.$message.warning('参数名称不可以与字段名相同!')
+          this.passTest = false
+        } else {
+          if (val) this.$message.success('测试成功')
+          this.exception = ''
+          this.msg = ''
+          this.passTest = true
         }
-        this.saveloading = false
-      }).catch(() => {
+        this.saveLoading = false
+      }).catch((e) => {
+        console.log('测试失败', e)
         this.passTest = false
-        this.saveloading = false
+        this.saveLoading = false
       })
     },
-    // 清空分类
+    /**
+     * 清空分类选择
+     */
     clearType () {
       this.typeName = ''
       this.dataForm.typeId = ''
     },
-    // 分类展开高亮
+    /**
+     * 分类展开高亮
+     * @param $event
+     */
     setCurrentNode ($event) {
       if ($event) {
         const key = this.dataForm.typeId || null
         this.$refs.categorySelectTree.setCurrentKey(key)
       }
     },
-    // 分类选择
+    /**
+     * 分类选择
+     * @param value
+     */
     selectParentCategory (value) {
       this.dataForm.typeId = value.id
       this.typeName = value.name
       this.$refs.selectParentName.blur()
     },
-    // 校验名称【参数名称不能与字段名重复】
-    checkParamsName (value) {
-      const checkList = this.structurePreviewList.filter(item => item.columnName === value.name)
-      if (checkList.length) {
-        this.$message.warning('参数名称不可以与字段名相同!')
-        value.name = ''
-      }
-    },
-    // 删除参数配置
-    delRow (index) {
-      this.paramsListCopy.splice(index, 1)
-    },
-    // 新增参数配置
-    addParam () {
-      this.paramsListCopy.push({
-        name: '',
-        type: '',
-        value: '',
-        status: 1,
-        require: 0,
-        remark: ''
-      })
-    },
-    // 获取数据源
-    getDataSource () {
-      const params = {
-        current: 1,
-        size: 1000,
-        sourceName: '',
-        sourceType: '',
-        moduleCode: this.appCode
-      }
-      datasourcePage(params).then(data => {
-        this.sourceList = data.list
-      })
-    },
     goBack () {
       this.$emit('back')
     },
-    async init () {
-      this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
-      if (this.typeId) {
-        this.dataForm.typeId = this.typeId
-        this.$nextTick(() => {
-          try {
-            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-          } catch (error) {
-            console.error(error)
-          }
-        })
-      }
-      // this.getTreeList()
-      this.getDataSource()
-      if (this.datasetId) {
-        // 获取详情
-        getDatasetInfo(this.datasetId).then(res => {
-          for (const key in res) {
-            if (this.dataForm.hasOwnProperty(key)) {
-              this.dataForm[key] = res[key]
-            }
-          }
-          this.dataForm.name = this.datasetName
-          this.dataForm.paramsList = this.dataForm.paramConfig.length ? JSON.parse(this.dataForm.paramConfig) : []
-          this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
-          if (this.dataForm.typeId) {
-            this.$nextTick(() => {
-              try {
-                this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-              } catch (error) {
-                console.error(error)
-              }
-            })
-          }
-          this.datasetTest(false)
-        })
-      }
+    // 每页大小改变触发
+    sizeChangeHandle (value) {
+      this.size = value
+      this.current = 1
+      this.datasetTest(false)
+    },
+    // 当前页数改变
+    currentChangeHandle (value) {
+      this.current = value
+      this.datasetTest(false)
     },
     // 表头添加提示
     renderHeader (h, { column, index }) {

+ 88 - 2
data-room-ui/packages/DataSetManagement/src/DatasetTypeDialog.vue

@@ -30,6 +30,87 @@
             </div>
           </el-card>
         </el-col>
+
+        <!-- <el-col
+          v-if="datasetTypeList.includes('original')"
+          :span="spanNum"
+        >
+          <el-card
+            class="bs-el-card"
+            shadow="hover"
+          >
+            <div
+              class="type-item"
+              @click="openAddForm('original')"
+            >
+              原始数据集
+            </div>
+          </el-card>
+        </el-col> -->
+        <!-- <el-col
+          v-if="datasetTypeList.includes('custom')"
+          :span="spanNum"
+        >
+          <el-card
+            class="bs-el-card"
+            shadow="hover"
+          >
+            <div
+              class="type-item"
+              @click="openAddForm('custom')"
+            >
+              自助数据集
+            </div>
+          </el-card>
+        </el-col> -->
+        <!-- <el-col
+          v-if="datasetTypeList.includes('storedProcedure')"
+          :span="spanNum"
+        >
+          <el-card
+            class="bs-el-card"
+            shadow="hover"
+          >
+            <div
+              class="type-item"
+              @click="openAddForm('storedProcedure')"
+            >
+              存储过程数据集
+            </div>
+          </el-card>
+        </el-col> -->
+        <!-- <el-col
+          v-if="datasetTypeList.includes('json')"
+          :span="spanNum"
+        >
+          <el-card
+            class="bs-el-card"
+            shadow="hover"
+          >
+            <div
+              class="type-item"
+              @click="openAddForm('json')"
+            >
+              JSON数据集
+            </div>
+          </el-card>
+        </el-col> -->
+        <!-- <el-col
+          v-if="datasetTypeList.includes('script')"
+          :span="spanNum"
+        >
+          <el-card
+            class="bs-el-card"
+            shadow="hover"
+          >
+            <div
+              class="type-item"
+              @click="openAddForm('script')"
+            >
+              脚本数据集
+            </div>
+          </el-card>
+        </el-col> -->
       </el-row>
     </div>
   </el-dialog>
@@ -37,7 +118,6 @@
 
 <script>
 export default {
-  name: 'DatasetTypeDialog',
   props: {
     datasetTypeList: {
       type: Array,
@@ -49,10 +129,16 @@ export default {
       dialogVisible: false
     }
   },
-  created () { },
+  created () {
+    // eslint-disable-next-line eqeqeq
+    // if (this.datasetTypeList.length == 1) this.spanNum = 24
+    // if ([2, 4].includes(this.datasetTypeList.length)) this.spanNum = 12
+    // if ([3, 5, 6].includes(this.datasetTypeList.length)) this.spanNum = 8
+  },
   methods: {
     // 选择新增类型
     openAddForm (type, componentName) {
+      console.log()
       this.dialogVisible = false
       this.$emit('openAddForm', type, componentName)
     }

+ 162 - 187
data-room-ui/packages/DataSetManagement/src/JsonEditForm.vue

@@ -1,6 +1,6 @@
 <template>
   <div
-    v-loading="saveloading"
+    v-loading="saveLoading"
     class="inner-container "
     :element-loading-text="saveText"
   >
@@ -171,11 +171,11 @@
             <div class="field-wrap bs-field-wrap">
               <div
                 v-for="field in structurePreviewList"
-                :key="field.columnName"
+                :key="field.fieldName"
                 class="field-item"
                 @click="fieldsetVisible = true"
               >
-                <span>{{ field.columnName }}</span>&nbsp;<span
+                <span>{{ field.fieldName }}</span>&nbsp;<span
                   v-show="field.fieldDesc"
                   style="color: #909399;"
                 >({{
@@ -224,77 +224,6 @@
           </el-table>
         </div>
       </div>
-      <div
-        v-if="!isEdit"
-        class="dataPreView"
-      >
-        <el-tabs v-model="activeName">
-          <el-tab-pane
-            label="数据1预览"
-            name="data"
-          >
-            <div class="bs-table-box">
-              <el-table
-                align="center"
-                :data="dataPreviewList"
-                max-height="400"
-                :border="true"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  v-for="(value, key) in dataPreviewList[0]"
-                  :key="key"
-                  :label="key"
-                  align="center"
-                  show-overflow-tooltip
-                  :render-header="renderHeader"
-                >
-                  <template slot-scope="scope">
-                    <span>{{ scope.row[key] }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-          <el-tab-pane
-            label="数据集结构"
-            name="structure"
-          >
-            <div class="bs-table-box">
-              <el-table
-                max-height="400"
-                :data="structurePreviewList"
-                :border="true"
-                align="center"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnName"
-                  label="字段值"
-                />
-                <el-table-column
-                  align="center"
-                  prop="fieldDesc"
-                  label="字段描述"
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.fieldDesc"
-                      size="small"
-                      class="labeldsc bs-el-input"
-                    />
-                    <span v-else>{{ scope.row.fieldDesc }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-        </el-tabs>
-      </div>
-
       <!-- 字段填充方式 -->
       <el-dialog
         title="提示"
@@ -350,7 +279,7 @@
             <el-table-column
               align="left"
               show-overflow-tooltip
-              prop="columnName"
+              prop="fieldName"
               label="字段值"
             />
             <el-table-column
@@ -395,7 +324,7 @@
 <script>
 import vueJsonEditor from 'vue-json-editor'
 import vueJsonViewer from 'vue-json-viewer'
-import { getDatasetTypeList, datasetAddorUpdate, getDataset, nameCheckRepeat } from 'packages/js/utils/datasetConfigService'
+import { getCategoryTree, datasetAdd, datasetUpdate, getDataset, nameCheckRepeat } from 'packages/js/utils/datasetConfigService'
 import _ from 'lodash'
 
 export default {
@@ -445,29 +374,28 @@ export default {
         id: '',
         name: '',
         typeId: '',
+        datasetType: 'json',
+        remark: '',
+        // 以下为config配置
         json: '',
-        remark: ''
+        fieldDesc: {},
+        fieldList: []
       },
       rules: {
         name: [
           { required: true, message: '请输入数据集名称', trigger: 'blur' },
           { validator: validateName, trigger: 'blur' }
         ]
-        // typeId: [
-        //   {required: true, message: '请选择分组', trigger: 'blur'}
-        // ]
       },
       typeName: '',
       categoryData: [],
-      activeName: 'data',
       structurePreviewList: [],
       structurePreviewListCopy: [],
       dataPreviewList: [],
       fieldsetVisible: false,
       fieldDescVisible: false,
       passTest: false, // 通过测试
-      fieldDesc: null, // 字段描述
-      saveloading: false,
+      saveLoading: false,
       saveText: ''
     }
   },
@@ -475,12 +403,58 @@ export default {
     this.init()
   },
   methods: {
-    // json错误校验
-    onError () {
-      this.passTest = false
+    /**
+     * 初始化
+     * 1. 获取分类树
+     * 2. 获取数据集详情
+     * 3. 分析JSON
+     */
+    async init () {
+      this.categoryData = await getCategoryTree({ tableName: 'dataset', moduleCode: this.appCode })
+      if (this.typeId) {
+        this.dataForm.typeId = this.typeId
+        this.$nextTick(() => {
+          try {
+            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+          } catch (error) {
+            console.error(error)
+          }
+        })
+      }
+      if (!this.datasetId) {
+        this.dataForm.json = []
+        return
+      }
+      getDataset(this.datasetId).then(res => {
+        this.dataForm.id = res.id
+        this.dataForm.name = res.name
+        this.dataForm.typeId = res.typeId
+        this.dataForm.remark = res.remark
+        this.dataForm.datasetType = res.datasetType
+        this.dataForm.moduleCode = res.moduleCode
+        this.dataForm.editable = res.editable
+        this.dataForm.sourceId = res.sourceId
+        // config 配置
+        this.dataForm.fieldDesc = res.config.fieldDesc
+        this.dataForm.json = JSON.parse(res.config.json)
+        if (this.dataForm.typeId) {
+          this.$nextTick(() => {
+            try {
+              this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+            } catch (error) {
+              console.error(error)
+            }
+          })
+        }
+        this.analysisJSON(null, true)
+      })
     },
-    // 保存数据集
-    save (formName, nochecktosave = false) {
+    /**
+     * 保存数据集
+     * @param  formName 表单名称
+     * @param  noCheckToSave 保存时是否检查
+     */
+    save (formName, noCheckToSave = false) {
       if (!this.passTest) {
         this.$message.error('请确保JSON不为空且解析通过')
         return
@@ -489,7 +463,7 @@ export default {
         this.$message.warning('该JSON未生成输出字段,请重新检查')
         return
       }
-      if (!nochecktosave) {
+      if (!noCheckToSave) {
         const temp = this.structurePreviewList.some(item => {
           return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
         }) // true-存在为空
@@ -499,102 +473,110 @@ export default {
         }
       }
       this.$refs[formName].validate((valid) => {
-        if (valid) {
-          // 通过校验
-          const data = {
-            json: this.dataForm.json,
-            fieldDesc: this.fieldDesc
+        if (!valid) {
+          return
+        }
+        this.dataForm.fieldList = this.structurePreviewList.length ? this.structurePreviewList : []
+        let datasetSave = null
+        datasetSave = this.dataForm.id ? datasetUpdate : datasetAdd
+        const datasetParams = {
+          id: this.dataForm.id,
+          name: this.dataForm.name,
+          typeId: this.dataForm.typeId,
+          datasetType: 'json',
+          remark: this.dataForm.remark,
+          moduleCode: this.appCode,
+          editable: this.appCode ? 1 : 0,
+          config: {
+            className: 'com.gccloud.dataset.entity.config.JsonDataSetConfig',
+            json: JSON.stringify(this.dataForm.json),
+            fieldDesc: this.dataForm.fieldDesc,
+            fieldList: this.dataForm.fieldList
           }
-          this.saveloading = true
-          this.saveText = '正在保存...'
-          datasetAddorUpdate({
-            id: this.datasetId,
-            name: this.dataForm.name,
-            typeId: this.dataForm.typeId,
-            remark: this.dataForm.remark,
-            datasetType: 'json',
-            moduleCode: this.appCode,
-            editable: this.appCode ? 1 : 0,
-            data: JSON.stringify(data)
-          }).then(() => {
-            this.$message.success('保存成功')
-            this.$parent.init(false)
-            this.$parent.setType = null
-            this.saveloading = false
-            this.saveText = ''
-          }).catch(() => {
-            this.saveloading = false
-            this.saveText = ''
-          })
-        } else {
-          return false
         }
+        datasetSave(datasetParams).then(() => {
+          this.$message.success('保存成功')
+          this.$parent.init(false)
+          this.$parent.setType = null
+          this.saveLoading = false
+          this.saveText = ''
+        }).catch(() => {
+          this.saveLoading = false
+          this.saveText = ''
+        })
       })
     },
-    // 字段值填充
+    /**
+     * 使用字段名作为字段描述
+     */
     fieldDescFill () {
-      this.fieldDesc = {}
+      this.dataForm.fieldDesc = {}
       this.structurePreviewList.forEach(field => {
         if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
-          field.fieldDesc = field.columnName
-          this.fieldDesc[field.columnName] = field.columnName
+          field.fieldDesc = field.fieldName
+          this.dataForm.fieldDesc[field.fieldName] = field.fieldName
         } else {
-          this.fieldDesc[field.columnName] = field.fieldDesc
+          this.dataForm.fieldDesc[field.fieldName] = field.fieldDesc
         }
       })
       this.save('form')
       this.fieldDescVisible = false
     },
-    // 进入编辑
+    /**
+     * 进入字段描述编辑弹窗
+     */
     fieldDescEdit () {
       this.fieldDescVisible = false
       this.fieldsetVisible = true
     },
-    // 继续保存
+    /**
+     * 跳过字段描述编辑直接保存
+     */
     toSave () {
-      this.fieldDesc = {}
+      this.dataForm.fieldDesc = {}
       this.structurePreviewList.forEach(field => {
-        this.fieldDesc[field.columnName] = field.fieldDesc
+        this.dataForm.fieldDesc[field.fieldName] = field.fieldDesc
       })
       this.save('form', true)
       this.fieldDescVisible = false
     },
-    // 取消操作
+    /**
+     * 取消字段描述编辑
+     */
     cancelField () {
       this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
       this.fieldsetVisible = false
     },
-    // 设置输出字段
+    /**
+     * 保存字段描述编辑
+     */
     setField () {
       this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
       if (this.structurePreviewList.length) {
-        this.fieldDesc = {}
+        this.dataForm.fieldDesc = {}
         this.structurePreviewList.forEach(key => {
-          this.fieldDesc[key.columnName] = key.fieldDesc
+          this.dataForm.fieldDesc[key.fieldName] = key.fieldDesc
         })
       } else {
-        this.fieldDesc = null
+        this.dataForm.fieldDesc = null
       }
       this.fieldsetVisible = false
     },
-    // 字段描述构建及同步
-    buildFieldDesc () {
-      const fieldDesc = {}
-      this.structurePreviewList.forEach(field => {
-        if (this.fieldDesc.hasOwnProperty(field.columnName)) {
-          field.fieldDesc = this.fieldDesc[field.columnName]
-        }
-        fieldDesc[field.columnName] = field.fieldDesc
-      })
-      this.fieldDesc = fieldDesc
+    // json错误校验
+    onError () {
+      this.passTest = false
     },
-    // 解析json
+    /**
+     * 解析JSON
+     * @param  $event 事件
+     * @param  initAnalysis 是否初始化解析
+     */
     analysisJSON ($event, initAnalysis = false) {
       if (Object.prototype.toString.call(this.dataForm.json) === '[object Object]') {
         // json为对象
         this.structurePreviewList = Object.keys(this.dataForm.json).map(key => {
           return {
-            columnName: key,
+            fieldName: key,
             fieldDesc: ''
           }
         })
@@ -605,7 +587,7 @@ export default {
         if (Object.prototype.toString.call(this.dataForm.json[0]) === '[object Object]') {
           this.structurePreviewList = Object.keys(this.dataForm.json[0]).map(key => {
             return {
-              columnName: key,
+              fieldName: key,
               fieldDesc: ''
             }
           })
@@ -615,7 +597,7 @@ export default {
           try {
             this.structurePreviewList = Object.keys(JSON.parse(this.dataForm.json[0])).map(key => {
               return {
-                columnName: key,
+                fieldName: key,
                 fieldDesc: ''
               }
             })
@@ -636,7 +618,7 @@ export default {
             // json为对象
             this.structurePreviewList = Object.keys(json).map(key => {
               return {
-                columnName: key,
+                fieldName: key,
                 fieldDesc: ''
               }
             })
@@ -647,7 +629,7 @@ export default {
             if (Object.prototype.toString.call(json[0]) === '[object Object]') {
               this.structurePreviewList = Object.keys(json[0]).map(key => {
                 return {
-                  columnName: key,
+                  fieldName: key,
                   fieldDesc: ''
                 }
               })
@@ -657,7 +639,7 @@ export default {
               try {
                 this.structurePreviewList = Object.keys(JSON.parse(json[0])).map(key => {
                   return {
-                    columnName: key,
+                    fieldName: key,
                     fieldDesc: ''
                   }
                 })
@@ -677,7 +659,7 @@ export default {
           this.$message.warning('JSON格式错误')
         }
       }
-      if (this.structurePreviewList.length && this.fieldDesc) {
+      if (this.structurePreviewList.length && this.dataForm.fieldDesc) {
         this.buildFieldDesc()
       }
       if (this.passTest && !initAnalysis) {
@@ -685,64 +667,57 @@ export default {
       }
       this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
     },
-    // 初始化
-    async init () {
-      this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
-      if (this.typeId) {
-        this.dataForm.typeId = this.typeId
-        this.$nextTick(() => {
-          try {
-            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-          } catch (error) {
-            console.error(error)
-          }
-        })
-      }
-      if (this.datasetId) {
-        getDataset(this.datasetId).then(res => {
-          this.dataForm.id = res.id
-          const data = JSON.parse(res.data)
-          this.dataForm.name = res.name
-          this.dataForm.typeId = res.typeId
-          this.dataForm.remark = res.remark
-          this.dataForm.json = data.json
-          this.fieldDesc = data.fieldDesc
-          if (this.dataForm.typeId) {
-            this.$nextTick(() => {
-              try {
-                this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-              } catch (error) {
-                console.error(error)
-              }
-            })
-          }
-          this.analysisJSON(null, true)
-        })
-      }
+    /**
+     * 构建字段描述
+     */
+    buildFieldDesc () {
+      const fieldDesc = {}
+      this.structurePreviewList.forEach(field => {
+        if (this.dataForm.fieldDesc.hasOwnProperty(field.fieldName)) {
+          field.fieldDesc = this.dataForm.fieldDesc[field.fieldName]
+        }
+        fieldDesc[field.fieldName] = field.fieldDesc
+      })
+      this.dataForm.fieldDesc = fieldDesc
     },
+    /**
+     * 回到数据集列表页面
+     */
     goBack () {
       this.$emit('back')
     },
-    // 表头添加提示
+    /**
+     * 表头添加提示
+     * @param h
+     * @param column
+     * @param index
+     * @returns {*}
+     */
     renderHeader (h, { column, index }) {
       const labelLong = column.label.length // 表头label长度
       const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义
       column.minWidth = labelLong * size < 120 ? 120 : labelLong * size // 根据label长度计算该表头最终宽度
       return h('span', { class: 'cell-content', style: { width: '100%' } }, [column.label])
     },
-    // 清空分类
+    /**
+     * 清空分类
+     */
     clearType () {
       this.typeName = ''
       this.dataForm.typeId = ''
     },
-    // 分类展开高亮
+    /**
+     * 分类展开高亮
+     */
     setCurrentNode ($event) {
       if ($event) {
         const key = this.dataForm.typeId || null
         this.$refs.categorySelectTree.setCurrentKey(key)
       }
     },
-    // 分类选择
+    /**
+     * 分类选择
+     */
     selectParentCategory (value) {
       this.dataForm.typeId = value.id
       this.typeName = value.name

+ 280 - 295
data-room-ui/packages/DataSetManagement/src/OriginalEditForm.vue

@@ -1,6 +1,6 @@
 <template>
   <div
-    v-loading="saveloading"
+    v-loading="saveLoading"
     class="inner-container"
     :element-loading-text="saveText"
   >
@@ -15,7 +15,7 @@
               <div class="page-header-right">
                 <el-button
                   class="bs-el-button-default"
-                  @click="openNewWindow('https://www.yuque.com/chuinixiongkou/bigscreen/original_dataset')"
+                  @click="openNewWindow('https://www.yuque.com/chuinixiongkou/bigscreen/ry3ggnrts7q3ro1g')"
                 >
                   帮助
                 </el-button>
@@ -271,11 +271,11 @@
             <div class="field-wrap bs-field-wrap bs-scrollbar">
               <div
                 v-for="field in structurePreviewList"
-                :key="field.columnName"
+                :key="field.fieldName"
                 class="field-item"
                 @click="fieldsetVisible = true"
               >
-                <span>{{ field.columnName }}</span>&nbsp;<span
+                <span>{{ field.fieldName }}</span>&nbsp;<span
                   v-show="field.fieldDesc"
                   style="color: #909399;"
                 >({{
@@ -343,109 +343,6 @@
           />
         </div>
       </div>
-      <div
-        v-if="!isEdit"
-        class="dataPreView"
-      >
-        <el-tabs v-model="activeName">
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据预览"
-            name="data"
-          >
-            <div class="bs-table-box">
-              <el-table
-                align="center"
-                :data="dataPreviewList"
-                max-height="400"
-                :border="true"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  v-for="(value, key) in dataPreviewList[0]"
-                  :key="key"
-                  :label="key"
-                  align="center"
-                  show-overflow-tooltip
-                  :render-header="renderHeader"
-                >
-                  <template slot-scope="scope">
-                    <span>{{ scope.row[key] }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据集结构"
-            name="structure"
-          >
-            <div class="bs-table-box">
-              <el-table
-                max-height="400"
-                :data="structurePreviewList"
-                :border="true"
-                align="center"
-              >
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnName"
-                  label="字段值"
-                />
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnType"
-                  label="字段类型"
-                />
-                <el-table-column
-                  align="center"
-                  prop="fieldDesc"
-                  label="字段描述"
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.fieldDesc"
-                      size="small"
-                      class="labeldsc bs-el-input"
-                    />
-                    <span v-else>{{ scope.row.fieldDesc }}</span>
-                  </template>
-                </el-table-column>
-
-                <el-table-column
-                  align="center"
-                  prop="orderNum"
-                  label="字段排序"
-                  sortable
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.orderNum"
-                      size="small"
-                      class="labeldsc bs-el-input"
-                    />
-                    <span v-else>{{ scope.row.orderNum }}</span>
-                  </template>
-                </el-table-column>
-                <el-table-column
-                  align="center"
-                  prop="sourceTable"
-                  label="字段来源"
-                >
-                  <template slot-scope="scope">
-                    <span>{{ scope.row.sourceTable }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-        </el-tabs>
-      </div>
       <el-dialog
         title="提示"
         :visible.sync="fieldDescVisible"
@@ -500,13 +397,13 @@
             <el-table-column
               align="left"
               show-overflow-tooltip
-              prop="columnName"
+              prop="fieldName"
               label="字段值"
             />
             <el-table-column
               align="center"
               show-overflow-tooltip
-              prop="columnType"
+              prop="fieldType"
               label="字段类型"
             />
             <el-table-column
@@ -570,8 +467,13 @@
 </template>
 
 <script>
-import { getDatasetTypeList, nameCheckRepeat, getOriginalTableDetail, addOrUpdateOriginal, getOriginalTableFieldInfo, getOriginalTableDetailsById } from 'packages/js/utils/datasetConfigService'
-import { datasourcePage, getSourceTable, getSourceView } from 'packages/js/utils/dataSourceService'
+import {
+  getCategoryTree,
+  nameCheckRepeat,
+  datasetExecuteTest,
+  getDataset, datasetUpdate, datasetAdd
+} from 'packages/js/utils/datasetConfigService'
+import { datasourceList, getSourceTable, getSourceView, getTableFieldList } from 'packages/js/utils/dataSourceService'
 import _ from 'lodash'
 export default {
   name: 'OriginalEditForm',
@@ -616,22 +518,21 @@ export default {
         id: '',
         name: '',
         typeId: '',
+        datasetType: 'original',
+        remark: '',
+        // 以下为config信息
         sourceId: '',
         repeatStatus: 1,
         tableName: '',
         fieldInfo: [],
-        remark: '',
-        fieldDesc: '',
-        fieldJson: ''
+        fieldDesc: {},
+        fieldList: []
       },
       rules: {
         name: [
           { required: true, message: '数据集名称不能为空', trigger: 'blur' },
           { validator: validateName, trigger: 'blur' }
         ],
-        // typeId: [
-        //   {required: true, message: '请选择分组', trigger: 'blur'}
-        // ],
         sourceId: [
           { required: true, message: '请选择数据源', trigger: 'blur' }
         ],
@@ -643,20 +544,28 @@ export default {
         ]
       },
       typeName: '',
+      // 分组分类树
       categoryData: [],
+      // 数据源列表
       sourceList: [],
+      // 表列表
       tableList: [],
+      // 视图列表
       viewList: [],
+      // 字段列表
       fieldList: [],
       isSelectAll: false,
       activeName: 'data',
+      // 预览数据
       dataPreviewList: [],
+      // 字段结构
       structurePreviewList: [],
+      // 字段结构副本
       structurePreviewListCopy: [],
       tableLoading: false,
       fieldDescVisible: false,
       fieldsetVisible: false,
-      saveloading: false,
+      saveLoading: false,
       saveText: '',
       totalCount: 0,
       currentCount: 0,
@@ -669,7 +578,14 @@ export default {
       handler (value) {
         try {
           this.setCheck()
-          this.getPreViewData()
+          const fieldDescMap = {}
+          this.fieldList.forEach((item) => {
+            if (value.length !== 0 && !value.includes(item.columnName)) {
+              return
+            }
+            fieldDescMap[item.columnName] = item.columnComment
+          })
+          this.getPreViewData(fieldDescMap)
         } catch (error) {
           console.error(error)
         }
@@ -682,21 +598,79 @@ export default {
     this.init()
   },
   methods: {
-    // 获取预览数据
+    /**
+     * 初始化
+     * 1.获取分类树
+     * 2.获取数据源列表
+     * 3.获取数据集详情
+     * 4.获取原始表列表
+     * 5.获取字段列表
+     */
+    async init () {
+      // 获取分类树
+      this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
+      // 如果传入了分类id,则设置分类id和分类名称
+      if (this.typeId) {
+        this.dataForm.typeId = this.typeId
+        this.$nextTick(() => {
+          try {
+            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+          } catch (error) {
+            console.error(error)
+          }
+        })
+      }
+      this.queryAllSource()
+      if (!this.datasetId) {
+        return
+      }
+      // 获取详情
+      getDataset(this.datasetId).then(res => {
+        this.dataForm.id = res.id
+        this.dataForm.name = res.name
+        this.dataForm.typeId = res.typeId
+        this.dataForm.remark = res.remark
+        this.dataForm.datasetType = res.datasetType
+        this.dataForm.moduleCode = res.moduleCode
+        this.dataForm.editable = res.editable
+        this.dataForm.sourceId = res.sourceId
+        // config 配置
+        this.dataForm.tableName = res.config.tableName
+        this.dataForm.repeatStatus = res.config.repeatStatus
+        this.dataForm.fieldList = res.config.fieldList
+        this.dataForm.fieldDesc = res.config.fieldDesc
+        // 字段信息,转为数组
+        this.dataForm.fieldInfo = res.config.fieldInfo ? res.config.fieldInfo.split(',') : []
+        if (this.dataForm.typeId) {
+          this.$nextTick(() => {
+            try {
+              this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+            } catch (error) {
+              console.error(error)
+            }
+          })
+        }
+        this.queryAllTable()
+        this.queryAllField()
+      })
+    },
+    /**
+     * 获取预览数据
+     */
     getData () {
-      const params = {
-        id: this.dataForm.id ? this.dataForm.id : '',
-        sourceId: this.dataForm.sourceId,
-        tableName: this.dataForm.tableName,
-        fieldInfo: this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo.join(',') : '',
-        repeatStatus: this.dataForm.repeatStatus,
+      const executeParams = {
+        dataSourceId: this.dataForm.sourceId,
+        script: this.getSql(),
+        // 原始表数据集没有数据集参数
+        params: [],
+        dataSetType: 'original',
         size: this.size,
         current: this.current
       }
       this.tableLoading = true
-      getOriginalTableDetail(params).then((data) => {
-        this.dataPreviewList = data.dataPreview
-        this.totalCount = data.totalCount
+      datasetExecuteTest(executeParams).then((data) => {
+        this.dataPreviewList = data.data.list
+        this.totalCount = data.data.totalCount
         this.tableLoading = false
       }).catch(() => {
         this.dataPreviewList = []
@@ -704,59 +678,74 @@ export default {
         this.tableLoading = false
       })
     },
-    // 每页大小改变触发
-    sizeChangeHandle (value) {
-      this.size = value
-      this.current = 1
-      this.getData()
-    },
-    // 当前页数改变
-    currentChangeHandle (value) {
-      this.current = value
-      this.getData()
+    /**
+     * 组装sql
+     * @returns {string}
+     */
+    getSql () {
+      let sql = 'SELECT '
+      if (this.dataForm.repeatStatus === 0) {
+        sql += ' DISTINCT '
+      }
+      if (this.dataForm.fieldInfo.length > 0) {
+        sql += this.dataForm.fieldInfo.join(',')
+      } else {
+        sql += '*'
+      }
+      sql += ` FROM ${this.dataForm.tableName}`
+      return sql
     },
-    // 取消操作
+    /**
+     * 取消字段描述编辑
+     */
     cancelField () {
       this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
       this.fieldsetVisible = false
     },
-    // 设置输出字段
+    /**
+     * 保存字段描述编辑
+     */
     setField () {
       this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
       this.fieldsetVisible = false
     },
-    // 字段值填充
+    /**
+     * 使用字段名作为字段描述
+     */
     fieldDescFill () {
       this.structurePreviewList.forEach(item => {
         if (item.fieldDesc === '') {
-          item.fieldDesc = item.columnName
+          item.fieldDesc = item.fieldName
         }
       })
       this.save('form')
       this.fieldDescVisible = false
     },
-    // 进入编辑
+    /**
+     * 进入字段描述编辑弹窗
+     */
     fieldDescEdit () {
-      this.activeName = 'structure'
-      // 滑动到底部
-      this.$nextTick(() => {
-        const dataAdd = document.getElementsByClassName('router-tab__container')[0]
-        dataAdd.scrollTop = dataAdd.scrollHeight
-      })
       this.fieldDescVisible = false
+      this.fieldsetVisible = true
     },
-    // 继续保存
+    /**
+     * 跳过字段描述编辑直接保存
+     */
     toSave () {
       this.save('form', true)
       this.fieldDescVisible = false
     },
-    // 保存
-    save (formName, nochecktosave = false) {
+    /**
+     * 保存数据集
+     * @param formName 表单名称
+     * @param noCheckToSave 是否不检查直接保存
+     */
+    save (formName, noCheckToSave = false) {
       if (!this.structurePreviewList.length) {
         this.$message.warning('该原始数据集未生成输出字段,请重新检查')
         return
       }
-      if (!nochecktosave) {
+      if (!noCheckToSave) {
         const temp = this.structurePreviewList.some(item => {
           return item.fieldDesc === ''
         }) // true-存在为空
@@ -766,117 +755,69 @@ export default {
         }
       }
       this.$refs[formName].validate((valid) => {
-        if (valid) {
-          const columnMap = {}
-          this.structurePreviewList.forEach(item => {
-            columnMap[item.columnName] = item.fieldDesc
-          })
-          this.dataForm.fieldDesc = JSON.stringify(columnMap)
-          this.dataForm.fieldInfo = this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo.join(',') : ''
-          this.dataForm.fieldJson = this.structurePreviewList.length ? JSON.stringify(this.structurePreviewList) : ''
-          this.saveloading = true
-          this.saveText = '正在保存...'
-          addOrUpdateOriginal({
-            ...this.dataForm,
-            moduleCode: this.appCode,
-            editable: this.appCode ? 1 : 0
-          }).then(res => {
-            this.$message.success('保存成功')
-            this.$parent.init(false)
-            this.$parent.setType = null
-            this.saveloading = false
-            this.saveText = ''
-          }).catch(() => {
-            this.$message.error('保存失败')
-            this.saveloading = false
-            this.saveText = ''
-          })
-        } else {
-          this.saveloading = false
+        if (!valid) {
+          this.saveLoading = false
           this.saveText = ''
           return false
         }
-      })
-    },
-    goBack () {
-      this.$emit('back')
-    },
-    async init () {
-      this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
-      // this.getTreeList()
-      if (this.typeId) {
-        this.dataForm.typeId = this.typeId
-        this.$nextTick(() => {
-          try {
-            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-          } catch (error) {
-            console.error(error)
-          }
+        // 组装字段描述
+        const columnMap = {}
+        this.structurePreviewList.forEach(item => {
+          columnMap[item.fieldName] = item.fieldDesc
         })
-      }
-      this.queryAllSource()
-      if (this.datasetId) {
-        // 获取详情
-        getOriginalTableDetailsById(this.datasetId).then(res => {
-          for (const key in res) {
-            if (this.dataForm.hasOwnProperty(key)) {
-              this.dataForm[key] = res[key]
-            }
-          }
-          this.dataForm.fieldInfo = res.fieldInfo ? res.fieldInfo.split(',') : []
-          this.dataForm.name = this.datasetName
-          if (this.dataForm.typeId) {
-            this.$nextTick(() => {
-              try {
-                this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-              } catch (error) {
-                console.error(error)
-              }
-            })
-          }
-          this.queryAllTable()
-          this.queryAllField()
+        // 组装保存参数
+        const datasetParams = {
+          id: this.dataForm.id,
+          name: this.dataForm.name,
+          typeId: this.dataForm.typeId,
+          remark: this.dataForm.remark,
+          datasetType: 'original',
+          sourceId: this.dataForm.sourceId,
+          config: {
+            className: 'com.gccloud.dataset.entity.config.OriginalDataSetConfig',
+            sourceId: this.dataForm.sourceId,
+            tableName: this.dataForm.tableName,
+            fieldInfo: this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo.join(',') : '',
+            fieldDesc: columnMap,
+            fieldList: this.structurePreviewList,
+            repeatStatus: this.dataForm.repeatStatus
+          },
+          moduleCode: this.appCode,
+          editable: this.appCode ? 1 : 0
+        }
+        this.saveLoading = true
+        this.saveText = '正在保存...'
+        const saveOriginal = this.dataForm.id ? datasetUpdate : datasetAdd
+        saveOriginal(datasetParams).then(res => {
+          this.$message.success('保存成功')
+          this.$parent.init(false)
+          this.$parent.setType = null
+          this.saveLoading = false
+          this.saveText = ''
+        }).catch(() => {
+          this.$message.error('保存失败')
+          this.saveLoading = false
+          this.saveText = ''
         })
-      }
-    },
-    // 清空分类
-    clearType () {
-      this.typeName = ''
-      this.dataForm.typeId = ''
-    },
-    // 分类展开高亮
-    setCurrentNode ($event) {
-      if ($event) {
-        const key = this.dataForm.typeId || null
-        this.$refs.categorySelectTree.setCurrentKey(key)
-      }
-    },
-    // 分类选择
-    selectParentCategory (value) {
-      this.dataForm.typeId = value.id
-      this.typeName = value.name
-      this.$refs.selectParentName.blur()
+      })
     },
-    // 获取树节点
-    // getTreeList() {
-    //   getOriginalTableList().then(res => {
-    //     this.categoryData = res
-    //   })
-    // },
-    // 获取数据集
+    /**
+     * 获取数据源列表
+     */
     queryAllSource () {
       const params = {
-        current: 1,
-        size: 1000,
         sourceName: '',
         sourceType: '',
         moduleCode: this.appCode
       }
-      datasourcePage(params).then(res => {
-        this.sourceList = res.list
+      datasourceList(params).then(res => {
+        this.sourceList = res
       })
     },
-    // 设置数据源
+    /**
+     * 选中数据源
+     * @param value
+     */
     setSource (value) {
       this.dataForm.tableName = ''
       this.dataForm.fieldInfo = []
@@ -885,7 +826,11 @@ export default {
       if (!this.dataForm.sourceId) return
       this.queryAllTable()
     },
-    // 获取原始表
+    /**
+     * 获取原始表列表
+     * 1.获取表列表
+     * 2.获取视图列表
+     */
     queryAllTable () {
       getSourceTable(this.dataForm.sourceId).then(res => {
         this.tableList = res
@@ -898,31 +843,39 @@ export default {
         this.viewList = []
       })
     },
-    // 设置原始表
+    /**
+     * 选中原始表
+     * @param value
+     */
     setTable (value) {
       this.fieldList = []
       this.dataForm.fieldInfo = []
       if (!this.dataForm.tableName) return
       this.queryAllField()
     },
-    // 获取原始表字段
+    /**
+     * 获取原始表字段列表
+     */
     queryAllField () {
-      getOriginalTableFieldInfo({
-        sourceId: this.dataForm.sourceId,
-        tableName: this.dataForm.tableName
-      }).then((data) => {
+      getTableFieldList(this.dataForm.sourceId, this.dataForm.tableName).then((data) => {
+        const fieldDescMap = {}
         this.fieldList = data.map(field => {
+          fieldDescMap[field.columnName] = field.columnComment
           field.isCheck = false
           if (this.dataForm.fieldInfo.includes(field.columnName)) {
             field.isCheck = true
           }
           return field
         })
-        this.getPreViewData()
+        this.getPreViewData(fieldDescMap)
       }).catch(() => {
         this.fieldList = []
       })
     },
+    /**
+     * 选中字段
+     * @param values 选中的字段列表
+     */
     setFields (values) {
       if (values.includes('全选')) {
         // 说明已经全选了,所以全不选
@@ -933,7 +886,9 @@ export default {
         }
       }
     },
-    // 设置字段check
+    /**
+     * 设置字段选中状态
+     */
     setCheck () {
       this.fieldList.forEach(field => {
         if (this.dataForm.fieldInfo.includes(field.columnName)) {
@@ -948,24 +903,28 @@ export default {
         this.isSelectAll = false
       }
     },
-    getPreViewData () {
+    /**
+     * 获取数据预览
+     * @param fieldDescMap 字段描述
+     */
+    getPreViewData (fieldDescMap) {
       this.dataPreviewList = []
       this.structurePreviewList = []
       this.structurePreviewListCopy = []
       if (!this.dataForm.sourceId || !this.dataForm.tableName) return
-      const params = {
-        id: this.dataForm.id ? this.dataForm.id : '',
-        sourceId: this.dataForm.sourceId,
-        tableName: this.dataForm.tableName,
-        fieldInfo: this.dataForm.fieldInfo.length ? this.dataForm.fieldInfo.join(',') : '',
-        repeatStatus: this.dataForm.repeatStatus,
+      const executeParams = {
+        dataSourceId: this.dataForm.sourceId,
+        script: this.getSql(),
+        // 原始表数据集没有数据集参数
+        params: [],
+        dataSetType: 'original',
         size: this.size,
         current: this.current
       }
       this.tableLoading = true
-      getOriginalTableDetail(params).then((data) => {
-        this.dataPreviewList = data.dataPreview
-        this.structurePreviewList = data.structurePreview
+      datasetExecuteTest(executeParams).then((data) => {
+        this.dataPreviewList = data.data.list
+        this.structurePreviewList = data.structure
         this.structurePreviewList.forEach(item => {
           if (!item.hasOwnProperty('orderNum')) {
             this.$set(item, 'orderNum', 0)
@@ -974,14 +933,19 @@ export default {
             this.$set(item, 'sourceTable', this.dataForm.tableName)
           }
           if (!item.hasOwnProperty('fieldDesc')) {
-            this.$set(item, 'fieldDesc', '')
+            let fieldDesc = ''
+            if (fieldDescMap && fieldDescMap[item.fieldName]) {
+              fieldDesc = fieldDescMap[item.fieldName]
+            }
+            this.$set(item, 'fieldDesc', fieldDesc)
           }
         })
         this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-        this.totalCount = data.totalCount
-        this.currentCount = data.currentCount
+        this.totalCount = data.data.totalCount
+        this.currentCount = data.data.currentCount
         this.tableLoading = false
-      }).catch(() => {
+      }).catch((e) => {
+        console.log(e)
         this.dataPreviewList = []
         this.structurePreviewList = []
         this.structurePreviewListCopy = []
@@ -990,34 +954,55 @@ export default {
         this.tableLoading = false
       })
     },
-    // 表头添加提示
+    /**
+     * 表头添加提示
+     */
     renderHeader (h, { column, index }) {
       const labelLong = column.label.length // 表头label长度
       const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义
       column.minWidth = labelLong * size < 120 ? 120 : labelLong * size // 根据label长度计算该表头最终宽度
       return h('span', { class: 'cell-content', style: { width: '100%' } }, [column.label])
     },
-    resetData () {
-      this.dataForm = {
-        id: '',
-        name: '',
-        typeId: '',
-        sourceId: '',
-        repeatStatus: 0,
-        tableName: '',
-        fieldInfo: [],
-        remark: '',
-        fieldDesc: ''
+    /**
+     * 回到数据集列表页面
+     */
+    goBack () {
+      this.$emit('back')
+    },
+    /**
+     * 清空分类
+     */
+    clearType () {
+      this.typeName = ''
+      this.dataForm.typeId = ''
+    },
+    /**
+     * 分类展开高亮
+     */
+    setCurrentNode ($event) {
+      if ($event) {
+        const key = this.dataForm.typeId || null
+        this.$refs.categorySelectTree.setCurrentKey(key)
       }
-      this.sourceList = []
-      this.tableList = []
-      this.fieldList = []
-      this.isSelectAll = false
-      this.activeName = 'data'
-      this.dataPreviewList = []
-      this.structurePreviewList = []
-      this.structurePreviewListCopy = []
-      this.$refs.form.clearValidate()
+    },
+    /**
+     * 分类选择
+     */
+    selectParentCategory (value) {
+      this.dataForm.typeId = value.id
+      this.typeName = value.name
+      this.$refs.selectParentName.blur()
+    },
+    // 每页大小改变触发
+    sizeChangeHandle (value) {
+      this.size = value
+      this.current = 1
+      this.getData()
+    },
+    // 当前页数改变
+    currentChangeHandle (value) {
+      this.current = value
+      this.getData()
     },
     openNewWindow (url) {
       window.open(url, '_blank')

+ 224 - 263
data-room-ui/packages/DataSetManagement/src/ScriptEditForm.vue

@@ -1,6 +1,6 @@
 <template>
   <div
-    v-loading="saveloading"
+    v-loading="saveLoading"
     class="inner-container"
     :element-loading-text="saveText"
   >
@@ -201,11 +201,11 @@
               <div class="field-wrap bs-field-wrap bs-scrollbar">
                 <div
                   v-for="field in structurePreviewList"
-                  :key="field.columnName"
+                  :key="field.fieldName"
                   class="field-item"
                   @click="fieldsetVisible = true"
                 >
-                  <span>{{ field.columnName }}</span>&nbsp;<span
+                  <span>{{ field.fieldName }}</span>&nbsp;<span
                     v-show="field.fieldDesc"
                     style="color: #909399;"
                   >({{
@@ -258,78 +258,6 @@
           </el-table>
         </div>
       </div>
-      <div
-        v-if="!isEdit"
-        class="dataPreView"
-      >
-        <el-tabs v-model="activeName">
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据预览"
-            name="data"
-          >
-            <div class="bs-table-box">
-              <el-table
-                align="center"
-                :data="dataPreviewList"
-                max-height="400"
-                :border="true"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  v-for="(value, key) in dataPreviewList[0]"
-                  :key="key"
-                  :label="key"
-                  align="center"
-                  show-overflow-tooltip
-                  :render-header="renderHeader"
-                >
-                  <template slot-scope="scope">
-                    <span>{{ scope.row[key] }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据集结构"
-            name="structure"
-          >
-            <div class="bs-table-box">
-              <el-table
-                max-height="400"
-                :data="structurePreviewList"
-                :border="true"
-                align="center"
-              >
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnName"
-                  label="字段值"
-                />
-                <el-table-column
-                  align="center"
-                  prop="fieldDesc"
-                  label="字段描述"
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.fieldDesc"
-                      size="small"
-                      class="labeldsc bs-el-input"
-                    />
-                    <span v-else>{{ scope.row.fieldDesc }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-        </el-tabs>
-      </div>
-
       <!-- 字段填充方式 -->
       <el-dialog
         title="提示"
@@ -385,7 +313,7 @@
             <el-table-column
               align="left"
               show-overflow-tooltip
-              prop="columnName"
+              prop="fieldName"
               label="字段值"
             />
             <el-table-column
@@ -588,9 +516,14 @@
 </template>
 
 <script>
-import { nameCheckRepeat, getDatasetTypeList, datasetAddorUpdate, getDataset, datasetExecute } from 'packages/js/utils/datasetConfigService'
+import {
+  nameCheckRepeat,
+  getCategoryTree,
+  getDataset,
+  datasetExecuteTest,
+  datasetAdd, datasetUpdate
+} from 'packages/js/utils/datasetConfigService'
 import { codemirror } from 'vue-codemirror'
-// import 'codemirror/mode/sql/sql.js'
 import 'codemirror/mode/groovy/groovy'
 
 import 'codemirror/lib/codemirror.css'
@@ -642,18 +575,19 @@ export default {
         id: '',
         name: '',
         typeId: '',
+        datasetType: 'script',
         remark: '',
+        // 以下为config配置
         script: '',
-        paramsList: []
+        paramsList: [],
+        fieldDesc: {},
+        fieldList: []
       },
       rules: {
         name: [
           { required: true, message: '请输入数据集名称', trigger: 'blur' },
           { validator: validateName, trigger: 'blur' }
         ]
-        // typeId: [
-        //   {required: true, message: '请选择分组', trigger: 'blur'}
-        // ]
       },
       cOptions: {
         mode: 'text/x-groovy',
@@ -665,28 +599,23 @@ export default {
           completeSingle: true
         }
       },
-      activeName: 'data',
       dataPreviewList: [],
       structurePreviewList: [],
       structurePreviewListCopy: [],
-      typeSelect: [{
-        value: 'String'
-      }, {
-        value: 'Integer'
-      }, {
-        value: 'Double'
-      }, {
-        value: 'Long'
-      }, {
-        value: 'Date'
-      }],
+      typeSelect: [
+        { value: 'String' },
+        { value: 'Integer' },
+        { value: 'Double' },
+        { value: 'Long' },
+        { value: 'Date' }
+      ],
       typeName: '',
       categoryData: [],
       fieldDescVisible: false,
       fieldsetVisible: false,
       paramsVisible: false,
       tableLoading: false,
-      saveloading: false,
+      saveLoading: false,
       saveText: '',
       paramsListCopy: [],
       isSet: false, // 参数是否配置状态
@@ -703,8 +632,50 @@ export default {
     this.init()
   },
   methods: {
-    // 保存数据集
-    save (formName, nochecktosave = false) {
+    /**
+     * 初始化
+     * 1. 获取数据集分类
+     * 2. 获取数据集详情
+     * 3. 执行脚本数据集
+     */
+    async init () {
+      this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
+      if (this.typeId) {
+        this.dataForm.typeId = this.typeId
+        this.$nextTick(() => {
+          try {
+            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+          } catch (error) {
+            console.error(error)
+          }
+        })
+      }
+      if (!this.datasetId) {
+        return
+      }
+      getDataset(this.datasetId).then(res => {
+        this.dataForm.id = res.id
+        this.dataForm.name = res.name
+        this.dataForm.typeId = res.typeId
+        this.dataForm.remark = res.remark
+        this.dataForm.datasetType = res.datasetType
+        this.dataForm.moduleCode = res.moduleCode
+        this.dataForm.editable = res.editable
+        this.dataForm.sourceId = res.sourceId
+        // config 配置
+        this.dataForm.script = res.config.script
+        this.dataForm.paramsList = res.config.paramsList ? res.config.paramsList : []
+        this.dataForm.fieldDesc = res.config.fieldDesc
+        this.dataForm.fieldList = res.config.fieldList
+        this.scriptExecute(true)
+      })
+    },
+    /**
+     * 保存数据集
+     * @param formName
+     * @param noCheckToSave 是否不检查直接保存
+     */
+    save (formName, noCheckToSave = false) {
       if (this.passTest === false) {
         this.$message.error('请确保脚本不为空且执行通过')
         return
@@ -713,7 +684,7 @@ export default {
         this.$message.warning('该执行脚本未生成输出字段,请重新检查')
         return
       }
-      if (!nochecktosave) {
+      if (!noCheckToSave) {
         const temp = this.structurePreviewList.some(item => {
           return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
         }) // true-存在为空
@@ -723,138 +694,93 @@ export default {
         }
       }
       this.$refs[formName].validate((valid) => {
-        if (valid) {
-          if (this.dataForm.paramsList.length > 0) {
-            const names = this.dataForm.paramsList.map(value => value.name)
-            const namesSet = new Set(names)
-            if (namesSet.size !== names.length) {
-              this.$message.error('参数名称不能重复,请重新输入')
-              return
-            }
+        if (!valid) {
+          return false
+        }
+        if (this.dataForm.paramsList.length > 0) {
+          const names = this.dataForm.paramsList.map(value => value.name)
+          const namesSet = new Set(names)
+          if (namesSet.size !== names.length) {
+            this.$message.error('参数名称不能重复,请重新输入')
+            return
           }
-          this.saveloading = true
-          this.saveText = '正在保存...'
-          const data = {
+        }
+        this.dataForm.fieldList = this.structurePreviewList.length ? this.structurePreviewList : []
+        // 组装输出字段描述
+        const columnMap = {}
+        if (this.structurePreviewList.length > 0) {
+          this.structurePreviewList.forEach(r => {
+            columnMap[r.fieldName] = r.fieldDesc
+          })
+          this.dataForm.fieldDesc = columnMap
+        }
+        this.saveLoading = true
+        this.saveText = '正在保存...'
+        const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
+        const datasetParams = {
+          id: this.dataForm.id,
+          name: this.dataForm.name,
+          typeId: this.dataForm.typeId,
+          datasetType: 'script',
+          remark: this.dataForm.remark,
+          sourceId: this.dataForm.sourceId,
+          moduleCode: this.appCode,
+          editable: this.appCode ? 1 : 0,
+          config: {
+            className: 'com.gccloud.dataset.entity.config.GroovyDataSetConfig',
             script: this.dataForm.script,
-            fieldDesc: this.fieldDesc,
-            paramsList: this.dataForm.paramsList
+            paramsList: this.dataForm.paramsList,
+            fieldList: this.dataForm.fieldList,
+            fieldDesc: this.dataForm.fieldDesc
           }
-          datasetAddorUpdate({
-            id: this.datasetId,
-            name: this.dataForm.name,
-            typeId: this.dataForm.typeId,
-            remark: this.dataForm.remark,
-            datasetType: 'script',
-            moduleCode: this.appCode,
-            editable: this.appCode ? 1 : 0,
-            data: JSON.stringify(data)
-          }).then(() => {
-            this.$message.success('保存成功')
-            this.$parent.init(false)
-            this.$parent.setType = null
-            this.saveloading = false
-            this.saveText = ''
-          }).catch(() => {
-            this.saveloading = false
-            this.saveText = ''
-          })
-        } else {
-          return false
         }
-      })
-    },
-    // 取消操作
-    cancelField () {
-      this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-      this.fieldsetVisible = false
-    },
-    // 设置输出字段
-    setField () {
-      this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
-      if (this.structurePreviewList.length) {
-        this.fieldDesc = {}
-        this.structurePreviewList.forEach(key => {
-          this.fieldDesc[key.columnName] = key.fieldDesc
+        datasetSave(datasetParams).then(() => {
+          this.$message.success('保存成功')
+          this.$parent.init(false)
+          this.$parent.setType = null
+          this.saveLoading = false
+          this.saveText = ''
+        }).catch(() => {
+          this.saveLoading = false
+          this.saveText = ''
         })
-      } else {
-        this.fieldDesc = null
-      }
-      this.fieldsetVisible = false
-    },
-    // 字段值填充
-    fieldDescFill () {
-      this.fieldDesc = {}
-      this.structurePreviewList.forEach(field => {
-        if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
-          field.fieldDesc = field.columnName
-          this.fieldDesc[field.columnName] = field.columnName
-        } else {
-          this.fieldDesc[field.columnName] = field.fieldDesc
-        }
       })
-      this.save('form')
-      this.fieldDescVisible = false
-    },
-    // 进入编辑
-    fieldDescEdit () {
-      this.fieldDescVisible = false
-      this.fieldsetVisible = true
-    },
-    // 继续保存
-    toSave () {
-      this.fieldDesc = {}
-      this.structurePreviewList.forEach(field => {
-        this.fieldDesc[field.columnName] = field.fieldDesc
-      })
-      this.save('form', true)
-      this.fieldDescVisible = false
-    },
-    // 字段描述构建及同步
-    buildFieldDesc () {
-      const fieldDesc = {}
-      this.structurePreviewList.forEach(field => {
-        if (this.fieldDesc.hasOwnProperty(field.columnName)) {
-          field.fieldDesc = this.fieldDesc[field.columnName]
-        }
-        fieldDesc[field.columnName] = field.fieldDesc
-      })
-      this.fieldDesc = fieldDesc
     },
+
     // 脚本执行
     scriptExecute (isInit = false) {
-      const data = {
+      // 组装数据集执行参数
+      const executeParams = {
         script: this.dataForm.script,
-        fieldDesc: this.fieldDesc,
-        paramsList: this.paramsListCopy
+        params: this.dataForm.paramsList,
+        dataSetType: 'script'
       }
-      this.saveloading = true
-      datasetExecute({
-        params: this.paramsListCopy,
-        dataSetType: 'script',
-        data: JSON.stringify(data)
-      }).then(res => {
+      this.saveLoading = true
+      datasetExecuteTest(executeParams).then(res => {
         if (!isInit) {
           this.$message.success('脚本执行通过')
         }
-        this.dataPreviewList = res.length ? res : []
+        this.dataPreviewList = res.data ? res.data : []
         this.structurePreviewList = []
-        if (res.length) {
-          this.structurePreviewList = Object.keys(res[0]).map(item => {
+        if (res.data.length) {
+          this.structurePreviewList = Object.keys(res.data[0]).map(item => {
             return {
-              columnName: item,
+              fieldName: item,
               fieldDesc: ''
             }
           })
         }
-        if (this.structurePreviewList.length && this.fieldDesc) {
+        console.log(this.structurePreviewList)
+        if (this.structurePreviewList.length && this.dataForm.fieldDesc) {
           this.buildFieldDesc()
         }
         this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-        this.saveloading = false
+        this.saveLoading = false
         this.passTest = true
-      }).catch(() => {
+      }).catch((e) => {
+        console.log(e)
         this.passTest = false
-        this.saveloading = false
+        this.saveLoading = false
       })
     },
     // 执行事件
@@ -867,17 +793,77 @@ export default {
         this.scriptExecute()
       }
     },
-    // 脚本参数配置
+    /**
+     * 使用字段名填充字段描述
+     */
+    fieldDescFill () {
+      this.structurePreviewList.forEach(field => {
+        if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
+          field.fieldDesc = field.fieldName
+        }
+      })
+      this.save('form')
+      this.fieldDescVisible = false
+    },
+    /**
+     * 打开字段描述编辑弹窗
+     */
+    fieldDescEdit () {
+      this.fieldDescVisible = false
+      this.fieldsetVisible = true
+    },
+    /**
+     * 跳过字段描述编辑直接保存
+     */
+    toSave () {
+      this.save('form', true)
+      this.fieldDescVisible = false
+    },
+    /**
+     * 取消编辑字段
+     */
+    cancelField () {
+      this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
+      this.fieldsetVisible = false
+    },
+    /**
+     * 保存字段设置
+     */
+    setField () {
+      this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
+      this.fieldsetVisible = false
+    },
+    /**
+     * 字段描述构建及同步
+     */
+    buildFieldDesc () {
+      const fieldDesc = {}
+      this.structurePreviewList.forEach(field => {
+        if (this.dataForm.fieldDesc.hasOwnProperty(field.fieldName)) {
+          field.fieldDesc = this.dataForm.fieldDesc[field.fieldName]
+        }
+        fieldDesc[field.fieldName] = field.fieldDesc
+      })
+      this.dataForm.fieldDesc = fieldDesc
+    },
+
+    /**
+     * 打开参数配置弹窗
+     */
     openParamsConfig () {
       this.isSet = true
       this.paramsVisible = true
     },
-    // 取消操作
+    /**
+     * 取消编辑参数
+     */
     cancelParam () {
       this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
       this.paramsVisible = false
     },
-    // 设置脚本参数
+    /**
+     * 保存参数设置
+     */
     setParam () {
       if (!this.isSet) {
         this.scriptExecute()
@@ -887,43 +873,27 @@ export default {
       }
       this.paramsVisible = false
     },
-    // 清空分类
-    clearType () {
-      this.typeName = ''
-      this.dataForm.typeId = ''
-    },
-    // 分类展开高亮
-    setCurrentNode ($event) {
-      if ($event) {
-        const key = this.dataForm.typeId || null
-        this.$refs.categorySelectTree.setCurrentKey(key)
-      }
-    },
-    // 分类选择
-    selectParentCategory (value) {
-      this.dataForm.typeId = value.id
-      this.typeName = value.name
-      this.$refs.selectParentName.blur()
-    },
-    // 获取树节点
-    // getTreeList() {
-    //   getOriginalTableList().then(res => {
-    //     this.categoryData = res
-    //   })
-    // },
-    // 校验名称【参数名称不能与字段名重复】
+    /**
+     * 校验名称【参数名称不能与字段名重复】
+     * @param value
+     */
     checkParamsName (value) {
-      const checkList = this.structurePreviewList.filter(item => item.columnName === value.name)
+      const checkList = this.structurePreviewList.filter(item => item.fieldName === value.name)
       if (checkList.length) {
         this.$message.warning('参数名称不可以与字段名相同!')
         value.name = ''
       }
     },
-    // 删除参数配置
+    /**
+     * 删除参数配置
+     * @param index
+     */
     delRow (index) {
       this.paramsListCopy.splice(index, 1)
     },
-    // 新增参数配置
+    /**
+     * 新增参数配置
+     */
     addParam () {
       this.paramsListCopy.push({
         name: '',
@@ -934,36 +904,27 @@ export default {
         remark: ''
       })
     },
-    goBack () {
-      this.$emit('back')
+    // 清空分类
+    clearType () {
+      this.typeName = ''
+      this.dataForm.typeId = ''
     },
-    async init () {
-      this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
-      if (this.typeId) {
-        this.dataForm.typeId = this.typeId
-        this.$nextTick(() => {
-          try {
-            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-          } catch (error) {
-            console.error(error)
-          }
-        })
-      }
-      if (this.datasetId) {
-        getDataset(this.datasetId).then(res => {
-          this.dataForm.id = res.id
-          const data = JSON.parse(res.data)
-          this.dataForm.name = res.name
-          this.dataForm.typeId = res.typeId
-          this.dataForm.remark = res.remark
-          this.dataForm.script = data.script
-          this.dataForm.paramsList = data.paramsList
-          this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
-          this.fieldDesc = data.fieldDesc
-          this.scriptExecute(true)
-        })
+    // 分类展开高亮
+    setCurrentNode ($event) {
+      if ($event) {
+        const key = this.dataForm.typeId || null
+        this.$refs.categorySelectTree.setCurrentKey(key)
       }
     },
+    // 分类选择
+    selectParentCategory (value) {
+      this.dataForm.typeId = value.id
+      this.typeName = value.name
+      this.$refs.selectParentName.blur()
+    },
+    goBack () {
+      this.$emit('back')
+    },
     renderHeader (h, { column, index }) {
       const labelLong = column.label.length // 表头label长度
       const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义

+ 247 - 504
data-room-ui/packages/DataSetManagement/src/StoredProcedureEditForm.vue

@@ -1,7 +1,7 @@
 <!-- eslint-disable vue/no-parsing-error -->
 <template>
   <div
-    v-loading="saveloading"
+    v-loading="saveLoading"
     class="inner-container"
     :element-loading-text="saveText"
   >
@@ -163,29 +163,15 @@
               />
               <div class="bs-codemirror-bottom-text">
                 示例:
-                <strong v-if="dataForm.curingType === '3'">call 存储过程名称(<span
+                <strong>call 存储过程名称(<span
                   style="color: red;"
                 >${参数名称}</span>,?)</strong>
-                <strong v-else><br>
-                  1、常规使用 select * from table where table_field = <span style="color: red;">${参数名称}</span><br>
-                  2、标签使用
-                  <el-tooltip
-                    class="item"
-                    effect="dark"
-                    content="<参数名称></参数名称>为非空标签, 当该参数值为空时, 标签部分不进行处理"
-                    placement="top-start"
-                  ><i class="el-icon-question" />
-                  </el-tooltip>
-                  select * from table where 1=1 <span style="color: blue;">&lt;参数名称&gt;</span> and table_field = <span
-                    style="color: red;"
-                  >${参数名称}</span> <span style="color: blue;">&lt;/参数名称&gt;</span>
-                </strong>
               </div>
             </div>
             <div style="text-align: center; padding: 16px 0;">
               <el-button
                 type="primary"
-                @click="buildParams"
+                @click="buildParamsAndRun"
               >
                 运行
               </el-button>
@@ -245,11 +231,11 @@
               <div class="field-wrap bs-field-wrap bs-scrollbar">
                 <div
                   v-for="field in structurePreviewList"
-                  :key="field.columnName"
+                  :key="field.fieldName"
                   class="field-item"
                   @click="fieldsetVisible = true"
                 >
-                  <span>{{ field.columnName }}</span>&nbsp;<span
+                  <span>{{ field.fieldName }}</span>&nbsp;<span
                     v-show="field.fieldDesc"
                     style="color: #909399;"
                   >({{
@@ -302,97 +288,6 @@
           </div>
         </div>
       </div>
-      <div v-if="!isEdit">
-        <el-tabs v-model="activeName">
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据预览"
-            name="data"
-          >
-            <div class="bs-table-box">
-              <el-table
-                align="center"
-                :data="dataPreviewList"
-                max-height="400"
-                :border="true"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  v-for="(value, key) in dataPreviewList[0]"
-                  :key="key"
-                  :label="key"
-                  align="center"
-                  show-overflow-tooltip
-                  :render-header="renderHeader"
-                >
-                  <template slot-scope="scope">
-                    <span>{{ scope.row[key] }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-          <el-tab-pane
-            v-loading="tableLoading"
-            label="数据集结构"
-            name="structure"
-          >
-            <div class="bs-table-box">
-              <el-table
-                max-height="400"
-                :data="structurePreviewList"
-                :border="true"
-                align="center"
-                class="bs-el-table"
-              >
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnName"
-                  label="字段值"
-                />
-                <el-table-column
-                  align="center"
-                  show-overflow-tooltip
-                  prop="columnType"
-                  label="字段类型"
-                />
-                <el-table-column
-                  align="center"
-                  prop="fieldDesc"
-                  label="字段描述"
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.fieldDesc"
-                      size="small"
-                      class="labeldsc"
-                    />
-                    <span v-else>{{ scope.row.fieldDesc }}</span>
-                  </template>
-                </el-table-column>
-                <el-table-column
-                  align="center"
-                  prop="orderNum"
-                  label="字段排序"
-                  sortable
-                >
-                  <template slot-scope="scope">
-                    <el-input
-                      v-if="isEdit"
-                      v-model="scope.row.orderNum"
-                      size="small"
-                      class="labeldsc"
-                    />
-                    <span v-else>{{ scope.row.orderNum }}</span>
-                  </template>
-                </el-table-column>
-              </el-table>
-            </div>
-          </el-tab-pane>
-        </el-tabs>
-      </div>
 
       <!-- 字段填充方式 -->
       <el-dialog
@@ -454,13 +349,13 @@
             <el-table-column
               align="left"
               show-overflow-tooltip
-              prop="columnName"
+              prop="fieldName"
               label="字段值"
             />
             <el-table-column
               align="center"
               show-overflow-tooltip
-              prop="columnType"
+              prop="fieldType"
               label="字段类型"
             />
             <el-table-column
@@ -659,40 +554,28 @@
 </template>
 
 <script>
-import { nameCheckRepeat, sqlTest, datasetAdd, datasetUpdate, getDatasetInfo, getDatasetTypeList } from 'packages/js/utils/datasetConfigService'
-import { datasourcePage } from 'packages/js/utils/dataSourceService'
+import {
+  nameCheckRepeat,
+  datasetAdd,
+  datasetUpdate,
+  getCategoryTree,
+  datasetExecuteTest,
+  getDataset
+} from 'packages/js/utils/datasetConfigService'
+import { datasourceList } from 'packages/js/utils/dataSourceService'
 import { codemirror } from 'vue-codemirror'
 import 'codemirror/lib/codemirror.css'
 import 'codemirror/theme/nord.css'
 import 'codemirror/mode/sql/sql.js'
 import _ from 'lodash'
+import { datasetMixins} from 'packages/js/mixins/datasetMixin'
+
 export default {
   name: 'StoredProcedureEditForm',
   components: {
     codemirror
   },
-  props: {
-    isEdit: {
-      type: Boolean,
-      default: false
-    },
-    datasetId: {
-      type: String,
-      default: null
-    },
-    datasetName: {
-      type: String,
-      default: ''
-    },
-    typeId: {
-      type: String,
-      default: ''
-    },
-    appCode: {
-      type: String,
-      default: ''
-    }
-  },
+  mixins: [datasetMixins],
   data () {
     const validateName = (rule, value, callback) => {
       nameCheckRepeat({
@@ -712,30 +595,23 @@ export default {
         id: '',
         name: '',
         typeId: '',
-        code: '',
-        curingType: '3',
+        datasetType: 'storedProcedure',
         remark: '',
+        // 以下为config配置
         sourceId: '',
         sqlProcess: 'call ',
-        script: '',
         paramsList: [],
-        paramConfig: '',
-        cacheCoherence: null,
-        fieldDesc: '',
-        fieldJson: '',
-        processType: '2'
+        fieldDesc: {},
+        fieldList: [],
+        code: '',
+        script: '',
+        cacheCoherence: null
       },
       rules: {
         name: [
           { required: true, message: '请输入数据集名称', trigger: 'blur' },
           { validator: validateName, trigger: 'blur' }
         ],
-        // typeId: [
-        //   {required: true, message: '请选择分组', trigger: 'blur'}
-        // ],
-        curingType: [
-          { required: true, message: '请选择固化形式', trigger: 'blur' }
-        ],
         sourceId: [
           { required: true, message: '请选择数据源', trigger: 'blur' }
         ]
@@ -751,35 +627,10 @@ export default {
         }
       },
       sourceList: [],
-      activeName: 'data',
-      dataPreviewList: [],
-      structurePreviewList: [],
-      structurePreviewListCopy: [],
       msg: '',
       exception: '',
-      typeSelect: [{
-        value: 'String'
-      }, {
-        value: 'Integer'
-      }, {
-        value: 'Double'
-      }, {
-        value: 'Long'
-      }, {
-        value: 'Date'
-      }],
-      typeName: '',
-      categoryData: [],
       passTest: false, // 通过测试
-      current: 1,
-      size: 10,
-      totalCount: 0,
-      fieldDescVisible: false,
-      fieldsetVisible: false,
       paramsVisible: false,
-      tableLoading: false,
-      saveloading: false,
-      saveText: '',
       tableNameList: [],
       paramsListCopy: [],
       isTest: false // 是否执行测试
@@ -806,17 +657,109 @@ export default {
     this.init()
   },
   methods: {
-    // 打开参数配置
+    /**
+     * 初始化
+     * 1. 获取分类树
+     * 2. 获取数据源列表
+     * 3. 获取数据集详情
+     */
+    async init () {
+      this.categoryData = await getCategoryTree({ type: 'dataset', moduleCode: this.appCode })
+      if (this.typeId) {
+        this.dataForm.typeId = this.typeId
+        this.$nextTick(() => {
+          try {
+            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+          } catch (error) {
+            console.error(error)
+          }
+        })
+      }
+      this.getDataSource()
+      if (!this.datasetId) {
+        return
+      }
+      // 获取详情
+      getDataset(this.datasetId).then(res => {
+        this.dataForm.id = res.id
+        this.dataForm.name = res.name
+        this.dataForm.typeId = res.typeId
+        this.dataForm.remark = res.remark
+        this.dataForm.datasetType = res.datasetType
+        this.dataForm.moduleCode = res.moduleCode
+        this.dataForm.editable = res.editable
+        this.dataForm.sourceId = res.sourceId
+        // config 配置
+        this.dataForm.sqlProcess = res.config.sqlProcess
+        this.dataForm.paramsList = res.config.paramsList ? res.config.paramsList : []
+        this.dataForm.fieldDesc = res.config.fieldDesc
+        this.dataForm.fieldList = res.config.fieldList
+        this.dataForm.cacheCoherence = res.config.cacheCoherence
+        // 使用传入的数据集名称 ?
+        this.dataForm.name = this.datasetName
+        this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
+        if (this.dataForm.typeId) {
+          this.$nextTick(() => {
+            try {
+              this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
+            } catch (error) {
+              console.error(error)
+            }
+          })
+        }
+        this.datasetTest(false)
+      })
+    },
+    /**
+     * 获取数据源列表
+     */
+    getDataSource () {
+      const params = {
+        sourceName: '',
+        sourceType: '',
+        moduleCode: this.appCode
+      }
+      datasourceList(params).then(data => {
+        this.sourceList = data
+      })
+    },
+    /**
+     * 打开参数配置弹窗
+     */
     openParamsConfig () {
       this.isTest = false
       this.paramsVisible = true
     },
-    // 取消操作
+    /**
+     * 删除参数配置
+     * @param {*} index
+     */
+    delRow (index) {
+      this.paramsListCopy.splice(index, 1)
+    },
+    /**
+     * 新增参数配置
+     */
+    addParam () {
+      this.paramsListCopy.push({
+        name: '',
+        type: '',
+        value: '',
+        status: 1,
+        require: 0,
+        remark: ''
+      })
+    },
+    /**
+     * 取消编辑参数
+     */
     cancelParam () {
       this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
       this.paramsVisible = false
     },
-    // 设置SQL参数
+    /**
+     * 保存参数设置
+     */
     setParam () {
       this.dataForm.paramsList = _.cloneDeep(this.paramsListCopy)
       if (this.isTest) {
@@ -824,79 +767,12 @@ export default {
       }
       this.paramsVisible = false
     },
-    // 取消操作
-    cancelField () {
-      this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-      this.fieldsetVisible = false
-    },
-    // 设置输出字段
-    setField () {
-      this.structurePreviewList = _.cloneDeep(this.structurePreviewListCopy)
-      this.fieldsetVisible = false
-    },
-    // 每页大小改变触发
-    sizeChangeHandle (value) {
-      this.size = value
-      this.current = 1
-      if (this.dataForm.processType === '2') {
-        this.datasetTest(false)
-      }
-    },
-    // 当前页数改变
-    currentChangeHandle (value) {
-      this.current = value
-      if (this.dataForm.processType === '2') {
-        this.datasetTest(false)
-      }
-    },
-    // 表视图切换,sql加工相关信息置空
-    curingTypeChoose (value) {
-      if (value === '3') {
-        if (this.dataForm.sqlProcess === 'select ') {
-          this.dataForm.sqlProcess = 'call '
-        }
-      } else {
-        if (this.dataForm.sqlProcess === 'call ') {
-          this.dataForm.sqlProcess = 'select '
-        }
-      }
-      if ((!['select ', 'call '].includes(this.dataForm.sqlProcess) && this.dataForm.sqlProcess !== '') || this.dataForm.sourceId !== '' || this.dataForm.paramsList.length > 0) {
-        this.$confirm('结果固化形式切换,表和视图处理情况不同,建议清空sql加工配置数据,是否清空数据?', '提示', {
-          confirmButtonText: '是',
-          cancelButtonText: '否',
-          type: 'warning',
-          customClass: 'bs-el-message-box'
-        }).then(() => {
-          this.curingTypeChooseClear(value)
-        }).catch(() => {
-        })
-      } else {
-        this.curingTypeChooseClear(value)
-      }
-    },
-    curingTypeChooseClear (value) {
-      // 数据源id置空
-      this.dataForm.sourceId = ''
-      // sql脚本置空
-      this.dataForm.sqlProcess = value === '3' ? 'call ' : 'select '
-      this.passTest = false
-      // 参数配置信息置空
-      this.dataForm.paramsList = []
-      this.paramsListCopy = []
-      if (this.dataForm.id !== '') {
-        getDatasetInfo(this.datasetId).then(data => {
-          if (data.curingType === this.dataForm.curingType) {
-            this.dataForm.sourceId = data.sourceId
-            this.dataForm.sqlProcess = data.sqlProcess
-            this.dataForm.paramsList = data.paramConfig !== '' ? JSON.parse(data.paramConfig) : []
-            this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
-            this.passTest = true
-          }
-        })
-      }
-    },
-    // 保存
-    save (formName, nochecktosave = false) {
+    /**
+     * 保存
+     * @param formName
+     * @param noCheckToSave 是否跳过检查直接保存
+     */
+    save (formName, noCheckToSave = false) {
       if (this.passTest === false) {
         this.$message.error('请确保数据集SQL加工脚本不为空且测试通过')
         return
@@ -905,7 +781,7 @@ export default {
         this.$message.warning('该存储过程未生成输出字段,请重新检查')
         return
       }
-      if (!nochecktosave) {
+      if (!noCheckToSave) {
         const temp = this.structurePreviewList.some(item => {
           return item.fieldDesc === '' || !item.hasOwnProperty('fieldDesc')
         }) // true-存在为空
@@ -915,86 +791,66 @@ export default {
         }
       }
       this.$refs[formName].validate((valid) => {
-        if (valid) {
-          if (this.dataForm.paramsList.length > 0) {
-            const names = this.dataForm.paramsList.map(value => value.name)
-            const namesSet = new Set(names)
-            if (namesSet.size !== names.length) {
-              this.$message.error('参数名称不能重复,请重新输入')
-              return
-            }
-          }
-          this.dataForm.paramConfig = this.dataForm.paramsList.length !== 0 ? JSON.stringify(this.dataForm.paramsList) : ''
-          const columnMap = {}
-          if (this.structurePreviewList.length > 0) {
-            this.structurePreviewList.forEach(r => {
-              columnMap[r.columnName] = r.fieldDesc
-            })
-            this.dataForm.fieldDesc = JSON.stringify(columnMap)
-          }
-          this.dataForm.fieldJson = this.structurePreviewList.length ? JSON.stringify(this.structurePreviewList) : ''
-          this.saveloading = true
-          this.saveText = '正在保存...'
-          if (this.dataForm.id === '') {
-            datasetAdd({
-              ...this.dataForm,
-              moduleCode: this.appCode,
-              editable: this.appCode ? 1 : 0
-            }).then(res => {
-              this.$message.success('保存成功')
-              this.$parent.init(false)
-              this.$parent.setType = null
-              this.saveloading = false
-              this.saveText = ''
-            }).catch(() => {
-              this.saveloading = false
-              this.saveText = ''
-            })
-          } else {
-            datasetUpdate({
-              ...this.dataForm,
-              moduleCode: this.appCode,
-              editable: this.appCode ? 1 : 0
-            }).then(res => {
-              this.$message.success('保存成功')
-              this.$parent.init(false)
-              this.$parent.setType = null
-              this.saveloading = false
-              this.saveText = ''
-            }).catch(() => {
-              this.saveloading = false
-              this.saveText = ''
-            })
-          }
-          this.saveloading = false
-          this.saveText = ''
-        } else {
+        if (!valid) {
           return false
         }
-      })
-    },
-    // 字段值填充
-    fieldDescFill () {
-      this.structurePreviewList.forEach(field => {
-        if (field.fieldDesc === '' || !field.hasOwnProperty('fieldDesc')) {
-          field.fieldDesc = field.columnName
+        // 检查参数名称是否重复
+        if (this.dataForm.paramsList.length > 0) {
+          const names = this.dataForm.paramsList.map(value => value.name)
+          const namesSet = new Set(names)
+          if (namesSet.size !== names.length) {
+            this.$message.error('参数名称不能重复,请重新输入')
+            return
+          }
+        }
+        // 组装输出字段描述
+        const columnMap = {}
+        if (this.structurePreviewList.length > 0) {
+          this.structurePreviewList.forEach(r => {
+            columnMap[r.fieldName] = r.fieldDesc
+          })
+          this.dataForm.fieldDesc = columnMap
         }
+        this.dataForm.fieldList = this.structurePreviewList.length ? this.structurePreviewList : []
+        this.saveLoading = true
+        this.saveText = '正在保存...'
+        const dataSave = this.dataForm.id ? datasetUpdate : datasetAdd
+        const datasetParams = {
+          id: this.dataForm.id,
+          name: this.dataForm.name,
+          typeId: this.dataForm.typeId,
+          datasetType: 'storedProcedure',
+          remark: this.dataForm.remark,
+          sourceId: this.dataForm.sourceId,
+          moduleCode: this.appCode,
+          editable: this.appCode ? 1 : 0,
+          config: {
+            className: 'com.gccloud.dataset.entity.config.StoredProcedureDataSetConfig',
+            sourceId: this.dataForm.sourceId,
+            sqlProcess: this.dataForm.sqlProcess,
+            paramsList: this.dataForm.paramsList,
+            fieldList: this.dataForm.fieldList,
+            fieldDesc: this.dataForm.fieldDesc
+          }
+        }
+        dataSave(datasetParams).then(res => {
+          this.$message.success('保存成功')
+          this.$parent.init(false)
+          this.$parent.setType = null
+          this.saveLoading = false
+          this.saveText = ''
+        }).catch(() => {
+          this.saveLoading = false
+          this.saveText = ''
+        })
+        this.saveLoading = false
+        this.saveText = ''
       })
-      this.save('form')
-      this.fieldDescVisible = false
     },
-    // 进入编辑
-    fieldDescEdit () {
-      this.fieldDescVisible = false
-      this.fieldsetVisible = true
-    },
-    // 继续保存
-    toSave () {
-      this.save('form', true)
-      this.fieldDescVisible = false
-    },
-    // 获取参数配置
-    buildParams () {
+    /**
+     * 解析参数配置,并且执行测试
+     */
+    buildParamsAndRun () {
       this.isTest = true
       const reg = /\${(.*?)}/g
       const paramNames = [...new Set([...this.dataForm.sqlProcess.matchAll(reg)].map(item => item[1]))]
@@ -1023,7 +879,10 @@ export default {
         this.datasetTest()
       }
     },
-    // 数据集测试
+    /**
+     * 执行测试
+     * @param val
+     */
     datasetTest (val = true) {
       if (this.dataForm.sourceId === '') {
         this.$message.error('请选择数据源')
@@ -1045,188 +904,72 @@ export default {
       if (val === true) {
         this.current = 1
       }
-      this.saveloading = true
-      sqlTest({
-        datasetId: this.dataForm.id,
-        sqlProcess: this.dataForm.sqlProcess,
-        script: this.dataForm.script,
-        paramConfig: this.dataForm.paramsList.length !== 0 ? JSON.stringify(this.dataForm.paramsList) : '',
-        sourceId: this.dataForm.sourceId,
-        current: this.current,
-        size: this.size,
-        curingType: this.dataForm.curingType,
-        dataSetCode: this.dataForm.code,
-        processType: '2'
-      }).then(res => {
-        if (res.code === 500) {
-          this.$message.error('数据查询失败:' + res.msg)
-          this.exception = res.exception
-          this.msg = res.msg
-          this.passTest = false
-        } else {
-          this.dataPreviewList = res.dataMap.dataPreview
-          this.structurePreviewList = res.dataMap.structurePreview
-          // 输出字段描述合并
-          this.structurePreviewList.forEach(item => {
-            const field = this.structurePreviewListCopy.find(_item => _item.columnName === item.columnName)
-            if (field) {
-              item.fieldDesc = field.fieldDesc
-            }
-          })
-          this.structurePreviewList.forEach(item => {
-            if (!item.hasOwnProperty('orderNum')) {
-              this.$set(item, 'orderNum', 0)
-            }
-            if (!item.hasOwnProperty('sourceTable')) {
-              this.$set(item, 'sourceTable', '')
-            }
-            if (!item.hasOwnProperty('fieldDesc')) {
-              this.$set(item, 'fieldDesc', '')
-            }
-          })
-          this.totalCount = res.totalCount
-          this.tableNameList = res.tableNameList
-          if (this.tableNameList && this.tableNameList.length === 1) {
-            this.structurePreviewList.forEach(item => {
-              item.sourceTable = this.tableNameList[0]
-            })
-          }
-          this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
-          this.dataForm.cacheCoherence = res.cacheCoherence
-          let paramsNameCheck = false
-          this.dataForm.paramsList.forEach(param => {
-            const checkList = this.structurePreviewList.filter(item => item.columnName === param.name)
-            if (checkList.length) {
-              paramsNameCheck = true
-              param.name = ''
-            }
-          })
-          if (paramsNameCheck) {
-            this.$message.warning('参数名称不可以与字段名相同!')
-            this.passTest = false
-          } else {
-            if (val) this.$message.success('测试成功')
-            this.exception = ''
-            this.msg = ''
-            this.passTest = true
-          }
-        }
-        this.saveloading = false
-      }).catch(() => {
-        this.passTest = false
-        this.saveloading = false
-      })
-    },
-    // 清空分类
-    clearType () {
-      this.typeName = ''
-      this.dataForm.typeId = ''
-    },
-    // 分类展开高亮
-    setCurrentNode ($event) {
-      if ($event) {
-        const key = this.dataForm.typeId || null
-        this.$refs.categorySelectTree.setCurrentKey(key)
+      this.saveLoading = true
+      // 组装数据集执行参数
+      const executeParams = {
+        dataSourceId: this.dataForm.sourceId,
+        script: this.dataForm.sqlProcess,
+        params: this.dataForm.paramsList,
+        dataSetType: 'storedProcedure',
+        // 存储过程数据集默认查询20条数据
+        size: 20,
+        current: 1
       }
-    },
-    // 分类选择
-    selectParentCategory (value) {
-      this.dataForm.typeId = value.id
-      this.typeName = value.name
-      this.$refs.selectParentName.blur()
-    },
-    // 获取树节点
-    // getTreeList() {
-    //   getOriginalTableList().then(res => {
-    //     this.categoryData = res
-    //   })
-    // },
-    // 校验名称【参数名称不能与字段名重复】
-    checkParamsName (value) {
-      const checkList = this.structurePreviewList.filter(item => item.columnName === value.name)
-      if (checkList.length) {
-        this.$message.warning('参数名称不可以与字段名相同!')
-        value.name = ''
-      }
-    },
-    // 删除参数配置
-    delRow (index) {
-      this.paramsListCopy.splice(index, 1)
-    },
-    // 新增参数配置
-    addParam () {
-      this.paramsListCopy.push({
-        name: '',
-        type: '',
-        value: '',
-        status: 1,
-        require: 0,
-        remark: ''
-      })
-    },
-    // 获取数据源
-    getDataSource () {
-      const params = {
-        current: 1,
-        size: 1000,
-        sourceName: '',
-        sourceType: '',
-        moduleCode: this.appCode
-      }
-      datasourcePage(params).then(data => {
-        this.sourceList = data.list
-      })
-    },
-    goBack () {
-      this.$emit('back')
-    },
-    async init () {
-      this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
-      if (this.typeId) {
-        this.dataForm.typeId = this.typeId
-        this.$nextTick(() => {
-          try {
-            this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-          } catch (error) {
-            console.error(error)
+      datasetExecuteTest(executeParams).then(res => {
+        this.dataPreviewList = res.data.list
+        this.structurePreviewList = res.structure
+        // 输出字段描述合并
+        this.structurePreviewList.forEach(field => {
+          const fieldInfo = this.dataForm.fieldList.find(item => item.fieldName === field.fieldName)
+          if (fieldInfo) {
+            field.fieldDesc = fieldInfo.fieldDesc
+            field.orderNum = fieldInfo.orderNum
+            field.sourceTable = fieldInfo.sourceTable
           }
         })
-      }
-      // this.getTreeList()
-      this.getDataSource()
-      if (this.datasetId) {
-        // 获取详情
-        getDatasetInfo(this.datasetId).then(res => {
-          for (const key in res) {
-            if (this.dataForm.hasOwnProperty(key)) {
-              this.dataForm[key] = res[key]
-            }
+        this.structurePreviewList.forEach(item => {
+          if (!item.hasOwnProperty('orderNum')) {
+            this.$set(item, 'orderNum', 0)
+          }
+          if (!item.hasOwnProperty('sourceTable')) {
+            this.$set(item, 'sourceTable', '')
           }
-          this.dataForm.name = this.datasetName
-          this.dataForm.paramsList = this.dataForm.paramConfig.length ? JSON.parse(this.dataForm.paramConfig) : []
-          this.paramsListCopy = _.cloneDeep(this.dataForm.paramsList)
-          if (this.dataForm.typeId) {
-            this.$nextTick(() => {
-              try {
-                this.typeName = this.$refs.categorySelectTree.getNode(this.dataForm.typeId).data.name
-              } catch (error) {
-                console.error(error)
-              }
-            })
+          if (!item.hasOwnProperty('fieldDesc')) {
+            this.$set(item, 'fieldDesc', '')
           }
-          this.datasetTest(false)
         })
-      }
-    },
-    // 表头添加提示
-    renderHeader (h, { column, index }) {
-      const labelLong = column.label.length // 表头label长度
-      const size = 14 // 根据需要定义标尺,直接使用字体大小确定就行,也可以根据需要定义
-      column.minWidth = labelLong * size < 120 ? 120 : labelLong * size // 根据label长度计算该表头最终宽度
-      return h('span', { class: 'cell-content', style: { width: '100%' } }, [column.label])
-    },
-    openNewWindow (url) {
-      window.open(url, '_blank')
+        this.totalCount = res.data.totalCount
+        this.tableNameList = res.tableNameList
+        // 如果只有一个表,自动填充字段表名
+        if (this.tableNameList && this.tableNameList.length === 1) {
+          this.structurePreviewList.forEach(item => {
+            item.sourceTable = this.tableNameList[0]
+          })
+        }
+        this.structurePreviewListCopy = _.cloneDeep(this.structurePreviewList)
+        let paramsNameCheck = false
+        this.dataForm.paramsList.forEach(param => {
+          const checkList = this.structurePreviewList.filter(item => item.fieldName === param.name)
+          if (checkList.length) {
+            paramsNameCheck = true
+            param.name = ''
+          }
+        })
+        if (paramsNameCheck) {
+          this.$message.warning('参数名称不可以与字段名相同!')
+          this.passTest = false
+        } else {
+          if (val) this.$message.success('测试成功')
+          this.exception = ''
+          this.msg = ''
+          this.passTest = true
+        }
+        this.saveLoading = false
+      }).catch((e) => {
+        console.log('测试失败', e)
+        this.passTest = false
+        this.saveLoading = false
+      })
     }
   }
 }

+ 10 - 25
data-room-ui/packages/DataSetManagement/src/TypeTree.vue

@@ -139,7 +139,7 @@
           </ul>
         </div>
       </div>
-      <CategroyEditForm
+      <org-edit-form
         v-if="editFormVisible"
         ref="editForm"
         :app-code="appCode"
@@ -157,12 +157,12 @@ import 'ztree/js/jquery.ztree.exhide'
 import 'packages/assets/style/zTree/metroStyle.css'
 import 'packages/assets/style/zTree/zTree.scss'
 import 'packages/assets/style/zTree/zTreeSelect.scss'
-import { getDatasetTypeList, categoryRemove } from 'packages/js/utils/datasetConfigService'
-import CategroyEditForm from './CategroyEditForm.vue'
+import { getCategoryTree, categoryRemove } from 'packages/js/utils/datasetConfigService'
+import OrgEditForm from './CategroyEditForm.vue'
 export default {
-  name: 'TypeTree',
+  name: 'OrgTreeIndex',
   components: {
-    CategroyEditForm
+    OrgEditForm
   },
   props: {
     datasetTypeList: {
@@ -178,14 +178,6 @@ export default {
     return {
       activeName: 'group',
       categoryData: [],
-      // typeDataList: [
-      //   { name: '全部', datasetType: '' },
-      //   { name: '原始数据集', datasetType: 'original' },
-      //   { name: '自助数据集', datasetType: 'custom' },
-      //   { name: '存储过程数据集', datasetType: 'storedProcedure' },
-      //   { name: 'JSON数据集', datasetType: 'json' },
-      //   { name: '脚本数据集', datasetType: 'script' }
-      // ],
       curType: '-1',
       noData: false,
       loading: false,
@@ -229,14 +221,7 @@ export default {
       isBoth: false // 是否为全部
     }
   },
-  computed: {
-    // typeData () {
-    //   const types = this.typeDataList.filter(type => {
-    //     return type.datasetType === '' || this.dsType.includes(type.datasetType)
-    //   })
-    //   return types
-    // }
-  },
+  computed: { },
   mounted () {
     this.initLazyOrgTree()
   },
@@ -305,7 +290,7 @@ export default {
     // 初始化树节点
     initLazyOrgTree () {
       this.loading = true
-      getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode }).then((res) => {
+      getCategoryTree({ type: 'dataset', moduleCode: this.appCode }).then((res) => {
         this.categoryData = res.map((item) => {
           return { isParent: item.hasChildren, ...item }
         })
@@ -394,7 +379,7 @@ export default {
       this.editFormVisible = true
       if (editType === this.editTypeConstant.editOrg) {
         this.$nextTick(() => {
-          this.$refs.editForm.tableName = 'r_dataset'
+          this.$refs.editForm.type = 'dataset'
           this.$refs.editForm.dialogFormVisible = true
           this.$refs.editForm.init(this.rightClickForm.org, false)
           this.$refs.editForm.title = '节点编辑'
@@ -404,7 +389,7 @@ export default {
       // 新增同级节点
       if (editType === this.editTypeConstant.addSiblingOrg) {
         this.$nextTick(() => {
-          this.$refs.editForm.tableName = 'r_dataset'
+          this.$refs.editForm.type = 'dataset'
           this.$refs.editForm.dialogFormVisible = true
           this.$refs.editForm.init(this.rightClickForm.org, true)
           this.$refs.editForm.radio = 0
@@ -415,7 +400,7 @@ export default {
       // 新增子节点
       if (editType === this.editTypeConstant.addChildOrg) {
         this.$nextTick(() => {
-          this.$refs.editForm.tableName = 'r_dataset'
+          this.$refs.editForm.type = 'dataset'
           this.$refs.editForm.dialogFormVisible = true
           this.$refs.editForm.init(this.rightClickForm.org, true)
           this.$refs.editForm.radio = 1

+ 49 - 50
data-room-ui/packages/DataSetManagement/src/index.vue

@@ -85,7 +85,6 @@
           </el-form-item>
           <el-form-item class="filter-item">
             <el-button
-              v-if="!isDialog"
               class="bs-el-button-default"
               @click="addDataset"
             >
@@ -144,7 +143,7 @@
             <el-table-column
               prop="remark"
               label="备注"
-              align="center"
+              align="left"
               show-overflow-tooltip
             />
             <!--操作栏-->
@@ -153,23 +152,24 @@
               width="200"
               align="center"
             >
-              <template slot-scope="scope">
-                <div v-if="showOperate(scope.row.datasetType)">
-                  <el-button
-                    class="bs-el-button-default"
-                    :disabled="scope.row.editable === 1 && !appCode"
-                    @click="toEdit(scope.row.id, scope.row.datasetType, scope.row.name, scope.row.typeId)"
-                  >
-                    编辑
-                  </el-button>
-                  <el-button
-                    class="bs-el-button-default"
-                    :disabled="scope.row.editable === 1 && !appCode"
-                    @click="delDataset(scope.row.id)"
-                  >
-                    删除
-                  </el-button>
-                </div>
+              <template
+                v-if="showOperate(scope.row.datasetType)"
+                slot-scope="scope"
+              >
+                <el-button
+                  class="bs-el-button-default"
+                  :disabled="scope.row.editable === 1 && !appCode"
+                  @click="toEdit(scope.row.id, scope.row.datasetType, scope.row.name, scope.row.typeId)"
+                >
+                  编辑
+                </el-button>
+                <el-button
+                  class="bs-el-button-default"
+                  :disabled="scope.row.editable === 1 && !appCode"
+                  @click="delDataset(scope.row.id)"
+                >
+                  删除
+                </el-button>
               </template>
             </el-table-column>
           </el-table>
@@ -199,10 +199,10 @@
       @openAddForm="openAddForm"
     />
     <component
-      :is="customDatasetComponentData.component"
+      :is="componentData.component"
       ref="EditForm"
-      :key="customDatasetComponentData.key"
-      :config="customDatasetComponentData.config"
+      :key="componentData.key"
+      :config="componentData.config"
       :dataset-id="datasetId"
       :dataset-name="datasetName"
       :type-id="typeId"
@@ -214,16 +214,17 @@
 </template>
 
 <script>
-import table from 'packages/js/utils/table.js'
 import TypeTree from './TypeTree.vue'
-import DatasetTypeDialog from './DatasetTypeDialog.vue'
-import OriginalEditForm from './OriginalEditForm.vue'
-import CustomEditForm from './CustomEditForm.vue'
 import JsonEditForm from './JsonEditForm.vue'
-import StoredProcedureEditForm from './StoredProcedureEditForm.vue'
+import table from 'packages/js/utils/table.js'
 import ScriptEditForm from './ScriptEditForm.vue'
-import { datasetPage, datasetRemove } from 'packages/js/utils/datasetConfigService'
+import CustomEditForm from './CustomEditForm.vue'
 import { pageMixins } from 'packages/js/mixins/page'
+import OriginalEditForm from './OriginalEditForm.vue'
+import DatasetTypeDialog from './DatasetTypeDialog.vue'
+// import remoteComponents from '@/customDatasetComponents/exports.js'
+import StoredProcedureEditForm from './StoredProcedureEditForm.vue'
+import { datasetPage, datasetRemove } from 'packages/js/utils/datasetConfigService'
 export default {
   name: 'DataSetManagement',
   directives: {
@@ -260,6 +261,7 @@ export default {
       type: Boolean,
       default: false
     }
+
   },
   data () {
     return {
@@ -272,6 +274,8 @@ export default {
         datasetType: '',
         typeId: '' // 分类id
       }, // 查询条件
+      // 数据集类型
+      datasetTypeList: [],
       isPackUpTree: false,
       transition: 0.1,
       loadingText: '正在加载数据',
@@ -287,8 +291,8 @@ export default {
       typeId: '', // 详情typeId
       curRow: null,
       multipleSelection: [],
-      datasetTypeList: [],
-      customDatasetComponentData: {
+      // 远程组件
+      componentData: {
         component: null,
         config: null,
         key: new Date().getTime()
@@ -347,9 +351,6 @@ export default {
         }
       }
     },
-    showOperate (datasetType) {
-      return this.getComponents(this.datasetTypeList.find(type => type.datasetType === datasetType).componentName)?.config?.showOperate ?? true
-    },
     // 手动勾选
     selectDs (selection, row) {
       if (this.isDialog && this.multiple) {
@@ -405,16 +406,10 @@ export default {
       this.typeId = typeId
       this.isEdit = false
     },
-    openAddForm (type, componentName) {
-      this.datasetType = type
-      this.customDatasetComponentData = this.getComponents(componentName)
-      this.typeId = this.queryForm.typeId
-      this.isEdit = true
-    },
     toEdit (id, type, name, typeId) {
       this.datasetId = id
       this.datasetType = type
-      this.customDatasetComponentData = this.getComponents(this.datasetTypeList.find(item => item?.datasetType === type).componentName)
+      this.componentData = this.getComponents(this.datasetTypeList.find(item => item?.datasetType === type).componentName)
       this.datasetName = name
       this.typeId = typeId
       this.isEdit = true
@@ -424,25 +419,29 @@ export default {
       this.datasetType = null
       this.isEdit = false
     },
+    // 新增数据集-类型
+    openAddForm (type, componentName) {
+      this.datasetType = type
+      this.componentData = this.getComponents(componentName)
+      this.typeId = this.queryForm.typeId
+      this.isEdit = true
+    },
+    showOperate (datasetType) {
+      return this.getComponents(this.datasetTypeList.find(type => type.datasetType === datasetType).componentName)?.config?.showOperate ?? true
+    },
     getComponents (componentName) {
       const components = Object.values(this.$options.components)
-      let componentData = null
+      let remoteComponentData = null
       if (window.BS_CONFIG?.customDatasetComponents.length > 0) {
         // 获取远程组件
-        componentData = window.BS_CONFIG?.customDatasetComponents.find(item => item.config.componentName === componentName)
+        remoteComponentData = window.BS_CONFIG?.customDatasetComponents.find(item => item.config.componentName === componentName)
       }
       return {
-        component: components.find(component => component.name === componentName) || componentData?.vueFile,
-        config: componentData?.config || null,
+        component: components.find(component => component.name === componentName) || remoteComponentData?.vueFile,
+        config: remoteComponentData?.config || null,
         key: new Date().getTime()
       }
     },
-    // 新增数据集-类型
-    // setDatasetOfType (type) {
-    //   this.datasetType = type
-    //   this.typeId = this.queryForm.typeId
-    //   this.isEdit = true
-    // },
     // 初始化
     init (temp = true) {
       if (temp) {