This commit is contained in:
haoouba 2021-01-20 19:59:23 +08:00
parent 10d5b45193
commit 0a436bd869
6 changed files with 745 additions and 650 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,72 +1,72 @@
window.Joe = function () {
/* Dropdown */
{
$('.joe_dropdown').each(function (index, item) {
const menu = $(this).find('.joe_dropdown__menu');
/* 弹出方式 */
const trigger = $(item).attr('trigger') || 'click';
/* 弹出高度 */
const placement = $(item).attr('placement') || $(this).height() || 0;
/* 设置弹出高度 */
menu.css('top', placement);
/* 如果是hover则绑定hover事件 */
if (trigger === 'hover') {
$(this).hover(
() => $(this).addClass('active'),
() => $(this).removeClass('active')
);
} else {
/* 否则绑定点击事件 */
$(this).on('click', function (e) {
$(this).toggleClass('active');
$(document).one('click', () => $(this).removeClass('active'));
e.stopPropagation();
});
menu.on('click', e => e.stopPropagation());
}
});
}
/* Timelife */
if ($('.joe_aside__item.timelife').length !== 0) {
let timelife = [
{ title: '今日已经过去', endTitle: '小时', num: 0, percent: '0%' },
{ title: '这周已经过去', endTitle: '天', num: 0, percent: '0%' },
{ title: '本月已经过去', endTitle: '天', num: 0, percent: '0%' },
{ title: '今年已经过去', endTitle: '个月', num: 0, percent: '0%' }
];
{
let nowDate = +new Date();
let todayStartDate = new Date(new Date().toLocaleDateString()).getTime();
let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60;
let todayPassHoursPercent = (todayPassHours / 24) * 100;
timelife[0].num = parseInt(todayPassHours);
timelife[0].percent = parseInt(todayPassHoursPercent) + '%';
}
{
let weeks = { 0: 7, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6 };
let weekDay = weeks[new Date().getDay()];
let weekDayPassPercent = (weekDay / 7) * 100;
timelife[1].num = parseInt(weekDay);
timelife[1].percent = parseInt(weekDayPassPercent) + '%';
}
{
let year = new Date().getFullYear();
let date = new Date().getDate();
let month = new Date().getMonth() + 1;
let monthAll = new Date(year, month, 0).getDate();
let monthPassPercent = (date / monthAll) * 100;
timelife[2].num = date;
timelife[2].percent = parseInt(monthPassPercent) + '%';
}
{
let month = new Date().getMonth() + 1;
let yearPass = (month / 12) * 100;
timelife[3].num = month;
timelife[3].percent = parseInt(yearPass) + '%';
}
let htmlStr = '';
timelife.forEach((item, index) => {
htmlStr += `
/* Dropdown */
{
$('.joe_dropdown').each(function (index, item) {
const menu = $(this).find('.joe_dropdown__menu')
/* 弹出方式 */
const trigger = $(item).attr('trigger') || 'click'
/* 弹出高度 */
const placement = $(item).attr('placement') || $(this).height() || 0
/* 设置弹出高度 */
menu.css('top', placement)
/* 如果是hover则绑定hover事件 */
if (trigger === 'hover') {
$(this).hover(
() => $(this).addClass('active'),
() => $(this).removeClass('active')
)
} else {
/* 否则绑定点击事件 */
$(this).on('click', function (e) {
$(this).toggleClass('active')
$(document).one('click', () => $(this).removeClass('active'))
e.stopPropagation()
})
menu.on('click', e => e.stopPropagation())
}
})
}
/* Timelife */
if ($('.joe_aside__item.timelife').length !== 0) {
let timelife = [
{ title: '今日已经过去', endTitle: '小时', num: 0, percent: '0%' },
{ title: '这周已经过去', endTitle: '天', num: 0, percent: '0%' },
{ title: '本月已经过去', endTitle: '天', num: 0, percent: '0%' },
{ title: '今年已经过去', endTitle: '个月', num: 0, percent: '0%' }
]
{
let nowDate = +new Date()
let todayStartDate = new Date(new Date().toLocaleDateString()).getTime()
let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60
let todayPassHoursPercent = (todayPassHours / 24) * 100
timelife[0].num = parseInt(todayPassHours)
timelife[0].percent = parseInt(todayPassHoursPercent) + '%'
}
{
let weeks = { 0: 7, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6 }
let weekDay = weeks[new Date().getDay()]
let weekDayPassPercent = (weekDay / 7) * 100
timelife[1].num = parseInt(weekDay)
timelife[1].percent = parseInt(weekDayPassPercent) + '%'
}
{
let year = new Date().getFullYear()
let date = new Date().getDate()
let month = new Date().getMonth() + 1
let monthAll = new Date(year, month, 0).getDate()
let monthPassPercent = (date / monthAll) * 100
timelife[2].num = date
timelife[2].percent = parseInt(monthPassPercent) + '%'
}
{
let month = new Date().getMonth() + 1
let yearPass = (month / 12) * 100
timelife[3].num = month
timelife[3].percent = parseInt(yearPass) + '%'
}
let htmlStr = ''
timelife.forEach((item, index) => {
htmlStr += `
<div class="item">
<div class="title">
${item.title}
@ -80,20 +80,43 @@ window.Joe = function () {
<div class="progress-percentage">${item.percent}</div>
</div>
</div>
`;
});
$('.joe_aside__item.timelife .joe_aside__item-contain').html(htmlStr);
}
`
})
$('.joe_aside__item.timelife .joe_aside__item-contain').html(htmlStr)
}
/* Weather */
if ($('.joe_aside__item.weather').length !== 0) {
const key = $('.joe_aside__item.weather').attr('data-key');
const style = $('.joe_aside__item.weather').attr('data-style');
const aqiColor = { 1: 'FFFFFF', 2: '4A4A4A', 3: 'FFFFFF' };
window.WIDGET = { CONFIG: { layout: 2, width: '220', height: '270', background: style, dataColor: aqiColor[style], language: 'zh', key: key } };
}
/* Weather */
if ($('.joe_aside__item.weather').length !== 0) {
const key = $('.joe_aside__item.weather').attr('data-key')
const style = $('.joe_aside__item.weather').attr('data-style')
const aqiColor = { 1: 'FFFFFF', 2: '4A4A4A', 3: 'FFFFFF' }
window.WIDGET = { CONFIG: { layout: 2, width: '220', height: '270', background: style, dataColor: aqiColor[style], language: 'zh', key: key } }
}
new LazyLoad('.lazyload');
};
if ($('.joe_aside__item.ranking').length !== 0) {
$.ajax({
url: '/index.php/action/ranking',
success(res) {
$('.joe_aside__item.ranking .joe_aside__item-title .text').html(res.title)
let htmlStr = ''
if (res.code === 1) {
res.data.forEach((item, index) => {
htmlStr += `
<li class="item">
<span class="sort">${index + 1}</span>
<a class="link" href="${item.url}" title="${item.title}" target="_blank" rel="noopener noreferrer nofollow">${item.title}</a>
</li>
`
})
} else {
htmlStr += `<li class="error">数据抓取异常!</li>`
}
$('.joe_aside__item.ranking .joe_aside__item-contain').html(htmlStr)
}
})
}
document.addEventListener('DOMContentLoaded', () => Joe());
new LazyLoad('.lazyload')
}
document.addEventListener('DOMContentLoaded', () => Joe())

View File

@ -20,11 +20,16 @@ function _getRanking($self)
$res = json_decode($json, TRUE);
if ($res['code'] === 0) {
$self->response->throwJson([
"code" => 1,
"title" => $ranking_arr[0],
"data" => $res["data"]
]);
} else {
$self->response->throwJson(null);
$self->response->throwJson([
"code" => 0,
"title" => $ranking_arr[0],
"data" => null
]);
}
}

View File

@ -288,7 +288,7 @@ function themeConfig($form)
'JThumbnail',
NULL,
NULL,
'自定义缩略图(非必填)',
'自定义缩略图',
'介绍:用于修改主题默认缩略图 <br/>
格式:图片地址,一行一个 <br />
注意:不填写时,则使用主题内置的默认缩略图
@ -301,7 +301,7 @@ function themeConfig($form)
'JLazyload',
NULL,
"https://cdn.jsdelivr.net/gh/HaoOuBa/Joe@master/assets/img/lazyload.jpg",
'自定义懒加载图(非必填)',
'自定义懒加载图',
'介绍:用于修改主题默认懒加载图 <br/>
格式:图片地址'
);

View File

@ -75,6 +75,20 @@
</section>
<?php endif; ?>
<?php if (in_array('ranking', $this->options->JAside)) : ?>
<section class="joe_aside__item ranking">
<div class="joe_aside__item-title">
<svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
<path d="M939.855405 202.777641H832.417563v-78.366426A124.320931 124.320931 0 0 0 708.367484 0H315.271381a124.411215 124.411215 0 0 0-124.05008 124.411215v78.366426H83.873744A84.144595 84.144595 0 0 0 0 286.922236c0 123.14724 82.248633 199.437136 194.561806 232.481044a321.862105 321.862105 0 0 0 281.414918 273.469935v158.899665H308.680656a36.11356 36.11356 0 0 0 0 72.22712h406.277552a36.11356 36.11356 0 0 0 0-72.22712H547.662141v-158.899665a321.681538 321.681538 0 0 0 281.414918-273.469935c112.313172-33.043908 194.65209-109.333804 194.652089-232.481044a84.144595 84.144595 0 0 0-83.873743-84.144595zM67.442074 286.922236A16.612238 16.612238 0 0 1 83.873744 270.851702h107.347557v175.602186C118.542761 415.305943 67.442074 370.976547 67.442074 286.922236z m444.377358 440.314583a254.14918 254.14918 0 0 1-252.794921-253.968612V124.411215a56.69829 56.69829 0 0 1 56.24687-56.69829h393.096103a56.69829 56.69829 0 0 1 56.608005 56.69829v348.856992a254.14918 254.14918 0 0 1-252.794921 253.968612z m320.598131-280.782931V270.851702h107.437842a16.612238 16.612238 0 0 1 16.341386 16.43167c0 83.693176-51.100688 128.022571-123.779228 159.170516z" p-id="15686"></path>
<path d="M696.540293 469.476283a33.675895 33.675895 0 0 0-43.426556 19.772174 153.482631 153.482631 0 0 1-92.540999 90.283901 33.856463 33.856463 0 0 0 11.014636 65.816963 32.953624 32.953624 0 0 0 10.924352-1.805678 218.938459 218.938459 0 0 0 133.710457-130.640804A33.856463 33.856463 0 0 0 696.540293 469.476283zM517.417034 157.906542l-2.437665 2.708517a163.955563 163.955563 0 0 1-33.856463 27.08517 183.998589 183.998589 0 0 1-39.8152 16.341386l-6.410157 1.62511v64.914125l10.743784-3.069653a180.567801 180.567801 0 0 0 55.253747-25.911479v223.272086h64.282137v-306.965262z" p-id="15687"></path>
</svg>
<span class="text"></span>
<span class="line"></span>
</div>
<ul class="joe_aside__item-contain"></ul>
</section>
<?php endif; ?>
<?php if (in_array('weather', $this->options->JAside) && $this->options->JAside_Weather_Key) : ?>
<section class="joe_aside__item weather" data-key="<?php $this->options->JAside_Weather_Key() ?>" data-style="<?php $this->options->JAside_Weather_Style() ?>">
<div class="joe_aside__item-title">