2022.8.3
This commit is contained in:
parent
5a013dce53
commit
84c917538c
10
resources/frontend/src/api/users.js
vendored
10
resources/frontend/src/api/users.js
vendored
@ -1,10 +0,0 @@
|
|||||||
import http from '@/util/http.js'
|
|
||||||
|
|
||||||
// 用户管理页面
|
|
||||||
export function users (data) {
|
|
||||||
return http({
|
|
||||||
url: '/api/users',
|
|
||||||
method: 'get',
|
|
||||||
data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
3
resources/frontend/src/main.js
vendored
3
resources/frontend/src/main.js
vendored
@ -6,6 +6,7 @@ import ElementUI from 'element-ui'
|
|||||||
import 'element-ui/lib/theme-chalk/index.css'
|
import 'element-ui/lib/theme-chalk/index.css'
|
||||||
import '@/css/style.css'
|
import '@/css/style.css'
|
||||||
import './router/index2'
|
import './router/index2'
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
|
||||||
// import Router from 'vue-router'
|
// import Router from 'vue-router'
|
||||||
@ -14,8 +15,8 @@ import './router/index2'
|
|||||||
// return routerPush.call(this, location).catch(error=> error)
|
// return routerPush.call(this, location).catch(error=> error)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Vue.use(ElementUI)
|
|
||||||
|
|
||||||
|
Vue.use(ElementUI)
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
new Vue({
|
new Vue({
|
||||||
|
|||||||
25
resources/frontend/src/router/index.js
vendored
25
resources/frontend/src/router/index.js
vendored
@ -1,12 +1,23 @@
|
|||||||
import Vue from 'vue'
|
import Vue from "vue";
|
||||||
import VueRouter from 'vue-router'
|
import VueRouter from "vue-router";
|
||||||
|
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
const createRouter = () =>
|
const createRouter = () =>
|
||||||
new VueRouter({
|
new VueRouter({
|
||||||
scrollBehavior: () => ({ y: 0 })
|
scrollBehavior: () => ({ y: 0 }),
|
||||||
})
|
});
|
||||||
|
|
||||||
const router = createRouter()
|
const router = createRouter();
|
||||||
export default router
|
|
||||||
|
router.beforeEach((to, from, next) => {
|
||||||
|
if (localStorage.getItem("token")) {
|
||||||
|
next();
|
||||||
|
} else if (to.fullPath === "/logo") {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
next("/logo");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
|
|||||||
9
resources/frontend/src/router/index1.js
vendored
9
resources/frontend/src/router/index1.js
vendored
@ -1,12 +1,3 @@
|
|||||||
/*
|
|
||||||
* @Description:
|
|
||||||
* @Author: czw (725551805@qq.com)
|
|
||||||
* @Date: 2022-02-25 10:40:17
|
|
||||||
* @LastEditors: czw (725551805@qq.com)
|
|
||||||
* @LastEditTime: 2022-03-01 20:29:32
|
|
||||||
* @FilePath: /glxt/src/router/index1.js
|
|
||||||
*/
|
|
||||||
|
|
||||||
const list = [
|
const list = [
|
||||||
{
|
{
|
||||||
path: '/logo',
|
path: '/logo',
|
||||||
|
|||||||
24
resources/frontend/src/store/index.js
vendored
24
resources/frontend/src/store/index.js
vendored
@ -1,15 +1,13 @@
|
|||||||
import Vue from 'vue'
|
import Vue from "vue";
|
||||||
import Vuex from 'vuex'
|
import Vuex from "vuex";
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex);
|
||||||
|
|
||||||
export default new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
state: {
|
state: {},
|
||||||
},
|
mutations: {},
|
||||||
mutations: {
|
actions: {},
|
||||||
},
|
modules: {},
|
||||||
actions: {
|
});
|
||||||
},
|
|
||||||
modules: {
|
export default store;
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
2
resources/frontend/src/util/auth.js
vendored
2
resources/frontend/src/util/auth.js
vendored
@ -1,7 +1,7 @@
|
|||||||
const TokenKey = 'admin_token'
|
const TokenKey = 'admin_token'
|
||||||
// 获取token
|
// 获取token
|
||||||
export function getToken () {
|
export function getToken () {
|
||||||
return localStorage.getItem(TokenKey)
|
return 'w1rr6IsxZIud46dIrGIivNAroFpqN52sSpXhk3azpPq2ZTbUXhgKTOLheoRm'
|
||||||
}
|
}
|
||||||
// 设置token
|
// 设置token
|
||||||
export function setToken (token) {
|
export function setToken (token) {
|
||||||
|
|||||||
@ -8,33 +8,113 @@
|
|||||||
>
|
>
|
||||||
</p>
|
</p>
|
||||||
<p class="title-1">登录</p>
|
<p class="title-1">登录</p>
|
||||||
<input type="text" placeholder="请输入用户名" />
|
<input type="text" placeholder="请输入用户名" v-model="form.name" />
|
||||||
<br />
|
<br />
|
||||||
<input type="text" placeholder="请输入密码" />
|
<input type="password" placeholder="请输入密码" v-model="form.password" />
|
||||||
<br />
|
<br />
|
||||||
<el-checkbox v-model="checked">记住密码</el-checkbox>
|
<el-checkbox v-model="checked">记住密码</el-checkbox>
|
||||||
<br />
|
<br />
|
||||||
<el-button type="primary">登录</el-button>
|
<el-button type="primary" @click="Login()">登录</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import axios from "axios";
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
checked: true, //记住密码变量
|
checked: false, //记住密码变量
|
||||||
form: {
|
form: {
|
||||||
add: "",
|
//用户名和密码
|
||||||
app: "",
|
name: "",
|
||||||
|
password: "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {}, // 计算机属性 类似与data概念
|
mounted() {
|
||||||
watch: {}, // 监控data中数据变化
|
this.getCookie();
|
||||||
created() {}, // 生命周期-创建完成(可以访问当前this实例)
|
},
|
||||||
mounted() {}, // 生命周期-挂载完成(可以访问DOM元素)
|
methods: {
|
||||||
methods: {},
|
Login() {
|
||||||
|
// 判断复选框是否被勾选 勾选则调用配置cookie方法
|
||||||
|
if (this.checked === true) {
|
||||||
|
this.setCookie(this.form.name, this.form.password, true, 7);
|
||||||
|
} else {
|
||||||
|
this.clearCookie();
|
||||||
|
}
|
||||||
|
//判断用户名和密码是否为空
|
||||||
|
if (this.form.name === "" || this.form.password === "") {
|
||||||
|
this.$message({
|
||||||
|
message: "账号或密码不能为空",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
axios
|
||||||
|
.post("/api/auth/login", this.form, {
|
||||||
|
headers: {
|
||||||
|
Authorization:
|
||||||
|
"Bearer w1rr6IsxZIud46dIrGIivNAroFpqN52sSpXhk3azpPq2ZTbUXhgKTOLheoRm",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
let data = res.data;
|
||||||
|
console.log(data);
|
||||||
|
if (data.error) {
|
||||||
|
this.$message({
|
||||||
|
message: "账号或密码错误,请重新输入",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
this.form.name = "";
|
||||||
|
this.form.password = "";
|
||||||
|
this.checked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.token) {
|
||||||
|
this.form = {};
|
||||||
|
localStorage.setItem("token", data.token);
|
||||||
|
this.$message({
|
||||||
|
message: "成功登录,欢迎来到后台管理系统",
|
||||||
|
type: "success",
|
||||||
|
});
|
||||||
|
this.$router.push("/USER_MANAGE");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 设置cookie
|
||||||
|
setCookie(c_name, c_pwd, c_state, exdays) {
|
||||||
|
const exdate = new Date();
|
||||||
|
exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); // 保存的天数
|
||||||
|
window.document.cookie =
|
||||||
|
"name" + "=" + c_name + ";path=/;expires=" + exdate.toGMTString();
|
||||||
|
window.document.cookie =
|
||||||
|
"password" + "=" + c_pwd + ";path=/;expires=" + exdate.toGMTString();
|
||||||
|
window.document.cookie =
|
||||||
|
"state" + "=" + c_state + ";path=/;expires=" + exdate.toGMTString();
|
||||||
|
},
|
||||||
|
// 读取cookie
|
||||||
|
getCookie() {
|
||||||
|
if (document.cookie.length > 0) {
|
||||||
|
const arr = document.cookie.split("; ");
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
const arr2 = arr[i].split("=");
|
||||||
|
// console.log(arr[2]);
|
||||||
|
if (arr2[0] === "name") {
|
||||||
|
this.form.name = arr2[1];
|
||||||
|
} else if (arr2[0] === "password") {
|
||||||
|
this.form.password = arr2[1];
|
||||||
|
} else if (arr2[0] === "state") {
|
||||||
|
this.checked = Boolean(arr2[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 清除cookie
|
||||||
|
clearCookie: function () {
|
||||||
|
this.setCookie("", "", false, -1);
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -8,18 +8,23 @@
|
|||||||
<el-dialog title="新增用户" :visible.sync="dialogVisible" width="30%">
|
<el-dialog title="新增用户" :visible.sync="dialogVisible" width="30%">
|
||||||
<div>
|
<div>
|
||||||
<el-form label-width="80px">
|
<el-form label-width="80px">
|
||||||
<el-form-item label="ID">
|
|
||||||
<el-input></el-input>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="姓名">
|
<el-form-item label="姓名">
|
||||||
<el-input></el-input>
|
<el-input v-model="from.name"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="密码">
|
||||||
|
<el-input v-model="from.password"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="确认密码">
|
||||||
|
<el-input v-model="from.password_confirmation"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色">
|
<el-form-item label="角色">
|
||||||
<el-input></el-input>
|
<el-input v-model="from.role_name"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<div class="from-btn">
|
<div class="from-btn">
|
||||||
<el-button type="danger">取消</el-button>
|
<el-button type="danger" @click="dialogVisible = false"
|
||||||
<el-button>确认</el-button>
|
>取消</el-button
|
||||||
|
>
|
||||||
|
<el-button @click="onSubmit">确认</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-form>
|
</el-form>
|
||||||
</div>
|
</div>
|
||||||
@ -53,19 +58,44 @@ export default {
|
|||||||
return {
|
return {
|
||||||
dialogVisible: false, //新增按钮变量
|
dialogVisible: false, //新增按钮变量
|
||||||
tableList: [], //列表数据
|
tableList: [], //列表数据
|
||||||
|
from: {
|
||||||
|
name: "",
|
||||||
|
password: "",
|
||||||
|
password_confirmation: "",
|
||||||
|
role_name: "超级管理员",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
//用户表单数据请求
|
//用户表单数据请求
|
||||||
axios({
|
axios
|
||||||
method: "get",
|
.get("api/users", {
|
||||||
params: {},
|
headers: {
|
||||||
url: "http://doc.ii090.com/mock/267/api/users",
|
Authorization:
|
||||||
}).then((res) => {
|
"Bearer w1rr6IsxZIud46dIrGIivNAroFpqN52sSpXhk3azpPq2ZTbUXhgKTOLheoRm",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
this.tableList = res.data.data;
|
this.tableList = res.data.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
onSubmit() {
|
||||||
|
axios
|
||||||
|
.post("/api/users", this.from, {
|
||||||
|
headers: {
|
||||||
|
Authorization:
|
||||||
|
"Bearer w1rr6IsxZIud46dIrGIivNAroFpqN52sSpXhk3azpPq2ZTbUXhgKTOLheoRm",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
console.log(res);
|
||||||
|
});
|
||||||
|
this.dialogVisible = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user