绘智AI相机

main
gongdi 9 months ago
parent 4d15721075
commit 416d184b78

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

@ -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,
});
};

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

@ -33,7 +33,6 @@
</view>
<view class="img-name">{{ item.model_name }}</view>
<uni-icons
v-if="item.target_img_url && item.target_img_url !== ''"
type="trash"
color=""
size="24"
@ -76,14 +75,15 @@ const { data, toUpdateList, imgPreview, toDelete } = getData();
justify-content: space-between;
.work-image {
width: 24.8rem;
height: 26.5rem;
height: 30.5rem;
position: relative;
display: flex;
flex-direction: column;
justify-content: center;
margin-bottom: 1.5rem;
.img-content {
width: 100%;
height: 21.5rem;
height: 26.5rem;
background-color: #484961;
border-radius: 2rem;
display: flex;

@ -79,6 +79,5 @@ const pro = (url: string) => {
export function caleRootFontSize() {
const clientWidth = uni.getSystemInfoSync().windowWidth;
const rootFontSize = (clientWidth / 1080) * 20;
console.log("rootFontSize:", rootFontSize);
uni.setStorageSync("rootFontSize", rootFontSize);
}

@ -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();
}
Loading…
Cancel
Save