Skip to content

Commit 8f9de65

Browse files
committed
更新[BoxJs]: 增加长文本控件, setting & data key支持表达式: @foo.name
1 parent 19a28b9 commit 8f9de65

1 file changed

Lines changed: 45 additions & 33 deletions

File tree

‎chavy.box.js‎

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,14 @@ function wrapapps(apps) {
354354
// 获取持久化数据
355355
app.datas = Array.isArray(app.datas) ? app.datas : []
356356
app.keys.forEach((key) => {
357-
app.datas.push({ key, val: $.getdata(key) })
357+
const valdat = $.getdata(key)
358+
const val = [undefined, null, 'null', ''].includes(valdat) ? null : valdat
359+
app.datas.push({ key, val })
358360
})
359361
Array.isArray(app.settings) &&
360362
app.settings.forEach((setting) => {
361-
const val = $.getdata(setting.id)
363+
const valdat = $.getdata(setting.id)
364+
const val = [undefined, null, 'null', ''].includes(valdat) ? null : valdat
362365
if (setting.type === 'boolean') {
363366
setting.val = val === null ? setting.val : val === 'true'
364367
} else if (setting.type === 'int') {
@@ -785,10 +788,10 @@ function printHtml(data, curapp = null, curview = 'app') {
785788
</v-subheader>
786789
<v-form class="pl-4 pr-4">
787790
<template v-for="(setting, settingIdx) in ui.curapp.settings">
788-
<v-slider :label="setting.name" v-model="setting.val" :hint="setting.desc" :min="setting.min" :max="setting.max" thumb-label="always" v-if="setting.type === 'slider'"></v-slider>
789-
<v-switch :label="setting.name" v-model="setting.val" :hint="setting.desc" v-else-if="setting.type === 'boolean'"></v-switch>
790-
<v-textarea :label="setting.name" v-model="setting.val" :hint="setting.desc" :auto-grow="setting.autoGrow" v-else-if="setting.type === 'textarea'"></v-textarea>
791-
<v-text-field :label="setting.name" v-model="setting.val" :hint="setting.desc" v-else="setting.type === 'text'"></v-text-field>
791+
<v-slider :label="setting.name" v-model="setting.val" :hint="setting.desc" :min="setting.min" :max="setting.max" thumb-label="always" :placeholder="setting.placeholder" v-if="setting.type === 'slider'"></v-slider>
792+
<v-switch :label="setting.name" v-model="setting.val" :hint="setting.desc" :placeholder="setting.placeholder" v-else-if="setting.type === 'boolean'"></v-switch>
793+
<v-textarea :label="setting.name" v-model="setting.val" :hint="setting.desc" :auto-grow="setting.autoGrow" :placeholder="setting.placeholder" v-else-if="setting.type === 'textarea'"></v-textarea>
794+
<v-text-field :label="setting.name" v-model="setting.val" :hint="setting.desc" :placeholder="setting.placeholder" v-else="setting.type === 'text'"></v-text-field>
792795
</template>
793796
</v-form>
794797
<v-divider></v-divider>
@@ -988,27 +991,6 @@ function printHtml(data, curapp = null, curview = 'app') {
988991
</v-list-item>
989992
</template>
990993
</v-card>
991-
<v-dialog v-model="ui.impGlobalBakDialog.show">
992-
<v-card>
993-
<v-card-title>
994-
导入备份
995-
<v-spacer></v-spacer>
996-
<v-btn text small class="mr-n4" color="red darken-1" @click="ui.impGlobalBakDialog.bak = ''">清空</v-btn>
997-
</v-card-title>
998-
<v-divider></v-divider>
999-
<v-card-text>
1000-
<v-textarea clearable v-model="ui.impGlobalBakDialog.bak" label="备份内容" hint="请粘贴全局备份内容!"></v-textarea>
1001-
</v-card-text>
1002-
<v-divider></v-divider>
1003-
<v-card-actions>
1004-
<v-btn text small @click="" v-clipboard:copy="ui.impGlobalBakDialog.bak" v-clipboard:success="onCopy">复制</v-btn>
1005-
<v-btn text small @click="onImpGlobalBakPaste">粘粘</v-btn>
1006-
<v-spacer></v-spacer>
1007-
<v-btn text small color="grey darken-1" text @click="ui.impGlobalBakDialog.show = false">取消</v-btn>
1008-
<v-btn text small color="success darken-1" text @click="onImpGlobalBak">导入</v-btn>
1009-
</v-card-actions>
1010-
</v-card>
1011-
</v-dialog>
1012994
<v-dialog v-model="ui.editProfileDialog.show">
1013995
<v-card>
1014996
<v-card-title>个人资料</v-card-title>
@@ -1043,6 +1025,30 @@ function printHtml(data, curapp = null, curview = 'app') {
10431025
</v-card-actions>
10441026
</v-card>
10451027
</v-dialog>
1028+
<v-dialog v-model="ui.impGlobalBakDialog.show">
1029+
<v-card>
1030+
<v-card-title>
1031+
导入备份
1032+
<v-spacer></v-spacer>
1033+
<v-btn text small class="mr-n4" color="red darken-1" @click="ui.impGlobalBakDialog.bak = ''">清空</v-btn>
1034+
</v-card-title>
1035+
<v-divider></v-divider>
1036+
<v-card-text>
1037+
<v-textarea clearable v-model="ui.impGlobalBakDialog.bak" label="备份内容" hint="请粘贴全局备份内容!"></v-textarea>
1038+
</v-card-text>
1039+
<v-divider></v-divider>
1040+
<v-card-actions>
1041+
<v-btn text small @click="" v-clipboard:copy="ui.impGlobalBakDialog.bak" v-clipboard:success="onCopy">复制</v-btn>
1042+
<v-btn text small @click="onImpGlobalBakPaste">粘粘</v-btn>
1043+
<v-spacer></v-spacer>
1044+
<v-btn text small color="grey darken-1" text @click="ui.impGlobalBakDialog.show = false">取消</v-btn>
1045+
<v-btn text small color="success darken-1" text @click="onImpGlobalBak">导入</v-btn>
1046+
</v-card-actions>
1047+
</v-card>
1048+
</v-dialog>
1049+
<v-overlay v-model="ui.overlay.show">
1050+
<v-progress-circular indeterminate size="64"></v-progress-circular>
1051+
</v-overlay>
10461052
</v-main>
10471053
<v-expand-transition>
10481054
<v-bottom-navigation v-model="ui.curview" app v-show="ui.navi.show && !box.usercfgs.isHideNavi">
@@ -1092,6 +1098,7 @@ function printHtml(data, curapp = null, curview = 'app') {
10921098
curapp: ${curapp},
10931099
curappTabs: { curtab: 'sessions' },
10941100
curappSessions: null,
1101+
overlay: { show: false },
10951102
editProfileDialog: { show: false, bak: '' },
10961103
impGlobalBakDialog: { show: false, bak: '' },
10971104
reloadConfirmDialog: { show: false, title: '操作成功', message: '是否马上刷新页面?' },
@@ -1138,25 +1145,25 @@ function printHtml(data, curapp = null, curview = 'app') {
11381145
dat[KEY_sysApps] = this.box.sysapps
11391146
this.box.sysapps.forEach((app, appIdx) => {
11401147
app.datas.forEach((data, dataIdx) => {
1141-
if (![undefined, null, 'null'].includes(data.val) && !/^@/.test(data.key)) {
1148+
if (![undefined, null, 'null'].includes(data.val)) {
11421149
dat[data.key] = data.val
11431150
}
11441151
})
11451152
app.settings && app.settings.forEach((setting, settingIdx) => {
1146-
if (![undefined, null, 'null'].includes(setting.val) && !/^@/.test(setting.id)) {
1153+
if (![undefined, null, 'null'].includes(setting.val)) {
11471154
dat[setting.id] = setting.val
11481155
}
11491156
})
11501157
})
11511158
this.box.appsubs.forEach((sub, subIdx) => {
11521159
sub.apps.forEach((app, appIdx) => {
11531160
app.datas.forEach((data, dataIdx) => {
1154-
if (![undefined, null, 'null'].includes(data.val) && !/^@/.test(data.key)) {
1161+
if (![undefined, null, 'null'].includes(data.val)) {
11551162
dat[data.key] = data.val
11561163
}
11571164
})
11581165
app.settings && app.settings.forEach((setting, settingIdx) => {
1159-
if (![undefined, null, 'null'].includes(setting.val) && !/^@/.test(setting.id)) {
1166+
if (![undefined, null, 'null'].includes(setting.val)) {
11601167
dat[setting.id] = setting.val
11611168
}
11621169
})
@@ -1271,6 +1278,7 @@ function printHtml(data, curapp = null, curview = 'app') {
12711278
onClearCurAppSessionData(app, datas, data) {
12721279
data.val = ''
12731280
axios.post('/api', JSON.stringify({ cmd: 'saveCurAppSession', val: app }))
1281+
this.onReload()
12741282
},
12751283
onSaveSession() {
12761284
const session = {
@@ -1280,14 +1288,15 @@ function printHtml(data, curapp = null, curview = 'app') {
12801288
appName: this.ui.curapp.name,
12811289
enable: true,
12821290
createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
1283-
datas: this.ui.curapp.datas
1291+
datas: JSON.parse(JSON.stringify(this.ui.curapp.datas))
12841292
}
12851293
this.box.sessions.push(session)
12861294
this.ui.curappSessions.push(session)
12871295
axios.post('/api', JSON.stringify({ cmd: 'saveSession', val: session }))
12881296
},
12891297
onSaveSettings() {
12901298
axios.post('/api', JSON.stringify({ cmd: 'saveSettings', val: this.ui.curapp.settings }))
1299+
this.onReload()
12911300
},
12921301
onImpSessionPaste() {
12931302
navigator.clipboard.readText().then((text) => {
@@ -1341,6 +1350,7 @@ function printHtml(data, curapp = null, curview = 'app') {
13411350
this.ui.reloadConfirmDialog.show = true
13421351
},
13431352
onReload() {
1353+
this.ui.overlay.show = true
13441354
window.location.reload()
13451355
},
13461356
onDelSession(session) {
@@ -1353,6 +1363,7 @@ function printHtml(data, curapp = null, curview = 'app') {
13531363
onUseSession(session) {
13541364
axios.post('/api', JSON.stringify({ cmd: 'useSession', val: session }))
13551365
this.ui.curapp.datas = JSON.parse(JSON.stringify(session.datas))
1366+
this.onReload()
13561367
},
13571368
onImpGlobalBak() {
13581369
const env = this.box.syscfgs.env
@@ -1371,6 +1382,7 @@ function printHtml(data, curapp = null, curview = 'app') {
13711382
this.box.globalbaks.push(bakobj)
13721383
this.ui.impGlobalBakDialog.show = false
13731384
axios.post('/api', JSON.stringify({ cmd: 'globalBak', val: bakobj }))
1385+
this.onReload()
13741386
},
13751387
onGlobalBak() {
13761388
const env = this.box.syscfgs.env
@@ -1427,4 +1439,4 @@ function printJson() {
14271439
}
14281440

14291441
// prettier-ignore
1430-
function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch{return{}}}}}writedata(){if(this.isNode){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),h=JSON.stringify(this.data);e?this.fs.writeFileSync(t,h):i?this.fs.writeFileSync(s,h):this.fs.writeFileSync(t,h)}}getdata(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setdata(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:h,body:o}=t;s(null,{status:e,statusCode:i,headers:h,body:o},o)},t=>s(t))}}msg(s=t,e="",i="",h){this.isSurge()||this.isLoon()?$notification.post(s,e,i):this.isQuanX()&&$notify(s,e,i),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t=null){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)}
1442+
function Env(t,s){return new class{constructor(t,s){this.name=t,this.data=null,this.dataFile="box.dat",this.logs=[],this.logSeparator="\n",this.startTime=(new Date).getTime(),Object.assign(this,s),this.log("",`\ud83d\udd14${this.name}, \u5f00\u59cb!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient}isLoon(){return"undefined"!=typeof $loon}loaddata(){if(!this.isNode)return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s);if(!e&&!i)return{};{const i=e?t:s;try{return JSON.parse(this.fs.readFileSync(i))}catch{return{}}}}}writedata(){if(this.isNode){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),s=this.path.resolve(process.cwd(),this.dataFile),e=this.fs.existsSync(t),i=!e&&this.fs.existsSync(s),o=JSON.stringify(this.data);e?this.fs.writeFileSync(t,o):i?this.fs.writeFileSync(s,o):this.fs.writeFileSync(t,o)}}lodash_get(t,s,e){const i=s.replace(/\[(\d+)\]/g,".$1").split(".");let o=t;for(const t of i)if(o=Object(o)[t],void 0===o)return e;return o}lodash_set(t,s,e){return Object(t)!==t?t:(Array.isArray(s)||(s=s.toString().match(/[^.[\]]+/g)||[]),s.slice(0,-1).reduce((t,e,i)=>Object(t[e])===t[e]?t[e]:t[e]=Math.abs(s[i+1])>>0==+s[i+1]?[]:{},t)[s[s.length-1]]=e,t)}getdata(t){let s=this.getval(t);if(/^@/.test(t)){const[,e,i]=/^@(.*?)\.(.*?)$/.exec(t),o=e?this.getval(e):"";if(o)try{const t=JSON.parse(o);s=t?this.lodash_get(t,i,""):s}catch(t){s=""}}return s}setdata(t,s){let e=!1;if(/^@/.test(s)){const[,i,o]=/^@(.*?)\.(.*?)$/.exec(s),h=this.getval(i),a=i?"null"===h?null:h||"{}":"{}";try{const s=JSON.parse(a);this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i),console.log(`${i}: ${JSON.stringify(s)}`)}catch{const s={};this.lodash_set(s,o,t),e=this.setval(JSON.stringify(s),i),console.log(`${i}: ${JSON.stringify(s)}`)}}else e=$.setval(t,s);return e}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,s){return this.isSurge()||this.isLoon()?$persistentStore.write(t,s):this.isQuanX()?$prefs.setValueForKey(t,s):this.isNode()?(this.data=this.loaddata(),this.data[s]=t,this.writedata(),!0):this.data&&this.data[s]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,s=(()=>{})){t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon()?$httpClient.get(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))}):this.isQuanX()?$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)):this.isNode()&&(this.initGotEnv(t),this.got(t).on("redirect",(t,s)=>{try{const e=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();this.ckjar.setCookieSync(e,null),s.cookieJar=this.ckjar}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t)))}post(t,s=(()=>{})){if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),delete t.headers["Content-Length"],this.isSurge()||this.isLoon())$httpClient.post(t,(t,e,i)=>{!t&&e&&(e.body=i,e.statusCode=e.status,s(t,e,i))});else if(this.isQuanX())t.method="POST",$task.fetch(t).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t));else if(this.isNode()){this.initGotEnv(t);const{url:e,...i}=t;this.got.post(e,i).then(t=>{const{statusCode:e,statusCode:i,headers:o,body:h}=t;s(null,{status:e,statusCode:i,headers:o,body:h},h)},t=>s(t))}}msg(s=t,e="",i="",o){this.isSurge()||this.isLoon()?$notification.post(s,e,i):this.isQuanX()&&$notify(s,e,i),this.logs.push("","==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="),this.logs.push(s),e&&this.logs.push(e),i&&this.logs.push(i)}log(...t){t.length>0?this.logs=[...this.logs,...t]:console.log(this.logs.join(this.logSeparator))}logErr(t,s){const e=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();e?$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.stack):$.log("",`\u2757\ufe0f${this.name}, \u9519\u8bef!`,t.message)}wait(t){return new Promise(s=>setTimeout(s,t))}done(t=null){const s=(new Date).getTime(),e=(s-this.startTime)/1e3;this.log("",`\ud83d\udd14${this.name}, \u7ed3\u675f! \ud83d\udd5b ${e} \u79d2`),this.log(),(this.isSurge()||this.isQuanX()||this.isLoon())&&$done(t)}}(t,s)}

0 commit comments

Comments
 (0)