Skip to content

Commit

Permalink
4/26
Browse files Browse the repository at this point in the history
  • Loading branch information
VCCICCV committed Apr 26, 2023
1 parent 20f43cd commit 623d508
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 293 deletions.
12 changes: 7 additions & 5 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ const routes = [
component: () => import("@/views/404.vue"),
},
];

const router = new VueRouter({
routes,
mode:'history',
});
router.beforeEach((to,from,next) =>{
if(to.path == '/login') next()
const admin = Cookies.get('admin')
if(!admin && to.path !=='/login')return next('/login') //强制退回到登录页面
next()
if (to.path === '/login' || to.path === '/forgetThePassword') { // 如果访问的是 login 或 forgetThePassword 页面,则直接放行
next()
} else {
const admin = Cookies.get('admin')
if (!admin) return next('/login') // 强制退回到登录页面
next()
}
})
export default router;
3 changes: 2 additions & 1 deletion src/views/admin/Add.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<el-form-item label="联系方式" prop="phone">
<el-input v-model="form.phone" placeholder="请输入联系方式"></el-input>
</el-form-item>
<el-form-item label="邮箱" prop="eamil">
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" placeholder="请输入邮箱"></el-input>
</el-form-item>
</el-form>
Expand Down Expand Up @@ -42,6 +42,7 @@ export default {
phone: [
{ validator: checkPhone, trigger: "blur" }
],
// email:[{}],
},
};
},
Expand Down
96 changes: 82 additions & 14 deletions src/views/admin/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
</div>
<el-table :data="tableData" stripe>
<el-table-column prop="id" label="编号" width="50"></el-table-column>
<el-table-column prop="username" label="用户名"></el-table-column>
<el-table-column prop="phone" label="联系方式"></el-table-column>
<el-table-column prop="email" label="邮箱"></el-table-column>
<el-table-column prop="createtime" label="创建时间"></el-table-column>
<el-table-column prop="updatetime" label="更新时间"></el-table-column>

<el-table-column label="操作">
<el-table-column prop="username" label="用户名" width="90"></el-table-column>
<el-table-column prop="phone" label="联系方式" width="110"></el-table-column>
<el-table-column prop="email" label="邮箱" width="210"></el-table-column>
<el-table-column prop="createtime" label="创建时间" width="100"></el-table-column>
<el-table-column prop="updatetime" label="更新时间" width="100"></el-table-column>
<el-table-column label="状态" width="100">
<template v-slot="scope">
<el-switch v-model="scope.row.status" @change="changeStatus(scope.row)" active-color="#13ce66"
inactive-color="#ff4949">
</el-switch>
</template>
</el-table-column>
<el-table-column label="操作" style="width: 300px;">
<template v-slot="scope">
<!-- <el-button type="primary">编辑</el-button> -->
<el-button type="primary" @click="$router.push('/editAdmin?id=' + scope.row.id)" size="mini">编辑</el-button>
<el-popconfirm title="确定删除?" @confirm="del(scope.row.id)">
<el-button type="danger" slot="reference" size="mini">删除</el-button>
</el-popconfirm>
<el-button style="margin-left: 5px" type="warning" @click="handleChangePass(scope.row)">修改密码</el-button>

</template>
</el-table-column>
Expand All @@ -33,34 +39,54 @@
@current-change="handleCurrentChange" layout="prev, pager, next" :total="total">
</el-pagination>
</div>
<!-- 弹窗 -->
<el-dialog title="修改密码" :visible.sync="dialogFormVisible" width="30%">
<el-form :model="form" label-width="100px" ref="formRef" :rules="rules">
<el-form-item label="新密码" prop="newPass">
<el-input v-model="form.newPass" autocomplete="off" show-password @keypress.enter.native="savePass"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消</el-button>
<el-button type="primary" @click="savePass">确 定</el-button>
</div>
</el-dialog>
</div>
</template>

<script>
// @ is an alias to /src
import request from '@/utils/request';
import Cookies from 'js-cookie';
export default {
name: "Admin",
name: "AdminList",
components: {
// HelloWorld
},
data() {
return {
admin: Cookies.get('admin') ? JSON.parse(Cookies.get('admin')) : {},
tableData: [],
total: 0,
form: {},
dialogFormVisible: false,
params: {
pageNum: 1,
pageSize: 10,
username: '',
phone: '',
email:''
email: ''
},
rules: {
newPass: [
{required: true, message: '请输入新密码', trigger: 'blur'},
{min: 3, max: 10, message: '长度在3-10个字符', trigger: 'blur'}
]
}
};
},
created() {
this.load()
},
methods: {
load() {
Expand All @@ -79,7 +105,7 @@ export default {
pageSize: 10,
username: '',
phone: '',
email:'',
email: '',
}
this.load()
},
Expand All @@ -89,7 +115,7 @@ export default {
this.load()
},
del(id) {
request.delete("/user/delete/" + id).then(res => {
request.delete("/admin/delete/" + id).then(res => {
if (res.code === '200') {
this.$notify.success('删除成功')
this.load()
Expand All @@ -98,6 +124,48 @@ export default {
}
})
},
// 管理员状态
changeStatus(row) {
if (this.admin.id === row.id && !row.status) {
row.status = true
this.$notify.warning('您的操作不合法')
return
}
request.put('/admin/update', row).then(res => {
if (res.code === '200') {
this.$notify.success('操作成功')
this.load()
} else {
this.$notify.error(res.msg)
}
})
},
handleChangePass(row) {
this.form = JSON.parse(JSON.stringify(row))
this.dialogFormVisible = true
},
savePass() {
this.$refs['formRef'].validate((valid) => {
if (valid) {
request.put('/admin/password', this.form).then(res => {
if (res.code === '200') {
this.$notify.success("修改成功")
// 当前修改的用户id 等于当前登录的管理员id,那么修改成功之后需要重新登录
if (this.form.id === this.admin.id) {
Cookies.remove('admin')
this.$router.push('/login')
} else {
this.load()
this.dialogFormVisible = false
}
} else {
this.$notify.error("修改失败")
}
})
}
})
},
// handleAccountAdd(row) {
// this.form = JSON.parse(JSON.stringify(row))
// this.dialogFormVisible = true
Expand Down
133 changes: 107 additions & 26 deletions src/views/login/ForgetThePassword.vue
Original file line number Diff line number Diff line change
@@ -1,37 +1,118 @@
<template>
<div>
<div class="input-div one">
<div class="i">
<i class="fas fa-user"></i>
</div>
<div class="div">
<input type="text" class="input" placeholder="邮箱">
</div>
<div style="width: 80%px; height: 50%; background-color: white; border-radius: 10px;
margin:auto; padding:50px">
<div style="margin: 30px; text-align: center; font-size: 30px; font-weight: bold; color: dodgerblue">登 录</div>
<el-form :model="admin" :rules="rules" ref="loginForm">
<el-form-item prop="username">
<el-input placeholder="请输入账号" prefix-icon="el-icon-user" size="medium"
v-model="admin.username"></el-input>
</el-form-item>
<el-form-item prop="email">
<el-input placeholder="请输入邮箱" show-password prefix-icon="el-icon-lock" size="medium"
v-model="admin.email"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input placeholder="请输入新密码" show-password prefix-icon="el-icon-lock" size="medium"
v-model="admin.email" @keypress.enter.native="login"></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input placeholder="请再次输入密码" show-password prefix-icon="el-icon-lock" size="medium"
v-model="admin.email" @keypress.enter.native="login"></el-input>
</el-form-item>
<el-form-item prop="验证码">
<el-input placeholder="请输入验证码" show-password prefix-icon="el-icon-lock" size="medium"
v-model="admin.email" @keypress.enter.native="login"></el-input>
</el-form-item>
<el-form-item>
<el-button style="width: 100%" size="medium" type="primary" @click="login" class="btn">更新</el-button>
</el-form-item>
</el-form>
</div>
<div class="input-div pass">
<div class="i">
<i class="fas fa-lock"></i>
</div>
<div class="div">
<input type="password" class="input" placeholder="新密码">
</div>
</div>
<div class="input-div verification">
<div class="i">
<i class="fas fa-lock"></i>
</div>
<div class="div">
<input type="verif" class="input" placeholder="验证码">
</div>
</div>
<input type="submit" class="btn" value="验证" />
</div>
<!-- <el-popconfirm title="确定重置为1234?" @confirm="handleResetPass(scope.row.id)">
<el-button type="warning" slot="reference" size="mini">重置</el-button>
</el-popconfirm> -->
</template>

<script lang="ts">
<script>
import request from "@/utils/request";
import Cookies from 'js-cookie'
export default {
name: "ForgetThePassword",
components: {},
data() {
return {
loginAdmin: {},
admin: {},
rules: {
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在3-10个字符', trigger: 'blur' }
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 3, max: 10, message: '长度在3-10个字符', trigger: 'blur' }
]
}
}
},
methods: {
login() {
this.$refs['loginForm'].validate((valid) => {
if (valid) {
// request.post('/admin/login', this.admin).then(res => {
// if (res.code === '200') {
// this.loginAdmin = res.data
// this.$notify.success("登录成功")
// Cookies.set('admin', JSON.stringify(this.loginAdmin))
// this.$router.push('/')
// } else {
// this.$notify.error(res.msg)
// }
// })
}
})
},
handleResetPass(id) {
request.put("/admin/resetPass/" + id).then(res => {
if (res.code === '200') {
this.$notify.success('重置成功')
// 重置的当前用户id
if (this.form.id === this.admin.id) {
Cookies.remove('admin')
this.$router.push('/login')
}
this.load()
} else {
this.$notify.error(res.msg)
}
})
},
}
};
</script>
<style scoped></style>
<style>
.btn {
display: block;
width: 100%;
height: 50px;
border-radius: 25px;
outline: none;
border: none;
background-image: linear-gradient(to right, #32be8f, #38d39f, #32be8f);
background-size: 200%;
font-size: 1.2rem;
color: #fff;
font-family: 'Poppins', sans-serif;
text-transform: uppercase;
margin: 1rem 0;
cursor: pointer;
transition: .5s;
}
.btn:hover {
background-position: right;
}
</style>
Loading

0 comments on commit 623d508

Please sign in to comment.