Skip to content

Commit 3f7782c

Browse files
committed
新增:富文本支持文档一键导入,支持Word文档(docx)、Markdown文档(md)
1 parent bccc612 commit 3f7782c

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

module/ContentBlock/Admin/Controller/ContentBlockController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
use ModStart\Core\Util\ConvertUtil;
1111
use ModStart\Field\AbstractField;
1212
use ModStart\Field\AutoRenderedFieldValue;
13+
use ModStart\Form\Form;
1314
use ModStart\Grid\GridFilter;
1415
use ModStart\Support\Concern\HasFields;
1516
use Module\ContentBlock\Model\ContentBlock;
1617
use Module\ContentBlock\Type\ContentBlockType;
18+
use Module\ContentBlock\Util\ContentBlockUtil;
1719

1820
class ContentBlockController extends Controller
1921
{
@@ -70,6 +72,9 @@ protected function crud(AdminCRUDBuilder $builder)
7072
$filter->eq('type', '类型')->select(ContentBlockType::class);
7173
$filter->eq('name', '标识');
7274
})
75+
->hookChanged(function (Form $form) {
76+
ContentBlockUtil::clearCache();
77+
})
7378
->operateFixed('right')
7479
->canCopy(true)
7580
->title('内容区块');

module/ContentBlock/Docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.2.0
22

33
- 新增:内容块支持通用类型
4+
- 优化:内容块修改时自动清理缓存
45

56
---
67

module/ContentBlock/Util/ContentBlockUtil.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ class ContentBlockUtil
1313
{
1414
const CACHE_KEY_PREFIX = 'ContentBlock:';
1515

16+
public static function clearCache()
17+
{
18+
$records = ContentBlock::all(['id', 'name']);
19+
foreach ($records as $record) {
20+
CacheUtil::forget(self::CACHE_KEY_PREFIX . 'Id:' . $record->id);
21+
CacheUtil::forget(self::CACHE_KEY_PREFIX . 'Name:' . $record->name);
22+
CacheUtil::forget(self::CACHE_KEY_PREFIX . 'Name:' . $record->name . ':All');
23+
}
24+
}
25+
1626
private static function getBy($where)
1727
{
1828
$m = ContentBlock::where($where)
@@ -30,12 +40,12 @@ private static function getBy($where)
3040
return null;
3141
}
3242
$m = $m->toArray();
33-
ModelUtil::decodeRecordJson($m, ['images']);
43+
ModelUtil::decodeRecordJson($m, ['basicImages', 'basicTexts']);
3444
if ($m['image']) {
3545
$m['image'] = AssetsUtil::fixFull($m['image']);
3646
}
37-
if ($m['images']) {
38-
$m['images'] = AssetsUtil::fixFull($m['images'], false);
47+
if ($m['basicImages']) {
48+
$m['basicImages'] = AssetsUtil::fixFull($m['basicImages'], false);
3949
}
4050
return $m;
4151
}
@@ -57,8 +67,9 @@ private static function allBy($where, $limit)
5767
}
5868
$ms = $query->get()->toArray();
5969
AssetsUtil::recordsFixFullOrDefault($ms, ['image']);
70+
ModelUtil::decodeRecordsJson($ms, ['basicImages', 'basicTexts']);
6071
foreach ($ms as $mIndex => $m) {
61-
$ms[$mIndex]['images'] = AssetsUtil::fixFull($m['images'], false);
72+
$ms[$mIndex]['basicImages'] = AssetsUtil::fixFull($m['basicImages'], false);
6273
}
6374
return $ms;
6475
}
@@ -107,10 +118,14 @@ public static function getByIdCached($id)
107118

108119
public static function allCached($name, $limit = 0)
109120
{
110-
return CacheUtil::remember(self::CACHE_KEY_PREFIX . "Name:" . $name . ':' . $limit,
121+
$records = CacheUtil::remember(self::CACHE_KEY_PREFIX . "Name:" . $name . ':All',
111122
3600,
112-
function () use ($name, $limit) {
113-
return self::all($name, $limit);
123+
function () use ($name) {
124+
return self::all($name);
114125
});
126+
if ($limit > 0) {
127+
$records = array_slice($records, 0, $limit);
128+
}
129+
return $records;
115130
}
116131
}

0 commit comments

Comments
 (0)