Skip to content

Commit 91d1432

Browse files
committed
add notice module
1 parent 19c7bfe commit 91d1432

8 files changed

Lines changed: 176 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
mv dist/ result/dist/
4646
mv images/ result/images/
4747
mv js/ result/js/
48-
mv background.html result/
4948
mv index.html result/
5049
mv manifest.json result/
5150
mv options.html result/

background.html

Lines changed: 0 additions & 11 deletions
This file was deleted.

dist/build.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/build.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/background.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
console.log('222');
1+
setInterval(() => {
2+
const date = new Date();
3+
const hour = date.getHours();
4+
const minute = date.getMinutes();
5+
noticeAlert(hour, minute);
6+
}, 60000);
7+
8+
// 发送闹钟提醒
9+
function noticeAlert(hour, minute) {
10+
chrome.storage.local.get(['noticeList'], (result) => {
11+
const res = result.noticeList;
12+
if (res !== undefined && res !== null && res !== '') {
13+
try {
14+
const rows = JSON.parse(res);
15+
console.log(rows);
16+
for (let i = 0; i < rows.length; i += 1) {
17+
if (rows[i].hour === hour || rows[i].hour === -1) {
18+
if (parseInt(rows[i].minute, 10) === minute) {
19+
chrome.notifications.create(null, {
20+
type: 'basic',
21+
iconUrl: './../images/icon.png',
22+
title: '知敏工具提醒您',
23+
message: rows[i].remark,
24+
});
25+
}
26+
}
27+
}
28+
} catch (e) {
29+
console.log(e);
30+
}
31+
}
32+
});
33+
}

manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "知敏工具",
33
"description": "This is zhimin chrome extension",
44
"version": "0.0.1",
5-
"manifest_version": 2,
5+
"manifest_version": 3,
66
"permissions": [
77
"alarms",
88
"tabs",
@@ -15,7 +15,7 @@
1515
"storage"
1616
],
1717
"background": {
18-
"page": "background.html"
18+
"service_worker": "js/background.js"
1919
},
2020
"icons":
2121
{
@@ -31,7 +31,7 @@
3131
}
3232
],
3333
"options_page": "options.html",
34-
"browser_action": {
34+
"action": {
3535
"default_icon" : "images/icon.png",
3636
"default_title": "知敏工具",
3737
"default_popup": "index.html"

src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
</div>
2323
</el-tab-pane>
2424
<el-tab-pane label="Json格式化" name="json"><Json :isFull = "isFull"/></el-tab-pane>
25-
<el-tab-pane label="链接" name="link"><Link /></el-tab-pane>
25+
<el-tab-pane label="提醒" name="link"><Notice /></el-tab-pane>
26+
<el-tab-pane label="链接" name="notice"><Link /></el-tab-pane>
2627
<el-tab-pane label="模拟请求" v-if="isFull" name="sim"><Sim /></el-tab-pane>
2728
<el-tab-pane label="JsonToGo" name="jsonToGo"><JsonToGo /></el-tab-pane>
2829
<el-tab-pane label="SqlToModel" name="sqlToModel"><SqlToModel /></el-tab-pane>
@@ -41,6 +42,7 @@ import JsonToGo from './components/JsonToGo.vue';
4142
import HtmlShow from './components/Html.vue';
4243
import Link from './components/Link.vue';
4344
import SqlToModel from './components/SqlToModel.vue';
45+
import Notice from './components/Notice.vue';
4446
4547
export default {
4648
name: 'app',
@@ -66,6 +68,7 @@ export default {
6668
HtmlShow,
6769
Link,
6870
SqlToModel,
71+
Notice,
6972
},
7073
};
7174
</script>

src/components/Notice.vue

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<template>
2+
<div class="notice-container">
3+
<div style="margin-bottom:10px;display: flex;justify-content: flex-end;">
4+
<el-button @click="editForm" v-if="disabledInput">编辑</el-button>
5+
<el-button @click="editFormCancel" v-if="!disabledInput">取消</el-button>
6+
<el-button @click="editFormSave" v-if="!disabledInput">保存</el-button>
7+
</div>
8+
<div v-for="(value,index) in timeList" :key="index" style="display:flex;margin-bottom:20px">
9+
<el-select v-model="value.hour" style="width:90px" placeholder="请选择"
10+
:disabled="disabledInput">
11+
<el-option
12+
v-for="item in options"
13+
:key="item.value"
14+
:label="item.label"
15+
:value="item.value">
16+
</el-option>
17+
</el-select>
18+
<el-input style="width:90px" :disabled="disabledInput" v-model="value.minute"
19+
@input="changeMinute(value.minute, index)" type="number"></el-input>
20+
<div class="center-item">分,将提醒您:</div>
21+
<el-input style="width:400px" :disabled="disabledInput"
22+
v-model="value.remark" placeholder="请输入备注,为空不保存哦!"></el-input>
23+
<i class="el-icon-delete" v-if="!disabledInput" @click="deleteThis(index)"></i>
24+
</div>
25+
</div>
26+
</template>
27+
<script>
28+
export default {
29+
data() {
30+
return {
31+
key: 'noticeList',
32+
timeList: [],
33+
tempList: [],
34+
disabledInput: false,
35+
options: [
36+
{ label: '每小时', value: -1 }, { label: '0点', value: 0 }, { label: '1点', value: 1 },
37+
{ label: '2点', value: 2 }, { label: '3点', value: 3 }, { label: '4点', value: 4 },
38+
{ label: '5点', value: 5 }, { label: '6点', value: 6 }, { label: '7点', value: 7 },
39+
{ label: '8点', value: 8 }, { label: '9点', value: 9 }, { label: '10点', value: 10 },
40+
{ label: '11点', value: 11 }, { label: '12点', value: 12 },
41+
{ label: '13点', value: 13 }, { label: '14点', value: 14 },
42+
{ label: '15点', value: 15 }, { label: '16点', value: 16 }, { label: '17点', value: 17 },
43+
{ label: '18点', value: 18 },
44+
{ label: '19点', value: 19 }, { label: '20点', value: 20 }, { label: '21点', value: 21 },
45+
{ label: '22点', value: 22 },
46+
{ label: '23点', value: 23 },
47+
],
48+
};
49+
},
50+
created() {
51+
this.disabledInput = true;
52+
const res = localStorage.getItem(this.key);
53+
if (res !== undefined && res !== null && res !== '') {
54+
try {
55+
this.timeList = JSON.parse(res);
56+
} catch (e) {
57+
console.log(e);
58+
}
59+
}
60+
},
61+
methods: {
62+
deleteThis(index) {
63+
this.timeList.splice(index, 1);
64+
},
65+
editForm() {
66+
if (this.timeList.length > 0) {
67+
this.tempList = JSON.parse(JSON.stringify(this.timeList));
68+
} else {
69+
this.tempList = [];
70+
}
71+
this.timeList.push({
72+
hour: -1,
73+
minute: 0,
74+
remark: '',
75+
});
76+
this.disabledInput = !this.disabledInput;
77+
},
78+
editFormCancel() {
79+
this.timeList = this.tempList;
80+
this.disabledInput = !this.disabledInput;
81+
},
82+
editFormSave() {
83+
const checkExistTime = {};
84+
for (let i = 0; i < this.timeList.length; i += 1) {
85+
if (checkExistTime[`${this.timeList[i].hour}_${this.timeList[i].minute}`] === undefined) {
86+
checkExistTime[`${this.timeList[i].hour}_${this.timeList[i].minute}`] = 0;
87+
}
88+
checkExistTime[`${this.timeList[i].hour}_${this.timeList[i].minute}`] += 1;
89+
}
90+
let checkOk = true;
91+
for (const key in checkExistTime) {
92+
if (checkExistTime[key] > 1) {
93+
checkOk = false;
94+
this.$message.error('时间有重复,请检查');
95+
}
96+
}
97+
if (!checkOk) {
98+
return;
99+
}
100+
const rows = [];
101+
for (let i = 0; i < this.timeList.length; i += 1) {
102+
if (this.timeList[i].remark !== '') {
103+
rows.push(this.timeList[i]);
104+
}
105+
}
106+
const jsonStr = JSON.stringify(rows);
107+
localStorage.setItem(this.key, jsonStr);
108+
this.timeList = rows;
109+
chrome.storage.local.set({ noticeList: jsonStr }, () => {
110+
console.log('ok');
111+
});
112+
this.disabledInput = !this.disabledInput;
113+
},
114+
changeMinute(val, index) {
115+
if (val > 60) {
116+
this.timeList[index].minute = 0;
117+
} else if (val < 0) {
118+
this.timeList[index].minute = 0;
119+
}
120+
},
121+
},
122+
};
123+
</script>
124+
<style lang="sass" scope>
125+
.notice-container
126+
font-size: 14px
127+
.center-item
128+
display: flex
129+
justify-content: center
130+
align-items: center
131+
</style>

0 commit comments

Comments
 (0)