2020-06-19 17:10:44 +08:00
|
|
|
<template>
|
2020-07-03 11:04:25 +08:00
|
|
|
<el-row justify="space-between" type="flex">
|
2020-08-04 21:50:59 +08:00
|
|
|
<el-col :span="24">
|
2020-08-21 15:26:04 +08:00
|
|
|
<el-col :xs="8" :sm="4" :md="4" :xl="3" style="padding-top: .5rem;">
|
2020-08-12 11:28:37 +08:00
|
|
|
<a class="navbar-brand" href="/" rel="nofollow">
|
2020-07-03 11:04:25 +08:00
|
|
|
<img src="@/assets/rymcu.png" alt="RYMCU" class="navbar-brand-img">
|
|
|
|
</a>
|
|
|
|
</el-col>
|
2020-11-30 23:56:08 +08:00
|
|
|
<el-col :xs="0" :sm="12" :md="8" :xl="8" style="text-align: center;">
|
|
|
|
<el-row type="flex" justify="center">
|
|
|
|
<el-col>
|
|
|
|
<el-menu :default-active="getActiveMenu" style="margin-top: -2px;border: 0;" mode="horizontal"
|
|
|
|
@select="handleSelectMenu">
|
|
|
|
<el-menu-item index="index">首页</el-menu-item>
|
|
|
|
<el-menu-item index="topic">专题</el-menu-item>
|
|
|
|
</el-menu>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
|
|
|
</el-col>
|
2020-07-03 11:04:25 +08:00
|
|
|
<el-col :xs="16" :sm="8" :md="6" :xl="3" style="padding-top: 1rem;">
|
2020-08-04 21:50:59 +08:00
|
|
|
<client-only>
|
|
|
|
<el-col v-if="user" style="text-align: right;">
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="padding-left: 10px;padding-right: 10px;" href="/article/post">发帖
|
2020-08-04 21:50:59 +08:00
|
|
|
</el-link>
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="padding-left: 10px;padding-right: 10px;">
|
2020-08-04 21:50:59 +08:00
|
|
|
<el-dropdown trigger="click" @command="handleCommand">
|
|
|
|
<el-badge :value="notificationNumbers" class="item">
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="font-size: 1.4rem;" class="el-icon-bell"></el-link>
|
2020-08-04 21:50:59 +08:00
|
|
|
</el-badge>
|
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
|
<el-dropdown-item v-for="notification in notifications" :key="notification.idNotification"
|
|
|
|
command="notification">{{ notification.dataSummary }}
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="notification">查看所有消息</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</el-dropdown>
|
|
|
|
</el-link>
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="margin-left: 10px;">
|
2020-08-04 21:50:59 +08:00
|
|
|
<el-dropdown trigger="click" @command="handleCommand">
|
|
|
|
<el-avatar v-if="avatarURL" size="small" :src="avatarURL"></el-avatar>
|
|
|
|
<el-avatar v-else size="small" src="https://static.rymcu.com/article/1578475481946.png"></el-avatar>
|
|
|
|
<el-dropdown-menu slot="dropdown">
|
|
|
|
<el-dropdown-item command="user" style="align-items: center;">
|
|
|
|
<el-avatar class="mr-3" v-if="avatarURL" size="small" style="margin-top: 1rem;"
|
|
|
|
:src="avatarURL"></el-avatar>
|
|
|
|
<el-avatar class="mr-3" v-else size="small" style="margin-top: 1rem;"
|
|
|
|
src="https://static.rymcu.com/article/1578475481946.png"></el-avatar>
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="margin-left: 10px;margin-bottom: 1rem;">{{ nickname }}</el-link>
|
2020-08-04 21:50:59 +08:00
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item v-if="hasPermissions" command="admin-dashboard">系统管理</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="user-info">资料与账号</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="drafts">我的草稿</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="logout" divided>退出登录</el-dropdown-item>
|
|
|
|
</el-dropdown-menu>
|
|
|
|
</el-dropdown>
|
|
|
|
</el-link>
|
|
|
|
</el-col>
|
|
|
|
<el-col v-else style="text-align: right;">
|
|
|
|
<nuxt-link to="/login">
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="margin-left: 10px;">登录</el-link>
|
2020-08-04 21:50:59 +08:00
|
|
|
</nuxt-link>
|
|
|
|
<nuxt-link to="/register">
|
2020-08-12 11:28:37 +08:00
|
|
|
<el-link rel="nofollow" :underline="false" style="margin-left: 10px;">注册</el-link>
|
2020-08-04 21:50:59 +08:00
|
|
|
</nuxt-link>
|
|
|
|
</el-col>
|
|
|
|
</client-only>
|
2020-07-03 11:04:25 +08:00
|
|
|
</el-col>
|
|
|
|
</el-col>
|
|
|
|
</el-row>
|
2020-06-19 17:10:44 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-08-06 15:44:29 +08:00
|
|
|
import { isBrowser } from '~/environment'
|
|
|
|
|
2020-07-03 11:04:25 +08:00
|
|
|
const Cookie = process.client ? require('js-cookie') : undefined
|
|
|
|
export default {
|
|
|
|
name: "MobileHeader",
|
|
|
|
computed: {
|
|
|
|
getActiveMenu() {
|
|
|
|
return this.$store.state.activeMenu;
|
|
|
|
},
|
2020-08-04 21:50:59 +08:00
|
|
|
user() {
|
2020-07-03 11:04:25 +08:00
|
|
|
return this.$store.state.oauth;
|
|
|
|
},
|
|
|
|
avatarURL() {
|
2020-08-06 15:44:29 +08:00
|
|
|
let _ts = this;
|
|
|
|
if (isBrowser) {
|
|
|
|
if (!_ts.$store.state.userInfo) {
|
|
|
|
let user = localStorage.getItem('user');
|
|
|
|
if (user) {
|
|
|
|
_ts.$store.commit('setUser', JSON.parse(user))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _ts.$store.state.userInfo?.avatarURL;
|
2020-07-03 11:04:25 +08:00
|
|
|
},
|
|
|
|
nickname() {
|
2020-08-06 15:44:29 +08:00
|
|
|
let _ts = this;
|
|
|
|
if (isBrowser) {
|
|
|
|
if (!_ts.$store.state.userInfo) {
|
|
|
|
let user = localStorage.getItem('user');
|
|
|
|
if (user) {
|
|
|
|
_ts.$store.commit('setUser', JSON.parse(user))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _ts.$store.state.userInfo?.nickname;
|
2020-07-03 11:04:25 +08:00
|
|
|
},
|
2021-03-26 10:44:54 +08:00
|
|
|
account() {
|
|
|
|
let _ts = this;
|
|
|
|
if (isBrowser) {
|
|
|
|
if (!_ts.$store.state.userInfo) {
|
|
|
|
let user = localStorage.getItem('user');
|
|
|
|
if (user) {
|
|
|
|
_ts.$store.commit('setUser', JSON.parse(user))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _ts.$store.state.userInfo?.account;
|
|
|
|
},
|
2020-07-03 11:04:25 +08:00
|
|
|
hasPermissions() {
|
|
|
|
return this.$store.getters.hasPermissions('blog_admin');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
restaurants: [],
|
|
|
|
state: '',
|
|
|
|
timeout: null,
|
|
|
|
show: false,
|
|
|
|
notifications: [],
|
|
|
|
notificationNumbers: ""
|
|
|
|
};
|
|
|
|
},
|
|
|
|
watch: {
|
2020-08-04 21:50:59 +08:00
|
|
|
user: function () {
|
2020-07-03 11:04:25 +08:00
|
|
|
this.getUnreadNotifications();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleSelectMenu(item) {
|
|
|
|
let _ts = this;
|
|
|
|
let activeMenu = _ts.$store.state.activeMenu;
|
|
|
|
if (activeMenu !== item) {
|
2020-08-04 21:50:59 +08:00
|
|
|
switch (item) {
|
|
|
|
case 'topic':
|
|
|
|
_ts.$router.push({
|
|
|
|
path: '/topic/news'
|
|
|
|
})
|
|
|
|
break;
|
|
|
|
case 'github':
|
|
|
|
window.open("https://github.com/rymcu");
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_ts.$router.push(
|
|
|
|
{
|
2020-09-21 15:05:10 +08:00
|
|
|
path: '/'
|
2020-06-19 17:10:44 +08:00
|
|
|
}
|
2020-08-04 21:50:59 +08:00
|
|
|
)
|
2020-07-03 11:04:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handleCommand(item) {
|
|
|
|
let _ts = this;
|
2020-08-04 21:50:59 +08:00
|
|
|
switch (item) {
|
|
|
|
case 'user':
|
|
|
|
_ts.$router.push({
|
2021-03-26 10:44:54 +08:00
|
|
|
path: '/user/' + _ts.account
|
2020-08-04 21:50:59 +08:00
|
|
|
})
|
|
|
|
break;
|
|
|
|
case 'user-info':
|
|
|
|
_ts.$router.push({
|
|
|
|
path: '/user/settings/account'
|
|
|
|
})
|
|
|
|
break;
|
|
|
|
case 'logout':
|
|
|
|
Cookie.remove('auth')
|
|
|
|
_ts.$store.commit('setAuth', null)
|
|
|
|
item = 'login';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_ts.$router.push({
|
|
|
|
name: item
|
|
|
|
})
|
2020-07-03 11:04:25 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
getUnreadNotifications() {
|
|
|
|
let _ts = this;
|
2020-08-04 21:50:59 +08:00
|
|
|
if (_ts.user) {
|
|
|
|
_ts.$axios.$get('/api/notification/unread').then(function (res) {
|
2020-07-03 11:04:25 +08:00
|
|
|
if (res) {
|
2020-08-04 21:50:59 +08:00
|
|
|
_ts.$set(_ts, 'notifications', res.notifications);
|
2021-12-21 19:51:47 +08:00
|
|
|
_ts.$set(_ts, 'notificationNumbers', res.pagination.total === 0 ? "" : res.pagination.total);
|
2020-07-03 11:04:25 +08:00
|
|
|
}
|
|
|
|
})
|
2020-06-19 17:10:44 +08:00
|
|
|
}
|
2022-01-14 10:38:55 +08:00
|
|
|
},
|
|
|
|
browserFingerprint() {
|
|
|
|
let _ts = this
|
|
|
|
let canvas = document.createElement('canvas');
|
|
|
|
let ctx = canvas.getContext('2d');
|
|
|
|
let txt = 'https://rymcu.com/';
|
|
|
|
ctx.textBaseline = "top";
|
|
|
|
ctx.font = "14px 'Arial'";
|
|
|
|
ctx.textBaseline = "rymcu";
|
|
|
|
ctx.fillStyle = "#f60";
|
|
|
|
ctx.fillRect(125,1,62,20);
|
|
|
|
ctx.fillStyle = "#069";
|
|
|
|
ctx.fillText(txt, 2, 15);
|
|
|
|
ctx.fillStyle = "rgba(102, 204, 0, 0.7)";
|
|
|
|
ctx.fillText(txt, 4, 17);
|
|
|
|
let b64 = canvas.toDataURL().replace("data:image/png;base64,","");
|
|
|
|
let bin = atob(b64);
|
|
|
|
let fingerprint = _ts.bin2hex(bin.slice(-16,-12));
|
|
|
|
_ts.$store.commit('setFingerprint', fingerprint);
|
|
|
|
},
|
|
|
|
bin2hex(str) {
|
|
|
|
let _ts = this
|
|
|
|
let result = "";
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
let c = str.charCodeAt(i);
|
|
|
|
// 高字节
|
|
|
|
result += _ts.byte2Hex(c >> 8 & 0xff);
|
|
|
|
// 低字节
|
|
|
|
result += _ts.byte2Hex(c & 0xff);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
byte2Hex(b) {
|
|
|
|
if (b < 0x10) {
|
|
|
|
return "0" + b.toString(16);
|
|
|
|
} else {
|
|
|
|
return b.toString(16);
|
|
|
|
}
|
2020-07-03 11:04:25 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
2022-01-14 10:38:55 +08:00
|
|
|
let _ts = this
|
|
|
|
let user = _ts.user;
|
2020-08-04 21:50:59 +08:00
|
|
|
if (user) {
|
2022-01-14 10:38:55 +08:00
|
|
|
_ts.getUnreadNotifications();
|
|
|
|
}
|
|
|
|
let fingerprint = _ts.$store.state.fingerprint
|
|
|
|
if (!fingerprint) {
|
|
|
|
_ts.browserFingerprint();
|
2020-07-03 11:04:25 +08:00
|
|
|
}
|
2020-06-19 17:10:44 +08:00
|
|
|
}
|
2020-07-03 11:04:25 +08:00
|
|
|
|
|
|
|
}
|
2020-06-19 17:10:44 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2020-07-03 11:04:25 +08:00
|
|
|
.navbar-brand {
|
|
|
|
color: inherit;
|
|
|
|
margin-right: 1rem;
|
|
|
|
font-size: 1.25rem;
|
|
|
|
white-space: nowrap;
|
|
|
|
font-weight: 600;
|
|
|
|
padding: 0;
|
|
|
|
transition: .3s opacity;
|
|
|
|
line-height: 2rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.navbar-brand-img {
|
|
|
|
height: 2rem;
|
|
|
|
line-height: 2rem;
|
|
|
|
vertical-align: bottom;
|
|
|
|
margin-right: .5rem;
|
|
|
|
width: auto;
|
|
|
|
}
|
2020-06-19 17:10:44 +08:00
|
|
|
</style>
|