Files
cieanyau 651c36367f
前端验证 / verify (push) Failing after 15m2s
接入 ESLint 与 Prettier 并加入 CI 静态门禁
2026-11-07 01:24:36 +08:00

1461 lines
56 KiB
Vue

<script>
// 通用模块升级及展示适配:归一化按钮、镜像、图表和配置项,并管理配置/商品升级流程。
import "~/assets/styles/CommonUpgrade.C8sZ-ExM.css";
import { toDisplayString } from "vue";
import { renderList } from "vue";
import { onMounted } from "vue";
import { onBeforeUnmount } from "vue";
import { watch } from "vue";
import { createBlock } from "vue";
import { ref } from "vue";
import { withCtx } from "vue";
import { createCommentVNode } from "vue";
import { computed } from "vue";
import { isRef } from "vue";
import { createElementBlock } from "vue";
import { Fragment } from "vue";
import { createElementVNode } from "vue";
import { createTextVNode } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import { useApi } from "~/lib/auth.js";
import dialog from "primevue/dialog";
import button from "primevue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "primevue/message";
import select from "primevue/select";
import inputnumber from "primevue/inputnumber";
import { t as os_name_t } from "~/lib/os-name.js";
import { r as configuration_display_r } from "~/lib/configuration-display.js";
import { t as configuration_display_t } from "~/lib/configuration-display.js";
import { t as common_advanced_rules_t } from "~/lib/common-advanced-rules.js";
import multiselect from "primevue/multiselect";
var j = (e) => (e && typeof e == `object` && !Array.isArray(e) ? e : {}),
M = (e) => e === !0 || e === 1 || e === `1`,
N = (e) => e === !1 || e === 0 || e === `0`,
P = new Set([
`on`,
`off`,
`reboot`,
`hard_off`,
`hard_reboot`,
`crack_pass`,
`reinstall`,
`vnc`,
`rescue_system`,
]),
F = new Set([`on`, `off`, `reboot`, `hard_off`, `hard_reboot`, `vnc`]);
// 兼容单项或 console/control 分组按钮;仅开放已适配动作,重复项有禁用标记时从严合并。
function I(e, t) {
let n = (Array.isArray(e) ? e : [e])
.flatMap((e) => {
let t = j(e);
return t.func
? [t]
: [t.console, t.control].flatMap((e) =>
Array.isArray(e) ? e.map(j) : [],
);
})
.flatMap((e) => {
if (typeof e.func != `string` || !/^[a-z][a-z0-9_]*$/i.test(e.func))
return [];
let n = typeof e.type == `string` ? e.type : `default`,
r = M(e.disabled) || N(e.enabled) || N(e.enable),
i = !t && n === `custom` && e.func === `exitRescue` && !e.custom_fields,
a = !r && ((n === "default" && (t ? F : P).has(e.func)) || i);
return [
{
func: e.func,
name: String(e.name || e.func),
type: n,
supported: a,
reason: r
? `当前实例没有此操作权限`
: a
? void 0
: `此子模块操作暂未适配`,
},
];
});
return n
.filter((e, t) => n.findIndex((t) => t.func === e.func) === t)
.map((e) =>
n.some((t) => t.func === e.func && !t.supported)
? {
...e,
supported: !1,
reason: `当前实例未开放此操作`,
}
: e,
);
}
// 将配置项→系统→版本的嵌套镜像结构展开,保留版本所属 optionId 供重装接口使用。
function L(e) {
return (Array.isArray(e) ? e : [e]).flatMap((e) => {
let t = j(e);
return (Array.isArray(t.subs) ? t.subs : []).flatMap((e) => {
let n = j(e);
return (Array.isArray(n.version) ? n.version : []).flatMap((e) => {
let r = j(e),
i = Number(r.id),
a = Number(t.id);
return i > 0 && a > 0
? [
{
id: i,
optionId: a,
name: String(r.option_name || n.os || i),
os: String(r.option_param || ``),
group: String(n.os || ``),
},
]
: [];
});
});
});
}
// 将模块提供的图表类型及下拉选项转换为统一展示结构。
function R(e) {
return (Array.isArray(e) ? e : []).flatMap((e) => {
let t = j(e);
return typeof t.type != `string` || !t.type
? []
: [
{
title: String(t.title || t.type),
type: t.type,
select: (Array.isArray(t.select) ? t.select : []).map((e) => {
let t = j(e);
return {
name: String(t.name ?? t.value ?? ``),
value: String(t.value ?? ``),
};
}),
},
];
});
}
// 兼容多序列 value 列表与 in_bw/out_bw 列表;按首序列时间对齐,缺失采样保留 null。
function z(e) {
let t = j(e);
if (!Array.isArray(t.list)) throw Error(`图表数据格式暂未适配`);
let n = t.list,
r = n.length === 0 || Array.isArray(n[0]),
i = r ? n : [n, n],
a =
r && Array.isArray(t.label) ? t.label.map(String) : [`入带宽`, `出带宽`],
o = (e) => e.map(j),
s = (e) =>
typeof e == `number`
? new Date(e * 1e3).toLocaleString(`zh-CN`)
: String(e ?? ``),
c = o(i[0] || []).map((e) => s(e.time)),
l = i.map((e, t) => {
let n = new Map(
o(e).map((e) => [
s(e.time),
r ? e.value : e[t === 0 ? `in_bw` : `out_bw`],
]),
);
return {
name: a[t] || `数据 ${t + 1}`,
type: `line`,
showSymbol: !1,
data: c.map((e) => {
let t = n.get(e);
return t != null && t !== `` && Number.isFinite(Number(t))
? Number(t)
: null;
}),
};
});
return {
tooltip: {
trigger: `axis`,
renderMode: `richText`,
},
legend: {
data: l.map((e) => e.name),
},
grid: {
top: 48,
left: 56,
right: 20,
bottom: 45,
},
xAxis: {
type: `category`,
data: c,
},
yAxis: {
type: `value`,
name: String(t.unit || ``),
},
series: l,
};
}
// 当前配置按类型展示数量、级联路径或子项文本,镜像和网络标签沿用统一格式化规则。
function B(e) {
let t = e.unit ? ` ${e.unit}` : ``;
if (e.option_type === `cascade`) return String(e.cascade_path || `--`) + t;
if ([`quantity`, `quantity_range`].includes(String(e.option_type)))
return `${e.qty ?? 0}${t}`;
let n = configuration_display_t(
String(e.option_name || ``),
String(e.option_type || ``),
),
r = (Array.isArray(e.subs) ? e.subs : [])
.map(j)
.map((e) => {
let t = String(e.option_name || ``);
return [`操作系统`, `镜像版本`].includes(n)
? os_name_t(t)
: n === `网络类型`
? configuration_display_r(t)
: t;
})
.filter(Boolean);
return r.length ? r.join(`、`) + t : String(e.sub_name || `--`);
}
// 递归展开可见级联叶子为完整路径,深度上限避免异常后台树导致无限递归。
function V(e, t = [], n = 0) {
return !Array.isArray(e) || n > 20
? []
: e.flatMap((e) => {
let r = j(e);
if (Number(r.hidden) === 1) return [];
let i = [...t, String(r.item_name || r.item_id || ``)];
return Array.isArray(r.children) &&
r.children.length &&
Number(r.is_leaf) !== 1
? V(r.children, i, n + 1)
: Number(r.item_id) > 0
? [
{
value: Number(r.item_id),
label: i.join(` / `),
},
]
: [];
});
}
// 归一化可升级配置;数量区间按步长对齐,隐藏选项过滤后再判定是否支持编辑。
function H(e) {
return Array.isArray(e)
? e.flatMap((e) => {
let t = j(e);
if (!Number.isSafeInteger(Number(t.id)) || Number(t.id) <= 0) return [];
let n = String(t.option_type || ``),
r = (Array.isArray(t.subs) ? t.subs : [])
.map(j)
.filter((e) => Number(e.hidden) !== 1),
i =
n === `cascade`
? V(t.tree)
: n === `os`
? r.flatMap((e) =>
(Array.isArray(e.version) ? e.version : [])
.map(j)
.filter((e) => Number(e.hidden) !== 1)
.map((t) => ({
value: Number(t.id),
label: `${e.os || ``} / ${t.option_name || t.id}`,
})),
)
: r.map((e) => ({
value: Number(e.id),
label: String(e.option_name || e.id),
})),
a = Number(t.qty_min ?? r[0]?.qty_min ?? 1),
o = Number(t.qty_max ?? r.at(-1)?.qty_max ?? 999999),
s = n === `quantity` || n === `quantity_range`,
c = Math.max(1, Number(t.qty_change || 1)),
l =
n === `quantity_range`
? r
.map((e) => ({
min:
a +
Math.ceil((Math.max(a, Number(e.qty_min)) - a) / c) * c,
max:
a +
Math.floor((Math.min(o, Number(e.qty_max)) - a) / c) * c,
}))
.filter(
(e) =>
Number.isSafeInteger(e.min) &&
Number.isSafeInteger(e.max) &&
e.min <= e.max,
)
: void 0;
return [
{
id: String(t.id),
name: String(t.option_name || t.id),
type: n,
unit: String(t.unit || ``),
choices: i.filter(
(e) => Number.isSafeInteger(e.value) && e.value > 0,
),
min: a,
max: o,
step: c,
repeat:
Number(t.allow_repeat) === 1
? Math.max(1, Number(t.max_repeat || 1))
: 1,
ranges: l,
supported:
[
`quantity`,
`quantity_range`,
`select`,
`radio`,
`yes_no`,
`area`,
`os`,
`cascade`,
`multi_select`,
].includes(n) &&
(s
? Number.isFinite(a) &&
Number.isFinite(o) &&
o >= a &&
Number.isSafeInteger(c) &&
(n !== `quantity_range` || !!l?.length)
: i.length > 0),
},
];
})
: [];
}
// 校验表单成员、数量区间/步长和重复数量,分别生成普通与级联配置请求字段。
function U(e, t, n) {
let r = {},
i = {};
for (let a of e) {
if (!a.supported) throw Error(`${a.name}配置格式暂未适配`);
let e = t[a.id];
if (a.type === `cascade`) {
let e = n[a.id];
if (
!e ||
!a.choices.some((t) => t.value === e.item_id) ||
!Number.isSafeInteger(e.quantity) ||
e.quantity < 1
)
throw Error(`请选择有效的${a.name}`);
i[a.id] = {
item_id: e.item_id,
quantity: e.quantity,
};
} else if (a.type === `quantity` || a.type === `quantity_range`) {
let t = Array.isArray(e) ? e : [e],
n = a.ranges ?? [
{
min: a.min,
max: a.max,
},
];
if (
!t.length ||
t.length > a.repeat ||
t.some(
(e) =>
typeof e != `number` ||
!Number.isSafeInteger(e) ||
!n.some(
(t) => e >= t.min && e <= t.max && (e - t.min) % a.step === 0,
),
)
)
throw Error(`${a.name}数量或步长无效`);
r[a.id] = t;
} else if (a.type === `multi_select`) {
if (
!Array.isArray(e) ||
!e.length ||
e.some((e) => !a.choices.some((t) => t.value === e))
)
throw Error(`请选择有效的${a.name}`);
r[a.id] = [...new Set(e)];
} else {
if (typeof e != `number` || !a.choices.some((t) => t.value === e))
throw Error(`请选择有效的${a.name}`);
r[a.id] = e;
}
}
return {
configoption: r,
cascade_configoption: i,
};
}
// 升级状态机:配置升级通用于已适配模块,跨商品升级仅由 idcsmart_common 开放。
function W(e, t) {
let n = useApi(),
a = ref(`config`),
s = computed(() => e().module === `idcsmart_common`),
c = computed(() => a.value === `config` || s.value),
u = ref({}),
d = computed(() =>
(Array.isArray(u.value.upgrade) ? u.value.upgrade : []).map(j),
),
f = ref(0),
p = computed(() => d.value[f.value] || {}),
m = computed(() => {
let e =
a.value === `config`
? u.value.upgrade_configoptions
: p.value.configoptions;
return Array.isArray(e) ? e : [];
}),
h = computed(() =>
a.value === `config` ? u.value.advanced_rules : p.value.advanced_rules,
),
g = computed(() =>
a.value === `config`
? [
...(Array.isArray(j(e().current).configoptions)
? j(e().current).configoptions
: []),
...(Array.isArray(u.value.configoptions)
? u.value.configoptions
: []),
]
: [],
),
_ = computed(() => {
try {
return {
...common_advanced_rules_t(m.value, b.value, h.value, g.value),
error: ``,
};
} catch (e) {
return {
options: m.value,
form: b.value,
error: e instanceof Error ? e.message : `商品高级规则无效`,
};
}
}),
v = computed(() => H(_.value.options)),
b = ref({}),
x = ref({}),
S = ref(``),
C = computed(() => {
let e = j(p.value.common_product);
return [`free`, `onetime`].includes(String(e.pay_type))
? [
{
label: e.pay_type === `free` ? `免费` : `一次性`,
value: String(e.pay_type),
},
]
: (Array.isArray(p.value.custom_cycles)
? p.value.custom_cycles
: []
).map((e) => {
let t = j(e);
return {
label: String(t.name || t.id),
value: Number(t.id),
};
});
}),
w = computed(() =>
Number(
j(p.value.common_product).id ||
j(p.value.configoptions?.[0]).product_id,
),
),
T = computed(
() =>
a.value === `product` &&
((Array.isArray(p.value.son) && p.value.son.length > 0) ||
(Array.isArray(u.value.son_host) && u.value.son_host.length > 0)),
),
E = ref(!1),
D = ref(!1),
O = ref(!1),
A = ref(!1),
M = ref(!1),
N = ref(``),
P = ref(``),
F = ref(``),
I = !0,
L = 0,
R = 0,
z = !1,
B = computed(() =>
JSON.stringify([
e().hostId,
e().module,
e().allowed,
a.value,
f.value,
b.value,
x.value,
S.value,
]),
),
V = computed(
() =>
e().allowed &&
c.value &&
A.value &&
!E.value &&
!D.value &&
!O.value &&
F.value === B.value &&
P.value !== ``,
);
function W() {
(L++, (F.value = ``), (P.value = ``), (O.value = !1), (M.value = !1));
}
// 应用商品高级规则并同步联动后的表单;同步锁阻止 watch 再入递归。
function G() {
if (!z) {
if (_.value.error) throw Error(_.value.error);
if (JSON.stringify(b.value) !== JSON.stringify(_.value.form)) {
z = !0;
try {
b.value = _.value.form;
} finally {
z = !1;
}
}
}
}
// 配置升级优先使用实例当前值,换商品则使用目标默认值,并初始化周期和级联数量。
function K() {
let e = Array.isArray(u.value.configoptions)
? u.value.configoptions.map(j)
: [],
t = {},
n = {};
for (let r of H(m.value)) {
let i =
a.value === `config` ? e.filter((e) => String(e.id) === r.id) : [];
r.type === `cascade`
? (n[r.id] = {
item_id:
Number(i[0]?.current_cascade_item_id || i[0]?.cascade_item_id) ||
r.choices[0]?.value ||
null,
quantity: Number(i[0]?.qty) || 1,
})
: [`quantity`, `quantity_range`].includes(r.type)
? (t[r.id] = i.length
? i.map((e) => Number(e.qty) || r.min)
: [r.min])
: r.type === `multi_select`
? (t[r.id] = i.length
? i.map((e) => Number(e.configoption_sub_id))
: r.choices[0]
? [r.choices[0].value]
: [])
: (t[r.id] =
Number(i[0]?.configoption_sub_id) ||
r.choices[0]?.value ||
null);
}
((b.value = t),
(x.value = n),
(S.value = C.value[0]?.value ?? ``),
W(),
G());
}
// 按升级模式选择配置接口,实例或模式切换后通过代次废弃旧结果。
async function q() {
if (!I || D.value || !e().allowed) return;
if (!c.value) {
(R++,
W(),
(u.value = {}),
(A.value = !1),
(E.value = !1),
(N.value = `此模块未开放更换商品`));
return;
}
let t = ++R;
((E.value = !0), (A.value = !1), (N.value = ``), (u.value = {}), W());
try {
let r = await n.get(
`/${e().module}/host/${e().hostId}/${a.value === `config` ? `upgrade_config` : `upgrade`}`,
);
if (!I || t !== R) return;
if (
((u.value = j(r)),
!Array.isArray(
u.value[a.value === `config` ? `upgrade_configoptions` : `upgrade`],
))
)
throw Error(`升降级配置响应异常,请重试`);
((f.value = 0), (A.value = !0), K());
} catch (e) {
I &&
t === R &&
(N.value = e instanceof Error ? e.message : `升降级配置加载失败`);
} finally {
I && t === R && (E.value = !1);
}
}
// 统一构建报价/下单载荷;尚未适配含子商品组合的升级,不能只提交父商品。
function J() {
if (!c.value) throw Error(`此模块未开放更换商品`);
if (_.value.error) throw Error(_.value.error);
if (T.value) throw Error(`包含子商品的升降级组合暂未适配,请联系支持`);
let e = U(v.value, b.value, x.value);
if (a.value === `product`) {
if (!w.value || !C.value.some((e) => e.value === S.value))
throw Error(`请选择目标商品与周期`);
return {
...e,
product_id: w.value,
cycle: S.value,
};
}
return e;
}
// 高级规则联动完成后再记录快照;价格必须有效且非负,改动表单立即废弃报价。
async function Y() {
if (
!I ||
!A.value ||
E.value ||
D.value ||
!e().allowed ||
(!v.value.length && a.value === `config`)
)
return;
(W(), (N.value = ``));
let t = L,
// eslint-disable-next-line no-useless-assignment -- 边界一致性:保留 try 外 computed 求值及异常传播顺序。
r = B.value;
try {
(G(), (t = L), (r = B.value));
let i = J();
O.value = !0;
let o = await n.post(
`/${e().module}/host/${e().hostId}/${a.value === `config` ? `sync_upgrade_config_price` : `sync_upgrade_price`}`,
i,
);
if (!I || t !== L || r !== B.value) return;
let s = a.value === `product` ? o.upgrade_price : o.price;
if (
![`string`, `number`].includes(typeof s) ||
String(s).trim() === `` ||
!Number.isFinite(Number(s)) ||
Number(s) < 0
)
throw Error(`升降级报价无效,请重试`);
((P.value = String(s)), (F.value = r));
} catch (e) {
I &&
t === L &&
(N.value = e instanceof Error ? e.message : `获取报价失败`);
} finally {
I && t === L && (O.value = !1);
}
}
// 需要有效报价和用户确认;商品升级将配置包裹进 config_options,与配置升级载荷区分。
async function X() {
if (!I || !V.value || !M.value) return;
let r = B.value;
((D.value = !0), (N.value = ``));
try {
let i = J(),
o =
a.value === `config`
? i
: {
product_id: w.value,
config_options: i,
},
s = await n.post(
`/${e().module}/host/${e().hostId}/${a.value === `config` ? `upgrade_config` : `upgrade`}`,
o,
);
if (!I || r !== B.value) return;
if (!/^[1-9]\d*$/.test(String(s.id)))
throw Error(`订单响应无效,请到订单列表核实结果`);
(t({
order_id: s.id,
amount: P.value,
}),
W());
} catch (e) {
I &&
r === B.value &&
(N.value =
e instanceof Error
? e.message
: `创建订单失败,请先核实订单列表再重试`);
} finally {
I && (D.value = !1);
}
}
return (
watch(B, W, {
flush: `sync`,
}),
watch(
b,
() => {
if (!(!A.value || E.value || D.value || z))
try {
(G(), (N.value = ``));
} catch (e) {
(W(),
(N.value = e instanceof Error ? e.message : `商品高级规则无效`));
}
},
{
deep: !0,
flush: `sync`,
},
),
watch(a, () => {
q();
}),
watch(f, () => {
try {
K();
} catch (e) {
(W(), (N.value = e instanceof Error ? e.message : `商品高级规则无效`));
}
}),
watch(
() => [e().hostId, e().module, e().allowed],
() => {
(R++, W(), (u.value = {}), (A.value = !1), q());
},
{
flush: `sync`,
},
),
onBeforeUnmount(() => {
((I = !1), R++, W());
}),
{
mode: a,
productUpgradeSupported: s,
products: d,
selected: f,
options: v,
form: b,
cascade: x,
cycle: S,
cycles: C,
childProductsUnsupported: T,
loading: E,
busy: D,
quoting: O,
loaded: A,
confirming: M,
error: N,
price: P,
ready: V,
load: q,
quote: Y,
submit: X,
}
);
}
var G = {
key: 0,
class: `common-upgrade`,
},
K = {
class: `upgrade-toolbar`,
},
q = {
key: 0,
},
J = {
key: 2,
},
Y = {
key: 1,
},
X = {
key: 0,
},
ee = {
key: 0,
class: `muted`,
},
te = {
key: 3,
class: `upgrade-toolbar`,
},
ne = {
key: 0,
},
Z = Object.assign(
_plugin_vue_export_helper_t(
defineComponent({
__name: `CommonUpgrade`,
props: {
hostId: {},
module: {},
allowed: {
type: Boolean,
},
current: {},
},
emits: [`pay`],
setup(r, { expose: i, emit: o }) {
let g = r,
y = o,
{
mode: S,
productUpgradeSupported: E,
products: D,
selected: O,
options: k,
form: M,
cascade: N,
cycle: P,
cycles: F,
childProductsUnsupported: I,
loading: L,
busy: R,
quoting: z,
loaded: B,
confirming: V,
error: H,
price: U,
ready: Z,
load: Q,
quote: re,
submit: ie,
} = W(
() => g,
(e) => y(`pay`, e),
),
ae = computed(() =>
D.value.map((e, t) => ({
value: t,
label: String(j(e.common_product).name || `商品 ${t + 1}`),
})),
);
function $(e) {
let t = M.value[e];
return Array.isArray(t) ? t : [Number(t) || 0];
}
function oe(e, t, n) {
let r = $(e).slice();
((r[t] = n ?? 0), (M.value[e] = r));
}
return (
onMounted(Q),
i({
busy: R,
}),
(n, i) => {
let o = select,
l = button,
g = message,
y = inputnumber,
j = multiselect,
W = dialog;
return r.allowed
? (openBlock(),
createElementBlock(`section`, G, [
createElementVNode(`div`, K, [
createVNode(
o,
{
modelValue: unref(S),
"onUpdate:modelValue": (i[0] ||= (e) =>
isRef(S) ? (S.value = e) : null),
options: [
{
label: `调整配置`,
value: `config`,
},
...(unref(E)
? [
{
label: `更换商品`,
value: `product`,
},
]
: []),
],
"option-label": `label`,
"option-value": `value`,
"aria-label": `升降级类型`,
disabled: unref(R),
},
null,
8,
[`modelValue`, `options`, `disabled`],
),
createVNode(
l,
{
label: `刷新配置`,
severity: `secondary`,
loading: unref(L),
disabled: unref(R),
onClick: unref(Q),
},
null,
8,
[`loading`, `disabled`, `onClick`],
),
]),
unref(H)
? (openBlock(),
createBlock(
g,
{
key: 0,
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(H)), 1),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
unref(B)
? (openBlock(),
createElementBlock(
Fragment,
{
key: 1,
},
[
unref(S) === `product`
? (openBlock(),
createElementBlock(
Fragment,
{
key: 0,
},
[
(i[6] ||= createElementVNode(
`label`,
null,
`目标商品`,
-1,
)),
createVNode(
o,
{
modelValue: unref(O),
"onUpdate:modelValue": (i[1] ||= (e) =>
isRef(O) ? (O.value = e) : null),
options: unref(ae),
"option-label": `label`,
"option-value": `value`,
"aria-label": `目标商品`,
disabled: unref(R),
},
null,
8,
[`modelValue`, `options`, `disabled`],
),
unref(F).length
? (openBlock(),
createElementBlock(
`label`,
q,
`计费周期`,
))
: createCommentVNode(``, !0),
unref(F).length
? (openBlock(),
createBlock(
o,
{
key: 1,
modelValue: unref(P),
"onUpdate:modelValue": (i[2] ||= (
e,
) =>
isRef(P) ? (P.value = e) : null),
options: unref(F),
"option-label": `label`,
"option-value": `value`,
"aria-label": `计费周期`,
disabled: unref(R),
},
null,
8,
[`modelValue`, `options`, `disabled`],
))
: createCommentVNode(``, !0),
unref(D).length
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(
`p`,
J,
`当前没有可更换的商品。`,
)),
],
64,
))
: unref(k).length
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(
`p`,
Y,
`当前没有可调整的配置。`,
)),
unref(I)
? (openBlock(),
createBlock(
g,
{
key: 2,
severity: `warn`,
closable: !1,
},
{
default: withCtx(() => [
...(i[7] ||= [
createTextVNode(
`此商品包含联动子商品,请联系支持处理完整组合的升降级。`,
-1,
),
]),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
(openBlock(!0),
createElementBlock(
Fragment,
null,
renderList(
unref(k),
(n) => (
openBlock(),
createElementBlock(
`div`,
{
key: n.id,
class: `upgrade-option`,
},
[
createElementVNode(`label`, null, [
createTextVNode(
toDisplayString(n.name) + ` `,
1,
),
n.unit
? (openBlock(),
createElementBlock(
`small`,
X,
toDisplayString(n.unit),
1,
))
: createCommentVNode(``, !0),
]),
n.supported
? n.type === `quantity` ||
n.type === `quantity_range`
? (openBlock(),
createElementBlock(
Fragment,
{
key: 1,
},
[
(openBlock(!0),
createElementBlock(
Fragment,
null,
renderList(
$(n.id),
(e, t) => (
openBlock(),
createElementBlock(
`div`,
{
key: t,
class: `upgrade-toolbar`,
},
[
createVNode(
y,
{
"model-value": e,
min: n.min,
max: n.max,
step: n.step,
"aria-label": `${n.name} ${t + 1}`,
disabled:
unref(R),
"use-grouping":
!1,
"onUpdate:modelValue":
(e) =>
oe(
n.id,
t,
e,
),
},
null,
8,
[
`model-value`,
`min`,
`max`,
`step`,
`aria-label`,
`disabled`,
`onUpdate:modelValue`,
],
),
t > 0
? (openBlock(),
createBlock(
l,
{
key: 0,
label: `移除`,
text: ``,
severity: `secondary`,
disabled:
unref(R),
onClick: (
e,
) =>
(unref(M)[
n.id
] = $(
n.id,
).filter(
(e, n) =>
n !== t,
)),
},
null,
8,
[
`disabled`,
`onClick`,
],
))
: createCommentVNode(
``,
!0,
),
],
)
),
),
128,
)),
$(n.id).length < n.repeat
? (openBlock(),
createBlock(
l,
{
key: 0,
label: `添加配置`,
text: ``,
disabled: unref(R),
onClick: (e) =>
(unref(M)[n.id] = [
...$(n.id),
n.min,
]),
},
null,
8,
[`disabled`, `onClick`],
))
: createCommentVNode(``, !0),
],
64,
))
: n.type === `cascade` &&
unref(N)[n.id]
? (openBlock(),
createElementBlock(
Fragment,
{
key: 2,
},
[
createVNode(
o,
{
"model-value":
unref(N)[n.id]?.item_id,
options: n.choices,
"option-label": `label`,
"option-value": `value`,
"aria-label": n.name,
disabled: unref(R),
"onUpdate:modelValue": (
e,
) => {
unref(N)[n.id] &&
(unref(N)[
n.id
].item_id = e);
},
},
null,
8,
[
`model-value`,
`options`,
`aria-label`,
`disabled`,
`onUpdate:modelValue`,
],
),
createVNode(
y,
{
"model-value":
unref(N)[n.id]
?.quantity,
min: 1,
"aria-label": `${n.name}数量`,
disabled: unref(R),
"onUpdate:modelValue": (
e,
) => {
unref(N)[n.id] &&
(unref(N)[
n.id
].quantity = e || 1);
},
},
null,
8,
[
`model-value`,
`aria-label`,
`disabled`,
`onUpdate:modelValue`,
],
),
],
64,
))
: n.type === `multi_select`
? (openBlock(),
createBlock(
j,
{
key: 3,
modelValue: unref(M)[n.id],
"onUpdate:modelValue": (
e,
) => (unref(M)[n.id] = e),
options: n.choices,
"option-label": `label`,
"option-value": `value`,
"aria-label": n.name,
disabled: unref(R),
},
null,
8,
[
`modelValue`,
`onUpdate:modelValue`,
`options`,
`aria-label`,
`disabled`,
],
))
: (openBlock(),
createBlock(
o,
{
key: 4,
"model-value":
unref(M)[n.id],
options: n.choices,
"option-label": `label`,
"option-value": `value`,
"aria-label": n.name,
disabled: unref(R),
"onUpdate:modelValue": (
e,
) => (unref(M)[n.id] = e),
},
null,
8,
[
`model-value`,
`options`,
`aria-label`,
`disabled`,
`onUpdate:modelValue`,
],
))
: (openBlock(),
createElementBlock(
`p`,
ee,
`此配置类型暂未适配,请联系支持。`,
)),
],
)
),
),
128,
)),
unref(k).length ||
(unref(S) === `product` && unref(D).length)
? (openBlock(),
createElementBlock(`div`, te, [
createVNode(
l,
{
label: `获取本次费用`,
loading: unref(z),
disabled:
unref(R) ||
unref(I) ||
unref(k).some((e) => !e.supported),
onClick: unref(re),
},
null,
8,
[`loading`, `disabled`, `onClick`],
),
unref(U) === ``
? createCommentVNode(``, !0)
: (openBlock(),
createElementBlock(
`span`,
ne,
`本次费用:¥` +
toDisplayString(unref(U)),
1,
)),
createVNode(
l,
{
label: `核对并创建订单`,
disabled: !unref(Z),
onClick: (i[3] ||= (e) => (V.value = !0)),
},
null,
8,
[`disabled`],
),
]))
: createCommentVNode(``, !0),
],
64,
))
: createCommentVNode(``, !0),
createVNode(
W,
{
visible: unref(V),
"onUpdate:visible": (i[5] ||= (e) =>
isRef(V) ? (V.value = e) : null),
header: `确认升降级`,
modal: ``,
closable: !unref(R),
"close-on-escape": !unref(R),
draggable: !1,
style: {
width: `460px`,
maxWidth: `94vw`,
},
},
{
footer: withCtx(() => [
createVNode(
l,
{
label: `返回修改`,
severity: `secondary`,
disabled: unref(R),
onClick: (i[4] ||= (e) => (V.value = !1)),
},
null,
8,
[`disabled`],
),
createVNode(
l,
{
label: `确认创建订单`,
loading: unref(R),
disabled: !unref(Z),
onClick: unref(ie),
},
null,
8,
[`loading`, `disabled`, `onClick`],
),
]),
default: withCtx(() => [
createElementVNode(
`p`,
null,
`实例 #` +
toDisplayString(r.hostId) +
`,本次费用 ¥` +
toDisplayString(unref(U)) +
`。确认后将生成订单,付款完成后按服务端结果生效。`,
1,
),
unref(H)
? (openBlock(),
createBlock(
g,
{
key: 0,
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(
toDisplayString(unref(H)),
1,
),
]),
_: 1,
},
))
: createCommentVNode(``, !0),
]),
_: 1,
},
8,
[`visible`, `closable`, `close-on-escape`],
),
]))
: createCommentVNode(``, !0);
}
);
},
}),
[[`__scopeId`, `data-v-830ee5e4`]],
),
{
__name: `CommonUpgrade`,
},
);
export { B as a, z as i, I as n, L as o, R as r, j as s };
export default Z;
</script>