fix - bug
This commit is contained in:
@ -3,10 +3,13 @@
|
||||
namespace App\Constants;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use function Hyperf\Support\env;
|
||||
|
||||
#[Constants]
|
||||
class Config extends AbstractConstants
|
||||
{
|
||||
//以下为图片业务自定义常量
|
||||
public const DOMAIN = "https://seo.23cm.cn";
|
||||
public static function getDomain()
|
||||
{
|
||||
return env('APP_DOMAIN', '');
|
||||
}
|
||||
}
|
@ -100,7 +100,7 @@ class UploadController extends AbstractController
|
||||
'errno' => 0,
|
||||
'msg' => '上传成功!!',
|
||||
'data' => [
|
||||
'url' => Config::DOMAIN . $url,
|
||||
'url' => Config::getDomain() . $url,
|
||||
]
|
||||
]);
|
||||
}
|
||||
@ -152,7 +152,7 @@ class UploadController extends AbstractController
|
||||
'errno' => 0,
|
||||
'msg' => '上传成功~~',
|
||||
'data' => [
|
||||
'url' => Config::DOMAIN . $url,
|
||||
'url' => Config::getDomain() . $url,
|
||||
'file_name' => $url
|
||||
]
|
||||
]);
|
||||
|
@ -1,113 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\admin\api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Enums\ArticlePublishedStatusEnum;
|
||||
use App\FormModel\admin\articles\ModifyModel;
|
||||
use App\Helpers\AppHelper;
|
||||
use App\Model\AppArticle;
|
||||
use App\Model\AppBrand;
|
||||
use App\Model\AppNews;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
#[Controller(prefix: 'admin/api')]
|
||||
class ArticleController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* 文章列表
|
||||
* @url /admin/api/article
|
||||
* @return array
|
||||
*/
|
||||
#[RequestMapping(path:'articles', methods: 'get')]
|
||||
public function index(): array
|
||||
{
|
||||
$publishedStatus = $this->request->query('published_status', '');
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
}
|
||||
|
||||
if ($index == 1) {
|
||||
$item = strtotime($item . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
|
||||
$query = AppNews::formatQuery(['module', 'published_status', 'location'])
|
||||
->select(['id'])
|
||||
->when($publishedStatus !== '', fn($q) => $q->where('published_status', $publishedStatus))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('created_at', 'desc');
|
||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||
foreach ($pagination->items() as $item) {
|
||||
$ids[] = $item->id;
|
||||
}
|
||||
|
||||
$value = AppNews::find($ids, ['aid', 'title', 'module', 'published_status', 'location'])->toArray();
|
||||
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $value];
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 新增/编辑文章
|
||||
// * @url /api/v1/articles/save
|
||||
// * @return array
|
||||
// */
|
||||
// #[RequestMapping(path:'save', methods: 'post')]
|
||||
// public function save(): array
|
||||
// {
|
||||
// $id = $this->request->input('id');
|
||||
// $model = new ArticlesModel();
|
||||
// if ($id) {
|
||||
// $model->edit();
|
||||
// } else {
|
||||
// $model->create();
|
||||
// }
|
||||
//
|
||||
// return [
|
||||
// 'code' => 0,
|
||||
// 'message' => 'ok'
|
||||
// ];
|
||||
// }
|
||||
|
||||
#[RequestMapping(path:'brand-search', methods: 'get')]
|
||||
public function brandSearch(): array
|
||||
{
|
||||
$input = $this->request->input('brand');
|
||||
$query = AppBrand::query()->select(['name', 'cn_name', 'id'])->where('name', 'like', "%$input%")
|
||||
->orWhere('cn_name', 'like', "%$input%")
|
||||
->get()->toArray();
|
||||
|
||||
return ['code' => 0, 'msg' => 'ok', 'data' => $query];
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'view', methods: 'get')]
|
||||
public function view(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$query = AppNews::formatQuery(['images', 'brand_name', 'translate_title'])
|
||||
->select(['brand as brand_name', 'brand', 'images', 'id', 'title', 'title as translate_title', 'cover', 'aid', 'location'])
|
||||
->where('aid', $this->request->query('id'));
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query->first()]);
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'publish', methods: 'post')]
|
||||
public function publish()
|
||||
{
|
||||
$query = AppArticle::where('aid', $this->request->post('aid'))->first();
|
||||
$query->published_status = ArticlePublishedStatusEnum::TRUE->value;
|
||||
$query->published_at = time();
|
||||
$query->save();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
|
||||
#[RequestMapping(path:'update', methods: 'post')]
|
||||
public function update()
|
||||
{
|
||||
$model = new ModifyModel();
|
||||
$model->setAttributes($this->request->post());
|
||||
$model->update();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
@ -47,6 +47,7 @@ class KeywordsController extends AbstractController
|
||||
public function monitorInsert(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$keyword = $this->request->post('keyword');
|
||||
$ignoreUrl = $this->request->post('ignore_url');
|
||||
|
||||
$query = AppKeywordsMonitor::query()->where([
|
||||
['keyword', $keyword],
|
||||
@ -59,7 +60,9 @@ class KeywordsController extends AbstractController
|
||||
$query = new AppKeywordsMonitor();
|
||||
|
||||
$query->keyword = $keyword;
|
||||
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||
|
||||
$query->ignore_url = json_encode($ignoreUrl);
|
||||
$query->save();
|
||||
|
||||
foreach ($this->request->post('platform', []) as $platform) {
|
||||
@ -83,11 +86,14 @@ class KeywordsController extends AbstractController
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
|
||||
$query = AppKeywordsMonitor::query()->where(['id' => $id])->first()->toArray();
|
||||
$query = AppKeywordsMonitor::formatQuery(['ignore_url'])->where(['id' => $id])->first()->toArray();
|
||||
if (!$query) {
|
||||
return $this->response->json(['code' => 400, 'msg' => 'id 有误']);
|
||||
}
|
||||
|
||||
if ($query['ignore_url']) {
|
||||
$query['ignore_url'] = implode(PHP_EOL, $query['ignore_url']);
|
||||
}
|
||||
$query['platform'] = AppKeywordsMonitorTask::query()->select(['platform'])
|
||||
->where([
|
||||
['aid', $query['id']],
|
||||
@ -109,6 +115,7 @@ class KeywordsController extends AbstractController
|
||||
$id = $this->request->post('id');
|
||||
$keyword = $this->request->post('keyword');
|
||||
$platform = $this->request->post('platform', []);
|
||||
$ignoreUrl = $this->request->post('ignore_url');
|
||||
|
||||
$query = AppKeywordsMonitor::find($id);
|
||||
if (!$query) {
|
||||
@ -116,6 +123,9 @@ class KeywordsController extends AbstractController
|
||||
}
|
||||
|
||||
$query->keyword = $keyword;
|
||||
$ignoreUrl = array_filter(array_unique(explode(PHP_EOL, $ignoreUrl)));
|
||||
|
||||
$query->ignore_url = json_encode($ignoreUrl);
|
||||
$query->save();
|
||||
|
||||
// 先全部删掉
|
||||
@ -163,20 +173,26 @@ class KeywordsController extends AbstractController
|
||||
/**
|
||||
* 导出关键词报表
|
||||
* @url /admin/api/keywords/monitor/export-all
|
||||
* @return \Psr\Http\Message\ResponseInterface
|
||||
*/
|
||||
#[RequestMapping(path: 'monitor/export-all', methods: 'get')]
|
||||
public function monitorExportAll(): \Psr\Http\Message\ResponseInterface
|
||||
public function monitorExportAll()
|
||||
{
|
||||
$res = AppKeywordsMonitorResult::query()->orderBy('aid', 'desc')->get()->toArray();
|
||||
|
||||
foreach ($res as &$v) {
|
||||
$v['keyword'] = AppKeywordsMonitorTask::find($v['aid'])->keyword;
|
||||
$v['screen_path'] = Config::DOMAIN . $v['screen_path'];
|
||||
$v['screen_path'] = Config::getDomain() . $v['screen_path'];
|
||||
}
|
||||
|
||||
// 百度PC非负率
|
||||
$total = 20 * AppKeywordsMonitorTask::query()->where('platform', 1)->count();
|
||||
$baiduRes = $res;
|
||||
$percent = round(($total - count($baiduRes)) / $total, 2) * 100;
|
||||
$fileName = date('Y-m-d') . '关键词监控结果';
|
||||
return ExcelHelper::exportData($this->response, list: $res, header: [
|
||||
|
||||
return ExcelHelper::exportData($this->response, list: [
|
||||
"百度PC端_$percent%" => $baiduRes
|
||||
], header: [
|
||||
['关键词', 'keyword', 'text'],
|
||||
['标题', 'title', 'text'],
|
||||
['排名', 'order', 'text'],
|
||||
|
@ -25,6 +25,7 @@ class NewsController extends AbstractController
|
||||
public function index(): array
|
||||
{
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
$title = $this->request->input('title', '');
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
@ -37,7 +38,9 @@ class NewsController extends AbstractController
|
||||
|
||||
$ids = [];
|
||||
$query = AppNews::query()
|
||||
->where('is_delete', 0)
|
||||
->select(['id'])
|
||||
->when($title, fn($q) => $q->where('title', 'like', "%{$title}%"))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('id', 'desc');
|
||||
$pagination = $query->paginate($this->request->input('limit', 10), page: $this->request->input('page'));
|
||||
@ -88,4 +91,19 @@ class NewsController extends AbstractController
|
||||
$model->insert();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除新新闻接口
|
||||
* @url /admin/api/news/delete
|
||||
*/
|
||||
#[RequestMapping(path:'delete', methods: 'post')]
|
||||
public function delete(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$query = AppNews::find($id);
|
||||
$query->is_delete = 1;
|
||||
$query->deleted_at = time();
|
||||
$query->save();
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\admin\api;
|
||||
|
||||
use App\Controller\AbstractController;
|
||||
use App\Enums\SpiderArticlePublishedStatusEnum;
|
||||
use App\FormModel\spiderArticle\ReviewModel;
|
||||
use App\Model\AppSpiderArticle;
|
||||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
|
||||
|
||||
#[Controller(prefix: 'admin/api/spider-article')]
|
||||
class SpiderArticleController extends AbstractController
|
||||
{
|
||||
#[RequestMapping(path: '', methods: 'get')]
|
||||
public function index(): array
|
||||
{
|
||||
$createdFilter = $this->request->query('created_at', [date('Y-m-d', strtotime('-1 month')), date('Y-m-d', time())]);
|
||||
foreach ($createdFilter as $index => &$item) {
|
||||
if ($index == 0) {
|
||||
$item = strtotime($item . ' 00:00:00');
|
||||
}
|
||||
|
||||
if ($index == 1) {
|
||||
$item = strtotime($item . ' 23:59:59');
|
||||
}
|
||||
}
|
||||
$titleFilter = $this->request->query('title');
|
||||
$publishedStatus = $this->request->query('published_status', SpiderArticlePublishedStatusEnum::FALSE);
|
||||
$request = $this->request;
|
||||
$query = AppSpiderArticle::formatQuery(['created_at', 'module', 'published_status'])
|
||||
->select(['id', 'title', 'created_at', 'module', 'source_url', 'published_status'])
|
||||
->when($publishedStatus !== null, fn($q) => $q->where('published_status', $publishedStatus))
|
||||
->when($titleFilter, fn($q) => $q->where('title', 'like', "%{$titleFilter}%"))
|
||||
->when($this->request->query('module', '') !== '', fn($q) => $q->where('module', $this->request->query('module')))
|
||||
->whereBetween('created_at', $createdFilter)
|
||||
->orderBy('created_at', 'desc');
|
||||
$pagination = $query->paginate($request->input('limit', 10), page: $request->input('page'));
|
||||
|
||||
return ['code' => 0, 'msg' => 'ok', 'count' => $pagination->total(), 'data' => $pagination->items()];
|
||||
}
|
||||
|
||||
#[RequestMapping(path: 'view', methods: 'get')]
|
||||
public function view(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$query = AppSpiderArticle::formatQuery(['images', 'module', 'brand'])->find($this->request->query('id'));
|
||||
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok', 'data' => $query->toArray()]);
|
||||
}
|
||||
|
||||
#[RequestMapping(path: 'pre-publish', methods: 'post')]
|
||||
public function prePublish(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$prePublishModel = new ReviewModel();
|
||||
$prePublishModel->prePublish($this->request->post('id'));
|
||||
return $this->response->json(['code' => 0, 'msg' => 'ok']);
|
||||
}
|
||||
}
|
@ -20,12 +20,16 @@ class ToolsController extends AbstractController
|
||||
#[RequestMapping(path:'get-query-keyword', methods:'get')]
|
||||
public function getQueryKeyword(): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$keyword = AppKeywordsMonitorTask::formatQuery(['created_at'])
|
||||
$keyword = AppKeywordsMonitorTask::query()
|
||||
->where('queried_at', '<=', strtotime('-2 hours'))
|
||||
->where('is_delete', 0);
|
||||
|
||||
if ($keyword) {
|
||||
$query = $keyword->first()?->toArray();
|
||||
if ($query) {
|
||||
$ignoreUrl = AppKeywordsMonitor::formatQuery([])->where('id', $query['aid'])->first()?->toArray()['ignore_url'] ?? [];
|
||||
$query['ignore_url'] = $ignoreUrl;
|
||||
}
|
||||
return $this->response->json([
|
||||
'code' => 0,
|
||||
'data' => $query
|
||||
|
@ -31,7 +31,7 @@ class ExcelHelper
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
|
||||
*/
|
||||
public static function exportData(ResponseInterface $response, $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
||||
public static function exportData(ResponseInterface $response, array $list = [], $header = [], $filename = '', $suffix = 'xlsx', $path = '')
|
||||
{
|
||||
if (!is_array($list) || !is_array($header)) {
|
||||
return false;
|
||||
@ -53,9 +53,11 @@ class ExcelHelper
|
||||
|
||||
// 开始写入内容
|
||||
$column = 2;
|
||||
$size = ceil(count($list) / 500);
|
||||
foreach ($list as $sheetTitle => $sheetListItem) {
|
||||
$sheet->setTitle($sheetTitle);
|
||||
$size = ceil(count($sheetListItem) / 500);
|
||||
for ($i = 0; $i < $size; $i++) {
|
||||
$buffer = array_slice($list, $i * 500, 500);
|
||||
$buffer = array_slice($sheetListItem, $i * 500, 500);
|
||||
|
||||
foreach ($buffer as $k => $row) {
|
||||
$span = 1;
|
||||
@ -73,7 +75,7 @@ class ExcelHelper
|
||||
unset($buffer[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 清除之前的错误输出
|
||||
// ob_end_clean();
|
||||
ob_start();
|
||||
|
@ -13,8 +13,9 @@ namespace App\Model;
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $deleted_at
|
||||
* @property int $is_delete
|
||||
* @property int $queried_at
|
||||
* @property int $platform
|
||||
* @property string $ignore_url
|
||||
* @property-read string $queried_at
|
||||
*/
|
||||
class AppKeywordsMonitor extends Model
|
||||
{
|
||||
@ -40,4 +41,11 @@ class AppKeywordsMonitor extends Model
|
||||
}
|
||||
return date('Y-m-d H:i:s', intval($value)) ?: '未查询';
|
||||
}
|
||||
|
||||
function getIgnoreUrlAttribute($value)
|
||||
{
|
||||
return $this->format('ignore_url', function (bool $isFormat) use ($value) {
|
||||
return $isFormat ? (($value && is_string($value)) ? json_decode($value, true) : []) : $value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ namespace App\Model;
|
||||
* @property string $keywords
|
||||
* @property string $content
|
||||
* @property string $description
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property int $created_by
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property int $updated_by
|
||||
@ -21,6 +20,8 @@ namespace App\Model;
|
||||
* @property int $platform
|
||||
* @property int $is_record
|
||||
* @property string $cover
|
||||
* @property int $is_delete
|
||||
* @property-read mixed $created_at
|
||||
*/
|
||||
class AppNews extends Model
|
||||
{
|
||||
@ -37,7 +38,7 @@ 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'];
|
||||
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 ?string $dateFormat = 'U';
|
||||
|
||||
|
@ -17,9 +17,14 @@ class NewsService extends BaseService
|
||||
*/
|
||||
public function view($id): array
|
||||
{
|
||||
$query = AppNews::find($id)->toArray();
|
||||
$query = AppNews::query()->where('id', $id)->where('is_delete', 0)->first()?->toArray();
|
||||
|
||||
if (!$query) {
|
||||
return $this->getResponse()->setCode(404)->send();
|
||||
}
|
||||
// 相关文章
|
||||
$query['about'] = AppNews::formatQuery(['created_at'])
|
||||
->where('is_delete', 0)
|
||||
->select(['title', 'id'])
|
||||
->limit(10)
|
||||
->orderBy('id', 'desc')
|
||||
@ -27,9 +32,9 @@ class NewsService extends BaseService
|
||||
->toArray();
|
||||
|
||||
// 上一篇文章
|
||||
$query['prevNews'] = AppNews::find($id - 1, ['title', 'id'])?->toArray();
|
||||
$query['prevNews'] = AppNews::query()->where('id', '<', $id)->select(['title', 'id'])->where('is_delete', 0)->orderBy('id', 'desc')->first();
|
||||
// 下一篇文章
|
||||
$query['nextNews'] = AppNews::find($id + 1, ['title', 'id'])?->toArray();
|
||||
$query['nextNews'] = AppNews::query()->where('id', '>', $id)->select(['title', 'id'])->where('is_delete', 0)->first();
|
||||
|
||||
return $this->getResponse()->setData($query)->setCode(0)->send();
|
||||
}
|
||||
@ -41,9 +46,10 @@ class NewsService extends BaseService
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $limit = 10, int $page = 1): array
|
||||
public function index(int $limit = 30, int $page = 1): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at'])
|
||||
->where('is_delete', 0)
|
||||
->select(['id'])
|
||||
->orderBy('id', 'desc');;
|
||||
$pagination = $query->paginate($limit, page: $page);
|
||||
|
@ -14,9 +14,9 @@ use function Hyperf\Support\env;
|
||||
return [
|
||||
'default' => [
|
||||
'driver' => env('DB_DRIVER', 'mysql'),
|
||||
'host' => env('DB_HOST', '192.168.23.15'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', 3306),
|
||||
'database' => env('DB_DATABASE', 'seo'),
|
||||
'database' => env('DB_DATABASE', 'database'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', 'root'),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
|
@ -60,7 +60,7 @@ return [
|
||||
Constant::OPTION_BUFFER_OUTPUT_SIZE => 2 * 1024 * 1024,
|
||||
Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024, // 最大上传限制
|
||||
// 静态资源
|
||||
'document_root' => BASE_PATH . '/public',
|
||||
'document_root' => BASE_PATH,
|
||||
'enable_static_handler' => true,
|
||||
],
|
||||
'callbacks' => [
|
||||
|
@ -25,7 +25,12 @@
|
||||
{{-- <input type="checkbox" name="arr[2]" title="选项3">--}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排除的链接(我们自己做的)</label>
|
||||
<div class="layui-input-block">
|
||||
<textarea name="ignore_url" required lay-verify="required" 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="save">
|
||||
|
@ -1,19 +1,3 @@
|
||||
<?php
|
||||
$articleModule = array_map(fn($case) => [
|
||||
'label' => ucfirst($case->toString()),
|
||||
'value' => $case->value,
|
||||
], \App\Enums\ArticleModuleEnum::cases());
|
||||
|
||||
$articlePublishedStatus = array_map(fn($case) => [
|
||||
'label' => ucfirst($case->toString()),
|
||||
'value' => $case->value,
|
||||
], \App\Enums\ArticlePublishedStatusEnum::cases());
|
||||
|
||||
$articleLocation = array_map(fn($case) => [
|
||||
'label' => ucfirst($case->toString()),
|
||||
'value' => $case->value,
|
||||
], \App\Enums\LocationEnum::cases());
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
@ -32,7 +16,7 @@ $articleLocation = array_map(fn($case) => [
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">文章标题</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="mobile" value="" class="layui-input">
|
||||
<input type="text" name="title" value="" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -98,8 +82,6 @@ $articleLocation = array_map(fn($case) => [
|
||||
|
||||
// 相关常量
|
||||
const PRIMARY_KEY = "id";
|
||||
const UPDATE_API = "/admin/update";
|
||||
const DELETE_API = "/admin/delete";
|
||||
|
||||
// ----------------------
|
||||
const UPDATE_URL = "/articles/update";
|
||||
@ -115,6 +97,7 @@ $articleLocation = array_map(fn($case) => [
|
||||
const VIEW_API = "/admin/news/view";
|
||||
const INSERT_API = "/admin/api/news/insert";
|
||||
const INSERT_URL = "/admin/news/insert";
|
||||
const DELETE_API = "/admin/api/news/delete";
|
||||
|
||||
// 字段 创建时间 created_at
|
||||
layui.use(["laydate"], function () {
|
||||
@ -198,41 +181,7 @@ $articleLocation = array_map(fn($case) => [
|
||||
edit(obj);
|
||||
}
|
||||
if (obj.event === "delete") {
|
||||
alert('未生效');
|
||||
} else if (obj.event === "publish") {
|
||||
console.log(obj.data.aid)
|
||||
layer.confirm('确定发布吗?', function (index) {
|
||||
// obj.del(); // 删除对应行(tr)的 DOM 结构,并更新缓存
|
||||
// layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
url: PUBLISH_API,
|
||||
data: {
|
||||
aid: obj.data.aid
|
||||
},
|
||||
dataType: "json",
|
||||
type: "post",
|
||||
success: (res) => {
|
||||
layer.close(index);
|
||||
if (res.code) {
|
||||
return layui.popup.failure(res.msg);
|
||||
}
|
||||
return layui.popup.success("操作成功", refreshTable);
|
||||
},
|
||||
error: function () {
|
||||
return layui.popup.failure("操作失败");
|
||||
},
|
||||
complete: function () {
|
||||
layer.close(loading);
|
||||
}
|
||||
})
|
||||
// 向后端发送删除请求,执行完毕后,可通过 reloadData 方法完成数据重载
|
||||
/*
|
||||
table.reloadData(id, {
|
||||
scrollPos: 'fixed' // 保持滚动条位置不变 - v2.7.3 新增
|
||||
});
|
||||
*/
|
||||
});
|
||||
deleteNews(obj);
|
||||
}
|
||||
});
|
||||
|
||||
@ -300,36 +249,22 @@ $articleLocation = array_map(fn($case) => [
|
||||
});
|
||||
}
|
||||
|
||||
// 删除一行
|
||||
let remove = function (obj) {
|
||||
return doRemove(obj.data[PRIMARY_KEY]);
|
||||
}
|
||||
|
||||
// 删除多行
|
||||
let batchRemove = function (obj) {
|
||||
let checkIds = common.checkField(obj, PRIMARY_KEY);
|
||||
if (checkIds === "") {
|
||||
layui.popup.warning("未选中数据");
|
||||
return false;
|
||||
}
|
||||
doRemove(checkIds.split(","));
|
||||
}
|
||||
|
||||
// 执行删除
|
||||
let doRemove = function (ids) {
|
||||
let data = {};
|
||||
data[PRIMARY_KEY] = ids;
|
||||
let deleteNews = function (obj) {
|
||||
console.log(obj)
|
||||
layer.confirm("确定删除?", {
|
||||
icon: 3,
|
||||
title: "提示"
|
||||
}, function (index) {
|
||||
layer.close(index);
|
||||
let loading = layer.load();
|
||||
$.ajax({
|
||||
layui.$.ajax({
|
||||
url: DELETE_API,
|
||||
data: data,
|
||||
dataType: "json",
|
||||
type: "post",
|
||||
type: "POST",
|
||||
dateType: "json",
|
||||
data: {
|
||||
id: obj.data.id
|
||||
},
|
||||
success: function (res) {
|
||||
layer.close(loading);
|
||||
if (res.code) {
|
||||
|
Reference in New Issue
Block a user