Vue考試系統(tǒng)的后臺(tái)管理功能開(kāi)發(fā)示例解讀
考試系統(tǒng)后臺(tái)管理項(xiàng)目介紹:
技術(shù)選型:Vue2.0+Elemenu-ui
項(xiàng)目功能介紹:
- 賬戶信息模塊:菜單權(quán)限、角色權(quán)限設(shè)置、角色權(quán)限分配、賬號(hào)設(shè)置、公司分組
- 考試管理模塊:新增/編輯/刪除考試試題、成績(jī)查看、閱卷評(píng)分、成績(jī)記錄、成績(jī)導(dǎo)出
- 題庫(kù)管理模塊:批量導(dǎo)入考題、批量刪除考題、編輯錄入考題、新增/編輯/刪除考試分類(lèi)
登錄界面
- 利用cookie實(shí)現(xiàn),實(shí)現(xiàn)記住密碼功能,下次打開(kāi)頁(yè)面自動(dòng)補(bǔ)全,設(shè)置有效期為7天;
- 賬號(hào)、密碼驗(yàn)證;
- 點(diǎn)擊登錄調(diào)用接口跳轉(zhuǎn)后臺(tái)首頁(yè)


login.vue組件代碼:
<template>
<div class="login-wrap">
<h2 class="title" style="color:#fff">考試系統(tǒng)后臺(tái)管理</h2>
<el-form label-position="left" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px"
class="demo-ruleForm login-container">
<h3 class="title">用戶登錄</h3>
<el-form-item prop="loginAccount">
<el-input type="text" v-model="ruleForm.loginAccount" auto-complete="off" placeholder="賬號(hào)"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" v-model="ruleForm.password" auto-complete="off" placeholder="密碼"></el-input>
</el-form-item>
<el-checkbox class="remember" v-model="rememberpwd">記住密碼</el-checkbox>
<el-form-item style="width:100%;">
<el-button type="primary" style="width:100%;" @click="submitForm('ruleForm'),loginIn('ruleForm')" :loading="logining">登錄</el-button>
</el-form-item>
</el-form>
<div class="copyright">版權(quán)********</div>
</div>
</template>data定義數(shù)據(jù):
rules定義賬號(hào)密碼驗(yàn)證規(guī)則,可自定義規(guī)則
data() {
return {
logining: false,
rememberpwd: false,
ruleForm: {
loginAccount: "",
password: ""
},
rules: {
loginAccount: [
{ required: true, message: "請(qǐng)輸入賬號(hào)", trigger: "blur" }
],
password: [{ required: true, message: "請(qǐng)輸入密碼", trigger: "blur" }]
}
};
},methods方法:
添加點(diǎn)擊鍵盤(pán)Enter的判斷,點(diǎn)擊之后觸發(fā)登錄,調(diào)用登錄接口
// 鍵盤(pán)enter注冊(cè)事件
loginIn(){
let keyCode = window.event.keyCode;
console.log(this.$route.path,"登錄path")
if(keyCode == 13 && this.$route.path=="/login"){
this.$refs.ruleForm.validate(valid => {
if (valid) {
this.logining = true;
this.loginFun();
} else {
this.$message.error("請(qǐng)輸入用戶名密碼!");
this.logining = false;
return false;
}
});
}else{
return;
}
},可以手動(dòng)點(diǎn)擊登錄調(diào)用登錄接口,也可以使用Enter鍵調(diào)用登錄
methods: {
// 獲取用戶名密碼
getuserpwd() {
// 如果緩存里面有記錄,就直接獲取登錄
if (getCookie("user") != "" && getCookie("pwd") != "") {
this.ruleForm.loginAccount = getCookie("user");
this.ruleForm.password = getCookie("pwd");
this.rememberpwd = true;
}
},
// 登錄方法封裝
async loginFun() {
const res = await login(this.ruleForm);
console.log(res, "res登錄");
if (res.code == 200) {
if (this.rememberpwd == true) {
//保存帳號(hào)到cookie,有效期7天
setCookie("user", this.ruleForm.loginAccount, 7);
//保存密碼到cookie,有效期7天
setCookie("pwd", this.ruleForm.password, 7);
} else {
delCookie("user");
delCookie("pwd");
}
setTimeout(() => {
this.logining = false;
this.$router.push("/first/first");
this.$message({
message: "登錄成功",
type: "success"
});
}, 1000);
} else {
this.$message.error(res.msg);
this.logining = false;
return false;
}
},
submitForm(ruleForm) {
this.$refs[ruleForm].validate(valid => {
if (valid) {
this.logining = true;
// 調(diào)用登錄接口
this.loginFun();
} else {
this.$message.error("請(qǐng)輸入用戶名密碼!");
this.logining = false;
return false;
}
});
},
// 鍵盤(pán)enter注冊(cè)事件
loginIn(){
let keyCode = window.event.keyCode;
console.log(this.$route.path,"登錄path")
if(keyCode == 13 && this.$route.path=="/login"){
this.$refs.ruleForm.validate(valid => {
if (valid) {
this.logining = true;
this.loginFun();
} else {
this.$message.error("請(qǐng)輸入用戶名密碼!");
this.logining = false;
return false;
}
});
}else{
return;
}
},
},點(diǎn)擊記住密碼方法調(diào)用:進(jìn)入到頁(yè)面進(jìn)行讀取
created() {
this.getuserpwd();
},鍵盤(pán)Enter事件監(jiān)聽(tīng):
mounted(){
window.addEventListener('keydown',this.loginIn);
},
destroyed(){
window.removeEventListener('keydown',this.loginIn,false);
}登錄接口引入:
import { login } from "../api/userMG";封裝的cookie方法引入:
import { setCookie, getCookie, delCookie } from "../utils/utils";utils.js公共方法:
/**
* 設(shè)置cookie
**/
function setCookie(name, value, day) {
let date = new Date();
date.setDate(date.getDate() + day);
document.cookie = name + '=' + value + ';expires=' + date;
};
/**
* 獲取cookie
**/
function getCookie(name) {
let reg = RegExp(name + '=([^;]+)');
let arr = document.cookie.match(reg);
if (arr) {
return arr[1];
} else {
return '';
}
};
/**
* 刪除cookie
**/
function delCookie(name) {
setCookie(name, null, -1);
};到此這篇關(guān)于Vue考試系統(tǒng)的后臺(tái)管理功能開(kāi)發(fā)示例解讀的文章就介紹到這了,更多相關(guān)Vue考試系統(tǒng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue 封裝防刷新考試倒計(jì)時(shí)組件的實(shí)現(xiàn)
- Vue3后臺(tái)管理系統(tǒng)之創(chuàng)建和配置項(xiàng)目
- VUE+element開(kāi)發(fā)后臺(tái)管理的搜索功能
- vue后臺(tái)管理如何配置動(dòng)態(tài)路由菜單
- Vue后臺(tái)管理系統(tǒng)之實(shí)現(xiàn)分頁(yè)功能示例
- Vue+Element的后臺(tái)管理框架的整合實(shí)踐
- vue后臺(tái)管理添加多語(yǔ)言功能的實(shí)現(xiàn)示例
- Vue 電商后臺(tái)管理項(xiàng)目階段性總結(jié)(推薦)
相關(guān)文章
Js+Ajax,Get和Post在使用上的區(qū)別小結(jié)
下面小編就為大家?guī)?lái)一篇Js+Ajax,Get和Post在使用上的區(qū)別小結(jié)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
JS實(shí)現(xiàn)禁止用戶使用Ctrl+鼠標(biāo)滾輪縮放網(wǎng)頁(yè)的方法
這篇文章主要介紹了JS實(shí)現(xiàn)禁止用戶使用Ctrl+鼠標(biāo)滾輪縮放網(wǎng)頁(yè)的方法,涉及javascript頁(yè)面元素與事件相關(guān)操作技巧,需要的朋友可以參考下2017-04-04
符合W3C網(wǎng)頁(yè)標(biāo)準(zhǔn)的iframe標(biāo)簽的使用方法
符合W3C網(wǎng)頁(yè)標(biāo)準(zhǔn)的iframe標(biāo)簽的使用方法...2007-07-07
javaScript 計(jì)算兩個(gè)日期的天數(shù)相差(示例代碼)
本篇文章主要介紹了javaScript 計(jì)算兩個(gè)日期的天數(shù)相差(示例代碼) 需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
JS代碼實(shí)現(xiàn)根據(jù)時(shí)間變換頁(yè)面背景效果
這篇文章主要介紹了JS代碼實(shí)現(xiàn)根據(jù)時(shí)間變換頁(yè)面背景效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友一起看下吧2016-06-06
第四篇Bootstrap網(wǎng)格系統(tǒng)偏移列和嵌套列
這篇文章主要介紹了Bootstrap網(wǎng)格系統(tǒng)偏移列和嵌套列的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
JS連接SQL數(shù)據(jù)庫(kù)與ACCESS數(shù)據(jù)庫(kù)的方法實(shí)例
這篇文章主要介紹了JS連接SQL數(shù)據(jù)庫(kù)與ACCESS數(shù)據(jù)庫(kù)的方法實(shí)例,有需要的朋友可以參考一下2013-11-11
關(guān)于TypeScript模塊導(dǎo)入的那些事
Typescrit的模塊機(jī)制與es6的模塊基本類(lèi)似,也提供了轉(zhuǎn)換為amd,es6,umd,commonjs,system的轉(zhuǎn)換,下面這篇文章就來(lái)給大家詳細(xì)介紹了關(guān)于TypeScript模塊導(dǎo)入的那些事,需要的朋友可以參考借鑒,下面來(lái)一起看看吧2018-06-06

