1021 lines
25 KiB
Vue
1021 lines
25 KiB
Vue
<template>
|
||
<view class="login-container" :style="bgStyle">
|
||
<view class="form_box">
|
||
<view class="header-section">
|
||
<text class="system-title">PDA仓库管理系统</text>
|
||
</view>
|
||
|
||
<view class="login-methods">
|
||
<!-- 账号密码登录 -->
|
||
<view class="method-card direct-login-card">
|
||
<view class="direct-login-form">
|
||
<u--input
|
||
v-model="loginForm.username"
|
||
placeholder="请输入账号"
|
||
inputAlign="center"
|
||
clearable
|
||
border="bottom"
|
||
:customStyle="{ marginBottom: '24rpx' }"
|
||
></u--input>
|
||
<view class="password-input-wrap">
|
||
<u--input
|
||
v-model="loginForm.password"
|
||
placeholder="请输入密码"
|
||
inputAlign="center"
|
||
:type="showPassword ? 'text' : 'password'"
|
||
@confirm="Login"
|
||
clearable
|
||
border="bottom"
|
||
:customStyle="{ marginBottom: '24rpx' }"
|
||
></u--input>
|
||
<u-icon
|
||
class="password-toggle-icon"
|
||
:name="showPassword ? 'eye' : 'eye-off-outline'"
|
||
size="32rpx"
|
||
color="#666"
|
||
@click="togglePasswordVisibility"
|
||
></u-icon>
|
||
</view>
|
||
<u-button
|
||
type="primary"
|
||
text="登录"
|
||
@click="Login"
|
||
></u-button>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 广播扫描登录 -->
|
||
<view class="method-card scan-login-card">
|
||
<view class="method-icon">
|
||
<u-icon name="scan" size="36rpx" color="#19be6b"></u-icon>
|
||
</view>
|
||
<text class="method-desc">PDA扫描工牌登录</text>
|
||
</view>
|
||
</view>
|
||
|
||
</view>
|
||
|
||
<view v-if="showUpdateDialog" class="update-mask">
|
||
<view class="update-dialog">
|
||
<view class="update-header">
|
||
<text class="update-title">发现新版本</text>
|
||
<text class="update-version">当前 {{ currentAppVersion || '--' }} → 最新 {{ updateInfo.version || '--' }}</text>
|
||
</view>
|
||
|
||
<view class="update-body">
|
||
<view class="update-row">
|
||
<text class="update-label">安装包</text>
|
||
<text class="update-value">{{ updateInfo.file || '未提供文件名' }}</text>
|
||
</view>
|
||
<view v-if="updateInfo.publishedAtUtc" class="update-row">
|
||
<text class="update-label">发布时间</text>
|
||
<text class="update-value">{{ formatUpdateTime(updateInfo.publishedAtUtc) }}</text>
|
||
</view>
|
||
<view class="update-tip-box">
|
||
<text class="update-tip">检测到新版本,确认后将开始下载安装包。</text>
|
||
<text class="update-tip">下载完成后会自动打开文件。</text>
|
||
</view>
|
||
|
||
<view v-if="isDownloadingUpdate" class="update-progress-section">
|
||
<view class="update-progress-head">
|
||
<text class="update-progress-text">正在下载更新</text>
|
||
<text class="update-progress-text">{{ updateDownloadProgress }}%</text>
|
||
</view>
|
||
<view class="update-progress-bar">
|
||
<view class="update-progress-inner" :style="{ width: updateDownloadProgress + '%' }"></view>
|
||
</view>
|
||
</view>
|
||
|
||
<text v-if="updateErrorMessage" class="update-error">{{ updateErrorMessage }}</text>
|
||
</view>
|
||
|
||
<view class="update-actions">
|
||
<u-button
|
||
v-if="!isDownloadingUpdate"
|
||
plain
|
||
text="暂不更新"
|
||
@click="closeUpdateDialog"
|
||
></u-button>
|
||
<u-button
|
||
type="primary"
|
||
:loading="isDownloadingUpdate"
|
||
:disabled="isDownloadingUpdate"
|
||
:text="isDownloadingUpdate ? '下载中...' : '立即更新'"
|
||
@click="confirmUpdateDownload"
|
||
></u-button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 消息提示 -->
|
||
<u-toast ref="uToast"></u-toast>
|
||
<u-notify ref="uNotify"></u-notify>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
setToken,
|
||
getToken
|
||
} from '@/core/utils/auth'
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
bgStyle: '',
|
||
updateLogSeq: 0,
|
||
currentAppVersion: '',
|
||
showUpdateDialog: false,
|
||
isCheckingUpdate: false,
|
||
isDownloadingUpdate: false,
|
||
updateDownloadProgress: 0,
|
||
updateErrorMessage: '',
|
||
hasCheckedUpdate: false,
|
||
updateTask: null,
|
||
updateInfo: {
|
||
version: '',
|
||
file: '',
|
||
url: '',
|
||
sha256: '',
|
||
publishedAtUtc: ''
|
||
},
|
||
showLoginConfirm: false,
|
||
showPassword: false,
|
||
scanning: false,
|
||
deviceCode: '',
|
||
scanUuid: '',
|
||
currentDevice: null,
|
||
qrCodeTimer: null,
|
||
scanTimer: null,
|
||
loginData: {
|
||
deviceId: '',
|
||
deviceName: '',
|
||
loginType: '' // qrcode, broadcast, manual
|
||
},
|
||
loginForm: {
|
||
username: '',
|
||
password: ''
|
||
},
|
||
}
|
||
},
|
||
onLoad() {
|
||
const storageBg = uni.getStorageSync("bg");
|
||
const bgUrl = storageBg || "/static/loginbg.jpg";
|
||
this.bgStyle = `--bg-url: url(${bgUrl})`;
|
||
this.logNonBuildInfo('登录页启动调试信息', {
|
||
nodeEnv: process.env.NODE_ENV,
|
||
platform: process.env.VUE_APP_PLATFORM || 'unknown'
|
||
});
|
||
this.scanning = true;
|
||
uni.hideTabBar();
|
||
this.$store.dispatch('broadcast/setCallbacks', {
|
||
onResult: this.handleBroadcastResult
|
||
});
|
||
this.$store.dispatch('broadcast/start');
|
||
this.updateLogSeq = 0;
|
||
this.logUpdateStep('onLoad -> 准备执行 checkForAppUpdate');
|
||
this.checkForAppUpdate();
|
||
},
|
||
onShow() {
|
||
this.scanning = true;
|
||
this.$store.dispatch('broadcast/resume');
|
||
},
|
||
onHide() {
|
||
this.$store.dispatch('broadcast/stop');
|
||
},
|
||
onUnload() {
|
||
this.$store.dispatch('broadcast/stop');
|
||
},
|
||
methods: {
|
||
logNonBuildInfo(message, payload) {
|
||
if (process.env.NODE_ENV === 'production') {
|
||
return;
|
||
}
|
||
if (typeof payload === 'undefined') {
|
||
console.log(`[non-build] ${message}`);
|
||
return;
|
||
}
|
||
console.log(`[non-build] ${message}`, payload);
|
||
},
|
||
logUpdateStep(step, payload) {
|
||
this.updateLogSeq += 1;
|
||
const seq = String(this.updateLogSeq).padStart(2, '0');
|
||
if (typeof payload === 'undefined') {
|
||
console.log(`[update][${seq}] ${step}`);
|
||
return;
|
||
}
|
||
console.log(`[update][${seq}] ${step}`, payload);
|
||
},
|
||
async checkForAppUpdate() {
|
||
this.logUpdateStep('checkForAppUpdate -> 开始执行');
|
||
if (this.hasCheckedUpdate || this.isCheckingUpdate) {
|
||
this.logUpdateStep('checkForAppUpdate -> 已检查过或正在检查,直接返回', {
|
||
hasCheckedUpdate: this.hasCheckedUpdate,
|
||
isCheckingUpdate: this.isCheckingUpdate
|
||
});
|
||
return;
|
||
}
|
||
|
||
if (typeof plus === 'undefined' || !plus.runtime) {
|
||
this.logUpdateStep('checkForAppUpdate -> 非 APP-PLUS 环境,跳过更新检查');
|
||
return;
|
||
}
|
||
|
||
this.hasCheckedUpdate = true;
|
||
this.isCheckingUpdate = true;
|
||
this.updateErrorMessage = '';
|
||
this.logUpdateStep('checkForAppUpdate -> 状态已置为检查中');
|
||
|
||
try {
|
||
this.logUpdateStep('checkForAppUpdate -> 并行获取当前版本和远端配置');
|
||
const [currentVersion, latestInfoRaw] = await Promise.all([
|
||
this.getCurrentAppVersion(),
|
||
this.fetchLatestVersionInfo()
|
||
]);
|
||
const latestInfo = this.normalizeLatestInfo(latestInfoRaw);
|
||
|
||
this.currentAppVersion = currentVersion;
|
||
this.logUpdateStep('checkForAppUpdate -> 已拿到版本信息', {
|
||
currentVersion,
|
||
latestVersion: latestInfo && latestInfo.version ? latestInfo.version : ''
|
||
});
|
||
this.logUpdateStep('checkForAppUpdate -> 标准化后的远端配置', latestInfo || {});
|
||
|
||
if (!latestInfo || !latestInfo.version || !latestInfo.url) {
|
||
this.logUpdateStep('checkForAppUpdate -> 远端配置缺少必要字段,结束', latestInfo || {});
|
||
return;
|
||
}
|
||
|
||
const isNewer = this.isVersionNewer(latestInfo.version, currentVersion);
|
||
this.logUpdateStep('checkForAppUpdate -> 版本比较完成', {
|
||
latestVersion: latestInfo.version,
|
||
currentVersion,
|
||
isNewer
|
||
});
|
||
|
||
if (!isNewer) {
|
||
this.logUpdateStep('checkForAppUpdate -> 远端版本不高于当前版本,不弹窗');
|
||
return;
|
||
}
|
||
|
||
this.updateInfo = {
|
||
version: String(latestInfo.version || '').trim(),
|
||
file: String(latestInfo.file || '').trim(),
|
||
url: String(latestInfo.url || '').trim(),
|
||
sha256: String(latestInfo.sha256 || '').trim(),
|
||
publishedAtUtc: String(latestInfo.publishedAtUtc || '').trim()
|
||
};
|
||
this.showUpdateDialog = true;
|
||
this.logUpdateStep('checkForAppUpdate -> 发现新版本,显示更新弹窗', this.updateInfo);
|
||
} catch (error) {
|
||
this.logUpdateStep('checkForAppUpdate -> 检查异常', error);
|
||
console.warn('[update] check failed:', error);
|
||
} finally {
|
||
this.isCheckingUpdate = false;
|
||
this.logUpdateStep('checkForAppUpdate -> 结束,isCheckingUpdate=false');
|
||
}
|
||
},
|
||
fetchLatestVersionInfo() {
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 发起请求', {
|
||
url: 'http://dl.wms.gztbyc.com/pda/latest.json'
|
||
});
|
||
return new Promise((resolve, reject) => {
|
||
uni.request({
|
||
url: 'http://dl.wms.gztbyc.com/pda/latest.json',
|
||
method: 'GET',
|
||
timeout: 10000,
|
||
success: (res) => {
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 请求成功', {
|
||
statusCode: res.statusCode
|
||
});
|
||
if (res.statusCode !== 200) {
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 状态码异常,reject', {
|
||
statusCode: res.statusCode
|
||
});
|
||
reject(new Error(`更新配置获取失败: ${res.statusCode}`));
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 配置解析成功', data || {});
|
||
resolve(data || {});
|
||
} catch (parseError) {
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 配置解析失败', parseError);
|
||
reject(parseError);
|
||
}
|
||
},
|
||
fail: (error) => {
|
||
this.logUpdateStep('fetchLatestVersionInfo -> 请求失败', error);
|
||
reject(error || new Error('更新配置获取失败'));
|
||
}
|
||
});
|
||
});
|
||
},
|
||
normalizeLatestInfo(raw) {
|
||
const source = raw && typeof raw === 'object' ? raw : {};
|
||
const version = String(source.version || source.versionName || source.appVersion || '').trim();
|
||
const url = String(
|
||
source.url ||
|
||
source.downloadUrl ||
|
||
source.apkUrl ||
|
||
source.download_url ||
|
||
''
|
||
).trim();
|
||
const file = String(source.file || source.fileName || source.apkName || source.name || '').trim();
|
||
|
||
return {
|
||
...source,
|
||
version,
|
||
url,
|
||
file,
|
||
sha256: String(source.sha256 || source.md5 || '').trim(),
|
||
publishedAtUtc: String(source.publishedAtUtc || source.publishedAt || source.releaseTime || '').trim()
|
||
};
|
||
},
|
||
getCurrentAppVersion() {
|
||
this.logUpdateStep('getCurrentAppVersion -> 开始读取当前版本');
|
||
return new Promise((resolve) => {
|
||
if (typeof plus === 'undefined' || !plus.runtime) {
|
||
this.logUpdateStep('getCurrentAppVersion -> 非 APP-PLUS,返回空版本');
|
||
resolve('');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
plus.runtime.getProperty(plus.runtime.appid, (info) => {
|
||
const version = String(info?.version || plus.runtime.version || '').trim();
|
||
this.logUpdateStep('getCurrentAppVersion -> 读取成功', {
|
||
version,
|
||
appid: plus.runtime.appid
|
||
});
|
||
resolve(version);
|
||
});
|
||
} catch (error) {
|
||
const fallbackVersion = String((typeof plus !== 'undefined' && plus.runtime && plus.runtime.version) || '').trim();
|
||
this.logUpdateStep('getCurrentAppVersion -> 读取异常,走兜底版本', {
|
||
fallbackVersion,
|
||
error
|
||
});
|
||
resolve(fallbackVersion);
|
||
}
|
||
});
|
||
},
|
||
isVersionNewer(latestVersion, currentVersion) {
|
||
const normalize = (version) => String(version || '')
|
||
.split('.')
|
||
.map(item => parseInt(item, 10) || 0);
|
||
|
||
const latest = normalize(latestVersion);
|
||
const current = normalize(currentVersion);
|
||
|
||
const maxLength = Math.max(latest.length, current.length);
|
||
for (let i = 0; i < maxLength; i++) {
|
||
const latestPart = latest[i] || 0;
|
||
const currentPart = current[i] || 0;
|
||
|
||
if (latestPart > currentPart) {
|
||
return true;
|
||
}
|
||
if (latestPart < currentPart) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
},
|
||
formatUpdateTime(value) {
|
||
if (!value) {
|
||
return '';
|
||
}
|
||
|
||
const date = new Date(value);
|
||
if (Number.isNaN(date.getTime())) {
|
||
return value;
|
||
}
|
||
|
||
const pad = (num) => String(num).padStart(2, '0');
|
||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||
},
|
||
closeUpdateDialog() {
|
||
if (this.isDownloadingUpdate) {
|
||
this.logUpdateStep('closeUpdateDialog -> 下载中,禁止关闭弹窗');
|
||
return;
|
||
}
|
||
|
||
this.showUpdateDialog = false;
|
||
this.updateErrorMessage = '';
|
||
this.logUpdateStep('closeUpdateDialog -> 用户取消更新,弹窗关闭');
|
||
},
|
||
confirmUpdateDownload() {
|
||
if (this.isDownloadingUpdate) {
|
||
this.logUpdateStep('confirmUpdateDownload -> 已在下载中,忽略重复点击');
|
||
return;
|
||
}
|
||
|
||
this.logUpdateStep('confirmUpdateDownload -> 用户确认更新,准备下载');
|
||
this.startUpdateDownload();
|
||
},
|
||
startUpdateDownload() {
|
||
this.logUpdateStep('startUpdateDownload -> 开始下载流程', {
|
||
url: this.updateInfo.url,
|
||
file: this.updateInfo.file
|
||
});
|
||
if (!this.updateInfo.url) {
|
||
this.updateErrorMessage = '未获取到下载地址';
|
||
this.logUpdateStep('startUpdateDownload -> 缺少下载地址,终止');
|
||
return;
|
||
}
|
||
|
||
this.isDownloadingUpdate = true;
|
||
this.updateDownloadProgress = 0;
|
||
this.updateErrorMessage = '';
|
||
|
||
const downloadTask = uni.downloadFile({
|
||
url: this.updateInfo.url,
|
||
success: (res) => {
|
||
this.updateTask = null;
|
||
this.logUpdateStep('startUpdateDownload -> 下载完成回调', {
|
||
statusCode: res.statusCode,
|
||
tempFilePath: res.tempFilePath
|
||
});
|
||
if (res.statusCode !== 200 || !res.tempFilePath) {
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = '安装包下载失败';
|
||
this.logUpdateStep('startUpdateDownload -> 下载结果无效,终止');
|
||
return;
|
||
}
|
||
|
||
this.updateDownloadProgress = 100;
|
||
this.logUpdateStep('startUpdateDownload -> 下载成功,准备打开文件');
|
||
this.openDownloadedFile(res.tempFilePath);
|
||
},
|
||
fail: (error) => {
|
||
this.updateTask = null;
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = error?.errMsg || '安装包下载失败';
|
||
this.logUpdateStep('startUpdateDownload -> 下载失败', error);
|
||
}
|
||
});
|
||
|
||
this.updateTask = downloadTask;
|
||
this.logUpdateStep('startUpdateDownload -> downloadTask 已创建');
|
||
|
||
if (downloadTask && typeof downloadTask.onProgressUpdate === 'function') {
|
||
downloadTask.onProgressUpdate((progressEvent) => {
|
||
this.updateDownloadProgress = Number(progressEvent.progress || 0);
|
||
this.logUpdateStep('startUpdateDownload -> 下载进度', {
|
||
progress: this.updateDownloadProgress,
|
||
totalBytesWritten: progressEvent.totalBytesWritten,
|
||
totalBytesExpectedToWrite: progressEvent.totalBytesExpectedToWrite
|
||
});
|
||
});
|
||
} else {
|
||
this.logUpdateStep('startUpdateDownload -> 当前环境不支持进度回调');
|
||
}
|
||
},
|
||
openDownloadedFile(filePath) {
|
||
this.logUpdateStep('openDownloadedFile -> 尝试打开下载文件', {
|
||
filePath
|
||
});
|
||
if (typeof plus === 'undefined' || !plus.runtime || typeof plus.runtime.openFile !== 'function') {
|
||
this.updateTask = null;
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = '当前环境不支持打开安装包';
|
||
this.logUpdateStep('openDownloadedFile -> 环境不支持 plus.runtime.openFile');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
plus.runtime.openFile(filePath, {}, () => {
|
||
this.updateTask = null;
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = '';
|
||
this.showUpdateDialog = false;
|
||
this.logUpdateStep('openDownloadedFile -> 文件打开成功,更新流程完成');
|
||
}, (error) => {
|
||
this.updateTask = null;
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = error?.message || '文件已下载,但打开失败';
|
||
this.logUpdateStep('openDownloadedFile -> 文件打开失败', error);
|
||
});
|
||
} catch (error) {
|
||
this.updateTask = null;
|
||
this.isDownloadingUpdate = false;
|
||
this.updateErrorMessage = error?.message || '文件已下载,但打开失败';
|
||
this.logUpdateStep('openDownloadedFile -> 调用异常', error);
|
||
}
|
||
},
|
||
togglePasswordVisibility() {
|
||
this.showPassword = !this.showPassword;
|
||
},
|
||
decodeBase64Text(value) {
|
||
if (!value) return '';
|
||
if (typeof atob !== 'function') return '';
|
||
const normalized = String(value).replace(/-/g, '+').replace(/_/g, '/');
|
||
const binary = atob(normalized);
|
||
try {
|
||
return decodeURIComponent(Array.prototype.map.call(binary, char => {
|
||
const code = char.charCodeAt(0).toString(16).padStart(2, '0');
|
||
return `%${code}`;
|
||
}).join(''));
|
||
} catch (e) {
|
||
return binary;
|
||
}
|
||
},
|
||
isBase64Text(value) {
|
||
if (!value) return false;
|
||
const text = String(value).trim().replace(/\s/g, '');
|
||
// 允许标准/URL安全Base64
|
||
return /^[A-Za-z0-9+/=_-]+$/.test(text) && text.length % 4 === 0;
|
||
},
|
||
parseScanCodeStrict(scanText) {
|
||
const raw = String(scanText || '').trim();
|
||
if (!raw) {
|
||
throw new Error('扫描内容为空');
|
||
}
|
||
|
||
if (!this.isBase64Text(raw)) {
|
||
throw new Error('扫描内容不是Base64');
|
||
}
|
||
|
||
const decoded = this.decodeBase64Text(raw);
|
||
if (!decoded) {
|
||
throw new Error('Base64反序列化失败');
|
||
}
|
||
|
||
let obj;
|
||
try {
|
||
obj = JSON.parse(decoded);
|
||
} catch (e) {
|
||
throw new Error('反序列化后不是JSON字符串');
|
||
}
|
||
|
||
const uuid = String(obj?.uuid || '').trim();
|
||
if (!uuid) {
|
||
throw new Error('JSON中缺少uuid键');
|
||
}
|
||
|
||
return uuid;
|
||
},
|
||
parseScanUuid(scanText) {
|
||
if (!scanText) {
|
||
return '';
|
||
}
|
||
|
||
const text = String(scanText).trim();
|
||
try {
|
||
const jsonObj = JSON.parse(text);
|
||
if (jsonObj && jsonObj.uuid) {
|
||
return String(jsonObj.uuid).trim();
|
||
}
|
||
} catch (e) {}
|
||
|
||
try {
|
||
const decoded = this.decodeBase64Text(text);
|
||
if (decoded) {
|
||
const decodedObj = JSON.parse(decoded);
|
||
if (decodedObj && decodedObj.uuid) {
|
||
return String(decodedObj.uuid).trim();
|
||
}
|
||
}
|
||
} catch (e) {}
|
||
|
||
return text;
|
||
},
|
||
extractToken(payload) {
|
||
if (!payload || typeof payload !== 'object') {
|
||
return '';
|
||
}
|
||
const keys = ['token', 'access_token', 'accessToken', 'jwt', 'jwtToken'];
|
||
for (let i = 0; i < keys.length; i++) {
|
||
const raw = payload[keys[i]];
|
||
if (raw) {
|
||
const text = String(raw).trim();
|
||
return text.startsWith('Bearer ') ? text.substring(7).trim() : text;
|
||
}
|
||
}
|
||
for (const key in payload) {
|
||
if (payload[key] && typeof payload[key] === 'object') {
|
||
const nestedToken = this.extractToken(payload[key]);
|
||
if (nestedToken) {
|
||
return nestedToken;
|
||
}
|
||
}
|
||
}
|
||
return '';
|
||
},
|
||
async loginByCode(uuid) {
|
||
const res = await this.$http('user.loginByCode', {
|
||
uuid: String(uuid).trim()
|
||
});
|
||
|
||
if (res?.flag === 'failure') {
|
||
throw new Error(res?.message || '工牌认证登录失败');
|
||
}
|
||
|
||
const token = this.extractToken(res);
|
||
if (token) {
|
||
setToken(token);
|
||
}
|
||
|
||
if (!getToken()) {
|
||
throw new Error('登录成功但未返回token');
|
||
}
|
||
},
|
||
async Login() {
|
||
try {
|
||
await this.$store.dispatch('login', this.loginForm)
|
||
uni.switchTab({ url: '/pages/index/index' })
|
||
} catch (error) {
|
||
uni.showToast({
|
||
title: error?.msg || error?.message || '登录失败',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
async confirmLogin() {
|
||
try {
|
||
const code = String(this.deviceCode || '').trim()
|
||
const uuid = String(this.scanUuid || this.parseScanUuid(code) || '').trim()
|
||
if (!code || !uuid) {
|
||
throw new Error('请先扫描有效工牌')
|
||
}
|
||
await this.$store.dispatch('loginByCode', { code })
|
||
uni.switchTab({ url: '/pages/index/index' })
|
||
} catch (error) {
|
||
this.scanning = true;
|
||
this.deviceCode = '';
|
||
this.scanUuid = '';
|
||
this.currentDevice = null;
|
||
this.$store.dispatch('broadcast/resume');
|
||
uni.showToast({
|
||
title: error?.msg || error?.message || '工牌认证登录失败',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
handleBroadcastResult(result) {
|
||
if (!this.scanning || !result || !result.data) return;
|
||
|
||
try {
|
||
const rawCode = String(result.data || '').trim(); // 扫描原文
|
||
const uuid = this.parseScanCodeStrict(rawCode); // 仅用于校验与展示
|
||
|
||
this.deviceCode = rawCode; // code = 扫描字符串
|
||
this.scanUuid = uuid;
|
||
this.currentDevice = {
|
||
deviceId: uuid,
|
||
deviceName: `工牌-${uuid}`
|
||
};
|
||
this.scanning = false;
|
||
|
||
uni.showToast({ title: '工牌扫描成功', icon: 'success' });
|
||
|
||
// 自动登录
|
||
this.confirmLogin();
|
||
} catch (e) {
|
||
this.scanning = true;
|
||
this.deviceCode = '';
|
||
this.scanUuid = '';
|
||
this.currentDevice = null;
|
||
this.$store.dispatch('broadcast/resume');
|
||
uni.showToast({ title: e?.message || '扫码数据不合法', icon: 'none' });
|
||
}
|
||
},
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.login-container {
|
||
width: 100vw;
|
||
height: 100vh;
|
||
margin: 0 auto;
|
||
background-image: var(--bg-url, url('@/static/loginbg.jpg'));
|
||
background-size: cover;
|
||
background-position: center;
|
||
background-repeat: no-repeat;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
position: relative;
|
||
flex-direction: row;
|
||
flex-wrap: wrap;
|
||
|
||
}
|
||
|
||
.form_box {
|
||
width: 80%;
|
||
margin: 0 auto;
|
||
background: rgba(255, 255, 255, 0.95);
|
||
border-radius: 20rpx;
|
||
padding: 60rpx 40rpx;
|
||
backdrop-filter: blur(10px);
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.update-mask {
|
||
position: fixed;
|
||
left: 0;
|
||
top: 0;
|
||
right: 0;
|
||
bottom: 0;
|
||
background: rgba(0, 0, 0, 0.48);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 9999;
|
||
padding: 32rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.update-dialog {
|
||
width: 100%;
|
||
max-width: 680rpx;
|
||
background: #fff;
|
||
border-radius: 24rpx;
|
||
padding: 36rpx;
|
||
box-sizing: border-box;
|
||
box-shadow: 0 24rpx 80rpx rgba(0, 0, 0, 0.18);
|
||
}
|
||
|
||
.update-header {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10rpx;
|
||
margin-bottom: 28rpx;
|
||
}
|
||
|
||
.update-title {
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #222;
|
||
}
|
||
|
||
.update-version {
|
||
font-size: 24rpx;
|
||
color: #5c6b77;
|
||
}
|
||
|
||
.update-body {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20rpx;
|
||
}
|
||
|
||
.update-row {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: flex-start;
|
||
gap: 20rpx;
|
||
}
|
||
|
||
.update-label {
|
||
font-size: 26rpx;
|
||
color: #86909c;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.update-value {
|
||
font-size: 26rpx;
|
||
color: #333;
|
||
text-align: right;
|
||
word-break: break-all;
|
||
}
|
||
|
||
.update-tip-box {
|
||
background: #f6f9ff;
|
||
border-radius: 16rpx;
|
||
padding: 24rpx;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 12rpx;
|
||
}
|
||
|
||
.update-tip {
|
||
font-size: 26rpx;
|
||
line-height: 1.6;
|
||
color: #4e5969;
|
||
}
|
||
|
||
.update-progress-section {
|
||
margin-top: 8rpx;
|
||
}
|
||
|
||
.update-progress-head {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 14rpx;
|
||
}
|
||
|
||
.update-progress-text {
|
||
font-size: 26rpx;
|
||
color: #333;
|
||
}
|
||
|
||
.update-progress-bar {
|
||
height: 18rpx;
|
||
background: #eef1f5;
|
||
border-radius: 999rpx;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.update-progress-inner {
|
||
height: 100%;
|
||
background: linear-gradient(90deg, #2979ff, #19be6b);
|
||
border-radius: 999rpx;
|
||
transition: width 0.2s ease;
|
||
}
|
||
|
||
.update-error {
|
||
font-size: 24rpx;
|
||
color: #fa3534;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.update-actions {
|
||
display: flex;
|
||
gap: 20rpx;
|
||
margin-top: 32rpx;
|
||
}
|
||
|
||
.update-actions :deep(.u-button) {
|
||
flex: 1;
|
||
}
|
||
|
||
.header-section {
|
||
text-align: left;
|
||
margin-bottom: 60rpx;
|
||
|
||
.system-title {
|
||
display: block;
|
||
text-align: center;
|
||
width: 100%;
|
||
font-size: 40rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-bottom: 20rpx;
|
||
}
|
||
}
|
||
|
||
.login-methods {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 30rpx;
|
||
}
|
||
|
||
.method-card {
|
||
background: #f8f9fa;
|
||
border-radius: 16rpx;
|
||
padding: 40rpx 30rpx;
|
||
text-align: center;
|
||
position: relative;
|
||
|
||
&:active {
|
||
background: #e9ecef;
|
||
}
|
||
|
||
.method-icon {
|
||
margin-bottom: 20rpx;
|
||
}
|
||
|
||
.method-title {
|
||
display: block;
|
||
font-size: 32rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
margin-bottom: 10rpx;
|
||
}
|
||
|
||
.method-desc {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: #666;
|
||
}
|
||
|
||
.scan-status {
|
||
margin-top: 20rpx;
|
||
}
|
||
}
|
||
|
||
.direct-login-card {
|
||
text-align: left;
|
||
|
||
.direct-login-form {
|
||
margin-top: 20rpx;
|
||
}
|
||
|
||
.password-input-wrap {
|
||
position: relative;
|
||
|
||
.password-toggle-icon {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 18rpx;
|
||
z-index: 2;
|
||
}
|
||
}
|
||
}
|
||
|
||
.scan-login-card {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
pointer-events: none;
|
||
background: transparent;
|
||
|
||
&:active {
|
||
background: transparent;
|
||
}
|
||
|
||
.method-icon {
|
||
margin-bottom: 0;
|
||
margin-right: 16rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.method-desc {
|
||
margin: 0;
|
||
}
|
||
}
|
||
|
||
.device-status {
|
||
margin-top: 40rpx;
|
||
|
||
.status-card {
|
||
background: #e7f3ff;
|
||
border-radius: 12rpx;
|
||
padding: 30rpx;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
|
||
.device-info {
|
||
flex: 1;
|
||
|
||
.device-name {
|
||
display: block;
|
||
font-size: 28rpx;
|
||
font-weight: 600;
|
||
color: #2979ff;
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.device-id {
|
||
display: block;
|
||
font-size: 24rpx;
|
||
color: #666;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 弹窗样式
|
||
.qr-popup, .input-popup {
|
||
width: 600rpx;
|
||
background: white;
|
||
border-radius: 20rpx;
|
||
padding: 40rpx;
|
||
|
||
.popup-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 40rpx;
|
||
|
||
.popup-title {
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
}
|
||
|
||
.qr-container {
|
||
text-align: center;
|
||
|
||
|
||
|
||
.qr-tip {
|
||
font-size: 26rpx;
|
||
color: #666;
|
||
}
|
||
}
|
||
|
||
.popup-footer {
|
||
text-align: center;
|
||
margin-top: 30rpx;
|
||
|
||
.refresh-text {
|
||
color: #2979ff;
|
||
font-size: 26rpx;
|
||
}
|
||
}
|
||
|
||
.input-container {
|
||
padding: 20rpx 0;
|
||
}
|
||
}
|
||
</style> |