Skip to content

Commit

Permalink
feat: naming,cluster api切换到v2,同时使用返回值统一处理工具; #24
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Dec 29, 2024
1 parent 4216427 commit 92f00b1
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 135 deletions.
6 changes: 3 additions & 3 deletions src/api/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { AxiosResponse } from 'axios';
import request from '../utils/request';
import { IClusterNode } from '@/types/cluster';
import { IConsoleResult } from '@/types/base';
import { IApiResult, IConsoleResult } from '@/types/base';
let axios = request;

class ClusterApi {
queryNodeList(): Promise<AxiosResponse<IConsoleResult<Array<IClusterNode>>>> {
queryNodeList(): Promise<AxiosResponse<IApiResult<Array<IClusterNode>>>> {
return axios.request({
method: 'get',
url: '/rnacos/api/console/cluster/cluster_node_list'
url: '/rnacos/api/console/v2/cluster/cluster_node_list'
});
}
}
Expand Down
52 changes: 28 additions & 24 deletions src/api/naming.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosResponse } from 'axios';
import request from '../utils/request';
import { IServiceInfo, IServiceInstance, IServiceKey } from '@/types/service';
import { IApiResult, IPageResult } from '@/types/base';
let axios = request;

export interface IServiceQueryPageParam {
Expand All @@ -9,7 +10,6 @@ export interface IServiceQueryPageParam {
groupNameParam: string;
pageNo: Number;
pageSize: Number;
accessToken?: string;
}

export interface IServiceQueryItem {
Expand All @@ -31,46 +31,50 @@ export interface IServiceQueryPageResult<T> {
class NamingApi {
queryServicePage(
param: IServiceQueryPageParam
): Promise<AxiosResponse<IServiceQueryPageResult<IServiceQueryItem>>> {
): Promise<AxiosResponse<IApiResult<IPageResult<IServiceQueryItem>>>> {
return axios.request({
method: 'get',
url: '/rnacos/api/console/ns/services',
url: '/rnacos/api/console/v2/service/list',
params: param
});
}
createService(info: IServiceInfo): Promise<AxiosResponse> {
return axios.request({

createService(info: IServiceInfo): Promise<AxiosResponse<IApiResult<any>>> {
return axios.requestJSON({
method: 'post',
url: '/rnacos/api/console/ns/service',
data: info
url: '/rnacos/api/console/v2/service/add',
data: JSON.stringify(info)
});
}
updateService(info: IServiceInfo): Promise<AxiosResponse> {
return axios.request({
method: 'put',
url: '/rnacos/api/console/ns/service',
data: info
updateService(info: IServiceInfo): Promise<AxiosResponse<IApiResult<any>>> {
return axios.requestJSON({
method: 'post',
url: '/rnacos/api/console/v2/service/update',
data: JSON.stringify(info)
});
}
removeService(key: IServiceKey): Promise<AxiosResponse> {
return axios.request({
method: 'delete',
url: '/rnacos/api/console/ns/service',
data: key
removeService(key: IServiceKey): Promise<AxiosResponse<IApiResult<any>>> {
return axios.requestJSON({
method: 'post',
url: '/rnacos/api/console/v2/service/remove',
data: JSON.stringify(key)
});
}
queryServiceInstances(key: IServiceKey): Promise<AxiosResponse> {
queryServiceInstances(
key: IServiceKey
): Promise<AxiosResponse<IApiResult<IPageResult<any>>>> {
return axios.request({
method: 'get',
url: '/rnacos/api/console/instances',
url: '/rnacos/api/console/v2/instance/list',
params: key
});
}

updateInstance(instance: IServiceInstance): Promise<AxiosResponse> {
return axios.request({
method: 'put',
url: '/rnacos/api/console/ns/instance',
updateInstance(
instance: IServiceInstance
): Promise<AxiosResponse<IApiResult<any>>> {
return axios.requestJSON({
method: 'post',
url: '/rnacos/api/console/v2/instance/update',
data: instance
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const getMessage = function (key) {
for (var subKey of items) {
obj = obj[subKey];
}
return obj || key;
return obj || '';
};

export default i18n;
4 changes: 4 additions & 0 deletions src/i18n/lang/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const message = {
part: 'Part',
permission: 'permission',
submitSuccess: 'Submit success',
success: 'Success',
home: 'Home'
},
cluster: {
Expand Down Expand Up @@ -94,6 +95,8 @@ const message = {
weight: 'Weight',
healthy: 'Healthy',
online: 'Enable',
onlineText: 'Online',
offlineText: 'Offline',
editTitle: 'Edit instance',
registerTime: 'Register time',
metadata: 'Metadata'
Expand Down Expand Up @@ -258,6 +261,7 @@ const message = {
},
error: {
NO_PERMISSION: 'NO_PERMISSION',
NO_NAMESPACE_PERMISSION: 'NO_NAMESPACE_PERMISSION',
SYSTEM_ERROR: 'SYSTEM_ERROR'
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/lang/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const message = {
part: '部分',
permission: '权限',
submitSuccess: '提交成功',
success: '成功',
home: '首页'
},
cluster: {
Expand Down Expand Up @@ -92,6 +93,8 @@ const message = {
weight: '权重',
healthy: '健康状态',
online: '是否上线',
onlineText: '上线',
offlineText: '下线',
editTitle: '编辑实例',
registerTime: '注册时间',
metadata: '元数据'
Expand Down Expand Up @@ -250,6 +253,7 @@ const message = {
},
error: {
NO_PERMISSION: '没有权限',
NO_NAMESPACE_PERMISSION: '没有命名空间权限',
SYSTEM_ERROR: '系统异常'
}
};
Expand Down
14 changes: 5 additions & 9 deletions src/pages/ClusterPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import { defineComponent } from 'vue';
import { clusterApi } from '@/api/cluster';
import { createColumns } from '@/components/cluster/ClusterInfoColumns';
import { handleApiResult, printApiError } from '@/utils/request';
export default defineComponent({
setup() {
Expand All @@ -32,16 +33,11 @@ export default defineComponent({
const doLoadData = function () {
clusterApi
.queryNodeList()
.then((res) => {
if (res.status == 200) {
dataRef.value = res.data.data;
} else {
window.$message.error('request err,status code:' + res.status);
}
.then(handleApiResult)
.then((data) => {
dataRef.value = data || [];
})
.catch((err) => {
window.$message.error(err.message);
});
.catch(printApiError);
};
return {
columns,
Expand Down
88 changes: 41 additions & 47 deletions src/pages/ServiceInstanceListPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ import { createColumns } from '@/components/naming/InstanceListColumns';
import ServiceInstanceDetail from './ServiceInstanceDetail.vue';
import * as constant from '@/types/constant';
import { useRoute } from 'vue-router';
import {
handleApiResult,
printApiError,
printApiSuccess
} from '@/utils/request';
export default defineComponent({
components: {
Expand Down Expand Up @@ -129,9 +134,9 @@ export default defineComponent({
const modelRef = ref({
ip: '',
port: '0',
port: 0,
enabled: true,
weight: '1',
weight: 1,
metadata: '{}',
mode: constant.FORM_MODE_DETAIL
});
Expand All @@ -141,9 +146,9 @@ export default defineComponent({
const showUpdate = (row) => {
modelRef.value = {
ip: row.ip,
port: row.port.toString(),
port: row.port,
enabled: row.enabled,
weight: (row.weight || 1).toString(),
weight: row.weight || 1,
metadata: JSON.stringify(row.metadata || {}),
mode: constant.FORM_MODE_UPDATE
};
Expand All @@ -163,23 +168,21 @@ export default defineComponent({
};
namingApi
.updateInstance(instance)
.then((res) => {
if (res.status == 200) {
if (enabled) {
window.$message.info('上线成功!');
} else {
window.$message.info('下线成功!');
}
row.enabled = enabled;
setCurrentPageData(paginationReactive.page || 1);
//reloadData()
return;
.then(handleApiResult)
.then(() => {
if (enabled) {
window.$message.info(
t('instance.onlineText') + t('common.join') + t('common.success')
);
} else {
window.$message.info(
t('instance.offlineText') + t('common.join') + t('common.success')
);
}
window.$message.error('设置失败,response code' + res.status);
row.enabled = enabled;
setCurrentPageData(paginationReactive.page || 1);
})
.catch((err) => {
window.$message.error('设置失败,' + err.message);
});
.catch(printApiError);
};
const onLine = (row) => {
setRowEnabled(row, true);
Expand Down Expand Up @@ -220,25 +223,21 @@ export default defineComponent({
if (!loadingRef.value) {
loadingRef.value = true;
doQueryList()
.then((res) => {
.then(handleApiResult)
.then((page) => {
loadingRef.value = false;
if (res.status == 200) {
let count = res.data.count;
let pageSize = paginationReactive.pageSize;
paginationReactive.itemCount = count;
paginationReactive.pageCount = Math.round(
(count + pageSize - 1) / pageSize
);
loadedRef.value = true;
sourceDataRef.value = res.data.list || [];
setCurrentPageData(currentPage);
} else {
window.$message.error('request err,status code:' + res.status);
dataRef.value = [];
}
let count = page.totalCount;
let pageSize = paginationReactive.pageSize;
paginationReactive.itemCount = count;
paginationReactive.pageCount = Math.round(
(count + pageSize - 1) / pageSize
);
loadedRef.value = true;
sourceDataRef.value = page.list || [];
setCurrentPageData(currentPage);
})
.catch((err) => {
window.$message.error('request err,message' + err.message);
printApiError(err);
dataRef.value = [];
loadingRef.value = false;
});
Expand Down Expand Up @@ -307,25 +306,20 @@ export default defineComponent({
ip: this.model.ip,
port: this.model.port,
weight: this.model.weight,
weight: parseFloat(this.model.weight) || 1,
enabled: this.model.enabled,
metadata: this.model.metadata
};
if (this.model.mode === constant.FORM_MODE_UPDATE) {
namingApi
.updateInstance(instance)
.then((res) => {
if (res.status == 200) {
window.$message.info('设置成功!');
this.useForm = false;
this.reloadData();
return;
}
window.$message.error('设置失败,response code' + res.status);
.then(handleApiResult)
.then(printApiSuccess)
.then(() => {
this.useForm = false;
this.reloadData();
})
.catch((err) => {
window.$message.error('设置失败,' + err.message);
});
.catch(printApiError);
} else {
this.useForm = false;
}
Expand Down
Loading

0 comments on commit 92f00b1

Please sign in to comment.