Commit 6d7235bc by zhangcheng

授权登录 首页数据

parent c38bcaf5
<template>
<!-- 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>
</template>
......
import App from './App'
import uView from 'uview-ui';
Vue.use(uView);
//引入vuex
import store from './store'
import utils from './utils/utils'
Vue.prototype.$utils = utils
// console.log(Vue.$u,22)
// 需要在Vue.use(uView)之后执行
// #ifndef VUE3
import Vue from 'vue'
import uView from 'uview-ui';
Vue.use(uView);
Vue.prototype.$utils = utils
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
......
......@@ -6,6 +6,7 @@
<script>
import config from '../../static/config/index.js'
import Order from '../../request/order/index'
import User from '@/request/user'
export default {
data() {
return {
......@@ -26,88 +27,24 @@
// let curRoute = routes[routes.length - 1].route //获取当前页面路由
//   let curParam = routes[routes.length - 1].options;
//  console.log(curParam)
let user=uni.getStorageSync(`currentUser`);
if(user){ //
user=await JSON.parse(user);
if(user.realName){ //有说明授权登陆过
this.checkSession();
}else{
uni.reLaunch({
url:'/pages/menu/menu'
})
}
let Authorization=uni.getStorageSync(`Authorization`);
let userInfo=uni.getStorageSync(`userInfo`);
if(Authorization){ //
if(userInfo){
this.$store.commit('setUserInfo',userInfo);
}
uni.reLaunch({
url:'/pages/menu/menu'
})
}else{
uni.clearStorageSync();
uni.reLaunch({
url:'/pages/menu/menu'
})
uni.removeStorageSync('Authorization');
uni.removeStorageSync('userInfo');
uni.reLaunch({
url:'/pages/menu/menu'
})
}
},
methods: {
// 登录
login(){
this.$utils.uniLogin().then(async user => {
this.$store.commit('setUserInfo',user);
if(!user.realName){
uni.reLaunch({
url:'/pages/menu/menu'
})
}else{
if(this.id!=''){//二维码参数
this.valiFrequency();
}else{
uni.reLaunch({
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校验登陆状态
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>
......
......@@ -188,7 +188,7 @@
"name": "今日特惠2",
"goods": [
{
"goodId": 100,
"goodId": 101,
"name": "冰茶咖啡2",
"price": 29.9,
"discount": 19.9,
......@@ -345,7 +345,7 @@
"name": "今日特惠3",
"goods": [
{
"goodId": 100,
"goodId": 102,
"name": "冰茶咖啡3",
"price": 29.9,
"discount": 19.9,
......@@ -502,7 +502,7 @@
"name": "今日特惠4",
"goods": [
{
"goodId": 100,
"goodId": 103,
"name": "冰茶咖啡4",
"price": 29.9,
"discount": 19.9,
......
......@@ -29,15 +29,12 @@ uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做
title: '加载中',
mask: true,
});
let user = uni.getStorageSync(`currentUser`);
let token = undefined;
if(user){
token = JSON.parse(user).sessionToken;
if (token){
config.header.token = token;
}
let Authorization = uni.getStorageSync(`Authorization`);
if (Authorization) {
config.header.Authorization = Authorization;
}
if (!token) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
console.log(config,4444)
if (!Authorization) { // 如果token不存在,return Promise.reject(config) 会取消本次请求
// return Promise.reject(config);
}
return config
......
export default {
// 获取菜单列表
getMenuList(id) {
uni.$u.http.get('/erer/erer',{
return uni.$u.http.get('/weixin/infoByShop', {
params:{
shopId:"4"
}
}).then(res => {
return res;
}).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 Vuex from 'vuex'
import user from './modules/user'
import menu from './modules/menu'
import getters from './getters'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
user,
menu
},
state: {
list: [
{
......@@ -25,24 +32,17 @@ const store = new Vuex.Store({
text: '我的'
}
],
userInfo:{},//授权信息
authorization:false,//是否授权
orderId:''//外部扫码进入的商品id
},
mutations: {
// 设置是否授权
setAuthorization(state,data){
state.authorization=data;
},
// 设置用户信息
setUserInfo(state,userInfo){
state.userInfo=userInfo;
},
// 设置扫码进入的商品id
setOrderId(state, orderId) {
state.orderId = orderId;
}
},
getters,
actions: {}
})
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 WXBizDataCrypt from "./WXBizDataCrypt.js";
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')
// })
}
})
import {$EventBus} from './EventBus'
export default{
uniLogin() {
uni.login({
provider: 'weixin',
success: function (loginRes) {
console.log(loginRes)
}})
},
async uniGetUserInfo(e) {
uni.getUserProfile({ //授权后可以通过uni.getUserProfile得到用户信息
lang: "zh_CN",
desc: '用于完善用户信息',
success: res => {
let avatarUrl = res.userInfo.avatarUrl;
let nickName = res.userInfo.nickName;
console.log(res)
this.uniLogin();
getallNum(arrA) {
let arrA1 = [{
"goodsId": 100,
"name": "冰茶咖啡",
"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": "常温"
},
{
"specId": 2,
"specName": "糖度",
"ruleId": 3,
"ruleName": "无糖"
}
]
},
{
"goodsId": 101,
"name": "冰茶咖啡",
"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: 3,
rules: [{
"specId": 1,
"specName": "温度",
"ruleId": 1,
"ruleName": "常温"
},
{
"specId": 2,
"specName": "糖度",
"ruleId": 3,
"ruleName": "无糖"
}
]
}
})
},
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')
})
}
})
]
// 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) {
......
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