首页 > 其他分享 >VUE一个仿微信提现的功能

VUE一个仿微信提现的功能

时间:2023-01-10 09:33:05浏览次数:41  
标签:box flex 提现 VUE weight val 仿微信 height font

 

UI组件用的是vant的键盘组件

1:HTML部分

<div class="withdraw_page">
        <div class="withdraw_page_header">
            <div class="withdraw_page_header_left">到账账户</div>
            <div class="withdraw_page_header_right">
                <div class="right_top">
                    <img src="@/assets/customer/wx.png" alt="" />
                    <span>微信账号</span>
                </div>
                <div class="right_bottom">预计7-14个工作日到账</div>
            </div>
        </div>
        <!--提现操作-->
        <div class="withdraw_page_content">
            <p class="content_title">提现金额</p>
            <div class="content_box">
                <span class="content_box_unit">¥</span>
                <div class="cursor"></div>
                <div class="input_box">
                    <van-field v-model="value" type="number" readonly clickable @touchstart.stop="show = true" />
                </div>
            </div>
            <div class="can_withdraw_money">
                <span>当前收入余额{{ amount }}元,提现手续费2%</span>
                <span class="all_withdraw" @click="allWithDraw">全部提现</span>
            </div>
            <span class="input_box_hidden">{{ value }}</span>
        </div>

        <van-number-keyboard :show="show" v-model="value" theme="custom" extra-key="." close-button-text="确定" @input="onInput" @delete="onDelete" @close="closeKeyboard" />
    </div>

2:css部分

.withdraw_page {
    width: 100%;
    height: 100%;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 35px;
    box-sizing: border-box;
    .withdraw_page_header {
        display: flex;
        .withdraw_page_header_left {
            font-size: 14px;
            font-weight: 400;
            color: #333333;
            line-height: 20px;
            margin-right: 42px;
        }
        .withdraw_page_header_right {
            display: flex;
            flex-direction: column;
            // align-items: flex-end;
            .right_top {
                display: flex;
                align-items: center;
                img {
                    width: 20px;
                    height: 20px;
                }
                span {
                    font-size: 14px;
                    font-weight: 600;
                    color: #333333;
                    line-height: 20px;
                }
            }
            .right_bottom {
                padding-left: 20px;
                margin-top: 4px;
                font-size: 14px;
                font-weight: 400;
                color: #666666;
                line-height: 20px;
            }
        }
    }
    .withdraw_page_content {
        width: 100%;
        flex: 1;
        margin-top: 27px;
        background: #ffffff;
        border-radius: 12px 12px 0px 0px;
        padding: 30px;
        box-sizing: border-box;
        .content_title {
            font-size: 14px;
            font-weight: 400;
            color: #333333;
            line-height: 20px;
        }
        .content_box {
            margin-top: 13px;
            padding-bottom: 8px;
            border-bottom: 1px solid #f1f1f1;
            display: flex;
            position: relative;
            .content_box_unit {
                margin-right: 12px;
                font-size: 28px;
                font-weight: 600;
                color: #000000;
                line-height: 39px;
            }
            .input_box {
                flex: 1;
                position: absolute;
                left: 30px;
                // width: 100%;
                // height: 100%;
                // position: absolute;
            }
            .cursor {
                position: relative;
                z-index: 100;
                width: 2px;
                height: 53px;
                background: #07c060;
                border-radius: 1px;
                animation: opacityMove 1s infinite;
            }
        }
        .can_withdraw_money {
            margin-top: 13px;
            font-size: 14px;
            font-weight: 400;
            color: #666666;
            line-height: 20px;
            .all_withdraw {
                color: #58608d;
            }
        }
        .input_box_hidden {
            display: inline-block;
            opacity: 0;
            font-size: 35px;
            font-weight: 600;
        }
    }
    :deep(.van-cell) {
        padding: 0;
        input {
            font-size: 35px;
            font-weight: 600;
        }
    }
    :deep(.van-key--blue) {
        background-color: #07c060;
    }
    :deep(.disabled_button) {
        opacity: 0.5;
    }
    @keyframes opacityMove {
        0% {
            opacity: 1;
        }
        25% {
            opacity: 0.5;
        }
        50% {
            opacity: 0;
        }
        75% {
            opacity: 0.5;
        }
        100% {
            opacity: 1;
        }
    }
}

3:JS部分

<script>
import { getShopBalanceResp, applyWithdraw } from '@/request/user.js'
export default {
    data() {
        return {
            value: '',
            show: true,
            amount: '',
        }
    },

    components: {},

    computed: {},
    mounted() {
        this.getShopBalanceRespInfo()
    },

    methods: {
        /**
         * 获取可提现金额
         */
        getShopBalanceRespInfo() {
            getShopBalanceResp()
                .then((response) => {
                    this.amount = response.data.amount
                })
                .catch((error) => {})
        },
        inputLimitFloat(val) {
            val = val.toString()
            // 截取可能为负号
            // const t = val.charAt(0)
            // 先把非数字的都替换掉,除了数字和.
            val = val.replace(/[^\d.]/g, '')
            // 必须保证第一个为数字而不是.
            val = val.replace(/^\./g, '')
            // 保证只有出现一个.而没有多个.
            val = val.replace(/\.{2,}/g, '.')
            // 保证.只出现一次,而不能出现两次以上
            val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
            val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
            if (val.indexOf('.') < 0 && val !== '') {
                // 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
                val = parseFloat(val)
            }
            // 如果第一位是负号,则允许添加
            // if (t === '-') {
            //   val = '-' + val
            // }
            return val
        },
        computeCursorPosition() {
            this.$nextTick(() => {
                let cursor = document.getElementsByClassName('cursor')[0]
                let hiddenVal = document.getElementsByClassName('input_box_hidden')[0]
                cursor.style.transform = `translateX(${hiddenVal.clientWidth + 5}px)`
            })
        },
        onInput(val) {
            this.computeCursorPosition()
        },
        closeKeyboard() {
            console.log(this.value)
            if (!this.value) {
                this.$toast('提现金额要大于0元')
                return false
            } else {
                applyWithdraw({
                    amount: Number(this.value),
                })
                    .then((response) => {
                        if (response) {
                            this.$toast('提现申请已提交')
                            this.$router.go(-1)
                        }
                    })
                    .catch((error) => {})
            }
        },
        onDelete() {
            this.computeCursorPosition()
        },
        /**
         * 全部提现
         */
        allWithDraw() {
            this.value = this.amount
            this.computeCursorPosition()
        },
    },
}
</script>

最主要的部分是去模拟光标的位置

onInput和
computeCursorPosition
这两个函数

 

标签:box,flex,提现,VUE,weight,val,仿微信,height,font
From: https://www.cnblogs.com/xubaoer/p/17039152.html

相关文章

  • Vue搭建项目的完整流程 如何搭建一个完整的vue项目 vue项目架构
    vue项目架构技术栈:vue3、vue-router、vuex(和pinia)、elementplus、axios、ts、sass1、安装vue3脚手架+tsvuecreateadmin2、分析目录结构node_modules......
  • 菜鸡的bug-vue组件中传递的数据能显示,但是控制台报not defind的错误
    在vue开发的父子组件传值的时候,我们一般都是先封装一个子组件,给他取名字,然后在要用到此组件的页面,也就是所说的父组件中将这个子组件导入、注册、再使用。我们一般都是用驼......
  • 菜鸡的bug-vue父子传值props的报错
    我们在vue中通过props来进行父子传值的时候,在当前页面没有问题,但是切换到其他页面的时候控制台会报错。后来我们会发现在props中简单的接受单个属性的时候没什么问题,但是......
  • Vue 跳转页面传参
    初创建于:2022-07-0811:03要在vue中跳转页面时传递参数,首先需要引入useRoute与useRouter:import{useRouter,useRoute}from'vue-router';constroute=use......
  • VUE3 AXIOS 封装
    网上找了很多AXIOS的封装但是都不是很满意,后来参考其他人的实现做了改动后特分享出来http.ts文件封装importtype{AxiosRequestConfig,AxiosResponse}from'axios......
  • vue后台项目中遇到的技术难点以及解决方案
    项目结构之前我有打算基于Webpack4自己写个脚手架用来打包文件,但是那段时间刚好Vue-cli3刚刚发布正式版并且也是基于Webpack4封装的,于是想了一下还决定使用新的Vue-cli3脚......
  • day06-Vue03
    Vue0310.组件化编程10.1基本说明官网链接:https://v2.cn.vuejs.org/v2/guide/components-registration.html在大型应用开发时,页面可以划分成很多部分。不同的页面,往往......
  • Vue中全局事件总线
    Vue中全局事件总线1:全局事件总线2:示例代码结构3:代码内容vue.config.jsconst{defineConfig}=require('@vue/cli-service')module.exports=defineConfig({transpi......
  • VUE 防抖简单实现
    防抖代码实现:exportclassDebounce{staticcurrent:Debounce=newDebounce();staticasyncInvoke<T>(func:()=>Promise<T>,timeout:number=300)......
  • 数据代理_3Vue中的数据代理
    数据代理_3Vue中的数据代理<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Vue中的数据代理</title><scriptsrc="../js/vue.js">......