Skip to content

Commit 14ac440

Browse files
committed
refactor: clean feature page warnings
1 parent dec3a96 commit 14ac440

24 files changed

Lines changed: 505 additions & 402 deletions

File tree

src/components/Designable/src/common/Container/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const Container: ReactFC = observer((props) => {
77
return <DroppableWidget>{props.children}</DroppableWidget>;
88
});
99

10-
export const withContainer = (Target: React.JSXElementConstructor<any>) => {
11-
return (props: any) => {
10+
export const withContainer = <P extends object>(Target: React.JSXElementConstructor<P>) => {
11+
return (props: P) => {
1212
return (
1313
<DroppableWidget>
1414
<Target {...props} />

src/components/Designable/src/components/Field/preview.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ const NeedShownExpression = {
3939
'x-value': true,
4040
};
4141

42-
const isExpression = (val: any) => isStr(val) && /^\{\{.*\}\}$/.test(val);
42+
const isExpression = (val: unknown) => isStr(val) && /^\{\{.*\}\}$/.test(val);
4343

44-
const filterExpression = (val: any) => {
44+
const filterExpression = (val: unknown): unknown => {
4545
if (typeof val === 'object') {
4646
const isArray = isArr(val);
4747
const results = reduce(
4848
val,
49-
(buf: any, value, key) => {
49+
(buf: Record<string, unknown> | unknown[], value, key) => {
5050
if (isExpression(value)) {
5151
return buf;
5252
} else {
@@ -69,8 +69,13 @@ const filterExpression = (val: any) => {
6969
return val;
7070
};
7171

72-
const toDesignableFieldProps = (schema: ISchema, components: any, nodeIdAttrName: string, id: string) => {
73-
const results: any = {};
72+
const toDesignableFieldProps = (
73+
schema: ISchema,
74+
components: Record<string, unknown>,
75+
nodeIdAttrName: string,
76+
id: string,
77+
) => {
78+
const results: Record<string, unknown> = {};
7479
each(SchemaStateMap, (fieldKey, schemaKey) => {
7580
const value = schema[schemaKey];
7681
if (isExpression(value)) {
@@ -98,9 +103,9 @@ const toDesignableFieldProps = (schema: ISchema, components: any, nodeIdAttrName
98103
results.component = [component, toJS(componentProps)];
99104
}
100105
if (decorator) {
101-
FormPath.setIn(results['decorator'][1], nodeIdAttrName, id);
106+
FormPath.setIn((results.decorator as [unknown, Record<string, unknown>])[1], nodeIdAttrName, id);
102107
} else if (component) {
103-
FormPath.setIn(results['component'][1], nodeIdAttrName, id);
108+
FormPath.setIn((results.component as [unknown, Record<string, unknown>])[1], nodeIdAttrName, id);
104109
}
105110
results.title = results.title && <span data-content-editable="title">{results.title}</span>;
106111
results.description = results.description && <span data-content-editable="description">{results.description}</span>;

src/components/Designable/src/components/Form/preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Form as FormilyForm } from '@formily/antd-v5';
22
import { createForm } from '@formily/core';
3-
import { observer } from '@formily/react';
3+
import { ISchema, observer } from '@formily/react';
44
import { createBehavior, createResource } from '@pind/designable-core';
55
import { DnFC, usePrefix } from '@pind/designable-react';
66
import React, { useMemo } from 'react';
@@ -36,7 +36,7 @@ Form.Behavior = createBehavior({
3636
propsSchema: {
3737
type: 'object',
3838
properties: {
39-
...(AllSchemas.FormLayout.properties as any),
39+
...((AllSchemas.FormLayout.properties || {}) as unknown as Record<string, ISchema>),
4040
style: AllSchemas.CSSStyle,
4141
},
4242
},

src/components/Designable/src/schemas/Form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FormLayout } from './FormLayout';
55
export const Form: ISchema = {
66
type: 'object',
77
properties: {
8-
...(FormLayout.properties as any),
8+
...((FormLayout.properties || {}) as unknown as Record<string, ISchema>),
99
style: CSSStyle,
1010
},
1111
};

src/components/Designable/src/schemas/Password.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Input } from './Input';
33
export const Password: ISchema = {
44
type: 'object',
55
properties: {
6-
...(Input.properties as any),
6+
...((Input.properties || {}) as unknown as Record<string, ISchema>),
77
checkStrength: {
88
type: 'boolean',
99
'x-decorator': 'FormItem',

src/components/Designable/src/shared.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Engine, TreeNode } from '@pind/designable-core';
22

3-
export type ComponentNameMatcher = string | string[] | ((name: string, node: TreeNode, context?: any) => boolean);
3+
export type ComponentNameMatcher = string | string[] | ((name: string, node: TreeNode, context?: unknown) => boolean);
44

5-
export const matchComponent = (node: TreeNode, name: ComponentNameMatcher, context?: any) => {
5+
export const matchComponent = (node: TreeNode, name: ComponentNameMatcher, context?: unknown) => {
66
if (name === '*') return true;
77
const componentName = node?.props?.['x-component'];
88
if (typeof name === 'function') return name(componentName || '', node, context);
99
if (Array.isArray(name)) return name.includes(componentName);
1010
return componentName === name;
1111
};
1212

13-
export const matchChildComponent = (node: TreeNode, name: ComponentNameMatcher, context?: any) => {
13+
export const matchChildComponent = (node: TreeNode, name: ComponentNameMatcher, context?: unknown) => {
1414
if (name === '*') return true;
1515
const componentName = node?.props?.['x-component'];
1616
if (!componentName) return false;

src/global.less

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#cesium-container {
2+
width: 100%;
3+
height: calc(100vh - 220px);
4+
min-height: 560px;
5+
}
6+
7+
#cesium-container .cesium-widget,
8+
#cesium-container .cesium-widget canvas {
9+
width: 100%;
10+
height: 100%;
11+
}
12+
13+
@media (max-width: 768px) {
14+
#cesium-container {
15+
height: calc(100vh - 260px);
16+
min-height: 420px;
17+
}
18+
}

src/pages/Feature/AudioFeature/AudioPlayer/index.tsx

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ProCard } from '@ant-design/pro-components';
2-
import { useMount } from 'ahooks';
2+
import { useEffect } from 'react';
33
import Player from 'xgplayer';
44
import MusicPreset, { Analyze, Lyric } from 'xgplayer-music';
55
import 'xgplayer-music/dist/index.min.css';
@@ -12,30 +12,34 @@ declare global {
1212
}
1313
}
1414

15+
type PlayerWithMode = Player & {
16+
mode: number;
17+
};
18+
1519
export default function AudioPlayer() {
16-
useMount(() => {
17-
function initEvents() {
18-
let jsSelect = document.getElementById('js-select') as HTMLSelectElement;
19-
jsSelect.addEventListener('change', function (e: any) {
20-
let value = e.target.value;
21-
if (window.analyze) {
22-
window.analyze.mode = value;
23-
if (value === 'lightning') {
24-
window.analyze.options.count = 512;
25-
window.analyze.options.stroke = 4;
20+
useEffect(() => {
21+
const jsSelect = document.getElementById('js-select') as HTMLSelectElement | null;
22+
const handleSelectChange = (e: Event) => {
23+
const value = (e.target as HTMLSelectElement).value;
24+
if (window.analyze) {
25+
window.analyze.mode = value;
26+
if (value === 'lightning') {
27+
window.analyze.options.count = 512;
28+
window.analyze.options.stroke = 4;
29+
} else {
30+
if (value === 'waves') {
31+
window.analyze.options.stroke = 3;
2632
} else {
27-
if (value === 'waves') {
28-
window.analyze.options.stroke = 3;
29-
} else {
30-
window.analyze.options.stroke = 2;
31-
}
32-
window.analyze.options.count = 256;
33+
window.analyze.options.stroke = 2;
3334
}
35+
window.analyze.options.count = 256;
3436
}
35-
});
36-
}
37-
initEvents();
38-
let player = new Player({
37+
}
38+
};
39+
40+
jsSelect?.addEventListener('change', handleSelectChange);
41+
42+
const player = new Player({
3943
id: 'mse',
4044
url: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/music/audio.mp3', //[{ src: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/music/audio.mp3', name: '林宥嘉·脆弱一分钟', poster: '//sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/music/poster-small.jpeg' }],
4145
volume: 0.8,
@@ -55,34 +59,32 @@ export default function AudioPlayer() {
5559
},
5660
});
5761
player.crossOrigin = 'anonymous';
58-
let lyricTxts = `[00:00.00] 脆弱一分钟\n[00:00.00] 作曲 : 林家谦\n[00:00.00] 作词 : 徐世珍/吴辉福\n[00:00.000]编曲:林家谦\n[00:00.000]时钟不要走\n[00:04.220]让我脆弱一分钟\n[00:07.440]要多久才能习惯被放手\n[00:15.800]马克杯空了 暖暖的温热\n[00:22.660]却还在我手中停留\n[00:27.960]\n[00:29.790]勇气不要走\n[00:32.200]给我理由再冲动\n[00:35.690]去相信爱情 就算还在痛\n[00:43.960]如果我不说不会有人懂\n[00:50.720]失去你我有多寂寞\n[00:55.610]还是愿意\n[00:57.580]付出一切仅仅为了一个好梦\n[01:03.980]梦里有人真心爱我 陪我快乐也陪我沉默\n[01:11.260]没有无缘无故的痛承受越多越成熟\n[01:18.630]能让你拥抱更好的我\n[01:25.030] 谁也不要走\n[01:28.270]应该是一种奢求\n[01:31.900]可是我只想 握紧你的手\n[01:39.780]我宁愿等候 也不愿错过\n[01:46.630]你对我微笑的时候\n[01:56.780]\n[02:18.910]还是愿意\n[02:21.320]用尽全力仅仅为了一个以后\n[02:27.870]哪怕生命并不温柔哪怕被幸福一再反驳\n[02:34.870]也要相信伤痕累累 其实只是在琢磨\n[02:42.070]能让你为之一亮 的我\n[02:53.910]\n[02:56.350]制作人:林宥嘉\n[02:57.750]制作助理:张婕汝\n[02:59.010]录音师:陈文骏、叶育轩\n[03:00.410]录音室:白金录音室\n[03:01.740]混音师:SimonLi @ nOiz\n[03:03.000]OP: Terence Lam Production & Co. (Warner/Chappell Music, HK Ltd.)\n[03:04.050]SP: Warner/Chappell Music Taiwan Ltd.\n[03:04.910]OP:Universal Ms Publ Ltd Taiwan\n`;
62+
const lyricTxts = `[00:00.00] 脆弱一分钟\n[00:00.00] 作曲 : 林家谦\n[00:00.00] 作词 : 徐世珍/吴辉福\n[00:00.000]编曲:林家谦\n[00:00.000]时钟不要走\n[00:04.220]让我脆弱一分钟\n[00:07.440]要多久才能习惯被放手\n[00:15.800]马克杯空了 暖暖的温热\n[00:22.660]却还在我手中停留\n[00:27.960]\n[00:29.790]勇气不要走\n[00:32.200]给我理由再冲动\n[00:35.690]去相信爱情 就算还在痛\n[00:43.960]如果我不说不会有人懂\n[00:50.720]失去你我有多寂寞\n[00:55.610]还是愿意\n[00:57.580]付出一切仅仅为了一个好梦\n[01:03.980]梦里有人真心爱我 陪我快乐也陪我沉默\n[01:11.260]没有无缘无故的痛承受越多越成熟\n[01:18.630]能让你拥抱更好的我\n[01:25.030] 谁也不要走\n[01:28.270]应该是一种奢求\n[01:31.900]可是我只想 握紧你的手\n[01:39.780]我宁愿等候 也不愿错过\n[01:46.630]你对我微笑的时候\n[01:56.780]\n[02:18.910]还是愿意\n[02:21.320]用尽全力仅仅为了一个以后\n[02:27.870]哪怕生命并不温柔哪怕被幸福一再反驳\n[02:34.870]也要相信伤痕累累 其实只是在琢磨\n[02:42.070]能让你为之一亮 的我\n[02:53.910]\n[02:56.350]制作人:林宥嘉\n[02:57.750]制作助理:张婕汝\n[02:59.010]录音师:陈文骏、叶育轩\n[03:00.410]录音室:白金录音室\n[03:01.740]混音师:SimonLi @ nOiz\n[03:03.000]OP: Terence Lam Production & Co. (Warner/Chappell Music, HK Ltd.)\n[03:04.050]SP: Warner/Chappell Music Taiwan Ltd.\n[03:04.910]OP:Universal Ms Publ Ltd Taiwan\n`;
5963

6064
// 初始化频谱
61-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
62-
let analyze = new Analyze(player, document.querySelector('canvas') as HTMLElement, {
65+
const analyze = new Analyze(player, document.querySelector('canvas') as HTMLElement, {
6366
bgColor: 'rgba(0,0,0,0.7)',
6467
stroke: 3,
6568
});
69+
window.analyze = analyze;
6670

6771
// 初始化歌词模块
68-
let lyric = new Lyric([lyricTxts], document.querySelector('#gc'));
72+
const lyric = new Lyric([lyricTxts], document.querySelector('#gc'));
6973
lyric.bind(player);
70-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
71-
let nullText = 0;
72-
player.on('lyricUpdate', (res) => {
73-
if (res.lyric === '\n') {
74-
nullText++;
75-
}
76-
});
77-
7874
player.on('playing', function () {
7975
lyric.show();
80-
(player as any).mode = 2;
76+
(player as PlayerWithMode).mode = 2;
8177
});
8278
let canvasDom = document.getElementById('canvas') as HTMLCanvasElement;
8379
canvasDom.width = window.innerWidth;
8480
canvasDom.height = window.innerHeight * 0.25;
85-
});
81+
82+
return () => {
83+
jsSelect?.removeEventListener('change', handleSelectChange);
84+
window.analyze = undefined;
85+
player.destroy();
86+
};
87+
}, []);
8688

8789
return (
8890
<AudioPlayerStyles>

src/pages/Feature/AudioFeature/AudioVisible/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { ProCard } from '@ant-design/pro-components';
22
import { Button } from 'antd';
33
import { useCallback, useEffect, useRef, useState } from 'react';
4-
import WaveSurfer from 'wavesurfer.js';
4+
import WaveSurfer, { type WaveSurferOptions } from 'wavesurfer.js';
55
import Timeline from 'wavesurfer.js/plugins/timeline';
66

77
import { AudioVisibleStyles } from './AudioVisible.style';
88

99
// WaveSurfer hook
10-
const useWavesurfer = (containerRef: React.RefObject<HTMLDivElement>, options: any) => {
10+
type WaveSurferPlayerProps = Omit<WaveSurferOptions, 'container'>;
11+
12+
const useWavesurfer = (containerRef: React.RefObject<HTMLDivElement>, options: WaveSurferPlayerProps) => {
1113
const [wavesurfer, setWavesurfer] = useState<WaveSurfer | null>(null);
1214

1315
// Initialize wavesurfer when the container mounts
@@ -25,14 +27,14 @@ const useWavesurfer = (containerRef: React.RefObject<HTMLDivElement>, options: a
2527
return () => {
2628
ws.destroy();
2729
};
28-
}, []); // eslint-disable-line react-hooks/exhaustive-deps
30+
}, [containerRef, options.url]);
2931

3032
return wavesurfer;
3133
};
3234

3335
// Create a React component that will render wavesurfer.
3436
// Props are wavesurfer options.
35-
const WaveSurferPlayer = (props: any) => {
37+
const WaveSurferPlayer = (props: WaveSurferPlayerProps) => {
3638
const containerRef = useRef<HTMLDivElement>(null);
3739
const [isPlaying, setIsPlaying] = useState(false);
3840
const [currentTime, setCurrentTime] = useState(0);
@@ -83,8 +85,7 @@ export default function AudioVisible() {
8385

8486
// Swap the audio URL
8587
const onUrlChange = useCallback(() => {
86-
urls.reverse();
87-
setAudioUrl(urls[0]);
88+
setAudioUrl((currentUrl) => (currentUrl === urls[0] ? urls[1] : urls[0]));
8889
}, []);
8990

9091
return (

0 commit comments

Comments
 (0)