// import config from "./config" // import store from "@/store/index.js" import { Decimal } from 'decimal.js' import config from "./config.js" export const setToken = (tokenVal) => { try { uni.setStorageSync(config.tokenKey, tokenVal); } catch (e) { // error } } export const getToken = () => { try { const value = uni.getStorageSync(config.tokenKey); return value || '' } catch (e) { // error } } export const setStorageSync = (key, val) => { console.log('setStorageSync = ', key, val) try { uni.setStorageSync(key, val); } catch (e) { // error } } export const getStorageSync = (key) => { try { const value = uni.getStorageSync(key); return value || '' } catch (e) { // error } } // 判断是否登录 export const ifLogin_ = () => { return new Promise((resolve, reject) => { if (getToken()) { resolve() } else { uni.navigateTo({ url: '/pages/login/index' }); reject() }; }) }; export const reverseBack = (path = undefined) => { const pages = getCurrentPages() if (pages.length <= 1) { uni.reLaunch({ url: '/pages/index/index' }); } else { let deltaNum = 1; if (path) { const pageLength = pages.length let num = pageLength; for (let i = 1; i < pageLength; i++) { num -= 1; if (pages[num].route === path) { deltaNum = i; } } }; console.log('pages = ' , pages) console.log('deltaNum = ' , deltaNum) uni.navigateBack({ delta: deltaNum, fail: err => {} }) } } export const decimalNum = { // 加法 add: (a, b) => { return new Decimal(a).add(new Decimal(b)) }, // 减法 sub: (a, b) => { return new Decimal(a).sub(new Decimal(b)) }, // 乘法 mul: (a, b) => { return new Decimal(a).mul(new Decimal(b)) }, // 除法 div: (a, b) => { return new Decimal(a).div(new Decimal(b)) }, // // 加法 // let c = new Decimal(a).add(new Decimal(b)) // // 减法 // let d = new Decimal(a).sub(new Decimal(b)) // // 乘法 // let e = new Decimal(a).mul(new Decimal(b)) // // 除法 // let f = new Decimal(a).div(new Decimal(b)) }