feat:"完成页面接口的对接"
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const api_index = require("../../api/index.js");
|
||||
const utils_config = require("../../utils/config.js");
|
||||
if (!Array) {
|
||||
const _easycom_before_after_1 = common_vendor.resolveComponent("before-after");
|
||||
_easycom_before_after_1();
|
||||
@@ -21,6 +22,7 @@ class CaseDetail extends UTS.UTSType {
|
||||
categoryName: { type: String, optional: false },
|
||||
beforeImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
|
||||
afterImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
|
||||
compareAfterImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
|
||||
description: { type: String, optional: false },
|
||||
material: { type: String, optional: false },
|
||||
duration: { type: String, optional: false },
|
||||
@@ -42,6 +44,7 @@ class CaseDetail extends UTS.UTSType {
|
||||
this.categoryName = this.__props__.categoryName;
|
||||
this.beforeImages = this.__props__.beforeImages;
|
||||
this.afterImages = this.__props__.afterImages;
|
||||
this.compareAfterImages = this.__props__.compareAfterImages;
|
||||
this.description = this.__props__.description;
|
||||
this.material = this.__props__.material;
|
||||
this.duration = this.__props__.duration;
|
||||
@@ -63,6 +66,7 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
categoryName: "",
|
||||
beforeImages: [],
|
||||
afterImages: [],
|
||||
compareAfterImages: [],
|
||||
description: "",
|
||||
material: "",
|
||||
duration: "",
|
||||
@@ -76,37 +80,57 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
return common_vendor.__awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const res = yield api_index.getCaseDetail(caseId.value);
|
||||
const data = res.data;
|
||||
caseDetail.value = new CaseDetail(
|
||||
{
|
||||
id: data["id"],
|
||||
title: data["title"],
|
||||
category: data["category"],
|
||||
categoryName: data["categoryName"],
|
||||
beforeImages: data["beforeImages"],
|
||||
afterImages: data["afterImages"],
|
||||
description: data["description"],
|
||||
material: data["material"],
|
||||
duration: data["duration"],
|
||||
price: data["price"],
|
||||
views: data["views"],
|
||||
likes: data["likes"],
|
||||
createTime: data["createTime"]
|
||||
}
|
||||
// 更新标题
|
||||
);
|
||||
common_vendor.index.setNavigationBarTitle({
|
||||
title: caseDetail.value.title
|
||||
if (res.code === 0 && res.data != null) {
|
||||
const data = res.data;
|
||||
const images = data["images"] || [];
|
||||
const beforeImages = data["beforeImages"] || [];
|
||||
const afterImages = data["afterImages"] || [];
|
||||
const createdAt = data["createdAt"] || "";
|
||||
const displayAfterImages = afterImages.length > 0 ? afterImages : images;
|
||||
const compareAfterImages = afterImages.length > 0 ? afterImages : [];
|
||||
caseDetail.value = new CaseDetail(
|
||||
{
|
||||
id: String(data["id"]),
|
||||
title: data["title"],
|
||||
category: data["serviceType"] || "",
|
||||
categoryName: utils_config.getServiceTypeName(data["serviceType"]),
|
||||
beforeImages,
|
||||
afterImages: displayAfterImages,
|
||||
compareAfterImages,
|
||||
description: data["description"],
|
||||
material: data["materials"] || "优质材料",
|
||||
duration: (data["duration"] || 0) + "天",
|
||||
price: data["price"] != null ? "¥" + data["price"] : "面议",
|
||||
views: data["views"] || 0,
|
||||
likes: data["likes"] || 0,
|
||||
createTime: createdAt.split("T")[0] || ""
|
||||
}
|
||||
// 更新标题
|
||||
);
|
||||
common_vendor.index.setNavigationBarTitle({
|
||||
title: caseDetail.value.title
|
||||
});
|
||||
} else {
|
||||
common_vendor.index.showToast({
|
||||
title: res.message || "加载失败",
|
||||
icon: "none"
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/cases/detail.uvue:197", "获取案例详情失败:", error);
|
||||
common_vendor.index.showToast({
|
||||
title: "加载失败",
|
||||
icon: "none"
|
||||
});
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at pages/cases/detail.uvue:173", "获取案例详情失败", e);
|
||||
}
|
||||
});
|
||||
};
|
||||
const previewImages = (index) => {
|
||||
const urls = caseDetail.value.afterImages || [];
|
||||
const current = urls[index] || urls[0] || "";
|
||||
common_vendor.index.previewImage({
|
||||
current: index,
|
||||
urls: caseDetail.value.afterImages
|
||||
current,
|
||||
urls
|
||||
});
|
||||
};
|
||||
const handleFavorite = () => {
|
||||
@@ -164,7 +188,7 @@ const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
f: common_vendor.t(common_vendor.unref(caseDetail).likes),
|
||||
g: common_vendor.p({
|
||||
beforeImage: common_vendor.unref(caseDetail).beforeImages[0] || "",
|
||||
afterImage: common_vendor.unref(caseDetail).afterImages[0] || "",
|
||||
afterImage: common_vendor.unref(caseDetail).compareAfterImages[0] || "",
|
||||
showTitle: true
|
||||
}),
|
||||
h: common_vendor.t(common_vendor.unref(caseDetail).material),
|
||||
|
||||
Reference in New Issue
Block a user