-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
秦丹一项目提交 #3
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "feat/\u79E6\u4E39\u4E00"
秦丹一项目提交 #3
Conversation
<div id="root"></div> | ||
</body> | ||
|
||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
height: 100%; | ||
min-height: 100vh; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码格式化一下
return ( | ||
<div className={styles.App}> | ||
<Menu /> | ||
{/* <Route path={`/home`} component={Home} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有用到的代码,可以删掉
margin-left: -1px; | ||
margin-top: -1px; | ||
cursor: pointer; | ||
// padding: 20px 12px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理,注释的代码如无必要不要提交
export default function ComplexSelect() { | ||
|
||
const { selectedList, setSelectedList, | ||
overallData, setOverallData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码格式化一下
收到
发自我的iPhone
…------------------ 原始邮件 ------------------
发件人: Zihang Zhang ***@***.***>
发送时间: 2021年10月15日 16:08
收件人: dt-fe/dt-fe-training ***@***.***>
抄送: asterism-q ***@***.***>, Author ***@***.***>
主题: 回复:[dt-fe/dt-fe-training] 秦丹一项目提交 (#3)
@Hungrated commented on this pull request.
In 秦丹一/data-analysis/src/components/ComplexSelect/index.tsx:
> @@ -0,0 +1,64 @@ +import React, { useState, useContext } from 'react' +// import { getOverall } from '../../service'; +import styles from './index.module.scss'; +import up from '../../images/up.svg' +import down from '../../images/down.svg' +import { percentFormat, numberFormat, handleSelect } from '../../utils' +import { OverallContext } from '../../pages/Home/index' + + +export default function ComplexSelect() { + + const { selectedList, setSelectedList, + overallData, setOverallData
代码格式化一下
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
import { OverallContext } from '../../pages/Home/index' | ||
|
||
|
||
export default function ComplexSelect() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般来说,组件声明应规范化,比如加上强类型
const Component: React.FC<Props> = React.memo((props: Props) => {
return xxx;
})
return ( | ||
<div className={`${styles.selection} ${overallData.length === 0 ? '' : styles.loading_hidden}`}> | ||
{ | ||
overallData.map((item) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意代码健壮性,如
(overallData || []).map
return ( | ||
<div className={styles.datebar}> | ||
<RangePicker | ||
format='YYYY-MM-DD' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'YYYY-MM-DD' 等常量,可以统一写到一个文件中供复用
bordered={false} | ||
allowClear={false} | ||
inputReadOnly={true} | ||
suffixIcon={<span></span>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果是空标签,这一行可以删掉
|
||
useEffect(() => { | ||
getCategoryData(time).then(res => { | ||
setCategoryData(res.data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res?.data
|
||
function choosePage(page: number) { | ||
setPageFlag(page) | ||
console.log(page); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
企业实践中,console 调用一般禁止提交
}, [freshCount, time]) | ||
|
||
|
||
function handleChangePage(move: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议组件内统一用箭头函数,语法更简单
<span>操作</span> | ||
</div> | ||
{ | ||
categoryData.slice(pageFlag * 10, pageFlag * 10 + maxOfpage - 1).map((item, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageFlag * 10 及 pageFlag * 10 + maxOfpage - 1 等,建议在组件头部声明语义化的变量
slice 的结果也可以语义化声明出来,增加代码可读性
<span className={styles.order}> | ||
{ | ||
{ | ||
0: ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接写label即可,不需要这样的封装,增加了缩进和代码复杂度
onClick={handleChangePage.bind(null, 1)} | ||
> | ||
下一页 | ||
<img src={require('../../images/nextpage.svg').default} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果确实需要requie,应统一声明在文件头部
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是否可以 import ?
const [searchKey, setSearchKey] = useState('') | ||
|
||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于业务逻辑,必要的地方加上注释增加代码可读性
}, [selectedGoodsList]) | ||
|
||
useEffect(() => { | ||
if (!renderList.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数组判空,使用 lodash
_.isEmpty(renderList)
useEffect(() => { | ||
if (!renderList.length) { | ||
let lenghthSum = 0 | ||
for (const item of selectedGoodsList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数组迭代逻辑一般无需使用 for 循环。
推荐使用 ES6 的 Array.prototype.map 和 Array.prototype.reduce;其他API也可以了解下,如 filter some every forEach等 都比较常用
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/map
function handleDeleteInput(event: any) { | ||
const { keyCode } = event | ||
//判断按下的是不是删除 | ||
if (keyCode !== 8) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if 语句,最好给每个条件后用花括号包裹,否则可能导致逻辑错误
const { keyCode } = event | ||
//判断按下的是不是删除 | ||
if (keyCode !== 8) return | ||
selectedGoodsList.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pop 方法会改变 selectedGoodsList 本身,不符合 React 数据流中的 immutable 原则;
这里可以直接根据需求在下一行 slice(0, _.size(selectedGoodsList)-1) 去掉最后一个,或 slice(1) 去掉第一个
function searchInput(e: any) { | ||
if (e.keyCode !== 13) return | ||
setSearchKey(e.target.value) | ||
console.log(e.target.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,这种代码不要提交
}) | ||
} | ||
{ | ||
renderList.length === selectedGoodsList.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数组长度用 _.size
export default function SideMenu() { | ||
const [selectedKey, setSelectedKey] = useState(sideMenuList[0].key) | ||
window.addEventListener('scroll', () => { | ||
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
取 scrollTop 可以抽象成一个通用方法
} | ||
|
||
export async function getName() { | ||
const url = `http://120.26.194.171:3000/v1/trade/overall`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const baseUrl = 'http://120.26.194.171:3000/v1';
No description provided.