From 0a0dbbe0aa2be52c0e78c1afe273dcbe3c9b6fd7 Mon Sep 17 00:00:00 2001
From: chenyc <501753378@qq.com>
Date: 星期五, 21 十月 2022 15:44:09 +0800
Subject: [PATCH] 34
---
src/views/login/index.vue | 107 ++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 73 insertions(+), 34 deletions(-)
diff --git a/src/views/login/index.vue b/src/views/login/index.vue
index e1b5a1d..f30bd9c 100644
--- a/src/views/login/index.vue
+++ b/src/views/login/index.vue
@@ -1,19 +1,24 @@
<script lang="ts" setup>
import { ref,onMounted } from 'vue'
import {useRoute,useRouter} from 'vue-router'
- import { ajaxGet } from '@/utils/axios'
- // import { Session } from '@/utils/storage'
- import { Dialog } from 'vant'
+ import { ajaxGet ,ajaxPost} from '@/utils/axios'
+ import { Session } from '@/utils/storage'
+ import { Dialog ,Toast } from 'vant'
import { userInfoStore } from '@/stores/userInfo'
import logo from 'assets/logo.png'
import shoujiLogin from 'assets/yijianLogin.png'
import pswdLogin from 'assets/pswdLogin.png'
+ const config={
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded'
+ },
+ }
const userInfo = userInfoStore()
const route = useRoute()
const router=useRouter()
const username = ref('')
const password = ref('')
- const visible=ref(1)
+ const visible=ref(3)
const seconds=ref(60)
const loadingBUt=ref(false)
const ruleForm2=ref({
@@ -29,18 +34,29 @@
const asyncValidator = (val:any) =>{
return val===ruleForm2.value.pass
}
+ const getUserinfo=()=>{
+ ajaxPost('/patient/info/getPatientInfo','').then((re:any)=>{
+ console.log(re,'得到患者的信息getUserinfo')
+ userInfo.setPatient(re)
+ router.push('/')
+ })
+ }
const onSubmit = (values:any) => {
console.log('submit', values)
- router.push('/')
- // const str=`user_no=${username.value}&user_password=${password.value}`
loadingBUt.value=true
- // signIn(str).then((res:any)=>{
- // Session.set('token', res.data)
- // router.push('/')
- // })
- // }).catch(()=>{
- // loadingBUt.value=false
- // })
+ ajaxPost('/patient/info/wechatLogin2',`mobile=${username.value}&password=${password.value}`,config).then((re:any)=>{
+ console.log(re)
+ if (re===''){
+ Toast('登录失败,请重新登录')
+ } else {
+ console.log('得到tokeng')
+ Session.set('token', re)
+ Toast('登录成功。。。。。')
+ getUserinfo()
+ }
+ }).finally(()=>{
+ loadingBUt.value=false
+ })
}
const onSubmit2=(values:any)=>{
console.log('提交表单',ruleForm2.value)
@@ -54,25 +70,41 @@
})
}
const onSubmit3=(values:any)=>{
- console.log('提交表单',ruleForm3.value)
- console.log(values)
+ if (userInfo.info.openid===''){
+ Toast('没有获取到openid')
+ return
+ }
+ console.log('提交表单',ruleForm3.value,values)
+ ajaxPost('patient/info/isValidCodeOK',`phoneNo=${ruleForm3.value.userPhone}&validCode=${ruleForm3.value.validateCode}&openId=${userInfo.info.openid}`,config).then((re:any)=>{
+ console.log(re)
+ if (re===false){
+ Toast('登录失败,请重新登录')
+ } else {
+ Session.set('token', re)
+ Toast('登录成功。。。。。')
+ getUserinfo()
+ }
+ })
}
const sendCode=()=>{
- if (ruleForm2.value.userPhone===''){
+ if (ruleForm3.value.userPhone===''){
Toast('手机号码不能为空')
return
}
- // sendValidateCode('mobileNo='+ruleForm2.value.userPhone).then(re=>{
- // console.log(re)
- // const timer= setInterval(() => {
- // if (seconds.value > 0) {
- // seconds.value--
- // } else {
- // seconds.value = 60
- // clearInterval(timer)
- // }
- // }, 1000)
- // })
+ ajaxPost('patient/info/sendValidCode','phoneNo='+ruleForm3.value.userPhone,config).then((re:any)=>{
+ console.log(re)
+ if (re.code===200){
+ return
+ }
+ const timer= setInterval(() => {
+ if (seconds.value > 0) {
+ seconds.value--
+ } else {
+ seconds.value = 60
+ clearInterval(timer)
+ }
+ }, 1000)
+ })
}
const wjmm=()=>{
visible.value=2
@@ -95,20 +127,27 @@
const queryInfo=route.query
const {code}=queryInfo
console.log(code)
- if (code){
+ if (code){ // 得到code换取openid
ajaxGet('wechat/code',{code}).then((re:any)=>{
- console.log(re)
- userInfo.setUserInfo({openid:re.openid,nickname:re.nickname,headimgurl:re.headimgurl})
- const openid = re.openid
- if (openid) {
- ajaxGet('patient/info/wechatLogin',{openid}).then((re:any)=>{
+ console.log(re,'获取openid')
+ userInfo.setInfo({openid:re.openid,nickname:re.nickname,headimgurl:re.headimgurl})
+ const openId = re.openid
+ if (openId) { // 检查登录
+ ajaxPost('patient/info/wechatLogin','openId='+openId,config).then((re:any)=>{
console.log('openid换的accesstoken=',re)
+ if (re===''){
+ Toast('请填写表单登录。。')
+ } else {
+ Session.set('token', re)
+ Toast('登录成功。。。。。')
+ getUserinfo()
+ }
})
}
})
}
- else {
+ else { // 没有code 就重新进入微信url获取code
const appid = 'wx790bd67db6206070' // 微信APPid
const local = window.location.href
window.location.href =
--
Gitblit v1.8.0