Compare commits

..

No commits in common. 'iot-template' and 'main' have entirely different histories.

  1. 2
      .env.development
  2. 20
      src/api/base/user/index.ts
  3. 2
      src/api/base/user/types.ts
  4. 18
      src/views/base/login/LoginForm.vue

2
.env.development

@ -7,7 +7,7 @@ VITE_PUBLIC_PATH = /
# 本地开发代理,可以解决跨域及多地址代理
# 如果接口地址匹配到,则会转发到http://localhost:3000,防止本地出现跨域问题
# 可以有多个,注意多个不能换行,否则代理将会失效
VITE_PROXY = [["/api","http://223.99.228.207:10406"]]
VITE_PROXY = [["/api","http://192.168.1.100:10408"]]
# 是否删除Console.log
VITE_DROP_CONSOLE = false

20
src/api/base/user/index.ts

@ -4,16 +4,18 @@ import { defHttp } from '@/utils/http/axios'
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
return defHttp.post<LoginResult>({
url: '/iot-auth/oauth/token',
url: '/baymax-auth/oauth/token',
params: {
username: params.username,
password: params.password,
grant_type: 'password',
grant_type: 'captcha',
scope: 'all',
type: 'account',
},
headers: {
'Tenant-Id': params.tenantId,
'Captcha-Key': params.captchaKey,
'Captcha-Code': params.captchaCode,
},
}, {
errorMessageMode: mode,
@ -24,7 +26,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
export function getUserInfo() {
return defHttp.get<UserInfo>({
url: '/iot-system/user/info',
url: '/baymax-system/user/info',
})
}
@ -46,19 +48,19 @@ export interface __MenuItem {
export function getUserRouters() {
return defHttp.get<__MenuItem[]>({
url: '/iot-system/sysApp/routes?appCode=mes',
url: '/baymax-system/menu/routes',
})
}
export function getUserButtons() {
return defHttp.get({
url: '/iot-system/sys-app-menu/buttons?appCode=mes',
url: '/baymax-system/menu/buttons',
})
}
export function doLogout() {
return defHttp.get({
url: '/iot-auth/oauth/logout',
return defHttp.post({
url: '/baymax-auth/oauth/logout',
})
}
@ -73,14 +75,14 @@ export function getLoginCaptcha() {
export function updateUserInfo(data: Partial<UserInfo>) {
return defHttp.post({
url: '/iot-system/user/update-info',
url: '/baymax-system/user/update-info',
data,
})
}
export function updatePassword(params: { oldPassword: string, newPassword: string, newPassword1: string }) {
return defHttp.post({
url: '/iot-system/user/update-password',
url: '/baymax-system/user/update-password',
params,
}, { joinParamsToUrl: true })
}

2
src/api/base/user/types.ts

@ -4,6 +4,8 @@ export interface LoginParams {
username: string
password: string
tenantId: string
captchaKey: string
captchaCode: string
}
export interface LoginResult extends User {

18
src/views/base/login/LoginForm.vue

@ -1,9 +1,12 @@
<script lang="ts" setup>
import type { LoginParams } from '@/api/base/user/types'
import { getLoginCaptcha } from '@/api/base/user'
import { useDesign } from '@/hooks/web/useDesign'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useUserStore } from '@/store/modules/user'
import { LoadingOutlined } from '@ant-design/icons-vue'
import { useAsyncState } from '@vueuse/core'
import { Form, Input } from 'ant-design-vue'
import CryptoJS from 'crypto-js'
import { computed, reactive, ref, unref } from 'vue'
@ -28,6 +31,8 @@ const formData = reactive<LoginParams>({
tenantId: '000000',
username: '',
password: '',
captchaKey: '',
captchaCode: '',
})
const { validForm } = useFormValid(formRef)
@ -41,6 +46,7 @@ async function handleLogin() {
loading.value = true
const userInfo = await userStore.login({
...formData,
captchaKey: captcha.value!.key,
password: CryptoJS.MD5(formData.password).toString(),
mode: 'none',
})
@ -53,6 +59,7 @@ async function handleLogin() {
}
}
catch (error) {
refreshCaptcha()
createErrorModal({
title: t('sys.api.errorTip'),
content: (error as unknown as Error).message || t('sys.api.networkExceptionMsg'),
@ -63,6 +70,8 @@ async function handleLogin() {
loading.value = false
}
}
const { state: captcha, execute: refreshCaptcha, isLoading: isLoadingCaptcha } = useAsyncState(getLoginCaptcha, undefined)
</script>
<template>
@ -86,6 +95,15 @@ async function handleLogin() {
class="fix-auto-fill"
/>
</FormItem>
<FormItem>
<div flex="~ justify-between items-center gap-12px">
<Input v-model:value="formData.captchaCode" size="large" placeholder="验证码" class="fix-auto-fill w-0 flex-1 min-w-auto!" />
<div w="100px" text="center">
<LoadingOutlined v-if="isLoadingCaptcha" />
<img v-else w-full :src="captcha?.image" @click="refreshCaptcha()">
</div>
</div>
</FormItem>
<FormItem class="enter-x">
<a-button type="primary" size="large" block :loading="loading" @click="handleLogin">

Loading…
Cancel
Save