salary
parent
de522af86f
commit
a557255b4a
@ -0,0 +1,45 @@ |
||||
import request from '@/config/axios' |
||||
|
||||
export interface FilePageReqVO extends PageParam { |
||||
path?: string |
||||
type?: string |
||||
createTime?: Date[] |
||||
} |
||||
|
||||
// 文件预签名地址 Response VO
|
||||
export interface FilePresignedUrlRespVO { |
||||
// 文件配置编号
|
||||
configId: number |
||||
// 文件上传 URL
|
||||
uploadUrl: string |
||||
// 文件 URL
|
||||
url: string |
||||
} |
||||
|
||||
// 查询文件列表
|
||||
export const getFilePage = (params: FilePageReqVO) => { |
||||
return request.get({ url: '/infra/file/page', params }) |
||||
} |
||||
|
||||
// 删除文件
|
||||
export const deleteFile = (id: number) => { |
||||
return request.delete({ url: '/infra/file/delete?id=' + id }) |
||||
} |
||||
|
||||
// 获取文件预签名地址
|
||||
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: '/infra/file/create', data }) |
||||
} |
||||
|
||||
// 上传文件
|
||||
export const updateFile = (data: any) => { |
||||
return request.upload({ url: '/admin-api/system/file/upload', data }) |
||||
} |
@ -1,25 +1,25 @@ |
||||
import request from '@/config/axios' |
||||
// 查询列表
|
||||
export const getProductPage = async (params) => { |
||||
return await request.get({ url: '/admin-api/crm/erp-product//page', params }) |
||||
return await request.get({ url: '/admin-api/crm/erp-product/page', params }) |
||||
} |
||||
|
||||
// 查询详情
|
||||
export const getProduct = async (id) => { |
||||
return await request.get({ url: '/admin-api/crm/erp-product//get?id=' + id }) |
||||
return await request.get({ url: '/admin-api/crm/erp-product/get?id=' + id }) |
||||
} |
||||
|
||||
// 新增
|
||||
export const createProduct = async (data) => { |
||||
return await request.post({ url: '/admin-api/crm/erp-product//create', data: data }) |
||||
return await request.post({ url: '/admin-api/crm/erp-product/create', data: data }) |
||||
} |
||||
|
||||
// 修改
|
||||
export const updateProduct = async (params) => { |
||||
return await request.put({ url: '/admin-api/crm/erp-product//update', data: params }) |
||||
return await request.put({ url: '/admin-api/crm/erp-product/update', data: params }) |
||||
} |
||||
|
||||
// 删除
|
||||
export const deleteProduct = async (id) => { |
||||
return await request.delete({ url: '/admin-api/crm/erp-product//delete?id=' + id }) |
||||
return await request.delete({ url: '/admin-api/crm/erp-product/delete?id=' + id }) |
||||
} |
||||
|
@ -0,0 +1,93 @@ |
||||
import * as FileApi from '@/api/infra/file' |
||||
import CryptoJS from 'crypto-js' |
||||
import { UploadRawFile, UploadRequestOptions } from 'element-plus/es/components/upload/src/upload' |
||||
import axios from 'axios' |
||||
|
||||
export const useUpload = () => { |
||||
// 后端上传地址
|
||||
const uploadUrl = import.meta.env.VITE_UPLOAD_URL |
||||
// 是否使用前端直连上传
|
||||
const isClientUpload = UPLOAD_TYPE.CLIENT === import.meta.env.VITE_UPLOAD_TYPE |
||||
// 重写ElUpload上传方法
|
||||
const httpRequest = async (options: UploadRequestOptions) => { |
||||
// 模式一:前端上传
|
||||
if (isClientUpload) { |
||||
// 1.1 生成文件名称
|
||||
const fileName = await generateFileName(options.file) |
||||
// 1.2 获取文件预签名地址
|
||||
const presignedInfo = await FileApi.getFilePresignedUrl(fileName) |
||||
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传,Minio 不支持)
|
||||
return axios.put(presignedInfo.uploadUrl, options.file).then(() => { |
||||
// 1.4. 记录文件信息到后端(异步)
|
||||
createFile(presignedInfo, fileName, options.file) |
||||
// 通知成功,数据格式保持与后端上传的返回结果一致
|
||||
return { data: presignedInfo.url } |
||||
}) |
||||
} else { |
||||
// 模式二:后端上传
|
||||
// 重写 el-upload httpRequest 文件上传成功会走成功的钩子,失败走失败的钩子
|
||||
return new Promise((resolve, reject) => { |
||||
FileApi.updateFile({ file: options.file }) |
||||
.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' |
||||
} |
@ -0,0 +1,50 @@ |
||||
<template> |
||||
<el-form :model="form" ref="formRef" label-width="auto"> |
||||
<el-form-item label="售后申请自动通过"> |
||||
<el-radio-group v-model="form.autoAudiAfterSale"> |
||||
<el-radio :label="0"> 是 </el-radio> |
||||
<el-radio :label="1"> 否 </el-radio> |
||||
</el-radio-group> |
||||
</el-form-item> |
||||
<el-form-item label="发货自动发起采购"> |
||||
<el-radio-group v-model="form.autoSend"> |
||||
<el-radio :label="0"> 是 </el-radio> |
||||
<el-radio :label="1"> 否 </el-radio> |
||||
</el-radio-group> |
||||
</el-form-item> |
||||
<el-form-item label="回款申请自动通过"> |
||||
<el-radio-group v-model="form.autoAuditReturn"> |
||||
<el-radio :label="0"> 是 </el-radio> |
||||
<el-radio :label="1"> 否 </el-radio> |
||||
</el-radio-group> |
||||
</el-form-item> |
||||
<el-form-item> |
||||
<el-button type="primary" @click="onSubmit">保存</el-button> |
||||
<el-button @click="getData">刷新</el-button> |
||||
</el-form-item> |
||||
</el-form> |
||||
</template> |
||||
|
||||
<script setup name="GeneralClue"> |
||||
const message = useMessage() |
||||
|
||||
const form = ref({ |
||||
autoAudiAfterSale: 0, |
||||
autoSend: 0, |
||||
autoAuditReturn: 0 |
||||
}) |
||||
|
||||
function getData() { |
||||
form.value = { |
||||
autoAudiAfterSale: 0, |
||||
autoSend: 0, |
||||
autoAuditReturn: 0 |
||||
} |
||||
} |
||||
|
||||
function onSubmit() { |
||||
message.success('保存成功') |
||||
} |
||||
</script> |
||||
|
||||
<style lang="scss" scoped></style> |
Loading…
Reference in new issue