From e382bb6bbadc2bd0649489a8e0f594f7d85a266c Mon Sep 17 00:00:00 2001 From: wangdan-fit2cloud Date: Fri, 29 Mar 2024 15:45:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E6=A6=82=E8=A7=88?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=91=E6=8E=A7=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/package.json | 2 + ui/src/api/application-overview.ts | 15 +- .../app-charts/components/LineCharts.vue | 128 ++++++++++ ui/src/components/app-charts/index.vue | 30 +++ ui/src/components/icons/index.ts | 88 +++++++ ui/src/styles/app.scss | 13 +- ui/src/utils/time.ts | 10 + ui/src/utils/utils.ts | 12 + .../component/StatisticsCharts.vue | 161 ++++++++++++ ui/src/views/applicaiton-overview/index.vue | 237 ++++++++++++------ 10 files changed, 618 insertions(+), 78 deletions(-) create mode 100644 ui/src/components/app-charts/components/LineCharts.vue create mode 100644 ui/src/components/app-charts/index.vue create mode 100644 ui/src/views/applicaiton-overview/component/StatisticsCharts.vue diff --git a/ui/package.json b/ui/package.json index 742ff4658..07c70038f 100644 --- a/ui/package.json +++ b/ui/package.json @@ -14,6 +14,7 @@ }, "dependencies": { "axios": "^0.28.0", + "echarts": "^5.5.0", "element-plus": "^2.5.6", "install": "^0.13.0", "lodash": "^4.17.21", @@ -29,6 +30,7 @@ "md-editor-v3": "^4.12.1", "medium-zoom": "^1.1.0", "mitt": "^3.0.0", + "moment": "^2.30.1", "npm": "^10.2.4", "nprogress": "^0.2.0", "pinia": "^2.1.6", diff --git a/ui/src/api/application-overview.ts b/ui/src/api/application-overview.ts index 940088353..d77da6322 100644 --- a/ui/src/api/application-overview.ts +++ b/ui/src/api/application-overview.ts @@ -55,9 +55,22 @@ const putAPIKey: ( return put(`${prefix}/${applicaiton_id}/api_key/${api_key_id}`, data, undefined, loading) } +/** + * 统计 + * @param 参数 applicaiton_id, data + */ +const getStatistics: ( + applicaiton_id: string, + data: any, + loading?: Ref +) => Promise> = (applicaiton_id, data, loading) => { + return get(`${prefix}/${applicaiton_id}/statistics/chat_record_aggregate_trend`, data, loading) +} + export default { getAPIKey, postAPIKey, delAPIKey, - putAPIKey + putAPIKey, + getStatistics } diff --git a/ui/src/components/app-charts/components/LineCharts.vue b/ui/src/components/app-charts/components/LineCharts.vue new file mode 100644 index 000000000..5c236e2cb --- /dev/null +++ b/ui/src/components/app-charts/components/LineCharts.vue @@ -0,0 +1,128 @@ + + + diff --git a/ui/src/components/app-charts/index.vue b/ui/src/components/app-charts/index.vue new file mode 100644 index 000000000..bc3f845a5 --- /dev/null +++ b/ui/src/components/app-charts/index.vue @@ -0,0 +1,30 @@ + + diff --git a/ui/src/components/icons/index.ts b/ui/src/components/icons/index.ts index 775c734c2..b093c63bc 100644 --- a/ui/src/components/icons/index.ts +++ b/ui/src/components/icons/index.ts @@ -640,5 +640,93 @@ export const iconMap: any = { ) ]) } + }, + 'app-user': { + iconReader: () => { + return h('i', [ + h( + 'svg', + { + style: { height: '100%', width: '100%' }, + viewBox: '0 0 24 24', + version: '1.1', + xmlns: 'http://www.w3.org/2000/svg' + }, + [ + h('path', { + d: 'M15 13H9C6.23858 13 3 14.9314 3 18.4V21.1C3 21.597 3.44772 22 4 22H20C20.5523 22 21 21.597 21 21.1V18.4C21 14.9285 17.7614 13 15 13Z', + fill: 'currentColor' + }), + h('path', { + d: 'M7 6.99997C7 9.76139 9.23858 12 12 12C14.7614 12 17 9.76139 17 6.99997C17 4.23855 14.7614 1.99997 12 1.99997C9.23858 1.99997 7 4.23855 7 6.99997Z', + fill: 'currentColor' + }) + ] + ) + ]) + } + }, + 'app-question': { + iconReader: () => { + return h('i', [ + h( + 'svg', + { + style: { height: '100%', width: '100%' }, + viewBox: '0 0 24 24', + version: '1.1', + xmlns: 'http://www.w3.org/2000/svg' + }, + [ + h('path', { + d: 'M12.7071 22.2009L17 18.5111H21.5C22.0523 18.5111 22.5 18.0539 22.5 17.4899V2.52112C22.5 1.95715 22.0523 1.49997 21.5 1.49997H2C1.44772 1.49997 1 1.95715 1 2.52112V17.4899C1 18.0539 1.44772 18.5111 2 18.5111H7L11.2929 22.2009C11.6834 22.5997 12.3166 22.5997 12.7071 22.2009ZM6.5 8.49997H7.5C8.05228 8.49997 8.5 8.94768 8.5 9.49997V10.5C8.5 11.0523 8.05228 11.5 7.5 11.5H6.5C5.94772 11.5 5.5 11.0523 5.5 10.5V9.49997C5.5 8.94768 5.94772 8.49997 6.5 8.49997ZM10.5 9.49997C10.5 8.94768 10.9477 8.49997 11.5 8.49997H12.5C13.0523 8.49997 13.5 8.94768 13.5 9.49997V10.5C13.5 11.0523 13.0523 11.5 12.5 11.5H11.5C10.9477 11.5 10.5 11.0523 10.5 10.5V9.49997ZM16.5 8.49997H17.5C18.0523 8.49997 18.5 8.94768 18.5 9.49997V10.5C18.5 11.0523 18.0523 11.5 17.5 11.5H16.5C15.9477 11.5 15.5 11.0523 15.5 10.5V9.49997C15.5 8.94768 15.9477 8.49997 16.5 8.49997Z', + fill: 'currentColor' + }) + ] + ) + ]) + } + }, + 'app-tokens': { + iconReader: () => { + return h('i', [ + h( + 'svg', + { + style: { height: '100%', width: '100%' }, + viewBox: '0 0 24 24', + version: '1.1', + xmlns: 'http://www.w3.org/2000/svg' + }, + [ + h('path', { + d: 'M15.6 2.39996C12.288 2.39996 9.60002 5.08796 9.60002 8.39996C9.60002 9.11996 9.74402 9.79196 9.97202 10.428L2.47325 17.9267C2.42636 17.9736 2.40002 18.0372 2.40002 18.1035V21.1C2.40002 21.3761 2.62388 21.6 2.90002 21.6H4.30002C4.57617 21.6 4.80002 21.3761 4.80002 21.1V20.4H6.70003C6.97617 20.4 7.20002 20.1761 7.20002 19.9V18H8.40002L10.8 15.6H12L13.572 14.028C14.208 14.256 14.88 14.4 15.6 14.4C18.912 14.4 21.6 11.712 21.6 8.39996C21.6 5.08796 18.912 2.39996 15.6 2.39996ZM17.4 8.39996C16.404 8.39996 15.6 7.59596 15.6 6.59996C15.6 5.60396 16.404 4.79996 17.4 4.79996C18.396 4.79996 19.2 5.60396 19.2 6.59996C19.2 7.59596 18.396 8.39996 17.4 8.39996Z', + fill: 'currentColor' + }) + ] + ) + ]) + } + }, + 'app-user-stars': { + iconReader: () => { + return h('i', [ + h( + 'svg', + { + style: { height: '100%', width: '100%' }, + viewBox: '0 0 24 24', + version: '1.1', + xmlns: 'http://www.w3.org/2000/svg' + }, + [ + h('path', { + d: 'M12 23C18.0751 23 23 18.0751 23 12C23 5.92484 18.0751 0.999969 12 0.999969C5.92487 0.999969 1 5.92484 1 12C1 18.0751 5.92487 23 12 23ZM8.5 10.5C7.67157 10.5 7 9.8284 7 8.99997C7 8.17154 7.67157 7.49997 8.5 7.49997C9.32843 7.49997 10 8.17154 10 8.99997C10 9.8284 9.32843 10.5 8.5 10.5ZM17 8.99997C17 9.8284 16.3284 10.5 15.5 10.5C14.6716 10.5 14 9.8284 14 8.99997C14 8.17154 14.6716 7.49997 15.5 7.49997C16.3284 7.49997 17 8.17154 17 8.99997ZM16.9779 13.4994C16.7521 16.0264 14.8169 18 12 18C9.18312 18 7.24789 16.0264 7.02213 13.4994C6.99756 13.2244 7.22386 13 7.5 13H16.5C16.7761 13 17.0024 13.2244 16.9779 13.4994Z', + fill: 'currentColor' + }) + ] + ) + ]) + } } } diff --git a/ui/src/styles/app.scss b/ui/src/styles/app.scss index b47dd0ff8..0d49981d9 100644 --- a/ui/src/styles/app.scss +++ b/ui/src/styles/app.scss @@ -105,6 +105,9 @@ h4 { .h-full { height: 100%; } +.w-120 { + width: 120px; +} .w-240 { width: 240px; } @@ -206,6 +209,10 @@ h4 { align-items: center; } +.align-baseline { + align-items: baseline; +} + .text-left { text-align: left; } @@ -424,9 +431,13 @@ h4 { color: var(--el-color-info); } +.color-secondary { + color: var(--app-text-color-secondary); +} + .app-warning-icon { font-size: 16px; - color: #646a73; + color: var(--app-text-color-secondary); } .dotting { diff --git a/ui/src/utils/time.ts b/ui/src/utils/time.ts index 1a0ebc18a..82cd16211 100644 --- a/ui/src/utils/time.ts +++ b/ui/src/utils/time.ts @@ -1,3 +1,13 @@ +import moment from 'moment' + +// 当天日期 YYYY-MM-DD +export const nowDate = moment().format('YYYY-MM-DD') + +// 当前时间的前n天 +export function beforeDay(n) { + return moment().subtract(n, 'days').format('YYYY-MM-DD') +} + const getCheckDate = (timestamp: any) => { if (!timestamp) return false const dt = new Date(timestamp) diff --git a/ui/src/utils/utils.ts b/ui/src/utils/utils.ts index 551c88400..062d6c625 100644 --- a/ui/src/utils/utils.ts +++ b/ui/src/utils/utils.ts @@ -64,3 +64,15 @@ export function isAllPropertiesEmpty(obj: object) { value === null || typeof value === 'undefined' || (typeof value === 'string' && !value) ) } + +// 数组对象中某一属性值的集合 +export function getAttrsArray(array, attr) { + return array.map((item) => { + return item[attr] + }) +} + +// 求和 +export function getSum(array) { + return array.reduce((totol, item) => totol + item, 0) +} diff --git a/ui/src/views/applicaiton-overview/component/StatisticsCharts.vue b/ui/src/views/applicaiton-overview/component/StatisticsCharts.vue new file mode 100644 index 000000000..e0fd889d7 --- /dev/null +++ b/ui/src/views/applicaiton-overview/component/StatisticsCharts.vue @@ -0,0 +1,161 @@ + + + diff --git a/ui/src/views/applicaiton-overview/index.vue b/ui/src/views/applicaiton-overview/index.vue index dba1cce5e..9e000a857 100644 --- a/ui/src/views/applicaiton-overview/index.vue +++ b/ui/src/views/applicaiton-overview/index.vue @@ -1,78 +1,104 @@