123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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)
- }
- }
-
- // Loadding
- public static showLoading(title='加载中...',mask:boolean=false) {
- uni.showLoading({
- title:title,
- mask:mask
- })
- }
-
- public static hideLoading() {
- uni.hideLoading()
- }
-
- // Toast
- 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
- })
- }
-
- // Modal
- public static showModal(title:string, content:string, confirm_cb:Function=null, cancel_cb:Function=null, confirmText:string='确定', showCancel:boolean=true, cancelText:string='取消') {
- uni.showModal({
- title: title,
- content: content,
- confirmText: confirmText,
- showCancel: showCancel,
- cancelText: cancelText,
- success: function (res) {
- if (res.confirm) {
- // console.log('用户点击确定')
- confirm_cb && confirm_cb()
- } else if (res.cancel) {
- // console.log('用户点击取消')
- cancel_cb && cancel_cb()
- }
- }
- })
- }
-
- public static showModalNoCancel(title:string, content:string, confirm_cb:Function=null, cancel_cb:Function=null, confirmText:string='确定'){
- this.showModal(title,content,confirm_cb,cancel_cb,confirmText,false)
- }
-
- // ActionSheet
- public static showActionSheet(alertText:string, itemList:string[], confirm_cb:Function, cancel_cb:Function=null) {
- uni.showActionSheet({
- alertText:alertText,
- itemList: itemList,
- success: function (res) {
- // console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
- confirm_cb && confirm_cb(res.tapIndex)
- },
- fail: function (err) {
- // console.log('showActionSheet err=',err.errMsg);
- cancel_cb && cancel_cb()
- }
- });
- }
-
- }
|