用户登录问题修改

This commit is contained in:
jiang 2024-11-06 20:53:49 +08:00
parent 22d2c5dba1
commit 5ac47fa006
6 changed files with 758 additions and 3 deletions

View File

@ -0,0 +1,57 @@
import request from '@/utils/request'
// 查询【请填写功能名称】列表
export function listWhitelist(query) {
return request({
url: '/system/whitelist/list',
method: 'get',
params: query
})
}
// 查询【请填写功能名称】详细
export function getWhitelist(id) {
return request({
url: '/system/whitelist/' + id,
method: 'get'
})
}
// 新增【请填写功能名称】
export function addWhitelist(data) {
return request({
url: '/system/whitelist/add',
method: 'post',
data: data
})
}
// 修改【请填写功能名称】
export function updateWhitelist(data) {
return request({
url: '/system/whitelist/edit',
method: 'post',
data: data
})
}
// 删除【请填写功能名称】
export function delWhitelist(id) {
return request({
url: '/system/whitelist/' + id,
method: 'post'
})
}
export function updateSysIpWhitelistStatus(id,status) {
const data = {
id,
status
}
return request({
url: '/system/whitelist/updateSysIpWhitelistStatus',
method: 'post',
data: data
})
}

View File

@ -0,0 +1,187 @@
<template>
<div>
<div class="ipBox">
<el-input
@input="(e) => checkFormat(e, 'a')"
placeholder="0-255"
:maxlength="3"
v-model="ip.a"
size="small"
@blur="blur"
ref="ipa"
@focus="focus"
@keydown.enter.native="handleEnter(0)"
:disabled="disabled"
:validate-event="true"
></el-input>
<div>&bull;</div>
<el-input
@input="(e) => checkFormat(e, 'b')"
placeholder="0-255"
:maxlength="3"
v-model="ip.b"
size="small"
@blur="blur"
ref="ipb"
@focus="focus"
@keydown.enter.native="handleEnter(1)"
:disabled="disabled"
:validate-event="true"
></el-input>
<div>&bull;</div>
<el-input
@input="(e) => checkFormat(e, 'c')"
placeholder="0-255"
:maxlength="3"
v-model="ip.c"
size="small"
@blur="blur"
ref="ipc"
@focus="focus"
@keydown.enter.native="handleEnter(2)"
:disabled="disabled"
:validate-event="true"
></el-input>
<div>&bull;</div>
<el-input
@input="(e) => checkFormat(e, 'd')"
placeholder="0-255"
:maxlength="3"
v-model="ip.d"
style="margin-right: 0"
size="small"
@blur="blur"
ref="ipd"
@focus="focus"
:disabled="disabled"
:validate-event="true"
></el-input>
</div>
</div>
</template>
<script>
export default {
data() {
return {
ip: {
a: "",
b: "",
c: "",
d: "",
},
};
},
props: {
value: {
type: String,
default: "",
},
disabled: Boolean,
},
watch: {
value(val) {
if (val && val !== "" && this.isValidIPv4(val)) {
this.setIpFromString(val);
} else if (val === ""|| !val) {
this.ip = { a: "", b: "", c: "", d: "" };
}
},
},
created() {
if (this.isValidIPv4(this.value)) {
this.setIpFromString(this.value);
}
},
methods: {
// IPv4
setIpFromString(ip) {
const [a, b, c, d] = ip.split(".");
this.ip = { a, b, c, d };
},
// IPv4
isValidIPv4(ip) {
const ipv4Pattern = /^(\d{1,3}\.){3}\d{1,3}$/;
if (ipv4Pattern.test(ip)) {
const parts = ip.split(".");
return parts.every((part) => {
const num = parseInt(part, 10);
return num >= 0 && num <= 255 && (part === "0" || part[0] !== "0" || part.length === 1);
});
}
return false;
},
//
handleEnter(index) {
const nextIndex = index + 1;
if (nextIndex < 4) {
this.$refs[`ip${String.fromCharCode(97 + nextIndex)}`].focus(); // 97 'a' ASCII
}
},
// IPv4
getIpValue() {
return `${this.ip.a}.${this.ip.b}.${this.ip.c}.${this.ip.d}`;
},
//
focus() {
if (this.ip.a && this.ip.b && this.ip.c && this.ip.d) {
this.$emit("focus", this.getIpValue());
}
},
//
blur() {
if (this.ip.a && this.ip.b && this.ip.c && this.ip.d) {
this.$emit("blur", this.getIpValue());
}
},
//
checkFormat(item, value) {
let val = item.toString().replace(/[^0-9]/g, ""); //
val = parseInt(val, 10);
if (isNaN(val)) {
val = ""; //
} else {
val = Math.max(0, Math.min(255, val)); // 0 255
}
this.ip[value] = val;
let o = {
a: "b",
b: "c",
c: "d",
};
// 3
if (val && val.toString().length === 3 && value !== "d") {
this.$refs[`ip${o[value]}`].focus();
}
// input
if (this.isValidIPv4(this.getIpValue())) {
this.$emit("input", this.getIpValue());
}
},
},
};
</script>
<style lang="scss" scoped>
.ipBox {
display: flex;
align-items: flex-start;
}
.el-input {
margin: 0 4px;
width: 70px;
}
</style>

View File

@ -9,7 +9,7 @@ import { saveAs } from 'file-saver'
import { encryptCBC, decryptCBC } from '@/utils/aescbc' import { encryptCBC, decryptCBC } from '@/utils/aescbc'
import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm' import { decryptWithSM4, encryptWithSM4, hashWithSM3AndSalt } from '@/utils/sm'
const systemConfig = { const systemConfig = {
requestConfig: { encryptRequest: true, checkIntegrity: true, encryptResponse: true } requestConfig: { encryptRequest: false, checkIntegrity: false, encryptResponse: false }
}; };
let downloadLoadingInstance let downloadLoadingInstance

View File

@ -0,0 +1,501 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="IP地址" prop="ipAddress">
<el-input
v-model="queryParams.ipAddress"
placeholder="请输入IP地址"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="开始时间" prop="accessStartTime">
<el-date-picker clearable
v-model="queryParams.accessStartTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择允许访问的开始时间"
>
</el-date-picker>
</el-form-item>
<el-form-item label="结束时间" prop="accessEndTime">
<el-date-picker clearable
v-model="queryParams.accessEndTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="请选择允许访问的结束时间"
>
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['system:whitelist:add']"
>新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:whitelist:edit']"
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:whitelist:remove']"
>删除
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="whitelistList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column type="index" label="序号" width="50"/>
<el-table-column label="IP地址" align="center" prop="ipAddress">
<template slot-scope="scope">
<span> {{scope.row.ipAddress?scope.row.ipAddress:scope.row.ipRangeStart+" - " + scope.row.ipRangeEnd}} </span>
</template>
</el-table-column>
<el-table-column label="开放时间" align="center" prop="ipRangeStart">
<template slot-scope="scope">
<span> {{!scope.row.accessStartTime?"不限时间":parseTime(scope.row.accessStartTime,'{h}:{i}:{s}')+" - " + parseTime(scope.row.accessEndTime,'{h}:{i}:{s}')}} </span>
</template>
</el-table-column>
<el-table-column label="状态" align="center" key="status">
<template slot-scope="scope">
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1"
@change="handleStatusChange(scope.row)"
></el-switch>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:whitelist:edit']"
>修改
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:whitelist:remove']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改请填写功能名称对话框 -->
<el-dialog title="新增" :visible.sync="open" width="800px">
<el-form ref="form" :model="form" :rules="rules">
<!-- IP 地址选择 -->
<el-form-item label="IP地址" required>
<el-radio-group v-model="ipType">
<el-radio label="single">单IP地址</el-radio>
<el-radio label="range">IP地址段</el-radio>
</el-radio-group>
<el-row v-show="ipType === 'single'" :gutter="24">
<el-col :span="10">
<IpInput
style="margin-top: 10px"
v-model="form.ipAddress"
:disabled=false
/>
</el-col>
</el-row>
<el-row v-show="ipType === 'range'" :gutter="24">
<el-col :span="10">
<IpInput
v-model="form.ipRangeStart"
style="margin-top: 10px"
:disabled=false
/>
</el-col>
<el-col :span="1">
<div style="margin-top: 10px">
<span></span>
</div>
</el-col>
<el-col :span="10">
<IpInput
v-model="form.ipRangeEnd"
style="margin-top: 10px"
:disabled=false
/>
</el-col>
</el-row>
</el-form-item>
<!-- 访问时间设置 -->
<el-form-item label="设置访问时间" required>
<el-radio-group v-model="timeLimit">
<el-radio label="unlimited">不限时间</el-radio>
<el-radio label="limited">限制时间</el-radio>
</el-radio-group>
<el-row v-if="timeLimit === 'limited'" :gutter="24">
<el-col :span="10">
<el-time-picker
is-range
:editable=false
v-model="form.accessStartTime"
value-format="yyyy-MM-dd HH:mm:ss"
range-separator="至"
start-placeholder="开始时间"
end-placeholder="结束时间"
placeholder="选择时间范围"
>
</el-time-picker>
</el-col>
</el-row>
</el-form-item>
<!-- 确认与取消按钮 -->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="addSubmitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { addWhitelist, delWhitelist, getWhitelist, listWhitelist, updateWhitelist,updateSysIpWhitelistStatus } from '@/api/system/ipWhitelist'
import IpInput from '@/components/bonus/IpInput/index.vue'
import { parseTime } from '../../../utils/bonus'
import { changeUserStatus } from '@/api/system/user'
export default {
components: { IpInput },
name: 'Whitelist',
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
whitelistList: [],
//
title: '',
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
ipAddress: null,
ipRangeStart: null,
ipRangeEnd: null,
accessStartTime: null,
accessEndTime: null,
createdAt: null,
updatedAt: null
},
ipType: 'single',
timeLimit: 'unlimited',
//
form: {},
//
rules: {
ipAddress: [
{ required: true, message: '记录创建时间不能为空', trigger: 'blur' }
],
ipRangeStart: [
{ required: true, message: '记录更新时间不能为空', trigger: 'blur' }
],
ipRangeEnd: [
{ required: true, message: '记录更新时间不能为空', trigger: 'blur' }
]
}
}
},
created() {
this.getList()
},
methods: {
//
handleStatusChange(row) {
let text = row.status === '0' ? '启用' : '停用'
this.$modal.confirm('确认要"' + text + '吗?').then(function() {
return updateSysIpWhitelistStatus(row.id, row.status)
}).then(() => {
this.$modal.msgSuccess(text + '成功')
}).catch(function() {
row.status = row.status === '0' ? '1' : '0'
})
},
// HH:mm:ss
formatTime(timeStr) {
return new Date(`1970-01-01T${timeStr.slice(11)}`); //
},
parseTime,
/** 查询【请填写功能名称】列表 */
getList() {
this.loading = true
listWhitelist(this.queryParams).then(response => {
this.whitelistList = response.rows
this.total = response.total
this.loading = false
})
},
//
cancel() {
this.open = false
this.reset()
},
//
reset() {
this.form = {
id: null,
ipAddress: null,
ipRangeStart: null,
ipRangeEnd: null,
accessStartTime: null,
accessEndTime: null,
createdAt: null,
updatedAt: null
}
this.ipType ='single'
this.timeLimit = 'unlimited'
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm('queryForm')
this.handleQuery()
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset()
this.open = true
this.title = '添加【请填写功能名称】'
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset()
const id = row.id || this.ids
getWhitelist(id).then(response => {
this.form = response.data
if (!this.form.ipAddress){
this.ipType = 'range'
}else {
this.ipType = 'single'
}
if (!this.form.accessStartTime){
this.timeLimit = 'unlimited'
}else {
this.timeLimit = 'limited'
this.form.accessStartTime=[this.formatTime(this.form.accessStartTime), this.formatTime(this.form.accessEndTime)]
}
this.open = true
this.title = '修改'
})
},
addSubmitForm() {
if (this.ipType === 'single') {
if (!this.form.ipAddress) {
this.$modal.msgWarning('请输入正确的ip地址')
return
} else {
this.form.ipRangeStart = null
this.form.ipRangeEnd = null
}
} else {
if (!this.form.ipRangeStart || !this.form.ipRangeEnd) {
this.$modal.msgWarning('请输入正确的ip地址段')
return
} else {
if (!this.checkSameSubnet(this.form.ipRangeStart, this.form.ipRangeEnd)){
this.$modal.msgWarning('请输入正确的ip地址段')
return
}
if (!this.checkIpRangeValidity(this.form.ipRangeStart, this.form.ipRangeEnd)){
this.$modal.msgWarning('请输入正确的ip地址段')
return
}
this.form.ipAddress = null
}
}
if (this.timeLimit === 'limited') {
if (!this.form.accessStartTime){
this.$modal.msgWarning('请选择访问时间段')
return
}else {
const date = this.form.accessStartTime;
this.form.accessStartTime = date[0];
this.form.accessEndTime = date[1];
}
}else {
this.form.accessStartTime = null;
this.form.accessEndTime = null;
}
if (this.form.id != null) {
updateWhitelist(this.form).then(response => {
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addWhitelist(this.form).then(response => {
this.$modal.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
},
// IP
ipToBinary(ip) {
return ip
.split('.')
.map((octet) => ('00000000' + parseInt(octet, 10).toString(2)).slice(-8))
.join('')
},
// IPABC
getClass(ip) {
const firstOctet = parseInt(ip.split('.')[0], 10)
if (firstOctet >= 1 && firstOctet <= 127) return 'A'
if (firstOctet >= 128 && firstOctet <= 191) return 'B'
if (firstOctet >= 192 && firstOctet <= 223) return 'C'
return 'Unknown'
},
//
getDefaultSubnetMask(ip) {
const ipClass = this.getClass(ip)
switch (ipClass) {
case 'A':
return '255.0.0.0' // /8
case 'B':
return '255.255.0.0' // /16
case 'C':
return '255.255.255.0' // /24
default:
return null
}
},
// IP
applySubnetMask(ipBinary, subnetBinary) {
let network = ''
for (let i = 0; i < 32; i++) {
network += ipBinary[i] === subnetBinary[i] ? ipBinary[i] : '0'
}
return network
},
// IP
checkSameSubnet(ip1, ip2) {
const subnetMask = this.getDefaultSubnetMask(ip1)
if (!subnetMask) return false //
const ip1Binary = this.ipToBinary(ip1)
const ip2Binary = this.ipToBinary(ip2)
const subnetBinary = this.ipToBinary(subnetMask)
const ip1Network = this.applySubnetMask(ip1Binary, subnetBinary)
const ip2Network = this.applySubnetMask(ip2Binary, subnetBinary)
return ip1Network === ip2Network
},
// IP
checkIpRangeValidity(startIp, endIp) {
const startBinary = this.ipToBinary(startIp)
const endBinary = this.ipToBinary(endIp)
// IPIP
return startBinary <= endBinary
},
/** 提交按钮 */
submitForm() {
this.$refs['form'].validate(valid => {
if (valid) {
}
})
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids
this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?').then(function() {
return delWhitelist(ids)
}).then(() => {
this.getList()
this.$modal.msgSuccess('删除成功')
}).catch(() => {
})
},
/** 导出按钮操作 */
handleExport() {
this.download('system/whitelist/export', {
...this.queryParams
}, `whitelist_${new Date().getTime()}.xlsx`)
}
}
}
</script>
<style lang="scss" scoped>
.el-radio__original {
display: none !important; /* 隐藏原生 radio 输入,但仍然允许交互 */
}
.el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
box-shadow: none !important;
}
</style>

View File

@ -0,0 +1,11 @@
<script setup>
</script>
<template>
</template>
<style scoped lang="scss">
</style>

View File

@ -113,8 +113,7 @@
:options="menuOptions" :options="menuOptions"
:normalizer="normalizer" :normalizer="normalizer"
:show-count="true" :show-count="true"
:searchable="false" :searchable="true"
:disable-branch-nodes="true"
placeholder="选择上级菜单" placeholder="选择上级菜单"
/> />
</el-form-item> </el-form-item>