基于React和Node.JS的表单录入系统的设计与实现 (4)

请求方法模块的封装

import Taro from '@tarojs/taro'; const baseUrl = 'http://127.0.0.1:9000'; // 请求的地址 export function request(options, isLoading = true) { const { url, data, method, header } = options; isLoading && Taro.showLoading({ title: '加载中' }); return new Promise((resolve, reject) => { Taro.request({ url: baseUrl + url, data: data || {}, method: method || 'GET', header: header || {}, success: res => { resolve(res); }, fail: err => { reject(err); }, complete: () => { isLoading && Taro.hideLoading(); } }); }); }

日期格式的封装

import moment from 'moment'; export const enumerateDaysBetweenDates = function(startDate, endDate) { let daysList = []; let SDate = moment(startDate); let EDate = moment(endDate); let xt; daysList.push(SDate.format('YYYY-MM-DD')); while (SDate.add(1, 'days').isBefore(EDate)) { daysList.push(SDate.format('YYYY-MM-DD')); } daysList.push(EDate.format('YYYY-MM-DD')); return daysList; }; export const getSubTractDate = function(n = -2) { return moment() .subtract(n, 'months') .format('YYYY-MM-DD'); };

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzfpzw.html