2 Star 3 Fork 1

Billy / ShoppingMall 前端

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.vue 3.33 KB
一键复制 编辑 原始数据 按行查看 历史
Billy 提交于 2022-01-22 00:40 . 前端
<script>
import { getConfig, setConfig, getCart,setToken, getToken ,getUserInfo} from "./utils/auth";
import myconfig from "./utils/config";
import request from "./utils/request";
let colors = getConfig();
let nowColor = ''
if(colors){
nowColor = colors.color
}
uni.$ajax = request.request; //挂载全局请求方法
export default {
onLaunch: function () {
let that =this;
uni.login({
provider: 'weixin',
success: function (loginRes) {
console.log(loginRes.code);
that.myrequest('data/api.wxapp/session', {
code:loginRes.code
}).then(res => {
console.log('解密see',res)
setToken(res.data.token.token)
uni.setStorageSync('uid', res.data.id);
uni.setStorageSync('openid1', res.data.openid1);
})
// 获取用户信息
}
});
// #ifdef MP-WEIXIN
uni.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
uni.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo; // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res);
}
}
});
}
}
});
// #endif
uni.getSystemInfo({ // 获取手机状态栏高度
complete: res => {
this.globalData.statusHeight = res.statusBarHeight;
if (res.platform == "ios") {
this.globalData.toBar = 44;
} else if (res.platform == "android") {
this.globalData.toBar = 48;
} else {
this.globalData.toBar = 44;
}
}
}); // 设置默认主题颜色
let config = getConfig();
if (config && config.color !== '') {
//如果存在设置的主题 使用设置的主题
uni.setTabBarStyle({
selectedColor: config.color
});
let tabList = config.tabList;
if (config.tabList) {
for (var i = 0; i < tabList.length; i++) {
let img = tabList[i];
uni.setTabBarItem({
//设置tabBar 首页图标
index: i,
selectedIconPath: img
});
}
}
} else {
//如果不存在主题 使用默认主题
let fristColor = {};
fristColor.color = '#1cbbb4';
fristColor.name = "cyan";
setConfig(fristColor);
uni.setTabBarStyle({
selectedColor: '#1cbbb4'
});
}
/**
* 模拟获取购物车的数量 getCart
*/
let cart = getCart()
let phone = uni.getStorageSync("phone");
let length = ''
if(cart && phone){
length = cart.length
uni.setTabBarBadge({
//给tabBar添加角标
index: 2,
text: String(length)
});
}
},
globalData: {
userInfo: null,
statusHeight: '20', //状态栏高度
toBar: '44', //标题栏高度
newColor: nowColor || '#1cbbb4', //小程序主题颜色
config: myconfig.themeList //主题图标
},
created(){
let uid = uni.getStorageSync("uid");
let phone = uni.getStorageSync("phone");
if(phone){
this.$store.dispatch({
type:'cartleng',
uid:uid
});
}
},
methods: {},
};
</script>
<style>
@import "./app.css";
</style>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/a2674442942/shopping-mall.git
git@gitee.com:a2674442942/shopping-mall.git
a2674442942
shopping-mall
ShoppingMall 前端
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891