星期
代码片段记录
首页 > 我的学习历程    作者:月丶   2020年5月25日 17:06 星期一   热度:1542°   百度已收录  
时间:2020-5-25 17:06   热度:1542° 

1、简易登录弹出框(vue,animate.css):

html:


    <div class="dialog">
      <div :class="['mask',showLoginDialog ? 'show' : 'hide']"></div>
      <div :class="['loginDialog animate__animated',showLoginDialog ? 'animate__fadeInDownBig' : 'animate__fadeOutUp']">
        <h3 class="loginTitle">登录</h3>
        <div class="list-item">
          <input type="text" placeholder="请输入手机号"/>
        </div>
        <div class="list-item">
          <input type="password" placeholder="请输入密码"/>
        </div>

        <div class="list-item">
          <div class="login-btn">登录</div>
        </div>
      </div>
    </div>
   


css:


    .loginDialog {
      positionfixed;
      width450px;
      height350px;
      top0;
      right0;
      left0;
      bottom0;
      marginauto;
      padding20px;
      background-color#fafafb;
      box-shadow#fafafb 0 0 5px;
      border-radius5px;
      font-size18px;
      z-index1001;
      .loginTitle {
        height60px;
        line-height60px;
        text-aligncenter;
        padding3px 0;
      }

      .list-item{
        padding10px 0;
        margin15px 0;
      }

      input{
        font-size18px;
        height100%;
        line-height100%;
        width280px;
        height30px;
        padding10px;  
        outline-stylenone ;
        border1px solid rgba(255,127,80,0.6 );
        border-radius5px;
      }

      input::placeholder{
        colorrgb(194193193);
      }

      input:focus{
          border-color#66afe9;
          outline0;
          -webkit-box-shadowinset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
          box-shadowinset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6)
      }

      .login-btn{
        width300px;
        height30px;
        padding10px 0;
        background-colorcoral;
        color#fafafb;
        margin0 auto;
        border-radius5px;
        cursorpointer;
      }
    }




2、vue车牌输入组件:


Keyborad.vue


<template>
  <div class="keyBoardContainer">
    <van-popup
      v-model="show"
      position="bottom"
      :overlay="showOverlay"
      :style="{background:'#BBC2CA'}"
      :safe-area-inset-bottom="true"
    >
      <!-- <span class="tempcar" @click="onKeyBoardPress" data-text="临">临</span> -->
      <span class="clearInput" @click="clearInput">清空</span>
      <span class="complete" @click="inputComplete">完成</span>
      <div class="keyboard">
        <div v-if="showCnKeyBoardclass="keyboard_content">
          <span @click="onKeyBoardPressdata-text="京"></span>
          <span @click="onKeyBoardPressdata-text="津"></span>
          <span @click="onKeyBoardPressdata-text="冀"></span>
          <span @click="onKeyBoardPressdata-text="鲁"></span>
          <span @click="onKeyBoardPressdata-text="晋"></span>
          <span @click="onKeyBoardPressdata-text="蒙"></span>
          <span @click="onKeyBoardPressdata-text="辽"></span>
          <span @click="onKeyBoardPressdata-text="吉"></span>
          <span @click="onKeyBoardPressdata-text="黑"></span>
          <span @click="onKeyBoardPressdata-text="沪"></span>
          <span @click="onKeyBoardPressdata-text="苏"></span>
          <span @click="onKeyBoardPressdata-text="浙"></span>
          <span @click="onKeyBoardPressdata-text="皖"></span>
          <span @click="onKeyBoardPressdata-text="闽"></span>
          <span @click="onKeyBoardPressdata-text="赣"></span>
          <span @click="onKeyBoardPressdata-text="豫"></span>
          <span @click="onKeyBoardPressdata-text="鄂"></span>
          <span @click="onKeyBoardPressdata-text="湘"></span>
          <span @click="onKeyBoardPressdata-text="粤"></span>
          <span @click="onKeyBoardPressdata-text="桂"></span>
          <span @click="onKeyBoardPressdata-text="渝"></span>
          <span @click="onKeyBoardPressdata-text="川"></span>
          <span @click="onKeyBoardPressdata-text="贵"></span>
          <span @click="onKeyBoardPressdata-text="云"></span>
          <span @click="onKeyBoardPressdata-text="藏"></span>
          <span @click="onKeyBoardPressdata-text="陕"></span>
          <span @click="onKeyBoardPressdata-text="甘"></span>
          <span @click="onKeyBoardPressdata-text="青"></span>
          <span @click="onKeyBoardPressdata-text="琼"></span>
          <span @click="onKeyBoardPressdata-text="新"></span>
          <span class="normalWidth change" @click="changeKeyBoard">ABC</span>
          <span @click="onKeyBoardPressdata-text="宁"></span>
          <span @click="onKeyBoardPressdata-text="港"></span>
          <span @click="onKeyBoardPressdata-text="澳"></span>
          <span @click="onKeyBoardPressdata-text="台"></span>
          <span @click="onKeyBoardPressdata-text="警"></span>
          <span @click="onKeyBoardPressdata-text="领"></span>
          <span @click="onKeyBoardPressdata-text="使">使</span>
          <span @click="onKeyBoardPressdata-text="临"></span>
          <span class="normalWidth delete" @click="delCarlicense">
            <img src="@/assets/images/del.png" alt />
          </span>
        </div>
        <div v-else class="keyboard_content">
          <span @click="onKeyBoardPressdata-text="1">1</span>
          <span @click="onKeyBoardPressdata-text="2">2</span>
          <span @click="onKeyBoardPressdata-text="3">3</span>
          <span @click="onKeyBoardPressdata-text="4">4</span>
          <span @click="onKeyBoardPressdata-text="5">5</span>
          <span @click="onKeyBoardPressdata-text="6">6</span>
          <span @click="onKeyBoardPressdata-text="7">7</span>
          <span @click="onKeyBoardPressdata-text="8">8</span>
          <span @click="onKeyBoardPressdata-text="9">9</span>
          <span @click="onKeyBoardPressdata-text="0">0</span>
          <span @click="onKeyBoardPressdata-text="Q">Q</span>
          <span @click="onKeyBoardPressdata-text="W">W</span>
          <span @click="onKeyBoardPressdata-text="E">E</span>
          <span @click="onKeyBoardPressdata-text="R">R</span>
          <span @click="onKeyBoardPressdata-text="T">T</span>
          <span @click="onKeyBoardPressdata-text="Y">Y</span>
          <span @click="onKeyBoardPressdata-text="U">U</span>
          <span @click="onKeyBoardPressdata-text="I">I</span>
          <span @click="onKeyBoardPressdata-text="O">O</span>
          <span @click="onKeyBoardPressdata-text="P">P</span>
          <span @click="onKeyBoardPressdata-text="A">A</span>
          <span @click="onKeyBoardPressdata-text="S">S</span>
          <span @click="onKeyBoardPressdata-text="D">D</span>
          <span @click="onKeyBoardPressdata-text="F">F</span>
          <span @click="onKeyBoardPressdata-text="G">G</span>
          <span @click="onKeyBoardPressdata-text="H">H</span>
          <span @click="onKeyBoardPressdata-text="J">J</span>
          <span @click="onKeyBoardPressdata-text="K">K</span>
          <span @click="onKeyBoardPressdata-text="L">L</span>
          <span class="change" @click="changeKeyBoard">ABC</span>
          <span @click="onKeyBoardPressdata-text="Z">Z</span>
          <span @click="onKeyBoardPressdata-text="X">X</span>
          <span @click="onKeyBoardPressdata-text="C">C</span>
          <span @click="onKeyBoardPressdata-text="V">V</span>
          <span @click="onKeyBoardPressdata-text="B">B</span>
          <span @click="onKeyBoardPressdata-text="N">N</span>
          <span @click="onKeyBoardPressdata-text="M">M</span>
          <span class="delete" @click="delCarlicense">
            <img src="@/assets/images/del.png" alt />
          </span>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
import Vue from "vue";
import { Popup } from "vant";

Vue.use(Popup);
export default {
  props: {
    showKeyBoard: {
      type: Boolean,
      required: true
    },
    showCNKeyBoard: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      show: this.showKeyBoard,
      showOverlay: false,
      showCnKeyBoard: this.showCNKeyBoard
    };
  },

  mounted() {},

  computed: {},

  watch: {
    showKeyBoard: function(val) {
      this.show = val;
    },
    showCNKeyBoard: function(val) {
      this.showCnKeyBoard = val;
    }
  },

  methods: {
    onKeyBoardPress(e) {
      this.$emit("key-press"e.target.innerHTML);
    },
    changeKeyBoard() {
      this.$emit("change-press");
    },
    delCarlicense() {
      this.$emit("del-press");
    },
    inputComplete() {
      this.$emit("input-over");
    },
    clearInput() {
      this.$emit("clear-press");
    }
  }
};
</script>

<style scoped lang="less">
.keyBoardContainer {
  font-family: PingFangSC-Regular, sans-serif;
  color#030303;
  .complete {
    displayblock;
    positionabsolute;
    top0;
    right10px;
    font-size18px;
    line-height32px;
    color#0078ff;
  }

  .clearInput {
    displayblock;
    positionabsolute;
    top0;
    left10px;
    font-size18px;
    line-height32px;
    color#0078ff;
  }

  // .tempcar{
  //   display: block;
  //   position: absolute;
  //   top: 0;
  //   left: 10px;
  //   font-size: 18px;
  //   line-height: 32px;
  // }

  .keyboard {
    positionrelative;
    backgroundrgb(206213221);
    margin-top32px;
  }

  .keyboard_content {
    displayflex;
    justify-contentcenter;
    flex-flowrow;
    flex-wrapwrap;
    padding-bottom10px;
  }

  .keyboard_content span {
    displayblock;
    text-aligncenter;
    width32px;
    height42px;
    line-height42px;
    font-size20px;
    backgroundwhite;
    padding-left0;
    padding-right0;
    margin5px 2.5px;
    border-radius5px;
    box-shadow0px 1px 0px 0px rgba(0000.35);
  }

  .keyboard_content .change,
  .keyboard_content .delete {
    font-size16px;
    width48px;
    background#abb3bd;
  }

  
  .keyboard_content .normalWidth {
    width32px;
  }

  .keyboard_content .delete img {
    width26px;
    height20px;
    margin-top11px;
  }
}
</style>


使用:



<KeyBoard
      :showKeyBoard="show"
      :showCNKeyBoard="showCn"
      v-on:input-over="hideKeyBoard"
      v-on:change-press="changeKeyBoard"
      v-on:key-press="getPressKeyValue"
      v-on:del-press="delCarKeyPress"
      v-on:clear-press="clearCarInput"
    />




3、判断扫码设备

//判断UA
export const JudgeUA = function () {
  const ua = navigator.userAgent.toLowerCase();
  if (ua != null && ua.includes('micromessenger')) return 'wechat';
  if (ua != null && ua.includes('alipay')) return 'alipay';
  if (ua != null && ua.includes('jdapp')) return 'jdapp';
  if (ua != null && ua.includes('jdjr')) return 'jdjr';
  if (ua != null && ua.includes('mpbank')) return 'cmbc';
  return "other";
}


4、判断设备系统


//判断设备为安卓还是ios系统
export const system = function () {
  const ua = navigator.userAgent;
  if (ua.indexOf("Android") > -1 || ua.indexOf('Adr') > -1) {
    return "android";
  }
  if (ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
    return "ios";
  }
}



5、保留两位小数


//保留两位小数
export const toDecimal2 = (x=> {
  var f = parseFloat(x);
  if (isNaN(f)) {
    return false;
  }
  f = Math.round(f * 100) / 100;
  var s = f.toString();
  var rs = s.indexOf('.');
  if (rs < 0) {
    rs = s.length;
    s += '.';
  }
  while (s.length <= rs + 2) {
    s += '0';
  }
  return s;
}



6、倒计时秒数转换为字符串



//将倒计时秒数转换为时间字符串
export const formatCountDownTime = function (second) {
  const s = parseInt(second);
  const min = Math.floor(s / 60) < 10 ? ('0' + Math.floor(s / 60).toString()) : (Math.floor(s / 60).toString());
  const sec = (s % 60) < 10 ? ('0' + (s % 60).toString()) : ((s % 60).toString());
  return min + ':' + sec;
}




7、防抖(原理:在一段时间后执行函数,若此段时间内继续操作,则清除定时器,过了指定时间未操作,则执行函数):(重复触发,只执行一次)
应用场景:input实时监测输入是否符合要求,拉动滚动条实时触发事件...
function debounce(fn,time){
let delay = time || 1000;
let timer = null; 
return function() {
if(timer){
clearTimeout(timer) 
}
timer = setTimeout(fn,delay)
}
}

8、节流:(重复触发,每隔一定时间执行一次)
function throttle(fn,delay){
let valid = true
return function() {
if(!valid){
//休息时间 暂不接客
return false 
}
// 工作时间,执行函数并且在间隔期内把状态位设为无效
valid = false
setTimeout(() => {
fn()
valid = true;
}, delay)
}
}

9、获取月份最后一天
let monthLastDay = new Date(y,m,0).getDate();
y:年份;m:月份;第三个参数为零则获取最后一天


10、JS编码
encodeURI() decodeURI()  //ASCII码标点不会编码:*@-_+./
encodeURIComponent() decodeURIComponent()  //都会编码,在有时候无法直接传参时可使用JSON.stringify(data)将数据变为字符串后在进行编码传递

base64编码
编码:btoa()
解码:atob()

11、浅拷贝
Object.assign()
var a = {a:1,b:{c:1}}
var copy = Object.assign({},a)
a.b.c = 2;
console.log(copy.b.c)  // 2

12、深拷贝
1、JSON.parse(JSON.stringify(obj))   //简单实用
2、function deepClone(obj) {
var newObj = obj instanceof Array ? [] : {};
if (typeof obj !== 'object') {
return obj;
}else {
for (var i in obj) {
newObj[i] = typeof obj[i] === 'object' ? deepClone(obj[i]) : obj[i];
}
}
return newObj;
}

13、最好的检测类型方法:
Object.prototype.toString.call();
类型:
基础类型:string,number,undefined,null,symbol,boolean
引用类型:object,array,function
function checkType(data){
return Object.prototype.toString.call(data).slice(8,-1).toLocaleLowerCase();
}

14、文本溢出处理
//单行 
.single { 
overflow: hidden; 
white-space: nowrap; 
text-overflow: ellipsis; 
}
//多行
.more { 
display: -webkit-box !important; 
overflow: hidden; 
text-overflow: ellipsis; 
work-break: break-all; 
-webkit-box-orient: vertical; 
-webkit-line-clamp: 2; //指定行数
}

15、垂直水平居中
absolute: position: absolute
配合
top:50%;left:50%;transform:translate(-50%, -50%) 

autobot: display:flex 配合 margin:auto 

flex: display:flex 配合 align-items:center、justify-content:center (推荐)

grid: display:grid 配合 place-content:center;






二维码加载中...
本文作者:月丶      文章标题: 代码片段记录
本文地址:http://silver.eleuu.com/?post=34
版权声明:若无注明,本文皆为“月丶”原创,转载请保留文章出处。

返回顶部    手机版本    会员注册   
版权所有:月丶    博主: 月丶    团队首页电子乌托邦  博客框架:emlog   蜀ICP备18008322号   
  
//音乐播放器