添加路由权限 和登陆页面

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

View File

@ -1,7 +1,8 @@
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 './voucherPosterComponent.scss'
import URL from '../../../serviceAPI.config'
@ -15,8 +16,8 @@ class VoucherPoster extends Component {
constructor() {
super(...arguments);
this.state = {
voucherName: '',
voucherPhone: '',
voucherName: this.props.userName,
voucherPhone: this.props.userPhone,
voucherPosterImage: 'background-image:url(' + URL.Base + '/Public/images/store/m_yhq.png);'
}
}
@ -63,12 +64,6 @@ class VoucherPoster extends Component {
})
}
}).catch(err => {
console.log('购买咨询请求失败', err)
})
@ -102,23 +97,25 @@ class VoucherPoster extends Component {
passDataToParent() {
this.props.onPassDataToChild(false)
}
componentWillReceiveProps(nextProps) {
}
componentDidMount() {
this.setState({
voucherName: Taro.getStorageSync('user_identity').username,
voucherPhone: Taro.getStorageSync('user_identity').userphone,
})
}
componentWillUnmount() { }
componentDidShow() { }
componentDidShow() {
}
componentDidHide() { }
render() {
return (
<View className='voucherEventPopUpComponent'>
{/* <!-- The Modal --> */}
<View className='modal myModal' style={this.props.isVoucherPoster ? 'display:block' : 'display:none'}>
<View className='modal-content' >
@ -132,12 +129,12 @@ class VoucherPoster extends Component {
</View>
<View className='input-name' >
<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 className='input-number' >
<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 File

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

View File

@ -28,7 +28,7 @@ class ShopTypeInteractionComp extends Component {
method: 'POST',
dataType: 'json',
data: {
id: this.props.shopId || Taro.getStorageSync('shopInfo').shop_id
id: this.props.shopId
},
header: {
'content-type': 'application/x-www-form-urlencoded',
@ -134,6 +134,7 @@ class ShopTypeInteractionComp extends Component {
componentDidMount() {
this.getShopTypeList(this.props.url)
}
@ -149,8 +150,6 @@ class ShopTypeInteractionComp extends Component {
componentDidHide() { }
render() {
return (
<View class='page-section'>
<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 CopyrightComponent from '../../component/copyrightComponent/copyrightComponent'
import LoginService from '../../LoginService'
import URL from '../../serviceAPI.config'
import './goods.scss'
@ -95,6 +96,10 @@ class Goods extends Component {
}
// 收藏商品
saveItem() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({
title: '收藏成功',
icon: 'success',
@ -103,6 +108,10 @@ class Goods extends Component {
}
//添加到购物车
addToCart() {
if (!Taro.getStorageSync('userInfo').user_id) {
LoginService()
return
}
Taro.showToast({
title: '添加成功',
icon: 'success',
@ -116,6 +125,7 @@ class Goods extends Component {
selectorChecked: this.state.selector[e.detail.value]
})
}
componentDidMount() {
this.getGoodDescription()
@ -227,7 +237,7 @@ class Goods extends Component {
{/* 详情和评论区 */}
<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} >
<View style='background-color: #FAFBFC;' >

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
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 './login.scss'
@ -10,23 +10,42 @@ class Login extends Component {
config = {
navigationBarTitleText: '登入'
}
constructor(){
this.state={
username:'',
password:'',
backgroundImage: 'background-image:url(' + URL.Base + '/Public/images/bg3.jpg);'
}
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',
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',
@ -34,22 +53,30 @@ class Login extends Component {
}
})
.then(res => {
console.log('res',res)
if(res.data.err_code===0){
if (res.data.err_code === 0) {
Taro.showToast({
title: res.data.msg,
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.switchTab({
url: '/pages/home/home'
url:'/pages/home/home'
})
}, 1000);
}else{
} else {
Taro.showToast({
title: res.data.msg,
title: res.data.err_msg,
icon: 'none',
duration: 2000
})
@ -58,22 +85,22 @@ class Login extends Component {
})
}
usernameHandler(e){
let value=e.detail.value
this.setState({username:value})
usernameHandler(e) {
let value = e.detail.value
this.setState({ username: value })
}
passwordHandler(e){
let value=e.detail.value
this.setState({password:value})
passwordHandler(e) {
let value = e.detail.value
this.setState({ password: value })
}
loginHandler(){
loginHandler() {
this.loginApi()
}
componentDidMount() {
}
componentWillReceiveProps(nextProps) {
console.log(this.props, nextProps)
}
@ -87,36 +114,37 @@ class Login extends Component {
render() {
return (
<View className='login'>
<View className='background' style={this.state.backgroundImage}></View>
<View className='logo'>
<View className='image-wrapper'>
<View>
<Image style='width: 250px;height: 80px;background: #fff;' src={URL.Base +'/Public/images/com-logo.png'} />
<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>
<Text className='register'>
立即注册
</Text>
<Button className='button button-orange' onClick={this.loginHandler}>登录</Button>
<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>
<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-direction: row;
align-items: center;
.image-inner-wrapper{
flex:2;
}
.title{
margin-left: 15%;
flex:1;
text-align: right;
margin-right:5%;
font-size: 25rpx
}
}
@ -31,8 +36,9 @@
background-color: #fff;
width:80%;
top: 30%;
left: 8%;
padding: 2%;
left: 6%;
padding: 4%;
border-radius:20px;
.title{
font-size: 40rpx
}

View File

@ -81,33 +81,6 @@ class MyGoodsEdit extends Component {
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
uploadGoods({ goods_name = "test2",
goods_price = "1.00",
@ -355,7 +328,6 @@ class MyGoodsEdit extends Component {
}
componentDidMount() {
this.getShopTypeList(URL.GetShopCategoryList)
}
componentWillReceiveProps(nextProps) {
@ -428,6 +400,7 @@ class MyGoodsEdit extends Component {
</View>
{/* 店铺分类 */}
<ShopTypeInteractionComp url={URL.GetShopCategoryList}
shopId={Taro.getStorageSync('shopInfo').shop_id}
selectedValue={this.state.shopTypeSelected}
onPassDataToChild={this.getDataFromShopChild.bind(this)}
></ShopTypeInteractionComp>

View File

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

View File

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

View File

@ -803,7 +803,8 @@ class Shop extends Component {
<View className='nav'>
<View className='shop-cate'>
<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}
onPassDataToChild={this.getDataFromShopChild.bind(this)}
></ShopTypeInteractionComp>

View File

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

View File

@ -1,6 +1,6 @@
// const LOCALURL = "http://192.168.1.230/"
const LOCALURL = "https://www.ihome6.com/"
const LOCALURL = "http://192.168.1.230/"
//const LOCALURL = "https://www.ihome6.com/"
const URL = {
Base: LOCALURL,
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)
}
}
})
}