123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import { config } from "../config/config"
- import { log } from "./log"
- import { tools } from "./tools"
- export class util {
- /**
- * 获取本地数据
- */
- public static getStorage(key:string){
- let d = uni.getStorageSync(key)
- if(util.isNull(d)){
- return null
- }
- return d
- }
-
- /**
- * 设置本地数据
- */
- public static setStorage(key:string,value:string){
- uni.setStorageSync(key,value)
- }
-
-
- /**
- * 清除本地key数据
- */
- public static clearStorageForKey(key:string){
- let d = util.getStorage(key)
- if(util.isNull(d)){
- log.Error(`${key} is null!`);
- }else{
- util.setStorage(key,null)
- }
- }
-
- /**
- * 清除本地数据
- */
- public static clearAllStorage(){
- uni.clearStorageSync()
- }
-
- public static isNull(v:any){
- if(v==null||v==undefined||v==""){
- return true
- }
- return false
- }
-
- public static alert(v:string){
- let Platform = tools.getCurPlatform()
- if(Platform==config.Platform.H5){
- alert(v)
- }else if(Platform==config.Platform.TOUTIAO){
- log.Debug("TOUTIAO",v)
- }else if(Platform==config.Platform.WEIXIN){
- log.Debug("WEIXIN",v)
- }
- }
-
- public static showLoading(title='加载中...',mask:boolean=false) {
- uni.showLoading({
- title:title,
- mask:mask
- })
- }
-
- public static hideLoading() {
- uni.hideLoading()
- }
-
- public static showInfoToast(title:string,duration=1500,mask=false) {
- uni.showToast({
- title:title,
- icon:'none',
- duration:duration,
- mask:mask
- })
- }
-
- public static showSuccessToast(title:string,duration=1500,mask=false) {
- uni.showToast({
- title:title,
- icon:'success',
- duration:duration,
- mask:mask
- })
- }
-
- public static showErrorToast(title:string,duration=1500,mask=false) {
- uni.showToast({
- title:title,
- icon:'error',
- duration:duration,
- mask:mask
- })
- }
-
-
- }
|