methodTool.js 1.4 KB

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