167 lines
4.6 KiB
Vue
167 lines
4.6 KiB
Vue
<script>
|
|
import "~/assets/styles/SensitiveValue.BSZlaRHT.css";
|
|
import { toDisplayString } from "vue";
|
|
import { normalizeClass } from "vue";
|
|
import { watch } from "vue";
|
|
import { ref } from "vue";
|
|
import { createCommentVNode } from "vue";
|
|
import { computed } from "vue";
|
|
import { createElementBlock } from "vue";
|
|
import { createElementVNode } from "vue";
|
|
import { unref } from "vue";
|
|
import { defineComponent } from "vue";
|
|
import { openBlock } from "vue";
|
|
import { useRoute } from "#app";
|
|
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
|
|
function p(e) {
|
|
return /[**•●]/u.test(e ?? ``);
|
|
}
|
|
function m(e) {
|
|
return !!e?.trim() && !p(e);
|
|
}
|
|
function h(e, t, n) {
|
|
let r = Array.from(e);
|
|
return r.length <= t + n
|
|
? `*`.repeat(Math.max(r.length, 1))
|
|
: `${r.slice(0, t).join(``)}****${n ? r.slice(-n).join(``) : ``}`;
|
|
}
|
|
function g(e, t) {
|
|
if (!e?.trim()) return ``;
|
|
if (p(e)) return e;
|
|
let n = e.trim(),
|
|
r = Array.from(n);
|
|
switch (t) {
|
|
case `phone`:
|
|
return r.length >= 8
|
|
? h(n, 3, 4)
|
|
: r.length >= 5
|
|
? h(n, 2, 2)
|
|
: h(n, +(r.length > 1), 0);
|
|
case `email`: {
|
|
let e = n.split(`@`);
|
|
if (e.length !== 2 || !e[0] || !e[1] || /\s/u.test(n)) return h(n, 1, 1);
|
|
let t = Array.from(e[0]),
|
|
r =
|
|
t.length > 2
|
|
? t.slice(0, 2).join(``)
|
|
: t.length > 1
|
|
? (t[0] ?? ``)
|
|
: ``;
|
|
return `${r}${`*`.repeat(Math.max(2, t.length - Array.from(r).length))}@${e[1]}`;
|
|
}
|
|
case `name`:
|
|
return r.length > 1 ? `${r[0]}**` : `*`;
|
|
case `text`:
|
|
return h(n, 2, 2);
|
|
case `identity`:
|
|
return r.length > 7 ? h(n, 3, 4) : h(n, +(r.length > 1), 0);
|
|
}
|
|
}
|
|
var _ = {
|
|
class: `sensitive-value`,
|
|
},
|
|
v = {
|
|
class: `sensitive-value-text`,
|
|
},
|
|
y = [`aria-label`, `aria-pressed`],
|
|
b = Object.assign(
|
|
_plugin_vue_export_helper_t(
|
|
defineComponent({
|
|
__name: `SensitiveValue`,
|
|
props: {
|
|
value: {
|
|
default: ``,
|
|
},
|
|
kind: {
|
|
default: `text`,
|
|
},
|
|
label: {
|
|
default: `敏感信息`,
|
|
},
|
|
prefix: {
|
|
default: ``,
|
|
},
|
|
placeholder: {
|
|
default: `—`,
|
|
},
|
|
empty: {},
|
|
resetKey: {
|
|
default: void 0,
|
|
},
|
|
},
|
|
setup(l) {
|
|
let f = l,
|
|
p = useRoute(),
|
|
h = ref(!1),
|
|
b = computed(() => m(f.value)),
|
|
x = computed(() => g(f.value, f.kind)),
|
|
S = computed(() => {
|
|
if (!x.value) return f.empty ?? f.placeholder;
|
|
let e = h.value && b.value ? f.value : x.value;
|
|
return f.prefix ? `${f.prefix} ${e}` : e;
|
|
});
|
|
return (
|
|
watch(
|
|
[
|
|
() => f.value,
|
|
() => f.kind,
|
|
() => f.prefix,
|
|
() => f.resetKey,
|
|
() => p.fullPath,
|
|
],
|
|
() => {
|
|
h.value = !1;
|
|
},
|
|
{
|
|
flush: `sync`,
|
|
},
|
|
),
|
|
(n, r) => (
|
|
openBlock(),
|
|
createElementBlock(`span`, _, [
|
|
createElementVNode(`span`, v, toDisplayString(unref(S)), 1),
|
|
unref(b)
|
|
? (openBlock(),
|
|
createElementBlock(
|
|
`button`,
|
|
{
|
|
key: 0,
|
|
type: `button`,
|
|
class: `sensitive-value-toggle`,
|
|
"aria-label": `${unref(h) ? `隐藏` : `显示完整`}${l.label}`,
|
|
"aria-pressed": unref(h),
|
|
onClick: (r[0] ||= (e) => (h.value = !unref(h))),
|
|
},
|
|
[
|
|
createElementVNode(
|
|
`i`,
|
|
{
|
|
class: normalizeClass([
|
|
`pi`,
|
|
unref(h) ? `pi-eye-slash` : `pi-eye`,
|
|
]),
|
|
"aria-hidden": `true`,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
],
|
|
8,
|
|
y,
|
|
))
|
|
: createCommentVNode(``, !0),
|
|
])
|
|
)
|
|
);
|
|
},
|
|
}),
|
|
[[`__scopeId`, `data-v-07008ebf`]],
|
|
),
|
|
{
|
|
__name: `SensitiveValue`,
|
|
},
|
|
);
|
|
export {};
|
|
export default b;
|
|
</script>
|