1
1
forked from wangqifan/calc

前台区域改成输入选择框

This commit is contained in:
wangqifan 2025-04-02 21:51:36 +08:00
parent 79dd7667bf
commit 5bb223d6c8
3 changed files with 66 additions and 10 deletions

View File

@ -54,9 +54,16 @@
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :md="6" :sm="24"> <el-col :md="6" :sm="24">
<el-form-item label="区域"> <el-form-item label="区域">
<el-select v-model="form.region" placeholder="请选择区域" class="full-width"> <el-select
v-model="form.region"
placeholder="请选择区域"
class="full-width"
filterable
clearable
:filter-method="filterRegions"
:remote-method="filterRegions">
<el-option <el-option
v-for="region in regions" v-for="region in filteredRegions"
:key="region.code" :key="region.code"
:label="region.name" :label="region.name"
:value="region.code"> :value="region.code">
@ -435,6 +442,7 @@
yearly_discount: 0.85 // 60%6 yearly_discount: 0.85 // 60%6
}, },
regions: [], regions: [],
filteredRegions: [], //
searchResults: [], searchResults: [],
selectedInstance: null, selectedInstance: null,
comparisonList: [], // comparisonList: [], //
@ -450,6 +458,7 @@
try { try {
// 使API // 使API
this.regions = await apiService.getRegions() this.regions = await apiService.getRegions()
this.filteredRegions = [...this.regions] //
// //
if (this.regions && this.regions.length > 0) { if (this.regions && this.regions.length > 0) {
@ -457,7 +466,7 @@
} }
// //
const savedComparison = localStorage.getItem('instance_comparison') const savedComparison = localStorage.getItem('instance_comparison_discount')
if (savedComparison) { if (savedComparison) {
this.comparisonList = JSON.parse(savedComparison) this.comparisonList = JSON.parse(savedComparison)
} }
@ -467,6 +476,16 @@
} }
}, },
methods: { methods: {
filterRegions(query) {
if (query) {
this.filteredRegions = this.regions.filter(region => {
return region.name.toLowerCase().includes(query.toLowerCase()) ||
region.code.toLowerCase().includes(query.toLowerCase())
})
} else {
this.filteredRegions = [...this.regions]
}
},
async searchInstances() { async searchInstances() {
if (!this.form.cpu_cores && !this.form.memory_gb && !this.form.disk_gb) { if (!this.form.cpu_cores && !this.form.memory_gb && !this.form.disk_gb) {
this.$message.warning('请至少指定一项配置要求') this.$message.warning('请至少指定一项配置要求')
@ -540,7 +559,7 @@
this.$message.success('已添加到对比列表') this.$message.success('已添加到对比列表')
// //
localStorage.setItem('instance_comparison', JSON.stringify(this.comparisonList)) localStorage.setItem('instance_comparison_discount', JSON.stringify(this.comparisonList))
// //
setTimeout(() => { setTimeout(() => {
@ -552,12 +571,12 @@
}, },
removeFromComparison(index) { removeFromComparison(index) {
this.comparisonList.splice(index, 1) this.comparisonList.splice(index, 1)
localStorage.setItem('instance_comparison', JSON.stringify(this.comparisonList)) localStorage.setItem('instance_comparison_discount', JSON.stringify(this.comparisonList))
this.$message.success('已从对比列表中移除') this.$message.success('已从对比列表中移除')
}, },
clearComparison() { clearComparison() {
this.comparisonList = [] this.comparisonList = []
localStorage.removeItem('instance_comparison') localStorage.removeItem('instance_comparison_discount')
this.$message.success('已清空对比列表') this.$message.success('已清空对比列表')
}, },
exportComparison() { exportComparison() {

View File

@ -54,9 +54,16 @@
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :md="6" :sm="24"> <el-col :md="6" :sm="24">
<el-form-item label="区域"> <el-form-item label="区域">
<el-select v-model="form.region" placeholder="请选择区域" class="full-width"> <el-select
v-model="form.region"
placeholder="请选择区域"
class="full-width"
filterable
clearable
:filter-method="filterRegions"
:remote-method="filterRegions">
<el-option <el-option
v-for="region in regions" v-for="region in filteredRegions"
:key="region.code" :key="region.code"
:label="region.name" :label="region.name"
:value="region.code"> :value="region.code">
@ -389,6 +396,7 @@ export default {
operating_system: 'Linux' // Linux operating_system: 'Linux' // Linux
}, },
regions: [], regions: [],
filteredRegions: [], //
searchResults: [], searchResults: [],
selectedInstance: null, selectedInstance: null,
comparisonList: [], // comparisonList: [], //
@ -404,6 +412,7 @@ export default {
try { try {
// 使API // 使API
this.regions = await apiService.getRegions() this.regions = await apiService.getRegions()
this.filteredRegions = [...this.regions] //
// //
if (this.regions && this.regions.length > 0) { if (this.regions && this.regions.length > 0) {
@ -421,6 +430,16 @@ export default {
} }
}, },
methods: { methods: {
filterRegions(query) {
if (query) {
this.filteredRegions = this.regions.filter(region => {
return region.name.toLowerCase().includes(query.toLowerCase()) ||
region.code.toLowerCase().includes(query.toLowerCase())
})
} else {
this.filteredRegions = [...this.regions]
}
},
async searchInstances() { async searchInstances() {
if (!this.form.cpu_cores && !this.form.memory_gb && !this.form.disk_gb) { if (!this.form.cpu_cores && !this.form.memory_gb && !this.form.disk_gb) {
this.$message.warning('请至少指定一项配置要求') this.$message.warning('请至少指定一项配置要求')

View File

@ -26,9 +26,16 @@
<el-col :md="12" :sm="24"> <el-col :md="12" :sm="24">
<el-form-item label="区域"> <el-form-item label="区域">
<el-select v-model="form.region" placeholder="请选择区域" class="full-width"> <el-select
v-model="form.region"
placeholder="请选择区域"
class="full-width"
filterable
clearable
:filter-method="filterRegions"
:remote-method="filterRegions">
<el-option <el-option
v-for="region in regions" v-for="region in filteredRegions"
:key="region" :key="region"
:label="region" :label="region"
:value="region"> :value="region">
@ -160,6 +167,7 @@ export default {
}, },
instanceTypes: [], instanceTypes: [],
regions: [], regions: [],
filteredRegions: [],
priceResult: null priceResult: null
} }
}, },
@ -172,12 +180,22 @@ export default {
this.instanceTypes = instanceTypes this.instanceTypes = instanceTypes
this.regions = regions.map(region => region.code) this.regions = regions.map(region => region.code)
this.filteredRegions = [...this.regions] //
} catch (error) { } catch (error) {
console.error('Error fetching data:', error) console.error('Error fetching data:', error)
this.$message.error('获取数据失败') this.$message.error('获取数据失败')
} }
}, },
methods: { methods: {
filterRegions(query) {
if (query) {
this.filteredRegions = this.regions.filter(region => {
return region.toLowerCase().includes(query.toLowerCase())
})
} else {
this.filteredRegions = [...this.regions]
}
},
async calculatePrice() { async calculatePrice() {
try { try {
this.priceResult = await apiService.calculatePrice(this.form) this.priceResult = await apiService.calculatePrice(this.form)