12345678910111213141516171819202122232425262728293031323334353637383940 |
- /*
- * @Author: your name
- * @Date: 2020-05-28 10:28:16
- * @LastEditTime: 2020-05-29 11:15:12
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \admin-frame\public\worker\worker.js
- */
- let time;
- onmessage = function(e) {
- const data = e.data;
- time = e.data.time / 1000 - 6;
- setInterval(jwtTime, 6000, data);
- };
- function jwtTime({ token }) {
- var base64Url = token.split('.')[1];
- var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
- var jsonPayload = decodeURIComponent(
- atob(base64)
- .split('')
- .map(function(c) {
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
- })
- .join('')
- );
- const exp = JSON.parse(jsonPayload).exp;
- time = Number(time + 6);
- if (time > exp) {
- postMessage({
- errcode: -1,
- errmsg: '登录过期',
- });
- } else {
- postMessage({
- errcode: 0,
- errmsg: '未过期',
- });
- }
- }
|