main
king 1 year ago
parent b0cf7f4496
commit ae6fd4f3ff
  1. 4
      .env
  2. 1
      src/api/user.ts
  3. 3
      src/pages/check/check.config.ts
  4. 13
      src/pages/check/check.module.scss
  5. 18
      src/pages/check/check.tsx
  6. 13
      src/pages/login/login.module.scss
  7. 139
      src/pages/login/login.tsx
  8. 11
      src/pages/manage/addStudent/addStudent.tsx
  9. 2
      src/pages/manage/depAdmin/depAdmin.tsx

@ -1,5 +1,5 @@
#TARO_APP_API=https://yjx.dev.yaojiankang.top TARO_APP_API=https://yjx.dev.yaojiankang.top
TARO_APP_API=https://playedu.yaojiankang.top #TARO_APP_API=https://playedu.yaojiankang.top
TARO_APP_LGOIN=true TARO_APP_LGOIN=true

@ -6,7 +6,6 @@ interface Code {
export interface LoginData { export interface LoginData {
access_token: string access_token: string
code?: Code
company: Company company: Company
token: string token: string
user: User user: User

@ -1,4 +1,3 @@
export default definePageConfig({ export default definePageConfig({
navigationStyle: 'custom', navigationBarTitleText: '绑定手机号'
navigationBarTitleText: '验证'
}) })

@ -1,3 +1,13 @@
.page{
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: #fff;
padding: 0 20rpx;
}
.submit { .submit {
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -17,7 +27,8 @@
} }
.image { .image {
width: 50px; width: 50rpx;
height: 50rpx;
vertical-align: top; vertical-align: top;
margin-right: 20px; margin-right: 20px;
} }

@ -1,5 +1,5 @@
import {FC, useCallback, useEffect, useRef, useState} from "react"; import {FC, useCallback, useEffect, useRef, useState} from "react";
import { Form, Image, Input, View} from "@tarojs/components"; import {Form, Image, Input, View} from "@tarojs/components";
import {Profile} from "@/store"; import {Profile} from "@/store";
import {userApi} from "@/api"; import {userApi} from "@/api";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
@ -14,8 +14,8 @@ const Bing: FC = () => {
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [codeTime, setCodeTime] = useState(0) const [codeTime, setCodeTime] = useState(0)
const {setUser, setToken, setCompany} = Profile.useContainer() const {setUser, setToken, setCompany} = Profile.useContainer()
const openid = localStorage.getItem('openid') const [openid, setOpenId] = useState('')
const [phone_number, setPhone_number] = useState<number | undefined>(undefined) const [phone_number, setPhone_number] = useState<number | null>()
useEffect(() => { useEffect(() => {
if (codeTime > 0) { if (codeTime > 0) {
@ -25,6 +25,14 @@ const Bing: FC = () => {
} }
}, [codeTime]) }, [codeTime])
Taro.useLoad(() => {
if (process.env.TARO_ENV === 'h5') {
setOpenId(localStorage.getItem('openid') || '')
} else {
setOpenId(Taro.getStorageSync('openid'))
}
})
async function Submit(data) { async function Submit(data) {
setLoading(true) setLoading(true)
const value = data.target.value const value = data.target.value
@ -67,7 +75,7 @@ const Bing: FC = () => {
}, [codeTime, phone_number]) }, [codeTime, phone_number])
return ( return (
<View className='px-3 bg-white h-10'> <View className={styles.page}>
<Form onSubmit={Submit} ref={form}> <Form onSubmit={Submit} ref={form}>
<View className={styles.formItem}> <View className={styles.formItem}>
@ -78,7 +86,7 @@ const Bing: FC = () => {
type='number' type='number'
name='phone_number' name='phone_number'
placeholder={'请输入手机号'} placeholder={'请输入手机号'}
value={String(phone_number)} value={phone_number as unknown as string}
onInput={(e) => setPhone_number(Number(e.detail.value))}/> onInput={(e) => setPhone_number(Number(e.detail.value))}/>
</View> </View>

@ -41,18 +41,6 @@
text-align: center; text-align: center;
} }
.submit {
display: flex;
justify-content: center;
align-items: center;
gap: 12px;
margin: 20rpx auto;
a {
color: #fff;
}
}
.errorTips { .errorTips {
position: fixed; position: fixed;
@ -65,7 +53,6 @@
border-radius: 20px; border-radius: 20px;
display: flex; display: flex;
align-items: center; align-items: center;
gap: 12px;
} }
.bing { .bing {

@ -1,93 +1,13 @@
import {FC, useEffect, useRef, useState} from "react"; import {FC, useEffect, useState} from "react";
import {Profile} from "@/store"; import {Profile} from "@/store";
import {Form, Image, Input, Text, View} from "@tarojs/components"; import {Image, Text, View} from "@tarojs/components";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import styles from './login.module.scss' import styles from './login.module.scss'
import Loading from "@/components/loading";
import Icon from "@/components/icon"; import Icon from "@/components/icon";
import {LoginData, userApi} from "@/api"; import {userApi} from "@/api";
import {regexTel} from "@/utils/regu";
import CustomPageContainer from "@/components/custom-page-container/custom-page-container";
import {loginApi, LoginParams} from "@/api/login"; import {loginApi, LoginParams} from "@/api/login";
import MyButton from "@/components/button/MyButton"; import MyButton from "@/components/button/MyButton";
interface BingProps {
code: string
catch_key: string
}
const Bing: FC<BingProps> = ({code, catch_key}: BingProps) => {
const [useCode, setUseCode] = useState<string>(code)
const form = useRef<HTMLFormElement | null>(null)
const [loading, setLoading] = useState(false)
const {setUser, setToken, setCompany} = Profile.useContainer()
useEffect(() => {
form.current?.reset?.()
setUseCode(code)
}, [code])
async function refreshCode() {
try {
const {code} = await userApi.code(catch_key)
setUseCode(code.image)
} catch (e) {
}
}
async function Submit(data) {
Taro.showLoading()
setLoading(true)
const value = data.target.value
if (!regexTel.exec(value.phone_number)) {
Taro.showToast({title: '手机号错误', icon: 'error'})
setLoading(false)
return
}
try {
const res = await userApi.checkout({...value, catch_key})
if (res) {
setCompany(res.company)
setUser(res.user)
setToken(res.token)
Taro.switchTab({url: '/pages/index/index'})
}
} catch (e) {
refreshCode()
}
Taro.hideLoading()
setLoading(false)
}
return (
<View className='h-5 pt-6 px-3'>
<Form className='form' onSubmit={Submit} ref={form}>
<View className='item'>
<View className='label'></View>
<Input name='phone_number' placeholder={'请输入手机号'}/>
</View>
<View className='item'>
<View className='label'></View>
<View className='flex align-center'>
<Input name='code' className='flex-1' placeholder={'请输入验证码'}/>
<Image className='w-2 ml-1' style='height:28px' src={useCode} onClick={refreshCode}/>
</View>
</View>
<MyButton className={styles.submit} formType='submit' disabled={loading}></MyButton>
</Form>
</View>
)
}
// function getMenuButtonBoundingClientRect() {
// if (process.env.TARO_ENV === 'h5') {
// return {top: 0, bottom: 44}
// }
// return Taro.getMenuButtonBoundingClientRect()
// }
const Login: FC = () => { const Login: FC = () => {
// const {statusBarHeight = 0} = Taro.getSystemInfoSync() // const {statusBarHeight = 0} = Taro.getSystemInfoSync()
// const bbc = getMenuButtonBoundingClientRect(); // const bbc = getMenuButtonBoundingClientRect();
@ -95,27 +15,11 @@ const Login: FC = () => {
const [isLoading, setLoading] = useState(false) const [isLoading, setLoading] = useState(false)
const [error, setError] = useState<string | null>(null) const [error, setError] = useState<string | null>(null)
const [validateCode, setCode] = useState<string | null>(null)
const [catch_key, setCatch_key] = useState<string | null>(null)
const {setUser, setToken, setCompany} = Profile.useContainer() const {setUser, setToken, setCompany} = Profile.useContainer()
const [h5params, setH5Params] = useState<LoginParams | null>(null) const [h5params, setH5Params] = useState<LoginParams | null>(null)
const params = Taro.getCurrentInstance()?.router?.params as unknown as { data: LoginData }
useEffect(() => { useEffect(() => {
if (params?.data) {
if (!params.data?.code) {
setUser(params.data.user)
setToken(params.data.token)
setCompany(params.data.company)
setLoading(false)
Taro.switchTab({url: '/pages/index/index'})
return
}
setCatch_key(catch_key)
setCode(params.data.code.image)
return
}
if (process.env.TARO_ENV === 'h5') { if (process.env.TARO_ENV === 'h5') {
setLoading(true); setLoading(true);
@ -133,7 +37,7 @@ const Login: FC = () => {
function login() { function login() {
if (isLoading) return; if (isLoading) return;
if (h5params == null) { if (h5params == null && process.env.TARO_ENV === 'h5') {
setError('页面参数错误,请刷新页面!') setError('页面参数错误,请刷新页面!')
return; return;
} }
@ -151,17 +55,17 @@ const Login: FC = () => {
Taro.login({ Taro.login({
success: async (res) => { success: async (res) => {
try { try {
const {code, catch_key, user, token, company} = await userApi.login(res.code) const {catch_key, user, token, company} = await userApi.login(res.code)
if (!code) { if (token) {
setUser(user) setUser(user)
setToken(token) setToken(token)
setCompany(company) setCompany(company)
setLoading(false) setLoading(false)
Taro.switchTab({url: '/pages/index/index'}) Taro.switchTab({url: '/pages/index/index'})
return } else {
Taro.setStorageSync('openid', catch_key)
Taro.reLaunch({url: '/pages/check/check'})
} }
setCatch_key(catch_key)
setCode(code.image)
} catch (e) { } catch (e) {
} }
setLoading(false) setLoading(false)
@ -182,33 +86,20 @@ const Login: FC = () => {
return ( return (
<View className={styles.container}> <View className={styles.container}>
<CustomPageContainer show={!!validateCode} position='bottom' onBeforeLeave={() => setCode(null)}>
{validateCode && <Bing code={validateCode!} catch_key={catch_key!}/>}
</CustomPageContainer>
<View className={styles.brand}> <View className={styles.brand}>
<Image mode={'scaleToFill'} src="https://playedu.yaojiankang.top/favicon.ico"/> <Image mode={'scaleToFill'} src="https://playedu.yaojiankang.top/favicon.ico"/>
<View className='mt-3'></View> <View className='mt-3'></View>
</View> </View>
<View className={styles.loginTips}> <View className={styles.loginTips}>
<Text>使</Text> <Text>使</Text>
</View> </View>
<MyButton onClick={login}> <MyButton onClick={login} loading={isLoading}></MyButton>
<View className={styles.submit}>
{isLoading ? <Loading/> : null} {error ? <View className={styles.errorTips}>
<View className={styles.navbar}> <View style={{flex: 1}}>{error}</View>
<Text></Text> <Icon name={'close'} onClick={() => setError(null)}/>
{error ? <View className={styles.errorTips}> </View> : null}
<View style={{flex: 1}}>{error}</View>
<View>
<Icon name={'close'} onClick={() => setError(null)}/>
</View>
</View> : null}
</View>
</View>
</MyButton>
{process.env.TARO_APP_LGOIN === 'true' && <MyButton onClick={TESTLOGIN}>线</MyButton>} {process.env.TARO_APP_LGOIN === 'true' && <MyButton onClick={TESTLOGIN}>线</MyButton>}
</View> </View>

@ -31,18 +31,13 @@ const AddStudent = () => {
async function submit(event) { async function submit(event) {
const value: Student = event.detail.value const value: Student = event.detail.value
for (const [key, value1] of Object.entries(value)) { for (const [_, value1] of Object.entries(value)) {
if (!value1 && !['id_card', 'password'].includes(key)) { if (!value1) {
Taro.showToast({title: "请认真填写", icon: 'error'}) Taro.showToast({title: "请填写学员姓名和手机号", icon: 'error'})
return return
} }
} }
if (!depIds.length) {
Taro.showToast({title: "请选择部门", icon: 'error'})
return
}
Taro.showLoading() Taro.showLoading()
try { try {
if (params.id) { if (params.id) {

@ -159,7 +159,7 @@ const DepAdmin: FC = () => {
<View className='operation'> <View className='operation'>
<View className='safeAreaInsetBottom'> <View className='safeAreaInsetBottom'>
<View onClick={jumpAddStudent}></View> <View onClick={jumpAddStudent}></View>
<View onClick={() => showPop(undefined)}></View> <View onClick={() => showPop(undefined)}></View>
{ {
router.params.id && <View onClick={managesSheet}></View> router.params.id && <View onClick={managesSheet}></View>
} }

Loading…
Cancel
Save