diff --git a/app/Http/Controllers/Api/FileController.php b/app/Http/Controllers/Api/FileController.php index 37cfa50b2..858499daa 100755 --- a/app/Http/Controllers/Api/FileController.php +++ b/app/Http/Controllers/Api/FileController.php @@ -525,7 +525,8 @@ class FileController extends AbstractController Base::makeDir(public_path($tmpPath)); $tmpPath .= md5($text) . "." . $matchs[1][$key]; if (file_put_contents(public_path($tmpPath), base64_decode($text))) { - $data['content'] = str_replace($matchs[0][$key], 'ext)); } + + /** + * 宽 + * @return int + */ + public function getWidthAttribute() + { + $this->generateSizeData(); + return $this->appendattrs['width']; + } + + /** + * 高 + * @return int + */ + public function getHeightAttribute() + { + $this->generateSizeData(); + return $this->appendattrs['height']; + } + + /** + * 生成尺寸数据 + */ + private function generateSizeData() + { + if (!isset($this->appendattrs['width'])) { + $width = -1; + $height = -1; + if (in_array($this->ext, ['jpg', 'jpeg', 'gif', 'png'])) { + $path = public_path($this->getRawOriginal('path')); + [$width, $height] = Cache::remember("File::size-" . md5($path), now()->addDays(7), function () use ($path) { + $width = -1; + $height = -1; + if (file_exists($path)) { + $paramet = getimagesize($path); + $width = $paramet[0]; + $height = $paramet[1]; + } + return [$width, $height]; + }); + } + $this->appendattrs['width'] = $width; + $this->appendattrs['height'] = $height; + } + } } diff --git a/resources/assets/js/components/PreviewImage/components/swipe.vue b/resources/assets/js/components/PreviewImage/components/swipe.vue index 2515dec70..3c9150195 100644 --- a/resources/assets/js/components/PreviewImage/components/swipe.vue +++ b/resources/assets/js/components/PreviewImage/components/swipe.vue @@ -54,7 +54,10 @@ export default { if (item.src) { item.src = $A.rightDelete(item.src, "_thumb.jpg"); } - return item + if (parseInt(item.width) > 0 && parseInt(item.height) > 0) { + return item + } + item = item.src; } return { html: `
`, diff --git a/resources/assets/js/components/TEditor.vue b/resources/assets/js/components/TEditor.vue index d0457e28a..b8f4c7907 100755 --- a/resources/assets/js/components/TEditor.vue +++ b/resources/assets/js/components/TEditor.vue @@ -508,15 +508,23 @@ }, getValueImages() { - let imgs = []; - let imgReg = /|\/>)/gi; - let srcReg = /src=['"]?([^'"]*)['"]?/i; - let array = (this.getContent() + "").match(imgReg); + const imgs = []; + const imgReg = /|\/>)/gi, + srcReg = new RegExp("src=([\"'])([^'\"]*)\\1"), + widthReg = new RegExp("original-width=\"(\\d+)\""), + heightReg = new RegExp("original-height=\"(\\d+)\"") + const array = (this.getContent() + "").match(imgReg); if (array) { for (let i = 0; i < array.length; i++) { - let src = array[i].match(srcReg); - if(src[1]){ - imgs.push(src[1]); + const src = array[i].match(srcReg); + const width = array[i].match(widthReg); + const height = array[i].match(heightReg); + if(src){ + imgs.push({ + src: src[2], + width: width ? width[1] : -1, + height: height ? height[1] : -1, + }); } } } diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 33d47d951..98900f33c 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -530,18 +530,18 @@ export default { const array = text.match(new RegExp(`]*?>`, "g")); const list = []; if (array) { - const srcReg = new RegExp("src=\"(.*?)\""), + const srcReg = new RegExp("src=([\"'])([^'\"]*)\\1"), widthReg = new RegExp("(original-)?width=\"(\\d+)\""), heightReg = new RegExp("(original-)?height=\"(\\d+)\"") array.some(res => { const srcMatch = res.match(srcReg), widthMatch = res.match(widthReg), heightMatch = res.match(heightReg); - if (srcMatch && widthMatch && heightMatch) { + if (srcMatch) { list.push({ - src: srcMatch[1].replace(/\{\{RemoteURL\}\}/g, baseUrl), - width: widthMatch[2], - height: heightMatch[2], + src: srcMatch[2].replace(/\{\{RemoteURL\}\}/g, baseUrl), + width: widthMatch ? widthMatch[2] : -1, + height: heightMatch ? heightMatch[2] : -1, }) } }) diff --git a/resources/assets/js/pages/manage/components/TaskDetail.vue b/resources/assets/js/pages/manage/components/TaskDetail.vue index f34e6c1d3..2417d141b 100644 --- a/resources/assets/js/pages/manage/components/TaskDetail.vue +++ b/resources/assets/js/pages/manage/components/TaskDetail.vue @@ -1269,10 +1269,20 @@ export default { const index = list.findIndex(item => item.id === file.id); if (index > -1) { this.$store.state.previewImageIndex = index; - this.$store.state.previewImageList = list.map(({path}) => path); + this.$store.state.previewImageList = list.map(item => { + return { + src: item.path, + width: item.width, + height: item.height, + } + }); } else { this.$store.state.previewImageIndex = 0; - this.$store.state.previewImageList = [file.path]; + this.$store.state.previewImageList = [{ + src: file.path, + width: file.width, + height: file.height, + }]; } return }