From b31cb9aa721d4ee8660a2d3575da6f52354aad58 Mon Sep 17 00:00:00 2001 From: bb_pan Date: Fri, 11 Jul 2025 10:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B0=8F=E6=95=B0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=87=BA=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login/index.vue | 51 +++++++++++-------- .../toolsBack/toolsAddBack.vue | 27 ++++++---- .../toolsLease/toolsLeaseAdd.vue | 25 +++++---- src/utils/http.js | 8 ++- 4 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue index e3555bb..a96d410 100644 --- a/src/pages/login/index.vue +++ b/src/pages/login/index.vue @@ -70,32 +70,43 @@ onMounted(async () => { } catch (error) { console.log(error) uni.hideLoading() - showToast('登录失败') + // showToast('登录失败') + // 弹框提示: + uni.showModal({ + title: '提示', + content: '登录失败, 请退出后重新登录', + showCancel: false, + confirmText: '确定', + }) } } }) // 登录按钮 const onHandleLogin = async () => { - const res = await appLoginAPI(loginForm) - if (res.code === 200) { - // 1. 获取 token 并存储 - memberStore.setToken(res.data.access_token) - // 2 . 获取用户信息并存储 - const result = await getUserInfoAPI() - console.log("xxxxxxxxxx",result) - memberStore.setUserInfo(result.user) - uni.showToast({ title: '登录成功!', icon: 'none' }) - uni.setStorageSync('username', loginForm.username) - uni.setStorageSync('password', loginForm.password) - uni.setStorageSync('id', result.user.userId) - uni.setStorageSync('deptName', result.user?.dept?.deptName) - uni.setStorageSync('urlPermissions',result.urlPermissions?result.urlPermissions:[]) - setTimeout(() => { - uni.switchTab({ - url: '/pages/index/index', - }) - }, 500) + try { + const res = await appLoginAPI(loginForm) + if (res.code === 200) { + // 1. 获取 token 并存储 + memberStore.setToken(res.data.access_token) + // 2 . 获取用户信息并存储 + const result = await getUserInfoAPI() + console.log("xxxxxxxxxx",result) + memberStore.setUserInfo(result.user) + uni.showToast({ title: '登录成功!', icon: 'none' }) + uni.setStorageSync('username', loginForm.username) + uni.setStorageSync('password', loginForm.password) + uni.setStorageSync('id', result.user.userId) + uni.setStorageSync('deptName', result.user?.dept?.deptName) + uni.setStorageSync('urlPermissions',result.urlPermissions?result.urlPermissions:[]) + setTimeout(() => { + uni.switchTab({ + url: '/pages/index/index', + }) + }, 500) + } + } catch (error) { + console.log('🚀 ~ onHandleLogin ~ error:', error) } } diff --git a/src/pages/materialsStation/toolsBack/toolsAddBack.vue b/src/pages/materialsStation/toolsBack/toolsAddBack.vue index 2fd3684..3dc6ae4 100644 --- a/src/pages/materialsStation/toolsBack/toolsAddBack.vue +++ b/src/pages/materialsStation/toolsBack/toolsAddBack.vue @@ -98,7 +98,7 @@ v-model="item.preNum" placeholder="请输入数量" type="number" - @blur="checkPerNum(item)" + @change="checkPerNum(item)" > {{ @@ -308,16 +308,21 @@ const checkPhone = (rule, value, callback) => { // 检查数量 const checkPerNum = (item) => { - // 大于1的正整数 正则校验 - if (!/^[1-9]\d*$/.test(item.preNum)) { - uni.showToast({ - icon: 'none', - title: '请输入正确的数量', - }) - // 重置为1 - item.preNum = 1 - return false + if (item.unitValue == 1) { + item.preNum = Number(String(item.preNum).replace(/[^\d.]/g, '')) + } else { + item.preNum = Number(String(item.preNum).replace(/[^\d]/g, '')) } + // 大于1的正整数 正则校验 + // if (!/^[1-9]\d*$/.test(item.preNum)) { + // uni.showToast({ + // icon: 'none', + // title: '请输入正确的数量', + // }) + // // 重置为1 + // item.preNum = 1 + // return false + // } } // 选择班组 const changeTeamd = (e) => { @@ -352,7 +357,7 @@ const changeEquipment = (e) => { // 从 equipmentList.value 中获取点击id的上一级的 typeName const equipment = findEquipmentById(equipmentList.value, e.parentId) - tableData.value.push({ + tableData.value.unshift({ ...JSON.parse(JSON.stringify(e)), maTypeName: equipment.typeName, preNum: e.manageType == '1' ? 1 : 0, // 如果是数量设备,默认退料数为1 diff --git a/src/pages/materialsStation/toolsLease/toolsLeaseAdd.vue b/src/pages/materialsStation/toolsLease/toolsLeaseAdd.vue index 63317dc..b8aaafa 100644 --- a/src/pages/materialsStation/toolsLease/toolsLeaseAdd.vue +++ b/src/pages/materialsStation/toolsLease/toolsLeaseAdd.vue @@ -111,7 +111,7 @@ v-model="item.preNum" placeholder="请输入数量" type="number" - @blur="checkPerNum(item)" + @change="checkPerNum(item)" > {{ @@ -387,15 +387,20 @@ const checkPhone = (rule, value, callback) => { // 检查数量 const checkPerNum = (item) => { // 大于1的正整数 正则校验 - if (!/^[1-9]\d*$/.test(item.preNum)) { - uni.showToast({ - icon: 'none', - title: '请输入正确的数量', - }) - // 重置为1 - item.preNum = 1 - return false + if (item.unitValue == 1) { + item.preNum = Number(String(item.preNum).replace(/[^\d.]/g, '')) + } else { + item.preNum = Number(String(item.preNum).replace(/[^\d]/g, '')) } + // if (!/^[1-9]\d*$/.test(item.preNum)) { + // uni.showToast({ + // icon: 'none', + // title: '请输入正确的数量', + // }) + // // 重置为1 + // item.preNum = 1 + // return false + // } if (opts.value.isOut) { if (item.preNum > item.storageNum) { uni.showToast({ @@ -448,7 +453,7 @@ const changeEquipment = (e) => { // 从 equipmentList.value 中获取点击id的上一级的 typeName const equipment = findEquipmentById(equipmentList.value, e.parentId) - tableData.value.push({ + tableData.value.unshift({ ...JSON.parse(JSON.stringify(e)), storageNum: e.num, maTypeName: equipment.typeName, diff --git a/src/utils/http.js b/src/utils/http.js index cbe6ab6..91b1b9f 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -66,11 +66,15 @@ export const http = (options) => { // 2. 401 表示token过期 去往登录页重新登录 uni.showToast({ icon: 'none', - title: `${res.data.msg}`, + title: `${res.data.msg || '账号已过期,请重新登录'}`, }) const memberStore = useMemberStore() memberStore.clearUserInfo() memberStore.clearToken() + uni.removeStorageSync('idCard') + uni.removeStorageSync('id') + uni.removeStorageSync('deptName') + uni.removeStorageSync('urlPermissions') const pages = getCurrentPages() const currentPage = pages[pages.length - 1] if (!currentPage.route.includes('login')) { @@ -82,7 +86,7 @@ export const http = (options) => { } else if (res.data && res.data.code === 500) { uni.showToast({ icon: 'none', - title: `${res.data.msg}`, + title: `${res.data.msg || '请求失败'}`, }) reject(res) } else {