-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.html
144 lines (133 loc) · 2.68 KB
/
react.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex, nofollow">
<title>Paste from Word</title>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://cdn.bootcss.com/babel-standalone/7.0.0-beta.3/babel.js"></script>
</head>
<body>
<div id="root">
</div>
<style type="text/css">
.model-mask{
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1000;
height: 100%;
background-color: rgba(0,0,0,0.45);
}
.model{
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1000;
overflow: auto;
outline: 0;
}
.model-content{
width:400px;
height: 200px;
position: relative;
top: 200px;
background: #fff;
margin: auto;;
}
.model-confirmInfo{
font-size: 16px;
text-align: center;
color: #999;
padding: 20px;
}
.model-options{
position: absolute;
bottom: 0;
width: 100%;
text-align:center;
}
.model-options button{
margin: 15px;
}
</style>
<script type="text/babel">
function confirm(info){
function Confirm(props){
const {callback} = props
const [confirmStatus, setConfirmStatus] = React.useState(true);
function close(status){
setConfirmStatus(false)
callback(status)
}
if(confirmStatus){
return (
<div>
<div className='model-mask'></div>
<div className="model">
<div className="model-content">
<p className="model-confirmInfo">
{info}
</p>
<div className="model-options">
<button onClick={()=>close(false)}>取消</button>
<button onClick={()=>close(true)}>确定</button>
</div>
</div>
</div>
</div>
)
}else{
return null
}
}
var modle = document.createElement('div')
document.body.appendChild(modle)
return new Promise(resolve=>{
ReactDOM.render(<Confirm callback={resolve} />, modle)
})
}
class Confirm extends React.Component{
state = {
text:'确认信息'
}
async componentDidMount(){
let res = await confirm("确定删除吗")
console.log(res,123)
if(res) {
console.log("是")
this.setState({
text:'已确认'
})
} else {
console.log("否")
this.setState({
text:'已取消'
})
}
}
render(){
return (
<div>
{this.state.text}
</div>
)
}
}
class App extends React.Component{
render(){
return (
<div>
<Confirm/>
</div>
)
}
}
ReactDOM.render(<App/>, document.getElementById('root'));
</script>
</body>
</html>