From 0263f775a525e2c16af8e098e91ef77097642be1 Mon Sep 17 00:00:00 2001 From: Maoqiang Zheng Date: Fri, 8 Mar 2019 17:32:42 +0800 Subject: [PATCH] =?UTF-8?q?alipay=20=E6=A0=B7=E5=BC=8F=201.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filteredShopComponent.js | 16 ++--- .../voucherPosterComponent.js | 3 +- .../goodsTypeInteractionComp.js | 70 +++++++++---------- .../interactionComponent.js | 3 +- .../shopTypeInteractionComp.js | 7 +- src/pages/allDemanding/allDemanding.js | 5 +- src/pages/goods/goods.js | 7 +- src/pages/goodsPublish/goodsPublish.js | 13 ++-- src/pages/grabOrderPage/grabOrderPage.js | 9 +-- src/pages/home/home.js | 24 +++++++ .../individualCenter/individualCenter.js | 12 ++-- .../myDemandSupplyEdit/myDemandSupplyEdit.js | 9 +-- src/pages/myGoodList/myGoodList.js | 14 ++-- src/pages/myGoodsEdit/myGoodsEdit.js | 13 ++-- src/pages/myNeeds/myNeeds.js | 7 +- src/pages/myNeedsEdit/myNeedsEdit.js | 9 +-- src/pages/myNeedsPublish/myNeedsPublish.js | 11 +-- src/pages/myNeedsView/myNeedsView.js | 5 +- src/pages/mySupplyDemand/mySupplyDemand.js | 9 +-- src/pages/shop/shop.js | 7 +- .../supplyDemandPublish.js | 19 ++--- .../supplyDemandView/supplyDemandView.js | 5 +- src/todo list.txt | 16 ++--- src/util/getSetStoage.js | 32 +++++++++ src/util/loginExpired.js | 3 +- src/util/logout.js | 3 +- src/util/onClickValueService.js | 1 - src/util/standardLogin.js | 14 ++-- src/util/weChatLogin.js | 3 +- 29 files changed, 214 insertions(+), 135 deletions(-) create mode 100644 src/util/getSetStoage.js diff --git a/src/component/filteredShopComponent/filteredShopComponent.js b/src/component/filteredShopComponent/filteredShopComponent.js index c503276..465eec4 100644 --- a/src/component/filteredShopComponent/filteredShopComponent.js +++ b/src/component/filteredShopComponent/filteredShopComponent.js @@ -7,6 +7,7 @@ import VoucherPosterComponent from './voucherPosterComponent/voucherPosterCompon import onClickValueService from '../../util/onClickValueService' import './filteredShopComponent.scss' import URL from '../../serviceAPI.config' +import { getGlobalStorage } from '../../util/getSetStoage'; const hornIcon = require('../../icons/horn.png') const houseIcon = require('../../icons/house.png') @@ -34,8 +35,8 @@ class recommondShop extends Component { isOpenConsult: false, consultTip: '', voucherResponseMsg: 'i am voucherResponseMsg', - userName: Taro.getStorageSync('user_identity').username || '', - userPhone: Taro.getStorageSync('user_identity').userphone || '', + userName: getGlobalStorage('user_identity').username || '', + userPhone: getGlobalStorage('user_identity').userphone || '', isCanConsult: true, isCanVoucher: true @@ -74,7 +75,7 @@ class recommondShop extends Component { header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -113,7 +114,7 @@ class recommondShop extends Component { header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -147,7 +148,7 @@ class recommondShop extends Component { header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -212,8 +213,8 @@ class recommondShop extends Component { this.setState({ isOpenVoucher: true, - userName: Taro.getStorageSync('user_identity').username, - userPhone: Taro.getStorageSync('user_identity').userphone + userName: getGlobalStorage('user_identity').username, + userPhone: getGlobalStorage('user_identity').userphone }, () => { this.getVoucherInfo({}) }) @@ -231,7 +232,6 @@ class recommondShop extends Component { render() { - const title = this.props.shop.shop_name const imgUrl = URL.Base + this.props.shop.goods[0].goods_url const price = this.props.shop.goods[0].goods_price diff --git a/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js b/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js index 850840a..f1e3b39 100644 --- a/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js +++ b/src/component/filteredShopComponent/voucherPosterComponent/voucherPosterComponent.js @@ -6,6 +6,7 @@ import { AtIcon } from 'taro-ui' import './voucherPosterComponent.scss' import URL from '../../../serviceAPI.config' import loginExpired from '../../../util/loginExpired' +import { getGlobalStorage } from '../../../util/getSetStoage'; @@ -50,7 +51,7 @@ class VoucherPoster extends Component { header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { diff --git a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js index af67340..eb452c0 100644 --- a/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js +++ b/src/component/goodsTypeInteractionComp/goodsTypeInteractionComp.js @@ -5,6 +5,7 @@ import { Picker } from 'taro-ui' import './goodsTypeInteractionComp.scss' import loginExpired from '../../util/loginExpired' +import { getGlobalStorage } from '../../util/getSetStoage'; let maxDepth = 0 let initialDataArray = [] @@ -35,46 +36,46 @@ class GoodsTypeInteractionComp extends Component { dataType: 'json', header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) .then(res => { if (res.data.err_code === 0) { console.log('商品分类目录', res) - - const recursionInteractionData=this.recursionInteraction(res.data.data) - maxDepth=0 - initialDataArray=[] - + + const recursionInteractionData = this.recursionInteraction(res.data.data) + maxDepth = 0 + initialDataArray = [] + this.recursionInitialized(res.data.data) // - const depthInArray=this.recursionDepth(res.data.data) - console.log('depthInArray',depthInArray) - console.log('initialDataArray',initialDataArray) - for(let i=initialDataArray.length;i { - // 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去 - // console.log('联动数据', this.state.interactionMultiArray) - // console.log('初始化数据', this.state.initailMultiArray) - + // 把全局变变量赋值给state之后,初始化商品分类为空, 不然第二次进去的时候会自动添加进去 + // console.log('联动数据', this.state.interactionMultiArray) + // console.log('初始化数据', this.state.initailMultiArray) + }) // 用递归来整理无限层次的数据 - // console.log('联动数据', this.recursionInteraction(res.data.data)) - // console.log('初始数据', this.recursionInitialized(res.data.data).reverse()) - }else if (res.data.err_code === 88888) { - loginExpired(res) + // console.log('联动数据', this.recursionInteraction(res.data.data)) + // console.log('初始数据', this.recursionInitialized(res.data.data).reverse()) + } else if (res.data.err_code === 88888) { + loginExpired(res) } else { Taro.showToast({ title: res.data.err_msg, icon: 'none' - }) + }) } } ) @@ -83,19 +84,16 @@ class GoodsTypeInteractionComp extends Component { }) } - - - //联动确认 bindMultiPickerChange(e) { // 如果没有上商品 那就不执行 - if(Taro.getStorageSync('shopInfo').shop_id){ + if (getGlobalStorage('shopInfo').shop_id) { this.setState({ multiIndex: e.detail.value.map(item => { if (item === null) { item = 0 } return item }) }, () => { - // console.log('picker发送选择改变,携带值为', this.state.multiIndex) + // console.log('picker发送选择改变,携带值为', this.state.multiIndex) this.returnResultToParent() - + }) } } @@ -110,7 +108,7 @@ class GoodsTypeInteractionComp extends Component { } } } - // 递归整理无限层初始数据,将整理好的数据赋值给initialDataArray + // 递归整理无限层初始数据,将整理好的数据赋值给initialDataArray recursionInitialized(data) { const arrayTem = [] if (data.length) { @@ -118,10 +116,10 @@ class GoodsTypeInteractionComp extends Component { arrayTem.push({ name: item.class_name, id: item.class_id }) } } - if(data[0].children.length){ + if (data[0].children.length) { this.recursionInitialized(data[0].children) } - initialDataArray.push(arrayTem) + initialDataArray.push(arrayTem) return arrayTem } @@ -156,7 +154,7 @@ class GoodsTypeInteractionComp extends Component { // arrayTem.length ? initialDataArray.push(arrayTem) : null // 数组为空则不添加 // return initialDataArray // } - + // 递归整理无限层初始数据 recursionDepth(data) { const arrayTem = [] @@ -320,12 +318,12 @@ class GoodsTypeInteractionComp extends Component { componentDidMount() { - if(Taro.getStorageSync('shopInfo').shop_id){ + if (getGlobalStorage('shopInfo').shop_id) { this.getProductCateList(this.props.url) - }else{ - + } else { + } - + } // 当然父组件有新的props的 会从新渲染组件 componentWillReceiveProps(nextProps) { diff --git a/src/component/interactionComponent/interactionComponent.js b/src/component/interactionComponent/interactionComponent.js index b4b53a7..11935cd 100644 --- a/src/component/interactionComponent/interactionComponent.js +++ b/src/component/interactionComponent/interactionComponent.js @@ -6,6 +6,7 @@ import { Picker } from 'taro-ui' import './interactionComponent.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; let maxDepth = 0 @@ -35,7 +36,7 @@ class Interaction extends Component { method: 'GET', dataType: 'json', header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } diff --git a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js index fac51fb..d526edd 100644 --- a/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js +++ b/src/component/shopTypeInteractionComp/shopTypeInteractionComp.js @@ -5,6 +5,7 @@ import { Picker } from 'taro-ui' import './shopTypeInteractionComp.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; class ShopTypeInteractionComp extends Component { @@ -33,7 +34,7 @@ class ShopTypeInteractionComp extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -46,7 +47,7 @@ class ShopTypeInteractionComp extends Component { return } console.log('店铺分类目录', res) - if(!Taro.getStorageSync('shopTypeObject')){ + if(!getGlobalStorage('shopTypeObject')){ Taro.setStorageSync('shopTypeObject',res.data.data) } this.setState({ @@ -127,7 +128,7 @@ class ShopTypeInteractionComp extends Component { } bindMultiPickerChange(e) { // console.log('picker发送选择改变,携带值为', e.detail.value) - if (Taro.getStorageSync('shopInfo').shop_id) { + if (getGlobalStorage('shopInfo').shop_id) { this.setState({ multiIndex: e.detail.value, }, () => { diff --git a/src/pages/allDemanding/allDemanding.js b/src/pages/allDemanding/allDemanding.js index 472881a..4566952 100644 --- a/src/pages/allDemanding/allDemanding.js +++ b/src/pages/allDemanding/allDemanding.js @@ -11,6 +11,7 @@ import onClickValueService from '../../util/onClickValueService' import URL from '../../serviceAPI.config' import './allDemanding.scss' import eyeIcon from '../../icons/eye.png' +import { getGlobalStorage } from '../../util/getSetStoage'; @@ -69,7 +70,7 @@ class AllDemanding extends Component { header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -139,7 +140,7 @@ class AllDemanding extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) diff --git a/src/pages/goods/goods.js b/src/pages/goods/goods.js index b25e9ce..ab52984 100644 --- a/src/pages/goods/goods.js +++ b/src/pages/goods/goods.js @@ -7,6 +7,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import LoginService from '../../util/LoginService' import URL from '../../serviceAPI.config' import './goods.scss' +import { getGlobalStorage } from '../../util/getSetStoage'; class Goods extends Component { @@ -46,7 +47,7 @@ class Goods extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -98,7 +99,7 @@ class Goods extends Component { } // 收藏商品 saveItem() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -110,7 +111,7 @@ class Goods extends Component { } //添加到购物车 addToCart() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } diff --git a/src/pages/goodsPublish/goodsPublish.js b/src/pages/goodsPublish/goodsPublish.js index be054e2..0f42cb8 100644 --- a/src/pages/goodsPublish/goodsPublish.js +++ b/src/pages/goodsPublish/goodsPublish.js @@ -13,6 +13,7 @@ import URL from '../../serviceAPI.config' import './goodsPublish.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; class GoodsPublish extends Component { @@ -89,7 +90,7 @@ class GoodsPublish extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -164,7 +165,7 @@ class GoodsPublish extends Component { }, header: { 'content-type': 'multipart/form-data', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' }, success(response) { @@ -264,7 +265,7 @@ class GoodsPublish extends Component { goToMyGoodListPage() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -283,7 +284,7 @@ class GoodsPublish extends Component { } componentWillMount() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() } } @@ -297,7 +298,7 @@ class GoodsPublish extends Component { componentWillUnmount() { } componentDidShow() { - if (!Taro.getStorageSync('shopInfo').shop_id && Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('shopInfo').shop_id && getGlobalStorage('userInfo').user_id) { Taro.showToast({ title: '您还没有店铺,不能使用该功能,快去申请吧', icon: 'none' @@ -375,7 +376,7 @@ class GoodsPublish extends Component { {/* 店铺分类 */} diff --git a/src/pages/grabOrderPage/grabOrderPage.js b/src/pages/grabOrderPage/grabOrderPage.js index 03c2288..498c32e 100644 --- a/src/pages/grabOrderPage/grabOrderPage.js +++ b/src/pages/grabOrderPage/grabOrderPage.js @@ -9,6 +9,7 @@ import RenderingView from './renderingView/renderingView' import CopyrightComponent from '../../component/copyrightComponent/copyrightComponent' import './grabOrderPage.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; class GrabOrderPage extends Component { @@ -48,7 +49,7 @@ class GrabOrderPage extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -96,7 +97,7 @@ class GrabOrderPage extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -208,7 +209,7 @@ class GrabOrderPage extends Component { demandId: demandId }, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } @@ -238,7 +239,7 @@ class GrabOrderPage extends Component { } render() { - const localStoageUserId = Taro.getStorageSync('userInfo').user_id + const localStoageUserId = getGlobalStorage('userInfo').user_id // 提示框 const deleteModalWindowElement = diff --git a/src/pages/home/home.js b/src/pages/home/home.js index 8faa131..060eec0 100644 --- a/src/pages/home/home.js +++ b/src/pages/home/home.js @@ -144,6 +144,27 @@ class Home extends Component { ) } getUserLocation() { + + if (process.env.TARO_ENV === 'alipay') { + return new Promise((resolve, reject) => { + my.getLocation({ + success(res) { + my.hideLoading(); + + resolve(res) + }, + fail(res) { + my.hideLoading(); + my.alert({ title: '定位失败' }); + reject(res) + }, + }) + + }) + + + + } else if (process.env.TARO_ENV === 'weapp') { return new Promise((resolve, reject) => { Taro.getLocation({ type: 'wgs84', // 返回可以用于wx.openLocation的经纬度 @@ -160,6 +181,9 @@ class Home extends Component { }) }) + + } + } diff --git a/src/pages/individualCenter/individualCenter.js b/src/pages/individualCenter/individualCenter.js index 058cd4e..0e2bb6a 100644 --- a/src/pages/individualCenter/individualCenter.js +++ b/src/pages/individualCenter/individualCenter.js @@ -8,6 +8,7 @@ import Logout from '../../util/logout' import './individualCenter.scss' import URL from '../../serviceAPI.config' import onClickValueService from '../../util/onClickValueService'; +import { getGlobalStorage } from '../../util/getSetStoage'; @@ -100,10 +101,10 @@ class IndividualCenter extends Component { // }) } getInfoFromStorage() { - const username = Taro.getStorageSync('userInfo').login_name||'' - const avatar = Taro.getStorageSync('userInfo').avatar||'' - const vip_level=Taro.getStorageSync('userInfo').vip_name||'' - const isShop = Taro.getStorageSync('shopInfo').shop_id ? true : false + const username = getGlobalStorage('userInfo').login_name||'' + const avatar = getGlobalStorage('userInfo').avatar||'' + const vip_level=getGlobalStorage('userInfo').vip_name||'' + const isShop = getGlobalStorage('shopInfo').shop_id ? true : false this.setState({ username, avatar, isShop,vip_level }) @@ -121,7 +122,8 @@ class IndividualCenter extends Component { componentWillUnmount() { } componentDidShow() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { + console.log('login service') LoginService() return } diff --git a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js index 7f26463..92ab4a5 100644 --- a/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js +++ b/src/pages/myDemandSupplyEdit/myDemandSupplyEdit.js @@ -9,6 +9,7 @@ import URL from '../../serviceAPI.config' import './myDemandSupplyEdit.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; @@ -50,7 +51,7 @@ class MyDemandSupplyEdit extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -126,7 +127,7 @@ class MyDemandSupplyEdit extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -177,7 +178,7 @@ class MyDemandSupplyEdit extends Component { name: 'file', header: { 'content-type': 'multipart/form-data', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' }, success(response) { @@ -222,7 +223,7 @@ class MyDemandSupplyEdit extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) diff --git a/src/pages/myGoodList/myGoodList.js b/src/pages/myGoodList/myGoodList.js index e456ef7..9655432 100644 --- a/src/pages/myGoodList/myGoodList.js +++ b/src/pages/myGoodList/myGoodList.js @@ -8,6 +8,7 @@ import URL from '../../serviceAPI.config' import './myGoodList.scss' import loginExpired from '../../util/loginExpired'; import onClickValueService from '../../util/onClickValueService'; +import { getGlobalStorage } from '../../util/getSetStoage'; class MyGoodList extends Component { @@ -83,7 +84,7 @@ class MyGoodList extends Component { dataType: 'json', header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } @@ -137,7 +138,7 @@ class MyGoodList extends Component { order: order }, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } @@ -220,7 +221,7 @@ class MyGoodList extends Component { // order: order // }, // header: { - // 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + // 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), // 'content-type': 'application/x-www-form-urlencoded', // 'X-Requested-With': 'XMLHttpRequest' // } @@ -256,7 +257,7 @@ class MyGoodList extends Component { goodsID: JSON.stringify(goodsID) }, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } @@ -303,7 +304,7 @@ class MyGoodList extends Component { goodsID: JSON.stringify(goodsID) }, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } @@ -493,10 +494,11 @@ class MyGoodList extends Component { // 单个商品选择 handleCheckChange(e) { //如果goodid 一样的那么checked 就取反 + console.log('clicke') const id = onClickValueService(e) const newMyGoodList = this.state.myGoodList.map((item) => { if (item.goods_id === id) { - item.checked = !item.checked + item['checked'] = !item.checked } return item }) diff --git a/src/pages/myGoodsEdit/myGoodsEdit.js b/src/pages/myGoodsEdit/myGoodsEdit.js index 7be0adf..d33cbc5 100644 --- a/src/pages/myGoodsEdit/myGoodsEdit.js +++ b/src/pages/myGoodsEdit/myGoodsEdit.js @@ -8,6 +8,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import URL from '../../serviceAPI.config' import './myGoodsEdit.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; class MyGoodsEdit extends Component { config = { @@ -41,7 +42,7 @@ class MyGoodsEdit extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -63,9 +64,9 @@ class MyGoodsEdit extends Component { // } // } // } - if (Taro.getStorageSync('shopTypeObject')) { + if (getGlobalStorage('shopTypeObject')) { let selectedValue = '' - const shopTypeObject = Taro.getStorageSync('shopTypeObject') + const shopTypeObject = getGlobalStorage('shopTypeObject') for (let key in shopTypeObject) { for (let item of shopTypeObject[key].c) { if (item.id === res.data.goods.shop_class_id) { @@ -157,7 +158,7 @@ class MyGoodsEdit extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -234,7 +235,7 @@ class MyGoodsEdit extends Component { }, header: { 'content-type': 'multipart/form-data', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' }, success(response) { @@ -440,7 +441,7 @@ class MyGoodsEdit extends Component { {/* 店铺分类 */} { @@ -268,7 +269,7 @@ class Shop extends Component { // 'content-type': 'application/x-www-form-urlencoded', // 'X-Requested-With': 'XMLHttpRequest' 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -314,7 +315,7 @@ class Shop extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { diff --git a/src/pages/supplyDemandPublish/supplyDemandPublish.js b/src/pages/supplyDemandPublish/supplyDemandPublish.js index 4d1a12b..ba885dd 100644 --- a/src/pages/supplyDemandPublish/supplyDemandPublish.js +++ b/src/pages/supplyDemandPublish/supplyDemandPublish.js @@ -9,6 +9,7 @@ import LoginService from '../../util/LoginService' import URL from '../../serviceAPI.config' import './supplyDemandPublish.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; class SupplyDemand extends Component { config = { @@ -22,8 +23,8 @@ class SupplyDemand extends Component { demandingSupplyState: [{ name: '上架', id: '1' }, { name: '下架', id: '0' }], // 状态选择 demandingSupplyStateSelected: { name: '上架', id: '1' },// 当前状态 title: '', - contactName: Taro.getStorageSync('user_identity').username||'', - contactNumber: Taro.getStorageSync('user_identity').userphone||'', + contactName: getGlobalStorage('user_identity').username||'', + contactNumber: getGlobalStorage('user_identity').userphone||'', contactAddress: '', content: '', pickerImageUrl: [], // 上传的图片 @@ -68,7 +69,7 @@ class SupplyDemand extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -124,7 +125,7 @@ class SupplyDemand extends Component { }, header: { 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryAWxeadaAVmRVQCiz', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' }, success(response) { @@ -196,7 +197,7 @@ class SupplyDemand extends Component { // 上传供求api publishButtonHandler() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -216,7 +217,7 @@ class SupplyDemand extends Component { } } publishAndNewButton() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -236,7 +237,7 @@ class SupplyDemand extends Component { } } goToMyDemSupPage() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -258,11 +259,11 @@ class SupplyDemand extends Component { componentWillUnmount() { } componentDidShow() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } - if (!Taro.getStorageSync('shopInfo').shop_id && Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('shopInfo').shop_id && getGlobalStorage('userInfo').user_id) { Taro.showToast({ title: '您还没有店铺,不能使用该功能,快去申请吧', icon: 'none' diff --git a/src/pages/supplyDemandView/supplyDemandView.js b/src/pages/supplyDemandView/supplyDemandView.js index c2b8d7e..3e36ba6 100644 --- a/src/pages/supplyDemandView/supplyDemandView.js +++ b/src/pages/supplyDemandView/supplyDemandView.js @@ -9,6 +9,7 @@ import CopyrightComponent from '../../component/copyrightComponent/copyrightComp import './supplyDemandView.scss' import loginExpired from '../../util/loginExpired'; +import { getGlobalStorage } from '../../util/getSetStoage'; @@ -43,7 +44,7 @@ class SupplyDemandView extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -88,7 +89,7 @@ class SupplyDemandView extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) diff --git a/src/todo list.txt b/src/todo list.txt index fd602e5..2721e4e 100644 --- a/src/todo list.txt +++ b/src/todo list.txt @@ -52,8 +52,8 @@ class Home extends Component { otherData: [], // 底部导航栏 isOpen: false, // 抢单消息提示 grabOrderId: '',//抢到订单的id - userName: Taro.getStorageSync('user_identity').userName || '',//用户名字 - userPhone: Taro.getStorageSync('user_identity').userPhone || '',// 用户电话 + userName: getGlobalStorage('user_identity').userName || '',//用户名字 + userPhone: getGlobalStorage('user_identity').userPhone || '',// 用户电话 isShowTopNav: false,// 是否显示返回顶部按钮 loadMorePageIndex: 1,//下拉加载页面数 isAddToList: false, @@ -83,7 +83,7 @@ class Home extends Component { Taro.request({ url: URL.ShopWxStore, header: { - // 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + // 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -128,7 +128,7 @@ class Home extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { @@ -214,7 +214,7 @@ class Home extends Component { }, header: { 'content-type': 'application/x-www-form-urlencoded', - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), 'X-Requested-With': 'XMLHttpRequest' } }) @@ -265,7 +265,7 @@ class Home extends Component { } // 转到其他页面 goToAllDemandingPage() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() return } @@ -285,7 +285,7 @@ class Home extends Component { this.setState({ isOpen: false }) } handleGrabConfirm() { - if (!Taro.getStorageSync('userInfo').user_id) { + if (!getGlobalStorage('userInfo').user_id) { LoginService() } this.setState({ isOpen: false }) @@ -329,7 +329,7 @@ class Home extends Component { this.getHomeCategoriesInfo() }) // 本地缓存没有userid时 从新登入 - Taro.getStorageSync('userInfo').user_id ? true : weChatLogin() + getGlobalStorage('userInfo').user_id ? true : weChatLogin() diff --git a/src/util/getSetStoage.js b/src/util/getSetStoage.js new file mode 100644 index 0000000..79a657f --- /dev/null +++ b/src/util/getSetStoage.js @@ -0,0 +1,32 @@ +import Taro from '@tarojs/taro' + + +const setGlobalStorage = (key, value) => { + if (process.env.TARO_ENV === 'weapp') { + Taro.setStorageSync({ + key: key, + data: value + }) + + } else if (process.env.TARO_ENV === 'alipay') { + my.setStorageSync({ + key: key, + data: value + }) + } +} + +const getGlobalStorage = (key) => { + if (process.env.TARO_ENV === 'weapp') { + getGlobalStorage(key) + + } else if (process.env.TARO_ENV === 'alipay') { + + let res = my.getStorageSync({ + key: key, + }) + res.data=res.data?res.data:{username:'',userphone:'',user_id:''} + return res.data ||res.APDataStorage + } +} +export { setGlobalStorage, getGlobalStorage } \ No newline at end of file diff --git a/src/util/loginExpired.js b/src/util/loginExpired.js index 51e2b1e..d2c6fdd 100644 --- a/src/util/loginExpired.js +++ b/src/util/loginExpired.js @@ -1,6 +1,7 @@ import Taro from '@tarojs/taro' import standardLogin from '../util/standardLogin' import weChatLogin from '../util/weChatLogin' +import { getGlobalStorage } from './getSetStoage'; @@ -32,7 +33,7 @@ export default function loginExpired(res) { }) setTimeout(() => { - const hasAccount = Taro.getStorageSync('accountInfo') + const hasAccount = getGlobalStorage('accountInfo') if (hasAccount) { standardLogin(hasAccount.username, hasAccount.password).then(res => { diff --git a/src/util/logout.js b/src/util/logout.js index 477e0dc..4b95355 100644 --- a/src/util/logout.js +++ b/src/util/logout.js @@ -1,11 +1,12 @@ import Taro from '@tarojs/taro' import URL from '../serviceAPI.config' +import { getGlobalStorage } from './getSetStoage'; export default function logout() { Taro.request({ url:URL.LogOut, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }).then(res=>{ Taro.showToast({ diff --git a/src/util/onClickValueService.js b/src/util/onClickValueService.js index 53da28f..1284623 100644 --- a/src/util/onClickValueService.js +++ b/src/util/onClickValueService.js @@ -9,6 +9,5 @@ export default function onClickValueService(e) { value = e.currentTarget.dataset.eTapAA } value=typeof(value)==='string'?encodeURIComponent(value):value - console.log('value',value) return value } \ No newline at end of file diff --git a/src/util/standardLogin.js b/src/util/standardLogin.js index f31e793..4da89d1 100644 --- a/src/util/standardLogin.js +++ b/src/util/standardLogin.js @@ -1,17 +1,18 @@ import Taro from '@tarojs/taro' import URL from '../serviceAPI.config' +import { setGlobalStorage, getGlobalStorage } from './getSetStoage'; const setUserInfoToStorage = () => { Taro.request({ url: URL.ShopWxStore, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => { if (res.data.err_msg === 'success') { - Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) + setGlobalStorage('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) } else { Taro.showToast({ @@ -45,10 +46,11 @@ export default function standardLogin(username, password) { icon: 'success', duration: 1000 }) - Taro.setStorageSync('session_id', res.data.session_id) - Taro.setStorageSync('shopInfo', res.data.shop_info) - Taro.setStorageSync('userInfo', res.data.user_info) - Taro.setStorageSync('accountInfo', { username: username, password: password }) + + setGlobalStorage('session_id', res.data.session_id) + setGlobalStorage('shopInfo', res.data.shop_info) + setGlobalStorage('userInfo', res.data.user_info) + setGlobalStorage('accountInfo', { username: username, password: password }) setUserInfoToStorage() resolve('success') } else { diff --git a/src/util/weChatLogin.js b/src/util/weChatLogin.js index 3658d00..e56cc80 100644 --- a/src/util/weChatLogin.js +++ b/src/util/weChatLogin.js @@ -1,12 +1,13 @@ import Taro from '@tarojs/taro' import URL from '../serviceAPI.config' +import { getGlobalStorage } from './getSetStoage'; //用户信息姓名和电话号码接口 const setUserInfoToStorage = () => { Taro.request({ url: URL.ShopWxStore, header: { - 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), + 'Cookie': 'PFWSSS=' + getGlobalStorage('session_id'), } }) .then(res => {