Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
gzydong committed Apr 10, 2021
1 parent 7e99dbd commit 75fe4c9
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 598 deletions.
4 changes: 3 additions & 1 deletion src/api/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export const ServeDownloadAnnex = (annex_id) => {
let link = document.createElement('a');
link.href = `${api}/api/v1/download/article-annex?annex_id=${annex_id}&token=${getToken()}`;
link.click();
} catch (e) {}
} catch (e) {
console.error(e)
}
}

//更新笔记标签服务接口
Expand Down
5 changes: 4 additions & 1 deletion src/components/editor/MeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export default {
ServeSendTalkImage(fileData)
.then(res => {
if (res.code == 200) ref.closeBox()
ref.loading = false
if (res.code == 200) {
ref.closeBox()
}
})
.finally(() => {
ref.loading = false
Expand Down
82 changes: 39 additions & 43 deletions src/main-mixin.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
import SocketInstance from './socket-instance';
import {
ServeGetUserSetting
} from "@/api/user";
import SocketInstance from './socket-instance'
import { ServeGetUserSetting } from '@/api/user'

export default {
created() {
// 判断用户是否登录
if (this.$store.getters.loginStatus) {
this.initialize();
}
created() {
// 判断用户是否登录
if (this.$store.getters.loginStatus) {
this.initialize()
}
},
methods: {
// 页面初始化设置
initialize() {
SocketInstance.connect()
this.loadUserSetting()
},
methods: {
// 页面初始化设置
initialize() {
SocketInstance.connect();
this.loadUserSetting();
},

// 加载用户相关设置信息,更新本地缓存
loadUserSetting() {
ServeGetUserSetting().then(res => {
if (res.code == 200) {
const {
user_info
} = res.data;
// 加载用户相关设置信息,更新本地缓存
loadUserSetting() {
ServeGetUserSetting().then(res => {
if (res.code == 200) {
const { user_info } = res.data

this.$store.commit('UPDATE_USER_INFO', {
uid: user_info.uid,
nickname: user_info.nickname,
sex: user_info.gender,
signature: user_info.motto,
avatar: user_info.avatar
});
}
});
},
this.$store.commit('UPDATE_USER_INFO', {
uid: user_info.uid,
nickname: user_info.nickname,
sex: user_info.gender,
signature: user_info.motto,
avatar: user_info.avatar,
})
}
})
},

// 跳转到指定好友对话页
dumpTalkPage(index_name) {
sessionStorage.setItem("send_message_index_name", index_name);
// 跳转到指定好友对话页
dumpTalkPage(index_name) {
sessionStorage.setItem('send_message_index_name', index_name)

if (this.$route.path == '/message') {
this.$root.$children[0].refreshView();
return;
}
if (this.$route.path == '/message') {
this.$root.$children[0].refreshView()
return
}

this.$router.push('/message');
}
}
}
this.$router.push('/message')
},
},
}
36 changes: 18 additions & 18 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'core-js/stable'
import 'regenerator-runtime/runtime'

import Vue from 'vue';
import App from '@/App';
import store from '@/store';
import router from '@/router';
import mixin from './main-mixin';
import Vue from 'vue'
import App from '@/App'
import store from '@/store'
import router from '@/router'
import mixin from './main-mixin'

import './core/lazy-use';
import './core/global-component';
import './core/filter';
import './core/directives';
import '@/permission';
import '@/icons';
import './core/lazy-use'
import './core/global-component'
import './core/filter'
import './core/directives'
import '@/permission'
import '@/icons'

// 引入自定义全局css
import '@/assets/css/global.less';
import '@/assets/css/global.less'

Vue.config.productionTip = false;
Vue.config.productionTip = false

const Instance = new Vue({
router,
store,
mixins: [mixin],
render: h => h(App)
}).$mount('#app');
render: h => h(App),
}).$mount('#app')

export default Instance;
export default Instance
40 changes: 20 additions & 20 deletions src/permission.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import router from '@/router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import config from '@/config/config';
import {
getToken
} from '@/utils/auth';
import router from '@/router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import config from '@/config/config'
import { getToken } from '@/utils/auth'

NProgress.configure({
showSpinner:false
});
showSpinner: false,
})

const WEBSITE_NAME = config.WEBSITE_NAME;
const WEBSITE_NAME = config.WEBSITE_NAME

// 登录用户强制重定向页面
const login_redirect = ['/login', '/register', '/forget'];
const redirect = ['/login', '/register', '/forget']

router.beforeEach((to, from, next) => {
document.title = to.meta.title ? `${WEBSITE_NAME} | ${to.meta.title}` : WEBSITE_NAME;
document.title = to.meta.title
? `${WEBSITE_NAME} | ${to.meta.title}`
: WEBSITE_NAME

// 如果有token说明该用户已登陆
if (getToken()) {
if (login_redirect.indexOf(to.path) >= 0) {
next('/');
if (redirect.indexOf(to.path) >= 0) {
next('/')
}
} else if (to.meta.needLogin) {
next('/login');
next('/login')
}

NProgress.start();
next();
});
NProgress.start()
next()
})

router.afterEach(() => {
NProgress.done();
});
NProgress.done()
})
Loading

0 comments on commit 75fe4c9

Please sign in to comment.