Skip to content

Commit

Permalink
Merge pull request #3 from lndj/feature_setting
Browse files Browse the repository at this point in the history
Feature setting
  • Loading branch information
lndj authored Mar 11, 2020
2 parents acadd82 + 5d0eb1d commit 94ac35d
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"axios": "^0.19.0",
"js-cookie": "^2.2.1",
"moment": "^2.24.0",
"url-loader": "^3.0.0",
"vant": "^2.5.3",
"vue": "^2.6.10",
"vue-router": "^3.0.1",
Expand Down
Binary file added src/assets/images/avatar.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 38 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ global.browser = require('webextension-polyfill');

console.log(`Hello ${store.getters.foo}!`);

const NEW_POST_NOTICE_CONFIG_KEY = 'newPostNotice';
var latestObjectId = '';
var intervalId = null;

function autoCheck() {
console.log('正在执行新帖子检测....');
fetch('https://lcen.xiaote.net/api/v1/communities?page_index=1&page_size=10')
.then(function(response) {
if (response.status !== 200) {
Expand All @@ -31,9 +34,41 @@ function autoCheck() {
}

function init() {
autoCheck();
// 4min 执行一次
setInterval(autoCheck, 240000);
console.log('初始化后台事件....');
chrome.storage.sync.get(NEW_POST_NOTICE_CONFIG_KEY, config => {
if (config.newPostNotice) {
const openNewPostNitice = config.newPostNotice.openNewPostNitice;
const newPostNiticeDeltaMinute = config.newPostNotice.newPostNiticeDeltaMinute;
setIntervalNewPostNotice(openNewPostNitice, parseFloat(newPostNiticeDeltaMinute));
}
});

newPostNoticeConfigListener();
}

function setIntervalNewPostNotice(isOpen, deltaMinute){
if (!isOpen) {
console.log('当前没有开启最新帖子通知功能!');
return;
}
autoCheck();
const microTime = deltaMinute * 60 * 1000;
intervalId = setInterval(autoCheck, microTime);
}

function newPostNoticeConfigListener() {
chrome.storage.onChanged.addListener(function(changes, namespace) {
for (let key in changes) {
console.log('监测到 key 变动', key);
if (key === NEW_POST_NOTICE_CONFIG_KEY) {
const storageChange = changes[key];
const openNewPostNitice = storageChange.newValue.openNewPostNitice;
const newPostNiticeDeltaMinute = storageChange.newValue.newPostNiticeDeltaMinute;
setIntervalNewPostNotice(openNewPostNitice, parseFloat(newPostNiticeDeltaMinute));
return;
}
}
});
}

init();
12 changes: 7 additions & 5 deletions src/popup/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<router-view v-if="!$route.meta.keepAlive"></router-view>
</transition>

<tab v-show="getPath() !== '/comments'"></tab>
<tab v-show="isShowTab()"></tab>
</div>
</template>

Expand Down Expand Up @@ -41,10 +41,8 @@ export default {
} else {
this.transitionName = '';
}
console.log(this.transitionName);
// 单独的个人中心页面禁止页面滚动
if (to.path === '/home') {
// 单独的个人中心页面 & 设置页面禁止页面滚动
if (to.path === '/home' || to.path === '/settings' || to.path === '/about') {
window.addEventListener('scroll', noScroll);
} else {
window.removeEventListener('scroll', noScroll);
Expand All @@ -58,6 +56,10 @@ export default {
getPath() {
return this.$router.history.current.path;
},
isShowTab() {
const path = this.$router.history.current.path;
return path !== '/comments' && path !== '/settings' && path != '/about';
}
},
};
</script>
Expand Down
74 changes: 74 additions & 0 deletions src/popup/router/pages/About.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<template>
<div class="container">
<van-nav-bar title="小特社区" :fixed="true" left-arrow @click-left="onClickLeft" />
<div style="height:46px;"></div>

<div class="about-icon">
<van-image
round
width="8rem"
height="8rem"
:src="AvatarImage"
/>
</div>

<div class="about-block">

<span>本插件进攻学习交流,请勿用于其他用途。</span>
<span>代码:<a href="https://github.com/lndj/chrome-xiaote" target="_blank">https://github.com/lndj/chrome-xiaote</a></span>

<span style="font-size: 16px;">使用我的 Tesla 推荐码购车,你我均可获得 1500KM 的免费超充额度,邀请链接:<br /><br /> <a href="https://ts.la/lnanddj59482" target="_blank">点我去购买(lnanddj59482)</a></span>
</div>

<!-- <div style="height:46px;"></div> -->
</div>
</template>

<script>
import { mapGetters } from 'vuex';
import AvatarImage from '@/assets/images/avatar.jpeg';
export default {
name: 'About',
data() {
return {
AvatarImage: AvatarImage,
};
},
created() {
document.body.scrollTop = document.documentElement.scrollTop = 0;
},
computed: {
...mapGetters(['currentPost']),
},
filters: {
},
methods: {
onClickLeft() {
this.$router.go(-1);
},
},
};
</script>

<style lang="scss" scoped>
.about-block {
margin-top: 40px;
}
span {
font-size: 14px;
text-align: center;
display: block;
margin: 20px 20px 0 20px;
color: rgba(69, 90, 100, 0.6);
}
.about-icon {
text-align: center;
margin-top: 20px;
}
a {
color: rgba(10, 90, 200, 0.6);
}
</style>
30 changes: 18 additions & 12 deletions src/popup/router/pages/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div slot="header" class="panel-header">
<van-row gutter="40">
<van-col span="6">
<van-image style="margin-top:8px;margin-left:6px;" round width="4rem" height="4rem" :src="user.avatarUrl" />
<van-image style="margin-top:6px;margin-bottom:6px;margin-left:6px;" round width="3.8rem" height="3.8rem" :src="user.avatarUrl" />
</van-col>
<van-col span="12">
<div class="panel-header-nickname">{{ user.nickname }}</div>
Expand All @@ -22,31 +22,37 @@
</van-panel>

<div>
<van-row class="statistics-block" type="flex" justify="center">
<van-grid>
<van-grid-item><span class="statistics-num">8</span><span class="statistics-name">发布</span></van-grid-item>
<van-grid-item><span class="statistics-num">10</span><span class="statistics-name">获赞</span></van-grid-item>
<van-grid-item><span class="statistics-num">8</span><span class="statistics-name">关注</span></van-grid-item>
<van-grid-item><span class="statistics-num">800</span><span class="statistics-name">粉丝</span></van-grid-item>
</van-grid>
<!-- <van-row class="staistics-bltock" type="flex" justify="center">
<van-col span="5"><span class="statistics-num">8</span><span class="statistics-name">发布</span></van-col>
<van-col span="5"><span class="statistics-num">20</span><span class="statistics-name">获赞</span></van-col>
<van-col span="5"><span class="statistics-num">8</span><span class="statistics-name">关注</span></van-col>
<van-col span="5"><span class="statistics-num">100</span><span class="statistics-name">粉丝</span></van-col>
</van-row>
</van-row> -->
</div>


<van-cell title="消息通知" icon="more-o" is-link to="setting" />
<van-cell title="我的私信" icon="chat-o" is-link to="setting" />
<van-cell title="我的评论" icon="notes-o" is-link to="setting" />
<van-cell title="我的收藏" icon="star-o" is-link to="setting" />
<van-cell title="系统设置" icon="setting-o" is-link to="setting" />

<van-cell title="消息通知" icon="more-o" />
<van-cell title="我的私信" icon="chat-o" />
<van-cell title="我的评论" icon="notes-o" />
<van-cell title="我的收藏" icon="star-o" />
<van-cell title="系统设置" icon="setting-o" is-link to="settings" />
<van-cell title="关于" icon="label-o" is-link to="about" />

<!-- <div style="height:46px;"></div> -->
</div>
</template>

<script>
import { comments, read } from '../../../api/index';
import { comments, read } from '@/api/index';
import moment from 'moment';
import { mapGetters } from 'vuex';
import { ImagePreview, Dialog, Toast } from 'vant';
import AvatarImage from '@/assets/images/avatar.jpeg';
export default {
name: 'Home',
Expand All @@ -56,7 +62,7 @@ export default {
user: {
nickname: '一毛哥',
objectId: 'kodslkdlskdsdsdsdsd',
avatarUrl: 'http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqdrJIITE6f8xg0wYJyiaJdBPFLbe3tm8dPvlPHTF86TLo9fZG3K3yR5SaicicXfGE0ibgkR5xwo6ITvg/132',
avatarUrl: AvatarImage,
tag: '上海 * 未认证',
},
refreshing: false,
Expand Down
6 changes: 3 additions & 3 deletions src/popup/router/pages/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@
</template>

<script>
import { communities, recommends } from '../../../api/index';
import { communities, recommends } from '@/api/index';
import moment from 'moment';
import { ImagePreview, Dialog, Toast } from 'vant';
import Cookies from 'js-cookie';
import { formatContent } from '../../../utils/tools';
import { formatContent } from '@/utils/tools';
import { mapGetters } from 'vuex';
export default {
Expand Down Expand Up @@ -104,7 +104,7 @@ export default {
},
mounted() {
Toast.loading({
duration: 0,
duration: 6000,
message: 'Loading...',
forbidClick: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/popup/router/pages/Recommend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</template>

<script>
import { communities, recommends } from '../../../api/index';
import { communities, recommends } from '@/api/index';
import moment from 'moment';
import { ImagePreview, Dialog, Toast } from 'vant';
import Cookies from 'js-cookie';
Expand Down
98 changes: 98 additions & 0 deletions src/popup/router/pages/Settings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<template>
<div class="container">
<van-nav-bar title="小特社区" :fixed="true" left-arrow @click-left="onClickLeft" />
<div style="height:46px;"></div>

<div class="setting-block">
<div class="setting-block-title">
<p>新帖子通知</p>
</div>
<van-cell title="开启新帖子通知">
<van-switch v-model="openNewPostNitice" slot="right-icon" size="24" />
</van-cell>
<van-field
v-model="newPostNiticeDeltaMinute"
center
type="number"
:disabled="!openNewPostNitice"
clearable
label="间隔分钟"
placeholder="请输入分钟"
>
<van-button slot="button" size="small" type="primary" @click="saveNoticeConfig">保存</van-button>
</van-field>
</div>

<!-- <div style="height:46px;"></div> -->
</div>
</template>

<script>
import { mapGetters } from 'vuex';
import { Toast } from 'vant';
import AvatarImage from '@/assets/images/avatar.jpeg';
export default {
name: 'Settings',
data() {
return {
openNewPostNitice: null,
newPostNiticeDeltaMinute: 5,
};
},
created() {
this.getNoticeConfig();
document.body.scrollTop = document.documentElement.scrollTop = 0;
},
computed: {
...mapGetters(['currentPost']),
},
filters: {
},
methods: {
saveNoticeConfig() {
const config = {
openNewPostNitice: this.openNewPostNitice,
newPostNiticeDeltaMinute: parseFloat(this.newPostNiticeDeltaMinute),
};
chrome.storage.sync.set({'newPostNotice': config}, function() {
Toast.success('配置保存成功');
});
},
getNoticeConfig() {
chrome.storage.sync.get('newPostNotice', config => {
if (config.newPostNotice) {
this.openNewPostNitice = config.newPostNotice.openNewPostNitice;
this.newPostNiticeDeltaMinute = config.newPostNotice.newPostNiticeDeltaMinute;
}
});
},
formatter(value) {
return value + ' 分钟';
},
onClickLeft() {
this.$router.go(-1);
},
},
};
</script>

<style lang="scss" scoped>
.setting-block-title {
margin: 0;
padding: 32px 12px 16px;
color: rgba(69, 90, 100, 0.6);
font-weight: normal;
font-size: 14px;
line-height: 8px;
}
.statistics-name {
display: block;
text-align: center;
font-size: 14px;
font-weight: 100;
color: gray;
}
</style>
16 changes: 16 additions & 0 deletions src/popup/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import PageIndex from './pages/Index';
import PageRecommends from './pages/Recommend';
import UserHome from './pages/Home';
import Comments from './pages/Comments';
import Settings from './pages/Settings';
import About from './pages/About';

export default [
{
Expand Down Expand Up @@ -32,4 +34,18 @@ export default [
keepAlive: false,
},
},
{
path: '/settings',
component: Settings,
meta: {
keepAlive: true,
},
},
{
path: '/about',
component: About,
meta: {
keepAlive: true,
},
},
];
Loading

0 comments on commit 94ac35d

Please sign in to comment.