diff --git a/.env b/.env index 0cde6d6..1eee7ad 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ -#TARO_APP_API=https://yjx.dev.yaojiankang.top -TARO_APP_API=https://playedu.yaojiankang.top +TARO_APP_API=https://yjx.dev.yaojiankang.top +#TARO_APP_API=https://playedu.yaojiankang.top TARO_APP_LGOIN=true diff --git a/src/api/user.ts b/src/api/user.ts index 3ce5610..d80e397 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -6,7 +6,6 @@ interface Code { export interface LoginData { access_token: string - code?: Code company: Company token: string user: User diff --git a/src/pages/check/check.config.ts b/src/pages/check/check.config.ts index 167907b..bdff298 100644 --- a/src/pages/check/check.config.ts +++ b/src/pages/check/check.config.ts @@ -1,4 +1,3 @@ export default definePageConfig({ - navigationStyle: 'custom', - navigationBarTitleText: '验证' + navigationBarTitleText: '绑定手机号' }) diff --git a/src/pages/check/check.module.scss b/src/pages/check/check.module.scss index 92c010f..47ccdb6 100644 --- a/src/pages/check/check.module.scss +++ b/src/pages/check/check.module.scss @@ -1,3 +1,13 @@ +.page{ + position: fixed; + left: 0; + right: 0; + bottom: 0; + top: 0; + background: #fff; + padding: 0 20rpx; +} + .submit { display: flex; justify-content: center; @@ -17,7 +27,8 @@ } .image { - width: 50px; + width: 50rpx; + height: 50rpx; vertical-align: top; margin-right: 20px; } diff --git a/src/pages/check/check.tsx b/src/pages/check/check.tsx index 149fac2..b461897 100644 --- a/src/pages/check/check.tsx +++ b/src/pages/check/check.tsx @@ -1,5 +1,5 @@ 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 {userApi} from "@/api"; import Taro from "@tarojs/taro"; @@ -14,8 +14,8 @@ const Bing: FC = () => { const [loading, setLoading] = useState(false) const [codeTime, setCodeTime] = useState(0) const {setUser, setToken, setCompany} = Profile.useContainer() - const openid = localStorage.getItem('openid') - const [phone_number, setPhone_number] = useState(undefined) + const [openid, setOpenId] = useState('') + const [phone_number, setPhone_number] = useState() useEffect(() => { if (codeTime > 0) { @@ -25,6 +25,14 @@ const Bing: FC = () => { } }, [codeTime]) + Taro.useLoad(() => { + if (process.env.TARO_ENV === 'h5') { + setOpenId(localStorage.getItem('openid') || '') + } else { + setOpenId(Taro.getStorageSync('openid')) + } + }) + async function Submit(data) { setLoading(true) const value = data.target.value @@ -67,7 +75,7 @@ const Bing: FC = () => { }, [codeTime, phone_number]) return ( - +
@@ -78,7 +86,7 @@ const Bing: FC = () => { type='number' name='phone_number' placeholder={'请输入手机号'} - value={String(phone_number)} + value={phone_number as unknown as string} onInput={(e) => setPhone_number(Number(e.detail.value))}/> diff --git a/src/pages/login/login.module.scss b/src/pages/login/login.module.scss index d371305..43518ce 100644 --- a/src/pages/login/login.module.scss +++ b/src/pages/login/login.module.scss @@ -41,18 +41,6 @@ text-align: center; } -.submit { - display: flex; - justify-content: center; - align-items: center; - gap: 12px; - margin: 20rpx auto; - - a { - color: #fff; - } -} - .errorTips { position: fixed; @@ -65,7 +53,6 @@ border-radius: 20px; display: flex; align-items: center; - gap: 12px; } .bing { diff --git a/src/pages/login/login.tsx b/src/pages/login/login.tsx index 1788d06..c4cff69 100644 --- a/src/pages/login/login.tsx +++ b/src/pages/login/login.tsx @@ -1,93 +1,13 @@ -import {FC, useEffect, useRef, useState} from "react"; +import {FC, useEffect, useState} from "react"; 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 styles from './login.module.scss' -import Loading from "@/components/loading"; import Icon from "@/components/icon"; -import {LoginData, userApi} from "@/api"; -import {regexTel} from "@/utils/regu"; -import CustomPageContainer from "@/components/custom-page-container/custom-page-container"; +import {userApi} from "@/api"; import {loginApi, LoginParams} from "@/api/login"; import MyButton from "@/components/button/MyButton"; -interface BingProps { - code: string - catch_key: string -} - -const Bing: FC = ({code, catch_key}: BingProps) => { - const [useCode, setUseCode] = useState(code) - const form = useRef(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 ( - - - - 手机号 - - - - - 验证码 - - - - - - - 提交 - - - ) -} - -// function getMenuButtonBoundingClientRect() { -// if (process.env.TARO_ENV === 'h5') { -// return {top: 0, bottom: 44} -// } -// return Taro.getMenuButtonBoundingClientRect() -// } - const Login: FC = () => { // const {statusBarHeight = 0} = Taro.getSystemInfoSync() // const bbc = getMenuButtonBoundingClientRect(); @@ -95,27 +15,11 @@ const Login: FC = () => { const [isLoading, setLoading] = useState(false) const [error, setError] = useState(null) - const [validateCode, setCode] = useState(null) - const [catch_key, setCatch_key] = useState(null) const {setUser, setToken, setCompany} = Profile.useContainer() const [h5params, setH5Params] = useState(null) - const params = Taro.getCurrentInstance()?.router?.params as unknown as { data: LoginData } 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') { setLoading(true); @@ -133,7 +37,7 @@ const Login: FC = () => { function login() { if (isLoading) return; - if (h5params == null) { + if (h5params == null && process.env.TARO_ENV === 'h5') { setError('页面参数错误,请刷新页面!') return; } @@ -151,17 +55,17 @@ const Login: FC = () => { Taro.login({ success: async (res) => { try { - const {code, catch_key, user, token, company} = await userApi.login(res.code) - if (!code) { + const {catch_key, user, token, company} = await userApi.login(res.code) + if (token) { setUser(user) setToken(token) setCompany(company) setLoading(false) 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) { } setLoading(false) @@ -182,33 +86,20 @@ const Login: FC = () => { return ( - setCode(null)}> - {validateCode && } - - 医学道 - 请完成微信授权以继续使用! - - - {isLoading ? : null} - - 微信授权登录 - {error ? - {error} - - setError(null)}/> - - : null} - - - + 微信授权登录 + + {error ? + {error} + setError(null)}/> + : null} {process.env.TARO_APP_LGOIN === 'true' && 线下登录} diff --git a/src/pages/manage/addStudent/addStudent.tsx b/src/pages/manage/addStudent/addStudent.tsx index 95ddb62..348f3de 100644 --- a/src/pages/manage/addStudent/addStudent.tsx +++ b/src/pages/manage/addStudent/addStudent.tsx @@ -31,18 +31,13 @@ const AddStudent = () => { async function submit(event) { const value: Student = event.detail.value - for (const [key, value1] of Object.entries(value)) { - if (!value1 && !['id_card', 'password'].includes(key)) { - Taro.showToast({title: "请认真填写", icon: 'error'}) + for (const [_, value1] of Object.entries(value)) { + if (!value1) { + Taro.showToast({title: "请填写学员姓名和手机号", icon: 'error'}) return } } - if (!depIds.length) { - Taro.showToast({title: "请选择部门", icon: 'error'}) - return - } - Taro.showLoading() try { if (params.id) { diff --git a/src/pages/manage/depAdmin/depAdmin.tsx b/src/pages/manage/depAdmin/depAdmin.tsx index df6af00..2956ae4 100644 --- a/src/pages/manage/depAdmin/depAdmin.tsx +++ b/src/pages/manage/depAdmin/depAdmin.tsx @@ -159,7 +159,7 @@ const DepAdmin: FC = () => { 添加学员 - showPop(undefined)}>添加部门 + showPop(undefined)}>分配部门 { router.params.id && 更多操作 }