Commit 3af50164 authored by Alan 张加强's avatar Alan 张加强

update

parent d3ed529c
/*
* @Author: your name
* @Date: 2020-06-19 16:41:51
* @LastEditTime: 2020-06-19 16:42:20
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \dva-jingzi-game\src\component\box.js
*/
import styled from 'styled-components'; import styled from 'styled-components';
import WinImg from './winImg'; import WinImg from './winImg';
const Box = styled.div ` const Box = styled.div `
...@@ -14,49 +22,56 @@ const Box = styled.div ` ...@@ -14,49 +22,56 @@ const Box = styled.div `
` `
function BoxMaster(props) { function BoxMaster(props) {
const handelClick = (value) => { const handelClick = (value) => {
// 判断游戏是否有胜利者 // 判断游戏是否有胜利者
if (props.winner) return if (props.winner) return
// 判断是否重复点击 // 判断是否重复点击
if (!reClick(value)) { if (!reClick(value)) {
// 更新整体 // 更新整体
props.dispatch({ props.dispatch({
type: 'main/updateObjFn', type: 'main/updateObjFn',
id: value.value, id: value.value,
flag: value.nowFliage, flag: value.nowFliage,
}) })
// 保存每一步操作 // 保存每一步操作
props.dispatch({ console.log("11");
type: 'main/saveActionFn',
id: value.value, props.dispatch({
flag: value.nowFliage, type: 'main/saveActionFn',
}) id: value.value,
flag: value.nowFliage,
})
}
} }
}
// 是否重复点击 // 是否重复点击
function reClick(value) { function reClick(value) {
let tempObj = value.datasource.find((item, index) => { let tempObj = value.datasource.find((item, index) => {
return item.value === value.value return item.value === value.value
}) })
if (tempObj && tempObj.flag) { if (tempObj && tempObj.flag) {
return true return true
} else { } else {
return false return false
}
} }
}
return ( return ( <
<Box onClick={ () => handelClick(props)} style={{background:props.winner && props.value === props.winner.value ?"":props.color}}> Box onClick = {
{ () => handelClick(props)
props.winner && props.value === props.winner.value ? ( }
<WinImg flag={props.flag} /> style = {
) : (<span>{props.flag}</span>) { background: props.winner && props.value === props.winner.value ? "" : props.color }
} > {
props.winner && props.value === props.winner.value ? ( <
WinImg flag = { props.flag }
/>
) : ( < span > { props.flag } < /span>)
} } <
</Box> /Box>
) )
} }
export default BoxMaster export default BoxMaster
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment