¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <view class="normal-login-container"> |
| | | <view class="logo-content"> |
| | | <text>è´¦å·å¯ç ç»å½</text> |
| | | </view> |
| | | <view class="login-form-content"> |
| | | <view class="input-item flex align-center"> |
| | | <up-input prefixIcon="account" placeholder="请è¾å
¥è´¦å·" border="bottom" |
| | | @blur="getUserLoginFacotryList" |
| | | maxlength="30" v-model="loginForm.username" clearable></up-input> |
| | | </view> |
| | | <view class="input-item flex align-center"> |
| | | <up-input prefixIcon="lock" placeholder="请è¾å
¥å¯ç " border="bottom" maxlength="20" v-model="loginForm.password" clearable type="password"></up-input> |
| | | </view> |
| | | <view class="input-item flex align-center select-container"> |
| | | <up-icon name="tags" size="18"></up-icon> |
| | | <up-picker-data |
| | | v-model="loginForm.factoryId" |
| | | title="è¯·éæ©å
¬å¸" |
| | | :options="factoryList" |
| | | valueKey="id" |
| | | labelKey="name"> |
| | | </up-picker-data> |
| | | </view> |
| | | <view> |
| | | <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">ç»å½</button> |
| | | </view> |
| | | </view> |
| | | <!-- è®°ä½å¯ç é项 --> |
| | | <view class="remember-password"> |
| | | <up-checkbox |
| | | :customStyle="{marginBottom: '8px'}" |
| | | label="è®°ä½å¯ç " |
| | | name="agree" |
| | | usedAlone |
| | | v-model:checked="rememberPassword" |
| | | > |
| | | </up-checkbox> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import modal from '@/plugins/modal' |
| | | import { userLoginFacotryList} from '@/api/login' |
| | | import { ref, onMounted } from "vue"; |
| | | import useUserStore from '@/store/modules/user' |
| | | import { getWxCode } from '@/utils/geek'; |
| | | import { wxLogin } from '@/api/oauth'; |
| | | import { setToken } from '@/utils/auth'; |
| | | const userStore = useUserStore() |
| | | const useWxLogin = ref(false); // æ¯å¦ä½¿ç¨å¾®ä¿¡ç»å½ |
| | | const rememberPassword = ref(false); // è®°ä½å¯ç |
| | | const loginForm = ref({ |
| | | username: "", |
| | | password: "", |
| | | factoryId: "", |
| | | currentFatoryName: "", |
| | | }); |
| | | const factoryList = ref([]) // å
¬å¸å表 |
| | | |
| | | // ä¿åå¯ç å°æ¬å°åå¨ |
| | | function savePassword() { |
| | | if (rememberPassword.value) { |
| | | uni.setStorageSync('remembered_username', loginForm.value.username); |
| | | uni.setStorageSync('remembered_password', loginForm.value.password); |
| | | uni.setStorageSync('remember_password', true); |
| | | } else { |
| | | uni.removeStorageSync('remembered_username'); |
| | | uni.removeStorageSync('remembered_password'); |
| | | uni.setStorageSync('remember_password', false); |
| | | } |
| | | } |
| | | |
| | | // 仿¬å°åå¨å è½½å¯ç |
| | | function loadPassword() { |
| | | const remembered = uni.getStorageSync('remember_password'); |
| | | if (remembered) { |
| | | rememberPassword.value = true; |
| | | const savedUsername = uni.getStorageSync('remembered_username'); |
| | | const savedPassword = uni.getStorageSync('remembered_password'); |
| | | if (savedUsername) { |
| | | loginForm.value.username = savedUsername; |
| | | } |
| | | if (savedPassword) { |
| | | loginForm.value.password = savedPassword; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (useWxLogin.value) { |
| | | getWxCode().then(res => { |
| | | console.log(res); |
| | | wxLogin('miniapp',res).then(res => { |
| | | if(res.token != null){ |
| | | setToken(res.token); |
| | | loginSuccess() |
| | | } |
| | | }); |
| | | }) |
| | | } |
| | | |
| | | function getUserLoginFacotryList() { |
| | | if(loginForm.value.username){ |
| | | userLoginFacotryList({userName:loginForm.value.username}).then(res => { |
| | | // æ£æ¥res.dataæ¯å¦ä¸ºæ°ç» |
| | | if (res.data && Array.isArray(res.data)) { |
| | | // éæ°ç»è£
æ°æ®æ ¼å¼ï¼deptIdåæidï¼deptNameåæname |
| | | factoryList.value = res.data.map(item => ({ |
| | | id: item.deptId, |
| | | name: item.deptName |
| | | })) |
| | | } else { |
| | | // 妿res.data䏿¯æ°ç»ï¼è®¾ç½®ä¸ºç©ºæ°ç» |
| | | factoryList.value = [] |
| | | } |
| | | }).catch(error => { |
| | | modal.msgError('è·åå
¬å¸å表失败:', error) |
| | | factoryList.value = [] |
| | | }) |
| | | }else { |
| | | factoryList.value = [] |
| | | } |
| | | } |
| | | |
| | | async function handleLogin() { |
| | | if (loginForm.value.username === "") { |
| | | modal.msgError("请è¾å
¥æ¨çè´¦å·") |
| | | } else if (loginForm.value.password === "") { |
| | | modal.msgError("请è¾å
¥æ¨çå¯ç ") |
| | | } else if (loginForm.value.factoryId === "") { |
| | | modal.msgError("è¯·éæ©å
¬å¸") |
| | | } else { |
| | | modal.loading("ç»å½ä¸ï¼è¯·èå¿çå¾
...") |
| | | pwdLogin() |
| | | } |
| | | }; |
| | | // å¯ç ç»å½ |
| | | async function pwdLogin() { |
| | | userStore.loginCheckFactory(loginForm.value).then(() => { |
| | | modal.closeLoading() |
| | | // ç»å½æååä¿åå¯ç |
| | | savePassword(); |
| | | loginSuccess() |
| | | }).catch(() => { |
| | | modal.closeLoading() |
| | | }) |
| | | }; |
| | | |
| | | function loginSuccess(result) { |
| | | // è®¾ç½®ç¨æ·ä¿¡æ¯ |
| | | userStore.getInfo().then(res => { |
| | | uni.switchTab({ |
| | | url: '/pages/index' |
| | | }); |
| | | }) |
| | | } |
| | | // 页é¢å è½½æ¶æ£æ¥æ¯å¦æä¿åçå¯ç |
| | | onMounted(() => { |
| | | loadPassword(); |
| | | getUserLoginFacotryList() |
| | | }); |
| | | </script> |
| | | |
| | | <style lang="scss"> |
| | | page { |
| | | background-color: #ffffff; |
| | | } |
| | | |
| | | .normal-login-container { |
| | | width: 100%; |
| | | height: 100vh; |
| | | |
| | | .logo-content { |
| | | width: 90%; |
| | | font-weight: 400; |
| | | font-size: 30px; |
| | | color: #333333; |
| | | margin: 80px 0 0 30px; |
| | | |
| | | image { |
| | | border-radius: 4px; |
| | | } |
| | | |
| | | .title { |
| | | margin-left: 10px; |
| | | } |
| | | } |
| | | .u-checkbox { |
| | | margin-left: 34px; |
| | | } |
| | | |
| | | .login-form-content { |
| | | text-align: center; |
| | | margin: 58px auto; |
| | | padding: 0 30px; |
| | | |
| | | .input-item { |
| | | margin: 30px auto; |
| | | height: 45px; |
| | | |
| | | .icon { |
| | | font-size: 38rpx; |
| | | margin-left: 10px; |
| | | color: #999; |
| | | } |
| | | |
| | | .input { |
| | | width: 100%; |
| | | font-size: 14px; |
| | | line-height: 20px; |
| | | text-align: left; |
| | | padding-left: 15px; |
| | | } |
| | | } |
| | | .select-container { |
| | | flex: 1; |
| | | border-bottom: 1px solid #e5e5e5; |
| | | padding: 6px 9px; |
| | | |
| | | :deep(.up-select) { |
| | | border: none; |
| | | background: transparent; |
| | | |
| | | .up-select__label { |
| | | font-size: 14px; |
| | | color: #333; |
| | | } |
| | | |
| | | .up-select__value { |
| | | font-size: 14px; |
| | | color: #333; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .login-btn { |
| | | margin-top: 60px; |
| | | height: 50px; |
| | | background: linear-gradient( 140deg, #00BAFF 0%, #006CFB 100%); |
| | | box-shadow: 0px 4px 10px 0px rgba(3,88,185,0.2); |
| | | border-radius: 40px 40px 40px 40px; |
| | | } |
| | | |
| | | .xieyi { |
| | | color: #333; |
| | | margin-top: 20px; |
| | | } |
| | | |
| | | .login-code { |
| | | height: 38px; |
| | | float: right; |
| | | |
| | | .login-code-img { |
| | | height: 38px; |
| | | position: absolute; |
| | | margin-left: 10px; |
| | | width: 200rpx; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | </style> |