统一用户信息付费查看
This commit is contained in:
@@ -121,6 +121,190 @@ export function userCardComponent() {
|
||||
return operatorPositionRank >= targetPositionRank;
|
||||
},
|
||||
|
||||
/** 返回名片资产字段的中文名称。 */
|
||||
assetValueLabel(asset) {
|
||||
return {
|
||||
exp_num: "经验",
|
||||
jjb: "金币",
|
||||
meili: "魅力",
|
||||
}[asset] || "资产";
|
||||
},
|
||||
|
||||
/** 判断名片资产字段是否处于可付费查看的隐藏状态。 */
|
||||
canRevealAssetValue(asset) {
|
||||
return Boolean(
|
||||
this.userInfo.asset_numbers_can_reveal
|
||||
&& this.userInfo.asset_numbers_masked
|
||||
&& this.userInfo[asset] === "******"
|
||||
&& this.userInfo.asset_reveal_user_id
|
||||
);
|
||||
},
|
||||
|
||||
/** 格式化名片里的经验、金币、魅力显示。 */
|
||||
displayAssetValue(asset) {
|
||||
if (this.canRevealAssetValue(asset)) {
|
||||
return "****** 👁️";
|
||||
}
|
||||
|
||||
return Number(this.userInfo[asset] || 0).toLocaleString();
|
||||
},
|
||||
|
||||
/** 返回名片资产字段的悬停提示。 */
|
||||
assetValueTitle(asset) {
|
||||
if (this.canRevealAssetValue(asset)) {
|
||||
const cost = Number(this.userInfo.asset_numbers_reveal_cost || 1000).toLocaleString();
|
||||
|
||||
return `点击查看${this.assetValueLabel(asset)},需扣除 ${cost} 金币`;
|
||||
}
|
||||
|
||||
return this.assetValueLabel(asset);
|
||||
},
|
||||
|
||||
/** 返回名片资产字段的点击态样式。 */
|
||||
assetValueStyle(asset, color) {
|
||||
const clickable = this.canRevealAssetValue(asset);
|
||||
|
||||
return [
|
||||
"font-weight: 700",
|
||||
`color: ${color}`,
|
||||
"font-size: 14px",
|
||||
clickable ? "cursor: pointer" : "cursor: default",
|
||||
"text-decoration: none",
|
||||
].join("; ");
|
||||
},
|
||||
|
||||
/** 付费查看当前名片里的经验、金币或魅力。 */
|
||||
async revealAssetValue(asset) {
|
||||
if (!this.canRevealAssetValue(asset)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cost = Number(this.userInfo.asset_numbers_reveal_cost || 1000);
|
||||
const label = this.assetValueLabel(asset);
|
||||
const confirmed = await this.$confirm(
|
||||
`查看 TA 的${label}需扣除 ${cost.toLocaleString()} 金币,是否继续?`,
|
||||
"信息查看付费",
|
||||
"#d97706",
|
||||
"扣费查看",
|
||||
"取消"
|
||||
);
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/user/reveal-info", {
|
||||
method: "POST",
|
||||
headers: this._headers(),
|
||||
body: JSON.stringify({
|
||||
user_id: this.userInfo.asset_reveal_user_id,
|
||||
asset,
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status !== "success") {
|
||||
this.$alert(data.message || "查看失败,请稍后重试。", "查看失败", "#cc4444");
|
||||
return;
|
||||
}
|
||||
|
||||
// 只解锁当前点击的资产字段,其他隐藏字段仍保持星号并可单独付费查看。
|
||||
this.userInfo[asset] = data.value;
|
||||
|
||||
if (window.chatContext && data.jjb !== undefined) {
|
||||
window.chatContext.myGold = data.jjb;
|
||||
}
|
||||
|
||||
this.$alert(data.message || `${label}已显示。`, "查看成功", "#16a34a");
|
||||
} catch (e) {
|
||||
this.$alert("网络异常,请稍后重试。", "查看失败", "#cc4444");
|
||||
}
|
||||
},
|
||||
|
||||
/** 格式化名片里的银行存款显示。 */
|
||||
displayBankBalance() {
|
||||
if (this.userInfo.bank_jjb_can_reveal && this.userInfo.bank_jjb_masked) {
|
||||
return "****** 👁️";
|
||||
}
|
||||
|
||||
return Number(this.userInfo.bank_jjb || 0).toLocaleString();
|
||||
},
|
||||
|
||||
/** 返回银行存款字段的悬停提示。 */
|
||||
bankBalanceTitle() {
|
||||
if (this.userInfo.bank_jjb_can_reveal && this.userInfo.bank_jjb_masked) {
|
||||
const cost = Number(this.userInfo.bank_jjb_reveal_cost || 1000).toLocaleString();
|
||||
|
||||
return `点击查看存款,需扣除 ${cost} 金币`;
|
||||
}
|
||||
|
||||
return "银行存款";
|
||||
},
|
||||
|
||||
/** 返回银行存款字段的点击态样式。 */
|
||||
bankBalanceStyle() {
|
||||
const clickable = this.userInfo.bank_jjb_can_reveal && this.userInfo.bank_jjb_masked;
|
||||
|
||||
return [
|
||||
"font-weight: 700",
|
||||
"color: #059669",
|
||||
"font-size: 14px",
|
||||
clickable ? "cursor: pointer" : "cursor: default",
|
||||
"text-decoration: none",
|
||||
].join("; ");
|
||||
},
|
||||
|
||||
/** 付费查看当前名片用户的银行存款。 */
|
||||
async revealBankBalance() {
|
||||
if (!this.userInfo.bank_jjb_can_reveal || !this.userInfo.bank_jjb_masked || !this.userInfo.bank_reveal_user_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cost = Number(this.userInfo.bank_jjb_reveal_cost || 1000);
|
||||
const confirmed = await this.$confirm(
|
||||
`查看 TA 的银行存款需扣除 ${cost.toLocaleString()} 金币,是否继续?`,
|
||||
"信息查看付费",
|
||||
"#d97706",
|
||||
"扣费查看",
|
||||
"取消"
|
||||
);
|
||||
|
||||
if (!confirmed) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/user/reveal-info", {
|
||||
method: "POST",
|
||||
headers: this._headers(),
|
||||
body: JSON.stringify({
|
||||
user_id: this.userInfo.bank_reveal_user_id,
|
||||
asset: "bank_jjb",
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.status !== "success") {
|
||||
this.$alert(data.message || "查看失败,请稍后重试。", "查看失败", "#cc4444");
|
||||
return;
|
||||
}
|
||||
|
||||
// 仅解锁当前名片这一处显示,重新打开名片时仍以后端返回的遮罩状态为准。
|
||||
this.userInfo.bank_jjb = data.value;
|
||||
this.userInfo.bank_jjb_masked = false;
|
||||
this.userInfo.bank_jjb_can_reveal = false;
|
||||
|
||||
if (window.chatContext && data.jjb !== undefined) {
|
||||
window.chatContext.myGold = data.jjb;
|
||||
}
|
||||
|
||||
this.$alert(data.message || "存款金额已显示。", "查看成功", "#16a34a");
|
||||
} catch (e) {
|
||||
this.$alert("网络异常,请稍后重试。", "查看失败", "#cc4444");
|
||||
}
|
||||
},
|
||||
|
||||
/** 切换好友关系(加好友 / 删好友) */
|
||||
async toggleFriend() {
|
||||
if (this.friendLoading) return;
|
||||
|
||||
Reference in New Issue
Block a user