解决登录页面 所有ts爆红
This commit is contained in:
parent
1af684224c
commit
5e3fa3c327
|
@ -14,7 +14,7 @@
|
|||
<a-form-item label="密码" name="passWord">
|
||||
<a-input-password placeholder="请输入密码" v-model:value="loginParams.passWord" />
|
||||
</a-form-item>
|
||||
<a-form-item :wrapper-col="{ span: 24 }">
|
||||
<a-form-item :wrapper-col="{span: 24}">
|
||||
<a-button type="primary" style="width: 100%" @click="login">登录</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
@ -24,17 +24,16 @@
|
|||
</template>
|
||||
<!-- -->
|
||||
<script setup lang="ts">
|
||||
import {JsonResult} from '@/axios'
|
||||
import api from '@/axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useUserStore } from '@/stores/modules/userStore'
|
||||
import aesUtil from '@/utils/aesUtil'
|
||||
import md5 from 'js-md5'
|
||||
import { FormInstance } from 'ant-design-vue'
|
||||
import { notification } from 'ant-design-vue'
|
||||
import { CLIENT_TYPE } from '@/configs'
|
||||
import { Rule } from 'ant-design-vue/es/form'
|
||||
import {ElMessage} from 'element-plus'
|
||||
import {ref, onMounted} from 'vue'
|
||||
import {useRouter} from 'vue-router'
|
||||
import {useUserStore} from '@/stores/modules/userStore'
|
||||
import {md5} from 'js-md5'
|
||||
import {FormInstance} from 'ant-design-vue'
|
||||
import {notification} from 'ant-design-vue'
|
||||
import {Rule} from 'ant-design-vue/es/form'
|
||||
const formRef = ref<FormInstance>(null)
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
|
@ -42,17 +41,17 @@ const userStore = useUserStore()
|
|||
const codeBase64Url = ref<string>('')
|
||||
const loginParamsRule: Record<string, Rule[]> = {
|
||||
userNameOrTelephone: [
|
||||
{ required: true, message: '请输入账号/手机号', trigger: 'change' },
|
||||
{ min: 3, max: 20, message: '账号长度最小为6最长为20', trigger: 'blur' },
|
||||
{required: true, message: '请输入账号/手机号', trigger: 'change'},
|
||||
{min: 3, max: 20, message: '账号长度最小为6最长为20', trigger: 'blur'}
|
||||
],
|
||||
passWord: [
|
||||
{ required: true, message: '请输入密码', trigger: 'change' },
|
||||
{ min: 3, max: 20, message: '密码长度最小为6最长为20', trigger: 'blur' },
|
||||
{required: true, message: '请输入密码', trigger: 'change'},
|
||||
{min: 3, max: 20, message: '密码长度最小为6最长为20', trigger: 'blur'}
|
||||
],
|
||||
code: [
|
||||
{ required: true, message: '请输入验证码', trigger: 'change' },
|
||||
{ len: 4, message: '验证码长度为4', trigger: 'blur' },
|
||||
],
|
||||
{required: true, message: '请输入验证码', trigger: 'change'},
|
||||
{len: 4, message: '验证码长度为4', trigger: 'blur'}
|
||||
]
|
||||
}
|
||||
const loginParams = ref<{
|
||||
userNameOrTelephone: string
|
||||
|
@ -61,30 +60,30 @@ const loginParams = ref<{
|
|||
}>({
|
||||
userNameOrTelephone: import.meta.env.VITE_APP_ENV === 'development' ? 'test001' : '',
|
||||
passWord: import.meta.env.VITE_APP_ENV === 'development' ? '123456' : '',
|
||||
code: import.meta.env.VITE_APP_ENV === 'development' ? '1234' : '',
|
||||
code: import.meta.env.VITE_APP_ENV === 'development' ? '1234' : ''
|
||||
})
|
||||
|
||||
const login = async () => {
|
||||
//校验表单
|
||||
await formRef.value.validate()
|
||||
//执行登录逻辑
|
||||
const resp = await api.post<string>(
|
||||
const resp: JsonResult<any> = await api.post<string>(
|
||||
'/common/client/user/login',
|
||||
{
|
||||
// clientType: CLIENT_TYPE,
|
||||
name: loginParams.value.userNameOrTelephone,
|
||||
password: md5(loginParams.value.passWord),
|
||||
password: md5(loginParams.value.passWord)
|
||||
// code: loginParams.value.code
|
||||
},
|
||||
{
|
||||
loading: true,
|
||||
loading: true
|
||||
}
|
||||
)
|
||||
|
||||
//保存用户信息
|
||||
api
|
||||
.post('/common/client/user/org/tree4', {
|
||||
name: loginParams.value.userNameOrTelephone,
|
||||
name: loginParams.value.userNameOrTelephone
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.code == 0) {
|
||||
|
@ -99,7 +98,7 @@ const login = async () => {
|
|||
api
|
||||
.post('multialarm/system/alarm/total', {
|
||||
name: loginParams.value.userNameOrTelephone,
|
||||
parent: resp.data.geoCode,
|
||||
parent: resp.data.geoCode
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.code == 0) {
|
||||
|
@ -111,7 +110,7 @@ const login = async () => {
|
|||
fetch(url)
|
||||
.then((response) => {
|
||||
var status = response['status']
|
||||
if (status == '500') {
|
||||
if (status == 500) {
|
||||
return new Promise((resovle) => {
|
||||
resovle('无数据')
|
||||
})
|
||||
|
@ -120,13 +119,13 @@ const login = async () => {
|
|||
return response.text()
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
.then((data: any) => {
|
||||
localStorage.setItem('mapdata', data)
|
||||
router.push('/index/indexmin').then(() => {
|
||||
notification.success({
|
||||
message: '登录成功',
|
||||
duration: 2,
|
||||
placement: 'topLeft',
|
||||
placement: 'topLeft'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -134,7 +133,7 @@ const login = async () => {
|
|||
// 验证码
|
||||
const getCode = async () => {
|
||||
const data = await api.get<string>('/common/generate/verification/code', {
|
||||
type: 'LOGIN',
|
||||
type: 'LOGIN'
|
||||
})
|
||||
codeBase64Url.value = data.data
|
||||
}
|
||||
|
|
|
@ -47,4 +47,4 @@
|
|||
"node_modules",
|
||||
"dist"
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue