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

update

上级 4003231b
......@@ -8,7 +8,7 @@
*/
// 当前环境版本号
const VERSION = 20221220
const VERSION = 20221222
// 组件配置文件名
const settingConfigName = 'settings.json';
// 组件默认配置
......@@ -1824,32 +1824,6 @@ class BaseWidget {
this.logDivider();
return response
}
/**
* 节假日信息
* @returns 节假日信息
*/
holidayInfo = async () => {
let holiday = { isHoliday: false, lunarDate: '', holiday_cn: '' };
const url = 'https://api.apihubs.cn/holiday/get?cn=1&size=31';
const holidayJsonData = await this.httpGet(url);
if (holidayJsonData.code === 0) {
const dateStr = getDateStr(new Date(), 'yyyyMMdd');
const list = holidayJsonData.data.list;
list.forEach(element => {
let lunar_date_cn = element.lunar_date_cn;
let index = lunar_date_cn.lastIndexOf('') + 1;
holiday.lunarDate = lunar_date_cn.slice(index);
holiday.holiday_cn = element.holiday_cn;
if (element.date == dateStr) {
holiday.isHoliday = element.workday == 2;
}
});
}
console.log(`🚀 节假日信息:${JSON.stringify(holiday)}`);
this.logDivider();
return holiday;
}
// ***************************************************
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
......
......@@ -3,7 +3,7 @@
// icon-color: red; icon-glyph: user-astronaut;
/**
* Author:LSP
* Date:2022-12-15
* Date:2022-12-22
*/
// -------------------------------------------------------
// 是否是开发环境,配合手机端调试使用,正式发布设置为false
......@@ -28,15 +28,14 @@ class Widget extends BaseWidget {
defaultPreference = {
caiyun: 'UR8ASaplvIwavDfR',
weatherIco: '0',
covArea: '440100',
temperatureFontColor: '#FFFFFF',
temperatureFontSize: '34',
dateFontColor: '#FFFEF9',
dateFontSize: '13',
weatherFontColor: '#F9F4DC',
weatherFontSize: '12',
covFontColor: '#F1939C',
covFontSize: '13',
holidayFontColor: '#F1939C',
holidayFontSize: '13',
quickFontSize: '11',
quickFontColor: '#FFFFFF',
quickConfigs: [
......@@ -67,15 +66,14 @@ class Widget extends BaseWidget {
getValueByKey = (key) => this.readWidgetSetting()[key] ?? this.defaultPreference[key];
caiyun = () => this.getValueByKey('caiyun');
weatherIco = () => this.getValueByKey('weatherIco');
covArea = () => this.getValueByKey('covArea');
temperatureFontColor = () => this.getValueByKey('temperatureFontColor');
temperatureFontSize = () => this.getValueByKey('temperatureFontSize');
dateFontColor = () => this.getValueByKey('dateFontColor');
dateFontSize = () => this.getValueByKey('dateFontSize');
weatherFontColor = () => this.getValueByKey('weatherFontColor');
weatherFontSize = () => this.getValueByKey('weatherFontSize');
covFontColor = () => this.getValueByKey('covFontColor');
covFontSize = () => this.getValueByKey('covFontSize');
holidayFontColor = () => this.getValueByKey('holidayFontColor');
holidayFontSize = () => this.getValueByKey('holidayFontSize');
quickFontSize = () => this.getValueByKey('quickFontSize');
quickFontColor = () => this.getValueByKey('quickFontColor');
......@@ -129,14 +127,6 @@ class Widget extends BaseWidget {
needLoading: false,
default: (this.weatherIco() >= 1 && this.weatherIco() <= 10) ? `第${this.weatherIco()}套图标` : '随机',
},
{
name: 'covArea',
label: '疫情地区',
type: 'cell',
icon: { name: 'location', color: '#ff5400', },
needLoading: false,
default: this.covArea(),
},
{
name: 'quickStart',
label: '快捷启动',
......@@ -253,29 +243,29 @@ class Widget extends BaseWidget {
default: this.weatherFontColor(),
},
{
name: 'covFontSize',
label: '疫情文字大小',
name: 'holidayFontSize',
label: '节假日文字大小',
type: 'cell',
icon: 'https://gitcode.net/enoyee/scriptable/-/raw/master/img/ic_corona_virus.png',
icon: 'https://gitcode.net/enoyee/scriptable/-/raw/master/img/icon_holiday.png',
needLoading: false,
alert: {
title: '疫情文字大小',
title: '节假日文字大小',
options: [
{
key: 'covFontSize',
key: 'holidayFontSize',
hint: '请输入字号',
}
]
},
default: this.covFontSize(),
default: this.holidayFontSize(),
},
{
name: 'covFontColor',
label: '疫情文字颜色',
name: 'holidayFontColor',
label: '节假日文字颜色',
type: 'color',
icon: 'https://gitcode.net/enoyee/scriptable/-/raw/master/img/ic_corona_virus.png',
icon: 'https://gitcode.net/enoyee/scriptable/-/raw/master/img/icon_holiday.png',
needLoading: false,
default: this.covFontColor(),
default: this.holidayFontColor(),
},
]
},
......@@ -289,26 +279,6 @@ class Widget extends BaseWidget {
insertDesc = (this.weatherIco() >= 1 && this.weatherIco() <= 10) ? `第${this.weatherIco()}套图标` : '随机';
break
case 'covArea':
const _alertID = await this.generateAlert(
'疫情地区',
'疫情数据对应的地区设置\n默认展示为广州\n其他地区请点击地区编码查询后填入',
['查看编码', '填写编码']
);
if (_alertID === 0) {
await Safari.openInApp('http://www.gov.cn/test/2011-08/22/content_1930111.htm', false);
} else {
await this.generateInputAlert({
title: '疫情地区',
options: [{ hint: '请输入地区编码', value: '' }]
}, async (inputArr) => {
const area = inputArr[0].value;
widgetSetting.covArea = area;
insertDesc = area;
});
}
break;
case 'quickStart':
const ufm = this.useFileManager();
const index = await this.presentSheet({
......@@ -457,8 +427,8 @@ class Widget extends BaseWidget {
const lunarInfo = await this.getLunarInfo()
// 请求彩云
const weatherInfo = await this.getWeather();
// 请求新冠疫情数据
const cov = await this.getCov();
// 节假日
const holidayInfo = await this.holidayInfo();
// ========================================
stack.addSpacer();
let weatherStack = stack.addStack();
......@@ -498,13 +468,13 @@ class Widget extends BaseWidget {
textWidget.font = Font.regularSystemFont(this.scaleFontSize(Number(this.weatherFontSize()), text.length, 50));
textWidget.lineLimit = 2;
// ------------------------------------------------
text = `${cov.cityName}确诊:${cov.mainland_confirmed_incr},无症状:${cov.asymptomatic_incr}`;
text = holidayInfo;
stack.addSpacer(6);
textWidget = stack.addText(text);
textWidget.url = 'https://so.toutiao.com/search?keyword=%E7%96%AB%E6%83%85%E5%AE%9E%E6%97%B6%E6%9C%80%E6%96%B0%E9%80%9A%E6%8A%A5';
textWidget.textColor = new Color(this.covFontColor());
textWidget.url = 'calshow://';
textWidget.textColor = new Color(this.holidayFontColor());
textWidget.font = Font.regularSystemFont(this.scaleFontSize(Number(this.covFontSize()), text.length, 15));
textWidget.font = Font.regularSystemFont(Number(this.holidayFontSize()));
textWidget.lineLimit = 1;
// ------------------------------------------------
stack.addSpacer();
......@@ -513,26 +483,48 @@ class Widget extends BaseWidget {
// --------------------------NET START--------------------------
/**
* 获取头条疫情数据
* @returns
* 节假日信息
* @returns 节假日信息
*/
getCov = async () => {
const areaCache = this.covArea();
const url = `https://i.snssdk.com/ncov/city_data/?recent_days=90&city_code=${areaCache}&only_history=0`;
const covJsonData = await this.httpGet(url);
const cityData = covJsonData.city_data;
const currentData = cityData.current;
const cityName = cityData.name;
const dateStr = this.getDateStr(new Date(currentData.update_time * 1000), 'MM月dd HH:mm');
// 确诊:mainland_confirmed_incr,无症状:asymptomatic_incr,现有:treating
const { mainland_confirmed_incr, asymptomatic_incr, treating, updateTimeStr = dateStr } = currentData;
return {
cityName,
mainland_confirmed_incr: mainland_confirmed_incr === '待公布' ? '--' : mainland_confirmed_incr,
asymptomatic_incr: asymptomatic_incr === '待公布' ? '--' : asymptomatic_incr,
treating,
updateTimeStr,
};
holidayInfo = async () => {
const currDate = new Date();
let url = 'https://api.apihubs.cn/holiday/get?field=date,workday,holiday_legal,holiday_today,holiday_recess,holiday,weekend&order_by=1&cn=1&size=31';
let holidayJsonData = await this.httpGet(url);
if (holidayJsonData.code === 0) {
let dateStr = this.getDateStr(currDate, 'yyyyMMdd');
let list = holidayJsonData.data.list;
let currItem = list.find(item => item.date == dateStr);
if (currItem.workday_cn == '非工作日') {
return '`周末啦~~Have fun(๑•̀ㅂ•́)و✧';
}
let currIndex = list.indexOf(currItem);
let remainArr = list.slice(currIndex, list.size);
let notWorkday = remainArr.find(item => item.workday_cn == '非工作日');
console.log(JSON.stringify(remainArr)); // TODO
if (notWorkday == undefined) {
let nexMonth = '';
const currMonth = currDate.getMonth() + 1;
if (currMonth == 12) {
nexMonth = `${currDate.getFullYear() + 1}${this.getDateStr(currDate, 'MM')}`;
}
url = `https://api.apihubs.cn/holiday/get?field=date,workday,holiday_legal,holiday_today,holiday_recess,holiday,weekend&order_by=1&month=${nexMonth}&cn=1&size=31`;
holidayJsonData = await this.httpGet(url);
notWorkday = remainArr.find(item => item.workday_cn == '非工作日');
}
let currDayFullYear = currItem.date_cn.replace('', '-').replace('', '-').replace('', '');
let notWorkdayFullYear = notWorkday.date_cn.replace('', '-').replace('', '-').replace('', '');
let remainDay = (new Date(notWorkdayFullYear) - new Date(currDayFullYear)) / 86400 / 1000;
let holidayTips = notWorkday.holiday_cn == '非节假日' ? notWorkday.weekend_cn : notWorkday.holiday_cn + '假期';
console.log(`还有${remainDay}天到${holidayTips}`);
return `还有${remainDay}天到${holidayTips}ヽ(;´Д`)ノ`;
}
return '接口数据飞到外太空了ヽ(;´Д`)ノ';
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册