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
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
* @return string
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/25
|
||||
*/
|
||||
* upload files
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
* @return string
|
||||
* @author JaguarJack
|
||||
* @email njphper@gmail.com
|
||||
* @time 2020/1/25
|
||||
*/
|
||||
public function upload(UploadedFile $file): string
|
||||
{
|
||||
$this->initUploadConfig();
|
||||
@ -186,12 +186,12 @@ class CatchUpload
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param UploadedFile $file
|
||||
* @return array
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @time 2020年01月25日
|
||||
* @param UploadedFile $file
|
||||
* @return array
|
||||
*/
|
||||
protected function data(UploadedFile $file)
|
||||
{
|
||||
return [
|
||||
|
@ -142,4 +142,16 @@ class Utils
|
||||
{
|
||||
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) {
|
||||
$this->param['creator_id'] = $this->user()->id;
|
||||
$this->post['creator'] = $this->user()->id;
|
||||
$this->post['creator_id'] = $this->user()->id;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -3,10 +3,12 @@ namespace catcher\library\excel;
|
||||
|
||||
use catcher\CatchUpload;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Utils;
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use think\file\UploadedFile;
|
||||
use think\helper\Str;
|
||||
|
||||
class Excel
|
||||
{
|
||||
@ -21,35 +23,54 @@ class Excel
|
||||
|
||||
protected $spreadsheet = null;
|
||||
|
||||
protected $extension = 'xlsx';
|
||||
|
||||
/**
|
||||
* save
|
||||
*
|
||||
* @time 2020年05月25日
|
||||
* @param ExcelContract $excel
|
||||
* @param $path
|
||||
* @param null $disk
|
||||
* @return bool
|
||||
* @param string $disk
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function save(ExcelContract $excel, $path, $disk = null)
|
||||
public function save(ExcelContract $excel, $path, $disk = 'local')
|
||||
{
|
||||
$this->excel = $excel;
|
||||
|
||||
$this->init();
|
||||
|
||||
Factory::make(pathinfo($path, PATHINFO_EXTENSION))
|
||||
->setSpreadsheet($this->spreadsheet)
|
||||
->save($path);
|
||||
!is_dir($path) && mkdir($path, 0777, true);
|
||||
|
||||
if (!file_exists($path)) {
|
||||
throw new FailedException($path . ' generate failed');
|
||||
$file = $path . date('YmdHis').Str::random(6) . '.' .$this->extension;
|
||||
Factory::make($this->extension)
|
||||
->setSpreadsheet($this->spreadsheet)
|
||||
->save($file);
|
||||
|
||||
if (!file_exists($file)) {
|
||||
throw new FailedException($file . ' generate failed');
|
||||
}
|
||||
|
||||
if ($disk) {
|
||||
$path = $this->upload($disk, $path);
|
||||
}
|
||||
if ($disk) {
|
||||
$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)
|
||||
{
|
||||
if ($disk == 'local') {
|
||||
return $this->local($path);
|
||||
}
|
||||
$upload = new CatchUpload;
|
||||
|
||||
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
|
||||
|
@ -20,8 +20,6 @@
|
||||
// +----------------------------------------------------------------------
|
||||
namespace catcher\middlewares;
|
||||
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\exceptions\PermissionForbiddenException;
|
||||
use think\Middleware;
|
||||
use think\Request;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user