You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.3 KiB

8 months ago
9 months ago
8 months ago
  1. import { WX_API, H5_API, httpPrefix } from './site.config.js';
  2. var _url = H5_API+ WX_API + httpPrefix
  3. import store from '@/store/index.js'
  4. export function checkToken(vm) {
  5. let expiresTime = vm.$store.state.user.vuex_loginInfo.expiresTime
  6. let nowTime = new Date() * 1
  7. // console.log('超时了')
  8. // console.log(expiresTime)
  9. if (nowTime > expiresTime * 1) {
  10. vm.$store.commit('goLogin')
  11. // 如果小于20分钟就刷新一下token &&
  12. } else if ((expiresTime * 1 - nowTime) / 60000 <5) {
  13. vm.$store.dispatch('refreshToken')
  14. }
  15. }
  16. function dateRangeFn(dateRange) {
  17. let tmp = []
  18. let dateArr = []
  19. dateRange.forEach((date) => {
  20. let dateStr = date.toISOString().split('T')[0]
  21. let dd = dateStr.split('-')[2]
  22. const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  23. const dayOfWeek = date.getDay();
  24. const weekName = daysOfWeek[dayOfWeek];
  25. // console.log(dateStr)
  26. // console.log(weekName)
  27. if (tmp.length == 0) {
  28. dateArr.push(tmp)
  29. }
  30. let obj = {
  31. week: weekName,
  32. num: dd,
  33. date: dateStr
  34. }
  35. tmp.push(obj)
  36. if (tmp.length == 5) {
  37. tmp = []
  38. }
  39. });
  40. // console.log(dateArr)
  41. return dateArr
  42. }
  43. export function getDates(startDate, endDate) {
  44. const dates = [];
  45. let currentDate = new Date(startDate);
  46. while (currentDate <= endDate) {
  47. dates.push(new Date(currentDate));
  48. currentDate.setDate(currentDate.getDate() + 1);
  49. }
  50. return dateRangeFn(dates)
  51. }
  52. export function uploadImgApi(filePath, imgName, imgLink='image') {
  53. console.log(filePath)
  54. let token = 'Bearer '+ store.state.user.vuex_loginInfo.accessToken
  55. let timer = new Date() * 1
  56. return new Promise((reslove, reject)=>{
  57. // 上传图片到服务器
  58. uni.uploadFile({
  59. url: _url + 'infra/file/upload',//接口
  60. filePath: filePath,//要上传的图片的本地路径
  61. name: 'file',
  62. // complain
  63. formData: {
  64. path: imgLink+'/'+ uni.$u.date(timer, 'yyyy-mm-dd')+'/'+timer + '-'+ imgName,
  65. type: 1,
  66. fileSuffix: "png"
  67. },
  68. header: {
  69. Authorization: token,
  70. // 'tenant-id': '1704459882232553474'
  71. },
  72. success(res) {
  73. console.log('上传成功??')
  74. console.log(res)
  75. let res2 = JSON.parse(res.data)
  76. reslove(res2.data)
  77. },
  78. fail() {
  79. reject(0)
  80. },
  81. complete: (err)=> {
  82. uni.hideLoading();
  83. }
  84. })
  85. })
  86. }