添加路由权限 和登陆页面

This commit is contained in:
郑茂强 2019-02-12 17:21:31 +08:00
parent cc7a0d5062
commit ccf896c310
19 changed files with 413 additions and 230 deletions

86
src/LoginService.js Normal file
View File

@ -0,0 +1,86 @@
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
})
}
})
}
// 异步函数登入api
export default function login() {
Taro.redirectTo({
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

@ -34,8 +34,8 @@ class recommondShop extends Component {
consultTip: '', consultTip: '',
voucherResponseMsg: '', voucherResponseMsg: '',
voucherCanConsult: false, voucherCanConsult: false,
userName: Taro.getStorageSync('user_identity').username, userName: Taro.getStorageSync('user_identity').username || '',
userPhone: Taro.getStorageSync('user_identity').userphone, userPhone: Taro.getStorageSync('user_identity').userphone || '',
} }
} }
goToShop(value) { goToShop(value) {
@ -136,7 +136,13 @@ class recommondShop extends Component {
// 优惠卷弹框。取消。确认 // 优惠卷弹框。取消。确认
isOpenVoucher() { isOpenVoucher() {
this.setState({ isOpenVoucher: true }) this.setState({
isOpenVoucher: true,
userName: Taro.getStorageSync('user_identity').username,
userPhone: Taro.getStorageSync('user_identity').userphone,
})
this.getVoucherInfo({}) this.getVoucherInfo({})
} }
voucherModalClose() { voucherModalClose() {
@ -148,7 +154,11 @@ class recommondShop extends Component {
} }
// 咨询弹框。取消。确认 // 咨询弹框。取消。确认
isOpenConsult() { isOpenConsult() {
this.setState({ isOpenConsult: true }) this.setState({
isOpenConsult: true,
userName: Taro.getStorageSync('user_identity').username,
userPhone: Taro.getStorageSync('user_identity').userphone,
})
this.getConsultInfo({}) this.getConsultInfo({})
} }
consultModalClose() { consultModalClose() {
@ -158,24 +168,16 @@ class recommondShop extends Component {
this.setState({ isOpenConsult: false }) this.setState({ isOpenConsult: false })
this.buyConsult({ user: this.state.userName, phone: this.state.userPhone }) this.buyConsult({ user: this.state.userName, phone: this.state.userPhone })
} }
handleInputVcherPhone(value) { handleInputCsultName(e) {
this.setState({ userPhone: value }) this.setState({ userName: e.detail.value })
} }
handleInputVcherName(value) { handleInputCsultPhone(e) {
this.setState({ userName: value }) this.setState({ userPhone: e.detail.value })
}
handleInputCsultName(value) {
this.setState({ userName: value })
}
handleInputCsultPhone(value) {
this.setState({ userPhone: value })
} }
getDataFromChild(value) { getDataFromChild(value) {
console.log('从voucherposter件传回来的值', value) console.log('从voucherposter件传回来的值', value)
this.setState({ isOpenVoucher: value }) this.setState({ isOpenVoucher: value })
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
//console.log(this.props, nextProps) //console.log(this.props, nextProps)
} }
@ -225,6 +227,7 @@ class recommondShop extends Component {
<Input name='value' <Input name='value'
type='text' type='text'
value={this.state.userName} value={this.state.userName}
placeholder='请输入联系人'
onInput={this.handleInputCsultName.bind(this)} onInput={this.handleInputCsultName.bind(this)}
/> />
@ -237,6 +240,7 @@ class recommondShop extends Component {
type='number' type='number'
maxLength='11' maxLength='11'
value={this.state.userPhone} value={this.state.userPhone}
placeholder='请输入联系电话'
onInput={this.handleInputCsultPhone.bind(this)} onInput={this.handleInputCsultPhone.bind(this)}
/> />
</View> </View>
@ -249,7 +253,10 @@ class recommondShop extends Component {
<View className='shop-list-box' > <View className='shop-list-box' >
{voucherModalElement} {voucherModalElement}
{consultModalElement} {consultModalElement}
<VoucherPosterComponent isVoucherPoster={this.state.isOpenVoucher} <VoucherPosterComponent
userName={this.state.userName}
userPhone={this.state.userPhone}
isVoucherPoster={this.state.isOpenVoucher}
onPassDataToChild={this.getDataFromChild.bind(this)} onPassDataToChild={this.getDataFromChild.bind(this)}
voucherLeft={this.props.shop.left_nums} voucherLeft={this.props.shop.left_nums}
voucherResponseMsg={this.state.voucherResponseMsg} voucherResponseMsg={this.state.voucherResponseMsg}

View File

@ -1,7 +1,8 @@
import Taro, { Component } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro'
import { View, Input, Text, Button } from '@tarojs/components' import { View, Input, Text, Button } from '@tarojs/components'
import { AtIcon } from 'taro-ui' import { AtIcon } from 'taro-ui'
import './voucherPosterComponent.scss' import './voucherPosterComponent.scss'
import URL from '../../../serviceAPI.config' import URL from '../../../serviceAPI.config'
@ -15,8 +16,8 @@ class VoucherPoster extends Component {
constructor() { constructor() {
super(...arguments); super(...arguments);
this.state = { this.state = {
voucherName: '', voucherName: this.props.userName,
voucherPhone: '', voucherPhone: this.props.userPhone,
voucherPosterImage: 'background-image:url(' + URL.Base + '/Public/images/store/m_yhq.png);' voucherPosterImage: 'background-image:url(' + URL.Base + '/Public/images/store/m_yhq.png);'
} }
} }
@ -63,12 +64,6 @@ class VoucherPoster extends Component {
}) })
} }
}).catch(err => { }).catch(err => {
console.log('购买咨询请求失败', err) console.log('购买咨询请求失败', err)
}) })
@ -102,23 +97,25 @@ class VoucherPoster extends Component {
passDataToParent() { passDataToParent() {
this.props.onPassDataToChild(false) this.props.onPassDataToChild(false)
} }
componentWillReceiveProps(nextProps) {
}
componentDidMount() { componentDidMount() {
this.setState({
voucherName: Taro.getStorageSync('user_identity').username,
voucherPhone: Taro.getStorageSync('user_identity').userphone,
})
} }
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
}
componentDidHide() { } componentDidHide() { }
render() { render() {
return ( return (
<View className='voucherEventPopUpComponent'> <View className='voucherEventPopUpComponent'>
{/* <!-- The Modal --> */} {/* <!-- The Modal --> */}
<View className='modal myModal' style={this.props.isVoucherPoster ? 'display:block' : 'display:none'}> <View className='modal myModal' style={this.props.isVoucherPoster ? 'display:block' : 'display:none'}>
<View className='modal-content' > <View className='modal-content' >
@ -132,12 +129,12 @@ class VoucherPoster extends Component {
</View> </View>
<View className='input-name' > <View className='input-name' >
<View className='title'> <Text>联系人</Text></View> <View className='title'> <Text>联系人</Text></View>
<Input class='input-info' type='text' value={this.state.voucherName} onInput={this.handleNameChange.bind(this)} /> <Input class='input-info' type='text' placeholder='请输入联系人' value={this.state.voucherName} onInput={this.handleNameChange.bind(this)} />
</View> </View>
<View className='input-number' > <View className='input-number' >
<View className='title'> <Text>联系电话</Text></View> <View className='title'> <Text>联系电话</Text></View>
<Input class='input-info' type='text' maxLength='11' value={this.state.voucherPhone} onInput={this.handlePhoneChange.bind(this)} /> <Input class='input-info' placeholder='请输入联系电话' type='text' maxLength='11' value={this.state.voucherPhone} onInput={this.handlePhoneChange.bind(this)} />
</View> </View>
<View> <View>

View File

@ -11,7 +11,6 @@
font-size:25rpx; font-size:25rpx;
.box{ .box{
margin-top:6%; margin-top:6%;
} }

View File

@ -28,7 +28,7 @@ class ShopTypeInteractionComp extends Component {
method: 'POST', method: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
id: this.props.shopId || Taro.getStorageSync('shopInfo').shop_id id: this.props.shopId
}, },
header: { header: {
'content-type': 'application/x-www-form-urlencoded', 'content-type': 'application/x-www-form-urlencoded',
@ -134,6 +134,7 @@ class ShopTypeInteractionComp extends Component {
componentDidMount() { componentDidMount() {
this.getShopTypeList(this.props.url) this.getShopTypeList(this.props.url)
} }
@ -149,8 +150,6 @@ class ShopTypeInteractionComp extends Component {
componentDidHide() { } componentDidHide() { }
render() { render() {
return ( return (
<View class='page-section'> <View class='page-section'>
<Picker <Picker

View File

@ -4,6 +4,7 @@ import { View, Text, Image, Swiper, SwiperItem } from '@tarojs/components'
import { AtTabs, AtTabsPane, AtSegmentedControl, AtIcon, Picker } from 'taro-ui' import { AtTabs, AtTabsPane, AtSegmentedControl, AtIcon, Picker } from 'taro-ui'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import URL from '../../serviceAPI.config' import URL from '../../serviceAPI.config'
import './goods.scss' import './goods.scss'
@ -95,6 +96,10 @@ class Goods extends Component {
} }
// 收藏商品 // 收藏商品
saveItem() { saveItem() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({ Taro.showToast({
title: '收藏成功', title: '收藏成功',
icon: 'success', icon: 'success',
@ -103,6 +108,10 @@ class Goods extends Component {
} }
//添加到购物车 //添加到购物车
addToCart() { addToCart() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({ Taro.showToast({
title: '添加成功', title: '添加成功',
icon: 'success', icon: 'success',
@ -116,6 +125,7 @@ class Goods extends Component {
selectorChecked: this.state.selector[e.detail.value] selectorChecked: this.state.selector[e.detail.value]
}) })
} }
componentDidMount() { componentDidMount() {
this.getGoodDescription() this.getGoodDescription()
@ -227,7 +237,7 @@ class Goods extends Component {
{/* 详情和评论区 */} {/* 详情和评论区 */}
<View className='details-box'> <View className='details-box'>
{/* 大类 */} {/* 大类 */}
<AtTabs className='alltabs' animated={false} current={this.state.current} tabList={mainTabList} onClick={this.handleClick.bind(this)}> <AtTabs className='alltabs' animated={false} current={this.state.current} tabList={mainTabList} onClick={this.handleClick.bind(this)}>
<AtTabsPane style='color:red' current={this.state.current} index={0} > <AtTabsPane style='color:red' current={this.state.current} index={0} >
<View style='background-color: #FAFBFC;' > <View style='background-color: #FAFBFC;' >

View File

@ -7,6 +7,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp
import ShopTypeInteractionComp from '../../component/shopTypeInteractionComp/shopTypeInteractionComp' import ShopTypeInteractionComp from '../../component/shopTypeInteractionComp/shopTypeInteractionComp'
import GoodsTypeInteractionComp from '../../component/goodsTypeInteractionComp/goodsTypeInteractionComp' import GoodsTypeInteractionComp from '../../component/goodsTypeInteractionComp/goodsTypeInteractionComp'
import LoginService from '../../LoginService'
import URL from '../../serviceAPI.config' import URL from '../../serviceAPI.config'
@ -31,8 +32,8 @@ class GoodsPublish extends Component {
ImagesInfo: [],// 后台传回来的图片信息 ImagesInfo: [],// 后台传回来的图片信息
shopCategoryList: [], shopCategoryList: [],
productCategoryList: [], productCategoryList: [],
isPublishAndAdd:false,// 是否点击发布新增按钮 isPublishAndAdd: false,// 是否点击发布新增按钮
isPublish:false, // 时候点击发布按钮 isPublish: false, // 时候点击发布按钮
} }
} }
@ -101,12 +102,12 @@ class GoodsPublish extends Component {
duration: 1000 duration: 1000
}) })
setTimeout(() => { setTimeout(() => {
if(this.state.isPublish){ if (this.state.isPublish) {
// 导航到编辑页面 // 导航到编辑页面
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/myGoodsEdit/myGoodsEdit?id=' + res.data.goods_id url: '/pages/myGoodsEdit/myGoodsEdit?id=' + res.data.goods_id
}) })
}else if(this.state.isPublishAndAdd){ } else if (this.state.isPublishAndAdd) {
// 导航到发布页面 // 导航到发布页面
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/goodsPublish/goodsPublish' url: '/pages/goodsPublish/goodsPublish'
@ -179,8 +180,8 @@ class GoodsPublish extends Component {
'X-Requested-With': 'XMLHttpRequest' 'X-Requested-With': 'XMLHttpRequest'
}, },
success(response) { success(response) {
const responseMsg=JSON.parse(response.data).err_msg const responseMsg = JSON.parse(response.data).err_msg
if (responseMsg=== 'success'||responseMsg === 'duplicate') { if (responseMsg === 'success' || responseMsg === 'duplicate') {
const data = JSON.parse(response.data) const data = JSON.parse(response.data)
const imagePath = URL.Base + data.file_path const imagePath = URL.Base + data.file_path
const newPickerImageUrl = that.state.pickerImageUrl.concat({ url: imagePath }) const newPickerImageUrl = that.state.pickerImageUrl.concat({ url: imagePath })
@ -217,6 +218,10 @@ class GoodsPublish extends Component {
} }
publishButtonHandler() { publishButtonHandler() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
if (this.state.productName && if (this.state.productName &&
this.state.productPrice && this.state.productPrice &&
this.state.productUnit && this.state.productUnit &&
@ -224,7 +229,7 @@ class GoodsPublish extends Component {
this.state.goodsTypeSelected.id && this.state.goodsTypeSelected.id &&
this.state.shopTypeSelected.id) { this.state.shopTypeSelected.id) {
Taro.showLoading({ title: '发布中' }).then(() => { Taro.showLoading({ title: '发布中' }).then(() => {
this.setState({isPublish:true},()=>{ this.setState({ isPublish: true }, () => {
this.uploadGoods({ this.uploadGoods({
goods_name: this.state.productName, goods_name: this.state.productName,
goods_price: this.state.productPrice, goods_price: this.state.productPrice,
@ -244,6 +249,10 @@ class GoodsPublish extends Component {
} }
} }
publishAndNewButton() { publishAndNewButton() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
if (this.state.productName && if (this.state.productName &&
this.state.productPrice && this.state.productPrice &&
this.state.productUnit && this.state.productUnit &&
@ -251,7 +260,7 @@ class GoodsPublish extends Component {
this.state.goodsTypeSelected.id && this.state.goodsTypeSelected.id &&
this.state.shopTypeSelected.id) { this.state.shopTypeSelected.id) {
Taro.showLoading({ title: '发布中' }).then(() => { Taro.showLoading({ title: '发布中' }).then(() => {
this.setState({isPublishAndAdd:true},()=>{ this.setState({ isPublishAndAdd: true }, () => {
this.uploadGoods({ this.uploadGoods({
goods_name: this.state.productName, goods_name: this.state.productName,
goods_price: this.state.productPrice, goods_price: this.state.productPrice,
@ -273,6 +282,11 @@ class GoodsPublish extends Component {
goToMyGoodListPage() { goToMyGoodListPage() {
console.log('list ', Taro.getStorageSync('userInfo'))
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/myGoodList/myGoodList' url: '/pages/myGoodList/myGoodList'
}) })
@ -286,6 +300,12 @@ class GoodsPublish extends Component {
console.log('从子组件商品分类传回来的值', value) console.log('从子组件商品分类传回来的值', value)
this.setState({ goodsTypeSelected: value }) this.setState({ goodsTypeSelected: value })
} }
componentWillMount() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
}
}
componentDidMount() { componentDidMount() {
// this.getProductCateList() // this.getProductCateList()
// this.getShopCateList() // this.getShopCateList()
@ -297,7 +317,9 @@ class GoodsPublish extends Component {
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
}
componentDidHide() { } componentDidHide() { }
@ -369,6 +391,7 @@ class GoodsPublish extends Component {
</View> </View>
{/* 店铺分类 */} {/* 店铺分类 */}
<ShopTypeInteractionComp url={URL.GetShopCategoryList} <ShopTypeInteractionComp url={URL.GetShopCategoryList}
shopId={Taro.getStorageSync('shopInfo').shop_id}
selectedValue={this.state.shopTypeSelected} selectedValue={this.state.shopTypeSelected}
onPassDataToChild={this.getDataFromShopChild.bind(this)} onPassDataToChild={this.getDataFromShopChild.bind(this)}
></ShopTypeInteractionComp> ></ShopTypeInteractionComp>
@ -401,9 +424,6 @@ class GoodsPublish extends Component {
<View className='button' onClick={this.goToMyGoodListPage.bind(this)}> <View className='button' onClick={this.goToMyGoodListPage.bind(this)}>
<Button size='mini' className='button-green'>商品列表</Button> <Button size='mini' className='button-green'>商品列表</Button>
</View> </View>
</View> </View>
<CopyrightComponent></CopyrightComponent> <CopyrightComponent></CopyrightComponent>

View File

@ -147,8 +147,6 @@ class GrabOrderPage extends Component {
render() { render() {
const localStoageUserId = Taro.getStorageSync('userInfo').user_id const localStoageUserId = Taro.getStorageSync('userInfo').user_id
let ButtonElement let ButtonElement
if (localStoageUserId === this.state.userId && this.state.stateId === '1') { if (localStoageUserId === this.state.userId && this.state.stateId === '1') {
ButtonElement = <View className='button-box'> ButtonElement = <View className='button-box'>

View File

@ -5,6 +5,8 @@ import FilteredShopComponent from '../../component/filteredShopComponent/filtere
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import weChatLogin from '../../weChatLogin'
import URL from '../../serviceAPI.config' import URL from '../../serviceAPI.config'
import './home.scss' import './home.scss'
@ -28,8 +30,8 @@ class Home extends Component {
otherData: [], // 底部导航栏 otherData: [], // 底部导航栏
isOpen: false, // 抢单消息提示 isOpen: false, // 抢单消息提示
grabOrderId: '',//抢到订单的id grabOrderId: '',//抢到订单的id
userName: '',//用户名字 userName: Taro.getStorageSync('user_identity').userName || '',//用户名字
userPhone: '',// 用户电话 userPhone: Taro.getStorageSync('user_identity').userPhone || '',// 用户电话
isShowTopNav: false,// 是否显示返回顶部按钮 isShowTopNav: false,// 是否显示返回顶部按钮
loadMorePageIndex: 1,//下拉加载页面数 loadMorePageIndex: 1,//下拉加载页面数
isAddToList: false, isAddToList: false,
@ -53,17 +55,16 @@ class Home extends Component {
//api得到首页的信息 //api得到首页的信息
getHomeCategoriesInfo() { getHomeCategoriesInfo() {
Taro.request({ Taro.request({
url: URL.ShopWxStore, url: URL.ShopWxStore,
header: { header: {
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), // 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
} }
}) })
.then(res => { .then(res => {
console.log('首页基本信息', res) console.log('首页基本信息', res)
if (res.data.err_msg === 'success') { if (res.data.err_msg === 'success') {
Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone })
this.setState({ this.setState({
ads: res.data.data.adsLb, ads: res.data.data.adsLb,
categories: [res.data.data.supplyClass[0], Object.values(res.data.data.supplyClass[1])], categories: [res.data.data.supplyClass[0], Object.values(res.data.data.supplyClass[1])],
@ -133,57 +134,7 @@ class Home extends Component {
) )
} }
// 异步函数登入api
async 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 === 0) {
console.log('微信登入成功', response)
Taro.setStorageSync('session_id', response.data.session_id)
Taro.setStorageSync('shopInfo', response.data.shop_info)
Taro.setStorageSync('userInfo', response.data.user_info)
} else if (response.data.err_code === 888){
Taro.navigateTo({
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)
}
}
})
}
// 微信用户设置 // 微信用户设置
// wxUserSetting() { // wxUserSetting() {
// Taro.getSetting({ // Taro.getSetting({
@ -268,6 +219,10 @@ class Home extends Component {
} }
// 转到其他页面 // 转到其他页面
goToAllDemandingPage() { goToAllDemandingPage() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/allDemanding/allDemanding' url: '/pages/allDemanding/allDemanding'
}) })
@ -283,6 +238,9 @@ class Home extends Component {
this.setState({ isOpen: false }) this.setState({ isOpen: false })
} }
handleGrabConfirm() { handleGrabConfirm() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
}
this.setState({ isOpen: false }) this.setState({ isOpen: false })
// 确认抢单之后 // 确认抢单之后
this.GrabDemand({ demandId: this.state.grabOrderId }) this.GrabDemand({ demandId: this.state.grabOrderId })
@ -306,16 +264,13 @@ class Home extends Component {
componentDidMount() { componentDidMount() {
// 页面加载后 得到首页的基本信息和推荐店铺的信息 // 页面加载后 得到首页的基本信息和推荐店铺的信息
(async ()=>{ Taro.showLoading({ title: '加载中' })
Taro.showLoading({ title: '加载中' }) if (!Taro.getStorageSync('userInfo').user_id) {
await this.login() weChatLogin()
this.getShops({}) }
this.getHomeCategoriesInfo()
console.log('didmount')
})()
this.getShops({})
this.getHomeCategoriesInfo()
// this.login().then(() => { // this.login().then(() => {
// this.getShops({}) // this.getShops({})
@ -329,7 +284,9 @@ class Home extends Component {
} }
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
}
componentDidHide() { } componentDidHide() { }
@ -425,8 +382,6 @@ class Home extends Component {
const shopCollectionElementsArray = this.state.shops.length ? this.state.shops.map((item, index) => { const shopCollectionElementsArray = this.state.shops.length ? this.state.shops.map((item, index) => {
return <FilteredShopComponent return <FilteredShopComponent
shop={item} shop={item}
userName={this.state.userName}
userPhone={this.state.userPhone}
key={index} key={index}
></FilteredShopComponent> ></FilteredShopComponent>
}) : <View className='no-more-title'> 没有更多了</View> }) : <View className='no-more-title'> 没有更多了</View>

View File

@ -124,7 +124,7 @@ $themeColor: #FF7142;
} }
.second-banner{ .second-banner{
height:26vh; height:28vh;
.categories{ .categories{
display: flex; display: flex;

View File

@ -1,5 +1,5 @@
import Taro, { Component } from '@tarojs/taro' import Taro, { Component } from '@tarojs/taro'
import { View,Input,Button,Text,Image } from '@tarojs/components' import { View, Input, Button, Text, Image } from '@tarojs/components'
import URL from '../../serviceAPI.config' import URL from '../../serviceAPI.config'
import './login.scss' import './login.scss'
@ -10,23 +10,42 @@ class Login extends Component {
config = { config = {
navigationBarTitleText: '登入' navigationBarTitleText: '登入'
} }
constructor(){ constructor() {
this.state={ this.state = {
username:'', username: '',
password:'', password: '',
backgroundImage: 'background-image:url(' + URL.Base + '/Public/images/bg3.jpg);' 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() { loginApi() {
Taro.request({ Taro.request({
url: URL.Base+'user-login', url: URL.Base + 'user-login',
method: 'POST', method: 'POST',
dataType: 'json', dataType: 'json',
data: { data: {
username: this.state.username, username: this.state.username,
password: this.state.password, password: this.state.password,
}, },
header: { header: {
'content-type': 'application/x-www-form-urlencoded', 'content-type': 'application/x-www-form-urlencoded',
@ -34,22 +53,30 @@ class Login extends Component {
} }
}) })
.then(res => { .then(res => {
console.log('res',res) if (res.data.err_code === 0) {
if(res.data.err_code===0){
Taro.showToast({ Taro.showToast({
title: res.data.msg, title: res.data.err_msg && '登入成功',
icon: 'success', icon: 'success',
duration: 1000 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(() => { setTimeout(() => {
// Taro.navigateBack({
// delta: 1
// })
Taro.switchTab({ Taro.switchTab({
url: '/pages/home/home' url:'/pages/home/home'
}) })
}, 1000); }, 1000);
}else{ } else {
Taro.showToast({ Taro.showToast({
title: res.data.msg, title: res.data.err_msg,
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}) })
@ -59,15 +86,15 @@ class Login extends Component {
} }
usernameHandler(e){ usernameHandler(e) {
let value=e.detail.value let value = e.detail.value
this.setState({username:value}) this.setState({ username: value })
} }
passwordHandler(e){ passwordHandler(e) {
let value=e.detail.value let value = e.detail.value
this.setState({password:value}) this.setState({ password: value })
} }
loginHandler(){ loginHandler() {
this.loginApi() this.loginApi()
} }
componentDidMount() { componentDidMount() {
@ -87,34 +114,35 @@ class Login extends Component {
render() { render() {
return ( return (
<View className='login'> <View className='login'>
<View className='background' style={this.state.backgroundImage}></View> <View className='background' style={this.state.backgroundImage}></View>
<View className='logo'> <View className='logo'>
<View className='image-wrapper'> <View className='image-wrapper'>
<View> <View className='image-inner-wrapper'>
<Image style='width: 250px;height: 80px;background: #fff;' src={URL.Base +'/Public/images/com-logo.png'} /> <Image style='width: 240px;height: 80px;background: #fff;' src={URL.Base + '/Public/images/com-logo.png'} />
</View>
<View className='title'>全屋定制商城</View>
</View> </View>
</View> <View className='title'>全屋定制商城</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>
<Text className='register'>
立即注册
</Text>
<Button className='button button-orange' onClick={this.loginHandler}>登录</Button>
</View> </View>
</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>
<Text className='register'>
立即注册
</Text>
<Button className='button button-orange' onClick={this.loginHandler}>登录</Button>
</View>
</View>
</View>
</View> </View>
) )

View File

@ -16,9 +16,14 @@
flex-wrap: nowrap; flex-wrap: nowrap;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
.image-inner-wrapper{
flex:2;
}
.title{ .title{
margin-left: 15%; flex:1;
text-align: right;
margin-right:5%;
font-size: 25rpx font-size: 25rpx
} }
} }
@ -31,8 +36,9 @@
background-color: #fff; background-color: #fff;
width:80%; width:80%;
top: 30%; top: 30%;
left: 8%; left: 6%;
padding: 2%; padding: 4%;
border-radius:20px;
.title{ .title{
font-size: 40rpx font-size: 40rpx
} }

View File

@ -81,33 +81,6 @@ class MyGoodsEdit extends Component {
console.log('商品详情获取失败', error) console.log('商品详情获取失败', error)
}) })
} }
//获取店铺分类筛选列表api
getShopTypeList(url) {
Taro.request({
url: url,
method: 'POST',
dataType: 'json',
data: {
id: Taro.getStorageSync('shopInfo').shop_id
},
header: {
'content-type': 'application/x-www-form-urlencoded',
'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'),
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(res => {
this.setState({ shopTypeList: res.data.data }, () => {
this.getGoodsInfo()
})
}
)
}
// 发布商品api // 发布商品api
uploadGoods({ goods_name = "test2", uploadGoods({ goods_name = "test2",
goods_price = "1.00", goods_price = "1.00",
@ -355,7 +328,6 @@ class MyGoodsEdit extends Component {
} }
componentDidMount() { componentDidMount() {
this.getShopTypeList(URL.GetShopCategoryList)
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
@ -428,6 +400,7 @@ class MyGoodsEdit extends Component {
</View> </View>
{/* 店铺分类 */} {/* 店铺分类 */}
<ShopTypeInteractionComp url={URL.GetShopCategoryList} <ShopTypeInteractionComp url={URL.GetShopCategoryList}
shopId={Taro.getStorageSync('shopInfo').shop_id}
selectedValue={this.state.shopTypeSelected} selectedValue={this.state.shopTypeSelected}
onPassDataToChild={this.getDataFromShopChild.bind(this)} onPassDataToChild={this.getDataFromShopChild.bind(this)}
></ShopTypeInteractionComp> ></ShopTypeInteractionComp>

View File

@ -6,6 +6,8 @@ import URL from '../../serviceAPI.config'
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
import InteractionComponent from '../../component/interactionComponent/interactionComponent' import InteractionComponent from '../../component/interactionComponent/interactionComponent'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import './myNeeds.scss' import './myNeeds.scss'
class MyNeeds extends Component { class MyNeeds extends Component {
@ -282,7 +284,12 @@ class MyNeeds extends Component {
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
componentDidHide() { } componentDidHide() { }
@ -299,19 +306,16 @@ class MyNeeds extends Component {
Taro.showLoading({ Taro.showLoading({
title: '加载中' title: '加载中'
}) })
this.setState({ isAddToList: true, loadMorePageIndex: this.state.loadMorePageIndex + 1 }, () => { this.setState({ isAddToList: true, loadMorePageIndex: this.state.loadMorePageIndex + 1 }, () => {
this.getMyNeedsList({ curr_page: this.state.loadMorePageIndex }) this.getMyNeedsList({ curr_page: this.state.loadMorePageIndex })
}) })
} }
getDataFromChild(value) { getDataFromChild(value) {
console.log('从子组件传回来的值', value) console.log('从子组件传回来的值', value)
this.setState({ industryTypeSelected: value }) this.setState({ industryTypeSelected: value })
} }
render() { render() {
console.log('myneed')
const myNeedsListArrayElement = this.state.allNeedsList.map((item, index) => { const myNeedsListArrayElement = this.state.allNeedsList.map((item, index) => {
return <View className='needs-box' key={index}> return <View className='needs-box' key={index}>
<View className='industy-type box'> <View className='industy-type box'>

View File

@ -5,6 +5,7 @@ import URL from '../../serviceAPI.config'
import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent' import ScrollToTopComponent from '../../component/scrollToTopComponent/scrollToTopComponent'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import './mySupplyDemand.scss' import './mySupplyDemand.scss'
@ -70,7 +71,7 @@ class MySupplyDemand extends Component {
console.log('我的供求列表', res) console.log('我的供求列表', res)
if (res.data.err_msg === "success") { if (res.data.err_msg === "success") {
if (this.state.isAddToList) { if (this.state.isAddToList) {
if (res.data.supplys.length&&res.data.count!=='0') { if (res.data.supplys.length && res.data.count !== '0') {
this.setState({ allDemandSupply: this.state.allDemandSupply.concat(res.data.supplys) }, () => { this.setState({ allDemandSupply: this.state.allDemandSupply.concat(res.data.supplys) }, () => {
this.setState({ isAddToList: false }) this.setState({ isAddToList: false })
}) })
@ -82,7 +83,7 @@ class MySupplyDemand extends Component {
}) })
} }
} else { } else {
if (res.data.count!=='0') { if (res.data.count !== '0') {
this.setState({ allDemandSupply: res.data.supplys, totalDemandSupply: res.data.count }) this.setState({ allDemandSupply: res.data.supplys, totalDemandSupply: res.data.count })
} else { } else {
this.setState({ allDemandSupply: [], totalDemandSupply: res.data.count }) this.setState({ allDemandSupply: [], totalDemandSupply: res.data.count })
@ -107,8 +108,8 @@ class MySupplyDemand extends Component {
onSearchButtonHandler() { onSearchButtonHandler() {
Taro.showLoading({ title: '加载中' }) Taro.showLoading({ title: '加载中' })
this.setState({ loadMorePageIndex:1 }, () => { this.setState({ loadMorePageIndex: 1 }, () => {
this.getMySupplyDemand({curr_page:this.state.loadMorePageIndex}) this.getMySupplyDemand({ curr_page: this.state.loadMorePageIndex })
}) })
} }
@ -247,7 +248,9 @@ class MySupplyDemand extends Component {
} }
componentWillMount() {
}
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps) console.log(this.props, nextProps)
} }
@ -259,7 +262,12 @@ class MySupplyDemand extends Component {
} }
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
componentDidHide() { } componentDidHide() { }
// 页面位置 // 页面位置

View File

@ -803,7 +803,8 @@ class Shop extends Component {
<View className='nav'> <View className='nav'>
<View className='shop-cate'> <View className='shop-cate'>
<View> <View>
<ShopTypeInteractionComp url={URL.GetShopCategoryList} style='position:absolute;z-index:2;opacity:0;left:0' <ShopTypeInteractionComp
url={URL.GetShopCategoryList} style='position:absolute;z-index:2;opacity:0;left:0'
shopId={this.state.shop_id} shopId={this.state.shop_id}
onPassDataToChild={this.getDataFromShopChild.bind(this)} onPassDataToChild={this.getDataFromShopChild.bind(this)}
></ShopTypeInteractionComp> ></ShopTypeInteractionComp>

View File

@ -4,9 +4,9 @@ import { View, Text, Button,Input } from '@tarojs/components'
import { AtInput, AtImagePicker, AtTextarea, Picker } from 'taro-ui' import { AtInput, AtImagePicker, AtTextarea, Picker } from 'taro-ui'
import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import URL from '../../serviceAPI.config' import URL from '../../serviceAPI.config'
import './supplyDemandPublish.scss' import './supplyDemandPublish.scss'
@ -191,6 +191,10 @@ class SupplyDemand extends Component {
// 上传供求api // 上传供求api
publishButtonHandler() { publishButtonHandler() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
if (this.state.demandingSupplyCateSelected && this.state.title && this.state.contactName && this.state.contactNumber && this.state.content && this.state.demandingSupplyStateSelected) { if (this.state.demandingSupplyCateSelected && this.state.title && this.state.contactName && this.state.contactNumber && this.state.content && this.state.demandingSupplyStateSelected) {
Taro.showLoading({ title: '发布中' }).then(() => { Taro.showLoading({ title: '发布中' }).then(() => {
@ -207,6 +211,10 @@ class SupplyDemand extends Component {
} }
} }
publishAndNewButton() { publishAndNewButton() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
if (this.state.demandingSupplyCateSelected && this.state.title && this.state.contactName && this.state.contactNumber && this.state.content && this.state.demandingSupplyStateSelected) { if (this.state.demandingSupplyCateSelected && this.state.title && this.state.contactName && this.state.contactNumber && this.state.content && this.state.demandingSupplyStateSelected) {
Taro.showLoading({ title: '发布中' }).then(() => { Taro.showLoading({ title: '发布中' }).then(() => {
@ -223,22 +231,33 @@ class SupplyDemand extends Component {
} }
} }
goToMyDemSupPage() { goToMyDemSupPage() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.navigateTo({ Taro.navigateTo({
url: '/pages/mySupplyDemand/mySupplyDemand' url: '/pages/mySupplyDemand/mySupplyDemand'
}) })
} }
componentWillMount(){
}
componentDidMount() { componentDidMount() {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps) // console.log(this.props, nextProps)
} }
componentWillUnmount() { } componentWillUnmount() { }
componentDidShow() { } componentDidShow() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
}
componentDidHide() { } componentDidHide() { }

View File

@ -1,6 +1,6 @@
// const LOCALURL = "http://192.168.1.230/" const LOCALURL = "http://192.168.1.230/"
const LOCALURL = "https://www.ihome6.com/" //const LOCALURL = "https://www.ihome6.com/"
const URL = { const URL = {
Base: LOCALURL, Base: LOCALURL,
Login: LOCALURL + 'Applet-login', //登入接口 Login: LOCALURL + 'Applet-login', //登入接口

73
src/weChatLogin.js Normal file
View File

@ -0,0 +1,73 @@
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
})
}
})
}
// 异步函数登入api
export default function 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{
Taro.showToast({
title: '微信登入失败',
icon: 'none',
duration: 2000
})
}
}
)
}
else {
console.log('登录失败!' + res.errMsg)
}
}
})
}