-
-
- MyGitHub
-
-
-
-
-
\ No newline at end of file
diff --git a/src/components/login.vue b/src/components/login.vue
new file mode 100644
index 0000000..199825a
--- /dev/null
+++ b/src/components/login.vue
@@ -0,0 +1,157 @@
+
+
+
+
+
+
+
+

+
+
+
+
+
Sign in to MyGithub
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Sign in
+ Forgot password?
+
+
+
+
+
+
+
+
+ New to GitHub?
+
+
+
+
+
+
+
+
+
+
+ >
+
+
\ No newline at end of file
diff --git a/src/main.js b/src/main.js
index a256d50..420afd2 100644
--- a/src/main.js
+++ b/src/main.js
@@ -15,6 +15,11 @@ import 'highlight.js/styles/googlecode.css' //样式文件
import {lineNumbersBlock} from '@/highlight/highlight-line-number'
import Vuetify from 'vuetify'
import vuetify from './plugins/vuetify'
+import store from "./store";
+
+import nprogress from 'nprogress'
+import 'nprogress/nprogress.css'
+nprogress.configure({ showSpinner: false });
Vue.directive('highlight', {
update(el){
@@ -33,6 +38,85 @@ Vue.directive('highlight', {
}
})
+// router.beforeEach(async (to, from, next) => {
+// if (to.path ==='/login') next();
+// let token = window.sessionStorage.getItem('TOKEN');
+// console.log("the token is ->");
+// console.log(token);
+// if(token) {
+// // 登录
+// if(to.path === '/login') {
+// // 登陆后访问登录页
+// next({path:from.path});
+// } else {
+// // 登陆后访问非登录页
+// if(store.state.userName === '') {
+// // 当空对象作为判断条件时,相当于true。当空对象与布尔值直接比较时,相当于true,但空数组与布尔值直接比较时是false
+// // 登录后访问非登录页,如果此时用户信息由于页面刷新,store为空需要再次请求后端,拿到用户信息
+// try {
+// await store.dispatch('getUserInfo');
+// next();
+// } catch (error) {
+// // token过期
+// await store.dispatch('userLogout');
+// next({path:'/login'});
+// }
+// } else {
+// // 登录后访问非登录页,无刷新操作
+// next();
+// }
+// }
+// } else {
+// // 未登录
+// Vue.prototype.$message({
+// type: "error",
+// message: "请先登录"
+// });
+// next('/login')
+// }
+// })
+
+
+const WhiteList = ["login","404"]
+router.beforeEach((to, from, next) => {
+ nprogress.start();
+ if (!WhiteList.includes(to.name)) {
+ let token = window.sessionStorage.getItem("Token")
+ console.log('now token is:')
+ console.log(token)
+ if (token) {
+ // if (!store.state.userName) {
+ // if (store.dispatch('getUserInfo')) {
+ // next()
+ // } else {
+ // Vue.prototype.$message({
+ // type: "error",
+ // message: "请先登录"
+ // });
+ // next('/login')
+ // }
+ // }
+ next()
+ } else {
+ Vue.prototype.$message({
+ type: "error",
+ message: "请先登录"
+ });
+ next('/login')
+ }
+ } else {
+ next()
+ }
+})
+
+router.afterEach(() => {
+ // 关闭进度条
+ nprogress.done()
+})
+
+
+
+
Vue.prototype.$http = axios
Vue.config.productionTip = false
@@ -41,10 +125,10 @@ Vue.use(uploader);
Vue.use(jQuery);
Vue.use(hljs);
Vue.use(Vuetify);
-// Vue.use(hljs.vuePlugin);
new Vue({
vuetify,
render: h => h(App),
- router: router
+ router: router,
+ store
}).$mount('#app')
diff --git a/src/mock/index.js b/src/mock/index.js
index c83af45..e07fc3a 100644
--- a/src/mock/index.js
+++ b/src/mock/index.js
@@ -45,7 +45,23 @@ let joey_userpage = Mock.mock({
"repoList": [{
"repoName": "OOAD_Project",
"permission": "public",
- "msg": "updated 1 days ago"
+ "msg": "updated 1 days ago",
+ "star": 2,
+ "fork": 1,
+ },
+ {
+ "repoName": "Demo",
+ "permission": "public",
+ "msg": "updated 1 days ago",
+ "star": 1,
+ "fork": 0,
+ },
+ {
+ "repoName": "Test",
+ "permission": "public",
+ "msg": "updated 1 days ago",
+ "star": 0,
+ "fork": 1,
},
],
@@ -56,6 +72,8 @@ let joey_repo_root = Mock.mock({
"display": /list/,
"branchList": [
{"branchName": "master"},
+ {"branchName": "public"},
+ {"branchName": "dev"},
],
"itemList": [
{
@@ -81,6 +99,8 @@ let joey_repo_src = Mock.mock({
"display": /list/,
"branchList": [
{"branchName": "master"},
+ {"branchName": "public"},
+ {"branchName": "dev"},
],
"itemList": [
{
@@ -102,6 +122,8 @@ let joey_repo_public = Mock.mock({
"display": /list/,
"branchList": [
{"branchName": "master"},
+ {"branchName": "public"},
+ {"branchName": "dev"},
],
"itemList": [
{
@@ -117,6 +139,8 @@ let joey_repo_mock = Mock.mock({
"display": /list/,
"branchList": [
{"branchName": "master"},
+ {"branchName": "public"},
+ {"branchName": "dev"},
],
"itemList": [
{
@@ -133,6 +157,8 @@ let joey_repo_components = Mock.mock({
"display": /list/,
"branchList": [
{"branchName": "master"},
+ {"branchName": "public"},
+ {"branchName": "dev"},
],
"itemList": [
{
@@ -148,39 +174,74 @@ let joey_repo_components = Mock.mock({
// Mock.mock('http://localhost:8080/UserPage/JoeyZi1', () => {
// return joey_userpage
// })
-
-
-// Mock.mock(RegExp('/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_components'), () => {
+// Mock.mock('http://localhost:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_components', () => {
// return joey_repo_components
// })
-
-// Mock.mock(RegExp('/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_mock'), () => {
+// Mock.mock('http://localhost:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_mock', () => {
// return joey_repo_mock
// })
-
-// Mock.mock(RegExp('/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src'), () => {
+// Mock.mock('http://localhost:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src', () => {
// return joey_repo_src
// })
-
-// Mock.mock(RegExp('/RepoBrowser/JoeyZi1/OOAD_Project/master/root_public'), () => {
+// Mock.mock('http://localhost:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_public', () => {
// return joey_repo_public
// })
+// Mock.mock('http://localhost:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root', () => {
+// console.log("mock info")
+// return joey_repo_root
+// })
-
-// Mock.mock(RegExp('/RepoBrowser/JoeyZi1/OOAD_Project/master/root'), () => {
+// Mock.mock('http://10.27.133.155:8080/UserPage/JoeyZi1', () => {
+// return joey_userpage
+// })
+// Mock.mock('http://10.27.133.155:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_components', () => {
+// return joey_repo_components
+// })
+// Mock.mock('http://10.27.133.155:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src_mock', () => {
+// return joey_repo_mock
+// })
+// Mock.mock('http://10.27.133.155:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_src', () => {
+// return joey_repo_src
+// })
+// Mock.mock('http://10.27.133.155:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root_public', () => {
+// return joey_repo_public
+// })
+// Mock.mock('http://10.27.133.155:8080/RepoBrowser/JoeyZi1/OOAD_Project/master/root', () => {
// console.log("mock info")
// return joey_repo_root
// })
+let img = Mock.mock({
+ "Img": "@Image('900x900','@color', 'Random Image')",
+})
+
+const Random = Mock.Random
+
+Mock.mock(RegExp('http://10.27.133.155:8080/mock/'), "get", (options) =>{
+ console.log('mock')
+ console.log(options);
+ console.log(options.url.split('/'));
+ var t = options.url.split('/')
+ var name = t[t.length-1]
+ console.log(name)
+ var temp = [];
+ temp.push("#");
+ for (let index = 0; index < name.length; index++) {
+ temp.push(parseInt(name[index].charCodeAt(0), 10).toString(16));
+ }
+ var s = String(temp.slice(0, 5).join('').slice(0, 4));
+ console.log(s)
+ return Mock.mock({
+ "Img": Random.image('500x500', s, '#fff',name),
+ });
+});
+
+
+//http://10.27.133.155:8080/mock/
let upload_response = Mock.mock({
"status": 200
-})
-
-// Mock.mock(RegExp('http://127.0.0.1:8081/upload'), () => {
-// console.log("accept file")
-// return upload_response
-// })
\ No newline at end of file
+})
\ No newline at end of file
diff --git a/src/router/index.js b/src/router/index.js
index 231c990..b5a1433 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -3,6 +3,8 @@ import Demo from '../components/Demo.vue'
import RepoBrowser from '../components/RepoBrowser.vue'
import UserPage from '../components/UserPage.vue'
import VueRouter from 'vue-router'
+import page404 from '../components/404.vue'
+import login from '../components/login.vue'
Vue.use(VueRouter)
@@ -10,7 +12,7 @@ const router = new VueRouter({
routes: [
{
path: '/',
- redirect: "UserPage/JoeyZi1"
+ redirect: "login"
},
{
path: '/UserPage/:userName',
@@ -22,6 +24,17 @@ const router = new VueRouter({
name: "RepoBrowser",
component: RepoBrowser
},
+ {
+ path: '/error',
+ component: page404,
+ name: "404",
+ hidden: true
+ },
+ {
+ path: '/login',
+ name: "login",
+ component: login
+ },
]
})
diff --git a/src/store/index.js b/src/store/index.js
new file mode 100644
index 0000000..1926fe1
--- /dev/null
+++ b/src/store/index.js
@@ -0,0 +1,90 @@
+import Vue from 'vue'
+import Vuex from 'vuex'
+import axios from '@/axios'
+Vue.use(Vuex)
+
+// 2. 创建对象
+const store = new Vuex.Store({
+ state:{
+ userName:'',
+ token: '',
+ },
+ mutations:{
+ edit(state, username){
+ state.userName = username
+ },
+ USERLOGIN(state,token){
+ state.token = token;
+ },
+ USERNAME(state,userName){
+ state.userName = userName;
+ },
+ },
+ actions:{
+ async userLogin(context,form){
+ var judge = false;
+ var token;
+ // 发送登录请求
+ await axios.get('/login/signin/'+ form.account + '/' + form.passWord).then((response)=>{
+ judge = response.Login
+ token = response.Token
+ })
+ if(judge) {
+ // 存放token
+ context.commit('USERLOGIN',token);
+ // localStorage.setItem('Token',token)
+ window.sessionStorage.removeItem('Token')
+ window.sessionStorage.setItem('Token', token)
+
+
+ //记录用户信息
+ context.commit('USERNAME', form.account);
+ return judge;
+ } else {
+ // 登录失败
+ return judge;
+ }
+ },
+
+ userLogout(context) {
+ return new Promise(resolve => {
+ context.commit('USERLOGIN', '');
+
+ // localStorage.removeItem('Token');
+ // console.log("--------after remove storage-------");
+ // console.log(localStorage.getItem('Token'));
+ // console.log("--------after remove storage-------");
+
+ context.commit('USERNAME', '');
+ window.sessionStorage.removeItem('Token');
+ resolve()
+ })
+
+ },
+
+ // getUserInfo() {
+ // let result = axios.get('/CheckToken').then((response)=>{
+ // context.commit('USERNAME',response.name);
+ // if (response.name === null || response.name === "" || response.name === undefined){
+ // return false
+ // } else {
+ // return true
+ // }
+ // }).catch(function (error) {
+ // return false
+ // });
+ // return false;
+ // }
+
+ },
+ getters:{
+
+ },
+ modules:{
+
+ }
+
+})
+
+// 3. 导出store对象
+export default store
\ No newline at end of file