Files
hms/apps/miniprogram/inject-auth.cjs
iven 50eae8b809 feat(miniprogram): 温润东方风全面 UI 重设计
73 文件变更,覆盖全部 40 个页面 SCSS + TabBar 图标 + 组件样式。
统一赤陶主色 #C4623A + 暖米背景 + 衬线标题字体 + 12px 圆角体系。
2026-04-28 00:19:52 +08:00

85 lines
2.7 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 重建后注入明文 token无加密密钥
*/
const automator = require('miniprogram-automator');
const http = require('http');
function getFreshToken() {
return new Promise((resolve, reject) => {
const data = JSON.stringify({ username: 'admin', password: 'Admin@2026' });
const req = http.request({
hostname: 'localhost', port: 3000,
path: '/api/v1/auth/login', method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) }
}, res => {
let body = '';
res.on('data', d => body += d);
res.on('end', () => {
try { const j = JSON.parse(body); resolve(j.data); } catch (e) { reject(e); }
});
});
req.on('error', reject);
req.write(data);
req.end();
});
}
async function main() {
console.log('1. 获取 token...');
const loginData = await getFreshToken();
console.log(` access: ${loginData.access_token.length} chars`);
console.log('2. 连接 DevTools...');
const mp = await automator.connect({ wsEndpoint: 'ws://localhost:9420' });
console.log('3. 写入 storage (明文模式)...');
const result = await mp.evaluate((at, rt, ud, ur, tid, pid) => {
try {
// 无加密密钥时 secureSet 走明文
// 但我们直接用 wx.setStorageSync 确保
wx.setStorageSync('access_token', at);
wx.setStorageSync('refresh_token', rt);
wx.setStorageSync('user_data', ud);
wx.setStorageSync('user_roles', ur);
wx.setStorageSync('tenant_id', tid);
wx.setStorageSync('current_patient_id', pid);
wx.setStorageSync('current_patient', {
id: pid, name: 'TestPatient', gender: 'male',
birth_date: '1990-01-15', status: 'active'
});
const v = wx.getStorageSync('access_token');
return 'ok:' + v.length;
} catch(e) { return 'err:' + e.message; }
},
loginData.access_token,
loginData.refresh_token,
JSON.stringify({
id: loginData.user.id,
username: loginData.user.username,
display_name: loginData.user.display_name,
tenant_id: '019d80da-7a2c-7820-b0a3-3d5266a3a324'
}),
JSON.stringify(['admin']),
'019d80da-7a2c-7820-b0a3-3d5266a3a324',
'019dcd34-bc4d-72c1-8c19-77ce1f4839d6'
);
console.log(` 结果: ${result}`);
console.log('4. reLaunch 首页...');
await mp.reLaunch('/pages/index/index');
await new Promise(r => setTimeout(r, 3000));
const page = await mp.currentPage();
console.log(`5. 当前页面: ${page.path}`);
if (page.path === 'pages/index/index') {
console.log('SUCCESS!');
} else {
console.log('FAILED - redirected to:', page.path);
}
await mp.disconnect();
}
main().catch(e => { console.error(e); process.exit(1); });