Sfoglia il codice sorgente

[edit] action sheet

wenliming 2 anni fa
parent
commit
1de8bc5eda
1 ha cambiato i file con 44 aggiunte e 9 eliminazioni
  1. 44 9
      src/view/components/input-action-sheet.vue

+ 44 - 9
src/view/components/input-action-sheet.vue

@@ -9,12 +9,12 @@
                     v-model="inputVal"
                     placeholder="0"
                     autofocus
-                    @input="onAmountInput"
-                    @blur="onAmountBlur">
+                    @input="onValueInput"
+                    @blur="onValueBlur">
             </div>
             <div class="btn-wrapper">
                 <div class="btn cancel">
-                    
+
                 </div>
                 <div class="btn confirm">
 
@@ -25,21 +25,56 @@
 </template>
 
 <script setup>
-import { onMounted, ref, defineProps } from "vue";
+import { ref, defineProps, defineEmits } from "vue";
 
 let inputVal = ref('');
 
-const onAmountInput = () => {
+const props = defineProps({
+    title: {
+        type: String,
+        default: '',
+    },
+    cancelText: {
+        type: String,
+        default: 'Cancel',
+    },
+    confirmText: {
+        type: String,
+        default: 'Continue',
+    },
+});
 
-}
+const emits = defineEmits(["cancel", "confirm"]);
 
-const onAmountBlur = () => {
+const onValueInput = () => {
+    inputValHandler();
+}
 
+const onValueBlur = () => {
+    inputValHandler();
 }
 
-onMounted(() => {
+//       emits("postPublishFinish", { publishRes });
+
+const inputValHandler = () => {
+    let val = inputVal.value;
+    val = val.replace(/[^\d^\.]+/g, "");
+
+    if(val == '00') {
+        val = '0'
+    }
+    if(val.indexOf('.') > -1){ //校验 例:00.12 => 0.12
+        let arr = val.split('.');
+        if(arr[0].startsWith('0')) {
+            let num = +arr[0];
+            val = num + '.' + arr[1];
+        }
+    }
+
+    inputVal.value = val;
+    return val;
+}
 
-})
 </script>
 
 <style scoped lang="scss">