Skip to content

Commit e8a9717

Browse files
author
Simon he
committed
chore: update
1 parent 07cc3ed commit e8a9717

File tree

6 files changed

+124
-11
lines changed

6 files changed

+124
-11
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,51 @@ import {
1919

2020
```
2121

22+
## sCharts
23+
- 简单的echarts图表封装
24+
- 不需要在onMounted中执行,可以在任意时刻使用
25+
- 参数:
26+
- container: string | HTMLElement, 图表容器
27+
- options: SChartsOption, echarts配置options,扩展了w: 初始化宽度, h: 初始化高度, theme: echarts主题, 所有的事件行为以on开头都会被调用
28+
- autoResize: boolean, 是否自动调整宽高, 根据container容器的宽高自动撑满,监听window的resize事件,自动调整宽高
29+
```javascript
30+
const charts = sCharts('#main', {
31+
w: 500,
32+
h: 300,
33+
theme: 'dark',
34+
xAxis: {
35+
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
36+
},
37+
yAxis: {},
38+
series: [
39+
{
40+
type: 'bar',
41+
data: [23, 24, 18, 25, 27, 28, 25],
42+
},
43+
],
44+
})
45+
```
46+
47+
## addEventListener
48+
- 给元素添加事件函数
49+
- 返回一个remove函数
50+
- 参数:
51+
- target: Element | string, 目标元素
52+
- eventName: string, 事件名称
53+
- callback: (e)=>void, 回调函数
54+
- capture: boolean, 是否捕获
55+
- autoRemove: boolean, 是否自动移除事件
56+
```javascript
57+
const remove = addEventListener('#btn',
58+
'click',
59+
() => {
60+
console.log('click')
61+
}
62+
)
63+
addEventListener(document,'DOMContentLoaded', () => {
64+
console.log('我就执行一次,然后事件就被自动移除了')
65+
}, false, true)
66+
```
2267
## createElement
2368
- 创建dom函数
2469
- 参数:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@
5555
"@types/node": "^17.0.38",
5656
"@types/spark-md5": "^3.0.2",
5757
"bumpp": "^7.1.1",
58+
"echarts": "^5.3.3",
5859
"eslint": "^8.16.0",
5960
"eslint-plugin-n": "^15.2.1",
6061
"express": "^4.18.1",
6162
"htmlparser2": "^8.0.1",
6263
"pkgroll": "^1.3.1",
63-
"simon-js-tool": "workspace:^2.0.20",
64+
"simon-js-tool": "workspace:^3.0.6",
6465
"spark-md5": "^3.0.2",
6566
"typescript": "^4.7.2",
6667
"vitest": "^0.14.2"

playground/src/App.vue

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
2-
import { fileSplice } from '../../src'
2+
import { fileSplice, sCharts } from '../../src'
3+
34
// import { lazyLoad } from "../../src";
45
// import { vFetch } from "../../src";
56
// const upload = ref(null)
@@ -25,12 +26,55 @@ import { fileSplice } from '../../src'
2526
// // lazyLoad(img);
2627
// // });
2728
// });
29+
// onMounted(() => {
30+
sCharts(
31+
'#main',
32+
{
33+
w: 400,
34+
h: 300,
35+
theme: 'dark',
36+
xAxis: {
37+
data: ['A', 'B', 'C', 'D', 'E'],
38+
},
39+
yAxis: {},
40+
series: [
41+
{
42+
type: 'bar',
43+
data: [
44+
10,
45+
22,
46+
28,
47+
{
48+
value: 43,
49+
// 设置单个柱子的样式
50+
itemStyle: {
51+
color: '#91cc75',
52+
shadowColor: '#91cc75',
53+
borderType: 'dashed',
54+
opacity: 0.5,
55+
},
56+
},
57+
49,
58+
],
59+
itemStyle: {
60+
barBorderRadius: 5,
61+
borderWidth: 1,
62+
borderType: 'solid',
63+
borderColor: '#73c0de',
64+
shadowColor: '#5470c6',
65+
shadowBlur: 3,
66+
},
67+
},
68+
],
69+
},
70+
true,
71+
)
72+
// });
2873
</script>
2974

3075
<template>
31-
<main font-sans p="x-4 y-10" text="center gray-700 dark:gray-200">
32-
上传:<input ref="upload" type="file" name="" value="">
33-
<router-view />
76+
<main font-sans p=" y-10" text="center gray-700 dark:gray-200">
77+
<div id="main" w-full ma inline-block />
3478
<Footer />
3579
</main>
3680
<!-- <img src="temp" data-src="../public/favicon.svg" alt="" h-10 bg-red /> -->

pnpm-lock.yaml

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ export { htmlTransform } from './htmlTransform'
9191
export { sleep } from './sleep'
9292
export { createElement } from './createElement'
9393
export { addLink } from './addLink'
94+
export { sCharts } from './sCharts'
95+
export { addEventListener } from './addEventListener'

src/sCharts.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import * as echarts from 'echarts'
2-
import type { EChartsOption, XAXisComponentOption, YAXisComponentOption } from 'echarts'
32
import { isStr } from './isStr'
43
import { addEventListener } from './addEventListener'
54

6-
interface SChartsOption extends EChartsOption {
5+
interface SChartsOption extends Record<string, any> {
76
theme?: string | object
8-
x: XAXisComponentOption | XAXisComponentOption[]
9-
y: YAXisComponentOption | YAXisComponentOption[]
7+
x: Record<string, any>
8+
y: Record<string, any>
9+
xAxis?: Record<string, any>
10+
yAxis?: Record<string, any>
1011
w?: number
1112
h?: number
13+
1214
}
1315

14-
export function sCharts(container: string | HTMLElement, options: SChartsOption, autoResize: boolean = true): echarts.ECharts {
16+
export function sCharts(container: string | HTMLElement, options: SChartsOption, autoResize = true): echarts.ECharts {
1517
const fragment = document.createDocumentFragment()
1618
const { x, y, xAxis, yAxis, w = 100, h = 100 } = options
1719

0 commit comments

Comments
 (0)