Fix: 修改代码风格 & 优化脚本结构

This commit is contained in:
2025-07-09 16:56:10 +08:00
parent 610a2e89a7
commit 6edd08b874
2 changed files with 52 additions and 64 deletions

View File

@ -15,7 +15,7 @@
rounded="xl" rounded="xl"
> >
<v-card-title class="text-h5 mb-6 d-flex align-center"> <v-card-title class="text-h5 mb-6 d-flex align-center">
<VIcon <v-icon
class="mr-3" class="mr-3"
color="primary" color="primary"
icon="mdi-tune" icon="mdi-tune"
@ -26,31 +26,31 @@
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperCoreDiameter" v-model="paperCoreDiameter"
:label="`${$t('paperCoreDiameter')} (${paperCoreDiameter.unit})`" :label="`${$t('paperCoreDiameter')} (${paperCoreDiameter.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperRollExternalDiameter" v-model="paperRollExternalDiameter"
:label="`${$t('paperRollExternalDiameter')} (${paperRollExternalDiameter.unit})`" :label="`${$t('paperRollExternalDiameter')} (${paperRollExternalDiameter.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperRollWidth" v-model="paperRollWidth"
:label="`${$t('paperRollWidth')} (${paperRollWidth.unit})`" :label="`${$t('paperRollWidth')} (${paperRollWidth.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperDensity" v-model="paperDensity"
:label="`${$t('paperDensity')} (${paperDensity.unit})`" :label="`${$t('paperDensity')} (${paperDensity.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperGrammage" v-model="paperGrammage"
:label="`${$t('paperGrammage')} (${paperGrammage.unit})`" :label="`${$t('paperGrammage')} (${paperGrammage.unit})`"
/> />
@ -77,42 +77,42 @@
lg="5" lg="5"
md="6" md="6"
> >
<VCard <v-card
class="pa-6 result-card" class="pa-6 result-card"
elevation="8" elevation="8"
rounded="xl" rounded="xl"
> >
<VCardTitle class="text-h5 mb-6 d-flex align-center"> <v-card-title class="text-h5 mb-6 d-flex align-center">
<VIcon <v-icon
class="mr-3" class="mr-3"
color="primary" color="primary"
icon="mdi-calculator" icon="mdi-calculator"
size="large" size="large"
/> />
{{ $t('results') }} {{ $t('results') }}
</VCardTitle> </v-card-title>
<VRow> <v-row>
<VCol cols="12"> <v-col cols="12">
<ResultCard <result-card
:label="$t('paperRollWeight')" :label="$t('paperRollWeight')"
:value="paperRollWeight" :value="result.paperRollWeight"
/> />
</VCol> </v-col>
<VCol cols="12"> <v-col cols="12">
<ResultCard <result-card
:label="$t('paperRollLength')" :label="$t('paperRollLength')"
:value="paperRollLength" :value="result.paperRollLength"
/> />
</VCol> </v-col>
<VCol cols="12"> <v-col cols="12">
<ResultCard <result-card
:label="$t('paperThickness')" :label="$t('paperThickness')"
:value="paperThickness" :value="result.paperThickness"
/> />
</VCol> </v-col>
</VRow> </v-row>
</VCard> </v-card>
</v-col> </v-col>
</v-row> </v-row>
</div> </div>
@ -128,30 +128,19 @@
const paperDensity = ref<Param>(createParam(0.76, 'g/cm³')) const paperDensity = ref<Param>(createParam(0.76, 'g/cm³'))
const paperGrammage = ref<Param>(createParam(420, 'g/m²')) const paperGrammage = ref<Param>(createParam(420, 'g/m²'))
const paperThickness = computed(() => { const result = computed(() => {
// 计算纸张厚度
return createParam(paperGrammage.value.value / paperDensity.value.value / 1000, 'mm')
})
const paperRollWeight = computed(() => {
// 计算纸卷总重量
const paperRollExternalRadius = paperRollExternalDiameter.value.value / 2 const paperRollExternalRadius = paperRollExternalDiameter.value.value / 2
const paperCoreRadius = paperCoreDiameter.value.value / 2 const paperCoreRadius = paperCoreDiameter.value.value / 2
const paperRollVolume = (Math.PI * Math.pow(paperRollExternalRadius, 2) - Math.PI * Math.pow(paperCoreRadius, 2)) * paperRollWidth.value.value const paperRollVolume = (Math.PI * Math.pow(paperRollExternalRadius, 2) - Math.PI * Math.pow(paperCoreRadius, 2)) * paperRollWidth.value.value
const weight = paperRollVolume * paperDensity.value.value / 1_000_000 // 计算重量 const paperThickness = paperGrammage.value.value / paperDensity.value.value / 1000 // 计算纸张厚度
return createParam(weight, 'kg') const paperRollWeight = paperRollVolume * paperDensity.value.value / 1_000_000 // 计算重量
const paperRollLength = paperRollVolume / (paperThickness * paperRollWidth.value.value) / 1000 // 计算长度
return {
paperRollWeight: createParam(paperRollWeight, 'kg'),
paperRollLength: createParam(paperRollLength, 'm'),
paperThickness: createParam(paperThickness, 'mm'),
}
}) })
const paperRollLength = computed(() => {
// 计算纸卷长度
const paperRollExternalRadius = paperRollExternalDiameter.value.value / 2
const paperCoreRadius = paperCoreDiameter.value.value / 2
const paperRollVolume = (Math.PI * Math.pow(paperRollExternalRadius,
2) - Math.PI * Math.pow(paperCoreRadius, 2)) * paperRollWidth.value.value
const length = paperRollVolume / (paperThickness.value.value * paperRollWidth.value.value) / 1000
return createParam(length, 'm')
})
</script> </script>
<style scoped lang="sass"> <style scoped lang="sass">

View File

@ -24,31 +24,31 @@
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperRollLength" v-model="paperRollLength"
:label="`${$t('paperRollLength')}(${paperRollLength.unit})`" :label="`${$t('paperRollLength')}(${paperRollLength.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperDensity" v-model="paperDensity"
:label="`${$t('paperDensity')}(${paperDensity.unit})`" :label="`${$t('paperDensity')}(${paperDensity.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="productionAmount" v-model="productionAmount"
:label="`${$t('productionAmount')}(${productionAmount.unit})`" :label="`${$t('productionAmount')}(${productionAmount.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperCoreDiameter" v-model="paperCoreDiameter"
:label="`${$t('paperCoreDiameter')}(${paperCoreDiameter.unit})`" :label="`${$t('paperCoreDiameter')}(${paperCoreDiameter.unit})`"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ParamInputField <param-input-field
v-model="paperRollWallThickness" v-model="paperRollWallThickness"
:label="`${$t('paperRollWallThickness')}(${paperRollWallThickness.unit})`" :label="`${$t('paperRollWallThickness')}(${paperRollWallThickness.unit})`"
/> />
@ -94,15 +94,15 @@
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<ResultCard <result-card
:label="`${$t('singlePaperTubeWeight')}(${singlePaperTubeWeight.unit})`" :label="`${$t('singlePaperTubeWeight')}(${result.singlePaperTubeWeight.unit})`"
:value="singlePaperTubeWeight" :value="result.singlePaperTubeWeight"
/> />
</v-col> </v-col>
<v-col cols="12"> <v-col cols="12">
<ResultCard <result-card
:label="`${$t('totalPaperTubeWeight')}(${totalPaperTubeWeight.unit})`" :label="`${$t('totalPaperTubeWeight')}(${result.totalPaperTubeWeight.unit})`"
:value="totalPaperTubeWeight" :value="result.totalPaperTubeWeight"
/> />
</v-col> </v-col>
</v-row> </v-row>
@ -122,17 +122,16 @@
const paperCoreDiameter = ref<Param>(createParam(76.2, 'mm')) const paperCoreDiameter = ref<Param>(createParam(76.2, 'mm'))
const paperRollWallThickness = ref<Param>(createParam(10, 'mm')) const paperRollWallThickness = ref<Param>(createParam(10, 'mm'))
const singlePaperTubeWeight = computed(() => { const result = computed(() => {
const paperCoreRadius = paperCoreDiameter.value.value / 2 const paperCoreRadius = paperCoreDiameter.value.value / 2
const paperRollExternalDiameter = paperCoreDiameter.value.value + 2 * paperRollWallThickness.value.value const paperRollExternalDiameter = paperCoreDiameter.value.value + 2 * paperRollWallThickness.value.value
const paperRollExternalRadius = paperRollExternalDiameter / 2 const paperRollExternalRadius = paperRollExternalDiameter / 2
const paperRollVolume = paperRollLength.value.value * Math.PI * (Math.pow(paperRollExternalRadius, 2) - Math.pow(paperCoreRadius, 2)) const paperRollVolume = paperRollLength.value.value * Math.PI * (Math.pow(paperRollExternalRadius, 2) - Math.pow(paperCoreRadius, 2))
const weight = paperRollVolume * paperDensity.value.value / 1_000_000 const singlePaperTubeWeight = paperRollVolume * paperDensity.value.value / 1_000_000
return createParam(weight, 'kg') const totalPaperTubeWeight = singlePaperTubeWeight * productionAmount.value.value
}) return {
singlePaperTubeWeight: createParam(singlePaperTubeWeight, 'kg'),
const totalPaperTubeWeight = computed(() => { totalPaperTubeWeight: createParam(totalPaperTubeWeight, 'kg'),
const weight = singlePaperTubeWeight.value.value * productionAmount.value.value }
return createParam(weight, 'kg')
}) })
</script> </script>