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

fix

上级 740e42d2
......@@ -27,12 +27,8 @@ const { BaseWidget } = require(dependencyFileName);
class Widget extends BaseWidget {
defaultPreference = {
photoHalving: '1'
};
getValueByKey = (key) => this.readWidgetSetting()[key] ?? this.defaultPreference[key];
photoHalving = () => this.getValueByKey('photoHalving');
constructor(scriptName) {
super(scriptName);
}
......@@ -40,30 +36,12 @@ class Widget extends BaseWidget {
async getAppViewOptions() {
return {
widgetProvider: {
small: true, // 是否提供小号组件
small: false, // 是否提供小号组件
medium: true, // 是否提供中号组件
large: true, // 是否提供大号组件
large: false, // 是否提供大号组件
},
// 预览界面的组件设置item
settingItems: [
{
name: 'photoHalving',
label: '图片等分',
type: 'cell',
icon: { name: 'photo.artframe', color: '#ffca3a' },
alert: {
title: '图片等分设置',
message: "小组件显示多少张图片,最大值为4",
options: [
{
key: 'photoHalving',
hint: '请输入数字进行等分',
}
]
},
needLoading: false,
default: this.photoHalving(),
},
],
};
}
......@@ -72,122 +50,8 @@ class Widget extends BaseWidget {
return await this.provideWidget(family, this.photoHalving());
}
async provideWidget(widgetFamily, photoHalving) {
let name = '大号';
switch (widgetFamily) {
case 'small':
name = '小号';
break;
case 'medium':
name = '中号';
break;
}
//=================================
const widget = new ListWidget();
widget.setPadding(0, 0, 0, 0);
//=================================
let stack = widget.addStack();
const imgRes = await this.loadMirrorPhotoRes();
const widgetSize = this.getWidgetSize(name);
const widgetWidth = widgetSize.width + 8 * Device.screenScale();
// 图片等分
const picHalvingCache = Number(photoHalving);
let imgStack;
switch (picHalvingCache) {
case 2:
stack.layoutHorizontally();
imgStack = stack.addStack();
imgStack.size = new Size(widgetWidth / 2, widgetWidth);
await this.addStackImg(imgRes, imgStack);
//
imgStack = stack.addStack();
imgStack.size = new Size(widgetWidth / 2, widgetWidth);
await this.addStackImg(imgRes, imgStack);
break;
case 3:
stack.layoutVertically();
imgStack = stack.addStack();
imgStack.size = new Size(widgetWidth, widgetWidth / 2);
await this.addStackImg(imgRes, imgStack);
//
imgStack = stack.addStack();
imgStack.layoutHorizontally();
let stack_3_1 = imgStack.addStack();
stack_3_1.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_3_1);
let stack_3_2 = imgStack.addStack();
stack_3_2.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_3_2);
break;
case 4:
stack.layoutVertically();
imgStack = stack.addStack();
imgStack.layoutHorizontally();
let stack_4_1 = imgStack.addStack();
stack_4_1.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_4_1);
let stack_4_2 = imgStack.addStack();
stack_4_2.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_4_2);
//
imgStack = stack.addStack();
imgStack.layoutHorizontally();
let stack_4_3 = imgStack.addStack();
stack_4_3.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_4_3);
let stack_4_4 = imgStack.addStack();
stack_4_4.size = new Size(widgetWidth / 2, widgetWidth / 2);
await this.addStackImg(imgRes, stack_4_4);
break;
default:
stack.layoutHorizontally();
imgStack = stack.addStack();
imgStack.size = new Size(widgetWidth, widgetWidth);
await this.addStackImg(imgRes, imgStack);
break;
}
//=================================
stack.addSpacer();
return widget;
}
addStackImg = async (imgRes, imgStack) => {
if (imgRes && imgRes.length > 0) {
let item = this.getRandowArrValue(imgRes);
let imgUrl = item.url;
imgStack.url = imgUrl;
let img = await this.getImageByUrl(imgUrl, 'mirror', true);
let imgSpan = imgStack.addImage(img);
imgSpan.applyFillingContentMode();
}
}
// --------------------------NET START--------------------------
loadMirrorPhotoRes = async (source = 0) => {
// 万年历数据
const url = `https://www.dounimei.co/page/${parseInt(Math.random() * 80) + 1}?orderby=hot`;
const headers = {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36"
};
const html = await this.httpGet(url, { jsonFromat: false, headers });
const imgResArr = [];
switch (source) {
case 0:
const imgRes = await this.httpGet(`https://dopaminegirl.com/api/posts/ranking?offset=${parseInt(Math.random() * 1000) + 100}`);
imgRes.forEach(element => {
imgResArr.push({ url: element.url });
});
break;
}
return imgResArr;
}
// --------------------------NET END--------------------------
}
......
......@@ -7,7 +7,7 @@
*/
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
const isDev = true;
const isDev = false;
console.log(`开发环境 👉👉👉👉👉 ${isDev ? 'DEV' : 'RELEASE'}`);
console.log(`----------------------------------------`);
const remoteRoot = 'https://gitcode.net/enoyee/scriptable/-/raw/master/';
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册