39 lines
2.9 KiB
Vue
39 lines
2.9 KiB
Vue
<template>
|
||
<view class="page-shell login-page">
|
||
<view class="login-brand">
|
||
<view class="login-logo-icon" aria-hidden="true"><view class="logo-grid-line logo-grid-line-horizontal"></view><view class="logo-grid-line logo-grid-line-vertical"></view></view>
|
||
<text class="login-logo-title">柏悦物流 · PDA作业端</text><text class="login-logo-sub">仓库现场作业系统</text>
|
||
</view>
|
||
<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>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { DEMO_ACCOUNTS, WAREHOUSES } from '@/data/demo-data.js'
|
||
import { session, signIn } from '@/stores/session.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' }) },
|
||
methods: {
|
||
changeWarehouse(event) { this.form.warehouse = this.warehouses[Number(event.detail.value)] || this.warehouses[0] },
|
||
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' }) }
|
||
}
|
||
}
|
||
</script>
|