首页
友链
壁纸
留言
今日热榜
更多
关于
时光
推荐
精品流量卡
Search
1
都二十多年了,你的梦为什么还没碎!
57,091 阅读
2
2022年5个好用的 BT/ 磁力链接下载工具推荐 |Windows 、安卓系统
37,401 阅读
3
nps内网穿透实现外网访问树莓派
32,429 阅读
4
实践利用宝塔建emlog个人博客-超详细【原创】
26,135 阅读
5
Typecho-Joe-Theme主题帮助文档
24,638 阅读
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
登录
Search
标签搜索
PHP
HTML
API
Javascript
源码
JS
Vue
Github
CloudFlare
接口
函数
SQL
ASP.NET
MVC
EF
T4模板
后台管理
CDN
微信小程序
MAC
韩小韩
累计撰写
262
篇文章
累计收到
1,308
条评论
首页
栏目
闲杂乱码
Python
网站源码
微信小程序
娱乐分享
Is相册
软件工具
页面
友链
壁纸
留言
今日热榜
关于
时光
推荐
精品流量卡
搜索到
151
篇与
闲杂乱码
的结果
2022-09-01
最实用的JavaScript一行代码
{message type="info" content="前些年的段子里,总有一些主考官的思想格局打不开,抛出这样的问题:让我在10秒钟内记住你。于是就有了,被打耳光的,被亲的,被扒衣服的,摔手机的······但作为程序员,要怎么用代码震惊的别人呢?Talk is cheap, show me the code!很简单:用简单的逻辑和尽可能少的代码行来解决一个复杂的问题。随着 ES6 箭头函数的引入,可以创建看起来优雅而简单的单行代码。在今天的文章中,我将与你一起来学习 11 个罕见但功能强大的单行代码。现在,准备好,让我们开始吧!"/}文字复制到剪贴板const copyText = async (text) => await navigator.clipboard.writeText(text) copyText('单行代码 前端世界'){callout color="#f0ad4e"}Clipboard API 它的所有操作都是异步的,返回 Promise 对象,不会造成页面卡顿。而且,它可以将任意内容(比如图片)放入剪贴板。{/callout}获取字符串中的字符数const characterCount = (str, char) => str.split(char).length - 1{callout color="#f0ad4e"}获取字符数是一个有用的实用程序,在许多情况下都很有用,我们可以使用它来获取空格数和随后的单词数,或者这可用于获取字符串中某个分隔符的计数。这个想法很简单,我们使用传递的参数 char 拆分字符串并获取返回数组的长度。由于每次将字符串拆分,都会比拆分器多一个;所以减去 1,我们有一个 characterCount 单行。{/callout}检查对象是否为空const isEmpty = obj => Reflect.ownKeys(obj).length === 0 && obj.constructor === Object{callout color="#f0ad4e"}检查对象的空性实际上比看起来要困难得多,即使对象为空,每次检查对象是否等于 {} 也会返回 false。幸运的是,下面的单行代码正是我们想要的。在这一行中,我们检查对象的键长度是否等于 0,以及传递的参数是否为实际对象。{/callout}等待一段时间再执行const wait = async (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));{callout color="#f0ad4e"}在这一行中,我们将通过一些异步编程来弄脏我们的代码。这个想法很简单,在运行代码时,如果你想等待一定的时间,这里是等待单行在等待单行中,我们创建一个承诺并在给定的时间后使用 setTimeout 函数解决它。{/callout}获取两个日期之间的日差const daysBetween = (date1, date2) => Math.ceil(Math.abs(date1 - date2) / (1000 * 60 * 60 * 24)){callout color="#f0ad4e"}在开发 Web 应用程序时,日期通常是实现起来最令人困惑的部分,因为有许多概念很容易被误算。这是一个强大的单线计算两个日期之间的天差。但还有更多事情要做,正如我所做的那样,你可以创建自己的单线来计算月、年差异等。这种单线背后的逻辑很容易理解。当两个日期相减时,返回值是以毫秒为单位的差值,要将毫秒转换为天,我们必须将其除以毫秒、秒、分钟和小时。{/callout}检查设备上的触摸支持const touchSupported = () => ('ontouchstart' in window || DocumentTouch && document instanceof DocumentTouch){callout color="#f0ad4e"}随着可以连接到互联网的设备越来越多,创建响应式网站的必要性也在增加。20 年前,开发者应该考虑网站的桌面版本,但今天超过 50% 的网络流量来自触摸移动设备。因此,基于设备的触控支持采取一些行动是一个非常重要的概念。在这一行中,我们正在检查文档是否支持 touchstart 事件。{/callout}在元素后插入 HTML 字符串const insertHTMLAfter = (html, el) => el.insertAdjacentHTML('afterend', html){callout color="#f0ad4e"}开发 Web 应用程序时,使用 JavaScript 更新 DOM 是一件很常见的事情。有一些基本的方法可以完成工作,但是,当情况变得复杂时,就很难克服。这是一个在 HTML 元素之后立即注入 HTML 字符串的单行代码。经过几分钟的思考和谷歌搜索,我相信你可以找到这个单线的以前版本。{/callout}随机排列数组const shuffle = arr => arr.sort(() => 0.5 - Math.random()){callout color="#f0ad4e"}在开发中打乱一组数据是一个常见的情况,你可以随时遇到,不幸的是,JavaScript 中没有内置数组的 shuffle 方法。但是,这里有一个你可以每天使用的 shuffle one-liner它利用数组的排序方法,在数组的前一个元素之前或之后随机排序。{/callout}获取随机布尔值const getRandomBoolean = () => Math.random() >= 0.5{callout color="#f0ad4e"}在开发时,尤其是在写游戏代码时,有时,我们会想随机采取行动。在这些情况下,下面的单行代码非常方便。上面的单行代码有 50/50 的机会返回真或假。因为生成的随机数大于0.5的概率等于变小的概率。然而,例如,如果你想得到一个概率为 70% 的随机布尔值,那么你可以简单地将 0.5 更改为 0.7 等等。{/callout}计算数组的平均值const average = (arr) => arr.reduce((a, b) => a + b) / arr.length{callout color="#f0ad4e"}可以使用多种方法计算数组的平均值。但逻辑对所有人都是一样的,我们必须得到数组及其长度的总和;然后,通过除法给出平均值。在平均单行中,我们使用 reduce 来获取一行中数组的总和,而不是使用循环。然后,我们将它除以数组长度,这是一个数组的平均值。{/callout}查询某天是否为工作日const isWeekday = (date) => date.getDay() % 6 !== 0; isWeekday(new Date(2023, 02, 01)) // true{callout color="#f0ad4e"}我们自己写日历组件时经常会用到,判断某个日期是否为工作日;周一至周五为工作日:{/callout}转换华氏/摄氏// 将华氏温度转换为摄氏温度 const fahrenheitToCelsius = (fahrenheit) => (fahrenheit - 32) * 5/9; fahrenheitToCelsius(50); // 10 // 将摄氏温度转华氏温度 const celsiusToFahrenheit = (celsius) => celsius * 9/5 + 32; celsiusToFahrenheit(100) // 212{callout color="#f0ad4e"}处理温度有时会晕头转向。这两个函数则能帮助大家将华氏温度转换为摄氏温度,以及将摄氏温度转换为华氏温度。{/callout}每隔4个空1格美团卷码[..."088896520132"].reduce((res, itm, idx) => (res += idx % 4 === 1 ? `${itm} `: itm),''); // 08 8896 5201 32检查当前选项卡是否在后台const isTabActive = () => !document.hidden; isTabActive() // true|false检查设备类型const judgeDeviceType = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ? 'Mobile' : 'PC'; judgeDeviceType() // PC | Mobile{message type="info" content="END"/}
2022年09月01日
1,745 阅读
6 评论
5 点赞
2022-08-24
FFMPEG视频切片TS文件添加PNG文件头伪图片上传
{message type="info" content="在这个图床泛滥的时代,不能白白浪费那么那么那么多免费的图床!总想着做点什么,想来想去,只想把我好多好多无处可放的视频传上去,可是图床它并不能上传视频。思来想去,图床只能上传图片嘛?为什么它知道我是图片?我想!并不是!看来看去,噢,原来只要把文件头改成图片HEAD头就OK,我说它是图片它就是图片!图片改头换面伪装大法现在开始~"/}前期准备{callout color="#f0ad4e"}FFmpeg 并配置环境变量(不会的话百度一下 你知道~){/callout}{cloud title="FFmpeg 官网下载" type="default" url="https://www.gyan.dev/ffmpeg/builds/" password=""/}{callout color="#f0ad4e"}python 环境 (自行安装,不会的话,百度一下噢~){/callout}{cloud title="Python 官网下载" type="default" url="https://www.python.org/downloads/" password=""/}整体步奏对MP4视频文件转换单TS文件对单TS文件切割成多个TS切片文件并生成M3U8文件对TS文件进行 "偷天换日 改头换面" 伪图片处理上传任意图床取 "PNG" 文件地址最后预览视频{callout color="#f0ad4e"}国外图床 测试可正常播放(视频质量过高,且国外CDN,速度加载较慢,国内图床无敌!){/callout}{dplayer src="https://jsd.onmicrosoft.cn/gh/uxiaohan/uxiaohan.github.io@master/v2/2022/08/index.m3u8"/}开始 Start{callout color="#f0ad4e"}Python 脚本博主已经写好,一键处理,方便至简!!!!{/callout}代码片段{callout color="#f0ad4e"}标准mp4视频转TS文件{/callout}# Mp4 文件名字 不需要加 .mp4 后缀 vName = 'SaiBoPengKe' cmd_str = f'ffmpeg -y -i {vName}.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb {vName}.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'标准 Mp4 转换到 TS 成功!'){callout color="#f0ad4e"}TS单文件切片{/callout}filePath = f'./{vName}' if os.path.exists(filePath) == False: os.makedirs(filePath) cmd_str = f'ffmpeg -i {vName}.ts -c copy -map 0 -f segment -segment_list ./{vName}/index.m3u8 -segment_time 2 ./{vName}/output%03d.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'TS 切片 成功!'){callout color="#f0ad4e"}TS切片文件批量重命名为PNG{/callout}file_list = os.listdir(filePath) for i in file_list: if i.endswith(".ts"): new_name = i.replace(".ts", ".png") os.rename(f'{filePath}/' + i, f'{filePath}/' + new_name) print("TS重命名为PNG 成功!"){callout color="#f0ad4e"}TS切片 偷天换日 改头换面 添加PNG文件头{/callout}file_list = os.listdir(filePath) rewritePath = f'{filePath}Png/' if os.path.exists(rewritePath) == False: os.makedirs(rewritePath) for i in file_list: if i.endswith(".png"): copyfile("PNG", f'{rewritePath}/' + i) else: copyfile(f'{filePath}/' + i, f'{rewritePath}/' + i) file_list = os.listdir(rewritePath) for i in file_list: if i.endswith(".png"): bin_file = open(f'{filePath}/' + i, 'rb') # 打开二进制文件 # 合并文件 with open(f'{rewritePath}/' + i, 'ab') as f: f.write(bin_file.read()) bin_file.close() print("PNG元数据转PNG-TS 成功!") os.remove(f'{vName}.ts') shutil.rmtree(filePath) print("临时文件删除成功"){callout color="#f0ad4e"}这里需要一个 PNG 文件头,可自己自定义,上传后伪图片文件可显示博主提供一个做好的{/callout}{callout color="#f0ad4e"}PNG头部HEAD数据16进制{/callout}89504E470D0A1A0A0000000D494844520000007C0000007508060000008C118576000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000011049444154785EEDD10101000008C320FB97BE411815B8855238A6704CE198C23185630AC7148E29{cloud title="PNG头文件下载" type="lz" url="https://ohan.lanzouv.com/i4PL80a5vgoh" password=""/}代码整合脚本# utf-8 import subprocess import os import shutil from shutil import copyfile # Mp4 文件名字 vName = 'sbpk' # 标准mp4转TS格式------------------------------------------------------------------------------ cmd_str = f'ffmpeg -y -i {vName}.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb {vName}.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'标准 Mp4 转换到 TS 成功!') # TS切片------------------------------------------------------------------------------ filePath = f'./{vName}' if os.path.exists(filePath) == False: os.makedirs(filePath) cmd_str = f'ffmpeg -i {vName}.ts -c copy -map 0 -f segment -segment_list ./{vName}/index.m3u8 -segment_time 2 ./{vName}/output%03d.ts' subprocess.run(cmd_str, encoding="utf-8", shell=True) print(f'TS 切片 成功!') # TS重命名为PNG------------------------------------------------------------------------------ file_list = os.listdir(filePath) for i in file_list: if i.endswith(".ts"): new_name = i.replace(".ts", ".png") os.rename(f'{filePath}/' + i, f'{filePath}/' + new_name) print("TS重命名为PNG 成功!") # PNG文件添加PNG文件头------------------------------------------------------------------------------ file_list = os.listdir(filePath) rewritePath = f'{filePath}Png/' if os.path.exists(rewritePath) == False: os.makedirs(rewritePath) for i in file_list: if i.endswith(".png"): copyfile("PNG", f'{rewritePath}/' + i) else: copyfile(f'{filePath}/' + i, f'{rewritePath}/' + i) file_list = os.listdir(rewritePath) for i in file_list: if i.endswith(".png"): bin_file = open(f'{filePath}/' + i, 'rb') # 打开二进制文件 # 合并文件 with open(f'{rewritePath}/' + i, 'ab') as f: f.write(bin_file.read()) bin_file.close() print("PNG元数据转PNG-TS 成功!") os.remove(f'{vName}.ts') shutil.rmtree(filePath) print("临时文件删除成功"){message type="info" content="我刚测试成功,立马发文,快去试试吧~"/}
2022年08月24日
2,092 阅读
8 评论
2 点赞
2022-08-23
微信小程序调用摄像头实现拍照功能
WXML文件代码<view class="content"> <view class="camera-con"> <camera wx:if="{{cameraStatus}}" device-position="back" flash="off" binderror="error"></camera> <van-image wx:if="{{!cameraStatus}}" width="100%" height="auto" src="{{src}}" fit="fill" /> </view> <view class="btn-con"> <van-button round color="#999999" size="small" bindtap="rePhoto">重新拍照</van-button> <van-button class="take" icon="stop-circle-o" color="rgba(0,0,0,0)" bindtap="takePhoto"></van-button> <van-button round color="#999999" size="small" bindtap="sendPhoto">提交图片</van-button> </view> </view>JS文件代码Page({ data: { cameraStatus: false, src: '', }, onLoad() { const _this = this wx.getSetting({ success: res => { if (res.authSetting['scope.camera']) { _this.setData({ cameraStatus: true }) } else { // 用户还没有授权,向用户发起授权请求 wx.authorize({ scope: 'scope.camera', success() { // 用户同意授权 _this.setData({ cameraStatus: true }) }, fail() { // 用户不同意授权 _this.openSetting().then(res => { _this.setData({ cameraStatus: true }) }) } }) } }, fail: res => { console.log('获取用户授权信息失败') } }) }, // 打开授权设置界面 openSetting() { const _this = this let promise = new Promise((resolve, reject) => { wx.showModal({ title: '授权', content: '请先授权获取摄像头权限', success(res) { if (res.confirm) { wx.openSetting({ success(res) { if (res.authSetting['scope.camera']) { // 用户打开了授权开关 resolve(true) } else { // 用户没有打开授权开关, 继续打开设置页面 _this.openSetting().then(res => { resolve(true) }) } }, fail(res) { console.log(res) } }) } else if (res.cancel) { _this.openSetting().then(res => { resolve(true) }) } } }) }) return promise; }, // 拍照 takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ src: res.tempImagePath, cameraStatus: false }) } }) }, // 重新拍照 rePhoto() { this.setData({ cameraStatus: true, src: '' }) } })WXSS文件代码.content { padding: 0; margin: 0; position: fixed; width: 100%; display: flex; flex-direction: column; box-sizing: border-box; justify-content: space-between; overflow: hidden; height: 100vh; } image { margin: 0; padding: 0; } .content .camera-con { flex: 1; overflow: hidden; } .content .camera-con image, .content .camera-con camera { width: 100%; height: calc(100vh - 148rpx); } .content .btn-con { display: flex; justify-content: space-between; align-items: center; height: 148rpx; background-color: #333333; } .content .btn-con button { margin: 0 30rpx; } .content .btn-con .take { border: 2rpx solid #FFFFFF; border-radius: 50%; height: 93rpx; width: 93rpx; display: flex; align-items: center; justify-content: center; }
2022年08月23日
1,601 阅读
0 评论
1 点赞
2022-07-27
按照图片尺寸自动分类 手机分辨率 电脑分辨率 python脚本
# coding=utf-8 """ 功能:按图片的尺寸大小进行分类 区分 电脑分辨率图片 手机分辨率图片 """ import os import shutil from PIL import Image # 定义一个分类函数,函数括号中为需要分类的图片文件夹路径 def photo_classify(files_path): # 读取文件夹中所有文件的名称 files_list = os.listdir(files_path) # 循环文件夹中的所有文件 for photo in files_list: # 获取图片的绝对路径 photo_abspath = os.path.join(files_path, photo) # print(photo_abspath) # 判断photo是不是文件夹,若是文件夹则跳过,若不是文件夹则继续执行 if os.path.isdir(photo_abspath): continue else: # 读图片的尺寸 img = Image.open(photo_abspath) # 取图片宽度 weight = img.size[0] # 取图片高度 high = img.size[1] # 对比图片宽高 if weight > high: # 根据图片尺寸Copy文件到新目录 PC new_paths = os.path.join(r'D:\Download\pc', photo) shutil.copyfile(photo_abspath, new_paths) print('pc') else: # 根据图片尺寸Copy文件到新目录 Mobil new_paths = os.path.join(r'D:\Download\mobil', photo) shutil.copyfile(photo_abspath, new_paths) print('mobil') img.close() # 转移完毕后 删除原文件 os.remove(photo_abspath) print('分类成功!') # 图片目录 files_path = r'D:\Download\meinv' if __name__ == '__main__': photo_classify(files_path)
2022年07月27日
513 阅读
4 评论
2 点赞
2022-07-06
JS正则常用校验大全(精华篇)
手机号(mobile phone)中国(严谨), 根据工信部2019年最新公布的手机号段const reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/; const str = "19119255642"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);email(邮箱)const reg = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; const str = "90203918@qq.com"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);座机(tel phone)电话(国内),如: 0341-86091234const reg = /^(?:(?:\d{3}-)?\d{8}|^(?:\d{4}-)?\d{7,8})(?:-\d+)?$/; const str = "0936-4211235"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);身份证号(2代,18位数字),最后一位是校验位,可能为数字或字符Xconst reg = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/; const str = "12345619991205131x"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);中文姓名const reg = /^(?:[\u4e00-\u9fa5·]{2,16})$/; const str = "韩小韩"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);英文姓名const reg = /(^[a-zA-Z][a-zA-Z\s]{0,20}[a-zA-Z]$)/; const str = "James Han"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);网址(URL)const reg = /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/; const str = "https://www.vvhan.com"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);必须带端口号的网址(或ip)const reg = /^((ht|f)tps?:\/\/)?[\w-]+(\.[\w-]+)+:\d{1,5}\/?$/; const str = "https://www.vvhan.com:80"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);银行卡号(10到30位, 覆盖对公/私账户, 参考[微信支付]const reg = /^[1-9]\d{9,29}$/; const str = "6222026006705354000"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线组合const reg = /^[a-zA-Z]\w{4,15}$/; const str = "han_666666"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);中文/汉字const reg = /^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/; const str = "韩小韩博客"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);密码强度校验,最少6位,包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符const reg = /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/; const str = "han@666vvx,"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);微信号(wx),6至20位,以字母开头,字母,数字,减号,下划线const reg = /^[a-zA-Z][-_a-zA-Z0-9]{5,19}$/; const str = "kd_-666"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);邮政编码(中国)const reg = /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/; const str = "734500"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);中文和数字const reg = /^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/; const str = "韩小韩好6啊"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);匹配连续重复的字符const reg = /(.)\1+/; const str = "112233"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);统一社会信用代码const reg = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/; const str = "91110108772551611J"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);子网掩码(不包含 0.0.0.0)const reg = /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(255|254|252|248|240|224|192|128|0)$/; const str = "255.255.255.0"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);车牌号(新能源)const reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](?:((\d{5}[A-HJK])|([A-HJK][A-HJ-NP-Z0-9][0-9]{4}))|[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳])$/; const str = "京AD92035"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);车牌号(非新能源)const reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]$/; const str = "京A00599"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);车牌号(新能源+非新能源)const reg = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$/; const str = "京A12345D"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);护照(包含香港、澳门)const reg = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/; const str = "s28233515"; console.log(`校验 ${reg.test(str) ? "正确" : "错误"}`);
2022年07月06日
1,110 阅读
7 评论
2 点赞
2022-07-04
Vue项目element组件遇到的坑(记录篇持续更新)
Input数字输入框<!-- 一般情况使用 type="number"存在问题:数字可为负数,且出现上增下减箭头 --> <el-input v-model="input" placeholder="请输入内容" type="number"></el-input> <!-- 我的解决方案 - Perfect --> <el-input v-model="input" placeholder="请输入内容" oninput="value=value.replace(/[^0-9]/g,'')"></el-input>JS校验判断姓名const reg = /^[\u4e00-\u9fa5]{2,8}$/; const name = '呜哈哈1'; console.log(`姓名校验 ${reg.test(name)?'正确':'错误'}`);JS校验判断手机号const reg = /^1[3|4|5|7|8]\d{9}$/; const mobil = '1525222222'; console.log(`手机号校验 ${reg.test(mobil)?'正确':'错误'}`);JS校验判断身份证号码const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; const userNum = '320333199806060011X'; console.log(`身份证号码校验 ${reg.test(userNum)?'正确':'错误'}`);
2022年07月04日
490 阅读
2 评论
2 点赞
2022-06-23
微信小程序原生wx.request简单封装(自用版)
调用方法import { get,post } from '../../request/request' // GET请求 const _res = await get('https://api.vvhan.com/api/ian') console.log(_res) // POST请求 const _res = await post('https://api.vvhan.com/api/ian') console.log(_res)request.jsconst request = (url, options) => { return new Promise((resolve) => { options.isLoading && wx.showLoading({ title: '正在加载', }) wx.request({ url, method: options.method, data: options.data, header: { 'Content-Type': 'application/x-www-form-urlencoded', }, success(res) { resolve(res.data) options.isLoading && wx.hideLoading(); }, fail(error) { options.isLoading && wx.hideLoading(); wx.showToast({ icon: 'none', title: '请求失败', duration: 1400 }); } }) }) } const get = (url, options = {}, isLoading = true) => { return request(url, { method: 'GET', data: options, isLoading }) } const post = (url, options = {}, isLoading = true) => { return request(url, { method: 'POST', data: options, isLoading }) } module.exports = { get, post, }
2022年06月23日
1,523 阅读
5 评论
0 点赞
2022-06-23
微信小程序登陆封装(自用版)欢迎指正
{dplayer src="https://jsd.onmicrosoft.cn/gh/uxiaohan/uxiaohan.github.io@master/v2/2022/07/2623010086.mp4"/}index.wxml<!-- 登陆组件弹窗 --> <van-popup show="{{ loginBtn }}" round position="bottom" custom-style="height: 24%" bind:close="onClose" duration="246"> <view class="loginPanel"> <view class="panel-title">我想要你的头像和昵称,可以嘛~</view> <view class="panel-btns"> <van-button type="info" round bind:click="onClose">不可以</van-button> <van-button type="primary" round bind:click="_login">好的</van-button> </view> </view> </van-popup> <!-- 内容 --> <block wx:if="{{!loginShow}}"> <view class="loginok"> <view>韩小韩博客 wwww.vvhan.com</view> <view>登录成功</view> <image src="{{userInfo.avatarUrl}}" mode="widthFix" /> <view>Nick:{{userInfo.nickName}}</view> <view>OpenId:{{userInfo.openid}}</view> </view> </block> <block wx:else> <van-button class="loginbtn" plain type="info" bind:click="onClose">点击登录</van-button> </block>index.jsconst app = getApp() Page({ data: { // 登陆按钮现实隐藏 loginBtn: false, // 全局是否登陆 loginShow: false, // 用户信息 userInfo: {} }, async onLoad() { const _res = await app._checkLogin() this.setData({ loginBtn: _res, loginShow: _res, userInfo: app.globalData.userInfo }) }, // 登陆 async _login() { const _res = await app._getUserInfo() _res && this.setData({ userInfo: app.globalData.userInfo, loginBtn: false }), this.onLoad() }, // 关闭登陆弹窗 onClose(e) { this.setData({ loginBtn: e.type == "click" ? !this.data.loginBtn : false }) } })app.jsApp({ onLaunch: function () { // 全局变量 this.globalData = { openId: wx.getStorageSync('openId'), userInfo: wx.getStorageSync('userInfo') }; if (!wx.cloud) { console.error('请使用 2.2.3 或以上的基础库以使用云能力'); } else { wx.cloud.init({ // env 参数说明: // env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源 // 此处请填入环境 ID, 环境 ID 可打开云控制台查看 // 如不填则使用默认环境(第一个创建的环境) // env: 'my-env-id', traceUser: true, }); } // 微信小程序获取版本更新 const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 }) updateManager.onUpdateReady(function () { wx.showModal({ title: '小韩提示', content: '新版来袭,速来体验!', success: function (res) { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(function () { // 新版本下载失败 }); // 获取OpedId this._getOpenId() }, // 获取用户OpenId _getOpenId() { ((this.globalData.openId || '') == '') && wx.cloud.callFunction({ name: 'login' }).then(res => { this.globalData.openId = res.result.openid; wx.setStorageSync('openId', res.result.openid) }).catch(res => { console.error(res) }); }, // 判断是否登陆 async _checkLogin() { const _this = this return new Promise((resolve) => { wx.checkSession({ success: function (_res) { const _userInfo = wx.getStorageSync('userInfo'); resolve((_userInfo || '') === '') }, fail: async function (_res) { await wx.login({}) resolve(true) } }) }) }, // 获取用户信息并存储 async _getUserInfo() { return new Promise((resolve) => { wx.getUserProfile({ desc: 'get用户信息', success: async res => { res.userInfo.openid = this.globalData.openId this.globalData.userInfo = res.userInfo wx.setStorageSync('userInfo', res.userInfo) resolve(true) }, fail: () => { resolve(false) } }); }) }, }); });
2022年06月23日
1,423 阅读
0 评论
3 点赞
1
...
3
4
5
...
19