This commit is contained in:
zhutao
2025-12-15 18:03:24 +08:00
parent 05f2882e93
commit 2421ff666a
8 changed files with 84 additions and 12 deletions

View File

@@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"axios": "^1.13.2",
"browser-md5-file": "^1.1.1",
"immer": "^11.0.1",
"lucide-react": "^0.487.0",
"motion": "^12.23.26",

15
pnpm-lock.yaml generated
View File

@@ -11,6 +11,9 @@ importers:
axios:
specifier: ^1.13.2
version: 1.13.2
browser-md5-file:
specifier: ^1.1.1
version: 1.1.1
immer:
specifier: ^11.0.1
version: 11.0.1
@@ -426,6 +429,9 @@ packages:
axios@1.13.2:
resolution: {integrity: sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==}
browser-md5-file@1.1.1:
resolution: {integrity: sha512-9h2UViTtZPhBa7oHvp5mb7MvJaX5OKEPUsplDwJ800OIV+In7BOR3RXOMB78obn2iQVIiS3WkVLhG7Zu1EMwbw==}
call-bind-apply-helpers@1.0.2:
resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==}
engines: {node: '>= 0.4'}
@@ -661,6 +667,9 @@ packages:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'}
spark-md5@2.0.2:
resolution: {integrity: sha512-9WfT+FYBEvlrOOBEs484/zmbtSX4BlGjzXih1qIEWA1yhHbcqgcMHkiwXoWk2Sq1aJjLpcs6ZKV7JxrDNjIlNg==}
tinyglobby@0.2.15:
resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==}
engines: {node: '>=12.0.0'}
@@ -969,6 +978,10 @@ snapshots:
transitivePeerDependencies:
- debug
browser-md5-file@1.1.1:
dependencies:
spark-md5: 2.0.2
call-bind-apply-helpers@1.0.2:
dependencies:
es-errors: 1.3.0
@@ -1232,6 +1245,8 @@ snapshots:
source-map-js@1.2.1: {}
spark-md5@2.0.2: {}
tinyglobby@0.2.15:
dependencies:
fdir: 6.5.0(picomatch@4.0.3)

View File

@@ -9,6 +9,7 @@ import toast, {Toaster} from "react-hot-toast";
import wxShare from "@/wx/wxShare";
import {enterpriseAnalyzeApi} from "@/api/service";
import {useUserStore} from "@/store/user-store";
import {uploadFileQoi} from "@/utils/upload/upload";
export default function App() {
const userStore = useUserStore()
@@ -27,9 +28,11 @@ export default function App() {
* 上传文件
*/
const handleUpload = async (file) => {
try {
handleNextScreen()
let fileUrl = await uploadFileQoi(file, "/analyze")
let res = await enterpriseAnalyzeApi({
analys_image: file,
analys_image: fileUrl,
analys_type: null,
}) as any
if (res.analysis_result.analyze_ret != "success") {
@@ -39,6 +42,9 @@ export default function App() {
}
userStore.setAnalysis(res)
handleNextScreen()
} catch (e) {
setCurrentScreen((prev => prev = 2))
}
};
const handlePayment = () => {

9
src/api/common.ts Normal file
View File

@@ -0,0 +1,9 @@
import request from "@/utils/http/request";
/**
* 获取七牛token
* @param path
*/
export function getQiuTokenApi(path: string) {
return request.get("/get_qiniu_upload_token", {file_key: path})
}

View File

@@ -2,7 +2,7 @@ import request from "@/utils/http/request";
type EnterpriseAnalyzeApi = {
analys_image: File,
analys_image: string,
analys_type: string,
}

View File

@@ -1,3 +1,4 @@
declare module "weixin-js-sdk"
declare module "browser-md5-file"

14
src/utils/common.ts Normal file
View File

@@ -0,0 +1,14 @@
import BMF from 'browser-md5-file'
/**
* 获取md5名字
* @param value
*/
export function getMd5Value(value: any): Promise<string> {
const bmf = new BMF()
return new Promise((resolve) => {
bmf.md5(value, (err: any, md5: string) => {
return resolve(md5)
})
})
}

View File

@@ -0,0 +1,26 @@
import {getMd5Value} from "@/utils/common";
import {getQiuTokenApi} from "@/api/common";
import axios from "axios";
/**
* 七牛上传文件
* @param file
* @param path 路径,格式/xx/x
*/
export async function uploadFileQoi(file: File, path: string): Promise<string | null> {
let uploadOptions = new FormData();
let md5 = await getMd5Value(file)
let suffix = file.name.split('.')[1]
let res = await getQiuTokenApi("效灵" + path + "/" + md5 + '.' + suffix) as any
uploadOptions.append("token", res.up_token)
uploadOptions.append("upload_url", res.upload_url)
uploadOptions.append("imgPrefix", res.domain)
uploadOptions.append("key", res.file_key)
uploadOptions.append("file", file)
let res2: any = await axios.post(res.upload_url, uploadOptions)
let data = res2.data
if (data.key) {
return `https://${res.domain}/${data.key}`
}
return null
}