MCPcopy Create free account
hub / github.com/circircir-circle/human_exist_device / Tools

Class Tools

mini_program/common/Tools.js:4–867  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import __config from '../siteinfo'
3
4class Tools {
5
6 constructor() {
7 Object.assign(this, {
8 $$basePath: __config.basePath
9 })
10 }
11
12 /**
13 * 返回文件后缀
14 * @param {Object} file
15 * @return {String}
16 */
17 getFilenameExt(file) {
18 const types = file.name.split('.')
19 return types[types.length - 1]
20 }
21
22 getCurrentDate() {
23 const date = new Date();
24 const year = date.getFullYear()
25 const month = date.getMonth() + 1
26 const day = date.getDate()
27 return [year, month, day].join('-')
28 }
29
30 getCurrentTime() {
31 const date = new Date();
32 const hour = date.getHours()
33 const minute = date.getMinutes()
34 return [hour, minute].join(':')
35 }
36
37 /**
38 * 返回指定范围内的一个整数
39 * @param {Number} min
40 * @param {Number} max
41 * @return {String}
42 */
43 rand(min, max) {
44 return Math.floor(Math.random() * (max - min + 1) + min)
45 }
46
47 /**
48 * 生成字符串组合
49 * @param {Number} size
50 * @return {String}
51 */
52 randString(size) {
53 let result = ''
54 let allChar = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
55
56 size = size || 1
57
58 while (size--) {
59 result += allChar.charAt(this.rand(0, allChar.length - 1))
60 }
61

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected