Refactor Prices view import and table display logic

This commit is contained in:
wood chen 2025-02-08 21:43:59 +08:00
parent 6d114d57a6
commit c1e63cea5b

View File

@ -126,12 +126,7 @@
{{ row.output_price === 0 ? '免费' : calculateRate(row.output_price, row.currency) }} {{ row.output_price === 0 ? '免费' : calculateRate(row.output_price, row.currency) }}
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建者" width="110"> <el-table-column width="180">
<template #default="{ row }">
<span class="creator-name">{{ row.created_by }}</span>
</template>
</el-table-column>
<el-table-column v-if="isAdmin" width="180">
<template #default="{ row }"> <template #default="{ row }">
<el-popover <el-popover
placement="left" placement="left"
@ -142,6 +137,10 @@
<el-button link type="primary">详情</el-button> <el-button link type="primary">详情</el-button>
</template> </template>
<div class="price-detail"> <div class="price-detail">
<div class="detail-item">
<span class="detail-label">创建者:</span>
<span class="detail-value">{{ row.created_by }}</span>
</div>
<div class="detail-item"> <div class="detail-item">
<span class="detail-label">价格来源:</span> <span class="detail-label">价格来源:</span>
<div class="detail-value"> <div class="detail-value">
@ -159,7 +158,7 @@
</el-popover> </el-popover>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column v-if="isAdmin" label="操作" width="200"> <el-table-column v-if="isAdmin" label="操作">
<template #default="{ row }"> <template #default="{ row }">
<el-button-group> <el-button-group>
<el-button type="primary" size="small" @click="handleEdit(row)">编辑</el-button> <el-button type="primary" size="small" @click="handleEdit(row)">编辑</el-button>
@ -637,16 +636,14 @@ const handleImport = () => {
const lines = importText.value.trim().split('\n') const lines = importText.value.trim().split('\n')
const newRows = lines.map(line => { const newRows = lines.map(line => {
// 使 // 使
const matches = line.trim().match(/("[^"]+"|[^\s]+)/g) const parts = line.trim().split(/\t+|\s{2,}/)
if (!matches || matches.length < 6) { if (!parts || parts.length < 6) {
ElMessage.warning(`行格式不正确:${line}`) ElMessage.warning(`行格式不正确:${line}`)
return null return null
} }
const [model, billingType, providerNameRaw, currency, inputPrice, outputPrice] = matches const [model, billingType, providerName, currency, inputPrice, outputPrice] = parts
//
const providerName = providerNameRaw.replace(/^"|"$/g, '')
// ID // ID
const provider = providers.value.find(p => p.name === providerName) const provider = providers.value.find(p => p.name === providerName)
@ -672,7 +669,7 @@ const handleImport = () => {
} }
return { return {
model: model.replace(/^"|"$/g, ''), model,
billing_type, billing_type,
channel_type: provider.id.toString(), channel_type: provider.id.toString(),
currency: currencyCode, currency: currencyCode,