Pārlūkot izejas kodu

feat:新增数据集以及数据源删除校验

liu.tao3 1 gadu atpakaļ
vecāks
revīzija
1b8bb8910c

+ 29 - 13
data-room-ui/packages/DataSetManagement/src/index.vue

@@ -231,6 +231,10 @@
       :dataset-type-list="datasetTypeList"
       @openAddForm="openAddForm"
     />
+    <checkDatasource
+      ref="checkDatasource"
+      :reasonList="reasonList"
+      />
     <component
       :is="componentData.component"
       v-if="datasetType"
@@ -253,12 +257,13 @@ import JsEditForm from './JsEditForm.vue'
 import JsonEditForm from './JsonEditForm.vue'
 import table from 'data-room-ui/js/utils/table.js'
 import ScriptEditForm from './ScriptEditForm.vue'
+import checkDatasource from 'data-room-ui/DataSourceManagement/src/checkDatasource.vue'
 import CustomEditForm from './CustomEditForm.vue'
 import { pageMixins } from 'data-room-ui/js/mixins/page'
 import OriginalEditForm from './OriginalEditForm.vue'
 import DatasetTypeDialog from './DatasetTypeDialog.vue'
 import StoredProcedureEditForm from './StoredProcedureEditForm.vue'
-import { datasetPage, datasetRemove } from 'data-room-ui/js/utils/datasetConfigService'
+import { datasetPage, datasetRemove, datasetCheck } from 'data-room-ui/js/utils/datasetConfigService'
 import { getLabelList } from 'data-room-ui/js/utils/LabelConfigService'
 export default {
   name: 'DataSetManagement',
@@ -273,7 +278,8 @@ export default {
     JsonEditForm,
     StoredProcedureEditForm,
     ScriptEditForm,
-    JsEditForm
+    JsEditForm,
+    checkDatasource
   },
   mixins: [pageMixins],
   props: {
@@ -305,6 +311,7 @@ export default {
   },
   data () {
     return {
+      reasonList:[],
       datasetType: null,
       isEdit: false,
       categoryData: [],
@@ -439,18 +446,27 @@ export default {
     },
     // 删除数据集
     delDataset (id) {
-      this.$confirm('确定删除当前数据集吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning',
-        customClass: 'bs-el-message-box'
-      }).then(() => {
-        datasetRemove(id).then(res => {
-          this.init(false)
-          this.$message.success('删除成功')
-        })
-      }).catch(() => {
+      datasetCheck(id).then((res)=>{
+        console.log(res)
+        if(res.canDelete){
+          this.$confirm('确定删除当前数据集吗?', '提示', {
+            confirmButtonText: '确定',
+            cancelButtonText: '取消',
+            type: 'warning',
+            customClass: 'bs-el-message-box'
+          }).then(() => {
+            datasetRemove(id).then(res => {
+              this.init(false)
+              this.$message.success('删除成功')
+            })
+          }).catch(() => {
+          })
+        }else{
+          this.reasonList=res.reasons
+          this.$refs.checkDatasource.checkDatasourceVisible = true
+        }
       })
+
     },
     // 详情
     toPreview (id, type, name, typeId) {

+ 62 - 0
data-room-ui/packages/DataSourceManagement/src/checkDatasource.vue

@@ -0,0 +1,62 @@
+<template>
+  <el-dialog
+    width="700px"
+    title="提示"
+    :visible.sync="checkDatasourceVisible"
+    :append-to-body="true"
+    :close-on-click-modal="false"
+    :before-close="handleClose"
+    class="bs-dialog-wrap bs-el-dialog"
+  >
+    <div
+      style="padding-right: 80px;"
+    >
+      <div class="item" v-for="(item,index) in reasonList" :key="index">
+        <span v-if="reasonList.length>1"> {{index+1}}、</span>{{item}}
+      </div>
+    </div>
+    <span
+      slot="footer"
+      class="dialog-footer"
+    >
+      <el-button
+        type="primary"
+        @click="handleClose"
+      >
+        确定
+      </el-button>
+    </span>
+  </el-dialog>
+</template>
+
+<script>
+export default {
+  props: {
+    reasonList: {
+      type: Array,
+      default: ()=>[]
+    }
+  },
+  data () {
+    return {
+      checkDatasourceVisible: false,
+    }
+  },
+  methods: {
+    handleClose(){
+      this.checkDatasourceVisible=false
+    }
+
+    }
+  }
+</script>
+
+<style lang="scss" scoped>
+@import '../../assets/style/bsTheme.scss';
+/deep/ .el-dialog__body{
+  min-height: 0 !important;
+}
+.item{
+  padding: 8px 0;
+}
+</style>

+ 27 - 11
data-room-ui/packages/DataSourceManagement/src/index.vue

@@ -128,14 +128,19 @@
       :app-code="appCode"
       @refreshTable="init"
     />
+     <checkDatasource
+      ref="checkDatasource"
+      :reasonList="reasonList"
+      />
   </div>
 </template>
 
 <script>
 import table from 'data-room-ui/js/utils/table.js'
 import '../style/index.scss'
-import { sourceLinkTest, datasourcePage, sourceRemove } from 'data-room-ui/js/utils/dataSourceService'
+import { sourceLinkTest, datasourcePage, sourceRemove, dataSourceCheck } from 'data-room-ui/js/utils/dataSourceService'
 import setDatasource from './setDatasource.vue'
+import checkDatasource from './checkDatasource.vue'
 import _ from 'lodash'
 import { pageMixins } from 'data-room-ui/js/mixins/page'
 export default {
@@ -144,7 +149,8 @@ export default {
     table // 注册自定义指令
   },
   components: {
-    setDatasource
+    setDatasource,
+    checkDatasource
   },
   // 路由守卫-离开页面
   beforeRouteLeave (to, from, next) {
@@ -179,6 +185,7 @@ export default {
   },
   data () {
     return {
+      reasonList:[],
       testBtnLoading: [],
       loadingText: '',
       searchLoading: false,
@@ -272,17 +279,26 @@ export default {
     handleDelete (row) {
       // eslint-disable-next-line eqeqeq
       if (row.editable == 1 && !this.appCode) return
-      this.$confirm('确定删除当前数据源吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning',
-        customClass: 'bs-el-message-box'
-      }).then(() => {
-        sourceRemove(row.id).then((r) => {
-          this.$message.success('删除成功')
-          this.init()
+      dataSourceCheck(row.id).then((res)=>{
+        console.log(res)
+        if(res.canDelete){
+          this.$confirm('确定删除当前数据源吗?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning',
+          customClass: 'bs-el-message-box'
+        }).then(() => {
+          sourceRemove(row.id).then((r) => {
+            this.$message.success('删除成功')
+            this.init()
+          })
         })
+        }else{
+          this.reasonList=res.reasons
+          this.$refs.checkDatasource.checkDatasourceVisible = true
+        }
       })
+
     },
     sourceLinkTest (row) {
       this.testBtnLoading.push(row.id)

+ 10 - 1
data-room-ui/packages/js/utils/dataSourceService.js

@@ -10,6 +10,14 @@ import Vue from 'vue'
  */
 const add = (params = {}, flag = false) => Vue.prototype.$dataRoomAxios.post('/datasource/add', params, flag)
 
+/**
+ * 删除数据源前查询是否使用
+ * @param params
+ * @param flag
+ * @returns {*}
+ */
+const dataSourceCheck = (id='-1', flag = false) => Vue.prototype.$dataRoomAxios.post(`/datasource/deleteCheck/${id}`, {}, flag)
+
 /**
  * 修改数据源
  * @param params
@@ -103,5 +111,6 @@ export {
   getSourceTable,
   getSourceView,
   getTableFieldList,
-  getViewFieldList
+  getViewFieldList,
+  dataSourceCheck
 }

+ 11 - 1
data-room-ui/packages/js/utils/datasetConfigService.js

@@ -11,6 +11,15 @@ import Vue from 'vue'
  */
 const datasetPage = (params = {}, flag = false) => Vue.prototype.$dataRoomAxios.get('/dataset/page', params, flag)
 
+/**
+ * 删除数据源前查询是否使用
+ * @param params
+ * @param flag
+ * @returns {*}
+ */
+const dataSourceCheck = (id='-1', flag = false) => Vue.prototype.$dataRoomAxios.post(`/datasource/deleteCheck/${id}`, {}, flag)
+
+
 /**
  * 数据集列表查询
  * @param params
@@ -113,5 +122,6 @@ export {
   getCategoryTree,
   categoryAdd,
   categoryUpdate,
-  categoryRemove
+  categoryRemove,
+  dataSourceCheck
 }