|
@@ -1,16 +1,16 @@
|
|
|
-// import store from '@/store'
|
|
|
|
|
|
|
+import store from '@/store'
|
|
|
// #ifdef H5
|
|
// #ifdef H5
|
|
|
import jweixin from 'jweixin-module'
|
|
import jweixin from 'jweixin-module'
|
|
|
// #endif
|
|
// #endif
|
|
|
-import { share } from '@/mixins'
|
|
|
|
|
-import Util from '@/utils/util'
|
|
|
|
|
-
|
|
|
|
|
-// import {
|
|
|
|
|
-// getBasicUserApi,
|
|
|
|
|
-// getUserApi,
|
|
|
|
|
-// checkLogin,
|
|
|
|
|
-// getRoleRealApi
|
|
|
|
|
-// } from '@/api/system'
|
|
|
|
|
|
|
+// import { share } from '@/mixins'
|
|
|
|
|
+import CONSTANT from '@/constant'
|
|
|
|
|
+import UTIL from '@/utils/util'
|
|
|
|
|
+
|
|
|
|
|
+import {
|
|
|
|
|
+ getUserApi
|
|
|
|
|
+ // checkLogin,
|
|
|
|
|
+ // getRoleRealApi
|
|
|
|
|
+} from '@/api/common'
|
|
|
// import { postWxCode } from '@/api/login'
|
|
// import { postWxCode } from '@/api/login'
|
|
|
|
|
|
|
|
// import util from './util'
|
|
// import util from './util'
|
|
@@ -43,26 +43,25 @@ import Util from '@/utils/util'
|
|
|
// return userInfo
|
|
// return userInfo
|
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
-// /**
|
|
|
|
|
-// * 获取后台用户信息
|
|
|
|
|
-// * @parmas update为true时会重新触发请求,重置vuex的数据
|
|
|
|
|
-// */
|
|
|
|
|
-// export async function getUser(update) {
|
|
|
|
|
-// let userInfo = store.getters.getUser
|
|
|
|
|
-// if (!util.isEmpty(userInfo) && !update) {
|
|
|
|
|
-// return userInfo
|
|
|
|
|
-// }
|
|
|
|
|
-// await getUserApi().then((res) => {
|
|
|
|
|
-// userInfo = res.data
|
|
|
|
|
-// store.dispatch('setUser', userInfo)
|
|
|
|
|
-// uni.setStorageSync('user_id', res.data.user_id)
|
|
|
|
|
-// }).catch(() => {
|
|
|
|
|
-// uni.removeStorageSync('token')
|
|
|
|
|
-// uni.removeStorageSync('user_id')
|
|
|
|
|
-// })
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 获取后台用户信息
|
|
|
|
|
+ * @parmas update为true时会重新触发请求,重置vuex的数据
|
|
|
|
|
+ */
|
|
|
|
|
+export async function getUser(update) {
|
|
|
|
|
+ let userInfo = store.getters.getUser
|
|
|
|
|
+ if (!UTIL.isEmpty(userInfo) && !update) {
|
|
|
|
|
+ return userInfo
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(getUserApi)
|
|
|
|
|
+ await getUserApi().then((res) => {
|
|
|
|
|
+ userInfo = res.data
|
|
|
|
|
+ store.dispatch('setUser', userInfo)
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ uni.removeStorageSync('token')
|
|
|
|
|
+ })
|
|
|
|
|
|
|
|
-// return userInfo
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ return userInfo
|
|
|
|
|
+}
|
|
|
// /**
|
|
// /**
|
|
|
// * 清除vuex的用户信息,目前包含(basicUser, user)
|
|
// * 清除vuex的用户信息,目前包含(basicUser, user)
|
|
|
// * @parmas 暂无,可扩展
|
|
// * @parmas 暂无,可扩展
|
|
@@ -98,56 +97,56 @@ import Util from '@/utils/util'
|
|
|
*/
|
|
*/
|
|
|
// let wxLoginFrist = true
|
|
// let wxLoginFrist = true
|
|
|
export async function wxLoginFn(update) {
|
|
export async function wxLoginFn(update) {
|
|
|
- // let params = {
|
|
|
|
|
- // appid: 'wxad348eb41eda2363',
|
|
|
|
|
- // redirect_uri: encodeURI('https://www.meijiabang.com'),
|
|
|
|
|
- // response_type: 'code',
|
|
|
|
|
- // scope: 'snsapi_base'
|
|
|
|
|
- // }
|
|
|
|
|
- // let oauthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
|
|
|
|
|
- // console.log(oauthUrl)
|
|
|
|
|
- // window.location.href = oauthUrl
|
|
|
|
|
- // uni.redirectTo({
|
|
|
|
|
- // url: `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
|
|
|
|
|
- // })
|
|
|
|
|
- // share.methods.getWeiXinOptin()
|
|
|
|
|
- return false
|
|
|
|
|
- let dataInfo = null
|
|
|
|
|
- let loginInfo = store.state.login.loginInfo
|
|
|
|
|
- if (!util.isEmpty(loginInfo) && !update) {
|
|
|
|
|
- return loginInfo
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // #ifdef H5
|
|
|
|
|
- jweixin.ready(function() {
|
|
|
|
|
-
|
|
|
|
|
- })
|
|
|
|
|
- // #endif
|
|
|
|
|
- // // #ifdef MP-WEIXIN
|
|
|
|
|
- // wxLoginFrist = false
|
|
|
|
|
- let getObj = await new Promise(resolve => {
|
|
|
|
|
- uni.login({
|
|
|
|
|
- provider: 'weixin',
|
|
|
|
|
- success: res => {
|
|
|
|
|
- uni.setStorageSync('code', res.code)
|
|
|
|
|
- console.log(res.code, 'res.code')
|
|
|
|
|
- resolve(res)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
- // // #endif
|
|
|
|
|
-
|
|
|
|
|
- await postWxCode({ code: getObj.code }).then(subRes => {
|
|
|
|
|
- const { openid, session_key, unionid } = subRes.data
|
|
|
|
|
- dataInfo = subRes.data
|
|
|
|
|
- store.commit('setLoginInfo', {
|
|
|
|
|
- openid,
|
|
|
|
|
- session_key,
|
|
|
|
|
- unionid
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+// // let params = {
|
|
|
|
|
+// // appid: 'wxad348eb41eda2363',
|
|
|
|
|
+// // redirect_uri: encodeURI('https://www.meijiabang.com'),
|
|
|
|
|
+// // response_type: 'code',
|
|
|
|
|
+// // scope: 'snsapi_base'
|
|
|
|
|
+// // }
|
|
|
|
|
+// // let oauthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
|
|
|
|
|
+// // console.log(oauthUrl)
|
|
|
|
|
+// // window.location.href = oauthUrl
|
|
|
|
|
+// // uni.redirectTo({
|
|
|
|
|
+// // url: `https://open.weixin.qq.com/connect/oauth2/authorize${Util.parse(params)}#wechat_redirect`
|
|
|
|
|
+// // })
|
|
|
|
|
+// // share.methods.getWeiXinOptin()
|
|
|
|
|
+// return false
|
|
|
|
|
+// let dataInfo = null
|
|
|
|
|
+// let loginInfo = store.state.login.loginInfo
|
|
|
|
|
+// if (!util.isEmpty(loginInfo) && !update) {
|
|
|
|
|
+// return loginInfo
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
- return dataInfo
|
|
|
|
|
|
|
+ // // #ifdef H5
|
|
|
|
|
+ // jweixin.ready(function() {
|
|
|
|
|
+
|
|
|
|
|
+ // })
|
|
|
|
|
+ // // #endif
|
|
|
|
|
+ // // // #ifdef MP-WEIXIN
|
|
|
|
|
+ // // wxLoginFrist = false
|
|
|
|
|
+ // let getObj = await new Promise(resolve => {
|
|
|
|
|
+ // uni.login({
|
|
|
|
|
+ // provider: 'weixin',
|
|
|
|
|
+ // success: res => {
|
|
|
|
|
+ // uni.setStorageSync('code', res.code)
|
|
|
|
|
+ // console.log(res.code, 'res.code')
|
|
|
|
|
+ // resolve(res)
|
|
|
|
|
+ // }
|
|
|
|
|
+ // })
|
|
|
|
|
+ // })
|
|
|
|
|
+ // // // #endif
|
|
|
|
|
+
|
|
|
|
|
+ // await postWxCode({ code: getObj.code }).then(subRes => {
|
|
|
|
|
+ // const { openid, session_key, unionid } = subRes.data
|
|
|
|
|
+ // dataInfo = subRes.data
|
|
|
|
|
+ // store.commit('setLoginInfo', {
|
|
|
|
|
+ // openid,
|
|
|
|
|
+ // session_key,
|
|
|
|
|
+ // unionid
|
|
|
|
|
+ // })
|
|
|
|
|
+ // })
|
|
|
|
|
+
|
|
|
|
|
+// return dataInfo
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -158,6 +157,8 @@ export async function getCheckLogin() {
|
|
|
let token = uni.getStorageSync('token')
|
|
let token = uni.getStorageSync('token')
|
|
|
if (token) {
|
|
if (token) {
|
|
|
status = true
|
|
status = true
|
|
|
|
|
+ } else {
|
|
|
|
|
+ location.href = `${CONSTANT.hostUrl}/auth/prepare?url=${encodeURIComponent(getMiniAppUrl(this.option, true))}`
|
|
|
}
|
|
}
|
|
|
// await checkLogin().then((res) => {
|
|
// await checkLogin().then((res) => {
|
|
|
// if (res.status === 'success') {
|
|
// if (res.status === 'success') {
|