common.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // import config from "./config"
  2. // import store from "@/store/index.js"
  3. import {
  4. Decimal
  5. } from 'decimal.js'
  6. import config from "./config.js"
  7. export const setToken = (tokenVal) => {
  8. try {
  9. uni.setStorageSync(config.tokenKey, tokenVal);
  10. } catch (e) {
  11. // error
  12. }
  13. }
  14. export const getToken = () => {
  15. try {
  16. const value = uni.getStorageSync(config.tokenKey);
  17. return value || ''
  18. } catch (e) {
  19. // error
  20. }
  21. }
  22. // 判断是否登录
  23. export const ifLogin_ = () => {
  24. return new Promise((resolve, reject) => {
  25. if (getToken()) {
  26. resolve()
  27. } else {
  28. uni.navigateTo({
  29. url: '/pages/login/index'
  30. });
  31. reject()
  32. };
  33. })
  34. };
  35. export const reverseBack = () => {
  36. const pages = getCurrentPages()
  37. if (pages.length <= 1) {
  38. uni.reLaunch({
  39. url: '/pages/index/index'
  40. });
  41. } else {
  42. uni.navigateBack({
  43. delta: 1,
  44. fail: err => {}
  45. })
  46. }
  47. }
  48. export const decimalNum = {
  49. // 加法
  50. add:(a , b) => {
  51. return new Decimal(a).add(new Decimal(b))
  52. },
  53. // 减法
  54. sub:(a , b) => {
  55. return new Decimal(a).sub(new Decimal(b))
  56. },
  57. // 乘法
  58. mul:(a , b) => {
  59. return new Decimal(a).mul(new Decimal(b))
  60. },
  61. // 除法
  62. div:(a , b) => {
  63. return new Decimal(a).div(new Decimal(b))
  64. },
  65. // // 加法
  66. // let c = new Decimal(a).add(new Decimal(b))
  67. // // 减法
  68. // let d = new Decimal(a).sub(new Decimal(b))
  69. // // 乘法
  70. // let e = new Decimal(a).mul(new Decimal(b))
  71. // // 除法
  72. // let f = new Decimal(a).div(new Decimal(b))
  73. }