添加公众号配置
This commit is contained in:
4
env/.env
vendored
4
env/.env
vendored
@ -10,12 +10,12 @@ VITE_APP_PUBLIC_BASE = '/h5'
|
|||||||
# 登录页面
|
# 登录页面
|
||||||
VITE_LOGIN_URL = '/pages/login/login'
|
VITE_LOGIN_URL = '/pages/login/login'
|
||||||
# 第一个请求地址
|
# 第一个请求地址
|
||||||
VITE_SERVER_BASEURL = 'https://cz.stnav.com/gzhapi'
|
VITE_SERVER_BASEURL = 'https://cz.stnav.com'
|
||||||
|
|
||||||
VITE_UPLOAD_BASEURL = 'https://cz.stnav.com/upload'
|
VITE_UPLOAD_BASEURL = 'https://cz.stnav.com/upload'
|
||||||
|
|
||||||
# h5是否需要配置代理
|
# h5是否需要配置代理
|
||||||
VITE_APP_PROXY=false
|
VITE_APP_PROXY=true
|
||||||
VITE_APP_PROXY_PREFIX = '/api'
|
VITE_APP_PROXY_PREFIX = '/api'
|
||||||
|
|
||||||
# 第二个请求地址 (目前alova中可以使用)
|
# 第二个请求地址 (目前alova中可以使用)
|
||||||
|
|||||||
2
env/.env.production
vendored
2
env/.env.production
vendored
@ -1,6 +1,6 @@
|
|||||||
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
|
# 变量必须以 VITE_ 为前缀才能暴露给外部读取
|
||||||
NODE_ENV = 'development'
|
NODE_ENV = 'development'
|
||||||
# 是否去除console 和 debugger
|
# 是否去除console 和 debugger
|
||||||
VITE_DELETE_CONSOLE = false
|
VITE_DELETE_CONSOLE = false
|
||||||
# 是否开启sourcemap
|
# 是否开启sourcemap
|
||||||
VITE_SHOW_SOURCEMAP = false
|
VITE_SHOW_SOURCEMAP = false
|
||||||
|
|||||||
@ -101,6 +101,8 @@
|
|||||||
"dayjs": "1.11.10",
|
"dayjs": "1.11.10",
|
||||||
"echarts": "^6.0.0",
|
"echarts": "^6.0.0",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
|
"jweixin-1.6.0": "^1.0.0",
|
||||||
|
"jweixin-module": "^1.6.0",
|
||||||
"pinia": "2.0.36",
|
"pinia": "2.0.36",
|
||||||
"pinia-plugin-persistedstate": "3.2.1",
|
"pinia-plugin-persistedstate": "3.2.1",
|
||||||
"vue": "3.4.21",
|
"vue": "3.4.21",
|
||||||
|
|||||||
40
pnpm-lock.yaml
generated
40
pnpm-lock.yaml
generated
@ -91,6 +91,12 @@ importers:
|
|||||||
js-cookie:
|
js-cookie:
|
||||||
specifier: ^3.0.5
|
specifier: ^3.0.5
|
||||||
version: 3.0.5
|
version: 3.0.5
|
||||||
|
jweixin-1.6.0:
|
||||||
|
specifier: ^1.0.0
|
||||||
|
version: 1.0.0
|
||||||
|
jweixin-module:
|
||||||
|
specifier: ^1.6.0
|
||||||
|
version: 1.6.0
|
||||||
pinia:
|
pinia:
|
||||||
specifier: 2.0.36
|
specifier: 2.0.36
|
||||||
version: 2.0.36(typescript@5.9.2)(vue@3.4.21(typescript@5.9.2))
|
version: 2.0.36(typescript@5.9.2)(vue@3.4.21(typescript@5.9.2))
|
||||||
@ -240,15 +246,6 @@ importers:
|
|||||||
specifier: ^2.2.10
|
specifier: ^2.2.10
|
||||||
version: 2.2.12(typescript@5.9.2)
|
version: 2.2.12(typescript@5.9.2)
|
||||||
|
|
||||||
src/uni_modules/lime-echart:
|
|
||||||
dependencies:
|
|
||||||
echarts:
|
|
||||||
specifier: ^5.4.1
|
|
||||||
version: 5.6.0
|
|
||||||
zrender:
|
|
||||||
specifier: ^5.4.3
|
|
||||||
version: 5.6.1
|
|
||||||
|
|
||||||
src/uni_modules/mescroll-uni: {}
|
src/uni_modules/mescroll-uni: {}
|
||||||
|
|
||||||
src/uni_modules/uni-icons: {}
|
src/uni_modules/uni-icons: {}
|
||||||
@ -3442,9 +3439,6 @@ packages:
|
|||||||
eastasianwidth@0.2.0:
|
eastasianwidth@0.2.0:
|
||||||
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
|
||||||
|
|
||||||
echarts@5.6.0:
|
|
||||||
resolution: {integrity: sha512-oTbVTsXfKuEhxftHqL5xprgLoc0k7uScAwtryCgWF6hPYFLRwOUHiFmHGCBKP5NPFNkDVopOieyUqYGH8Fa3kA==}
|
|
||||||
|
|
||||||
echarts@6.0.0:
|
echarts@6.0.0:
|
||||||
resolution: {integrity: sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==}
|
resolution: {integrity: sha512-Tte/grDQRiETQP4xz3iZWSvoHrkCQtwqd6hs+mifXcjrCuo2iKWbajFObuLJVBlDIJlOzgQPd1hsaKt/3+OMkQ==}
|
||||||
|
|
||||||
@ -4560,6 +4554,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
|
resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==}
|
||||||
engines: {'0': node >= 0.2.0}
|
engines: {'0': node >= 0.2.0}
|
||||||
|
|
||||||
|
jweixin-1.6.0@1.0.0:
|
||||||
|
resolution: {integrity: sha512-QH69Y/j4h8p9dy6wqIplXmhjLy67AGJswvrjwWUD84HUdB22QyHaX1PmV7oJFbsYL+Vn9Qe1uIx/2NFKkD51Bg==}
|
||||||
|
|
||||||
|
jweixin-module@1.6.0:
|
||||||
|
resolution: {integrity: sha512-dGk9cf+ipipHmtzYmKZs5B2toX+p4hLyllGLF6xuC8t+B05oYxd8fYoaRz0T30U2n3RUv8a4iwvjhA+OcYz52w==}
|
||||||
|
|
||||||
keyv@4.5.4:
|
keyv@4.5.4:
|
||||||
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
|
||||||
|
|
||||||
@ -6459,9 +6459,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-RcDeKFoCQB51dmrrTb1PMIazjTqGuAbFmjPS0/N5hdUNTCRvxGOOBTBFolvIxUcsWhrocI9C0mYDgUwXT6Dwcg==}
|
resolution: {integrity: sha512-RcDeKFoCQB51dmrrTb1PMIazjTqGuAbFmjPS0/N5hdUNTCRvxGOOBTBFolvIxUcsWhrocI9C0mYDgUwXT6Dwcg==}
|
||||||
engines: {HBuilderX: ^3.0.7}
|
engines: {HBuilderX: ^3.0.7}
|
||||||
|
|
||||||
zrender@5.6.1:
|
|
||||||
resolution: {integrity: sha512-OFXkDJKcrlx5su2XbzJvj/34Q3m6PvyCZkVPHGYpcCJ52ek4U/ymZyfuV1nKE23AyBJ51E/6Yr0mhZ7xGTO4ag==}
|
|
||||||
|
|
||||||
zrender@6.0.0:
|
zrender@6.0.0:
|
||||||
resolution: {integrity: sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==}
|
resolution: {integrity: sha512-41dFXEEXuJpNecuUQq6JlbybmnHaqqpGlbH1yxnA5V9MMP4SbohSVZsJIwz+zdjQXSSlR1Vc34EgH1zxyTDvhg==}
|
||||||
|
|
||||||
@ -10585,11 +10582,6 @@ snapshots:
|
|||||||
|
|
||||||
eastasianwidth@0.2.0: {}
|
eastasianwidth@0.2.0: {}
|
||||||
|
|
||||||
echarts@5.6.0:
|
|
||||||
dependencies:
|
|
||||||
tslib: 2.3.0
|
|
||||||
zrender: 5.6.1
|
|
||||||
|
|
||||||
echarts@6.0.0:
|
echarts@6.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.3.0
|
tslib: 2.3.0
|
||||||
@ -12109,6 +12101,10 @@ snapshots:
|
|||||||
|
|
||||||
jsonparse@1.3.1: {}
|
jsonparse@1.3.1: {}
|
||||||
|
|
||||||
|
jweixin-1.6.0@1.0.0: {}
|
||||||
|
|
||||||
|
jweixin-module@1.6.0: {}
|
||||||
|
|
||||||
keyv@4.5.4:
|
keyv@4.5.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
json-buffer: 3.0.1
|
json-buffer: 3.0.1
|
||||||
@ -14175,10 +14171,6 @@ snapshots:
|
|||||||
|
|
||||||
z-paging@2.8.7: {}
|
z-paging@2.8.7: {}
|
||||||
|
|
||||||
zrender@5.6.1:
|
|
||||||
dependencies:
|
|
||||||
tslib: 2.3.0
|
|
||||||
|
|
||||||
zrender@6.0.0:
|
zrender@6.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
tslib: 2.3.0
|
tslib: 2.3.0
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
import { navigateToInterceptor } from '@/router/interceptor'
|
import { navigateToInterceptor } from '@/router/interceptor'
|
||||||
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
|
||||||
import {snsapiBaseAuthorize} from '@/hooks/useWeiXin'
|
import {snsapiBaseAuthorize} from '@/hooks/useWeiXin'
|
||||||
|
import {initJweixinSDK} from '@/utils/jwexin'
|
||||||
|
|
||||||
onLaunch((options) => {
|
onLaunch((options) => {
|
||||||
// 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
|
// 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
|
||||||
@ -16,7 +17,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 微信静默授权
|
// 微信静默授权
|
||||||
snsapiBaseAuthorize()
|
// snsapiBaseAuthorize()
|
||||||
|
initJweixinSDK()
|
||||||
})
|
})
|
||||||
onShow((options) => {
|
onShow((options) => {
|
||||||
console.log('App Show', options)
|
console.log('App Show', options)
|
||||||
|
|||||||
13
src/api/jwexin.ts
Normal file
13
src/api/jwexin.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { http } from '@/http/alova'
|
||||||
|
import type { IJweiXin } from '@/api/types/jwexin'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取微信JSSDK签名
|
||||||
|
*/
|
||||||
|
export interface IJweiXinSignature {
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function wxSignature(data: IJweiXinSignature) {
|
||||||
|
return http.Get<IJweiXin>('/api/wechat/jsConfig', { params: data })
|
||||||
|
}
|
||||||
@ -4,19 +4,28 @@ import { API_DOMAINS, http } from '@/http/alova'
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信静默授权登录参数
|
* 微信静默授权登录
|
||||||
*/
|
*/
|
||||||
export interface IWxSnsapiBaseLoginForm {
|
export interface IWxSnsapiBaseLoginForm {
|
||||||
code: string
|
code: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export function wxSnsapiBaseLogin(data: IWxSnsapiBaseLoginForm) {
|
||||||
* 微信静默授权登录
|
return http.Post<IUserInfoVo>('/api/login/oaLogin', data)
|
||||||
*/
|
|
||||||
export function wxSnsapiBaseLogin(loginForm: IWxSnsapiBaseLoginForm) {
|
|
||||||
return http.Get<IUserLogin>('/login/oaLogin', {params: loginForm})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机验证码登录
|
||||||
|
*/
|
||||||
|
export interface IPhoneLoginForm {
|
||||||
|
account: number,
|
||||||
|
scene: number,
|
||||||
|
terminal: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function phoneLogin(data: IPhoneLoginForm) {
|
||||||
|
return http.Post<IUserLogin>('/api/login/oaLogin', {params: data})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录表单
|
* 登录表单
|
||||||
@ -33,7 +42,7 @@ export interface ILoginForm {
|
|||||||
* @returns ICaptcha 验证码
|
* @returns ICaptcha 验证码
|
||||||
*/
|
*/
|
||||||
export function getCode() {
|
export function getCode() {
|
||||||
return http.Get<ICaptcha>('/user/getCode')
|
return http.Get<ICaptcha>('/api/user/getCode')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,35 +50,35 @@ export function getCode() {
|
|||||||
* @param loginForm 登录表单
|
* @param loginForm 登录表单
|
||||||
*/
|
*/
|
||||||
export function login(loginForm: ILoginForm) {
|
export function login(loginForm: ILoginForm) {
|
||||||
return http.Post<IUserLogin>('/user/login', loginForm)
|
return http.Post<IUserLogin>('/api/user/login', loginForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
*/
|
*/
|
||||||
export function getUserInfo() {
|
export function getUserInfo() {
|
||||||
return http.Get<IUserInfoVo>('/user/info')
|
return http.Get<IUserInfoVo>('/api/user/info')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出登录
|
* 退出登录
|
||||||
*/
|
*/
|
||||||
export function logout() {
|
export function logout() {
|
||||||
return http.Get<void>('/user/logout')
|
return http.Get<void>('/api/user/logout')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户信息
|
* 修改用户信息
|
||||||
*/
|
*/
|
||||||
export function updateInfo(data: IUpdateInfo) {
|
export function updateInfo(data: IUpdateInfo) {
|
||||||
return http.Get('/user/updateInfo', data)
|
return http.Get('/api/user/updateInfo', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改用户密码
|
* 修改用户密码
|
||||||
*/
|
*/
|
||||||
export function updateUserPassword(data: IUpdatePassword) {
|
export function updateUserPassword(data: IUpdatePassword) {
|
||||||
return http.Post('/user/updatePassword', data)
|
return http.Post('/api/user/updatePassword', data)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,5 +105,5 @@ export function getWxCode() {
|
|||||||
* @returns Promise 包含登录结果
|
* @returns Promise 包含登录结果
|
||||||
*/
|
*/
|
||||||
export function wxLogin(data: { code: string }) {
|
export function wxLogin(data: { code: string }) {
|
||||||
return http.Post<IUserLogin>('/user/wxLogin', data)
|
return http.Post<IUserLogin>('/api/user/wxLogin', data)
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/api/types/jwexin.ts
Normal file
13
src/api/types/jwexin.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* JSSDK返回的签名参数
|
||||||
|
*/
|
||||||
|
export interface IJweiXin {
|
||||||
|
appId: string
|
||||||
|
debug: boolean
|
||||||
|
jsApiList: string[]
|
||||||
|
nonceStr: string
|
||||||
|
openTagList: string[]
|
||||||
|
signature: string
|
||||||
|
timestamp: number
|
||||||
|
url: string
|
||||||
|
}
|
||||||
@ -3,9 +3,14 @@
|
|||||||
*/
|
*/
|
||||||
export interface IUserInfoVo {
|
export interface IUserInfoVo {
|
||||||
id: number
|
id: number
|
||||||
username: string
|
nickname: string
|
||||||
avatar: string
|
avatar: string
|
||||||
token: string
|
token: string
|
||||||
|
sn: string
|
||||||
|
account: string
|
||||||
|
channel: number
|
||||||
|
is_new_user: number
|
||||||
|
mobile: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
import {wxSnsapiBaseLogin} from '@/api/login'
|
import {wxSnsapiBaseLogin} from '@/api/login'
|
||||||
// import {setUserInfo, getUserInfo} from '@/store/user'
|
import { useUserStore } from '@/store'
|
||||||
|
import type { IUserInfoVo } from '@/api/types/login'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信静默授权
|
* 微信静默授权
|
||||||
*/
|
*/
|
||||||
@ -22,6 +24,22 @@ const getUrlCode = (): { [key: string]: string | undefined } => {
|
|||||||
* 微信静默授权登录
|
* 微信静默授权登录
|
||||||
*/
|
*/
|
||||||
export function snsapiBaseAuthorize() {
|
export function snsapiBaseAuthorize() {
|
||||||
|
// TODO 测试代码
|
||||||
|
const res = {
|
||||||
|
account: "u39317465",
|
||||||
|
avatar: "https://cz.stnav.com/uploads/user/avatar/c2b3c5f94e3f20c8a989bd302519b4c7.jpeg",
|
||||||
|
channel:2,
|
||||||
|
is_new_user: 1,
|
||||||
|
id: 1,
|
||||||
|
sn:"39317465",
|
||||||
|
token: "14a11310d926121e352afec2ef1d2f7f",
|
||||||
|
nickname: '微信用户',
|
||||||
|
mobile: '15005837859'
|
||||||
|
}
|
||||||
|
useUserStore().setUserInfo(res)
|
||||||
|
console.log(useUserStore().userInfo)
|
||||||
|
return
|
||||||
|
|
||||||
let local = window.location.href // 获取页面url
|
let local = window.location.href // 获取页面url
|
||||||
let appid = import.meta.env.VITE_WX_SERVICE_ACCOUNT_APPID // 公众号的APPID
|
let appid = import.meta.env.VITE_WX_SERVICE_ACCOUNT_APPID // 公众号的APPID
|
||||||
console.log("🚀 ~ snsapiBaseAuthorize ~ appid:", appid)
|
console.log("🚀 ~ snsapiBaseAuthorize ~ appid:", appid)
|
||||||
@ -38,18 +56,17 @@ export function snsapiBaseAuthorize() {
|
|||||||
window.location.href =
|
window.location.href =
|
||||||
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
|
`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect`
|
||||||
} else {
|
} else {
|
||||||
console.log('存在code,使用code换取用户信息')
|
|
||||||
// 保存最新code
|
// 保存最新code
|
||||||
uni.setStorageSync('wechatCode',code)
|
uni.setStorageSync('wechatCode',code)
|
||||||
console.log("🚀 ~ snsapiBaseAuthorize ~ code:", code)
|
|
||||||
|
|
||||||
// 使用code换取用户信息
|
// 使用code换取用户信息
|
||||||
wxSnsapiBaseLogin({code}).then(res=>{
|
wxSnsapiBaseLogin({code}).then((res: IUserInfoVo) => {
|
||||||
console.log("🚀 ~ snsapiBaseAuthorize ~ res:", res)
|
console.log("登录成功 ~ snsapiBaseAuthorize ~ res:", res)
|
||||||
|
// 映射 IUserLogin 到 IUserInfoVo
|
||||||
}).catch(err=>{
|
useUserStore().setUserInfo(res)
|
||||||
|
console.log('登录成功 ~ ' + useUserStore().userInfo)
|
||||||
|
}).catch(err => {
|
||||||
// 失败就重新授权
|
// 失败就重新授权
|
||||||
uni.setStorageSync('wechatCode',0)
|
uni.setStorageSync('wechatCode', 0)
|
||||||
console.log('请求失败', err)
|
console.log('请求失败', err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import { createServerTokenAuthentication } from 'alova/client'
|
|||||||
import VueHook from 'alova/vue'
|
import VueHook from 'alova/vue'
|
||||||
import { toast } from '@/utils/toast'
|
import { toast } from '@/utils/toast'
|
||||||
import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum'
|
import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum'
|
||||||
|
import { useUserStore } from '@/store'
|
||||||
|
|
||||||
// 配置动态Tag
|
// 配置动态Tag
|
||||||
export const API_DOMAINS = {
|
export const API_DOMAINS = {
|
||||||
@ -87,6 +88,11 @@ const alovaInstance = createAlova({
|
|||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (statusCode === ResultEnum.Unauthorized) {
|
||||||
|
useUserStore().removeUserInfo()
|
||||||
|
uni.navigateTo({ url: '/pages/login/mobile' })
|
||||||
|
}
|
||||||
|
|
||||||
// 处理 HTTP 状态码错误
|
// 处理 HTTP 状态码错误
|
||||||
// if (statusCode !== 200) {
|
// if (statusCode !== 200) {
|
||||||
// const errorMessage = ShowMessage(statusCode) || `HTTP请求错误[${statusCode}]`
|
// const errorMessage = ShowMessage(statusCode) || `HTTP请求错误[${statusCode}]`
|
||||||
@ -97,12 +103,12 @@ const alovaInstance = createAlova({
|
|||||||
|
|
||||||
// 处理业务逻辑错误
|
// 处理业务逻辑错误
|
||||||
const { code, message, data } = rawData as IResponse
|
const { code, message, data } = rawData as IResponse
|
||||||
// if (code !== ResultEnum.Success) {
|
if (code !== ResultEnum.Success) {
|
||||||
// if (config.meta?.toast !== false) {
|
if (config.meta?.toast !== false) {
|
||||||
// toast.warning(message)
|
toast.warning(message)
|
||||||
// }
|
}
|
||||||
// throw new Error(`请求错误[${code}]:${message}`)
|
throw new Error(`请求错误[${code}]:${message}`)
|
||||||
// }
|
}
|
||||||
// 处理成功响应,返回业务数据
|
// 处理成功响应,返回业务数据
|
||||||
return data
|
return data
|
||||||
}),
|
}),
|
||||||
|
|||||||
@ -21,6 +21,7 @@ const httpInterceptor = {
|
|||||||
options.url += `?${queryStr}`
|
options.url += `?${queryStr}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 非 http 开头需拼接地址
|
// 非 http 开头需拼接地址
|
||||||
if (!options.url.startsWith('http')) {
|
if (!options.url.startsWith('http')) {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
@ -32,6 +33,7 @@ const httpInterceptor = {
|
|||||||
else {
|
else {
|
||||||
options.url = baseUrl + options.url
|
options.url = baseUrl + options.url
|
||||||
}
|
}
|
||||||
|
|
||||||
// #endif
|
// #endif
|
||||||
// 非H5正常拼接
|
// 非H5正常拼接
|
||||||
// #ifndef H5
|
// #ifndef H5
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
export enum ResultEnum {
|
export enum ResultEnum {
|
||||||
Success = 0, // 成功
|
Success = 1, // 成功
|
||||||
Error = 400, // 错误
|
Error = 0, // 错误
|
||||||
Unauthorized = 401, // 未授权
|
Unauthorized = 401, // 未授权
|
||||||
Forbidden = 403, // 禁止访问(原为forbidden)
|
Forbidden = 403, // 禁止访问(原为forbidden)
|
||||||
NotFound = 404, // 未找到(原为notFound)
|
NotFound = 404, // 未找到(原为notFound)
|
||||||
|
|||||||
@ -1,67 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "",
|
|
||||||
"appid": "",
|
|
||||||
"description": "",
|
|
||||||
"versionName": "1.0.0",
|
|
||||||
"versionCode": "100",
|
|
||||||
"transformPx": false,
|
|
||||||
"app-plus": {
|
|
||||||
"usingComponents": true,
|
|
||||||
"nvueStyleCompiler": "uni-app",
|
|
||||||
"compilerVersion": 3,
|
|
||||||
"splashscreen": {
|
|
||||||
"alwaysShowBeforeRender": true,
|
|
||||||
"waiting": true,
|
|
||||||
"autoclose": true,
|
|
||||||
"delay": 0
|
|
||||||
},
|
|
||||||
"modules": {},
|
|
||||||
"distribute": {
|
|
||||||
"android": {
|
|
||||||
"permissions": []
|
|
||||||
},
|
|
||||||
"ios": {},
|
|
||||||
"sdkConfigs": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"quickapp": {},
|
|
||||||
"mp-weixin": {
|
|
||||||
"appid": "",
|
|
||||||
"setting": {
|
|
||||||
"urlCheck": false
|
|
||||||
},
|
|
||||||
"usingComponents": true
|
|
||||||
},
|
|
||||||
"mp-alipay": {
|
|
||||||
"usingComponents": true
|
|
||||||
},
|
|
||||||
"mp-baidu": {
|
|
||||||
"usingComponents": true
|
|
||||||
},
|
|
||||||
"mp-toutiao": {
|
|
||||||
"usingComponents": true
|
|
||||||
},
|
|
||||||
"uniStatistics": {
|
|
||||||
"enable": false
|
|
||||||
},
|
|
||||||
"vueVersion": "3",
|
|
||||||
"default": {
|
|
||||||
"name": "茶址",
|
"name": "茶址",
|
||||||
"appid": "__UNI__D1E5001",
|
"appid": "__UNI__D1E5001",
|
||||||
"description": "",
|
"description": "",
|
||||||
"versionName": "1.0.0",
|
"versionName": "1.0.0",
|
||||||
"versionCode": "100",
|
"versionCode": "100",
|
||||||
"transformPx": false,
|
"transformPx": false,
|
||||||
"h5": {
|
|
||||||
"router": {}
|
|
||||||
},
|
|
||||||
"app-plus": {
|
"app-plus": {
|
||||||
"usingComponents": true,
|
"usingComponents": true,
|
||||||
"nvueStyleCompiler": "uni-app",
|
"nvueStyleCompiler": "uni-app",
|
||||||
"compilerVersion": 3,
|
"compilerVersion": 3,
|
||||||
"compatible": {
|
|
||||||
"ignoreVersion": true
|
|
||||||
},
|
|
||||||
"splashscreen": {
|
"splashscreen": {
|
||||||
"alwaysShowBeforeRender": true,
|
"alwaysShowBeforeRender": true,
|
||||||
"waiting": true,
|
"waiting": true,
|
||||||
@ -71,12 +18,6 @@
|
|||||||
"modules": {},
|
"modules": {},
|
||||||
"distribute": {
|
"distribute": {
|
||||||
"android": {
|
"android": {
|
||||||
"minSdkVersion": 30,
|
|
||||||
"targetSdkVersion": 30,
|
|
||||||
"abiFilters": [
|
|
||||||
"armeabi-v7a",
|
|
||||||
"arm64-v8a"
|
|
||||||
],
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
@ -93,6 +34,12 @@
|
|||||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||||
|
],
|
||||||
|
"minSdkVersion": 30,
|
||||||
|
"targetSdkVersion": 30,
|
||||||
|
"abiFilters": [
|
||||||
|
"armeabi-v7a",
|
||||||
|
"arm64-v8a"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"ios": {},
|
"ios": {},
|
||||||
@ -129,6 +76,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"compatible": {
|
||||||
|
"ignoreVersion": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"quickapp": {},
|
"quickapp": {},
|
||||||
@ -139,10 +89,10 @@
|
|||||||
"es6": true,
|
"es6": true,
|
||||||
"minified": true
|
"minified": true
|
||||||
},
|
},
|
||||||
|
"usingComponents": true,
|
||||||
"optimization": {
|
"optimization": {
|
||||||
"subPackages": true
|
"subPackages": true
|
||||||
},
|
}
|
||||||
"usingComponents": true
|
|
||||||
},
|
},
|
||||||
"mp-alipay": {
|
"mp-alipay": {
|
||||||
"usingComponents": true,
|
"usingComponents": true,
|
||||||
@ -157,6 +107,8 @@
|
|||||||
"uniStatistics": {
|
"uniStatistics": {
|
||||||
"enable": false
|
"enable": false
|
||||||
},
|
},
|
||||||
"vueVersion": "3"
|
"vueVersion": "3",
|
||||||
|
"h5": {
|
||||||
|
"router": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +133,7 @@
|
|||||||
{
|
{
|
||||||
"path": "pages/my/my",
|
"path": "pages/my/my",
|
||||||
"type": "page",
|
"type": "page",
|
||||||
|
"needLogin": true,
|
||||||
"layout": "tabbar",
|
"layout": "tabbar",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
|
|||||||
@ -149,6 +149,7 @@
|
|||||||
import {TeaSpecialistLevels} from '@/utils/teaSpecialist'
|
import {TeaSpecialistLevels} from '@/utils/teaSpecialist'
|
||||||
import TeaSpecialistLevel from '@/components/TeaSpecialistLevel.vue'
|
import TeaSpecialistLevel from '@/components/TeaSpecialistLevel.vue'
|
||||||
import { OrderSource, OrderStatus } from '@/utils/order'
|
import { OrderSource, OrderStatus } from '@/utils/order'
|
||||||
|
import {getlocation} from '@/utils/jwexin'
|
||||||
|
|
||||||
const OSS = inject('OSS')
|
const OSS = inject('OSS')
|
||||||
|
|
||||||
@ -159,6 +160,9 @@
|
|||||||
const { mescrollInit, downCallback } = useMescroll(onPageScroll, onReachBottom) // 调用mescroll的hook
|
const { mescrollInit, downCallback } = useMescroll(onPageScroll, onReachBottom) // 调用mescroll的hook
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
|
getlocation((res) => {
|
||||||
|
console.log('经纬度:' + res.latitude + ',' + res.longitude)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const Index = {
|
const Index = {
|
||||||
@ -231,7 +235,7 @@
|
|||||||
// 跳转到团体预约页面
|
// 跳转到团体预约页面
|
||||||
handleToGroupReserve: () => {
|
handleToGroupReserve: () => {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/pages/reservve/group-tea-specialist'
|
url: '/pages/reserve/group-tea-specialist'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,10 +250,10 @@
|
|||||||
.tea-level-scrollbar {
|
.tea-level-scrollbar {
|
||||||
&::-webkit-scrollbar {
|
&::-webkit-scrollbar {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
|
||||||
-ms-overflow-style: none;
|
-ms-overflow-style: none;
|
||||||
scrollbar-width: none;
|
scrollbar-width: none;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.home-bg {
|
.home-bg {
|
||||||
background-color: $cz-page-background;
|
background-color: $cz-page-background;
|
||||||
|
|||||||
@ -94,7 +94,7 @@
|
|||||||
|
|
||||||
/** 页面 **/
|
/** 页面 **/
|
||||||
let pageType = 'login' // 页面类型 login:登录 edit:修改手机号
|
let pageType = 'login' // 页面类型 login:登录 edit:修改手机号
|
||||||
const page = ref<{title: string, desc: string}>({title: '其他手机号登录', desc: '请输入你要登录的手机号'})
|
const page = ref<{title: string, desc: string}>({title: '绑定手机号', desc: '请输入你要绑定的手机号'})
|
||||||
const showEditSuccessPopup = ref<boolean>(false) // 显示手机号修改成功弹窗
|
const showEditSuccessPopup = ref<boolean>(false) // 显示手机号修改成功弹窗
|
||||||
const userId = ref<number>(0) // 用户ID,修改手机号时需要传
|
const userId = ref<number>(0) // 用户ID,修改手机号时需要传
|
||||||
|
|
||||||
@ -218,7 +218,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss" scoped>
|
||||||
page {
|
page {
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<route lang="jsonc" type="page">
|
<route lang="jsonc" type="page">
|
||||||
{
|
{
|
||||||
|
"needLogin": true,
|
||||||
"layout": "tabbar",
|
"layout": "tabbar",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationStyle": "custom"
|
"navigationStyle": "custom"
|
||||||
@ -25,13 +26,13 @@
|
|||||||
<view>
|
<view>
|
||||||
<wd-img width="120rpx" height="120rpx" :src="`${OSS}icon/icon_avatar.png`" mode="aspectFill" round />
|
<wd-img width="120rpx" height="120rpx" :src="`${OSS}icon/icon_avatar.png`" mode="aspectFill" round />
|
||||||
</view>
|
</view>
|
||||||
<view class="flex-1 ml-22rpx flex justify-between items-center">
|
<view class="flex-1 ml-22rpx flex justify-between items-center" @click="My.handleToProfile">
|
||||||
<view @click="My.handleToProfile">
|
<view>
|
||||||
<view class="text-[#303133] text-36rpx leading-50rpx ml-8rpx">{{ isLogin ? '王大帅' : '立即登录' }}</view>
|
<view class="text-[#303133] text-36rpx leading-50rpx ml-8rpx">{{ isLogin ? userInfo.nickname : '立即登录' }}</view>
|
||||||
<view v-if="isLogin" class="flex justify-center items-center vip-bg mt-10rpx">
|
<view v-if="isLogin" class="flex justify-center items-center vip-bg mt-10rpx" >
|
||||||
<!-- 会员显示图标 -->
|
<!-- 会员显示图标 -->
|
||||||
<view v-if="isVip" class="flex items-center mr-12rpx">
|
<view v-if="isVip" class="flex items-center mr-12rpx">
|
||||||
<wd-img width="36rpx" height="36rpx" mode="aspectFill" :src="`${OSS}icon/icon_crown.png`" round></wd-img>
|
<wd-img width="36rpx" height="36rpx" mode="aspectFill" :src="userInfo.avatar" round></wd-img>
|
||||||
</view>
|
</view>
|
||||||
<!-- 这里要根据用户身份显示不同的文字 -->
|
<!-- 这里要根据用户身份显示不同的文字 -->
|
||||||
<view class="text-24rpx text-[#675649] leading-34rpx flex items-center">茶址会员</view>
|
<view class="text-24rpx text-[#675649] leading-34rpx flex items-center">茶址会员</view>
|
||||||
@ -180,6 +181,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import {OrderStatus} from '@/utils/order'
|
import {OrderStatus} from '@/utils/order'
|
||||||
import {toast} from '@/utils/toast'
|
import {toast} from '@/utils/toast'
|
||||||
|
import { useUserStore } from '@/store'
|
||||||
|
|
||||||
const OSS = inject('OSS')
|
const OSS = inject('OSS')
|
||||||
const navbarHeight = inject('navbarHeight')
|
const navbarHeight = inject('navbarHeight')
|
||||||
@ -187,7 +189,7 @@
|
|||||||
|
|
||||||
// 登录信息相关
|
// 登录信息相关
|
||||||
const userInfo = ref<any>(null)
|
const userInfo = ref<any>(null)
|
||||||
const isLogin = ref<boolean>(true)
|
const isLogin = ref<boolean>(false)
|
||||||
const isVip = ref<boolean>(true)
|
const isVip = ref<boolean>(true)
|
||||||
|
|
||||||
// 茶艺师订单
|
// 茶艺师订单
|
||||||
@ -209,18 +211,19 @@
|
|||||||
// 领取优惠券
|
// 领取优惠券
|
||||||
const isClaimCoupon = ref<boolean>(false)
|
const isClaimCoupon = ref<boolean>(false)
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
const userStore = useUserStore()
|
||||||
|
if (userStore.userInfo.mobile) {
|
||||||
|
userInfo.value = userStore.userInfo
|
||||||
|
isLogin.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
onLoad(() => {
|
onLoad(() => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const My = {
|
const My = {
|
||||||
// 跳转到个人信息
|
|
||||||
handleToProfile: () => {
|
|
||||||
uni.navigateTo({
|
|
||||||
url: '/bundle/profile/profile'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
// 点击显示客服电话
|
// 点击显示客服电话
|
||||||
handleShowService: () => {
|
handleShowService: () => {
|
||||||
showServiceMobile.value = true
|
showServiceMobile.value = true
|
||||||
@ -250,6 +253,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 跳转到个人信息
|
||||||
|
handleToProfile: () => {
|
||||||
|
if (isLogin.value) {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/bundle/profile/profile'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/login/mobile'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 跳转到会员权益
|
// 跳转到会员权益
|
||||||
handleToVipBenefits: () => {
|
handleToVipBenefits: () => {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
@ -280,8 +296,8 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss" scoped>
|
||||||
page, home-bg{
|
page, home-bg {
|
||||||
background: $cz-page-background url(#{$OSS}images/my/my_image1.png) 0 0 no-repeat;
|
background: $cz-page-background url(#{$OSS}images/my/my_image1.png) 0 0 no-repeat;
|
||||||
background-size: 100%;
|
background-size: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,8 @@ const loginRoute = import.meta.env.VITE_LOGIN_URL
|
|||||||
|
|
||||||
function isLogined() {
|
function isLogined() {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
return !!userStore.userInfo.username
|
// 如果没有手机号或者token,就认为没有登录(需要绑定手机号)
|
||||||
|
return !!userStore.userInfo.mobile && !!userStore.userInfo.token
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDev = import.meta.env.DEV
|
const isDev = import.meta.env.DEV
|
||||||
|
|||||||
@ -10,12 +10,19 @@ import {
|
|||||||
} from '@/api/login'
|
} from '@/api/login'
|
||||||
import { toast } from '@/utils/toast'
|
import { toast } from '@/utils/toast'
|
||||||
|
|
||||||
|
const defaultAvatar = 'https://shchazhi.oss-cn-hangzhou.aliyuncs.com/fronted/icon/icon_avatar.png'
|
||||||
|
|
||||||
// 初始化状态
|
// 初始化状态
|
||||||
const userInfoState: IUserInfoVo = {
|
const userInfoState: IUserInfoVo = {
|
||||||
id: 0,
|
id: 0,
|
||||||
username: '',
|
nickname: '',
|
||||||
avatar: '/static/images/default-avatar.png',
|
avatar: defaultAvatar,
|
||||||
token: '',
|
token: '',
|
||||||
|
sn: '',
|
||||||
|
account: '',
|
||||||
|
channel: 0,
|
||||||
|
is_new_user: 1,
|
||||||
|
mobile: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUserStore = defineStore(
|
export const useUserStore = defineStore(
|
||||||
@ -31,7 +38,7 @@ export const useUserStore = defineStore(
|
|||||||
val.avatar = userInfoState.avatar
|
val.avatar = userInfoState.avatar
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val.avatar = 'https://oss.laf.run/ukw0y1-site/avatar.jpg?feige'
|
val.avatar = defaultAvatar
|
||||||
}
|
}
|
||||||
userInfo.value = val
|
userInfo.value = val
|
||||||
}
|
}
|
||||||
@ -103,6 +110,8 @@ export const useUserStore = defineStore(
|
|||||||
getUserInfo,
|
getUserInfo,
|
||||||
setUserAvatar,
|
setUserAvatar,
|
||||||
logout,
|
logout,
|
||||||
|
setUserInfo,
|
||||||
|
removeUserInfo
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
76
src/utils/jwexin.ts
Normal file
76
src/utils/jwexin.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import wx from 'jweixin-1.6.0'
|
||||||
|
import {wxSignature} from '@/api/jwexin'
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
entryUrl?: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isWechat() {
|
||||||
|
const ua = window.navigator.userAgent.toLowerCase();
|
||||||
|
if (ua.match(/micromessenger/i) !== null) {
|
||||||
|
//console.log('是微信客户端')
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
//console.log('不是微信客户端')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function initJweixinSDK(callback: (res?: any) => void = () => {}) {
|
||||||
|
if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
|
||||||
|
window.entryUrl = location.href.split('#')[0]
|
||||||
|
console.log("🚀 ~ initJweixin ~ window.entryUrl:", window.entryUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
let isiOS = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
|
||||||
|
// 进行签名的时候 Android 不用使用之前的链接, ios 需要
|
||||||
|
let signLink = isiOS ? window.entryUrl : location.href.split('#')[0];
|
||||||
|
console.log('-----------当前签名url--------------')
|
||||||
|
console.log(signLink)
|
||||||
|
// var uri = encodeURIComponent(location.href.split('#')[0]); //获取当前url然后传递给后台获取授权和签名信息
|
||||||
|
let url = encodeURIComponent(signLink); //获取当前url然后传递给后台获取授权和签名信息
|
||||||
|
wxSignature({ url }).then((res) => {
|
||||||
|
console.log("🚀 ~ initJweixin ~ res:", res)
|
||||||
|
wx.config({
|
||||||
|
debug: false,
|
||||||
|
appId: res.appId,
|
||||||
|
timestamp: res.timestamp,
|
||||||
|
nonceStr: res.nonceStr,
|
||||||
|
signature: res.signature,
|
||||||
|
jsApiList: res.jsApiList
|
||||||
|
});
|
||||||
|
wx.ready(function() {
|
||||||
|
console.log('config注入成功')
|
||||||
|
if (callback) {
|
||||||
|
callback(res)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getlocation(callback: (res: any) => void ) {
|
||||||
|
if (!isWechat()) {
|
||||||
|
//console.log('不是微信客户端')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
initJweixinSDK(function(res) {
|
||||||
|
wx.ready(function() {
|
||||||
|
wx.getLocation({
|
||||||
|
type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
|
||||||
|
success: function(res) {
|
||||||
|
// console.log(res);
|
||||||
|
callback(res)
|
||||||
|
},
|
||||||
|
fail: function(res) {
|
||||||
|
console.log('经纬度:' + res)
|
||||||
|
},
|
||||||
|
// complete:function(res){
|
||||||
|
// console.log(res)
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user