Browse Source

add small image create for new dirs

master
filesite 5 months ago
parent
commit
d47e5345b9
  1. 16
      themes/beauty/controller/SiteController.php
  2. 16
      www/js/beauty.js

16
themes/beauty/controller/SiteController.php

@ -171,6 +171,7 @@ Class SiteController extends Controller { @@ -171,6 +171,7 @@ Class SiteController extends Controller {
$code = 1;
$msg = 'OK';
$url = '';
$img_id = '';
$cacheId = $this->post('cid', '');
$cateId = $this->post('id', '');
@ -180,9 +181,9 @@ Class SiteController extends Controller { @@ -180,9 +181,9 @@ Class SiteController extends Controller {
}else {
//优先从缓存获取
$cacheKey = $this->getCacheKey($cateId, 'dirsnap');
$url = Common::getCacheFromFile($cacheKey);
$cachedData = Common::getCacheFromFile($cacheKey);
if (empty($url)) {
if (empty($cachedData)) {
//从缓存数据中获取目录的realpath
$cachedData = Common::getCacheFromFile($cacheId);
if (!empty($cachedData)) {
@ -208,11 +209,12 @@ Class SiteController extends Controller { @@ -208,11 +209,12 @@ Class SiteController extends Controller {
$cachedData = Common::getCacheFromFile($cacheKey_snap, $expireSeconds, $cacheSubDir);
if (!empty($cachedData)) {
$url = $cachedData['snapshot'];
Common::saveCacheToFile($cacheKey, $url);
Common::saveCacheToFile($cacheKey, compact('url', 'img_id'));
}
}
}else {
$url = $imgFile['path'];
$img_id = $imgFile['id'];
//小尺寸图片支持
$cacheKey = $this->getCacheKey($imgFile['id'], 'imgsm');
@ -221,18 +223,22 @@ Class SiteController extends Controller { @@ -221,18 +223,22 @@ Class SiteController extends Controller {
$cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir);
if (!empty($cachedData)) {
$url = $cachedData;
$img_id = ''; //无需再次生成小尺寸图片
}
Common::saveCacheToFile($cacheKey, $url);
Common::saveCacheToFile($cacheKey, compact('url', 'img_id'));
}
}else {
$code = 0;
$msg = '缓存数据已失效,请刷新网页';
}
}else {
$url = $cachedData['url'];
$img_id = $cachedData['img_id'];
}
}
return $this->renderJson(compact('code', 'msg', 'url'));
return $this->renderJson(compact('code', 'msg', 'url', 'img_id'));
}
//优先从缓存获取小尺寸的图片

16
www/js/beauty.js

@ -180,7 +180,21 @@ $('.dir_item').each(function(index, el) { @@ -180,7 +180,21 @@ $('.dir_item').each(function(index, el) {
}
}).done(function(data) {
if (data.code == 1 && data.url) {
$(el).find('.im_img_title').before('<img src="' + data.url + '" class="bor_radius im_img">');
var imgHtml = '<img src="' + data.url + '"';
if (data.img_id) {
imgHtml += ' data-id="' + data.img_id + '"'
}
imgHtml += ' class="bor_radius im_img">';
$(el).find('.im_img_title').before(imgHtml);
if (data.img_id) {
setTimeout(function() {
var imgs = $(el).find('.im_img');
if (imgs.length > 0) {
saveSmallImg(imgs[0]);
}
}, 100);
}
}else {
console.warn('目录 %s 里没有任何图片', id);
}

Loading…
Cancel
Save