Commit 30740d73 authored by 郑磊's avatar 郑磊

更新语言判断逻辑

parent fb6c9380
This source diff could not be displayed because it is too large. You can view the blob instead.
import { defineComponent as C, openBlock as l, createElementBlock as m, createElementVNode as c, normalizeStyle as S, pushScopeId as E, popScopeId as T, provide as Q, inject as tt, computed as $, normalizeClass as R, Fragment as V, toDisplayString as D, unref as y, renderSlot as et, createVNode as A, Transition as at, withCtx as O, createBlock as x, normalizeProps as st, mergeProps as nt, createCommentVNode as b, ref as f, onBeforeUnmount as W, toRef as rt, onMounted as ct, withModifiers as P, resolveDynamicComponent as ot } from "vue";
const it = (t) => (E("data-v-fcfe5ea2"), t = t(), T(), t), ut = { class: "captcha--slider-bar" }, dt = { class: "captcha--slider-bar--bar" }, lt = /* @__PURE__ */ it(() => /* @__PURE__ */ c("svg", {
import { defineComponent as C, openBlock as l, createElementBlock as m, createElementVNode as o, normalizeStyle as S, pushScopeId as E, popScopeId as T, provide as K, inject as Q, computed as $, normalizeClass as R, Fragment as V, toDisplayString as D, unref as y, renderSlot as tt, createVNode as A, Transition as et, withCtx as z, createBlock as x, normalizeProps as at, mergeProps as nt, createCommentVNode as b, ref as f, onBeforeUnmount as N, toRef as st, onMounted as rt, withModifiers as P, resolveDynamicComponent as ot } from "vue";
const ct = (t) => (E("data-v-fcfe5ea2"), t = t(), T(), t), it = { class: "captcha--slider-bar" }, ut = { class: "captcha--slider-bar--bar" }, dt = /* @__PURE__ */ ct(() => /* @__PURE__ */ o("svg", {
class: "captcha--slider-bar--track-icon",
viewBox: "0 0 1024 1024",
version: "1.1",
......@@ -8,13 +8,13 @@ const it = (t) => (E("data-v-fcfe5ea2"), t = t(), T(), t), ut = { class: "captch
width: "64",
height: "64"
}, [
/* @__PURE__ */ c("path", {
/* @__PURE__ */ o("path", {
d: "M576 192v256H0v128h576v256l448-320z",
"p-id": "4240"
})
], -1)), ht = [
lt
], pt = /* @__PURE__ */ C({
], -1)), lt = [
dt
], ht = /* @__PURE__ */ C({
__name: "SliderBar",
props: {
x: {
......@@ -23,80 +23,83 @@ const it = (t) => (E("data-v-fcfe5ea2"), t = t(), T(), t), ut = { class: "captch
}
},
setup(t) {
return (e, a) => (l(), m("div", ut, [
c("div", dt, [
c("div", {
return (e, a) => (l(), m("div", it, [
o("div", ut, [
o("div", {
class: "captcha--slider-bar--active",
style: S({ width: `${t.x}px` })
}, null, 4)
]),
c("div", {
o("div", {
class: "captcha--slider-bar--track",
style: S({
transform: `translateX(${t.x}px)`
})
}, ht, 4)
}, lt, 4)
]));
}
}), _ = (t, e) => {
const a = t.__vccOpts || t;
for (const [n, i] of e)
a[n] = i;
for (const [n, c] of e)
a[n] = c;
return a;
}, vt = /* @__PURE__ */ _(pt, [["__scopeId", "data-v-fcfe5ea2"]]), gt = {
}, pt = /* @__PURE__ */ _(ht, [["__scopeId", "data-v-fcfe5ea2"]]), vt = {
验证成功: "Success",
"验证失败,请再试一次": "Verification failed",
验证码已过期: "Expired",
拖动下方滑块完成拼图: "Drag the slider to complete the puzzle",
"网络异常,请点击重试": "Network error, click to retry"
}, ft = {
}, gt = {
验证成功: "验证成功",
"验证失败,请再试一次": "验证失败,请再试一次",
验证码已过期: "验证码已过期",
拖动下方滑块完成拼图: "拖动下方滑块完成拼图",
"网络异常,请点击重试": "网络异常,请点击重试"
}, mt = {
}, ft = {
验证成功: "驗證成功",
"验证失败,请再试一次": "驗證失敗,請再試一次",
验证码已过期: "驗證碼已過期",
拖动下方滑块完成拼图: "拖動下方滑塊完成拼圖",
"网络异常,请点击重试": "網路異常,請點擊重試"
}, U = {
en: gt,
"zh-cn": ft,
"zh-tw": mt
}, yt = Object.keys(U), wt = "zh-cn";
function _t(t) {
const e = t.split(/_|-/);
return e.length > 2 && e.splice(1, e.length - 2), e.map((a) => a.toLowerCase()).join("-");
}, mt = {
en: vt,
"zh-cn": gt,
"zh-tw": ft
}, yt = "zh-cn";
function wt(t) {
const e = t.toLowerCase().split(/_|-/), a = e[0], n = e.length > 1 ? e[e.length - 1] : void 0, c = e.length > 2 ? e[1] : void 0;
return {
lang: a,
country: n,
variant: c
};
}
function Ct(t) {
let e = typeof t == "string" && t ? [t] : navigator && navigator.languages ? navigator.languages : [wt];
e = e.map((a) => _t(a));
for (let a of e) {
if (a === "en" || a.startsWith("en-"))
function _t(t) {
const a = (typeof t == "string" && t ? [t] : navigator && navigator.languages ? navigator.languages : [yt]).map((n) => wt(n));
for (let n of a) {
if (n.lang === "en")
return "en";
if (a === "zh" || a.startsWith("zh-"))
return yt.includes(a) ? a : "zh-cn";
if (n.lang === "zh")
return n.variant === "hans" ? "zh-cn" : n.variant === "hant" ? "zh-tw" : n.country === "cn" ? "zh-cn" : n.country === "tw" ? "zh-tw" : "zh-cn";
}
return "en";
}
function xt(t) {
return U[Ct(t)] ?? {};
function Ct(t) {
return mt[_t(t)] ?? {};
}
function bt(t) {
const e = xt(t);
function xt(t) {
const e = Ct(t);
return (a) => e[a] ?? a;
}
function St(t, e, a) {
function bt(t, e, a) {
if (!e && !a)
return t;
const n = new URL(t, e);
return a && Object.entries(a).forEach(
([i, s]) => n.searchParams.append(i, s)
([c, s]) => n.searchParams.append(c, s)
), n.href;
}
function It(t) {
function St(t) {
const e = {};
return t.getAllResponseHeaders().split(`
`).forEach((a) => {
......@@ -105,18 +108,18 @@ function It(t) {
let [n] = a.split(":");
if (n = n.trim(), n === "")
return;
const i = t.getResponseHeader(n);
i !== null && (e[n] = i);
const c = t.getResponseHeader(n);
c !== null && (e[n] = c);
}), e;
}
function Z(t) {
function U(t) {
const {
url: e,
baseURL: a,
method: n,
params: i,
params: c,
headers: s,
data: o,
data: i,
timeout: u,
withCredentials: d = !1
} = t, r = new XMLHttpRequest();
......@@ -124,30 +127,30 @@ function Z(t) {
r.addEventListener("abort", p), r.addEventListener("error", p), r.addEventListener("timeout", p), r.addEventListener("load", function() {
w({
status: r.status,
headers: It(r),
headers: St(r),
data: JSON.parse(r.responseText)
});
}), r.addEventListener("readystatechange", function() {
if (r.readyState === XMLHttpRequest.OPENED) {
if (typeof s == "object" && s && Object.entries(s).forEach(
([h, v]) => r.setRequestHeader(h, v)
), typeof o < "u" && o !== null) {
if (typeof o == "string") {
r.send(o);
), typeof i < "u" && i !== null) {
if (typeof i == "string") {
r.send(i);
return;
} else if (typeof o == "object") {
r.setRequestHeader("Content-Type", "application/json"), r.send(JSON.stringify(o));
} else if (typeof i == "object") {
r.setRequestHeader("Content-Type", "application/json"), r.send(JSON.stringify(i));
return;
}
}
r.send();
}
}), r.open(n ?? "GET", St(e, a, i));
}), r.open(n ?? "GET", bt(e, a, c));
});
}
async function Lt(t) {
async function It(t) {
for (; ; ) {
const e = await Z({
const e = await U({
method: "POST",
data: {},
...t
......@@ -156,11 +159,11 @@ async function Lt(t) {
return e.data;
}
}
async function kt(t) {
async function Lt(t) {
const { data: e, ...a } = t;
let n;
try {
n = (await Z({
n = (await U({
...a,
method: "POST",
data: e
......@@ -186,14 +189,14 @@ function H(t) {
y: Math.round(e[0].clientY)
};
}
function N(t) {
const { triggers: e = [], max: a, onDrag: n, onVerify: i } = t;
let s = null, o = [];
function W(t) {
const { triggers: e = [], max: a, onDrag: n, onVerify: c } = t;
let s = null, i = [];
const u = (h) => {
s = {
...H(h),
startTime: Date.now()
}, o.push({
}, i.push({
x: 0,
y: 0,
type: "down",
......@@ -203,7 +206,7 @@ function N(t) {
if (!s)
return;
const v = H(h);
o.push({
i.push({
x: v.x - s.x,
y: v.y - s.y,
type: "move",
......@@ -213,19 +216,19 @@ function N(t) {
n(I);
}, r = (h) => {
if (s) {
if (p(), !o.some((v) => v.type === "move"))
o = [];
if (p(), !i.some((v) => v.type === "move"))
i = [];
else {
const v = H(h);
o.push({
i.push({
x: v.x - s.x,
y: v.y - s.y,
type: "up",
t: Date.now() - s.startTime
}), w(), i({
}), w(), c({
startSlidingTime: new Date(s.startTime).toISOString(),
endSlidingTime: (/* @__PURE__ */ new Date()).toISOString(),
trackList: o
trackList: i
});
}
s = null;
......@@ -246,17 +249,17 @@ function N(t) {
onDragStart: u
};
}
function Mt(t) {
const { captcha: e, ratio: a, onVerify: n, ...i } = t, s = Math.round(
function kt(t) {
const { captcha: e, ratio: a, onVerify: n, ...c } = t, s = Math.round(
(e.backgroundImageWidth - e.templateImageWidth) * a
);
return N({
...i,
return W({
...c,
captcha: e,
max: s,
onVerify: (o) => {
onVerify: (i) => {
n({
...o,
...i,
bgImageWidth: Math.round(e.backgroundImageWidth * a),
bgImageHeight: Math.round(
e.backgroundImageHeight * a
......@@ -271,13 +274,13 @@ function Mt(t) {
}
});
}
function Et(t) {
const { captcha: e, ratio: a, onVerify: n, onDrag: i, max: s, ...o } = t;
return N({
...o,
function Mt(t) {
const { captcha: e, ratio: a, onVerify: n, onDrag: c, max: s, ...i } = t;
return W({
...i,
captcha: e,
max: s,
onDrag: (u) => i(u, u / s * 360),
onDrag: (u) => c(u, u / s * 360),
onVerify: (u) => {
n({
...u,
......@@ -295,20 +298,20 @@ function Et(t) {
}
});
}
function Y(t, e) {
function Z(t, e) {
return Math.round(
(t.backgroundImageHeight - t.data.randomY) * e
);
}
function Tt(t) {
const { captcha: e, ratio: a, onVerify: n, max: i, ...s } = t;
return N({
function Et(t) {
const { captcha: e, ratio: a, onVerify: n, max: c, ...s } = t;
return W({
...s,
captcha: e,
max: i,
onVerify: (o) => {
max: c,
onVerify: (i) => {
n({
...o,
...i,
bgImageWidth: Math.round(e.backgroundImageWidth * a),
bgImageHeight: Math.round(
e.backgroundImageHeight * a
......@@ -316,20 +319,20 @@ function Tt(t) {
sliderImageWidth: Math.round(
e.backgroundImageWidth * a
),
sliderImageHeight: Y(e, a)
sliderImageHeight: Z(e, a)
});
}
});
}
const G = Symbol();
function $t(t) {
Q(G, t);
const Y = Symbol();
function Tt(t) {
K(Y, t);
}
function B(t) {
return t || (t = tt(G, () => $(() => {
}), !0)), $(() => bt(t.value));
return t || (t = Q(Y, () => $(() => {
}), !0)), $(() => xt(t.value));
}
const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F(() => /* @__PURE__ */ c("svg", {
const G = (t) => (E("data-v-4b782e10"), t = t(), T(), t), $t = /* @__PURE__ */ G(() => /* @__PURE__ */ o("svg", {
class: "captcha--status-tip--icon",
viewBox: "0 0 1024 1024",
version: "1.1",
......@@ -338,11 +341,11 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
width: "64",
height: "64"
}, [
/* @__PURE__ */ c("path", {
/* @__PURE__ */ o("path", {
d: "M896 512a384 384 0 1 0-768 0 384 384 0 0 0 768 0zM42.666667 512C42.666667 252.8 252.8 42.666667 512 42.666667s469.333333 210.133333 469.333333 469.333333-210.133333 469.333333-469.333333 469.333333S42.666667 771.2 42.666667 512z m652.501333-158.165333l60.330667 60.330666L469.333333 700.330667l-200.832-200.832 60.330667-60.330667L469.333333 579.669333l225.834667-225.834666z",
"p-id": "5408"
})
], -1)), Ot = /* @__PURE__ */ F(() => /* @__PURE__ */ c("svg", {
], -1)), Dt = /* @__PURE__ */ G(() => /* @__PURE__ */ o("svg", {
class: "captcha--status-tip--icon",
viewBox: "0 0 1024 1024",
version: "1.1",
......@@ -351,7 +354,7 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
width: "64",
height: "64"
}, [
/* @__PURE__ */ c("path", {
/* @__PURE__ */ o("path", {
d: "M575.986694 832.039919C575.986694 867.356032 547.316113 896.026613 512 896.026613 476.683887 896.026613 448.013306 867.356032 448.013306 832.039919 448.013306 796.723806 476.683887 768.048156 512 768.048156 547.316113 768.048156 575.986694 796.64777 575.986694 832.039919ZM512 255.997465C476.683887 255.997465 448.013306 284.668046 448.013306 319.984159L448.013306 639.998733C448.013306 675.314846 476.683887 703.990496 512 703.990496 547.316113 703.990496 575.986694 675.314846 575.986694 639.998733L575.986694 319.984159C575.986694 284.668046 547.316113 255.997465 512 255.997465ZM1023.979724 896.026613C1023.979724 966.729805 966.709529 1024.005069 896.006336 1024.005069L127.993664 1024.005069C57.290471 1024.005069 0.020276 966.658839 0.020276 896.026613 0.020276 874.868373 5.216059 854.931776 14.39105 837.311737L14.320083 837.24077 398.250384 69.304133 398.392317 69.304133C419.626593 28.133261 462.455047 0.040552 512 0.040552 561.544953 0.040552 604.373407 28.209297 625.67865 69.3751L1008.311272 834.711311C1018.348003 852.838256 1023.979724 873.783595 1023.979724 896.026613ZM959.99303 896.026613C959.99303 885.123073 957.392604 874.868373 952.191753 865.404445L951.613881 864.319667 951.112044 863.239958 568.621355 98.405584C557.499847 77.171308 535.834701 64.027246 512 64.027246 488.023365 64.027246 466.282184 77.318311 455.160675 98.765487L452.12938 104.544211 92.175714 824.527578 92.677551 825.034483 71.154339 866.778159C66.389426 875.948082 64.00697 885.842879 64.00697 896.097579 64.00697 931.413692 92.748517 960.089342 127.993664 960.089342L896.006336 960.089342C931.322449 960.013306 959.99303 931.342726 959.99303 896.026613Z",
"p-id": "6384"
})
......@@ -372,15 +375,15 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
class: R(`captcha--status-tip captcha--status-tip--${t.status ? "success" : "fail"}`)
}, [
t.status ? (l(), m(V, { key: 0 }, [
Dt,
c("div", null, D(y(e)("验证成功")), 1)
$t,
o("div", null, D(y(e)("验证成功")), 1)
], 64)) : (l(), m(V, { key: 1 }, [
Ot,
c("div", null, D(y(e)(t.message ?? "验证失败,请再试一次")), 1)
Dt,
o("div", null, D(y(e)(t.message ?? "验证失败,请再试一次")), 1)
], 64))
], 2));
}
}), Ht = /* @__PURE__ */ _(zt, [["__scopeId", "data-v-4b782e10"]]), Rt = { class: "captcha--view" }, Vt = { class: "captcha--view--tip" }, Wt = { class: "captcha--view--content" }, Nt = /* @__PURE__ */ C({
}), Ot = /* @__PURE__ */ _(zt, [["__scopeId", "data-v-4b782e10"]]), Ht = { class: "captcha--view" }, Rt = { class: "captcha--view--tip" }, Vt = { class: "captcha--view--content" }, Nt = /* @__PURE__ */ C({
__name: "CaptchaViewContainer",
props: {
verifyStatus: {
......@@ -393,21 +396,21 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
},
setup(t) {
const e = B();
return (a, n) => (l(), m("div", Rt, [
c("div", Vt, D(y(e)("拖动下方滑块完成拼图")), 1),
c("div", Wt, [
et(a.$slots, "default", {}, void 0, !0),
A(at, { name: "captcha--status-tip" }, {
default: O(() => [
t.verifyStatus ? (l(), x(Ht, st(nt({ key: 0 }, t.verifyStatus)), null, 16)) : b("", !0)
return (a, n) => (l(), m("div", Ht, [
o("div", Rt, D(y(e)("拖动下方滑块完成拼图")), 1),
o("div", Vt, [
tt(a.$slots, "default", {}, void 0, !0),
A(et, { name: "captcha--status-tip" }, {
default: z(() => [
t.verifyStatus ? (l(), x(Ot, at(nt({ key: 0 }, t.verifyStatus)), null, 16)) : b("", !0)
]),
_: 1
})
]),
A(vt, { x: t.x }, null, 8, ["x"])
A(pt, { x: t.x }, null, 8, ["x"])
]));
}
}), j = /* @__PURE__ */ _(Nt, [["__scopeId", "data-v-ef209593"]]), Bt = ["src"], jt = /* @__PURE__ */ C({
}), q = /* @__PURE__ */ _(Nt, [["__scopeId", "data-v-ef209593"]]), Wt = ["src"], Bt = /* @__PURE__ */ C({
__name: "ConcatCaptcha",
props: {
captcha: {
......@@ -420,29 +423,29 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
},
emits: ["verify"],
setup(t, { emit: e }) {
const a = e, n = t, i = 280 / n.captcha.backgroundImageWidth, s = f(0), o = $(() => Y(n.captcha, i)), u = Tt({
const a = e, n = t, c = 280 / n.captcha.backgroundImageWidth, s = f(0), i = $(() => Z(n.captcha, c)), u = Et({
captcha: n.captcha,
ratio: i,
ratio: c,
max: 225,
onDrag: (d) => s.value = d,
onVerify: (d) => a("verify", d)
});
return W(() => u.destroy()), (d, r) => (l(), x(j, {
return N(() => u.destroy()), (d, r) => (l(), x(q, {
class: "captcha--view--concat",
verifyStatus: t.verifyStatus,
x: s.value,
onTouchstart: y(u).onDragStart,
onMousedown: y(u).onDragStart
}, {
default: O(() => [
c("img", {
default: z(() => [
o("img", {
src: t.captcha.backgroundImage,
class: "captcha--view--concat--bg"
}, null, 8, Bt),
c("div", {
}, null, 8, Wt),
o("div", {
class: "captcha--view--concat--track",
style: S({
height: `${o.value}px`,
height: `${i.value}px`,
backgroundImage: `url('${t.captcha.backgroundImage}')`,
backgroundPositionX: `${s.value}px`
})
......@@ -451,7 +454,7 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
_: 1
}, 8, ["verifyStatus", "x", "onTouchstart", "onMousedown"]));
}
}), qt = /* @__PURE__ */ _(jt, [["__scopeId", "data-v-fd603259"]]), Xt = ["src"], At = ["src"], Pt = /* @__PURE__ */ C({
}), qt = /* @__PURE__ */ _(Bt, [["__scopeId", "data-v-fd603259"]]), Xt = ["src"], jt = ["src"], At = /* @__PURE__ */ C({
__name: "RotateCaptcha",
props: {
captcha: {
......@@ -464,37 +467,37 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
},
emits: ["verify"],
setup(t, { emit: e }) {
const a = e, n = t, i = f(0), s = f(0), o = 280 / n.captcha.backgroundImageWidth, u = Et({
const a = e, n = t, c = f(0), s = f(0), i = 280 / n.captcha.backgroundImageWidth, u = Mt({
captcha: n.captcha,
ratio: o,
ratio: i,
max: 225,
onDrag: (d, r) => {
i.value = d, s.value = r;
c.value = d, s.value = r;
},
onVerify: (d) => a("verify", d)
});
return W(() => u.destroy()), (d, r) => (l(), x(j, {
return N(() => u.destroy()), (d, r) => (l(), x(q, {
class: "captcha--view--rotate",
verifyStatus: t.verifyStatus,
x: i.value,
x: c.value,
onTouchstart: y(u).onDragStart,
onMousedown: y(u).onDragStart
}, {
default: O(() => [
c("img", {
default: z(() => [
o("img", {
src: t.captcha.backgroundImage,
class: "captcha--view--rotate--bg"
}, null, 8, Xt),
c("img", {
o("img", {
src: t.captcha.templateImage,
class: "captcha--view--rotate--track",
style: S({ transform: `rotate(${s.value}deg)` })
}, null, 12, At)
}, null, 12, jt)
]),
_: 1
}, 8, ["verifyStatus", "x", "onTouchstart", "onMousedown"]));
}
}), Ut = /* @__PURE__ */ _(Pt, [["__scopeId", "data-v-76bb4af9"]]), Zt = ["src"], Yt = ["src"], Gt = /* @__PURE__ */ C({
}), Pt = /* @__PURE__ */ _(At, [["__scopeId", "data-v-76bb4af9"]]), Ut = ["src"], Zt = ["src"], Yt = /* @__PURE__ */ C({
__name: "SliderCaptcha",
props: {
captcha: {
......@@ -507,36 +510,36 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
},
emits: ["verify"],
setup(t, { emit: e }) {
const a = e, n = t, i = 280 / n.captcha.backgroundImageWidth, s = f(0), o = Mt({
const a = e, n = t, c = 280 / n.captcha.backgroundImageWidth, s = f(0), i = kt({
captcha: n.captcha,
ratio: i,
ratio: c,
onDrag: (u) => {
s.value = u;
},
onVerify: (u) => a("verify", u)
});
return W(() => o.destroy()), (u, d) => (l(), x(j, {
return N(() => i.destroy()), (u, d) => (l(), x(q, {
class: "captcha--view--slider",
verifyStatus: t.verifyStatus,
x: s.value,
onTouchstart: y(o).onDragStart,
onMousedown: y(o).onDragStart
onTouchstart: y(i).onDragStart,
onMousedown: y(i).onDragStart
}, {
default: O(() => [
c("img", {
default: z(() => [
o("img", {
src: t.captcha.backgroundImage,
class: "captcha--view--slider--bg"
}, null, 8, Zt),
c("img", {
}, null, 8, Ut),
o("img", {
src: t.captcha.templateImage,
class: "captcha--view--slider--track",
style: S({ transform: `translateX(${s.value}px)` })
}, null, 12, Yt)
}, null, 12, Zt)
]),
_: 1
}, 8, ["verifyStatus", "x", "onTouchstart", "onMousedown"]));
}
}), Ft = /* @__PURE__ */ _(Gt, [["__scopeId", "data-v-8fb0f971"]]), Jt = (t) => (E("data-v-6ba70e16"), t = t(), T(), t), Kt = /* @__PURE__ */ Jt(() => /* @__PURE__ */ c("svg", {
}), Gt = /* @__PURE__ */ _(Yt, [["__scopeId", "data-v-8fb0f971"]]), Ft = (t) => (E("data-v-6ba70e16"), t = t(), T(), t), Jt = /* @__PURE__ */ Ft(() => /* @__PURE__ */ o("svg", {
class: "captcha--error--icon",
viewBox: "0 0 1024 1024",
version: "1.1",
......@@ -545,49 +548,49 @@ const F = (t) => (E("data-v-4b782e10"), t = t(), T(), t), Dt = /* @__PURE__ */ F
width: "64",
height: "64"
}, [
/* @__PURE__ */ c("path", {
/* @__PURE__ */ o("path", {
d: "M575.986694 832.039919C575.986694 867.356032 547.316113 896.026613 512 896.026613 476.683887 896.026613 448.013306 867.356032 448.013306 832.039919 448.013306 796.723806 476.683887 768.048156 512 768.048156 547.316113 768.048156 575.986694 796.64777 575.986694 832.039919ZM512 255.997465C476.683887 255.997465 448.013306 284.668046 448.013306 319.984159L448.013306 639.998733C448.013306 675.314846 476.683887 703.990496 512 703.990496 547.316113 703.990496 575.986694 675.314846 575.986694 639.998733L575.986694 319.984159C575.986694 284.668046 547.316113 255.997465 512 255.997465ZM1023.979724 896.026613C1023.979724 966.729805 966.709529 1024.005069 896.006336 1024.005069L127.993664 1024.005069C57.290471 1024.005069 0.020276 966.658839 0.020276 896.026613 0.020276 874.868373 5.216059 854.931776 14.39105 837.311737L14.320083 837.24077 398.250384 69.304133 398.392317 69.304133C419.626593 28.133261 462.455047 0.040552 512 0.040552 561.544953 0.040552 604.373407 28.209297 625.67865 69.3751L1008.311272 834.711311C1018.348003 852.838256 1023.979724 873.783595 1023.979724 896.026613ZM959.99303 896.026613C959.99303 885.123073 957.392604 874.868373 952.191753 865.404445L951.613881 864.319667 951.112044 863.239958 568.621355 98.405584C557.499847 77.171308 535.834701 64.027246 512 64.027246 488.023365 64.027246 466.282184 77.318311 455.160675 98.765487L452.12938 104.544211 92.175714 824.527578 92.677551 825.034483 71.154339 866.778159C66.389426 875.948082 64.00697 885.842879 64.00697 896.097579 64.00697 931.413692 92.748517 960.089342 127.993664 960.089342L896.006336 960.089342C931.322449 960.013306 959.99303 931.342726 959.99303 896.026613Z",
"p-id": "6384"
})
], -1)), Qt = { class: "captcha--error--text" }, te = /* @__PURE__ */ C({
], -1)), Kt = { class: "captcha--error--text" }, Qt = /* @__PURE__ */ C({
__name: "ErrorView",
emits: ["click"],
setup(t, { emit: e }) {
const a = e, n = B();
return (i, s) => (l(), m("div", {
return (c, s) => (l(), m("div", {
className: "captcha--error",
onClick: s[0] || (s[0] = (o) => a("click", o))
onClick: s[0] || (s[0] = (i) => a("click", i))
}, [
Kt,
c("div", Qt, D(y(n)("网络异常,请点击重试")), 1)
Jt,
o("div", Kt, D(y(n)("网络异常,请点击重试")), 1)
]));
}
}), ee = /* @__PURE__ */ _(te, [["__scopeId", "data-v-6ba70e16"]]), ae = {}, se = (t) => (E("data-v-edb749e2"), t = t(), T(), t), ne = { class: "captcha--loading" }, re = /* @__PURE__ */ se(() => /* @__PURE__ */ c("div", { class: "lds-ellipsis" }, [
/* @__PURE__ */ c("div"),
/* @__PURE__ */ c("div"),
/* @__PURE__ */ c("div"),
/* @__PURE__ */ c("div")
], -1)), ce = [
re
}), te = /* @__PURE__ */ _(Qt, [["__scopeId", "data-v-6ba70e16"]]), ee = {}, ae = (t) => (E("data-v-edb749e2"), t = t(), T(), t), ne = { class: "captcha--loading" }, se = /* @__PURE__ */ ae(() => /* @__PURE__ */ o("div", { class: "lds-ellipsis" }, [
/* @__PURE__ */ o("div"),
/* @__PURE__ */ o("div"),
/* @__PURE__ */ o("div"),
/* @__PURE__ */ o("div")
], -1)), re = [
se
];
function oe(t, e) {
return l(), m("div", ne, ce);
return l(), m("div", ne, re);
}
const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2"]]), q = (t) => (E("data-v-0a2d342a"), t = t(), T(), t), ue = { class: "captcha--box" }, de = { className: "captcha--bottom" }, le = /* @__PURE__ */ q(() => /* @__PURE__ */ c("path", {
const ce = /* @__PURE__ */ _(ee, [["render", oe], ["__scopeId", "data-v-edb749e2"]]), X = (t) => (E("data-v-0a2d342a"), t = t(), T(), t), ie = { class: "captcha--box" }, ue = { className: "captcha--bottom" }, de = /* @__PURE__ */ X(() => /* @__PURE__ */ o("path", {
d: "M715.7 794.7c-1.9-4.7-7.4-6.5-11.8-4-54.3 31.1-115.8 50.3-177.2 50.3-192.2 0-345.2-148.3-345.2-335.7 0-37.7 5.5-72.6 18.3-107.1l65.2 17.5c6.3 1.7 11.9-4.1 10-10.5l-55.5-183.1c-1.8-5.9-9.1-7.9-13.5-3.6l-139.4 131c-4.8 4.5-2.8 12.3 3.5 14.1l58.2 15.6c-15.7 42.6-25.4 86.5-25.4 135 0 226.6 187.9 409.8 419.5 409.8 76.7 0 149.6-18.6 215.5-55.9 3.6-2.1 5.2-6.5 3.6-10.4l-25.8-63zM308.2 229.2c1.9 4.7 7.4 6.5 11.8 4 54.3-31.2 115.8-50.3 177.2-50.3 192.2 0 345.2 148.3 345.2 335.7 0 37.7-5.5 72.6-18.3 107.1l-65.2-17.5c-6.3-1.7-11.9 4.1-10 10.5l55.5 183.1c1.8 5.9 9.1 7.9 13.5 3.6l139.5-130.8c4.8-4.5 2.8-12.3-3.5-14.1l-58.2-15.6c15.7-42.6 25.4-86.5 25.4-135 0-226.6-187.9-409.8-419.5-409.8-76.7 0-149.6 18.6-215.5 55.9-3.6 2.1-5.2 6.5-3.6 10.4l25.7 62.8z",
"p-id": "4400"
}, null, -1)), he = [
le
], pe = /* @__PURE__ */ q(() => /* @__PURE__ */ c("path", {
}, null, -1)), le = [
de
], he = /* @__PURE__ */ X(() => /* @__PURE__ */ o("path", {
d: "M509.866667 32C245.333333 32 32 247.466667 32 512s213.333333 480 477.866667 480S987.733333 776.533333 987.733333 512 774.4 32 509.866667 32z m0 896C281.6 928 96 742.4 96 512S281.6 96 509.866667 96 923.733333 281.6 923.733333 512s-185.6 416-413.866666 416z",
"p-id": "5378"
}, null, -1)), ve = /* @__PURE__ */ q(() => /* @__PURE__ */ c("path", {
}, null, -1)), pe = /* @__PURE__ */ X(() => /* @__PURE__ */ o("path", {
d: "M693.333333 330.666667c-12.8-12.8-32-12.8-44.8 0L512 467.2l-136.533333-136.533333c-12.8-12.8-32-12.8-44.8 0-12.8 12.8-12.8 32 0 44.8l136.533333 136.533333-136.533333 136.533333c-12.8 12.8-12.8 32 0 44.8 6.4 6.4 14.933333 8.533333 23.466666 8.533334s17.066667-2.133333 23.466667-8.533334l136.533333-136.533333 136.533334 136.533333c6.4 6.4 14.933333 8.533333 23.466666 8.533334s17.066667-2.133333 23.466667-8.533334c12.8-12.8 12.8-32 0-44.8L556.8 512l136.533333-136.533333c12.8-12.8 12.8-32 0-44.8z",
"p-id": "5379"
}, null, -1)), ge = [
pe,
ve
], fe = /* @__PURE__ */ C({
}, null, -1)), ve = [
he,
pe
], ge = /* @__PURE__ */ C({
__name: "Captcha",
props: {
requestCaptchaDataUrl: {
......@@ -621,17 +624,17 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
setup(t, { expose: e, emit: a }) {
const n = {
CONCAT: qt,
SLIDER: Ft,
ROTATE: Ut
}, i = a, s = t, o = $(
SLIDER: Gt,
ROTATE: Pt
}, c = a, s = t, i = $(
() => typeof s.radius == "number" && !isNaN(s.radius) && s.radius >= 0 ? { borderRadius: `${s.radius}px` } : {}
), u = rt(s, "locale");
$t(u);
const d = f(!1), r = f(!1), w = f(!1), p = f(), h = f(!1), v = f(), I = f(0), J = () => {
), u = st(s, "locale");
Tt(u);
const d = f(!1), r = f(!1), w = f(!1), p = f(), h = f(!1), v = f(), I = f(0), F = () => {
d.value = !0;
const L = ++I.value;
return new Promise((g, k) => {
Lt({
It({
url: s.requestCaptchaDataUrl,
data: {
extra: s.extra
......@@ -642,22 +645,22 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
L === I.value && (k(M), d.value = !1);
});
});
}, X = async () => {
}, j = async () => {
try {
p.value = await J();
p.value = await F();
} catch {
h.value = !0;
}
}, z = async () => {
r.value || w.value || (h.value = !1, r.value = !0, await X(), r.value = !1);
}, O = async () => {
r.value || w.value || (h.value = !1, r.value = !0, await j(), r.value = !1);
};
ct(z);
const K = async (L) => {
rt(O);
const J = async (L) => {
if (!p.value)
return;
const g = p.value;
w.value = !0;
const k = await kt({
const k = await Lt({
url: s.validCaptchaUrl,
data: {
key: g.key,
......@@ -665,20 +668,20 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
}
});
if (!k) {
g.verifyStatus = { status: !0 }, setTimeout(() => i("success", g.key), 1500);
g.verifyStatus = { status: !0 }, setTimeout(() => c("success", g.key), 1500);
return;
}
g.verifyStatus = {
status: !1,
message: k
}, setTimeout(() => {
w.value = !1, X();
w.value = !1, j();
}, 1500);
};
return e({
containerRef: v,
refresh: () => {
z();
O();
}
}), (L, g) => (l(), m("div", {
ref_key: "containerRef",
......@@ -687,24 +690,24 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
"captcha--container--radius": t.radius,
"captcha--container--shadow": t.shadow
}]),
style: S(o.value),
style: S(i.value),
onTouchmove: g[1] || (g[1] = P(() => {
}, ["prevent"])),
onMousemove: g[2] || (g[2] = P(() => {
}, ["prevent"]))
}, [
c("div", ue, [
o("div", ie, [
p.value ? (l(), x(ot(n[p.value.captcha.type]), {
key: p.value.key,
captcha: p.value.captcha,
verifyStatus: p.value.verifyStatus,
onVerify: K
onVerify: J
}, null, 40, ["captcha", "verifyStatus"])) : b("", !0),
p.value ? (l(), m(V, { key: 1 }, [], 64)) : b("", !0),
d.value ? (l(), x(ie, { key: 2 })) : b("", !0),
h.value ? (l(), x(ee, { key: 3 })) : b("", !0)
d.value ? (l(), x(ce, { key: 2 })) : b("", !0),
h.value ? (l(), x(te, { key: 3 })) : b("", !0)
]),
c("div", de, [
o("div", ue, [
(l(), m("svg", {
class: R(["captcha--svg-icon captcha--btn-refresh", {
"captcha--btn-refresh--active": r.value
......@@ -715,8 +718,8 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
"p-id": "4399",
width: "64",
height: "64",
onClick: z
}, he, 2)),
onClick: O
}, le, 2)),
t.showClose ? (l(), m("svg", {
key: 0,
class: "captcha--svg-icon captcha--btn-close",
......@@ -727,13 +730,13 @@ const ie = /* @__PURE__ */ _(ae, [["render", oe], ["__scopeId", "data-v-edb749e2
width: "64",
height: "64",
onClick: g[0] || (g[0] = () => {
w.value || i("close");
w.value || c("close");
})
}, ge)) : b("", !0)
}, ve)) : b("", !0)
])
], 38));
}
}), ye = /* @__PURE__ */ _(fe, [["__scopeId", "data-v-0a2d342a"]]);
}), me = /* @__PURE__ */ _(ge, [["__scopeId", "data-v-0a2d342a"]]);
export {
ye as Captcha
me as Captcha
};
{
"name": "fj-captcha-vue",
"version": "1.0.4",
"version": "1.0.5",
"type": "module",
"main": "./esm/index.js",
"typings": "./esm/index.d.ts",
......
......@@ -11,11 +11,6 @@ const translations: Record<string, Record<string, string>> = {
'zh-tw': zhTw,
}
/**
* 可用的语言标识
*/
const availableLanguages = Object.keys(translations)
/**
* 默认的语言标识
*/
......@@ -25,12 +20,16 @@ const DEFAULT_LANGUAGE = 'zh-cn'
* 标准化语言标识
* @param language
*/
function normalizeLanguage(language: string): string {
const parts = language.split(/_|-/)
if (parts.length > 2) {
parts.splice(1, parts.length - 2)
function normalizeLanguage(language: string) {
const parts = language.toLowerCase().split(/_|-/)
const lang = parts[0]
const country = parts.length > 1 ? parts[parts.length - 1] : undefined
const variant = parts.length > 2 ? parts[1] : undefined
return {
lang,
country,
variant,
}
return parts.map((t) => t.toLowerCase()).join('-')
}
/**
......@@ -45,28 +44,32 @@ export function getLanguage(language?: string): string {
? navigator.languages
: [DEFAULT_LANGUAGE]
languages = languages.map((t) => normalizeLanguage(t))
const langs = languages.map((t) => normalizeLanguage(t))
for (let language of languages) {
for (let lang of langs) {
//如果是英文那就返回英文
if (language === 'en' || language.startsWith('en-')) {
return 'en'
}
if (lang.lang === 'en') return 'en'
if (lang.lang === 'zh') {
//有变体优先判断变体
if (lang.variant === 'hans') {
return 'zh-cn'
} else if (lang.variant === 'hant') {
return 'zh-tw'
}
//如果是中文那就判断是简体还是繁体
if (language === 'zh' || language.startsWith('zh-')) {
if (availableLanguages.includes(language)) {
return language
//没有变体判断国家标识
if (lang.country === 'cn') {
return 'zh-cn'
} else if (lang.country === 'tw') {
return 'zh-tw'
}
//中文就默认用简体
//没有变体也没有国家标识就用简体中文
return 'zh-cn'
}
//都不是就继续循环
}
//到这里表示既不是英文,也不包含任何中文标识,那就用英文
return 'en'
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment