Browse Source

chore: iot 模版登录适配

iot-template
K 7 months ago
parent
commit
6a476d8bb8
  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://192.168.1.100:10408"]]
VITE_PROXY = [["/api","http://223.99.228.207:10406"]]
# 是否删除Console.log
VITE_DROP_CONSOLE = false

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

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

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

@ -4,8 +4,6 @@ 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,12 +1,9 @@
<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'
@ -31,8 +28,6 @@ const formData = reactive<LoginParams>({
tenantId: '000000',
username: '',
password: '',
captchaKey: '',
captchaCode: '',
})
const { validForm } = useFormValid(formRef)
@ -46,7 +41,6 @@ async function handleLogin() {
loading.value = true
const userInfo = await userStore.login({
...formData,
captchaKey: captcha.value!.key,
password: CryptoJS.MD5(formData.password).toString(),
mode: 'none',
})
@ -59,7 +53,6 @@ async function handleLogin() {
}
}
catch (error) {
refreshCaptcha()
createErrorModal({
title: t('sys.api.errorTip'),
content: (error as unknown as Error).message || t('sys.api.networkExceptionMsg'),
@ -70,8 +63,6 @@ async function handleLogin() {
loading.value = false
}
}
const { state: captcha, execute: refreshCaptcha, isLoading: isLoadingCaptcha } = useAsyncState(getLoginCaptcha, undefined)
</script>
<template>
@ -95,15 +86,6 @@ const { state: captcha, execute: refreshCaptcha, isLoading: isLoadingCaptcha } =
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