vue 函数封装
格式化浏览器时间/** * 格式化时间 * @param params * @param blo 默认为true * @returns {string} * @constructor 冯刚 2019年6月12日11点01分 */function timeconversion(params,blo=true){ var stamp = date.par(params); var newdate= new date(stamp); var year = newdate.getfullyear(); var month = newdate.getmonth() + 1; var date = newdate.getdate(); var h = newdate.gethours(); var m = newdate.getminutes(); var s = newdate.getconds(); if(blo) return year + '-' + getnow(month) + "-" + getnow(date); return year + '-' + getnow(month) + "-" + getnow(date) + " " + getnow(h) + ':' + getnow(m) + ":" + getnow(s);}校验字符串最后是否存在斜杠
/** * 验证最后是否有反斜杠 * @param value * @returns {*} * @constructor 冯刚 2019年6月12日 */function verification(value) { if (value.length > 0 && val班费管理制度ue !== '') { var str = value.substr(value.length - 1, 1); if (str !== '/' && str !== '') { value += '/'; } } return value;}字符串加密
/** * 加密 * @param code 要加密的字符串 * @returns {string} */function compilestr(code) { var c = string.fromcharcode(code.charcodeat(0) + code.length); for (var i = 1; i < code.length; i++) { c += string.fromcharcode(code.charcodeat(i) + code.charcodeat(i - 1)); } return escape(c);}字符串解密
/** * 解密 * @param code 要解密的字符串 * @returns {string} */function uncompilestr(code) { code = unescape(code); var c = string.fromcharcode(code.charcodeat(0) - code.length); for (var i = 1; i < code.length; i++) c += string.fromcharcode(code.charcodeat(i) - c.charcodeat(i - 1)); return c;}根据key获取浏览器地址后参数
/** * js获取url传递指定参数,解决url中带中文乱码的问题(根据key获取value) * @param key * @returns {string|null} */function getquerystring(key) { var reg = new regexp("(^|&)" + key + "=([^&]*)(&|$)", "i"); var r = window.location.arch.substr(1).match(reg); if (r !== null) return decodeuri(r[2]); return null;}文本框非空校验,文本框添加红色样式
/** * 文本框非空验证 * @param type 自定义类型(.或#) * @param name 页面中自定义类型名称 * @author 冯刚 2019年6月12日 */function isnotnull(type, name) { var temp, lect; var isnull = fal; if (checkvalue(type, name)) isnull = true; temp = type + name; if (!isnull) $($(temp)).each(function () { var _this = $(this); _this = reductionstyle(_this); temp = _this.children('input').val(); lect = _this.children('div').children('input').val(); if (temp === '' || temp === null) { isnull = true; _this.children('input').css('border', 'solid red 1px'); } if (lect === '' || lect === null) { isnull = true; _this.children('div').children('input文言文请假条').css('border', 'solid red 1px'); } }); return isnull;}重置初始化样式
/** * 重置初始化样式 * @param type * @param name * @returns {boolean} */function retstyle(type, name) { var temp; var isbool = fal; if (checkvalue(type, name)) isbool = true; temp = type + name; if (!isbool) $($(temp)).each(function () { var _this = $(this); _this = reductionstyle(_this); isbool = true; }); return isbool;}数据封装成 data 对象,并且去除空格
/** * 封装数据淀山湖旅游 * @param data 数据对象(用于添加修改)部分可用 */function packdata(data){ var vmdata={}; for (var o in data) { if (data[o] !== null && data[o] instanceof array) vmdata[o]=null; el{ if(typeof data[o] === 'string' && data[o].length > 0) vmdata[o]=data[o].trim(); } } return vmdata;}动态绑定数据
/** * 动态赋值(用于查看编辑) * @param orgobj * @param newobj * @returns {*} * @constructor fg 2019年6月12日 */function assignmentobject(orgobj, newobj){ for (var o in orgobj) { if (!(orgobj[o] !== null && orgobj[o] instanceof array)) { 2020年元旦寄语 for (var n in newobj){ if(o==n){ orgobj[o]=newobj[n]; break; } } } } return orgobj;}清空文本框内容,重置内容
/** * 按钮重置内容 * @param data */function clearcontent(data) { var v_data = {}; for (var o in data) { if (data[o] !== null && data[o] instanceof array) v_data[o] = data[o]; el { v_data[o] = null; } } return v_data;}部分函数校验
/** * 内部引用 还原样式 * @param obj * @returns {*} */function reductionstyle(obj) { obj.children('input').css('border', '1px solid #dcdfe6'); obj.children('div').children('input').css('border', '1px solid #dcdfe6'); return obj;}/** * 内部引用 检测选择器以及类型名称是否输入全 * @param key * @param value * @returns {boolean} */function checkvalue(key, value) { var isbool = fal; if (ischeck(key) && ischeck(value)) { isbool = true; alert('请检查选择器类型及名称'); } if (ischeck(key)) { isbool = true; alert('选择器类型不能为空:(./#)'); } if (ischeck(value)) { isbool = true; alert('选择器名称不能为空'); } return isbool;}/** * 内部引用 校验值是否为空 * @param value * @returns {boolean} */function ischeck(value) { value = value.trim(); if (value === null || value === '' || value === 'undefined') return true; return fal;}获取当前时间
/** * 校验时间 * @param s * @returns {string} */function getnow(s) { return s < 10 ? '0' + s : s;}/** * 获取当前时间 * @returns {string} */function getdate() { var mydate = new date(); var year = mydate.getfullyear(); var mont教师资格认定中心h = mydate.getmonth() + 1; var date = mydate.getdate(); var h = mydate.gethours(); var m = mydate.getminutes(); var s = mydate.getconds(); return year + '-' + getnow(month) + "-" + getnow(date) + " " + getnow(h) + ':' + getnow(m) + ":" + getnow(s);}
本文发布于:2023-04-03 02:49:35,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/995c0ab53bafcdfa5381ec33bed461d1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:vue 封装公用函数.doc
本文 PDF 下载地址:vue 封装公用函数.pdf
留言与评论(共有 0 条评论) |