Commit b0144a88 by chenwq1

fix: 提交

1 parent b360d66e
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"configurations" : [ "configurations" : [
{ {
"customPlaygroundType" : "local", "customPlaygroundType" : "local",
"playground" : "custom", "playground" : "standard",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {
......
...@@ -142,6 +142,27 @@ export async function getSoureData( ...@@ -142,6 +142,27 @@ export async function getSoureData(
if (dataObj.materialInfoList != null) { if (dataObj.materialInfoList != null) {
materialInfoList = dataObj.materialInfoList as Array<any>; materialInfoList = dataObj.materialInfoList as Array<any>;
} }
if (toolList.length == 0 && materialInfoList.length > 0) {
toolList = materialInfoList.map((item: any) => {
const obj = item as UTSJSONObject;
const shortTitle =
(obj.materialTitle as null | string)
?? (obj.detailTitle as null | string)
?? (obj.materialName as null | string)
?? "";
const shortTitleUrl =
(obj.thumbnail as null | string)
?? (obj.thumbnailUrl as null | string)
?? (obj.homeEntranceCover as null | string)
?? (obj.contentPicUrl as null | string)
?? "";
return {
id: obj.id,
shortTitle,
shortTitleUrl
} as UTSJSONObject;
});
}
const insurance = (materialInfoList as Array<any>).find((e: any) => (e as UTSJSONObject).componentName == "insurance"); const insurance = (materialInfoList as Array<any>).find((e: any) => (e as UTSJSONObject).componentName == "insurance");
const hasEquity = (toolList as Array<any>).find((e: any) => (e as UTSJSONObject).id == (insurance as UTSJSONObject).id); const hasEquity = (toolList as Array<any>).find((e: any) => (e as UTSJSONObject).id == (insurance as UTSJSONObject).id);
...@@ -264,6 +285,14 @@ async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): P ...@@ -264,6 +285,14 @@ async function imgTransformBase64(imgList: Array<any>= [], keyList: string[]): P
/** 转 base64 */ /** 转 base64 */
async function getBase64(url: string): Promise<string> { async function getBase64(url: string): Promise<string> {
function isProbablyBase64(raw: string): boolean {
if (raw == null || raw == "") return false;
const cleaned = raw.replace(/\s/g, "");
if (cleaned.length < 16) return false;
if ((cleaned.length % 4) != 0) return false;
return /^[A-Za-z0-9+/=]+$/.test(cleaned);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
url, url,
...@@ -281,15 +310,25 @@ async function getBase64(url: string): Promise<string> { ...@@ -281,15 +310,25 @@ async function getBase64(url: string): Promise<string> {
} }
if (typeof data === "string") { if (typeof data === "string") {
base64 = `data:image/png;base64,${data}`; const strData = (data as string).trim();
if (strData.startsWith("data:image/")) {
// 已是 data URI,直接返回
resolve(strData);
return;
}
const cleaned = strData.replace(/\s/g, "");
if (isProbablyBase64(cleaned)) {
base64 = `data:image/png;base64,${cleaned}`;
} else {
// 某些端会回二进制乱码字符串(如 "�PNG..."),该值不可直接作为 base64
resolve(url);
return;
}
} else { } else {
base64 = `data:image/png;base64,${uni.arrayBufferToBase64(data as ArrayBuffer)}`; base64 = `data:image/png;base64,${uni.arrayBufferToBase64(data as ArrayBuffer)}`;
} }
console.log("转换后的 base64:", `${base64.slice(0, 50) }...`);
resolve(base64); resolve(base64);
} catch (error) { } catch (error) {
console.error("转换 base64 失败:", error, "res.data:", res.data);
resolve(url); resolve(url);
} }
}, },
......
...@@ -171,7 +171,7 @@ type TabItem = { ...@@ -171,7 +171,7 @@ type TabItem = {
const tabs: TabItem[] = [ const tabs: TabItem[] = [
{ label: "首页", icon: "home", name: "HomeSlot" }, { label: "首页", icon: "home", name: "HomeSlot" },
{ label: "接待中心", icon: "record", name: "ReceptionCenter" }, { label: "接待中心", icon: "record", name: "ReceptionCenter" },
{ label: "学习中心", icon: "study", name: "StudyCenter" }, { label: "我的", icon: "my", name: "MyCenter" },
// { label: "场景集市", icon: "scene", name: "SceneMarket" }, // { label: "场景集市", icon: "scene", name: "SceneMarket" },
// { label: "活动中心", icon: "activity", name: "ActivityCenter" } // { label: "活动中心", icon: "activity", name: "ActivityCenter" }
]; ];
...@@ -186,6 +186,9 @@ function getTabIconSrc(icon: string, active: boolean): string { ...@@ -186,6 +186,9 @@ function getTabIconSrc(icon: string, active: boolean): string {
if (icon === "study") { if (icon === "study") {
return active ? "/static/images/tabbar/study-active.png" : "/static/images/tabbar/study.png"; return active ? "/static/images/tabbar/study-active.png" : "/static/images/tabbar/study.png";
} }
if (icon === "my") {
return active ? "/static/images/tabbar/study-active.png" : "/static/images/tabbar/study.png";
}
return "/static/images/tabbar/home.png"; return "/static/images/tabbar/home.png";
} }
......
<template>
<view class="my-center">
<scroll-view class="my-scroll" :scroll-y="true" :show-scrollbar="false">
<view class="my-content">
<view class="profile-head">
<un-avatar :text="avatarText"
shape="circle"
size="52"
bgColor="#2f6af7"
color="#ffffff"
fontSize="20" />
<text class="name">{{ userName }}</text>
</view>
<un-gap height="12" bg-color="transparent"></un-gap>
<view class="section-block">
<un-cell-group title="账号信息" :border="false" round="14" backgroundColor="#ffffff">
<un-cell title="姓名"
:value="userName"
icon="account-fill" />
<un-cell title="门店"
:value="shopName"
icon="home-fill" />
<un-cell title="手机号"
:value="plainPhone"
icon="phone-fill" />
<un-cell title="当前场景"
:value="currentSceneTitle"
icon="grid-fill" />
</un-cell-group>
</view>
<un-gap height="12" bg-color="transparent"></un-gap>
<view class="section-block">
<un-cell-group title="常用功能" :border="false" round="14" backgroundColor="#ffffff">
<un-cell title="切换场景"
:value="currentSceneTitle"
icon="grid-fill"
isLink
clickable
@click="onSceneChange" />
<un-cell title="个人考勤"
icon="clock-fill"
isLink
clickable
@click="goAttendance" />
<un-cell title="系统设置"
icon="setting-fill"
isLink
clickable
@click="onSetting" />
</un-cell-group>
</view>
</view>
</scroll-view>
<CenterPopup :list="sceneTypeList"
title="选择场景"
:visible="showScenePopup"
@choose="onChooseScene"
@update:visible="onScenePopupVisible" />
<SettingBox :visible="showSetting"
@update:visible="onSettingVisible" />
</view>
</template>
<script setup lang="uts">
import { computed, ref } from "vue";
import CenterPopup from "@/components/CenterPopup.uvue";
import { storage } from "@/utils/storage.uts";
import SettingBox from "./SettingBox.uvue";
const props = defineProps<{
userInfo?: null | UTSJSONObject
}>();
type SceneTypeItem = { title: string; describe: string; icon: string; };
const showScenePopup = ref(false);
const showSetting = ref(false);
function getSceneTypeItem(sceneId: number): null | SceneTypeItem {
if (sceneId == 1) return { title: "轻改", describe: "太阳膜升级转化", icon: "轻" };
if (sceneId == 0) return { title: "会员权益/升级", describe: "权益延保", icon: "权" };
if (sceneId == 7) return { title: "二手车", describe: "二手车业务", icon: "二" };
return null;
}
const sceneTypeIdList = computed((): number[] => {
const info = props.userInfo;
let openArr: number[] = [1, 0, 7];
if (info != null) {
const arr = (info as UTSJSONObject).openSceneArr as null | number[];
if (arr != null && arr.length > 0) {
openArr = arr;
}
}
const result: number[] = [];
for (const e of openArr) {
if (e == 1 || e == 0 || e == 7) {
result.push(e);
}
}
return result.length > 0 ? result : [1, 0, 7];
});
const sceneTypeList = computed((): UTSJSONObject[] => {
const result: UTSJSONObject[] = [];
for (const id of sceneTypeIdList.value) {
const item = getSceneTypeItem(id);
if (item != null) {
result.push({ title: item.title, describe: item.describe, icon: item.icon } as UTSJSONObject);
}
}
return result;
});
const userName = computed((): string => {
const info = props.userInfo;
if (info == null) return "";
const obj = info as UTSJSONObject;
const raw = obj.name ?? obj.staffName ?? obj.merchantName;
return raw != null ? `${raw}` : "";
});
const shopName = computed((): string => {
const info = props.userInfo;
if (info == null) return "";
const obj = info as UTSJSONObject;
const raw = obj.shopMerchantName ?? obj.merchantName ?? "";
return raw != null ? `${raw}` : "";
});
const phoneText = computed((): string => {
const info = props.userInfo;
if (info == null) return "";
const obj = info as UTSJSONObject;
const raw = obj.phone ?? obj.mobile ?? "";
return raw != null && `${raw}` != "" ? `手机号:${raw}` : "";
});
const plainPhone = computed((): string => {
const info = props.userInfo;
if (info == null) return "";
const obj = info as UTSJSONObject;
const raw = obj.phone ?? obj.mobile ?? "";
return raw != null ? `${raw}` : "";
});
const avatarText = computed((): string => {
const name = userName.value;
if (name == "") return "我";
return name.slice(0, 1);
});
const currentSceneTitle = computed((): string => {
const info = props.userInfo;
if (info == null) return "未知";
const sceneType = (info as UTSJSONObject).sceneType as null | number;
if (sceneType == null) return "未知";
const item = getSceneTypeItem(sceneType);
return item != null ? item.title : "未知";
});
function onScenePopupVisible(v: boolean): void {
showScenePopup.value = v;
}
function onSettingVisible(v: boolean): void {
showSetting.value = v;
}
function onSceneChange(): void {
showScenePopup.value = true;
}
function onSetting(): void {
showSetting.value = true;
}
function onChooseScene(index: number): void {
const ids = sceneTypeIdList.value;
if (index < 0 || index >= ids.length) return;
const sceneType = ids[index];
const raw = storage.get("userInfo");
if (raw == null) return;
const info = raw as UTSJSONObject;
const current = info.sceneType as null | number;
if (current != null && current == sceneType) return;
info.sceneType = sceneType;
uni.showLoading({ title: "切换中", mask: true });
storage.set("userInfo", info, 0);
let url = "/pages/boutique/index";
if (sceneType == 0) url = "/pages/equity/index";
else if (sceneType == 7) url = "/pages/usedCar/index";
uni.reLaunch({ url });
}
function goAttendance(): void {
uni.navigateTo({ url: "/pages/person/attendance" });
}
</script>
<style scoped lang="scss">
.my-center {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
background: linear-gradient(180deg, #eef4ff 0%, #f7f9fc 36%, #f7f9fc 100%);
}
.my-scroll {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
padding: 24px;
box-sizing: border-box;
}
.my-content {
width: 100%;
display: flex;
flex-direction: column;
align-items: stretch;
}
.section-block {
width: 100%;
}
.profile-row {
display: flex;
flex-direction: row;
align-items: center;
}
.profile-head {
display: flex;
flex-direction: row;
align-items: center;
padding: 10px 6px 2px;
}
.profile-main {
margin-left: 14px;
display: flex;
flex-direction: column;
flex: 1;
}
.name {
margin-left: 12px;
font-size: 20px;
font-weight: 600;
color: #1a2433;
line-height: 24px;
}
.meta {
margin-top: 4px;
font-size: 13px;
color: #808b9c;
}
.scene-tag {
margin-top: 10px;
}
</style>
...@@ -59,6 +59,9 @@ ...@@ -59,6 +59,9 @@
<ReceptionDetail :item="receptionDetailItem" @close="onReceptionDetailClose" /> <ReceptionDetail :item="receptionDetailItem" @close="onReceptionDetailClose" />
</view> </view>
</view> </view>
<view v-else-if="tabIndex == 2" class="my-center-wrap">
<MyCenter :user-info="userInfo" />
</view>
</view> </view>
<view v-else class="right-side"> <view v-else class="right-side">
...@@ -114,6 +117,9 @@ ...@@ -114,6 +117,9 @@
<ReceptionDetail :item="receptionDetailItem" @close="onReceptionDetailClose" /> <ReceptionDetail :item="receptionDetailItem" @close="onReceptionDetailClose" />
</view> </view>
</view> </view>
<view v-else-if="tabIndex == 2" class="my-center-wrap">
<MyCenter :user-info="userInfo" />
</view>
</view> </view>
<!-- 竖屏:底部 TabBar;横屏:左侧栏 --> <!-- 竖屏:底部 TabBar;横屏:左侧栏 -->
...@@ -153,7 +159,7 @@ import { storage } from "@/utils/storage.uts"; ...@@ -153,7 +159,7 @@ import { storage } from "@/utils/storage.uts";
import HomeFrameLeftSide from "./LeftSide.uvue"; import HomeFrameLeftSide from "./LeftSide.uvue";
import HomeFrameMessageIndex from "./MessageIndex.uvue"; import HomeFrameMessageIndex from "./MessageIndex.uvue";
import ReceptionCenter from "./ReceptionCenter/center.uvue"; import MyCenter from "./MyCenter.uvue";
import ReceptionDetail from "./ReceptionCenter/receptionDetail.uvue"; import ReceptionDetail from "./ReceptionCenter/receptionDetail.uvue";
const props = defineProps<{ const props = defineProps<{
...@@ -213,6 +219,10 @@ function hideDetailPage(): void { ...@@ -213,6 +219,10 @@ function hideDetailPage(): void {
function onChangeTab(index: number): void { function onChangeTab(index: number): void {
console.log('onChangeTabAACCC', index); console.log('onChangeTabAACCC', index);
tabIndex.value = index; tabIndex.value = index;
if (index != 1) {
showReceptionDetail.value = false;
receptionDetailItem.value = {};
}
} }
function onShowReceptionDetail(item: UTSJSONObject): void { function onShowReceptionDetail(item: UTSJSONObject): void {
...@@ -443,10 +453,11 @@ defineExpose({ ...@@ -443,10 +453,11 @@ defineExpose({
flex-direction: column; flex-direction: column;
} }
/* 仅接待中心内容区:收缩 + 裁剪溢出,让内部 scroll-view 获得固定视口高(勿加到 reception-detail-inner,避免裁切详情层) */ .my-center-wrap {
.reception-center-inner { flex: 1;
width: 100%;
height: 100%;
min-height: 0; min-height: 0;
overflow: hidden;
} }
/* 底部门店信息,与旧项目 store-addr 一致:居中、无通栏背景、两侧渐变线 */ /* 底部门店信息,与旧项目 store-addr 一致:居中、无通栏背景、两侧渐变线 */
......
...@@ -167,7 +167,6 @@ defineExpose({ open, close, hide }); ...@@ -167,7 +167,6 @@ defineExpose({ open, close, hide });
overflow: hidden; overflow: hidden;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
max-width: 100vw;
box-sizing: border-box; box-sizing: border-box;
.tips-content { .tips-content {
width: 100%; width: 100%;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view class="reception"> <view class="reception">
<scroll-view class="reception-scroll" <scroll-view class="reception-scroll"
:scroll-y="true"> :scroll-y="true">
<image :src="(props.views as UTSJSONObject).detailUrl" <image :src="getViewImageUrl()"
class="reception-image" class="reception-image"
mode="widthFix"> mode="widthFix">
</image> </image>
...@@ -10,14 +10,174 @@ ...@@ -10,14 +10,174 @@
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { state } from "@/store/index.uts";
const props = defineProps({ const props = defineProps({
views: { views: {
type: UTSJSONObject, type: [UTSJSONObject, Array],
default: (): UTSJSONObject => ({} as UTSJSONObject) default: (): UTSJSONObject => ({} as UTSJSONObject)
}, },
title: String, title: String,
show: Boolean show: Boolean
}); });
function getStringValue(value: any | null): string {
if (value != null && typeof value === "string") {
const str = value as string;
if (str != "") {
return str;
}
}
return "";
}
function isRenderableImage(value: string): boolean {
if (value == null || value == "") {
return false;
}
if (
value.startsWith("http://")
|| value.startsWith("https://")
|| value.startsWith("file://")
|| value.startsWith("content://")
|| value.startsWith("/")
|| value.startsWith("./")
|| value.startsWith("../")
) {
return true;
}
if (value.startsWith("data:image/")) {
const marker = "base64,";
const markerIndex = value.indexOf(marker);
if (markerIndex < 0) {
return false;
}
const raw = value.slice(markerIndex + marker.length).replace(/\s/g, "");
if (raw == "" || raw.length < 16) {
return false;
}
if (raw.indexOf("�") >= 0) {
return false;
}
return /^[A-Za-z0-9+/=]+$/.test(raw);
}
return false;
}
function getPreferredObjectImage(obj: UTSJSONObject): string {
const thumbnail = getStringValue(obj["thumbnail"] as any | null);
if (thumbnail != "" && isRenderableImage(thumbnail)) {
return thumbnail;
}
const thumbnailUrl = getStringValue(obj["thumbnailUrl"] as any | null);
if (thumbnailUrl != "" && isRenderableImage(thumbnailUrl)) {
return thumbnailUrl;
}
const detailUrl = getStringValue(obj["detailUrl"] as any | null);
if (detailUrl != "" && isRenderableImage(detailUrl)) {
return detailUrl;
}
return "";
}
function getImageFromArray(list: Array<any>): string {
const customerInfo = state.user.customerInfo as UTSJSONObject;
const carModelId = customerInfo != null ? customerInfo["carModelId"] : null;
if (carModelId != null) {
for (const item of list) {
if (item == null || typeof item !== "object") {
continue;
}
const itemObj = item as UTSJSONObject;
if (itemObj["carModelId"] == carModelId) {
const matchedUrl = getPreferredObjectImage(itemObj);
if (matchedUrl != "") {
return matchedUrl;
}
}
}
}
for (const item of list) {
if (item == null) {
continue;
}
if (typeof item === "string") {
const directUrl = getStringValue(item);
if (directUrl != "") {
return directUrl;
}
continue;
}
const itemObj = item as UTSJSONObject;
const url = getPreferredObjectImage(itemObj);
if (url != "") {
return url;
}
}
return "";
}
function getImageFromObject(obj: UTSJSONObject): string {
const directUrl = getPreferredObjectImage(obj);
if (directUrl != "") {
return directUrl;
}
const customerInfo = state.user.customerInfo as UTSJSONObject;
if (customerInfo != null) {
const carModelId = customerInfo["carModelId"];
if (carModelId != null) {
const modelValue: any | null = obj[`${carModelId}`];
if (typeof modelValue === "string") {
const modelUrl = getStringValue(modelValue);
if (modelUrl != "") {
return modelUrl;
}
} else if (modelValue != null && typeof modelValue === "object") {
const modelObj = modelValue as UTSJSONObject;
const modelUrl = getPreferredObjectImage(modelObj);
if (modelUrl != "") {
return modelUrl;
}
}
}
}
for (const key in obj) {
const value = obj[key];
if (typeof value === "string") {
const url = getStringValue(value);
if (url != "") {
return url;
}
continue;
}
if (value != null && typeof value === "object") {
const nestedObj = value as UTSJSONObject;
const nestedUrl = getPreferredObjectImage(nestedObj);
if (nestedUrl != "") {
return nestedUrl;
}
}
}
return "";
}
function getViewImageUrl(): string {
const views = props.views;
if (views == null) {
return "";
}
if (Array.isArray(views)) {
return getImageFromArray(views as Array<any>);
}
if (typeof views === "object") {
return getImageFromObject(views as UTSJSONObject);
}
return "";
}
</script> </script>
<style lang="scss"> <style lang="scss">
.reception { .reception {
...@@ -36,6 +196,5 @@ ...@@ -36,6 +196,5 @@
.reception-image { .reception-image {
width: 100%; width: 100%;
display: block;
} }
</style> </style>
...@@ -160,18 +160,59 @@ const penSwitch = computed<boolean>(() => { ...@@ -160,18 +160,59 @@ const penSwitch = computed<boolean>(() => {
return isPreview.value == false && drawStatus.value == true; return isPreview.value == false && drawStatus.value == true;
}); });
function getModuleDisplayTitle(obj: UTSJSONObject): string {
const title =
(obj["detailTitle"] as null | string)
?? (obj["materialTitle"] as null | string)
?? (obj["shortTitle"] as null | string)
?? (obj["materialName"] as null | string)
?? (obj["title"] as null | string)
?? "";
return title;
}
function isRenderableImage(value: string): boolean {
if (value == null || value == "") {
return false;
}
if (
value.startsWith("http://")
|| value.startsWith("https://")
|| value.startsWith("file://")
|| value.startsWith("content://")
|| value.startsWith("/")
|| value.startsWith("./")
|| value.startsWith("../")
) {
return true;
}
if (value.startsWith("data:image/")) {
const marker = "base64,";
const markerIndex = value.indexOf(marker);
if (markerIndex < 0) {
return false;
}
const raw = value.slice(markerIndex + marker.length).replace(/\s/g, "");
if (raw == "" || raw.length < 16) {
return false;
}
if (raw.indexOf("�") >= 0) {
return false;
}
return /^[A-Za-z0-9+/=]+$/.test(raw);
}
return false;
}
const title = computed(() => { const title = computed(() => {
for (const e of media.value) { for (const e of media.value) {
if ((e as UTSJSONObject).id == id.value) { if ((e as UTSJSONObject).id == id.value) {
const titleValue = (e as UTSJSONObject).detailTitle; return getModuleDisplayTitle(e as UTSJSONObject);
return titleValue != null ? titleValue as string : "";
} }
} }
for (const m of moduleList.value) { for (const m of moduleList.value) {
if ((m as UTSJSONObject).id == id.value) { if ((m as UTSJSONObject).id == id.value) {
const titleValue = (m as UTSJSONObject).detailTitle; return getModuleDisplayTitle(m as UTSJSONObject);
return titleValue != null ? titleValue as string : "";
} }
} }
return ""; return "";
...@@ -188,13 +229,27 @@ function toolItemsFromModuleList(modules: Array<any>): Array<any> { ...@@ -188,13 +229,27 @@ function toolItemsFromModuleList(modules: Array<any>): Array<any> {
const out: Array<any> = []; const out: Array<any> = [];
for (let i = 0; i < modules.length; i++) { for (let i = 0; i < modules.length; i++) {
const o = modules[i] as UTSJSONObject; const o = modules[i] as UTSJSONObject;
const detailTitle = o["detailTitle"] as string; const detailTitle = getModuleDisplayTitle(o);
const rid = o["id"]; const rid = o["id"];
const src = o["receptionSourceDetailList"] as UTSJSONObject; const src = o["receptionSourceDetailList"] as UTSJSONObject;
let url = ""; let url = "";
if (src != null) { if (src != null) {
const du = src["detailUrl"] as string; const thumbRaw: any | null = src["thumbnail"];
url = du != null ? du : ""; if (thumbRaw != null && typeof thumbRaw === "string" && isRenderableImage(thumbRaw as string)) {
url = thumbRaw as string;
}
if (url == "") {
const thumbUrlRaw: any | null = src["thumbnailUrl"];
if (thumbUrlRaw != null && typeof thumbUrlRaw === "string" && isRenderableImage(thumbUrlRaw as string)) {
url = thumbUrlRaw as string;
}
}
if (url == "") {
const duRaw: any | null = src["detailUrl"];
if (duRaw != null && typeof duRaw === "string" && isRenderableImage(duRaw as string)) {
url = duRaw as string;
}
}
} }
out.push({ out.push({
id: rid, id: rid,
...@@ -229,7 +284,7 @@ function setViewInfo(data: any): void { ...@@ -229,7 +284,7 @@ function setViewInfo(data: any): void {
break; break;
} }
} }
const detailTitle = findItem != null ? (findItem.detailTitle != null ? findItem.detailTitle : "") : ""; const detailTitle = findItem != null ? getModuleDisplayTitle(findItem) : "";
// receptionTrackLeave() // receptionTrackLeave()
console.log(data); console.log(data);
let dataObj: UTSJSONObject = {} as UTSJSONObject; let dataObj: UTSJSONObject = {} as UTSJSONObject;
...@@ -252,6 +307,12 @@ function setViewInfo(data: any): void { ...@@ -252,6 +307,12 @@ function setViewInfo(data: any): void {
// 处理 moduleList 的空值情况 // 处理 moduleList 的空值情况
const moduleListData: Array<any> = dataObj.moduleList != null ? dataObj.moduleList as Array<any> : []; const moduleListData: Array<any> = dataObj.moduleList != null ? dataObj.moduleList as Array<any> : [];
for (const item of moduleListData) {
const itemObj = item as UTSJSONObject;
if (itemObj["detailTitle"] == null || itemObj["detailTitle"] == "") {
itemObj["detailTitle"] = getModuleDisplayTitle(itemObj);
}
}
moduleList.value = moduleListData; moduleList.value = moduleListData;
// 处理 toolList 的空值情况(无 toolList 时用 module 推导,与 onLoad / 滑动一致) // 处理 toolList 的空值情况(无 toolList 时用 module 推导,与 onLoad / 滑动一致)
...@@ -267,7 +328,7 @@ function setViewInfo(data: any): void { ...@@ -267,7 +328,7 @@ function setViewInfo(data: any): void {
if (id.value != currentMediaId.value) { if (id.value != currentMediaId.value) {
let jumpItem: UTSJSONObject = {} as UTSJSONObject; let jumpItem: UTSJSONObject = {} as UTSJSONObject;
for (const e of moduleListData) { for (const e of moduleListData) {
if ((e as UTSJSONObject).detailTitle == detailTitle) { if (getModuleDisplayTitle(e as UTSJSONObject) == detailTitle) {
jumpItem = e as UTSJSONObject; jumpItem = e as UTSJSONObject;
break; break;
} }
......
...@@ -76,8 +76,105 @@ const toolList = ref<Array<any>>([]); ...@@ -76,8 +76,105 @@ const toolList = ref<Array<any>>([]);
const mediaId = ref<number | string>(""); const mediaId = ref<number | string>("");
const currentSwiperIndex = ref<number>(0); const currentSwiperIndex = ref<number>(0);
function normalizeModuleItem(item: any): UTSJSONObject {
const obj = item as UTSJSONObject;
const detailTitle =
(obj.detailTitle as null | string)
?? (obj.materialTitle as null | string)
?? (obj.shortTitle as null | string)
?? (obj.materialName as null | string)
?? (obj.title as null | string)
?? (obj.name as null | string)
?? "";
const briefIntroduction =
(obj.briefIntroduction as null | string)
?? (obj.productIntroduction as null | string)
?? (obj.introduction as null | string)
?? (obj.desc as null | string)
?? "";
return {
...obj,
detailTitle,
briefIntroduction
} as UTSJSONObject;
}
function normalizeViewData(data: any): UTSJSONObject {
const src = data as UTSJSONObject;
const rawModuleList =
(src.moduleList as null | Array<any>)
?? (src.materialInfoList as null | Array<any>)
?? [];
const modules = rawModuleList.map((item: any) => normalizeModuleItem(item));
const tools = (src.toolList as null | Array<any>) ?? [];
return {
...src,
moduleList: modules,
toolList: tools
} as UTSJSONObject;
}
function isRenderableImage(value: string): boolean {
if (value == null || value == "") {
return false;
}
if (
value.startsWith("http://")
|| value.startsWith("https://")
|| value.startsWith("file://")
|| value.startsWith("content://")
|| value.startsWith("/")
|| value.startsWith("./")
|| value.startsWith("../")
) {
return true;
}
if (value.startsWith("data:image/")) {
const marker = "base64,";
const markerIndex = value.indexOf(marker);
if (markerIndex < 0) {
return false;
}
const raw = value.slice(markerIndex + marker.length).replace(/\s/g, "");
if (raw == "" || raw.length < 16) {
return false;
}
if (raw.indexOf("�") >= 0) {
return false;
}
return /^[A-Za-z0-9+/=]+$/.test(raw);
}
return false;
}
function pickModuleCover(obj: UTSJSONObject): string {
const candidates = [
obj.thumbnail as any | null,
obj.thumbnailUrl as any | null,
obj.bannerImg as any | null,
obj.contentPicUrl as any | null,
obj.homeEntranceCover as any | null,
obj.imageUrl as any | null,
obj.imgUrl as any | null,
obj.coverUrl as any | null,
obj.coverImg as any | null,
obj.productPoster as any | null,
obj.detailUrl as any | null
];
for (const candidate of candidates) {
if (candidate == null || typeof candidate !== "string") {
continue;
}
const src = candidate as string;
if (isRenderableImage(src)) {
return src;
}
}
return "";
}
function setViewInfo(data: any): void { function setViewInfo(data: any): void {
const dataObj = data as UTSJSONObject; const dataObj = normalizeViewData(data);
moduleList.value = dataObj.moduleList as Array<any>; moduleList.value = dataObj.moduleList as Array<any>;
toolList.value = dataObj.toolList as Array<any>; toolList.value = dataObj.toolList as Array<any>;
currentSwiperIndex.value = 0; currentSwiperIndex.value = 0;
...@@ -89,20 +186,7 @@ function setViewInfo(data: any): void { ...@@ -89,20 +186,7 @@ function setViewInfo(data: any): void {
if (moduleList.value.length > 0) { if (moduleList.value.length > 0) {
console.log("[equity] setViewInfo first module:", moduleList.value[0]); console.log("[equity] setViewInfo first module:", moduleList.value[0]);
const firstObj = moduleList.value[0] as UTSJSONObject; const firstObj = moduleList.value[0] as UTSJSONObject;
const firstCover = const firstCover = pickModuleCover(firstObj);
(firstObj.bannerImg as null | string)
?? (firstObj.contentPicUrl as null | string)
?? (firstObj.homeEntranceCover as null | string)
?? (firstObj.imageUrl as null | string)
?? (firstObj.imgUrl as null | string)
?? (firstObj.coverUrl as null | string)
?? (firstObj.coverImg as null | string)
?? (firstObj.productPoster as null | string)
?? (firstObj.detailUrl as null | string)
?? (firstObj.thumbnailUrl as null | string)
?? (firstObj.thumbnail as null | string)
?? "";
console.log("[equity] setViewInfo first module cover:", firstCover);
} }
// 直接将数据属性设置到 state.user 上 // 直接将数据属性设置到 state.user 上
...@@ -131,7 +215,14 @@ function handleStart(): void { ...@@ -131,7 +215,14 @@ function handleStart(): void {
function getModuleName(item: any): string { function getModuleName(item: any): string {
const obj = item as UTSJSONObject; const obj = item as UTSJSONObject;
const value = (obj.name as null | string) ?? (obj.title as null | string) ?? ""; const value =
(obj.detailTitle as null | string)
?? (obj.materialTitle as null | string)
?? (obj.shortTitle as null | string)
?? (obj.materialName as null | string)
?? (obj.name as null | string)
?? (obj.title as null | string)
?? "";
return value; return value;
} }
...@@ -139,6 +230,7 @@ function getModuleDesc(item: any): string { ...@@ -139,6 +230,7 @@ function getModuleDesc(item: any): string {
const obj = item as UTSJSONObject; const obj = item as UTSJSONObject;
const value = const value =
(obj.briefIntroduction as null | string) (obj.briefIntroduction as null | string)
?? (obj.materialIntroduction as null | string)
?? (obj.productIntroduction as null | string) ?? (obj.productIntroduction as null | string)
?? (obj.introduction as null | string) ?? (obj.introduction as null | string)
?? (obj.desc as null | string) ?? (obj.desc as null | string)
...@@ -146,22 +238,76 @@ function getModuleDesc(item: any): string { ...@@ -146,22 +238,76 @@ function getModuleDesc(item: any): string {
return value; return value;
} }
function getReceptionCover(obj: UTSJSONObject): string {
const source = obj.receptionSourceDetailList;
if (source == null) {
return "";
}
if (Array.isArray(source)) {
const list = source as Array<any>;
for (const item of list) {
if (item == null) {
continue;
}
const itemObj = item as UTSJSONObject;
const detailUrl = itemObj.detailUrl as string;
if (detailUrl != null && isRenderableImage(detailUrl)) {
return detailUrl;
}
}
return "";
}
if (typeof source === "object") {
const sourceObj = source as UTSJSONObject;
const detailUrl = sourceObj.detailUrl as string;
if (detailUrl != null && isRenderableImage(detailUrl)) {
return detailUrl;
}
for (const key in sourceObj) {
const value = sourceObj[key];
if (value != null && typeof value === "string" && isRenderableImage(value as string)) {
return value as string;
}
if (value != null && typeof value === "object") {
const nestedObj = value as UTSJSONObject;
const nestedUrl = nestedObj.detailUrl as string;
if (nestedUrl != null && isRenderableImage(nestedUrl)) {
return nestedUrl;
}
}
}
}
return "";
}
function getToolCoverById(moduleId: any | null): string {
if (moduleId == null) {
return "";
}
for (const item of toolList.value) {
const itemObj = item as UTSJSONObject;
if (itemObj.id == moduleId) {
const cover = itemObj.shortTitleUrl as string;
if (cover != null && isRenderableImage(cover)) {
return cover;
}
}
}
return "";
}
function getModuleCover(item: any): string { function getModuleCover(item: any): string {
const obj = item as UTSJSONObject; const obj = item as UTSJSONObject;
const value = const value = pickModuleCover(obj);
(obj.bannerImg as null | string) if (value != null && value != "") {
?? (obj.contentPicUrl as null | string)
?? (obj.homeEntranceCover as null | string)
?? (obj.imageUrl as null | string)
?? (obj.imgUrl as null | string)
?? (obj.coverUrl as null | string)
?? (obj.coverImg as null | string)
?? (obj.productPoster as null | string)
?? (obj.detailUrl as null | string)
?? (obj.thumbnailUrl as null | string)
?? (obj.thumbnail as null | string)
?? "";
return value; return value;
}
const receptionCover = getReceptionCover(obj);
if (receptionCover != "") {
return receptionCover;
}
const moduleId: any | null = obj.id;
return getToolCoverById(moduleId);
} }
function getCurrentModuleTitle(): string { function getCurrentModuleTitle(): string {
...@@ -176,6 +322,9 @@ function getCurrentModuleTitle(): string { ...@@ -176,6 +322,9 @@ function getCurrentModuleTitle(): string {
const obj = item as UTSJSONObject; const obj = item as UTSJSONObject;
const value = const value =
(obj.detailTitle as null | string) (obj.detailTitle as null | string)
?? (obj.materialTitle as null | string)
?? (obj.shortTitle as null | string)
?? (obj.materialName as null | string)
?? (obj.title as null | string) ?? (obj.title as null | string)
?? (obj.name as null | string) ?? (obj.name as null | string)
?? ""; ?? "";
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!