update:更新部分组件
This commit is contained in:
parent
3fb55deaaf
commit
3a2689db18
10
catch/permissions/excel/UserExport.php
Normal file
10
catch/permissions/excel/UserExport.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
@ -51,14 +51,14 @@ class CatchUpload
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* upload files
|
* upload files
|
||||||
*
|
*
|
||||||
* @param UploadedFile $file
|
* @param UploadedFile $file
|
||||||
* @return string
|
* @return string
|
||||||
* @author JaguarJack
|
* @author JaguarJack
|
||||||
* @email njphper@gmail.com
|
* @email njphper@gmail.com
|
||||||
* @time 2020/1/25
|
* @time 2020/1/25
|
||||||
*/
|
*/
|
||||||
public function upload(UploadedFile $file): string
|
public function upload(UploadedFile $file): string
|
||||||
{
|
{
|
||||||
$this->initUploadConfig();
|
$this->initUploadConfig();
|
||||||
@ -186,12 +186,12 @@ class CatchUpload
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2020年01月25日
|
* @time 2020年01月25日
|
||||||
* @param UploadedFile $file
|
* @param UploadedFile $file
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function data(UploadedFile $file)
|
protected function data(UploadedFile $file)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -142,4 +142,16 @@ class Utils
|
|||||||
{
|
{
|
||||||
return Config::where('key', $key)->value('value');
|
return Config::where('key', $key)->value('value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* public path
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* @time 2020年09月08日
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function publicPath($path = '')
|
||||||
|
{
|
||||||
|
return root_path($path ? 'public/'. $path : 'public');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ class CatchRequest extends Request
|
|||||||
// 设置默认参数
|
// 设置默认参数
|
||||||
if ($this->needCreatorId) {
|
if ($this->needCreatorId) {
|
||||||
$this->param['creator_id'] = $this->user()->id;
|
$this->param['creator_id'] = $this->user()->id;
|
||||||
$this->post['creator'] = $this->user()->id;
|
$this->post['creator_id'] = $this->user()->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -3,10 +3,12 @@ namespace catcher\library\excel;
|
|||||||
|
|
||||||
use catcher\CatchUpload;
|
use catcher\CatchUpload;
|
||||||
use catcher\exceptions\FailedException;
|
use catcher\exceptions\FailedException;
|
||||||
|
use catcher\Utils;
|
||||||
use PhpOffice\PhpSpreadsheet\Exception;
|
use PhpOffice\PhpSpreadsheet\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
use think\file\UploadedFile;
|
use think\file\UploadedFile;
|
||||||
|
use think\helper\Str;
|
||||||
|
|
||||||
class Excel
|
class Excel
|
||||||
{
|
{
|
||||||
@ -21,35 +23,54 @@ class Excel
|
|||||||
|
|
||||||
protected $spreadsheet = null;
|
protected $spreadsheet = null;
|
||||||
|
|
||||||
|
protected $extension = 'xlsx';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* save
|
* save
|
||||||
*
|
*
|
||||||
* @time 2020年05月25日
|
* @time 2020年05月25日
|
||||||
* @param ExcelContract $excel
|
* @param ExcelContract $excel
|
||||||
* @param $path
|
* @param $path
|
||||||
* @param null $disk
|
* @param string $disk
|
||||||
* @return bool
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function save(ExcelContract $excel, $path, $disk = null)
|
public function save(ExcelContract $excel, $path, $disk = 'local')
|
||||||
{
|
{
|
||||||
$this->excel = $excel;
|
$this->excel = $excel;
|
||||||
|
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
Factory::make(pathinfo($path, PATHINFO_EXTENSION))
|
!is_dir($path) && mkdir($path, 0777, true);
|
||||||
->setSpreadsheet($this->spreadsheet)
|
|
||||||
->save($path);
|
|
||||||
|
|
||||||
if (!file_exists($path)) {
|
$file = $path . date('YmdHis').Str::random(6) . '.' .$this->extension;
|
||||||
throw new FailedException($path . ' generate failed');
|
Factory::make($this->extension)
|
||||||
|
->setSpreadsheet($this->spreadsheet)
|
||||||
|
->save($file);
|
||||||
|
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
throw new FailedException($file . ' generate failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($disk) {
|
if ($disk) {
|
||||||
$path = $this->upload($disk, $path);
|
$file = $this->upload($disk, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $path;
|
return ['url' => $file];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set extension
|
||||||
|
*
|
||||||
|
* @time 2020年09月08日
|
||||||
|
* @param $extension
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setExtension($extension)
|
||||||
|
{
|
||||||
|
$this->extension = $extension;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -219,11 +240,27 @@ class Excel
|
|||||||
*/
|
*/
|
||||||
protected function upload($disk, $path)
|
protected function upload($disk, $path)
|
||||||
{
|
{
|
||||||
|
if ($disk == 'local') {
|
||||||
|
return $this->local($path);
|
||||||
|
}
|
||||||
$upload = new CatchUpload;
|
$upload = new CatchUpload;
|
||||||
|
|
||||||
return ($disk ? $upload->setDriver($disk) : $upload)->upload($this->uploadedFile($path));
|
return ($disk ? $upload->setDriver($disk) : $upload)->upload($this->uploadedFile($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回本地下载地址
|
||||||
|
*
|
||||||
|
* @param $path
|
||||||
|
* @time 2020年09月08日
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function local($path)
|
||||||
|
{
|
||||||
|
return \config('filesystem.disks.local')['domain'] . '/' .
|
||||||
|
|
||||||
|
str_replace('\\', '/', str_replace(Utils::publicPath(), '', $path));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get uploaded file
|
* get uploaded file
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace catcher\middlewares;
|
namespace catcher\middlewares;
|
||||||
|
|
||||||
use catcher\exceptions\FailedException;
|
|
||||||
use catcher\exceptions\PermissionForbiddenException;
|
|
||||||
use think\Middleware;
|
use think\Middleware;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user