修复套餐计划重复的问题,先选择镜像再根据镜像显示兼容的套餐计划
This commit is contained in:
parent
f5132fbccf
commit
0803e58dcd
@ -32,31 +32,24 @@
|
|||||||
{{ getRegionName(region) }}
|
{{ getRegionName(region) }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<!-- 调试信息 -->
|
|
||||||
<div v-if="regions.length === 0" class="mt-2 text-sm text-gray-500">
|
|
||||||
正在加载区域列表...
|
|
||||||
</div>
|
|
||||||
<div v-if="regions.length > 0" class="mt-2 text-sm text-gray-500">
|
|
||||||
已加载 {{ regions.length }} 个区域
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">套餐选择</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">镜像选择(Jsite服务器推荐选择Ubuntu-22.04)</label>
|
||||||
<select v-model="selectedPlanId" class="w-full border rounded px-3 py-2" required>
|
<select v-model="selectedImageId" class="w-full border rounded px-3 py-2" required @change="onImageChange">
|
||||||
<option value="">请选择套餐</option>
|
<option value="">请选择镜像</option>
|
||||||
<option v-for="plan in plans" :key="plan.plan_id" :value="plan.plan_id">
|
<option v-for="image in images" :key="getImageId(image)" :value="getImageId(image)">
|
||||||
{{ getPlanDisplayName(plan) }}
|
{{ getImageDisplayName(image) }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-gray-700 mb-2">镜像选择</label>
|
<label class="block text-sm font-medium text-gray-700 mb-2">套餐选择</label>
|
||||||
<select v-model="selectedImageId" class="w-full border rounded px-3 py-2" required>
|
<select v-model="selectedPlanId" class="w-full border rounded px-3 py-2" required :disabled="!selectedImageId">
|
||||||
<option value="">请选择镜像</option>
|
<option value="">请选择套餐</option>
|
||||||
<option v-for="image in images" :key="getImageId(image)" :value="getImageId(image)">
|
<option v-for="plan in filteredPlans" :key="plan.plan_id" :value="plan.plan_id">
|
||||||
{{ getImageDisplayName(image) }}
|
{{ getPlanDisplayName(plan) }}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -533,6 +526,40 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
filteredPlans() {
|
||||||
|
// 如果没有选择镜像,返回空数组
|
||||||
|
if (!this.selectedImageId) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取选择的镜像信息
|
||||||
|
const selectedImage = this.images.find(img => this.getImageId(img) === this.selectedImageId);
|
||||||
|
if (!selectedImage) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取镜像平台信息
|
||||||
|
const imagePlatform = selectedImage.platform || '';
|
||||||
|
|
||||||
|
// 根据镜像平台过滤套餐
|
||||||
|
return this.plans.filter(plan => {
|
||||||
|
const supportPlatform = plan.support_platform;
|
||||||
|
if (!supportPlatform) {
|
||||||
|
return true; // 如果没有support_platform信息,默认显示
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 解析support_platform字段(JSON字符串格式)
|
||||||
|
const platforms = JSON.parse(supportPlatform);
|
||||||
|
return platforms.includes(imagePlatform);
|
||||||
|
} catch (e) {
|
||||||
|
// 如果解析失败,尝试字符串匹配
|
||||||
|
return supportPlatform.includes(imagePlatform);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
this.stopPaymentCheck();
|
this.stopPaymentCheck();
|
||||||
},
|
},
|
||||||
@ -547,13 +574,22 @@ export default {
|
|||||||
this.images = [];
|
this.images = [];
|
||||||
|
|
||||||
if (this.selectedRegionId) {
|
if (this.selectedRegionId) {
|
||||||
await this.$resources.aliyunPlans.submit({ region_id: this.selectedRegionId });
|
// 只加载镜像,套餐将在选择镜像后加载
|
||||||
await this.$resources.aliyunImages.submit({
|
await this.$resources.aliyunImages.submit({
|
||||||
region_id: this.selectedRegionId,
|
region_id: this.selectedRegionId,
|
||||||
image_type: 'system' // 明确指定镜像类型
|
image_type: 'system' // 明确指定镜像类型
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async onImageChange() {
|
||||||
|
this.selectedPlanId = '';
|
||||||
|
this.plans = [];
|
||||||
|
if (this.selectedImageId) {
|
||||||
|
await this.$resources.aliyunPlans.submit({
|
||||||
|
region_id: this.selectedRegionId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
async createInstance() {
|
async createInstance() {
|
||||||
if (!this.selectedRegionId || !this.selectedPlanId || !this.selectedImageId) {
|
if (!this.selectedRegionId || !this.selectedPlanId || !this.selectedImageId) {
|
||||||
this.error = '请选择完整配置';
|
this.error = '请选择完整配置';
|
||||||
@ -675,7 +711,7 @@ export default {
|
|||||||
return `${typePrefix}${cpu}核/${memoryDisplay}/${disk}GB/${bandwidthDisplay}/${publicIpNum}个公网IP - ¥${price}/月`;
|
return `${typePrefix}${cpu}核/${memoryDisplay}/${disk}GB/${bandwidthDisplay}/${publicIpNum}个公网IP - ¥${price}/月`;
|
||||||
},
|
},
|
||||||
getSelectedPlanPrice() {
|
getSelectedPlanPrice() {
|
||||||
const selectedPlan = this.plans.find(plan => plan.plan_id === this.selectedPlanId);
|
const selectedPlan = this.filteredPlans.find(plan => plan.plan_id === this.selectedPlanId);
|
||||||
return selectedPlan ? (selectedPlan.origin_price || 0) : 0;
|
return selectedPlan ? (selectedPlan.origin_price || 0) : 0;
|
||||||
},
|
},
|
||||||
getTotalAmount() {
|
getTotalAmount() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user