feat:样品分析
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="y-f" style="height: 55vh">
|
||||
<view class="weight">
|
||||
<view class="weight-data"> {{ nums }}</view>
|
||||
<view class="weight-data">{{ nums }}</view>
|
||||
</view>
|
||||
|
||||
<view class="keyboard-container">
|
||||
@@ -21,114 +21,90 @@
|
||||
<view @click="jianshao()" class="oner flex1">
|
||||
<u-icon name="arrow-leftward" bold></u-icon>
|
||||
</view>
|
||||
<view @click="setNull()" class="oner flex1 mt10 mb10"> 清空 </view>
|
||||
<view class="oner confirm" @click="ok()"> 确认 </view>
|
||||
<view @click="setNull()" class="oner flex1 mt10 mb10">清空</view>
|
||||
<view class="oner confirm" @click="ok()">确认</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'zzjc-num-keyboard',
|
||||
props: {
|
||||
numKeyboardParam: {
|
||||
type: Object,
|
||||
default: null
|
||||
} //小数位数,-1为不限制
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
nums: '',
|
||||
numbers: [
|
||||
{
|
||||
text: '1'
|
||||
},
|
||||
{
|
||||
text: '2'
|
||||
},
|
||||
{
|
||||
text: '3'
|
||||
},
|
||||
{
|
||||
text: '4'
|
||||
},
|
||||
{
|
||||
text: '5'
|
||||
},
|
||||
{
|
||||
text: '6'
|
||||
},
|
||||
{
|
||||
text: '7'
|
||||
},
|
||||
{
|
||||
text: '8'
|
||||
},
|
||||
{
|
||||
text: '9'
|
||||
},
|
||||
{
|
||||
text: '0',
|
||||
class: 'zero'
|
||||
},
|
||||
{
|
||||
text: '.'
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
created() {},
|
||||
methods: {
|
||||
//确认
|
||||
ok() {
|
||||
const val = {
|
||||
val: this.nums
|
||||
}
|
||||
this.nums = ''
|
||||
uni.$emit('keyboardOK', val)
|
||||
},
|
||||
/*
|
||||
* 清空
|
||||
* 数字类型改为0,其他类型改为空
|
||||
* */
|
||||
setNull() {
|
||||
this.nums = ''
|
||||
uni.$emit('keyboardOK', null)
|
||||
},
|
||||
clearNum() {
|
||||
this.nums = ''
|
||||
},
|
||||
jianshao() {
|
||||
if (this.nums) {
|
||||
this.nums = this.nums.substring(0, this.nums.length - 1)
|
||||
}
|
||||
},
|
||||
changeNums(item, index) {
|
||||
this.sumindex = index
|
||||
if (item.text == '.') {
|
||||
if (this.nums.indexOf('.') != -1 || this.nums.length == 0) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
//检查小数位数
|
||||
let decimal = this.numKeyboardParam.decimal
|
||||
if (decimal == null) decimal = -1
|
||||
if (this.nums.split('.') && this.nums.split('.')[1] && decimal != -1) {
|
||||
if (this.nums.split('.')[1].length >= decimal) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
this.nums = this.nums + item.text
|
||||
},
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
getListItemStyle(index) {
|
||||
return {
|
||||
background: this.numbers[index].background
|
||||
}
|
||||
}
|
||||
// Props
|
||||
const props = defineProps({
|
||||
numKeyboardParam: {
|
||||
type: Object,
|
||||
default: () => null
|
||||
}
|
||||
})
|
||||
|
||||
// Emits(虽然你用的是 uni.$emit,但也可以定义 emit 用于规范)
|
||||
// const emit = defineEmits(['keyboardOK'])
|
||||
|
||||
// Data
|
||||
const nums = ref('')
|
||||
const numbers = ref([
|
||||
{ text: '1' },
|
||||
{ text: '2' },
|
||||
{ text: '3' },
|
||||
{ text: '4' },
|
||||
{ text: '5' },
|
||||
{ text: '6' },
|
||||
{ text: '7' },
|
||||
{ text: '8' },
|
||||
{ text: '9' },
|
||||
{ text: '0', class: 'zero' },
|
||||
{ text: '.' }
|
||||
])
|
||||
|
||||
// Methods
|
||||
const ok = () => {
|
||||
const val = { val: nums.value }
|
||||
nums.value = ''
|
||||
if (val.val) {
|
||||
uni.$emit('keyboardOK', val)
|
||||
}
|
||||
}
|
||||
|
||||
const setNull = () => {
|
||||
nums.value = ''
|
||||
uni.$emit('keyboardOK', null)
|
||||
}
|
||||
const clearNum = () => {
|
||||
nums.value = ''
|
||||
}
|
||||
const jianshao = () => {
|
||||
if (nums.value) {
|
||||
nums.value = nums.value.substring(0, nums.value.length - 1)
|
||||
}
|
||||
}
|
||||
|
||||
const changeNums = (item, index) => {
|
||||
if (item.text === '.') {
|
||||
if (nums.value.indexOf('.') !== -1 || nums.value.length === 0) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 检查小数位数限制
|
||||
let decimal = props.numKeyboardParam?.decimal ?? -1
|
||||
const parts = nums.value.split('.')
|
||||
if (parts.length === 2 && decimal !== -1) {
|
||||
if (parts[1].length >= decimal) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
nums.value += item.text
|
||||
}
|
||||
|
||||
const getListItemStyle = index => {
|
||||
return {
|
||||
background: numbers.value[index]?.background || ''
|
||||
}
|
||||
}
|
||||
defineExpose({ clearNum })
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@@ -142,7 +118,7 @@ export default {
|
||||
}
|
||||
.keypad {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr); /* 默认 3 列 */
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 10px;
|
||||
padding: 10px;
|
||||
flex: 4;
|
||||
@@ -161,7 +137,6 @@ export default {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* 0 占两列 */
|
||||
.zero {
|
||||
width: 98%;
|
||||
grid-column: span 2;
|
||||
|
||||
Reference in New Issue
Block a user