1.实现短信登录
This commit is contained in:
parent
b98c1b9ed8
commit
1030f285dc
@ -33,10 +33,12 @@ const theme = createTheme({
|
|||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const dispatch = useDispatch();
|
||||||
const [cookies, setCookie] = useCookies(['accessToken']);
|
const [cookies, setCookie] = useCookies(['accessToken']);
|
||||||
const [value, setValue] = useState("1");
|
const [value, setValue] = useState("1");
|
||||||
const account = useSelector(state => state.user.account)
|
const account = useSelector(state => state.user.account)
|
||||||
const password = useSelector(state => state.user.password)
|
const password = useSelector(state => state.user.password)
|
||||||
|
const verificationCode = useSelector(state => state.user.verificationCode)
|
||||||
|
|
||||||
const handleChange = (event, newValue) => {
|
const handleChange = (event, newValue) => {
|
||||||
setValue(newValue);
|
setValue(newValue);
|
||||||
@ -46,19 +48,20 @@ export default function () {
|
|||||||
const flushToken = useSelector(state => state.user.flushToken)
|
const flushToken = useSelector(state => state.user.flushToken)
|
||||||
const udid = useSelector(state => state.user.udid)
|
const udid = useSelector(state => state.user.udid)
|
||||||
|
|
||||||
|
|
||||||
const dispatch = useDispatch()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const debug_test = () => {
|
const debug_test = () => {
|
||||||
console.log("accessToken", accessToken);
|
console.log("accessToken", accessToken);
|
||||||
}
|
}
|
||||||
const handleSubmit = (event) => {
|
const handleSubmit = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(`account: ${account}\nPassword: ${password} udid: ${udid}`);
|
console.log(`account: ${account}\nPassword: ${password} udid: ${udid}`, value);
|
||||||
|
|
||||||
yzs.login(udid, account, password).then(token => {
|
let result = null;
|
||||||
|
if (value === "1") {
|
||||||
|
result = yzs.dynamic_code_login(udid, account, verificationCode);
|
||||||
|
} else if (value === "2") {
|
||||||
|
result = yzs.login(udid, account, password);
|
||||||
|
}
|
||||||
|
result.then(token => {
|
||||||
dispatch(setFlushToken(token));
|
dispatch(setFlushToken(token));
|
||||||
yzs.get_access_token(udid, token).then(token => {
|
yzs.get_access_token(udid, token).then(token => {
|
||||||
// yzs.update_access_token(ip.payload, token);
|
// yzs.update_access_token(ip.payload, token);
|
||||||
@ -73,8 +76,6 @@ export default function () {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -102,9 +103,7 @@ export default function () {
|
|||||||
>
|
>
|
||||||
<TabContext value={value}>
|
<TabContext value={value}>
|
||||||
<Box>
|
<Box>
|
||||||
|
|
||||||
<TabList
|
<TabList
|
||||||
|
|
||||||
aria-label="basic tabs example" value={value} onChange={handleChange} >
|
aria-label="basic tabs example" value={value} onChange={handleChange} >
|
||||||
<Tab label="手机动态码登录" value="1" />
|
<Tab label="手机动态码登录" value="1" />
|
||||||
<Tab label="账号密码登录" value="2" />
|
<Tab label="账号密码登录" value="2" />
|
||||||
@ -112,7 +111,7 @@ export default function () {
|
|||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<TabPanel value="1" >
|
<TabPanel value="1" >
|
||||||
<DynamicCodeForm />
|
<DynamicCodeForm udid={udid} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value="2" >
|
<TabPanel value="2" >
|
||||||
<PasswordForm />
|
<PasswordForm />
|
||||||
|
@ -61,6 +61,10 @@ export default function ({ currentTime }) {
|
|||||||
player.current.currentTime = second;
|
player.current.currentTime = second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onChange = (event) => {
|
||||||
|
player.current.playbackRate = event.target.value;
|
||||||
|
};
|
||||||
|
|
||||||
return <Stack sx={{
|
return <Stack sx={{
|
||||||
position: "sticky",
|
position: "sticky",
|
||||||
top: 48,
|
top: 48,
|
||||||
@ -82,13 +86,14 @@ export default function ({ currentTime }) {
|
|||||||
<img src={pause ? pauseIcon : playIcon} />
|
<img src={pause ? pauseIcon : playIcon} />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<audio autoPlay ref={player} src={currentBlob} onDurationChange={onDurationChange} onTimeUpdate={onTimeUpdate} />
|
<audio ref={player} src={currentBlob} onDurationChange={onDurationChange} onTimeUpdate={onTimeUpdate} />
|
||||||
<ProgressBar width={isNaN(canvasWidth) ? 0 : canvasWidth} duration={Math.ceil(duration * 1000)}
|
<ProgressBar width={isNaN(canvasWidth) ? 0 : canvasWidth} duration={Math.ceil(duration * 1000)}
|
||||||
currentTime={currentTime} playing={!pause} seek={seekRecord}
|
currentTime={currentTime} playing={!pause} seek={seekRecord}
|
||||||
waveData={currentWaveData}
|
waveData={currentWaveData}
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
defaultValue={1.0}
|
defaultValue={1.0}
|
||||||
|
onChange={onChange}
|
||||||
sx={{
|
sx={{
|
||||||
flexGrow: 1,
|
flexGrow: 1,
|
||||||
width: 90
|
width: 90
|
||||||
|
@ -23,7 +23,7 @@ export default function () {
|
|||||||
yzs.download(accessToken, recordList.at(index).transResultUrl).then(
|
yzs.download(accessToken, recordList.at(index).transResultUrl).then(
|
||||||
blob => blob.text()
|
blob => blob.text()
|
||||||
).then(text => {
|
).then(text => {
|
||||||
console.log(text);
|
console.log("type", recordList.at(index).type, text);
|
||||||
let payload = recordList.at(index).type === 1 ? JSON.parse(text) : text;
|
let payload = recordList.at(index).type === 1 ? JSON.parse(text) : text;
|
||||||
dispatch(setCurrentLyric(payload));
|
dispatch(setCurrentLyric(payload));
|
||||||
});
|
});
|
||||||
@ -35,13 +35,11 @@ export default function () {
|
|||||||
context.decodeAudioData(arrayBuffer).then(audioBuffer => {
|
context.decodeAudioData(arrayBuffer).then(audioBuffer => {
|
||||||
let interval = audioBuffer.sampleRate / 1000 * 100;
|
let interval = audioBuffer.sampleRate / 1000 * 100;
|
||||||
let waveData = audioBuffer.getChannelData(0);
|
let waveData = audioBuffer.getChannelData(0);
|
||||||
|
|
||||||
let wave = [];
|
let wave = [];
|
||||||
let amplitude = 0;
|
let amplitude = 0;
|
||||||
for (let i = 0; i < waveData.length; i++) {
|
for (let i = 0; i < waveData.length; i++) {
|
||||||
amplitude += Math.abs(waveData[i]);
|
amplitude += Math.abs(waveData[i]);
|
||||||
if (i % interval == 0) {
|
if (i % interval == 0) {
|
||||||
console.log(amplitude / interval)
|
|
||||||
wave.push(Math.floor(amplitude * 500 / interval));
|
wave.push(Math.floor(amplitude * 500 / interval));
|
||||||
amplitude = 0;
|
amplitude = 0;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,6 @@ export default function ({ currentTime }) {
|
|||||||
return <div className={styles.lyricItem}>
|
return <div className={styles.lyricItem}>
|
||||||
<Typography align="left" color={isHighlight(currentTime, lyric) ? "red" : "black"}>{lyric.text}</Typography>
|
<Typography align="left" color={isHighlight(currentTime, lyric) ? "red" : "black"}>{lyric.text}</Typography>
|
||||||
</div>
|
</div>
|
||||||
}) : <React.Fragment />) : <div> {typeof currentLyric === "string" ? currentLyric : ""}</div>}
|
}) : <React.Fragment />) : <div style={{ whiteSpace: "pre-wrap" }}>{typeof currentLyric === "string" ? currentLyric : ""}</div>}
|
||||||
</Paper>
|
</Paper>
|
||||||
}
|
}
|
@ -170,7 +170,7 @@ const yzs = {
|
|||||||
let body = {};
|
let body = {};
|
||||||
body.subsystemId = 16;
|
body.subsystemId = 16;
|
||||||
body.clientId = udid;
|
body.clientId = udid;
|
||||||
body.timestamp = parseInt(new Date().getTime() / 1000);
|
body.timestamp = Math.round(new Date().getTime() / 1000);
|
||||||
body.account = account;
|
body.account = account;
|
||||||
body.password = md5(password);
|
body.password = md5(password);
|
||||||
|
|
||||||
@ -188,6 +188,49 @@ const yzs = {
|
|||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
dynamic_code_login: function (udid, userCell, phoneCode) {
|
||||||
|
let body = {};
|
||||||
|
body.subsystemId = 16;
|
||||||
|
body.clientId = udid;
|
||||||
|
body.timestamp = Math.round(new Date().getTime() / 1000);
|
||||||
|
body.userCell = userCell;
|
||||||
|
body.phoneCode = phoneCode;
|
||||||
|
return fetch(`${accessServer}/rest/v2/phone/login`, {
|
||||||
|
method: "POST",
|
||||||
|
body: constructParameter(body),
|
||||||
|
// mode: "no-cors",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
},
|
||||||
|
}).then(response => response.json()).then((json) => {
|
||||||
|
console.log("flushToken: ", json.result.flushToken);
|
||||||
|
return json.result.flushToken;
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
send_phone_code: function (udid, userCell) {
|
||||||
|
let body = {};
|
||||||
|
body.subsystemId = 16;
|
||||||
|
body.clientId = udid;
|
||||||
|
body.timestamp = Math.round(new Date().getTime() / 1000);
|
||||||
|
body.userCell = userCell;
|
||||||
|
return fetch(`${accessServer}/rest/v2/phone/send_phone_code`, {
|
||||||
|
method: "POST",
|
||||||
|
body: constructParameter(body),
|
||||||
|
// mode: "no-cors",
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
},
|
||||||
|
}).then(response => response.json()).then((json) => {
|
||||||
|
console.log("send_phone_code: ", json);
|
||||||
|
return json;
|
||||||
|
}).catch(error => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import { Container, TextField, InputAdornment, Link, Button, Stack, Typography } from "@mui/material";
|
import { Container, TextField, InputAdornment, Link, Button, Stack, Typography } from "@mui/material";
|
||||||
import { CheckBox } from '@mui/icons-material';
|
import { CheckBox } from '@mui/icons-material';
|
||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import PhoneIphoneIcon from '@mui/icons-material/PhoneIphone';
|
import PhoneIphoneIcon from '@mui/icons-material/PhoneIphone';
|
||||||
import LockIcon from '@mui/icons-material/Lock';
|
import LockIcon from '@mui/icons-material/Lock';
|
||||||
import { useSelector, useDispatch } from 'react-redux'
|
import { useSelector, useDispatch } from 'react-redux'
|
||||||
import { setAccount, setVerificationCode } from "../business/userSlice.js"
|
import { setAccount, setVerificationCode } from "../business/userSlice.js"
|
||||||
|
import yzs from "../business/request.js";
|
||||||
|
|
||||||
export default function () {
|
export default function ({ udid }) {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
const code = useRef(null);
|
||||||
|
const [seconds, setSeconds] = useState(0); // 倒计时
|
||||||
|
|
||||||
const account = useSelector(state => state.user.account)
|
const account = useSelector(state => state.user.account)
|
||||||
const verificationCode = useSelector(state => state.user.verificationCode)
|
const verificationCode = useSelector(state => state.user.verificationCode)
|
||||||
|
|
||||||
@ -17,13 +21,32 @@ export default function () {
|
|||||||
if (name === 'password') dispatch(setVerificationCode(value));
|
if (name === 'password') dispatch(setVerificationCode(value));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = window.setInterval(() => {
|
||||||
|
if (seconds > 0) {
|
||||||
|
setSeconds(seconds - 1);
|
||||||
|
} else {
|
||||||
|
code.current.disabled = false;
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
return () => {
|
||||||
|
window.clearInterval(timer);
|
||||||
|
};
|
||||||
|
}, [seconds]);
|
||||||
|
|
||||||
|
const onClick = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
code.current.disabled = true;
|
||||||
|
yzs.send_phone_code(udid, account)
|
||||||
|
setSeconds(60);
|
||||||
|
};
|
||||||
|
|
||||||
return <Container disableGutters={true}
|
return <Container disableGutters={true}
|
||||||
sx={{
|
sx={{
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 200,
|
height: 200,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
name="username"
|
name="username"
|
||||||
label="请输入手机号码"
|
label="请输入手机号码"
|
||||||
@ -58,7 +81,9 @@ export default function () {
|
|||||||
),
|
),
|
||||||
|
|
||||||
endAdornment: <InputAdornment position="end">
|
endAdornment: <InputAdornment position="end">
|
||||||
<Link>发送动态码</Link>
|
<Link ref={code}
|
||||||
|
color={seconds > 0 ? "#FFB3B3" : "red"}
|
||||||
|
component="button" underline="none" onClick={onClick}>{seconds > 0 ? `重新发送(${seconds})` : "发送动态码"}</Link>
|
||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -106,13 +106,9 @@ export default function ({ width, duration, currentTime, playing, seek, waveData
|
|||||||
|
|
||||||
const onMouseUp = (event) => {
|
const onMouseUp = (event) => {
|
||||||
setMouseDown(false);
|
setMouseDown(false);
|
||||||
console.log("onMouseUp");
|
|
||||||
// onMouseLeave(event);
|
|
||||||
seek(scrollLeft * interval / (pointWidth + pointMargin) / 1000);
|
seek(scrollLeft * interval / (pointWidth + pointMargin) / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const onMouseMove = (event) => {
|
const onMouseMove = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (!mouseDown) return;
|
if (!mouseDown) return;
|
||||||
@ -122,8 +118,7 @@ export default function ({ width, duration, currentTime, playing, seek, waveData
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onScroll = () => {
|
const onScroll = () => {
|
||||||
setScrollLeft(container.current.scrollLeft);
|
setScrollLeft(Math.round(container.current.scrollLeft));
|
||||||
// console.log("onScroll", container.current.scrollLeft, duration);
|
|
||||||
};
|
};
|
||||||
const paintWaveform = useCallback(() => {
|
const paintWaveform = useCallback(() => {
|
||||||
paintCanvas({
|
paintCanvas({
|
||||||
@ -144,9 +139,8 @@ export default function ({ width, duration, currentTime, playing, seek, waveData
|
|||||||
}, [canvas, width, duration, scrollLeft, waveData])
|
}, [canvas, width, duration, scrollLeft, waveData])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("mouseDown", mouseDown);
|
|
||||||
if (!mouseDown)
|
if (!mouseDown)
|
||||||
container.current.scrollLeft = currentTime * 1000 / interval * (pointWidth + pointMargin);
|
container.current.scrollLeft = Math.round(currentTime * 1000 / interval * (pointWidth + pointMargin));
|
||||||
}, [currentTime]);
|
}, [currentTime]);
|
||||||
|
|
||||||
return <div ref={container}
|
return <div ref={container}
|
||||||
|
@ -37,7 +37,7 @@ module.exports = function (app) {
|
|||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
logger: console,
|
logger: console,
|
||||||
onProxyReq: (proxyReq, req, res) => {
|
onProxyReq: (proxyReq, req, res) => {
|
||||||
proxyReq.setHeader('appKey', 'k5hfiei5eevouvjohkapjaudpk2gakpaxha22fiy');
|
proxyReq.setHeader('appKey', appKey);
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user