Commit 3c34888959fccc5937dd037880fbe0aae307c1b1
1 parent
88928901
fix: upload
Showing
4 changed files
with
38 additions
and
10 deletions
yudao-ui-admin-vue3/src/components/Editor/src/Editor.vue
| @@ -6,6 +6,7 @@ import { propTypes } from '@/utils/propTypes' | @@ -6,6 +6,7 @@ import { propTypes } from '@/utils/propTypes' | ||
| 6 | import { isNumber } from '@/utils/is' | 6 | import { isNumber } from '@/utils/is' |
| 7 | import { ElMessage } from 'element-plus' | 7 | import { ElMessage } from 'element-plus' |
| 8 | import { useLocaleStore } from '@/store/modules/locale' | 8 | import { useLocaleStore } from '@/store/modules/locale' |
| 9 | +import { getAccessToken, getTenantId } from '@/utils/auth' | ||
| 9 | 10 | ||
| 10 | const localeStore = useLocaleStore() | 11 | const localeStore = useLocaleStore() |
| 11 | 12 | ||
| @@ -80,12 +81,40 @@ const editorConfig = computed((): IEditorConfig => { | @@ -80,12 +81,40 @@ const editorConfig = computed((): IEditorConfig => { | ||
| 80 | }, | 81 | }, |
| 81 | autoFocus: false, | 82 | autoFocus: false, |
| 82 | scroll: true, | 83 | scroll: true, |
| 84 | + MENU_CONF: { | ||
| 85 | + ['uploadImage']: { | ||
| 86 | + server: import.meta.env.VITE_UPLOAD_URL, | ||
| 87 | + // 单个文件的最大体积限制,默认为 2M | ||
| 88 | + maxFileSize: 2 * 1024 * 1024, | ||
| 89 | + // 最多可上传几个文件,默认为 100 | ||
| 90 | + maxNumberOfFiles: 10, | ||
| 91 | + // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 [] | ||
| 92 | + allowedFileTypes: ['image/*'], | ||
| 93 | + | ||
| 94 | + // 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。 | ||
| 95 | + meta: {}, | ||
| 96 | + // 将 meta 拼接到 url 参数中,默认 false | ||
| 97 | + metaWithUrl: false, | ||
| 98 | + | ||
| 99 | + // 自定义增加 http header | ||
| 100 | + headers: { | ||
| 101 | + Accept: 'image/*', | ||
| 102 | + Authorization: 'Bearer ' + getAccessToken(), | ||
| 103 | + 'tenant-id': getTenantId() | ||
| 104 | + }, | ||
| 105 | + | ||
| 106 | + // 跨域是否传递 cookie ,默认为 false | ||
| 107 | + withCredentials: false, | ||
| 108 | + | ||
| 109 | + // 超时时间,默认为 10 秒 | ||
| 110 | + timeout: 5 * 1000 // 5 秒 | ||
| 111 | + } | ||
| 112 | + }, | ||
| 83 | uploadImgShowBase64: true | 113 | uploadImgShowBase64: true |
| 84 | }, | 114 | }, |
| 85 | props.editorConfig || {} | 115 | props.editorConfig || {} |
| 86 | ) | 116 | ) |
| 87 | }) | 117 | }) |
| 88 | - | ||
| 89 | const editorStyle = computed(() => { | 118 | const editorStyle = computed(() => { |
| 90 | return { | 119 | return { |
| 91 | height: isNumber(props.height) ? `${props.height}px` : props.height | 120 | height: isNumber(props.height) ? `${props.height}px` : props.height |
yudao-ui-admin-vue3/src/views/infra/file/fileList.data.ts renamed to yudao-ui-admin-vue3/src/views/infra/fileList/fileList.data.ts
yudao-ui-admin-vue3/src/views/infra/file/index.vue renamed to yudao-ui-admin-vue3/src/views/infra/fileList/index.vue
| @@ -7,8 +7,8 @@ import { useI18n } from '@/hooks/web/useI18n' | @@ -7,8 +7,8 @@ import { useI18n } from '@/hooks/web/useI18n' | ||
| 7 | import type { FileVO } from '@/api/infra/file/types' | 7 | import type { FileVO } from '@/api/infra/file/types' |
| 8 | import { allSchemas } from './fileList.data' | 8 | import { allSchemas } from './fileList.data' |
| 9 | import * as FileApi from '@/api/infra/file' | 9 | import * as FileApi from '@/api/infra/file' |
| 10 | -import { useCache } from '@/hooks/web/useCache' | ||
| 11 | -const { wsCache } = useCache() | 10 | +import { getAccessToken, getTenantId } from '@/utils/auth' |
| 11 | + | ||
| 12 | const { t } = useI18n() // 国际化 | 12 | const { t } = useI18n() // 国际化 |
| 13 | 13 | ||
| 14 | // ========== 列表相关 ========== | 14 | // ========== 列表相关 ========== |
| @@ -29,7 +29,7 @@ const uploadHeaders = ref() | @@ -29,7 +29,7 @@ const uploadHeaders = ref() | ||
| 29 | const beforeUpload = (file: UploadRawFile) => { | 29 | const beforeUpload = (file: UploadRawFile) => { |
| 30 | const isImg = file.type === 'image/jpeg' || 'image/gif' || 'image/png' | 30 | const isImg = file.type === 'image/jpeg' || 'image/gif' || 'image/png' |
| 31 | const isLt5M = file.size / 1024 / 1024 < 5 | 31 | const isLt5M = file.size / 1024 / 1024 < 5 |
| 32 | - if (!isImg) ElMessage.error('上传文件只能是 xls / xlsx 格式!') | 32 | + if (!isImg) ElMessage.error('上传文件只能是 jpeg / gif / png 格式!') |
| 33 | if (!isLt5M) ElMessage.error('上传文件大小不能超过 5MB!') | 33 | if (!isLt5M) ElMessage.error('上传文件大小不能超过 5MB!') |
| 34 | return isImg && isLt5M | 34 | return isImg && isLt5M |
| 35 | } | 35 | } |
| @@ -40,8 +40,8 @@ const beforeUpload = (file: UploadRawFile) => { | @@ -40,8 +40,8 @@ const beforeUpload = (file: UploadRawFile) => { | ||
| 40 | // 文件上传 | 40 | // 文件上传 |
| 41 | const submitFileForm = () => { | 41 | const submitFileForm = () => { |
| 42 | uploadHeaders.value = { | 42 | uploadHeaders.value = { |
| 43 | - Authorization: 'Bearer ' + wsCache.get('ACCESS_TOKEN'), | ||
| 44 | - 'tenant-id': wsCache.get('tenantId') | 43 | + Authorization: 'Bearer ' + getAccessToken(), |
| 44 | + 'tenant-id': getTenantId() | ||
| 45 | } | 45 | } |
| 46 | uploadDisabled.value = true | 46 | uploadDisabled.value = true |
| 47 | uploadRef.value!.submit() | 47 | uploadRef.value!.submit() |
yudao-ui-admin-vue3/src/views/system/user/index.vue
| @@ -30,9 +30,8 @@ import { listSimplePostsApi } from '@/api/system/post' | @@ -30,9 +30,8 @@ import { listSimplePostsApi } from '@/api/system/post' | ||
| 30 | import { rules, allSchemas } from './user.data' | 30 | import { rules, allSchemas } from './user.data' |
| 31 | import * as UserApi from '@/api/system/user' | 31 | import * as UserApi from '@/api/system/user' |
| 32 | import download from '@/utils/download' | 32 | import download from '@/utils/download' |
| 33 | -import { useCache } from '@/hooks/web/useCache' | ||
| 34 | import { CommonStatusEnum } from '@/utils/constants' | 33 | import { CommonStatusEnum } from '@/utils/constants' |
| 35 | -const { wsCache } = useCache() | 34 | +import { getAccessToken, getTenantId } from '@/utils/auth' |
| 36 | interface Tree { | 35 | interface Tree { |
| 37 | id: number | 36 | id: number |
| 38 | name: string | 37 | name: string |
| @@ -216,8 +215,8 @@ const beforeExcelUpload = (file: UploadRawFile) => { | @@ -216,8 +215,8 @@ const beforeExcelUpload = (file: UploadRawFile) => { | ||
| 216 | const uploadRef = ref<UploadInstance>() | 215 | const uploadRef = ref<UploadInstance>() |
| 217 | const submitFileForm = () => { | 216 | const submitFileForm = () => { |
| 218 | uploadHeaders.value = { | 217 | uploadHeaders.value = { |
| 219 | - Authorization: 'Bearer ' + wsCache.get('ACCESS_TOKEN'), | ||
| 220 | - 'tenant-id': wsCache.get('tenantId') | 218 | + Authorization: 'Bearer ' + getAccessToken(), |
| 219 | + 'tenant-id': getTenantId() | ||
| 221 | } | 220 | } |
| 222 | uploadDisabled.value = true | 221 | uploadDisabled.value = true |
| 223 | uploadRef.value!.submit() | 222 | uploadRef.value!.submit() |