处理session 过期

This commit is contained in:
郑茂强 2019-03-05 17:32:53 +08:00
parent 036bc4783a
commit 1f79ef2bda
23 changed files with 445 additions and 364 deletions

View File

@ -20,7 +20,7 @@ class App extends Component {
config = {
pages: [
//'pages/index/index', // index页面
'pages/individualCenter/individualCenter',// 个人中心页面
'pages/home/home',//首页 ---------------------
'pages/login/login',//登入页面 ---------------------
'pages/shop/shop',//店铺页面 ---------------------
@ -38,6 +38,7 @@ class App extends Component {
'pages/myNeedsView/myNeedsView',// 单个需求查看页面
'pages/myNeedsEdit/myNeedsEdit',// 单个需求编辑页面
'pages/myNeedsPublish/myNeedsPublish',// 需求发布
'pages/individualCenter/individualCenter',// 个人中心页面

View File

@ -164,8 +164,9 @@ class AllDemanding extends Component {
})
}
grabOrder(Id) {
this.setState({ isOpenedGrabModal: true, grabOrderId: Id })
grabOrder(e) {
const id = e.currentTarget.dataset.eTapAA
this.setState({ isOpenedGrabModal: true, grabOrderId: id })
}
handleGrabModalClose() {
this.setState({ isOpenedGrabModal: false })
@ -202,10 +203,10 @@ class AllDemanding extends Component {
this.setState({ industryTypeSelected: value })
}
goToGrabOrderPage(orderId) {
goToGrabOrderPage(e) {
const id = e.currentTarget.dataset.eTapAA
Taro.navigateTo({
url: '/pages/grabOrderPage/grabOrderPage?orderId=' + orderId
url: '/pages/grabOrderPage/grabOrderPage?orderId=' + id
})
}

View File

@ -264,7 +264,6 @@ class GoodsPublish extends Component {
goToMyGoodListPage() {
console.log('list ', Taro.getStorageSync('userInfo'))
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return

View File

@ -70,16 +70,12 @@ class GrabOrderPage extends Component {
renderingImage: res.data.sdInfo.render_pics || []
})
} else if (res.data.err_code === 88888) {
Taro.clearStorageSync()
loginExpired(res)
}else{
Taro.showToast({
title: res.data.err_msg,
icon: 'none'
title:res.data.err_msg,
icon:'none'
})
setTimeout(() => {
Taro.switchTab({
url: '/pages/home/home'
})
}, 1500);
}
}
@ -171,7 +167,7 @@ class GrabOrderPage extends Component {
componentDidHide() { }
goMyNeedsPublishPage() {
Taro.navigateTo({
Taro.switchTab({
url: '/pages/myNeedsPublish/myNeedsPublish'
})
}
@ -218,8 +214,8 @@ class GrabOrderPage extends Component {
duration: 1500
})
setTimeout(() => {
Taro.switchTab({
url: '/pages/myNeeds/myNeeds'
Taro.navigateBack({
delta:-1
})
}, 1500);
} else if (res.data.err_code === 88888) {
@ -232,7 +228,6 @@ class GrabOrderPage extends Component {
})
}
})
}
render() {
@ -259,7 +254,7 @@ class GrabOrderPage extends Component {
<AtIcon value='' size='12' color='white'></AtIcon>
我的需求</Button>
</View>
<View className='button' onClick={this.goMyNeedEditPage.bind(this)}>
{/* <View className='button' onClick={this.goMyNeedEditPage.bind(this)}>
<Button size='mini' className='button-blue'>
<AtIcon value='settings' size='12' color='white'></AtIcon>
修改</Button>
@ -269,7 +264,7 @@ class GrabOrderPage extends Component {
<Button size='mini' className='button-dark-red'>
<AtIcon value='trash' size='12' color='white'></AtIcon>
删除</Button>
</View>
</View> */}
</View>
} else if (localStoageUserId === this.state.userId && this.state.stateId != '1') {
ButtonElement = <View className='button-box'>

View File

@ -2,7 +2,7 @@ import Taro, { Component } from '@tarojs/taro'
import { View, Image, Button } from '@tarojs/components'
import { AtGrid, AtList, AtListItem, AtAvatar, AtButton } from "taro-ui"
import LoginService from '../../util/LoginService'
import './individualCenter.scss'
import URL from '../../serviceAPI.config'
@ -117,7 +117,12 @@ class IndividualCenter extends Component {
componentWillUnmount() { }
componentDidShow() { }
componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
componentDidHide() { }

View File

@ -1,7 +1,7 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Input, Button, Text, Image } from '@tarojs/components'
import { View, Input, Button, Image } from '@tarojs/components'
import URL from '../../serviceAPI.config'
import standardLogin from '../../util/standardLogin'
import './login.scss'
@ -17,74 +17,7 @@ class Login extends Component {
backgroundImage: 'background-image:url(' + URL.Base + '/Public/images/bg3.jpg);'
}
}
//用户信息姓名和电话号码接口
setUserInfoToStorage() {
Taro.request({
url: URL.ShopWxStore,
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
}
})
.then(res => {
if (res.data.err_msg === 'success') {
Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
loginApi() {
Taro.request({
url: URL.Base + 'user-login',
method: 'POST',
dataType: 'json',
data: {
username: this.state.username,
password: this.state.password,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.data.err_code === 0) {
Taro.showToast({
title: res.data.err_msg && '登入成功',
icon: 'success',
duration: 1000
})
Taro.setStorageSync('session_id', res.data.session_id)
Taro.setStorageSync('shopInfo', res.data.shop_info)
Taro.setStorageSync('userInfo', res.data.user_info)
this.setUserInfoToStorage()
setTimeout(() => {
// Taro.navigateBack({
// delta: 1
// })
Taro.reLaunch({
url:'/pages/home/home'
})
}, 1000);
} else {
Taro.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
}
})
}
usernameHandler(e) {
let value = e.detail.value
@ -95,7 +28,37 @@ class Login extends Component {
this.setState({ password: value })
}
loginHandler() {
this.loginApi()
if (this.state.username && this.state.password) {
standardLogin(this.state.username, this.state.password).then(res => {
Taro.reLaunch({
url: '/pages/home/home'
})
}).catch(res => {
Taro.showToast({
title: res.data.msg,
icon: 'none',
})
})
} else if (!this.state.username) {
Taro.showToast({
title: '请输入用户名',
icon: 'none',
})
} else if (!this.state.password) {
Taro.showToast({
title: '请输入密码',
icon: 'none',
})
} else {
Taro.showToast({
title: '未知错误请联系管理员',
icon: 'none',
})
}
}
componentDidMount() {
@ -135,7 +98,7 @@ class Login extends Component {
<View className='password'>
<Input type='password' name='password' placeholder='请输入密码' value={this.state.password} onInput={this.passwordHandler} />
</View>
<Button className='button button-orange' onClick={this.loginHandler}>登录</Button>
</View>
</View>

View File

@ -146,9 +146,9 @@ class MyDemandSupplyEdit extends Component {
url: '/pages/supplyDemandPublish/supplyDemandPublish'
})
} else {
// Taro.navigateTo({
// url: '/pages/myDemandSupplyEdit/myDemandSupplyEdit?sdId=' + res.data.sd_id
// })
Taro.redirectTo({
url: '/pages/mySupplyDemand/mySupplyDemand',//我的供求页面
})
}
}, 1000);
})
@ -314,9 +314,9 @@ class MyDemandSupplyEdit extends Component {
}
}
goToMyDemSupPage() {
Taro.navigateBack({
delta: 1
})
Taro.redirectTo({
url: '/pages/mySupplyDemand/mySupplyDemand',//我的供求页面
})
}
deleteButtonHandler() {
this.setState({ isConfirmWindow: true })
@ -468,9 +468,9 @@ class MyDemandSupplyEdit extends Component {
<View className='button' onClick={this.saveButtonHandler.bind(this)}>
<Button size='mini' className='button-orange'>保存</Button>
</View>
<View className='button' onClick={this.saveAndNewButton.bind(this)}>
{/* <View className='button' onClick={this.saveAndNewButton.bind(this)}>
<Button size='mini' className='button-green'>保存并新增</Button>
</View>
</View> */}
{/* <View className='button'>
<Button className='button-a' size='mini' className='button-orange'>保存并新增</Button>
@ -478,9 +478,9 @@ class MyDemandSupplyEdit extends Component {
<View className='button' onClick={this.goToMyDemSupPage.bind(this)}>
<Button size='mini' className='button-green'>我的供求</Button>
</View>
<View className='button' onClick={this.deleteButtonHandler.bind(this)}>
{/* <View className='button' onClick={this.deleteButtonHandler.bind(this)}>
<Button size='mini' className='button-dark-red'>删除</Button>
</View>
</View> */}
</View>
<CopyrightComponent></CopyrightComponent>

View File

@ -5,8 +5,6 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
import URL from '../../serviceAPI.config'
import './myGoodList.scss'
import loginExpired from '../../util/loginExpired';
@ -47,8 +45,8 @@ class MyGoodList extends Component {
isOpenOffStockModal: false,// 是否显示下架模态框
isAddToList: false,// 是否下拉加载 如果是 就添加商品到我的商品列表
isShowTopNav: false,// 是否显示返回顶部按钮
screenWidth:'',
screenHeight:''
screenWidth: '',
screenHeight: ''
}
}
@ -144,7 +142,9 @@ class MyGoodList extends Component {
}
}).then(res => {
const data = JSON.parse(res.data)
if (data.err_code != 10) {
if (data.err_code === 88888) {
loginExpired(data)
} else if (data.err_code != 10) {
console.log('我的商品列表', JSON.parse(res.data))
Taro.hideLoading()
@ -588,16 +588,16 @@ class MyGoodList extends Component {
url: '/pages/individualCenter/individualCenter'
})
}
getUserSystemInfo(){
Taro.getSystemInfo().then(res=>{
return res
}).then(res=>{
console.log('res',res)
this.setState({
screenWidth:res.screenWidth-80+'px',
screenHeight:res.screenHeight-200+'px'
getUserSystemInfo() {
Taro.getSystemInfo().then(res => {
return res
}).then(res => {
console.log('res', res)
this.setState({
screenWidth: res.screenWidth - 80 + 'px',
screenHeight: res.screenHeight - 200 + 'px'
})
})
})
}
@ -616,7 +616,7 @@ class MyGoodList extends Component {
componentWillUnmount() { }
componentDidShow() {
}
componentDidHide() { }
@ -691,8 +691,8 @@ class MyGoodList extends Component {
</AtModal>
return (
<MovableArea style='height: 100%; width: 100%; '>
<View className='MyGoodList' style='position:relative;'>
<MovableArea style='height: 100vh; width: 100%; '>
<View className='MyGoodList' >
{/* 删除模态提示框 */}
{modalMessageDeleteElement}
{/* 下架模态框提示 */}
@ -820,11 +820,12 @@ class MyGoodList extends Component {
<CopyrightComponent></CopyrightComponent>
<MovableView className='movable-point' x={this.state.screenWidth} y={this.state.screenHeight} style='opacity:0.3' direction='all' onClick={this.goToCenterPage.bind(this)} >
个人中心
</MovableView>
</View>
<MovableView className='movable-point' x={this.state.screenWidth} y={this.state.screenHeight} style='opacity:0.3' direction='all' onClick={this.goToCenterPage.bind(this)} >
个人中心
</MovableView>
</MovableArea>
)
}

View File

@ -46,6 +46,7 @@ class MyGoodsEdit extends Component {
}
})
.then(res => {
console.log('res',res)
if (res.data.err_code === 0) {
console.log('商品详情获取成功', res)
@ -62,8 +63,6 @@ class MyGoodsEdit extends Component {
// }
// }
// }
if (Taro.getStorageSync('shopTypeObject')) {
let selectedValue = ''
const shopTypeObject = Taro.getStorageSync('shopTypeObject')
@ -89,6 +88,7 @@ class MyGoodsEdit extends Component {
}
} else if (res.data.err_code === 88888) {
console.log('88888')
loginExpired(res)
}
else {
@ -172,10 +172,14 @@ class MyGoodsEdit extends Component {
}).then(() => {
setTimeout(() => {
if (this.state.isSaveButton) {
Taro.navigateBack({
delta:1
// Taro.navigateBack({
// delta:1
// url: '/pages/myGoodsList/myGoodsEdit?id=' + this.$router.params.id
})
// })
Taro.redirectTo({
url: '/pages/myGoodList/myGoodList'
})
} else if (this.state.isSaveAndNewBUtton) {
Taro.switchTab({
url: '/pages/goodsPublish/goodsPublish'
@ -349,7 +353,7 @@ class MyGoodsEdit extends Component {
})
}
goToMyGoodListPage() {
Taro.navigateTo({
Taro.redirectTo({
url: '/pages/myGoodList/myGoodList'
})
}

View File

@ -251,13 +251,15 @@ class MyNeeds extends Component {
needsStateSelected: this.state.needsState[e.detail.value]
})
}
goToMyNeedsViewPage(Id) {
goToMyNeedsViewPage(e) {
const id = e.currentTarget.dataset.eTapAA
Taro.navigateTo({
url: '/pages/grabOrderPage/grabOrderPage?orderId=' + Id
url: '/pages/grabOrderPage/grabOrderPage?orderId=' + id
})
}
goToMyNeedsEditPage(id) {
goToMyNeedsEditPage(e) {
const id = e.currentTarget.dataset.eTapAA
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + id
})

View File

@ -171,13 +171,16 @@ class MyNeedsEdit extends Component {
setTimeout(() => {
console.log('this.state.isSaveAndNew', this.state.isSaveAndNew)
if (this.state.isSaveAndNew) {
Taro.navigateTo({
url: '/pages/myNeedsPublish/myNeedsPublish'
})
// Taro.navigateTo({
// url: '/pages/myNeedsPublish/myNeedsPublish'
// })
} else {
// Taro.navigateTo({
// url: '/pages/myNeedsEdit/myNeedsEdit?id=' + this.state.sd_id
// })
Taro.reLaunch({
url: '/pages/myNeeds/myNeeds'
})
}
}, 1500);
})
@ -513,15 +516,15 @@ class MyNeedsEdit extends Component {
<View className='button' onClick={this.saveButtonHandler.bind(this)}>
<Button size='mini' className='button-orange'>保存</Button>
</View>
<View className='button' onClick={this.saveAndNewButton.bind(this)}>
{/* <View className='button' onClick={this.saveAndNewButton.bind(this)}>
<Button size='mini' className='button-green'>保存并新增</Button>
</View>
</View> */}
<View className='button' onClick={this.goToMyNeedsPage.bind(this)}>
<Button className='button-green' size='mini'>我的需求</Button>
</View>
<View className='button' onClick={this.deleteButtonHandler.bind(this)}>
{/* <View className='button' onClick={this.deleteButtonHandler.bind(this)}>
<Button className='button-dark-red' size='mini'>删除</Button>
</View>
</View> */}
</View>
<CopyrightComponent></CopyrightComponent>

View File

@ -6,6 +6,7 @@ import { AtInput, AtImagePicker, AtTextarea, Picker } from 'taro-ui'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import URL from '../../serviceAPI.config'
import InteractionComponent from '../../component/interactionComponent/interactionComponent'
import LoginService from '../../util/LoginService'
import './myNeedsPublish.scss'
@ -27,8 +28,8 @@ class MyNeedsPublish extends Component {
needsType: [{ name: '业主需求', id: '4' }, { name: '效果图', id: '5' }],
needsTypeSelected: { name: '业主需求', id: '4' },
title: '',
contactName: Taro.getStorageSync('user_identity').username||'',
contactNumber: Taro.getStorageSync('user_identity').userphone||'',
contactName: Taro.getStorageSync('user_identity').username || '',
contactNumber: Taro.getStorageSync('user_identity').userphone || '',
contactAddress: '',
content: '',
pickerImageUrl: [], // 上传的图片
@ -79,9 +80,13 @@ class MyNeedsPublish extends Component {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
console.log('上传需求', res)
if (res.data.err_code === 0) {
.then(response => {
console.log('上传需求', response)
const res = JSON.parse(response.data)
console.log('jonson parse', res)
Taro.hideLoading()
if (res.err_code === 0) {
Taro.showToast({
title: '发布成功',
icon: 'success',
@ -94,17 +99,20 @@ class MyNeedsPublish extends Component {
})
} else {
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + res.data.sd_id
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + res.sd_id
})
}
}, 1500);
})
} else if (res.data.err_code === 88888) {
loginExpired(res)
} else if (res.err_code === 88888) {
const resp = { data: { err_msg: res.err_msg } }
console.log('resp',resp)
loginExpired(resp)
} else {
Taro.showToast({
title: res.data.err_msg,
title: res.err_msg,
icon: 'none',
duration: 1500
})
@ -266,7 +274,12 @@ class MyNeedsPublish extends Component {
componentWillUnmount() { }
componentDidShow() { }
componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
componentDidHide() { }

View File

@ -147,7 +147,9 @@ class SupplyDemandView extends Component {
duration: 1500
})
setTimeout(() => {
this.goToMyNeedsPage()
Taro.navigateBack({
delta:-1
})
}, 1500);
} else if (res.data.err_code === 88888) {
loginExpired(res)
@ -168,19 +170,16 @@ class SupplyDemandView extends Component {
})
}
goMyNeedEditPage() {
console.log('edit page')
console.log('id', this.state.sd_id)
Taro.navigateTo({
url: '/pages/myNeedsEdit/myNeedsEdit?id=' + this.state.sd_id
})
}
goToMyNeedsPage() {
Taro.navigateTo({
url: '/pages/myNeeds/myNeeds'
})
}
deleteButton() {
this.setState({ isDeleteModal: true })

View File

@ -1,5 +1,5 @@
import Taro, { Component } from '@tarojs/taro'
import { View, Text, Button } from '@tarojs/components'
import { View, Text, Button, MovableArea, MovableView } from '@tarojs/components'
import { AtInput, Picker, AtIcon, AtModal, AtModalHeader, AtModalContent, AtModalAction } from 'taro-ui'
import URL from '../../serviceAPI.config'
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
@ -35,6 +35,8 @@ class MySupplyDemand extends Component {
currentPage: 1,//当前页数
isShowTopNav: false,// 是否显示返回顶部按钮
loadMorePageIndex: 1,//上拉加载页面数
screenWidth: '',
screenHeight: ''
}
}
//获取我的供求列表API
@ -111,7 +113,7 @@ class MySupplyDemand extends Component {
}
onSearchButtonHandler() {
Taro.showLoading({ title: '加载中' })
this.setState({ loadMorePageIndex: 1 }, () => {
@ -156,7 +158,7 @@ class MySupplyDemand extends Component {
}
)
}
// 新增我的供求
@ -236,7 +238,7 @@ class MySupplyDemand extends Component {
// 跳转到我的供求编辑页面
goToMyDSEditPage(e) {
const sdId=e.currentTarget.dataset.eTapAA
const sdId = e.currentTarget.dataset.eTapAA
Taro.navigateTo({
url: '/pages/myDemandSupplyEdit/myDemandSupplyEdit?sdId=' + sdId
})
@ -244,11 +246,28 @@ class MySupplyDemand extends Component {
}
// 转到供求查看页面
goSupplyDemandView(e) {
const sdId=e.currentTarget.dataset.eTapAA
const sdId = e.currentTarget.dataset.eTapAA
Taro.navigateTo({
url: '/pages/supplyDemandView/supplyDemandView?sdId=' + sdId
})
}
goToCenterPage() {
Taro.switchTab({
url: '/pages/individualCenter/individualCenter'
})
}
getUserSystemInfo() {
Taro.getSystemInfo().then(res => {
return res
}).then(res => {
console.log('res', res)
this.setState({
screenWidth: res.screenWidth - 80 + 'px',
screenHeight: res.screenHeight - 200 + 'px'
})
})
}
componentWillMount() {
@ -259,6 +278,7 @@ class MySupplyDemand extends Component {
}
componentDidMount() {
this.getUserSystemInfo()
Taro.showLoading({ title: '加载中' }).then(() => {
this.getMySupplyDemand({})
})
@ -360,7 +380,7 @@ class MySupplyDemand extends Component {
}) : <View className='no-more-title' >
没有更多了....
</View >
return (
return (<MovableArea style='height: 100vh; width: 100%; '>
<View className='mySupplyDemand'>
{/* 是否删除供求确认框 */}
{modalMessageConfirmElement}
@ -454,6 +474,11 @@ class MySupplyDemand extends Component {
<CopyrightComponent></CopyrightComponent>
</View>
<MovableView className='movable-point' x={this.state.screenWidth} y={this.state.screenHeight} style='opacity:0.3' direction='all' onClick={this.goToCenterPage.bind(this)} >
个人中心
</MovableView>
</MovableArea>
)
}
}

View File

@ -2,6 +2,21 @@ $themeColor:#FF7142;
.button-orange, .button-dark-red,.button-green{
font-size:28rpx;
}
.movable-point{
height:130rpx;
width:130rpx;
color:#ffffff;
background-color:black;
opacity: 0.3;
border-radius:50%;
position:fixed;
display: flex;
align-items: center;
justify-content:center;
font-size:25rpx;
opacity:1 ;
position:fixed;
}
.mySupplyDemand{
padding: 10px 20px;

View File

@ -240,7 +240,7 @@ class SupplyDemand extends Component {
LoginService()
return
}
Taro.navigateTo({
Taro.redirectTo({
url: '/pages/mySupplyDemand/mySupplyDemand'
})
}

View File

@ -121,19 +121,19 @@ class SupplyDemandView extends Component {
}
goToSDPublishPage() {
Taro.navigateTo({
Taro.redirectTo({
url: '/pages/supplyDemandPublish/supplyDemandPublish',// 供求发布页面
})
}
// 跳转到我的供求编辑页面
goToMyDSEditPage() {
Taro.navigateTo({
Taro.redirectTo({
url: '/pages/myDemandSupplyEdit/myDemandSupplyEdit?sdId=' + this.state.itemId
})
}
goToMySDPage() {
Taro.navigateBack({
Taro.redirectTo({
url: '/pages/mySupplyDemand/mySupplyDemand',//我的供求页面
})
}

View File

@ -17,137 +17,155 @@ bug 商品编辑 增加图片后 图片顺序乱了
等待后台--- 单个我的商品页面的图片顺序,单个我的需求页面的接口, 当个我哦的需求编辑页面的接口
import '@tarojs/async-await'
import Taro, { Component } from '@tarojs/taro'
import { Provider } from '@tarojs/redux'
import Home from './pages/home'
import { View, Input, Button, Image } from '@tarojs/components'
import URL from '../../serviceAPI.config'
import configStore from './store'
import './login.scss'
import './app.scss'
// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释:
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5') {
// require('nerv-devtools')
// }
const store = configStore()
class App extends Component {
isTrue = Taro.getStorageSync('session_id') ? true : false
class Login extends Component {
config = {
pages: [
//'pages/index/index', // index页面
'pages/home/home',//首页 ---------------------
'pages/login/login',//登入页面 ---------------------
'pages/shop/shop',//店铺页面 ---------------------
'pages/goods/goods',// 商品页面 ---------------------
'pages/goodsPublish/goodsPublish',// 商品发布页面 ---------------------
'pages/supplyDemandPublish/supplyDemandPublish',// 供求发布页面 ---------------------
'pages/mySupplyDemand/mySupplyDemand',// 我的供求列表页面 ---------------------
'pages/myGoodsEdit/myGoodsEdit',// 我的商品编辑页面 ---------------------
'pages/allDemanding/allDemanding',// 所有供求页面 ---------------------
'pages/myGoodList/myGoodList',// 我的商品列表页面 --------------------- 编辑商品按键
'pages/myDemandSupplyEdit/myDemandSupplyEdit',// 我的供求编辑页面 ---------------------
'pages/supplyDemandView/supplyDemandView',// 查看单个供求页面
'pages/grabOrderPage/grabOrderPage',// 抢单页面
'pages/myNeeds/myNeeds',// 我的需求页面
'pages/myNeedsView/myNeedsView',// 单个需求查看页面
'pages/myNeedsEdit/myNeedsEdit',// 单个需求编辑页面
'pages/myNeedsPublish/myNeedsPublish',// 需求发布
// 'pages/shopDescription/shopDescription',
],
permission: {
"scope.userLocation": {
"desc": "你的位置信息将用于小程序位置接口的效果展示"
}
},
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black',
// enablePullDownRefresh:true
onReachBottomDistance: 0
},
tabBar: {
list: [{
pagePath: "pages/home/home",
text: "首页",
iconPath: "./icons/home.png",
selectedIconPath: "./icons/home-actived.png"
},
, {
pagePath: "pages/myNeedsPublish/myNeedsPublish",
text: "需求发布",
iconPath: "./icons/publish.png",
selectedIconPath: "./icons/publish-actived.png"
}
, {
pagePath: "pages/myNeeds/myNeeds",
text: "我的需求",
iconPath: "./icons/needs.png",
selectedIconPath: "./icons/needs-actived.png"
}
// , {
// pagePath: "pages/individualCenter/individualCenter",
// text: "个人中心",
// iconPath: "./icons/needs.png",
// selectedIconPath: "./icons/needs-actived.png"
// }
],
color: '#333',
selectedColor: '#FF7142',
backgroundColor: '#fff',
borderStyle: 'black'
navigationBarTitleText: '登入'
}
constructor() {
this.state = {
username: '',
password: '',
backgroundImage: 'background-image:url(' + URL.Base + '/Public/images/bg3.jpg);'
}
}
//用户信息姓名和电话号码接口
setUserInfoToStorage() {
Taro.request({
url: URL.ShopWxStore,
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
}
})
.then(res => {
if (res.data.err_msg === 'success') {
Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
loginApi() {
Taro.request({
url: URL.Base + 'user-login',
method: 'POST',
dataType: 'json',
data: {
username: this.state.username,
password: this.state.password,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.data.err_code === 0) {
Taro.showToast({
title: res.data.err_msg && '登入成功',
icon: 'success',
duration: 1000
})
Taro.setStorageSync('session_id', res.data.session_id)
Taro.setStorageSync('shopInfo', res.data.shop_info)
Taro.setStorageSync('userInfo', res.data.user_info)
Taro.setStorageSync('accountInfo',{username:this.state.username,password:this.state.password})
this.setUserInfoToStorage()
setTimeout(() => {
// Taro.navigateBack({
// delta: 1
// })
Taro.reLaunch({
url:'/pages/home/home'
})
}, 1000);
} else {
Taro.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
}
})
}
usernameHandler(e) {
let value = e.detail.value
this.setState({ username: value })
}
passwordHandler(e) {
let value = e.detail.value
this.setState({ password: value })
}
loginHandler() {
this.loginApi()
}
componentDidMount() {
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
componentWillUnmount() { }
componentDidShow() { }
componentDidHide() { }
componentCatchError() { }
componentDidCatchError() { }
// 在 App 类中的 render() 函数没有实际作用
// 请勿修改此函数
render() {
return (
<Provider store={store}>
<Home />
</Provider>
<View className='login'>
<View className='background' style={this.state.backgroundImage}></View>
<View className='logo'>
<View className='image-wrapper'>
<View className='image-inner-wrapper'>
<Image style='width: 240px;height: 80px;background: #fff;' src={URL.Base + '/Public/images/com-logo.png'} />
</View>
<View className='title'>全屋定制商城</View>
</View>
</View>
<View className='login-wrapper'>
<View className='title'>用户登入</View>
<View className='bgtopWrap'>
<View className='loginWrap'>
<View className='username'>
<Input type='text' focus={true} name='username' maxLength='11' placeholder='请输入用户名/手机号' value={this.state.username} onInput={this.usernameHandler} />
</View>
<View className='password'>
<Input type='password' name='password' placeholder='请输入密码' value={this.state.password} onInput={this.passwordHandler} />
</View>
<Button className='button button-orange' onClick={this.loginHandler}>登录</Button>
</View>
</View>
</View>
</View>
)
}
}
Taro.render(<App />, document.getElementById('app'))
// {
// pagePath: "pages/goodsPublish/goodsPublish",
// text: "商品发布",
// iconPath: "./icons/box.png",
// selectedIconPath: "./icons/box-actived.png"
// }, {
// pagePath: "pages/supplyDemandPublish/supplyDemandPublish",
// text: "供求发布",
// iconPath: "./icons/publish.png",
// selectedIconPath: "./icons/publish-actived.png"
// }
// , {
// pagePath: "pages/mySupplyDemand/mySupplyDemand",
// text: "我的供求",
// iconPath: "./icons/menu.png",
// selectedIconPath: "./icons/menu-actived.png"
// }
export default Login

View File

@ -1,85 +1,11 @@
import Taro from '@tarojs/taro'
// //用户信息姓名和电话号码接口
// const setUserInfoToStorage=()=>{
// Taro.request({
// url: URL.ShopWxStore,
// header: {
// 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
// }
// })
// .then(res => {
// if (res.data.err_msg === 'success') {
// Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
// } else {
// Taro.showToast({
// title: res.data.err_msg,
// icon: 'none',
// duration: 1500
// })
// }
// })
// }
// 异步函数登入api
// 当用户没用登入时候 切换到首页, 然后导航到登录页面
export default function login() {
Taro.redirectTo({
url: '/pages/login/login'
Taro.switchTab({
url: '/pages/home/home'
})
Taro.navigateTo({
url:'/pages/login/login'
})
// Taro.login({
// success(res) {
// if (res.code) {
// // 发起网络请求
// // console.log('手机端微信code',res.code)
// Taro.request({
// url: URL.Login,
// method: 'POST',
// dataType: 'json',
// data: {
// code: res.code
// },
// header: {
// 'content-type': 'application/x-www-form-urlencoded',
// }
// })
// .then(response => {
// if (response.data.err_code === 888) {
// console.log('微信登入成功', response)
// Taro.showToast({
// title: '微信登入成功',
// icon: 'success',
// duration: 2000
// })
// Taro.setStorageSync('session_id', response.data.session_id)
// Taro.setStorageSync('shopInfo', response.data.shop_info)
// Taro.setStorageSync('userInfo', response.data.user_info)
// setUserInfoToStorage()
// } else if (response.data.err_code === 0){
// Taro.redirectTo({
// url: '/pages/login/login'
// })
// }else{
// Taro.showToast({
// title: '登入失败' + response.data.err_msg,
// icon: 'none',
// duration: 2000
// })
// }
// }
// ).catch(err => {
// console.log('登入微信失败', err)
// }).then(()=>{
// })
// }
// else {
// console.log('登录失败!' + res.errMsg)
// }
// }
// })
}

View File

@ -1,14 +1,47 @@
import Taro from '@tarojs/taro'
import standardLogin from '../util/standardLogin'
import weChatLogin from '../util/weChatLogin'
export default function loginExpired(res){
Taro.clearStorageSync()
Taro.showToast({
title: res.data.err_msg,
icon: 'none'
const tabbarURL = [
"pages/home/home",
"pages/myNeedsPublish/myNeedsPublish",
"pages/myNeeds/myNeeds",
"pages/individualCenter/individualCenter"
]
function reloadPage(){
let length = Taro.getCurrentPages().length - 1
let currentURL = Taro.getCurrentPages()[length].route
tabbarURL.includes(currentURL) ?
Taro.reLaunch({
url: '/' + currentURL
}) : Taro.navigateBack({
delta:-1
})
}
export default function loginExpired(res) {
// Taro.clearStorageSync()
Taro.showToast({
title:'登录过期,重新登录中...',
icon:'none',
duration:2000
})
setTimeout(() => {
Taro.reLaunch({
url: '/pages/home/home'
const hasAccount = Taro.getStorageSync('accountInfo')
if (hasAccount) {
standardLogin(hasAccount.username, hasAccount.password).then(res => {
reloadPage()
})
}, 1500);
} else {
weChatLogin().then(res=>{
reloadPage()
})
}
}, 2000);
}

View File

@ -0,0 +1,18 @@
import Taro from '@tarojs/taro'
const tabbarURL = [
"pages/home/home",
"pages/myNeedsPublish/myNeedsPublish",
"pages/myNeeds/myNeeds",
"pages/individualCenter/individualCenter"
]
export default function reloadCurrentPage() {
let currentURL = Taro.getCurrentPages().route
console.log('reloadCurrentPage',currentURL)
tabbarURL.includes(currentURL) ?
Taro.switchTab({
url: '/' + currentURL
}) : Taro.redirectTo({
url: '/' + currentURL
})
}

60
src/util/standardLogin.js Normal file
View File

@ -0,0 +1,60 @@
import Taro from '@tarojs/taro'
import URL from '../serviceAPI.config'
const setUserInfoToStorage = () => {
Taro.request({
url: URL.ShopWxStore,
header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
}
})
.then(res => {
if (res.data.err_msg === 'success') {
Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
} else {
Taro.showToast({
title: res.data.err_msg,
icon: 'none',
duration: 1500
})
}
})
}
export default function standardLogin(username, password) {
return new Promise((resolve,reject)=>{
Taro.request({
url: URL.Base + 'user-login',
method: 'POST',
dataType: 'json',
data: {
username: username,
password: password,
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
if (res.data.err_code === 0) {
Taro.showToast({
title: '登入成功',
icon: 'success',
duration: 1000
})
Taro.setStorageSync('session_id', res.data.session_id)
Taro.setStorageSync('shopInfo', res.data.shop_info)
Taro.setStorageSync('userInfo', res.data.user_info)
Taro.setStorageSync('accountInfo', { username: username, password: password })
setUserInfoToStorage()
resolve('success')
} else {
reject(res)
}
})
})
}

View File

@ -26,7 +26,7 @@ const setUserInfoToStorage = () => {
// 异步函数登入api
export default function login() {
export default function wechatLogin() {
return new Promise((resolve,reject)=>{
Taro.login({
success(res) {