Compare commits
31 Commits
f060934b86
...
main
Author | SHA1 | Date | |
---|---|---|---|
07fe136d62 | |||
24590b05c0 | |||
7d619fb503 | |||
95b480b346 | |||
eac64e779a | |||
f0eed20b0a | |||
9a76ce372b | |||
e9ab49ad24 | |||
0b85d58bb9 | |||
c0ccbd184f | |||
7c663867e8 | |||
6e3197d585 | |||
993fe4ed49 | |||
f34ebb58dc | |||
089b935cfb | |||
fca5d93e1b | |||
cae6609d71 | |||
0a83e2dfc6 | |||
b1159b17cb | |||
8ca0e04569 | |||
86c687409b | |||
dcbe1b6728 | |||
b4416260fd | |||
bb9639ce0c | |||
28336adc87 | |||
7e7424fc85 | |||
21de56d967 | |||
176e6afae7 | |||
a432723770 | |||
2664c7741d | |||
716e20675e |
222
app/Command/baidu/AutoPush.php
Normal file
222
app/Command/baidu/AutoPush.php
Normal 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}");
|
||||
}
|
||||
}
|
147
app/Command/sitemap/Toutiao.php
Normal file
147
app/Command/sitemap/Toutiao.php
Normal 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;
|
||||
}
|
||||
}
|
@ -10,6 +10,6 @@ class Config extends AbstractConstants
|
||||
{
|
||||
public static function getDomain()
|
||||
{
|
||||
return env('APP_DOMAIN', '');
|
||||
return env('APP_DOMAIN', 'http://127.0.0.1');
|
||||
}
|
||||
}
|
@ -69,10 +69,10 @@ class UploadController extends AbstractController
|
||||
}
|
||||
|
||||
// 校验类型
|
||||
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
if (!in_array($file->getClientMediaType(), $allowedTypes)) {
|
||||
return $this->response->json(['code' => 415, 'msg' => '不支持的图片格式']);
|
||||
}
|
||||
// $allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
|
||||
// if (!in_array($file->getClientMediaType(), $allowedTypes)) {
|
||||
// return $this->response->json(['code' => 415, 'msg' => '不支持的图片格式']);
|
||||
// }
|
||||
|
||||
// 限制大小 (例如 5MB)
|
||||
$maxSize = 5 * 1024 * 1024;
|
||||
@ -98,7 +98,7 @@ class UploadController extends AbstractController
|
||||
|
||||
return $this->response->json([
|
||||
'errno' => 0,
|
||||
'msg' => '上传成功!!',
|
||||
'msg' => '上传成功!!~',
|
||||
'data' => [
|
||||
'url' => Config::getDomain() . $url,
|
||||
]
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -37,6 +37,13 @@ class WebsiteController extends AbstractController
|
||||
$model->app_description = $this->request->post('app_description');
|
||||
$model->app_name = $this->request->post('app_name');
|
||||
$model->app_domain = $this->request->post('app_domain');
|
||||
$model->app_filing = $this->request->post('app_filing');
|
||||
$model->app_filing_url = $this->request->post('app_filing_url');
|
||||
$model->app_logo = $this->request->post('app_logo');
|
||||
$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([]);
|
||||
@ -77,7 +84,7 @@ class WebsiteController extends AbstractController
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
$query['template'] = $query['app_template'];
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query]);
|
||||
}
|
||||
|
||||
@ -100,6 +107,13 @@ class WebsiteController extends AbstractController
|
||||
$query->app_name = $this->request->post('app_name');
|
||||
$query->app_domain = $this->request->post('app_domain');
|
||||
$query->app_keywords = $this->request->post('app_keywords');
|
||||
$query->app_filing = $this->request->post('app_filing');
|
||||
$query->app_filing_url = $this->request->post('app_filing_url');
|
||||
$query->app_logo = $this->request->post('app_logo');
|
||||
$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();
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ class NewsFormModel
|
||||
$model->description = $this->attributes['description'];
|
||||
$model->cover = $this->attributes['cover'];
|
||||
$model->content = $this->attributes['content'];
|
||||
$model->platform = $this->attributes['platform'];
|
||||
$model->save();
|
||||
}
|
||||
}
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
30
app/Model/AppNewsColumn.php
Normal file
30
app/Model/AppNewsColumn.php
Normal 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'];
|
||||
}
|
@ -18,6 +18,15 @@ namespace App\Model;
|
||||
* @property string $app_domain
|
||||
* @property int $is_delete
|
||||
* @property string $app_keywords
|
||||
* @property string $app_filing
|
||||
* @property string $app_filing_url
|
||||
* @property string $app_extra
|
||||
* @property string $app_logo
|
||||
* @property int $app_template
|
||||
* @property string $app_telephone
|
||||
* @property string $app_download_url
|
||||
* @property string $app_extra_tag
|
||||
* @property string $app_baidu_zhanzhang
|
||||
*/
|
||||
class AppWebsiteConfig extends Model
|
||||
{
|
||||
@ -34,5 +43,5 @@ class AppWebsiteConfig 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', 'is_delete' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'created_at' => 'datetime', 'created_by' => 'integer', 'updated_at' => 'datetime', 'updated_by' => 'integer', 'is_delete' => 'integer', 'app_template' => 'integer'];
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
@ -46,12 +60,19 @@ class NewsService extends BaseService
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $limit = 30, int $page = 1): array
|
||||
public function index(int $id, int $limit = 30, int $page = 1): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at'])
|
||||
->where('is_delete', 0)
|
||||
->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) {
|
||||
@ -60,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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
|
@ -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;
|
||||
|
173
storage/view/news/import.blade.php
Normal file
173
storage/view/news/import.blade.php
Normal 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>
|
@ -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'];
|
||||
|
@ -1,8 +1,7 @@
|
||||
<?php
|
||||
$articleLocation = array_map(fn($case) => [
|
||||
'label' => ucfirst($case->toString()),
|
||||
'value' => $case->value,
|
||||
], \App\Enums\LocationEnum::cases());
|
||||
$platforms = call_user_func(function () {
|
||||
return \App\Model\AppWebsiteConfig::query()->where('is_delete', 0)->get()->toArray();
|
||||
});
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
@ -21,6 +20,17 @@ $articleLocation = array_map(fn($case) => [
|
||||
<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">
|
||||
|
@ -1,3 +1,8 @@
|
||||
<?php
|
||||
$platforms = call_user_func(function () {
|
||||
return \App\Model\AppWebsiteConfig::query()->where('is_delete', 0)->get()->toArray();
|
||||
});
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
@ -16,6 +21,17 @@
|
||||
<input type="hidden" name="id" value="" autocomplete="off">
|
||||
<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">
|
||||
@ -194,6 +210,9 @@
|
||||
document.querySelector('[id="cover"]').src = res.data.cover
|
||||
$("[name=cover]").val(res.data.cover);
|
||||
|
||||
$("select[name=platform]").val(res.data.platform);
|
||||
layui.form.render("select");
|
||||
|
||||
editor.setHtml(res.data.content)
|
||||
|
||||
// ajax产生错误
|
||||
|
@ -19,25 +19,67 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">网站名称</label>
|
||||
<div class="layui-input-inline layui-input-wrap">
|
||||
<input type="text" name="app_name" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_name" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">网站logo</label>
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn" id="logo_upload_btn">
|
||||
<i class="layui-icon"></i>上传图片
|
||||
</button>
|
||||
<img style="max-height: 50px;" src="" id="app_logo">
|
||||
<input type="hidden" name="app_logo" value="" class="layui-input" autocomplete="off">
|
||||
</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_description" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_description" 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_keywords" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_keywords" 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_company" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_company" 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_filing" 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_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="radio" name="template" value="2" title="模板2">
|
||||
<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">
|
||||
<input type="text" name="app_extra_tag" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
@ -54,9 +96,37 @@
|
||||
<script>
|
||||
// api
|
||||
const INSERT_API = "/admin/api/website/config/insert";
|
||||
const UPLOAD_API = '/upload/image' // 上传图片
|
||||
|
||||
layui.use(['upload', 'jquery', 'popup'], function(){
|
||||
const $ = layui.jquery;
|
||||
const upload = layui.upload;
|
||||
// 上传logo
|
||||
upload.render({
|
||||
elem: '#logo_upload_btn' //绑定元素
|
||||
,url: UPLOAD_API // 上传接口,实际使用时改成您自己的上传接口即可。
|
||||
,accept: 'images' // 限制为图片类型
|
||||
,exts: 'jpg|jpeg|png|gif|ico' // 允许上传的文件格式,加入 ico 格式
|
||||
,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
|
||||
console.log(obj)
|
||||
}
|
||||
,done: function(res){
|
||||
//上传完毕回调
|
||||
console.log(res)
|
||||
// 若上传失败
|
||||
if(res.code > 0){
|
||||
return layer.msg('上传失败');
|
||||
}
|
||||
// 上传成功的一些操作
|
||||
// …
|
||||
document.querySelector('[id="app_logo"]').src = res.data.url
|
||||
$("input[name=app_logo]").val(res.data.url);
|
||||
}
|
||||
,error: function(e){
|
||||
console.log(e)
|
||||
//请求异常回调
|
||||
}
|
||||
});
|
||||
|
||||
layui.form.on("submit(insert)", function (data) {
|
||||
console.log(data)
|
||||
|
@ -20,25 +20,67 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">网站名称</label>
|
||||
<div class="layui-input-inline layui-input-wrap">
|
||||
<input type="text" name="app_name" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_name" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">网站logo</label>
|
||||
<div class="layui-input-block">
|
||||
<button type="button" class="layui-btn" id="logo_upload_btn">
|
||||
<i class="layui-icon"></i>上传图片
|
||||
</button>
|
||||
<img style="max-height: 50px;" src="" id="app_logo">
|
||||
<input type="hidden" name="app_logo" value="" class="layui-input" autocomplete="off">
|
||||
</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_description" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_description" 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_keywords" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_keywords" 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_company" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
<input type="text" name="app_company" 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_filing" 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_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="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">extra_tag</label>
|
||||
<div class="layui-input-inline layui-input-wrap">
|
||||
<input type="text" name="app_extra_tag" autocomplete="off" lay-affix="clear" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
@ -57,10 +99,11 @@
|
||||
// API
|
||||
const VIEW_API = "/admin/api/website/config/view"; // 获取关键词数据
|
||||
const SAVE_API = "/admin/api/website/config/save"; // 重新保存数据
|
||||
const UPLOAD_API = '/upload/image' // 上传图片
|
||||
|
||||
layui.use(['upload', 'jquery', 'popup', 'form'], function(){
|
||||
const $ = layui.jquery;
|
||||
|
||||
const upload = layui.upload;
|
||||
initViewData()
|
||||
layui.form.on("submit(save)", function (data) {
|
||||
layui.$.ajax({
|
||||
@ -81,7 +124,32 @@
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
// 上传logo
|
||||
upload.render({
|
||||
elem: '#logo_upload_btn' //绑定元素
|
||||
,url: UPLOAD_API // 上传接口,实际使用时改成您自己的上传接口即可。
|
||||
,accept: 'images' // 限制为图片类型
|
||||
,exts: 'jpg|jpeg|png|gif|ico' // 允许上传的文件格式,加入 ico 格式
|
||||
,before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
|
||||
console.log(obj)
|
||||
}
|
||||
,done: function(res){
|
||||
//上传完毕回调
|
||||
console.log(res)
|
||||
// 若上传失败
|
||||
if(res.code > 0){
|
||||
return layer.msg('上传失败');
|
||||
}
|
||||
// 上传成功的一些操作
|
||||
// …
|
||||
document.querySelector('[id="app_logo"]').src = res.data.url
|
||||
$("input[name=app_logo]").val(res.data.url);
|
||||
}
|
||||
,error: function(e){
|
||||
console.log(e)
|
||||
//请求异常回调
|
||||
}
|
||||
});
|
||||
function initViewData() {
|
||||
let viewId = layui.url().search['id']
|
||||
$.ajax({
|
||||
@ -92,6 +160,10 @@
|
||||
method: 'get',
|
||||
dataType: "json",
|
||||
success: function (res) {
|
||||
// ajax产生错误
|
||||
if (res.code) {
|
||||
layui.popup.failure(res.msg);
|
||||
}
|
||||
|
||||
// 赋值表单
|
||||
layui.each(res.data, function (key, value) {
|
||||
@ -109,23 +181,17 @@
|
||||
});
|
||||
|
||||
const form = layui.form;
|
||||
|
||||
const selectedPlatforms = res.data.platform; // 后端数据
|
||||
|
||||
selectedPlatforms?.forEach(val => {
|
||||
// 设置 value 对应的 checkbox 为选中
|
||||
document.querySelectorAll('input[name="platform[]"]').forEach(el => {
|
||||
if (el.value == val) {
|
||||
el.checked = true;
|
||||
}
|
||||
});
|
||||
const app_template = res.data.app_template
|
||||
console.log(document.querySelectorAll('input[name="template"]'))
|
||||
document.querySelectorAll('input[name="template"]').forEach(el => {
|
||||
if (el.value == app_template) {
|
||||
el.checked = true;
|
||||
}
|
||||
// console.log(el)
|
||||
});
|
||||
|
||||
form.render('checkbox'); // 重新渲染
|
||||
// ajax产生错误
|
||||
if (res.code) {
|
||||
layui.popup.failure(res.msg);
|
||||
}
|
||||
document.querySelector('[id="app_logo"]').src = res.data.app_logo
|
||||
form.render('radio'); // 重新渲染
|
||||
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user