Skip to content

Commit 0818ca1

Browse files
committed
fix:声望默认图片
1 parent 5009c88 commit 0818ca1

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

7.47 KB
Loading

src/components/reputation/ReputationItem.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template>
22
<div class="m-pvx-reputation-item" @click="go(item.dwForceID)" v-if="!item.bHide">
33
<div class="u-pvx-reputation-icon">
4-
<img v-if="getReputationIcon(item.szIconPath)" :src="getReputationIcon(item.szIconPath)" />
5-
<div v-else class="u-pvx-reputation-no-img"></div>
4+
<img :src="getReputationIcon(item.szIconPath)" @error="replaceByDefault" />
65
</div>
76
<div class="m-pvx-reputation-name">
87
<div class="u-pvx-reputation-name">{{ item.szName }}</div>
@@ -14,7 +13,7 @@
1413
</template>
1514

1615
<script>
17-
import { getReputationIcon } from "@/utils/reputation";
16+
import { DEFAULT_REPUTATION_ICON, getReputationIcon } from "@/utils/reputation";
1817
1918
export default {
2019
name: "ReputationItem",
@@ -26,6 +25,9 @@ export default {
2625
},
2726
methods: {
2827
getReputationIcon,
28+
replaceByDefault(e) {
29+
e.target.src = DEFAULT_REPUTATION_ICON;
30+
},
2931
go(id) {
3032
window.open(`/reputation/${id}`, "_self");
3133
},

src/utils/reputation.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
import { __imgPath } from "@/utils/config";
22
import paths from "@/assets/data/reputation_exchange_path.json";
33
import levelList from "@/assets/data/reputation_level.json";
4+
import defaultReputationIcon from "@/assets/img/reputation/reputation-null.png";
45

56
export const LOST_RESPECT_UNAVAILABLE = "无法使用遗失的尊敬来提高该声望等级进度";
7+
export const DEFAULT_REPUTATION_ICON = defaultReputationIcon;
68

7-
export function getReputationIcon(iconPath, type = "icon") {
9+
function getIconName(iconPath) {
810
const rPath = iconPath ? iconPath.replace(/\//g, "\\") : "";
9-
const iconName = rPath
10-
? rPath.split("\\")[rPath.split("\\").length - 1].toLowerCase().split(".tga")[0]
11-
: "";
11+
return rPath ? rPath.split("\\")[rPath.split("\\").length - 1].toLowerCase().split(".tga")[0] : "";
12+
}
13+
14+
export function getReputationIcon(iconPath, type = "icon") {
15+
const iconName = getIconName(iconPath);
1216
if (iconName) {
1317
return __imgPath + "reputation/reputation/std/" + type + "/" + iconName + ".png";
1418
}
15-
return "";
19+
return DEFAULT_REPUTATION_ICON;
1620
}
1721

1822
export function getBotIcon(iconPath) {
19-
const rPath = iconPath ? iconPath.replace(/\//g, "\\") : "";
20-
const iconName = rPath
21-
? rPath.split("\\")[rPath.split("\\").length - 1].toLowerCase().split(".tga")[0]
22-
: "";
23+
const iconName = getIconName(iconPath);
2324
if (iconName) {
2425
return __imgPath + "reputation/reputation/std/icon/" + iconName + ".png";
2526
}
26-
return "";
27+
return DEFAULT_REPUTATION_ICON;
2728
}
2829

2930
export function getReputationPath(name) {

src/views/reputation/SingleRobot.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
</div>
1717
<div class="m-pvx-reputation-robot-info m-pvx__item">
1818
<div class="u-reputation-logo">
19-
<img v-if="getBotIcon(reputation.szIconPath)" width="28" :src="getBotIcon(reputation.szIconPath)" />
19+
<img
20+
v-if="getBotIcon(reputation.szIconPath)"
21+
width="28"
22+
:src="getBotIcon(reputation.szIconPath)"
23+
@error="replaceReputationIconByDefault"
24+
/>
2025
</div>
2126
<div class="u-intro" v-html="reputation.szDesc"></div>
2227
</div>
@@ -75,7 +80,13 @@
7580
<script>
7681
import PvxUser from "@/components/PvxUser.vue";
7782
import ItemIcon from "@/components/common/item_icon.vue";
78-
import { getReputationIcon, getBotIcon, getReputationPath, LOST_RESPECT_UNAVAILABLE } from "@/utils/reputation";
83+
import {
84+
DEFAULT_REPUTATION_ICON,
85+
getReputationIcon,
86+
getBotIcon,
87+
getReputationPath,
88+
LOST_RESPECT_UNAVAILABLE,
89+
} from "@/utils/reputation";
7990
8091
export default {
8192
name: "SingleRobot",
@@ -106,6 +117,9 @@ export default {
106117
methods: {
107118
getReputationIcon,
108119
getBotIcon,
120+
replaceReputationIconByDefault(e) {
121+
e.target.src = DEFAULT_REPUTATION_ICON;
122+
},
109123
replaceByDefault(e) {
110124
e.target.src = require("@/assets/img/reputation/sw-null.jpg");
111125
},

0 commit comments

Comments
 (0)