Skip to content

Commit

Permalink
perf: 文件查看图片直接弹窗浏览
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Mar 31, 2022
1 parent ce03296 commit dde2813
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/Http/Controllers/Api/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function lists()
}
}
}
// 图片直接返回预览地址
foreach ($array as &$item) {
File::handleImageUrl($item);
}
return Base::retSuccess('success', $array);
}

Expand Down Expand Up @@ -757,6 +761,7 @@ public function content__upload()
//
$data = $tmpRow->toArray();
$data['full_name'] = $webkitRelativePath ?: $data['name'];
File::handleImageUrl($data);
return Base::retSuccess($data['name'] . ' 上传成功', $data);
});
}
Expand Down
22 changes: 22 additions & 0 deletions app/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class File extends AbstractModel
'ppt', 'pptx',
];

/**
* 图片文件
*/
const imageExt = [
'jpg', 'jpeg', 'png', 'gif', 'bmp'
];

/**
* 本地媒体文件
*/
Expand Down Expand Up @@ -285,6 +292,21 @@ public function pushMsg($action, $data = null, $userid = null)
Task::deliver($task);
}

/**
* 处理返回图片地址
* @param $item
* @return void
*/
public static function handleImageUrl(&$item)
{
if (in_array($item['ext'], self::imageExt) ) {
$content = Base::json2array(FileContent::whereFid($item['id'])->orderByDesc('id')->value('content'));
if ($content) {
$item['image_url'] = Base::fillUrl($content['url']);
}
}
}

/**
* 获取文件并检测权限
* @param $id
Expand Down
17 changes: 14 additions & 3 deletions resources/assets/js/pages/manage/file.vue
Original file line number Diff line number Diff line change
Expand Up @@ -880,12 +880,23 @@ export default {
this.searchKey = '';
this.pid = item.id;
} else {
// 图片直接浏览
if (item.image_url) {
const list = this.fileList.filter(({image_url}) => !!image_url)
if (list.length > 0) {
this.$store.state.previewImageIndex = list.findIndex(({id}) => item.id === id);
this.$store.state.previewImageList = list.map(item => item.image_url);
return;
}
}
// 客户端打开独立窗口
if (this.$Electron) {
this.openSingle(item);
} else {
this.fileInfo = item;
this.fileShow = true;
return;
}
// 正常显示弹窗
this.fileInfo = item;
this.fileShow = true;
}
},
Expand Down

0 comments on commit dde2813

Please sign in to comment.