| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // import { CryptoJS } from './crypto-js.min.js';
- import { CryptoJS } from './crypto-js.min.js';
- let loading = false;
- let count = 0;
- /** 请求弹窗开启 */
- export const showLoading = function (title = '') {
- if (!loading) {
- uni.showLoading({
- title: title || '',
- mask: true,
- });
- loading = true;
- }
- count += 1;
- };
- /** 请求弹窗关闭 */
- export const hideLoading = function () {
- let timer = setTimeout(() => {
- // 在下一次tick中如果没有新的loading进来(count === 1) 则关闭loading (消除多接口同步或者异步的loading闪屏)
- if (count === 1 && loading) {
- uni.hideLoading();
- loading = false;
- }
- count -= 1;
- clearTimeout(timer);
- timer = null;
- }, 0);
- };
- /** 提示消息 */
- export const showToast = function (msg: string, fn = () => {}, duration = 1500) {
- let timer = null;
- uni.showToast({
- title: msg,
- mask: true,
- icon: 'none',
- duration: duration,
- });
- if (fn) {
- timer = setTimeout(() => {
- fn();
- timer = null;
- }, duration);
- }
- };
- /** 提示信息 */
- export const showModal = function (content: string, callBack = () => {}, data: any = {}) {
- uni.showModal({
- content: content,
- title: data.title || '',
- confirmText: data.confirmText || '确定',
- confirmColor: data.confirmColor || '',
- cancelColor: data.cancelColor || '',
- cancelText: data.cancelText || '',
- showCancel: data.cancelText ? true : false,
- success: (res) => {
- if (res.confirm && callBack instanceof Function) {
- callBack();
- }
- if (!res.confirm && data.callBack instanceof Function) {
- data.callBack();
- }
- },
- });
- };
- /** 是否为空 */
- export const isEmpty = function (obj) {
- if (obj == undefined || obj == null || obj == '') {
- return true;
- } else if (obj instanceof Array) {
- return obj.length <= 0;
- } else if (obj instanceof Object) {
- return Object.keys(obj).length <= 0;
- }
- return false;
- };
- /** 是否不为空 */
- export const isNotEmpty = function (obj) {
- return !isEmpty(obj);
- };
- /** des加密 */
- export const desEncrypt = function (message, key) {
- let keyHex = CryptoJS.enc.Utf8.parse(key);
- let encrypted = CryptoJS.DES.encrypt(message, keyHex, {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7,
- });
- return encrypted.toString();
- };
- /** des ECB解密str:秘钥串;key:秘钥;exportType:输出方式; */
- export const desDecrypt = function (str, key, exportType) {
- let keyHex = CryptoJS.enc.Utf8.parse(key);
- let decrypted = CryptoJS.DES.decrypt(
- exportType == 'hex'
- ? {
- ciphertext: CryptoJS.enc.Hex.parse(str),
- }
- : str,
- keyHex,
- {
- mode: CryptoJS.mode.ECB,
- padding: CryptoJS.pad.Pkcs7,
- }
- );
- return decrypted.toString(CryptoJS.enc.Utf8);
- };
- /** 数组转化成对象,方便使用 */
- export const turnToMap = (list) => {
- let map = {};
- list.map((item) => {
- map[item.routePath] = JSON.parse(item.infoJson || '{}');
- });
- return map;
- };
|