修复会议图片不显示,优化file.ts文件
This commit is contained in:
1 parent
69f17ad249
commit
c9ff397591
3 files changed
+40
-6
No files matched your search
@@ -10,7 +10,7 @@
|
||||
|
||||
<!-- 会议室信息 -->
|
||||
<view class="room-info-box">
|
||||
<image :src="room.img" class="room-img" mode="aspectFill"></image>
|
||||
<image :src="roomImage" class="room-img" mode="aspectFill" />
|
||||
<view class="room-info-main">
|
||||
<view class="room-title">{{ room.name }} <text class="room-capacity">{{ room.capacity }}人</text></view>
|
||||
<view class="room-address"><text>📍</text> {{ room.address }}</view>
|
||||
@@ -110,6 +110,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import meetingRoomApi from '@/sheep/api/meetingRoom'
|
||||
import { filePath } from '@/sheep/utils/file'
|
||||
|
||||
// 定义类型
|
||||
interface TimeSlotItem {
|
||||
@@ -147,6 +148,15 @@ const room = ref({
|
||||
img: '/static/meeting/room1.jpg'
|
||||
})
|
||||
|
||||
const roomImage = computed(() => {
|
||||
const raw = room.value.img || ''
|
||||
const fallback = '/static/meeting/default.jpg'
|
||||
if (!raw) return fallback
|
||||
if (raw.startsWith('/static/') || raw.startsWith('data:')) return raw
|
||||
const src = filePath(raw)
|
||||
return src || raw || fallback
|
||||
})
|
||||
|
||||
// 当前用户信息
|
||||
const currentUser = ref({
|
||||
name: '张三',
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<image :src="room.picUrl || '/static/icon/service_4.png'" class="room-img" mode="aspectFill"></image>
|
||||
<image :src="getRoomImage(room.picUrl)" class="room-img" mode="aspectFill" />
|
||||
</view>
|
||||
<!-- 时间条 -->
|
||||
<view class="timeline-bar">
|
||||
@@ -62,6 +62,7 @@
|
||||
import { ref, onMounted } from "vue"
|
||||
import meetingRoomApi from "@/sheep/api/meetingRoom"
|
||||
import MeetingTabbar from "@/sheep/components/MeetingTabbar.vue"
|
||||
import { filePath } from "@/sheep/utils/file"
|
||||
|
||||
const goBack = () => {
|
||||
uni.navigateBack()
|
||||
@@ -109,6 +110,11 @@ function goDetail(room) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function getRoomImage(picUrl: string) {
|
||||
const src = filePath(picUrl)
|
||||
return src || "/static/icon/service_4.png"
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
+22
-4
@@ -1,7 +1,25 @@
|
||||
import { isDevEnv } from "./app"
|
||||
|
||||
export const filePath = (path?: string) => {
|
||||
const imageBaseUrl = isDevEnv() ? import.meta.env.VITE_IMAGE_DEV_PATH : import.meta.env.VITE_APP_PROD_IMAGE
|
||||
if (!path) return ""
|
||||
return imageBaseUrl + path
|
||||
const normalizeBase = (base: string | undefined) => {
|
||||
if (!base) return ""
|
||||
return base.endsWith("/") ? base.slice(0, -1) : base
|
||||
}
|
||||
|
||||
const ensureLeadingSlash = (url: string) => {
|
||||
if (!url) return ""
|
||||
return url.startsWith("/") ? url : `/${url}`
|
||||
}
|
||||
|
||||
export const filePath = (path?: string | null) => {
|
||||
const rawPath = (path || "").trim()
|
||||
if (!rawPath) return ""
|
||||
if (/^https?:\/\//i.test(rawPath)) return rawPath
|
||||
|
||||
const devBase = normalizeBase(import.meta.env.VITE_IMAGE_DEV_PATH || import.meta.env.VITE_APP_DEV_SERVICE)
|
||||
const prodBase = normalizeBase(import.meta.env.VITE_APP_PROD_IMAGE)
|
||||
const base = isDevEnv() ? devBase : prodBase
|
||||
|
||||
if (!base) return rawPath
|
||||
|
||||
return `${base}${ensureLeadingSlash(rawPath)}`
|
||||
}
|
||||
Reference in new issue
Block a user