一、首页布局

pages.json的代码如下

{"pages": [{"path": "pages/main/main","style": {"navigationBarTitleText": "点餐小程序","navigationStyle": "custom",                                "enablePullDownRefresh": true}}],"globalStyle": {"navigationBarTextStyle": "black","navigationBarTitleText": "点餐小程序","navigationBarBackgroundColor": "#F8F8F8","backgroundColor": "#F8F8F8",                "onReachBottomDistance": 50}
}

  • navigationStyle属性值为custom,设置成自定义导航;
  • enablePullDownRefresh属性值为true,表示下拉刷新;
  • onReachBottomDistance属性值未50,表示上拉触底事件触发时距底部的距离,单位为px;  

二、异步数据流对接配合地图定位显示附近的商铺

uni-app已内置Vuex,无须安装即可使用。

1.首先配置Vuex,在根目录创建store->index.js

import Vue from "vue";
import Vuex from "vuex";Vue.use(Vuex);const store=new Vuex.Store({modules:{}
});export default store;

2.将Vuex注册到Vue中,main.js文件中的代码如下:

import Vue from 'vue'
import App from './App'
import store from "./store";Vue.config.productionTip = falseApp.mpType = 'app'const app = new Vue({...App,store
})
app.$mount()

3.封装request()方法:在static->js->utils->request.js文件

function request(url,method="get",data={}){return new Promise(((resolve, reject) => {uni.request({url: url,data: data,method:method.toLocaleUpperCase(),header: {'content-type': 'application/x-www-form-urlencoded'},success: (res) => {resolve(res.data)},fail:(res)=>{reject(res)}});}))
}
export {request
}

4.配置公共的参数,其中存放接口地址。在static->js->conf->config.js文件

let baseApi="https://diancan.glbuys.com/api";
export default {baseApi
}

5.请求服务端数据:根目录创建api文件夹,在该文件夹下创建business/index.js文件。

import config from "../../static/js/conf/config";
import {request} from "../../static/js/utils/request";//显示首页商家列表
export function getShopData(data){return request(config.baseApi+"/v1/business/shop","get",data)
}

6.与Vuex对接:store->business->index.js

import {getShopData} from "../../api/business";
export default {namespaced: true,state:{shops:[]},mutations:{//设置商铺列表["SET_SHOPS"](state,payload){state.shops=payload.shops;}},actions:{//显示首页商家列表getShop(conText,payload){getShopData(payload).then(res=>{if(res.code==200){conText.commit("SET_SHOPS",{shops:res.data});}})}}
}

7.首页是自定义导航,需要先解决iPhoneX“刘海”的兼容性问题

由于这个项目会有多个页面需要自定义导航,因此我们需要一个全局变量去识别是否在iPhoneX中,全局首选Vuex。

store->system->index.js中:

export default {namespaced:true,state:{isIpx:false, //是否iPhoneXplatform:1//平台类型。值:1:微信小程序,2:微信公众号},mutations:{//设置isIpx["SET_IPX"](state,payload){state.isIpx=payload.isIpx;}}
}

注册到Vuex中,store->index.js文件中新增代码如下:

import Vue from "vue";
import Vuex from "vuex";
import system from "./system";
import business from "./business";Vue.use(Vuex);const store=new Vuex.Store({modules:{system,business}
});export default store;

判断是否在iPhoneX中进行,在App.vue中新增代码如下:  

onLaunch: function() {uni.getSystemInfo({success: res=> {if(res.model.indexOf('iPhone X')>-1){this.$store.commit("system/SET_IPX",{isIpx:true});}}});
},

将Vuex的数据对接到pages/main/main.vue中,该文件中的代码如下:

(1)使用getSetting()方法获取用户的当前设置,利用返回值res.authSetting['scope.userLocation']判断用户是否开启地理位置。

如果没有开启,使用openSetting()方法调起客户端小程序设置界面。

用户开启地理位置后,使用getLocation()方法获取地理位置。

注意:为例定位准确,务必使用GCJ-02获取坐标,最后调用getShop()方法获取商品列表数据

(2)如果用户没有关闭地理位置功能。可以直接获取地理位置并获取商铺列表数据。

<template><view class="page"><view class="status_bar"></view><view class="header"><view :class="{'search-header':true,ipx:isIpx}"><view class="search-wrap"><view class="icon"></view><view class="text">请输入商家名或菜品</view></view></view></view><view class="shop-main"><view class="shop-list" v-for="item in shops" :key="item.branch_shop_id"><view class="shop-wrap"><view class="image"><image :src="item.logo"></image></view><view class="shop-info"><view class="shop-name">{{item.branch_shop_name}}</view><view class="distance">{{item.distance}}</view><view class="address">{{item.address}}</view><view class="pack-btn">自提</view></view></view></view></view></view>
</template><script>import {mapState,mapActions} from "vuex";export default {data() {return {}},onLoad() {this.lng=0;//经度this.lat=0;//纬度},onShow(){uni.getSetting({success:(res)=> {//用户没有开启地位位置if(!res.authSetting['scope.userLocation']){uni.showModal({title: '开启获取地理位置',content: '请打开"位置信息"权限,找到附近的店铺',success: (res)=> {if (res.confirm) {//调起客户端小程序设置界面uni.openSetting({success:(res2)=> {//如果用户打开了地理位置if(res2.authSetting['scope.userLocation']){uni.getLocation({type: 'gcj02',success:  (res)=> {this.lng=res.longitude;this.lat=res.latitude;this.getShop({page:1,lng:this.lng,lat:this.lat});}});}}});}}});}}})uni.getLocation({type: 'gcj02',success:  (res)=> {this.lng=res.longitude;this.lat=res.latitude;this.getShop({page:1,lng:this.lng,lat:this.lat});}});},methods: {...mapActions({getShop:"business/getShop"})},computed:{...mapState({isIpx:state=>state.system.isIpx,shops:state=>state.business.shops})},onShareAppMessage(res) {return {title: '点餐小程序',path: '/pages/main/main'}}}
</script><style scoped>.page{width:100%;min-height:100vh;orverflow:hidden;}.header{width:100%;background-color:#eb1625;overflow:hidden;position: fixed;left:0;top:0;z-index:90;}.header .search-header{width:100%;height:170rpx;margin-top:40rpx;padding-bottom:20rpx;display:flex;justify-content: center;align-items: flex-end;}.header .search-header.ipx{height:210rpx;}.header .search-wrap{width:80%;height:52rpx;background-color:rgba(255,255,255,0.9);border-radius: 5px;display: flex;align-items: center;}.header .icon{width:44rpx;height:44rpx;background-image:url("@/static/images/main/search_icon.png");background-size:100%;background-position: center;background-repeat: no-repeat;margin:0 20rpx;}.header .text{color:#999999;font-size:28rpx;}.shop-main{width:100%;margin-top:220rpx;}.shop-main .shop-list{width:100%;border-bottom:1px solid #EFEFEF;box-sizing: border-box;padding:20rpx 0;}.shop-main .shop-list .shop-wrap{width:92%;margin:0 auto;display:flex;}.shop-main .shop-list .shop-wrap .image{width:160rpx;height:160rpx;margin-right:20rpx;}.shop-main .shop-list .shop-wrap .image image{width:100%;height:100%;border-radius: 5px;}.shop-main .shop-list .shop-info{width:72%;clear: both;}.shop-main .shop-list .shop-info .shop-name{width:100%;height:44rpx;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;font-size:32rpx;font-weight: bold;}.shop-main .shop-list .shop-info .distance{font-size:28rpx;margin-top:10rpx;color:#666666}.shop-main .shop-list .shop-info .address{font-size:28rpx;margin-top:10rpx;color:#666666;width:100%;height:44rpx;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;}.shop-main .shop-list .shop-info .pack-btn{padding:10rpx 20rpx;background-color:#eb1625;font-size:28rpx;color:#FFFFFF;display: table;border-radius: 5px;float: right;margin-top:10rpx;}
</style>


注:项目教程来自《uni-app多端跨平台开发从入门到企业级实战》

【仿美团点餐App】—— 首页(一)相关推荐

  1. 【vue】二、vue2仿去哪儿网app——首页开发

    文章目录 二.vue2仿去哪儿网app--首页开发 Ⅰ 页面结构 Ⅱ 开发笔记及注意点 1.公共样式抽取 2.路径 --> 绝对路径 3.用padding-bottom实现固定宽高比 4.保证内 ...

  2. nuxt全栈仿美团官网13——首页下面的格调

    文档:nuxt全栈仿美团官网13--首页下面的格... 链接:http://note.youdao.com/noteshare?id=6b7b36720b665f830357b221a0d28fba& ...

  3. 游戏陪玩源码开发,仿某看书app首页Banner轮播+背景渐变

    在游戏陪玩源码开发时,会设计到很多UI界面设计,其中首页Banner轮播就很重要,最近发现一个比较有意思的效果图,于是想自己操作实践下.效果图如下: 作者实现的效果: 1. 游戏陪玩源码开发,仿某看书 ...

  4. Flutter仿美团应用开发笔记-首页 (1)

    首页篇 Github项目地址:项目地址 上一篇博客讲解了该应用的基础结构,如底部导航栏等.基础结构篇 这篇博客将详细讲解美团首页的界面实现,在下一篇博客实现推荐卡片无限加载,带插入和移除动画的列表,弹 ...

  5. 《iVX 高仿美团APP制作移动端完整项目》01 标题需求分析思路及制作流程

    点击整个专栏查看其它系列文章 (系列文章更新中-):<iVX 高仿美团APP制作移动端完整项目> 项目界面预览: 一.创建项目 首先打开在线编辑器地址:https://editor.ivx ...

  6. 《iVX 高仿美团APP制作移动端完整项目》04 美食页 标题、搜索、商家标题制作

    点击整个专栏查看其它系列文章 (系列文章更新中-):<iVX 高仿美团APP制作移动端完整项目> 项目界面预览: 一.美食页顶部商家页制作 1.1 页面主格调确认 该美食页为首页中美食按钮 ...

  7. 《iVX 高仿美团APP制作移动端完整项目》03 推介信息及推荐商家分析及制作

    点击整个专栏查看其它系列文章 (系列文章更新中-):<iVX 高仿美团APP制作移动端完整项目> 项目界面预览: 一.推荐信息制作 推荐信息与之前的标题下推荐信息制作类似: 此时依旧创建一 ...

  8. 《iVX 高仿美团APP制作移动端完整项目》02 搜索、搜索提示及类别需求分析思路及制作流程

    点击整个专栏查看其它系列文章 (系列文章更新中-):<iVX 高仿美团APP制作移动端完整项目> 项目界面预览: 一.搜索制作 在上一节中我们完成了标题头的制作,接下来我们查看如何制作搜索 ...

  9. Android 仿美团选择城市、微信通讯录、饿了么点餐列表的导航悬停分组索引列表

    SuspensionIndexBar 项目地址:mcxtzhang/SuspensionIndexBar 简介:快速实现分组悬停.右侧索引导航联动 列表. 如 美团选择城市界面,微信通讯录界面.饿了么 ...

  10. 视频教程-Web前端开发仿美团/饿了吗移动App之高德地图接口对接案例-JavaScript

    Web前端开发仿美团/饿了吗移动App之高德地图接口对接案例 互联网编程行业10年开发和授课经验 曾任太极集团,外资企业等一线互联网python高级开发工程师 现任聚焦计算机技术有限公司项目组担任架构 ...

最新文章

  1. 两大电网大手笔投建能源大数据中心,15省都有哪些落地案例?
  2. 关于Vmware workstation虚拟机的网络设置问题
  3. 前端学习(2481):关于接口的调错
  4. pythonmessage用法_请问Mac下如何用python读取iMessage信息?
  5. 深圳大学计算机考研复习资料百度云,深圳大学(专业学位)计算机技术研究生考试科目和考研参考书目...
  6. Tornado之异步authenticated
  7. 那些做Android开发必须知道的ADB命令
  8. spring(12)
  9. Java面试题中高级,java简历技术栈怎么写
  10. 2018年统计用区划代码和城乡划分代码
  11. 注册表--设置文件打开方式
  12. 微信建群怎么建?2个方法,快速学会!
  13. cm11修改wifi_mac地址
  14. 【Android】JNI调用(完整版)
  15. 网页多媒体服务器,大区网页直播间搭建,服务器流媒体全对接服务
  16. 将一个十六进制字符串转换为十进制数值的问题
  17. 微信开发学习笔记01
  18. 神经网络模型结果怎么看,神经网络的数据预处理
  19. Android Studio 单工程、多工程级联依赖下的aar的引用
  20. ipad忘记密码,显示iPad已停用 连接iTunes

热门文章

  1. 免费调用快递鸟物流跟踪轨迹订阅接口技术文档
  2. tp6 thinkswoole 使用极光curl请求时报错
  3. php doctrine 使用,php – Doctrine 2 – 多数据库配置和使用
  4. 惠普计算机工作站,HP 笔记本计算机和移动工作站电池安全召回和更换计划
  5. Linux下邮箱客户端推荐
  6. 商城购物APP——YiGo
  7. 万顿思电商:拼多多推广是如何收费的?
  8. L1-5 不变初心数 (15 分)(C/C++)
  9. WikiOI 1139 观光公交 (NOIP2011) 贪心
  10. 水星怎么设置网速最快_wifi怎样设置网速最快