Commit 61308a40 by cen

fix: oss处理

1 parent 7b268dcd
......@@ -9,7 +9,7 @@
<view :class="['popup-body', { 'has-ai': AIUrl }]">
<video ref="videoPlayer" :src="detailUrl" controls v-if="sourceType == 2"></video>
<view class="img-detail" v-else>
<image @click="back" :src="detailUrl" mode="heightFix" />
<image @click="back" :src="imagePreviewUrl" mode="heightFix" />
</view>
</view>
<view class="AI-window" v-if="AIUrl">
......@@ -20,6 +20,7 @@
</template>
<script type="text/ecmascript-6">
import { aiUrlMixin, report } from '@/mixin/index.js'
import { getImageDisplayUrl } from '@/utils/ossImageProcess.js'
export default {
mixins: [report, aiUrlMixin],
......@@ -53,6 +54,10 @@ export default {
if (this.isComponents) status = this.show
return status
},
imagePreviewUrl () {
// 仅图片回显拼接 OSS 参数展示,视频保持原始 URL
return getImageDisplayUrl(this.detailUrl)
}
},
onLoad (options) {
this.init(options)
......
......@@ -147,7 +147,6 @@ import OrderPopup from '@/components/OrderPopup/index.vue'
import SelectCar from './components/SelectCar.vue'
import FormCell from './components/FormCell.vue'
import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { appendImageOssProcess } from '@/utils/ossImageProcess.js'
import SelectCity from './components/SelectCity.vue'
import UploadMedia from './components/uploadMedia.vue'
import NoticePopup from '@/components/NoticePopup.vue'
......@@ -1236,7 +1235,6 @@ export default {
// 上传所有选择的图片
for (const tempFilePath of res.tempFilePaths) {
let url = await uploadFile(tempFilePath)
url = appendImageOssProcess(url)
console.log('上传图片成功', url)
this[type](url)
}
......@@ -1265,7 +1263,6 @@ export default {
// 上传所有选择的图片
for (const tempFilePath of res.tempFilePaths) {
let url = await uploadFile(tempFilePath)
url = appendImageOssProcess(url)
console.log('上传图片成功', url)
this[type](url)
}
......
......@@ -37,7 +37,7 @@
<script>
// import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { uploadFile } from '@/utils/ossUpload.js'
import { appendImageOssProcess, getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import { getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import permision from '@/js_sdk/wa-permission/permission.js'
export default {
......@@ -156,7 +156,6 @@ export default {
// 上传所有选择的图片
for (let i = 0; i < res.tempFilePaths.length; i++) {
let url = await uploadFile(res.tempFiles[i], res.tempFilePaths[i])
url = appendImageOssProcess(url)
uni.hideLoading()
......@@ -198,7 +197,6 @@ export default {
// 上传所有选择的图片
for (let i = 0; i < res.tempFilePaths.length; i++) {
let url = await uploadFile(res.tempFiles[i], res.tempFilePaths[i])
url = appendImageOssProcess(url)
console.log('上传图片成功', url)
uni.hideLoading()
// const fileExtension = res.tempFiles[0]?.name ? res.tempFiles[0]?.name.split('.').pop().toLowerCase() : res.tempFiles[0]?.path.split('.').pop().toLowerCase()
......
......@@ -119,7 +119,7 @@
<script>
// import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { uploadFile } from '@/utils/ossUpload.js'
import { appendImageOssProcess, getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import { getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import FormCell from './components/FormCell.vue'
import GeneralPopup from './components/GeneralPopup.vue'
import OrderPopup from '@/components/OrderPopup/index.vue'
......@@ -671,8 +671,8 @@ export default {
},
// 添加图片到对应的数组中(确保响应式更新)
addImage(field, url) {
// 图片追加 OSS 处理参数,视频不处理
const finalUrl = url.includes(this.videoProcess) ? url : appendImageOssProcess(url)
// 上传完成后保持原始 URL;仅在回显/预览时拼接 OSS 处理参数展示
const finalUrl = url
// 添加新图片
if (!Array.isArray(this.uploadedImages[field.key])) {
this.$set(this.uploadedImages, field.key, [])
......
......@@ -373,7 +373,7 @@ import FormCell from './components/FormCell.vue'
import GeneralPopup from './components/GeneralPopup.vue'
// import { uploadFile } from '@/utils/ossUploadFile/uploadFile.js'
import { uploadFile } from '@/utils/ossUpload.js'
import { appendImageOssProcess, getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import { getImageDisplayUrl } from '@/utils/ossImageProcess.js'
import OrderPopup from '@/components/OrderPopup/index.vue'
import dayjs from 'dayjs'
import NoticePopup from '@/components/NoticePopup.vue'
......@@ -1416,8 +1416,8 @@ export default {
})
},
addMedia(field, media) {
const url = media.type === 'image' ? appendImageOssProcess(media.url) : media.url
this.$set(this.formData, field, url)
// 上传完成后保持原始 URL;仅在回显/预览时拼接 OSS 处理参数展示
this.$set(this.formData, field, media.url)
},
removeMedia(field) {
// 显示确认对话框
......
......@@ -13,14 +13,17 @@
{{ imgList.length }}/10
</view>
</template>
<template v-for="(i, index) in imgList">
<view class="img-item" :key="index">
<image :src="i" class="img" mode="aspectFill" @click="previewMedia(i, 1)" />
<view class="del flex">
<uni-icons type="closeempty" :size="10" color="#fff" @click="delImage(index)"></uni-icons>
</view>
<view
class="img-item"
v-for="(i, index) in imgList"
:key="index"
>
<!-- 缩略图展示时为图片拼接 OSS 预览参数,存储与提交依然使用原始 URL -->
<image :src="getImageDisplayUrl(i)" class="img" mode="aspectFill" @click="previewMedia(i, 1)" />
<view class="del flex">
<uni-icons type="closeempty" :size="10" color="#fff" @click="delImage(index)"></uni-icons>
</view>
</template>
</view>
</view>
<view class="img-tips">单个文件不超过10M,最多可上传10张。</view>
</view>
......@@ -46,6 +49,7 @@
<script type="text/ecmascript-6">
import { uploadFile } from '@/utils/ossUpload.js'
import permision from '@/js_sdk/wa-permission/permission.js'
import { getImageDisplayUrl as rawGetImageDisplayUrl } from '@/utils/ossImageProcess.js'
const MAX_IMAGE_SIZE = 10 * 1024 * 1024, // 图片最大10MB
MAX_IMG_COUNT = 10 // 最大图片数量
export default {
......@@ -68,6 +72,9 @@ export default {
mounted() {
},
methods: {
getImageDisplayUrl(url) {
return rawGetImageDisplayUrl(url)
},
delImage(index) {
this.imgList.splice(index, 1)
},
......
<template>
<view class="step-3">
<view class="upload-box box">
<view class="title">
交付照片
</view>
<view class="title">交付照片</view>
<view class="img-list flex">
<template v-for="(i, index) in detail.imgList">
<view
class="img-item"
:key="index"
>
<image
:src="i"
class="img"
mode="aspectFill"
@click="previewMedia(i, 1)"
/>
<view class="img-item" :key="index">
<image :src="getImageDisplayUrl(i)" class="img" mode="aspectFill" @click="previewMedia(i, 1)" />
</view>
</template>
</view>
......@@ -30,7 +20,7 @@
<view class="sprite-icon icon-delivery-step-2"></view>
<view class="info">
客户提车确认
<view class="des">提车时间:{{detail.pickUpTime}}</view>
<view class="des">提车时间:{{ detail.pickUpTime }}</view>
</view>
<view class="btn flex">已提车</view>
</view>
......@@ -38,6 +28,7 @@
</template>
<script type="text/ecmascript-6">
import { getImageDisplayUrl as rawGetImageDisplayUrl } from '@/utils/ossImageProcess.js'
export default {
name: '',
props: {
......@@ -56,6 +47,9 @@ export default {
mounted () {
},
methods: {
getImageDisplayUrl (url) {
return rawGetImageDisplayUrl(url)
},
previewMedia (media, type) {
const url = `/pages/boutique/preview?tabName=预览&sourceType=${type}&detailUrl=${media}`
uni.navigateTo({
......
......@@ -2,7 +2,7 @@
* OSS 图片处理参数
* 用于上传图片返回地址及详情/编辑回显时的图片展示
*/
export const IMAGE_OSS_PROCESS = 'x-oss-process=image/format,jpg/quality,q_100'
const IMAGE_OSS_PROCESS = 'x-oss-process=image/format,jpg/quality,q_100'
const VIDEO_EXTENSIONS = ['.mp4', '.mov', '.avi', '.wmv', '.flv', '.m4v', '.3gp', '.mkv', '.webm']
const VIDEO_OSS_SNAPSHOT = 'x-oss-process=video/snapshot'
......@@ -12,7 +12,7 @@ const VIDEO_OSS_SNAPSHOT = 'x-oss-process=video/snapshot'
* @param {string} url - 媒体 URL
* @returns {boolean}
*/
export function isVideoUrl(url) {
function isVideoUrl(url) {
if (!url || typeof url !== 'string') return false
if (url.includes(VIDEO_OSS_SNAPSHOT)) return true
const urlLower = url.toLowerCase()
......@@ -25,7 +25,7 @@ export function isVideoUrl(url) {
* @param {string} url - 原始 URL
* @returns {string} 带处理参数的 URL
*/
export function appendImageOssProcess(url) {
function appendImageOssProcess(url) {
if (!url || typeof url !== 'string') return url || ''
if (isVideoUrl(url)) return url
if (url.includes(IMAGE_OSS_PROCESS)) return url
......@@ -40,9 +40,16 @@ export function appendImageOssProcess(url) {
* @param {boolean} [isImageType] - 已知为图片类型时可传 true,跳过视频判断
* @returns {string}
*/
export function getImageDisplayUrl(url, isImageType = false) {
function getImageDisplayUrl(url, isImageType = false) {
if (!url || typeof url !== 'string') return url || ''
if (isImageType) return appendImageOssProcess(url)
if (isVideoUrl(url)) return url
return appendImageOssProcess(url)
}
module.exports = {
IMAGE_OSS_PROCESS,
isVideoUrl,
appendImageOssProcess,
getImageDisplayUrl
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!