小程序点餐系统——基本配置(utils)

2021/4/8 20:27:28

本文主要是介绍小程序点餐系统——基本配置(utils),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

文章目录

  • 基本配置(utils)
    • 公共css
    • fetch.js 接口的请求
    • util.js 公共方法

基本配置(utils)

公共css

/* 订单详情部分 */
.order-info{
  background: white;
  margin-top:10px;
}
.order-info-title{
  font-size:12px;
  color: #D1D1D1;
  padding: 12px;
  border-bottom: 1px #E3E3E3 solid
}
/* 清单数量 */
.cart-list-box{
  background:#FFFFFF;
  display:flex;
  font-size:15px;
  border-bottom:1px #E3E3E3 solid;
}
.list-info{
  width:50%;
  padding:5px 15px;
}
.list-info-size{
  font-size:12px;
  color:#B1B1B1;
}
/* 总金额超过20,出现满减 */
.order-cut{
  height:30px;
  padding:5px 15px;
  border-bottom: 1px #E3E3E3 solid;
}
.order-cut-dec{
  background:#F07474;
  font-size:13px;
  color:white;
  padding:2px
}
.order-cut-note{
  margin-left:3px;
  font-size:14px
}
.order-cut-number{
  font-size:14px;
  float:right;
}
/* 总计 */
.order-sum{
  height:30px;
  padding:5px 15px;
  font-size:14px;
}
.order-sum-number{
  font-size:14px;
  float:right;
}
.activity-color{
  color:#FF9C35;
}

fetch.js 接口的请求

第五行要换成你自己服务器的IP地址。如果没有服务器就在本地开启node服务器,用本地的端口

module.exports = function(path, data, method) {
  // 暴露接口
  return new Promise((resolve, reject) => {
    wx.request({
      url: 'http://你自己的服务器ip:8081/api/' + path, //api地址
      // url: 'http://127.0.0.1:8081/api/' + path, //api地址
      method: method, // 请求方法
      data: data, // 参数
      header: {
        'Content-Type': 'json'
      }, // 请求头,默认
      success: resolve,
      fail: function() {
        reject()
        wx.showModal({
          showCancel: false,
          title: '失败'
        })
      }
    })
  })
}

util.js 公共方法

这里只有初始化时间方法

const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

// const formatNumber = n => {
//   n = n.toString()
//   return n[1] ? n : '0' + n
// }

const formatNumber = function(n){
  n = n.toString()
  return n[1] ? n : '0' + n
}
module.exports = {
  formatTime: formatTime
}




这篇关于小程序点餐系统——基本配置(utils)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程