h5-token过期验证.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view>
  3. <web-view :src="href"></web-view>
  4. </view>
  5. </template>
  6. <script>
  7. import "@/common/time.js"
  8. // 返回指定日期距今多少天
  9. const daysComputed = time => {
  10. let oldTimeFormat = new Date(time)
  11. let nowDate = new Date()
  12. if (nowDate.getTime() - oldTimeFormat.getTime() > 0) {
  13. let times = nowDate.getTime() - oldTimeFormat.getTime()
  14. let days = parseInt(times / (60 * 60 * 24 * 1000))
  15. return days
  16. } else {
  17. throw ('传入时间不能大于当前日期')
  18. }
  19. }
  20. // console.log(daysComputed('2022-02-26'))
  21. export default {
  22. data() {
  23. return {
  24. url: "",
  25. href: ""
  26. };
  27. },
  28. onLoad() {
  29. // #ifndef APP-NVUE
  30. const eventChannel = this.getOpenerEventChannel();
  31. // #endif
  32. // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
  33. eventChannel.on('acceptDataFromOpenerPage', (data) => {
  34. console.log(data)
  35. this.url = escape(data.url)
  36. })
  37. if (!uni.getStorageSync("oa_login_time")) {
  38. // 第一次登录
  39. console.log("第一次登陆")
  40. let oa_login_time = "2010-01-01"
  41. uni.setStorageSync("oa_login_time", new Date().format("yyyy-MM-dd"))
  42. this.href = "http://oa_system.nxmy.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
  43. .staff_num + "&url=" + this.url + "&oa_login_time=" + oa_login_time
  44. } else {
  45. // 有登录记录
  46. console.log("有登录记录")
  47. let oa_login_time = uni.getStorageSync("oa_login_time")
  48. if (daysComputed(oa_login_time) > 5) {
  49. uni.setStorageSync("oa_login_time", new Date().format("yyyy-MM-dd"))
  50. console.log(">5",uni.getStorageSync("oa_login_time"))
  51. this.href = "http://oa_system.nxmy.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
  52. .staff_num + "&url=" + this.url + "&oa_login_time=" + uni.getStorageSync("oa_login_time")
  53. } else {
  54. console.log("<5",oa_login_time)
  55. this.href = "http://oa_system.nxmy.com:8011/oa_login.html?staff_num=" + uni.getStorageSync('user')
  56. .staff_num + "&url=" + this.url + "&oa_login_time=" + oa_login_time
  57. }
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss">
  63. </style>