Files
console-dev/app/pages/products/dedicated-server/customize.vue
T

264 lines
9.4 KiB
Vue

<script>
/**
* 物理服务器定制入口:只接受有效商品 ID 且模块为 mf_dcim/remf_dcim,避免把其他类型商品交给物理服务器配置器。
*/
import { definePageMeta } from "#imports";
import "~/assets/styles/dedicated-server.CiJfMYtk.css";
import "~/assets/styles/ConfigDiskCard.Dx9IqqQ_.css";
import "~/assets/styles/PromoCodeField.qFEkB6Hm.css";
import "~/assets/styles/ProductCustomFields.B2QMnPil.css";
import "~/assets/styles/OsIcon.CAi4Iz2S.css";
import "~/assets/styles/MfDcimConfig.BhC_eZ0V.css";
import "~/assets/styles/PaymentDialog.BNFKQF1U.css";
import "~/assets/styles/customize.Cc123Awf.css";
definePageMeta({
key: (e) => e.fullPath,
});
import { toDisplayString } from "vue";
import { onMounted } from "vue";
import { onScopeDispose } 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 { createElementVNode } from "vue";
import { createTextVNode } from "vue";
import { unref } from "vue";
import { defineComponent } from "vue";
import { createVNode } from "vue";
import { openBlock } from "vue";
import { useRoute } from "#app";
import { useRouter } from "#app";
import { NuxtLink } from "#components";
import { useApi } from "~/lib/auth.js";
import button from "openvue/button";
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
import message from "openvue/message";
import PaymentDialog from "~/components/PaymentDialog.vue";
import skeleton from "openvue/skeleton";
import { t as product_order_module_t } from "~/lib/product-order-module.js";
import MfDcimConfig from "~/components/config/MfDcimConfig.vue";
import { t as composables_t } from "~/lib/composables-2.js";
import { t as product_description_data_t } from "~/lib/product-description-data.js";
import index from "~/pages/products/dedicated-server/index.vue";
import { productId } from "~/lib/product-id.js";
var A = {
key: 1,
class: `dedicated-customize`,
},
j = {
class: `product-links`,
},
M = {
key: 0,
class: `panel`,
},
N = {
key: 1,
class: `panel config-load-error`,
},
P = _plugin_vue_export_helper_t(
defineComponent({
__name: `customize`,
setup(p) {
let x = useRoute(),
P = useRouter(),
F = useApi(),
I = computed(() => x.query.id ?? x.query.product_id ?? ``);
composables_t({
key: (e) => e.fullPath,
});
let L = ref(null),
R = ref(!0),
z = ref(``),
B = ref(!1),
V = ref(null),
H = ref(``),
U = 0;
onScopeDispose(() => {
U++;
});
// 重新读取商品并解析实际模块;页面离开时提升序号,描述异步补全也必须匹配当前请求。
async function W() {
let e = ++U,
t = I.value;
((R.value = !0), (z.value = ``), (L.value = null));
try {
if (productId(t) === null) throw Error(`商品编号无效`);
let n = await F.get(`/product/${t}`);
if (e !== U) return;
let r = n?.product ?? n;
if (!r || Number(r.id) !== Number(t) || r.hidden === 1)
throw Error(`商品不存在或已下架`);
let i = r,
a = await product_order_module_t(F, i);
if (a !== `mf_dcim` && a !== `remf_dcim`)
throw Error(`该商品不支持物理服务器定制,请返回列表重新选择`);
((L.value = {
...i,
module: a,
}),
product_description_data_t(F, L.value).then((t) => {
e === U && L.value && (L.value.description = t);
}));
} catch (t) {
e === U &&
(z.value = t instanceof Error ? t.message : `加载商品失败`);
} finally {
e === U && (R.value = !1);
}
}
// 使用配置器返回的订单信息打开支付,不重复下单。
function G(e) {
((V.value = e.order_id), (H.value = e.amount), (B.value = !0));
}
return (
onMounted(() => {
I.value ? W() : (R.value = !1);
}),
// 只有已验证的物理商品挂载 MfDcimConfig,付款使用配置器返回订单而非再次下单。
(t, n) => {
let i = NuxtLink,
s = skeleton,
p = message,
g = button,
_ = MfDcimConfig,
y = PaymentDialog;
return unref(I)
? (openBlock(),
createElementBlock(`div`, A, [
createElementVNode(`header`, null, [
(n[4] ||= createElementVNode(
`h1`,
null,
`定制物理服务器`,
-1,
)),
createElementVNode(`div`, j, [
createVNode(
i,
{
to: `/products/dedicated-server`,
},
{
default: withCtx(() => [
...(n[2] ||= [
createElementVNode(
`i`,
{
class: `pi pi-angle-left`,
"aria-hidden": `true`,
},
null,
-1,
),
createTextVNode(`返回物理服务器列表`, -1),
]),
]),
_: 1,
},
),
createVNode(
i,
{
to: `/cart`,
},
{
default: withCtx(() => [
...(n[3] ||= [
createElementVNode(
`i`,
{
class: `pi pi-shopping-cart`,
"aria-hidden": `true`,
},
null,
-1,
),
createTextVNode(`购物车`, -1),
]),
]),
_: 1,
},
),
]),
]),
unref(R)
? (openBlock(),
createElementBlock(`div`, M, [
createVNode(s, {
height: `360px`,
}),
]))
: unref(z)
? (openBlock(),
createElementBlock(`div`, N, [
createVNode(
p,
{
severity: `error`,
closable: !1,
},
{
default: withCtx(() => [
createTextVNode(toDisplayString(unref(z)), 1),
]),
_: 1,
},
),
createVNode(g, {
label: `重新加载商品`,
icon: `pi pi-refresh`,
severity: `secondary`,
text: ``,
onClick: W,
}),
]))
: unref(L)
? (openBlock(),
createBlock(
_,
{
key: 2,
"product-id": unref(I),
module: unref(L).module,
"initial-product": unref(L),
onSettled: G,
},
null,
8,
[`product-id`, `module`, `initial-product`],
))
: createCommentVNode(``, !0),
createVNode(
y,
{
modelValue: unref(B),
"onUpdate:modelValue": (n[0] ||= (e) =>
isRef(B) ? (B.value = e) : null),
"order-id": unref(V),
amount: unref(H),
onSuccess: (n[1] ||= (e) => unref(P).push(`/orders`)),
},
null,
8,
[`modelValue`, `order-id`, `amount`],
),
]))
: (openBlock(),
createBlock(index, {
key: 0,
}));
}
);
},
}),
[[`__scopeId`, `data-v-5618b27d`]],
);
export {};
export default P;
</script>