Leo 2 years ago
parent
commit
89d95cbf50

+ 12 - 6
src/module/datasource/component/DatasourceManage.jsx

@@ -1,4 +1,9 @@
-import React, { useState, useEffect, useImperativeHandle } from 'react'
+import React, {
+  useState,
+  useEffect,
+  useImperativeHandle,
+  forwardRef,
+} from 'react'
 import {
   Space,
   Table,
@@ -17,7 +22,7 @@ import {
   getTableNamesList,
   getDataSourceInfo,
   getAilabList,
-  getUserProjects,
+  getAllShareProject,
   shareAilab,
   getLakeTable,
   ailabTablePreview,
@@ -29,7 +34,7 @@ import {
 const { Option } = Select
 const { TabPane } = Tabs
 
-export default function DatasourceManage({ onRef, dataType }) {
+const DatasourceManage = ({ dataType }, ref) => {
   // 查看数据源弹窗是否可可视
   const [dataModalVisible, setDataModalVisible] = useState(false)
   const [dataPreviewVisible, setDataPreviewVisible] = useState(false)
@@ -137,9 +142,8 @@ export default function DatasourceManage({ onRef, dataType }) {
     }
     setDataLoading(false)
   }
-
   // 暴露更新列表方法
-  useImperativeHandle(onRef, () => {
+  useImperativeHandle(ref, () => {
     return {
       updateSourceList: fetchDataSourceList,
       updateAilabList: fetchAilabList,
@@ -286,7 +290,7 @@ export default function DatasourceManage({ onRef, dataType }) {
   }, [isShareData])
 
   const fetchProjects = async () => {
-    const { data } = await getUserProjects()
+    const { data } = await getAllShareProject()
     if (data.code === 200) {
       const list = data.data.map(item => {
         return {
@@ -666,3 +670,5 @@ export default function DatasourceManage({ onRef, dataType }) {
     </div>
   )
 }
+
+export default forwardRef(DatasourceManage)

+ 7 - 4
src/module/datasource/component/StepOne.jsx

@@ -103,11 +103,11 @@ export default function StepOne({
         updateTableStruct(ds_id, val)
         break
       case 'datalake':
-        updateDrawLakeStruct(currentTable)
         drawDataForm.setFieldValue(
           'reader_path',
-          tableList.find(item => (item.value = currentTable)?.table_path)
+          tableList.find(item => item.value === currentTable).table_path
         )
+        updateDrawLakeStruct(currentTable)
         break
       default:
         updateDrawAilabStruct(currentTable)
@@ -119,7 +119,10 @@ export default function StepOne({
     setDsType(val)
     switch (val) {
       case 'datasource':
-        selectDatasource(drawDataForm.getFieldValue('datasource_name'))
+        const ds_id = drawDataForm.getFieldValue('datasource_name')
+        if (ds_id) {
+          selectDatasource(ds_id)
+        }
         break
       case 'datalake':
         setDatasourceType('hive')
@@ -169,7 +172,7 @@ export default function StepOne({
           <Select
             allowClear
             options={
-              ['1', '2', '3'].includes(sessionStorage.getItem('role'))
+              sessionStorage.getItem('project_type') === '0'
                 ? [
                     { label: '自添加数据源', value: 'datasource' },
                     { label: 'AIlab', value: 'ailab' },

+ 4 - 4
src/module/datasource/component/StepThree.jsx

@@ -110,7 +110,7 @@ export default function StepThree({
         ? await getTableSchema({ id, table_name })
         : ds_type === 'datalake'
         ? await lakeSchema(table_name)
-        : ailabSchema(table_name)
+        : await ailabSchema(table_name)
     if (data.code === 200) {
       const list = formatData(data.data)
       setDatasourceFields(list)
@@ -123,7 +123,7 @@ export default function StepThree({
         ? await getTableSchema({ id, table_name })
         : ds_type === 'datalake'
         ? await lakeSchema(table_name)
-        : ailabSchema(table_name)
+        : await ailabSchema(table_name)
     if (data.code === 200) {
       const list = formatData(data.data)
       setSyncFields([...list])
@@ -147,7 +147,7 @@ export default function StepThree({
     const ds_id = drawDataForm.getFieldValue('datasource_name')
     const table_name = drawDataForm.getFieldValue('datasource_table')
     const ds_type = drawDataForm.getFieldValue('datasource_type')
-    if (ds_id && table_name && ds_type) {
+    if (table_name && ds_type) {
       fetchDatasource(ds_id, table_name, ds_type)
     }
   }, [drawDataForm])
@@ -156,7 +156,7 @@ export default function StepThree({
     const ds_id = loadDataForm.getFieldValue('datasource_name')
     const table_name = loadDataForm.getFieldValue('datasource_table')
     const ds_type = loadDataForm.getFieldValue('datasource_type')
-    if (ds_id && table_name && ds_type) {
+    if (table_name && ds_type) {
       fetchSyncData(ds_id, table_name, ds_type)
     }
   }, [loadDataForm])

+ 5 - 2
src/module/datasource/component/StepTwo.jsx

@@ -95,7 +95,10 @@ export default function LoadFormConfig({
     setDsType(val)
     switch (val) {
       case 'datasource':
-        selectDatasource(loadDataForm.getFieldValue('datasource_name'))
+        const ds_id = loadDataForm.getFieldValue('datasource_name')
+        if (ds_id) {
+          selectDatasource(ds_id)
+        }
         break
       default:
         setDatasourceType('hive')
@@ -140,7 +143,7 @@ export default function LoadFormConfig({
           <Select
             allowClear
             options={
-              ['1', '2', '3'].includes(sessionStorage.getItem('role'))
+              sessionStorage.getItem('project_type') === '0'
                 ? [
                     { label: '自添加数据源', value: 'datasource' },
                     { label: 'AIlab', value: 'ailab' },

+ 3 - 1
src/module/datasource/component/SyncTaskAdd.jsx

@@ -218,7 +218,9 @@ export default function SyncTaskAdd() {
 
   // 挂载的时候获取SourceList
   useEffect(() => {
-    fetchDataSourceList()
+    if (sessionStorage.getItem('project_type') === '0') {
+      fetchDataSourceList()
+    }
   }, [])
 
   const [syncMapSaving, setSyncMapSaving] = useState([])

+ 32 - 27
src/module/datasource/page/DatasourceView.jsx

@@ -21,8 +21,8 @@ export default function DatasourceView() {
   const navigate = useNavigate()
   const { state } = useLocation()
   // 数据源管理ref
-  const sourceRef = React.createRef()
-  const logRef = React.createRef()
+  const sourceRef = React.useRef()
+  const logRef = React.useRef()
   // 当前所处页面
   const [currentKey, setCurrentKey] = useState('1')
   const [currentLog, setCurrentLog] = useState(null)
@@ -51,17 +51,17 @@ export default function DatasourceView() {
       }
     }
   }, [state])
-
   // 更新数据源列表
   const updateDataSource = () => {
-    sourceRef.current.updateSourceList()
+    sourceRef.current?.updateSourceList()
   }
 
-  const updateAilabList = () => {
-    sourceRef.current.updateAilabList()
+  const updateAilab = () => {
+    sourceRef.current?.updateAilabList()
   }
-  const updateLakeList = () => {
-    sourceRef.current.updateLakeList()
+
+  const updateLake = () => {
+    sourceRef.current?.updateLakeList()
   }
   const updateLogs = () => {
     logRef.current?.updateLogList()
@@ -91,7 +91,7 @@ export default function DatasourceView() {
           message.success('导入成功')
           datatableForm.resetFields()
           setImportData(false)
-          updateLakeList()
+          updateLake()
         } else {
           message.error(data.msg)
         }
@@ -166,12 +166,13 @@ export default function DatasourceView() {
           message.success('创建成功')
           ailabtableForm.resetFields()
           setIsCreateTable(false)
-          updateAilabList()
+          updateAilab()
         } else {
           message.error(data.msg)
         }
       })
       .catch(err => {
+        console.log(err)
         message.error('请检查表单数据是否完整')
       })
   }
@@ -323,25 +324,29 @@ export default function DatasourceView() {
             <Select
               value={currentDataType}
               onChange={changeDataType}
-              options={[
-                { value: 'datasource', label: '自添加数据源' },
-                { value: 'ailab', label: 'AIlab' },
-                { value: 'datalake', label: '数据湖' },
-              ]}
+              options={
+                ['1', '2', '3'].includes(sessionStorage.getItem('role'))
+                  ? [
+                      { value: 'datasource', label: '自添加数据源' },
+                      { value: 'ailab', label: 'AIlab' },
+                      { value: 'datalake', label: '数据湖' },
+                    ]
+                  : [{ value: 'ailab', label: 'AIlab' }]
+              }
             />
-            {currentDataType === 'datasource' && (
-              <DatasourceAdd updateDataSource={updateDataSource} />
-            )}
-            {currentDataType === 'ailab' &&
+            {currentDataType === 'datasource' &&
               sessionStorage.getItem('role') === '1' && (
-                <Button
-                  type="primary"
-                  onClick={() => {
-                    setIsCreateTable(true)
-                  }}>
-                  创建数据表
-                </Button>
+                <DatasourceAdd updateDataSource={updateDataSource} />
               )}
+            {currentDataType === 'ailab' && (
+              <Button
+                type="primary"
+                onClick={() => {
+                  setIsCreateTable(true)
+                }}>
+                创建数据表
+              </Button>
+            )}
             {currentDataType === 'datalake' &&
               sessionStorage.getItem('role') === '1' && (
                 <Button
@@ -380,7 +385,7 @@ export default function DatasourceView() {
           setCurrentLog(null)
         }}>
         <TabPane tab="数据源管理" key="1">
-          <DataSourceManage onRef={sourceRef} dataType={currentDataType} />
+          <DataSourceManage ref={sourceRef} dataType={currentDataType} />
         </TabPane>
         <TabPane tab="同步配置" key="2">
           <DatasourceSyncView

+ 6 - 0
src/module/datasource/services/index.js

@@ -205,3 +205,9 @@ export const lakeSchema = (table_name) =>
     method: 'get',
   })
 
+export const getAllShareProject = () =>
+  request({
+    url: `jpt/project/share_projects`,
+    method: 'get',
+  })
+

+ 38 - 36
src/module/layout/Main.jsx

@@ -11,6 +11,7 @@ import {
   Input,
   message,
   Table,
+  Popconfirm,
 } from 'antd'
 import {
   Routes,
@@ -161,7 +162,6 @@ const Main = () => {
   }, [pathname])
 
   useEffect(() => {
-    sessionStorage.getItem('user_token')
     getAllProjects()
   }, [])
 
@@ -176,30 +176,29 @@ const Main = () => {
         }
       })
       setProjectsList(list)
-      // changeProject(list[0].value, { key: list[0].id })
+      if (!sessionStorage.getItem('project_id')) {
+        changeProject(list[0].value, { key: list[0].id })
+      } else {
+        changeProject(sessionStorage.getItem('project_token'), {
+          key: sessionStorage.getItem('project_id'),
+        })
+      }
     } else {
       message.error(data.msg)
     }
   }
 
-  useEffect(() => {
-    if (projectsList.length) {
-      changeProject(sessionStorage.getItem('project_token'), {
-        key: sessionStorage.getItem('project_id'),
-      })
-    }
-  }, [projectsList])
-
   const onSelectSide = val => {
     setCurrentSide(val.key)
   }
 
   const changeProject = async (val, option) => {
     sessionStorage.setItem('project_id', option.key)
+    sessionStorage.setItem('project_token', val)
     const { data } = await getUserRole()
     if (data.code === 200) {
       sessionStorage.setItem('role', data.data.role_id)
-      sessionStorage.setItem('project_token', val)
+      sessionStorage.setItem('project_type', data.data.type)
       setCurrentProject(val)
     } else {
       message.error(data.msg)
@@ -362,31 +361,34 @@ const Main = () => {
       width: '25%',
       render: (_, record) => (
         <Space size="middle">
-          {!record.role.includes('管理员') && (
-            <Button
-              type="link"
-              onClick={() => {
-                setUserAdmin(record.key)
-              }}>
-              添加为管理员
-            </Button>
-          )}
-          {record.role.includes('管理员') && (
-            <Button
-              type="link"
-              onClick={() => {
-                removeUserAdmin(record.key)
-              }}>
-              移除管理员
-            </Button>
-          )}
-          <Button
-            onClick={() => {
-              removeUser(record.key)
-            }}
-            type="link">
-            移除
-          </Button>
+          {!record.role.includes('管理员') &&
+            sessionStorage.getItem('role') === '1' && (
+              <Button
+                type="link"
+                onClick={() => {
+                  setUserAdmin(record.key)
+                }}>
+                添加为管理员
+              </Button>
+            )}
+          {record.role.includes('管理员') &&
+            sessionStorage.getItem('role') === '1' && (
+              <Popconfirm
+                title="确认移除?"
+                okText="确认"
+                cancelText="取消"
+                onConfirm={() => removeUserAdmin(record.key)}>
+                <Button type="link">移除管理员</Button>
+              </Popconfirm>
+            )}
+
+          <Popconfirm
+            title="确认移除?"
+            okText="确认"
+            cancelText="取消"
+            onConfirm={() => removeUser(record.key)}>
+            <Button type="link">移除</Button>
+          </Popconfirm>
         </Space>
       ),
     },

+ 8 - 1
src/utils/request.js

@@ -30,14 +30,21 @@ axiosInstance.interceptors.response.use(
     if (error.response.status) {
       switch (error.response.status) {
         case 401:
+          sessionStorage.clear()
           window.location.pathname = "/login"
           break
-        default:
+        case 403:
           error.response.data = {
             code: 404,
             msg: '请选择项目'
           }
           break
+        default:
+          error.response.data = {
+            code: 404,
+            msg: '接口错误'
+          }
+          break
       }
       return Promise.resolve(error.response);
     }