限制初始密码强制范围并修复后台图片加载

This commit is contained in:
yml
2026-06-18 15:44:41 +08:00
parent 35f2d93fdf
commit 275663c4ea
6 changed files with 73 additions and 8 deletions
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { onBeforeUnmount, ref, watch } from 'vue'
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { fetchAdminFileBlob, fetchFileBlobByURL } from '@/shared/api/files'
import { isAdminPath } from '@/shared/utils/adminPath'
const props = defineProps<{
source: string
@@ -9,6 +10,7 @@ const props = defineProps<{
const objectURL = ref('')
const failed = ref(false)
const effectiveAdmin = computed(() => props.admin || isAdminPath(window.location.pathname))
function extractObjectKey(value: string) {
try {
@@ -35,7 +37,9 @@ async function loadImage() {
try {
const key = extractObjectKey(props.source)
const blob =
props.admin && key ? await fetchAdminFileBlob(key) : await fetchFileBlobByURL(props.source)
effectiveAdmin.value && key
? await fetchAdminFileBlob(key)
: await fetchFileBlobByURL(props.source)
objectURL.value = URL.createObjectURL(blob)
} catch {
failed.value = true
@@ -47,7 +51,7 @@ function openImage() {
window.open(objectURL.value, '_blank')
}
watch(() => [props.source, props.admin] as const, loadImage, { immediate: true })
watch(() => [props.source, effectiveAdmin.value] as const, loadImage, { immediate: true })
onBeforeUnmount(revokeCurrentURL)
</script>
+4 -1
View File
@@ -47,6 +47,9 @@ const passwordForm = reactive({
new_password: '',
confirm_password: '',
})
const shouldForcePasswordChange = computed(
() => adminSession.passwordMustChange && adminSession.isSuperAdmin
)
interface NavItem {
label: string
@@ -394,7 +397,7 @@ async function handleForcedPasswordChange() {
</section>
<el-dialog
:model-value="adminSession.passwordMustChange"
:model-value="shouldForcePasswordChange"
title="修改初始密码"
width="420px"
:close-on-click-modal="false"
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, ref, watch } from 'vue'
import { fetchAdminFileBlob, fetchFileBlobByURL } from '@/shared/api/files'
import { isAdminPath } from '@/shared/utils/adminPath'
const props = withDefaults(
defineProps<{
@@ -33,6 +34,7 @@ const failed = ref(false)
const createdURLs: string[] = []
const usePreview = computed(() => !!props.previewSrcList?.length)
const effectiveAdmin = computed(() => props.admin || isAdminPath(window.location.pathname))
const fallbackText = computed(() => (failed.value ? '图片加载失败' : '图片加载中'))
const imageStyleValue = computed(() => {
if (!props.fit) return props.imageStyle
@@ -52,18 +54,22 @@ function shouldFetchWithAuth(value: string) {
return value.includes('/api/files/object') || value.includes('/api/admin/files/object')
}
function shouldFetchAsAdmin(value: string) {
return effectiveAdmin.value || value.includes('/api/admin/files/object')
}
async function resolveURL(url: string): Promise<string> {
if (!url || !shouldFetchWithAuth(url)) return url
const key = extractObjectKey(url)
const blob =
props.admin && key ? await fetchAdminFileBlob(key) : await fetchFileBlobByURL(url)
shouldFetchAsAdmin(url) && key ? await fetchAdminFileBlob(key) : await fetchFileBlobByURL(url)
const blobURL = URL.createObjectURL(blob)
createdURLs.push(blobURL)
return blobURL
}
function cleanup() {
createdURLs.forEach((u) => URL.revokeObjectURL(u))
createdURLs.forEach(u => URL.revokeObjectURL(u))
createdURLs.length = 0
}
@@ -88,7 +94,7 @@ async function loadImage() {
}
}
watch(() => [props.source, props.admin, props.previewSrcList] as const, loadImage, {
watch(() => [props.source, effectiveAdmin.value, props.previewSrcList] as const, loadImage, {
immediate: true,
deep: true,
})