Comments and suggestions are welcome in the following!
The method name | parameter | introduce |
judgeNull | value | Check for null values, including {} and [], null true, otherwise false |
judgeString | value | Checks whether it is a string, true if, false otherwise |
judgeNumber | value | Checks whether it is a numeric type, true if, false otherwise |
judgeBoolean | value | Checks whether it is a Boolean type, true if, false otherwise |
judgeArray | value | Checks whether it is an array type, true if, false otherwise |
judgeObject | value | Checks whether it is an object type, true if it is, and false otherwise |
judgeFunction | value | Checks whether it is a method type, true if, and false otherwise |
mergeObject | ob1,ob2… | Merge object, deep clone |
getApp | Same as wechat official getApp | |
getCurrentPages | Same as wechat official getCurrentPages | |
getCurrentPage | Get current page | |
getCurrentPath | Gets the current page path | |
getPath | targetPath | A simple encapsulation of getRelativePath that doesn’t require the current path, just the destination path |
getRelativePath | currentPath,targetPath | Gets the relative path between two paths |
getTimestamp | Get timestamp | |
getClassName | The object key corresponds to class, and the value corresponds to true or false | The method of obtaining class, using the same method as ng, more convenient generation of class |
app.js
import utils from './utils/index';
App({
onLaunch() {
this.utils = new utils()
}
})
Copy the code
Const colors = [' 1 ', '2', '3', '4', '5', '6', '7', '1, 2, 1, 4, '1,5,6,7'] let app = getApp() let utils = app.utils Page({data: {string: ", number: 0, Boolean: true, object: {}, array: [] }, onLoad() { console.log(this.data.string) console.log('this.data.string is string : ' + utils.judgeString(this.data.string)) console.log('this.data.string is null : ' + utils.judgeNull(this.data.string)) console.log(this.data.number) console.log('this.data.number is number : ' + utils.judgeNumber(this.data.number)) console.log(this.data.boolean) console.log('this.data.boolean is boolean : ' + utils.judgeBoolean(this.data.boolean)) console.log(this.data.object) console.log('this.data.object is object : ' + utils.judgeObject(this.data.object)) console.log('this.data.object is null : ' + utils.judgeNull(this.data.object)) console.log(this.data.array) console.log('this.data.array is array : ' + utils.judgeArray(this.data.array)) console.log('this.data.string is null : ' + utils.judgeNull(this.data.array)) let aObject = { aa: { a: 1 } } let bObject = { bb: { b: 2 } } let cObject = utils.mergeObject(aObject, bObject) console.log(aObject) console.log(bObject) console.log(cObject) aObject.aa.a = 2 console.log(cObject) let currentPath = utils.getCurrentPath() let targetPath = 'pages/list/list' let relativePath = utils.getPath(targetPath) console.log(currentPath) console.log(targetPath) console.log(relativePath) console.log(this.getColors(colors)) }, getColors(colors) { let returnColors = [] for (var a = 0; a < colors.length; a++) { let color = ',' + colors[a] + ',' let className = utils.getClassName({ 'block': true, 'red': color.indexOf(',1,') > -1, 'orange': color.indexOf(',2,') > -1, 'yellow': color.indexOf(',3,') > -1, 'green': color.indexOf(',4,') > -1, 'lightblue': color.indexOf(',5,') > -1, 'blue': color.indexOf(',6,') > -1, 'purple': color.indexOf(',7,') > -1 }) returnColors.push(className) } return returnColors } })Copy the code
File download:
reply