### 请求header **请求header已经在所有接口请求时统一携带,具体接口发请求时不用考虑header,在前端创作平台项目http文件下的intercept.js文件的请求拦截器中进行了封装** 通用配置 | key | value | | :----------- | :----------------------------- | | Content-Type | application/json;charset=utf-8 | 如果用户进入到某个作品后,统一在请求头加上如下参数 | key | value | | :------------ | :------------------------------- | | Content-Type | application/json;charset=utf-8 | | Authorization | 用户认证签名(用户登录后统一携带) | | Botaccount | 作品帐号 | | Groupid | 项目组ID | | Mul | true(默认值写死) | | Projectid | 项目ID(默认值写死) | 代码 ```js // 通用配置 var instance = axios.create({ headers: { "Content-Type": "application/json;charset=UTF-8", }, timeout: 60 * 1000 * 5 // 5分钟ajax请求超时 }); let isheadrsinfo = JSON.parse(sessionStorage.getItem("headrsinfo")); // 如果用户进入到某个作品后,统一在请求头加上如下参数 if (isheadrsinfo) { var instance = axios.create({ headers: { "Content-Type": "application/json;charset=UTF-8", projectId: isheadrsinfo.projectId, mul: isheadrsinfo.mul, groupId: isheadrsinfo.groupId, botAccount: isheadrsinfo.botAccount, // "Origin":'hw-gz54.heyqiwu.cn' }, timeout: 60 * 1000 * 5 // 5分钟超时 }); } // 请求前拦截 instance.interceptors.request.use( async function (config) { // console.log(config) let nextChecked = window.localStorage.getItem("nextChecked"); let now = new Date().getTime(); let overTime = window.localStorage.getItem("duration") - 5000; if (mask) { // 加上蒙层等待效果 maskDialog.createMask(mask); } //勾选保持登录 过期处理 if (nextChecked === "1" && now >= overTime && clockIt) { clockIt = false; let password = window.localStorage.getItem("loginPassWord"); let userName = window.localStorage.getItem("loginName"); let parme = { username: decodeURI(userName), password: window.atob(window.atob(password)) }; const res = await toLogin(parme) if (res.data.code === 1) { var duration = res.data.data.duration; //超时时间 let overTimes = new Date().getTime() + duration; localStorage.setItem("duration", overTimes); console.log(new Date(overTimes), "超时时间"); console.log(res.data.data, "2222"); cookie.setCookie("platform_token", res.data.data.token, duration); // 存入localStorage window.localStorage.setItem( "platform_token", res.data.data.token ); config.auth.username = res.data.data.token; config.headers.Authorization = "Basic " + btoa(res.data.data.token + ":" + "s00pers3cret"); location.reload() } clockIt = true; // resolve() // }); } // console.log(config); return config; }, function (error) { return Promise.reject(error); } ); ```