diff --git a/src/LoginService.js b/src/LoginService.js
new file mode 100644
index 0000000..77d8ef7
--- /dev/null
+++ b/src/LoginService.js
@@ -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)
+// }
+// }
+// })
+}
\ No newline at end of file
diff --git a/src/component/filteredShopComponent/filteredShopComponent.js b/src/component/filteredShopComponent/filteredShopComponent.js
index 4f308e1..4619c6f 100644
--- a/src/component/filteredShopComponent/filteredShopComponent.js
+++ b/src/component/filteredShopComponent/filteredShopComponent.js
@@ -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 {
@@ -237,6 +240,7 @@ class recommondShop extends Component {
type='number'
maxLength='11'
value={this.state.userPhone}
+ placeholder='请输入联系电话'
onInput={this.handleInputCsultPhone.bind(this)}
/>
@@ -249,7 +253,10 @@ class recommondShop extends Component {
{voucherModalElement}
{consultModalElement}
- {
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 (
-
{/* */}
@@ -132,12 +129,12 @@ class VoucherPoster extends Component {
联系人:
-
+
联系电话:
-
+
diff --git a/src/component/scrollToTopComponent/scrollToTopComponent.scss b/src/component/scrollToTopComponent/scrollToTopComponent.scss
index de817d3..7399acf 100644
--- a/src/component/scrollToTopComponent/scrollToTopComponent.scss
+++ b/src/component/scrollToTopComponent/scrollToTopComponent.scss
@@ -11,7 +11,6 @@
font-size:25rpx;
.box{
margin-top:6%;
-
}
diff --git a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js
index d2d6f9e..875f982 100644
--- a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js
+++ b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js
@@ -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 (
{/* 大类 */}
-
+
diff --git a/src/pages/goodsPublish/goodsPublish.js b/src/pages/goodsPublish/goodsPublish.js
index 222d102..41cf6da 100644
--- a/src/pages/goodsPublish/goodsPublish.js
+++ b/src/pages/goodsPublish/goodsPublish.js
@@ -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 {
{/* 店铺分类 */}
@@ -401,9 +424,6 @@ class GoodsPublish extends Component {
-
-
-
diff --git a/src/pages/grabOrderPage/grabOrderPage.js b/src/pages/grabOrderPage/grabOrderPage.js
index 9b481d4..44ff40d 100644
--- a/src/pages/grabOrderPage/grabOrderPage.js
+++ b/src/pages/grabOrderPage/grabOrderPage.js
@@ -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 =
diff --git a/src/pages/home/home.js b/src/pages/home/home.js
index 38fb902..dfdfb48 100644
--- a/src/pages/home/home.js
+++ b/src/pages/home/home.js
@@ -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
}) : 没有更多了
diff --git a/src/pages/home/home.scss b/src/pages/home/home.scss
index 149b9f3..d04eb8d 100644
--- a/src/pages/home/home.scss
+++ b/src/pages/home/home.scss
@@ -124,7 +124,7 @@ $themeColor: #FF7142;
}
.second-banner{
- height:26vh;
+ height:28vh;
.categories{
display: flex;
diff --git a/src/pages/login/login.js b/src/pages/login/login.js
index 54b44a6..865fb9b 100644
--- a/src/pages/login/login.js
+++ b/src/pages/login/login.js
@@ -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 (
-
-
-
-
-
+
+
+
+
+
- 全屋定制商城
-
-
-
-
- 用户登入
-
-
-
-
-
-
-
-
-
- 立即注册
-
-
+
+ 全屋定制商城
+
+
+
+ 用户登入
+
+
+
+
+
+
+
+
+
+ 立即注册
+
+
+
+
+
-
-
)
}
}
diff --git a/src/pages/login/login.scss b/src/pages/login/login.scss
index b34a5a0..221b579 100644
--- a/src/pages/login/login.scss
+++ b/src/pages/login/login.scss
@@ -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
}
diff --git a/src/pages/myGoodsEdit/myGoodsEdit.js b/src/pages/myGoodsEdit/myGoodsEdit.js
index bcb2d5a..2a7eec6 100644
--- a/src/pages/myGoodsEdit/myGoodsEdit.js
+++ b/src/pages/myGoodsEdit/myGoodsEdit.js
@@ -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 {
{/* 店铺分类 */}
diff --git a/src/pages/myNeeds/myNeeds.js b/src/pages/myNeeds/myNeeds.js
index b4a2850..f4a4d87 100644
--- a/src/pages/myNeeds/myNeeds.js
+++ b/src/pages/myNeeds/myNeeds.js
@@ -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
diff --git a/src/pages/mySupplyDemand/mySupplyDemand.js b/src/pages/mySupplyDemand/mySupplyDemand.js
index 09c95a1..bfac3af 100644
--- a/src/pages/mySupplyDemand/mySupplyDemand.js
+++ b/src/pages/mySupplyDemand/mySupplyDemand.js
@@ -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() { }
// 页面位置
diff --git a/src/pages/shop/shop.js b/src/pages/shop/shop.js
index 4b1f3ed..0e0b704 100644
--- a/src/pages/shop/shop.js
+++ b/src/pages/shop/shop.js
@@ -803,7 +803,8 @@ class Shop extends Component {
-
diff --git a/src/pages/supplyDemandPublish/supplyDemandPublish.js b/src/pages/supplyDemandPublish/supplyDemandPublish.js
index f0c4266..19617e6 100644
--- a/src/pages/supplyDemandPublish/supplyDemandPublish.js
+++ b/src/pages/supplyDemandPublish/supplyDemandPublish.js
@@ -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() { }
diff --git a/src/serviceAPI.config.js b/src/serviceAPI.config.js
index 8dd018e..4f2e54f 100644
--- a/src/serviceAPI.config.js
+++ b/src/serviceAPI.config.js
@@ -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', //登入接口
diff --git a/src/weChatLogin.js b/src/weChatLogin.js
new file mode 100644
index 0000000..de1066f
--- /dev/null
+++ b/src/weChatLogin.js
@@ -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)
+ }
+ }
+ })
+}
\ No newline at end of file