ADD 无操作自动登出 默认关闭

This commit is contained in:
sc 2022-11-09 09:35:00 +08:00
parent 43219b8402
commit 1908e5e9bf
3 changed files with 89 additions and 3 deletions

View File

@ -187,6 +187,8 @@
<el-drawer title="布局实时演示" v-model="settingDialog" :size="400" append-to-body destroy-on-close>
<setting></setting>
</el-drawer>
<auto-exit></auto-exit>
</template>
<script>
@ -197,6 +199,7 @@
import userbar from './components/userbar.vue';
import setting from './components/setting.vue';
import iframeView from './components/iframeView.vue';
import autoExit from './other/autoExit.js';
export default {
name: 'index',
@ -207,7 +210,8 @@
NavMenu,
userbar,
setting,
iframeView
iframeView,
autoExit
},
data() {
return {

View File

@ -0,0 +1,51 @@
export default {
render() {
},
data() {
return {
logoutCount: this.$TOOL.data.get('AUTO_EXIT')
}
},
mounted() {
if(this.logoutCount){
this.setNewAutoExitTime()
document.onclick = () => {
this.setNewAutoExitTime()
}
document.onmousemove = () => {
this.setNewAutoExitTime()
}
document.onkeydown = () => {
this.setNewAutoExitTime()
}
document.onscroll = () => {
this.setNewAutoExitTime()
}
window.autoExitTimer = window.setInterval(this.autoExitfun, 1000)
}
},
unmounted() {
if(this.logoutCount){
clearInterval(window.autoExitTimer)
window.autoExitTimer = null
}
},
methods: {
setNewAutoExitTime(){
window.autoExitTime = new Date().getTime()
},
autoExitfun(){
if(new Date().getTime() - window.autoExitTime > this.logoutCount * 60 * 1000){
clearInterval(window.autoExitTimer)
window.autoExitTimer = null
this.$router.replace({path: '/login'})
this.$alert("用户长时间无操作,为保证账户安全,系统已自动登出。", "提示", {
type: 'warning',
center: true,
roundButton: true
})
}
}
}
}

View File

@ -17,6 +17,29 @@
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" header="个人设置" style="margin-top:20px;">
<el-form ref="form" label-width="120px" style="margin-top:20px;">
<el-form-item label="自动登出">
<el-select v-model="config.autoExit">
<el-option label="从不" :value="0"></el-option>
<el-option label="1分钟" :value="1"></el-option>
<el-option label="5分钟" :value="5"></el-option>
<el-option label="10分钟" :value="10"></el-option>
<el-option label="15分钟" :value="15"></el-option>
<el-option label="20分钟" :value="20"></el-option>
<el-option label="25分钟" :value="25"></el-option>
<el-option label="30分钟" :value="30"></el-option>
<el-option label="35分钟" :value="35"></el-option>
<el-option label="40分钟" :value="40"></el-option>
<el-option label="45分钟" :value="45"></el-option>
<el-option label="50分钟" :value="50"></el-option>
<el-option label="55分钟" :value="55"></el-option>
<el-option label="60分钟" :value="60"></el-option>
</el-select>
<div class="el-form-item-msg">自动登出设置将在下次登录时生效</div>
</el-form-item>
</el-form>
</el-card>
</template>
<script>
@ -29,7 +52,8 @@
config: {
lang: this.$TOOL.data.get('APP_LANG') || this.$CONFIG.LANG,
dark: this.$TOOL.data.get('APP_DARK') || false,
colorPrimary: this.$TOOL.data.get('APP_COLOR') || this.$CONFIG.COLOR || '#409EFF'
colorPrimary: this.$TOOL.data.get('APP_COLOR') || this.$CONFIG.COLOR || '#409EFF',
autoExit: this.$TOOL.data.get('AUTO_EXIT') || 0,
}
}
},
@ -60,7 +84,14 @@
document.documentElement.style.setProperty(`--el-color-primary-dark-${i}`, colorTool.darken(val,i/10));
}
this.$TOOL.data.set("APP_COLOR", val);
}
},
'config.autoExit'(val){
if(val == 0){
this.$TOOL.data.remove("AUTO_EXIT")
}else{
this.$TOOL.data.set("AUTO_EXIT", val)
}
},
},
}
</script>