封装axios+添加早上好弹窗

This commit is contained in:
熊猫 2024-02-19 15:15:21 +08:00
parent 37d72cfcb0
commit e22b485ec2
11 changed files with 116 additions and 24 deletions

View File

@ -68,25 +68,42 @@ const validatePassword = (rule: any, value: any, callback: any) => {
} }
} }
//
const validatorPassword = (rule: any, value: any, callback: any) => {
if (value.length >= 6) {
callback();
} else {
callback(new Error('密码长度至少6位'));
}
}
const validatorPhone = (rule: any, value: any, callback: any) => {
if (value.length == 11) {
callback();
} else {
callback(new Error('手机号码长度为11位'));
}
}
const rules = reactive({ const rules = reactive({
phone: [ phone: [
{ required: true, message: '请输入手机号', trigger: 'blur' }, { required: true, validator:validatorPhone, trigger: 'change' },
], ],
name: [ name: [
{ required: true, message: '请输入用户名', trigger: 'blur' }, { required: true, message: '请输入名', trigger: 'blur' },
], ],
mailbox: [ mailbox: [
{ type: 'email', message: '邮箱格式不正确', trigger: ['blur', 'change'] }, { type: 'email', message: '邮箱格式不正确', trigger: ['blur', 'change'] },
], ],
password: [ password: [
{ required: true, message: '请输入密码', trigger: 'blur' }, { required: true, validator: validatorPassword, trigger: 'change' },
], ],
newPassword: [ newPassword: [
{ required: true, message: '请选择新密码', trigger: 'blur' }, { required: true, validator: validatorPassword, trigger: 'change' },
{ validator: validatePassword, trigger: 'blur' } //{ validator: validatePassword, trigger: 'blur' }
], ],
confirmPassword: [ confirmPassword: [
{ required: true, message: '请选择新密码', trigger: 'blur' }, { required: true, message: '请输入密码', trigger: 'change' },
{ validator: validatePassword, trigger: 'blur' } { validator: validatePassword, trigger: 'blur' }
] ]
}) })

View File

@ -1,4 +1,4 @@
import { getData, postData } from '@/axios/index' import { getData, postData } from '@/utils/request'
export const getHospitalsData = () => { export const getHospitalsData = () => {
const hospitals = [] as any const hospitals = [] as any

6
src/stores/index.ts Normal file
View File

@ -0,0 +1,6 @@
//仓库大仓库
import { createPinia } from 'pinia'
//创建大仓库
const pinia = createPinia()
//对外暴露:入口文件需要安装仓库
export default pinia

View File

@ -5,12 +5,12 @@ const BASE_URL = import.meta.env.BASE_URL
export const get = (url: any, params: any, success: any) => { export const get = (url: any, params: any, success: any) => {
axios.get(HOST + url, params) axios.get(HOST + url, params)
.then(res => { .then(res => {
success(res); success(res);
}) })
.catch(err => { .catch(err => {
success(err); success(err);
}); });
}; };
export const post = (url: any, params: any, success: any) => { export const post = (url: any, params: any, success: any) => {
axios.post(HOST + url, params) axios.post(HOST + url, params)

17
src/utils/time.ts Normal file
View File

@ -0,0 +1,17 @@
//封装一个函数:获取一个结果:当前早上|上午|下午|晚上
export const getTime = () => {
let message = ''
//通过内置构造函数Date
const hours = new Date().getHours()
//情况的判断
if (hours <= 9) {
message = '早上'
} else if (hours <= 12) {
message = '上午'
} else if (hours <= 18) {
message = '下午'
} else {
message = '晚上'
}
return message
}

13
src/utils/token.ts Normal file
View File

@ -0,0 +1,13 @@
//封装本地存储存储数据与读取数据方法
//存储数据
export const SET_TOKEN = (token: string) => {
localStorage.setItem('TOKEN', token)
}
//本地存储获取数据
export const GET_TOKEN = () => {
return localStorage.getItem('TOKEN')
}
//本地存储删除数据方法
export const REMOVE_TOKEN = () => {
localStorage.removeItem('TOKEN')
}

View File

@ -65,7 +65,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'
import { useLoginStore } from '@/stores/user-info-store' import { useLoginStore } from '@/stores/user-info-store'
import { getHospitalsData } from '@/static-data/core' import { getHospitalsData } from '@/static-data/core'
import userInfoForm from '@/components/user-info.vue' import userInfoForm from '@/components/user-info.vue'
import {wsApi} from "@/axios/ws"; import {wsApi} from "@/api/ws";
const router = useRouter() const router = useRouter()
const route = useRoute() const route = useRoute()

View File

@ -34,7 +34,7 @@
</template> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-button class="login-btn" type="primary" @click="login('password')">登录</el-button> <el-button :loading="loading" class="login-btn" type="primary" @click="login('password')">登录</el-button>
<span class="register-btn" @click="getCaptchaCode()">注册账号</span> <span class="register-btn" @click="getCaptchaCode()">注册账号</span>
</div> </div>
<div class="login-form code-login" v-else> <div class="login-form code-login" v-else>
@ -124,13 +124,19 @@
<script lang='ts' setup> <script lang='ts' setup>
import {onMounted, reactive, ref, toRefs, watch} from 'vue' import {onMounted, reactive, ref, toRefs, watch} from 'vue'
import {useRouter} from 'vue-router' import {useRouter,useRoute} from 'vue-router'
import {ElMessage, ElMessageBox} from 'element-plus' import {ElMessage, ElMessageBox} from 'element-plus'
import {useLoginStore} from '@/stores/user-info-store' import {useLoginStore} from '@/stores/user-info-store'
import {getHospitalsData, getPhoneAreasData} from '@/static-data/core' import {getHospitalsData, getPhoneAreasData} from '@/static-data/core'
import {v4} from "uuid"; import {v4} from "uuid";
import {HOST} from "@/axios"; import {HOST} from "@/utils/request";
import SliderVerify from "@/components/SliderVerify/index.vue"; import SliderVerify from "@/components/SliderVerify/index.vue";
import { ElNotification } from 'element-plus';
//
import { getTime } from '@/utils/time';
//
//import useUserStore from "@/stores/user-info-store";
//let useStore = useUserStore();
const router = useRouter() const router = useRouter()
@ -140,7 +146,8 @@ getHospitalsData().then((res: any) => {
}) })
const phoneAreas: any = getPhoneAreasData() const phoneAreas: any = getPhoneAreasData()
//
let loading = ref(false);
// //
const validatorUserName = (rule: any, value: any, callback: any) => { const validatorUserName = (rule: any, value: any, callback: any) => {
@ -151,7 +158,7 @@ const validatorUserName = (rule: any, value: any, callback: any) => {
if (value.length >= 4) { if (value.length >= 4) {
callback(); callback();
} else { } else {
callback(new Error('账号长度至少位')); callback(new Error('账号长度至少4位'));
} }
} }
@ -159,7 +166,7 @@ const validatorPassword = (rule: any, value: any, callback: any) => {
if (value.length >= 6) { if (value.length >= 6) {
callback(); callback();
} else { } else {
callback(new Error('密码长度至少位')); callback(new Error('密码长度至少6位'));
} }
} }
@ -171,8 +178,6 @@ const validatorPhone = (rule: any, value: any, callback: any) => {
} }
} }
const loginRules = reactive({ const loginRules = reactive({
account: [ account: [
{ required: true, validator: validatorUserName, trigger: 'change' }, { required: true, validator: validatorUserName, trigger: 'change' },
@ -208,6 +213,10 @@ const registerRules = reactive({
] ]
}) })
//
let $router = useRouter();
//
let $route = useRoute();
const loginFormRef = ref() const loginFormRef = ref()
const registerFormRef = ref() const registerFormRef = ref()
const slideVerifyRef = ref() const slideVerifyRef = ref()
@ -302,6 +311,36 @@ const login = async (type: string) => {
} else { } else {
// console.log('error submit!', fields) // console.log('error submit!', fields)
} }
//:
loading.value = true;
/*try {
//
await useStore.userLogin(loginFormRef);
}*/
//
//,queryquery
let redirect: any = $route.query.redirect;
$router.push({ path: redirect || '/' });
//
ElNotification({
type: 'success',
message: '欢迎回来',
title: `HI,${getTime()}`
});
//
loading.value = false;
/*} catch (error) {
//
loading.value = false;
//
ElNotification({
type: 'error',
message: (error as Error).message
})*/
}) })
} }

View File

@ -136,7 +136,7 @@ import { useRouter, useRoute } from 'vue-router'
import { ElMessageBox, ElMessage } from 'element-plus'; import { ElMessageBox, ElMessage } from 'element-plus';
import { useRemoteStore } from '@/stores/remote-info-store' import { useRemoteStore } from '@/stores/remote-info-store'
import { dateFormater } from '@/utils/date-util'; import { dateFormater } from '@/utils/date-util';
import { post } from "@/axios/index"; import { post } from "@/utils/request";
import chartLine from './chart/chart-line.vue'; import chartLine from './chart/chart-line.vue';
import chartEcg from './chart/chart-ecg.vue'; import chartEcg from './chart/chart-ecg.vue';
import PatientsForm from '@/views/patients-manage/form/patients-form.vue' import PatientsForm from '@/views/patients-manage/form/patients-form.vue'

View File

@ -6,7 +6,7 @@
import { onMounted, reactive, ref, toRefs, watch } from 'vue' import { onMounted, reactive, ref, toRefs, watch } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { getMapJson } from '@/axios/index' import { getMapJson } from '@/utils/request'
const router = useRouter() const router = useRouter()