新增打包模式、修改登录页面
This commit is contained in:
parent
23a746e26a
commit
7361f30c3c
@ -19,6 +19,34 @@ export function getLoginWechatCode(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台登录:获取工作台绑定码 / 绑定状态(免登录、免鉴权)
|
||||||
|
* - 不传 clientCode:分配新客户端编码并立即返回绑定码
|
||||||
|
* - 传入 clientCode:进入长轮询等待 workbench.bind,绑定成功返回 token;
|
||||||
|
* 等待超时/缓存失效时服务端会重新生成绑定码后才返回
|
||||||
|
*/
|
||||||
|
export function getWorkbenchBindCode(
|
||||||
|
data: Record<string, unknown> = {},
|
||||||
|
options?: RequestOptions
|
||||||
|
) {
|
||||||
|
return request<ApiBody>('index.getWorkbenchBindCode', data, {
|
||||||
|
skipAuth: true,
|
||||||
|
...options,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工作台信息:使用工作台 token 获取工作台信息(免登录、免鉴权)
|
||||||
|
* - 需传工作台 token(64 位);token 不存在或无对应工作台时返回失败(flag=failure、code=403)
|
||||||
|
*/
|
||||||
|
export function getWorkbenchInfo(token: string) {
|
||||||
|
return request<ApiBody>(
|
||||||
|
'workbench.getWorkbenchInfo',
|
||||||
|
{ token },
|
||||||
|
{ skipAuth: true }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/** 工牌 / 条码码登录 */
|
/** 工牌 / 条码码登录 */
|
||||||
export function loginByCode(code: string) {
|
export function loginByCode(code: string) {
|
||||||
return request<ApiBody>('user.loginByCode', { code }, { skipAuth: true })
|
return request<ApiBody>('user.loginByCode', { code }, { skipAuth: true })
|
||||||
|
|||||||
@ -32,6 +32,13 @@
|
|||||||
"titleNView": false,
|
"titleNView": false,
|
||||||
"navigationBarTitleText": "退件"
|
"navigationBarTitleText": "退件"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/packaging/index",
|
||||||
|
"style": {
|
||||||
|
"titleNView": false,
|
||||||
|
"navigationBarTitleText": "打包模式"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
|
|||||||
@ -20,6 +20,12 @@
|
|||||||
<view :class="['tab-item', loginMode === 'scan' ? 'tab-item--active' : '']" @click="switchMode('scan')">
|
<view :class="['tab-item', loginMode === 'scan' ? 'tab-item--active' : '']" @click="switchMode('scan')">
|
||||||
扫码登录
|
扫码登录
|
||||||
</view>
|
</view>
|
||||||
|
<view
|
||||||
|
:class="['tab-item', loginMode === 'workbench' ? 'tab-item--active' : '']"
|
||||||
|
@click="switchMode('workbench')"
|
||||||
|
>
|
||||||
|
工作台
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="panel-stage">
|
<view class="panel-stage">
|
||||||
@ -72,6 +78,42 @@
|
|||||||
</view>
|
</view>
|
||||||
<button class="primary-btn" type="primary" @click="handleAccountLogin">登录</button>
|
<button class="primary-btn" type="primary" @click="handleAccountLogin">登录</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view v-show="loginMode === 'workbench'" class="panel panel--workbench panel--mode">
|
||||||
|
<block v-if="hasStoredWorkbench">
|
||||||
|
<text class="wb-tip-top">本机已保存工作台绑定,可直接进入打包模式</text>
|
||||||
|
<view class="wb-quick-box">
|
||||||
|
<text class="wb-quick-title">工作台会话</text>
|
||||||
|
<text class="wb-quick-desc">退出后仍可一键恢复进入,无需重新绑定</text>
|
||||||
|
</view>
|
||||||
|
<button class="primary-btn wb-enter-btn" type="primary" @click="enterStoredWorkbench">
|
||||||
|
进入打包模式
|
||||||
|
</button>
|
||||||
|
<view class="wb-rebind-link" @click="chooseRebindWorkbench">
|
||||||
|
<text>重新绑定其他工作台</text>
|
||||||
|
</view>
|
||||||
|
</block>
|
||||||
|
<block v-else>
|
||||||
|
<text class="wb-tip-top">在已登录的工作台管理端扫描二维码或输入绑定码,即可完成本机与工作台的绑定登录</text>
|
||||||
|
<view class="wb-code-box">
|
||||||
|
<image
|
||||||
|
v-if="workbenchQrImage"
|
||||||
|
class="wb-qr-image"
|
||||||
|
:src="workbenchQrImage"
|
||||||
|
mode="aspectFit"
|
||||||
|
@error="handleWorkbenchQrError"
|
||||||
|
></image>
|
||||||
|
<text v-else-if="workbenchBindCode" class="wb-code">{{ workbenchBindCode }}</text>
|
||||||
|
<text v-else class="wb-code-placeholder">绑定码生成中...</text>
|
||||||
|
</view>
|
||||||
|
<text v-if="workbenchBindCode" class="wb-code-text">绑定码:{{ workbenchBindCode }}</text>
|
||||||
|
<text class="wb-tip-bottom">{{ workbenchStatus }}</text>
|
||||||
|
<text v-if="workbenchClientCode" class="wb-client-hint">客户端编码:{{ workbenchClientCode }}</text>
|
||||||
|
<button class="wb-refresh-btn" :disabled="workbenchLoading" @click="handleWorkbenchRefresh">
|
||||||
|
刷新绑定码
|
||||||
|
</button>
|
||||||
|
</block>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -92,7 +134,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getLoginWechatCode, loginByCode, loginByAccount } from '@/api/index'
|
import { getLoginWechatCode, loginByCode, loginByAccount, getWorkbenchBindCode } from '@/api/index'
|
||||||
|
|
||||||
const qrBaseUrl = 'https://ye4s.wms.gztbyc.com/grcode/build?text='
|
const qrBaseUrl = 'https://ye4s.wms.gztbyc.com/grcode/build?text='
|
||||||
const qrFallbackBaseUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=280x280&data='
|
const qrFallbackBaseUrl = 'https://api.qrserver.com/v1/create-qr-code/?size=280x280&data='
|
||||||
@ -140,11 +182,22 @@ export default {
|
|||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
},
|
},
|
||||||
|
workbenchLoading: false,
|
||||||
|
workbenchLoggedIn: false,
|
||||||
|
hasStoredWorkbench: false,
|
||||||
|
workbenchClientCode: '',
|
||||||
|
workbenchBindCode: '',
|
||||||
|
workbenchQrImage: '',
|
||||||
|
workbenchStatus: '等待绑定...',
|
||||||
|
workbenchPollTimer: null,
|
||||||
|
workbenchPollInterval: 1500,
|
||||||
|
workbenchRequestTimeout: 120000,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
this.pageActive = false
|
this.pageActive = false
|
||||||
this.stopScanLongPolling()
|
this.stopScanLongPolling()
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
this.removePlusKeyboardListener()
|
this.removePlusKeyboardListener()
|
||||||
this.removeGlobalKeyboardListener()
|
this.removeGlobalKeyboardListener()
|
||||||
this.clearScanFocusResumeTimer()
|
this.clearScanFocusResumeTimer()
|
||||||
@ -154,6 +207,7 @@ export default {
|
|||||||
},
|
},
|
||||||
onReady() {
|
onReady() {
|
||||||
this.pageActive = true
|
this.pageActive = true
|
||||||
|
this.hasStoredWorkbench = !!uni.getStorageSync('workbench_token')
|
||||||
this.setupScanCaptureMode()
|
this.setupScanCaptureMode()
|
||||||
this.attachPlusKeyboardListener()
|
this.attachPlusKeyboardListener()
|
||||||
this.attachGlobalKeyboardListener()
|
this.attachGlobalKeyboardListener()
|
||||||
@ -167,9 +221,11 @@ export default {
|
|||||||
this.attachGlobalKeyboardListener()
|
this.attachGlobalKeyboardListener()
|
||||||
this.suppressSoftKeyboardBurst()
|
this.suppressSoftKeyboardBurst()
|
||||||
this.scheduleScanInputFocus(320)
|
this.scheduleScanInputFocus(320)
|
||||||
|
this.resumeWorkbenchFlow()
|
||||||
},
|
},
|
||||||
onHide() {
|
onHide() {
|
||||||
this.pageActive = false
|
this.pageActive = false
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
this.removePlusKeyboardListener()
|
this.removePlusKeyboardListener()
|
||||||
this.removeGlobalKeyboardListener()
|
this.removeGlobalKeyboardListener()
|
||||||
this.clearScanFocusResumeTimer()
|
this.clearScanFocusResumeTimer()
|
||||||
@ -199,6 +255,13 @@ export default {
|
|||||||
this.startScanLongPolling()
|
this.startScanLongPolling()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode !== 'workbench') {
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
}
|
||||||
|
if (mode === 'workbench') {
|
||||||
|
this.resumeWorkbenchFlow()
|
||||||
|
}
|
||||||
|
|
||||||
this.suppressSoftKeyboardBurst()
|
this.suppressSoftKeyboardBurst()
|
||||||
this.scheduleScanInputFocus(280)
|
this.scheduleScanInputFocus(280)
|
||||||
},
|
},
|
||||||
@ -784,6 +847,240 @@ export default {
|
|||||||
this.scanPollTimer = null
|
this.scanPollTimer = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
startWorkbenchLongPolling() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!this.workbenchClientCode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.workbenchPollTimer = setTimeout(() => {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.handleWorkbenchBind(true)
|
||||||
|
}, this.workbenchPollInterval)
|
||||||
|
},
|
||||||
|
stopWorkbenchLongPolling() {
|
||||||
|
if (this.workbenchPollTimer) {
|
||||||
|
clearTimeout(this.workbenchPollTimer)
|
||||||
|
this.workbenchPollTimer = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resumeWorkbenchFlow() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.loginMode !== 'workbench') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 已保存工作台会话:停在快捷进入/重新绑定选择页,不自动发起绑定
|
||||||
|
if (this.hasStoredWorkbench) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchLoggedIn) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchBindCode && this.workbenchClientCode) {
|
||||||
|
this.startWorkbenchLongPolling()
|
||||||
|
} else {
|
||||||
|
this.handleWorkbenchBind(false)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buildWorkbenchQrImageUrl(code) {
|
||||||
|
if (!code) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return `${qrBaseUrl}${encodeURIComponent(code)}`
|
||||||
|
},
|
||||||
|
buildFallbackWorkbenchQrImageUrl(code) {
|
||||||
|
if (!code) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return `${qrFallbackBaseUrl}${encodeURIComponent(code)}`
|
||||||
|
},
|
||||||
|
handleWorkbenchQrError() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const fallbackUrl = this.buildFallbackWorkbenchQrImageUrl(this.workbenchBindCode)
|
||||||
|
if (fallbackUrl && this.workbenchQrImage !== fallbackUrl) {
|
||||||
|
this.workbenchQrImage = fallbackUrl
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.workbenchQrImage = ''
|
||||||
|
this.workbenchStatus = '二维码加载失败,请使用下方绑定码'
|
||||||
|
},
|
||||||
|
handleWorkbenchRefresh() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 不传 clientCode:由服务端分配新客户端并立即返回新的绑定码(旧绑定码随即失效)
|
||||||
|
this.workbenchClientCode = ''
|
||||||
|
this.workbenchBindCode = ''
|
||||||
|
this.workbenchQrImage = ''
|
||||||
|
this.workbenchStatus = '正在刷新绑定码...'
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.handleWorkbenchBind(false)
|
||||||
|
},
|
||||||
|
handleWorkbenchBind(isPolling = false) {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (this.workbenchLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isPolling) {
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.workbenchStatus = this.workbenchBindCode ? '正在刷新绑定码...' : '正在获取绑定码...'
|
||||||
|
}
|
||||||
|
|
||||||
|
this.workbenchLoading = true
|
||||||
|
const requestData = this.workbenchClientCode ? { clientCode: this.workbenchClientCode } : {}
|
||||||
|
|
||||||
|
getWorkbenchBindCode(requestData, { timeout: this.workbenchRequestTimeout })
|
||||||
|
.then((body) => {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const payload = body?.data || body?.result || body
|
||||||
|
const clientCode =
|
||||||
|
payload?.client_code || payload?.clientCode || body?.client_code || body?.clientCode || ''
|
||||||
|
const bindCode = payload?.code || body?.code || ''
|
||||||
|
const status = payload?.status || body?.status || ''
|
||||||
|
const token = payload?.token || body?.token || ''
|
||||||
|
const workbenchId =
|
||||||
|
payload?.workbench_id ?? payload?.workbenchId ?? body?.workbench_id ?? body?.workbenchId ?? null
|
||||||
|
|
||||||
|
if (clientCode) {
|
||||||
|
this.workbenchClientCode = clientCode
|
||||||
|
}
|
||||||
|
if (bindCode) {
|
||||||
|
this.workbenchBindCode = bindCode
|
||||||
|
this.workbenchQrImage = this.buildWorkbenchQrImageUrl(bindCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'bound' && token) {
|
||||||
|
this.finishWorkbenchLogin(token, workbenchId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.workbenchStatus = bindCode
|
||||||
|
? '等待绑定...'
|
||||||
|
: body?.message || body?.msg || '绑定码获取失败'
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const errMsg = err?.errMsg || ''
|
||||||
|
if (errMsg.includes('timeout') || errMsg.includes('abort') || errMsg.includes('cancel')) {
|
||||||
|
this.workbenchStatus = this.workbenchBindCode ? '等待绑定...' : '请求超时,正在重试...'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.workbenchStatus = '网络异常,请稍后重试'
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.workbenchLoading = false
|
||||||
|
if (
|
||||||
|
this.isPageActive() &&
|
||||||
|
this.loginMode === 'workbench' &&
|
||||||
|
this.workbenchClientCode &&
|
||||||
|
!this.workbenchLoggedIn
|
||||||
|
) {
|
||||||
|
this.startWorkbenchLongPolling()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
finishWorkbenchLogin(token, workbenchId) {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.workbenchLoggedIn = true
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.workbenchStatus = '绑定成功,正在登录...'
|
||||||
|
|
||||||
|
this.scanInputFocus = false
|
||||||
|
this.clearScanFocusResumeTimer()
|
||||||
|
this.clearHiddenRefocusTimer()
|
||||||
|
this.clearHiddenScanTimer()
|
||||||
|
this.suppressSoftKeyboardBurst()
|
||||||
|
uni.setStorageSync('token', token)
|
||||||
|
uni.setStorageSync('workbench_token', token)
|
||||||
|
if (workbenchId !== undefined && workbenchId !== null && workbenchId !== '') {
|
||||||
|
uni.setStorageSync('workbench_id', workbenchId)
|
||||||
|
}
|
||||||
|
uni.showToast({
|
||||||
|
title: '登录成功',
|
||||||
|
icon: 'success',
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/packaging/index',
|
||||||
|
})
|
||||||
|
}, 300)
|
||||||
|
},
|
||||||
|
enterStoredWorkbench() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const storedToken = uni.getStorageSync('workbench_token')
|
||||||
|
if (!storedToken) {
|
||||||
|
this.hasStoredWorkbench = false
|
||||||
|
this.chooseRebindWorkbench()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.workbenchLoggedIn = true
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.workbenchStatus = '正在进入打包模式...'
|
||||||
|
|
||||||
|
this.scanInputFocus = false
|
||||||
|
this.clearScanFocusResumeTimer()
|
||||||
|
this.clearHiddenRefocusTimer()
|
||||||
|
this.clearHiddenScanTimer()
|
||||||
|
this.suppressSoftKeyboardBurst()
|
||||||
|
uni.setStorageSync('token', storedToken)
|
||||||
|
uni.showToast({
|
||||||
|
title: '正在进入打包模式',
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/packaging/index',
|
||||||
|
})
|
||||||
|
}, 250)
|
||||||
|
},
|
||||||
|
chooseRebindWorkbench() {
|
||||||
|
if (!this.isPageActive()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 清除已保存会话,回到绑定码流程生成新绑定码
|
||||||
|
uni.removeStorageSync('workbench_token')
|
||||||
|
this.hasStoredWorkbench = false
|
||||||
|
this.stopWorkbenchLongPolling()
|
||||||
|
this.workbenchBindCode = ''
|
||||||
|
this.workbenchQrImage = ''
|
||||||
|
this.workbenchClientCode = ''
|
||||||
|
this.workbenchStatus = '正在获取绑定码...'
|
||||||
|
this.handleWorkbenchBind(false)
|
||||||
|
},
|
||||||
handleScanLogin(isPolling = false) {
|
handleScanLogin(isPolling = false) {
|
||||||
if (!this.isPageActive()) {
|
if (!this.isPageActive()) {
|
||||||
return
|
return
|
||||||
@ -1149,6 +1446,147 @@ export default {
|
|||||||
margin-top: 86rpx;
|
margin-top: 86rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.panel--workbench {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 40rpx 28rpx 36rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-tip-top {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 28rpx;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: #666;
|
||||||
|
margin-bottom: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-code-box {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 420rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 2rpx dashed #bcd7ff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
background: linear-gradient(135deg, #eef5ff, #f8fbff);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 20rpx;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-qr-image {
|
||||||
|
width: 280rpx;
|
||||||
|
height: 280rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-code-text {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 700;
|
||||||
|
letter-spacing: 6rpx;
|
||||||
|
text-indent: 6rpx;
|
||||||
|
color: #1f5fd6;
|
||||||
|
font-family: 'Courier New', Consolas, monospace;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-code {
|
||||||
|
font-size: 72rpx;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: 16rpx;
|
||||||
|
text-indent: 16rpx;
|
||||||
|
color: #1f5fd6;
|
||||||
|
font-family: 'Courier New', Consolas, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-code-placeholder {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #9aa7bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-tip-bottom {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #2fbf71;
|
||||||
|
margin-bottom: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-client-hint {
|
||||||
|
display: block;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #b0b8c6;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-refresh-btn {
|
||||||
|
width: 240rpx;
|
||||||
|
height: 72rpx;
|
||||||
|
line-height: 72rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #007aff;
|
||||||
|
background-color: #eef5ff;
|
||||||
|
border: 1rpx solid #bcd7ff;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-refresh-btn::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-refresh-btn[disabled] {
|
||||||
|
color: #a9b4c6;
|
||||||
|
background-color: #f2f3f5;
|
||||||
|
border-color: #e5e5e5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-quick-box {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1rpx solid #e5e5e5;
|
||||||
|
border-radius: 12rpx;
|
||||||
|
background-color: #fafbfc;
|
||||||
|
padding: 28rpx;
|
||||||
|
margin-bottom: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-quick-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-quick-desc {
|
||||||
|
display: block;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #999;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-enter-btn {
|
||||||
|
margin-top: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wb-rebind-link {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
padding: 24rpx 0 0;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #2f7dff;
|
||||||
|
}
|
||||||
|
|
||||||
.scan-box {
|
.scan-box {
|
||||||
width: 320rpx;
|
width: 320rpx;
|
||||||
height: 320rpx;
|
height: 320rpx;
|
||||||
|
|||||||
373
src/pages/packaging/index.vue
Normal file
373
src/pages/packaging/index.vue
Normal file
@ -0,0 +1,373 @@
|
|||||||
|
<template>
|
||||||
|
<view class="page">
|
||||||
|
<view class="mode-topbar">
|
||||||
|
<text class="mode-title">打包模式</text>
|
||||||
|
<button class="logout-btn" type="warn" @click="handleLogout">退出登录</button>
|
||||||
|
</view>
|
||||||
|
<view class="mode-main">
|
||||||
|
<view v-if="infoLoading" class="mode-card mode-card--center">
|
||||||
|
<text class="mode-card-desc">正在获取工作台信息...</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-else-if="workbenchInfo" class="info-stack">
|
||||||
|
<view class="mode-card mode-card--info">
|
||||||
|
<view class="info-head">
|
||||||
|
<text class="info-name">{{ workbenchInfo.name || '未命名工作台' }}</text>
|
||||||
|
<view class="mode-tags">
|
||||||
|
<text class="mode-tag">{{ workbenchTypeText }}</text>
|
||||||
|
<text
|
||||||
|
class="mode-tag"
|
||||||
|
:class="workbenchEnabled ? 'mode-tag--on' : 'mode-tag--off'"
|
||||||
|
>{{ workbenchStatusText }}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="mode-card mode-card--desc">
|
||||||
|
<text class="mode-card-desc">当前为工作台打包模式(页面占位,待对接打包业务接口)</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view v-else class="mode-card mode-card--center">
|
||||||
|
<text class="mode-card-desc">{{ infoError || '工作台信息加载失败' }}</text>
|
||||||
|
<button v-if="infoError" class="retry-btn" @click="loadWorkbenchInfo">重试</button>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { getWorkbenchInfo, logout } from '@/api/index'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PackagingPage',
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
workbenchInfo: null,
|
||||||
|
infoLoading: false,
|
||||||
|
infoError: '',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
workbenchTypeText() {
|
||||||
|
const type = this.workbenchInfo?.type
|
||||||
|
if (type === 'group') {
|
||||||
|
return '团体工作台'
|
||||||
|
}
|
||||||
|
if (type === 'personal') {
|
||||||
|
return '个人工作台'
|
||||||
|
}
|
||||||
|
return type ? String(type) : '未知类型'
|
||||||
|
},
|
||||||
|
workbenchStatusText() {
|
||||||
|
const status = Number(this.workbenchInfo?.status)
|
||||||
|
if (status === 1) {
|
||||||
|
return '启用'
|
||||||
|
}
|
||||||
|
if (status === 0) {
|
||||||
|
return '禁用'
|
||||||
|
}
|
||||||
|
return this.workbenchInfo?.status !== undefined && this.workbenchInfo?.status !== ''
|
||||||
|
? '未知'
|
||||||
|
: '—'
|
||||||
|
},
|
||||||
|
workbenchEnabled() {
|
||||||
|
return Number(this.workbenchInfo?.status) === 1
|
||||||
|
},
|
||||||
|
},
|
||||||
|
onLoad() {
|
||||||
|
// 简单守卫:无 token 时回到登录页
|
||||||
|
if (!uni.getStorageSync('token')) {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/login/login',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loadWorkbenchInfo()
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
pickInfoField(raw, body, keys) {
|
||||||
|
const sources = [raw, body]
|
||||||
|
for (const src of sources) {
|
||||||
|
if (!src || typeof src !== 'object') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for (const key of keys) {
|
||||||
|
const value = src[key]
|
||||||
|
if (value !== undefined && value !== null && value !== '') {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
},
|
||||||
|
loadWorkbenchInfo() {
|
||||||
|
if (this.infoLoading) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const token = uni.getStorageSync('token')
|
||||||
|
if (!token) {
|
||||||
|
this.exitToLogin('登录状态已失效,请重新登录')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.infoLoading = true
|
||||||
|
this.infoError = ''
|
||||||
|
getWorkbenchInfo(String(token))
|
||||||
|
.then((body) => {
|
||||||
|
const payload = body?.data || body?.result || body
|
||||||
|
const raw =
|
||||||
|
payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : null
|
||||||
|
const flag = body?.flag || raw?.flag || ''
|
||||||
|
const bizCode = body?.code ?? raw?.code ?? null
|
||||||
|
if (flag === 'failure' || Number(bizCode) === 403) {
|
||||||
|
this.workbenchInfo = null
|
||||||
|
this.infoError = '工作台不存在或 token 无效'
|
||||||
|
// token 已失效:清除本地保存的工作台会话,回到登录页重新绑定
|
||||||
|
this.exitToLogin(this.infoError, { clearStored: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const info = {
|
||||||
|
id: this.pickInfoField(raw, body, ['id']),
|
||||||
|
warehouseId: this.pickInfoField(raw, body, ['warehouse_id', 'warehouseId']),
|
||||||
|
name: this.pickInfoField(raw, body, ['name']),
|
||||||
|
status: this.pickInfoField(raw, body, ['status']),
|
||||||
|
type: this.pickInfoField(raw, body, ['type']),
|
||||||
|
remark: this.pickInfoField(raw, body, ['remark']),
|
||||||
|
deviceIds: this.pickInfoField(raw, body, ['device_ids', 'deviceIds']),
|
||||||
|
createdAt: this.pickInfoField(raw, body, ['created_at', 'createdAt']),
|
||||||
|
updatedAt: this.pickInfoField(raw, body, ['updated_at', 'updatedAt']),
|
||||||
|
}
|
||||||
|
if (!Array.isArray(info.deviceIds)) {
|
||||||
|
info.deviceIds = []
|
||||||
|
}
|
||||||
|
if (!info.id && !info.name) {
|
||||||
|
this.workbenchInfo = null
|
||||||
|
this.infoError = '未获取到工作台信息'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.workbenchInfo = info
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.workbenchInfo = null
|
||||||
|
this.infoError = '网络异常,请稍后重试'
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.infoLoading = false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
exitToLogin(message, options = {}) {
|
||||||
|
const { clearStored = false } = options
|
||||||
|
if (message) {
|
||||||
|
uni.showToast({
|
||||||
|
title: message,
|
||||||
|
icon: 'none',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
uni.removeStorageSync('token')
|
||||||
|
// 主动退出默认保留 workbench_token,登录页工作台 Tab 可一键再次进入打包模式
|
||||||
|
if (clearStored) {
|
||||||
|
uni.removeStorageSync('workbench_token')
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.reLaunch({
|
||||||
|
url: '/pages/login/login',
|
||||||
|
})
|
||||||
|
}, 400)
|
||||||
|
},
|
||||||
|
finishLogout() {
|
||||||
|
this.exitToLogin('已退出登录')
|
||||||
|
},
|
||||||
|
handleLogout() {
|
||||||
|
const token = uni.getStorageSync('token')
|
||||||
|
if (!token) {
|
||||||
|
this.finishLogout()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logout().finally(() => {
|
||||||
|
this.finishLogout()
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.page {
|
||||||
|
min-height: 100vh;
|
||||||
|
min-width: 960px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: flex-start;
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-topbar {
|
||||||
|
background-color: #2f7dff;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 20rpx 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-title {
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn {
|
||||||
|
width: 160rpx;
|
||||||
|
height: 60rpx;
|
||||||
|
line-height: 60rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logout-btn::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-main {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 40rpx;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card {
|
||||||
|
background-color: #fff;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 56rpx 40rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card-title {
|
||||||
|
display: block;
|
||||||
|
font-size: 34rpx;
|
||||||
|
color: #333;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card-desc {
|
||||||
|
display: block;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #888;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card--center {
|
||||||
|
text-align: center;
|
||||||
|
padding: 48rpx 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card--info {
|
||||||
|
text-align: left;
|
||||||
|
padding: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-card--desc {
|
||||||
|
margin-top: 24rpx;
|
||||||
|
padding: 32rpx 40rpx;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-stack {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-head {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-name {
|
||||||
|
display: block;
|
||||||
|
font-size: 38rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-tags {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-tag {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 6rpx 20rpx;
|
||||||
|
border-radius: 999rpx;
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #2f7dff;
|
||||||
|
background-color: #eef5ff;
|
||||||
|
margin: 0 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-tag--on {
|
||||||
|
color: #2fbf71;
|
||||||
|
background-color: #e8f8ef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mode-tag--off {
|
||||||
|
color: #e64340;
|
||||||
|
background-color: #fdeaea;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-divider {
|
||||||
|
height: 1rpx;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
margin: 20rpx 0 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 16rpx 0;
|
||||||
|
border-bottom: 1rpx solid #f4f4f4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-row:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-label {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #888;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.info-value {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #333;
|
||||||
|
text-align: right;
|
||||||
|
word-break: break-all;
|
||||||
|
margin-left: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.retry-btn {
|
||||||
|
width: 200rpx;
|
||||||
|
height: 64rpx;
|
||||||
|
line-height: 64rpx;
|
||||||
|
font-size: 26rpx;
|
||||||
|
margin: 28rpx auto 0;
|
||||||
|
padding: 0;
|
||||||
|
border-radius: 8rpx;
|
||||||
|
color: #2f7dff;
|
||||||
|
background-color: #eef5ff;
|
||||||
|
border: 1rpx solid #bcd7ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.retry-btn::after {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Loading…
x
Reference in New Issue
Block a user