从后端模板迁过来的样式现在真正用上了,并修掉两处不一致:
- 登录页:.panel-switch + .pane-account / .pane-wechat + 右上角 .corner-toggle 三角形切换;
字段改成无 label 的 .field-plain + 悬浮 .tip;验证码用 .input-row 与按钮同行。
- 找回 / 重置密码页:同样换成 .field-plain 紧凑字段。
- 列表页(设备管理 / 扫码记录):AppLayout 支持 fill → 内容区加 .content-fill,
表格包进 .table-wrap → 卡片撑满剩余高度、表头吸顶、只有表格内部滚动、分页贴底。
- 卡片间距交给 .card + .card;测试页结果区改用全局 .json-box 与 .sub-title。
- ⚠️ 修 bug:「注册」标签下注册面板不显示 —— 登录与注册共用 .pane-account,
但 CSS 只写了 .is-login .pane-account / .is-register .pane-register(后者没有对应元素);
同时给 .is-register 补上 padding-top,避免折角三角形压住第一个输入框。
- 顺带去掉不再需要的内联 margin。
验证:vue-tsc + vite build 通过;浏览器实测三个面板都能切换(注册面板 5 个字段可见、
三角形不压输入框),两个列表页 content-fill 生效、整页不滚动、表格内部滚动且表头 sticky。
233 lines
9.0 KiB
Vue
233 lines
9.0 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 测试页:把真机链路拆开跑(没有实物设备时联调用)
|
||
*
|
||
* ① 模拟设备扫码登录 —— `POST /api/web/test/device-login`(以当前账号为「确认人」,等价于有人扫码确认)
|
||
* ② 模拟中控上报 —— `POST /api/web/test/scan`(SN + 长期 JWT,与真机 `/api/scan/*` 同一套校验)
|
||
* ③ 模拟扫码授权 —— `GET /api/wechat/status` + `POST /api/wechat/confirm`(小程序里就是这一步,纯 AJAX)
|
||
*/
|
||
import { reactive, ref } from 'vue';
|
||
import AppLayout from '@/components/AppLayout.vue';
|
||
import { ApiError } from '@/api/client';
|
||
import { confirmWechatLogin, fetchWechatStatus, testDeviceLogin, testScanReport } from '@/api/web';
|
||
import { getToken } from '@/composables/useAuth';
|
||
import type { DeviceLoginResult, ScanReportResult, WechatCodeStatus } from '@/api/types';
|
||
|
||
const error = ref('');
|
||
const ok = ref('');
|
||
|
||
// ① 模拟设备扫码登录
|
||
const deviceForm = reactive({ sn: '', name: '测试中控', vendor: 'ACME', model: 'HUB-1', firmware: '1.0.0', expiresIn: '' });
|
||
const deviceBusy = ref(false);
|
||
const loginResult = ref<DeviceLoginResult | null>(null);
|
||
|
||
async function doDeviceLogin() {
|
||
error.value = '';
|
||
ok.value = '';
|
||
deviceBusy.value = true;
|
||
try {
|
||
const data = await testDeviceLogin({
|
||
sn: deviceForm.sn.trim(),
|
||
name: deviceForm.name.trim(),
|
||
vendor: deviceForm.vendor.trim(),
|
||
model: deviceForm.model.trim(),
|
||
firmware: deviceForm.firmware.trim(),
|
||
expiresIn: deviceForm.expiresIn.trim(),
|
||
});
|
||
loginResult.value = data;
|
||
scanForm.sn = data.sn;
|
||
scanForm.token = data.token;
|
||
ok.value = `设备 ${data.sn} 已登录${data.firstTime ? '(本次首次注册)' : '(已存在,换发新令牌)'}`;
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '模拟登录失败';
|
||
} finally {
|
||
deviceBusy.value = false;
|
||
}
|
||
}
|
||
|
||
// ② 模拟中控上报
|
||
const scanForm = reactive({ sn: '', token: '', channelId: 'CH-1', channelName: '一号口', barcode: '6901234567892', scanTime: '' });
|
||
const scanBusy = ref(false);
|
||
const scanResult = ref<ScanReportResult | null>(null);
|
||
|
||
async function doScanReport() {
|
||
error.value = '';
|
||
ok.value = '';
|
||
scanBusy.value = true;
|
||
try {
|
||
scanResult.value = await testScanReport({
|
||
sn: scanForm.sn.trim(),
|
||
token: scanForm.token.trim(),
|
||
channelId: scanForm.channelId.trim(),
|
||
channelName: scanForm.channelName.trim(),
|
||
barcode: scanForm.barcode.trim(),
|
||
scanTime: scanForm.scanTime ? scanForm.scanTime.replace('T', ' ') : '',
|
||
});
|
||
ok.value = '模拟上报完成';
|
||
} catch (err) {
|
||
error.value = err instanceof ApiError ? err.message : '模拟上报失败';
|
||
} finally {
|
||
scanBusy.value = false;
|
||
}
|
||
}
|
||
|
||
// ③ 模拟扫码授权(登录码)
|
||
const wechatInput = ref('');
|
||
const wechatBusy = ref(false);
|
||
const wechatStatus = ref<WechatCodeStatus | null>(null);
|
||
const wechatJson = ref('');
|
||
|
||
function showJson(value: unknown) {
|
||
wechatJson.value = JSON.stringify(value, null, 2);
|
||
}
|
||
|
||
async function doStatus() {
|
||
error.value = '';
|
||
wechatBusy.value = true;
|
||
try {
|
||
const data = await fetchWechatStatus(wechatInput.value.trim());
|
||
wechatStatus.value = data;
|
||
showJson(data);
|
||
} catch (err) {
|
||
wechatStatus.value = null;
|
||
showJson({ ok: false, message: err instanceof ApiError ? err.message : '查询失败' });
|
||
} finally {
|
||
wechatBusy.value = false;
|
||
}
|
||
}
|
||
|
||
async function doConfirm() {
|
||
error.value = '';
|
||
wechatBusy.value = true;
|
||
try {
|
||
showJson(await confirmWechatLogin(wechatInput.value.trim()));
|
||
} catch (err) {
|
||
showJson({ ok: false, message: err instanceof ApiError ? err.message : '确认失败' });
|
||
} finally {
|
||
wechatBusy.value = false;
|
||
}
|
||
}
|
||
|
||
/** 当前账号的用户令牌(贴到小程序里调试用;接口只认 header,不认 cookie) */
|
||
const apiToken = ref(getToken());
|
||
</script>
|
||
|
||
<template>
|
||
<AppLayout>
|
||
<template #title>测试页</template>
|
||
|
||
<div v-if="error" class="alert alert-error">{{ error }}</div>
|
||
<div v-if="ok" class="alert alert-ok">{{ ok }}</div>
|
||
|
||
<!-- ① 模拟设备扫码登录 -->
|
||
<div class="card">
|
||
<h3>① 模拟设备扫码登录</h3>
|
||
<p class="hint">
|
||
等价于「设备发码 → 有人扫码确认」:以 <b>当前登录账号</b> 为确认人,设备不存在就现场注册并绑定,
|
||
首次会返回长期 JWT(真机上这一步由手机扫码完成)。
|
||
</p>
|
||
<div class="form-grid">
|
||
<label class="field"><span>设备 SN(留空自动生成)</span><input v-model="deviceForm.sn" placeholder="SN-TEST-01" /></label>
|
||
<label class="field"><span>名称</span><input v-model="deviceForm.name" /></label>
|
||
<label class="field"><span>厂商</span><input v-model="deviceForm.vendor" /></label>
|
||
<label class="field"><span>型号</span><input v-model="deviceForm.model" /></label>
|
||
<label class="field"><span>固件</span><input v-model="deviceForm.firmware" /></label>
|
||
<label class="field"><span>令牌时长(可空,如 30d,不得超过服务端上限)</span><input v-model="deviceForm.expiresIn" placeholder="30d" /></label>
|
||
</div>
|
||
<button class="btn" :disabled="deviceBusy" @click="doDeviceLogin">扫码登录</button>
|
||
|
||
<div v-if="loginResult" class="result">
|
||
<h4 class="sub-title">返回结果</h4>
|
||
<p class="hint">
|
||
{{ loginResult.sn }} · {{ loginResult.firstTime ? '首次注册' : '已存在' }} ·
|
||
归属:{{ loginResult.user ? (loginResult.user.nickname || loginResult.user.username) : '—' }}
|
||
</p>
|
||
<label class="field">
|
||
<span>长期 JWT(复制到 ② 里用)</span>
|
||
<textarea v-model="loginResult.token" readonly rows="3" />
|
||
</label>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ② 模拟中控上报 -->
|
||
<div class="card">
|
||
<h3>② 模拟中控上报</h3>
|
||
<p class="hint">拿①里的 SN + 长期 JWT 上报一条扫码记录(与真机 <code>/api/scan/records</code> 同一套校验)。</p>
|
||
<div class="form-grid">
|
||
<label class="field"><span>设备 SN</span><input v-model="scanForm.sn" placeholder="SN-TEST-01" /></label>
|
||
<label class="field"><span>通道 id</span><input v-model="scanForm.channelId" /></label>
|
||
<label class="field"><span>通道名</span><input v-model="scanForm.channelName" /></label>
|
||
<label class="field"><span>条码</span><input v-model="scanForm.barcode" /></label>
|
||
<label class="field"><span>扫码时间(留空 = 现在)</span><input v-model="scanForm.scanTime" type="datetime-local" /></label>
|
||
</div>
|
||
<label class="field">
|
||
<span>长期 JWT</span>
|
||
<textarea v-model="scanForm.token" rows="3" placeholder="从 ① 里复制过来" />
|
||
</label>
|
||
<button class="btn" :disabled="scanBusy" @click="doScanReport">上报</button>
|
||
|
||
<template v-if="scanResult">
|
||
<h4 class="sub-title">返回结果</h4>
|
||
<pre class="json-box">{{ JSON.stringify(scanResult, null, 2) }}</pre>
|
||
</template>
|
||
</div>
|
||
|
||
<!-- ③ 模拟扫码授权 -->
|
||
<div class="card">
|
||
<h3>③ 模拟扫码授权(AJAX)</h3>
|
||
<p class="hint">
|
||
填电脑端登录页的 6 位码(或整条 <code>/wechat?spm=…</code> 地址):
|
||
「查状态」调 <code>GET /api/wechat/status</code>,「请求登录」调 <code>POST /api/wechat/confirm</code>,
|
||
电脑端会立刻登录。小程序里就是这两步。
|
||
</p>
|
||
<div class="toolbar">
|
||
<input v-model="wechatInput" placeholder="6 位登录码 / 整条扫码地址" style="flex: 1" />
|
||
<button class="btn btn-ghost" :disabled="wechatBusy || !wechatInput.trim()" @click="doStatus">查状态</button>
|
||
<button class="btn" :disabled="wechatBusy || !wechatInput.trim()" @click="doConfirm">请求登录</button>
|
||
</div>
|
||
<p v-if="wechatStatus" class="hint">当前状态:{{ wechatStatus.status }}</p>
|
||
<pre v-if="wechatJson" class="json-box">{{ wechatJson }}</pre>
|
||
</div>
|
||
|
||
<!-- 当前账号令牌 -->
|
||
<div class="card">
|
||
<h3>当前账号的用户令牌</h3>
|
||
<p class="hint">
|
||
接口鉴权 <b>只看 header</b>(<code>Authorization: Bearer <token></code>),不看 cookie,
|
||
所以小程序 / App 直接带这枚令牌即可(有效期见后端 <code>USER_JWT_EXPIRES</code>)。
|
||
</p>
|
||
<textarea :value="apiToken" readonly rows="3" class="token-box" />
|
||
</div>
|
||
</AppLayout>
|
||
</template>
|
||
|
||
<style scoped>
|
||
h3 {
|
||
margin: 0 0 10px;
|
||
font-size: 15px;
|
||
}
|
||
.form-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||
gap: 0 16px;
|
||
}
|
||
.result {
|
||
margin-top: 14px;
|
||
padding-top: 12px;
|
||
border-top: 1px dashed var(--border);
|
||
}
|
||
textarea {
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 9px 12px;
|
||
font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
|
||
resize: vertical;
|
||
width: 100%;
|
||
background: #fff;
|
||
}
|
||
/* 结果区用全局 .json-box(浅色、可滚动),令牌框用浅灰底 */
|
||
.token-box {
|
||
background: #f9fafb;
|
||
}
|
||
</style>
|