<template>
    <div class="level">
        <div class="level-item" :style="{backgroundColor:nowLevel>=1?'#F56C6C':'#ccc'}">
            低
        </div>
        <div class="level-item" :style="{backgroundColor:nowLevel>=2?'#E6A23C':'#ccc'}">
            中
        </div>
        <div class="level-item" :style="{backgroundColor:nowLevel>=3?'#67C23A':'#ccc'}">
            高
        </div>
    </div>
</template>

<script>

export default {
    name: 'passwordLevel',
    props: {
        password: {
            type: String,
            default: ''
        }
    },
    data() {
        return {

        }
    },
    computed: {
        nowLevel() {
            var index = 0
            if (this.password.match(/[a-z]/g)) { index++; }
            if (this.password.match(/[0-9]/g)) { index++; }
            if (this.password.match(/(.[^a-z0-9])/g)) { index++; }
            if (this.password.length < 6) { index = 0; }
            if (index > 3) { index = 3; }

            return index
        }
    },
    methods: {

    }
}
</script>

<style lang="less" scoped>
.level-item {
    width: 30%;
    display: inline-block;
    vertical-align: middle;
    height: 30px;
    background-color: #ccc;
    text-align: center;
    line-height: 30px;
    margin-top: 5px;
    border-radius: 4px;
    color: #fff;
}
</style>
