@@ -286,6 +286,7 @@ function getSystemApps() {
286286 sysapps
287287 . sort ( ( a , b ) => a . id . localeCompare ( b . id ) )
288288 . forEach ( ( app ) => {
289+ // 获取持久化数据
289290 app . datas = Array . isArray ( app . datas ) ? app . datas : [ ]
290291 app . keys . forEach ( ( key ) => {
291292 app . datas . push ( { key, val : $ . getdata ( key ) } )
@@ -301,13 +302,20 @@ function getSystemApps() {
301302 setting . val = val || setting . val
302303 }
303304 } )
305+ // 判断是否收藏应用
306+ const usercfgs = getUserCfgs ( )
307+ const favapps = usercfgs && usercfgs . favapps
308+ if ( favapps ) {
309+ app . isFav = favapps . findIndex ( ( appId ) => app . id === appId ) > - 1 ? true : false
310+ }
304311 } )
305312 return sysapps
306313}
307314
308315function getUserCfgs ( ) {
316+ const defcfgs = { favapps : [ ] }
309317 const userCfgsStr = $ . getdata ( $ . KEY_userCfgs )
310- return userCfgsStr ? JSON . parse ( userCfgsStr ) : { }
318+ return userCfgsStr ? Object . assign ( defcfgs , JSON . parse ( userCfgsStr ) ) : defcfgs
311319}
312320
313321function getUserApps ( ) {
@@ -477,7 +485,7 @@ function printHtml(data, curapp = null) {
477485 <template v-slot:activator="{ on }">
478486 <v-btn icon v-on="on"><v-icon>mdi-palette</v-icon></v-btn>
479487 </template>
480- <v-list>
488+ <v-list dense >
481489 <v-list-item v-for="(color, colorIdx) in box.colors" :key="color.id" @click="ui.appbar.color=color.id">
482490 <v-list-item-title>22{{ color.name }}</v-list-item-title>
483491 </v-list-item>
@@ -491,7 +499,7 @@ function printHtml(data, curapp = null) {
491499 </v-avatar>
492500 </v-btn>
493501 </template>
494- <v-list>
502+ <v-list dense >
495503 <v-list-item v-for="(env, envIdx) in box.syscfgs.envs" :key="env.id" @click="box.syscfgs.env=env.id">
496504 <v-list-item-avatar size="24"><v-img :src="env.icon"></v-img></v-list-item-avatar>
497505 <v-list-item-title>{{ env.id }}</v-list-item-title>
@@ -575,37 +583,53 @@ function printHtml(data, curapp = null) {
575583 </v-list-item>
576584 </v-list>
577585 </v-navigation-drawer>
578- <v-content>
586+ <v-content :class="box.usercfgs.isHideNavi ? 'mb-0' : 'mb-14'" >
579587 <v-container fluid v-if="ui.curview === 'app'">
580- <v-card class="mx-auto" tile >
588+ <v-card class="mx-auto" v-if="favapps.length > 0" >
581589 <v-list nav dense>
582- <v-subheader inset>内置应用 ({{ box.sysapps .length }})</v-subheader>
583- <v-list-item three-line dense v-for="(app, appIdx) in box.sysapps " :key="app.id" @click="goAppSessionView(app)">
590+ <v-subheader inset>收藏应用 ({{ favapps .length }})</v-subheader>
591+ <v-list-item three-line dense v-for="(app, appIdx) in favapps " :key="app.id" @click="goAppSessionView(app)">
584592 <v-list-item-avatar><v-img :src="app.icons[box.usercfgs.isTransparentIcons ? 0 : 1]"></v-img></v-list-item-avatar>
585593 <v-list-item-content>
586594 <v-list-item-title>{{ app.name }} ({{ app.id }})</v-list-item-title>
587595 <v-list-item-subtitle>{{ app.repo }}</v-list-item-subtitle>
588596 <v-list-item-subtitle color="blue">{{ app.author }}</v-list-item-subtitle>
589597 </v-list-item-content>
590598 <v-list-item-action>
591- <v-btn icon> <v-icon color="grey lighten-1">mdi-chevron-right</v-icon></v-btn>
599+ <v-menu bottom left>
600+ <template v-slot:activator="{ on }">
601+ <v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
602+ </template>
603+ <v-list dense>
604+ <v-list-item v-if="appIdx > 0" @click="onMoveFav(appIdx, -1)">
605+ <v-list-item-title>上移</v-list-item-title>
606+ </v-list-item>
607+ <v-list-item v-if="appIdx + 1 < favapps.length" @click="onMoveFav(appIdx, 1)">
608+ <v-list-item-title>下移</v-list-item-title>
609+ </v-list-item>
610+ <v-divider v-if="favapps.length > 1"></v-divider>
611+ <v-list-item @click="onFav(app)">
612+ <v-list-item-title>取消收藏</v-list-item-title>
613+ </v-list-item>
614+ </v-list>
615+ </v-menu>
592616 </v-list-item-action>
593617 </v-list-item>
594- <v-divider></v-divider>
595- <v-subheader inset>
596- <span>自建应用 ({{ box.userapps.length }})</span>
597- <v-spacer></v-spacer>
598- <v-btn icon> <v-icon color="green">mdi-plus-circle</v-icon></v-btn>
599- </v-subheader>
600- <v-list-item three-line dense v-for="(app, appIdx) in box.userapps" :key="app.id" @click="goAppSessionView(app)">
601- <v-list-item-avatar><v-img :src="app.icon"></v-img></v-list-item-avatar>
618+ </v-list>
619+ </v-card>
620+ <v-card class="mx-auto mt-4">
621+ <v-list nav dense>
622+ <v-subheader inset>内置应用 ({{ box.sysapps.length }})</v-subheader>
623+ <v-list-item three-line dense v-for="(app, appIdx) in box.sysapps" :key="app.id" @click="goAppSessionView(app)">
624+ <v-list-item-avatar><v-img :src="app.icons[box.usercfgs.isTransparentIcons ? 0 : 1]"></v-img></v-list-item-avatar>
602625 <v-list-item-content>
603- <v-list-item-title>{{ app.name }}</v-list-item-title>
626+ <v-list-item-title>{{ app.name }} ({{ app.id }}) </v-list-item-title>
604627 <v-list-item-subtitle>{{ app.repo }}</v-list-item-subtitle>
605628 <v-list-item-subtitle color="blue">{{ app.author }}</v-list-item-subtitle>
606629 </v-list-item-content>
607630 <v-list-item-action>
608- <v-btn icon> <v-icon color="grey lighten-1">mdi-chevron-right</v-icon></v-btn>
631+ <v-btn icon v-if="app.isFav" @click.stop="onFav(app, appIdx)"><v-icon color="yellow darken-2">mdi-star</v-icon></v-btn>
632+ <v-btn icon v-else @click.stop="onFav(app, appIdx)"><v-icon color="grey">mdi-star-outline</v-icon></v-btn>
609633 </v-list-item-action>
610634 </v-list-item>
611635 </v-list>
@@ -639,7 +663,7 @@ function printHtml(data, curapp = null) {
639663 <template v-slot:activator="{ on }">
640664 <v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn>
641665 </template>
642- <v-list>
666+ <v-list dense >
643667 <v-list-item @click="" v-clipboard:copy="JSON.stringify(ui.curapp)" v-clipboard:success="onCopy">
644668 <v-list-item-title>复制会话</v-list-item-title>
645669 </v-list-item>
@@ -712,7 +736,7 @@ function printHtml(data, curapp = null) {
712736 <v-snackbar top color="success" v-model="ui.snackbar.show" :timeout="ui.snackbar.timeout">
713737 {{ ui.snackbar.text }}
714738 <template v-slot:action>
715- <v-btn text @click="ui.snackbar.show = false">关闭</v-btn>
739+ <v-btn text @click="ui.snackbar.show = false">关闭</v-btn>
716740 </template>
717741 </v-snackbar>
718742 </v-content>
@@ -786,6 +810,18 @@ function printHtml(data, curapp = null) {
786810 })
787811 })
788812 return dat
813+ },
814+ favapps: function () {
815+ const favapps = []
816+ if (this.box.usercfgs.favapps) {
817+ this.box.usercfgs.favapps.forEach((favappId) => {
818+ const app = this.box.sysapps.find((app) => app.id === favappId)
819+ if (app) {
820+ favapps.push(app)
821+ }
822+ })
823+ }
824+ return favapps
789825 }
790826 },
791827 watch: {
@@ -798,7 +834,7 @@ function printHtml(data, curapp = null) {
798834 var state = { title: 'BoxJs' }
799835 document.title = state.title
800836 history.pushState(state, '', '/home')
801- this.$vuetify.goTo(this.ui.scrollY, {duration: 0, offset: 0})
837+ this.$vuetify.goTo(this.ui.scrollY, { duration: 0, offset: 0 })
802838 }
803839 }
804840 }
@@ -808,10 +844,30 @@ function printHtml(data, curapp = null) {
808844 window.open(link)
809845 },
810846 onScroll(e) {
811- if(this.ui.curview === 'app') {
847+ if (this.ui.curview === 'app') {
812848 this.ui.scrollY = e.currentTarget.scrollY + 48
813849 }
814850 },
851+ onMoveFav(favIdx, moveCnt) {
852+ const fromIdx = favIdx
853+ const toIdx = favIdx + moveCnt
854+ this.box.usercfgs.favapps.splice(fromIdx, 1, ...this.box.usercfgs.favapps.splice(toIdx, 1, this.box.usercfgs.favapps[fromIdx]))
855+ this.onUserCfgsChange()
856+ },
857+ onFav(app) {
858+ const appIdx = this.box.sysapps.findIndex((appId) => appId === app.id)
859+ app.isFav = !app.isFav
860+ Vue.set(this.box.sysapps, appIdx, this.box.sysapps[appIdx])
861+ const usercfgs = this.box.usercfgs ? this.box.usercfgs : { favapps: [] }
862+ usercfgs.favapps = usercfgs.favapps ? usercfgs.favapps : []
863+ const idx = usercfgs.favapps.findIndex((appId) => appId === app.id)
864+ if (app.isFav === true && idx === -1) {
865+ usercfgs.favapps.push(app.id)
866+ } else if (app.isFav === false && idx > -1) {
867+ usercfgs.favapps.splice(idx, 1)
868+ }
869+ this.onUserCfgsChange()
870+ },
815871 onUserCfgsChange() {
816872 axios.post('/api', JSON.stringify({ cmd: 'saveUserCfgs', val: this.box.usercfgs }))
817873 },
0 commit comments