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 1561634..50909cc 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 = val.village ? true : false
+ // 判断是否设置村庄
+ val.isset = !!userInfoState.village
userInfo.value = val
}
const setUserAvatar = (avatar: string) => {
@@ -57,7 +59,7 @@ export const useUserStore = defineStore(
const res = await _getUserInfo()
const user = res.data
const newData = userInfo.value
- newData.isset = user.village ? true : false
+ newData.isset = !!user.village
userInfo.value = newData
// uni.setStorageSync('userInfo', userInfo)
// uni.setStorageSync('token', userInfo.token)
@@ -108,6 +110,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,
@@ -116,6 +133,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 &&