Commit 6d7235bc by zhangcheng

授权登录 首页数据

parent c38bcaf5
<template>
<u-popup :show="false" mode="bottom" :round="10" :overlay="true" :safeAreaInsetBottom="true" @close="showShopCar=false">
<view class="shop-car">
<view class="header">
<text class="left">购物袋</text>
<text class="right" @click="clearCar"><u-icon name="trash" color="#2979ff" size="28"></u-icon>清空购物车</text>
</view>
<view class="container">
<view>
<view class="empty" v-if="show==false">
<image src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309" mode="widthFix" style="width: 400rpx;"></image>
<view class="empty-text">空空如也的购物</view>
<view class="empty-button" @click="goshopping">去选购</view>
</view>
<view v-if="show==true">
<view class="goods-detail" v-for="(item,index) in goods" :key="index">
<view class="detail-left">
<view class="goods-left">
<u-checkbox-group @change="selected(item)">
<label>
<u-checkbox shape="circle" class="selected" color="#555555" :checked="item.flag"/><text></text>
</label>
</u-checkbox-group>
<image :src="item.thumbnail" style="width: 150rpx;height: 140rpx;"></image>
</view>
<view class="size">
<text style="font-size: 28rpx;color: #000000;">{{item.name}}</text>
<text style="font-size:20rpx;color:#666666"><text v-for="(rl,index) in item.rules" :key="rl.ruleName">{{rl.ruleName}}<text v-if="index!=item.rules.length-1">/</text></text></text>
<text><text class="goods-price">{{item.discount}}</text><text style="color: #666666; font-size:20rpx;text-decoration:line-through; margin-left:10rpx">{{item.price}}</text></text>
</view>
</view>
<view class="detail-right">
<text class="subtract" @click="reduce(item)">-</text>
<text class="num">{{item.num}}</text>
<text @click="add(item)" class="add">+</text>
</view>
</view>
</view>
<view class="end">
<view class="end-left">
<!-- <checkbox-group @change="selectgoods()">
<label>
<checkbox :checked="allchecked" />全选
</label>
</checkbox-group> -->
<view style="display:flex">
<text class="car-img"></text>
<text style="color:#000000;font-weight: bold;display: flex; align-items: center;">{{totalPrice.toFixed(2)}}</text>
</view>
</view>
<view class="end-right">
付款
<!-- ({{totalNum}}) -->
</view>
</view>
</view>
</view>
<view style="height:200rpx"></view>
</view>
</u-popup>
</template>
<script>
import { $EventBus } from "../../utils/EventBus";
export default{
data(){
return{
showShopCar:false,//是否弹出购物车列表
show:true,
allchecked:true,
// checked:true,
goods:[],//购物车商品信息
}
},
created() {
// this.getallNum();
},
mounted() {
this.goods = uni.getStorageSync('shopCarInfo')||[];
$EventBus.$on('updateCar',()=> {
this.goods=uni.getStorageSync('shopCarInfo')||[];
});
},
methods:{
// // 获取总数
// getallNum(arrA) {
// let shopCarInfo = uni.getStorageSync('shopCarInfo');
// let shopCarInfoAdd=[]
// if(shopCarInfo){
// let ids = shopCarInfo.map(v=>v.goodId);
// console.log(ids,444)
// shopCarInfo.forEach((item)=>{
// arrA.forEach((preItem,index)=>{
// console.log(ids.includes(preItem.goodId),1234567)
// let ind=ids.indexOf(preItem.goodId);
// if(ind>-1){
// let num = 0;
// for(let i=0; i<item.rules.length; i++){
// let it = item.rules[i];
// for(let r=0; r<preItem.rules.length; r++){
// let ry = preItem.rules[r];
// if(ry.specId==it.specId && ry.ruleId==it.ruleId){
// num+=1;
// }
// }
// }
// if(num==item.rules.length){
// item.num+=1
// }else{
// shopCarInfoAdd.push(preItem)
// }
// }else{
// shopCarInfoAdd.push(preItem);
// arrA.splice(index,1)
// }
// });
// })
// }else{
// shopCarInfo=arrA
// }
// shopCarInfo = [...shopCarInfo,...shopCarInfoAdd];
// uni.setStorageSync('shopCarInfo',shopCarInfo)
// this.goods=uni.getStorageSync('shopCarInfo');
// },
clearCar() {
uni.removeStorageSync('shopCarInfo');
$EventBus.$emit('updateCar');
},
goshopping(){
uni.navigateTo({
url:'../contact/contact'
})
},
change(e){
console.log(e)
},
selected(item){
item.flag=!item.flag
if(!item.flag){
this.allchecked=false
}else{
const a=this.goods.filter((item)=>{
return item.flag==true
})
if(a){
this.allchecked=true
}else{
this.allchecked=false
}
}
uni.setStorageSync('shopCarInfo',this.goods);
},
selectgoods(){
this.allchecked=!this.allchecked
if(this.allchecked){
this.goods.map(item=>{
item.flag=true
})
}else{
this.goods.map(item=>{
item.flag=false
})
}
uni.setStorageSync('shopCarInfo',this.goods);
},
reduce(item){
let num=item.num
if(num>1){
num-=1
}else if(num=1){
uni.showToast({
title:"该宝贝不能减少了哟~"
})
return;
}
item.num=num
uni.setStorageSync('shopCarInfo',this.goods);
},
add(item){
let num =item.num
item.num=num+1
uni.setStorageSync('shopCarInfo',this.goods);
}
},
computed:{
totalNum(){
let totalNum = 0;
this.goods.map(item => {
item.flag ? totalNum += item.num : totalNum += 0
})
return totalNum
},
totalPrice() {
let totalPrice = 0;
this.goods.map(item => {
item.flag ? totalPrice += item.num * item.discount : totalPrice += 0
})
return totalPrice
}
}
}
</script>
<style lang="scss">
.shop-car {
display: flex;
flex-direction: column;
height: 40vh;
.header{
height: 100rpx;
display: flex;
border-bottom:1rpx solid #ccc;
.left{
flex: 1;
display: flex;
align-items: center;
padding-left: 40rpx;
}
.right{
flex: 1;
display: flex;
align-items: center;
justify-content: right;
padding-right: 40rpx;
}
}
.container{
flex: 1;
overflow: auto;
}
}
.goods{
line-height: 80rpx;
background-color: #FFFFFF;
&-detail{
display: flex;
padding: 30rpx 15rpx 30rpx 30rpx;
background-color: #fff;
justify-content: space-between;
border-bottom: 5rpx solid #F1F1F1;
align-items: center;
.detail-left{
display: flex;
.goods-left{
display: flex;
align-items: center;
}
}
.size{
display: flex;
justify-content: space-around;
flex-direction: column;
margin-left: 30rpx;
.goods-price{
font-size: 24rpx;
color: #F44545;
}
}
.detail-right{
text{
width: 40rpx;
line-height: 40rpx;
text-align: center;
display: inline-block;
margin-right: 10rpx;
color:#000000;
}
.add {
color: #FFFFFF;
border-radius: 40rpx;
margin-right: 20rpx;
background:#006ECF;
}
.subtract{
border:1rpx solid #006ECF;
border-radius: 40rpx;
color:red;
}
}
}
}
.empty{
position: relative;
top: 220rpx;
text-align: center;
display: flex;
align-items: center;
flex-direction: column;
&-text{
color: #808080;
margin-bottom: 50rpx;
}
&-button{
width: 300rpx;
height: 90rpx;
color:orange;
border: 1rpx solid orange;
text-align: center;
line-height: 90rpx;
border-radius: 48rpx;
}
}
.end{
width: 100%;
height: 90rpx;
background-color:#fff;
position: fixed;
bottom: 100rpx;
left: 0;
display: flex;
align-items: center;
&-left{
width: 70%;
display: flex;
justify-content: space-between;
padding: 0 30rpx;
.end-flex{
display: flex;
align-items: center;
}
.car-img{
width:40rpx;
height: 48rpx;
display: inline-block;
background: #006ECF;
}
}
&-right{
width: 30%;
line-height: 90rpx;
background-color: #006ECF;
text-align: center;
color: #fff;
}
}
</style>
<template> <template>
<!-- Tab --> <!-- Tab -->
<u-tabbar v-model="selectedTabbar" :border="false" inactive-color="#000000" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch"> <u-tabbar zIndex="10075" v-model="selectedTabbar" :border="false" inactive-color="#000000" active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch">
<u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item> <u-tabbar-item v-for="(item,index) in list" :key="item.text" :text="item.text" :icon="selectedTabbar==index?item.activeIcon:item.icon"></u-tabbar-item>
</u-tabbar> </u-tabbar>
</template> </template>
......
import App from './App' import App from './App'
import uView from 'uview-ui';
Vue.use(uView);
//引入vuex //引入vuex
import store from './store' import store from './store'
import utils from './utils/utils' import utils from './utils/utils'
Vue.prototype.$utils = utils
// console.log(Vue.$u,22) // console.log(Vue.$u,22)
// 需要在Vue.use(uView)之后执行 // 需要在Vue.use(uView)之后执行
// #ifndef VUE3 // #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
import uView from 'uview-ui';
Vue.use(uView);
Vue.prototype.$utils = utils
Vue.config.productionTip = false Vue.config.productionTip = false
App.mpType = 'app' App.mpType = 'app'
const app = new Vue({ const app = new Vue({
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<script> <script>
import config from '../../static/config/index.js' import config from '../../static/config/index.js'
import Order from '../../request/order/index' import Order from '../../request/order/index'
import User from '@/request/user'
export default { export default {
data() { data() {
return { return {
...@@ -26,88 +27,24 @@ ...@@ -26,88 +27,24 @@
// let curRoute = routes[routes.length - 1].route //获取当前页面路由 // let curRoute = routes[routes.length - 1].route //获取当前页面路由
//   let curParam = routes[routes.length - 1].options; //   let curParam = routes[routes.length - 1].options;
//  console.log(curParam) //  console.log(curParam)
let Authorization=uni.getStorageSync(`Authorization`);
let userInfo=uni.getStorageSync(`userInfo`);
let user=uni.getStorageSync(`currentUser`); if(Authorization){ //
if(user){ // if(userInfo){
user=await JSON.parse(user); this.$store.commit('setUserInfo',userInfo);
if(user.realName){ //有说明授权登陆过
this.checkSession();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
}else{
uni.clearStorageSync();
uni.reLaunch({
url:'/pages/menu/menu'
})
} }
},
methods: {
// 登录
login(){
this.$utils.uniLogin().then(async user => {
this.$store.commit('setUserInfo',user);
if(!user.realName){
uni.reLaunch({ uni.reLaunch({
url:'/pages/menu/menu' url:'/pages/menu/menu'
}) })
}else{ }else{
if(this.id!=''){//二维码参数 uni.removeStorageSync('Authorization');
this.valiFrequency(); uni.removeStorageSync('userInfo');
}else{
uni.reLaunch({ uni.reLaunch({
url:'/pages/menu/menu' url:'/pages/menu/menu'
}) })
} }
}
}).catch((err)=>{
uni.showToast({
icon:'none',
title:'登录失败'
})
});
},
// 校验
async valiFrequency() {//去订单查看是否有此订单
let order=await Order.valiFrequency(this.id);
if(!order){
//无此订单
// uni.navigateTo({
// url:`/pages/detail/detail?id=${this.id}`
// })
}else{
// uni.navigateTo({
// url:`/pages/detail/detail?id=${this.id}`
// });
//是订单跳转到详情页或者其他相关页面
}
}, },
// sessionkey校验登陆状态 methods: {
checkSession(){
uni.checkSession({
success:(res)=>{
let user=uni.getStorageSync(`currentUser`);
this.$store.commit('setUserInfo',user);
if(this.id!=''){//二维码参数
this.valiFrequency();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
},
fail:(res)=>{
uni.clearStorageSync();
this.login();
}
});
}
} }
} }
</script> </script>
......
...@@ -188,7 +188,7 @@ ...@@ -188,7 +188,7 @@
"name": "今日特惠2", "name": "今日特惠2",
"goods": [ "goods": [
{ {
"goodId": 100, "goodId": 101,
"name": "冰茶咖啡2", "name": "冰茶咖啡2",
"price": 29.9, "price": 29.9,
"discount": 19.9, "discount": 19.9,
...@@ -345,7 +345,7 @@ ...@@ -345,7 +345,7 @@
"name": "今日特惠3", "name": "今日特惠3",
"goods": [ "goods": [
{ {
"goodId": 100, "goodId": 102,
"name": "冰茶咖啡3", "name": "冰茶咖啡3",
"price": 29.9, "price": 29.9,
"discount": 19.9, "discount": 19.9,
...@@ -502,7 +502,7 @@ ...@@ -502,7 +502,7 @@
"name": "今日特惠4", "name": "今日特惠4",
"goods": [ "goods": [
{ {
"goodId": 100, "goodId": 103,
"name": "冰茶咖啡4", "name": "冰茶咖啡4",
"price": 29.9, "price": 29.9,
"discount": 19.9, "discount": 19.9,
......
...@@ -5,13 +5,14 @@ ...@@ -5,13 +5,14 @@
<view class="login-area"> <view class="login-area">
<view class="avatar"><image :src="'../../static/logo.png'"></image></view> <view class="avatar"><image :src="'../../static/logo.png'"></image></view>
<view class="user-info"> <view class="user-info">
<view class="user-name">HI!小黑山羊</view> <view class="user-name" v-if="userms">HI!{{userms.nickName}}</view>
<view class="user-name" v-else>未登录</view>
<view class="dialog"> <view class="dialog">
<view class="content">希望你今天,明天,天天都开心~</view> <view class="content" v-if="userms">希望你今天,明天,天天都开心~</view>
<view class="arrow">></view> <view class="content" v-if="!userms">请您尽快登录</view>
</view> </view>
</view> </view>
<view></view> <view class="login-btn" v-if="!userms" @click="uniGetUserInfo">立刻登录</view>
</view> </view>
</view> </view>
<view class="order-banner" v-if="buied"> <view class="order-banner" v-if="buied">
...@@ -26,7 +27,7 @@ ...@@ -26,7 +27,7 @@
</view> </view>
</view> </view>
<view class="page-body" > <view class="page-body" >
<!-- <u-button @click="uniGetUserInfo">按钮授权</u-button> -->
<scroll-view class="nav-left" scroll-y :style="{height:`${height-bannerh}px`}" :scroll-top="scrollLeftTop" scroll-with-animation> <scroll-view class="nav-left" scroll-y :style="{height:`${height-bannerh}px`}" :scroll-top="scrollLeftTop" scroll-with-animation>
<view class="nav-left-item" @click="categoryClickMain(index)" :key="index" :class="index == categoryActive ? 'active' : ''" v-for="(item, index) in classifyData"> <view class="nav-left-item" @click="categoryClickMain(index)" :key="index" :class="index == categoryActive ? 'active' : ''" v-for="(item, index) in classifyData">
{{ item.name }} {{ item.name }}
...@@ -44,8 +45,8 @@ ...@@ -44,8 +45,8 @@
> >
<view v-for="(category, index) in classifyData" :key="index" class="box"> <view v-for="(category, index) in classifyData" :key="index" class="box">
<view class="right-title">{{category.name}}</view> <view class="right-title">{{category.name}}</view>
<view class="nav-right-item" v-for="(item, i) in category.goods" :key="item.goodId" @click="cart(item.name)"> <view class="nav-right-item" v-for="(item, i) in category.goods" :key="item.goodsId" @click="cart(item.name)">
<image class="thumbnail" :src="'../../static/logo.png'" /> <image class="thumbnail" :src="item.pics.thumbnail" />
<view class="info"> <view class="info">
<view class="goods-name">{{ item.name }}</view> <view class="goods-name">{{ item.name }}</view>
<view class="tags"> <view class="tags">
...@@ -53,7 +54,7 @@ ...@@ -53,7 +54,7 @@
</view> </view>
<view class="dis-box"> <view class="dis-box">
<view class="dis">{{item.desc}}</view> <view class="dis">{{item.desc}}</view>
<view class="add-btn">+</view> <view class="add-btn" @click="getallNum(item)">+</view>
</view> </view>
<view class="mon"> <view class="mon">
<view class="discount">{{item.discount}}</view> <view class="discount">{{item.discount}}</view>
...@@ -63,83 +64,127 @@ ...@@ -63,83 +64,127 @@
</view> </view>
</view> </view>
</scroll-view> </scroll-view>
<shopCar></shopCar>
<tabBar :selectedTabbar="selectedTabbar"></tabBar> <tabBar :selectedTabbar="selectedTabbar"></tabBar>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import menuInfo from './menu.json' import User from '@/request/user'
import ShopCar from '../../components/shopCar/shopCar.vue'
import Utils from '@/utils/utils'
import Menu from '@/request/menu'
export default { export default {
data() { data() {
return { return {
buied:true,//是否已经下单产生取单码 menuINfo:{},
orderBannerh:0,//取单码区域的高度 buied: true,
bannerh:0,//头部banner区域的高度 orderBannerh: 0,
name: 'wkiwi', bannerh: 0,
name: "wkiwi",
height: 0, height: 0,
categoryActive: 0, categoryActive: 0,
scrollTop: 0, scrollTop: 0,
scrollLeftTop: 0, scrollLeftTop: 0,
// scrollHeight: 0, // scrollHeight: 0,
classifyData: [], classifyData: [],
arr: [0, 584, 1168, 1752, 2336, 2805, 3274, 3858, 4442, 4911, 5380, 5734, 6203, 6672, 7017], //初始值,后边计算会根据手机适配覆盖 arr: [0, 584, 1168, 1752, 2336, 2805, 3274, 3858, 4442, 4911, 5380, 5734, 6203, 6672, 7017],
leftItemHeight: 51, //49行会计算出新值进行覆盖 leftItemHeight: 51,
navLeftHeight: 0, //左边scroll-view 内层nav的总高度 navLeftHeight: 0,
diff: 0, //左边scroll-view 内层nav的总高度与视口之差 diff: 0,
tabBarHeight: 50, //如果此页面为Tab页面,自己改变高度值,,一般tab高度为51 tabBarHeight: 50,
selectedTabbar: 0, //选中的tab
selectedTabbar:0,//选中的tab };
},
computed: {
userms() {
let res = uni.getStorageSync("userInfo").userInfo;
return res;
} }
}, },
created() { created() {
this.menuINfo = uni.getMenuButtonBoundingClientRect();
//如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中 //如果你的分类数据为后台异步获取请 将下方代码放置你的数据回调中
// this.$nextTick(()=>{ // this.$nextTick(()=>{
// this.getHeightList(); // this.getHeightList();
// }) // })
}, },
onLoad: function() { async onShow() {
this.classifyData = menuInfo.categorys; console.log(1243)
// 获取首页菜单数据
await this.getMenuList();
let _this = this; let _this = this;
uni.createSelectorQuery() uni.createSelectorQuery()
.select('.menu-banner') .select(".menu-banner")
.boundingClientRect(data => { .boundingClientRect(data => {
_this.bannerh = data.height; _this.bannerh = data.height;
}).exec(); }).exec();
if(this.buied){ if (this.buied) {
uni.createSelectorQuery() uni.createSelectorQuery()
.select('.order-banner') .select(".order-banner")
.boundingClientRect(data => { .boundingClientRect(data => {
_this.orderBannerh = data.height; _this.orderBannerh = data.height;
_this.height = uni.getSystemInfoSync().windowHeight - _this.tabBarHeight-_this.orderBannerh; _this.height = uni.getSystemInfoSync().windowHeight - _this.tabBarHeight - _this.orderBannerh;
}).exec(); }).exec();
}else{ }
else {
this.height = uni.getSystemInfoSync().windowHeight - this.tabBarHeight; this.height = uni.getSystemInfoSync().windowHeight - this.tabBarHeight;
} }
this.getHeightList();
},
onLoad: function () {
}, },
onReady() { onReady() {
this.getHeightList();
}, },
methods: { methods: {
// 获取用户授权登录
uniGetUserInfo() { uniGetUserInfo() {
this.$utils.uniGetUserInfo() User.uniGetUserInfo();
},
async getMenuList() {
let res = await Menu.getMenuList();
if(res.data.code ==200){
res.data.data = JSON.parse(JSON.stringify(res.data.data));
console.log(res.data.data,87654567)
this.$store.commit('setMenuAllInfo',res.data.data);
this.classifyData = res.data.data.categorys;
}
},
// 加入购物车数据
getallNum(item) {
console.log(this.classifyData,998877)
console.log(item,333)
let reItem =[
{
goodsId: item.goodsId,
name: item.name,
price: item.price,
discount: item.discount,
flag:true,
thumbnail:'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
num:1,
rules:item.skus[0].rules
}
]
Utils.getallNum(reItem);
}, },
getHeightList() { getHeightList() {
let _this = this; let _this = this;
let selectorQuery = uni.createSelectorQuery(); let selectorQuery = uni.createSelectorQuery();
selectorQuery.selectAll('.nav-left-item').boundingClientRect(function(rects) { selectorQuery.selectAll(".nav-left-item").boundingClientRect(function (rects) {
_this.leftItemHeight = rects[0].height; _this.leftItemHeight = rects[0].height;
_this.navLeftHeight = _this.leftItemHeight * _this.classifyData.length; _this.navLeftHeight = _this.leftItemHeight * _this.classifyData.length;
_this.diff = _this.navLeftHeight; //- _this.height _this.diff = _this.navLeftHeight; //- _this.height
}); });
selectorQuery selectorQuery
.selectAll('.box') .selectAll(".box")
.boundingClientRect(function(rects) { .boundingClientRect(function (rects) {
let arr = [0]; let arr = [0];
let top = 0; let top = 0;
rects.forEach(function(rect) { rects.forEach(function (rect) {
// rect.id // 节点的ID // rect.id // 节点的ID
// rect.dataset // 节点的dataset // rect.dataset // 节点的dataset
// rect.left // 节点的左边界坐标 // rect.left // 节点的左边界坐标
...@@ -161,7 +206,7 @@ import menuInfo from './menu.json' ...@@ -161,7 +206,7 @@ import menuInfo from './menu.json'
if (this.timeoutId) { if (this.timeoutId) {
clearTimeout(this.timeoutId); clearTimeout(this.timeoutId);
} }
this.timeoutId = setTimeout(function() { this.timeoutId = setTimeout(function () {
//节流 //节流
_this.scrollHeight = e.detail.scrollTop + 1 + _this.height / 2; _this.scrollHeight = e.detail.scrollTop + 1 + _this.height / 2;
//+1不要删除,解决最后一项某种情况下翻到底部,左边按钮并不会切换至最后一个 //+1不要删除,解决最后一项某种情况下翻到底部,左边按钮并不会切换至最后一个
...@@ -183,14 +228,15 @@ import menuInfo from './menu.json' ...@@ -183,14 +228,15 @@ import menuInfo from './menu.json'
this.categoryActive = index; this.categoryActive = index;
this.scrollTop == this.arr[index] ? (this.scrollTop = this.scrollTop + 1) : (this.scrollTop = this.arr[index]); //防止两次相等造成点击不触发滚动时间 this.scrollTop == this.arr[index] ? (this.scrollTop = this.scrollTop + 1) : (this.scrollTop = this.arr[index]); //防止两次相等造成点击不触发滚动时间
}, },
cart: function(text) { cart: function (text) {
uni.showToast({ uni.showToast({
title: text, title: text,
icon: 'none' icon: "none"
}); });
} }
} },
} components: { ShopCar }
}
</script> </script>
<style lang="scss"> <style lang="scss">
...@@ -261,7 +307,18 @@ import menuInfo from './menu.json' ...@@ -261,7 +307,18 @@ import menuInfo from './menu.json'
} }
} }
} }
.login-btn{
width: 114rpx;
height: 48rpx;
background: #006ECF;
border-radius: 4rpx;
font-size: 20rpx;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #FFFFFF;
line-height: 48rpx;
text-align: center;
}
} }
} }
......
...@@ -29,15 +29,12 @@ uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做 ...@@ -29,15 +29,12 @@ uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做
title: '加载中', title: '加载中',
mask: true, mask: true,
}); });
let user = uni.getStorageSync(`currentUser`); let Authorization = uni.getStorageSync(`Authorization`);
let token = undefined; if (Authorization) {
if(user){ config.header.Authorization = Authorization;
token = JSON.parse(user).sessionToken;
if (token){
config.header.token = token;
} }
} console.log(config,4444)
if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求 if (!Authorization) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
// return Promise.reject(config); // return Promise.reject(config);
} }
return config return config
......
export default { export default {
// 获取菜单列表 // 获取菜单列表
getMenuList(id) { getMenuList(id) {
uni.$u.http.get('/erer/erer',{ return uni.$u.http.get('/weixin/infoByShop', {
params:{ params:{
shopId:"4"
} }
}).then(res => { }).then(res => {
return res;
}).catch(err => { }).catch(err => {
}) })
......
import Store from '@/store'
export default{
getLocation() {
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log(res, 'res')
var params = {
lat: res.latitude,
lng: res.longitude
}
// getAddress(params).then(res => {
// console.log(res, 'aaa')
// })
}
})
},
uniLogin(res) {
uni.login({
provider: 'weixin',
success: function (data) {
// 传给后台接口所需登录数据
uni.$u.http.post('/weixin/login', {
code: data.code,
source: 3, //默认是3,扫码进来是2
iv: res.iv,
encryptedData: res.encryptedData
}).then((response) => {
if (response.statusCode == 200 && response.data && response.data.code==200) {
console.log(response.data.token,54443)
uni.setStorage({key:'Authorization',data:response.data.token});
Store.commit('setAuthorization', response.data.token);
uni.showToast({
title:'登录成功'
});
}
}).catch((err) => {
uni.showToast({
title: err.msg
});
})
}
})
},
async uniGetUserInfo(e) {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息
lang: "zh_CN",
desc: '用于完善用户信息',
success: res => {
uni.setStorage({key:'userInfo', data:res})
Store.commit("setUserInfo",res)
this.uniLogin(res);
}
})
},
getLocation() {
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log(res, 'res')
var params = {
lat: res.latitude,
lng: res.longitude
}
getAddress(params).then(res => {
console.log(res, 'aaa')
})
}
})
},
}
\ No newline at end of file
const getters = {
userInfo: state => state.user.userInfo.userInfo,
nickName: state => state.user.userInfo.userInfo.nickName,
Authorization: state => state.user.Authorization,
menuAllInfo: state => state.menu.menuAllInfo,
}
export default getters
\ No newline at end of file
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import user from './modules/user'
import menu from './modules/menu'
import getters from './getters'
Vue.use(Vuex) Vue.use(Vuex)
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: {
user,
menu
},
state: { state: {
list: [ list: [
{ {
...@@ -25,24 +32,17 @@ const store = new Vuex.Store({ ...@@ -25,24 +32,17 @@ const store = new Vuex.Store({
text: '我的' text: '我的'
} }
], ],
userInfo:{},//授权信息
authorization:false,//是否授权
orderId:''//外部扫码进入的商品id orderId:''//外部扫码进入的商品id
}, },
mutations: { mutations: {
// 设置是否授权
setAuthorization(state,data){
state.authorization=data;
},
// 设置用户信息
setUserInfo(state,userInfo){
state.userInfo=userInfo;
},
// 设置扫码进入的商品id // 设置扫码进入的商品id
setOrderId(state, orderId) { setOrderId(state, orderId) {
state.orderId = orderId; state.orderId = orderId;
} }
}, },
getters,
actions: {} actions: {}
}) })
export default store export default store
\ No newline at end of file
const menu = {
state: {
menuAllInfo: null, //菜单信息
},
mutations: {
// 设置用户菜单信息
setMenuAllInfo(state, menuAllInfo) {
state.menuAllInfo = menuAllInfo;
},
},
actions: {
}
}
export default menu
const user = {
state: {
userInfo: null, //授权信息
Authorization: null, //是否授权
},
mutations: {
// 设置是否授权
setAuthorization(state, data) {
console.log(data,665)
state.Authorization = data;
},
// 设置用户信息
setUserInfo(state, userInfo) {
state.userInfo = userInfo;
},
},
actions: {
}
}
export default user
import Vue from 'vue'
export const $EventBus = new Vue();
\ No newline at end of file
import Config from '../static/config/index.js'; import Config from '../static/config/index.js';
import WXBizDataCrypt from "./WXBizDataCrypt.js"; import WXBizDataCrypt from "./WXBizDataCrypt.js";
uni.getLocation({ import {$EventBus} from './EventBus'
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
success: function (res) {
console.log(res, 'res')
var params = {
lat: res.latitude,
lng: res.longitude
}
// getAddress(params).then(res => {
// console.log(res, 'aaa')
// })
}
})
export default{ export default{
uniLogin() { getallNum(arrA) {
uni.login({ let arrA1 = [{
provider: 'weixin', "goodsId": 100,
success: function (loginRes) { "name": "冰茶咖啡",
console.log(loginRes) "price": 29.9,
"discount": 19.9,
}}) flag: true,
thumbnail: 'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
num: 1,
rules: [{
"specId": 1,
"specName": "温度",
"ruleId": 1,
"ruleName": "常温"
}, },
async uniGetUserInfo(e) { {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息 "specId": 2,
lang: "zh_CN", "specName": "糖度",
desc: '用于完善用户信息', "ruleId": 3,
success: res => { "ruleName": "无糖"
let avatarUrl = res.userInfo.avatarUrl;
let nickName = res.userInfo.nickName;
console.log(res)
this.uniLogin();
} }
}) ]
}, },
getLocation() { {
uni.getLocation({ "goodsId": 101,
type: 'gcj02', //返回可以用于uni.openLocation的经纬度 "name": "冰茶咖啡",
success: function (res) { "price": 29.9,
console.log(res, 'res') "discount": 19.9,
var params = { flag: true,
lat: res.latitude, thumbnail: 'https://img2.baidu.com/it/u=1001625387,3275765924&fm=26&fmt=auto&gp=0.jpg',
lng: res.longitude num: 3,
rules: [{
"specId": 1,
"specName": "温度",
"ruleId": 1,
"ruleName": "常温"
},
{
"specId": 2,
"specName": "糖度",
"ruleId": 3,
"ruleName": "无糖"
} }
getAddress(params).then(res => { ]
console.log(res, 'aaa') }
}) ]
// arrA = []
let shopCarInfo = uni.getStorageSync('shopCarInfo');
let shopCarInfoAdd = []
console.log(shopCarInfo, 55553333)
if (shopCarInfo) {
let ids = shopCarInfo.map(v => v.goodsId);
console.log(ids, 444)
shopCarInfo.forEach((item) => {
arrA.forEach((preItem, index) => {
console.log(ids.includes(preItem.goodsId), 1234567)
let ind = ids.indexOf(preItem.goodsId);
if (ind > -1) {
let num = 0;
for (let i = 0; i < item.rules.length; i++) {
let it = item.rules[i];
for (let r = 0; r < preItem.rules.length; r++) {
let ry = preItem.rules[r];
if (ry.specId == it.specId && ry.ruleId == it.ruleId) {
num += 1;
} }
}
}
if (num == item.rules.length) {
item.num += 1
} else {
shopCarInfoAdd.push(preItem)
}
} else {
shopCarInfoAdd.push(preItem);
arrA.splice(index, 1)
}
});
}) })
} else {
shopCarInfo = arrA
}
shopCarInfo = [...shopCarInfo, ...shopCarInfoAdd];
uni.setStorageSync('shopCarInfo', shopCarInfo);
$EventBus.$emit('updateCar');
// this.goods = uni.getStorageSync('shopCarInfo');
}, },
// 解密手机 // 解密手机
async onGetPhoneNumber(appid,session_key,encryptedData,iv) { async onGetPhoneNumber(appid,session_key,encryptedData,iv) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment