Skip to content

Commit

Permalink
Add charts (#30)
Browse files Browse the repository at this point in the history
* 优化图表页面

* 优化图标功能

* fix bug
  • Loading branch information
admin8756 committed May 6, 2024
1 parent e93259b commit a82b136
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"i18n-ally.localesPaths": ["locales"],
"cSpell.words": [
"daisyui",
"echarts",
"intlify",
"leelaa",
"nprogress",
"pinia",
"rushstack",
"tailwindcss",
"unplugin",
"vueuse"
"vueuse",
"Xdata"
],
"i18n-ally.keystyle": "nested",
"css.lint.unknownAtRules": "ignore",
Expand Down
9 changes: 3 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
</head>
<body>
<noscript>
<strong
>We're sorry but
doesn't work properly without JavaScript enabled. Please enable it to continue.</strong
>
<strong>We're sorry but doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app">
<main id="app">
<div class="loading-view">
<div class="orbit-spinner">
<div class="orbit"></div>
Expand All @@ -21,7 +18,7 @@
</div>
<span class="loading-text">Loading...</span>
</div>
</div>
</main>
<style type="text/css">
body {
margin: 0;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.6.8",
"echarts": "^5.5.0",
"nprogress": "^0.2.0",
"pinia": "^2.1.7",
"theme-change": "^2.5.0",
Expand Down
67 changes: 45 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export const request = async (url, options = {}) => {
});
};

// 聊天接口
export const chat = (text) => request(`api/ai?text=${text}`);

// 登录接口
export const login = (postData) => {
return request(`api/user`, {
method: 'POST',
Expand Down
3 changes: 3 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export {}

declare module 'vue' {
export interface GlobalComponents {
BarView: typeof import('./components/charts/BarView.vue')['default']
ChartBar: typeof import('./components/charts/ChartBar.vue')['default']
DropdownView: typeof import('./components/DropdownView.vue')['default']
LineView: typeof import('./components/charts/LineView.vue')['default']
MessageBox: typeof import('./components/MsgBox/MessageBox.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Expand Down
107 changes: 107 additions & 0 deletions src/components/charts/BarView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<template>
<div class="chart-bar" ref="chartBar" :style="style"></div>
</template>
<script setup>
import * as echarts from "echarts/core";
import { GridComponent } from "echarts/components";
import { BarChart } from "echarts/charts";
import { TitleComponent } from "echarts/components";
import { CanvasRenderer } from "echarts/renderers";
import { ref, onMounted, computed, watch } from "vue";
import { useWindowSize } from "@vueuse/core";
import { watchThrottled } from "@vueuse/core";
const chartBar = ref(null);
let myChart = "";
const props = defineProps({
// x轴数据
xData: {
type: Object,
default: () => {},
},
// 数据
yData: {
type: Object,
default: () => {},
},
// 标题
title: {
type: String,
default: "",
},
// 样式
style: {
type: Object,
default: () => {},
},
// 颜色
color: {
type: String,
default: "",
},
});
// 更新图表
const updateChart = () => {
const option = {
title: {
text: props.title,
},
xAxis: {
type: "category",
data: props.xData,
},
yAxis: {
type: "value",
},
series: [
{
data: props.yData,
type: "bar",
},
],
};
myChart.setOption(option);
};
// 组件加载
onMounted(() => {
const window = computed(() => {
const { width, height } = useWindowSize();
return width.value * height.value;
});
echarts.use([GridComponent, BarChart, CanvasRenderer, TitleComponent]);
myChart = echarts.init(chartBar.value);
updateChart();
watchThrottled(
window,
() => {
myChart.resize();
},
{ throttle: 800 }
);
});
// 监听数据发生变化
watch(
[props.xData, props.yData],
() => {
updateChart();
},
{ deep: true }
);
</script>

<style scoped>
.chart-bar {
width: 100%;
height: 100%;
min-height: 400px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 20px;
overflow: hidden;
box-sizing: border-box;
}
</style>
3 changes: 3 additions & 0 deletions src/components/charts/LineView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div class="line-view"></div>
</template>

1 comment on commit a82b136

@vercel
Copy link

@vercel vercel bot commented on a82b136 May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.