feat: 完成三方平台发布管理

This commit is contained in:
augushong
2025-05-05 10:29:49 +08:00
parent d27772ef03
commit 70b17cbd10
8 changed files with 188 additions and 96 deletions

View File

@@ -154,8 +154,8 @@ class Post extends Common
$list_post_platform = Nav::where('type', 12)->order('sort asc')->select(); $list_post_platform = Nav::where('type', 12)->order('sort asc')->select();
foreach ($list_post_platform as $model_platform) { foreach ($list_post_platform as $model_platform) {
$platform_info = explode("\n",$model_platform->desc); $platform_info = explode("\n", $model_platform->desc);
$model_platform->home_url = $platform_info[0]?? ''; $model_platform->home_url = $platform_info[0] ?? '';
$model_platform->account = $platform_info[1] ?? ''; $model_platform->account = $platform_info[1] ?? '';
} }
@@ -235,6 +235,26 @@ class Post extends Common
return $this->success('保存成功', url('index', ['type' => $model_post->getData('type')])); return $this->success('保存成功', url('index', ['type' => $model_post->getData('type')]));
} }
public function setPostPlatformData()
{
$type = $this->request->param('type', 1);
$value = $this->request->param('value', '');
$post_id = $this->request->param('post_id', 0);
$model_post = ModelPost::find($post_id);
if (empty($model_post)) {
return json_message('文章不存在');
}
$post_platform_data = $model_post->post_platform_data_array;
$post_platform_data[$type] = $value;
$model_post->post_platform_data = json_encode($post_platform_data);
$model_post->post_platform_status = ',' . implode(',', array_keys($post_platform_data)) . ',';
$model_post->save();
return htmx()->message('文章设置成功');
}
/** /**
* 删除指定资源. * 删除指定资源.
* *

View File

@@ -1,4 +1,5 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ] // | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
@@ -14,50 +15,55 @@
use app\model\Admin; use app\model\Admin;
use app\model\AdminPermission; use app\model\AdminPermission;
use app\model\SystemConfig; use app\model\SystemConfig;
use think\facade\Cache;
use League\Flysystem\Util\MimeType;
use think\File;
use think\facade\Filesystem;
use app\model\UploadFiles; use app\model\UploadFiles;
use think\facade\Session; use League\Flysystem\Util\MimeType;
use think\app\Url; use think\app\Url;
use think\facade\Cache;
use think\facade\Filesystem;
use think\facade\Session;
use think\File;
use think\Response;
use think\response\Htmx;
function json_message($data = [], $code = 0, $msg = '') function json_message($data = [], $code = 0, $msg = '')
{ {
if (is_string($data)) { if (is_string($data)) {
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) { if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
$data = [ $data = [
'jump_to_url' => $data 'jump_to_url' => $data,
]; ];
} else { } else {
$code = $code === 0 ? 500 : $code; $code = $code === 0 ? 500 : $code;
$msg = $data; $msg = $data;
$data = []; $data = [];
} }
} else if ($data instanceof Url) { } elseif ($data instanceof Url) {
$data = [ $data = [
'jump_to_url' => (string)$data 'jump_to_url' => (string) $data,
]; ];
} }
return json([ return json([
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'data' => $data 'data' => $data,
]); ]);
} }
function htmx($data = '', $code = 200) : Htmx
{
return Response::create($data, 'htmx', $code);
}
function get_system_config($name = '', $default = '') function get_system_config($name = '', $default = '')
{ {
$list = Cache::get('system_config'); $list = Cache::get('system_config');
if (empty($list)) { if (empty($list)) {
try { try {
$list = SystemConfig::column('value', 'name'); $list = SystemConfig::column('value', 'name');
Cache::set('system_config', $list); Cache::set('system_config', $list);
} catch (\Throwable $th) { } catch (Throwable $th) {
return $default; return $default;
} }
} }
@@ -75,7 +81,6 @@ function get_system_config($name = '', $default = '')
function get_source_link($url) function get_source_link($url)
{ {
if (empty($url)) { if (empty($url)) {
$url = '/static/images/avatar.png'; $url = '/static/images/avatar.png';
} }
@@ -90,6 +95,7 @@ function get_source_link($url)
if (empty($resource_domain)) { if (empty($resource_domain)) {
$resource_domain = request()->domain(); $resource_domain = request()->domain();
} }
return $resource_domain . '/' . $url; return $resource_domain . '/' . $url;
} }
} }
@@ -100,12 +106,12 @@ function de_source_link($url)
if (strpos($url, $domain) === 0) { if (strpos($url, $domain) === 0) {
return str_replace($domain, '', $url); return str_replace($domain, '', $url);
} }
return false; return false;
} }
function save_url_file($url, $type) function save_url_file($url, $type)
{ {
$file_data = geturl($url); $file_data = geturl($url);
$mime_type = MimeType::detectByContent($file_data); $mime_type = MimeType::detectByContent($file_data);
@@ -130,16 +136,17 @@ function save_url_file($url, $type)
$model_file->save_name = $save_name; $model_file->save_name = $save_name;
$model_file->save(); $model_file->save();
unlink($temp_file); unlink($temp_file);
return $save_name; return $save_name;
} }
function geturl($url) function geturl($url)
{ {
$headerArray = array(); $headerArray = [];
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray); curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
$output = curl_exec($ch); $output = curl_exec($ch);
@@ -148,48 +155,41 @@ function geturl($url)
return $output; return $output;
} }
function posturl($url, $data) function posturl($url, $data)
{ {
$data = json_encode($data); $data = json_encode($data);
$headerArray = array(); $headerArray = [];
$curl = curl_init(); $curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray); curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl); $output = curl_exec($curl);
curl_close($curl); curl_close($curl);
return $output; return $output;
} }
function format_size($filesize) function format_size($filesize)
{ {
if ($filesize >= 1073741824) { if ($filesize >= 1073741824) {
$filesize = round($filesize / 1073741824 * 100) / 100 . ' GB'; $filesize = round($filesize / 1073741824 * 100) / 100 . ' GB';
} elseif ($filesize >= 1048576) { } elseif ($filesize >= 1048576) {
$filesize = round($filesize / 1048576 * 100) / 100 . ' MB'; $filesize = round($filesize / 1048576 * 100) / 100 . ' MB';
} elseif ($filesize >= 1024) { } elseif ($filesize >= 1024) {
$filesize = round($filesize / 1024 * 100) / 100 . ' KB'; $filesize = round($filesize / 1024 * 100) / 100 . ' KB';
} else { } else {
$filesize = $filesize . ' 字节'; $filesize = $filesize . ' 字节';
} }
return $filesize; return $filesize;
} }
/** /**
* 数组层级缩进转换 * 数组层级缩进转换.
* @param array $array 源数组 * @param array $array 源数组
* @param int $pid * @param int $pid
* @param int $level * @param int $level
@@ -197,17 +197,16 @@ function format_size($filesize)
*/ */
function array2level($array, $pid = 0, $level = 1) function array2level($array, $pid = 0, $level = 1)
{ {
static $list = []; static $list = [];
if ($level == 0) { if ($level == 0) {
$list = []; $list = [];
$level = 1; $level = 1;
} }
foreach ($array as $v) { foreach ($array as $v) {
if(!empty($v)) { if (!empty($v)) {
if ($v['pid'] == $pid) { if ($v['pid'] == $pid) {
$v['level'] = $level; $v['level'] = $level;
$list[] = $v; $list[] = $v;
array2level($array, $v['id'], $level + 1); array2level($array, $v['id'], $level + 1);
} }
} }
@@ -217,7 +216,6 @@ function array2level($array, $pid = 0, $level = 1)
return $list; return $list;
} }
function check_permission($key, $admin_id = null) function check_permission($key, $admin_id = null)
{ {
if (is_null($admin_id)) { if (is_null($admin_id)) {
@@ -238,7 +236,6 @@ function check_permission($key, $admin_id = null)
return true; return true;
} }
$cache_key = 'permission_' . $key; $cache_key = 'permission_' . $key;
$model_permission = Cache::get($cache_key); $model_permission = Cache::get($cache_key);
@@ -249,7 +246,7 @@ function check_permission($key, $admin_id = null)
if (empty($model_permission)) { if (empty($model_permission)) {
$model_permission = AdminPermission::create([ $model_permission = AdminPermission::create([
'key' => $key 'key' => $key,
]); ]);
Cache::set($cache_key, $model_permission, 60); Cache::set($cache_key, $model_permission, 60);
} }
@@ -261,29 +258,24 @@ function check_permission($key, $admin_id = null)
return false; return false;
} }
/** /**
* 多应用下的url生成器 * 多应用下的url生成器
* 在这里的@后面跟随的首先被认为成应用名而不是源文档的域名(或子域名) * 在这里的@后面跟随的首先被认为成应用名而不是源文档的域名(或子域名)
* 程序会尝试找到应用对应的域名来生成地址,如果没找到,则按照源文档的逻辑执行 * 程序会尝试找到应用对应的域名来生成地址,如果没找到,则按照源文档的逻辑执行.
* @param string $url * @param string $url
* @param array $vars * @param array $vars
* @param boolean $suffix * @param bool $suffix
* @param boolean $domain * @param bool $domain
* @return void * @return void
*/ */
function app_url(string $url = '', array $vars = [], $suffix = true, $domain = false) function app_url(string $url = '', array $vars = [], $suffix = true, $domain = false)
{ {
return url($url, $vars, $suffix, $domain); return url($url, $vars, $suffix, $domain);
} }
if (!function_exists('ua_htmlspecialchars')) { if (!function_exists('ua_htmlspecialchars')) {
function ua_htmlspecialchars($string) function ua_htmlspecialchars($string)
{ {
if (is_null($string)) { if (is_null($string)) {
$string = ''; $string = '';
} }
@@ -295,7 +287,6 @@ if (!function_exists('ua_htmlspecialchars')) {
if (!function_exists('ua_htmlentities')) { if (!function_exists('ua_htmlentities')) {
function ua_htmlentities($string) function ua_htmlentities($string)
{ {
if (is_null($string)) { if (is_null($string)) {
$string = ''; $string = '';
} }
@@ -304,7 +295,8 @@ if (!function_exists('ua_htmlentities')) {
} }
} }
function show_time_ago($timestamp) { function show_time_ago($timestamp)
{
$current_time = new DateTime(); $current_time = new DateTime();
$target_time = new DateTime("@$timestamp"); $target_time = new DateTime("@$timestamp");
$interval = $current_time->diff($target_time); $interval = $current_time->diff($target_time);

View File

@@ -264,4 +264,13 @@ class Post extends Base
return $value; return $value;
} }
public function getPostPlatformDataArrayAttr()
{
$data = $this->getData('post_platform_data');
if (empty($data)) {
return [];
}
return json_decode($data, true);
}
} }

View File

@@ -1,11 +1,11 @@
<?php <?php
use think\facade\Env;
use think\facade\App; use think\facade\App;
use think\facade\Env;
return [ return [
// 默认使用的数据库连接配置 // 默认使用的数据库连接配置
'default' => Env::get('database.driver', 'sqlite'), 'default' => Env::get('database.driver', 'sqlite'),
// 自定义时间查询规则 // 自定义时间查询规则
'time_query_rule' => [], 'time_query_rule' => [],
@@ -13,89 +13,88 @@ return [
// 自动写入时间戳字段 // 自动写入时间戳字段
// true为自动识别类型 false关闭 // true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date // 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true, 'auto_timestamp' => true,
// 时间字段取出后的默认时间格式 // 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s', 'datetime_format' => 'Y-m-d H:i:s',
// 数据库连接配置信息 // 数据库连接配置信息
'connections' => [ 'connections' => [
'mysql' => [ 'mysql' => [
// 数据库类型 // 数据库类型
'type' => Env::get('database.type', 'mysql'), 'type' => Env::get('database.type', 'mysql'),
// 服务器地址 // 服务器地址
'hostname' => Env::get('database.hostname', ''), 'hostname' => Env::get('database.hostname', ''),
// 数据库名 // 数据库名
'database' => Env::get('database.database', ''), 'database' => Env::get('database.database', ''),
// 用户名 // 用户名
'username' => Env::get('database.username', ''), 'username' => Env::get('database.username', ''),
// 密码 // 密码
'password' => Env::get('database.password', ''), 'password' => Env::get('database.password', ''),
// 端口 // 端口
'hostport' => Env::get('database.hostport', '3306'), 'hostport' => Env::get('database.hostport', '3306'),
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8mb4'), 'charset' => Env::get('database.charset', 'utf8mb4'),
// 数据库表前缀 // 数据库表前缀
'prefix' => Env::get('database.prefix', 'ul_'), 'prefix' => Env::get('database.prefix', 'ul_'),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0, 'deploy' => 0,
// 数据库读写是否分离 主从式有效 // 数据库读写是否分离 主从式有效
'rw_separate' => false, 'rw_separate' => false,
// 读写分离后 主服务器数量 // 读写分离后 主服务器数量
'master_num' => 1, 'master_num' => 1,
// 指定从服务器序号 // 指定从服务器序号
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 是否需要断线重连 // 是否需要断线重连
'break_reconnect' => false, 'break_reconnect' => true,
// 监听SQL // 监听SQL
'trigger_sql' => true, 'trigger_sql' => true,
// 开启字段缓存 // 开启字段缓存
'fields_cache' => true, 'fields_cache' => false,
], ],
'sqlite' => [ 'sqlite' => [
// 数据库类型 // 数据库类型
'type' => 'sqlite', 'type' => 'sqlite',
// 服务器地址 // 服务器地址
'hostname' => Env::get('root_path') . 'ul.db', 'hostname' => Env::get('root_path') . 'ul.db',
// 数据库名 // 数据库名
'database' => App::getRootPath() . 'ul.db', 'database' => App::getRootPath() . 'ul.db',
// 用户名 // 用户名
'username' => Env::get('database.username', ''), 'username' => Env::get('database.username', ''),
// 密码 // 密码
'password' => Env::get('database.password', ''), 'password' => Env::get('database.password', ''),
// 端口 // 端口
'hostport' => Env::get('database.hostport', '3306'), 'hostport' => Env::get('database.hostport', '3306'),
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => Env::get('database.charset', 'utf8'), 'charset' => Env::get('database.charset', 'utf8'),
// 数据库表前缀 // 数据库表前缀
'prefix' => Env::get('database.prefix', 'ul_'), 'prefix' => Env::get('database.prefix', 'ul_'),
// 数据库调试模式 // 数据库调试模式
'debug' => Env::get('database.debug', true), 'debug' => Env::get('database.debug', true),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0, 'deploy' => 0,
// 数据库读写是否分离 主从式有效 // 数据库读写是否分离 主从式有效
'rw_separate' => false, 'rw_separate' => false,
// 读写分离后 主服务器数量 // 读写分离后 主服务器数量
'master_num' => 1, 'master_num' => 1,
// 指定从服务器序号 // 指定从服务器序号
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 是否需要进行SQL性能分析 // 是否需要进行SQL性能分析
'sql_explain' => false, 'sql_explain' => false,
// 是否需要断线重连 // 是否需要断线重连
'break_reconnect' => false, 'break_reconnect' => false,
'fields_cache' => true 'fields_cache' => false,
], ],
// 更多的数据库配置信息 // 更多的数据库配置信息
], ],

View File

@@ -0,0 +1,33 @@
<?php
namespace think\response;
use think\Response;
class Htmx extends Response
{
protected $triggerOptions = [];
public function addTrigger($name, $data = null)
{
$this->triggerOptions[$name] = $data;
return $this;
}
public function message($message)
{
$this->triggerOptions['layerMsg'] = ['type' => 1, 'title' => $message];
return $this;
}
protected function output($data)
{
$this->header([
'HX-Trigger' => json_encode($this->triggerOptions),
]);
return parent::output($data);
}
}

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,7 @@
<link rel="stylesheet" href="/static/lib/layui/css/layui.css"> <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
<link rel="stylesheet" href="/static/css/{$Request.cookie.skin_name|default='skin-1'}.css"> <link rel="stylesheet" href="/static/css/{$Request.cookie.skin_name|default='skin-1'}.css">
<link rel="stylesheet" href="/static/css/common.css"> <link rel="stylesheet" href="/static/css/common.css">
<script src="/static/lib/htmx-v2.0.4/htmx.min.js"></script>
<script src="/static/lib/jquery/jquery-3.4.1.min.js"></script> <script src="/static/lib/jquery/jquery-3.4.1.min.js"></script>
<script src="/static/lib/jquery/jquery.cookie.js"></script> <script src="/static/lib/jquery/jquery.cookie.js"></script>
<script src="/static/lib/layui/layui.js"></script> <script src="/static/lib/layui/layui.js"></script>

View File

@@ -12,6 +12,7 @@
content="width=device-width, initial-scale=1.0" content="width=device-width, initial-scale=1.0"
> >
<title>{$post.title}</title> <title>{$post.title}</title>
<script src="/static/lib/htmx-v2.0.4/htmx.min.js"></script>
<script src="/static/lib/jquery/jquery-3.4.1.min.js"></script> <script src="/static/lib/jquery/jquery-3.4.1.min.js"></script>
<script src="/static/lib/jquery/jquery.cookie.js"></script> <script src="/static/lib/jquery/jquery.cookie.js"></script>
<script src="/static/lib/layui/layui.js"></script> <script src="/static/lib/layui/layui.js"></script>
@@ -40,12 +41,11 @@
position: fixed; position: fixed;
right: 0; right: 0;
top: 0; top: 0;
margin: 15px;
padding: 15px; padding: 15px;
border-radius: 5; border-radius: 5;
border: 1px solid #e8e8e8; border: 1px solid #e8e8e8;
background: #fff; background: #fff;
overflow: auto;
} }
.options-box>a, .options-box>a,
@@ -65,6 +65,12 @@
color: #333; color: #333;
font-size: 12px; font-size: 12px;
} }
.post-platform-item a,
.post-platform-item a:hover,
.post-platform-item a:visited {
color: #fff;
}
</style> </style>
</head> </head>
@@ -154,16 +160,41 @@
class="post-platform-label" class="post-platform-label"
style="text-align: left;" style="text-align: left;"
> >
<span>
{$vo.title}
</span>
<a
href="{$vo.value}"
target="_blank"
>
{$vo.title}
</a>
<a
style="margin-left: 6px;"
href="{$vo.home_url}"
title="{$vo.account}"
target=" _blank"
>
主页
</a>
{empty name='$post.post_platform_data_array[$vo.id]'}
<span style="margin-left: 6px;">文章:</span>
{else /}
<a
href="{$post.post_platform_data_array[$vo.id]}"
target=" _blank"
style="margin-left: 6px;"
>文章:</a>
{/empty}
</div> </div>
<div class="post-platform-label"> <div class="post-platform-label">
<input <input
type="text" type="text"
name="post-platform[{$vo.id}]" name="value"
value="{$post.post_platform_data_array[$vo.id]|default=''}"
placeholder="请输入文章链接" placeholder="请输入文章链接"
hx-post="{:url('setPostPlatformData')}"
hx-vals="js:{post_id:{$post.id},type:{$vo.id}}"
> >
</div> </div>
</div> </div>
@@ -302,6 +333,12 @@
}); });
}; };
$('textarea[autoHeight]').autoHeight(); $('textarea[autoHeight]').autoHeight();
});
layui.use(['element', 'layer', 'util'], function () { });
$('body').on('layerMsg', function (evt) {
layui.layer.msg(evt.originalEvent.detail.title);
}) })
</script> </script>
</body> </body>