Skip to content

Commit

Permalink
Make the fields of mock JS simulated data consistent with the real in…
Browse files Browse the repository at this point in the history
…terface.
  • Loading branch information
ikun-Lg committed Nov 10, 2024
1 parent 758283c commit 2ee99ea
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 208 deletions.
125 changes: 70 additions & 55 deletions ui-vue3/src/api/mock/mockApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,31 @@ Mock.mock('/mock/application/metrics', 'get', () => {
}
})

Mock.mock('/mock/application/search', 'get', () => {
let total = Mock.mock('@integer(8, 1000)')
let list = []
Mock.mock(devTool.mockUrl('/mock/application/search'), 'get', () => {
const total = Mock.mock('@integer(3, 20)')
const list = []
for (let i = 0; i < total; i++) {
let tmp: any = {
registerClusters: []
}
let num = Mock.mock('@integer(1,3)')
for (let j = 0; j < num; j++) {
let r = Mock.mock('@string(5)')
tmp.registerClusters.push(`cluster_${r}`)
}
list.push({
appName: 'app_' + Mock.mock('@string(2,10)'),
instanceNum: Mock.mock('@integer(80, 200)'),
deployCluster: 'cluster_' + Mock.mock('@string(5)'),
...tmp
appName: Mock.Random.pick(['QuickStartApplication', 'shop-comment', 'shop-detail', 'shop-order', 'shop-user']),
deployClusters: [Mock.Random.pick(['default', 'prod', 'test'])],
instanceCount: Mock.mock('@integer(1, 5)'),
registryClusters: [`${Mock.mock('@ip')}:8848`]
})
}

return {
code: 200,
message: 'success',
msg: 'success',
data: {
total: total,
curPage: 1,
pageSize: 10,
data: list
list: list,
pageInfo: {
Total: total,
NextOffset: ''
}
}
}
})

Mock.mock('/mock/application/instance/statistics', 'get', () => {
return {
code: 1000,
Expand All @@ -70,21 +65,15 @@ Mock.mock('/mock/application/instance/statistics', 'get', () => {
})

Mock.mock(devTool.mockUrl('/mock/application/instance/info'), 'get', () => {
let total = Mock.mock('@integer(8, 1000)')
let total = Mock.mock('@integer(8, 100)')
let list = []
for (let i = 0; i < total; i++) {
list.push({
ip: '121.90.211.162',
name: 'shop-user',
deployState: Mock.Random.pick(['Running', 'Pending', 'Terminating', 'Crashing']),
deployCluster: 'tx-shanghai-1',
registerStates: [
{
label: 'Registed',
value: 'Registed',
level: 'healthy'
}
],
registerState: 'Registed',
registerClusters: ['ali-hangzhou-1', 'ali-hangzhou-2'],
cpu: '1.2c',
memory: '2349MB',
Expand All @@ -98,41 +87,53 @@ Mock.mock(devTool.mockUrl('/mock/application/instance/info'), 'get', () => {
}
return {
code: 200,
message: 'success',
msg: 'success',
data: Mock.mock({
total: total,
curPage: 1,
pageSize: 10,
data: list
pageInfo: {
Total: list.length,
NextOffset: 0
},
list: list
})
}
})

Mock.mock('/mock/application/detail', 'get', () => {
Mock.mock(devTool.mockUrl('/mock/application/detail'), 'get', () => {
return {
code: 200,
message: 'success',
msg: 'success',
data: {
appName: ['shop-user'],
rpcProtocols: ['dubbo 2.0.2'],
dubboVersions: ['Dubbo 3.2.10', 'Dubbo 2.7.4.1'],
dubboPorts: ['20880'],
serialProtocols: ['fastjson2'],
appTypes: ['无状态'],
images: [
'harbor.apche.org/dubbo-samples-shop-user:v1.0',
'harbor.apche.org/dubbo-samples-shop-user:v1.1',
'harbor.apche.org/dubbo-samples-shop-user:v1.2'
],
workloads: [
'dubbo-samples-shop-user-base',
'dubbo-samples-shop-user-gray',
'dubbo-samples-shop-user-gray',
'dubbo-samples-shop-user-gray'
],
deployCluster: ['ali-shanghai-1', 'tx-shanghai-2'],
registerCluster: ['nacos-cluster-1', 'nacos-cluster-2'],
registerMode: ['应用级', '接口级']
appName: Mock.mock('@word(10,20)'),
appTypes: Mock.mock({
'array|2-5': ['@word(5,10)']
}).array,
deployClusters: Mock.mock({
'array|3-6': ['@word(8,15)']
}).array,
dubboPorts: Mock.mock({
'array|1-3': ['@integer(10000,65535)']
}).array,
dubboVersions: Mock.mock({
'array|2-4': ['@word(3,8)']
}).array,
images: Mock.mock({
'array|2-5': ['@word(10,20)']
}).array,
registerClusters: Mock.mock({
'array|2-4': ['@word(8,15)']
}).array,
registerModes: Mock.mock({
'array|1-3': ['@word(5,10)']
}).array,
rpcProtocols: Mock.mock({
'array|2-4': ['@word(3,8)']
}).array,
serialProtocols: Mock.mock({
'array|2-4': ['@word(4,8)']
}).array,
workloads: Mock.mock({
'array|3-6': ['@word(6,12)']
}).array
}
}
})
Expand All @@ -155,3 +156,17 @@ Mock.mock('/mock/application/event', 'get', () => {
}
}
})

Mock.mock(devTool.mockUrl('/mock/application/service/form'), 'get', () => {
return {
code: 200,
message: 'success',
data: {
list: [],
pageInfo: {
Total: 0,
NextOffset: ''
}
}
}
})
36 changes: 16 additions & 20 deletions ui-vue3/src/api/mock/mockInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/

import Mock from 'mockjs'
import devTool from '@/utils/DevToolUtil'

Mock.mock('/mock/instance/search', 'get', () => {
Mock.mock(devTool.mockUrl('/mock/instance/search'), 'get', () => {
let total = Mock.mock('@integer(8, 1000)')
let list = []
for (let i = 0; i < total; i++) {
Expand All @@ -26,17 +27,11 @@ Mock.mock('/mock/instance/search', 'get', () => {
name: 'shop-user',
deployState: Mock.Random.pick(['Running', 'Pending', 'Terminating', 'Crashing']),
deployCluster: 'tx-shanghai-1',
registerStates: [
{
label: 'Registed',
value: 'Registed',
level: 'healthy'
}
],
registerState: 'Registed',
registerClusters: ['ali-hangzhou-1', 'ali-hangzhou-2'],
cpu: '1.2c',
memory: '2349MB',
startTime: '2023-06-09 03:47:10',
startTime_k8s: '2023-06-09 03:47:10',
registerTime: '2023-06-09 03:48:20',
labels: {
region: 'beijing',
Expand All @@ -46,20 +41,21 @@ Mock.mock('/mock/instance/search', 'get', () => {
}
return {
code: 200,
message: 'success',
msg: 'success',
data: Mock.mock({
total: total,
curPage: 1,
pageSize: 10,
data: list
pageInfo: {
Total: total,
NextOffset: '0'
},
list: list
})
}
})

Mock.mock('/mock/instance/detail', 'get', () => {
Mock.mock(devTool.mockUrl('/mock/instance/detail'), 'get', () => {
return {
code: 200,
message: 'success',
msg: 'success',
data: {
deployState: 'Running',
registerStates: 'Unregisted',
Expand All @@ -82,15 +78,15 @@ Mock.mock('/mock/instance/detail', 'get', () => {
probes: {
startupProbe: {
type: 'http',
port: 22222
open: true
},
readinessProbe: {
type: 'http',
port: 22222
open: true
},
livenessPronbe: {
livenessProbe: {
type: 'http',
port: 22222
open: true
}
}
}
Expand Down
32 changes: 21 additions & 11 deletions ui-vue3/src/api/mock/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@
*/

import Mock from 'mockjs'
import devTool from '../../utils/DevToolUtil'
Mock.mock(devTool.mockUrl('/mock/metadata'), 'get', {
code: 200,
msg: 'success',
data: {
registry: 'nacos://47.101.215.139:8848?username=nacos&password=nacos',
metadata: 'nacos://47.101.215.139:8848?username=nacos&password=nacos',
config: 'nacos://47.101.215.139:8848?username=nacos&password=nacos',
prometheus: 'http://prometheus.observability.svc.cluster.local:9090/',
grafana: 'http://47.251.100.138:3000/d/a0b114ca-edf7-4dfe-ac2c-34a4fc545fed/application',
tracing: 'http://47.251.100.138:3000/d/e968a89b-f03d-42e3-8ad3-930ae815cb0f/application'
}
})

Mock.mock('/mock/metrics/metadata', 'get', {
Mock.mock(devTool.mockUrl('/mock/overview'), 'get', {
code: 200,
message: '成功',
msg: 'success',
data: {
versions: ['dubbo-golang-3.0.4'],
protocols: ['tri'],
rules: ['DemoService:1.0.0:test.configurators', 'DemoService4:bb:aa.configurators'],
configCenter: '127.0.0.1:2181',
registry: '127.0.0.1:2181',
metadataCenter: '127.0.0.1:2181',
// make sure the X-Frame-Options is forbidden
grafana: `http://${window.location.host}/admin/home`,
prometheus: '127.0.0.1:9090'
appCount: 0,
serviceCount: 0,
insCount: 0,
protocols: {},
releases: {},
discoveries: {}
}
})
41 changes: 28 additions & 13 deletions ui-vue3/src/api/mock/mockService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ import devTool from '@/utils/DevToolUtil'

Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
code: 200,
message: 'success',
msg: 'success',
data: {
total: 8,
curPage: 1,
pageSize: 5,
data: [
pageInfo: {
Total: 8,
NextOffset: '0'
},
list: [
{
serviceName: 'org.apache.dubbo.samples.UserService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -52,7 +53,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apache.dubbo.samples.OrderService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -76,7 +77,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apache.dubbo.samples.DetailService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -100,7 +101,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apache.dubbo.samples.PayService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -124,7 +125,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apache.dubbo.samples.CommentService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -148,7 +149,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apache.dubbo.samples.RepayService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -172,7 +173,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apche.dubbo.samples.TransportService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -196,7 +197,7 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
},
{
serviceName: 'org.apche.dubbo.samples.DistributionService',
versionGroup: [
versionGroups: [
{
version: '1.0.0',
group: 'group1'
Expand All @@ -221,3 +222,17 @@ Mock.mock(devTool.mockUrl('/mock/service/search'), 'get', {
]
}
})

Mock.mock(devTool.mockUrl('/mock/service/distribution'), 'get', () => {
return {
code: 200,
msg: 'success',
data: {
pageInfo: {
Total: 8,
NextOffset: '0'
},
list: []
}
}
})
Loading

0 comments on commit 2ee99ea

Please sign in to comment.