diff --git a/miniprogram/HuiYa/pages/make_convert/index.js b/miniprogram/HuiYa/pages/make_convert/index.js
index 373781db..cb2251c6 100644
--- a/miniprogram/HuiYa/pages/make_convert/index.js
+++ b/miniprogram/HuiYa/pages/make_convert/index.js
@@ -169,6 +169,7 @@ Page({
let _file = e.detail.files[0];
let _fileUrl = _file.url;
+ console.log(_fileUrl)
let fileExtension = _file.name.split('.').pop();
let fileName = this.getGuid() + "." + fileExtension;
let key = "Images/Upload/" + fileName;
diff --git a/miniprogram/ai-camera/src/apis/api.ts b/miniprogram/ai-camera/src/apis/api.ts
index 906a3198..526c232e 100644
--- a/miniprogram/ai-camera/src/apis/api.ts
+++ b/miniprogram/ai-camera/src/apis/api.ts
@@ -134,3 +134,12 @@ export const wxGetConvertChildModel = (params: any) => {
data: params,
});
};
+
+//获取签名 图片上传使用
+export const wxGetSignature = (params: any) => {
+ return http({
+ method: "POST",
+ url: "/QingLong/HuiYa/wxGetSignature",
+ data: params,
+ });
+};
diff --git a/miniprogram/ai-camera/src/pages/make/make.ts b/miniprogram/ai-camera/src/pages/make/make.ts
index 3a278afb..23bd483b 100644
--- a/miniprogram/ai-camera/src/pages/make/make.ts
+++ b/miniprogram/ai-camera/src/pages/make/make.ts
@@ -1,10 +1,13 @@
import { reactive } from "vue";
import { onLoad } from "@dcloudio/uni-app";
+import { genGuid } from "@/utils/guidUtil";
+
import {
getModelToMake,
getImgHistory,
makeImg,
wxGetConvertChildModel,
+ wxGetSignature,
} from "@/apis/api";
export default function () {
@@ -34,6 +37,7 @@ export default function () {
},
loadStatus: "more",
tempImgUrl: "", //上传文件路径
+ imgCloudUrl: "", //图片云路径
isMaking: false, //正在制作
isDisabled: false, //按钮在上传时禁用
imgWidth: Math.floor((screenWidth - 60) / 3), //历史图片适配宽度
@@ -144,8 +148,90 @@ export default function () {
count: 1,
success: (res) => {
data.tempImgUrl = res.tempFilePaths[0];
+ let fileExtension = data.tempImgUrl.split(".")[1];
+ const guid = genGuid();
+ let fileName = guid + "." + fileExtension;
+ let key = "Images/Upload/" + fileName;
+ if (
+ fileExtension == "png" ||
+ fileExtension == "jpg" ||
+ fileExtension == "jpeg"
+ ) {
+ uni.getImageInfo({
+ src: data.tempImgUrl,
+ success: (info) => {
+ const width = info.width;
+ if (width < 384 || width < 384) {
+ data.tempImgUrl = "";
+ uni.showToast({
+ icon: "none",
+ title: "图片分辨率过小!",
+ });
+ } else {
+ //获取签名
+ const param = {
+ token: data.token,
+ };
+ wxGetSignature(param).then((res: any) => {
+ if (res.success) {
+ let signature = res.data.signature;
+ let policy = res.data.policy;
+ let host = res.data.host;
+ //上传文件到云服务器
+ uni.uploadFile({
+ url: host,
+ filePath: data.tempImgUrl,
+ name: "file",
+ formData: {
+ key: key,
+ policy: policy,
+ OSSAccessKeyId: "LTAI5tE4tgpGcKWhbZg6C4bh",
+ signature: signature,
+ },
+ success: (res) => {
+ if (res.statusCode == 204) {
+ let imgUrl =
+ "http://hzkc.oss-cn-beijing.aliyuncs.com/Images/Upload/" +
+ fileName;
+ data.imgCloudUrl = imgUrl;
+ }
+ },
+ fail: (err) => {
+ data.tempImgUrl = "";
+ uni.showToast({
+ icon: "none",
+ title: "图片上传失败!",
+ });
+ },
+ });
+ } else {
+ data.tempImgUrl = "";
+ uni.showToast({
+ icon: "none",
+ title: "签名获取失败!",
+ });
+ }
+ });
+ }
+ },
+ fail: (err) => {
+ data.tempImgUrl = "";
+ uni.showToast({
+ icon: "none",
+ title: "图片信息获取失败!",
+ });
+ },
+ });
+ } else {
+ data.tempImgUrl = "";
+ uni.showToast({
+ icon: "none",
+ title: "只允许上传.png、.jpg、.jpep 格式!",
+ });
+ }
},
fail: (err) => {
+ data.tempImgUrl = "";
uni.showToast({
icon: "none",
title: "图片上传失败!",
@@ -162,6 +248,7 @@ export default function () {
//历史转临时上传文件
function convertTemp(url: string) {
data.tempImgUrl = url;
+ data.imgCloudUrl = url;
}
//立即制作
@@ -171,7 +258,7 @@ export default function () {
model_id: data.moduleId,
prompt_id: data.promptId,
token: data.token,
- source_img_url: data.tempImgUrl,
+ source_img_url: data.imgCloudUrl,
count: 1,
};
data.isMaking = true;
diff --git a/miniprogram/ai-camera/src/pages/works/works.vue b/miniprogram/ai-camera/src/pages/works/works.vue
index bb1e24c5..5bc8c4f5 100644
--- a/miniprogram/ai-camera/src/pages/works/works.vue
+++ b/miniprogram/ai-camera/src/pages/works/works.vue
@@ -33,7 +33,6 @@
{{ item.model_name }}
{
export function caleRootFontSize() {
const clientWidth = uni.getSystemInfoSync().windowWidth;
const rootFontSize = (clientWidth / 1080) * 20;
- console.log("rootFontSize:", rootFontSize);
uni.setStorageSync("rootFontSize", rootFontSize);
}
diff --git a/miniprogram/ai-camera/src/utils/guidUtil.ts b/miniprogram/ai-camera/src/utils/guidUtil.ts
new file mode 100644
index 00000000..50748c8f
--- /dev/null
+++ b/miniprogram/ai-camera/src/utils/guidUtil.ts
@@ -0,0 +1,32 @@
+function s4() {
+ return Math.floor((1 + Math.random()) * 0x10000)
+ .toString(16)
+ .substring(1);
+}
+
+/**
+ * @returns guid(8-4-4-4-12)
+ */
+export function genGuid() {
+ return (
+ s4() +
+ s4() +
+ "-" +
+ s4() +
+ "-" +
+ s4() +
+ "-" +
+ s4() +
+ "-" +
+ s4() +
+ s4() +
+ s4()
+ );
+}
+
+/**
+ * @returns uuid(32)
+ */
+export function genUuid() {
+ return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
+}