Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
get validatePassed() {
// forbid gd
if (this.state.school_id === 1) {
Toast.fail('请输入正确的密码', 1)
return false
}
if (this.state.school_id === -1) {
Toast.offline('请选择你的学校噢~', 1)
return false
}
if (!this.state.account) {
Toast.offline('请输入学号噢~', 1)
return false
}
if (!this.state.password) {
Toast.offline('请输入密码噢~', 1)
return false
} = this.props.user
setToken({
uid,
token,
timestamp
})
this.props.dispatch(initApp())
try {
login(user.account, user.password, user.school_id)
Actions[SCENE_INDEX]()
} catch (e) {
console.log(e)
Toast.fail('自动登录失败', 1.5)
Actions[SCENE_LOGIN]()
}
RNSplashScreen.hide()
}
fetchHotBooks = async () => {
let params = { page: 1 }
let result
try {
result = (await HttpUtils.post(URL, params)) || {}
} catch (e) {
Toast.fail('加载失败', 1)
this.setState({ isLoading: false })
return
}
if (result.status !== 0) {
return
}
this.setState({
books: result.data,
isLoading: false
})
}
}
if (!content.trim()) {
Toast.info('请输入您的反馈内容哦~', 1)
return
}
let params = {
content,
contact
}
let response = (await HttpUtils.post(URL, params)) || {}
if (response.status !== 0) {
Toast.fail(response.msg, '1')
return
}
Toast.success('反馈成功', 1, () => {
Actions.pop()
})
}
fetchSubscribeBooks = async () => {
let result
try {
result = await HttpUtils.post(URL, {})
} catch (e) {
Toast.fail('加载失败', 1)
this.setState({ isLoading: false })
return
}
if (result.status !== 0) {
return
}
this.setState({
books: result.books,
isLoading: false
})
}
export default async function fetchData (func, success = '已加载最新数据', failed = '加载失败,请稍后重试') {
Toast.loading('正在加载', 0)
try {
await func()
} catch (e) {
Toast.fail(failed, 1)
return
}
Toast.success(success, 1)
}
fetchBooks = async (index) => {
Toast.loading('正在加载', 0)
const params = {
content: this.props.content,
type: index
}
let response = (await HttpUtils.post(URL, params)) || {}
if (response.status !== 0) {
Toast.fail(response.msg, 1)
return []
}
Toast.hide()
return response.data
}
fetchList = async () => {
const list_id = this.props.item.list_id
const params = { list_id }
const response = await HttpUtils.post(URL_SHOW, params)
if (response.status !== 0) {
Toast.fail('获取数据异常', 1)
return
}
const data = response.data
this.setState({ book_list: data })
}
return
}
const {
account,
password
} = this.state
Toast.loading('正在登陆', 0)
try {
const response = await login(account, password, this.state.school_id)
Toast.hide()
Actions[SCENE_INDEX]({ user: response.data })
} catch (e) {
Toast.fail(e.message, 1)
return
}
}