From 2cace4e916e4005a0b493670f8e271e8d982b29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=85=9C=E5=9D=A4?= Date: Mon, 14 Oct 2024 16:57:13 +0800 Subject: [PATCH] [ISSUE #12017] Update the frontend of the console by using the Console API for other section * Update the request path * Update the request parameters * Update the return values --- console-ui/src/pages/Login/Login.jsx | 1 + console-ui/src/pages/NameSpace/NameSpace.js | 12 +++++---- .../ServiceDetail/EditClusterDialog.js | 4 +-- .../ServiceDetail/EditInstanceDialog.js | 4 +-- .../ServiceDetail/EditServiceDialog.js | 10 +++---- .../ServiceDetail/InstanceTable.js | 8 +++--- .../ServiceDetail/ServiceDetail.js | 4 +-- .../ServiceList/ServiceList.js | 10 +++---- console-ui/src/reducers/authority.js | 26 +++++++++---------- console-ui/src/reducers/base.js | 10 +++---- console-ui/src/reducers/configuration.js | 8 +++--- console-ui/src/reducers/namespace.js | 4 +-- console-ui/src/reducers/subscribers.js | 4 +-- console-ui/src/utils/request.js | 2 +- 14 files changed, 55 insertions(+), 52 deletions(-) diff --git a/console-ui/src/pages/Login/Login.jsx b/console-ui/src/pages/Login/Login.jsx index 644616707c6..dd6e196e725 100644 --- a/console-ui/src/pages/Login/Login.jsx +++ b/console-ui/src/pages/Login/Login.jsx @@ -73,6 +73,7 @@ class Login extends React.Component { } login(values) .then(res => { + res= res.data; localStorage.setItem('token', JSON.stringify(res)); this.props.history.push('/'); }) diff --git a/console-ui/src/pages/NameSpace/NameSpace.js b/console-ui/src/pages/NameSpace/NameSpace.js index e5e119138e5..4fb7fd9c644 100644 --- a/console-ui/src/pages/NameSpace/NameSpace.js +++ b/console-ui/src/pages/NameSpace/NameSpace.js @@ -57,9 +57,9 @@ class NameSpace extends React.Component { request({ type: 'get', beforeSend() {}, - url: 'v1/console/namespaces', + url: 'v3/console/core/namespace/list', success: res => { - if (res.code === 200) { + if (res.code === 0) { const data = res.data || []; window.namespaceList = data; @@ -113,11 +113,12 @@ class NameSpace extends React.Component { const { namespaceDetails, namespaceName, namespaceID, configuration, description } = locale; const { namespace } = record; // 获取ak,sk request({ - url: `v1/console/namespaces?show=all&namespaceId=${namespace}`, + url: `v3/console/core/namespace?namespaceId=${namespace}`, beforeSend: () => { this.openLoading(); }, success: res => { + res = res.data; if (res !== null) { Dialog.alert({ style: { width: '500px' }, @@ -182,11 +183,12 @@ class NameSpace extends React.Component { ), onOk: () => { - const url = `v1/console/namespaces?namespaceId=${record.namespace}`; + const url = `v3/console/core/namespace?namespaceId=${record.namespace}`; request({ url, type: 'delete', success: res => { + res = res.data; const _payload = {}; _payload.title = configurationManagement; if (res === true) { @@ -210,7 +212,7 @@ class NameSpace extends React.Component { refreshNameSpace() { request({ type: 'get', - url: 'v1/console/namespaces', + url: 'v3/console/core/namespace', success: res => { if (res.code === 200) { window.namespaceList = res.data; diff --git a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditClusterDialog.js b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditClusterDialog.js index be8d0e15253..b2e4e07eaa5 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditClusterDialog.js +++ b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditClusterDialog.js @@ -69,7 +69,7 @@ class EditClusterDialog extends React.Component { } = this.state.editCluster; request({ method: 'PUT', - url: 'v1/ns/cluster', + url: 'v3/console/ns/service/cluster', data: { serviceName, clusterName: name, @@ -81,7 +81,7 @@ class EditClusterDialog extends React.Component { dataType: 'text', beforeSend: () => openLoading(), success: res => { - if (res !== 'ok') { + if (res.data !== 'ok') { Message.error(res); return; } diff --git a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditInstanceDialog.js b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditInstanceDialog.js index 0ae62f5170c..f0541791574 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditInstanceDialog.js +++ b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditInstanceDialog.js @@ -69,7 +69,7 @@ class EditInstanceDialog extends React.Component { const { ip, port, ephemeral, weight, enabled, metadataText } = this.state.editInstance; request({ method: 'PUT', - url: 'v1/ns/instance', + url: 'v3/console/ns/instance', data: { serviceName, clusterName, @@ -84,7 +84,7 @@ class EditInstanceDialog extends React.Component { dataType: 'text', beforeSend: () => openLoading(), success: res => { - if (res !== 'ok') { + if (res.data !== 'ok') { Message.error(res); return; } diff --git a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js index f7ec01bc80c..b6d695b19e8 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js +++ b/console-ui/src/pages/ServiceManagement/ServiceDetail/EditServiceDialog.js @@ -86,7 +86,7 @@ class EditServiceDialog extends React.Component { if (!this.validator({ name, protectThreshold })) return; request({ method: isCreate ? 'POST' : 'PUT', - url: 'v1/ns/service', + url: 'v3/console/ns/service', data: { serviceName: name, groupName: groupName || 'DEFAULT_GROUP', @@ -97,7 +97,7 @@ class EditServiceDialog extends React.Component { dataType: 'text', beforeSend: () => this.setState({ loading: true }), success: res => { - if (res !== 'ok') { + if (res.data !== 'ok') { Message.error(res); return; } @@ -107,7 +107,7 @@ class EditServiceDialog extends React.Component { this.props.getServiceDetail(); } }, - error: res => Message.error(res.responseText || res.statusText), + error: res => Message.error(res.data.responseText || res.data.statusText), complete: () => this.setState({ loading: false }), }); this.hide(); @@ -136,9 +136,9 @@ class EditServiceDialog extends React.Component { getSelectorTypes() { request({ method: 'GET', - url: 'v1/ns/service/selector/types', + url: 'v3/console/ns/service/selector/types', success: response => { - if (response.code !== 200) { + if (response.code !== 0) { Message.error(response.message); return; } diff --git a/console-ui/src/pages/ServiceManagement/ServiceDetail/InstanceTable.js b/console-ui/src/pages/ServiceManagement/ServiceDetail/InstanceTable.js index 3bcbea26d65..30a570ebe4b 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceDetail/InstanceTable.js +++ b/console-ui/src/pages/ServiceManagement/ServiceDetail/InstanceTable.js @@ -69,7 +69,7 @@ class InstanceTable extends React.Component { if (!clusterName) return; const { pageSize, pageNum } = this.state; request({ - url: 'v1/ns/catalog/instances', + url: 'v3/console/ns/instance/list', data: { serviceName, clusterName, @@ -78,7 +78,7 @@ class InstanceTable extends React.Component { pageNo: pageNum, }, beforeSend: () => this.openLoading(), - success: instance => this.setState({ instance }), + success: ({ data: instance }) => this.setState({ instance }), complete: () => this.closeLoading(), }); } @@ -93,7 +93,7 @@ class InstanceTable extends React.Component { const { clusterName, serviceName, groupName } = this.props; request({ method: 'PUT', - url: 'v1/ns/instance', + url: 'v3/console/ns/instance', data: { serviceName, clusterName, @@ -107,7 +107,7 @@ class InstanceTable extends React.Component { }, dataType: 'text', beforeSend: () => this.openLoading(), - success: () => { + success: ({ data }) => { const newVal = Object.assign({}, instance); newVal.list[index].enabled = !enabled; this.setState({ instance: newVal }); diff --git a/console-ui/src/pages/ServiceManagement/ServiceDetail/ServiceDetail.js b/console-ui/src/pages/ServiceManagement/ServiceDetail/ServiceDetail.js index 651b6b116c2..23b9b5f1259 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceDetail/ServiceDetail.js +++ b/console-ui/src/pages/ServiceManagement/ServiceDetail/ServiceDetail.js @@ -72,9 +72,9 @@ class ServiceDetail extends React.Component { getServiceDetail() { const { serviceName, groupName } = this.state; request({ - url: `v1/ns/catalog/service?serviceName=${serviceName}&groupName=${groupName}`, + url: `v3/console/ns/service?serviceName=${serviceName}&groupName=${groupName}`, beforeSend: () => this.openLoading(), - success: ({ clusters = [], service = {} }) => this.setState({ service, clusters }), + success: ({ data: { clusters = [], service = {} } }) => this.setState({ service, clusters }), error: e => Message.error(e.responseText || 'error'), complete: () => this.closeLoading(), }); diff --git a/console-ui/src/pages/ServiceManagement/ServiceList/ServiceList.js b/console-ui/src/pages/ServiceManagement/ServiceList/ServiceList.js index f30ceac8d3e..e272407ac24 100644 --- a/console-ui/src/pages/ServiceManagement/ServiceList/ServiceList.js +++ b/console-ui/src/pages/ServiceManagement/ServiceList/ServiceList.js @@ -103,8 +103,8 @@ class ServiceList extends React.Component { }); this.openLoading(); request({ - url: `v1/ns/catalog/services?${parameter.join('&')}`, - success: ({ count = 0, serviceList = [] } = {}) => { + url: `v3/console/ns/service/list?${parameter.join('&')}`, + success: ({ data: { count = 0, serviceList = [] } = {} }) => { this.setState({ dataSource: serviceList, total: count, @@ -158,17 +158,17 @@ class ServiceList extends React.Component { onOk: () => { request({ method: 'DELETE', - url: `v1/ns/service?serviceName=${service.name}&groupName=${service.groupName}`, + url: `v3/console/ns/service?serviceName=${service.name}&groupName=${service.groupName}`, dataType: 'text', beforeSend: () => this.openLoading(), success: res => { - if (res !== 'ok') { + if (res.data !== 'ok') { Message.error(res); return; } this.queryServiceList(); }, - error: res => Message.error(res.responseText || res.statusText), + error: res => Message.error(res.data.responseText || res.data.statusText), complete: () => this.closeLoading(), }); }, diff --git a/console-ui/src/reducers/authority.js b/console-ui/src/reducers/authority.js index 8c4ece20617..cee28cfb568 100644 --- a/console-ui/src/reducers/authority.js +++ b/console-ui/src/reducers/authority.js @@ -51,35 +51,35 @@ const successMsg = res => { * @param {*} params */ const getUsers = params => dispatch => - request.get('v1/auth/users', { params }).then(data => dispatch({ type: USER_LIST, data })); + request.get('v3/auth/user/list', { params }).then(data => dispatch({ type: USER_LIST, data: data.data })); /** * 创建用户 * @param {*} param0 */ const createUser = ([username, password]) => - request.post('v1/auth/users', { username, password }).then(res => successMsg(res)); + request.post('v3/auth/user', { username, password }).then(res => successMsg(res)); /** * 通过username 模糊匹配 * @param {*} param0 */ const searchUsers = username => - request.get('v1/auth/users/search', { params: { username } }).then(res => successMsg(res)); + request.get('v3/auth/user/search', { params: { username } }).then(res => successMsg(res.data)); /** * 删除用户 * @param {*} username */ const deleteUser = username => - request.delete('v1/auth/users', { params: { username } }).then(res => successMsg(res)); + request.delete('v3/auth/user', { params: { username } }).then(res => successMsg(res)); /** * 重置密码 * @param {*} param0 */ const passwordReset = ([username, newPassword]) => - request.put('v1/auth/users', { username, newPassword }).then(res => successMsg(res)); + request.put('v3/auth/user', { username, newPassword }).then(res => successMsg(res)); /** * 角色列表 @@ -87,28 +87,28 @@ const passwordReset = ([username, newPassword]) => */ const getRoles = params => dispatch => - request.get('v1/auth/roles', { params }).then(data => dispatch({ type: ROLE_LIST, data })); + request.get('v3/auth/role/list', { params }).then(data => dispatch({ type: ROLE_LIST, data: data.data })); /** * 通过username 模糊匹配 * @param {*} param0 */ const searchRoles = role => - request.get('v1/auth/roles/search', { params: { role } }).then(res => successMsg(res)); + request.get('v3/auth/role/search', { params: { role } }).then(res => successMsg(res.data)); /** * 创建角色 * @param {*} param0 */ const createRole = ([role, username]) => - request.post('v1/auth/roles', { role, username }).then(res => successMsg(res)); + request.post('v3/auth/role', { role, username }).then(res => successMsg(res)); /** * 删除角色 * @param {*} param0 */ const deleteRole = role => - request.delete('v1/auth/roles', { params: role }).then(res => successMsg(res)); + request.delete('v3/auth/role', { params: role }).then(res => successMsg(res)); /** * 权限列表 @@ -116,22 +116,22 @@ const deleteRole = role => */ const getPermissions = params => dispatch => request - .get('v1/auth/permissions', { params }) - .then(data => dispatch({ type: PERMISSIONS_LIST, data })); + .get('v3/auth/permission/list', { params }) + .then(data => dispatch({ type: PERMISSIONS_LIST, data: data.data })); /** * 给角色添加权限 * @param {*} param0 */ const createPermission = ([role, resource, action]) => - request.post('v1/auth/permissions', { role, resource, action }).then(res => successMsg(res)); + request.post('v3/auth/permission', { role, resource, action }).then(res => successMsg(res)); /** * 删除权限 * @param {*} param0 */ const deletePermission = permission => - request.delete('v1/auth/permissions', { params: permission }).then(res => successMsg(res)); + request.delete('v3/auth/permission', { params: permission }).then(res => successMsg(res)); export default (state = initialState, action) => { switch (action.type) { diff --git a/console-ui/src/reducers/base.js b/console-ui/src/reducers/base.js index b773ec77191..d1137027073 100644 --- a/console-ui/src/reducers/base.js +++ b/console-ui/src/reducers/base.js @@ -33,13 +33,13 @@ const initialState = { * 用户登录 * @param {*} param0 */ -const login = user => request.post('v1/auth/users/login', user); -const admin = user => request.post('v1/auth/users/admin', user); +const login = user => request.post('v3/auth/user/login', user); +const admin = user => request.post('v3/auth/user/admin', user); /** * 单独在login处调用 获取提示信息 */ -const guide = () => request.get('v1/console/server/guide'); +const guide = () => request.get('v3/console/server/guide'); /** * 单独在login调用 判断是否可以登陆 @@ -82,7 +82,7 @@ const getState = () => dispatch => const getNotice = () => dispatch => request - .get('v1/console/server/announcement?language=' + localStorage.getItem(LANGUAGE_KEY)) + .get('v3/console/server/announcement?language=' + localStorage.getItem(LANGUAGE_KEY)) .then(res => { dispatch({ type: GET_NOTICE, @@ -102,7 +102,7 @@ const getNotice = () => dispatch => const getGuide = () => dispatch => request - .get('v1/console/server/guide') + .get('v3/console/server/guide') .then(res => { dispatch({ type: SERVER_GUIDE, diff --git a/console-ui/src/reducers/configuration.js b/console-ui/src/reducers/configuration.js index 5e5c000bbc7..b7f720c6f3b 100644 --- a/console-ui/src/reducers/configuration.js +++ b/console-ui/src/reducers/configuration.js @@ -23,13 +23,13 @@ const initialState = { const getConfigs = params => dispatch => request - .get('v1/cs/configs', { params }) - .then(data => dispatch({ type: GET_CONFIGURATION, data })); + .get('v3/console/cs/config/list', { params }) + .then(data => dispatch({ type: GET_CONFIGURATION, data: data.data })); const getConfigsV2 = params => dispatch => request - .get('v2/cs/config/searchDetail', { params }) - .then(data => dispatch({ type: GET_CONFIGURATION, data })); + .get('v3/console/cs/config/searchDetail', { params }) + .then(data => dispatch({ type: GET_CONFIGURATION, data: data.data })); export default (state = initialState, action) => { switch (action.type) { diff --git a/console-ui/src/reducers/namespace.js b/console-ui/src/reducers/namespace.js index d5cecd8026a..d84cd9dca54 100644 --- a/console-ui/src/reducers/namespace.js +++ b/console-ui/src/reducers/namespace.js @@ -22,11 +22,11 @@ const initialState = { }; const getNamespaces = params => dispatch => - request.get('v1/console/namespaces', { params }).then(response => { + request.get('v3/console/core/namespace/list', { params }).then(response => { const { code, data } = response; dispatch({ type: GET_NAMESPACES, - data: code === 200 ? data : [], + data: code === 0 ? data : [], }); }); diff --git a/console-ui/src/reducers/subscribers.js b/console-ui/src/reducers/subscribers.js index da5667d2d1f..fb36b1d7f31 100644 --- a/console-ui/src/reducers/subscribers.js +++ b/console-ui/src/reducers/subscribers.js @@ -22,10 +22,10 @@ const initialState = { }; const getSubscribers = params => dispatch => - request.get('v1/ns/service/subscribers', { params }).then(data => { + request.get('v3/console/ns/service/subscribers', { params }).then(data => { dispatch({ type: GET_SUBSCRIBERS, - data, + data: data.data, }); }); const removeSubscribers = () => dispatch => dispatch({ type: REMOVE_SUBSCRIBERS }); diff --git a/console-ui/src/utils/request.js b/console-ui/src/utils/request.js index fd07b92e6b7..18b981d94bd 100644 --- a/console-ui/src/utils/request.js +++ b/console-ui/src/utils/request.js @@ -40,7 +40,7 @@ const request = () => { if (!params) { config.params = {}; } - if (!url.includes('auth/users/login') && localStorage.token) { + if (!url.includes('auth/user/login') && localStorage.token) { let token = {}; try { token = JSON.parse(localStorage.token);