新增 阿拉伯语 和 俄语
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { service } from '@/utils/request'
|
||||
import type { ICommonResponse } from '@/types/common'
|
||||
|
||||
export interface IUploadResult {
|
||||
url: string
|
||||
}
|
||||
|
||||
export const uploadImage = (file: File) => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
|
||||
return service.post<ICommonResponse<IUploadResult>>('/upload', formData, {
|
||||
transformRequest: [
|
||||
(data, headers) => {
|
||||
if (data instanceof FormData && headers) {
|
||||
delete headers['Content-Type']
|
||||
}
|
||||
return data
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<template>
|
||||
<div class="thumbnail-field">
|
||||
<div v-if="modelValue" class="thumbnail-field__preview">
|
||||
<el-image
|
||||
:src="previewSrc"
|
||||
fit="cover"
|
||||
:preview-src-list="[previewSrc]"
|
||||
preview-teleported
|
||||
class="thumbnail-field__image"
|
||||
/>
|
||||
<el-button type="danger" link @click="clearThumbnail">移除</el-button>
|
||||
</div>
|
||||
|
||||
<div class="thumbnail-field__actions">
|
||||
<el-upload
|
||||
:show-file-list="false"
|
||||
accept="image/jpeg,image/png,image/gif,image/webp,image/avif"
|
||||
:http-request="handleUpload"
|
||||
:disabled="uploading"
|
||||
>
|
||||
<el-button :loading="uploading">{{ modelValue ? '重新上传' : '上传图片' }}</el-button>
|
||||
</el-upload>
|
||||
<el-input
|
||||
:model-value="modelValue"
|
||||
placeholder="或输入图片地址,如 /images/cases/case-1.png"
|
||||
@update:model-value="updateValue"
|
||||
/>
|
||||
<div class="thumbnail-field__tip">支持 JPG、PNG、GIF、WEBP、AVIF,大小不超过 5MB</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ElMessage, type UploadRequestOptions } from 'element-plus'
|
||||
import { uploadImage } from '@/api/upload'
|
||||
|
||||
defineOptions({ name: 'ThumbnailField' })
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: string
|
||||
}>()
|
||||
|
||||
const emits = defineEmits<{
|
||||
(e: 'update:modelValue', value: string): void
|
||||
}>()
|
||||
|
||||
const uploading = ref(false)
|
||||
|
||||
const previewSrc = computed(() => {
|
||||
const value = props.modelValue.trim()
|
||||
if (!value) return ''
|
||||
if (/^https?:\/\//i.test(value) || value.startsWith('/')) return value
|
||||
return `/${value.replace(/^\/+/, '')}`
|
||||
})
|
||||
|
||||
const updateValue = (value: string) => {
|
||||
emits('update:modelValue', value)
|
||||
}
|
||||
|
||||
const clearThumbnail = () => {
|
||||
emits('update:modelValue', '')
|
||||
}
|
||||
|
||||
const handleUpload = async (options: UploadRequestOptions) => {
|
||||
const file = options.file
|
||||
if (!(file instanceof File)) return
|
||||
|
||||
uploading.value = true
|
||||
try {
|
||||
const { data: res } = await uploadImage(file)
|
||||
if (res.code !== 200 || !res.data?.url) return
|
||||
|
||||
emits('update:modelValue', res.data.url)
|
||||
ElMessage.success('上传成功')
|
||||
options.onSuccess?.(res)
|
||||
} catch (error) {
|
||||
options.onError?.(error as Error)
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.thumbnail-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
|
||||
&__preview {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
&__image {
|
||||
width: 160px;
|
||||
height: 100px;
|
||||
border-radius: 6px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
&__actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&__tip {
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,37 @@
|
||||
/** 官网内容语言(媒体中心 / SEO 等),与前台 SiteLocale 一致 */
|
||||
export type ContentLocale = 'en' | 'zh' | 'ar' | 'ru'
|
||||
|
||||
export const CONTENT_LOCALES: readonly ContentLocale[] = ['zh', 'en', 'ar', 'ru'] as const
|
||||
|
||||
export const CONTENT_LOCALE_LABELS: Record<ContentLocale, string> = {
|
||||
zh: '中文',
|
||||
en: '英文',
|
||||
ar: '阿拉伯语',
|
||||
ru: '俄语'
|
||||
}
|
||||
|
||||
export const CONTENT_LOCALE_FILTER_OPTIONS = [
|
||||
{ label: '全部', value: '' as const },
|
||||
...CONTENT_LOCALES.map((value) => ({
|
||||
label: CONTENT_LOCALE_LABELS[value],
|
||||
value
|
||||
}))
|
||||
]
|
||||
|
||||
export function isContentLocale(value: string): value is ContentLocale {
|
||||
return (CONTENT_LOCALES as readonly string[]).includes(value)
|
||||
}
|
||||
|
||||
export function contentLocaleLabel(locale: string): string {
|
||||
return isContentLocale(locale) ? CONTENT_LOCALE_LABELS[locale] : locale
|
||||
}
|
||||
|
||||
export function contentLocaleTagType(
|
||||
locale: string
|
||||
): 'primary' | 'success' | 'warning' | 'danger' | 'info' {
|
||||
if (locale === 'zh') return 'primary'
|
||||
if (locale === 'en') return 'success'
|
||||
if (locale === 'ar') return 'warning'
|
||||
if (locale === 'ru') return 'danger'
|
||||
return 'info'
|
||||
}
|
||||
Reference in New Issue
Block a user