|
@@ -27,12 +27,8 @@
|
|
|
v-model="data.code"
|
|
v-model="data.code"
|
|
|
placeholder="请输入验证码"
|
|
placeholder="请输入验证码"
|
|
|
>
|
|
>
|
|
|
- <template #append>
|
|
|
|
|
- <el-button
|
|
|
|
|
- :class="isStart? '' : 'code-button-active'"
|
|
|
|
|
- @click="getCode"
|
|
|
|
|
- :disabled="isStart"
|
|
|
|
|
- >
|
|
|
|
|
|
|
+ <template #suffix>
|
|
|
|
|
+ <el-button type="text" @click="getCode" :disabled="isStart">
|
|
|
{{ isStart ? countdown : '获取验证码' }}
|
|
{{ isStart ? countdown : '获取验证码' }}
|
|
|
</el-button>
|
|
</el-button>
|
|
|
</template>
|
|
</template>
|
|
@@ -50,14 +46,14 @@
|
|
|
<el-form-item>
|
|
<el-form-item>
|
|
|
<el-button class="login-button" @click="handleLogin">用户登录</el-button>
|
|
<el-button class="login-button" @click="handleLogin">用户登录</el-button>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
- <div class="sign" @click="onClickSign">去注册?</div>
|
|
|
|
|
|
|
+ <div class="sign" @click="onClickSign">注册账号</div>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
- import { ref, reactive,defineProps } from 'vue';
|
|
|
|
|
|
|
+ import { ref, reactive, defineProps } from 'vue';
|
|
|
import { useStore } from '@/store';
|
|
import { useStore } from '@/store';
|
|
|
import useApis from '@/apis';
|
|
import useApis from '@/apis';
|
|
|
import router from "@/router";
|
|
import router from "@/router";
|
|
@@ -108,27 +104,59 @@
|
|
|
{ required: true, message: props.isCode ? '验证码不能为空' : '密码不能为空', trigger: 'blur' },
|
|
{ required: true, message: props.isCode ? '验证码不能为空' : '密码不能为空', trigger: 'blur' },
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- // 这个功能实现了吗?
|
|
|
|
|
|
|
+
|
|
|
const getCode = () => {
|
|
const getCode = () => {
|
|
|
start();
|
|
start();
|
|
|
props.onCode?.();
|
|
props.onCode?.();
|
|
|
- // console.log('获取验证码');
|
|
|
|
|
|
|
+
|
|
|
|
|
+ console.log('获取验证码');
|
|
|
|
|
+ apis.sendLoginVerifyCode(data.officialNumber)
|
|
|
|
|
+ .then((res: any) => {
|
|
|
|
|
+ if (res.data.code === 200) {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '验证码发送成功,请前往您的邮箱查看',
|
|
|
|
|
+ type: 'success',
|
|
|
|
|
+ })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '验证码发送失败' + res.data.msg,
|
|
|
|
|
+ // message: '验证码发送失败',
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((err: any) => {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '验证码发送失败',
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ })
|
|
|
|
|
+ console.log(err)
|
|
|
|
|
+ })
|
|
|
|
|
+ .finally(() => {
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
let assignmentId = ref(1)
|
|
let assignmentId = ref(1)
|
|
|
const handleLogin = () => {
|
|
const handleLogin = () => {
|
|
|
|
|
+ if(!props.isCode) {
|
|
|
|
|
+ login()
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loginByEmail()
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const login = () => {
|
|
|
apis.login({
|
|
apis.login({
|
|
|
officialNumber: data.officialNumber,
|
|
officialNumber: data.officialNumber,
|
|
|
password: data.password
|
|
password: data.password
|
|
|
}).then((_res:any) => {
|
|
}).then((_res:any) => {
|
|
|
const data = _res.data.data
|
|
const data = _res.data.data
|
|
|
|
|
+ console.log(_res.data)
|
|
|
if (_res.data.code === 200) {
|
|
if (_res.data.code === 200) {
|
|
|
store.setUser(data);
|
|
store.setUser(data);
|
|
|
store.setToken(data?.token)
|
|
store.setToken(data?.token)
|
|
|
localStorage.setItem('Authorization', data?.token);
|
|
localStorage.setItem('Authorization', data?.token);
|
|
|
localStorage.setItem('User', data);
|
|
localStorage.setItem('User', data);
|
|
|
- // router.push("/")
|
|
|
|
|
router.push(`/home`)
|
|
router.push(`/home`)
|
|
|
} else if(_res.data.code === 400){
|
|
} else if(_res.data.code === 400){
|
|
|
ElMessage({
|
|
ElMessage({
|
|
@@ -142,8 +170,36 @@
|
|
|
type: 'error',
|
|
type: 'error',
|
|
|
})
|
|
})
|
|
|
console.log("登陆失败", _err)
|
|
console.log("登陆失败", _err)
|
|
|
- })
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const loginByEmail = () => {
|
|
|
|
|
+ apis.loginByEmail({
|
|
|
|
|
+ officialEmail: data.officialNumber,
|
|
|
|
|
+ verifyCode: data.code
|
|
|
|
|
+ }).then((_res:any) => {
|
|
|
|
|
+ const data = _res.data.data
|
|
|
|
|
+ if (_res.data.code === 200) {
|
|
|
|
|
+ store.setUser(data);
|
|
|
|
|
+ store.setToken(data?.token)
|
|
|
|
|
+ localStorage.setItem('Authorization', data?.token);
|
|
|
|
|
+ localStorage.setItem('User', data);
|
|
|
|
|
+ router.push(`/home`)
|
|
|
|
|
+ } else if(_res.data.code === 400){
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '邮箱或验证码错误' + _res.data.msg,
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch((_err:any) => {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '网络错误',
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ })
|
|
|
|
|
+ console.log("登陆失败", _err)
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const onClickSign = () => {
|
|
const onClickSign = () => {
|
|
|
router.push('/register');
|
|
router.push('/register');
|
|
|
};
|
|
};
|