Compare commits

...

21 Commits

Author SHA1 Message Date
07fe136d62 update 2025-07-18 19:08:39 +08:00
24590b05c0 update 2025-07-18 15:30:20 +08:00
7d619fb503 update 2025-07-18 15:23:34 +08:00
95b480b346 update 2025-07-17 19:19:35 +08:00
eac64e779a update 2025-07-17 16:43:41 +08:00
f0eed20b0a update 2025-07-17 11:37:15 +08:00
9a76ce372b update 2025-07-16 17:30:05 +08:00
e9ab49ad24 update 2025-07-15 17:03:20 +08:00
0b85d58bb9 update 2025-07-14 19:24:47 +08:00
c0ccbd184f update 2025-07-14 19:20:47 +08:00
7c663867e8 update 2025-07-14 19:18:29 +08:00
6e3197d585 update 2025-07-11 15:18:01 +08:00
993fe4ed49 update 2025-07-11 15:15:02 +08:00
f34ebb58dc update 2025-07-11 15:12:22 +08:00
089b935cfb update 2025-07-11 15:08:22 +08:00
fca5d93e1b update 2025-07-11 15:07:39 +08:00
cae6609d71 update 2025-07-11 15:04:14 +08:00
0a83e2dfc6 update 2025-07-11 14:49:59 +08:00
b1159b17cb update 2025-07-09 19:25:22 +08:00
8ca0e04569 update 2025-07-07 19:24:21 +08:00
86c687409b update 2025-07-07 18:00:35 +08:00
17 changed files with 745 additions and 33 deletions

View File

@ -0,0 +1,222 @@
<?php
namespace App\Command\baidu;
use App\Command\spider\BaseSpider;
use App\Model\AppNews;
use App\Model\AppWebsiteConfig;
use Hyperf\Command\Annotation\Command;
use Hyperf\DbConnection\Db;
use Hyperf\Logger\LoggerFactory;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function Swoole\Coroutine\run;
#[Command]
class AutoPush extends BaseSpider
{
/**
* @var string
*/
protected string $baseUrl = 'http://data.zz.baidu.com/urls?site=https://www.jiangsucf.com&token=5CtAd8vD3QQazJjh';
protected const PLATFORM = 'elle-street';
public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory)
{
parent::__construct('baidu:auto-push');
}
public function configure()
{
parent::configure();
// 普通收录
//使用说明
//1、普通收录工具可以向百度搜索主动推送资源缩短爬虫发现网站链接的时间不保证收录和展现效果。
//2、API提交和手动提交共享配额sitemap提交配额不与其他方式共享具体配额以站点页面显示数据为准 。配额不可累计,当日有效。
//3、若链接存在跳转关系请直接提交跳转后链接。如网站换域名需提交新域名资源进行HTTPS改造页面请提交HTTPS资源。
$this->setDescription('自动向百度推送');
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$url = AppWebsiteConfig::query()->select(['app_domain', 'id'])->where('is_delete', 0)->get()->toArray();
$pushArray = [];
$push = function () use (&$pushArray) {
$ch = curl_init();
$options = array(
CURLOPT_URL => $this->baseUrl,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $pushArray),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$pushArray = [];
var_dump($result);
};
foreach ($url as $item) {
$article = AppNews::query()->where('platform', $item['id'])->select(['id'])->get()->toArray();
foreach ($article as $articleItem) {
$pushArray[] = 'https://' . $item['app_domain'] . '/news/' . $articleItem['id'];
}
if ($pushArray) {
$push();
}
}
// echo $result;
// var_dump($result);
var_dump($pushArray);
return 0;
}
private function _getTask($brand): \Generator
{
$query = Db::table('app_brands');
if ($brand) {
$query->where(['id' => $brand]);
}
$query->where('id', '>', 1)->orderBy('id');
foreach ($query->cursor() as $row) {
yield $row;
}
}
private function _getTaskName($name): string
{
return strtolower(strtr($name, [
'.' => '-',
' ' => '-'
]));
}
public function spiderStart(): void
{
list($result, $httpCode) = $this->request($this->getBaseUrl() . '/fashion/street-style/');
preg_match_all('/<script id="json-ld" type="application\/ld\+json">([\s\S]*?)<\/script>/', $result, $matches);
if (!is_array($matches) && count($matches) < 1) {
$this->logger->info(self::getPlatform() . " 数据获取失败。");
return;
}
$val = json_decode(($matches[1][0]), true);
$articles = $val[0]['itemListElement'] ?? [];
if (!$articles) {
$this->logger->info(self::getPlatform() . " 文章数据获取失败。");
return;
}
$saveImages = [];
foreach ($articles as $article) {
list($result, $httpCode) = $this->request($article['url']);
preg_match_all('/<script id="json-ld" type="application\/ld\+json">([\s\S]*?)<\/script>/', $result, $matches);
if (isset($matches[1][0])) {
$val = json_decode($matches[1][0], true);
$images = $val['about']['itemListElement'];
foreach ($images as $image) {
$saveImages[] = $image['item']['image'];
}
}
}
var_dump($saveImages);
return;
$this->createCoroutine(function () use ($task) {
$brandName = $this->_getTaskName($task->name);
$url = $this->getBaseUrl() . '/fashion-shows/designer/' . $brandName;
$this->logger->info(sprintf("[Command] brandName: {$this->_getTaskName($task->name)}; spiderUrl: {$url}"));
// 取发布会列表
$showsList = $this->_getShowsList($url);
foreach ($showsList as $list) {
$this->createCoroutine(function () use ($task, $list) {
$this->_getDetail($task->id, $list);
});
}
});
}
private function _getShowsList($url)
{
list($request, $httpCode) = $this->request($url);
if ($httpCode == 200) {
preg_match_all('/window.__PRELOADED_STATE__ = ([\s\S]*?);<\/script>/', $request, $matches);
$val = json_decode(current(end($matches)), true);
return $val['transformed']['runwayDesignerContent']['designerCollections'] ?? [];
} else {
$this->logger->info('未找到数据.');
return [];
}
}
private function _getDetail(int $brandId, array $info)
{
$model = $this->getArticleModel(['brand' => $brandId, 'title' => $info['hed']]);
$model->title = $info['hed'];
$model->images = json_encode([]);
$model->platform = self::getPlatform();
// 获取图片
$pageUri = $info['url'];
$requestUrl = $this->getBaseUrl() . $pageUri . '/slideshow/collection';
$this->logger->info("正在匹配发布会详情 {$requestUrl}");
$matches = [];
list($result, $httpCode) = $this->request($requestUrl);
if ($httpCode != 200 || !$result) {
$this->logger->warning($requestUrl . '请求失败.');
return;
}
preg_match_all('/window\.__PRELOADED_STATE__ = (.*?);</s', $result, $matches);
$saveUrl = [];
if (count($matches) > 1) {
$val = json_decode(current($matches[1]), true);
$images = $val['transformed']['runwayGalleries']['galleries'][0]['items'] ?? false;
if ($images === false) {
$this->logger->warning($requestUrl . '获取图片失败.');
return;
}
foreach (is_array($images) ? $images : [] as $img) {
$saveUrl[] = [
'src' => $img['image']['sources']['xxl']['url']
];
}
$model->images = json_encode($saveUrl);
}
$model->save();
$this->logger->info("end: {$requestUrl}");
}
}

View File

@ -0,0 +1,147 @@
<?php
namespace App\Command\sitemap;
use App\Command\spider\BaseSpider;
use App\Model\AppNews;
use App\Model\AppWebsiteConfig;
use Hyperf\Command\Annotation\Command;
use Hyperf\DbConnection\Db;
use Hyperf\Logger\LoggerFactory;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function Swoole\Coroutine\run;
/**
* 生成头条的sitemap
*/
#[Command]
class Toutiao extends BaseSpider
{
/**
* @var string
*/
protected string $baseUrl = 'http://data.zz.baidu.com/urls?site=https://www.jiangsucf.com&token=5CtAd8vD3QQazJjh';
protected const PLATFORM = 'elle-street';
public function __construct(protected ContainerInterface $container, LoggerFactory $loggerFactory)
{
parent::__construct('sitemap:toutiao');
}
public function configure()
{
parent::configure();
// 普通收录
//使用说明
//1、普通收录工具可以向百度搜索主动推送资源缩短爬虫发现网站链接的时间不保证收录和展现效果。
//2、API提交和手动提交共享配额sitemap提交配额不与其他方式共享具体配额以站点页面显示数据为准 。配额不可累计,当日有效。
//3、若链接存在跳转关系请直接提交跳转后链接。如网站换域名需提交新域名资源进行HTTPS改造页面请提交HTTPS资源。
$this->setDescription('生成头条sitemap');
$this->addOption('platform', 'p', InputOption::VALUE_OPTIONAL, '指定的平台id.', false);
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$platform = $input->getOption('platform');
// 域名
$domain = AppWebsiteConfig::find($platform)->app_domain;
$sitemapArray = [];
$query = AppNews::query()->select(['id', 'created_at'])->where('platform', $platform)->where('is_delete', 0)->get()->toArray();
foreach ($query as $item) {
$date = date('Y-m-d', $item['created_at']);
$sitemapArray[] = <<<EOF
<url>
<loc>https://$domain/news/{$item['id']}</loc>
<lastmod>{$date}</lastmod>
</url>
EOF;
}
if ($sitemapArray) {
$val = implode(PHP_EOL, $sitemapArray);
$sitemap = <<<EOF
<?xml version="1.0" encoding="utf-8"?>
<urlset>
$val
</urlset>
EOF;
file_put_contents('/www/wwwroot/huoerguosifeichi/sitemap.xml', $sitemap);
}
//var_dump($links);
return 0;
}
private function _getTask($brand): \Generator
{
$query = Db::table('app_brands');
if ($brand) {
$query->where(['id' => $brand]);
}
$query->where('id', '>', 1)->orderBy('id');
foreach ($query->cursor() as $row) {
yield $row;
}
}
private function _getTaskName($name): string
{
return strtolower(strtr($name, [
'.' => '-',
' ' => '-'
]));
}
public function spiderStart(): void
{
list($result, $httpCode) = $this->request($this->getBaseUrl() . '/fashion/street-style/');
preg_match_all('/<script id="json-ld" type="application\/ld\+json">([\s\S]*?)<\/script>/', $result, $matches);
if (!is_array($matches) && count($matches) < 1) {
$this->logger->info(self::getPlatform() . " 数据获取失败。");
return;
}
$val = json_decode(($matches[1][0]), true);
$articles = $val[0]['itemListElement'] ?? [];
if (!$articles) {
$this->logger->info(self::getPlatform() . " 文章数据获取失败。");
return;
}
$saveImages = [];
foreach ($articles as $article) {
list($result, $httpCode) = $this->request($article['url']);
preg_match_all('/<script id="json-ld" type="application\/ld\+json">([\s\S]*?)<\/script>/', $result, $matches);
if (isset($matches[1][0])) {
$val = json_decode($matches[1][0], true);
$images = $val['about']['itemListElement'];
foreach ($images as $image) {
$saveImages[] = $image['item']['image'];
}
}
}
var_dump($saveImages);
return;
}
}

View File

@ -39,4 +39,14 @@ class NewsController extends AbstractController
{
return $render->render('news/insert');
}
/**
* 导入新闻
* @url /admin/news/insert
*/
#[RequestMapping(path: 'import', methods: 'get')]
public function import(RenderInterface $render): \Psr\Http\Message\ResponseInterface
{
return $render->render('news/import');
}
}

View File

@ -12,6 +12,7 @@ use App\Model\AppBrand;
use App\Model\AppNews;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use function Hyperf\Support\env;
#[Controller(prefix: 'admin/api/news')]
class NewsController extends AbstractController
@ -87,11 +88,62 @@ class NewsController extends AbstractController
public function insert()
{
$model = new NewsFormModel();
$model->setAttributes($this->request->post(), ['title', 'keywords', 'description', 'cover', 'content']);
$model->setAttributes($this->request->post(), ['title', 'keywords', 'description', 'cover', 'content', 'platform']);
$model->insert();
return $this->response->json(['code' => 0, 'msg' => 'ok']);
}
/**
* 导入
* [{title:'',desc:'',keywords:'',content:''}]
* @url /admin/api/news/insert
*/
#[RequestMapping(path:'import', methods: 'post')]
public function import()
{
$content = $this->request->post('content', null);
$platform = $this->request->post('platform', 0);
$column = $this->request->post('column', 0);
// 随机图片
$directory = env('COVER_ROOT'); // 文件夹路径
$images = glob($directory . '/*.{jpg,jpeg,png,gif,bmp}', GLOB_BRACE); // 获取图片文件
$imagesArr = [];
if (count($images) > 0) {
foreach ($images as $image) {
$imagesArr[] = basename($image);
}
}
if (!$imagesArr) {
return $this->response->json(['code' => 400, 'msg' => 'not content.']);
}
if (!$content) {
return $this->response->json(['code' => 400, 'msg' => 'not content.']);
}
$content = json_decode($content, true);
foreach ($content as $item) {
$randIndex = mt_rand(1,count($imagesArr));
$cover = $imagesArr[$randIndex];
$model = new AppNews();
$model->title = is_array($item['title']) ? current($item['title']) : $item['title'];
$model->description = $item['desc'];
$model->keywords = $item['keywords'];
$model->platform = $platform;
$model->cover = env('APP_DOMAIN') . '/uploads/cover/' . $cover;
$model->content = strtr($item['content'], [
'<imageSlot>' => <<<EOF
<p style="text-align:center"><img style="aspect-ratio: 4 / 3;max-width: 56%;" class="ue-image" src="$model->cover"></p>
EOF
]);
$model->column_tag = $column;
$model->save();
}
return $this->response->json(['code' => 0, 'msg' => 'ok']);
}
/**
* 删除新新闻接口
* @url /admin/api/news/delete

View File

@ -43,6 +43,7 @@ class WebsiteController extends AbstractController
$model->app_extra = $this->request->post('app_extra');
$model->app_template = $this->request->post('template');
$model->app_extra_tag = $this->request->post('app_extra_tag');
$model->app_baidu_zhanzhang = $this->request->post('app_baidu_zhanzhang');
$model->save();
return $this->response->json([]);
@ -112,6 +113,7 @@ class WebsiteController extends AbstractController
$query->app_extra = $this->request->post('app_extra');
$query->app_template = $this->request->post('template');
$query->app_extra_tag = $this->request->post('app_extra_tag');
$query->app_baidu_zhanzhang = $this->request->post('app_baidu_zhanzhang');
$query->save();

View File

@ -56,15 +56,4 @@ class ArticlesController extends AbstractController
'message' => 'ok'
];
}
#[RequestMapping(path:'brand-search', methods: 'get')]
public function brandSearch(): array
{
$input = $this->request->input('brand');
$query = Model::query()->select(['name', 'cn_name', 'id'])->where('name', 'like', "%$input%")
->orWhere('cn_name', 'like', "%$input%")
->get()->toArray();
return ['code' => 0, 'msg' => 'ok', 'data' => $query];
}
}

View File

@ -21,6 +21,9 @@ namespace App\Model;
* @property int $is_record
* @property string $cover
* @property int $is_delete
* @property string $source_url
* @property string $source_platform
* @property int $column_tag
* @property-read mixed $created_at
*/
class AppNews extends Model
@ -38,12 +41,14 @@ class AppNews extends Model
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer', 'is_delete' => 'integer'];
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'deleted_at' => 'integer', 'deleted_by' => 'integer', 'platform' => 'integer', 'is_record' => 'integer', 'is_delete' => 'integer', 'column_tag' => 'integer'];
protected ?string $dateFormat = 'U';
public function getCreatedAtAttribute($value)
{
return date('Y-m-d H:i:s', intval($value));
return $this->format('created_at', function (bool $isFormat) use ($value) {
return $isFormat ? date('Y-m-d', intval($value)) : $value;
});
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Model;
/**
* @property int $id
* @property string $name
* @property string $url
*/
class AppNewsColumn extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'app_news_column';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer'];
}

View File

@ -26,6 +26,7 @@ namespace App\Model;
* @property string $app_telephone
* @property string $app_download_url
* @property string $app_extra_tag
* @property string $app_baidu_zhanzhang
*/
class AppWebsiteConfig extends Model
{

View File

@ -10,6 +10,7 @@ class RpcResponse
public array $meta = [];
public string $title = '';
public array $pageModule = [];
public array $extra = [];
public function setData(array $data)
@ -18,6 +19,12 @@ class RpcResponse
return $this;
}
public function setExtra($extraKey = '', $value = '')
{
$this->extra[$extraKey] = $value;
return $this;
}
public function setCode(int $code)
{
$this->code = $code;
@ -32,10 +39,17 @@ class RpcResponse
public function send()
{
return [
$resp = [
'code' => $this->code,
'msg' => $this->msg,
'data' => $this->data,
];
if ($this->extra) {
foreach ($this->extra as $key => $item) {
$resp[$key] = $item;
}
}
return $resp;
}
}

View File

@ -3,27 +3,41 @@
namespace App\Rpc\v1;
use App\Model\AppNews;
use App\Model\AppNewsColumn;
use App\Rpc\BaseService;
use Hyperf\RpcServer\Annotation\RpcService;
#[RpcService(name: "news", server: "jsonrpc-http", protocol: "jsonrpc-http")]
class NewsService extends BaseService
{
public const RELATION = [
'11' => [1, 11],
'10' => [9, 10],
];
/**
* 查看单个新闻详情
* @url /news/view
* @param $id
* @return array
*/
public function view($id): array
public function view($id, $app_id): array
{
$query = AppNews::query()->where('id', $id)->where('is_delete', 0)->first()?->toArray();
$isRelation = isset(self::RELATION[$app_id]);
$query = AppNews::query()->where('id', $id)->where('platform', $isRelation ? current(self::RELATION[$app_id]) : $app_id)->where('is_delete', 0)->first()?->toArray();
if (!$query) {
return $this->getResponse()->setCode(404)->send();
}
$query['created_at'] = date('Y-m-d', $query['created_at']);
$columnTag = AppNewsColumn::find($query['column_tag']);
$query['column_tag'] = $columnTag->name ?? '';
$query['column_tag_url'] = $columnTag->url ?? '';
// 相关文章
$query['about'] = AppNews::formatQuery(['created_at'])
->where('platform', $isRelation ? current(self::RELATION[$app_id]) : $app_id)
->where('is_delete', 0)
->select(['title', 'id'])
->limit(10)
@ -32,9 +46,9 @@ class NewsService extends BaseService
->toArray();
// 上一篇文章
$query['prevNews'] = AppNews::query()->where('id', '<', $id)->select(['title', 'id'])->where('is_delete', 0)->orderBy('id', 'desc')->first();
$query['prevNews'] = AppNews::query()->where('id', '<', $id)->select(['title', 'id'])->where('platform', $app_id)->where('is_delete', 0)->orderBy('id', 'desc')->first();
// 下一篇文章
$query['nextNews'] = AppNews::query()->where('id', '>', $id)->select(['title', 'id'])->where('is_delete', 0)->first();
$query['nextNews'] = AppNews::query()->where('id', '>', $id)->select(['title', 'id'])->where('platform', $app_id)->where('is_delete', 0)->first();
return $this->getResponse()->setData($query)->setCode(0)->send();
}
@ -48,11 +62,17 @@ class NewsService extends BaseService
*/
public function index(int $id, int $limit = 30, int $page = 1): array
{
$query = AppNews::formatQuery(['created_at'])
->where('is_delete', 0)
->where('platform', $id)
->select(['id'])
->orderBy('id', 'desc');;
$query = AppNews::formatQuery(['created_at', 'column_tag'])
->where('is_delete', 0);
if (isset(self::RELATION[$id])) {
$query->whereIn('platform', self::RELATION[$id]);
} else {
$query->where('platform', $id);
}
$query->select(['id'])->orderBy('id', 'desc');
$total = $query->count();
$pagination = $query->paginate($limit, page: $page);
$ids = [];
foreach ($pagination->items() as $item) {
@ -61,6 +81,22 @@ class NewsService extends BaseService
$value = AppNews::query()->whereIn('id', $ids)->orderBy('id', 'desc')->get()->toArray();
return $this->getResponse()->setData($value)->setCode(0)->send();
foreach ($value as &$item) {
$item['created_at'] = date('Y-m-d', $item['created_at']);
$columnTag = AppNewsColumn::find($item['column_tag']);
$item['column_tag'] = $columnTag->name ?? '';
$item['column_tag_url'] = $columnTag->url ?? '';
}
$hot = AppNews::formatQuery(['created_at'])
->where('platform', $id)
->where('is_delete', 0)
->select(['title', 'id', 'cover'])
->limit(5)
->orderBy('id', 'desc')
->get()
->toArray();
return $this->getResponse()->setExtra('hot', $hot)->setExtra('total', ceil($total / $limit))->setData($value)->setCode(0)->send();
}
}

View File

@ -18,7 +18,7 @@ class WebsiteService extends BaseService
*/
public function config($host): array
{
$query = AppWebsiteConfig::query()->where('app_domain', $host)->where('is_delete', 0)->first()?->toArray();
$query = AppWebsiteConfig::query()->where('app_domain', 'like' , "%$host%")->where('is_delete', 0)->first()?->toArray();
if (!$query) {
return $this->getResponse()->setCode(404)->send();

View File

@ -369,6 +369,13 @@ $articleLocation = array_map(fn($case) => [
});
</script>
<style>
h1, .h1, h2, .h2, h3, .h3, p {
font-family: 'Microsoft Yahei",Helvetica,Arial,sans-serif'; /* 常见的、现代的无衬线字体,增加可读性 */
text-indent: unset !important;
margin-top: 0.5rem;
margin-bottom: unset;
}
.res-options {
padding: 0 10px;
line-height: 36px;

View File

@ -0,0 +1,173 @@
<?php
$platforms = call_user_func(function () {
return \App\Model\AppWebsiteConfig::query()->where('is_delete', 0)->get()->toArray();
});
$columnTag = call_user_func(function () {
return \App\Model\AppNewsColumn::query()->get()->toArray();
});
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>导入</title>
<link rel="stylesheet" href="/component/pear/css/pear.css" />
<link rel="stylesheet" href="/admin/css/reset.css" />
</head>
<body>
<form class="layui-form" action="">
<div class="mainBox">
<div class="main-container mr-5">
<div class="layui-form-item">
<label class="layui-form-label required">发布平台</label>
<div class="layui-input-block">
<select name="platform" lay-search="">
<option value="">请选择</option>
<?php foreach ($platforms ?: [] as $platform): ?>
<option value="<?= $platform['id'] ?>"><?= $platform['app_name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label required">栏目</label>
<div class="layui-input-block">
<select name="column" lay-search="">
<option value="">请选择</option>
<?php foreach ($columnTag ?: [] as $tag): ?>
<option value="<?= $tag['id'] ?>"><?= $tag['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">json数据</label>
<div class="layui-input-block">
<textarea name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
</div>
</div>
<div class="layui-form-item">
<div class="button-container">
<button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="submit">
提交
</button>
</div>
</div>
</div>
</div>
</form>
<script src="/component/layui/layui.js?v=2.8.12"></script>
<script src="/component/pear/pear.js"></script>
<script>
// api
const SAVE_API = "/admin/api/news/import"; // 插入新闻
const UPLOAD_API = '/upload/image' // 上传图片
layui.use(['upload', 'jquery', 'popup'], function(){
const upload = layui.upload;
const $ = layui.jquery;
layui.form.on("submit(submit)", function (data) {
layui.$.ajax({
url: SAVE_API,
type: "POST",
dateType: "json",
data: data.field,
success: function (res) {
if (res.code) {
return layui.popup.failure(res.msg);
}
return layui.popup.success("操作成功", function () {
parent.refreshTable();
parent.layer.close(parent.layer.getFrameIndex(window.name));
});
}
});
return false;
});
});
</script>
<style>
#editor—wrapper {
border: 1px solid #ccc;
z-index: 100; /* 按需定义 */
}
#toolbar-container {
border-bottom: 1px solid #ccc;
}
#editor-container {
height: 500px;
}
</style>
<style>
.res-options {
padding: 0 10px;
line-height: 36px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.layui-upload-list {
margin-top: 20px;
display: grid;
grid-template-columns: repeat(auto-fill, 120px);
gap: 15px;
}
.img-item {
position: relative;
border: 1px solid #e6e6e6;
border-radius: 4px;
cursor: move;
}
.img-preview {
width: 100%;
height: 120px;
object-fit: contain;
}
.img-operate {
position: absolute;
top: 5px;
right: 5px;
opacity: 0;
transition: .3s;
}
.img-item:hover .img-operate {
opacity: 1;
}
#images-tpl-container .layui-icon-close,
#images-tpl-container .layui-icon-util {
color: #fff;
background: #ff5722;
border-radius: 50%;
padding: 2px;
cursor: pointer;
}
.layui-upload-list {
/* 保持原有样式 */
margin-top: 20px;
display: grid;
grid-template-columns: repeat(auto-fill, 120px);
gap: 15px;
}
/* 新增显示限制 */
.img-item:nth-child(n+31) {
display: none;
}
.load-more-btn {
grid-column: 1 / -1;
text-align: center;
padding: 10px 0;
}
</style>
</body>
</html>

View File

@ -63,9 +63,9 @@
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
<i class="layui-icon layui-icon-add-1"></i>新增
</button>
{{-- <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">--}}
{{-- <i class="layui-icon layui-icon-delete"></i>删除--}}
{{-- </button>--}}
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="import">
<i class="layui-icon layui-icon-file"></i>导入
</button>
</script>
<!-- 表格行工具栏 -->
@ -97,6 +97,7 @@
const VIEW_API = "/admin/news/view";
const INSERT_API = "/admin/api/news/insert";
const INSERT_URL = "/admin/news/insert";
const IMPORT_URL = "/admin/news/import";
const DELETE_API = "/admin/api/news/delete";
// 字段 创建时间 created_at
@ -191,8 +192,8 @@
add();
} else if (obj.event === "refresh") {
refreshTable();
} else if (obj.event === "batchRemove") {
batchRemove(obj);
} else if (obj.event === "import") {
importNews(obj);
}
});
@ -237,6 +238,17 @@
});
}
// 导入数据
let importNews = function () {
layer.open({
type: 2,
title: "导入",
shade: 0.1,
area: [common.isModile() ? "100%" : "98%", common.isModile() ? "100%" : "95%"],
content: IMPORT_URL
});
}
// 表格编辑数据
let edit = function (obj) {
let value = obj.data['id'];

View File

@ -66,10 +66,16 @@
<label class="layui-form-label">模板</label>
<div class="layui-input-inline layui-input-wrap">
<input type="radio" name="template" value="2" title="模板2">
{{-- <input type="radio" name="sex" value="2" title="">--}}
<input type="radio" name="template" value="3" title="模板3">
{{-- <input type="radio" name="sex" value="nv" title="" checked>--}}
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">百度站长验证</label>
<div class="layui-input-inline layui-input-wrap">
<input type="text" name="app_baidu_zhanzhang" autocomplete="off" lay-affix="clear" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">extra_tag</label>
<div class="layui-input-inline layui-input-wrap">

View File

@ -63,11 +63,17 @@
<input type="text" name="app_filing_url" autocomplete="off" lay-affix="clear" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">百度站长验证</label>
<div class="layui-input-inline layui-input-wrap">
<input type="text" name="app_baidu_zhanzhang" autocomplete="off" lay-affix="clear" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">模板</label>
<div class="layui-input-inline layui-input-wrap">
<input type="radio" name="template" value="2" title="模板2">
{{-- <input type="radio" name="sex" value="2" title="">--}}
<input type="radio" name="template" value="3" title="模板3">
{{-- <input type="radio" name="sex" value="nv" title="" checked>--}}
</div>
</div>