@@ -70,7 +70,7 @@ import { useRouter } from 'vue-router'
import { formatDate } from 'vue3-common/utils/dateUtil'
import { ITravelSpot } from '@/types/travel.ts'
import { commonElMessageBox } from 'vue3-common/utils/elUtil'
-import { AListPath } from '@/utils'
+import { AListUrl } from '@/utils'
import { parsePerson } from '@/utils/home/travelUtil.ts'
const router = useRouter()
diff --git a/src/utils/element/elUpload.ts b/src/utils/element/elUpload.ts
index 9708725..9fb4a6b 100644
--- a/src/utils/element/elUpload.ts
+++ b/src/utils/element/elUpload.ts
@@ -1,8 +1,9 @@
-import { ElLoading, ElMessage, UploadRawFile, UploadRequestOptions } from 'element-plus'
-import { getFileExtension, getFileHashName, validateImage } from '@/utils/home/file.ts'
+import { ElLoading, ElMessage } from 'element-plus'
+import type { UploadRawFile, UploadRequestOptions } from 'element-plus'
+import { getFileExtension, getFileHashName, validateImage, compressOptions, validateVideo } from '@/utils/file.ts'
import { compressImage } from 'vue3-common/utils/fileUtil'
-import { compressOptions } from '@/utils'
import { uploadAListFileApi } from '@/apis/file.ts'
+import { AListPath } from '@/utils'
export const beforeUploadImage = (rawFile: UploadRawFile): boolean => {
const maxFileMax = 1024 * 1024 * 10
@@ -23,7 +24,27 @@ export const beforeUploadImage = (rawFile: UploadRawFile): boolean => {
return true
}
-export const httpRequestFile = async (basePath: string, options: UploadRequestOptions) => {
+export const beforeUploadVideo = (rawFile: UploadRawFile): boolean => {
+ const maxFileMax = 1024 * 1024 * 200
+ const fileType = rawFile.type
+ const fileName = rawFile.name
+ const fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase()
+
+ if (!validateVideo(fileType, fileExtension)) {
+ ElMessage.error('请上传视频')
+ return false
+ }
+
+ if (rawFile.size > maxFileMax) {
+ ElMessage.error('请上传200M以内的文件!')
+ return false
+ }
+
+ return true
+}
+
+export const httpRequestFile = async (basePath: string,
+ options: UploadRequestOptions, isCompress = true) => {
const loading = ElLoading.service({
lock: true,
text: '文件上传中 请等待',
@@ -31,11 +52,15 @@ export const httpRequestFile = async (basePath: string, options: UploadRequestOp
})
try {
- const filePath = `/local/${basePath}/${getFileHashName(options.file.name)}.${getFileExtension(options.file.name)}`
- const compressFile = await compressImage(options.file, compressOptions)
-
+ const filePath = `${AListPath}/${basePath}/${getFileHashName(options.file)}.${getFileExtension(options.file.name)}`
const data = new FormData()
- data.append('file', compressFile)
+
+ if (isCompress) {
+ const compressFile = await compressImage(options.file, compressOptions)
+ data.append('file', compressFile)
+ } else {
+ data.append('file', options.file)
+ }
data.append('filePath', filePath)
const result = await uploadAListFileApi(data)
diff --git a/src/utils/home/file.ts b/src/utils/file.ts
similarity index 88%
rename from src/utils/home/file.ts
rename to src/utils/file.ts
index c0095b6..6d252f9 100644
--- a/src/utils/home/file.ts
+++ b/src/utils/file.ts
@@ -1,15 +1,17 @@
import { hashSHA256 } from 'vue3-common/utils/cryptoUtil'
-export const getFileHashName = (name: string) => {
- return hashSHA256(name)
+export const getFileHashName = (file: File) => {
+ return hashSHA256(`${file.name}_${file.lastModified}`)
}
export const getFileExtension = (name: string) => {
return name.substring(name.lastIndexOf('.') + 1).toLowerCase()
}
-export const getFilePath = (basePath: string, name: string) => {
- return `/local/${basePath}/${getFileHashName(name)}.${getFileExtension(name)}`
+export const compressOptions = {
+ quality: 0.7,
+ maxHeight: 800,
+ maxWidth: 600
}
export const validateExcel = (fileType: string, fileExtension: string): boolean => {
@@ -29,6 +31,8 @@ export const validateExcel = (fileType: string, fileExtension: string): boolean
export const acceptImageTypes = '.jpg,.jpeg,.png,.gif,.webp,.bmp,.JPG,.JPEG,.PNG,.GIF,.WEBP,.BMP'
+export const acceptVideoTypes = '.mp4,.mov,.avi,.wmv,.flv,.webm,.mpeg,.mpg,.m4v,.3gp,.3g2,.mkv,.ts,.mts,.m2ts'
+
export const validateImage = (fileType: string, fileExtension: string): boolean => {
// 常见的图片 MIME 类型
const imageMimeTypes = [
diff --git a/src/utils/home/journalUtil.ts b/src/utils/home/journalUtil.ts
new file mode 100644
index 0000000..7c4be2a
--- /dev/null
+++ b/src/utils/home/journalUtil.ts
@@ -0,0 +1,17 @@
+export const journalCategoryTypeList = ['生活', '工作', '其他']
+
+export const journalWeatherTypeList = [{
+ value: 'sunny',
+ label: '晴'
+}, {
+ value: 'rainy',
+ label: '雨'
+}, {
+ value: 'snowy',
+ label: '雪'
+}, {
+ value: 'cloudy',
+ label: '阴'
+}]
+
+export const journalMoodTypeList = ['😀', '🙁', '😡']
diff --git a/src/utils/index.ts b/src/utils/index.ts
index 49a79b5..045911d 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -28,13 +28,9 @@ export const fileServiceUrl = '/home-api/file'
*/
export const serviceFileRootPath = '/home-api/'
-export const AListPath = '/alist-api/'
+export const AListUrl = '/alist-api/'
-export const compressOptions = {
- quality: 0.7,
- maxHeight: 800,
- maxWidth: 600
-}
+export const AListPath = import.meta.env.VITE_API_ALIST_PATH
/**
* 获取assets静态资源
diff --git a/src/views/food/recordForm.vue b/src/views/food/recordForm.vue
index 17ead62..e40ffcb 100644
--- a/src/views/food/recordForm.vue
+++ b/src/views/food/recordForm.vue
@@ -71,11 +71,11 @@ import { ref, reactive, onMounted } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox, FormRules, UploadProps, UploadRawFile, UploadRequestOptions, UploadUserFile } from 'element-plus'
import { foodRecordRules } from '@/utils/element/elRules.ts'
-import { AListPath } from '@/utils'
+import { AListUrl } from '@/utils'
import { commonElMessageBox } from 'vue3-common/utils/elUtil'
import { useAppStore } from '@/store/app.ts'
import { beforeUploadImage, httpRequestFile } from '@/utils/element/elUpload.ts'
-import { acceptImageTypes } from '@/utils/home/file.ts'
+import { acceptImageTypes } from '@/utils/file.ts'
const rules = reactive
(foodRecordRules)
@@ -97,7 +97,7 @@ const initImageFileList = () => {
if (imageUrl) {
imageFileList.value.push({
name: 'image',
- url: `${AListPath}${imageUrl}`
+ url: `${AListUrl}${imageUrl}`
})
}
}
@@ -107,11 +107,11 @@ const beforeUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => {
}
const httpRequest: UploadProps['httpRequest'] = async (options: UploadRequestOptions): Promise => {
- await httpRequestFile(foodStore.foodImagePath, options)
+ return await httpRequestFile(foodStore.foodImagePath, options)
}
const handleSuccess = (response: string) => {
- foodStore.currentFoodRecord.imageUrl = `p/${response}`
+ foodStore.currentFoodRecord.imageUrl = `p${response}`
}
const handleExceed: UploadProps['onExceed'] = () => {
@@ -133,6 +133,7 @@ const confirmClick = () => {
formRef.value.validate().then(() => {
foodStore.handleFoodRecordApi(foodStore.currentFoodRecord)
history.back()
+ appStore.isShowMobileBack = false
})
}
diff --git a/src/views/journal/detail[id].vue b/src/views/journal/detail[id].vue
index cc94aea..cfb5a74 100644
--- a/src/views/journal/detail[id].vue
+++ b/src/views/journal/detail[id].vue
@@ -36,7 +36,7 @@
@@ -46,7 +46,7 @@
@@ -60,27 +60,53 @@
-
+
+
+
+
+ 请上传小于10M的图片
+
+
+
-
+
+ 点击上传
+
+
+ 请上传小于200M的视频
+
+
+
@@ -95,43 +121,97 @@