Commit e40384a5 by 汪伟伟

封装imges

parent 6ba13c1f
...@@ -5,6 +5,7 @@ namespace App\Admin\Controllers; ...@@ -5,6 +5,7 @@ namespace App\Admin\Controllers;
use App\Admin\Extensions\Tools\BackAction; use App\Admin\Extensions\Tools\BackAction;
use App\Admin\Repositories\TasksReceive; use App\Admin\Repositories\TasksReceive;
use App\Admin\Services\CityAreaService; use App\Admin\Services\CityAreaService;
use App\Admin\Services\TaskService;
use App\Models\Task; use App\Models\Task;
use App\Models\TasksCollect; use App\Models\TasksCollect;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
...@@ -340,24 +341,8 @@ class AlreadyDoneTaskController extends AdminController ...@@ -340,24 +341,8 @@ class AlreadyDoneTaskController extends AdminController
// }); // });
//保存后回调 //保存后回调
$form->saved(function (Form $form) { $form->saved(function (Form $form) {
$start = 'src="'; $images = TaskService::getImagesFromStr($form->input('collects.net_img'));
$end = '" alt';
ini_set('pcre.backtrack_limit', '2097152');
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
preg_match_all($pattern, $form->input('collects.net_img'), $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
TasksCollect::query()->where('receive_id', $this->id)->update(['images' => $images]);//更新 TasksCollect::query()->where('receive_id', $this->id)->update(['images' => $images]);//更新
\App\Models\TasksReceive::query()->where('id', $this->id)->update(['time'=>date('Y-m-d H:i:s')]);//更新完成时间 \App\Models\TasksReceive::query()->where('id', $this->id)->update(['time'=>date('Y-m-d H:i:s')]);//更新完成时间
}); });
......
...@@ -6,6 +6,7 @@ use App\Admin\Extensions\Tools\BackAction; ...@@ -6,6 +6,7 @@ use App\Admin\Extensions\Tools\BackAction;
use App\Admin\Repositories\Tas; use App\Admin\Repositories\Tas;
use App\Admin\Repositories\TasksReceive; use App\Admin\Repositories\TasksReceive;
use App\Admin\Services\CityAreaService; use App\Admin\Services\CityAreaService;
use App\Admin\Services\TaskService;
use App\Models\TasksApprove; use App\Models\TasksApprove;
use App\Models\TasksCollect; use App\Models\TasksCollect;
use Dcat\Admin\Actions\Action; use Dcat\Admin\Actions\Action;
...@@ -366,24 +367,9 @@ class NoDoneTaskController extends AdminController ...@@ -366,24 +367,9 @@ class NoDoneTaskController extends AdminController
// }); // });
//保存后回调 //保存后回调
$form->saved(function (Form $form) { $form->saved(function (Form $form) {
$start = 'src="';
$end = '" alt'; $images = TaskService::getImagesFromStr($form->input('collects.net_img'));
ini_set('pcre.backtrack_limit', '2097152');
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
preg_match_all($pattern, $form->input('collects.net_img'), $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
TasksCollect::query()->where('receive_id', $this->id)->update(['images' => $images]);//更新 TasksCollect::query()->where('receive_id', $this->id)->update(['images' => $images]);//更新
if ($this->status == 0) { if ($this->status == 0) {
......
...@@ -5,6 +5,7 @@ namespace App\Admin\Controllers; ...@@ -5,6 +5,7 @@ namespace App\Admin\Controllers;
use App\Admin\Extensions\Tools\ListAction; use App\Admin\Extensions\Tools\ListAction;
use App\Admin\Repositories\Tas; use App\Admin\Repositories\Tas;
use App\Admin\Services\CityAreaService; use App\Admin\Services\CityAreaService;
use App\Admin\Services\TaskService;
use App\Models\Task; use App\Models\Task;
use App\Models\TasksReceive; use App\Models\TasksReceive;
use Dcat\Admin\Actions\Action; use Dcat\Admin\Actions\Action;
...@@ -236,24 +237,8 @@ class TasController extends AdminController ...@@ -236,24 +237,8 @@ class TasController extends AdminController
// // 在表单提交前调用 // // 在表单提交前调用
$form->submitted(function (Form $form) { $form->submitted(function (Form $form) {
$start = 'src="'; $images = TaskService::getImagesFromStr($form->input('guide'));
$end = '" alt';
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
ini_set('pcre.backtrack_limit', '2097152');
preg_match_all($pattern, $form->input('guide'), $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
$form->images = $images; $form->images = $images;
//... //...
...@@ -302,24 +287,9 @@ class TasController extends AdminController ...@@ -302,24 +287,9 @@ class TasController extends AdminController
$param['city_id'] = explode(',', $city_id); $param['city_id'] = explode(',', $city_id);
$param['year'] = explode(',', $year); $param['year'] = explode(',', $year);
$start = 'src="'; $images = TaskService::getImagesFromStr($param['guide']);
$end = '" alt';
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
ini_set('pcre.backtrack_limit', '2097152');
preg_match_all($pattern, $param['guide'], $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
$form = Form::make(); $form = Form::make();
$insertData = []; $insertData = [];
foreach ($param['city_id'] as $city) { foreach ($param['city_id'] as $city) {
......
...@@ -7,6 +7,7 @@ use App\Admin\Extensions\Tools\ListAction; ...@@ -7,6 +7,7 @@ use App\Admin\Extensions\Tools\ListAction;
use App\Admin\Extensions\Tools\ReceiveAction; use App\Admin\Extensions\Tools\ReceiveAction;
use App\Admin\Repositories\Task; use App\Admin\Repositories\Task;
use App\Admin\Services\CityAreaService; use App\Admin\Services\CityAreaService;
use App\Admin\Services\TaskService;
use App\Models\TasksReceive; use App\Models\TasksReceive;
use Dcat\Admin\Admin; use Dcat\Admin\Admin;
use Dcat\Admin\Form; use Dcat\Admin\Form;
...@@ -331,24 +332,7 @@ class TaskController extends AdminController ...@@ -331,24 +332,7 @@ class TaskController extends AdminController
// // 在表单提交前调用 // // 在表单提交前调用
$form->submitted(function (Form $form) { $form->submitted(function (Form $form) {
$start = 'src="'; $images = TaskService::getImagesFromStr($form->input('guide'));
$end = '" alt';
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
ini_set('pcre.backtrack_limit', '2097152');
preg_match_all($pattern, $form->input('guide'), $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
$form->images = $images; $form->images = $images;
//... //...
...@@ -392,25 +376,8 @@ class TaskController extends AdminController ...@@ -392,25 +376,8 @@ class TaskController extends AdminController
// dd($request->input()); // dd($request->input());
$param = $request->input(); $param = $request->input();
$images = TaskService::getImagesFromStr($param['guide']);
$start = 'src="';
$end = '" alt';
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
ini_set('pcre.backtrack_limit', '2097152');
preg_match_all($pattern, $param['guide'], $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
$form = Form::make(); $form = Form::make();
foreach ($param['city_id'] as $city) { foreach ($param['city_id'] as $city) {
if ($city) { if ($city) {
......
<?php
namespace App\Admin\Services;
use Illuminate\Support\Facades\Storage;
class TaskService
{
public static function getImagesFromStr($guide):string
{
$start = 'src="';
$end = '" alt';
$pattern = '/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/';
ini_set('pcre.backtrack_limit', '2097152');
preg_match_all($pattern, $guide, $matches);
$images = '';
foreach ($matches[1] as $v) {
if (filter_var($v, FILTER_VALIDATE_URL) !== false) {//是链接
$images .= $v . ',';
} else {
// 去除Base64字符串开头的"data:"及其后面的逗号
$base64Data = substr($v, strpos($v, ',') + 1);
$path = '/tinymce/images/' . time() . uniqid() . '.png';
Storage::disk('admin')->put($path, base64_decode($base64Data));
$url = Storage::disk('admin')->url($path);
$images .= $url . ',';
}
}
return $images;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment