ljlong_2630 1 month ago
parent
commit
64cd4c5449
  1. 8
      .env.development
  2. 29
      src/api/system/password/index.ts
  3. 14
      src/views/login/components/LoginForm.vue
  4. 153
      src/views/system/passwordRule/index.vue

8
.env.development

@ -4,11 +4,11 @@ NODE_ENV=development
VITE_DEV=false
# 请求路径
VITE_BASE_URL='http://localhost:12080'
VITE_BASE_URL='http://192.168.0.159:12080'
# VITE_BASE_URL='http://192.168.0.165:12080'
# 上传路径
VITE_UPLOAD_URL='http://localhost:12080/admin-api/infra/file/upload'
VITE_UPLOAD_URL='http://192.168.0.159:12080/admin-api/infra/file/upload'
# 接口前缀
VITE_API_BASEPATH=/dev-api
@ -32,7 +32,7 @@ VITE_SOURCEMAP=false
VITE_OUT_DIR=dist
# 自定义接口路径
VITE_INTERFACE_URL='http://localhost:12080/magic/web/index.html'
VITE_INTERFACE_URL='http://192.168.0.159:12080/magic/web/index.html'
# 积木报表请求路径
VITE_JMREPORT_BASE_URL='http://localhost:12080'
VITE_JMREPORT_BASE_URL='http://192.168.0.159:12080'

29
src/api/system/password/index.ts

@ -0,0 +1,29 @@
import request from '@/config/axios'
export interface PassWordConfigVO {
id: number
status: boolean
ruleLevel: string
ruleDesc: string
tryCount: number
lockMinutes: number
updatePeriod: number
}
// 获取密码策略
export const getConfig = () => {
return request.get({ url: '/system/password/getConfig' })
}
// 设置密码策略
export const setConfig = (data: PassWordConfigVO) => {
return request.post({ url: '/system/password/setConfig', data })
}
// 获取密码复杂度
export const getRuleList = () => {
return request.get({ url: '/system/password/getRuleList'})
}
// 验证密码是否过期
export const validateResetTime = (userId:number) => {
return request.get({ url: '/system/password/validateResetTime?userId=' + userId})
}

14
src/views/login/components/LoginForm.vue

@ -86,6 +86,7 @@ import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login'
import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
import { getCodeImg } from "@/api/login";
import * as PassWordApi from '@/api/system/password'
defineOptions({ name: 'LoginForm' })
@ -187,6 +188,19 @@ const handleLogin = async (params) => {
return
}
const res = await LoginApi.login(loginData.loginForm)
try{
await PassWordApi.validateResetTime(res.userId)
}catch (e) {
if (e.code === 1002000010) {
await ElMessageBox.alert(
'<strong>密码长时间未修改,存在安全隐患,请及时修改</strong>',
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
}
}
if (!res) {
getCode()
return

153
src/views/system/passwordRule/index.vue

@ -0,0 +1,153 @@
<template>
<!-- 搜索 -->
<div v-loading="loading" class="box">
<el-form ref="formSmsLogin" :model="data" :rules="rules" label-width="70px" size="large">
<div
class="title"
style="font-size: 20px; text-align: center; margin-bottom: 20px; font-weight: bold"
>密码策略</div
>
<el-row type="flex" justify="center" align="middle">
<el-col>
<el-form-item label="密码难度" prop="ruleLevel" align="center">
<el-select v-model="passwordConfig.ruleLevel" placeholder="请选择密码难度">
<el-option
v-for="item in ruleList"
:key="item.value"
:label="item.ruleLevel"
:value="item.ruleLevel"
/>
</el-select>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="试错次数" prop="tryCount">
<el-input-number
v-model="passwordConfig.tryCount"
:min="0"
:precision="0"
style="margin-right: 10px"
/>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="锁定时长" prop="lockMinutes">
<el-input-number
v-model="passwordConfig.lockMinutes"
:min="0"
:precision="0"
style="margin-right: 10px"
/>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="更新周期" prop="updatePeriod">
<el-input-number
v-model="passwordConfig.updatePeriod"
:min="0"
:precision="0"
style="margin-right: 10px"
/>
</el-form-item>
</el-col>
<el-col>
<el-form-item label="是否开启" prop="status">
<el-switch v-model="passwordConfig.status" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div class="dialog-footer">
<el-button
type="primary"
@click="handleUpdate"
style="width: 100%; height: 40px; line-height: 40px"
> </el-button
>
<el-button type="danger" @click="reset" style="width: 100%; height: 40px; line-height: 40px"
> </el-button
>
</div>
</div>
</template>
<script lang="ts" setup>
import * as api from '@/api/system/password'
defineOptions({ name: 'PasswordRule' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(false)
const rules = {
password: [required],
againPassword: [required]
}
const reset = () => {
passwordConfig.value = {
status: true,
ruleLevel: "简单",
ruleDesc: "",
tryCount: 3,
lockMinutes: 1,
updatePeriod: 1,
}
}
const passwordConfig = ref({
status: true,
ruleLevel: "简单",
ruleDesc: "",
tryCount: 3,
lockMinutes: 1,
updatePeriod: 1,
})
/** 查询配置 */
const getConfig = async () => {
loading.value = true
try {
passwordConfig.value = await api.getConfig()
} finally {
loading.value = false
}
}
const ruleList = ref([])
/** 获取规则等级 */
const getRuleList = async () => {
loading.value = true
try {
ruleList.value = await api.getRuleList()
} finally {
loading.value = false
}
}
/** 保存 */
const handleUpdate = async () => {
try {
loading.value = true
await api.setConfig(passwordConfig.value)
message.success(t('common.save'))
} catch {
}finally {
loading.value = false
}
}
/** 初始化 **/
onMounted(async () => {
getConfig()
getRuleList()
})
</script>
<style lang="scss" scoped>
.box {
margin: 50px auto;
width: 500px;
background: white;
padding: 20px;
border: 1px solid #dedede;
}
.dialog-footer {
display: flex;
width: 160px;
margin: 0 auto;
}
</style>
Loading…
Cancel
Save