diff --git a/nginx.conf b/nginx.conf index 1d72944..004adb9 100644 --- a/nginx.conf +++ b/nginx.conf @@ -8,6 +8,8 @@ server { server_name _; + client_max_body_size 500M; + location /sweet-hut/ { alias /usr/share/nginx/html/; try_files $uri $uri/ /sweet-hut/index.html; diff --git a/src/apis/file.ts b/src/apis/file.ts index 208b34b..ac3b742 100644 --- a/src/apis/file.ts +++ b/src/apis/file.ts @@ -18,6 +18,7 @@ export const uploadAListFileApi = (form: FormData): Promise => headers: { 'Content-Type': 'multipart/form-data' }, + timeout: 0, method: 'post', data: form }) diff --git a/src/components/Food/Data/FoodRecordData.vue b/src/components/Food/Data/FoodRecordData.vue index a9b21f6..3873fae 100644 --- a/src/components/Food/Data/FoodRecordData.vue +++ b/src/components/Food/Data/FoodRecordData.vue @@ -12,8 +12,8 @@ 完成人:{{ item.person }} @@ -25,7 +25,7 @@ diff --git a/src/views/food/recipeForm.vue b/src/views/food/recipeForm.vue index 9dd2add..f7bb943 100644 --- a/src/views/food/recipeForm.vue +++ b/src/views/food/recipeForm.vue @@ -68,7 +68,8 @@ import FoodMaterialDialog from '@/components/Food/Form/FoodMaterialDialog.vue' import FoodStepDialog from '@/components/Food/Form/FoodStepDialog.vue' import { useFoodStore } from '@/store/food.ts' -import { ref, reactive } from 'vue' +import { useAppStore } from '@/store/app.ts' +import { ref, reactive, onMounted } from 'vue' import { FormRules } from 'element-plus' import { foodRecordRules } from '@/utils/element/elRules.ts' import { commonElMessageBox } from 'vue3-common/utils/elUtil' @@ -80,9 +81,14 @@ const rules = reactive(foodRecordRules) const formRef = ref() const activeStep = ref(0) const foodStore = useFoodStore() +const appStore = useAppStore() const foodCategoryList = ['家常菜', '淮扬菜', '鲁菜', '川菜', '粤菜', '闽菜', '浙菜', '湘菜', '徽菜', '其他'] +onMounted(() => { + appStore.isShowMobileBack = true +}) + const previewClick = () => { activeStep.value-- } @@ -103,6 +109,7 @@ const confirmClick = () => { const cancelClick = () => { history.back() + appStore.isShowMobileBack = false } const deleteClick = () => { diff --git a/src/views/food/recordForm.vue b/src/views/food/recordForm.vue index 5c45e49..17ead62 100644 --- a/src/views/food/recordForm.vue +++ b/src/views/food/recordForm.vue @@ -38,10 +38,11 @@ 删除 取消 - - - - @@ -72,33 +69,30 @@ import { useFoodStore } from '@/store/food.ts' import { ref, reactive, onMounted } from 'vue' import { Plus } from '@element-plus/icons-vue' -import { - ElLoading, - ElMessage, ElMessageBox, - FormRules, - UploadProps, - UploadRawFile, - UploadRequestOptions, - UploadUserFile -} from 'element-plus' +import { ElMessage, ElMessageBox, FormRules, UploadProps, UploadRawFile, UploadRequestOptions, UploadUserFile } from 'element-plus' import { foodRecordRules } from '@/utils/element/elRules.ts' import { AListPath } from '@/utils' import { commonElMessageBox } from 'vue3-common/utils/elUtil' -import { getFileExtension, getFileHashName, validateImage } from '@/utils/home/file.ts' -import { uploadAListFileApi } from '@/apis/file.ts' +import { useAppStore } from '@/store/app.ts' +import { beforeUploadImage, httpRequestFile } from '@/utils/element/elUpload.ts' +import { acceptImageTypes } from '@/utils/home/file.ts' const rules = reactive(foodRecordRules) const formRef = ref() const foodStore = useFoodStore() +const appStore = useAppStore() const imageFileList = ref([]) -const dialogImageUrl = ref('') -const dialogVisible = ref(false) -onMounted(async () => { +onMounted(() => { + appStore.isShowMobileBack = true + + initImageFileList() +}) + +const initImageFileList = () => { imageFileList.value = [] - const { imageUrl } = foodStore.currentFoodRecord if (imageUrl) { imageFileList.value.push({ @@ -106,65 +100,28 @@ onMounted(async () => { url: `${AListPath}${imageUrl}` }) } -}) +} const beforeUpload: UploadProps['beforeUpload'] = (rawFile: UploadRawFile) => { - const maxFileMax = 1024 * 1024 * 10 - const fileType = rawFile.type - const fileName = rawFile.name - const fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase() - - if (!validateImage(fileType, fileExtension)) { - ElMessage.error('请上传图片') - return false - } - - if (rawFile.size > maxFileMax) { - ElMessage.error('请上传10M以内的文件!') - return false - } - - return true + return beforeUploadImage(rawFile) } const httpRequest: UploadProps['httpRequest'] = async (options: UploadRequestOptions): Promise => { - const loading = ElLoading.service({ - lock: true, - text: '文件上传中 请等待', - background: 'rgba(0, 0, 0, 0.7)' - }) + await httpRequestFile(foodStore.foodImagePath, options) +} - try { - const filePath = `/local/food/${getFileHashName(options.file.name)}.${getFileExtension(options.file.name)}` - - const data = new FormData() - data.append('file', options.file) - data.append('filePath', filePath) - - await uploadAListFileApi(data) - foodStore.currentFoodRecord.imageUrl = `p/${filePath}` - ElMessage.success('上传成功') - } catch (error) { - console.log(error) - ElMessage.error('上传失败 请联系管理员') - } finally { - loading.close() - } +const handleSuccess = (response: string) => { + foodStore.currentFoodRecord.imageUrl = `p/${response}` } const handleExceed: UploadProps['onExceed'] = () => { ElMessage.warning('最多上传1张图片') } -const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => { +const handleRemove: UploadProps['onRemove'] = () => { foodStore.currentFoodRecord.imageUrl = '' } -const handlePreview: UploadProps['onPreview'] = (uploadFile) => { - dialogImageUrl.value = uploadFile.url! - dialogVisible.value = true -} - const beforeRemove: UploadProps['beforeRemove'] = () => { return ElMessageBox.confirm('确认删除该文件?').then(() => true, () => false) } @@ -181,6 +138,7 @@ const confirmClick = () => { const cancelClick = () => { history.back() + appStore.isShowMobileBack = false } const deleteClick = () => {