|
本帖最后由 浅浅` 于 2021-9-30 19:37 编辑
如上图所示,可以添加一个卡密处理的小工具
VUE引用JS示例:
- <template>
- <div class="teslist">
- <button @click="methods1">显示console</button>
- </div>
- </template>
- <script src="../../lib/myconsole.js"></script>
- <script>
- import { realconsole } from '../../lib/myconsole.js'
- export default {
- methods:{
- methods1:function(){
- realconsole();
- }
- }}
- </script>
- <style>
- .teslist {
- }
- </style>
复制代码 卡密处理JS代码
- //去除重复卡密 传入卡密数组
- function removeRepetitionKey(arr) {
- return Array.from(new Set(arr))
- }
- //随机生成卡密 len:卡密长度 str:开头 type:1大写字母 2小写字母 3大小写混合 4数字 5数字大小写字母混合 默认数字大小写混合
- function randomKey(len, str, nub, type) {
- len = len || 32;
- var arr = [];
- switch (type) {
- case 1:
- var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- break;
- case 2:
- var $chars = 'abcdefghijklmnopqrstuvwxyz';
- break;
- case 3:
- var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
- break;
- case 4:
- var $chars = '1234567890';
- break;
- case 5:
- var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
- break;
- default:
- var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
- break;
- }
- var maxPos = $chars.length;
- for (j = 0; j < nub; j++) {
- var pwd = '';
- for (i = 0; i < len; i++) {
- pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
- }
- arr.push(str+pwd)
- }
- return arr
- }
- //替换卡密内容 传入卡密数组,将每条卡密的str1替换成str2 这个会替换原数组,不影响
- function replaceKey(arr, str1, str2) {
- arr.forEach((v, i) => {
- arr[i] = arr[i].replace(str1, str2)
- })
- return arr
- }
- //头部或尾部增加字符串
- function addKey(arr, before, after) {
- arr.forEach((v, i) => {
- arr[i] = before + arr[i] + after
- })
- return arr
- }
- //复制卡密 nub:复制几次 disorganize:是否打乱顺序
- function copyKey(arr, nub, disorganize) {
- var arr_new = []
- arr.forEach((v, i) => {
- for (let i = 0; i < nub; i++) {
- arr_new.push(v)
- }
- })
- if (disorganize) {
- arr_new.sort(function() {
- return .5 - Math.random();
- });
- }
- return arr_new
- }
- //过滤卡密 len 长度 isCut(true是去除卡密 false是保留卡密)type=1 大于 type=2 小于 type=3等于
- function removeLenKey(arr, len, isCut, type) {
- var arr_new = []
- if (isCut) {
- for (let i = 0; i < arr.length; i++) {
- if (type == 1) {
- if (arr[i].length > len) {
- arr.splice(i, 1)
- i--;
- }
- } else if (type == 2) {
- if (arr[i].length < len) {
- arr.splice(i, 1)
- i--;
- }
- } else {
- if (arr[i].length == len) {
- arr.splice(i, 1)
- i--;
- }
- }
- }
- arr_new = arr
- } else { //
- arr.forEach((v, i) => {
- if (type == 1) {
- if (v.length > len) {
- arr_new.push(v)
- }
- } else if (type == 2) {
- if (v.length < len) {
- arr_new.push(v)
- }
- } else {
- if (v.length == len) {
- arr_new.push(v)
- }
- }
- })
- }
- return arr_new
- }
- //截取卡密 len 截取长度 isLeft(true是截取前面(左侧) false是截取后面(右侧))
- function cutOutKey(arr, len, isLeft) {
- arr.forEach((v, i) => {
- if (isLeft) {
- arr[i] = arr[i].substring(0, len);
- } else {
- arr[i] = arr[i].substring(arr[i].length - len, arr[i].length);
- }
- })
- return arr;
- }
- //截取卡密 str 截取字符串之前或之后 isLeft(true是截取前面(左侧) false是截取后面(右侧))
- function cutOutKey1(arr, str, isLeft) {
- arr.forEach((v, i) => {
- arr[i] = getCaption(arr[i], str, isLeft);
- })
- return arr;
- }
- //这个函数是给其他调用的
- function getCaption(obj, str, state) {
- if (state) {
- var index = obj.indexOf(str);
- } else {
- var index = obj.lastIndexOf(str);
- }
- if (state) {
- obj = obj.substring(0, index) == '' ? obj : obj.substring(0, index);
- } else {
- obj = obj.substring(index + 1, obj.length) == '' ? obj : obj.substring(index + 1, obj.length);
- }
- return obj;
- }
- //生成序列
- function listKey(min, max) {
- var arr = []
- var len = max - min + 1
- for (var i = 0; i < len; i++) {
- arr.push(Number(min) + Number(i))
- }
- return arr
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|