parent
17c2d8a850
commit
239a69d724
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "io.yutent.gaystat",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"description": "搞基数据",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -1 +1 @@
|
|||
html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .sidebar{display:flex;flex-direction:column;justify-content:space-between;width:76px;height:100%;padding:48px 22px 24px;background:var(--color-dark-1);color:var(--color-plain-1)}.app .sidebar .item{cursor:pointer}.app .sidebar .item:hover,.app .sidebar .item.active{color:var(--color-orange-1)}.app .sidebar .item:active{color:var(--color-orange-2)}.app .select-box{display:flex;flex-direction:column;width:200px;height:100%;background:rgba(255,255,255,0.5)}.app .select-box .form{display:flex;align-items:center;width:100%;height:35px;padding:0 6px;background:#fff;border-bottom:1px solid var(--color-plain-2)}.app .select-box .form wc-input{flex:1}.app .select-box .list{flex:1}.app .select-box .list .item{display:flex;flex-direction:column;justify-content:center;height:48px;padding:6px;transition:color 0.15s ease-in-out, background 0.15s ease-in-out;cursor:pointer}.app .select-box .list .item section{display:flex;justify-content:space-between;align-items:center}.app .select-box .list .item cite{color:var(--color-grey-2)}.app .select-box .list .item .percent{padding:0 4px;border-radius:2px;font-size:12px;font-weight:bold;color:var(--color-grey-1)}.app .select-box .list .item .percent.red{color:var(--color-red-1)}.app .select-box .list .item .percent.green{color:var(--color-green-3)}.app .select-box .list .item:nth-child(odd){background:rgba(255,255,255,0.35)}.app .select-box .list .item:hover{color:var(--color-blue-1);background:rgba(255,255,255,0.35)}.app .select-box .list .item.active{color:var(--color-blue-3);background:rgba(255,255,255,0.7)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:#fff}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app .detail.blur::after{position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'';background:rgba(255,255,255,0.75);-webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)}.app .preferences{width:640px;height:360px;border-radius:10px}.app .preferences .titlebar{width:100%;height:72px;border-bottom:1px solid var(--color-plain-3);background:var(--color-plain-1)}.app .preferences .titlebar .title{width:100%;height:24px;line-height:24px;text-align:center}.app .preferences .titlebar nav{display:flex;width:100%;height:40px;padding:0 16px;--size: 18px}.app .preferences .titlebar nav span{display:flex;flex-direction:column;align-items:center;justify-content:center;width:52px;height:40px;margin:0 6px;border-radius:6px;font-size:12px}.app .preferences .titlebar nav span.active{background:var(--color-plain-2);color:var(--color-blue-1)}.app .preferences .titlebar nav span:hover{background:var(--color-plain-2)}.app .preferences .tab-panel{padding:64px}.app .preferences .tab-panel p{margin-bottom:16px}.app .preferences .tab-panel .field{display:flex;align-items:center;height:64px}.app .preferences .tab-panel .field .label{width:200px;color:var(--color-grey-1)}
|
||||
html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .sidebar{display:flex;flex-direction:column;justify-content:space-between;width:76px;height:100%;padding:48px 22px 24px;background:var(--color-dark-1);color:var(--color-plain-1)}.app .sidebar .item{cursor:pointer}.app .sidebar .item:hover,.app .sidebar .item.active{color:var(--color-orange-1)}.app .sidebar .item:active{color:var(--color-orange-2)}.app .select-box{display:flex;flex-direction:column;width:200px;height:100%;background:rgba(255,255,255,0.5)}.app .select-box .form{display:flex;align-items:center;width:100%;height:35px;padding:0 6px;background:#fff;border-bottom:1px solid var(--color-plain-2)}.app .select-box .form wc-input{flex:1}.app .select-box .list{flex:1}.app .select-box .list .item{display:flex;flex-direction:column;justify-content:center;height:48px;padding:6px;transition:color 0.15s ease-in-out, background 0.15s ease-in-out;cursor:pointer}.app .select-box .list .item section{display:flex;justify-content:space-between;align-items:center}.app .select-box .list .item cite{color:var(--color-grey-2)}.app .select-box .list .item .percent{padding:0 4px;border-radius:2px;font-size:12px;font-weight:bold;color:var(--color-grey-1)}.app .select-box .list .item .percent.red{color:var(--color-red-1)}.app .select-box .list .item .percent.green{color:var(--color-green-3)}.app .select-box .list .item:nth-child(odd){background:rgba(255,255,255,0.35)}.app .select-box .list .item:hover{color:var(--color-blue-1);background:rgba(255,255,255,0.35)}.app .select-box .list .item.active{color:var(--color-blue-3);background:rgba(255,255,255,0.7)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:#fff}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app .detail.blur::after{display:flex;justify-content:center;align-items:center;position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'搞基数据';background:#fff;color:#f7f8fb;font-size:100px}.app .preferences{width:640px;height:360px;border-radius:10px}.app .preferences .titlebar{width:100%;height:72px;border-bottom:1px solid var(--color-plain-3);background:var(--color-plain-1)}.app .preferences .titlebar .title{width:100%;height:24px;line-height:24px;text-align:center}.app .preferences .titlebar nav{display:flex;width:100%;height:40px;padding:0 16px;--size: 18px}.app .preferences .titlebar nav span{display:flex;flex-direction:column;align-items:center;justify-content:center;width:52px;height:40px;margin:0 6px;border-radius:6px;font-size:12px}.app .preferences .titlebar nav span.active{background:var(--color-plain-2);color:var(--color-blue-1)}.app .preferences .titlebar nav span:hover{background:var(--color-plain-2)}.app .preferences .tab-panel{padding:64px}.app .preferences .tab-panel p{margin-bottom:16px}.app .preferences .tab-panel .field{display:flex;align-items:center;height:64px}.app .preferences .tab-panel .field .label{width:200px;color:var(--color-grey-1)}.app.loading::after{display:flex;justify-content:center;align-items:center;position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'🌑';background:rgba(255,255,255,0.01);-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);color:var(--color-orange-1);font-size:50px;-webkit-animation:loading 1s infinite;animation:loading 1s infinite}@-webkit-keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}@keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}
|
||||
|
|
|
@ -176,15 +176,19 @@ body {
|
|||
|
||||
&.blur {
|
||||
&::after {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
content: '';
|
||||
background: rgba(255, 255, 255, 0.75);
|
||||
backdrop-filter: blur(10px);
|
||||
content: '搞基数据';
|
||||
background: #fff;
|
||||
color: #f7f8fb;
|
||||
font-size: 100px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -255,4 +259,52 @@ body {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.loading {
|
||||
&::after {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
content: '🌑';
|
||||
background: rgba(255, 255, 255, 0.01);
|
||||
backdrop-filter: blur(2px);
|
||||
color: var(--color-orange-1);
|
||||
font-size: 50px;
|
||||
animation: loading 1s infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
1%,
|
||||
100% {
|
||||
content: '🌑';
|
||||
}
|
||||
12.5% {
|
||||
content: '🌒';
|
||||
}
|
||||
25% {
|
||||
content: '🌓';
|
||||
}
|
||||
37.5% {
|
||||
content: '🌔';
|
||||
}
|
||||
50% {
|
||||
content: '🌕';
|
||||
}
|
||||
62.5% {
|
||||
content: '🌖';
|
||||
}
|
||||
75% {
|
||||
content: '🌗';
|
||||
}
|
||||
87.5% {
|
||||
content: '🌘';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</head>
|
||||
<body class="noselect">
|
||||
|
||||
<div class="app" anot="app">
|
||||
<div class="app" anot="app" :class="{loading: loading}">
|
||||
|
||||
<aside class="sidebar app-drag">
|
||||
<wc-icon class="app-nodrag item stat active" is="chart"></wc-icon>
|
||||
|
@ -63,7 +63,7 @@
|
|||
circle
|
||||
color="red"
|
||||
size="mini"
|
||||
@click="updateGay"
|
||||
@click="updateGays"
|
||||
icon="eye">
|
||||
</wc-button>
|
||||
</span>
|
||||
|
|
105
src/js/app.js
105
src/js/app.js
|
@ -35,6 +35,12 @@ function getLineStat(str) {
|
|||
})), e1: +syl_1y, e3: +syl_3y, e6: +syl_6y, e12: +syl_1n}`)()
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(_ => setTimeout(_, ms))
|
||||
}
|
||||
|
||||
window.app = app
|
||||
|
||||
Anot({
|
||||
$id: 'app',
|
||||
state: {
|
||||
|
@ -47,6 +53,7 @@ Anot({
|
|||
},
|
||||
list: [],
|
||||
$dict: {},
|
||||
loading: false,
|
||||
preferences: {
|
||||
tab: 1,
|
||||
notify: Anot.ls('notify') === '1'
|
||||
|
@ -63,28 +70,36 @@ Anot({
|
|||
},
|
||||
|
||||
mounted() {
|
||||
var gays = Anot.ls('gays') || '{}'
|
||||
var list = []
|
||||
var old = this.syncOldStat()
|
||||
|
||||
if (old === false) {
|
||||
gays = JSON.parse(gays)
|
||||
|
||||
for (let code in gays) {
|
||||
let { name, cm, cp, t } = gays[code]
|
||||
list.push({ code, name, cm, cp, t })
|
||||
this.$dict[code] = 1
|
||||
}
|
||||
list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
this.list = list
|
||||
this.reloadGays()
|
||||
}
|
||||
|
||||
if (this.preferences.notify) {
|
||||
app.dispatch('notify')
|
||||
}
|
||||
|
||||
app.on('data-reload', data => {
|
||||
this.reloadGays()
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
reloadGays() {
|
||||
var gays = Anot.ls('gays') || '{}'
|
||||
var list = []
|
||||
gays = JSON.parse(gays)
|
||||
|
||||
for (let code in gays) {
|
||||
let { name, cm, cp, t } = gays[code]
|
||||
list.push({ code, name, cm, cp, t: t || 0 })
|
||||
this.$dict[code] = 1
|
||||
}
|
||||
list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
this.list = list
|
||||
},
|
||||
|
||||
syncOldStat() {
|
||||
var old = Anot.ls('watch_list')
|
||||
var list = []
|
||||
|
@ -168,42 +183,49 @@ Anot({
|
|||
}
|
||||
},
|
||||
|
||||
updateGay() {
|
||||
async updateGays() {
|
||||
var { code, stat } = this.curr
|
||||
var info = this.getGayStat(code)
|
||||
|
||||
this.loading = true
|
||||
for (let it of this.list) {
|
||||
if (it.code === code) {
|
||||
let d
|
||||
//
|
||||
let info = this.getGayStat(it.code)
|
||||
let time, needUpdate
|
||||
|
||||
it.cm = +info.gsz
|
||||
it.cp = +info.gszzl
|
||||
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
|
||||
d = new Date(info.gztime.slice(0, 10) + ' 00:00:00')
|
||||
d = ~~(d.getTime() / 1000) - 24 * 3600
|
||||
time = new Date(info.gztime.slice(0, 10) + ' 00:00:00')
|
||||
time = ~~(time.getTime() / 1000) - 24 * 3600
|
||||
|
||||
// 如果走势最后的日期比当前最新的小, 则全量更新
|
||||
if (it.t < d) {
|
||||
Anot.ls(code, null)
|
||||
this.viewGay(it)
|
||||
console.log('update all stat...')
|
||||
return
|
||||
if (it.t < time) {
|
||||
it.t = time
|
||||
needUpdate = this.updateLine(it.code)
|
||||
}
|
||||
|
||||
if (it.code === code) {
|
||||
stat = JSON.parse(stat)
|
||||
stat.cm = it.cm
|
||||
stat.cp = it.cp
|
||||
if (needUpdate) {
|
||||
stat.rank = needUpdate.line.slice(-60).map(_ => _.p)
|
||||
stat.e1 = needUpdate.e1
|
||||
stat.e3 = needUpdate.e3
|
||||
stat.e6 = needUpdate.e6
|
||||
stat.e12 = needUpdate.e12
|
||||
this.curr.line = JSON.stringify(needUpdate.line)
|
||||
}
|
||||
this.curr.stat = JSON.stringify(stat)
|
||||
|
||||
this.saveCache()
|
||||
layer.toast('数据更新成功', 'success')
|
||||
}
|
||||
await sleep(500)
|
||||
}
|
||||
//
|
||||
this.loading = false
|
||||
Anot.ss('last_update', Date.now())
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
layer.toast('数据更新成功', 'success')
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
this.saveCache()
|
||||
},
|
||||
|
||||
removeGay() {
|
||||
|
@ -234,6 +256,16 @@ Anot({
|
|||
Anot.ls('gays', dict)
|
||||
},
|
||||
|
||||
updateLine(code) {
|
||||
var gay = app.dispatch(
|
||||
'fetch',
|
||||
`http://fund.eastmoney.com/pingzhongdata/${code}.js?v=${Date.now()}`
|
||||
)
|
||||
gay = getLineStat(gay)
|
||||
Anot.ls(code, JSON.stringify(gay))
|
||||
return gay
|
||||
},
|
||||
|
||||
viewGay(item) {
|
||||
var gay = Anot.ls(item.code)
|
||||
var rank, line
|
||||
|
@ -251,16 +283,9 @@ Anot({
|
|||
}
|
||||
|
||||
if (!gay) {
|
||||
gay = app.dispatch(
|
||||
'fetch',
|
||||
`http://fund.eastmoney.com/pingzhongdata/${
|
||||
item.code
|
||||
}.js?v=${Date.now()}`
|
||||
)
|
||||
gay = getLineStat(gay)
|
||||
gay = this.updateLine(item.code)
|
||||
item.t = gay.line[gay.line.length - 1].x
|
||||
this.saveCache()
|
||||
Anot.ls(item.code, JSON.stringify(gay))
|
||||
}
|
||||
|
||||
rank = gay.line.slice(-60).map(_ => _.p)
|
||||
|
|
|
@ -74,6 +74,7 @@ Anot({
|
|||
}
|
||||
this.list.sort((a, b) => b.cp - a.cp)
|
||||
this.saveCache()
|
||||
app.dispatch('data-reload')
|
||||
},
|
||||
saveCache() {
|
||||
var dict = {}
|
||||
|
|
30
src/main.js
30
src/main.js
|
@ -16,6 +16,8 @@ const path = require('path')
|
|||
const fs = require('iofs')
|
||||
|
||||
const { createMainWindow, createFloatWindow } = require('./tools/window')
|
||||
const createMenu = require('./tools/menu')
|
||||
const createTay = require('./tools/tray')
|
||||
|
||||
const MIME_TYPES = {
|
||||
'.js': 'text/javascript',
|
||||
|
@ -82,7 +84,7 @@ protocol.registerSchemesAsPrivileged([
|
|||
|
||||
/* ----------------------------------------------------- */
|
||||
|
||||
// app.dock.hide()
|
||||
app.dock.hide()
|
||||
|
||||
// 初始化应用
|
||||
app.once('ready', () => {
|
||||
|
@ -98,6 +100,9 @@ app.once('ready', () => {
|
|||
app.__main__ = createMainWindow(path.resolve(ROOT, './images/app.png'))
|
||||
app.__float__ = createFloatWindow()
|
||||
|
||||
createMenu(app.__main__)
|
||||
createTay(app.__float__, app.__main__)
|
||||
|
||||
app.__main__.on('closed', () => {
|
||||
app.__main__ = null
|
||||
app.__float__ = null
|
||||
|
@ -105,19 +110,22 @@ app.once('ready', () => {
|
|||
})
|
||||
|
||||
// mac专属事件,点击dock栏图标,可激活窗口
|
||||
app.on('activate', _ => {
|
||||
if (app.__main__) {
|
||||
app.__main__.restore()
|
||||
}
|
||||
})
|
||||
// app.on('activate', _ => {
|
||||
// if (app.__main__) {
|
||||
// app.__main__.restore()
|
||||
// }
|
||||
// })
|
||||
})
|
||||
|
||||
ipcMain.on('app', (ev, conn) => {
|
||||
if (conn.type === 'fetch') {
|
||||
switch (conn.type) {
|
||||
case 'fetch':
|
||||
fetch(conn.data).then(r => {
|
||||
ev.returnValue = r
|
||||
})
|
||||
} else if (conn.type === 'notify') {
|
||||
break
|
||||
|
||||
case 'notify':
|
||||
clearTimeout(timer)
|
||||
var t1 = Date.now()
|
||||
var t2 = new Date()
|
||||
|
@ -130,5 +138,11 @@ ipcMain.on('app', (ev, conn) => {
|
|||
}
|
||||
|
||||
ev.returnValue = true
|
||||
break
|
||||
|
||||
case 'data-reload':
|
||||
app.__main__.webContents.send('app', { type: 'data-reload', data: null })
|
||||
ev.returnValue = true
|
||||
break
|
||||
}
|
||||
})
|
||||
|
|
|
@ -4,18 +4,39 @@
|
|||
* @date 2020/12/10 19:30:20
|
||||
*/
|
||||
|
||||
const { Tray } = require('electron')
|
||||
const { Tray, Menu } = require('electron')
|
||||
const path = require('path')
|
||||
const ROOT = __dirname
|
||||
|
||||
module.exports = function(win) {
|
||||
win.__TRAY__ = new Tray(path.join(ROOT, '../images/tray.png'))
|
||||
module.exports = function(mini, main) {
|
||||
var menuList = Menu.buildFromTemplate([
|
||||
{
|
||||
label: '显示主窗口',
|
||||
click(a, b, ev) {
|
||||
main.restore()
|
||||
}
|
||||
},
|
||||
{
|
||||
label: '不搞基了',
|
||||
accelerator: 'Command+Q',
|
||||
click(a, b, ev) {
|
||||
main.destroy()
|
||||
}
|
||||
}
|
||||
])
|
||||
var tray = new Tray(path.join(ROOT, '../images/tray.png'))
|
||||
|
||||
win.__TRAY__.on('click', _ => {
|
||||
var b = win.__TRAY__.getBounds()
|
||||
win.setBounds({ x: b.x - 120, y: b.y + b.height })
|
||||
win.show()
|
||||
win.focus()
|
||||
win.webContents.send('app', { type: 'float-visible', data: null })
|
||||
tray.on('click', _ => {
|
||||
var b = tray.getBounds()
|
||||
mini.setBounds({ x: b.x - 120, y: b.y + b.height })
|
||||
mini.show()
|
||||
mini.focus()
|
||||
mini.webContents.send('app', { type: 'float-visible', data: null })
|
||||
})
|
||||
|
||||
tray.on('right-click', _ => {
|
||||
tray.popUpContextMenu(menuList)
|
||||
})
|
||||
|
||||
main.__tray__ = tray
|
||||
}
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
const { BrowserWindow } = require('electron')
|
||||
|
||||
const createMenu = require('./menu')
|
||||
const createTay = require('./tray')
|
||||
|
||||
/**
|
||||
* 应用主窗口
|
||||
*/
|
||||
|
@ -36,12 +33,10 @@ exports.createMainWindow = function(icon) {
|
|||
|
||||
win.loadURL('app://local/index.html')
|
||||
|
||||
createMenu(win)
|
||||
|
||||
win.on('ready-to-show', _ => {
|
||||
win.show()
|
||||
// win.on('ready-to-show', _ => {
|
||||
// win.show()
|
||||
// win.openDevTools()
|
||||
})
|
||||
// })
|
||||
|
||||
win.on('close', ev => {
|
||||
ev.preventDefault()
|
||||
|
@ -75,7 +70,6 @@ exports.createFloatWindow = function() {
|
|||
win.hide()
|
||||
})
|
||||
|
||||
createTay(win)
|
||||
win.loadURL('app://local/float.html')
|
||||
|
||||
return win
|
||||
|
|
Loading…
Reference in New Issue