methodTool.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const BASE_IMG_URL = 'https://file-dev.xyyxt.net/'
  2. import store from '@/store/index.js'
  3. export default {
  4. isLogin() {
  5. if (uni.getStorageSync('union_id')) {
  6. return true;
  7. } else {
  8. return false
  9. }
  10. },
  11. splitImgHost(url) {
  12. if (!url) {
  13. return ''
  14. }
  15. if (url.indexOf("http") != -1 || url.indexOf("https") != -1) {
  16. return url;
  17. }
  18. return BASE_IMG_URL + url
  19. },
  20. exit() {
  21. uni.removeStorageSync('union_id')
  22. uni.removeStorageSync('token')
  23. store.state.userInfo = null
  24. uni.reLaunch({
  25. url: '/pages/index/index'
  26. });
  27. },
  28. /* 时间戳转换成日期
  29. * @param timestamp
  30. * @returns {*}
  31. */
  32. timestampToTime(timestamp, isDay = true) {
  33. var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  34. var Y = date.getFullYear() + '-';
  35. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  36. var D = date.getDate() + ' ';
  37. var h = date.getHours() + ':';
  38. var m = date.getMinutes() + ':';
  39. var s = date.getSeconds();
  40. if (isDay) {
  41. return Y + M + D;
  42. }
  43. return Y + M + D + h + m + s;
  44. },
  45. TimeTotimestamp(date) {
  46. var newDate = new Date(date)
  47. return (newDate.getTime() / 1000)
  48. },
  49. timest() {
  50. var tmp = Date.parse(new Date()).toString();
  51. tmp = tmp.substr(0, 10);
  52. return tmp;
  53. }
  54. }