123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- "use strict";
- const common_vendor = require("../common/vendor.js");
- const config_config = require("../config/config.js");
- const framework_log = require("./log.js");
- const framework_tools = require("./tools.js");
- class util {
- /**
- * 获取本地数据
- */
- static getStorage(key) {
- let d = common_vendor.index.getStorageSync(key);
- if (util.isNull(d)) {
- return null;
- }
- return d;
- }
- /**
- * 设置本地数据
- */
- static setStorage(key, value) {
- common_vendor.index.setStorageSync(key, value);
- }
- /**
- * 清除本地key数据
- */
- static clearStorageForKey(key) {
- let d = util.getStorage(key);
- if (util.isNull(d)) {
- framework_log.log.Error(`${key} is null!`);
- } else {
- util.setStorage(key, null);
- }
- }
- /**
- * 清除本地数据
- */
- static clearAllStorage() {
- common_vendor.index.clearStorageSync();
- }
- static isNull(v) {
- if (v == null || v == void 0 || v == "") {
- return true;
- }
- return false;
- }
- static alert(v) {
- let Platform = framework_tools.tools.getCurPlatform();
- if (Platform == config_config.config.Platform.H5) {
- alert(v);
- } else if (Platform == config_config.config.Platform.TOUTIAO) {
- framework_log.log.Debug("TOUTIAO", v);
- } else if (Platform == config_config.config.Platform.WEIXIN) {
- framework_log.log.Debug("WEIXIN", v);
- }
- }
- // Loadding
- static showLoading(title = "加载中...", mask = false) {
- common_vendor.index.showLoading({
- title,
- mask
- });
- }
- static hideLoading() {
- common_vendor.index.hideLoading();
- }
- // Toast
- static showInfoToast(title, duration = 1500, mask = false) {
- common_vendor.index.showToast({
- title,
- icon: "none",
- duration,
- mask
- });
- }
- static showSuccessToast(title, duration = 1500, mask = false) {
- common_vendor.index.showToast({
- title,
- icon: "success",
- duration,
- mask
- });
- }
- static showErrorToast(title, duration = 1500, mask = false) {
- common_vendor.index.showToast({
- title,
- icon: "error",
- duration,
- mask
- });
- }
- // Modal
- static showModal(title, content, confirm_cb = null, cancel_cb = null, confirmText = "确定", showCancel = true, cancelText = "取消") {
- common_vendor.index.showModal({
- title,
- content,
- confirmText,
- showCancel,
- cancelText,
- success: function(res) {
- if (res.confirm) {
- confirm_cb && confirm_cb();
- } else if (res.cancel) {
- cancel_cb && cancel_cb();
- }
- }
- });
- }
- static showModalNoCancel(title, content, confirm_cb = null, cancel_cb = null, confirmText = "确定") {
- this.showModal(title, content, confirm_cb, cancel_cb, confirmText, false);
- }
- // ActionSheet
- static showActionSheet(alertText, itemList, confirm_cb, cancel_cb = null) {
- common_vendor.index.showActionSheet({
- alertText,
- itemList,
- success: function(res) {
- confirm_cb && confirm_cb(res.tapIndex);
- },
- fail: function(err) {
- cancel_cb && cancel_cb();
- }
- });
- }
- }
- exports.util = util;
|