feat: improve auth guard and manual scan flow
This commit is contained in:
parent
962d7157fc
commit
4ba720b4c7
@ -2,6 +2,8 @@
|
|||||||
"version" : "1.0",
|
"version" : "1.0",
|
||||||
"configurations" : [
|
"configurations" : [
|
||||||
{
|
{
|
||||||
|
"customPlaygroundType" : "local",
|
||||||
|
"packageName" : "com.gztbyc.pda_wms",
|
||||||
"playground" : "standard",
|
"playground" : "standard",
|
||||||
"type" : "uni-app:app-android"
|
"type" : "uni-app:app-android"
|
||||||
},
|
},
|
||||||
|
|||||||
3
androidPrivacy.json
Normal file
3
androidPrivacy.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"prompt" : "none"
|
||||||
|
}
|
||||||
@ -15,14 +15,16 @@ export default function http(
|
|||||||
) {
|
) {
|
||||||
let api = getApiPath(url);
|
let api = getApiPath(url);
|
||||||
console.log(api);
|
console.log(api);
|
||||||
|
const token = uni.getStorageSync('token');
|
||||||
|
if (api.auth && !token) {
|
||||||
|
store.dispatch('logout');
|
||||||
|
uni.hideLoading();
|
||||||
|
return Promise.reject({
|
||||||
|
msg: `暂未登录,已阻止此次API请求: '${api.url}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
/* 请求之前拦截器 */
|
/* 请求之前拦截器 */
|
||||||
Request.interceptor.request((config, cancel) => {
|
Request.interceptor.request((config, cancel) => {
|
||||||
let token = uni.getStorageSync('token');
|
|
||||||
if (api.auth && !token) {
|
|
||||||
store.dispatch('logout');
|
|
||||||
uni.hideLoading()
|
|
||||||
throw (`暂未登录,已阻止此次API请求: '${api.url}'`);
|
|
||||||
}
|
|
||||||
token && Request.setConfig(config => {
|
token && Request.setConfig(config => {
|
||||||
config.header.authorization = `Bearer ${token}`
|
config.header.authorization = `Bearer ${token}`
|
||||||
})
|
})
|
||||||
|
|||||||
@ -72,18 +72,27 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
const hasGetUserInfo = store.getters.user.employees_name;
|
const hasGetUserInfo = store.getters.user.employees_name;
|
||||||
console.log("有没有用户信息",hasGetUserInfo);
|
console.log("有没有用户信息",hasGetUserInfo);
|
||||||
if (hasGetUserInfo) {
|
if (hasGetUserInfo) {
|
||||||
const isVisible =await store.dispatch('floatWindowManager/is_visible');
|
try {
|
||||||
if(to.meta && to.meta.auth){
|
store.dispatch('floatWindowManager/is_visible').catch(error => {
|
||||||
console.log(to.path);
|
console.log('浮窗显示检查失败:', error);
|
||||||
const hasPermiss =await store.dispatch('checkPath',to.path);
|
});
|
||||||
if(!hasPermiss){
|
if(to.meta && to.meta.auth){
|
||||||
next({path:"/pages/403"})
|
console.log(to.path);
|
||||||
return;
|
const hasPermiss =await store.dispatch('checkPath',to.path);
|
||||||
|
if(!hasPermiss){
|
||||||
|
next({path:"/pages/403"})
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if(to.path==from.path){
|
||||||
if(to.path==from.path){
|
console.log('路由重复,取消跳转:', to.path);
|
||||||
next(false);
|
next(false);
|
||||||
}else{
|
}else{
|
||||||
|
console.log('路由放行:', from.path, '->', to.path);
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('已登录分支路由守卫异常:', error);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,10 +101,14 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
try {
|
try {
|
||||||
await store.dispatch('getUserInfo');
|
await store.dispatch('getUserInfo');
|
||||||
console.log("获取完成,去哪里",to)
|
console.log("获取完成,去哪里",to)
|
||||||
await store.dispatch('floatWindowManager/is_visible');
|
store.dispatch('floatWindowManager/is_visible').catch(error => {
|
||||||
|
console.log('浮窗显示检查失败:', error);
|
||||||
|
});
|
||||||
if (to.path === '/pages/index/index') {
|
if (to.path === '/pages/index/index') {
|
||||||
|
console.log('路由放行:', from.path, '->', to.path);
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
|
console.log('路由重定向:', from.path, '->', to.fullPath);
|
||||||
next({
|
next({
|
||||||
path: to.fullPath,
|
path: to.fullPath,
|
||||||
NAVTYPE: 'SwitchTab'
|
NAVTYPE: 'SwitchTab'
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import {
|
|||||||
removeToken
|
removeToken
|
||||||
} from '@/core/utils/auth'
|
} from '@/core/utils/auth'
|
||||||
import { router } from '../../router'
|
import { router } from '../../router'
|
||||||
import { goLogin } from '@/core/utils/auth-guard'
|
import { clearSession, goLogin } from '@/core/utils/auth-guard'
|
||||||
|
|
||||||
const normalizeMenus = (user = {}) => {
|
const normalizeMenus = (user = {}) => {
|
||||||
const sourceMenus = Array.isArray(user.menus)
|
const sourceMenus = Array.isArray(user.menus)
|
||||||
@ -135,10 +135,7 @@ const actions = {
|
|||||||
commit,
|
commit,
|
||||||
dispatch
|
dispatch
|
||||||
}) {
|
}) {
|
||||||
removeToken()
|
clearSession(store)
|
||||||
commit('SET_PERMISSIONS', [])
|
|
||||||
commit('SET_USER', {})
|
|
||||||
commit('SET_ROLEID', 0)
|
|
||||||
return goLogin()
|
return goLogin()
|
||||||
},
|
},
|
||||||
checkPath({
|
checkPath({
|
||||||
|
|||||||
@ -22,6 +22,18 @@ export function clearSession(store) {
|
|||||||
removeToken()
|
removeToken()
|
||||||
if (!store) return
|
if (!store) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('token', '')
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('isLogin', false)
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('userInfo', {})
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
store.commit('SET_PERMISSIONS', [])
|
store.commit('SET_PERMISSIONS', [])
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@ -33,11 +45,33 @@ export function clearSession(store) {
|
|||||||
try {
|
try {
|
||||||
store.commit('SET_ROLEID', 0)
|
store.commit('SET_ROLEID', 0)
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('USER_DATA', {})
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('AGENT_INFO', {})
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('AUTH_TYPE', '')
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
store.commit('deviceInfo/CLEAR_DEVICE_INFO')
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigate(url, type) {
|
function navigate(url, type) {
|
||||||
const currentRoute = getCurrentRoute()
|
const currentRoute = getCurrentRoute()
|
||||||
if (redirecting || currentRoute === url) {
|
if (redirecting || currentRoute === url) {
|
||||||
|
console.log('[auth-guard] 跳转已忽略:', {
|
||||||
|
url,
|
||||||
|
type,
|
||||||
|
redirecting,
|
||||||
|
currentRoute
|
||||||
|
})
|
||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,17 +86,31 @@ function navigate(url, type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'switchTab') {
|
if (type === 'switchTab') {
|
||||||
|
console.log('[auth-guard] 开始跳转:', { url, type })
|
||||||
uni.switchTab({
|
uni.switchTab({
|
||||||
url,
|
url,
|
||||||
|
success: () => {
|
||||||
|
console.log('[auth-guard] 跳转成功:', { url, type })
|
||||||
|
},
|
||||||
|
fail: error => {
|
||||||
|
console.log('[auth-guard] 跳转失败:', { url, type, error })
|
||||||
|
},
|
||||||
complete: done
|
complete: done
|
||||||
})
|
}, true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('[auth-guard] 开始跳转:', { url, type })
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url,
|
url,
|
||||||
|
success: () => {
|
||||||
|
console.log('[auth-guard] 跳转成功:', { url, type })
|
||||||
|
},
|
||||||
|
fail: error => {
|
||||||
|
console.log('[auth-guard] 跳转失败:', { url, type, error })
|
||||||
|
},
|
||||||
complete: done
|
complete: done
|
||||||
})
|
}, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -94,6 +94,9 @@
|
|||||||
"spotlight@3x" : "unpackage/res/icons/120x120.png"
|
"spotlight@3x" : "unpackage/res/icons/120x120.png"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"splashscreen" : {
|
||||||
|
"useOriginalMsgbox" : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -45,11 +45,19 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 广播扫描登录 -->
|
<!-- 广播扫描登录 -->
|
||||||
<view class="method-card scan-login-card">
|
<view class="method-card scan-login-card" @click="handleManualScan">
|
||||||
<view class="method-icon">
|
<view class="method-icon">
|
||||||
<u-icon name="scan" size="36rpx" color="#19be6b"></u-icon>
|
<u-icon name="scan" size="36rpx" color="#19be6b"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
<text class="method-desc">PDA扫描工牌登录</text>
|
<view class="scan-login-content">
|
||||||
|
<text class="method-desc">PDA扫描工牌登录</text>
|
||||||
|
<u-button
|
||||||
|
type="success"
|
||||||
|
size="mini"
|
||||||
|
text="点击扫描工牌"
|
||||||
|
@click.stop="handleManualScan"
|
||||||
|
></u-button>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -532,31 +540,55 @@ export default {
|
|||||||
parseScanCodeStrict(scanText) {
|
parseScanCodeStrict(scanText) {
|
||||||
const raw = String(scanText || '').trim();
|
const raw = String(scanText || '').trim();
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
throw new Error('扫描内容为空');
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: '扫描内容为空',
|
||||||
|
uuid: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isBase64Text(raw)) {
|
if (!this.isBase64Text(raw)) {
|
||||||
throw new Error('扫描内容不是Base64');
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: '扫描内容不是Base64',
|
||||||
|
uuid: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const decoded = this.decodeBase64Text(raw);
|
const decoded = this.decodeBase64Text(raw);
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
throw new Error('Base64反序列化失败');
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: 'Base64反序列化失败',
|
||||||
|
uuid: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let obj;
|
let obj;
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(decoded);
|
obj = JSON.parse(decoded);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error('反序列化后不是JSON字符串');
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: '反序列化后不是JSON字符串',
|
||||||
|
uuid: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const uuid = String(obj?.uuid || '').trim();
|
const uuid = String(obj?.uuid || '').trim();
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
throw new Error('JSON中缺少uuid键');
|
return {
|
||||||
|
ok: false,
|
||||||
|
error: 'JSON中缺少uuid键',
|
||||||
|
uuid: ''
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return uuid;
|
return {
|
||||||
|
ok: true,
|
||||||
|
error: '',
|
||||||
|
uuid
|
||||||
|
};
|
||||||
},
|
},
|
||||||
parseScanUuid(scanText) {
|
parseScanUuid(scanText) {
|
||||||
if (!scanText) {
|
if (!scanText) {
|
||||||
@ -583,6 +615,67 @@ export default {
|
|||||||
|
|
||||||
return text;
|
return text;
|
||||||
},
|
},
|
||||||
|
normalizeUniScanResult(scanResult) {
|
||||||
|
if (!scanResult) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult === 'string') {
|
||||||
|
return scanResult.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.result === 'string') {
|
||||||
|
return scanResult.result.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(scanResult.result)) {
|
||||||
|
const firstResult = scanResult.result.find(item => item);
|
||||||
|
if (typeof firstResult === 'string') {
|
||||||
|
return firstResult.trim();
|
||||||
|
}
|
||||||
|
if (firstResult && typeof firstResult.data === 'string') {
|
||||||
|
return firstResult.data.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.data === 'string') {
|
||||||
|
return scanResult.data.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
handleManualScan() {
|
||||||
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||||||
|
success: (res) => {
|
||||||
|
const rawCode = this.normalizeUniScanResult(res);
|
||||||
|
if (!rawCode) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '未识别到有效内容',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleBroadcastResult({
|
||||||
|
data: rawCode,
|
||||||
|
source: 'uni.scanCode'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||||||
|
if (errMsg.includes('cancel')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '扫描失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
extractToken(payload) {
|
extractToken(payload) {
|
||||||
if (!payload || typeof payload !== 'object') {
|
if (!payload || typeof payload !== 'object') {
|
||||||
return '';
|
return '';
|
||||||
@ -658,9 +751,19 @@ export default {
|
|||||||
handleBroadcastResult(result) {
|
handleBroadcastResult(result) {
|
||||||
if (!this.scanning || !result || !result.data) return;
|
if (!this.scanning || !result || !result.data) return;
|
||||||
|
|
||||||
try {
|
const rawCode = String(result.data || '').trim(); // 扫描原文
|
||||||
const rawCode = String(result.data || '').trim(); // 扫描原文
|
const parsed = this.parseScanCodeStrict(rawCode); // 仅用于校验与展示
|
||||||
const uuid = this.parseScanCodeStrict(rawCode); // 仅用于校验与展示
|
if (!parsed.ok) {
|
||||||
|
this.scanning = true;
|
||||||
|
this.deviceCode = '';
|
||||||
|
this.scanUuid = '';
|
||||||
|
this.currentDevice = null;
|
||||||
|
this.$store.dispatch('broadcast/resume');
|
||||||
|
uni.showToast({ title: parsed.error || '扫码数据不合法', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uuid = parsed.uuid;
|
||||||
|
|
||||||
this.deviceCode = rawCode; // code = 扫描字符串
|
this.deviceCode = rawCode; // code = 扫描字符串
|
||||||
this.scanUuid = uuid;
|
this.scanUuid = uuid;
|
||||||
@ -674,14 +777,6 @@ export default {
|
|||||||
|
|
||||||
// 自动登录
|
// 自动登录
|
||||||
this.confirmLogin();
|
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' });
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -923,7 +1018,6 @@ export default {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
pointer-events: none;
|
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
@ -940,6 +1034,12 @@ export default {
|
|||||||
.method-desc {
|
.method-desc {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.scan-login-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.device-status {
|
.device-status {
|
||||||
|
|||||||
@ -113,6 +113,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
const BROADCAST_SETTINGS_DRAFT_KEY = 'broadcast_settings_draft';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -150,10 +152,12 @@
|
|||||||
this.setupScanCallback();
|
this.setupScanCallback();
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
|
this.persistDraft();
|
||||||
// 页面隐藏时不停止广播,保持后台运行
|
// 页面隐藏时不停止广播,保持后台运行
|
||||||
this.removeScanCallback();
|
this.removeScanCallback();
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
|
this.persistDraft();
|
||||||
this.removeScanCallback();
|
this.removeScanCallback();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -167,6 +171,42 @@
|
|||||||
const enabled = await this.$store.dispatch('setting/getValue', 'broadcast.enabled');
|
const enabled = await this.$store.dispatch('setting/getValue', 'broadcast.enabled');
|
||||||
console.log("enabled", enabled);
|
console.log("enabled", enabled);
|
||||||
this.broadcastEnabled = enabled !== 'false';
|
this.broadcastEnabled = enabled !== 'false';
|
||||||
|
this.restoreDraft();
|
||||||
|
},
|
||||||
|
|
||||||
|
persistDraft() {
|
||||||
|
uni.setStorageSync(BROADCAST_SETTINGS_DRAFT_KEY, {
|
||||||
|
newAction: this.newAction,
|
||||||
|
newKey: this.newKey,
|
||||||
|
canChanges: this.canChanges
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
restoreDraft() {
|
||||||
|
const draft = uni.getStorageSync(BROADCAST_SETTINGS_DRAFT_KEY);
|
||||||
|
if (!draft) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parsedDraft = draft;
|
||||||
|
if (typeof draft === 'string') {
|
||||||
|
try {
|
||||||
|
parsedDraft = JSON.parse(draft);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('解析广播设置草稿失败:', error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parsedDraft && parsedDraft.canChanges === false) {
|
||||||
|
this.newAction = parsedDraft.newAction || this.newAction;
|
||||||
|
this.newKey = parsedDraft.newKey || this.newKey;
|
||||||
|
this.canChanges = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
clearDraft() {
|
||||||
|
uni.removeStorageSync(BROADCAST_SETTINGS_DRAFT_KEY);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 检查广播状态
|
// 检查广播状态
|
||||||
@ -183,6 +223,7 @@
|
|||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
if (this.canChanges) {
|
if (this.canChanges) {
|
||||||
this.canChanges = false;
|
this.canChanges = false;
|
||||||
|
this.persistDraft();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +253,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
this.clearDraft();
|
||||||
// 3. 设置回调函数
|
// 3. 设置回调函数
|
||||||
this.setupScanCallback();
|
this.setupScanCallback();
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { goLogin, isLoginRoute, getCurrentRoute } from '@/core/utils/auth-guard'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -102,14 +104,14 @@
|
|||||||
methods: {
|
methods: {
|
||||||
// 加载用户信息
|
// 加载用户信息
|
||||||
loadUserInfo() {
|
loadUserInfo() {
|
||||||
const userData = this.$store.getters.user;
|
const token = uni.getStorageSync('token');
|
||||||
if (userData) {
|
const userData = this.$store.getters.user || {};
|
||||||
|
if (token && Object.keys(userData).length > 0) {
|
||||||
this.userInfo = userData;
|
this.userInfo = userData;
|
||||||
} else {
|
} else {
|
||||||
|
this.userInfo = {};
|
||||||
// 如果未登录,跳转到登录页
|
// 如果未登录,跳转到登录页
|
||||||
uni.reLaunch({
|
goLogin();
|
||||||
url: '/pages/login/login'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -182,6 +184,10 @@
|
|||||||
// 调用登出 action
|
// 调用登出 action
|
||||||
await this.$store.dispatch('logout');
|
await this.$store.dispatch('logout');
|
||||||
|
|
||||||
|
if (!isLoginRoute(getCurrentRoute())) {
|
||||||
|
await goLogin();
|
||||||
|
}
|
||||||
|
|
||||||
// 登出成功提示
|
// 登出成功提示
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '已退出登录',
|
title: '已退出登录',
|
||||||
|
|||||||
@ -33,6 +33,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { goLogin } from '@/core/utils/auth-guard'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -245,9 +247,7 @@
|
|||||||
title: '请先登录',
|
title: '请先登录',
|
||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
uni.navigateTo({
|
goLogin();
|
||||||
url: '/pages/login/login'
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,8 +4,13 @@
|
|||||||
<view class="detail-display" v-if="selectedDetail">
|
<view class="detail-display" v-if="selectedDetail">
|
||||||
<view class="detail-header">
|
<view class="detail-header">
|
||||||
<view class="search-box">
|
<view class="search-box">
|
||||||
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
|
<view class="search-box-inner">
|
||||||
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
|
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
|
||||||
|
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
|
||||||
|
<view class="scan-camera-btn" @click="handleManualScan">
|
||||||
|
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="detail-actions">
|
<view class="detail-actions">
|
||||||
@ -244,6 +249,67 @@
|
|||||||
printBarcode(data){
|
printBarcode(data){
|
||||||
this.$emit('print',data);
|
this.$emit('print',data);
|
||||||
},
|
},
|
||||||
|
normalizeUniScanResult(scanResult) {
|
||||||
|
if (!scanResult) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult === 'string') {
|
||||||
|
return scanResult.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.result === 'string') {
|
||||||
|
return scanResult.result.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(scanResult.result)) {
|
||||||
|
const firstResult = scanResult.result.find(item => item);
|
||||||
|
if (typeof firstResult === 'string') {
|
||||||
|
return firstResult.trim();
|
||||||
|
}
|
||||||
|
if (firstResult && typeof firstResult.data === 'string') {
|
||||||
|
return firstResult.data.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.data === 'string') {
|
||||||
|
return scanResult.data.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
handleManualScan() {
|
||||||
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||||||
|
success: (res) => {
|
||||||
|
const rawCode = this.normalizeUniScanResult(res);
|
||||||
|
if (!rawCode) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '未识别到有效内容',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scan({
|
||||||
|
data: rawCode,
|
||||||
|
source: 'uni.scanCode'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||||||
|
if (errMsg.includes('cancel')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '扫码失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
scan(data) {
|
scan(data) {
|
||||||
if(!data.data){
|
if(!data.data){
|
||||||
return;
|
return;
|
||||||
@ -290,6 +356,32 @@
|
|||||||
.search-box {
|
.search-box {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
margin-right: 20rpx;
|
margin-right: 20rpx;
|
||||||
|
|
||||||
|
.search-box-inner {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
|
||||||
|
::v-deep .u-search {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scan-camera-btn {
|
||||||
|
width: 76rpx;
|
||||||
|
height: 76rpx;
|
||||||
|
border-radius: 38rpx;
|
||||||
|
background: #eef4ff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-actions {
|
.detail-actions {
|
||||||
|
|||||||
@ -68,7 +68,7 @@
|
|||||||
</u-form-item>
|
</u-form-item>
|
||||||
|
|
||||||
<u-form-item label="创建时间">
|
<u-form-item label="创建时间">
|
||||||
<u-input v-model="receivingInfo.created_at" disabled />
|
<u-input :value="formatDate(receivingInfo.created_at)" disabled />
|
||||||
</u-form-item>
|
</u-form-item>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -166,6 +166,30 @@
|
|||||||
// 调用绘制方法将二维码图案绘制到canvas上
|
// 调用绘制方法将二维码图案绘制到canvas上
|
||||||
qr.drawCanvas();
|
qr.drawCanvas();
|
||||||
},
|
},
|
||||||
|
formatDate(dateStr) {
|
||||||
|
if (!dateStr) return '-';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const normalizedDateStr = typeof dateStr === 'string' ? dateStr.replace(/-/g, '/') : dateStr;
|
||||||
|
const date = new Date(normalizedDateStr);
|
||||||
|
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
const hour = String(date.getHours()).padStart(2, '0');
|
||||||
|
const minute = String(date.getMinutes()).padStart(2, '0');
|
||||||
|
const second = String(date.getSeconds()).padStart(2, '0');
|
||||||
|
|
||||||
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('日期格式化错误:', error);
|
||||||
|
return dateStr;
|
||||||
|
}
|
||||||
|
},
|
||||||
getStatusType(status) {
|
getStatusType(status) {
|
||||||
const map = {
|
const map = {
|
||||||
'receiving': 'primary',
|
'receiving': 'primary',
|
||||||
|
|||||||
@ -6,10 +6,16 @@
|
|||||||
<view class="search-filter">
|
<view class="search-filter">
|
||||||
<!-- 搜索框 -->
|
<!-- 搜索框 -->
|
||||||
<view class="search-box">
|
<view class="search-box">
|
||||||
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
|
<view class="search-box-inner">
|
||||||
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
|
<u-search v-model="searchKeyword" placeholder="搜索运单号、货主、商品条码、车牌" bg-color="#f5f5f5" shape="round"
|
||||||
|
:show-action="false" @search="handleSearch" @clear="handleSearch"></u-search>
|
||||||
|
<view class="scan-camera-btn" @click="handleManualScan">
|
||||||
|
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|
||||||
<!-- 筛选按钮 -->
|
<!-- 筛选按钮 -->
|
||||||
<view class="filter-actions">
|
<view class="filter-actions">
|
||||||
<view class="filter-buttons">
|
<view class="filter-buttons">
|
||||||
@ -323,6 +329,67 @@
|
|||||||
this.searchKeyword = data.data;
|
this.searchKeyword = data.data;
|
||||||
this.handleSearch();
|
this.handleSearch();
|
||||||
},
|
},
|
||||||
|
normalizeUniScanResult(scanResult) {
|
||||||
|
if (!scanResult) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult === 'string') {
|
||||||
|
return scanResult.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.result === 'string') {
|
||||||
|
return scanResult.result.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(scanResult.result)) {
|
||||||
|
const firstResult = scanResult.result.find(item => item);
|
||||||
|
if (typeof firstResult === 'string') {
|
||||||
|
return firstResult.trim();
|
||||||
|
}
|
||||||
|
if (firstResult && typeof firstResult.data === 'string') {
|
||||||
|
return firstResult.data.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof scanResult.data === 'string') {
|
||||||
|
return scanResult.data.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
handleManualScan() {
|
||||||
|
uni.scanCode({
|
||||||
|
onlyFromCamera: false,
|
||||||
|
scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
|
||||||
|
success: (res) => {
|
||||||
|
const rawCode = this.normalizeUniScanResult(res);
|
||||||
|
if (!rawCode) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '未识别到有效内容',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scan({
|
||||||
|
data: rawCode,
|
||||||
|
source: 'uni.scanCode'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
fail: (error) => {
|
||||||
|
const errMsg = String(error?.errMsg || '').toLowerCase();
|
||||||
|
if (errMsg.includes('cancel')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '扫码失败,请重试',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
async loadStore() {
|
async loadStore() {
|
||||||
try {
|
try {
|
||||||
@ -565,6 +632,32 @@
|
|||||||
|
|
||||||
.search-box {
|
.search-box {
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
|
|
||||||
|
.search-box-inner {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16rpx;
|
||||||
|
|
||||||
|
::v-deep .u-search {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scan-camera-btn {
|
||||||
|
width: 76rpx;
|
||||||
|
height: 76rpx;
|
||||||
|
border-radius: 38rpx;
|
||||||
|
background: #eef4ff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
flex-shrink: 0;
|
||||||
|
box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-actions {
|
.filter-actions {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user