61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
|
"use strict";
|
||
|
var __async = (__this, __arguments, generator) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
var fulfilled = (value) => {
|
||
|
try {
|
||
|
step(generator.next(value));
|
||
|
} catch (e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
};
|
||
|
var rejected = (value) => {
|
||
|
try {
|
||
|
step(generator.throw(value));
|
||
|
} catch (e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
};
|
||
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||
|
step((generator = generator.apply(__this, __arguments)).next());
|
||
|
});
|
||
|
};
|
||
|
const common_vendor = require("../common/vendor.js");
|
||
|
const utils_http = require("../utils/http.js");
|
||
|
const chooseImage = () => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
common_vendor.index.chooseImage({
|
||
|
count: 1,
|
||
|
success: (res) => __async(exports, null, function* () {
|
||
|
try {
|
||
|
const filePath = res.tempFilePaths[0];
|
||
|
const uploadedUrl = yield uploadImage(filePath);
|
||
|
resolve(uploadedUrl);
|
||
|
} catch (error) {
|
||
|
reject(error);
|
||
|
}
|
||
|
}),
|
||
|
fail: () => {
|
||
|
common_vendor.index.showToast({ title: "图片选择失败", icon: "none" });
|
||
|
reject(new Error("图片选择失败"));
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
const uploadImage = (filePath) => __async(exports, null, function* () {
|
||
|
try {
|
||
|
const uploadResult = yield utils_http.httpUploadFile("/file/upload", filePath);
|
||
|
if (uploadResult && uploadResult.data && uploadResult.data.url) {
|
||
|
return uploadResult.data.url;
|
||
|
} else {
|
||
|
common_vendor.index.showToast({ title: "图片上传失败", icon: "none" });
|
||
|
return "";
|
||
|
}
|
||
|
} catch (error) {
|
||
|
console.error(error);
|
||
|
common_vendor.index.showToast({ title: "图片上传失败", icon: "none" });
|
||
|
return "";
|
||
|
}
|
||
|
});
|
||
|
exports.chooseImage = chooseImage;
|
||
|
//# sourceMappingURL=fileservice.js.map
|