微信小程序快速开发-食堂菜单案例

(1)这是目录结构。
这里写图片描述

(2)只写了一个index页面。

——这个页面的布局分为上下两部分。上面一部分是一个view,里面嵌套了3个view,用来切换tab的。

——下面是内容区域。用了小程序的swiper控件,swiper控件里面放置的是scroll-view控件。这里面设置的高度用的是百分比,这存在一定的问题。不如css3可以混用百分比和数值来的方便,虽然这种方式存在兼容性问题。

——index.wxml。

<view class="recipe_tabs">
  <view class="recipe_tab {{currentTab==0 ? 'recipe_tab_active' : ''}}" data-current="0" bindtap="swipeContent">早餐</view>
  <view class="recipe_tab {{currentTab==1 ? 'recipe_tab_active' : ''}}" data-current="1" bindtap="swipeContent">午餐</view>
  <view class="recipe_tab {{currentTab==2 ? 'recipe_tab_active' : ''}}" data-current="2" bindtap="swipeContent">咖吧</view>
</view>

<swiper current="{{currentTab}}" class="swiper_container" bindchange="swiperChange">
  <swiper-item>
    <scroll-view scroll-y style="height:100%">
      <view class="recipe_cell" wx:for="{{breakfests}}">
        <image class="recipe_img" src="{{item.RECIPE_IMG}}"></image>
        <view class="recipe_name">{{item.RECIPE_NAME}}</view>
      </view>
    </scroll-view>
  </swiper-item>
  <swiper-item>
    <scroll-view scroll-y style="height:100%">
      <view class="recipe_cell" wx:for="{{lunches}}">
        <image class="recipe_img" src="{{item.RECIPE_IMG}}"></image>
        <view class="recipe_name">{{item.RECIPE_NAME}}</view>
      </view>
    </scroll-view>
  </swiper-item>
  <swiper-item>
    <scroll-view scroll-y style="height:100%">
      <view class="recipe_cell" wx:for="{{desserts}}">
        <image class="recipe_img" src="{{item.RECIPE_IMG}}"></image>
        <view class="recipe_name">{{item.RECIPE_NAME}}</view>
      </view>
    </scroll-view>
  </swiper-item>
</swiper>

(3)样式没什么好说的,index.wxss。

/**index.wxss**/
page{
  background-color: #EEEEEE;
  height: 100%;
}

/* recipe_tab */
.recipe_tabs{
  background-color: #FFFFFF;
  height: 7%;
}
.recipe_tab{
  display: inline-block;
  width: 20%;
  height: 80rpx;
  line-height: 80rpx;
  text-align: center;
  margin-left: 10%;
}
.recipe_tab_active{
  color: red;
  font-weight: 700;
  border-bottom: 4rpx solid red;
}
/* content */
.swiper_container{
  height: 93%;
  overflow: hidden;
}
.recipe_cell{
  background-color: #FFFFFF;
  width: 100%;
  padding-bottom: 20rpx;
  margin-top: 14rpx;
}
.recipe_img{
  width: 94%;
  height: 400rpx;
  padding: 3%;
}
.recipe_name{
  padding-left: 3%;
  line-height: 60rpx;
}

/* app_tab */
.app_tab{
  height: 9%;
  background-color: red;
}

(4)微信小程序除了布局之外,基本都是js的内容。其实小程序的开发和AngularJS十分相似。

——这里面用到了微信自带的util.js文件里的格式化日期,但是和服务器要求的日期格式还是有点差别,所以我们在此基础上再格式化了一下。

//index.js
//获取应用实例
var app = getApp();
var util=require('../../utils/util.js');
Page({
  data: {
    // 初始化数据
    breakfests:[],
    lunches:[],
    desserts:[],
    currentTab:0,
    currentDate:''
  },
  // 点击切换
  swipeContent:function(e){
    var _this=this;
    if(this.data.currentTab!=e.target.dataset.current){
      _this.setData({
        currentTab: e.target.dataset.current,
      });
    }
  },
  swiperChange:function(e){
    var _this=this;
    _this.setData({
      currentTab:e.detail.current,
    });
  },

  // 页面加载的时候执行
  onLoad:function(){
    var _this=this;
    // 获取当前日期
    var currD = util.formatTime(new Date());
    _this.setData({
      // 2017/07/14 12:12:12
      currentDate: currD.substr(0, 4) + "-" + currD.substr(5, 2) + "-"+ currD.substr(8, 2),
    });
    // 发送请求
    wx.request({
      url: 'http://xxx',
      method: 'POST',
      data: {
        userId: 'xxx',
        date: this.data.currentDate,
        mealId: 0,
        pageIndex: 1,
        pageSize: 100
      },
      success: function (res) {
        _this.setData({
          breakfests: res.data.data
        });
      }
    });
    // 发送请求
    wx.request({
      url: 'http://xxx',
      method: 'POST',
      data: {
        userId: 'xxx',
        date: this.data.currentDate,
        mealId: 1,
        pageIndex: 1,
        pageSize: 100
      },
      success: function (res) {
        _this.setData({
          lunches: res.data.data
        });
      }
    });
    // 发送请求
    wx.request({
      url: 'http://xxx',
      method: 'POST',
      data: {
        userId: 'xxx',
        date: this.data.currentDate,
        mealId: 2,
        pageIndex: 1,
        pageSize: 100
      },
      success: function (res) {
        _this.setData({
          desserts: res.data.data
        });
      }
    });
  }
})
**微信小程序案例:SSM食堂窗口自助点餐系统** 此资源是一套完整、可二次开发的计算机专业毕业设计项目,致力于解决食堂窗口的自助点餐问题。基于微信小程序平台,采用SSM(Spring + Spring MVC + MyBatis)框架进行开发,确保了系统的稳定性与扩展性。 **一、核心功能** 1. 用户登录与注册:用户通过微信一键授权登录,方便快捷;同时提供邮箱注册选项。 2. 菜单浏览与搜索:用户可查看当前窗口提供的所有菜品,并通过关键词搜索快速定位目标菜品。 3. 点餐与支付:用户将心仪菜品加入购物车,确认无误后在线支付,支持多种支付方式。 4. 个人中心:用户可查看历史订单、收藏菜品等个人信息,方便再次点餐。 5. 后台管理:管理员可对菜品、订单等进行实时监控与管理,确保系统高效运行。 **二、技术亮点** 1. 微信小程序原生开发,充分利用微信生态优势,为用户提供流畅的使用体验。 2. SSM框架整合,分层明确,易于维护与升级。 3. MyBatis作为数据持久层框架,简化数据库操作,提高开发效率。 4. 前后端分离设计,降低耦合度,便于二次开发与定制。 5. 完善的异常处理机制,确保系统稳定运行。 **三、资源包含** 1. 源代码(Java、XML、JavaScript、WXML、WXSS等)。 2. 说明文档(需求分析、系统设计、数据库设计、使用说明等)。 3. 测试数据与演示视频。 此资源旨在帮助计算机专业毕业生快速构建一个高质量的毕业设计项目,同时也为相关开发者提供一个可二次开发的参考模板。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值