1、node实现登录
/** * 登录零碎 * @param {String} username 用户名 * @param {String} password 明码 */async function login(username, password) { const res = await fetch(`${BASE_URL}/websys/xxx/login.do`, { credentials: 'include', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Referer': ' http://xxx.com.cn/websys/xxx/index.html' }, body: qs.stringify({ name: username, pwd: password }) }) const matchArr = res.headers.get('set-cookie').match(new RegExp('sys_auth?=([^;]+)')); const sys_auth = matchArr && matchArr[1]; if (!sys_auth) { throw new Error('登录谬误,请确认用户名或明码是否正确'); } cookie = `SITE=alm01; ws_auth=${ws_auth};` // 全局保留登录token}/** * 根据登录token申请后续接口 */async function getPlans(planId) { return await fetch(`${BASE_URL}/websys/xxx/${planId}/plan/?planList`, { credentials: 'include', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Cookie': cookie }, body: qs.stringify({ pageSize: 10, pageNo: 5, }) }) .then(res => res.json()) .then(data => data.plans.rows);}
2、node操作excel