Skip to content

Commit afbe0bb

Browse files
committed
更新[chavy.box.js]: 增加 BoxJs 悬浮图标, 可导出所有由 BoxJs 管理的数据
1 parent b0e1fa1 commit afbe0bb

1 file changed

Lines changed: 114 additions & 25 deletions

File tree

‎chavy.box.js‎

Lines changed: 114 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ function getSystemCfgs() {
6464
id: 'Orz-3',
6565
icon: 'https://raw.githubusercontent.com/Orz-3/task/master/Orz-3.png',
6666
repo: 'https://github.com/Orz-3/'
67+
},
68+
boxjs: {
69+
id: 'BoxJs',
70+
show: false,
71+
icon: 'https://raw.githubusercontent.com/Orz-3/task/master/box.png',
72+
repo: 'https://github.com/chavyleung/scripts'
6773
}
6874
}
6975
}
@@ -411,32 +417,36 @@ function handleApi() {
411417
}
412418
}
413419

414-
function handleApp(appId) {
415-
const box = {
420+
function getBoxData() {
421+
return {
416422
sessions: getSessions(),
417423
sysapps: getSystemApps(),
418424
userapps: getUserApps(),
419425
syscfgs: getSystemCfgs(),
420426
usercfgs: getUserCfgs(),
421427
colors: getSystemThemes()
422428
}
429+
}
430+
431+
function handleApp(appId) {
432+
const box = getBoxData()
423433
const curapp = appId ? box.sysapps.find((app) => app.id === appId) : null
424434
$.html = printHtml(JSON.stringify(box), JSON.stringify(curapp))
425-
console.log($.html)
435+
if (box.usercfgs.isDebugFormat) {
436+
console.log(printHtml(`'\${data}'`, `'\${curapp}'`))
437+
} else if (box.usercfgs.isDebugData) {
438+
console.log($.html)
439+
}
426440
}
427441

428442
function handleHome() {
429-
$.html = printHtml(
430-
JSON.stringify({
431-
sessions: getSessions(),
432-
sysapps: getSystemApps(),
433-
userapps: getUserApps(),
434-
syscfgs: getSystemCfgs(),
435-
usercfgs: getUserCfgs(),
436-
colors: getSystemThemes()
437-
})
438-
)
439-
console.log($.html)
443+
const box = getBoxData()
444+
$.html = printHtml(JSON.stringify(box))
445+
if (box.usercfgs.isDebugFormat) {
446+
console.log(printHtml(`'\${data}'`, `'\${curapp}'`))
447+
} else if (box.usercfgs.isDebugData) {
448+
console.log($.html)
449+
}
440450
}
441451

442452
function printHtml(data, curapp = null) {
@@ -446,9 +456,9 @@ function printHtml(data, curapp = null) {
446456
<head>
447457
<title>BoxJs</title>
448458
<meta charset="utf-8" />
449-
<link rel="Bookmark" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png">
450-
<link rel="shortcut icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png">
451-
<link rel="apple-touch-icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png"/>
459+
<link rel="Bookmark" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
460+
<link rel="shortcut icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
461+
<link rel="apple-touch-icon" href="https://raw.githubusercontent.com/chavyleung/scripts/master/BOXJS.png" />
452462
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet" />
453463
<link href="https://cdn.jsdelivr.net/npm/@mdi/font@5.x/css/materialdesignicons.min.css" rel="stylesheet" />
454464
<link href="https://cdn.jsdelivr.net/npm/vuetify@2.x/dist/vuetify.min.css" rel="stylesheet" />
@@ -471,7 +481,7 @@ function printHtml(data, curapp = null) {
471481
<v-menu bottom left v-else-if="['app', 'home', 'log', 'data'].includes(ui.curview) && box.syscfgs.env !== ''">
472482
<template v-slot:activator="{ on }">
473483
<v-btn icon v-on="on">
474-
<v-avatar size="24">
484+
<v-avatar size="26">
475485
<img :src="box.syscfgs.envs.find(e=>e.id===box.syscfgs.env).icon" alt="box.syscfgs.env" />
476486
</v-avatar>
477487
</v-btn>
@@ -486,11 +496,31 @@ function printHtml(data, curapp = null) {
486496
<v-btn icon @click="ui.curview = ui.bfview" v-else><v-icon>mdi-chevron-left</v-icon></v-btn>
487497
<v-autocomplete :label="ui.curapp ? ui.curapp.name + ' ' + ui.curapp.author : 'chavy.box.js'" no-data-text="未实现" dense hide-details solo> </v-autocomplete>
488498
<v-btn icon @click="ui.drawer.show = true">
489-
<v-avatar size="24">
499+
<v-avatar size="26">
490500
<img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" />
491501
</v-avatar>
492502
</v-btn>
493503
</v-app-bar>
504+
<v-fab-transition>
505+
<v-speed-dial v-show="ui.box.show && !box.usercfgs.isHideBoxIcon" fixed fab bottom :left="ui.drawer.show" :right="!ui.drawer.show" class="mb-12">
506+
<template v-slot:activator>
507+
<v-btn fab>
508+
<v-avatar size="48">
509+
<img :src="box.syscfgs.boxjs.icon" :alt="box.syscfgs.boxjs.repo" />
510+
</v-avatar>
511+
</v-btn>
512+
</template>
513+
<v-btn fab small color="grey" @click="box.usercfgs.isHideBoxIcon = true, onUserCfgsChange()">
514+
<v-icon>mdi-eye-off</v-icon>
515+
</v-btn>
516+
<v-btn fab small color="indigo" disabled>
517+
<v-icon>mdi-database-import</v-icon>
518+
</v-btn>
519+
<v-btn fab small color="green" @click="" v-clipboard:copy="JSON.stringify(boxdat)" v-clipboard:success="onCopy">
520+
<v-icon>mdi-export-variant</v-icon>
521+
</v-btn>
522+
</v-speed-dial>
523+
</v-fab-transition>
494524
<v-navigation-drawer v-model="ui.drawer.show" app temporary right>
495525
<v-list dense nav>
496526
<v-list-item two-line dense @click="onLink(box.syscfgs.chavy.repo)">
@@ -505,12 +535,34 @@ function printHtml(data, curapp = null) {
505535
<v-divider></v-divider>
506536
<v-list-item>
507537
<v-list-item-content>
508-
<v-switch label="透明图标" v-model="box.usercfgs.isTransparentIcons" @change="onIconChange"></v-switch>
538+
<v-switch label="透明图标" v-model="box.usercfgs.isTransparentIcons" @change="onUserCfgsChange"></v-switch>
509539
</v-list-item-content>
510540
<v-list-item-action @click="onLink(box.syscfgs.orz3.repo)">
511-
<v-avatar size="32"><img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" /></v-avatar>
541+
<v-btn fab small text>
542+
<v-avatar size="32"><img :src="box.syscfgs.orz3.icon" :alt="box.syscfgs.orz3.repo" /></v-avatar>
543+
</v-btn>
512544
</v-list-item-action>
513545
</v-list-item>
546+
<v-list-item>
547+
<v-list-item-content>
548+
<v-switch label="隐藏图标 (Box)" v-model="box.usercfgs.isHideBoxIcon" @change="onUserCfgsChange"></v-switch>
549+
</v-list-item-content>
550+
<v-list-item-action @click="onLink(box.syscfgs.boxjs.repo)">
551+
<v-btn fab small text>
552+
<v-avatar size="32"><img :src="box.syscfgs.boxjs.icon" :alt="box.syscfgs.boxjs.repo" /></v-avatar>
553+
</v-btn>
554+
</v-list-item-action>
555+
</v-list-item>
556+
<v-list-item>
557+
<v-list-item-content>
558+
<v-switch label="调试模式 (数据)" v-model="box.usercfgs.isDebugData" @change="onUserCfgsChange"></v-switch>
559+
</v-list-item-content>
560+
</v-list-item>
561+
<v-list-item>
562+
<v-list-item-content>
563+
<v-switch label="调试模式 (格式)" v-model="box.usercfgs.isDebugFormat" @change="onUserCfgsChange"></v-switch>
564+
</v-list-item-content>
565+
</v-list-item>
514566
</v-list>
515567
</v-navigation-drawer>
516568
<v-content>
@@ -652,7 +704,7 @@ function printHtml(data, curapp = null) {
652704
</v-dialog>
653705
</v-container>
654706
</v-content>
655-
<v-bottom-navigation :value="ui.curview" app>
707+
<v-bottom-navigation :value="ui.curview" app v-if="false">
656708
<v-btn value="home">
657709
<span>首页</span>
658710
<v-icon>mdi-home</v-icon>
@@ -693,12 +745,33 @@ function printHtml(data, curapp = null) {
693745
impSessionDialog: { show: false, impval: '' },
694746
snackbar: { show: false, text: '已复制!', timeout: 2000 },
695747
appbar: { color: '' },
748+
box: { show: false },
696749
drawer: { show: false }
697750
},
698751
box: ${data}
699752
}
700753
},
701-
computed: {},
754+
computed: {
755+
boxdat: function () {
756+
const KEY_sessions = 'chavy_boxjs_sessions'
757+
const KEY_sysCfgs = 'chavy_boxjs_sysCfgs'
758+
const KEY_userCfgs = 'chavy_boxjs_userCfgs'
759+
const KEY_sysApps = 'chavy_boxjs_sysApps'
760+
const dat = {}
761+
dat[KEY_sessions] = this.box.sessions
762+
dat[KEY_sysCfgs] = this.box.syscfgs
763+
dat[KEY_userCfgs] = this.box.usercfgs
764+
dat[KEY_sysApps] = this.box.sysapps
765+
this.box.sysapps.forEach((app, appIdx) => {
766+
app.datas.forEach((data, dataIdx) => {
767+
if (![undefined, null].includes(data.val)) {
768+
dat[data.key] = data.val
769+
}
770+
})
771+
})
772+
return dat
773+
}
774+
},
702775
watch: {
703776
'ui.curview': {
704777
handler(newval, oldval) {
@@ -717,7 +790,18 @@ function printHtml(data, curapp = null) {
717790
onLink(link) {
718791
window.open(link)
719792
},
720-
onIconChange() {
793+
onShare() {
794+
const KEY_sessions = 'chavy_boxjs_sessions'
795+
const KEY_userCfgs = 'chavy_boxjs_userCfgs'
796+
const data = {}
797+
data[KEY_sessions] = this.box.sessions
798+
data[KEY_userCfgs] = this.box.usercfgs
799+
this.box.sessions.forEach((session, sessionIdx) => {
800+
session.datas.forEach((_data, dataIdx) => (data[_data.key] = _data.val))
801+
})
802+
this.$copyText(JSON.stringify(data))
803+
},
804+
onUserCfgsChange() {
721805
axios.post('/api', JSON.stringify({ cmd: 'saveUserCfgs', val: this.box.usercfgs }))
722806
},
723807
goAppSessionView(app) {
@@ -801,6 +885,11 @@ function printHtml(data, curapp = null) {
801885
if (this.ui.curapp) {
802886
this.goAppSessionView(this.ui.curapp)
803887
}
888+
if (!this.box.usercfgs.isHideBoxIcon) {
889+
setTimeout(() => {
890+
this.ui.box.show = true
891+
}, 1000)
892+
}
804893
}
805894
})
806895
</script>
@@ -815,4 +904,4 @@ function printJson() {
815904
}
816905

817906
// prettier-ignore
818-
function Env(t){this.name=t,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.log=((...t)=>{this.logs=[...this.logs,...t],t?console.log(t.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((t=this.name,s="",i="")=>{this.isSurge()&&$notification.post(t,s,i),this.isQuanX()&&$notify(t,s,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];t&&e.push(t),s&&e.push(s),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(t=>this.isSurge()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):void 0),this.setdata=((t,s)=>this.isSurge()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):void 0),this.get=((t,s)=>this.send(t,"GET",s)),this.wait=((t,s=t)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(s-t+1)+t))),this.post=((t,s)=>this.send(t,"POST",s)),this.send=((t,s,i)=>{if(this.isSurge()){const e="POST"==s?$httpClient.post:$httpClient.get;e(t,(t,s,e)=>{s&&(s.body=e,s.statusCode=s.status),i(t,s,e)})}this.isQuanX()&&(t.method=s,$task.fetch(t).then(t=>{t.status=t.statusCode,i(null,t,t.body)},t=>i(t.error,t,t)))}),this.done=((t={})=>$done(t))}
907+
function Env(s){this.name=s,this.data=null,this.logs=[],this.isSurge=(()=>"undefined"!=typeof $httpClient),this.isQuanX=(()=>"undefined"!=typeof $task),this.isNode=(()=>"undefined"!=typeof module&&!!module.exports),this.log=((...s)=>{this.logs=[...this.logs,...s],s?console.log(s.join("\n")):console.log(this.logs.join("\n"))}),this.msg=((s=this.name,t="",i="")=>{this.isSurge()&&$notification.post(s,t,i),this.isQuanX()&&$notify(s,t,i);const e=["","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="];s&&e.push(s),t&&e.push(t),i&&e.push(i),console.log(e.join("\n"))}),this.getdata=(s=>{if(this.isSurge())return $persistentStore.read(s);if(this.isQuanX())return $prefs.valueForKey(s);if(this.isNode()){const t="box.dat";return this.fs=this.fs?this.fs:require("fs"),this.fs.existsSync(t)?(this.data=JSON.parse(this.fs.readFileSync(t)),this.data[s]):null}}),this.setdata=((s,t)=>{if(this.isSurge())return $persistentStore.write(s,t);if(this.isQuanX())return $prefs.setValueForKey(s,t);if(this.isNode()){const i="box.dat";return this.fs=this.fs?this.fs:require("fs"),!!this.fs.existsSync(i)&&(this.data=JSON.parse(this.fs.readFileSync(i)),this.data[t]=s,this.fs.writeFileSync(i,JSON.stringify(this.data)),!0)}}),this.wait=((s,t=s)=>i=>setTimeout(()=>i(),Math.floor(Math.random()*(t-s+1)+s))),this.get=((s,t)=>this.send(s,"GET",t)),this.post=((s,t)=>this.send(s,"POST",t)),this.send=((s,t,i)=>{if(this.isSurge()){const e="POST"==t?$httpClient.post:$httpClient.get;e(s,(s,t,e)=>{t&&(t.body=e,t.statusCode=t.status),i(s,t,e)})}this.isQuanX()&&(s.method=t,$task.fetch(s).then(s=>{s.status=s.statusCode,i(null,s,s.body)},s=>i(s.error,s,s))),this.isNode()&&(this.request=this.request?this.request:require("request"),s.method=t,s.gzip=!0,this.request(s,(s,t,e)=>{t&&(t.status=t.statusCode),i(null,t,e)}))}),this.done=((s={})=>this.isNode()?null:$done(s))}

0 commit comments

Comments
 (0)