nili
8 months ago
57 changed files with 1583 additions and 1228 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,13 +1,16 @@ |
|||
<!DOCTYPE html><html><head> |
|||
<!DOCTYPE html> |
|||
<html> |
|||
<head> |
|||
<meta charset="utf-8"> |
|||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> |
|||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> |
|||
<title>Ant Design Pro</title> |
|||
<link rel="stylesheet" href="/umi.1ca9308c.css"> |
|||
<script async="" src="/scripts/loading.js"></script> |
|||
<script async src="/scripts/loading.js"></script> |
|||
<script>!function(){"use strict";var t="/".replace(/([^/])$/,"$1/"),e=location.pathname,n=e.startsWith(t)&&decodeURI("/".concat(e.slice(t.length)));if(n){var a=document,c=a.head,r=a.createElement.bind(a),i=function(t,e,n){var a,c=e.r[t]||(null===(a=Object.entries(e.r).find((function(e){var n=e[0];return new RegExp("^".concat(n.replace(/\/:[^/]+/g,"/[^/]+").replace("/*","/.+"),"$")).test(t)})))||void 0===a?void 0:a[1]);return null==c?void 0:c.map((function(t){var a=e.f[t][1],c=e.f[t][0];return{type:c.split(".").pop(),url:"".concat(n.publicPath).concat(c),attrs:[["data-".concat(e.b),"".concat(e.p,":").concat(a)]]}}))}(n,{"p":"ant-design-pro","b":"webpack","f":[["p__AppManagement.7cb3b3e5.async.js",39],["51.e174e29e.async.js",51],["63.d3cf24e7.async.js",63],["134.6fc81d91.async.js",134],["169.57647c7d.async.js",169],["p__Welcome.61596037.async.js",185],["235.f7c67994.async.js",235],["247.3fe8fb10.async.js",247],["258.d191bbdb.async.js",258],["287.b21721be.async.js",287],["t__plugin-layout__Layout.6cae69f5.chunk.css",301],["t__plugin-layout__Layout.afe80231.async.js",301],["335.e3ecf74a.async.js",335],["p__User__Login__index.9d3ab92e.async.js",366],["p__DeviceOwnerApp.0a01face.async.js",371],["390.41467286.async.js",390],["393.b64a7324.async.js",393],["397.fb5f72c1.async.js",397],["p__SuperAdmin.d2274a04.async.js",455],["531.47eea593.async.js",531],["p__Bind.b6ee068f.async.js",557],["559.016bfdbb.async.js",559],["p__404.0c100574.async.js",571],["635.84db70b9.async.js",635],["p__AdminManagement.a0dd8c31.async.js",816],["p__AdvRecordList.4131e6d9.async.js",857],["905.6e225d1b.async.js",905],["930.42e2019f.async.js",930]],"r":{"/*":[22,26],"/":[3,10,11,21,23,26],"/welcome":[3,4,5,16,21,27,10,11,23,26],"/super":[1,2,3,4,6,7,18,27,10,11,21,23,26],"/adminList":[1,4,6,9,24,3,10,11,21,23,26],"/bind":[3,4,16,17,20,21,27,10,11,23,26],"/appList":[0,1,2,3,4,6,9,12,17,19,26,27,10,11,21,23],"/advList/:code":[1,2,3,4,6,8,9,12,19,21,25,26,27,10,11,23],"/app/:code":[1,2,3,4,6,8,9,12,14,19,21,26,27,10,11,23],"/user/login":[2,3,4,6,9,13,19]}},{publicPath:"/"});null==i||i.forEach((function(t){var e,n=t.type,a=t.url;if("js"===n)(e=r("script")).src=a,e.async=!0;else{if("css"!==n)return;(e=r("link")).href=a,e.rel="preload",e.as="style"}t.attrs.forEach((function(t){e.setAttribute(t[0],t[1]||"")})),c.appendChild(e)}))}}();</script> |
|||
</head> |
|||
<body> |
|||
<div id="root"></div> |
|||
<script src="/umi.04a1e043.js"></script> |
|||
|
|||
</body></html> |
|||
<script src="/umi.18c8c913.js"></script> |
|||
</body> |
|||
</html> |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,124 @@ |
|||
import { toMD5 } from '@/utils/encryptUtil'; |
|||
import OSS from 'ali-oss'; |
|||
import { message, Upload, UploadFile, UploadProps } from 'antd'; |
|||
import React, { useEffect, useState } from 'react'; |
|||
import { getSts } from '../services/matrix/admin'; |
|||
|
|||
interface OSSUploadProps { |
|||
onUploadSuccess?: (fileUrl: string) => void; |
|||
onUploadError?: (error: any) => void; |
|||
} |
|||
|
|||
const OSSUpload: React.FC<OSSUploadProps> = ({ onUploadSuccess, onUploadError }) => { |
|||
const [uploading, setUploading] = useState(false); |
|||
const [fileList, setFileList] = useState<UploadFile[]>([]); |
|||
const [ossClient, setOssClient] = useState<OSS | null>(null); |
|||
const { Dragger } = Upload; |
|||
|
|||
useEffect(() => { |
|||
async function initOssClient() { |
|||
try { |
|||
const stsResponse = await getSts(); // 假设你有一个 getSTS 函数可以获取 STS 凭证
|
|||
if ( |
|||
!stsResponse.data || |
|||
!stsResponse.data.accessKeySecret || |
|||
!stsResponse.data.accessKeyId |
|||
) { |
|||
message.error('初始化失败,请稍后再试'); |
|||
return; |
|||
} |
|||
const client = new OSS({ |
|||
region: 'oss-cn-beijing', |
|||
accessKeyId: stsResponse.data.accessKeyId, |
|||
accessKeySecret: stsResponse.data.accessKeySecret, |
|||
stsToken: stsResponse.data.securityToken, |
|||
bucket: stsResponse.data.bucket, |
|||
}); |
|||
setOssClient(client); |
|||
} catch (error) { |
|||
message.error('初始化 OSS 客户端失败'); |
|||
if (onUploadError) { |
|||
onUploadError(error); |
|||
} |
|||
} |
|||
} |
|||
initOssClient(); |
|||
}, [onUploadError]); |
|||
|
|||
const onRemove = (file: UploadFile) => { |
|||
const files = (fileList || []).filter((v) => v.url !== file.url); |
|||
setFileList(files); |
|||
}; |
|||
|
|||
const handleUpload: UploadProps['customRequest'] = async (options) => { |
|||
const { file } = options; |
|||
if (file instanceof File) { |
|||
setUploading(true); |
|||
|
|||
try { |
|||
const md5 = await toMD5(file); |
|||
const fileName = `matrix/${md5}.${file.name.split('.').pop()}`; |
|||
await ossClient?.put(fileName, file, { |
|||
headers: { |
|||
'Content-Type': file.type, |
|||
}, |
|||
}); |
|||
const fileUrl = `https://apks.bzgames.cn/${fileName}`; |
|||
|
|||
if (onUploadSuccess) { |
|||
onUploadSuccess(fileUrl); |
|||
} |
|||
setUploading(false); |
|||
// 将上传成功的文件信息添加到 fileList
|
|||
setFileList((prevFileList) => [ |
|||
...prevFileList, |
|||
{ |
|||
uid: file.uid, |
|||
name: file.name + ':' + fileUrl, |
|||
status: 'done', |
|||
url: fileUrl, |
|||
}, |
|||
]); |
|||
} catch (error) { |
|||
message.error('文件上传失败'); |
|||
if (onUploadError) { |
|||
onUploadError(error); |
|||
} |
|||
setFileList((prevFileList) => [ |
|||
...prevFileList, |
|||
{ |
|||
uid: file.uid, |
|||
name: file.name, |
|||
status: 'error', |
|||
}, |
|||
]); |
|||
} finally { |
|||
setUploading(false); |
|||
} |
|||
} else { |
|||
message.error('上传文件类型错误'); |
|||
} |
|||
}; |
|||
|
|||
return ( |
|||
<Dragger |
|||
fileList={fileList} |
|||
multiple |
|||
customRequest={handleUpload} |
|||
onRemove={onRemove} |
|||
disabled={uploading || !ossClient} |
|||
onPreview={async (file) => { |
|||
await navigator.clipboard.writeText(file.url || ''); |
|||
message.success('链接复制成功 ' + file.url); |
|||
}} |
|||
> |
|||
<p className="ant-upload-drag-icon"> |
|||
<i className="anticon anticon-inbox" /> |
|||
</p> |
|||
<p className="ant-upload-text">点击或拖拽文件到此区域上传</p> |
|||
<p className="ant-upload-hint">支持单个或批量上传。文件名将使用文件的 MD5 值命名。</p> |
|||
</Dragger> |
|||
); |
|||
}; |
|||
|
|||
export default OSSUpload; |
@ -0,0 +1,45 @@ |
|||
// @ts-ignore
|
|||
/* eslint-disable */ |
|||
import { request } from '@umijs/max'; |
|||
|
|||
/** 此处后端没有提供注释 GET /api/citrus/register/getApp */ |
|||
export async function getApp( |
|||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
|||
params: API.getAppParams, |
|||
options?: { [key: string]: any }, |
|||
) { |
|||
return request<API.RMatrixAppBo>('/api/citrus/register/getApp', { |
|||
method: 'GET', |
|||
params: { |
|||
...params, |
|||
}, |
|||
...(options || {}), |
|||
}); |
|||
} |
|||
|
|||
/** 此处后端没有提供注释 POST /api/citrus/register/sendCode */ |
|||
export async function sendCode( |
|||
// 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
|
|||
params: API.sendCodeParams, |
|||
options?: { [key: string]: any }, |
|||
) { |
|||
return request<API.RVoid>('/api/citrus/register/sendCode', { |
|||
method: 'POST', |
|||
params: { |
|||
...params, |
|||
}, |
|||
...(options || {}), |
|||
}); |
|||
} |
|||
|
|||
/** 此处后端没有提供注释 POST /api/citrus/register/submitRegister */ |
|||
export async function submitRegister(body: API.RegisterBo, options?: { [key: string]: any }) { |
|||
return request<API.RVoid>('/api/citrus/register/submitRegister', { |
|||
method: 'POST', |
|||
headers: { |
|||
'Content-Type': 'application/json', |
|||
}, |
|||
data: body, |
|||
...(options || {}), |
|||
}); |
|||
} |
@ -0,0 +1,21 @@ |
|||
import SparkMD5 from 'spark-md5'; |
|||
|
|||
async function toMD5(file: File): Promise<string> { |
|||
return new Promise((resolve, reject) => { |
|||
const spark = new SparkMD5.ArrayBuffer(); |
|||
const fileReader = new FileReader(); |
|||
|
|||
fileReader.onload = (e) => { |
|||
spark.append(e.target?.result as ArrayBuffer); |
|||
resolve(spark.end()); |
|||
}; |
|||
|
|||
fileReader.onerror = (err) => { |
|||
reject(err); |
|||
}; |
|||
|
|||
fileReader.readAsArrayBuffer(file); |
|||
}); |
|||
} |
|||
|
|||
export { toMD5 }; |
Loading…
Reference in new issue