修改单位控件适应微信小程序

This commit is contained in:
廖德云 2025-12-04 00:10:19 +08:00
parent 4350152488
commit bb71cacfd1

View File

@ -28,8 +28,11 @@
left: unitSelectorLeft + 'px',
top: unitSelectorTop + 'px'
}">
<scroll-view scroll-y :style="{ maxHeight: '200px' }">
<view v-for="unit in sortedUnits" :key="unit.id" class="unit-option" @tap="selectUnit(unit)">
<scroll-view scroll-y :style="{ maxHeight: '300px' }">
<view v-for="(unit, index) in sortedUnits" :key="unit.id" class="unit-option"
:class="{ active: activeIndex === index }" <!-- 动态绑定active类 -->
@tap="() => { selectUnit(unit); setActiveIndex(index); }" <!-- 点击时设置active -->
>
{{ showEnglishOnly ? unit.unitName.split('(')[0] : unit.unitName }}
</view>
</scroll-view>
@ -40,7 +43,11 @@
<script>
import {
storage
} from '@/utils/storageUnit.ts';
} from '@/utils/storageUnit.ts';
import {
ref
} from 'vue';
export default {
name: 'UniUnitConverter',
emits: ['update:modelValue', 'update:unitOrder', 'conversion'],
@ -105,9 +112,16 @@
/* 新增三个数据项 */
originalValue: this.modelValue, //
originalUnit: null, //
isInternalUpdate: false //
};
isInternalUpdate: false, //
//
activeIndex: -1
}
},
mounted() {
this.initComponent();
this.setGlobalClickHandler();
@ -162,7 +176,10 @@
await this.$nextTick();
this.updateInputWidth();
},
// active
setActiveIndex(index) {
activeIndex.value = index;
},
setGlobalClickHandler() {
if (typeof document !== 'undefined') {
document.addEventListener('click', this.handleClickOutside);
@ -283,6 +300,7 @@
this.updateInputWidth();
this.convertAndEmit();
});
activeIndex.value = -1; // active
},
/* 修改输入处理 */
@ -415,11 +433,7 @@
font-size: 14px;
}
.unit-option:hover {
.unit-option:active {
background-color: #f0f0f0;
}
scroll-view {
max-height: 200px;
}
</style>