esop文件管理

liutao_branch
liutao 2 months ago
parent 2f5055f67e
commit 559c341ee1

@ -0,0 +1,85 @@
import request from '@/config/axios'
// esop文件表库 VO
export interface FileVO {
id: number // id
configId: number // 配置编号
code: string // 文件编码
name: string // 文件名
path: string // 文件路径
url: string // 文件 URL
type: string // 文件类型
class: string // 文件分类
status: number // 文件状态
size: number // 文件大小
}
// 文件预签名地址 Response VO
export interface FilePresignedUrlRespVO {
// 文件配置编号
configId: number
// 文件上传 URL
uploadUrl: string
// 文件 URL
url: string
}
export enum ApiUrl{
'/admin-api/mes/esop/file/create'
}
// esop文件表库 API
export const FileApi = {
// 查询esop文件表库分页
getFilePage: async (params: any) => {
return await request.get({ url: `/esop/file/page`, params })
},
// 查询esop文件表库详情
getFile: async (id: number) => {
return await request.get({ url: `/esop/file/get?id=` + id })
},
// 新增esop文件表库
createFile: async (data: FileVO) => {
return await request.post({ url: `/esop/file/create`, data })
},
// 修改esop文件表库
updateFile: async (data: FileVO) => {
return await request.put({ url: `/esop/file/update`, data })
},
// 删除esop文件表库
deleteFile: async (id: number) => {
return await request.delete({ url: `/esop/file/delete?id=` + id })
},
// 导出esop文件表库 Excel
exportFile: async (params) => {
return await request.download({ url: `/esop/file/export-excel`, params })
},
// 获取文件编码
generateCode: async () => {
return await request.get({ url: `/esop/file/generate`})
},
}
// 获取文件预签名地址
export const getFilePresignedUrl = (path: string) => {
return request.get<FilePresignedUrlRespVO>({
url: '/infra/file/presigned-url',
params: { path }
})
}
// 创建文件
export const createFile = (data: any) => {
return request.post({ url: '/esop/file/create', data })
}
// 上传文件
export const updateFile = (data: any) => {
return request.upload({ url: '/esop/file/create', data })
}

@ -2069,6 +2069,69 @@ export default {
validatorNameRequired: 'Unit name can not be empty',
validatorStatusRequired: 'Unit status can not be empty',
validatorPrimaryFlagRequired: 'Primary unit flag can not be empty'
},
CalHoliday: {
setWorkingDays: 'set working days',
setHoliday: 'set holiday',
lastMonth:'last month',
today:'today',
nextMonth:'next month',
work:'work',
rest:'rest',
searchDateStartPlaceholder: '开始日期',
searchDateEndPlaceholder: '结束日期',
searchTypeLabel: '类型',
searchTypePlaceholder: '请选择类型',
searchRemarkLabel: '备注',
searchRemarkPlaceholder: '请输入备注',
searchButtonText: '搜索',
resetButtonText: '重置',
addButtonText: '新增',
exportButtonText: '导出'
},
EsopFile: {
moduleName: 'File Management',
searchCodeLabel: 'File Code',
searchCodePlaceholder: 'Please enter file code',
searchFileNameLabel: 'File_Name',
searchFileNamePlaceholder: 'Please enter file name',
searchClassificationLabel: 'File Classification',
searchClassificationPlaceholder: 'Please select file Classification',
searchStatusLabel: 'File Status',
searchStatusPlaceholder: 'Please select file status',
searchButtonText: 'Search',
resetButtonText: 'Reset',
uploadButtonText: 'Upload',
exportButtonText: 'Export',
tableCodeColumn: 'File Code',
tableNameColumn: 'File Name',
tableClassificationColumn: 'File Classification',
tableTypeColumn: 'File Type',
tableStatusColumn: 'File Status',
tableCreatorNameColumn: 'Uploader',
tableCreateTimeColumn: 'Upload Time',
tableOperateColumn: 'Operation',
tableEditAction: 'Edit',
tableDownloadAction: 'Download',
tableDeleteAction: 'Delete',
dialogFileNameLabel: 'File Name',
dialogFileNamePlaceholder: 'Please enter file name',
dialogClassificationLabel: 'File Classification',
dialogClassificationPlaceholder: 'Please select file classification',
dialogStatusLabel: 'File Status',
dialogCancelButton: 'Cancel',
dialogSubmitButton: 'Confirm',
messageOne: 'Tip: Only ',
messageTwo: ' format files are allowed to be imported!',
messageThree: ' Drag the file to this area, or ',
messageFour: ' click to upload',
validatorCodeRequired: 'File code can not be empty',
validatorNameRequired: 'File name can not be empty',
validatorClassificationRequired: 'File classification can not be empty',
validatorTypeRequired: 'File type can not be empty',
validatorStatusRequired: 'File status can not be empty'
}
},

@ -2875,7 +2875,66 @@ export default {
validatorNameRequired: '单位名称不能为空',
validatorStatusRequired: '单位状态不能为空',
validatorPrimaryFlagRequired: '是否主单位不能为空'
},
//假日管理
CalHoliday: {
setWorkingDays: '设置工作日',
setHoliday: '设置休息日',
lastMonth:'上个月',
today:'今天',
nextMonth:'下个月',
work:'班',
rest:'休',
searchDateStartPlaceholder: '开始日期',
searchDateEndPlaceholder: '结束日期',
searchTypeLabel: '类型',
searchTypePlaceholder: '请选择类型',
searchRemarkLabel: '备注',
searchRemarkPlaceholder: '请输入备注',
searchButtonText: '搜索',
resetButtonText: '重置',
addButtonText: '新增',
exportButtonText: '导出'
},
//esop文件管理
EsopFile: {
searchFileNameLabel: '文件名称',
searchFileNamePlaceholder: '请输入文件名',
searchClassificationLabel: '文件分类',
searchClassificationPlaceholder: '请选择文件分类',
searchStatusLabel: '文件状态',
searchStatusPlaceholder: '请选择文件状态',
searchButtonText: '搜索',
resetButtonText: '重置',
uploadButtonText: '文件上传',
addButtonText: '新增',
exportButtonText: '导出',
tableCodeColumn:'文件编码',
tableNameColumn: '文件名称',
tableClassificationColumn: '文件分类',
tableTypeColumn: '文件类型',
tableStatusColumn: '文件状态',
tableCreatorNameColumn: '上传人',
tableCreateTimeColumn: '上传时间',
tableOperateColumn: '操作',
tableEditAction: '编辑',
tableDownloadAction:'下载',
tableDeleteAction: '删除',
dialogFileNameLabel: '文件名',
dialogFileNamePlaceholder: '请输入文件名',
dialogClassificationLabel: '文件分类',
dialogClassificationPlaceholder: '请选择文件分类',
dialogStatusLabel: '文件状态',
dialogCancelButton: '取 消',
dialogSubmitButton: '确 定',
messageOne:'提示:仅允许导入 ',
messageTwo:' 格式文件!',
messageThree:' 将文件拖到此处,或',
messageFour:'点击上传',
validatorNameRequired: '文件名不能为空',
validatorStatusRequired: '文件状态不能为空'
}
},
ProductionPlan: {
Task: {
@ -4221,6 +4280,8 @@ export default {
messageDeviceNoParams: '该设备下没有参数',
messageFetchChartFailed: '获取图表数据失败'
}
}
}
}

@ -266,6 +266,8 @@ export enum DICT_TYPE {
MOLD_GET_STATUS = "mold_get_status",
MES_PRE_PRODUCTION = "mes_pre_production",
MES_ZJ_PRODUCT = "mes_zj_product",
FILE_STATUS = "file_status",
Classification = "classification",
//====iot
IOT_SIEMENS_TYPE = "iot_siemens_type",
IOT_MODBUS_TYPE = "iot_modbus_type",

@ -22,33 +22,33 @@
type="primary"
size="small"
@click="handleWorkday(date)"
>设置工作日
>{{ t('FactoryModeling.CalHoliday.setWorkingDays') }}
</el-button>
<el-button style="margin-left: 10px"
type="success"
size="small"
@click="handleHoliday(date)"
>设置休息日
>{{ t('FactoryModeling.CalHoliday.setHoliday') }}
</el-button>
<el-button style="margin-left: 10px"
size="small"
:icon="ArrowLeft"
@click="handleOriginalPrevMonth"
>
上个月
{{ t('FactoryModeling.CalHoliday.lastMonth') }}
</el-button>
<el-button
size="small"
@click="handleOriginalToday"
>
今天
{{ t('FactoryModeling.CalHoliday.today') }}
</el-button>
<el-button
size="small"
:icon="ArrowRight"
@click="handleOriginalNextMonth"
>
下个月</el-button>
{{ t('FactoryModeling.CalHoliday.nextMonth') }}</el-button>
</el-button-group>
</div>
</div>
@ -64,8 +64,8 @@
</div>
</el-col>
<el-col :span="8">
<el-tag v-if="holidayList.indexOf(data.day) ==-1" effect="dark"></el-tag>
<el-tag v-else effect="dark" type="success"></el-tag>
<el-tag v-if="holidayList.indexOf(data.day) ==-1" effect="dark">{{ t('FactoryModeling.CalHoliday.work') }}</el-tag>
<el-tag v-else effect="dark" type="success">{{ t('FactoryModeling.CalHoliday.rest') }}</el-tag>
</el-col>
</el-row>
<el-row>
@ -138,21 +138,26 @@ const loadMonthData = () => {
//
const handleOriginalPrevMonth = () => {
queryParams.theDay = dayjs(currentDate.value).format('YYYY-MM-DD');
currentDate.value = dayjs(currentDate.value)
.subtract(1, 'month')
.toDate()
loadMonthData()
getList()
}
const handleOriginalNextMonth = () => {
queryParams.theDay = dayjs(currentDate.value).format('YYYY-MM-DD');
currentDate.value = dayjs(currentDate.value)
.add(1, 'month')
.toDate()
loadMonthData()
getList()
}
const handleOriginalToday = () => {
currentDate.value = new Date()
currentDate.value = new Date();
queryParams.theDay = dayjs(currentDate.value).format('YYYY-MM-DD');
loadMonthData()
}

@ -0,0 +1,228 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible" >
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<!-- <el-form-item label="配置编号" prop="configId">
<el-input v-model="formData.configId" placeholder="请输入配置编号" />
</el-form-item>-->
<el-form-item :label="t('FactoryModeling.EsopFile.tableCodeColumn')" prop="code">
<el-input v-model="formData.code" placeholder="点击新增时自动生成" :readonly="true">
<!-- <template #append>
<el-button @click="refreshCode" title="重新生成">
<Refresh />
</el-button>
</template>-->
</el-input>
<!-- <div class="form-tips">此编号为系统自动生成</div>-->
</el-form-item>
<el-form-item :label="t('FactoryModeling.EsopFile.tableNameColumn')" prop="name">
<el-input v-model="formData.name" :placeholder="t('FactoryModeling.EsopFile.searchFileNamePlaceholder')" />
</el-form-item>
<el-form-item :label="t('FactoryModeling.EsopFile.searchClassificationLabel')" prop="classification">
<el-select
v-model="formData.classification"
clearable
:placeholder="t('FactoryModeling.EsopFile.searchClassificationPlaceholder')"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.Classification)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<!-- <el-form-item label="文件类型" prop="type">
<el-input v-model="formData.type" placeholder="请输入文件类型" />
</el-form-item>-->
<el-form-item :label="t('FactoryModeling.EsopFile.searchStatusLabel')" prop="status">
<el-radio-group v-model="formData.status">
<el-radio
v-for="dict in getIntDictOptions(DICT_TYPE.FILE_STATUS)"
:key="dict.value"
:label="dict.value"
>
{{ dict.label }}
</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<el-upload
ref="uploadRef"
v-model:file-list="fileList"
:action="uploadUrl"
:auto-upload="false"
:data="data"
:disabled="isEdit"
:limit="1"
:on-change="handleFileChange"
:on-error="submitFormError"
:on-exceed="handleExceed"
:on-success="submitFormSuccess"
:http-request="httpRequest"
accept=".jpg, .png, .gif ,.pdf,.word,.excel,.ppt,.mp4,.avi,.mov"
drag
>
<i class="el-icon-upload"></i>
<div class="el-upload__text"> {{t('FactoryModeling.EsopFile.messageThree')}} <em>{{t('FactoryModeling.EsopFile.messageFour')}}</em></div>
<template #tip>
<div class="el-upload__tip" style="color: red">
{{t('FactoryModeling.EsopFile.messageOne')}} .jpg, .png, .gif ,.pdf,.word,.excel,.ppt,.mp4,.avi,.mov {{t('FactoryModeling.EsopFile.messageTwo')}}
</div>
</template>
</el-upload>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitFileForm">{{t('FactoryModeling.EsopFile.dialogSubmitButton')}}</el-button>
<el-button @click="dialogVisible = false">{{t('FactoryModeling.EsopFile.dialogCancelButton')}}</el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import {useUpload} from "@/views/mes/esopFile/useUpload";
import {FileApi, FileVO} from "@/api/mes/esopFile";
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import {FeedingRecordPlanApi, FeedingRecordPlanVO} from "@/api/mes/feedingplan";
defineOptions({ name: 'InfraFileForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) //
const isEdit = ref(false)
const fileList = ref([]) //
const data = ref({ path: '' })
const uploadRef = ref()
const dialogTitle = ref('') //
const { uploadUrl, httpRequest } = useUpload()
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
configId: undefined,
code: undefined,
name: undefined,
path: undefined,
url: undefined,
type: undefined,
classification: undefined,
status: 1,
size: undefined,
})
const formRules = reactive({
path: [{ required: true, message: '文件路径不能为空', trigger: 'blur' }],
url: [{ required: true, message: '文件 URL不能为空', trigger: 'blur' }],
status: [{ required: true, message: '文件状态不能为空', trigger: 'blur' }],
size: [{ required: true, message: '文件大小不能为空', trigger: 'blur' }],
})
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
fileList.value =[]
resetForm()
//
if (id) {
formLoading.value = true
isEdit.value = true
try {
formData.value = await FileApi.getFile(id)
let file = {
name: formData.value.name,
url: formData.value.url,
size: formData.value.size,
}
fileList.value.push(file)
} finally {
formLoading.value = false
}
}else{
formData.value = {}
await getGeneratedCode()
}
}
defineExpose({ open }) // open
/** 处理上传的文件发生变化 */
const handleFileChange = (file) => {
data.value.path = file.name
}
/** 提交表单 */
const submitFileForm = async () => {
data.value.params = formData
if(isEdit){
//
formLoading.value = true
try {
const data = formData.value as unknown as FileVO
await FileApi.updateFile(data)
message.success(t('common.updateSuccess'))
dialogVisible.value = false
emit('success')
} finally {
formLoading.value = false
}
}else{
if (fileList.value.length == 0) {
message.error('请上传文件')
return
}
unref(uploadRef)?.submit()
}
}
/** 文件上传成功处理 */
const emit = defineEmits(['success']) // success
const submitFormSuccess = () => {
//
dialogVisible.value = false
formLoading.value = false
unref(uploadRef)?.clearFiles()
//
message.success(t('common.createSuccess'))
emit('success')
}
/** 上传错误提示 */
const submitFormError = (): void => {
message.error('上传失败,请您重新上传!')
formLoading.value = false
}
/** 重置表单 */
const resetForm = () => {
//
formLoading.value = false
uploadRef.value?.clearFiles()
}
/** 文件数超出提示 */
const handleExceed = (): void => {
message.error('最多只能上传一个文件!')
}
//
const getGeneratedCode = async () => {
try {
const res = await FileApi.generateCode() //
if (res !== undefined) {
formData.value.code = res
formData.value.status = 1
}
} catch (error) {
console.error('获取编码失败:', error)
//
formData.value.code = 'ESOP_' + Date.now()
}
}
</script>

@ -0,0 +1,234 @@
<template>
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
min-label-width="68px"
>
<el-form-item :label="t('FactoryModeling.EsopFile.searchFileNameLabel')" prop="name">
<el-input
v-model="queryParams.name"
:placeholder="t('FactoryModeling.EsopFile.searchFileNamePlaceholder')"
clearable
@keyup.enter="handleQuery"
class="!w-240px"
/>
</el-form-item>
<el-form-item :label="t('FactoryModeling.EsopFile.searchClassificationLabel')" prop="classification">
<el-select
v-model="queryParams.classification"
:placeholder="t('FactoryModeling.EsopFile.searchClassificationPlaceholder')"
clearable
@keyup.enter="handleQuery"
class="!w-240px">
<el-option
v-for="dict in getDictOptions('classification')" :key="dict.value" :label="dict.label"
:value="dict.value" />
</el-select>
</el-form-item>
<el-form-item :label="t('FactoryModeling.EsopFile.searchStatusLabel')" prop="status">
<el-select
v-model="queryParams.status"
:placeholder="t('FactoryModeling.EsopFile.searchStatusPlaceholder')"
clearable
class="!w-240px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.FILE_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> {{t('FactoryModeling.EsopFile.searchButtonText')}}</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> {{t('FactoryModeling.EsopFile.resetButtonText')}}</el-button>
<el-button
type="primary"
plain
@click="openForm('create')"
v-hasPermi="['esop:file:create']"
> <Icon icon="ep:plus" class="mr-5px" />
{{t('FactoryModeling.EsopFile.uploadButtonText')}}
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<!-- <el-table-column label="id" align="center" prop="id" />
<el-table-column label="配置编号" align="center" prop="configId" />-->
<el-table-column :label="t('FactoryModeling.EsopFile.tableCodeColumn')" align="center" prop="code" />
<el-table-column :label="t('FactoryModeling.EsopFile.tableNameColumn')" align="center" prop="name" />
<el-table-column :label="t('FactoryModeling.EsopFile.tableClassificationColumn')" align="center" prop="classification" >
<template #default="scope">
<dict-tag type="classification" :value="scope.row.classification" />
</template>
</el-table-column>
<el-table-column :label="t('FactoryModeling.EsopFile.tableTypeColumn')" align="center" prop="type" />
<el-table-column :label="t('FactoryModeling.EsopFile.tableStatusColumn')" align="center" prop="status">
<template #default="scope">
<dict-tag :type="DICT_TYPE.FILE_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column :label="t('FactoryModeling.EsopFile.tableCreatorNameColumn')" align="center" prop="creatorName" />
<el-table-column
:label="t('FactoryModeling.EsopFile.tableCreateTimeColumn')"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="180px"
/>
<el-table-column :label="t('FactoryModeling.EsopFile.tableOperateColumn')" align="center" min-width="120px">
<template #default="scope">
<el-button
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="['esop:file:update']"
>
{{t('FactoryModeling.EsopFile.tableEditAction') }}
</el-button>
<el-button
link
type="primary"
@click="downloadFile(scope.row.url)"
v-hasPermi="['esop:file:update']"
>
{{t('FactoryModeling.EsopFile.tableDownloadAction') }}
</el-button>
<!-- <el-link v-show="scope.row.path" type="primary" download :href="row.url" :underline="false" target="_blank"
>下载</el-link
>-->
<el-button
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['esop:file:delete']"
>
{{t('FactoryModeling.EsopFile.tableDeleteAction') }}
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<FileForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { FileApi, FileVO } from '@/api/mes/esopFile'
import FileForm from './FileForm.vue'
import { getDictOptions } from '@/utils/dict'
/** esop文件表库 列表 */
defineOptions({ name: 'EsopFile' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const list = ref<FileVO[]>([]) //
const total = ref(0) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
configId: undefined,
code: undefined,
name: undefined,
path: undefined,
url: undefined,
type: undefined,
class: undefined,
status: undefined,
size: undefined,
createTime: [],
})
const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await FileApi.getFilePage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value.resetFields()
handleQuery()
}
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
formRef.value.open(type, id)
}
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
try {
//
await message.delConfirm()
//
await FileApi.deleteFile(id)
message.success(t('common.delSuccess'))
//
await getList()
} catch {}
}
const downloadFile = (url) => {
window.open(url, '_blank')
}
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await FileApi.exportFile(queryParams)
download.excel(data, 'esop文件表库.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/
onMounted(() => {
getList()
})
</script>

@ -0,0 +1,117 @@
import * as FileApi from '@/api/mes/esopFile'
import CryptoJS from 'crypto-js'
import { UploadRawFile, UploadRequestOptions } from 'element-plus/es/components/upload/src/upload'
import axios from 'axios'
/**
* URL
*/
export const getUploadUrl = (): string => {
return import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/esop/file/create'
}
export const useUpload = () => {
// 后端上传地址
const uploadUrl = getUploadUrl()
// 是否使用前端直连上传
const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE
// 重写ElUpload上传方法
const httpRequest = async (options: UploadRequestOptions) => {
// 模式一:前端上传
if (isClientUpload) {
const fileName = await generateFileName(options.file)
const presignedInfo = await FileApi.getFilePresignedUrl(fileName)
return axios
.put(presignedInfo.uploadUrl, options.file, {
headers: {
'Content-Type': options.file.type
}
})
.then(() => {
const fileVo = createFile(presignedInfo, fileName, options.file)
return {
code: 0,
status: 0,
data: {
fileName: fileVo.path,
fileUrl: fileVo.url
},
msg: ''
}
})
} else {
const fileVo = {
file: options.file,
code: options.data.params.code,
name: options.data.params.name,
type: options.data.params.type,
classification: options.data.params.classification,
status: options.data.params.status,
}
// 模式二:后端上传
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
return new Promise((resolve, reject) => {
FileApi.updateFile(fileVo)
.then((res) => {
if (res.code === 0) {
resolve(res)
} else {
reject(res)
}
})
.catch((res) => {
reject(res)
})
})
}
}
return {
uploadUrl,
httpRequest
}
}
/**
*
* @param vo
* @param name
* @param file
*/
function createFile(vo: FileApi.FilePresignedUrlRespVO, name: string, file: UploadRawFile) {
const fileVo = {
configId: vo.configId,
url: vo.url,
path: name,
name: file.name,
type: file.type,
size: file.size
}
FileApi.createFile(fileVo)
return fileVo
}
/**
* 使SHA256
* @param file
*/
async function generateFileName(file: UploadRawFile) {
// 读取文件内容
const data = await file.arrayBuffer()
const wordArray = CryptoJS.lib.WordArray.create(data)
// 计算SHA256
const sha256 = CryptoJS.SHA256(wordArray).toString()
// 拼接后缀
const ext = file.name.substring(file.name.lastIndexOf('.'))
return `${sha256}${ext}`
}
/**
*
*/
enum UPLOAD_TYPE {
// 客户端直接上传只支持S3服务
CLIENT = 'client',
// 客户端发送到后端上传
SERVER = 'server'
}
Loading…
Cancel
Save