Commit 1bfd8d22 by 张立顺

Merge branch 'develop' of 192.168.3.233:saas_plus/business-assistant into develop

2 parents 9b49f4ca 0df974e1
import api from '~/utils/request/request' import api from '~/utils/request/request'
const { appId } = wx.getAccountInfoSync().miniProgram const {
appId
} = wx.getAccountInfoSync().miniProgram
class UsersApi { class UsersApi {
/**调用后台接口获取用户信息 */ /**调用后台接口获取用户信息js_code换取sessionId */
async login() { async wxCodeLogin() {
return this.getWxCode().then(({ code }) => { const {
return api.post( code
{ } = await this.getWxCode()
method: 'scrm.api.sso.weapp.jscode.login', return await api.post({
appId, method: 'scrm.api.sso.wechat.applets.jscode.login',
code appId,
}, code
true },
) true
}) )
}
/**退出登录 */
logout() {
return api.post({
method: 'scrm.api.sso.wechat.applets.logout'
},
true
)
} }
/**调用接口获取登录凭证(code)。通过凭证进而换取用户登录态信息,包括用户在当前小程序的唯一标识(openid)、微信开放平台帐号下的唯一标识(unionid,若当前小程序已绑定到微信开放平台帐号)及本次登录的会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 */ /**调用接口获取登录凭证(code)。通过凭证进而换取用户登录态信息,包括用户在当前小程序的唯一标识(openid)、微信开放平台帐号下的唯一标识(unionid,若当前小程序已绑定到微信开放平台帐号)及本次登录的会话密钥(session_key)等。用户数据的加解密通讯需要依赖会话密钥完成。 */
getWxCode() { getWxCode() {
...@@ -23,39 +33,75 @@ class UsersApi { ...@@ -23,39 +33,75 @@ class UsersApi {
}) })
}) })
} }
/**授权手机号 */ /**授权手机号登录 */
async authUserPhone(detail, sessionId) { async authUserPhone(detail, loginToken) {
if (!sessionId) { if (!loginToken) {
wx.$api.showToast('缺少sessionId') wx.$api.showToast('缺少loginToken')
Promise.reject() Promise.reject()
return
} }
if (detail.errMsg && detail.errMsg == 'getPhoneNumber:fail user deny') Promise.reject() if (detail.errMsg && detail.errMsg == 'getPhoneNumber:fail user deny') Promise.reject()
delete detail.errMsg delete detail.errMsg
if (detail.iv && detail.encryptedData) { if (detail.iv && detail.encryptedData) {
wx.$api.showLoading() detail.loginToken = loginToken
detail.sessionId = sessionId return api.post({
return api.post( method: 'scrm.api.sso.wechat.applets.auth.phone',
{ ...detail,
method: 'scrm.api.sso.weapp.auth.phone', platformEntrance: 'BUSINESS_ASSISTANT', // 平台标识:生意助手-BUSINESS_ASSISTANT,门店助手-STORE_ASSISTANT
...detail
}, },
true true
) )
} else Promise.reject() } else Promise.reject()
} }
/**更新客户手机号 */ /**账号密码登录 */
updataCustomerPhone() { accountLogin(data = {}) {
let customerId = wx.$storage.get('srcm_shopmall_customer_id'), return api.post({
merchantId = wx.$storage.get('srcm_shopmall_merchant_id') method: 'scrm.api.sso.wechat.applets.password.login',
api ...data,
.post({ platformEntrance: 'BUSINESS_ASSISTANT',
method: 'scrm.api.sso.weapp.mark.phone', },
customerId, true
merchantId )
}) }
.then(() => { /** 手机号获取短信验证码 */
wx.removeStorageSync('srcm_shopmall_customer_id') getSmsCode(mobile) {
}) return api.post({
method: 'scrm.api.sso.wechat.applets.sms.get.code',
mobile
},
true
)
}
/** 手机号短信验证码登录 */
phoneSmsLogin(data = {}) {
return api.post({
method: 'scrm.api.sso.wechat.applets.sms.login',
...data,
source: 'MINIAPP',
platformEntrance: 'BUSINESS_ASSISTANT'
},
true
)
}
/** 获取登录账号列表 */
getAccountList() {
return api.post({
method: 'scrm.api.sso.wechat.applets.listSelectAccount',
platformEntrance: 'BUSINESS_ASSISTANT'
},
true
)
}
/**
* 选择账号登录(手机绑定多个账号时) */
selectAccountLogin(data) {
return api.post({
method: 'scrm.api.sso.wechat.applets.selectAccountLogin',
platformEntrance: 'BUSINESS_ASSISTANT',
...data
},
true
)
} }
} }
export default UsersApi export default UsersApi
\ No newline at end of file \ No newline at end of file
{ {
"pages": ["login/loading/loading", "pages/tab/index/index", "pages/tab/output/output", "pages/tab/mine/mine", "pages/webView/webView", "login/index/index"], "pages": ["login/loading/loading", "pages/tab/index/index", "pages/tab/output/output", "pages/tab/mine/mine", "pages/webView/webView", "login/index/index","login/accountItems/accountItems"],
"requiredPrivateInfos": ["getLocation"], "requiredPrivateInfos": ["getLocation"],
"lazyCodeLoading": "requiredComponents", "lazyCodeLoading": "requiredComponents",
"window": { "window": {
......
// pages/accountItems/accountItems.js
import USERAPI from '~/api/usersApi/index'
Page({
/**
* 页面的初始数据
*/
data: {
/**accountLevel 1工厂。2省 ,3市。4门店 */
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getListSelectAccount()
},
getListSelectAccount() {
wx.$util.showLoading('加载中...')
api.getListSelectAccount().then(res => {
wx.hideLoading()
console.log(res)
let {
code,
data,
message
} = res
if (code == 0) {
let {
loginUserInfoList,
sessionId
} = data
wx.$util.setSessionId(sessionId)
this.setData({
loginUserInfoList
})
} else {
wx.$util.showToast(message)
}
this.setData({
flag: true
})
})
},
chooseAccount(e) {
let {
index
} = e.currentTarget.dataset
let {
loginUserInfoList
} = this.data
if (loginUserInfoList[index].active) return
loginUserInfoList.map(i => (i.active = false))
loginUserInfoList[index].active = true
this.setData({
loginUserInfoList
})
},
choiceAccountLogin() {
let {
loginUserInfoList
} = this.data
let id = null
loginUserInfoList.map(e => {
if (e.active) id = e.uuid
})
if (!id) {
wx.$util.showToast('请选择账号')
return
}
wx.$util.showLoading()
api.selectAccountLogin({
id
}).then(res => {
let {
data,
message
} = res
if (data) {
wx.$util.setUserInfo(data.loginUserInfoList[0])
const SCENE = wx.$SCENE
if (SCENE) {
let {
path,
query: {
scene
}
} = SCENE
let {
target,
name
} = wx.$util.getSceneId(path)
wx.$router.reLaunch(`${target}.${name}`, {
scene
})
wx.$SCENE = null
} else {
wx.$router.reLaunch('tabIndex.index')
}
} else {
wx.$util.showToast(message)
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
wx.hideHomeButton()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {},
})
\ No newline at end of file \ No newline at end of file
{
"navigationBarTitleText": "选择账号"
}
\ No newline at end of file \ No newline at end of file
/* login/accountItems/accountItems.wxss */
.layout {
margin: 40rpx 40rpx 0;
font-size: 28rpx;
color: #333;
letter-spacing: 0;
}
.title {
margin-bottom: 32rpx;
}
.items {
width: 100%;
min-height: 104rpx;
box-shadow: 0 0 8rpx 0 rgba(0, 0, 0, 0.15);
padding: 32rpx;
margin-bottom: 40rpx;
background-color: #fff;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
}
.items .name{
width: calc(100% - 70rpx);
}
.items:last-of-type {
margin-bottom: 0;
}
.radio {
width: 32rpx;
height: 32rpx;
border: 2rpx solid #cccccc;
border-radius: 100%;
transition: all .2s;
}
.icon {
width: 36rpx;
height: 36rpx;
transition: all .2s;
display: none;
}
.active .icon {
display: block;
}
.active .radio{
display: none;
}
.btn-box {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 140rpx;
display: flex;
justify-content: center;
align-items: center;
z-index: 20;
background-color: #fff;
border-radius: 40rpx;
font-size: 32rpx;
color: #fff;
letter-spacing: 13rpx;
}
.isFullSucreen-btn {
padding-bottom: 34px !important;
}
.btn {
width: calc(100% - 80rpx);
height: 80rpx;
line-height: 80rpx;
text-align: center;
background-color: #3582EE;
border-radius: 16rpx;
}
.list-not{
font-size: 40rpx;
}
\ No newline at end of file \ No newline at end of file
<view class="layout" style="padding-bottom:{{isFullSucreen?'224rpx':'160rpx'}}">
<view class="title">请选择登录的账号</view>
<view class="list">
<block wx:if="{{flag}}">
<block wx:if="{{loginUserInfoList}}">
<block wx:for="{{loginUserInfoList}}" wx:key="index">
<view class="items {{item.active?'active':''}}" bindtap="chooseAccount" data-index="{{index}}">
<view class="name">
{{item.merchantName}}{{item.isSuper==true?'(超管)':item.userType==1?'(商户号)':'(员工号)'}}
</view>
<view class="icon">
<image src="/images/active-arc.png" />
</view>
<view class='radio' />
</view>
</block>
</block>
<block wx:else>
<view class="list-not" style="height: calc(100vh - {{isFullSucreen ? '159' :'125'}}px)" bindtap="getListSelectAccount">
点击刷新
</view>
</block>
</block>
</view>
<view class="btn-box {{isFullSucreen?'isFullSucreen-btn':''}}">
<view class='btn' bindtap="choiceAccountLogin">确定</view>
</view>
</view>
// login/index/components/LoginBox.js // login/index/components/LoginBox.js
import USERAPI from '~/api/usersApi/index' import USERAPI from '~/api/usersApi/index'
import { setSessionId } from '~/utils/cache/storageApi'
let thisPage let thisPage
const countDown = 60
Component({ Component({
options: { options: {
styleIsolation: 'shared' styleIsolation: 'shared'
...@@ -19,10 +20,10 @@ Component({ ...@@ -19,10 +20,10 @@ Component({
*/ */
data: { data: {
formData: { formData: {
phone: '', phone: '13714966184',
code: '', code: '8888',
account: '', account: 'admin',
password: '' password: '123456789'
}, },
phoneReady: false, phoneReady: false,
countDown: null countDown: null
...@@ -32,6 +33,11 @@ Component({ ...@@ -32,6 +33,11 @@ Component({
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
hideError(name) {
if (name == 'code') this.setData({
smsError: false
})
},
input(e) { input(e) {
const { const {
value value
...@@ -44,6 +50,7 @@ Component({ ...@@ -44,6 +50,7 @@ Component({
if (name == 'phone') this.setData({ if (name == 'phone') this.setData({
phoneReady: thisPage.validate.methods.tel(value) phoneReady: thisPage.validate.methods.tel(value)
}) })
this.hideError(name)
this.checkFormData() this.checkFormData()
}, },
clear(e) { clear(e) {
...@@ -53,20 +60,40 @@ Component({ ...@@ -53,20 +60,40 @@ Component({
this.setData({ this.setData({
[`formData.${name}`]: '' [`formData.${name}`]: ''
}) })
this.hideError(name)
this.checkFormData() this.checkFormData()
}, },
getSms() { getSmsCode() {
const { const {
phoneReady, phoneReady,
formData,
count count
} = this.data } = this.data,
countDown = 60
if (!phoneReady || count) return if (!phoneReady || count) return
this.setData({ this.setData({
count: countDown smsLoading: true
})
USERAPI.getSmsCode(formData.phone).then(({
code,
message
}) => {
this.setData({
smsLoading: false
})
if (code == '0') this.countDown(countDown)
else wx.$api.showToast(message || '发送验证码失败')
}).catch(err => {
this.setData({
smsLoading: false
})
wx.$api.showToast(err || '发送验证码失败')
}) })
this.countDown()
}, },
countDown() { countDown(countDown) {
if (countDown) this.setData({
count: countDown
})
setTimeout(() => { setTimeout(() => {
let { let {
count count
...@@ -101,17 +128,74 @@ Component({ ...@@ -101,17 +128,74 @@ Component({
}) })
}, },
login() { login() {
const {
formData,
loginType
} = this.data,
target = {
1: 'phoneSmsLogin',
2: 'accountLogin'
} [loginType],
obj = loginType == 1 ? {
mobile: formData.phone,
code: formData.code
} : {
userName: formData.account,
password: formData.password
}
this.setBtnLoading() this.setBtnLoading()
setTimeout(() => { USERAPI[target](obj).then(({
code,
data,
message
}) => {
this.setBtnLoading(false) this.setBtnLoading(false)
}, 5e3) if (code == '0') {} else {
if (loginType == 1) this.setData({
smsError: true
})
wx.$api.showToast(message || '系统异常')
}
}).catch(err => {
wx.$api.showToast('系统异常')
this.setBtnLoading(false)
})
}, },
wxLogin({detail}) { wxLogin({
if(!detail.code) return detail
}) {
if (!detail.code) return
this.setBtnLoading() this.setBtnLoading()
setTimeout(() => { USERAPI.authUserPhone(detail, this.loginToken).then(({
code,
data,
message
}) => {
if (code == '0') {
const {
loginUserInfoList,
sessionId
} = data
if (loginUserInfoList.length > 1) {
wx.$router.go('login.accountItems')
} else {
wx.$router.go('login.accountItems')
USERAPI.selectAccountLogin({
id: loginUserInfoList[0].uuid,
sessionId
}).then(res =>{
console.log(res)
setSessionId(sessionId)
})
}
} else wx.$api.showToast(message || '系统异常')
this.setBtnLoading(false) this.setBtnLoading(false)
}, 5e3) }).catch(({
errMsg
}) => {
wx.$api.showToast(errMsg || '系统异常')
this.setBtnLoading(false)
})
}, },
setBtnLoading(loading = true) { setBtnLoading(loading = true) {
thisPage.setData({ thisPage.setData({
...@@ -120,15 +204,45 @@ Component({ ...@@ -120,15 +204,45 @@ Component({
this.setData({ this.setData({
loading loading
}) })
},
async init() {
thisPage = wx.$router.getPageInstance()
wx.$api.showLoading()
try {
const {
data,
code,
message
} = await USERAPI.wxCodeLogin()
if (code == '0') {
thisPage.setData({
disabled: false
})
this.loginToken = data
} else this.reLogin(message)
wx.hideLoading()
} catch ({
errMsg
}) {
console.error(errMsg)
this.reLogin()
}
},
reLogin(message) {
wx.showModal({
content: message || '获取loginToken失败',
confirmText: '重试',
confirmColor: '#3666FE'
}).then(({
confirm
}) => {
if (confirm) this.init()
})
} }
}, },
lifetimes: { lifetimes: {
attached: function () { attached: function () {
// 在组件实例进入页面节点树时执行 this.init()
USERAPI.login().then(res => {
console.log(res)
})
thisPage = wx.$router.getPageInstance()
}, },
detached: function () { detached: function () {
// 在组件实例被从页面节点树移除时执行 // 在组件实例被从页面节点树移除时执行
......
...@@ -47,16 +47,16 @@ ...@@ -47,16 +47,16 @@
} }
.sms { .sms {
width: 130rpx; width: 160rpx;
flex-shrink: 0; flex-shrink: 0;
color: #5092FF; color: #5092FF;
font-size: 24rpx; font-size: 24rpx;
padding: 0;
text-align: right;
&[disabled]:not([type]){
color: #CCCED1;
}
} }
.sms-disabled {
color: #CCCED1;
}
.error { .error {
position: absolute; position: absolute;
font-size: 24rpx; font-size: 24rpx;
......
...@@ -11,11 +11,11 @@ ...@@ -11,11 +11,11 @@
<input-icon show="{{formData.phone}}" bindtap="clear" data-name="phone" /> <input-icon show="{{formData.phone}}" bindtap="clear" data-name="phone" />
</view> </view>
<view class="input"> <view class="input">
<input type="number" placeholder="填写验证码" placeholder-class="placeholder" bindinput="input" data-name="code" value="{{formData.code}}" maxlength="6" /> <input type="number" placeholder="填写验证码" placeholder-class="placeholder" bindinput="input" data-name="code" value="{{formData.code}}" maxlength="4" />
<input-icon show="{{formData.code}}" bindtap="clear" data-name="code" /> <input-icon show="{{formData.code}}" bindtap="clear" data-name="code" />
<view class="sms text-center {{count?'sms-disabled':''}} {{phoneReady?'':'sms-disabled'}} " bindtap="getSms">{{ <button class="sms text-center " bindtap="getSmsCode" disabled="{{count || !phoneReady}}" loading="{{smsLoading}}">{{
count? count + 's':'获取验证码' count? count + 's':'获取验证码'
}}</view> }}</button>
<block wx:if="{{smsError}}"> <block wx:if="{{smsError}}">
<view class="error">验证码错误</view> <view class="error">验证码错误</view>
</block> </block>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</block> </block>
<block wx:else> <block wx:else>
<view class="input"> <view class="input">
<input type="text" placeholder="填写账号名" placeholder-class="placeholder" bindinput="input" data-name="account" value="{{formData.account}}" maxlength="20" /> <input type="text" placeholder="填写账号" placeholder-class="placeholder" bindinput="input" data-name="account" value="{{formData.account}}" maxlength="20" />
<input-icon show="{{formData.account}}" bindtap="clear" data-name="account" /> <input-icon show="{{formData.account}}" bindtap="clear" data-name="account" />
</view> </view>
<view class="input"> <view class="input">
......
...@@ -6,9 +6,11 @@ Page({ ...@@ -6,9 +6,11 @@ Page({
*/ */
data: { data: {
loginType: 0, loginType: 0,
agree: true disabled: true
},
onRoute(options){
console.log(options)
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
...@@ -31,7 +33,6 @@ Page({ ...@@ -31,7 +33,6 @@ Page({
wx.hideLoading() wx.hideLoading()
} }
}) })
this.checkLoginBtn()
}, },
/** /**
...@@ -60,23 +61,23 @@ Page({ ...@@ -60,23 +61,23 @@ Page({
// onShareAppMessage() { // onShareAppMessage() {
// }, // },
checkLoginBtn(flag = false) { checkLoginBtn(disabled = false) {
const { const {
agree,
loginType loginType
} = this.data } = this.data, {
if (loginType == 0) flag = true data: {
else {
const {
formData, formData,
phoneReady phoneReady
} = this.selectComponent('#box').data },
flag = loginType == 1 ? loginToken
phoneReady && formData.code : } = this.selectComponent('#box')
formData.account && formData.password if (loginType == 0) {
} disabled = loginToken
} else disabled = loginType == 1 ?
phoneReady && formData.code :
formData.account && formData.password
this.setData({ this.setData({
disabled: !agree || !flag disabled: !disabled
}) })
}, },
}) })
\ No newline at end of file \ No newline at end of file
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
"navigation-bar": "/components/NavigationBar/NavigationBar", "navigation-bar": "/components/NavigationBar/NavigationBar",
"mask": "./components/Mask/Mask", "mask": "./components/Mask/Mask",
"box": "./components/Box/Box", "box": "./components/Box/Box",
"type-list": "./components/TypeList/TypeList", "type-list": "./components/TypeList/TypeList"
"protocol": "./components/Protocol/Protocol"
}, },
"navigationStyle": "custom" "navigationStyle": "custom"
} }
\ No newline at end of file \ No newline at end of file
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
<navigation-bar navStyle="background-color: rgba(0,0,0,0)">生意助手</navigation-bar> <navigation-bar navStyle="background-color: rgba(0,0,0,0)">生意助手</navigation-bar>
<box loginType="{{loginType}}" disabled="{{disabled}}" id="box" /> <box loginType="{{loginType}}" disabled="{{disabled}}" id="box" />
<type-list loginType="{{loginType}}" /> <type-list loginType="{{loginType}}" />
<protocol agree="{{agree}}" /> <!-- <protocol agree="{{agree}}" /> -->
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -25,19 +25,24 @@ Page({ ...@@ -25,19 +25,24 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
wx.$api.showLoading()
const { const {
sessionId, sessionId,
} = wx.$storage.get(), { } = wx.$storage.get(), {
url, url,
path = decodeURIComponent(url) targetPath = decodeURIComponent(url)
} = this.options } = this.options
console.log(path) console.log(targetPath)
wx.nextTick(() => {
if (sessionId) { if (sessionId) {
// wx.$router.reLaunch('login.index')
} else {
wx.$router.reLaunch('login.index', {
targetPath
})
}
})
} else {
wx.$router.reLaunch('login.index')
}
}, },
/** /**
......
<view class="layout"> <view class="layout">
<image class="icon" src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_LIVE.gif"></image> <!-- <image class="icon" src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/COVER_LIVE.gif"></image> -->
</view> </view>
\ No newline at end of file \ No newline at end of file
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
"query": "", "query": "",
"launchMode": "default", "launchMode": "default",
"scene": null "scene": null
},
{
"name": "携带目标页面",
"pathName": "login/loading/loading",
"query": "url=pages%2Ftab%2Findex%2Findex%3Fid%3D123",
"launchMode": "default",
"scene": null
} }
] ]
} }
......
...@@ -2,7 +2,6 @@ const _routeHooks = Symbol('_routeHooks') ...@@ -2,7 +2,6 @@ const _routeHooks = Symbol('_routeHooks')
const _query = Symbol('_query') const _query = Symbol('_query')
const _routerList = Symbol('_routerList') const _routerList = Symbol('_routerList')
import { import {
wxOnAppRouteFn,
generateRoutList generateRoutList
} from './wxOnAppRoute.js' } from './wxOnAppRoute.js'
import { import {
...@@ -17,15 +16,23 @@ class Router { ...@@ -17,15 +16,23 @@ class Router {
[_routerList] = [] [_routerList] = []
constructor(router) { constructor(router) {
this[_routerList] = generateRoutList(router) this[_routerList] = generateRoutList(router)
let obj = { wx.onAppRoute &&
query: this[_query], wx.onAppRoute(e => {
routeHooks: this[_routeHooks], let thisPage = this.getPageInstance()
routerList: this[_routerList], if (thisPage) {
getPageInstance: this.getPageInstance, this.setNavigationBarTitleText(thisPage)
setNavigationBarTitleText: this.setNavigationBarTitleText, let onRoute = thisPage.onRoute
getRouterList: this.getRouterList typeof onRoute === 'function' && onRoute(this[_query])
} }
wxOnAppRouteFn(obj) this[_routeHooks].forEach(fn => {
try {
typeof fn === 'function' && fn(e, this[_query], this[_routerList])
} catch (err) {
console.log(err)
}
})
this[_query] = {}
})
} }
/**设置标题栏 */ /**设置标题栏 */
setNavigationBarTitleText = thisPage => { setNavigationBarTitleText = thisPage => {
...@@ -72,10 +79,13 @@ class Router { ...@@ -72,10 +79,13 @@ class Router {
/**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */ /**只传页面名 默认跳转当前包下的页面,相同名称默认第一个 */
if (!_name && !last_name) name = _parent if (!_name && !last_name) name = _parent
const routerMapItem = this[_routerList].find(item => { const routerMapItem = this[_routerList].find(item => {
if (last_name) { if (route.includes('/')) return item.url === route
return item.parent === parent && item.name === last_name && item.subPages === name else {
} else { if (last_name) {
return item.parent === parent && item.name === name return item.parent === parent && item.name === last_name && item.subPages === name
} else {
return item.parent === parent && item.name === name
}
} }
}) })
if (!routerMapItem) { if (!routerMapItem) {
...@@ -89,11 +99,8 @@ class Router { ...@@ -89,11 +99,8 @@ class Router {
} }
/**跳转至H5 */ /**跳转至H5 */
jumpH5(url) { jumpH5(url) {
this.intercept().then(response => { wx.navigateTo({
if (response) return url: `/pages/webView/webView?url=${encodeURIComponent(url)}`
wx.navigateTo({
url: `/pages/webView/webView?url=${encodeURIComponent(url)}`
})
}) })
} }
/**页面跳转 /**页面跳转
...@@ -117,20 +124,10 @@ class Router { ...@@ -117,20 +124,10 @@ class Router {
url: routerMapItem.url url: routerMapItem.url
}) })
} else { } else {
if (events && events.notIntercept) { wx.navigateTo({
wx.navigateTo({ url: `${routerMapItem.url}${query}`,
url: `${routerMapItem.url}${query}`, success: res => events && res.eventChannel.emit('getData', events)
success: res => events && res.eventChannel.emit('getData', events) })
})
} else {
this.intercept().then(response => {
if (response) return
wx.navigateTo({
url: `${routerMapItem.url}${query}`,
success: res => events && res.eventChannel.emit('getData', events)
})
})
}
} }
} }
/**关闭所有页面,打开到应用内的某个页面 */ /**关闭所有页面,打开到应用内的某个页面 */
...@@ -139,11 +136,8 @@ class Router { ...@@ -139,11 +136,8 @@ class Router {
routerMapItem, routerMapItem,
query query
} = this.checkRouter(route, events) } = this.checkRouter(route, events)
this.intercept().then(response => { wx.reLaunch({
if (response) return url: `${routerMapItem.url}${query}`
wx.reLaunch({
url: `${routerMapItem.url}${query}`
})
}) })
} }
/**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */ /**关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。 */
...@@ -152,11 +146,8 @@ class Router { ...@@ -152,11 +146,8 @@ class Router {
routerMapItem, routerMapItem,
query query
} = this.checkRouter(route, events) } = this.checkRouter(route, events)
this.intercept().then(response => { wx.redirectTo({
if (response) return url: `${routerMapItem.url}${query}`
wx.redirectTo({
url: `${routerMapItem.url}${query}`
})
}) })
} }
/**prevPageSize = 1 /**prevPageSize = 1
...@@ -173,7 +164,7 @@ class Router { ...@@ -173,7 +164,7 @@ class Router {
} }
goHome() { goHome() {
let [index] = this[_routerList] let [index] = this[_routerList]
wx.switchTab({ wx.reLaunch({
url: index.url url: index.url
}) })
} }
...@@ -189,18 +180,6 @@ class Router { ...@@ -189,18 +180,6 @@ class Router {
if (i > -1) list.splice(i, 1) if (i > -1) list.splice(i, 1)
} }
} }
async intercept() {
const authStatus = wx.$authStatus
if (authStatus) {
const thisPage = this.getPageInstance()
thisPage.setData({
showLogin: true
})
return await true
} else {
return await false
}
}
} }
export default Router export default Router
\ No newline at end of file \ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
/**处理前置钩子逻辑 */ /**处理前置钩子逻辑 */
const routerBefore = (next) => { const routerBefore = (next) => {
// console.log("处理前置钩子逻辑"); // console.log("处理前置钩子逻辑");
next(); next();
}; };
/**处理后置钩子逻辑 */ /**处理后置钩子逻辑 */
...@@ -33,4 +32,4 @@ Page = function (options) { ...@@ -33,4 +32,4 @@ Page = function (options) {
OldPage(options); OldPage(options);
}; };
export default routerBefore; export default routerBefore;
\ No newline at end of file \ No newline at end of file
import util from '../utils/util.js' import util from '../utils/util.js'
import { getUserInfo } from '~/utils/cache/userInfo' import {
import { IMG_URL } from '~/utils/constantData' getUserInfo
} from '~/utils/cache/userInfo'
import {
IMG_URL
} from '~/utils/constantData'
/** /**
* wx.onAppRoute钩子方法, * wx.onAppRoute钩子方法,
...@@ -13,26 +17,6 @@ import { IMG_URL } from '~/utils/constantData' ...@@ -13,26 +17,6 @@ import { IMG_URL } from '~/utils/constantData'
* @param {*} obj.setNavigationBarTitleText * @param {*} obj.setNavigationBarTitleText
* @param {*} obj.getRouterList * @param {*} obj.getRouterList
*/ */
export const wxOnAppRouteFn = obj => {
wx.onAppRoute &&
wx.onAppRoute(e => {
let thisPage = obj.getPageInstance()
if (thisPage) {
obj.setNavigationBarTitleText(thisPage)
let onRoute = thisPage.onRoute
typeof onRoute === 'function' && onRoute(obj.query)
}
obj.routeHooks.forEach(fn => {
try {
typeof fn === 'function' && fn(e, obj.query, obj.routerList)
} catch (err) {
console.log(err)
}
})
obj.query = {}
})
}
/** /**
* 生成特定格式路由 * 生成特定格式路由
* *
...@@ -50,7 +34,9 @@ export const generateRoutList = routerList => { ...@@ -50,7 +34,9 @@ export const generateRoutList = routerList => {
if (item.parent != '__plugin__') { if (item.parent != '__plugin__') {
obj = { obj = {
...item, ...item,
isTab: __wxConfig.tabBar.list.some(({ pagePath }) => item.url.includes(pagePath.replace('.html', ''))) isTab: __wxConfig.tabBar.list.some(({
pagePath
}) => item.url.includes(pagePath.replace('.html', '')))
} }
if (item.parent !== 'pages') { if (item.parent !== 'pages') {
let parentList = item.url.split(`/`) let parentList = item.url.split(`/`)
...@@ -59,14 +45,9 @@ export const generateRoutList = routerList => { ...@@ -59,14 +45,9 @@ export const generateRoutList = routerList => {
obj.subPages = item.url.split(`/${item.parent}/pages/`)[1].split('/')[0] obj.subPages = item.url.split(`/${item.parent}/pages/`)[1].split('/')[0]
} }
} }
if (obj.isTab) {
__wxConfig.tabBar.list.map(e => {
if (obj.url === `/${e.pagePath.replace('.html', '')}`) obj.rootName = e.rootName
})
}
} }
return obj return obj
})) }))
} catch (err) {} } catch (err) {}
return _routerList return _routerList
} }
\ No newline at end of file \ No newline at end of file
...@@ -9,6 +9,12 @@ export function getSessionId() { ...@@ -9,6 +9,12 @@ export function getSessionId() {
export function setSessionId(sessionId) { export function setSessionId(sessionId) {
$Storage.set('scrm_shopmall_sessionId', sessionId) $Storage.set('scrm_shopmall_sessionId', sessionId)
} }
export function getUserInfo() {
return $Storage.get('scrm_shopmall_userInfo')
}
export function setUserInfo(data) {
$Storage.set('scrm_shopmall_userInfo', data)
}
export function removeSystemStorage() { export function removeSystemStorage() {
$Storage.rm('srcm_shopmall_user_info') $Storage.rm('srcm_shopmall_user_info')
$Storage.rm('scrm_shopmall_sessionId') $Storage.rm('scrm_shopmall_sessionId')
......
...@@ -6,7 +6,7 @@ const target = ['ip', 'dev', 'uat', 'prod'] ...@@ -6,7 +6,7 @@ const target = ['ip', 'dev', 'uat', 'prod']
2测试 2测试
3生产 3生产
*/ */
const index = 3 const index = 0
const secretKey = { const secretKey = {
ip: {}, ip: {},
dev: { dev: {
...@@ -32,7 +32,7 @@ const secretKey = { ...@@ -32,7 +32,7 @@ const secretKey = {
const domain = { const domain = {
// ip: 'http://192.168.2.94:8558', // ip: 'http://192.168.2.94:8558',
// ip: 'http://192.168.2.3:8315', // ip: 'http://192.168.2.3:8315',
ip: 'http://192.168.3.181:8394', ip: 'http://192.168.1.170:8315',
/**登录: 192.168.2.3:8315 /**登录: 192.168.2.3:8315
商城: 192.168.2.3:8558 */ 商城: 192.168.2.3:8558 */
dev: 'https://scrm.dev.glsx.com.cn', dev: 'https://scrm.dev.glsx.com.cn',
......
...@@ -2,14 +2,12 @@ import { ...@@ -2,14 +2,12 @@ import {
secretKey, secretKey,
pathEnum, pathEnum,
domain, domain,
index,
sign sign
} from './http.js' } from './http.js'
// import util from '../util' // import util from '../util'
import { import {
getSessionId getSessionId
} from '~/utils/cache/storageApi' } from '~/utils/cache/storageApi'
let INTERRUPT = false
/**接口 */ /**接口 */
class Request { class Request {
get(params, returnAll = false) { get(params, returnAll = false) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!