1 Star 2 Fork 1

冯兴/food-mp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
App.vue 2.29 KB
一键复制 编辑 原始数据 按行查看 历史
冯兴 提交于 2021-11-15 12:29 . 初始化项目
<script>
import {getBannerList, getReommendList, getUserInfo, getStoreList} from 'api/home/index.js';
import {
myCouponList
} from 'api/me/index.js';
import {getGoods} from 'api/order/index.js';
import Vue from 'vue';
import {mapActions} from 'vuex';
import {setToken} from 'utils/auth.js';
import {getDistance} from 'utils/index.js';
export default {
onLaunch: function() {
const that = this;
// 轮播图
getBannerList().then(res => {
this.setBannerList({bannerList: res.data});
});
// 商品
getGoods().then(res => {
this.setGoods({goodsList: res.data});
});
// 门店列表
getStoreList().then(res => {
let store = res.data[0];
store.status = !!Number(store.status);
uni.getLocation({
type: 'wgs84',
success: function (res) {
let distance = getDistance(res.latitude, res.longitude, store.latitude, store.longitude)
that.setStore({store: Object.assign(store, {distance})});
},
fail() {
that.setStore({store: Object.assign(store, {distance: '9999km'})});
}
});
});
uni.getSystemInfo({
success(e) {
Vue.prototype.scrollviewHeilght = e.safeArea.height;
}
});
uni.login({
provider: 'weixin',
success(e) {
let {
code,
errMsg
} = e;
if (errMsg = 'login:ok') {
that.$slLoading('加载中...').then(() => {
// 获取用户信息
getUserInfo(code).then(res => {
const {token, user: userInfo} = res;
if(userInfo) {
setToken(token);
that.setUserInfo({userInfo});
// 获取优惠券
myCouponList().then(res => {
that.setCouponList({couponList: res.rows});
})
// 获取桌子信息
that.setStatusInfo({id: userInfo.id});
}
}).finally(() => {
uni.hideLoading();
})
})
}
}
})
},
onShow: function() {
},
onHide: function() {
},
methods: {
...mapActions(['setBannerList', 'setUserInfo', 'setStore', 'setCategory', 'setGoods', 'setCouponList', 'setStatusInfo'])
}
}
</script>
<style lang="scss">
/*每个页面公共css */
@import "static/css/index.css";
// 引入vant样式
@import "wxcomponents/vant/dist/common/index.wxss";
// 引入iconfont
@import "static/css/iconfont.css";
</style>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/joyfeng/food-mp.git
git@gitee.com:joyfeng/food-mp.git
joyfeng
food-mp
food-mp
master

搜索帮助