💄 处理转义

This commit is contained in:
目棃
2024-12-27 14:20:34 +08:00
parent 00ebacac23
commit f6ae5b335a
11 changed files with 340 additions and 123 deletions

View File

@@ -6,7 +6,7 @@
:title="props.data.attributes?.link"
:style="getTextStyle()"
>
{{ props.data.insert }}
{{ decodeRegExp(props.data.insert) }}
</span>
<span v-else-if="mode == 'emoji'" class="tp-text-emoji">
<img :src="getEmojiUrl()" :alt="getEmojiName()" :title="getEmojiName()" />
@@ -17,7 +17,7 @@
:data="emoji"
:key="indexE"
/>
<span v-else :style="getTextStyle()">{{ props.data.insert }}</span>
<span v-else :style="getTextStyle()">{{ decodeRegExp(props.data.insert) }}</span>
</template>
<script lang="ts" setup>
import showSnackbar from "@comp/func/snackbar.js";
@@ -25,7 +25,7 @@ import { getEmojis } from "@Mys/request/getEmojis.js";
import { onMounted, ref, shallowRef, StyleValue, toRaw } from "vue";
import { parseLink, parsePost } from "@/utils/linkParser.js";
import { isColorSimilar } from "@/utils/toolFunc.js";
import { isColorSimilar, decodeRegExp } from "@/utils/toolFunc.js";
export type TpText = {
insert: string;

View File

@@ -1,8 +1,8 @@
<template>
<div
:style="getLineStyle()"
class="tp-texts"
:class="{
'tp-inline': props.data.attributes === undefined || props.data.attributes.align === undefined,
'tp-texts-header1': props.data.attributes && props.data.attributes.header === 1,
'tp-texts-header2': props.data.attributes && props.data.attributes.header === 2,
'tp-texts-header3': props.data.attributes && props.data.attributes.header === 3,
@@ -11,6 +11,7 @@
'tp-texts-header6': props.data.attributes && props.data.attributes.header === 6,
}"
:title="getTitle()"
:style="{ textAlign: props.data.attributes?.align }"
>
<component
:is="getComp(text)"
@@ -21,7 +22,7 @@
</div>
</template>
<script lang="ts" setup>
import type { Component, StyleValue } from "vue";
import type { Component } from "vue";
import TpImage from "./tp-image.vue";
import TpMention, { type TpMention as TpMentionType } from "./tp-mention.vue";
@@ -44,51 +45,22 @@ function getTitle(): string {
if (props.data.attributes.header) return `H${props.data.attributes.header}`;
return "";
}
function getLineStyle(): StyleValue {
const ruleInline: StyleValue = "display: inline";
if (props.data.attributes === undefined) return ruleInline;
if (props.data.attributes.align === undefined) return ruleInline;
return `text-align: ${props.data.attributes.align};`;
}
</script>
<style lang="css" scoped>
<style lang="scss" scoped>
.tp-texts {
line-break: anywhere;
white-space: pre-wrap;
word-break: break-all;
&.tp-inline {
display: inline;
}
}
.tp-texts-header1,
.tp-texts-header2,
.tp-texts-header3,
.tp-texts-header4,
.tp-texts-header5,
.tp-texts-header6 {
font-family: var(--font-title);
}
.tp-texts-header1 {
font-size: 24px;
}
.tp-texts-header2 {
font-size: 20px;
}
.tp-texts-header3 {
font-size: 18px;
}
.tp-texts-header4 {
font-size: 16px;
}
.tp-texts-header5 {
font-size: 14px;
}
.tp-texts-header6 {
font-size: 12px;
@for $i from 1 through 6 {
.tp-texts-header#{$i} {
font-family: var(--font-title);
font-size: calc(26px - $i * 2px);
}
}
</style>

View File

@@ -75,7 +75,7 @@
<TSubLine>统计周期 {{ item.startTime }} ~ {{ item.endTime }}</TSubLine>
<TucOverview :data="item.stat" :fights="item.detail.fight_statisic" />
<TSubLine>使用角色({{ item.detail.backup_avatars.length }})</TSubLine>
<TucAvatars :model-value="item.detail.backup_avatars" />
<TucAvatars :model-value="item.detail.backup_avatars" :detail="false" />
<TSubLine>详情</TSubLine>
<div class="ucw-rounds">
<TucRound
@@ -139,6 +139,7 @@ onMounted(async () => {
} else uidCur.value = "";
await loadCombat();
await showLoading.end();
console.log("UserCombat", localCombat.value);
});
watch(() => uidCur.value, loadCombat);

View File

@@ -60,13 +60,13 @@ import { useRouter } from "vue-router";
import { useAppStore } from "@/store/modules/app.js";
import TGLogger from "@/utils/TGLogger.js";
import { decodeRegExp } from "@/utils/toolFunc.js";
import Hk4eApi, { type AnnoLang, AnnoServer } from "@/web/request/hk4eReq.js";
import { getAnnoCard } from "@/web/utils/getAnnoCard.js";
import { decodeRegExp } from "@/web/utils/tools.js";
type AnnoSelect = { text: string; value: string };
type AnnoKey = keyof typeof AnnoType;
type AnnoCard = { [key in AnnoKey]: TGApp.App.Announcement.ListCard[] };
type AnnoCard = { [key in AnnoKey]: Array<TGApp.App.Announcement.ListCard> };
const annoServerList: Array<AnnoSelect> = [
{ text: "国服-官方服", value: AnnoServer.CN_ISLAND },

View File

@@ -1,7 +1,7 @@
/**
* @file src/utils/linkParser.ts
* @description 处理链接
* @since Beta v0.6.5
* @since Beta v0.6.7
*/
import showDialog from "@comp/func/dialog.js";
@@ -11,7 +11,7 @@ import { emit } from "@tauri-apps/api/event";
import TGClient from "./TGClient.js";
import { createPost } from "./TGWindow.js";
import { getGameId } from "@/web/utils/tools.js";
import { getGameId } from "@/utils/toolFunc.js";
/**
* @function parsePost

View File

@@ -11,6 +11,8 @@ import type { KEYWORD } from "color-convert/conversions.js";
import { v4 } from "uuid";
import { score } from "wcag-color";
import TGConstant from "@/web/constant/TGConstant.js";
/**
* @description 时间戳转换为时间字符串
* @returns {string} 时间字符串 d天 hh:mm:ss
@@ -250,3 +252,42 @@ export function getVideoDuration(durationMill: number): string {
result += `${seconds.toString().padStart(2, "0")}`;
return result;
}
/**
* @description 转义正则表达式
* @since Beta v0.3.3
* @param {string} data 内容
* @returns {string} 转义后的内容
*/
export function decodeRegExp(data: string): string {
let res = data;
if (res.length === 0) return res;
res = res.replace(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, `"`);
res = res.replace(/&apos;/g, "'");
res = res.replace(/&amp;/g, "&");
return res;
}
/**
* @description 根据 gid 获取游戏名称
* @param {number} gid
* @returns {string}
*/
export function getGameName(gid: number): string {
const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString());
return game ? game.title : "未知游戏";
}
/**
* @description 获取游戏id
* @param {string} mini
* @returns {string}
*/
export function getGameId(mini: string): string {
const game = TGConstant.BBS.CHANNELS.find((item) => item.mini === mini);
return game ? game.gid : "0";
}

View File

@@ -1,13 +1,13 @@
/**
* @file web/utils/annoParser.ts
* @description 解析游戏内公告数据
* @since Beta v0.6.0
* @since Beta v0.6.7
*/
import TpText from "@comp/viewPost/tp-text.vue";
import { h, render } from "vue";
import { decodeRegExp } from "./tools.js";
import { decodeRegExp } from "@/utils/toolFunc.js";
/**
* @description 预处理p

View File

@@ -1,47 +0,0 @@
/**
* @file web/utils/tools.ts
* @description 应用用到的工具函数
* @since Beta v0.6.3
*/
import TGConstant from "@/web/constant/TGConstant.js";
/**
* @description 转义正则表达式
* @since Beta v0.3.3
* @param {string} data 内容
* @returns {string} 转义后的内容
*/
export function decodeRegExp(data: string): string {
let res = data;
if (res.length === 0) return res;
res = res.replace(/&lt;/g, "<");
res = res.replace(/&gt;/g, ">");
res = res.replace(/&nbsp;/g, " ");
res = res.replace(/&#39;/g, "'");
res = res.replace(/&quot;/g, `"`);
res = res.replace(/&apos;/g, "'");
res = res.replace(/&amp;/g, "&");
return res;
}
/**
* @description 根据 gid 获取游戏名称
* @param {number} gid
* @returns {string}
*/
export function getGameName(gid: number): string {
const game = TGConstant.BBS.CHANNELS.find((item) => item.gid === gid.toString());
return game ? game.title : "未知游戏";
}
/**
* @description 获取游戏id
* @param {string} mini
* @returns {string}
*/
export function getGameId(mini: string): string {
const game = TGConstant.BBS.CHANNELS.find((item) => item.mini === mini);
return game ? game.gid : "0";
}