diff --git a/miniprogram/ai-camera/src/apis/api.ts b/miniprogram/ai-camera/src/apis/api.ts
index 2480236c..c0298729 100644
--- a/miniprogram/ai-camera/src/apis/api.ts
+++ b/miniprogram/ai-camera/src/apis/api.ts
@@ -53,3 +53,12 @@ export const getImgHistory = (params: any) => {
data: params,
});
};
+
+//制作图片 https://www.hzkjai.com/QingLong/HuiYa/wxAddTask
+export const makeImg = (params: any) => {
+ return http({
+ method: "POST",
+ url: "/QingLong/HuiYa/wxAddTask",
+ data: params,
+ });
+};
diff --git a/miniprogram/ai-camera/src/pages/home/home.ts b/miniprogram/ai-camera/src/pages/home/home.ts
index 03a4bbce..af1ba91e 100644
--- a/miniprogram/ai-camera/src/pages/home/home.ts
+++ b/miniprogram/ai-camera/src/pages/home/home.ts
@@ -59,7 +59,11 @@ export default function () {
const init = async () => {
const info: any = await wxLogin();
+ data.pageNum = 1;
+ data.totalPage = 0;
data.token = info.token;
+ data.hotList = [];
+ data.modelId = "";
getHotListFn();
};
@@ -93,23 +97,6 @@ export default function () {
getHotListFn();
}
- const toUpload = () => {
- uni.chooseImage({
- count: 1,
- success: (res) => {
- console.log(res);
- },
- complete: (res) => {
- console.log("complete", res);
- data.imgUrl = res.tempFilePaths[0];
- },
- });
- };
-
- function loadImg() {
- console.log("加载完成");
- }
-
//到制作同款页面
function toMake(index: number) {
const model = data.hotList.find((item: any) => {
@@ -130,10 +117,8 @@ export default function () {
return {
data,
- toUpload,
changeList,
changeModelId,
- loadImg,
toMake,
};
}
diff --git a/miniprogram/ai-camera/src/pages/make/make.ts b/miniprogram/ai-camera/src/pages/make/make.ts
index 7f9454fa..e4b35acc 100644
--- a/miniprogram/ai-camera/src/pages/make/make.ts
+++ b/miniprogram/ai-camera/src/pages/make/make.ts
@@ -1,9 +1,11 @@
import { reactive } from "vue";
import { onLoad } from "@dcloudio/uni-app";
-import { getModelToMake, getImgHistory } from "@/apis/api";
+import { getModelToMake, getImgHistory, makeImg } from "@/apis/api";
export default function () {
const token = uni.getStorageSync("token");
+ const { screenWidth } = uni.getWindowInfo();
+
const data: any = reactive({
moduleId: "",
promptId: "",
@@ -22,11 +24,17 @@ export default function () {
contentnomore: "没有更多数据了~",
},
loadStatus: "more",
+ tempImgUrl: "", //上传文件路径
+ isMaking: false, //正在制作
+ isDisabled: false, //按钮在上传时禁用
+ imgWidth: Math.floor((screenWidth - 60) / 3), //历史图片适配宽度
});
onLoad((options: any) => {
data.moduleId = options.modelId;
data.promptId = options.promptId;
+ console.log(data);
+
getModelToMakeFn();
getImgHistoryFn();
});
@@ -86,10 +94,74 @@ export default function () {
// }
// }
+ //上传图片
+ function toUpload() {
+ uni.chooseImage({
+ count: 1,
+ success: (res) => {
+ data.tempImgUrl = res.tempFilePaths[0];
+ },
+ fail: (err) => {
+ uni.showToast({
+ icon: "none",
+ title: "图片上传失败!",
+ });
+ },
+ });
+ }
+
+ //删除临时上传图片
+ function deleteTemp() {
+ data.tempImgUrl = "";
+ }
+
+ //历史转临时上传文件
+ function convertTemp(url: string) {
+ data.tempImgUrl = url;
+ }
+
//立即制作
- function toMake() {}
+ function toMake() {
+ if (data.tempImgUrl && data.tempImgUrl !== "") {
+ const param = {
+ model_id: data.moduleId,
+ prompt_id: data.promptId,
+ token: data.token,
+ source_img_url: data.tempImgUrl,
+ count: 1,
+ };
+ data.isMaking = true;
+ makeImg(param).then((res: any) => {
+ data.isMaking = false;
+ if (res.success) {
+ uni.showToast({
+ duration: 3500,
+ icon: "none",
+ title: res.estimation_finish_time,
+ });
+ data.isDisabled = true;
+ setTimeout(() => {
+ uni.navigateBack();
+ }, 3500);
+ } else {
+ uni.showToast({
+ icon: "none",
+ title: res.message,
+ });
+ }
+ });
+ } else {
+ uni.showToast({
+ icon: "none",
+ title: "请上传图片!",
+ });
+ }
+ }
return {
data,
toMake,
+ toUpload,
+ deleteTemp,
+ convertTemp,
};
}
diff --git a/miniprogram/ai-camera/src/pages/make/make.vue b/miniprogram/ai-camera/src/pages/make/make.vue
index 52e981b1..ce6d594e 100644
--- a/miniprogram/ai-camera/src/pages/make/make.vue
+++ b/miniprogram/ai-camera/src/pages/make/make.vue
@@ -35,7 +35,24 @@
上传照片
-