|
|
|
@ -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;
|
|
|
|
|