作者 开飞机的舒克

大屏接口优化

... ... @@ -171,44 +171,13 @@ class Study extends Backend
}
}
public function qiniu($filePath = '', $fileName = '')
public function chang_down()
{
// $filePath=ROOT_PATH.'public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg';//文件路径
// $fileName='public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg'; //七牛云上的名字
// $filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg';//文件路径
// $fileName = 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg'; //七牛云上的名字,头部不带杠
$config = get_addon_config('qiniu');
$policy = array(
'saveKey' => $fileName,
);
$auth = new \Qiniu\Auth($config['accessKey'], $config['secretKey']);
$token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy);
$multipart = [
['name' => 'token', 'contents' => $token],
[
'name' => 'file',
'contents' => fopen($filePath, 'r'),
'filename' => $fileName,
]
];
try {
$client = new Client();
$res = $client->request('POST', $config['uploadurl'], [
'multipart' => $multipart
]);
$code = $res->getStatusCode();
//成功不做任何操作
} catch (\GuzzleHttp\Exception\ClientException $e) {
// unlink($filePath);
$this->error("上传失败");
$id = input('id');
$res = \app\admin\model\Study::where('id', $id)->update(['grade_id' => 1]);
if ($res !== false) {
$this->success('');
}
// dump($code);
// $url = '/';
//上传成功后将存储变更为qiniu
// $this->success("上传成功", ['url' => cdnurl($url), 'save_path' => $url]);
}
/**
... ...
... ... @@ -109,13 +109,16 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
icon: 'fa fa-leaf',
// dropdown: '更多',//如果包含dropdown,将会以下拉列表的形式展示
click: function (e, data) {
$.ajax({
type: 'get',
url: 'study/chang_down',
data: {id: data.id},
success: function (res) {
if (res.code === 1) {
var domain = 'http://campus.cn/';
var url = domain + data.barcode_images;
var domain = window.location.href.split(':')[0] + '://' + document.domain;
var url = domain + data.barcode;
alert(url);
var link = document.createElement('a');
link.setAttribute("download", "");
link.href = url;
... ...