修复缓存问题,开始使用scss重构

This commit is contained in:
2022-03-26 18:33:24 +08:00
parent e72f20a538
commit 9cb26e2cbf
8 changed files with 437 additions and 387 deletions

2
.gitignore vendored
View File

@@ -6,3 +6,5 @@
ul.db
composer.lock
public/upload/*
/public/cdn/layui-ul.css
/public/cdn/layui-ul.css.map

View File

@@ -20,139 +20,141 @@ use think\route\Url as RouteUrl;
function json_message($data = [], $code = 0, $msg = '')
{
if (is_string($data)) {
if (is_string($data)) {
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
$data = [
'jump_to_url' => $data
];
} else {
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
$data = [
'jump_to_url' => $data
];
} else {
$code = $code === 0 ? 500 : $code;
$msg = $data;
$data = [];
$code = $code === 0 ? 500 : $code;
$msg = $data;
$data = [];
}
} else if ($data instanceof RouteUrl) {
$data = [
'jump_to_url' => (string)$data
];
}
} else if ($data instanceof RouteUrl) {
$data = [
'jump_to_url' => (string)$data
];
}
return json([
'code' => $code,
'msg' => $msg,
'data' => $data
]);
return json([
'code' => $code,
'msg' => $msg,
'data' => $data
]);
}
function get_system_config($name = '', $default = '')
{
$list = Cache::get('system_config');
$list = Cache::get('system_config');
if (empty($list)) {
try {
if (empty($list)) {
try {
$list = SystemConfig::column('value', 'name');
} catch (\Throwable $th) {
return $default;
$list = SystemConfig::column('value', 'name');
Cache::set('system_config', $list);
} catch (\Throwable $th) {
return $default;
}
}
}
if ($name === '') {
return $list;
}
if ($name === '') {
return $list;
}
if (isset($list[$name])) {
return $list[$name];
}
if (isset($list[$name])) {
return $list[$name];
}
return $default;
return $default;
}
function get_source_link($url,$default = '')
function get_source_link($url, $default = '')
{
if (empty($url)) {
if (empty($url)) {
if(!empty($default)){
$url = $default;
}else{
$url = '/static/images/avatar.png';
if (!empty($default)) {
$url = $default;
} else {
$url = '/static/images/avatar.png';
}
}
}
if (strpos($url, '/') === 0) {
return request()->domain() . $url;
}
if (strpos($url, 'http') === 0) {
return $url;
} else {
$resource_domain = get_system_config('resource_domain');
if (strpos($url, '/') === 0) {
return request()->domain() . $url;
}
if (strpos($url, 'http') === 0) {
return $url;
} else {
$resource_domain = get_system_config('resource_domain');
if (empty($resource_domain)) {
$resource_domain = request()->domain();
if (empty($resource_domain)) {
$resource_domain = request()->domain();
}
return $resource_domain . '/' . $url;
}
return $resource_domain . '/' . $url;
}
}
function de_source_link($url)
{
$domain = get_system_config('resource_domain') . '/';
if (strpos($url, $domain) === 0) {
return str_replace($domain, '', $url);
}
return false;
$domain = get_system_config('resource_domain') . '/';
if (strpos($url, $domain) === 0) {
return str_replace($domain, '', $url);
}
return false;
}
function geturl($url)
{
$headerArray = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
$output = curl_exec($ch);
curl_close($ch);
$headerArray = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
$output = curl_exec($ch);
curl_close($ch);
return $output;
return $output;
}
function posturl($url, $data)
{
$data = json_encode($data);
$headerArray = array();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
$data = json_encode($data);
$headerArray = array();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
function format_size($filesize)
{
if ($filesize >= 1073741824) {
if ($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
} elseif ($filesize >= 1048576) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
} elseif ($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
} elseif ($filesize >= 1024) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
} elseif ($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' KB';
} else {
$filesize = round($filesize / 1024 * 100) / 100 . ' KB';
} else {
$filesize = $filesize . ' 字节';
}
$filesize = $filesize . ' 字节';
}
return $filesize;
return $filesize;
}
@@ -167,71 +169,71 @@ function format_size($filesize)
function array2level($array, $pid = 0, $level = 1)
{
static $list = [];
if ($level == 0) {
$list = [];
$level = 1;
}
foreach ($array as $v) {
if ($v['pid'] == $pid) {
$v['level'] = $level;
$list[] = $v;
array2level($array, $v['id'], $level + 1);
static $list = [];
if ($level == 0) {
$list = [];
$level = 1;
}
}
// halt($list);
foreach ($array as $v) {
if ($v['pid'] == $pid) {
$v['level'] = $level;
$list[] = $v;
array2level($array, $v['id'], $level + 1);
}
}
// halt($list);
return $list;
return $list;
}
function check_permission($key, $admin_id = null)
{
if (is_null($admin_id)) {
$admin_id = Session::get('admin_id');
}
if (is_null($admin_id)) {
$admin_id = Session::get('admin_id');
}
if (empty($admin_id)) {
return true;
}
if (empty($admin_id)) {
return true;
}
if ($admin_id == 1) {
return true;
}
if ($admin_id == 1) {
return true;
}
$model_admin = Admin::cache(60)->find($admin_id);
$model_admin = Admin::cache(60)->find($admin_id);
if (empty($model_admin->getData('group_id'))) {
return true;
}
if (empty($model_admin->getData('group_id'))) {
return true;
}
$cache_key = 'permission_' . $key;
$cache_key = 'permission_' . $key;
$model_permission = Cache::get($cache_key);
if (empty($model_permission)) {
$model_permission = AdminPermission::where('key', $key)->find();
Cache::set($cache_key, $model_permission);
}
$model_permission = Cache::get($cache_key);
if (empty($model_permission)) {
$model_permission = AdminPermission::where('key', $key)->find();
Cache::set($cache_key, $model_permission);
}
if (empty($model_permission)) {
$model_permission = AdminPermission::create([
'key' => $key
]);
Cache::set($cache_key, $model_permission, 60);
}
if (empty($model_permission)) {
$model_permission = AdminPermission::create([
'key' => $key
]);
Cache::set($cache_key, $model_permission, 60);
}
if (in_array($model_permission->id, $model_admin->group->permissions)) {
return true;
}
if (in_array($model_permission->id, $model_admin->group->permissions)) {
return true;
}
return false;
return false;
}
function get_order_sn($start = '', $end = '')
{
return $start . date('YmdHis') . mt_rand(1000, 9999) . $end;
return $start . date('YmdHis') . mt_rand(1000, 9999) . $end;
}
/**
@@ -247,22 +249,22 @@ function get_order_sn($start = '', $end = '')
function app_url(string $url = '', array $vars = [], $suffix = true, $domain = false): RouteUrl
{
$url_result = explode('@', $url);
// 在这里,@首先认为是应用名,而不是域名(或子域名)
if (isset($url_result[1])) {
$app_default_doamin = config('app.app_default_doamin');
if (empty($app_default_doamin)) {
$app_domain_bind = config('app.domain_bind');
$url_result = explode('@', $url);
// 在这里,@首先认为是应用名,而不是域名(或子域名)
if (isset($url_result[1])) {
$app_default_doamin = config('app.app_default_doamin');
if (empty($app_default_doamin)) {
$app_domain_bind = config('app.domain_bind');
if (!empty($app_domain_bind)) {
$app_default_doamin = array_flip($app_domain_bind);
}
if (!empty($app_domain_bind)) {
$app_default_doamin = array_flip($app_domain_bind);
}
}
if (isset($app_default_doamin[$url_result[1]]) && $app_default_doamin[$url_result[1]] != '*') {
$url = $url_result[0] . "@" . $app_default_doamin[$url_result[1]];
}
}
if (isset($app_default_doamin[$url_result[1]]) && $app_default_doamin[$url_result[1]] != '*') {
$url = $url_result[0] . "@" . $app_default_doamin[$url_result[1]];
}
}
return url($url, $vars, $suffix, $domain);
return url($url, $vars, $suffix, $domain);
}

View File

@@ -11,92 +11,95 @@ use think\Request;
class Index extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index($post_id = 0)
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index($doc_name = '')
{
$list_post = Post::quickSelect();
if (empty($post_id)) {
$model_post = $list_post->first()->post->first();
} else {
$model_post = Post::quickFind($post_id);
$list_post = Post::quickSelect();
if (empty($doc_name)) {
$model_post = $list_post->first()->post->first();
} else {
if (is_numeric($doc_name)) {
$model_post = Post::quickFind($doc_name);
} else {
$model_post = Post::quickFindByTplName($doc_name);
}
}
View::assign('model_post', $model_post);
View::assign('list_post', $list_post);
return View::fetch();
}
View::assign('model_post', $model_post);
View::assign('list_post', $list_post);
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
return View::fetch();
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存新的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
}
/**
* 保存新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 显示指定资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
}
}

View File

@@ -2,4 +2,4 @@
use think\facade\Route;
Route::rule('doc/[:post_id]','Index/index');
Route::rule('doc/[:doc_name]','Index/index');

View File

@@ -6,6 +6,7 @@ namespace app\model;
use think\facade\App;
use think\facade\Cache;
use think\facade\Request;
use think\facade\View;
use think\Model;
use think\model\concern\SoftDelete;
@@ -15,185 +16,207 @@ use think\model\concern\SoftDelete;
*/
class Post extends Model
{
//
//
public static $stausNameList = [
0 => '不发布',
1 => '发布'
];
public static $stausNameList = [
0 => '不发布',
1 => '发布'
];
use SoftDelete;
use SoftDelete;
protected $defaultSoftDelete = 0;
protected $defaultSoftDelete = 0;
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
public function categorys()
{
return $this->hasMany(PostCategory::class, 'post_id');
}
public function tags()
{
return $this->hasMany(PostTag::class, 'post_id');
}
public function setPublishTimeAttr($value)
{
return strtotime($value);
}
public function getPublishTimeTextAttr()
{
$value = $this->getData('publish_time');
return date('Y-m-d', $value);
}
public function getPublishTimeDatetimeAttr()
{
$value = $this->getData('publish_time');
return date('Y-m-d H:i:s', $value);
}
public function getCategorysListAttr()
{
$list_post_categorys = $this->getAttr('categorys');
$list = array_column($list_post_categorys->append(['category'])->toArray(), 'category');
$list = array2level($list, 0, 0);
return $list;
}
public function getTagsListAttr()
{
$list_post_tags = $this->getAttr('tags');
$list = array_column($list_post_tags->append(['tag'])->toArray(), 'tag');
return $list;
}
public function getDescShortAttr()
{
$desc = $this->getData('desc');
if (strlen($desc) > 100) {
$desc = mb_substr($desc, 0, 100) . '...';
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
return $desc;
}
public function getDescListAttr()
{
$desc = $this->getData('desc');
if (empty($desc)) {
return '';
}
$list = explode("\n", $desc);
return $list;
}
public function getDescHtmlAttr()
{
$desc = $this->getData('desc');
if (empty($desc)) {
return '';
public function categorys()
{
return $this->hasMany(PostCategory::class, 'post_id');
}
return str_replace("\n", '<br>', $desc);
}
public function getStatusNameAttr()
{
return self::$stausNameList[$this->getData('status')];
}
public function setPubishTimeAttr($value)
{
return strtotime($value);
}
public function setContentAttr($value)
{
return json_encode($value);
}
public function setContentHtmlAttr($value)
{
return trim($value);
}
public function getContentAttr($value)
{
return json_decode($value, true);
}
public function getPosterAttr($value)
{
if (empty($value)) {
$value = '/static/images/avatar.png';
public function tags()
{
return $this->hasMany(PostTag::class, 'post_id');
}
return get_source_link($value);
}
public function setPublishTimeAttr($value)
{
return strtotime($value);
}
public function getPublishTimeTextAttr()
{
public function getDemoPageAttr()
{
if (empty($this->getData('tpl_name'))) {
return '';
$value = $this->getData('publish_time');
return date('Y-m-d', $value);
}
public function getPublishTimeDatetimeAttr()
{
$value = $this->getData('publish_time');
return date('Y-m-d H:i:s', $value);
}
$base_dir = App::getRootPath() . '/demo/' . $this->getAttr('category')->getData('tpl_name') . '/';
public function getCategorysListAttr()
{
$list_post_categorys = $this->getAttr('categorys');
$file_path = $base_dir . $this->getData('tpl_name') . '.html';
if (!file_exists($file_path)) {
return '';
$list = array_column($list_post_categorys->append(['category'])->toArray(), 'category');
$list = array2level($list, 0, 0);
return $list;
}
View::assign('site_logo_src', get_source_link(get_system_config('site_logo')));
public function getTagsListAttr()
{
$list_post_tags = $this->getAttr('tags');
return View::fetch($file_path);
}
$list = array_column($list_post_tags->append(['tag'])->toArray(), 'tag');
public static function quickSelect($clear = false)
{
$cacke_key = 'post_list';
$list_post = Cache::get($cacke_key);
if (empty($list_post) || $clear) {
$list_post = Category::with(['post'])->where('type', 'default')
->where('status', 1)
->order('sort asc')
->select();
Cache::set($cacke_key, $list_post, 600);
return $list;
}
return $list_post;
}
public function getDescShortAttr()
{
$desc = $this->getData('desc');
public static function quickFind($id, $clear = false)
{
$cache_key = 'post_' . $id;
if (strlen($desc) > 100) {
$desc = mb_substr($desc, 0, 100) . '...';
}
$model_post = Cache::get($cache_key);
if (empty($model_post) || $clear) {
$model_post = Post::find($id);
Cache::set($cache_key, $model_post, get_system_config('cache_expire_time'));
return $desc;
}
return $model_post;
}
public function getDescListAttr()
{
$desc = $this->getData('desc');
if (empty($desc)) {
return '';
}
$list = explode("\n", $desc);
return $list;
}
public function getDescHtmlAttr()
{
$desc = $this->getData('desc');
if (empty($desc)) {
return '';
}
return str_replace("\n", '<br>', $desc);
}
public function getStatusNameAttr()
{
return self::$stausNameList[$this->getData('status')];
}
public function setPubishTimeAttr($value)
{
return strtotime($value);
}
public function setContentAttr($value)
{
return json_encode($value);
}
public function setContentHtmlAttr($value)
{
return trim($value);
}
public function getContentAttr($value)
{
return json_decode($value, true);
}
public function getPosterAttr($value)
{
if (empty($value)) {
$value = '/static/images/avatar.png';
}
return get_source_link($value);
}
public function getDemoPageAttr()
{
if (empty($this->getData('tpl_name'))) {
return '';
}
$base_dir = App::getRootPath() . '/demo/' . $this->getAttr('category')->getData('tpl_name') . '/';
$file_path = $base_dir . $this->getData('tpl_name') . '.html';
if (!file_exists($file_path)) {
return '';
}
View::assign('site_logo_src', get_source_link(get_system_config('site_logo')));
return View::fetch($file_path);
}
public static function quickSelect($clear = false)
{
$cacke_key = 'post_list';
$list_post = Cache::get($cacke_key);
if (empty($list_post) || $clear) {
$list_post = Category::with(['post'])->where('type', 'default')
->where('status', 1)
->order('sort asc')
->select();
Cache::set($cacke_key, $list_post, 600);
}
return $list_post;
}
public static function quickFind($id, $clear = false)
{
$cache_key = 'post_item_' . $id;
$model_post = Cache::get($cache_key);
if (empty($model_post) || $clear) {
$model_post = Post::find($id);
Cache::set($cache_key, $model_post, get_system_config('cache_expire_time'));
}
return $model_post;
}
public static function quickFindByTplName($tpl_name, $clear = false)
{
$cache_key = 'post_item_' . $tpl_name;
$model_post = Cache::get($cache_key);
if (empty($model_post) || $clear) {
$model_post = Post::where('tpl_name', $tpl_name)->find();
Cache::set($cache_key, $model_post, get_system_config('cache_expire_time'));
}
return $model_post;
}
public function getReadUrlAttr()
{
$domain = Request::domain();
$doc_name = $this->getData('tpl_name') ?: $this->getData('id');
return $domain . '/index/doc/' . $doc_name . '.html';
}
}

View File

@@ -1,4 +1,5 @@
<?php
use think\facade\Env;
// +----------------------------------------------------------------------
@@ -6,7 +7,7 @@ use think\facade\Env;
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => Env::get('log.channel', 'file'),
'default' => Env::get('log.channel', 'debug_mysql'),
// 日志记录级别
'level' => [],
// 日志类型记录的通道 ['error'=>'email',...]
@@ -41,6 +42,26 @@ return [
'realtime_write' => false,
],
// 其它日志通道配置
// 其它日志通道配置
'debug_mysql' => [
'type' => 'DebugMysql',
// 服务器地址
'hostname' => Env::get('database.hostname', '127.0.0.1'),
// 数据库名
'database' => Env::get('database.database', ''),
// 用户名
'username' => Env::get('database.username', ''),
// 密码
'password' => Env::get('database.password', ''),
// 端口
'hostport' => Env::get('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => Env::get('database.prefix', 'ul_'),
]
],
];

View File

@@ -1,5 +1,4 @@
/* 列表开始 */
.ul-nav-tree {}
.ul-nav-tree-group-title {

View File

@@ -38,7 +38,7 @@
</div>
<div class="ul-nav-tree-group-main">
{volist name='category.post' id='post'}
<a href="{:url('Index/index',['post_id'=>$post.id])}" class="ul-nav-tree-item {eq name='post.id' value='$Request.param.post_id'}current{/eq}">
<a href="{$post.read_url}" class="ul-nav-tree-item {eq name='post.id' value='$model_post.id'}current{/eq}">
<div class="ul-nav-tree-item-title">
{$post.title}
</div>