提交 9fdb5d7f 编写于 作者: AndroidLeaves's avatar AndroidLeaves

update

上级 7c920e8e
......@@ -31,6 +31,12 @@ const { BaseWidget } = require(dependencyFileName);
class Widget extends BaseWidget {
defaultPreference = {
centerIconUrls: [
'img/ic_pikachu_1.png',
'img/ic_pikachu_2.png',
'img/ic_pikachu_3.png',
'img/ic_pikachu_4.png',
],
leftStackWidth: 80,
userInfoParam: {
'functionId': 'queryJDUserInfo',
......@@ -60,8 +66,26 @@ class Widget extends BaseWidget {
'sceneval': 2,
'g_login_type': 1,
},
nicknameColor: Color.dynamic(new Color('#000000'), new Color('#999999')),
jvColor: Color.dynamic(new Color('#000000'), new Color('#999999')),
nicknameDayColor: '#000000',
nicknameNightColor: '#000000',
jvDayColor: '#000000',
jvNightColor: '#000000',
beanDayColor: '#F62910',
beanNightColor: '#F62910',
expiredBeanDayColor: '#AD4731',
expiredBeanNightColor: '#AD4731',
dateBeanTitleDayColor: '#000000',
dateBeanTitleNightColor: '#000000',
dateBeaneDayColor: '#000000',
dateBeanNightColor: '#000000',
redPackageDayColor: '#F62910',
redPackageNightColor: '#F62910',
expiredRedPackageDayColor: '#ff8260',
expiredRedPackageNightColor: '#ff8260',
fruitDayColor: '#84B264',
fruitNightColor: '#84B264',
baiTiaoDayColor: '#F62910',
baiTiaoNightColor: '#F62910',
};
userInfo = {
......@@ -107,9 +131,35 @@ class Widget extends BaseWidget {
ck = () => this.getValueByKey('cookie');
nicknameColor = () => this.getValueByKey('nicknameColor');
nicknameDayColor = () => this.getValueByKey('nicknameDayColor');
nicknameNightColor = () => this.getValueByKey('nicknameNightColor');
jvColor = () => this.getValueByKey('jvColor');
jvDayColor = () => this.getValueByKey('jvDayColor');
jvNightColor = () => this.getValueByKey('jvNightColor');
beanDayColor = () => this.getValueByKey('beanDayColor');
beanNightColor = () => this.getValueByKey('beanNightColor');
expiredBeanDayColor = () => this.getValueByKey('expiredBeanDayColor');
expiredBeanNightColor = () => this.getValueByKey('expiredBeanNightColor');
dateBeanTitleDayColor = () => this.getValueByKey('dateBeanTitleDayColor');
dateBeanTitleNightColor = () => this.getValueByKey('dateBeanTitleNightColor');
dateBeanDayColor = () => this.getValueByKey('dateBeanDayColor');
dateBeanNightColor = () => this.getValueByKey('dateBeanNightColor');
redPackageDayColor = () => this.getValueByKey('redPackageDayColor');
redPackageNightColor = () => this.getValueByKey('redPackageNightColor');
expiredRedPackageDayColor = () => this.getValueByKey('expiredRedPackageDayColor');
expiredRedPackageNightColor = () => this.getValueByKey('expiredRedPackageNightColor');
fruitDayColor = () => this.getValueByKey('fruitDayColor');
fruitNightColor = () => this.getValueByKey('fruitNightColor');
baiTiaoDayColor = () => this.getValueByKey('baiTiaoDayColor');
baiTiaoNightColor = () => this.getValueByKey('baiTiaoNightColor');
constructor(scriptName) {
super(scriptName);
......@@ -147,7 +197,216 @@ class Widget extends BaseWidget {
type: 'cell',
icon: `${remoteRoot}/img/jd/icon_app_logo.png`,
needLoading: true,
default: '',
default: this.ck()?.length > 0 ? '已登录' : '未登录',
},
{
name: 'otherSetting',
label: '其他设置',
type: 'cell',
icon: `${remoteRoot}/img/setting.gif`,
needLoading: true,
childItems: [
{
items: [
{
name: 'nicknameDayColor',
label: '用户名白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.nicknameDayColor(),
},
{
name: 'nicknameNightColor',
label: '用户名深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.nicknameNightColor(),
}
]
},
{
items: [
{
name: 'jvDayColor',
label: '京享值白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.jvDayColor(),
},
{
name: 'jvNightColor',
label: '京享值深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.jvNightColor(),
}
]
},
{
items: [
{
name: 'beanDayColor',
label: '京豆白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.beanDayColor(),
},
{
name: 'beanNightColor',
label: '京豆深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.beanNightColor(),
}
]
},
{
items: [
{
name: 'expiredBeanDayColor',
label: '快过期京豆白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.expiredBeanDayColor(),
},
{
name: 'expiredBeanNightColor',
label: '快过期京豆深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.expiredBeanNightColor(),
}
]
},
{
items: [
{
name: 'dateBeanTitleDayColor',
label: '日期标题白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.dateBeanTitleDayColor(),
},
{
name: 'dateBeanTitleNightColor',
label: '日期标题深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.dateBeanTitleNightColor(),
}
]
},
{
items: [
{
name: 'dateBeanDayColor',
label: '日期京豆白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.dateBeanDayColor(),
},
{
name: 'dateBeanNightColor',
label: '日期京豆深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.dateBeanNightColor(),
}
]
},
{
items: [
{
name: 'redPackageDayColor',
label: '红包白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.redPackageDayColor(),
},
{
name: 'redPackageNightColor',
label: '红包深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.redPackageNightColor(),
}
]
},
{
items: [
{
name: 'expiredRedPackageDayColor',
label: '快过期红包白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.expiredRedPackageDayColor(),
},
{
name: 'expiredRedPackageNightColor',
label: '快过期红包深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.expiredRedPackageNightColor(),
}
]
},
{
items: [
{
name: 'fruitDayColor',
label: '农场白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.fruitDayColor(),
},
{
name: 'fruitNightColor',
label: '农场深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.fruitNightColor(),
}
]
},
{
items: [
{
name: 'baiTiaoDayColor',
label: '白条白天颜色',
type: 'color',
icon: { name: 'pencil.and.outline', color: '#3a86ff', },
needLoading: false,
default: this.baiTiaoDayColor(),
},
{
name: 'baiTiaoNightColor',
label: '白条深色颜色',
type: 'color',
icon: { name: 'square.and.pencil', color: '#3a0ca3', },
needLoading: false,
default: this.baiTiaoNightColor(),
}
]
},
]
},
],
// cell类型的item点击回调
......@@ -297,7 +556,7 @@ class Widget extends BaseWidget {
}
textSpan = nameStack.addText(this.userInfo.nickname);
textSpan.lineLimit = 1;
textSpan.textColor = this.nicknameColor();
textSpan.textColor = Color.dynamic(new Color(this.nicknameDayColor()), new Color(this.nicknameNightColor()));
textSpan.font = Font.regularSystemFont(12);
//================================
userInfoStack.addSpacer(5 + this.vSpacer / 2);
......@@ -311,28 +570,21 @@ class Widget extends BaseWidget {
jvStack.setPadding(2, 8, 2, 8);
textSpan = jvStack.addText(`京享值 ${this.userInfo.jvalue}`);
textSpan.textOpacity = 0.9;
textSpan.textColor = this.jvColor();
textSpan.textColor = Color.dynamic(new Color(this.jvDayColor()), new Color(this.jvNightColor()));
textSpan.font = Font.regularSystemFont(10);
jvStack.cornerRadius = 10;
}
async detailInfoStack(detailInfoStack, widgetSize) {
let icon = 'robot-face.png';
const icon = this.getRandowArrValue(this.defaultPreference.centerIconUrls);
let btInfoIndex = parseInt(this.keyGet('btInfoIndex', '0'));
if (btInfoIndex == 0) {
// 红包
icon = 'partying-face.png';
} else if (btInfoIndex == 1) {
// 东东农场
icon = 'face-with-rainbow-glasses.png';
}
const bannerSize = new Size(34 + this.vSpacer, 34 + this.vSpacer);
const textBannerSize = new Size(30 + this.vSpacer, 30 + this.vSpacer);
const normalBeanSize = new Size(16, 16);
const expireBeanSize = new Size(13, 13);
const emojiSize = new Size(44, 44);
const beanColor = new Color('#F62910');
const expiredBeanColor = new Color('#AD4731', 0.7);
const emojiSize = new Size(48, 48);
const beanColor = Color.dynamic(new Color(this.beanDayColor()), new Color(this.beanNightColor()));
const expiredBeanColor = Color.dynamic(new Color(this.expiredBeanDayColor()), new Color(this.expiredBeanNightColor()));
//================================
let imgSpan;
let textSpan;
......@@ -379,30 +631,30 @@ class Widget extends BaseWidget {
let yesterdayBeanStack = beanInfoStack.addStack();
yesterdayBeanStack.layoutVertically();
textSpan = yesterdayBeanStack.addText(`昨天`);
textSpan.textColor = new Color('#000000');
textSpan.textColor = Color.dynamic(new Color(this.dateBeanTitleDayColor()), new Color(this.dateBeanTitleNightColor()));
textSpan.font = Font.regularSystemFont(12);
yesterdayBeanStack.addSpacer(5);
//
textSpan = yesterdayBeanStack.addText(`${this.beanInfo.yesterdayGain}`);
textSpan.textColor = new Color('#000000');
textSpan.textColor = Color.dynamic(new Color(this.dateBeanDayColor()), new Color(this.dateBeanNightColor()));
textSpan.font = Font.regularSystemFont(25);
//================================
beanInfoStack.addSpacer();
image = await this.getImageByUrl(`${remoteRoot}/img/jd/${icon}`);
image = await this.getImageByUrl(`${remoteRoot}/${icon}`);
imgSpan = beanInfoStack.addImage(image);
imgSpan.imageSize = emojiSize;
imgSpan.imageOpacity = 0.7;
imgSpan.imageOpacity = 0.8;
//================================
beanInfoStack.addSpacer();
let todayBeanStack = beanInfoStack.addStack();
todayBeanStack.layoutVertically();
textSpan = todayBeanStack.addText(`今天`);
textSpan.textColor = new Color('#000000');
textSpan.textColor = Color.dynamic(new Color(this.dateBeanTitleDayColor()), new Color(this.dateBeanTitleNightColor()));
textSpan.font = Font.regularSystemFont(12);
todayBeanStack.addSpacer(5);
//
textSpan = todayBeanStack.addText(`${this.beanInfo.todayGain}`);
textSpan.textColor = new Color('#000000');
textSpan.textColor = Color.dynamic(new Color(this.dateBeanDayColor()), new Color(this.dateBeanNightColor()));
textSpan.font = Font.regularSystemFont(25);
beanInfoStack.addSpacer(10);
//================================
......@@ -428,8 +680,8 @@ class Widget extends BaseWidget {
let image;
//================================
const walletSize = new Size(25, 25);
const redPackageColor = new Color('#F62910');
const expiredRedPackageColor = new Color('#ff8260');
const redPackageColor = Color.dynamic(new Color(this.redPackageDayColor()), new Color(this.redPackageNightColor()));
const expiredRedPackageColor = Color.dynamic(new Color(this.expiredRedPackageDayColor()), new Color(this.expiredRedPackageNightColor()));
//================================
detailInfoStack.addSpacer(2);
let walletStack = detailInfoStack.addStack();
......@@ -461,7 +713,7 @@ class Widget extends BaseWidget {
let image;
//================================
const fruitSize = new Size(18, 18);
const fruitColor = new Color('#84B264');
const fruitColor = Color.dynamic(new Color(this.fruitDayColor()), new Color(this.fruitNightColor()));
//================================
detailInfoStack.addSpacer(6);
let fruitStack = detailInfoStack.addStack();
......
......@@ -2177,10 +2177,22 @@ class BaseWidget {
// icon转换
for (let index = 0; index < settingItems.length; index++) {
const item = settingItems[index];
const icon = item.icon;
const { name, color } = icon;
if (typeof icon !== 'string') {
item.icon = await this.loadSF2B64(name, color);
if (isChildLevel) {
const childItems = item.items;
for (let childIndex = 0; childIndex < childItems.length; childIndex++) {
const childItem = childItems[childIndex];
const icon = childItem.icon;
const { name, color } = icon;
if (typeof icon !== 'string') {
childItem.icon = await this.loadSF2B64(name, color);
}
}
} else {
const icon = item.icon;
const { name, color } = icon;
if (typeof icon !== 'string') {
item.icon = await this.loadSF2B64(name, color);
}
}
}
......@@ -2212,116 +2224,140 @@ class BaseWidget {
invoke('changeSettings', formData)
})
const formData = {};
const fragment = document.createDocumentFragment()
for (const item of settingItems) {
const value = item.desc ?? settings[item.name] ?? item.default ?? null
if(value && item.type != 'cell') {
formData[item.name] = value;
}
const label = document.createElement("label");
label.className = "form-item";
if(item.id) {
label.id = item.id;
}
const divLabel = document.createElement("div");
divLabel.className = 'form-label';
label.appendChild(divLabel);
const img = document.createElement("img");
img.src = item.icon;
img.className = 'form-label-img';
divLabel.appendChild(img);
const divTitle = document.createElement("div");
divTitle.className = 'form-label-title';
divTitle.innerText = item.label;
divLabel.appendChild(divTitle);
if (item.type === 'select') {
const select = document.createElement('select')
select.className = 'form-item__input'
select.name = item.name
select.value = value
for (const opt of (item.options || [])) {
const option = document.createElement('option')
option.value = opt.value
option.innerText = opt.label
option.selected = value === opt.value
select.appendChild(option)
function createSettingItems(fragment, settingItems, formId) {
const formData = {};
for (const item of settingItems) {
const value = item.desc ?? settings[item.name] ?? item.default ?? null;
if(value && item.type != 'cell') {
formData[item.name] = value;
}
select.addEventListener('change', (e) => {
formData[item.name] = e.target.value
invoke('changeSettings', formData)
})
label.appendChild(select)
} else if (item.type === 'cell') {
label.classList.add('form-item--link')
const divLabel2 = document.createElement("div");
divLabel2.className = 'form-label';
label.appendChild(divLabel2);
const descDiv = document.createElement("div");
descDiv.setAttribute('id', item.name);
descDiv.className = 'form-item-right-desc';
if(item.showDesc != false) {
descDiv.innerText = value ?? '';
const label = document.createElement("label");
label.className = "form-item";
if(item.id) {
label.id = item.id;
}
divLabel2.appendChild(descDiv);
const icon = document.createElement('i')
icon.className = 'iconfont icon-arrow-right'
divLabel2.appendChild(icon)
label.addEventListener('click', (e) => {
if(item.needLoading) {
toggleIcoLoading(e);
const divLabel = document.createElement("div");
divLabel.className = 'form-label';
label.appendChild(divLabel);
const img = document.createElement("img");
img.src = item.icon;
img.className = 'form-label-img';
divLabel.appendChild(img);
const divTitle = document.createElement("div");
divTitle.className = 'form-label-title';
divTitle.innerText = item.label;
divLabel.appendChild(divTitle);
if (item.type === 'select') {
const select = document.createElement('select');
select.className = 'form-item__input';
select.name = item.name;
select.value = value;
for (const opt of (item.options || [])) {
const option = document.createElement('option');
option.value = opt.value;
option.innerText = opt.label;
option.selected = value === opt.value;
select.appendChild(option);
}
let openWeb = item.openWeb
if(openWeb) {
invoke('safari', openWeb)
} else {
invoke('itemClick', item)
select.addEventListener('change', (e) => {
formData[item.name] = e.target.value;
invoke('changeSettings', formData);
})
label.appendChild(select);
} else if (item.type === 'cell') {
label.classList.add('form-item--link');
const divLabel2 = document.createElement("div");
divLabel2.className = 'form-label';
label.appendChild(divLabel2);
const descDiv = document.createElement("div");
descDiv.setAttribute('id', item.name);
descDiv.className = 'form-item-right-desc';
if(item.showDesc != false) {
descDiv.innerText = value ?? '';
}
})
} else {
const input = document.createElement("input")
input.className = 'form-item__input'
input.name = item.name
input.type = item.type || "text";
input.enterKeyHint = 'done'
input.value = value
if (item.type === 'switch') {
input.type = 'checkbox'
input.role = 'switch'
input.checked = value
}
if (item.type === 'number') {
input.inputMode = 'decimal'
}
if (input.type === 'text') {
input.size = 12
divLabel2.appendChild(descDiv);
const icon = document.createElement('i');
icon.className = 'iconfont icon-arrow-right';
divLabel2.appendChild(icon);
label.addEventListener('click', (e) => {
if(item.needLoading) {
toggleIcoLoading(e);
}
let openWeb = item.openWeb;
if(openWeb) {
invoke('safari', openWeb);
} else {
invoke('itemClick', item);
}
})
} else {
const input = document.createElement("input");
input.className = 'form-item__input';
input.name = item.name;
input.type = item.type || "text";
input.enterKeyHint = 'done';
input.value = value;
if (item.type === 'switch') {
input.type = 'checkbox';
input.role = 'switch';
input.checked = value;
}
if (item.type === 'number') {
input.inputMode = 'decimal';
}
if (input.type === 'text') {
input.size = 12;
}
input.addEventListener("change", (e) => {
formData[item.name] =
item.type === 'switch'
? e.target.checked
: item.type === 'number'
? Number(e.target.value)
: e.target.value;
invoke('changeSettings', formData)
});
label.appendChild(input);
}
input.addEventListener("change", (e) => {
formData[item.name] =
item.type === 'switch'
? e.target.checked
: item.type === 'number'
? Number(e.target.value)
: e.target.value;
invoke('changeSettings', formData)
});
label.appendChild(input);
fragment.appendChild(label);
}
fragment.appendChild(label);
document.getElementById(formId).appendChild(fragment);
return formData;
}
let formData = {};
const fragment = document.createDocumentFragment();
if(${isChildLevel}) {
let subIndex = 0;
let tmpFormData = {};
for (const item of settingItems) {
subIndex++;
//
const subForm = document.createElement("form");
let formId = 'form_sub_menu_' + subIndex;
subForm.id = formId;
subForm.className = 'list__body';
subForm.action = 'javascript:void(0);';
//
document.getElementById('sub_list').appendChild(subForm);
tmpFormData = createSettingItems(fragment, item.items, formId);
formData = Object.assign(formData, tmpFormData);
}
} else {
formData = createSettingItems(fragment, settingItems, 'form');
}
document.getElementById('form').appendChild(fragment)
// 切换ico的loading效果
const toggleIcoLoading = (e) => {
......@@ -2418,10 +2454,10 @@ class BaseWidget {
</form>
</div>
<!--组件设置-->
<div class="list">
<div class="list__header">${subTitle ? subTitle : '组件设置'}</div>
<div class="list" style="display:${!isChildLevel ? '' : 'none'}">
<div class="list__header">组件设置</div>
<form id="form" class="list__body" action="javascript:void(0);">
<label id="widgetBg" class="form-item form-item--link" style="display:${!isChildLevel && showWidgetBg ? '' : 'none'}">
<label id="widgetBg" class="form-item form-item--link" style="display:${showWidgetBg ? '' : 'none'}">
<div class="form-label">
<img class="form-label-img" src="${widgetBgIco}"/>
<div class="form-label-title">组件背景</div>
......@@ -2496,6 +2532,9 @@ class BaseWidget {
</label>
</form>
</div>
<!--二级菜单-->
<div id='sub_list' class="list" style="display:${isChildLevel ? '' : 'none'}">
</div>
<footer style="display:${!isChildLevel ? '' : 'none'}">
<div class="copyright"><div> </div><div>© 界面样式修改自 <a href="javascript:invoke('safari', 'https://www.imarkr.com');">@iMarkr.</a></div></div>
</footer>
......@@ -2527,6 +2566,7 @@ class BaseWidget {
}
})()`, true).catch((err) => {
console.error(err);
this.dismissLoading(previewWebView);
});
////////////////////////////////////
let widgetSetting = this.readWidgetSetting();
......@@ -2847,7 +2887,7 @@ class BaseWidget {
isChildLevel: true,
showWidgetBg: false,
subTitle: label,
settingItems: [...childItems]
settingItems: childItems
});
} else {
if (alert) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册