July 10th report
关闭浏览器安全策略
mac
新建一个 ChromeDevUserData 文件夹,
再打开终端输入以下命令。
open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/v_lixiaofei04/Documents/MyChromeDevUserData
即可打开关闭安全策略后的窗口
windows
同样是新建 ChromeDevUserData 文件夹,
然后桌面复制一个 chrome 快捷方式 ,打开属性 ---> 快捷方式
在后面追加
--user-data-dir="D:\ChromeDevUserData" --test-type --disable-web-security
点保存,然后点这个快捷方式启动chrome,就是关闭安全策略后的窗口。
关闭安全策略的作用:
这也是支持跨域的一种方式。
参考资料: https://www.cnblogs.com/cmyoung/p/13355388.html
event.srcElement
event.srcElement.tagName 获得的是当前作用对象的大写标签名称 , 如 'DIV' 、'A';
利用 event.srcElement 获取子对象:
第一个子标签:event.srcElement.firstChild;
最后一个:event.srcElement.lastChild;
第几个子对象: event.srcElement.children[i];
所有子对象:event.srcElement.children;
所有子对象节点:event.srcElement.childNodes;
event.target 它永远都是直接接收事件的dom元素。
获取这个对象的id:
let targetId = event.target ? event.target : event.srcElement ;
antd Transfer
onSelectChange 函数包含两个参数
const onSelectChange = (sourceSelectedKeys: string[], targetSelectedKeys: string[]) => {
const saveKeys = {
0: sourceSelectedKeys,
1: targetSelectedKeys,
};
}
const onChange = (nextTargetKeys: string[], direction: string, moveKeys: string[]) => {
setTargetKeys(nextTargetKeys);
const chooseDirection = direction === Direction.right ? 1 : 0;
const params: SendParams = {
categoryIdList: moveKeys,
categoryState: chooseDirection,
};
changeVerticalStatus(params);
};
map async 形式
const result = arr.map(async item => {
const res = await getApiFunc();
return res
});
const renderGoButton = () => ({goButton: <div className={styles.goPage}>GO</div>});
classnames 插件 : 非对象形式,满足条件的class
<ClockCircleOutlined
className={cn(styles['timer'], showDate && styles['plus-icon'])}
onClick={dateClick}
/>
form.validateFields()
.then(values => {
if (values) {
console.log('values', values);
}
})
.catch(err => console.err(err));
设置 :global 属性,要在当前组件的class下
设置 :global 属性,要在当前组件的class下, 不然会影响其他组件。
antd 自定义校验
rules: [
{
validator: (rule, value) => {
if (value === undefined || value === '') {
return Promise.resolve();
}
const result = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@? ^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/.test(value);
if (result) {
return Promise.resolve();
}
return Promise.reject('请输入正确的服务地址');
}
}
]
moment 时间时期格式化
可以格式化 new Date() 、 moment 对象, 后端传过来的字符串对象
moment(date).format('YYYY-MM-DD HH:mm:ss')
直系span
// 只会作用于自己的子元素 span , 不会影响 例如 span 下 div 的 icon 组件的 span 。
>span:nth-child(1) {}
直接操作 dom 更改 antd message 的值
const countDown = () => {
setTimeout(() => {
const newText = numsRef.current.innerText[1] - 1;
numsRef.current.innerText = `(${newText})s`;
if (newText <= 0) {
return;
}
countDown();
}, 1000);
};
const commonMessage = (key: keyof MessageInstance, text: string, status: MessageType, dur: number) => {
return message[`${key}`]({
content: renderMessage(text, status),
duration: dur,
key: MES,
className: cn(styles.message),
});
};
commonMessage('success', ele.name, params.status, 5);
commonMessage('warning', '输入内容不合法!', undefined, 5);
const numsRef: MutableRefObject<any> = useRef(null);
const renderMessage = (name: string, status: string | number | undefined) => {
return (
<div style={
{
display: 'flex',
justifyContent: 'space-between',
height: '100%',
}}
>
<div style={{lineHeight: '32px'}}>
{
status
? `“${name}”审核已${EXAIMNETEXT[status as ExamineType]}`
: name
}
</div>
<div style={{marginRight: '15px', display: 'flex', alignItems: 'center'}}>
<p style={{margin: '0px', marginRight: '10px'}} ref={numsRef}>({count})s</p>
<CloseOutlined onClick={() => message.destroy()} style={{color: '#84868b', cursor: 'pointer'}} />
</div>
</div>
);
};
forwardRef 使用
const CreateHot = (props: PropsCreateHot, ref: ForwardedRef<Mutable>) => {
useImperativeHandle(ref, () => {
return {getFormValue, resetForm};
});
return <div>
...
..
</div>
};
export default forwardRef<Mutable, PropsCreateHot>(CreateHot);
const hotRef: MutableRefObject<any> = useRef(null);
<CreateHot ref={hotRef} />
const submitForm = () => {
hotRef.current.getFormValue();
};
react svg图标 icon 组件用法
import History from './history.svg?react';
import WaitExamine from './waitexamine.svg?react';
export const historyIcon = () => {
return <History className="anticon" />;
};
export const waitExamineIcon = () => {
return <WaitExamine className="anticon" />;
};
const renderTitleExtra = () => (
<div
key={1}
className={styles.history}
onClick={() => {
setVisible(true);
}}
>
{historyIcon()}
<span style={{marginLeft: 5}}>history</span>
</div>
);
const route = [
{
path: '/companyPortrait',
name: 'companyPortrait',
exact: true,
component: lazy(() => import('@/page/Home/List')),
title: '首页',
icon: UserPortraitIcon,
auth: [authKeys.CUSTOMER_VIEW.CUSTOMER_VIEW],
},
]
import {renderRoutes} from 'react-router-config';
<Router history={history}>
{renderRoutes(routes)}
</Router>