From 2c654d38ee8757e73d220d243bd659e35e1c7ecb Mon Sep 17 00:00:00 2001 From: lewis <604446095@qq.com> Date: Sat, 6 Sep 2025 15:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- env/.env | 6 +- src/api/login.ts | 4 ++ src/pages/login/login.vue | 115 +++++++++++++++++++++++++++++++-- src/pages/my/uploadProduct.vue | 38 ++++++++++- src/store/user.ts | 26 ++++++-- src/utils/http.ts | 10 ++- 6 files changed, 182 insertions(+), 17 deletions(-) diff --git a/env/.env b/env/.env index 9349bfb..9fc7ece 100644 --- a/env/.env +++ b/env/.env @@ -28,9 +28,9 @@ VITE_SERVER_BASEURL__WEIXIN_DEVELOP = 'https://test.data-middle.lihaink.cn' VITE_SERVER_BASEURL__WEIXIN_TRIAL = 'https://test.data-middle.lihaink.cn' VITE_SERVER_BASEURL__WEIXIN_RELEASE = 'https://test.data-middle.lihaink.cn' -VITE_UPLOAD_BASEURL__WEIXIN_DEVELOP = 'https://test.data-middle.lihaink.cn/upload' -VITE_UPLOAD_BASEURL__WEIXIN_TRIAL = 'https://test.data-middle.lihaink.cn/upload' -VITE_UPLOAD_BASEURL__WEIXIN_RELEASE = 'https://test.data-middle.lihaink.cn/upload' +VITE_UPLOAD_BASEURL__WEIXIN_DEVELOP = 'https://test.data-middle.lihaink.cn/api/upload/image' +VITE_UPLOAD_BASEURL__WEIXIN_TRIAL = 'https://test.data-middle.lihaink.cn/api/upload/image' +VITE_UPLOAD_BASEURL__WEIXIN_RELEASE = 'https://test.data-middle.lihaink.cn/api/upload/image' # h5是否需要配置代理 VITE_APP_PROXY=true diff --git a/src/api/login.ts b/src/api/login.ts index 39d642b..3092627 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -92,3 +92,7 @@ export function wxLogin(data: { code: string }) { // export function routineLoginApi(data: { code: string }) { // return http.post('/api/auth/routineLogin', data) // } + +export function phoneLogin(data) { + return http.post('/api/auth/phoneLogin', data) +} diff --git a/src/pages/login/login.vue b/src/pages/login/login.vue index 5474bf4..4bf7569 100644 --- a/src/pages/login/login.vue +++ b/src/pages/login/login.vue @@ -7,14 +7,117 @@ } - - + + diff --git a/src/pages/my/uploadProduct.vue b/src/pages/my/uploadProduct.vue index 7805e27..c304401 100644 --- a/src/pages/my/uploadProduct.vue +++ b/src/pages/my/uploadProduct.vue @@ -41,14 +41,43 @@ function getUserInfo() { } function handleSubmit() { + if (formData.user_id == '') { + uni.showToast({ + title: '请选择村民', + icon: 'error', + }) + return + } + if (formData.store_name == '') { + uni.showToast({ + title: '请填写商品名称', + icon: 'error', + }) + return + } + if (formData.number == '') { + uni.showToast({ + title: '请填写数量', + icon: 'error', + }) + return + } + if (formData.price == '') { + uni.showToast({ + title: '请填写单价', + icon: 'error', + }) + return + } commitProduct(formData).then((res) => { - if (res.code == 1) { + if (res.code === 1) { uni.showToast({ title: '上传成功', }) } else { uni.showToast({ - title: res.data.msg, + title: res.msg, + icon: 'error', }) } }) @@ -62,6 +91,11 @@ function uploadSuccess(res) { const response = JSON.parse(res.file.response) if (response.code === 1) { formData.image.push(response.data.uri) + } else { + uni.showToast({ + title: response.msg, + icon: 'error', + }) } } diff --git a/src/store/user.ts b/src/store/user.ts index bc279bf..09cb1df 100644 --- a/src/store/user.ts +++ b/src/store/user.ts @@ -1,15 +1,17 @@ import type { IUserInfoVo } from '@/api/login.typings' import { defineStore } from 'pinia' import { ref } from 'vue' -import { getEnvBaseUrl } from '@/utils' import { getUserInfo as _getUserInfo, login as _login, logout as _logout, wxLogin as _wxLogin, getWxCode, + phoneLogin, } from '@/api/login' +import { getEnvBaseUrl } from '@/utils' import { toast } from '@/utils/toast' + const baseUrl = getEnvBaseUrl() // 初始化状态 const userInfoState: IUserInfoVo = { @@ -32,11 +34,11 @@ export const useUserStore = defineStore( if (!val.avatar) { val.avatar = userInfoState.avatar } else { - val.avatar = baseUrl + val.avatar //地址拼接 + val.avatar = baseUrl + val.avatar // 地址拼接 // val.avatar = 'https://oss.laf.run/ukw0y1-site/avatar.jpg?feige' } - //判断是否设置村庄 - val.isset = userInfoState.village ? true : false + // 判断是否设置村庄 + val.isset = !!userInfoState.village userInfo.value = val } const setUserAvatar = (avatar: string) => { @@ -105,6 +107,21 @@ export const useUserStore = defineStore( return res } + const wxPhoneLogin = async (iv, encryptedData) => { + const code = await getWxCode() + const data = { + iv, + code: code.code, + encryptedData, + } + const res = await phoneLogin(data) + const userInfo = res.data + setUserInfo(userInfo) + uni.setStorageSync('userInfo', userInfo) + uni.setStorageSync('token', userInfo.token) + return res + } + return { userInfo, setUserInfo, @@ -113,6 +130,7 @@ export const useUserStore = defineStore( getUserInfo, setUserAvatar, logout, + wxPhoneLogin, } }, { diff --git a/src/utils/http.ts b/src/utils/http.ts index e868f59..a27bc28 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -18,8 +18,14 @@ export function http(options: CustomRequestOptions) { } else if (res.statusCode === 401) { // 401错误 -> 清理用户信息,跳转到登录页 // userStore.clearUserInfo() - // uni.navigateTo({ url: '/pages/login/login' }) - reject(res) + uni.showToast({ + icon: 'none', + title: (res.data as IResData).msg || '请登录', + }) + setTimeout(() => { + uni.navigateTo({ url: '/pages/login/login' }) + }, 1500) + // reject(res) } else { // 其他错误 -> 根据后端错误信息轻提示 !options.hideErrorToast &&