index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. export const LOGIN_USER = "login_user"
  2. // 获取存储的数据
  3. export const getStorage = function(key) {
  4. var val = sessionStorage.getItem(key)
  5. if (val) {
  6. return JSON.parse(val)
  7. } else {
  8. return false
  9. }
  10. }
  11. // 存储数据
  12. export const setStorage = function(key, val) {
  13. sessionStorage.setItem(key, JSON.stringify(val))
  14. }
  15. // 删除存储数据
  16. export const removeStorage = function(key) {
  17. sessionStorage.removeItem(key)
  18. }
  19. // 性别格式化
  20. export const sexFormater = function(sex) {
  21. var val = sex
  22. if (val === 1) {
  23. return '男'
  24. } else if (val === 0) {
  25. return '女'
  26. } else if (val === -1) {
  27. return '未知'
  28. } else {
  29. return ''
  30. }
  31. }
  32. export const payTypeFormater = function(type) {
  33. if (type === 1) {
  34. return '支付宝'
  35. } else if (type === 2) {
  36. return '微信'
  37. } else {
  38. return '未知'
  39. }
  40. }
  41. export const payStatusFormater = function(payStatus) {
  42. if (payStatus === 0) {
  43. return '待支付'
  44. } else if (payStatus === 10) {
  45. return '支付完成'
  46. } else {
  47. return '未知'
  48. }
  49. }
  50. export const checkStatusFormater = function(checkStatus) {
  51. if (checkStatus === 0) {
  52. return '未核对'
  53. } else if (checkStatus === 10) {
  54. return '核对成功'
  55. } else if (checkStatus === 20) {
  56. return '核对失败'
  57. } else {
  58. return '未知'
  59. }
  60. }
  61. export const timeFormater = function(ctime) {
  62. var time = new Date(ctime * 1000)
  63. var month = time.getMonth() + 1
  64. var day = time.getDate()
  65. if (month < 10) {
  66. month = '0' + month
  67. }
  68. if (day < 10) {
  69. day = '0' + day
  70. }
  71. return time.getFullYear() + '-' + month + '-' + day
  72. }
  73. export const timeDetailFormater = function(ctime) {
  74. var time = new Date(ctime * 1000)
  75. var month = time.getMonth() + 1
  76. var day = time.getDate()
  77. var hour = time.getHours()
  78. var minu = time.getMinutes()
  79. var sec = time.getSeconds()
  80. if (month < 10) {
  81. month = '0' + month
  82. }
  83. if (day < 10) {
  84. day = '0' + day
  85. }
  86. if (hour < 10) {
  87. hour = '0' + hour
  88. }
  89. if (minu < 10) {
  90. minu = '0' + minu
  91. }
  92. if (sec < 10) {
  93. sec = '0' + sec
  94. }
  95. return time.getFullYear() + '-' + month + '-' + day + " " + hour + ":" + minu + ":" + sec
  96. }