Browse Source

1、购买选择规格属性点不了

2、购物车列表点击管理 点击收藏功能去掉
3、下单点击积分抵扣没反应
4、待收货 列表查看物流点击没反应,详情查看物流可以点
5、添加地址选择地区无效
6、个人中心我的余额点进去点击账单记录一直正在加载中,点击下全部就出来了,应该你没带默认参数
8、订单点击评价没反应
9、小程序订单核销没上 你那边先根据路径判断隐藏下
10、我的推广,里面样式有问题,点击海报里面空白
11、分类点击 会分类Tab页分类一级比一级低
12、拼团详情客服功能隐藏去掉,其他地方有客服功能的都去掉
master
Gao xiaosong 5 years ago
parent
commit
728deeaa35
  1. 2
      assets/css/style.css
  2. 2
      assets/css/style.css.map
  3. 2
      assets/css/style.less
  4. 15
      components/OrderGoods.vue
  5. 24
      components/ProductWindow.vue
  6. 7
      pages/activity/DargainDetails/index.vue
  7. 3
      pages/activity/GoodsBargain/index.vue
  8. 4
      pages/activity/GroupDetails/index.vue
  9. 4
      pages/activity/SeckillDetails/index.vue
  10. 53
      pages/order/MyOrder/index.vue
  11. 1173
      pages/order/OrderDetails/index.vue
  12. 3
      pages/order/OrderSubmission/index.vue
  13. 4
      pages/shop/GoodsClass/index.vue
  14. 1683
      pages/shop/GoodsCon/index.vue
  15. 2
      pages/shop/ShoppingCart/index.vue
  16. 2
      pages/user/User/index.vue
  17. 17
      pages/user/address/AddAddress/index.vue
  18. 287
      pages/user/promotion/Poster/index.vue
  19. 17
      store/index.js
  20. 24
      utils/index.js
  21. 33
      utils/request.js

2
assets/css/style.css

File diff suppressed because one or more lines are too long

2
assets/css/style.css.map

File diff suppressed because one or more lines are too long

2
assets/css/style.less

@ -4494,7 +4494,7 @@ flex: 0 2.4*100rpx;
transform: rotate(180deg); transform: rotate(180deg);
} }
.bargain .bargainGang .title .pictrue img, .bargain .bargainGang .title .pictrue image,
.bargain .goodsDetails .title .pictrue image{ .bargain .goodsDetails .title .pictrue image{
width: 100%; width: 100%;
height: 100%; height: 100%;

15
components/OrderGoods.vue

@ -16,11 +16,7 @@
v-if="cart.productInfo.attrInfo" v-if="cart.productInfo.attrInfo"
>{{ cart.productInfo.attrInfo.suk }}</view> >{{ cart.productInfo.attrInfo.suk }}</view>
<view class="money font-color-red">{{ cart.truePrice }}</view> <view class="money font-color-red">{{ cart.truePrice }}</view>
<view <view class="evaluate" v-if="evaluate == 3" @click="routerGo(cart)">评价</view>
class="evaluate"
v-if="evaluate == 3"
@click="routerGo(cart)"
>评价</view>
</view> </view>
</view> </view>
</view> </view>
@ -41,9 +37,12 @@ export default {
}, },
mounted: function() {}, mounted: function() {},
methods: { methods: {
routerGo(item) { routerGo(cart) {
this.$yrouter.push({ path: '/pages/shop/GoodsEvaluate/index',query:{id:cart.unique} }); this.$yrouter.push({
}, path: "/pages/shop/GoodsEvaluate/index",
query: { id: cart.unique }
});
}
} }
}; };
</script> </script>

24
components/ProductWindow.vue

@ -65,13 +65,8 @@ export default {
data: function() { data: function() {
return {}; return {};
}, },
watch: {
attr:function(ne){
console.log(ne)
}
},
mounted: function() { mounted: function() {
console.log(this.attr) console.log(this.attr);
}, },
methods: { methods: {
closeAttr: function() { closeAttr: function() {
@ -84,16 +79,23 @@ export default {
this.$emit("changeFun", { action: "ChangeCartNum", value: 1 }); this.$emit("changeFun", { action: "ChangeCartNum", value: 1 });
}, },
tapAttr: function(indexw, indexn) { tapAttr: function(indexw, indexn) {
//
// H5attrH5
// props
// this.attr.productAttr[res.indexw].index = res.indexn;
let that = this; let that = this;
console.log(that.attr.productAttr);
console.log(that.attr.productAttr[indexw], indexw, indexn);
that.attr.productAttr[indexw].index = indexn;
let value = that let value = that
.getCheckedValue() .getCheckedValue()
.sort() .sort()
.join(","); .join(",");
console.log(value); that.$emit("changeFun", {
that.$emit("changeFun", { action: "ChangeAttr", value: value }); action: "ChangeAttr",
value: {
value,
indexw,
indexn
}
});
}, },
// //
getCheckedValue: function() { getCheckedValue: function() {

7
pages/activity/DargainDetails/index.vue

@ -84,9 +84,9 @@
<image src="@/static/images/left.png" /> <image src="@/static/images/left.png" />
</view> </view>
<view class="titleCon">砍价帮</view> <view class="titleCon">砍价帮</view>
<view class="pictrue on"> <!-- <view class="pictrue on">
<image src="@/static/images/left.png" /> <image src="@/static/images/left.png" />
</view> </view> -->
</view> </view>
<view class="list"> <view class="list">
<view <view
@ -507,6 +507,9 @@ export default {
</script> </script>
<style lang="less"> <style lang="less">
.bargain{
background: #00c17b;
}
.bargainBnts { .bargainBnts {
display: flex; display: flex;
align-items: center; align-items: center;

3
pages/activity/GoodsBargain/index.vue

@ -78,4 +78,7 @@ export default {
</script> </script>
<style > <style >
page{
background: #00c17b;
}
</style> </style>

4
pages/activity/GroupDetails/index.vue

@ -107,10 +107,10 @@
</view> </view>
<view style="height:100rpx;"></view> <view style="height:100rpx;"></view>
<view class="footer-group acea-row row-between-wrapper"> <view class="footer-group acea-row row-between-wrapper">
<view class="customerSer acea-row row-center-wrapper row-column"> <!-- <view class="customerSer acea-row row-center-wrapper row-column">
<view class="iconfont icon-kefu"></view> <view class="iconfont icon-kefu"></view>
<view>客服</view> <view>客服</view>
</view> </view> -->
<view class="bnt bg-color-violet" @click="openAlone">单独购买</view> <view class="bnt bg-color-violet" @click="openAlone">单独购买</view>
<view class="bnt bg-color-red" @click="openTeam">立即开团</view> <view class="bnt bg-color-red" @click="openTeam">立即开团</view>
</view> </view>

4
pages/activity/SeckillDetails/index.vue

@ -39,13 +39,13 @@
</view> </view>
<view style="height:100rpx;"></view> <view style="height:100rpx;"></view>
<view class="footerRush acea-row row-between-wrapper"> <view class="footerRush acea-row row-between-wrapper">
<view <!-- <view
class="customerSer acea-row row-center-wrapper row-column" class="customerSer acea-row row-center-wrapper row-column"
@click="routerGo()" @click="routerGo()"
> >
<view class="iconfont icon-kefu"></view> <view class="iconfont icon-kefu"></view>
<view>客服</view> <view>客服</view>
</view> </view> -->
<view class="bnt bg-color-red" @click="tapBuy">立即购买</view> <view class="bnt bg-color-red" @click="tapBuy">立即购买</view>
</view> </view>
<ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cartNum"></ProductWindow> <ProductWindow v-on:changeFun="changeFun" :attr="attr" :cartNum="cartNum"></ProductWindow>

53
pages/order/MyOrder/index.vue

@ -107,31 +107,18 @@
</view> </view>
<view class="totalPrice"> <view class="totalPrice">
{{ order.cartInfo.length || 0 }}件商品总金额 {{ order.cartInfo.length || 0 }}件商品总金额
<text <text class="money font-color-red">{{ order.payPrice }}</text>
class="money font-color-red"
>{{ order.payPrice }}</text>
</view> </view>
<view class="bottom acea-row row-right row-middle"> <view class="bottom acea-row row-right row-middle">
<template v-if="order._status._type == 0"> <template v-if="order._status._type == 0">
<view class="bnt cancelBnt" @click="cancelOrder(order)">取消订单</view> <view class="bnt cancelBnt" @click="cancelOrder(order)">取消订单</view>
<view <view class="bnt bg-color-red" @click="goOrderDetails(order)">立即付款</view>
class="bnt bg-color-red"
@click="goOrderDetails(order)"
>立即付款</view>
</template> </template>
<template v-if="order._status._type == 1 || order._status._type == 9"> <template v-if="order._status._type == 1 || order._status._type == 9">
<view <view class="bnt bg-color-red" @click="goOrderDetails(order)">查看详情</view>
class="bnt bg-color-red"
@click="goOrderDetails(order)"
>查看详情</view>
</template> </template>
<template v-if="order._status._type == 2"> <template v-if="order._status._type == 2">
<view <view class="bnt default" @click="goLogistics(order)">查看物流</view>
class="bnt default"
@click="
$yrouter.push({ path: '/pages/order/Logistics/index',query:{id:order.orderId}})
"
>查看物流</view>
<view class="bnt bg-color-red" @click="takeOrder(order)">确认收货</view> <view class="bnt bg-color-red" @click="takeOrder(order)">确认收货</view>
</template> </template>
<template v-if="order._status._type == 3"> <template v-if="order._status._type == 3">
@ -144,16 +131,10 @@
<!--&gt;--> <!--&gt;-->
<!--查看物流--> <!--查看物流-->
<!--</view>--> <!--</view>-->
<view <view class="bnt bg-color-red" @click="goOrderDetails(order)">去评价</view>
class="bnt bg-color-red"
@click="goOrderDetails(order)"
>去评价</view>
</template> </template>
<template v-if="order._status._type === 4"> <template v-if="order._status._type === 4">
<view <view class="bnt bg-color-red" @click="goOrderDetails(order)">查看订单</view>
class="bnt bg-color-red"
@click="goOrderDetails(order)"
>查看订单</view>
</template> </template>
</view> </view>
</view> </view>
@ -231,6 +212,12 @@ export default {
type() {} type() {}
}, },
methods: { methods: {
goLogistics(order) {
this.$yrouter.push({
path: "/pages/order/Logistics/index",
query: { id: order.orderId }
});
},
goOrderDetails(order) { goOrderDetails(order) {
this.$yrouter.push({ this.$yrouter.push({
path: "/pages/order/OrderDetails/index", path: "/pages/order/OrderDetails/index",
@ -334,19 +321,19 @@ export default {
<style scoped lang="less"> <style scoped lang="less">
.noCart { .noCart {
margin-top: 0.17*100rpx; margin-top: 0.17 * 100rpx;
padding-top: 0.1*100rpx; padding-top: 0.1 * 100rpx;
} }
.noCart .pictrue { .noCart .pictrue {
width: 4*100rpx; width: 4 * 100rpx;
height: 3*100rpx; height: 3 * 100rpx;
overflow: hidden; overflow: hidden;
margin: 0.7*100rpx auto 0.5*100rpx auto; margin: 0.7 * 100rpx auto 0.5 * 100rpx auto;
} }
.noCart .pictrue image{ .noCart .pictrue image {
width: 4*100rpx; width: 4 * 100rpx;
height: 3*100rpx; height: 3 * 100rpx;
} }
</style> </style>

1173
pages/order/OrderDetails/index.vue

File diff suppressed because it is too large Load Diff

3
pages/order/OrderSubmission/index.vue

@ -58,7 +58,7 @@
当前积分 当前积分
<text class="num font-color-red">{{ userInfo.integral || 0 }}</text> <text class="num font-color-red">{{ userInfo.integral || 0 }}</text>
</text> </text>
<checkbox value :checked="useIntegral ? true : false"></checkbox> <checkbox value="true" :checked="useIntegral ? true : false"></checkbox>
</label> </label>
</checkbox-group> </checkbox-group>
</view> </view>
@ -345,6 +345,7 @@
}, },
changeUseIntegral: function(e) { changeUseIntegral: function(e) {
// this.computedPrice(); // this.computedPrice();
console.log(e)
this.useIntegral = e.mp.detail.value[0]; this.useIntegral = e.mp.detail.value[0];
}, },
computedPrice() { computedPrice() {

4
pages/shop/GoodsClass/index.vue

@ -20,8 +20,8 @@
</view> </view>
</view> </view>
<view class="conter"> <view class="conter">
<view class="listw" v-for="(item, eq) in category" :key="eq"> <view v-for="(item, eq) in category" :key="eq">
<view v-if="eq === navActive"> <view class="listw" v-if="eq === navActive">
<view class="title acea-row row-center-wrapper" ref="title"> <view class="title acea-row row-center-wrapper" ref="title">
<view class="line"></view> <view class="line"></view>
<view class="name">{{ item.cateName }}</view> <view class="name">{{ item.cateName }}</view>

1683
pages/shop/GoodsCon/index.vue

File diff suppressed because it is too large Load Diff

2
pages/shop/ShoppingCart/index.vue

@ -130,7 +130,7 @@
<view class="placeOrder bg-color-red" @click="placeOrder">立即下单</view> <view class="placeOrder bg-color-red" @click="placeOrder">立即下单</view>
</view> </view>
<view class="button acea-row row-middle" v-else> <view class="button acea-row row-middle" v-else>
<view class="bnt cart-color" @click="collectAll">收藏</view> <!-- <view class="bnt cart-color" @click="collectAll">收藏</view> -->
<view class="bnt" @click="delgoods">删除</view> <view class="bnt" @click="delgoods">删除</view>
</view> </view>
</view> </view>

2
pages/user/User/index.vue

@ -96,7 +96,7 @@
</view> </view>
<view class="serviceList acea-row row-middle"> <view class="serviceList acea-row row-middle">
<template v-for="(item, MyMenusIndex) in MyMenus"> <template v-for="(item, MyMenusIndex) in MyMenus">
<view class="item" :key="MyMenusIndex" @click="goPages(MyMenusIndex)" v-if="item.url"> <view class="item" :key="MyMenusIndex" @click="goPages(MyMenusIndex)" v-if="item.url&&item.id!='230'">
<view class="pictrue"> <view class="pictrue">
<image :src="item.pic" /> <image :src="item.pic" />
</view> </view>

17
pages/user/address/AddAddress/index.vue

@ -11,8 +11,8 @@
</view> </view>
<view class="item acea-row row-between-wrapper"> <view class="item acea-row row-between-wrapper">
<view class="name">所在地区</view> <view class="name">所在地区</view>
<view class="picker acea-row row-between-wrapper select-value form-control"> <view class="picker acea-row row-between-wrapper select-value form-control" >
<view class="address"> <view class="address" @tap="openAddres2">
<!-- <picker <!-- <picker
@columnchange="addRessColumnchange" @columnchange="addRessColumnchange"
@change="changeAddress" @change="changeAddress"
@ -23,7 +23,7 @@
<text class="uni-input" v-if="model2">{{model2}}</text> <text class="uni-input" v-if="model2">{{model2}}</text>
<text class="uni-input" v-else>请选择地区</text> <text class="uni-input" v-else>请选择地区</text>
</picker>--> </picker>-->
<text class="uni-input" @tap="openAddres2" >{{model2||'请选择'}}</text> <text class="uni-input" >{{model2||'请选择'}}</text>
<simple-address <simple-address
ref="simpleAddress" ref="simpleAddress"
:pickerValueDefault="cityPickerValueDefault" :pickerValueDefault="cityPickerValueDefault"
@ -116,7 +116,7 @@ if(this.address.province){
"label" "label"
); );
console.log(index); console.log(index);
this.cityPickerValueDefault = index.index; this.cityPickerValueDefault = index.index;
} }
this.$refs.simpleAddress.open(); this.$refs.simpleAddress.open();
}, },
@ -226,3 +226,12 @@ if(this.address.province){
} }
}; };
</script> </script>
<style lang="less">
.address{
text{
width: 100%;
display: block;
}
}
</style>

287
pages/user/promotion/Poster/index.vue

@ -1,153 +1,160 @@
<template> <template>
<view class="distribution-posters"> <view class="distribution-posters">
<view class="slider-banner banner"> <view class="slider-banner banner">
<swiper indicatorDots="true"> <swiper indicatorDots="true">
<block v-for="(item, infoIndex) in info" :key="infoIndex"> <block v-for="(item, infoIndex) in info" :key="infoIndex">
<swiper-item> <swiper-item>
<image class="slide-image" :src="item.wap_poster" mode="widthFix" show-menu-by-longpress /> <image
</swiper-item> class="slide-image"
</block> :src="item.wap_poster"
</swiper> mode="widthFix"
</view> show-menu-by-longpress
<view class="keep bg-color-red" @click="saveImg">保存海报</view> />
</view> </swiper-item>
</block>
</swiper>
</view>
<view class="keep bg-color-red" @click="saveImg">保存海报</view>
</view>
</template> </template>
<script> <script>
// import { swiper, swiperSlide } from "vue-awesome-swiper"; // import { swiper, swiperSlide } from "vue-awesome-swiper";
import { import { getSpreadImg } from "@/api/user";
getSpreadImg
} from "@/api/user";
export default { export default {
name: "Poster", name: "Poster",
components: { components: {
// swiper, // swiper,
// swiperSlide // swiperSlide
}, },
props: {}, props: {},
data: function() { data: function() {
return { return {
swiperPosters: { swiperPosters: {
speed: 1000, speed: 1000,
effect: "coverflow", effect: "coverflow",
slidesPerView: "auto", slidesPerView: "auto",
centeredSlides: true, centeredSlides: true,
coverflowEffect: { coverflowEffect: {
rotate: 0, // rotate: 0, //
stretch: -20, // stretch: -20, //
depth: 100, // depth: 100, //
modifier: 3, // modifier: 3, //
slideShadows: false // slideShadows: false //
}, },
observer: true, observer: true,
observeParents: true observeParents: true
}, },
info: [], info: [],
activeIndex: 0 activeIndex: 0
}; };
}, },
mounted: function() { mounted: function() {
this.getIndex(); this.getIndex();
let that = this; let that = this;
// this.swiper.on("slideChange", function() { // this.swiper.on("slideChange", function() {
// that.activeIndex = that.swiper.activeIndex; // that.activeIndex = that.swiper.activeIndex;
// }); // });
}, },
computed: { computed: {
swiper() { swiper() {
// return this.$refs.mySwiper.swiper; // return this.$refs.mySwiper.swiper;
} }
}, },
methods: { methods: {
getIndex: function() { getIndex: function() {
let that = this; let that = this;
let form = {} let form = {};
if (this.$deviceType == 'app') { if (this.$deviceType == "app") {
form.form = 'app' form.form = "app";
} }
getSpreadImg(form).then( getSpreadImg(form).then(
res => { res => {
that.info = res.data; that.info = res.data;
}, },
err => { err => {
uni.showToast({ uni.showToast({
title: err.msg || err.response.data.msg, title: err.msg || err.response.data.msg,
icon: 'none', icon: "none",
duration: 2000 duration: 2000
}); });
} }
); );
}, },
downloadIamge: function(imgsrc, name) { downloadIamge: function(imgsrc, name) {
var that = this; var that = this;
this.isDown = true; this.isDown = true;
var downloadUrl = imgsrc; var downloadUrl = imgsrc;
if (!wx.saveImageToPhotosAlbum) { if (!wx.saveImageToPhotosAlbum) {
uni.showModal({ uni.showModal({
title: "提示", title: "提示",
content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。" content:
}); "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。"
that.openDialogVisible = true; });
that.openDialogVisible = true;
return; return;
} }
// wx.getSetting "scope.writePhotosAlbum" scope // wx.getSetting "scope.writePhotosAlbum" scope
wx.getSetting({ wx.getSetting({
success(res) { success(res) {
if (!res.authSetting["scope.writePhotosAlbum"]) { if (!res.authSetting["scope.writePhotosAlbum"]) {
that.openDialogVisible = true; that.openDialogVisible = true;
// //
wx.authorize({ wx.authorize({
scope: "scope.writePhotosAlbum", scope: "scope.writePhotosAlbum",
success() { success() {
that.downloadImage(downloadUrl); that.downloadImage(downloadUrl);
}, },
fail() { fail() {
// //
// //
wx.openSetting({ wx.openSetting({
success: function(data) {}, success: function(data) {},
fail: function(data) {} fail: function(data) {}
}); });
} }
}); });
} else { } else {
that.downloadImage(downloadUrl); that.downloadImage(downloadUrl);
} }
}, },
fail(res) { fail(res) {
that.openDialogVisible = true; that.openDialogVisible = true;
} }
}); });
}, },
saveImg: function() { saveImg: function() {
this.downloadIamge( this.downloadIamge(
this.info[this.activeIndex].wap_poster, this.info[this.activeIndex].wap_poster,
"poster" + this.activeIndex "poster" + this.activeIndex
); );
} }
} }
}; };
</script> </script>
<style scoped lang="less"> <style lang="less">
.distribution-posters { page {
height: 100%; height: 100%;
} }
.distribution-posters {
height: 100%;
}
.banenr { .banenr {
height: 100%; height: 100%;
} }
.banner swiper { .banner swiper {
height: 100%; height: 100%;
} }
.banner .slide-image { .banner .slide-image {
width: 100%; width: 100%;
height: auto; height: auto;
} }
</style> </style>

17
store/index.js

@ -4,7 +4,7 @@ import Vuex from "vuex";
Vue.use(Vuex); Vue.use(Vuex);
const debug = process.env.NODE_ENV !== "production"; const debug = process.env.NODE_ENV !== "production";
import store from "@/utils/store/cookie"; import cookie from "@/utils/store/cookie";
import { import {
getUserInfo getUserInfo
} from "@/api/user"; } from "@/api/user";
@ -18,8 +18,9 @@ const vuexStore = new Vuex.Store({
isAuthorizationPage: false, isAuthorizationPage: false,
// 是否授权 // 是否授权
isAuthorization: false, isAuthorization: false,
token: store.get(LOGIN_KEY) || null, // 不建议从这里取 token,但是删除掉会影响其他的页面
userInfo: store.get('userInfo'), token: cookie.get(LOGIN_KEY) || null,
userInfo: cookie.get('userInfo'),
$deviceType: null, $deviceType: null,
}, },
mutations: { mutations: {
@ -46,12 +47,12 @@ const vuexStore = new Vuex.Store({
}, },
LOGIN(state, token, expires_time) { LOGIN(state, token, expires_time) {
state.token = token; state.token = token;
store.set(LOGIN_KEY, token, expires_time); cookie.set(LOGIN_KEY, token, expires_time);
}, },
LOGOUT(state) { LOGOUT(state) {
state.token = null; state.token = null;
state.userInfo = null state.userInfo = null
store.clearAll() cookie.clearAll()
}, },
BACKGROUND_COLOR(state, color) { BACKGROUND_COLOR(state, color) {
state.color = color; state.color = color;
@ -99,9 +100,9 @@ const vuexStore = new Vuex.Store({
}, user) { }, user) {
commit("UPDATE_USERINFO", user); commit("UPDATE_USERINFO", user);
if (user) { if (user) {
store.set('userInfo', user) cookie.set('userInfo', user)
} else { } else {
store.set('userInfo', null) cookie.set('userInfo', null)
} }
}, },
changeAuthorizationPage({ changeAuthorizationPage({
@ -127,4 +128,4 @@ const vuexStore = new Vuex.Store({
strict: debug strict: debug
}); });
export default vuexStore export default vuexStore

24
utils/index.js

@ -218,7 +218,7 @@ export const login = (option) => {
console.log('登录成功4') console.log('登录成功4')
store.commit("LOGIN", data.token, dayjs(data.expires_time)); store.commit("LOGIN", data.token, dayjs(data.expires_time));
console.log('登录成功5') console.log('登录成功5')
console.log(store)
handleGetUserInfo() handleGetUserInfo()
}).catch(error => { }).catch(error => {
@ -259,6 +259,7 @@ export const login = (option) => {
} }
export const handleGetUserInfo = () => { export const handleGetUserInfo = () => {
console.log('登录后请求用户信息')
getUser().then(res => { getUser().then(res => {
console.log(res.data, '登录后的样式') console.log(res.data, '登录后的样式')
store.dispatch('setUserInfo', res.data) store.dispatch('setUserInfo', res.data)
@ -341,9 +342,25 @@ export function parseRoute($mp) {
} }
} }
export function auth() {
/**
* 如何判断权限?
* 用户如果登录了系统会留下两个东西一个是token一个是userInfo
* token存在会过期的问题如果长时间没有打开小程序会导致登录失效出现打开一个页面瞬间跳转到授权页面的问题
* 解决办法保存token的时候加上过期时间每次请求都取一下缓存里的token
* userInfo只是用来限时用户信息作用并不是很大
* ps只需要判断 token 是否存在即可
*/
console.log(cookie.get('login_status'), 'token')
if (cookie.get('login_status')) {
return true
}
return false
}
export const handleLoginStatus = (location, complete, fail, success) => { export const handleLoginStatus = (location, complete, fail, success) => {
console.log(location, '开始健全') console.log(location, '开始检验权限')
// 不登录可访问的页面 // 不登录可访问的页面
let page = [{ let page = [{
path: '/pages/Loading/index', path: '/pages/Loading/index',
@ -374,8 +391,7 @@ export const handleLoginStatus = (location, complete, fail, success) => {
path = location.path path = location.path
} }
console.log(store.getters.userInfo, '用户信息') if (!auth()) {
if (!store.getters.token) {
page.map((item) => { page.map((item) => {
console.log(item.path == path) console.log(item.path == path)
if (item.path == path) { if (item.path == path) {

33
utils/request.js

@ -2,6 +2,7 @@ import Fly from "flyio/dist/npm/wx";
import $store from "../store"; import $store from "../store";
import toLogin from "@/libs/login"; import toLogin from "@/libs/login";
import { VUE_APP_API_URL } from "@/config"; import { VUE_APP_API_URL } from "@/config";
import cookie from "@/utils/store/cookie";
const fly = new Fly() const fly = new Fly()
@ -28,28 +29,38 @@ fly.interceptors.response.use(
const defaultOpt = { login: true }; const defaultOpt = { login: true };
function baseRequest(options) { function baseRequest(options) {
const token = $store.state.token;
const headers = options.headers || {}; // 从缓存中获取 token 防止 token 失效后还会继续请求的情况
if (options.login) { const token = cookie.get('login_status');
headers["Authorization"] = "Bearer " + token;
// 合并传参过来的 headers
// 如果接口需要登录,携带 token 去请求
options.headers = {
...options.headers,
Authorization: options.login ? "Bearer " + token : null
} }
options.headers = headers; // 如果需要登录才可访问的接口没有拿到 token 视为登录失效
if (options.login && !token) { if (options.login === true && !token) {
// 跳转到登录或授权页面
toLogin(); toLogin();
// 提示错误信息
return Promise.reject({ msg: "未登录", toLogin: true }); return Promise.reject({ msg: "未登录", toLogin: true });
} }
// 结构请求需要的参数
const { url, params, data, login, ...option } = options const { url, params, data, login, ...option } = options
// 发起请求
return fly.request(url, params || data, { return fly.request(url, params || data, {
...option ...option
}).then(res => { }).then(res => {
console.log(res) console.log(res)
// console.log(url,params,data, ...option) // console.log(url,params,data, ...option)
const data = res.data || {}; const data = res.data || {};
if (res.status !== 200) if (res.status !== 200) {
return Promise.reject({ msg: "请求失败", res, data }); return Promise.reject({ msg: "请求失败", res, data });
}
if ([410000, 410001, 410002].indexOf(data.status) !== -1) { if ([410000, 410001, 410002].indexOf(data.status) !== -1) {
toLogin(); toLogin();
return Promise.reject({ msg: res.data.msg, res, data, toLogin: true }); return Promise.reject({ msg: res.data.msg, res, data, toLogin: true });

Loading…
Cancel
Save