From 138ee2b86abec9b8a02c8ec36fa21efb84f02503 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Wed, 31 Aug 2022 23:08:26 +0800 Subject: [PATCH] image lazy load --- .../User/UserResource/Pages/UserProfile.php | 5 ++- app/Models/Torrent.php | 2 +- include/constants.php | 2 +- include/functions.php | 18 +++++++- nexus/Install/Update.php | 2 +- public/js/nexus.js | 37 ++++++++++++++++- public/pic/misc/spinner.svg | 41 +++++++++++++++++++ 7 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 public/pic/misc/spinner.svg diff --git a/app/Filament/Resources/User/UserResource/Pages/UserProfile.php b/app/Filament/Resources/User/UserResource/Pages/UserProfile.php index c230df3b..7071dbc8 100644 --- a/app/Filament/Resources/User/UserResource/Pages/UserProfile.php +++ b/app/Filament/Resources/User/UserResource/Pages/UserProfile.php @@ -82,13 +82,16 @@ class UserProfile extends Page private function buildEnableDisableAction(): Actions\Action { - return Actions\Action::make($this->record->enabled == 'yes' ? __('admin.resources.user.actions.disable_modal_btn') : __('admin.resources.user.actions.enable_modal_btn')) + return Actions\Action::make('enable_disable') + ->label($this->record->enabled == 'yes' ? __('admin.resources.user.actions.disable_modal_btn') : __('admin.resources.user.actions.enable_modal_btn')) ->modalHeading($this->record->enabled == 'yes' ? __('admin.resources.user.actions.disable_modal_title') : __('admin.resources.user.actions.enable_modal_title')) ->form([ Forms\Components\TextInput::make('reason')->label(__('admin.resources.user.actions.enable_disable_reason'))->placeholder(__('admin.resources.user.actions.enable_disable_reason_placeholder')), Forms\Components\Hidden::make('action')->default($this->record->enabled == 'yes' ? 'disable' : 'enable'), Forms\Components\Hidden::make('uid')->default($this->record->id), ]) +// ->visible(false) +// ->hidden(true) ->action(function ($data) { $userRep = $this->getRep(); try { diff --git a/app/Models/Torrent.php b/app/Models/Torrent.php index 88e1dc22..aa7b762f 100644 --- a/app/Models/Torrent.php +++ b/app/Models/Torrent.php @@ -216,7 +216,7 @@ class Torrent extends NexusModel public static function getFieldsForList($appendTableName = false): array|bool { - $fields = 'id, sp_state, promotion_time_type, promotion_until, banned, picktype, pos_state, category, source, medium, codec, standard, processing, team, audiocodec, leechers, seeders, name, small_descr, times_completed, size, added, comments,anonymous,owner,url,cache_stamp, pt_gen, hr, approval_status'; + $fields = 'id, sp_state, promotion_time_type, promotion_until, banned, picktype, pos_state, category, source, medium, codec, standard, processing, team, audiocodec, leechers, seeders, name, small_descr, times_completed, size, added, comments,anonymous,owner,url,cache_stamp, pt_gen, hr, approval_status, cover'; $fields = preg_split('/[,\s]+/', $fields); if ($appendTableName) { foreach ($fields as &$value) { diff --git a/include/constants.php b/include/constants.php index 5d781857..7d47fff0 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr); $tagRep = new \App\Repositories\TagRepository(); @@ -3487,7 +3488,20 @@ foreach ($rows as $row) $sp_torrent = get_torrent_promotion_append($row['sp_state'],"",true,$row["added"], $row['promotion_time_type'], $row['promotion_until'], $row['__ignore_global_sp_state'] ?? false); $hrImg = get_hr_img($row); - print("', $coverSrc); + print(""); if ($wait) diff --git a/nexus/Install/Update.php b/nexus/Install/Update.php index 54bd9569..497faaad 100644 --- a/nexus/Install/Update.php +++ b/nexus/Install/Update.php @@ -91,7 +91,7 @@ class Update extends Install */ foreach (['adminpanel', 'modpanel', 'sysoppanel'] as $table) { $columnInfo = NexusDB::getMysqlColumnInfo($table, 'id'); - if ($columnInfo['DATA_TYPE'] == 'tinyint') { + if ($columnInfo['DATA_TYPE'] == 'tinyint' || empty($columnInfo['EXTRA']) || $columnInfo['EXTRA'] != 'auto_increment') { sql_query("alter table $table modify id int(11) unsigned not null AUTO_INCREMENT"); } } diff --git a/public/js/nexus.js b/public/js/nexus.js index bd0ea98f..bca0eea3 100644 --- a/public/js/nexus.js +++ b/public/js/nexus.js @@ -8,9 +8,21 @@ jQuery(document).ready(function () { } }) + // preview function getPosition(e, imgEle) { let imgWidth = imgEle.prop('naturalWidth') let imgHeight = imgEle.prop("naturalHeight") + console.log(`imgWidth: ${imgWidth}, imgHeight: ${imgHeight}`) + let ratio = imgWidth / imgHeight; + if (imgWidth > window.innerWidth) { + imgWidth = window.innerWidth; + imgHeight = imgWidth / ratio; + } + if (imgHeight > window.innerHeight) { + imgHeight = window.innerHeight; + imgWidth = imgHeight * ratio; + } + let width = imgWidth, height= imgHeight; let left = e.pageX + 10; if (left + imgWidth > window.innerWidth) { left = e.pageX - 10 - imgWidth @@ -19,7 +31,9 @@ jQuery(document).ready(function () { if (top + imgHeight > window.innerHeight) { top = e.pageY - imgHeight / 2 } - return {left, top} + let result = {left, top, width, height} + console.log(result) + return result } var previewEle = jQuery('#nexus-preview') var imgEle, selector = '.preview' @@ -37,4 +51,25 @@ jQuery(document).ready(function () { previewEle.css(position) }) + // lazy load + if ("IntersectionObserver" in window) { + const imgList = [...document.querySelectorAll('.nexus-lazy-load')] + var io = new IntersectionObserver((entries) =>{ + entries.forEach(item => { + // isIntersecting是一个Boolean值,判断目标元素当前是否可见 + if (item.isIntersecting) { + item.target.src = item.target.dataset.src + item.target.classList.add('preview') + // 图片加载后即停止监听该元素 + io.unobserve(item.target) + } + }) + }, { + root: document.querySelector('body') + }) + + // observe遍历监听所有img节点 + imgList.forEach(img => io.observe(img)) + } + }) diff --git a/public/pic/misc/spinner.svg b/public/pic/misc/spinner.svg new file mode 100644 index 00000000..73eddcc9 --- /dev/null +++ b/public/pic/misc/spinner.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file
".$stickyicon."".htmlspecialchars($dispname).""); + //cover + $coverSrc = ''; + if ($imdb_id = parse_imdb_id($row["url"])) { + try { + $coverSrc = $imdb->getMovie($imdb_id)->photo(false); + } catch (\Exception $exception) { + do_log("torrent: {$row['id']} get cover from imdb error: ".$exception->getMessage() . "\n[stacktrace]\n" . $exception->getTraceAsString(), 'error'); + } + } + if (empty($coverSrc) && !empty($row['cover'])) { + $coverSrc = $row['cover']; + } + $tdCover = sprintf('$tdCover\n"); + print("\n"); print("
".$stickyicon."".htmlspecialchars($dispname).""); $picked_torrent = ""; if ($CURUSER['appendpicked'] != 'no'){ if($row['picktype']=="hot") @@ -3547,7 +3561,7 @@ foreach ($rows as $row) $act .= ($act ? "
" : "")."".get_torrent_bookmark_state($CURUSER['id'], $id).""; } - print("
".$act."".$act."