diff --git a/src/assets/css/components/views/charts2/networkOverviewApps.scss b/src/assets/css/components/views/charts2/networkOverviewApps.scss index 6d56c0a8..42c48662 100644 --- a/src/assets/css/components/views/charts2/networkOverviewApps.scss +++ b/src/assets/css/components/views/charts2/networkOverviewApps.scss @@ -233,9 +233,16 @@ } } .add-app__body { + display: flex; + flex-direction: column; position: relative; flex: 1; background-color: #EBF1F4; + .body__loading { + width: 100%; + flex: 1; + position: relative; + } .el-tabs__item.is-top { height: 32px; } @@ -269,8 +276,12 @@ .el-tabs__header { padding-left: 20px; } + .body__apps-no-grid.body__apps { + height: 410px; + display: flex; + } .body__apps { - height: 420px; + height: 410px; padding: 0 20px; overflow: auto; display: grid; @@ -320,7 +331,7 @@ span { i { - color: green; + color: #38ACD2; margin-right: 2px; font-size: 16px; } diff --git a/src/views/charts2/charts/networkOverview/NetworkOverviewApps.vue b/src/views/charts2/charts/networkOverview/NetworkOverviewApps.vue index bc7275da..29504d22 100644 --- a/src/views/charts2/charts/networkOverview/NetworkOverviewApps.vue +++ b/src/views/charts2/charts/networkOverview/NetworkOverviewApps.vue @@ -72,30 +72,34 @@
-
-
+
+ +
- - {{app.name}} + + {{app.value}}
-
{{app.desc}}
+
{{app.remark}}
+
-
-
-
+
+ +
- - {{app.name}} + + {{app.value}}
-
{{app.desc}}
+
{{app.remark}}
+
-
@@ -103,6 +107,7 @@
+
@@ -119,14 +124,20 @@ import { get, put } from '@/utils/http' import { api } from '@/utils/api' import _ from 'lodash' import { getSecond } from '@/utils/date-util' -import { appTestData, appPrevTestData, providerTestData, providerPrevTestData } from '../appsTestData' import { getChainRatio } from '@/utils/tools' +import loading from '@/components/common/Loading' +import ChartNoData from '@/views/charts/charts/ChartNoData' export default { name: 'NetworkOverviewApps', props: { chart: Object, timeFilter: Object }, + components: { + loading, + ChartNoData + }, + setup () { return { myChart: shallowRef([]) @@ -162,12 +173,32 @@ export default { appShowName: false, searcherApp: '', appShowTypeTab: 0, - initialAppOptionsData: [], - initialProviderOptionsData: [], // 选中的app,不区分app和provider toSaveApp: [], myChartArray: [], - appShowType: 'bytes' + appShowType: 'bytes', + pageObj: { // 分页对象 + pageNo: 1, + pageSize: 24, + pages: 0 + }, + loading: false, + timerScroll: null, + offset: 0, + flag: false, + timerSearc: null + } + }, + watch: { + showAddApp: { + deep: true, + handler (n) { + if (n) { + window.addEventListener('scroll', this.handleScroll, true) + } else { + window.removeEventListener('scroll', this.handleScroll, true) + } + } } }, methods: { @@ -222,7 +253,7 @@ export default { // if (true) { const prevData = res[0].data.result const data = res[1].data.result - /*let prevData + /* let prevData let data if (_t === 'app') { prevData = appPrevTestData @@ -230,7 +261,7 @@ export default { } else if (_t === 'provider') { prevData = providerPrevTestData data = providerTestData - }*/ + } */ let toCompareType = 'bytes' if (this.metricFilter === 'Sessions/s') { toCompareType = 'sessions' @@ -301,34 +332,100 @@ export default { }) } }, + handleScroll (e) { + const clientHeight = e.target.clientHeight + const scrollTop = e.target.scrollTop + const scrollHeight = e.target.scrollHeight + if (scrollTop && (clientHeight + scrollTop) >= scrollHeight) { + if (this.pageObj.pages > this.pageObj.pageNo) { + this.pageObj.pageNo++ + this.loading = true + const params = { + startTime: getSecond(this.timeFilter.startTime), + endTime: getSecond(this.timeFilter.endTime), + pageSize: this.pageObj.pageSize, + pageNo: this.pageObj.pageNo + } + if (this.appShowTypeTab == 0) { + params.type = 'overviewProvide' + get(api.dict, params).then(res => { + if (res.code === 200) { + res.data.list.forEach(t => { + this.toSaveApp.forEach(e => { + if (t.value === e.name) { + t.provideShow = e.provideShow + } + }) + }) + this.providerOptions.push(...res.data.list) + this.pageObj.pages = res.data.pages + this.appListData([], this.providerOptions) + } + this.loading = false + }) + } else if (this.appShowTypeTab == 1) { + params.type = 'overviewApp' + get(api.dict, params).then(res => { + if (res.code === 200) { + res.data.list.forEach(t => { + this.toSaveApp.forEach(e => { + if (t.value === e.name) { + t.appShow = e.appShow + } + }) + }) + this.appOptions.push(...res.data.list) + this.pageObj.pages = res.data.pages + this.appListData(this.appOptions, []) + } + this.loading = false + }) + } + } + } + }, addApp () { this.showAddApp = true this.searcherApp = '' const letter = 'abcdefghijklmnopqrstuvwxyz' - const appOptions = [] - const providerOptions = [] - for (let i = 0; i < 100; i++) { - appOptions.push({ - name: letter[i % 26] + i, - desc: 'this is a really nice app', - appShow: false + this.providerOptions = [] + this.appOptions = [] + this.pageObj.pageNo = 1 + const params = { + startTime: getSecond(this.timeFilter.startTime), + endTime: getSecond(this.timeFilter.endTime), + pageSize: this.pageObj.pageSize, + pageNo: this.pageObj.pageNo + } + if (this.appShowTypeTab == 0) { + params.type = 'overviewProvide' + get(api.dict, params).then(res => { + if (res.code === 200) { + this.providerOptions.push(...res.data.list) + this.pageObj.pages = res.data.pages + this.appListData([], this.providerOptions) + } }) - providerOptions.push({ - name: letter[i % 26] + i, - desc: 'this is a really nice provider', - provideShow: false + } else if (this.appShowTypeTab == 1) { + params.type = 'overviewApp' + get(api.dict, params).then(res => { + if (res.code === 200) { + this.appOptions.push(...res.data.list) + this.pageObj.pages = res.data.pages + this.appListData(this.appOptions, []) + } }) } + }, + appListData (appOptions, providerOptions) { const oldApps = this.appData ? this.appData.filter(a => a.type === 'app') : [] const oldProviders = this.appData ? this.appData.filter(a => a.type === 'provider') : [] this.appOptions = appOptions.filter(a => { - return !oldApps.some(o => o.name === a.name) + return !oldApps.some(o => o.name === a.value) }) this.providerOptions = providerOptions.filter(a => { - return !oldProviders.some(o => o.name === a.name) + return !oldProviders.some(o => o.name === a.value) }) - this.initialAppOptionsData = [...this.appOptions] - this.initialProviderOptionsData = [...this.providerOptions] }, cancelApp () { this.showAddApp = false @@ -336,22 +433,62 @@ export default { appTypeTabChange (val) { this.appShowTypeTab = val.index this.searcherApp = '' - this.searcherAppChange(this.searcherApp) + this.addApp(val.index) + window.addEventListener('scroll', this.scrollChange, true) + this.timerScroll = setTimeout(() => { + window.removeEventListener('scroll', this.scrollChange, true) + }, 300) + }, + scrollChange (e) { + e.target.scrollTop = 0 }, searcherAppChange (val) { - if (val) { - if (this.appShowTypeTab == 0) { - this.providerOptions = this.initialProviderOptionsData.filter(t => t.name.indexOf(val) > -1) - } else if (this.appShowTypeTab == 1) { - this.appOptions = this.initialAppOptionsData.filter(t => t.name.indexOf(val) > -1) + clearTimeout(this.timerSearc) + this.timerSearc = setTimeout(() => { + if (this.flag) { + return false } - } else { - if (this.appShowTypeTab == 0) { - this.providerOptions = this.initialProviderOptionsData - } else if (this.appShowTypeTab == 1) { - this.appOptions = this.initialAppOptionsData + this.flag = true + if (!val) { + this.pageObj.pageNo = 1 } - } + const params = { + startTime: getSecond(this.timeFilter.startTime), + endTime: getSecond(this.timeFilter.endTime), + pageSize: this.pageObj.pageSize, + pageNo: this.pageObj.pageNo + } + if (this.appShowTypeTab == 0) { + params.type = 'overviewProvide' + get(api.dict, params).then(res => { + if (res.code === 200) { + res.data.list.forEach(t => { + this.toSaveApp.forEach(e => { + if (t.value === e.name) { + t.provideShow = e.provideShow + } + }) + }) + this.providerOptions = res.data.list.filter(t => t.value.indexOf(val) > -1) + } + }) + } else if (this.appShowTypeTab == 1) { + params.type = 'overviewApp' + get(api.dict, params).then(res => { + if (res.code === 200) { + res.data.list.forEach(t => { + this.toSaveApp.forEach(e => { + if (t.value === e.name) { + t.appShow = e.appShow + } + }) + }) + this.appOptions = res.data.list.filter(t => t.value.indexOf(val) > -1) + } + }) + } + this.flag = false + }, 500) }, // 保存变更,并且在增、删app后,根据当前app数量更改整体高度 saveChart (toSaveChart) { @@ -431,12 +568,12 @@ export default { appCheckedChange (app, num) { if (num === 0) { this.providerOptions.forEach(t => { - if (t.name === app.name) { + if (t.value === app.value) { t.provideShow = !t.provideShow if (t.provideShow) { - this.toSaveApp.push({ type: 'provider', name: app.name }) + this.toSaveApp.push({ type: 'provider', name: app.value, provideShow: t.provideShow }) } else { - const index = this.toSaveApp.findIndex(a => a.name === app.name) + const index = this.toSaveApp.findIndex(a => a.name === app.value) if (index > -1) { this.toSaveApp.splice(index, 1) } @@ -445,12 +582,12 @@ export default { }) } else if (num === 1) { this.appOptions.forEach(t => { - if (t.name === app.name) { + if (t.value === app.value) { t.appShow = !t.appShow if (t.appShow) { - this.toSaveApp.push({ type: 'app', name: app.name }) + this.toSaveApp.push({ type: 'app', name: app.value, appShow: t.appShow }) } else { - const index = this.toSaveApp.findIndex(a => a.name === app.name) + const index = this.toSaveApp.findIndex(a => a.name === app.value) if (index > -1) { this.toSaveApp.splice(index, 1) } @@ -484,6 +621,11 @@ export default { this.init() window.addEventListener('resize', this.resize) } + }, + beforeUnmount () { + window.removeEventListener('resize', this.resize) + clearTimeout(this.timerScroll) + clearTimeout(this.timerSearc) } }