1
1
forked from wangqifan/calc

Compare commits

..

11 Commits
main ... main

Author SHA1 Message Date
3934ce4542 修改按年优惠功能 2025-12-31 12:34:10 +08:00
9675aacdb0 更新数据库配置,修改MySQL密码以提高安全性。 2025-09-05 17:50:16 +08:00
70aecaa82d 更新数据库配置,修改MySQL主机地址和密码以增强安全性。 2025-09-05 17:49:20 +08:00
9558e84409 Merge branch 'main' of http://47.96.181.224:3000/wangqifan/calc 2025-09-02 17:54:20 +08:00
e634d68b53 更新API配置,使用相对路径以简化前端与后端的交互。 2025-09-02 17:52:41 +08:00
1192e5c518 删除前端构建的dist.zip文件,并更新API配置以使用相对路径,简化API调用。 2025-09-02 14:37:29 +08:00
d9c7da8ef9 更新实例搜索功能,添加gp2存储价格的计算逻辑,以确保在gp3价格为0时正确计算磁盘月度价格。 2025-09-01 16:47:21 +08:00
a4e6da603e 优化实例搜索功能,调整CPU核心数和内存容量的最大值,确保输入更灵活,同时限制返回结果数量至40条。 2025-08-29 18:42:01 +08:00
b1d50572df 更新实例搜索功能,调整CPU核心数和内存容量的最小值为0,以支持更灵活的资源配置。 2025-08-29 18:32:40 +08:00
a31ae8c6dd 更新AWS区域名称映射,替换为更完整的中文和英文名称,同时在实例搜索功能中添加gp2和gp3存储价格的计算逻辑。 2025-08-29 18:09:42 +08:00
02ba9ea77f 更新前端页面以支持按价格排序功能 2025-08-25 09:38:06 +08:00
13 changed files with 694 additions and 248 deletions

2
.env
View File

@ -1,2 +1,2 @@
# API配置 # API配置
VUE_APP_API_BASE_URL=http://localhost:8000 VUE_APP_API_BASE_URL=/api/

View File

@ -3,7 +3,7 @@ AWS_SECRET_ACCESS_KEY=BQjaaHNm5skCN/3k3r/uNdEG9xb49are+hv5fajK
AWS_DEFAULT_REGION=us-east-1 AWS_DEFAULT_REGION=us-east-1
# MySQL数据库配置 # MySQL数据库配置
MYSQL_HOST=47.76.209.7 MYSQL_HOST=163.123.183.106
MYSQL_USER=aws_price MYSQL_USER=aws_price
MYSQL_PASSWORD=123456 MYSQL_PASSWORD=YCwjLmHM5dZtwHEw
MYSQL_DATABASE=aws_price MYSQL_DATABASE=aws_price

View File

@ -0,0 +1,115 @@
# 云计算价格计算器 API 文档
**描述:** 支持多云平台价格计算的服务。
**基本 URL:** `/api`
---
## 端点
### 1. 获取区域列表
- **描述:** 获取指定平台的可用区域列表。
- **路径:** `GET /regions`
- **方法:** `GET`
- **查询参数:**
- `platform` (string, optional, default: "aws"): 云平台。支持的值: "aws", "azure", "aliyun"。
- **成功响应 (200):**
```json
[
{
"code": "us-east-1",
"name": "US East (N. Virginia)"
}
]
```
- **错误响应 (400):** 如果平台不受支持。
---
### 2. 获取实例类型
- **描述:** 获取指定平台的可用实例类型。
- **路径:** `GET /instance-types`
- **方法:** `GET`
- **查询参数:**
- `platform` (string, optional, default: "aws"): 云平台。
- **成功响应 (200):** 包含实例类型及其信息的字典。
- **错误响应 (400):** 如果平台不受支持。
---
### 3. 搜索实例
- **描述:** 搜索符合指定条件的实例类型。
- **路径:** `POST /search-instances`
- **方法:** `POST`
- **请求体:** `InstanceSearchRequest`
- **成功响应 (200):** 匹配的实例列表,按月度总价排序。
- **错误响应 (400):** 如果缺少必需的参数。
- **错误响应 (500):** 内部服务器错误。
---
### 4. 搜索实例 V2
- **描述:** 使用 MySQL 数据库搜索符合条件的 AWS 实例。
- **路径:** `POST /search-instances-v2`
- **方法:** `POST`
- **请求体:** `InstanceSearchRequestV2`
- **成功响应 (200):** 匹配的实例列表。
- **错误响应 (500):** 内部服务器错误。
---
### 5. 比较价格
- **描述:** 比较多种实例配置的价格。
- **路径:** `POST /compare-prices`
- **方法:** `POST`
- **请求体:** `PriceComparison`
- **成功响应 (200):** 包含配置及其计算价格的列表。
- **错误响应 (500):** 内部服务器错误。
---
## 数据模型
### `InstanceSearchRequest`
| 字段 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| `cpu_cores` | integer | CPU 核心数 | (optional) |
| `memory_gb` | float | 内存 (GB) | (optional) |
| `disk_gb` | integer | 磁盘大小 (GB) | (optional) |
| `region` | string | 区域 | (optional) |
| `operating_system` | string | 操作系统 | "Linux" |
| `platform` | string | 云平台 | "aws" |
### `InstanceSearchRequestV2`
| 字段 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| `cpu_cores` | integer | CPU 核心数 | (optional) |
| `memory_gb` | float | 内存 (GB) | (optional) |
| `disk_gb` | integer | 磁盘大小 (GB) | (optional) |
| `region` | string | 区域 | (optional) |
| `operating_system` | string | 操作系统 | "Linux" |
### `PriceComparison`
| 字段 | 类型 | 描述 |
|---|---|---|
| `configurations` | List[`PriceRequest`] | 价格请求配置列表 |
### `PriceRequest`
| 字段 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| `instance_type` | string | 实例类型 (required) | |
| `region` | string | 区域 (required) | |
| `operating_system` | string | 操作系统 (required) | |
| `purchase_option` | string | 购买选项 (required) | |
| `duration` | integer | 持续时间 | 1 |
| `disk_gb` | integer | 磁盘大小 (GB) | 0 |

217
backend/apifox_spec.yaml Normal file
View File

@ -0,0 +1,217 @@
openapi: 3.0.0
info:
title: 云计算价格计算器 API
description: 支持多云平台价格计算的服务。
version: "1.0.0"
servers:
- url: /api
description: Main API server
paths:
/regions:
get:
summary: 获取区域列表
description: 获取指定平台的可用区域列表。
parameters:
- name: platform
in: query
description: '云平台。支持的值: "aws", "azure", "aliyun"。'
required: false
schema:
type: string
default: "aws"
enum: ["aws", "azure", "aliyun"]
responses:
'200':
description: 成功响应
content:
application/json:
schema:
type: array
items:
type: object
properties:
code:
type: string
example: "us-east-1"
name:
type: string
example: "US East (N. Virginia)"
'400':
description: 如果平台不受支持。
/instance-types:
get:
summary: 获取实例类型
description: 获取指定平台的可用实例类型。
parameters:
- name: platform
in: query
description: 云平台。
required: false
schema:
type: string
default: "aws"
responses:
'200':
description: 成功响应,包含实例类型及其信息的字典。
content:
application/json:
schema:
type: object
'400':
description: 如果平台不受支持。
/search-instances:
post:
summary: 搜索实例
description: 搜索符合指定条件的实例类型。
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/InstanceSearchRequest'
responses:
'200':
description: 匹配的实例列表,按月度总价排序。
content:
application/json:
schema:
type: array
items:
type: object
'400':
description: 如果缺少必需的参数。
'500':
description: 内部服务器错误。
/search-instances-v2:
post:
summary: 搜索实例 V2
description: 使用 MySQL 数据库搜索符合条件的 AWS 实例。
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/InstanceSearchRequestV2'
responses:
'200':
description: 匹配的实例列表。
content:
application/json:
schema:
type: array
items:
type: object
'500':
description: 内部服务器错误。
/compare-prices:
post:
summary: 比较价格
description: 比较多种实例配置的价格。
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PriceComparison'
responses:
'200':
description: 包含配置及其计算价格的列表。
content:
application/json:
schema:
type: array
items:
type: object
'500':
description: 内部服务器错误。
components:
schemas:
InstanceSearchRequest:
type: object
properties:
cpu_cores:
type: integer
description: CPU 核心数
memory_gb:
type: number
format: float
description: 内存 (GB)
disk_gb:
type: integer
description: 磁盘大小 (GB)
region:
type: string
description: 区域
operating_system:
type: string
description: 操作系统
default: "Linux"
platform:
type: string
description: 云平台
default: "aws"
InstanceSearchRequestV2:
type: object
properties:
cpu_cores:
type: integer
description: CPU 核心数
memory_gb:
type: number
format: float
description: 内存 (GB)
disk_gb:
type: integer
description: 磁盘大小 (GB)
region:
type: string
description: 区域
operating_system:
type: string
description: 操作系统
default: "Linux"
PriceComparison:
type: object
properties:
configurations:
type: array
items:
$ref: '#/components/schemas/PriceRequest'
description: 价格请求配置列表
PriceRequest:
type: object
required:
- instance_type
- region
- operating_system
- purchase_option
properties:
instance_type:
type: string
description: 实例类型
region:
type: string
description: 区域
operating_system:
type: string
description: 操作系统
purchase_option:
type: string
description: 购买选项
duration:
type: integer
description: 持续时间
default: 1
disk_gb:
type: integer
description: 磁盘大小 (GB)
default: 0

View File

@ -30,210 +30,220 @@ AWS_PRICING_EBS = {
# 区域中文名称映射 # 区域中文名称映射
AWS_REGION_NAMES = { AWS_REGION_NAMES = {
"af-south-1": "非洲 (开普敦)", "Asia Pacific (Malaysia)":"区域:亚太地区(马来西亚)",
"ap-northeast-1": "亚太地区 (东京)", "Asia Pacific (Taipei)":"区域:亚太地区(台北)",
"ap-northeast-2": "亚太地区 (首尔)", "Asia Pacific (Thailand)":"区域:亚太地区(泰国)",
"ap-northeast-3": "亚太地区 (大阪)", "Mexico (Central)":"区域:墨西哥(中部)",
"ap-east-1": "亚太地区 (香港)", "Africa (Cape Town)":"区域:非洲(开普敦)",
"ap-south-1": "亚太地区 (孟买)", "Asia Pacific (Hong Kong)":"区域:亚太地区(香港)",
"ap-south-2": "亚太地区 (海得拉巴)", "Asia Pacific (Hyderabad)":"区域:亚太地区(海得拉巴)",
"ap-southeast-1": "亚太地区 (新加坡)", "Asia Pacific (Jakarta)":"区域:亚太地区(雅加达)",
"ap-southeast-2": "亚太地区 (悉尼)", "Asia Pacific (Melbourne)":"区域:亚太地区(墨尔本)",
"ap-southeast-3": "亚太地区 (雅加达)", "Asia Pacific (Osaka)":"区域:亚太地区(大阪)",
"ap-southeast-4": "亚太地区 (墨尔本)", "Canada West (Calgary)":"区域:加拿大西部(卡尔加里)",
"ap-southeast-5": "亚太地区 (马来西亚)", "EU (Milan)":"区域:欧洲地区(米兰)",
"ap-southeast-7": "亚太地区 (泰国)", "EU (Spain)":"区域:欧洲(西班牙)",
"ca-central-1": "加拿大 (中部)", "EU (Stockholm)":"区域:欧洲地区(斯德哥尔摩)",
"ca-west-1": "加拿大西部 (卡尔加里)", "EU (Zurich)":"区域:欧洲(苏黎世)",
"eu-central-1": "欧洲 (法兰克福)", "Israel (Tel Aviv)":"区域:以色列(特拉维夫)",
"eu-central-2": "欧洲 (苏黎世)", "Middle East (Bahrain)":"区域:中东(巴林)",
"eu-north-1": "欧洲 (斯德哥尔摩)", "Middle East (UAE)":"区域:中东(阿联酋)",
"eu-south-1": "欧洲 (米兰)", "US West (N. California)":"区域:美国西部(北加利福尼亚)",
"eu-south-2": "欧洲 (西班牙)", "Argentina (Buenos Aires)":"本地区域:阿根廷(布宜诺斯艾利斯)",
"eu-west-1": "欧洲 (爱尔兰)", "Asia Pacific (KDDI) - Osaka":"运营商区域:亚太地区KDDI 大阪",
"eu-west-2": "欧洲 (伦敦)", "Asia Pacific (KDDI) - Tokyo":"运营商区域:亚太地区KDDI 东京",
"eu-west-3": "欧洲 (巴黎)", "Asia Pacific (SKT) - Daejeon":"运营商区域:亚太地区SKT 大田",
"il-central-1": "以色列 (特拉维夫)", "Asia Pacific (SKT) - Seoul":"运营商区域:亚太地区SKT 首尔",
"me-central-1": "中东 (阿联酋)", "Australia (Perth)":"本地区域:澳大利亚(珀斯)",
"me-south-1": "中东 (巴林)", "Canada (BELL) - Toronto":"运营商区域:加拿大BELL 多伦多",
"mx-central-1": "墨西哥 (中部)", "Chile (Santiago)":"本地区域:智利(圣地亚哥)",
"sa-east-1": "南美洲 (圣保罗)", "Denmark (Copenhagen)":"本地区域:丹麦(哥本哈根)",
"us-east-1": "美国东部 (弗吉尼亚北部)", "EU (British Telecom) - Manchester":"运营商区域:欧洲(英国电信)- 曼彻斯特",
"us-east-2": "美国东部 (俄亥俄)", "EU (Vodafone) - Berlin":"运营商区域:欧洲Vodafone 柏林",
"us-east-2-mci-1": "美国东部 (堪萨斯城)", "EU (Vodafone) - Dortmund":"运营商区域:欧洲Vodafone 多特蒙德",
"us-gov-east-1": "AWS GovCloud (美国东部)", "EU (Vodafone) - London":"运营商区域:欧洲Vodafone 伦敦",
"us-gov-west-1": "AWS GovCloud (美国西部)", "EU (Vodafone) - Manchester":"运营商区域:欧洲Vodafone 曼彻斯特",
"us-west-1": "美国西部 (加利福尼亚北部)", "EU (Vodafone) - Munich":"运营商区域:欧洲Vodafone 慕尼黑",
"us-west-2": "美国西部 (俄勒冈)", "Finland (Helsinki)":"本地区域:芬兰(赫尔辛基)",
"ap-northeast-1-tpe-1": "亚太地区 (台湾)", "Germany (Hamburg)":"本地区域:德国(汉堡)",
"ap-northeast-1-wl1-kix1": "亚太地区 (KDDI) - 大阪", "India (Delhi)":"本地区域:印度(德里)",
"ap-northeast-1-wl1-nrt1": "亚太地区 (KDDI) - 东京", "India (Kolkata)":"本地区域:印度(加尔各答)",
"ap-northeast-2-wl1-cjj1": "亚太地区 (SKT) - 大田", "Mexico (Queretaro)":"本地区域:墨西哥(克雷塔罗)",
"ap-northeast-2-wl1-sel1": "亚太地区 (SKT) - 首尔", "Morocco (Casablanca)":"运营商区域:摩洛哥(卡萨布兰卡)",
"ca-central-1-wl1-yto1": "加拿大 (BELL) - 多伦多", "New Zealand (Auckland)":"本地区域:新西兰(奥克兰)",
"eu-central-1-wl1-ber1": "欧洲 (沃达丰) - 柏林", "Nigeria (Lagos)":"本地区域:尼日利亚(拉各斯)",
"eu-central-1-wl1-dtm1": "欧洲 (沃达丰) - 多特蒙德", "Oman (Muscat)":"本地区域:阿曼(马斯喀特)",
"eu-central-1-wl1-muc1": "欧洲 (沃达丰) - 慕尼黑", "Peru (Lima)":"本地区域:秘鲁(利马)",
"eu-west-2-wl1-lon1": "欧洲 (沃达丰) - 伦敦", "Philippines (Manila)":"本地区域:菲律宾(马尼拉)",
"eu-west-2-wl1-man1": "欧洲 (沃达丰) - 曼彻斯特", "Poland (Warsaw)":"本地区域:波兰(华沙)",
"eu-west-2-wl2-man1": "欧洲 (英国电信) - 曼彻斯特", "Senegal (Dakar)":"运营商区域:塞内加尔(达喀尔)",
"eu-west-3-wl1-cmn1": "摩洛哥 (卡萨布兰卡)", "Taiwan (Taipei)":"本地区域:台湾(台北)",
"us-east-1-wl1": "美国东部 (Verizon) - 波士顿", "Thailand (Bangkok)":"本地区域:泰国(曼谷)",
"us-east-1-wl1-atl1": "美国东部 (Verizon) - 亚特兰大", "US East (Atlanta)":"本地区域:美国东部(亚特兰大)",
"us-east-1-wl1-bna1": "美国东部 (Verizon) - 纳什维尔", "US East (Boston)":"本地区域:美国东部(波士顿)",
"us-east-1-wl1-chi1": "美国东部 (Verizon) - 芝加哥", "US East (Chicago)":"本地区域:美国东部(芝加哥)",
"us-east-1-wl1-clt1": "美国东部 (Verizon) - 夏洛特", "US East (Dallas)":"本地区域:美国东部(达拉斯)",
"us-east-1-wl1-dfw1": "美国东部 (Verizon) - 达拉斯", "US East (Houston)":"本地区域:美国东部(休斯顿)",
"us-east-1-wl1-dtw1": "美国东部 (Verizon) - 底特律", "US East (Kansas City 2)":"本地区域:美国东部(堪萨斯城 2",
"us-east-1-wl1-iah1": "美国东部 (Verizon) - 休斯顿", "US East (Lenexa)":"运营商区域:美国东部(列涅萨)",
"us-east-1-wl1-mia1": "美国东部 (Verizon) - 迈阿密", "US East (Miami)":"本地区域:美国东部(迈阿密)",
"us-east-1-wl1-msp1": "美国东部 (Verizon) - 明尼阿波利斯", "US East (Minneapolis)":"本地区域:美国东部(明尼阿波利斯)",
"us-east-1-wl1-nyc1": "美国东部 (Verizon) - 纽约", "US East (New York City)":"本地区域:美国东部(纽约市)",
"us-east-1-wl1-tpa1": "美国东部 (Verizon) - 坦帕", "US East (Philadelphia)":"本地区域:美国东部(费城)",
"us-east-1-wl1-was1": "美国东部 (Verizon) - 华盛顿特区", "US East (Verizon) - Atlanta":"运营商区域:美国东部(威瑞森)– 亚特兰大",
"us-west-2-wl1": "美国西部 (Verizon) - 旧金山湾区", "US East (Verizon) - Boston":"运营商区域:美国东部(威瑞森)– 波士顿",
"us-west-2-wl1-den1": "美国西部 (Verizon) - 丹佛", "US East (Verizon) - Charlotte":"运营商区域:美国东部(威瑞森)– 夏洛特",
"us-west-2-wl1-las1": "美国西部 (Verizon) - 拉斯维加斯", "US East (Verizon) - Chicago":"运营商区域:美国东部(威瑞森)– 芝加哥",
"us-west-2-wl1-lax1": "美国西部 (Verizon) - 洛杉矶", "US East (Verizon) - Dallas":"运营商区域:美国东部(威瑞森)– 达拉斯",
"us-west-2-wl1-phx1": "美国西部 (Verizon) - 凤凰城", "US East (Verizon) - Detroit":"运营商区域:美国东部(威瑞森)– 底特律",
"us-west-2-wl1-sea1": "美国西部 (Verizon) - 西雅图", "US East (Verizon) - Houston":"运营商区域:美国东部(威瑞森)– 休斯顿",
"af-south-1-los-1": "尼日利亚 (拉各斯)", "US East (Verizon) - Miami":"运营商区域:美国东部(威瑞森)– 迈阿密",
"ap-south-1-ccu-1": "印度 (加尔各答)", "US East (Verizon) - Minneapolis":"运营商区域:美国东部(威瑞森)– 明尼阿波利斯",
"ap-south-1-del-1": "印度 (德里)", "US East (Verizon) - Nashville":"运营商区域:美国东部(威瑞森)- 纳什维尔",
"ap-southeast-1-bkk-1": "泰国 (曼谷)", "US East (Verizon) - New York":"运营商区域:美国东部(威瑞森)– 纽约",
"ap-southeast-1-mnl-1": "菲律宾 (马尼拉)", "US East (Verizon) - Tampa":"运营商区域:美国东部(威瑞森)– 坦帕",
"ap-southeast-2-akl-1": "新西兰 (奥克兰)", "US East (Verizon) - Washington DC":"运营商区域:美国东部(威瑞森)– 华盛顿特区",
"ap-southeast-2-per-1": "澳大利亚 (珀斯)", "US West (Denver)":"本地区域:美国西部(丹佛)",
"eu-central-1-ham-1": "德国 (汉堡)", "US West (Honolulu)":"本地区域:美国西部(檀香山)",
"eu-central-1-waw-1": "波兰 (华沙)", "US West (Las Vegas)":"本地区域:美国西部(拉斯维加斯)",
"eu-north-1-cph-1": "丹麦 (哥本哈根)", "US West (Los Angeles)":"本地区域:美国西部(洛杉矶)",
"eu-north-1-hel-1": "芬兰 (赫尔辛基)", "US West (Phoenix)":"本地区域:美国西部(菲尼克斯)",
"me-south-1-mct-1": "阿曼 (马斯喀特)", "US West (Portland)":"本地区域:美国西部(波特兰)",
"us-east-1-atl-1": "美国东部 (亚特兰大)", "US West (Seattle)":"本地区域:美国西部(西雅图)",
"us-east-1-bos-1": "美国东部 (波士顿)", "US West (Verizon) - Denver":"运营商区域:美国西部(威瑞森)- 丹佛",
"us-east-1-bue-1": "阿根廷 (布宜诺斯艾利斯)", "US West (Verizon) - Las Vegas":"运营商区域:美国西部(威瑞森)- 拉斯维加斯",
"us-east-1-chi-1": "美国东部 (芝加哥)", "US West (Verizon) - Los Angeles":"运营商区域:美国西部(威瑞森)– 洛杉矶",
"us-east-1-dfw-1": "美国东部 (达拉斯)", "US West (Verizon) - Phoenix":"运营商区域:美国东部(威瑞森)– 凤凰城",
"us-east-1-iah-1": "美国东部 (休斯顿)", "US West (Verizon) - San Francisco Bay Area":"运营商区域:美国西部(威瑞森)– 旧金山港湾区",
"us-east-1-lim-1": "秘鲁 (利马)", "US West (Verizon) - Seattle":"运营商区域:美国西部(威瑞森)- 西雅图",
"us-east-1-mci-1": "美国东部 (堪萨斯城 2)", "AWS GovCloud (US)":"区域:AWS GovCloud美国西部",
"us-east-1-mia-1": "美国东部 (迈阿密)", "AWS GovCloud (US-East)":"区域:AWS GovCloud美国东部",
"us-east-1-msp-1": "美国东部 (明尼阿波利斯)", "Asia Pacific (Mumbai)":"区域:亚太地区(孟买)",
"us-east-1-nyc-1": "美国东部 (纽约市)", "Asia Pacific (Seoul)":"区域:亚太地区(首尔)",
"us-east-1-phl-1": "美国东部 (费城)", "Asia Pacific (Singapore)":"区域:亚太地区(新加坡)",
"us-east-1-qro-1": "墨西哥 (克雷塔罗)", "Asia Pacific (Sydney)":"区域:亚太地区(悉尼)",
"us-east-1-scl-1": "智利 (圣地亚哥)", "Asia Pacific (Tokyo)":"区域:亚太地区(东京)",
"us-west-2-den-1": "美国西部 (丹佛)", "Canada (Central)":"区域:加拿大(中部)",
"us-west-2-hnl-1": "美国西部 (火奴鲁鲁)", "EU (Frankfurt)":"区域:欧洲地区(法兰克福)",
"us-west-2-las-1": "美国西部 (拉斯维加斯)", "EU (Ireland)":"区域:欧洲地区(爱尔兰)",
"us-west-2-lax-1": "美国西部 (洛杉矶)", "EU (London)":"区域:欧洲地区(伦敦)",
"us-west-2-pdx-1": "美国西部 (波特兰)", "South America (Sao Paulo)":"区域:南美洲(圣保罗)",
"us-west-2-phx-1": "美国西部 (凤凰城)", "US East (N. Virginia)":"区域:美国东部(弗吉尼亚州北部)",
"us-west-2-sea-1": "美国西部 (西雅图)" "US East (Ohio)":"区域:美国东部(俄亥俄州)",
"US West (Oregon)":"区域:美国西部(俄勒冈州)",
"EU (Paris)":"区域:欧洲地区(巴黎)"
} }
AWS_REGION_NAMES_EN = { AWS_REGION_NAMES_EN = {
"af-south-1": "Africa (Cape Town)", "Asia Pacific (Malaysia)":"Asia Pacific (Malaysia)",
"ap-northeast-1": "Asia Pacific (Tokyo)", "Asia Pacific (Taipei)":"Asia Pacific (Taipei)",
"ap-northeast-2": "Asia Pacific (Seoul)", "Asia Pacific (Thailand)":"Asia Pacific (Thailand)",
"ap-northeast-3": "Asia Pacific (Osaka)", "Mexico (Central)":"Mexico (Central)",
"ap-south-1": "Asia Pacific (Mumbai)", "Africa (Cape Town)":"Africa (Cape Town)",
"ap-east-1": "Asia Pacific (Hong Kong)", "Asia Pacific (Hong Kong)":"Asia Pacific (Hong Kong)",
"ap-south-2": "Asia Pacific (Hyderabad)", "Asia Pacific (Hyderabad)":"Asia Pacific (Hyderabad)",
"ap-southeast-1": "Asia Pacific (Singapore)", "Asia Pacific (Jakarta)":"Asia Pacific (Jakarta)",
"ap-southeast-2": "Asia Pacific (Sydney)", "Asia Pacific (Melbourne)":"Asia Pacific (Melbourne)",
"ap-southeast-3": "Asia Pacific (Jakarta)", "Asia Pacific (Osaka)":"Asia Pacific (Osaka)",
"ap-southeast-4": "Asia Pacific (Melbourne)", "Canada West (Calgary)":"Canada West (Calgary)",
"ap-southeast-5": "Asia Pacific (Malaysia)", "EU (Milan)":"EU (Milan)",
"ap-southeast-7": "Asia Pacific (Thailand)", "EU (Spain)":"EU (Spain)",
"ca-central-1": "Canada (Central)", "EU (Stockholm)":"EU (Stockholm)",
"ca-west-1": "Canada West (Calgary)", "EU (Zurich)":"EU (Zurich)",
"eu-central-1": "EU (Frankfurt)", "Israel (Tel Aviv)":"Israel (Tel Aviv)",
"eu-central-2": "EU (Zurich)", "Middle East (Bahrain)":"Middle East (Bahrain)",
"eu-north-1": "EU (Stockholm)", "Middle East (UAE)":"Middle East (UAE)",
"eu-south-1": "EU (Milan)", "US West (N. California)":"US West (N. California)",
"eu-south-2": "EU (Spain)", "External":"External",
"eu-west-1": "EU (Ireland)", "Amazon CloudFront":"Amazon CloudFront",
"eu-west-2": "EU (London)", "Argentina (Buenos Aires)":"Argentina (Buenos Aires)",
"eu-west-3": "EU (Paris)", "Asia Pacific (KDDI) - Osaka":"Asia Pacific (KDDI) - Osaka",
"il-central-1": "Israel (Tel Aviv)", "Asia Pacific (KDDI) - Tokyo":"Asia Pacific (KDDI) - Tokyo",
"me-central-1": "Middle East (UAE)", "Asia Pacific (New Zealand)":"Asia Pacific (New Zealand)",
"me-south-1": "Middle East (Bahrain)", "Asia Pacific (SKT) - Daejeon":"Asia Pacific (SKT) - Daejeon",
"mx-central-1": "Mexico (Central)", "Asia Pacific (SKT) - Seoul":"Asia Pacific (SKT) - Seoul",
"sa-east-1": "South America (Sao Paulo)", "Australia (Perth)":"Australia (Perth)",
"us-east-1": "US East (N. Virginia)", "Canada (BELL) - Toronto":"Canada (BELL) - Toronto",
"us-east-2": "US East (Ohio)", "Chile (Santiago)":"Chile (Santiago)",
"us-east-2-mci-1": "US East (Kansas City)", "Denmark (Copenhagen)":"Denmark (Copenhagen)",
"us-gov-east-1": "AWS GovCloud (US-East)", "EU (British Telecom) - Manchester":"EU (British Telecom) - Manchester",
"us-gov-west-1": "AWS GovCloud (US)", "EU (Vodafone) - Berlin":"EU (Vodafone) - Berlin",
"us-west-1": "US West (N. California)", "EU (Vodafone) - Dortmund":"EU (Vodafone) - Dortmund",
"us-west-2": "US West (Oregon)", "EU (Vodafone) - London":"EU (Vodafone) - London",
"ap-northeast-1-wl1-kix1": "Asia Pacific (KDDI) - Osaka", "EU (Vodafone) - Manchester":"EU (Vodafone) - Manchester",
"ap-northeast-1-wl1-nrt1": "Asia Pacific (KDDI) - Tokyo", "EU (Vodafone) - Munich":"EU (Vodafone) - Munich",
"ap-northeast-2-wl1-cjj1": "Asia Pacific (SKT) - Daejeon", "Finland (Helsinki)":"Finland (Helsinki)",
"ap-northeast-2-wl1-sel1": "Asia Pacific (SKT) - Seoul", "Germany (Hamburg)":"Germany (Hamburg)",
"ap-northeast-1-tpe-1": "Asia Pacific (Taiwan)", "India (Delhi)":"India (Delhi)",
"ca-central-1-wl1-yto1": "Canada (BELL) - Toronto", "India (Kolkata)":"India (Kolkata)",
"eu-central-1-wl1-ber1": "EU (Vodafone) - Berlin", "Mexico (Queretaro)":"Mexico (Queretaro)",
"eu-central-1-wl1-dtm1": "EU (Vodafone) - Dortmund", "Morocco (Casablanca)":"Morocco (Casablanca)",
"eu-central-1-wl1-muc1": "EU (Vodafone) - Munich", "New Zealand (Auckland)":"New Zealand (Auckland)",
"eu-west-2-wl1-lon1": "EU (Vodafone) - London", "Nigeria (Lagos)":"Nigeria (Lagos)",
"eu-west-2-wl1-man1": "EU (Vodafone) - Manchester", "Oman (Muscat)":"Oman (Muscat)",
"eu-west-2-wl2-man1": "EU (British Telecom) - Manchester", "Peru (Lima)":"Peru (Lima)",
"eu-west-3-wl1-cmn1": "Morocco (Casablanca)", "Philippines (Manila)":"Philippines (Manila)",
"us-east-1-wl1": "US East (Verizon) - Boston", "Poland (Warsaw)":"Poland (Warsaw)",
"us-east-1-wl1-atl1": "US East (Verizon) - Atlanta", "SG Government (Singapore)":"SG Government (Singapore)",
"us-east-1-wl1-bna1": "US East (Verizon) - Nashville", "Senegal (Dakar)":"Senegal (Dakar)",
"us-east-1-wl1-chi1": "US East (Verizon) - Chicago", "Taiwan (Taipei)":"Taiwan (Taipei)",
"us-east-1-wl1-clt1": "US East (Verizon) - Charlotte", "Thailand (Bangkok)":"Thailand (Bangkok)",
"us-east-1-wl1-dfw1": "US East (Verizon) - Dallas", "US East (Atlanta)":"US East (Atlanta)",
"us-east-1-wl1-dtw1": "US East (Verizon) - Detroit", "US East (Boston)":"US East (Boston)",
"us-east-1-wl1-iah1": "US East (Verizon) - Houston", "US East (Chicago)":"US East (Chicago)",
"us-east-1-wl1-mia1": "US East (Verizon) - Miami", "US East (Dallas)":"US East (Dallas)",
"us-east-1-wl1-msp1": "US East (Verizon) - Minneapolis", "US East (Houston)":"US East (Houston)",
"us-east-1-wl1-nyc1": "US East (Verizon) - New York", "US East (Kansas City 2)":"US East (Kansas City 2)",
"us-east-1-wl1-tpa1": "US East (Verizon) - Tampa", "US East (Kansas City)":"US East (Kansas City)",
"us-east-1-wl1-was1": "US East (Verizon) - Washington DC", "US East (Lenexa)":"US East (Lenexa)",
"us-west-2-wl1": "US West (Verizon) - San Francisco Bay Area", "US East (Miami)":"US East (Miami)",
"us-west-2-wl1-den1": "US West (Verizon) - Denver", "US East (Minneapolis)":"US East (Minneapolis)",
"us-west-2-wl1-las1": "US West (Verizon) - Las Vegas", "US East (New York City)":"US East (New York City)",
"us-west-2-wl1-lax1": "US West (Verizon) - Los Angeles", "US East (Philadelphia)":"US East (Philadelphia)",
"us-west-2-wl1-phx1": "US West (Verizon) - Phoenix", "US East (South Bend)":"US East (South Bend)",
"us-west-2-wl1-sea1": "US West (Verizon) - Seattle", "US East (Verizon) - Atlanta":"US East (Verizon) - Atlanta",
"af-south-1-los-1": "Nigeria (Lagos)", "US East (Verizon) - Boston":"US East (Verizon) - Boston",
"ap-south-1-ccu-1": "India (Kolkata)", "US East (Verizon) - Charlotte":"US East (Verizon) - Charlotte",
"ap-south-1-del-1": "India (Delhi)", "US East (Verizon) - Chicago":"US East (Verizon) - Chicago",
"ap-southeast-1-bkk-1": "Thailand (Bangkok)", "US East (Verizon) - Dallas":"US East (Verizon) - Dallas",
"ap-southeast-1-mnl-1": "Philippines (Manila)", "US East (Verizon) - Detroit":"US East (Verizon) - Detroit",
"ap-southeast-2-akl-1": "New Zealand (Auckland)", "US East (Verizon) - Houston":"US East (Verizon) - Houston",
"ap-southeast-2-per-1": "Australia (Perth)", "US East (Verizon) - Miami":"US East (Verizon) - Miami",
"eu-central-1-ham-1": "Germany (Hamburg)", "US East (Verizon) - Minneapolis":"US East (Verizon) - Minneapolis",
"eu-central-1-waw-1": "Poland (Warsaw)", "US East (Verizon) - Nashville":"US East (Verizon) - Nashville",
"eu-north-1-cph-1": "Denmark (Copenhagen)", "US East (Verizon) - New York":"US East (Verizon) - New York",
"eu-north-1-hel-1": "Finland (Helsinki)", "US East (Verizon) - Tampa":"US East (Verizon) - Tampa",
"me-south-1-mct-1": "Oman (Muscat)", "US East (Verizon) - Washington DC":"US East (Verizon) - Washington DC",
"us-east-1-atl-1": "US East (Atlanta)", "US West (Denver)":"US West (Denver)",
"us-east-1-bos-1": "US East (Boston)", "US West (Honolulu)":"US West (Honolulu)",
"us-east-1-bue-1": "Argentina (Buenos Aires)", "US West (Las Vegas)":"US West (Las Vegas)",
"us-east-1-chi-1": "US East (Chicago)", "US West (Los Angeles)":"US West (Los Angeles)",
"us-east-1-dfw-1": "US East (Dallas)", "US West (Phoenix)":"US West (Phoenix)",
"us-east-1-iah-1": "US East (Houston)", "US West (Portland)":"US West (Portland)",
"us-east-1-lim-1": "Peru (Lima)", "US West (Seattle)":"US West (Seattle)",
"us-east-1-mci-1": "US East (Kansas City 2)", "US West (Verizon) - Denver":"US West (Verizon) - Denver",
"us-east-1-mia-1": "US East (Miami)", "US West (Verizon) - Las Vegas":"US West (Verizon) - Las Vegas",
"us-east-1-msp-1": "US East (Minneapolis)", "US West (Verizon) - Los Angeles":"US West (Verizon) - Los Angeles",
"us-east-1-nyc-1": "US East (New York City)", "US West (Verizon) - Phoenix":"US West (Verizon) - Phoenix",
"us-east-1-phl-1": "US East (Philadelphia)", "US West (Verizon) - San Francisco Bay Area":"US West (Verizon) - San Francisco Bay Area",
"us-east-1-qro-1": "Mexico (Queretaro)", "US West (Verizon) - Seattle":"US West (Verizon) - Seattle",
"us-east-1-scl-1": "Chile (Santiago)", "AWS GovCloud (US)":"AWS GovCloud (US)",
"us-west-2-den-1": "US West (Denver)", "AWS GovCloud (US-East)":"AWS GovCloud (US-East)",
"us-west-2-hnl-1": "US West (Honolulu)", "Asia Pacific (Mumbai)":"Asia Pacific (Mumbai)",
"us-west-2-las-1": "US West (Las Vegas)", "Asia Pacific (Seoul)":"Asia Pacific (Seoul)",
"us-west-2-lax-1": "US West (Los Angeles)", "Asia Pacific (Singapore)":"Asia Pacific (Singapore)",
"us-west-2-pdx-1": "US West (Portland)", "Asia Pacific (Sydney)":"Asia Pacific (Sydney)",
"us-west-2-phx-1": "US West (Phoenix)", "Asia Pacific (Tokyo)":"Asia Pacific (Tokyo)",
"us-west-2-sea-1": "US West (Seattle)" "Canada (Central)":"Canada (Central)",
"EU (Frankfurt)":"EU (Frankfurt)",
"EU (Ireland)":"EU (Ireland)",
"EU (London)":"EU (London)",
"South America (Sao Paulo)":"South America (Sao Paulo)",
"US East (N. Virginia)":"US East (N. Virginia)",
"US East (Ohio)":"US East (Ohio)",
"US West (Oregon)":"US West (Oregon)",
"EU (Paris)":"EU (Paris)"
} }
# 可以添加其他云平台的配置 # 可以添加其他云平台的配置
AZURE_REGION_NAMES = { AZURE_REGION_NAMES = {

View File

@ -58,6 +58,8 @@ async def search_instances_v2(
operating_system, operating_system,
vcpu, vcpu,
memory, memory,
gp3,
gp2,
updatetime updatetime
FROM aws_price FROM aws_price
WHERE 1=1 WHERE 1=1
@ -69,11 +71,11 @@ async def search_instances_v2(
query += " AND area_en = %s" query += " AND area_en = %s"
params.append(region_name) params.append(region_name)
if cpu_cores: if cpu_cores > 0:
query += " AND vcpu = %s" query += " AND vcpu = %s"
params.append(cpu_cores) params.append(cpu_cores)
if memory_gb: if memory_gb > 0:
query += " AND memory = %s" query += " AND memory = %s"
params.append(memory_gb) params.append(memory_gb)
@ -86,10 +88,15 @@ async def search_instances_v2(
cursor.execute(query, params) cursor.execute(query, params)
results = cursor.fetchall() results = cursor.fetchall()
if len(results) >= 40:
results = results[0:40]
# 处理结果 # 处理结果
instances = [] instances = []
for row in results: for row in results:
hourly_price = float(row['price']) hourly_price = float(row['price'])
gp3_price = float(row['gp3'])
gp2_price = float(row['gp2'])
monthly_price = hourly_price * 730 # 730小时/月 monthly_price = hourly_price * 730 # 730小时/月
# 计算存储价格 # 计算存储价格
@ -102,7 +109,8 @@ async def search_instances_v2(
region_code = code region_code = code
break break
disk_monthly_price = await calculate_ebs_price(region_code, disk_gb) if region_code else 0 # disk_monthly_price = await calculate_ebs_price(region_code, disk_gb) if region_code else 0
disk_monthly_price = gp3_price * disk_gb if gp3_price > 0 else gp2_price * disk_gb
# 计算总价格 # 计算总价格
total_monthly_price = monthly_price + disk_monthly_price total_monthly_price = monthly_price + disk_monthly_price

View File

@ -1,2 +1,2 @@
# 生产环境API配置 # 生产环境API配置
VUE_APP_API_BASE_URL=http://calc.buddyscloud.com:8000 VUE_APP_API_BASE_URL=/api

Binary file not shown.

View File

@ -41,7 +41,7 @@ const apiService = {
// 获取区域列表 // 获取区域列表
getRegions: async () => { getRegions: async () => {
try { try {
const response = await apiClient.get('/api/regions') const response = await apiClient.get('/regions')
return response.data return response.data
} catch (error) { } catch (error) {
console.error('获取区域列表失败:', error) console.error('获取区域列表失败:', error)
@ -52,7 +52,7 @@ const apiService = {
// 获取实例类型列表 // 获取实例类型列表
getInstanceTypes: async () => { getInstanceTypes: async () => {
try { try {
const response = await apiClient.get('/api/instance-types') const response = await apiClient.get('/instance-types')
return response.data return response.data
} catch (error) { } catch (error) {
console.error('获取实例类型列表失败:', error) console.error('获取实例类型列表失败:', error)
@ -63,7 +63,7 @@ const apiService = {
// 搜索实例 // 搜索实例
searchInstances: async (params) => { searchInstances: async (params) => {
try { try {
const response = await apiClient.post('/api/search-instances-v2', params) const response = await apiClient.post('/search-instances-v2', params)
return response.data return response.data
} catch (error) { } catch (error) {
console.error('搜索实例失败:', error) console.error('搜索实例失败:', error)
@ -74,7 +74,7 @@ const apiService = {
// 计算价格 // 计算价格
calculatePrice: async (params) => { calculatePrice: async (params) => {
try { try {
const response = await apiClient.post('/api/calculate-price', params) const response = await apiClient.post('/calculate-price', params)
return response.data return response.data
} catch (error) { } catch (error) {
console.error('计算价格失败:', error) console.error('计算价格失败:', error)
@ -85,7 +85,7 @@ const apiService = {
// 比较价格 // 比较价格
comparePrices: async (params) => { comparePrices: async (params) => {
try { try {
const response = await apiClient.post('/api/compare-prices', params) const response = await apiClient.post('/compare-prices', params)
return response.data return response.data
} catch (error) { } catch (error) {
console.error('比较价格失败:', error) console.error('比较价格失败:', error)
@ -96,7 +96,7 @@ const apiService = {
// 获取预算估算 // 获取预算估算
getBudgetEstimate: async (params) => { getBudgetEstimate: async (params) => {
try { try {
const response = await apiClient.post('/api/budget', params) const response = await apiClient.post('/budget', params)
return response.data return response.data
} catch (error) { } catch (error) {
console.error('获取预算估算失败:', error) console.error('获取预算估算失败:', error)

View File

@ -1,7 +1,9 @@
// API 配置文件 // API 配置文件
const config = { const config = {
// 后端API基础URL - 从环境变量中读取,如果不存在则使用默认值 // 后端API基础URL 使用相对路径,通过 devServer 代理到后端
apiBaseUrl: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8000', // apiBaseUrl: process.env.VUE_APP_API_BASE_URL ,
apiBaseUrl: '/api',
// 其他全局配置 // 其他全局配置
defaultRegion: 'us-east-1', defaultRegion: 'us-east-1',

View File

@ -361,25 +361,41 @@
<el-table-column label="官方月付全额" width="120" align="center"> <el-table-column label="官方月付全额" width="120" align="center">
<template #default="scope"> <template #default="scope">
<span class="price-value">${{ scope.row.total_monthly_price.toFixed(2) }}</span> <div class="price-breakdown-text">
<div>实例: ${{ (Number(scope.row.monthly_price) || 0).toFixed(2) }}</div>
<div>磁盘: ${{ (Number(scope.row.disk_monthly_price) || 0).toFixed(2) }}</div>
<div class="price-value highlight">共计: ${{ getOfficialMonthlyPrice(scope.row).toFixed(2) }}</div>
</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="月付优惠价" width="120" align="center"> <el-table-column label="月付优惠价" width="120" align="center">
<template #default="scope"> <template #default="scope">
<span class="price-value highlight">${{ (scope.row.total_monthly_price * form.monthly_discount).toFixed(2) }}</span> <div class="price-breakdown-text">
<div>实例: ${{ (scope.row.monthly_price * form.monthly_discount).toFixed(2) }}</div>
<div>磁盘: ${{ scope.row.disk_monthly_price.toFixed(2) }}</div>
<div class="price-value highlight">共计: ${{ getDiscountedMonthlyPrice(scope.row).toFixed(2) }}</div>
</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="官方年付全额" width="120" align="center"> <el-table-column label="官方年付全额" width="120" align="center">
<template #default="scope"> <template #default="scope">
<span class="price-value">${{ (scope.row.total_monthly_price * 12).toFixed(2) }}</span> <div class="price-breakdown-text">
<div>实例: ${{ ((Number(scope.row.monthly_price) || 0) * 12).toFixed(2) }}</div>
<div>磁盘: ${{ ((Number(scope.row.disk_monthly_price) || 0) * 12).toFixed(2) }}</div>
<div class="price-value highlight">共计: ${{ getOfficialYearlyPrice(scope.row).toFixed(2) }}</div>
</div>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="年付优惠价" width="120" align="center"> <el-table-column label="年付优惠价" width="120" align="center">
<template #default="scope"> <template #default="scope">
<span class="price-value highlight">${{ (scope.row.total_monthly_price * 12 * form.yearly_discount).toFixed(2) }}</span> <div class="price-breakdown-text">
<div>实例: ${{ (scope.row.monthly_price * 12 * form.yearly_discount).toFixed(2) }}</div>
<div>磁盘: ${{ (scope.row.disk_monthly_price * 12).toFixed(2) }}</div>
<div class="price-value highlight">共计: ${{ getDiscountedYearlyPrice(scope.row).toFixed(2) }}</div>
</div>
</template> </template>
</el-table-column> </el-table-column>
@ -401,8 +417,8 @@
<div class="note-title">说明事项:</div> <div class="note-title">说明事项:</div>
<div class="note-items"> <div class="note-items">
<div class="note-item">1. 以上价格仅包服务器和磁盘的费用, 以上价格仅包服务器和磁盘的费用, 公共带宽流量按官网价格 均价$0.12USD/GB</div> <div class="note-item">1. 以上价格仅包服务器和磁盘的费用, 以上价格仅包服务器和磁盘的费用, 公共带宽流量按官网价格 均价$0.12USD/GB</div>
<div class="note-item">2. 月付按官网价 {{ formatDiscount(form.monthly_discount) }} </div> <div class="note-item">2. 月付仅实例部分按官网价 {{ formatDiscount(form.monthly_discount) }} 磁盘不参与优惠</div>
<div class="note-item">3. 年付按官网价 {{ formatDiscount(form.yearly_discount) }} </div> <div class="note-item">3. 年付仅实例部分按官网价 {{ formatDiscount(form.yearly_discount) }} 磁盘不参与优惠</div>
</div> </div>
</div> </div>
@ -605,10 +621,32 @@
// //
const dataRows = this.comparisonList.map(instance => { const dataRows = this.comparisonList.map(instance => {
const officialMonthlyPrice = instance.total_monthly_price const officialMonthlyPrice = this.getOfficialMonthlyPrice(instance)
const discountedMonthlyPrice = officialMonthlyPrice * this.form.monthly_discount const officialYearlyPrice = this.getOfficialYearlyPrice(instance)
const officialYearlyPrice = officialMonthlyPrice * 12 const discountedMonthlyPrice = this.getDiscountedMonthlyPrice(instance)
const discountedYearlyPrice = officialYearlyPrice * this.form.yearly_discount const discountedYearlyPrice = this.getDiscountedYearlyPrice(instance)
const instanceMonthlyPrice = Number(instance.monthly_price) || 0
const diskMonthlyPrice = Number(instance.disk_monthly_price) || 0
const officialMonthlyDetail = [
`实例: $${instanceMonthlyPrice.toFixed(2)}`,
`磁盘: $${diskMonthlyPrice.toFixed(2)}`,
`共计: $${officialMonthlyPrice.toFixed(2)}`
].join('\n')
const discountedMonthlyDetail = [
`实例: $${(instanceMonthlyPrice * Number(this.form.monthly_discount || 0)).toFixed(2)}`,
`磁盘: $${diskMonthlyPrice.toFixed(2)}`,
`共计: $${discountedMonthlyPrice.toFixed(2)}`
].join('\n')
const officialYearlyDetail = [
`实例: $${(instanceMonthlyPrice * 12).toFixed(2)}`,
`磁盘: $${(diskMonthlyPrice * 12).toFixed(2)}`,
`共计: $${officialYearlyPrice.toFixed(2)}`
].join('\n')
const discountedYearlyDetail = [
`实例: $${(instanceMonthlyPrice * 12 * Number(this.form.yearly_discount || 0)).toFixed(2)}`,
`磁盘: $${(diskMonthlyPrice * 12).toFixed(2)}`,
`共计: $${discountedYearlyPrice.toFixed(2)}`
].join('\n')
return [ return [
'EC2', 'EC2',
@ -616,10 +654,10 @@
`${instance.disk_gb}G GP3`, `${instance.disk_gb}G GP3`,
this.formatOS(instance.operating_system), this.formatOS(instance.operating_system),
this.getRegionName(instance.region), this.getRegionName(instance.region),
officialMonthlyPrice.toFixed(2), officialMonthlyDetail,
discountedMonthlyPrice.toFixed(2), discountedMonthlyDetail,
officialYearlyPrice.toFixed(2), officialYearlyDetail,
discountedYearlyPrice.toFixed(2) discountedYearlyDetail
] ]
}) })
@ -628,8 +666,8 @@
emptyRow, emptyRow,
['说明事项:'], ['说明事项:'],
['1. 以上价格仅包服务器和磁盘的费用, 以上价格仅包服务器和磁盘的费用, 公共带宽流量按官网价格 均价$0.12USD/GB'], ['1. 以上价格仅包服务器和磁盘的费用, 以上价格仅包服务器和磁盘的费用, 公共带宽流量按官网价格 均价$0.12USD/GB'],
[`2. 月付按官网价 ${this.formatDiscount(this.form.monthly_discount)}`], [`2. 月付(仅实例部分)按官网价 ${this.formatDiscount(this.form.monthly_discount)},磁盘不参与优惠`],
[`3. 年付按官网价 ${this.formatDiscount(this.form.yearly_discount)}`] [`3. 年付(仅实例部分)按官网价 ${this.formatDiscount(this.form.yearly_discount)},磁盘不参与优惠`]
] ]
// //
@ -656,6 +694,9 @@
const rowHeights = Array(allRows.length).fill({ hpt: 25 }) const rowHeights = Array(allRows.length).fill({ hpt: 25 })
rowHeights[0] = { hpt: 35 } // rowHeights[0] = { hpt: 35 } //
rowHeights[4] = { hpt: 30 } // rowHeights[4] = { hpt: 30 } //
for (let i = 0; i < dataRows.length; i++) {
rowHeights[4 + 1 + i] = { hpt: 55 }
}
ws['!rows'] = rowHeights ws['!rows'] = rowHeights
// //
@ -737,11 +778,20 @@
} }
} }
//
for (let r = noteStartRow; r < noteStartRow + 5; r++) {
for (let c = 0; c < 9; c++) {
const cellRef = XLSX.utils.encode_cell({ r, c })
if (!ws[cellRef]) ws[cellRef] = { v: '', t: 's' }
if (!ws[cellRef].s) ws[cellRef].s = {}
ws[cellRef].s.alignment = { horizontal: 'left', vertical: 'center', wrapText: true }
}
}
// //
const priceColsStyle = { const priceColsStyle = {
numFmt: '0.00',
font: { color: { rgb: '1F7B69' } }, font: { color: { rgb: '1F7B69' } },
alignment: { horizontal: 'center', vertical: 'center' }, alignment: { horizontal: 'left', vertical: 'center', wrapText: true },
border: { border: {
top: { style: 'thin' }, top: { style: 'thin' },
bottom: { style: 'thin' }, bottom: { style: 'thin' },
@ -808,6 +858,26 @@
if (os === 'Windows') return 'Windows' if (os === 'Windows') return 'Windows'
return os return os
}, },
getOfficialMonthlyPrice(instance) {
const instancePrice = Number(instance.monthly_price) || 0
const diskPrice = Number(instance.disk_monthly_price) || 0
return instancePrice + diskPrice
},
getOfficialYearlyPrice(instance) {
return this.getOfficialMonthlyPrice(instance) * 12
},
getDiscountedMonthlyPrice(instance) {
const instancePrice = Number(instance.monthly_price) || 0
const diskPrice = Number(instance.disk_monthly_price) || 0
const discount = Number(this.form.monthly_discount) || 0
return instancePrice * discount + diskPrice
},
getDiscountedYearlyPrice(instance) {
const instancePrice = Number(instance.monthly_price) || 0
const diskPrice = Number(instance.disk_monthly_price) || 0
const discount = Number(this.form.yearly_discount) || 0
return instancePrice * 12 * discount + diskPrice * 12
},
// //
calculateDiscountedPrice(originalPrice, discount) { calculateDiscountedPrice(originalPrice, discount) {
return originalPrice * discount; return originalPrice * discount;
@ -956,14 +1026,22 @@
font-weight: 500; font-weight: 500;
} }
.price-value.highlight { .price-value.highlight {
color: #2ecc71; color: #2ecc71;
font-weight: 700; font-weight: 700;
} }
.no-results { .price-breakdown-text {
display: flex;
flex-direction: column;
gap: 2px;
font-size: 12px;
line-height: 1.3;
}
.no-results {
padding: 40px 0; padding: 40px 0;
} }
.selected-instance { .selected-instance {
margin-top: 40px; margin-top: 40px;

View File

@ -15,8 +15,8 @@
<el-form-item label="CPU 核心数"> <el-form-item label="CPU 核心数">
<el-input-number <el-input-number
v-model="form.cpu_cores" v-model="form.cpu_cores"
:min="1" :min="0"
:max="64" :max="9999"
:step="1" :step="1"
placeholder="所需CPU核心数" placeholder="所需CPU核心数"
class="full-width"> class="full-width">
@ -28,8 +28,8 @@
<el-form-item label="内存(GB)"> <el-form-item label="内存(GB)">
<el-input-number <el-input-number
v-model="form.memory_gb" v-model="form.memory_gb"
:min="0.5" :min="0"
:max="256" :max="99999"
:step="0.5" :step="0.5"
placeholder="所需内存容量(GB)" placeholder="所需内存容量(GB)"
class="full-width"> class="full-width">
@ -388,8 +388,8 @@ export default {
data() { data() {
return { return {
form: { form: {
cpu_cores: null, cpu_cores: 0,
memory_gb: null, memory_gb: 0,
disk_gb: 30, // 30GB disk_gb: 30, // 30GB
region: 'us-east-1', region: 'us-east-1',
disk_type: 'gp3', disk_type: 'gp3',

16
frontend/vue.config.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://127.0.0.1:8000',
changeOrigin: true,
ws: false,
secure: false,
// 保留 /api 前缀并转发到后端 FastAPI后端已以 /api 为前缀)
pathRewrite: { '^/api': '/api' },
},
},
},
}