diff --git a/index.html b/index.html
index f8a54cb..84dca45 100644
--- a/index.html
+++ b/index.html
@@ -1,13 +1,22 @@
-
+
+
+
diff --git a/src/api/login.ts b/src/api/login.ts
index 4c7adf1..43b98f0 100644
--- a/src/api/login.ts
+++ b/src/api/login.ts
@@ -6,12 +6,12 @@ import { http } from './request/request'
export const getBindPhoneTypeApi = async data => {
return await http.post('/xcx/login/getBindRelationList', data)
}
-/**
- * 手机号获取用户身份
- * @param data 请求参数
- */
-export const getAdminTypeByPhoneApi = async (params: any) =>
- await http.get('/sysUser/getAdminTypeByPhone', params)
+// /**
+// * 手机号获取用户身份
+// * @param data 请求参数
+// */
+// export const getAdminTypeByPhoneApi = async (params: any) =>
+// await http.get('/sysUser/getAdminTypeByPhone', params)
/**
* 发送验证码
@@ -30,12 +30,31 @@ export const smsLoginApi = async data =>
clientType: 'MOBILE',
})
+/**
+ * 微信登录
+ * @param data 请求参数
+ */
+export const wxLoginApi = async data =>
+ await http.post('/wxLogin', {
+ ...data,
+ clientType: 'MOBILE',
+ })
+
+/**
+ * 微信绑定账号
+ * @param data 请求参数
+ */
+export const wxBindAccountApi = async data =>
+ await http.post('/wxBindAccount', {
+ ...data,
+ clientType: 'MOBILE',
+ })
+
/**
* 获取用户信息
* @param data 请求参数
*/
-export const getUserInfoApi = async () =>
- await http.get('/sysUser/selectUser')
+export const getUserInfoApi = async () => await http.get('/sysUser/selectUser')
/**
* 更新用户信息
@@ -55,9 +74,7 @@ export const bindAuthInfoApi = async data =>
* 获取静默授权链接
* @param data 请求参数
*/
-export const getAuthUrlApi = async () =>
- await http.get('/wechatPublic/getAuthUrl')
+export const getAuthUrlApi = async () => await http.get('/wechatPublic/getAuthUrl')
// 退出登录
-export const logout = async () =>
- await http.get('/logout')
+export const logout = async () => await http.get('/logout')
diff --git a/src/api/request/interceptor.ts b/src/api/request/interceptor.ts
index 0221477..04d2294 100644
--- a/src/api/request/interceptor.ts
+++ b/src/api/request/interceptor.ts
@@ -33,15 +33,12 @@ export const responseInterceptor = async (
console.log('response', response)
// 处理成功响应
- if (statusCode === HTTP_STATUS.SUCCESS) {
- if (data.statusCode === 200 || data.code === 200) return response
- throw {
- statusCode,
- errMsg: data.data,
- }
+ if (statusCode === HTTP_STATUS.SUCCESS && data.code === 200) {
+ return response
} else {
throw {
statusCode,
+ errMsg: data.message || '网络问题,请稍后再试',
}
}
}
@@ -55,7 +52,7 @@ export const errorInterceptor = (error: any): Promise => {
message = errMsg
} else {
// 处理特定状态码
- switch (error.statusCode) {
+ switch (statusCode) {
case HTTP_STATUS.AUTHENTICATE:
toLogin = true
message = ERROR_MSG.AUTH_ERROR
diff --git a/src/api/request/request.ts b/src/api/request/request.ts
index 4a0fc73..55a1f7c 100644
--- a/src/api/request/request.ts
+++ b/src/api/request/request.ts
@@ -23,8 +23,8 @@ class HttpRequest {
url,
timeout: this.timeout,
})) as unknown as ResponseData
-
- return (await responseInterceptor(response)).data
+ const res = (await responseInterceptor(response)).data as any
+ return res?.data
} catch (error) {
return errorInterceptor(error) as any
}
diff --git a/src/pages/login/index.vue b/src/pages/login/index.vue
index d8f0581..ae0665f 100644
--- a/src/pages/login/index.vue
+++ b/src/pages/login/index.vue
@@ -48,23 +48,6 @@
-
-
-
-
-
@@ -74,10 +57,11 @@ import { ref, computed, nextTick, onMounted } from 'vue'
import {
getBindPhoneTypeApi,
sendCodeMessageApi,
- getAdminTypeByPhoneApi,
smsLoginApi,
getUserInfoApi,
getAuthUrlApi,
+ wxLoginApi,
+ wxBindAccountApi,
} from '@/api'
import { setCache, getCache } from '@/utils'
import { getUserInfo as dx_getUserInfoApi } from '@/api/inspector/mine'
@@ -129,12 +113,8 @@ async function fetchDXUserInfo() {
}
// 获取验证码
async function getCode() {
- loginForm.value.phone = formatPhone.value.replace(/\s+/g, '')
- if (!loginForm.value.phone) {
- uni.showToast({
- icon: 'none',
- title: '请输入手机号',
- })
+ if (!validatePhone()) {
+ hud.error('请输入正确的手机号')
return
}
try {
@@ -161,76 +141,64 @@ async function handleLogin() {
})
return
}
- uni.showLoading({
- title: '登录中...',
- })
- getAdminTypeByPhone()
-}
-// 用户身份
-async function getAdminTypeByPhone() {
- const res = await getAdminTypeByPhoneApi({
- phone: loginForm.value.phone,
- })
- userAdmin.value = res
- if (userAdmin.value.length <= 1) {
- // 非多个身份
- loginForm.value.adminType = userAdmin.value[0].adminType
+ if (db.get('openid')) {
+ await wxBindAccount()
+ } else {
await smsLogin()
- if (loginForm.value.adminType === 6) return
- } else {
- // 多个身份
- uni.hideLoading()
-
- adminPopup.value = true
}
}
+
async function smsLogin() {
- uni.showLoading({
- title: '登录中...',
+ hud.load({
+ task: async () => {
+ const token = await smsLoginApi(loginForm.value)
+ setToken(token)
+ await getUserInfo()
+ router.reLaunch('/pages/home/index')
+ },
+ option: '登录',
})
- const res = await smsLoginApi(loginForm.value)
- setToken(res)
- const data = await getUserInfo()
+}
- if (!data.openid) {
- // 初次注册
- const authRes = await getAuthUrlApi()
- // #ifdef H5
- window.location.href = authRes
- // #endif
- // if (data.adminType === 16) {
- // const authRes = await getAuthUrlApi();
- // // #ifdef H5
- // window.location.href = authRes.data;
- // // #endif
- // } else {
- // fetchDXUserInfo();
- // uni.reLaunch({
- // url: '/pages/inspector/schedule/index',
- // });
- // }
- } else {
- router.reLaunch('/pages/home/index')
- // let adminType = getCache('userInfo').adminType;
- // if (adminType === 16) {
- // uni.reLaunch({
- // url: '/pages/home/index',
- // });
- // } else if (adminType === 6) {
- // fetchDXUserInfo();
- // uni.reLaunch({
- // url: '/pages/inspector/schedule/index',
- // });
- // }
+async function wxBindAccount() {
+ hud.load({
+ task: async () => {
+ await wxBindAccountApi(loginForm.value)
+ await getUserInfo()
+ router.reLaunch('/pages/home/index')
+ },
+ option: '登录',
+ })
+}
+
+async function wxLogin() {
+ const code = db.get('code')
+ if (!code) {
+ return
}
- uni.hideLoading()
-}
-async function chooseAdmin(i) {
- loginForm.value.adminType = i.adminType
- adminPopup.value = false
- await smsLogin()
- if (loginForm.value.adminType === 6) return
+ // 移除code
+ db.pop('code')
+
+ hud.load({
+ task: async () => {
+ // 登录逻辑
+ const { accessToken, openid } = await wxLoginApi({
+ code,
+ })
+ db.set('openid', openid)
+ setToken(accessToken)
+ },
+ option: '微信自动登录',
+ })
}
+
+onMounted(async () => {
+ // 清空token
+ db.pop('token')
+
+ // 尝试微信登录
+ wxLogin()
+})