1 line
33 KiB
Plaintext
1 line
33 KiB
Plaintext
|
{"version":3,"file":"index.js","sources":["../../../../../src/sheep/helper/index.js"],"sourcesContent":["import test from './test.js'\r\nimport { round } from './digit.js'\r\n/**\r\n * @description 如果value小于min,取min;如果value大于max,取max\r\n * @param {number} min\r\n * @param {number} max\r\n * @param {number} value\r\n */\r\nfunction range(min = 0, max = 0, value = 0) {\r\n return Math.max(min, Math.min(max, Number(value)))\r\n}\r\n\r\n/**\r\n * @description 用于获取用户传递值的px值 如果用户传递了\"xxpx\"或者\"xxrpx\",取出其数值部分,如果是\"xxxrpx\"还需要用过uni.upx2px进行转换\r\n * @param {number|string} value 用户传递值的px值\r\n * @param {boolean} unit\r\n * @returns {number|string}\r\n */\r\nexport function getPx(value, unit = false) {\r\n if (test.number(value)) {\r\n return unit ? `${value}px` : Number(value)\r\n }\r\n // 如果带有rpx,先取出其数值部分,再转为px值\r\n if (/(rpx|upx)$/.test(value)) {\r\n return unit ? `${uni.upx2px(parseInt(value))}px` : Number(uni.upx2px(parseInt(value)))\r\n }\r\n return unit ? `${parseInt(value)}px` : parseInt(value)\r\n}\r\n\r\n/**\r\n * @description 进行延时,以达到可以简写代码的目的\r\n * @param {number} value 堵塞时间 单位ms 毫秒\r\n * @returns {Promise} 返回promise\r\n */\r\nexport function sleep(value = 30) {\r\n return new Promise((resolve) => {\r\n setTimeout(() => {\r\n resolve()\r\n }, value)\r\n })\r\n}\r\n/**\r\n * @description 运行期判断平台\r\n * @returns {string} 返回所在平台(小写)\r\n * @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台\r\n */\r\nexport function os() {\r\n return uni.getSystemInfoSync().platform.toLowerCase()\r\n}\r\n/**\r\n * @description 获取系统信息同步接口\r\n * @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync\r\n */\r\nexport function sys() {\r\n return uni.getSystemInfoSync()\r\n}\r\n\r\n/**\r\n * @description 取一个区间数\r\n * @param {Number} min 最小值\r\n * @param {Number} max 最大值\r\n */\r\nfunction random(min, max) {\r\n if (min >= 0 && max > 0 && max >= min) {\r\n const gab = max - min + 1\r\n return Math.floor(Math.random() * gab + min)\r\n }\r\n return 0\r\n}\r\n\r\n/**\r\n * @param {Number} len uuid的长度\r\n * @param {Boolean} firstU 将返回的首字母置为\"u\"\r\n * @param {Nubmer} radix 生成uuid的基数(意味着返回的字符串都是这个基数),2-二进制,8-八进制,10-十进制,16-十六进制\r\n */\r\nexport function guid(len = 32, firstU = true, radix = null) {\r\n const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')\r\n const uuid = []\r\n radix = radix || chars.length\r\n\r\n if (len) {\r\n // 如果指定uuid长度,只是取随机的字符,0|x为位运算,能去掉x的小数位,返回整数位\r\n for (let i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]\r\n } else {\r\n let r\r\n // rfc4122标准要求返回的uuid中,某些位为固定的字符\r\n uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'\r\n uuid[14] = '4'\r\n\r\n for (let i = 0; i < 36; i++) {\r\n if (!uuid[i]) {\r\n r = 0 | (Math.random() * 16)\r\n uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r]\r\n }\r\n }\r\n }\r\n // 移除第一个字符,并用u替代,因为第一个字符为数值时,该guuid不能用作id或者class\r\n if (firstU) {\r\n uuid.shift()\r\n return `u${uuid.join('')}`\r\n }\r\n return uuid.join('')\r\n}\r\n\r\n/**\r\n* @description 获取父组件的参数,因为支付宝小程序不支持provide/inject的写法\r\n this.$parent在非H5中,可以准确获取到父组件,但是在H5中,需要多次this.$parent.$parent.xxx\r\n 这里默认值等于undefined有它的含义,因为最顶层元素(组件)的$parent就是undefined,意味着不传name\r\n 值(默认为undefined),就是查找最顶层的$parent\r\n* @param {string|unde
|