Browse Source

优化登录的逻辑,

master
gaoxs 5 years ago
parent
commit
4cc4c60a87
  1. 17
      components/Footer.vue
  2. 63
      libs/login.js
  3. 2
      libs/wechat.js
  4. 20
      pages/activity/GroupDetails/index.vue
  5. 379
      pages/authorization/index.vue
  6. 4
      pages/home/index.vue
  7. 4
      pages/launch/index.vue
  8. 11
      pages/order/OrderDetails/index.vue
  9. 40
      pages/orderAdmin/OrderCancellation/index.vue
  10. 8
      pages/shop/GoodsCon/index.vue
  11. 961
      pages/shop/ShoppingCart/index.vue
  12. 5
      pages/user/PersonalData/index.vue
  13. 4
      pages/user/Recharge/index.vue
  14. 371
      pages/user/User/index.vue
  15. 17
      pages/user/promotion/Poster/index.vue
  16. 33
      store/index.js
  17. 433
      utils/index.js
  18. 45
      utils/store/cookie.js

17
components/Footer.vue

@ -1,10 +1,8 @@
<template> <template>
<view> <view>
<view v-if="isIpx" class="iphonex-footer-bg"></view> <view class="footer-bg"></view>
<view v-else class="footer-bg"></view>
<view id="footer" :class="[isIpx ? 'iphonex-footer' : '', 'acea-row row-middle'] "> <view id="footer" :class="[isIpx ? 'iphonex-footer' : '', 'acea-row row-middle'] ">
<view <view
@click="changeTabtar(footerIndex)"
class="item" class="item"
:class="{ on: footerIndex == tabtarIndex }" :class="{ on: footerIndex == tabtarIndex }"
v-for="(item, footerIndex) in footerList" v-for="(item, footerIndex) in footerList"
@ -59,20 +57,9 @@ export default {
...mapState(["tabtarIndex"]) ...mapState(["tabtarIndex"])
}, },
methods: { methods: {
...mapActions(["changeTabtar"])
}, },
mounted() { mounted() {
let that = this;
this.changeTabtar(this.$yroute.query.type);
wx.getSystemInfo({
success: function(res) {
console.log(res);
var name = "iPhone X";
if (res.model.indexOf(name) > -1) {
that.isIpx = true;
}
}
});
} }
}; };
</script> </script>

63
libs/login.js

@ -1,32 +1,45 @@
// import router from "../router"; // import router from "../router";
import store from "../store"; import store from "../store";
import cookie from "@/utils/store/cookie"; import cookie from "@/utils/store/cookie";
import { isWeixin, login, getCurrentPageUrl, getCurrentPageUrlWithArgs, parseQuery, replace, handleQrCode } from "@/utils"; import {
isWeixin,
login,
replaceLogin,
getCurrentPageUrl,
getCurrentPageUrlWithArgs,
parseQuery,
replace,
handleQrCode
} from "@/utils";
export default function toLogin(push, backUrl) { export default function toLogin(push, backUrl) {
store.commit("LOGOUT"); store.commit("LOGOUT");
if (store.getters.isAuthorization) { // 如果没有授权,走登录的接口重新授权
login() // 授权获取失败会跳转到授权的接口
return if (store.getters.isAuthorization) {
} login()
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') { return
return }
} // 判断当前是不是已经在登录页面或者授权页,防止二次跳转
if (store.getters.isAuthorizationPage || getCurrentPageUrl() == '/pages/user/Login/index') {
return
}
// 判断是不是扫描的砍价海报进来的 // 判断是不是扫描的砍价海报进来的
if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) { if (getCurrentPageUrl() == 'pages/activity/DargainDetails/index' && handleQrCode()) {
let url = handleQrCode(); let url = handleQrCode();
if (url) { if (url) {
console.log(222222222) replaceLogin({
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, id: url.bargainId, partake: url.uid } }) redirect: `/${getCurrentPageUrl()}`,
} else { id: url.bargainId,
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, ...parseQuery() } }) partake: url.uid
} })
} else { } else {
console.log(222222222) replaceLogin()
replace({ path: '/pages/user/Login/index', query: { redirect: `/${getCurrentPageUrl()}`, ...parseQuery() } }) }
} } else {
store.commit("UPDATE_AUTHORIZATION", false); replaceLogin()
store.commit("UPDATE_AUTHORIZATIONPAGE", true); }
store.commit("UPDATE_AUTHORIZATION", false);
store.commit("UPDATE_AUTHORIZATIONPAGE", true);
} }

2
libs/wechat.js

@ -2,7 +2,7 @@
export const weappPay = (option) => { export const weappPay = (option) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 吊起微信支付 // 吊起微信支付
wx.requestPayment({ uni.requestPayment({
...option, ...option,
timeStamp: option.timeStamp + '', timeStamp: option.timeStamp + '',
success: (success) => { success: (success) => {

20
pages/activity/GroupDetails/index.vue

@ -47,7 +47,7 @@
<view class="lack"> <view class="lack">
<text>还差</text> <text>还差</text>
<text class="font-color-red" v-text="item.count"></text> <text class="font-color-red" v-text="item.count"></text>
<text>人成团</text> <text>人成团</text>
</view> </view>
<count-down <count-down
:is-day="false" :is-day="false"
@ -200,7 +200,7 @@ export default {
cart_num: 1 cart_num: 1
} }
}, },
cartNum:1 cartNum: 1
}; };
}, },
watch: { watch: {
@ -286,11 +286,11 @@ export default {
var that = this; var that = this;
that.attr.productSelect.cart_num = 1; that.attr.productSelect.cart_num = 1;
that.cartNum = 1; that.cartNum = 1;
uni.showToast({ uni.showToast({
title: "每人每次限购1" + that.storeInfo.unitName, title: "每人每次限购1" + that.storeInfo.unitName,
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
}, },
setProductSelect: function() { setProductSelect: function() {
var that = this; var that = this;
@ -322,9 +322,9 @@ export default {
}) })
.catch(err => { .catch(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
}); });
}); });
} }

379
pages/authorization/index.vue

@ -1,201 +1,192 @@
<template> <template>
<view class="container"> <view class="container">
<view v-if="!isAuthorization"> <view v-if="!isAuthorization">
<view class="getUserInfo"> <view class="getUserInfo">
<view>您还未允许微信登录授权请点击下方按钮允许微信授权登录</text> <text>您还未允许微信登录授权请点击下方按钮允许微信授权登录</text>
<vant-button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</vant-button> <view style="height:20rpx"></view>
<view class="sp-cell"></view> <button type="primary" open-type="getUserInfo" @getuserinfo="getUserInfo">允许微信登录授权</button>
<vant-button type="default" @click="back">取消微信登录授权</vant-button> <view style="height:20rpx"></view>
</view> <button @click="back">取消微信登录授权</button>
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { import { mapState, mapMutations, mapActions } from "vuex";
mapState, //
mapMutations, // import request from "@//api/request";
mapActions import { wxappAuth, getUser } from "@/api/user";
} from "vuex"; import dayjs from "dayjs";
// import cookie from "@/utils/store/cookie";
// import request from "@//api/request"; import { login } from "@/utils";
import {
wxappAuth, export default {
getUser data() {
} from "@/api/user"; return {};
import dayjs from "dayjs"; },
import cookie from "@/utils/store/cookie"; computed: {
import { ...mapState(["isAuthorization"])
login },
} from "@/utils"; onShow() {
this.UPDATE_AUTHORIZATIONPAGE(true);
export default { },
data() { onHide() {
return {}; this.UPDATE_AUTHORIZATIONPAGE(false);
}, this.changeAuthorization(false);
computed: { },
...mapState(["isAuthorization"]) onUnload() {
}, this.UPDATE_AUTHORIZATIONPAGE(false);
onShow() { this.changeAuthorization(false);
this.UPDATE_AUTHORIZATIONPAGE(false); },
}, methods: {
onHide() { ...mapActions(["changeAuthorization", "changeUserInfo"]),
this.changeAuthorization(false); ...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]),
}, back() {
onUnload() { this.$yrouter.switchTab({
this.changeAuthorization(false); path: "/pages/home/index",
}, query: {}
methods: { });
...mapActions(["changeAuthorization", "changeUserInfo"]), },
...mapMutations(["UPDATE_AUTHORIZATIONPAGE", "CHANGE_TABTAR"]), getUserInfo(data) {
back() { if (data.detail.errMsg == "getUserInfo:fail auth deny") {
// if (this.$yroute.query.redirect) { uni.showToast({
// this.$yrouter.replace({ title: "取消授权",
// path: this.$yroute.query.redirect icon: "none",
// }); duration: 2000
// } else { });
// this.$yrouter.replace({ return;
// path: "/pages/launch/index", }
// query: { type: 0 } uni.showLoading({
// }); title: "登录中"
// } });
this.CHANGE_TABTAR(0); login({
this.$yrouter.replace({ success: () => {}
path: "/pages/home/index", });
query: { }
type: 0 },
} onUnload() {},
}); mounted() {}
}, };
getUserInfo(data) {
uni.showLoading({
title: "登录中"
});
login();
}
},
onUnload() {},
mounted() {}
};
</script> </script>
<style lang="less"> <style lang="less">
.sp-cell { .sp-cell {
height: 20rpx; height: 20rpx;
} }
.getUserInfo { .getUserInfo {
display: flex; display: flex;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
padding: 30px; padding: 30px;
p { p {
margin-bottom: 20px; margin-bottom: 20px;
} }
} }
.container { .container {
flex: 1; flex: 1;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: flex-start; justify-content: flex-start;
position: relative; position: relative;
} }
.tab-bar { .tab-bar {
font-size: 0; font-size: 0;
display: flex; display: flex;
align-items: center; align-items: center;
background: rgba(255, 255, 255, 0.9); background: rgba(255, 255, 255, 0.9);
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0; left: 0;
right: 0; right: 0;
z-index: 99; z-index: 99;
border-top: 1px solid rgba(248, 248, 248, 1); border-top: 1px solid rgba(248, 248, 248, 1);
.tab-bar-item { .tab-bar-item {
flex: 1; flex: 1;
height: 49px; height: 49px;
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
&.active { &.active {
text { text {
color: #ee7559; color: #ee7559;
} }
.tab-bar-pic { .tab-bar-pic {
display: none; display: none;
background: #f9f9f9; background: #f9f9f9;
&.active { &.active {
display: block; display: block;
} }
} }
} }
.tab-bar-pic { .tab-bar-pic {
display: block; display: block;
background: #f9f9f9; background: #f9f9f9;
&.active { &.active {
display: none; display: none;
} }
} }
} }
.tab-bar-pic { .tab-bar-pic {
width: 25px; width: 25px;
height: 25px; height: 25px;
background: #f9f9f9; background: #f9f9f9;
image { image {
width: 25px; width: 25px;
height: 25px; height: 25px;
} }
} }
.tab-bar-pic-active {} .tab-bar-pic-active {
}
text {
font-size: 10px; text {
color: rgb(160, 160, 160); font-size: 10px;
line-height: 10px; color: rgb(160, 160, 160);
margin-top: 5px; line-height: 10px;
} margin-top: 5px;
} }
}
.tab-bar-bg {
padding-top: 46px; .tab-bar-bg {
width: 100%; padding-top: 46px;
} width: 100%;
}
.view-item {
display: none; .view-item {
width: 100%; display: none;
} width: 100%;
}
.view-item-active {
display: block; .view-item-active {
} display: block;
}
.getUserInfo {
display: flex; .getUserInfo {
align-items: center; display: flex;
flex-direction: column; align-items: center;
padding: 30px; flex-direction: column;
padding: 30px;
p {
margin-bottom: 20px; p {
} margin-bottom: 20px;
} }
}
._van-dialog {
z-index: 99999999999; ._van-dialog {
} z-index: 99999999999;
</style> }
</style>

4
pages/home/index.vue

@ -254,6 +254,9 @@ export default {
}, },
mounted: function() { mounted: function() {
let that = this; let that = this;
uni.showLoading({
title:'加载中'
})
getHomeData().then(res => { getHomeData().then(res => {
that.logoUrl = res.data.logoUrl; that.logoUrl = res.data.logoUrl;
that.$set(that, "banner", res.data.banner); that.$set(that, "banner", res.data.banner);
@ -269,6 +272,7 @@ export default {
that.$set(that, "lovely", res.data.lovely); that.$set(that, "lovely", res.data.lovely);
that.$set(that, "benefit", res.data.benefit); that.$set(that, "benefit", res.data.benefit);
that.$set(that, "couponList", res.data.couponList); that.$set(that, "couponList", res.data.couponList);
uni.hideLoading()
that.setOpenShare(); that.setOpenShare();
}); });
}, },

4
pages/launch/index.vue

@ -43,22 +43,18 @@ export default {
...mapState(["tabtarIndex"]) ...mapState(["tabtarIndex"])
}, },
methods: { methods: {
...mapActions(["changeTabtar"])
}, },
mounted() { mounted() {
let type = this.$yroute.query.type; let type = this.$yroute.query.type;
console.log(2222) console.log(2222)
if (type) { if (type) {
this.changeTabtar(type);
} }
// if (!this.tabtarIndex) { // if (!this.tabtarIndex) {
// this.changeTabtar(0);
// } // }
}, },
onHide() { onHide() {
console.log("清除状态"); console.log("清除状态");
// this.changeTabtar(0);
} }
}; };
</script> </script>

11
pages/order/OrderDetails/index.vue

@ -495,7 +495,8 @@
}, },
methods: { methods: {
copyClipboard, copyClipboard,
showChang: function() { showChang: function() {
//
if (isWeixin()) { if (isWeixin()) {
let config = { let config = {
latitude: this.system_store.latitude, latitude: this.system_store.latitude,
@ -503,14 +504,6 @@
name: this.system_store.name, name: this.system_store.name,
address: this.system_store._detailed_address address: this.system_store._detailed_address
}; };
// wechatEvevt("openLocation", config)
// .then(res => {
// })
// .catch(res => {
// if (res.is_ready) {
// res.wx.openLocation(config);
// }
// });
} else { } else {
if (!this.mapKey) if (!this.mapKey)
uni.showToast({ uni.showToast({

40
pages/orderAdmin/OrderCancellation/index.vue

@ -151,44 +151,8 @@
}); });
}, },
openQRCode: function() { openQRCode: function() {
let that = this; let that = this;
// wechatEvevt("scanQRCode", { //
// needResult: 1,
// scanType: ["qrCode", "barCode"]
// })
// .then(res => {
// if (res.resultStr) {
// that.verify_code = res.resultStr;
// that.storeCancellation();
// } else {
// uni.showToast({
// title: '',
// icon: "none",
// duration: 2000
// });
// }
// })
// .catch(res => {
// if (res.is_ready) {
// res.wx.scanQRCode({
// needResult: 1,
// scanType: ["qrCode", "barCode"],
// success: function(res) {
// that.verify_code = res.resultStr;
// that.storeCancellation();
// },
// fail: function(res) {
// if (res.errMsg == "scanQRCode:permission denied") {
// uni.showToast({
// title: '',
// icon: "none",
// duration: 2000
// });
// }
// }
// });
// }
// });
} }
} }
}; };

8
pages/shop/GoodsCon/index.vue

@ -288,14 +288,6 @@ export default {
name: this.system_store.name, name: this.system_store.name,
address: this.system_store._detailed_address address: this.system_store._detailed_address
}; };
// wechatEvevt("openLocation", config)
// .then(res => {
// })
// .catch(res => {
// if (res.is_ready) {
// res.wx.openLocation(config);
// }
// });
} else { } else {
if (!this.mapKey) { if (!this.mapKey) {
uni.showToast({ uni.showToast({

961
pages/shop/ShoppingCart/index.vue

@ -1,98 +1,135 @@
<template> <template>
<view class="shoppingCart"> <view class="shoppingCart">
<view class="labelNav acea-row row-around row-middle"> <view class v-if="userInfo.uid">
<view class="item"> <view class="labelNav acea-row row-around row-middle">
<text class="iconfont icon-xuanzhong"></text>100%正品保证 <view class="item">
</view> <text class="iconfont icon-xuanzhong"></text>100%正品保证
<view class="item"> </view>
<text class="iconfont icon-xuanzhong"></text>所有商品精挑细选 <view class="item">
</view> <text class="iconfont icon-xuanzhong"></text>所有商品精挑细选
<view class="item"> </view>
<text class="iconfont icon-xuanzhong"></text>售后无忧 <view class="item">
</view> <text class="iconfont icon-xuanzhong"></text>售后无忧
</view> </view>
<view class="nav acea-row row-between-wrapper"> </view>
<view> <view class="nav acea-row row-between-wrapper">
购物数量 <view>
<text class="num font-color-red">{{ count }}</text> 购物数量
</view> <text class="num font-color-red">{{ count }}</text>
<view v-if="cartList.valid.length > 0" class="administrate acea-row row-center-wrapper" @click="manage">{{ footerswitch ? "取消" : "管理" }}</view> </view>
</view> <view
<view v-if="validList.length > 0 || cartList.invalid.length > 0"> v-if="cartList.valid.length > 0"
<view class="list"> class="administrate acea-row row-center-wrapper"
<view class="item acea-row row-between-wrapper" v-for="(item, cartListValidIndex) in validList" :key="cartListValidIndex"> @click="manage"
<view class="select-btn"> >{{ footerswitch ? "取消" : "管理" }}</view>
<view class="checkbox-wrapper"> </view>
<checkbox-group @change="switchSelect(cartListValidIndex)"> <view v-if="validList.length > 0 || cartList.invalid.length > 0">
<label class="well-check"> <view class="list">
<checkbox value :checked="item.checked"></checkbox> <view
</label> class="item acea-row row-between-wrapper"
</checkbox-group> v-for="(item, cartListValidIndex) in validList"
</view> :key="cartListValidIndex"
</view> >
<view class="picTxt acea-row row-between-wrapper"> <view class="select-btn">
<view class="pictrue" @click="goGoodsCon(item)"> <view class="checkbox-wrapper">
<image :src="item.productInfo.attrInfo.image" v-if="item.productInfo.attrInfo" /> <checkbox-group @change="switchSelect(cartListValidIndex)">
<image :src="item.productInfo.image" v-else /> <label class="well-check">
</view> <checkbox value :checked="item.checked"></checkbox>
<view class="text"> </label>
<view class="line1">{{ item.productInfo.storeName }}</view> </checkbox-group>
<view class="infor line1" v-if="item.productInfo.attrInfo">属性{{ item.productInfo.attrInfo.suk }}</view> </view>
<view class="money">{{ item.truePrice }}</view> </view>
</view> <view class="picTxt acea-row row-between-wrapper">
<view class="carnum acea-row row-center-wrapper"> <view class="pictrue" @click="goGoodsCon(item)">
<view class="reduce" :class="validList[cartListValidIndex].cartNum <= 1 ? 'on' : ''" @click.prevent="reduce(cartListValidIndex)">-</view> <image :src="item.productInfo.attrInfo.image" v-if="item.productInfo.attrInfo" />
<view class="num">{{ item.cartNum }}</view> <image :src="item.productInfo.image" v-else />
<view class="plus" v-if="validList[cartListValidIndex].attrInfo" :class="validList[cartListValidIndex].cartNum >=validList[cartListValidIndex].attrInfo.stock? 'on': ''" </view>
@click.prevent="plus(cartListValidIndex)">+</view> <view class="text">
<view class="plus" v-else :class="validList[cartListValidIndex].cartNum >= validList[cartListValidIndex].stock? 'on': ''" <view class="line1">{{ item.productInfo.storeName }}</view>
@click.prevent="plus(cartListValidIndex)">+</view> <view
</view> class="infor line1"
</view> v-if="item.productInfo.attrInfo"
</view> >属性{{ item.productInfo.attrInfo.suk }}</view>
</view> <view class="money">{{ item.truePrice }}</view>
<view class="invalidGoods" v-if="cartList.invalid.length > 0"> </view>
<view class="goodsNav acea-row row-between-wrapper"> <view class="carnum acea-row row-center-wrapper">
<view @click="goodsOpen"> <view
<text class="iconfont" :class="goodsHidden === true ? 'icon-xiangyou' : 'icon-xiangxia'"></text>失效商品 class="reduce"
</view> :class="validList[cartListValidIndex].cartNum <= 1 ? 'on' : ''"
<view class="del" @click="delInvalidGoods"> @click.prevent="reduce(cartListValidIndex)"
<text class="iconfont icon-shanchu1"></text>清空 >-</view>
</view> <view class="num">{{ item.cartNum }}</view>
</view> <view
<view class="goodsList" :hidden="goodsHidden"> class="plus"
<view v-for="(item, cartListinvalidIndex) in cartList.invalid" :key="cartListinvalidIndex"> v-if="validList[cartListValidIndex].attrInfo"
<view @click="goGoodsCon(item)" class="item acea-row row-between-wrapper" v-if="item.productInfo"> :class="validList[cartListValidIndex].cartNum >=validList[cartListValidIndex].attrInfo.stock? 'on': ''"
<view class="invalid acea-row row-center-wrapper">失效</view> @click.prevent="plus(cartListValidIndex)"
<view class="pictrue"> >+</view>
<image :src="item.productInfo.attrInfo.image" v-if="item.productInfo.attrInfo" /> <view
<image :src="item.productInfo.image" v-else /> class="plus"
</view> v-else
<view class="text acea-row row-column-between"> :class="validList[cartListValidIndex].cartNum >= validList[cartListValidIndex].stock? 'on': ''"
<view class="line1">{{ item.productInfo.storeName }}</view> @click.prevent="plus(cartListValidIndex)"
<view class="infor line1" v-if="item.productInfo.attrInfo">属性{{ item.productInfo.attrInfo.suk }}</view> >+</view>
<view class="acea-row row-between-wrapper"> </view>
<view class="end">该商品已下架</view> </view>
</view> </view>
</view> </view>
</view> <view class="invalidGoods" v-if="cartList.invalid.length > 0">
</view> <view class="goodsNav acea-row row-between-wrapper">
</view> <view @click="goodsOpen">
</view> <text
</view> class="iconfont"
<!--购物车暂无商品--> :class="goodsHidden === true ? 'icon-xiangyou' : 'icon-xiangxia'"
<view class="noCart" v-if="cartList.valid.length === 0 && cartList.invalid.length === 0"> ></text>失效商品
<view class="pictrue"> </view>
<image :src="$VUE_APP_RESOURCES_URL+'/images/noCart.png'" /> <view class="del" @click="delInvalidGoods">
</view> <text class="iconfont icon-shanchu1"></text>清空
<Recommend></Recommend> </view>
</view> </view>
<view style="height:2.1rem"></view> <view class="goodsList" :hidden="goodsHidden">
<view :class="['footer acea-row row-between-wrapper']" v-if="cartList.valid.length > 0"> <view
<view> v-for="(item, cartListinvalidIndex) in cartList.invalid"
<view class="select-btn"> :key="cartListinvalidIndex"
<view class="checkbox-wrapper"> >
<!-- <label class="well-check"> <view
@click="goGoodsCon(item)"
class="item acea-row row-between-wrapper"
v-if="item.productInfo"
>
<view class="invalid acea-row row-center-wrapper">失效</view>
<view class="pictrue">
<image :src="item.productInfo.attrInfo.image" v-if="item.productInfo.attrInfo" />
<image :src="item.productInfo.image" v-else />
</view>
<view class="text acea-row row-column-between">
<view class="line1">{{ item.productInfo.storeName }}</view>
<view
class="infor line1"
v-if="item.productInfo.attrInfo"
>属性{{ item.productInfo.attrInfo.suk }}</view>
<view class="acea-row row-between-wrapper">
<view class="end">该商品已下架</view>
</view>
</view>
</view>
</view>
</view>
</view>
</view>
<!--购物车暂无商品-->
<view class="noCart" v-if="cartList.valid.length === 0 && cartList.invalid.length === 0">
<view class="pictrue">
<image :src="$VUE_APP_RESOURCES_URL+'/images/noCart.png'" />
</view>
<Recommend></Recommend>
</view>
<view style="height:2.1rem"></view>
<view :class="['footer acea-row row-between-wrapper']" v-if="cartList.valid.length > 0">
<view>
<view class="select-btn">
<view class="checkbox-wrapper">
<!-- <label class="well-check">
<input <input
type="checkbox" type="checkbox"
name name
@ -102,377 +139,385 @@
/> />
<i class="icon"></i> <i class="icon"></i>
<text class="checkAll">全选 ({{ cartCount }})</text> <text class="checkAll">全选 ({{ cartCount }})</text>
</label>--> </label>-->
<checkbox-group @change="allChecked"> <checkbox-group @change="allChecked">
<label class="well-check"> <label class="well-check">
<checkbox value :checked="isAllSelect && cartCount > 0"></checkbox> <checkbox value :checked="isAllSelect && cartCount > 0"></checkbox>
<text class="checkAll">全选 ({{ cartCount }})</text> <text class="checkAll">全选 ({{ cartCount }})</text>
</label> </label>
</checkbox-group> </checkbox-group>
</view> </view>
</view> </view>
</view> </view>
<view class="money acea-row row-middle" v-if="footerswitch === false"> <view class="money acea-row row-middle" v-if="footerswitch === false">
<text class="font-color-red">{{ countmoney }}</text> <text class="font-color-red">{{ countmoney }}</text>
<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>
</view> </view>
<Authorization v-else />
</view>
</template> </template>
<script> <script>
import Recommend from "@/components/Recommend"; import Recommend from "@/components/Recommend";
import { import Authorization from "@/pages/authorization/index";
getCartList, import { mapGetters } from "vuex";
postCartDel,
changeCartNum,
getCartCount
} from "@/api/store";
import {
postCollectAll
} from "@/api/user";
import {
mul,
add
} from "@/utils/bc";
import cookie from "@/utils/store/cookie";
import debounce from "lodash.debounce";
const CHECKED_IDS = "cart_checked"; import {
getCartList,
postCartDel,
changeCartNum,
getCartCount
} from "@/api/store";
import { postCollectAll } from "@/api/user";
import { mul, add } from "@/utils/bc";
import cookie from "@/utils/store/cookie";
import debounce from "lodash.debounce";
export default { const CHECKED_IDS = "cart_checked";
name: "ShoppingCart",
components: { export default {
Recommend name: "ShoppingCart",
}, components: {
props: {}, Recommend,
data: function() { Authorization
return { },
isIpx: false, props: {},
cartList: { data: function() {
invalid: [], return {
valid: [] cartList: {
}, invalid: [],
validList: [], valid: []
isAllSelect: false, },
cartCount: 0, validList: [],
countmoney: 0, isAllSelect: false,
goodsHidden: true, cartCount: 0,
footerswitch: false, countmoney: 0,
count: 0, goodsHidden: true,
checkedIds: [], footerswitch: false,
loaded: false count: 0,
}; checkedIds: [],
}, loaded: false
watch: { };
$yroute(n) { },
if (n.name === "ShoppingCart") { computed: mapGetters(["userInfo"]),
this.carnum();
this.countMoney(); // watch: {
this.getCartList(); // $yroute(n) {
this.gainCount(); // if (n.name === "ShoppingCart") {
this.goodsHidden = true; // this.carnum();
this.footerswitch = false; // this.countMoney();
} // this.getCartList();
}, // this.gainCount();
cartList(list) { // this.goodsHidden = true;
this.validList = list.valid; // this.footerswitch = false;
} // }
}, // },
mounted: function() { // cartList(list) {
let that = this; // this.validList = list.valid;
that.carnum(); // }
that.countMoney(); // },
that.getCartList(); watch: {
that.gainCount(); userInfo(user) {
wx.getSystemInfo({ console.log(user);
success: function(res) { if (user.uid) {
console.log(res); this.carnum();
var name = "iPhone X"; this.countMoney();
if (res.model.indexOf(name) > -1) { this.getCartList();
that.isIpx = true; this.gainCount();
} }
} },
}); cartList(list) {
}, this.validList = list.valid;
methods: { }
goGoodsCon(item) { },
this.$yrouter.push({ onShow: function() {
path: "/pages/shop/GoodsCon/index", if (this.userInfo.uid) {
query: { this.carnum();
id: item.productId this.countMoney();
} this.getCartList();
}); this.gainCount();
}, }
getCartList: function() { },
let that = this; methods: {
getCartList().then(res => { goGoodsCon(item) {
that.cartList = res.data; this.$yrouter.push({
let checkedIds = cookie.get(CHECKED_IDS) || []; path: "/pages/shop/GoodsCon/index",
if (!Array.isArray(checkedIds)) checkedIds = []; query: {
this.cartList.valid.forEach(cart => { id: item.productId
if (checkedIds.indexOf(cart.id) !== -1) cart.checked = true; }
}); });
if (checkedIds.length) { },
that.checkedIds = checkedIds; getCartList: function() {
that.isAllSelect = checkedIds.length === this.cartList.valid.length; let that = this;
that.carnum(); getCartList().then(res => {
that.countMoney(); that.cartList = res.data;
} let checkedIds = cookie.get(CHECKED_IDS) || [];
this.loaded = true; if (!Array.isArray(checkedIds)) checkedIds = [];
}); this.cartList.valid.forEach(cart => {
}, if (checkedIds.indexOf(cart.id) !== -1) cart.checked = true;
// });
delgoods: function() { if (checkedIds.length) {
let that = this, that.checkedIds = checkedIds;
id = [], that.isAllSelect = checkedIds.length === this.cartList.valid.length;
valid = [], that.carnum();
list = that.cartList.valid; that.countMoney();
list.forEach(function(val) { }
if (val.checked === true) { this.loaded = true;
id.push(val.id); });
} },
}); //
if (id.length === 0) { delgoods: function() {
uni.showToast({ let that = this,
title: "请选择产品", id = [],
icon: "none", valid = [],
duration: 2000 list = that.cartList.valid;
}); list.forEach(function(val) {
return; if (val.checked === true) {
} id.push(val.id);
postCartDel(id).then(function() { }
list.forEach(function(val, i) { });
if (val.checked === false || val.checked === undefined) if (id.length === 0) {
valid.push(list[i]); uni.showToast({
}); title: "请选择产品",
that.$set(that.cartList, "valid", valid); icon: "none",
that.carnum(); duration: 2000
that.countMoney(); });
that.gainCount(); return;
that.getCartList(); }
}); postCartDel(id).then(function() {
}, list.forEach(function(val, i) {
// // if (val.checked === false || val.checked === undefined)
gainCount: function() { valid.push(list[i]);
let that = this; });
getCartCount().then(res => { that.$set(that.cartList, "valid", valid);
that.count = res.data.count; that.carnum();
}); that.countMoney();
}, that.gainCount();
// that.getCartList();
delInvalidGoods: function() { });
let that = this, },
id = [], // //
list = that.cartList.invalid; gainCount: function() {
list.forEach(function(val) { let that = this;
id.push(val.id); getCartCount().then(res => {
}); that.count = res.data.count;
postCartDel(id).then(function() { });
list.splice(0, list.length); },
that.gainCount(); //
that.getCartList(); delInvalidGoods: function() {
}); let that = this,
}, id = [],
//; list = that.cartList.invalid;
collectAll: function() { list.forEach(function(val) {
let that = this, id.push(val.id);
data = { });
id: [], postCartDel(id).then(function() {
category: "" list.splice(0, list.length);
}, that.gainCount();
list = that.cartList.valid; that.getCartList();
list.forEach(function(val) { });
if (val.checked === true) { },
data.id.push(val.product_id); //;
data.category = val.type; collectAll: function() {
} let that = this,
}); data = {
if (data.id.length === 0) { id: [],
uni.showToast({ category: ""
title: "请选择产品", },
icon: "none", list = that.cartList.valid;
duration: 2000 list.forEach(function(val) {
}); if (val.checked === true) {
return; data.id.push(val.product_id);
} data.category = val.type;
postCollectAll(data).then(function() { }
uni.showToast({ });
title: "收藏成功!", if (data.id.length === 0) {
icon: "none", uni.showToast({
duration: 2000 title: "请选择产品",
}); icon: "none",
}); duration: 2000
}, });
// return;
placeOrder: function() { }
let that = this, postCollectAll(data).then(function() {
list = that.cartList.valid, uni.showToast({
id = []; title: "收藏成功!",
list.forEach(function(val) { icon: "none",
if (val.checked === true) { duration: 2000
id.push(val.id); });
} });
}); },
if (id.length === 0) { //
uni.showToast({ placeOrder: function() {
title: "请选择产品", let that = this,
icon: "none", list = that.cartList.valid,
duration: 2000 id = [];
}); list.forEach(function(val) {
return; if (val.checked === true) {
} id.push(val.id);
console.log(id); }
this.$yrouter.push({ });
path: "/pages/order/OrderSubmission/index", if (id.length === 0) {
query: { uni.showToast({
id: id.join(",") title: "请选择产品",
} icon: "none",
}); duration: 2000
}, });
manage: function() { return;
let that = this; }
that.footerswitch = !that.footerswitch; console.log(id);
}, this.$yrouter.push({
goodsOpen: function() { path: "/pages/order/OrderSubmission/index",
let that = this; query: {
that.goodsHidden = !that.goodsHidden; id: id.join(",")
}, }
// });
plus: function(index) { },
let that = this; manage: function() {
let list = that.cartList.valid[index]; let that = this;
list.cartNum++; that.footerswitch = !that.footerswitch;
if (list.attrInfo) { },
if (list.cartNum >= list.attrInfo.stock) { goodsOpen: function() {
that.$set(list, "cart_num", list.attrInfo.stock); let that = this;
} that.goodsHidden = !that.goodsHidden;
} else { },
if (list.cartNum >= list.stock) { //
that.$set(list, "cart_num", list.stock); plus: function(index) {
} let that = this;
} let list = that.cartList.valid[index];
that.carnum(); list.cartNum++;
that.countMoney(); if (list.attrInfo) {
that.syncCartNum(list); if (list.cartNum >= list.attrInfo.stock) {
}, that.$set(list, "cart_num", list.attrInfo.stock);
// }
reduce: function(index) { } else {
let that = this; if (list.cartNum >= list.stock) {
let list = that.cartList.valid[index]; that.$set(list, "cart_num", list.stock);
if (list.cartNum <= 1) { }
uni.showToast({ }
title: "已经是底线啦!", that.carnum();
that.countMoney();
that.syncCartNum(list);
},
//
reduce: function(index) {
let that = this;
let list = that.cartList.valid[index];
if (list.cartNum <= 1) {
uni.showToast({
title: "已经是底线啦!",
icon: "none",
duration: 2000
});
return;
}
list.cartNum--;
if (list.cartNum < 1) {
that.$set(list, "cart_num", 1);
}
that.carnum();
that.countMoney();
that.syncCartNum(list);
},
syncCartNum(cart) {
if (!cart.sync) {
changeCartNum(cart.id, Math.max(cart.cartNum, 1) || 1)
.then(res => {
this.getCartList();
})
.catch(error => {
uni.showToast({
title: error.response.data.msg,
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
return; });
} }
list.cartNum--; },
if (list.cartNum < 1) { //
that.$set(list, "cart_num", 1); switchSelect: function(index) {
} let that = this,
that.carnum(); cart = that.cartList.valid[index],
that.countMoney(); i = this.checkedIds.indexOf(cart.id);
that.syncCartNum(list); cart.checked = !cart.checked;
},
syncCartNum(cart) {
if (!cart.sync) {
changeCartNum(cart.id, Math.max(cart.cartNum, 1) || 1)
.then(res => {
this.getCartList();
})
.catch(error => {
uni.showToast({
title: error.response.data.msg,
icon: "none",
duration: 2000
});
});
}
},
//
switchSelect: function(index) {
let that = this,
cart = that.cartList.valid[index],
i = this.checkedIds.indexOf(cart.id);
cart.checked = !cart.checked;
if (i !== -1) this.checkedIds.splice(i, 1); if (i !== -1) this.checkedIds.splice(i, 1);
if (cart.checked) { if (cart.checked) {
this.checkedIds.push(cart.id); this.checkedIds.push(cart.id);
} }
let len = that.cartList.valid.length; let len = that.cartList.valid.length;
let selectnum = []; let selectnum = [];
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
if (that.cartList.valid[i].checked === true) { if (that.cartList.valid[i].checked === true) {
selectnum.push(true); selectnum.push(true);
} }
} }
that.isAllSelect = selectnum.length === len; that.isAllSelect = selectnum.length === len;
that.$set(that, "cartList", that.cartList); that.$set(that, "cartList", that.cartList);
that.$set(that, "isAllSelect", that.isAllSelect); that.$set(that, "isAllSelect", that.isAllSelect);
cookie.set(CHECKED_IDS, that.checkedIds); cookie.set(CHECKED_IDS, that.checkedIds);
that.carnum(); that.carnum();
that.countMoney(); that.countMoney();
}, },
// //
allChecked: function(e) { allChecked: function(e) {
let that = this; let that = this;
let selectAllStatus = e.mp.detail.value[0] ? true : false; let selectAllStatus = e.mp.detail.value[0] ? true : false;
// let selectAllStatus = that.isAllSelect; // let selectAllStatus = that.isAllSelect;
let checkedIds = []; let checkedIds = [];
// for (let i = 0; i < array.length; i++) { // for (let i = 0; i < array.length; i++) {
// array[i].checked = selectAllStatus; // array[i].checked = selectAllStatus;
// checked.push() // checked.push()
// } // }
that.cartList.valid.forEach(cart => { that.cartList.valid.forEach(cart => {
cart.checked = selectAllStatus; cart.checked = selectAllStatus;
if (selectAllStatus) { if (selectAllStatus) {
checkedIds.push(cart.id); checkedIds.push(cart.id);
} }
}); });
let cartList = { let cartList = {
...that.cartList ...that.cartList
}; };
that.cartList = []; that.cartList = [];
that.cartList = cartList; that.cartList = cartList;
this.$set(this, "cartList", this.cartList); this.$set(this, "cartList", this.cartList);
this.$set(this, "isAllSelect", selectAllStatus); this.$set(this, "isAllSelect", selectAllStatus);
this.checkedIds = checkedIds; this.checkedIds = checkedIds;
cookie.set(CHECKED_IDS, checkedIds); cookie.set(CHECKED_IDS, checkedIds);
that.carnum(); that.carnum();
that.countMoney(); that.countMoney();
this.$forceUpdate(); this.$forceUpdate();
}, },
// //
carnum: function() { carnum: function() {
let that = this; let that = this;
var carnum = 0; var carnum = 0;
var array = that.cartList.valid; var array = that.cartList.valid;
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
if (array[i].checked === true) { if (array[i].checked === true) {
carnum += parseInt(array[i].cartNum); carnum += parseInt(array[i].cartNum);
} }
} }
that.$set(that, "cartCount", carnum); that.$set(that, "cartCount", carnum);
}, },
// //
countMoney: function() { countMoney: function() {
let that = this; let that = this;
let carmoney = 0; let carmoney = 0;
let array = that.cartList.valid; let array = that.cartList.valid;
for (let i = 0; i < array.length; i++) { for (let i = 0; i < array.length; i++) {
if (array[i].checked === true) { if (array[i].checked === true) {
carmoney = add(carmoney, mul(array[i].cartNum, array[i].truePrice)); carmoney = add(carmoney, mul(array[i].cartNum, array[i].truePrice));
} }
} }
that.countmoney = carmoney; that.countmoney = carmoney;
} }
} }
}; };
</script> </script>

5
pages/user/PersonalData/index.vue

@ -121,11 +121,6 @@ export default {
userIndex: 0 userIndex: 0
}; };
}, },
watch: {
$yroute(n) {
if (n.name === "PersonalData") this.$store.dispatch("USERINFO", true);
}
},
computed: mapGetters(["userInfo"]), computed: mapGetters(["userInfo"]),
mounted: function() { mounted: function() {
this.avatar = this.userInfo.avatar; this.avatar = this.userInfo.avatar;

4
pages/user/Recharge/index.vue

@ -63,14 +63,14 @@ export default {
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
return return;
} else if (price < 0.01) { } else if (price < 0.01) {
uni.showToast({ uni.showToast({
title: "转入金额不能低于0.01", title: "转入金额不能低于0.01",
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
return return;
} }
uni.showModal({ uni.showModal({

371
pages/user/User/index.vue

@ -1,157 +1,161 @@
<template> <template>
<view class="user"> <view class="user">
<view class="header bg-color-red acea-row row-between-wrapper"> <view v-if="userInfo.uid">
<view class="picTxt acea-row row-between-wrapper"> <view class="header bg-color-red acea-row row-between-wrapper">
<view class="pictrue"> <view class="picTxt acea-row row-between-wrapper">
<image :src="userInfo.avatar" /> <view class="pictrue">
</view> <image :src="userInfo.avatar" />
<view class="text">
<view class="acea-row row-middle">
<view class="name line1">{{ userInfo.nickname }}</view>
<view class="member acea-row row-middle" v-if="userInfo.vip">
<image :src="userInfo.vipIcon" />
<text>{{ userInfo.vipName }}</text>
</view>
</view> </view>
<view @click="goPersonalData()" class="id" v-if="userInfo.phone"> <view class="text">
<text>ID{{ userInfo.uid || 0}}</text> <view class="acea-row row-middle">
<text class="iconfont icon-bianji1"></text> <view class="name line1">{{ userInfo.nickname }}</view>
<view class="member acea-row row-middle" v-if="userInfo.vip">
<image :src="userInfo.vipIcon" />
<text>{{ userInfo.vipName }}</text>
</view>
</view>
<view @click="goPersonalData()" class="id" v-if="userInfo.phone">
<text>ID{{ userInfo.uid || 0}}</text>
<text class="iconfont icon-bianji1"></text>
</view>
<button
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
class="binding"
v-else
>
<text>绑定手机号</text>
</button>
</view> </view>
<button
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
class="binding"
v-else
>
<text>绑定手机号</text>
</button>
</view>
</view>
<text class="iconfont icon-shezhi" @click="goPersonalData()"></text>
</view>
<view class="wrapper">
<view class="nav acea-row row-middle">
<view @click="goUserAccount()" class="item">
<text>我的余额</text>
<text class="num">{{ userInfo.nowMoney || 0 }}</text>
</view>
<view
@click="goUserPromotion()"
class="item"
v-if="userInfo.isPromoter === 1 || userInfo.statu === 2"
>
<text>当前佣金</text>
<text class="num">{{ userInfo.brokeragePrice || 0 }}</text>
</view>
<view @click="goIntegral()" class="item" v-else>
<text>当前积分</text>
<text class="num">{{ userInfo.integral || 0 }}</text>
</view>
<view @click="goUserCoupon()" class="item">
<text>优惠券</text>
<text class="num">{{ userInfo.couponCount || 0 }}</text>
</view> </view>
<text class="iconfont icon-shezhi" @click="goPersonalData()"></text>
</view> </view>
<view class="myOrder"> <view class="wrapper">
<view class="title acea-row row-between-wrapper"> <view class="nav acea-row row-middle">
<text>我的订单</text> <view @click="goUserAccount()" class="item">
<text @click="goMyOrder()" class="allOrder"> <text>我的余额</text>
全部订单 <text class="num">{{ userInfo.nowMoney || 0 }}</text>
<text class="iconfont icon-jiantou"></text> </view>
</text> <view
@click="goUserPromotion()"
class="item"
v-if="userInfo.isPromoter === 1 || userInfo.statu === 2"
>
<text>当前佣金</text>
<text class="num">{{ userInfo.brokeragePrice || 0 }}</text>
</view>
<view @click="goIntegral()" class="item" v-else>
<text>当前积分</text>
<text class="num">{{ userInfo.integral || 0 }}</text>
</view>
<view @click="goUserCoupon()" class="item">
<text>优惠券</text>
<text class="num">{{ userInfo.couponCount || 0 }}</text>
</view>
</view> </view>
<view class="orderState acea-row row-middle"> <view class="myOrder">
<view @click="goMyOrder(0)" class="item"> <view class="title acea-row row-between-wrapper">
<view class="pictrue"> <text>我的订单</text>
<image :src="$VUE_APP_RESOURCES_URL + '/images/dfk.png'" /> <text @click="goMyOrder()" class="allOrder">
<text 全部订单
class="order-status-num" <text class="iconfont icon-jiantou"></text>
v-if="orderStatusNum.unpaidCount > 0" </text>
>{{ orderStatusNum.unpaidCount }}</text>
</view>
<view>待付款</view>
</view> </view>
<view @click="goMyOrder(1)" class="item"> <view class="orderState acea-row row-middle">
<view class="pictrue"> <view @click="goMyOrder(0)" class="item">
<image :src="$VUE_APP_RESOURCES_URL+'/images/dfh.png'" /> <view class="pictrue">
<text <image :src="$VUE_APP_RESOURCES_URL + '/images/dfk.png'" />
class="order-status-num" <text
v-if="orderStatusNum.unshippedCount > 0" class="order-status-num"
>{{ orderStatusNum.unshippedCount }}</text> v-if="orderStatusNum.unpaidCount > 0"
>{{ orderStatusNum.unpaidCount }}</text>
</view>
<view>待付款</view>
</view> </view>
<view>待发货</view> <view @click="goMyOrder(1)" class="item">
</view> <view class="pictrue">
<view @click="goMyOrder(2)" class="item"> <image :src="$VUE_APP_RESOURCES_URL+'/images/dfh.png'" />
<view class="pictrue"> <text
<image :src="$VUE_APP_RESOURCES_URL+'/images/dsh.png'" /> class="order-status-num"
<text v-if="userInfo.orderStatusNum.unshippedCount > 0"
class="order-status-num" >{{ userInfo.orderStatusNum.unshippedCount }}</text>
v-if="orderStatusNum.receivedCount > 0" </view>
>{{ orderStatusNum.receivedCount }}</text> <view>待发货</view>
</view> </view>
<text>待收货</text> <view @click="goMyOrder(2)" class="item">
</view> <view class="pictrue">
<view @click="goMyOrder(3)" class="item"> <image :src="$VUE_APP_RESOURCES_URL+'/images/dsh.png'" />
<view class="pictrue"> <text
<image :src="$VUE_APP_RESOURCES_URL+'/images/dpj.png'" /> class="order-status-num"
<text v-if="userInfo.orderStatusNum.receivedCount > 0"
class="order-status-num" >{{ userInfo.orderStatusNum.receivedCount }}</text>
v-if="orderStatusNum.evaluatedCount > 0" </view>
>{{ orderStatusNum.evaluatedCount }}</text> <text>待收货</text>
</view> </view>
<text>待评价</text> <view @click="goMyOrder(3)" class="item">
</view> <view class="pictrue">
<view @click="goReturnList()" class="item"> <image :src="$VUE_APP_RESOURCES_URL+'/images/dpj.png'" />
<view class="pictrue"> <text
<image :src="$VUE_APP_RESOURCES_URL+'/images/sh.png'" /> class="order-status-num"
<text v-if="userInfo.orderStatusNum.evaluatedCount > 0"
class="order-status-num" >{{ userInfo.orderStatusNum.evaluatedCount }}</text>
v-if="orderStatusNum.refundCount > 0" </view>
>{{ orderStatusNum.refundCount }}</text> <text>待评价</text>
</view> </view>
<text>售后/退款</text> <view @click="goReturnList()" class="item">
</view>
</view>
</view>
<view class="myService">
<view class="title acea-row row-middle">
<text>我的服务</text>
</view>
<view class="serviceList acea-row row-middle">
<template v-for="(item, MyMenusIndex) in MyMenus">
<view class="item" :key="MyMenusIndex" @click="goPages(MyMenusIndex)" v-if="item.url">
<view class="pictrue"> <view class="pictrue">
<image :src="item.pic" /> <image :src="$VUE_APP_RESOURCES_URL+'/images/sh.png'" />
<text
class="order-status-num"
v-if="userInfo.orderStatusNum.refundCount > 0"
>{{ userInfo.orderStatusNum.refundCount }}</text>
</view> </view>
<view>{{ item.name }}</view> <text>售后/退款</text>
</view> </view>
</template> </view>
</view>
<view class="myService">
<view class="title acea-row row-middle">
<text>我的服务</text>
</view>
<view class="serviceList acea-row row-middle">
<template v-for="(item, MyMenusIndex) in MyMenus">
<view class="item" :key="MyMenusIndex" @click="goPages(MyMenusIndex)" v-if="item.url">
<view class="pictrue">
<image :src="item.pic" />
</view>
<view>{{ item.name }}</view>
</view>
</template>
</view>
</view> </view>
<!--<view -->
<!--class="item"-->
<!--@click="changeswitch(true)"-->
<!--v-if="userInfo.phone && isWeixin"-->
<!--&gt;-->
<!--<view class="pictrue"><image :src="$VUE_APP_RESOURCES_URL+'/images/switch.png'" /></view>-->
<!--<view>账号切换</!--<view>-->
<!--</!--<view>-->
<!-- </view>
</view>-->
</view> </view>
<!--<view --> <view style="text-align: center;margin-top: 1rem">By@意象</view>
<!--class="item"--> <view class="footer-line-height"></view>
<!--@click="changeswitch(true)"--> <SwitchWindow
<!--v-if="userInfo.phone && isWeixin"--> v-on:changeswitch="changeswitch"
<!--&gt;--> :switchActive="switchActive"
<!--<view class="pictrue"><image :src="$VUE_APP_RESOURCES_URL+'/images/switch.png'" /></view>--> :login_type="userInfo.login_type"
<!--<view>账号切换</!--<view>--> ></SwitchWindow>
<!--</!--<view>-->
<!-- </view>
</view>-->
</view> </view>
<view style="text-align: center;margin-top: 1rem">By@意象</view> <Authorization v-else />
<view class="footer-line-height"></view>
<SwitchWindow
v-on:changeswitch="changeswitch"
:switchActive="switchActive"
:login_type="userInfo.login_type"
></SwitchWindow>
</view> </view>
</template> </template>
<script> <script>
import { getUser, getMenuUser, bindingPhone } from "@/api/user"; import { getUser, getMenuUser, bindingPhone } from "@/api/user";
import { isWeixin, VUE_APP_RESOURCES_URL } from "@/utils"; import { isWeixin, VUE_APP_RESOURCES_URL } from "@/utils";
import SwitchWindow from "@/components/SwitchWindow"; import SwitchWindow from "@/components/SwitchWindow";
import Authorization from "@/pages/authorization/index";
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
const NAME = "User"; const NAME = "User";
@ -159,30 +163,18 @@ const NAME = "User";
export default { export default {
name: NAME, name: NAME,
components: { components: {
SwitchWindow SwitchWindow,
Authorization
}, },
props: {}, props: {},
data: function() { data: function() {
return { return {
userInfo: {},
MyMenus: [], MyMenus: [],
orderStatusNum: {},
switchActive: false, switchActive: false,
isWeixin: false isWeixin: false
}; };
}, },
computed: mapGetters(["wxCode"]), computed: mapGetters(["userInfo"]),
watch: {
$yroute(n) {
if (n.name === NAME) this.User();
}
},
mounted: function() {
console.log("这个是个人中心");
this.User();
this.MenuUser();
this.isWeixin = isWeixin();
},
methods: { methods: {
goReturnList() { goReturnList() {
this.$yrouter.push("/pages/order/ReturnList/index"); this.$yrouter.push("/pages/order/ReturnList/index");
@ -214,33 +206,44 @@ export default {
}, },
getPhoneNumber: function(e) { getPhoneNumber: function(e) {
console.log(e.mp.detail); console.log(e.mp.detail);
//
if (e.mp.detail.errMsg == "getPhoneNumber:ok") { if (e.mp.detail.errMsg == "getPhoneNumber:ok") {
uni.showLoading({ uni.showLoading({
title: "绑定中" title: "绑定中"
}); });
wx.login({ //
success: loginRes => { uni.getProvider({
bindingPhone({ service: "oauth",
code: loginRes.code, success: function(res) {
encryptedData: e.mp.detail.encryptedData, console.log(res.provider);
iv: e.mp.detail.iv // h5
}) if (res.provider) {
.then(res => { uni.login({
this.User(); success: loginRes => {
uni.hideLoading(); bindingPhone({
uni.showToast({ code: loginRes.code,
title: res.msg, encryptedData: e.mp.detail.encryptedData,
icon: "success", iv: e.mp.detail.iv
duration: 2000 })
}); .then(res => {
}) this.User();
.catch(error => { uni.hideLoading();
uni.showToast({ uni.showToast({
title: error.msg || error.response.data.msg, title: res.msg,
icon: "none", icon: "success",
duration: 2000 duration: 2000
}); });
})
.catch(error => {
uni.showToast({
title: error.msg || error.response.data.msg,
icon: "none",
duration: 2000
});
});
}
}); });
}
} }
}); });
} else { } else {
@ -256,10 +259,10 @@ export default {
}, },
User: function() { User: function() {
let that = this; let that = this;
getUser().then(res => { // getUser().then(res => {
that.userInfo = res.data; // that.user = res.data;
that.orderStatusNum = res.data.orderStatusNum; // that.orderStatusNum = res.data.orderStatusNum;
}); // });
}, },
MenuUser: function() { MenuUser: function() {
let that = this; let that = this;
@ -287,12 +290,12 @@ export default {
url === "/pages/orderAdmin/OrderIndex/index" && url === "/pages/orderAdmin/OrderIndex/index" &&
!this.userInfo.adminid !this.userInfo.adminid
) { ) {
uni.showToast({ uni.showToast({
title: "您还不是管理员!!", title: "您还不是管理员!!",
icon: "none", icon: "none",
duration: 2000 duration: 2000
}); });
return; return;
} }
this.$yrouter.push({ this.$yrouter.push({
@ -300,10 +303,18 @@ export default {
}); });
} }
}, },
watch: {
userInfo() {
this.MenuUser();
}
},
onShow() { onShow() {
this.User(); console.log(this.userInfo);
this.MenuUser(); if (this.userInfo.uid) {
this.isWeixin = isWeixin(); this.User();
this.MenuUser();
this.isWeixin = isWeixin();
}
} }
}; };
</script> </script>

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

@ -73,23 +73,6 @@ export default {
); );
}, },
downloadIamge: function(imgsrc, name) { downloadIamge: function(imgsrc, name) {
// let image = new Image();
// image.setAttribute("crossOrigin", "anonymous");
// image.onload = function() {
// // let canvas = document.createElement("canvas");
// // canvas.width = image.width;
// // canvas.height = image.height;
// // let context = canvas.getContext("2d");
// // context.drawImage(image, 0, 0, image.width, image.height);
// // let url = canvas.toDataURL("image/png"); //base64
// // let a = document.createElement("a"); // a
// // let event = new MouseEvent("click"); //
// // a.download = name || "photo"; //
// // a.href = url; // URLa.href
// // a.dispatchEvent(event); // a
// };
// image.src = imgsrc;
var that = this; var that = this;
this.isDown = true; this.isDown = true;
var downloadUrl = imgsrc; var downloadUrl = imgsrc;

33
store/index.js

@ -12,15 +12,11 @@ const LOGIN_KEY = "login_status";
const vuexStore = new Vuex.Store({ const vuexStore = new Vuex.Store({
state: { state: {
wxCode: null, // 是否已经在授权页面
isAuthorizationPage: false, isAuthorizationPage: false,
// 是否授权
isAuthorization: false, isAuthorization: false,
footer: true,
home: true,
tabtarIndex: 0,
homeActive: false,
token: store.get(LOGIN_KEY) || null, token: store.get(LOGIN_KEY) || null,
backgroundColor: "#fff",
userInfo: null userInfo: null
}, },
mutations: { mutations: {
@ -50,8 +46,9 @@ const vuexStore = new Vuex.Store({
store.set(LOGIN_KEY, token, expires_time); store.set(LOGIN_KEY, token, expires_time);
}, },
LOGOUT(state) { LOGOUT(state) {
state.token = undefined; state.token = null;
store.remove(LOGIN_KEY); state.userInfo = null
store.clearAll()
}, },
BACKGROUND_COLOR(state, color) { BACKGROUND_COLOR(state, color) {
state.color = color; state.color = color;
@ -66,10 +63,6 @@ const vuexStore = new Vuex.Store({
UPDATE_AUTHORIZATION(state, isAuthorization) { UPDATE_AUTHORIZATION(state, isAuthorization) {
state.isAuthorization = isAuthorization; state.isAuthorization = isAuthorization;
}, },
UPDATE_WXCODE(state, wxCode) {
console.log(wxCode, 'wxCode')
state.wxCode = wxCode;
}
}, },
actions: { actions: {
USERINFO({ state, commit }, force) { USERINFO({ state, commit }, force) {
@ -85,31 +78,25 @@ const vuexStore = new Vuex.Store({
dialog.error("获取信息失败!"); dialog.error("获取信息失败!");
}); });
}, },
changeLogin({ state, commit }, data, date) {
commit("LOGIN", data, date);
},
changeUserInfo({ state, commit }, user) { changeUserInfo({ state, commit }, user) {
commit("UPDATE_USERINFO", user.user); commit("UPDATE_USERINFO", user.user);
}, },
changeTabtar({ state, commit }, index) { changeAuthorizationPage({ state, commit }, index) {
commit("CHANGE_TABTAR", index); commit("UPDATE_AUTHORIZATIONPAGE", index);
}, },
changeAuthorization({ state, commit }, index) { changeAuthorization({ state, commit }, index) {
commit("UPDATE_AUTHORIZATION", index); commit("UPDATE_AUTHORIZATION", index);
}, },
changeWxCode({ state, commit }, index) {
commit("UPDATE_WXCODE", index);
},
}, },
getters: { getters: {
wxCode: state => state.wxCode,
isAuthorizationPage: state => state.isAuthorizationPage, isAuthorizationPage: state => state.isAuthorizationPage,
isAuthorization: state => state.isAuthorization, isAuthorization: state => state.isAuthorization,
footer: state => state.footer,
homeActive: state => state.homeActive,
home: state => state.home,
token: state => state.token, token: state => state.token,
isLogin: state => !!state.token, isLogin: state => !!state.token,
backgroundColor: state => state.backgroundColor,
userInfo: state => state.userInfo || {}, userInfo: state => state.userInfo || {},
tabtarIndex: state => state.tabtarIndex
}, },
strict: debug strict: debug
}); });

433
utils/index.js

@ -97,7 +97,7 @@ export function getCurrentPageUrlWithArgs() {
// 复制到剪切板 // 复制到剪切板
export const copyClipboard = (data) => { export const copyClipboard = (data) => {
wx.setClipboardData({ uni.setClipboardData({
data: data, data: data,
success: (res) => { success: (res) => {
uni.showToast({ uni.showToast({
@ -110,139 +110,209 @@ export const copyClipboard = (data) => {
} }
export const toAuthorization = (msg) => { export const replaceLogin = (msg) => {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ uni.showToast({
title: msg, title: msg,
icon: 'none', icon: 'none',
duration: 2000 duration: 2000
}); });
console.log(222222222) console.log(Vue.prototype.$deviceType)
replace({ // 这里代表已经失去登录状态以及401强制推出登录了
path: '/pages/user/Login/index', store.commit('LOGOUT')
query: {
redirect: `/${getCurrentPageUrl()}`, if (Vue.prototype.$deviceType == 'Weixin') {
...parseQuery() // 如果是微信小程序,跳转到授权页
} replace({
}) path: '/pages/authorization/index',
query: {
redirect: `/${getCurrentPageUrl()}`,
...parseQuery()
}
})
} else {
// 如果不是小程序跳转到登录页
replace({
path: '/pages/user/Login/index',
query: query || {
redirect: `/${getCurrentPageUrl()}`,
...parseQuery()
}
})
}
} }
export const login = (option) => { export const getProvider = () => {
console.log('调用登录')
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
// 获取当前环境的服务商 // 获取当前环境的服务商
uni.getProvider({ uni.getProvider({
service: 'oauth', service: 'oauth',
success: function(res) { success: function (res) {
console.log(res.provider) console.log(`当前环境的服务商为 | ${res.provider}`)
// 此处可以排除h5 // 此处可以排除h5
if (res.provider) { if (res.provider) {
// 调用登录接口 resolve(res.provider[0])
uni.login({
provider: res.provider[0],
success: function(loginRes) {
// 微信登录
console.log('获取code')
let code = loginRes.code;
store.commit("UPDATE_WXCODE", loginRes.code);
console.log(JSON.stringify(loginRes));
// 检查授权, 检查用户信息授权
uni.authorize({
scope: 'scope.userInfo',
success() {
uni.getUserInfo({
provider: res.provider[0],
success: function(user) {
console.log(user)
console.log('用户昵称为:' + user.userInfo.nickName);
if (Vue.prototype.$deviceType == 'Weixin') {
wxappAuth({
encryptedData: user.encryptedData,
iv: user.iv,
code: code,
spread: cookie.get("spread")
}).then(({
data
}) => {
resolve(res.data)
uni.hideLoading();
store.commit("LOGIN", data.token, dayjs(data.expires_time));
getUser().then(res => {
store.dispatch('changeUserInfo', {
user: res.data
})
});
var pages = getCurrentPages() //获取加载的页面
var currentPage = pages[pages.length - 1] //获取当前页面的对象
let url = "/pages/home/index"
let query = {}
if (currentPage) {
if (currentPage.route != 'pages/Loading/index' && currentPage.route !=
'pages/user/Login/index') {
url = currentPage.route
}
if (currentPage.route == 'pages/user/Login/index') {
const {
redirect,
...querys
} = currentPage.options
url = redirect
query = { ...querys
}
}
}
switchTab({
path: url,
query
});
}).catch(error => {
reject()
option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
});
}
},
fail() {
// 获取用户信息失败
reject()
option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
}
});
},
fail() {
// 获取用户信息失败
reject()
option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
}
})
},
fail() {
// 调用登录接口失败
reject()
option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
}
});
} }
}, },
fail() { fail() {
reject() reject('获取环境服务商失败')
option && option.fail ? option.fail() : toAuthorization('获取用户信息失败,请重试')
} }
}); })
}).catch(error => {
console.log(error)
}) })
}
}
export const authorize = (authorizeStr) => {
return new Promise((resolve, reject) => {
uni.authorize({
scope: `scope.${authorizeStr}`,
success() {
resolve('获取授权成功')
},
fail() {
reject('获取授权失败')
}
})
}).catch(error => {
console.log(error)
})
}
export const login = (option) => {
console.log('调用登录')
return new Promise((resolve, reject) => {
getProvider().then(provider => {
// 调用登录接口
uni.login({
provider: provider,
success: function (loginRes) {
// 微信登录
console.log(`获取code | ${loginRes.code}`)
let code = loginRes.code;
// 检查授权, 检查用户信息授权
authorize('userInfo').then(() => {
uni.getUserInfo({
provider: provider,
success: function (user) {
console.log(user)
console.log(`用户昵称为 | ${user.userInfo.nickName}`);
console.log(`当前的环境 | ${Vue.prototype.$deviceType}`)
if (Vue.prototype.$deviceType == 'Weixin') {
wxappAuth({
encryptedData: user.encryptedData,
iv: user.iv,
code: code,
spread: cookie.get("spread")
}).then(({
data
}) => {
console.log('登录成功')
console.log(data)
console.log('登录成功1')
resolve(data)
console.log('登录成功3')
uni.hideLoading();
console.log('登录成功4')
store.commit("LOGIN", data.token, dayjs(data.expires_time));
console.log('登录成功5')
getUser().then(res => {
store.dispatch('changeUserInfo', {
user: res.data
})
console.log('登录成功6')
console.log(option)
// option && option.success ? option.success() : null
var pages = getCurrentPages() //获取加载的页面
console.log('登录成功7')
var currentPage = pages[pages.length - 1] //获取当前页面的对象
let url = "/pages/home/index"
let query = {}
console.log('登录成功8')
console.log(currentPage)
if (currentPage) {
// 获取到最后一个页面
if (
currentPage.route != 'pages/Loading/index'
&&
currentPage.route != 'pages/user/Login/index'
) {
url = currentPage.route
}
if (currentPage.route == 'pages/authorization/index') {
const {
redirect,
...querys
} = currentPage.options
url = redirect
query = {
...querys
}
}
}
console.log('登录成功9')
console.log({
path: url,
query
})
switchTab({
path: `${url}`,
query
});
})
}).catch(error => {
reject()
console.log('微信登录失败')
console.log(error)
handleFail(option, '微信登录失败')
});
}
},
fail() {
// 获取用户信息失败
reject()
handleFail(option, '获取用户信息失败')
}
});
}).catch(error => {
reject()
console.log(error)
handleFail(option, '拒绝授权')
})
},
fail() {
// 调用登录接口失败
reject()
handleFail(option, '登录失败')
}
});
}).catch(error => {
reject()
console.log(error)
handleFail(option, '获取环境服务商失败')
})
}).catch(error => {
console.log(error)
handleFail(option, '登录失败')
})
}
const handleFail = (option, msg) => {
// 此处是处理登录失效的问题的
console.log(store)
option && option.fail ? option.fail() : replaceLogin('登录失败,请重新登录')
}
export function parseUrl(location) { export function parseUrl(location) {
if (typeof location === 'string') return location if (typeof location === 'string') return location
const { const {
path, path,
query query
@ -272,53 +342,95 @@ export function parseRoute($mp) {
} }
} }
export function push(location, complete, fail, success) {
export const handleLoginStatus = (location, complete, fail, success) => {
console.log(location, '开始健全')
// 不登录可访问的页面
let page = [{
path: '/pages/Loading/index',
name: 'loading页面'
},
{
path: '/pages/home/index',
name: '首页'
},
{
path: '/pages/user/Login/index',
name: '登录页面'
},
{
path: '/pages/authorization/index',
name: '授权页面'
},
]
// 是否可以访问
let isAuth = false
// 从 location 中获取当前url,location typeof string || object
let path = '' let path = ''
if (typeof location === 'string') { if (typeof location === 'string') {
path = location path = location
} else { } else {
path = location.path path = location.path
} }
console.log(path)
if (path != '/pages/launch/index' || path != '/pages/loading/index' || path != '/pages/home/index' || path != console.log(store.getters.userInfo, '用户信息')
'/pages/loading/index') { if (!store.getters.userInfo.uid) {
if (!store.getters.userInfo.uid) { page.map((item) => {
replace({ console.log(item.path == path)
path: '/pages/user/Login/index', if (item.path == path) {
query: { isAuth = true
redirect: `/${getCurrentPageUrl()}`, }
...parseQuery() })
} } else {
isAuth = true
}
return new Promise((resolve, reject) => {
if (isAuth) {
console.log('有权限')
// 登录了有权限
console.log({
url: parseUrl(location),
complete,
fail,
success
}) })
return resolve({
url: parseUrl(location),
complete,
fail,
success
})
} else {
console.log('无权限')
// 未登录没有权限
replaceLogin()
reject()
} }
} }).catch(error => {
const url = parseUrl(location) console.log(error)
const params = { })
url, }
complete,
fail,
success
}
if (location.isTab) { export function push(location, complete, fail, success) {
uni.switchTab(params) handleLoginStatus(location, complete, fail, success).then(params => {
return console.log(params)
} uni.navigateTo(params)
if (location.reLaunch) { }).catch(error => {
uni.reLaunch(params) // 没有权限
return
} })
uni.navigateTo(params)
} }
export function replace(location, complete, fail, success) { export function replace(location, complete, fail, success) {
const url = parseUrl(location) handleLoginStatus(location, complete, fail, success).then(params => {
uni.redirectTo({ console.log(params)
url, uni.redirectTo(params)
complete, }).catch(error => {
fail, // 没有权限
success
}) })
} }
@ -331,18 +443,18 @@ export function go(delta) {
export function back() { export function back() {
uni.navigateBack({ uni.navigateBack({
delta: 1, delta: 1,
success: function(e) {}, success: function (e) { },
fail: function(e) {} fail: function (e) { }
}) })
} }
export function switchTab(location, complete, fail, success) { export function switchTab(location, complete, fail, success) {
const url = parseUrl(location) console.log(location)
uni.switchTab({ handleLoginStatus(location, complete, fail, success).then(params => {
url, console.log(params)
complete, uni.switchTab(params)
fail, }).catch(error => {
success // 没有权限
}) })
} }
@ -383,20 +495,19 @@ export function handleQrCode() {
} }
const getImageInfo = (images) => { const getImageInfo = (images) => {
console.log(images)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let imageAry = {} let imageAry = {}
images.map((item, index) => { images.map((item, index) => {
wx.getImageInfo({ uni.getImageInfo({
src: item, src: item,
fail: function(res) { fail: function (res) {
imageAry[index] = null imageAry[index] = null
console.log(res) console.log(res)
if (imageAry.length == images.length) { if (imageAry.length == images.length) {
resolve(imageAry) resolve(imageAry)
} }
}, },
success: function(res) { success: function (res) {
imageAry[index] = res imageAry[index] = res
console.log(res) console.log(res)
if (Object.keys(imageAry).length == images.length) { if (Object.keys(imageAry).length == images.length) {
@ -425,7 +536,7 @@ export const PosterCanvas = (store, successCallBack) => {
}); });
getImageInfo([store.image, store.code]).then(res => { getImageInfo([store.image, store.code]).then(res => {
let contentHh = 48 * 1.3 let contentHh = 48 * 1.3
const ctx = wx.createCanvasContext('myCanvas'); const ctx = uni.createCanvasContext('myCanvas');
ctx.clearRect(0, 0, 0, 0); ctx.clearRect(0, 0, 0, 0);
const WIDTH = 747 const WIDTH = 747
const HEIGHT = 1326; const HEIGHT = 1326;
@ -455,17 +566,17 @@ export const PosterCanvas = (store, successCallBack) => {
ctx.fillText('长按识别二维码立即购买', WIDTH / 2, 1167); ctx.fillText('长按识别二维码立即购买', WIDTH / 2, 1167);
// ctx.drawImage(store.code, 199, 1064, 200, 200); // ctx.drawImage(store.code, 199, 1064, 200, 200);
ctx.save(); ctx.save();
ctx.draw(true, function(oi) { ctx.draw(true, function (oi) {
wx.canvasToTempFilePath({ uni.canvasToTempFilePath({
canvasId: 'myCanvas', canvasId: 'myCanvas',
fileType: 'png', fileType: 'png',
destWidth: WIDTH, destWidth: WIDTH,
destHeight: HEIGHT, destHeight: HEIGHT,
success: function(res) { success: function (res) {
uni.hideLoading(); uni.hideLoading();
successCallBack && successCallBack(res.tempFilePath); successCallBack && successCallBack(res.tempFilePath);
}, },
fail: function(error) { fail: function (error) {
console.log(error) console.log(error)
}, },
@ -473,7 +584,7 @@ export const PosterCanvas = (store, successCallBack) => {
}); });
}) })
// wx.getImageInfo({ // uni.getImageInfo({
// src: store.image, // src: store.image,
// fail: function (res) { // fail: function (res) {
// uni.showToast({ // uni.showToast({
@ -486,4 +597,4 @@ export const PosterCanvas = (store, successCallBack) => {
// } // }
// }) // })
} }

45
utils/store/cookie.js

@ -7,69 +7,36 @@ function get(key) {
if (!key || !_has(key)) { if (!key || !_has(key)) {
return null; return null;
} }
return wx.getStorageSync(key) return uni.getStorageSync(key)
// let regexpStr =
// "(?:^|.*;\\s*)" +
// escape(key).replace(/[-.+*]/g, "\\$&") +
// "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*";
// return JSON.parse(unescape(doc.cookie.replace(new RegExp(regexpStr), "$1")));
} }
function all() { function all() {
return wx.getStorageInfoSync() return uni.getStorageInfoSync()
// let cookies = doc.cookie.split(/; ?/g),
// data = {};
// for (let i = cookies.length - 1; i >= 0; i--) {
// if (!trim(cookies[i])) {
// continue;
// }
// let kvp = cookies[i].split("=");
// let key = unescape(kvp[0]);
// data[key] = unescape(kvp[1]);
// }
// return data;
} }
function set(key, data, time) { function set(key, data, time) {
if (!key) { if (!key) {
return; return;
} }
// let expires = "Tue, 19 Jan 2038 03:14:07 GMT"; uni.setStorageSync(key, data)
// if (time) {
// let date;
// if (isType(time, "Date")) {
// date = time;
// } else {
// date = new Date();
// date.setTime(date.getTime() + time * 60000);
// }
// expires = date.toGMTString();
// }
// data = JSON.stringify(data);
// doc.cookie =
// escape(key) + "=" + escape(data) + "; expires=" + expires + "; path=/";
wx.setStorageSync(key, data)
} }
function remove(key) { function remove(key) {
if (!key || !_has(key)) { if (!key || !_has(key)) {
return; return;
} }
wx.removeStorageSync(key) uni.removeStorageSync(key)
} }
function clearAll() { function clearAll() {
wx.clearStorage() uni.clearStorage()
} }
function _has(key) { function _has(key) {
if (!key) { if (!key) {
return return
} }
let value = wx.getStorageSync(key) let value = uni.getStorageSync(key)
if (value) { if (value) {
return true return true
} }

Loading…
Cancel
Save