feat(pda): connect online picking workflow

This commit is contained in:
2026-08-11 11:31:05 +08:00
parent fc1944fb7e
commit be776c8efa
16 changed files with 440 additions and 82 deletions
+20 -15
View File
@@ -7,32 +7,37 @@
<view class="login-card">
<view class="login-field"><text class="login-field-label">工号 / 用户名</text><input v-model="form.userId" class="login-field-input" aria-label="工号 / 用户名" placeholder="请输入工号" confirm-type="next" @focus="error = ''" /></view>
<view class="login-field"><text class="login-field-label">密码</text><input v-model="form.password" class="login-field-input" aria-label="密码" type="password" placeholder="请输入密码" confirm-type="done" @focus="error = ''" @confirm="login" /></view>
<view class="login-field"><text class="login-field-label">作业仓库</text><picker aria-label="作业仓库" :range="warehouses" :value="warehouseIndex" @change="changeWarehouse"><view class="login-field-select"><text>{{ form.warehouse }}</text><text class="select-chevron">⌄</text></view></picker></view>
<text v-if="error" class="login-error" role="alert">{{ error }}</text>
<button class="login-btn" @tap="login">登录</button>
<view class="login-accounts"><text class="login-accounts-title">快捷登录(演示账号)</text><view class="login-quick-btns"><button v-for="account in accounts" :key="account.id" class="login-quick-btn" @tap="enter(account)"><text class="login-quick-btn-name">{{ account.id }} {{ account.name }}</text><text class="login-quick-btn-role"> · {{ account.role }}</text></button></view></view>
<button class="login-btn" :disabled="submitting" @tap="login">{{ submitting ? '登录中...' : '登录' }}</button>
</view>
</view>
</template>
<script>
import { DEMO_ACCOUNTS, WAREHOUSES } from '@/data/demo-data.js'
import { session, signIn } from '@/stores/session.js'
import { login as loginRequest } from '@/api/auth.js'
import { session, restoreSession, signInWithTokens } from '@/stores/session.js'
import { requireOnline } from '@/utils/network.js'
export default {
data() { return { accounts: DEMO_ACCOUNTS, warehouses: WAREHOUSES, form: { userId: '', password: '', warehouse: WAREHOUSES[0] }, error: '' } },
computed: { warehouseIndex() { return Math.max(0, this.warehouses.indexOf(this.form.warehouse)) } },
onLoad() { if (session.currentUser) uni.reLaunch({ url: '/pages/home/home' }) },
data() { return { form: { userId: '', password: '' }, error: '', submitting: false } },
onLoad() { if (session.currentUser || restoreSession()) uni.reLaunch({ url: '/pages/home/home' }) },
methods: {
changeWarehouse(event) { this.form.warehouse = this.warehouses[Number(event.detail.value)] || this.warehouses[0] },
login() {
async login() {
const userId = this.form.userId.trim()
if (!userId) return void (this.error = '请输入工号')
if (!this.form.password) return void (this.error = '请输入密码')
const account = this.accounts.find((entry) => entry.id === userId)
if (!account || account.password !== this.form.password) return void (this.error = '工号或密码错误')
this.enter(account)
},
enter(account) { signIn(account, this.form.warehouse); uni.reLaunch({ url: '/pages/home/home' }) }
this.submitting = true
this.error = ''
try {
requireOnline('当前网络不可用,无法登录')
const tokens = await loginRequest(userId, this.form.password)
signInWithTokens(tokens)
uni.reLaunch({ url: '/pages/home/home' })
} catch (error) {
this.error = error.network ? '当前网络不可用,请联网后重试' : (error.message || '登录失败')
} finally {
this.submitting = false
}
}
}
}
</script>