gaoluyang
2025-12-29 89469f566f4ad8602def16aef6744d205a3d20a8
src/pages/login.vue
@@ -6,22 +6,10 @@
      <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"
               style="width: 100%;"
               labelKey="name">
            </up-picker-data>
         </view>
         <view>
            <button @click="handleLogin" class="login-btn cu-btn block bg-blue lg round">登录</button>
@@ -50,7 +38,6 @@
      icon: 'none'
   })
}
import { userLoginFacotryList} from '@/api/login'
import { ref, onMounted } from "vue";
import useUserStore from '@/store/modules/user'
import { getWxCode } from '@/utils/geek';
@@ -63,7 +50,6 @@
const loginForm = ref({
   userName: "",
   password: "",
   factoryId: "",
   currentFatoryName: "",
});
const factoryList = ref([]) // 公司列表
@@ -109,37 +95,11 @@
   })
}
function getUserLoginFacotryList() {
   if(loginForm.value.userName){
      userLoginFacotryList({userName:loginForm.value.userName}).then(res => {
         console.log('res',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 => {
         showToast('获取公司列表失败:', error)
         factoryList.value = []
      })
   }else {
      factoryList.value = []
   }
}
async function handleLogin() {
   if (loginForm.value.userName === "") {
      showToast("请输入您的账号")
   } else if (loginForm.value.password === "") {
      showToast("请输入您的密码")
   } else if (loginForm.value.factoryId === "") {
      showToast("请选择公司")
   } else {
      showToast("登录中,请耐心等待...")
      pwdLogin()
@@ -147,7 +107,7 @@
};
// 密码登录
async function pwdLogin() {
   userStore.loginCheckFactory(loginForm.value).then(() => {
   userStore.login(loginForm.value).then(() => {
      modal.closeLoading()
      // 登录成功后保存密码
      savePassword();
@@ -168,7 +128,6 @@
// 页面加载时检查是否有保存的密码
onMounted(() => {
   loadPassword();
   getUserLoginFacotryList()
});
</script>