Merge branch 'dev_NEW_pro' into dev_帮太
| | |
| | | import request from '@/utils/request' |
| | | import request from "@/utils/request"; |
| | | |
| | | // 登录方法 |
| | | export function loginCheckFactory(username, password) { |
| | | export function loginCheckFactory(username, password, factoryId) { |
| | | const data = { |
| | | username, |
| | | password, |
| | | } |
| | | factoryId, |
| | | }; |
| | | return request({ |
| | | url: '/loginCheckFactory', |
| | | url: "/loginCheckFactory", |
| | | headers: { |
| | | isToken: false |
| | | isToken: false, |
| | | repeatSubmit: false, |
| | | }, |
| | | method: 'post', |
| | | data: data |
| | | }) |
| | | method: "post", |
| | | data: data, |
| | | }); |
| | | } |
| | | |
| | | // 获取用户详细信息 |
| | | export function getInfo() { |
| | | return request({ |
| | | url: '/getInfo', |
| | | method: 'get' |
| | | }) |
| | | url: "/getInfo", |
| | | method: "get", |
| | | }); |
| | | } |
| | | |
| | | // 退出方法 |
| | | export function logout() { |
| | | return request({ |
| | | url: '/logout', |
| | | method: 'post' |
| | | }) |
| | | url: "/logout", |
| | | method: "post", |
| | | }); |
| | | } |
| | | |
| | | // 获取公司列表 |
| | | export function userLoginFacotryList(params) { |
| | | return request({ |
| | | url: '/userLoginFacotryList', |
| | | method: 'get', |
| | | params: params |
| | | }) |
| | | url: "/userLoginFacotryList", |
| | | method: "get", |
| | | params: params, |
| | | }); |
| | | } |
| | | |
| | | // 获取未过期公告数量 |
| | | export function noticesList(params) { |
| | | return request({ |
| | | url: '/collaborativeApproval/notice/page', |
| | | method: 'get', |
| | | params: params |
| | | }) |
| | | url: "/collaborativeApproval/notice/page", |
| | | method: "get", |
| | | params: params, |
| | | }); |
| | | } |
| | | |
| | | // 发送客户端推送标识到服务器 |
| | | export function updateClientId(data) { |
| | | return request({ |
| | | url: '/system/client/addOrUpdateClientId', |
| | | method: 'post', |
| | | data: data |
| | | }) |
| | | url: "/system/client/addOrUpdateClientId", |
| | | method: "post", |
| | | data: data, |
| | | }); |
| | | } |
| | | |
| | | |
| | | // 查询公告列表 |
| | | export function listNotice(query) { |
| | | return request({ |
| | | url: '/system/notice/list', |
| | | method: 'get', |
| | | params: query |
| | | }) |
| | | url: "/system/notice/list", |
| | | method: "get", |
| | | params: query, |
| | | }); |
| | | } |
| | | |
| | | // 获取未读消息数量 |
| | | export function getNoticeCount(consigneeId) { |
| | | return request({ |
| | | url: '/system/notice/getCount', |
| | | method: 'get', |
| | | params: { consigneeId } |
| | | }) |
| | | url: "/system/notice/getCount", |
| | | method: "get", |
| | | params: { consigneeId }, |
| | | }); |
| | | } |
| | | |
| | | // 标记消息为已读 |
| | |
| | | clearable |
| | | type="password"></up-input> |
| | | </view> |
| | | <!-- <view class="input-item flex align-center" |
| | | v-if="factoryList.length > 0"> |
| | | <up-input prefixIcon="home" |
| | | placeholder="请选择工厂" |
| | | border="bottom" |
| | | readonly |
| | | @click="showFactorySelect = true" |
| | | v-model="selectedFactoryName" |
| | | clearable></up-input> |
| | | <up-action-sheet :show="showFactorySelect" |
| | | :actions="factoryList" |
| | | title="请选择工厂" |
| | | @close="showFactorySelect = false" |
| | | @select="handleFactorySelect"></up-action-sheet> |
| | | </view> --> |
| | | <view> |
| | | <button @click="handleLogin" |
| | | class="login-btn cu-btn block bg-blue lg round">登录</button> |
| | |
| | | const loginForm = ref({ |
| | | userName: "", |
| | | password: "", |
| | | currentFatoryName: "", |
| | | factoryId: "", |
| | | }); |
| | | const factoryList = ref([]); // 公司列表 |
| | | const showFactorySelect = ref(false); |
| | | const selectedFactoryName = ref(""); |
| | | |
| | | const handleFactorySelect = e => { |
| | | loginForm.value.factoryId = e.id; |
| | | selectedFactoryName.value = e.name; |
| | | showFactorySelect.value = false; |
| | | }; |
| | | |
| | | // 保存密码到本地存储 |
| | | function savePassword() { |
| | |
| | | id: item.deptId, |
| | | name: item.deptName, |
| | | })); |
| | | // 如果只有一个工厂,默认选中 |
| | | if (factoryList.value.length === 1) { |
| | | loginForm.value.factoryId = factoryList.value[0].id; |
| | | selectedFactoryName.value = factoryList.value[0].name; |
| | | } |
| | | } else { |
| | | // 如果res.data不是数组,设置为空数组 |
| | | factoryList.value = []; |
| | | loginForm.value.factoryId = ""; |
| | | selectedFactoryName.value = ""; |
| | | } |
| | | }) |
| | | .catch(error => { |
| | | showToast("获取公司列表失败:", error); |
| | | factoryList.value = []; |
| | | loginForm.value.factoryId = ""; |
| | | selectedFactoryName.value = ""; |
| | | }); |
| | | } else { |
| | | factoryList.value = []; |
| | | loginForm.value.factoryId = ""; |
| | | selectedFactoryName.value = ""; |
| | | } |
| | | } |
| | | |
| | |
| | | showToast("请输入您的账号"); |
| | | } else if (loginForm.value.password === "") { |
| | | showToast("请输入您的密码"); |
| | | } else if (factoryList.value.length > 0 && loginForm.value.factoryId === "") { |
| | | showToast("请选择工厂"); |
| | | } else { |
| | | showToast("登录中,请耐心等待..."); |
| | | pwdLogin(); |
| | |
| | | const accountInfo = uni.getAccountInfoSync(); |
| | | if (accountInfo?.miniProgram?.version) { |
| | | versionName.value = accountInfo.miniProgram.version; |
| | | console.log("[login-version] 当前环境=MP-WEIXIN,版本=", versionName.value); |
| | | console.log( |
| | | "[login-version] 当前环境=MP-WEIXIN,版本=", |
| | | versionName.value |
| | | ); |
| | | } |
| | | } catch (e) { |
| | | // 获取失败时使用默认值 |
| | |
| | | // @ts-ignore |
| | | const appid = plus.runtime.appid; |
| | | // @ts-ignore |
| | | plus.runtime.getProperty(appid, (info) => { |
| | | plus.runtime.getProperty(appid, info => { |
| | | const v = info?.version || info?.versionName || ""; |
| | | if (v) { |
| | | versionName.value = String(v); |
| | | console.log("[login-version] 当前环境=APP-PLUS,版本=", versionName.value); |
| | | console.log( |
| | | "[login-version] 当前环境=APP-PLUS,版本=", |
| | | versionName.value |
| | | ); |
| | | } else { |
| | | console.log("[login-version] APP-PLUS 获取到的版本字段为空,使用默认值:", versionName.value); |
| | | console.log( |
| | | "[login-version] APP-PLUS 获取到的版本字段为空,使用默认值:", |
| | | versionName.value |
| | | ); |
| | | } |
| | | console.log("[login-version] 最终版本号:", versionName.value); |
| | | }); |
| | | } else { |
| | | console.log("[login-version] APP-PLUS 环境下缺少 getProperty,使用默认值:", versionName.value); |
| | | console.log( |
| | | "[login-version] APP-PLUS 环境下缺少 getProperty,使用默认值:", |
| | | versionName.value |
| | | ); |
| | | console.log("[login-version] 最终版本号:", versionName.value); |
| | | } |
| | | // #endif |
| | |
| | | import { getToken, setToken, removeToken } from "@/utils/auth"; |
| | | import defAva from "@/static/images/profile.jpg"; |
| | | import { defineStore } from "pinia"; |
| | | import config from '@/config.js' |
| | | import config from "@/config.js"; |
| | | |
| | | export interface LoginForm { |
| | | userName: string; |
| | |
| | | actions: { |
| | | // 部门登录 |
| | | loginCheckFactory(userInfo: any) { |
| | | const userName = userInfo.userName |
| | | const password = userInfo.password |
| | | const userName = userInfo.userName.trim(); |
| | | const password = userInfo.password; |
| | | const factoryId = userInfo.factoryId; |
| | | return new Promise((resolve, reject) => { |
| | | loginCheckFactory(userName, password).then((res: any) => { |
| | | setToken(res.token) |
| | | this.token = res.token |
| | | resolve(null) |
| | | }).catch((error: any) => { |
| | | reject(error) |
| | | loginCheckFactory(userName, password, factoryId) |
| | | .then((res: any) => { |
| | | const token = res.token || res.data?.token; |
| | | if (token) { |
| | | setToken(token); |
| | | this.token = token; |
| | | resolve(null); |
| | | } else { |
| | | reject("未获取到登录令牌"); |
| | | } |
| | | }) |
| | | }) |
| | | .catch((error: any) => { |
| | | reject(error); |
| | | }); |
| | | }); |
| | | }, |
| | | // 获取用户信息 |
| | | getInfo() { |
| | | return new Promise((resolve, reject) => { |
| | | getInfo() |
| | | .then((res: any) => { |
| | | const user = res.user |
| | | let avatar = user.avatar || "" |
| | | avatar = config.baseUrl + '/profile/' + avatar |
| | | if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 |
| | | this.roles = res.roles |
| | | this.permissions = res.permissions |
| | | // 兼容 res.data 结构 |
| | | const data = res.data || res; |
| | | const user = data.user || {}; |
| | | let avatar = user.avatar || ""; |
| | | avatar = config.baseUrl + "/profile/" + avatar; |
| | | if (data.roles && data.roles.length > 0) { |
| | | // 验证返回的roles是否是一个非空数组 |
| | | this.roles = data.roles; |
| | | this.permissions = data.permissions; |
| | | } else { |
| | | this.roles = ['ROLE_DEFAULT'] |
| | | this.roles = ["ROLE_DEFAULT"]; |
| | | } |
| | | this.id = user.userId |
| | | this.name = user.userName |
| | | this.avatar = avatar |
| | | this.currentFactoryName = user.currentFactoryName |
| | | this.nickName = user.nickName |
| | | this.roleName = user.roles[0].roleName |
| | | this.currentDeptId = user.tenantId |
| | | this.currentLoginTime = this.getCurrentTime() |
| | | resolve(res); |
| | | this.id = user.userId || ""; |
| | | this.name = user.userName || ""; |
| | | this.avatar = avatar; |
| | | this.currentFactoryName = user.currentFactoryName || ""; |
| | | this.nickName = user.nickName || ""; |
| | | this.roleName = Array.isArray(user.roles) && user.roles.length > 0 ? user.roles[0].roleName || "" : ""; |
| | | this.currentDeptId = user.tenantId || ""; |
| | | this.currentLoginTime = this.getCurrentTime(); |
| | | resolve(data); |
| | | }) |
| | | .catch((error) => { |
| | | .catch(error => { |
| | | reject(error); |
| | | }); |
| | | }); |
| | |
| | | removeToken(); |
| | | resolve(null); |
| | | }) |
| | | .catch((error) => { |
| | | .catch(error => { |
| | | reject(error); |
| | | }); |
| | | }); |
| | |
| | | getCurrentTime() { |
| | | const now = new Date(); |
| | | const year = now.getFullYear(); // 获取年份 |
| | | const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,要+1,并补零 |
| | | const day = String(now.getDate()).padStart(2, '0'); // 日期补零 |
| | | const hours = String(now.getHours()).padStart(2, '0'); // 小时补零 |
| | | const minutes = String(now.getMinutes()).padStart(2, '0'); // 分钟补零 |
| | | const seconds = String(now.getSeconds()).padStart(2, '0'); // 秒数补零 |
| | | const month = String(now.getMonth() + 1).padStart(2, "0"); // 月份从0开始,要+1,并补零 |
| | | const day = String(now.getDate()).padStart(2, "0"); // 日期补零 |
| | | const hours = String(now.getHours()).padStart(2, "0"); // 小时补零 |
| | | const minutes = String(now.getMinutes()).padStart(2, "0"); // 分钟补零 |
| | | const seconds = String(now.getSeconds()).padStart(2, "0"); // 秒数补零 |
| | | return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| | | }, |
| | | // 获取路由权限 |
| | |
| | | this.routers = res.data || []; |
| | | resolve(res); |
| | | }) |
| | | .catch((error) => { |
| | | .catch(error => { |
| | | reject(error); |
| | | }); |
| | | }); |