From d1339f8180d2879675d151164ffe09b24a3c1196 Mon Sep 17 00:00:00 2001 From: "[caserKing]" <[wkx12138@126.com]> Date: Tue, 11 Aug 2020 16:22:48 +0800 Subject: [PATCH] =?UTF-8?q?c=E7=AB=AF=E9=9B=86=E5=9B=A2=E7=89=88=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 147 +++++++++++++++++++++++++ app.json | 16 +++ app.wxss | 0 config/config.js | 16 +++ pages/ces.js | 66 +++++++++++ pages/ces.json | 3 + pages/ces.wxml | 0 pages/ces.wxss | 1 + pages/ces/ces.js | 66 +++++++++++ pages/ces/ces.json | 3 + pages/ces/ces.wxml | 2 + pages/ces/ces.wxss | 1 + pages/index/index.js | 97 +++++++++++++++++ pages/index/index.json | 3 + pages/index/index.wxml | 33 ++++++ pages/index/index.wxss | 87 +++++++++++++++ pages/location/location.js | 66 +++++++++++ pages/location/location.json | 3 + pages/location/location.wxml | 21 ++++ pages/location/location.wxss | 58 ++++++++++ project.config.json | 45 ++++++++ sitemap.json | 7 ++ utils/HttpBasics.js | 117 ++++++++++++++++++++ utils/util.js | 206 +++++++++++++++++++++++++++++++++++ 24 files changed, 1064 insertions(+) create mode 100644 app.js create mode 100644 app.json create mode 100644 app.wxss create mode 100644 config/config.js create mode 100644 pages/ces.js create mode 100644 pages/ces.json create mode 100644 pages/ces.wxml create mode 100644 pages/ces.wxss create mode 100644 pages/ces/ces.js create mode 100644 pages/ces/ces.json create mode 100644 pages/ces/ces.wxml create mode 100644 pages/ces/ces.wxss create mode 100644 pages/index/index.js create mode 100644 pages/index/index.json create mode 100644 pages/index/index.wxml create mode 100644 pages/index/index.wxss create mode 100644 pages/location/location.js create mode 100644 pages/location/location.json create mode 100644 pages/location/location.wxml create mode 100644 pages/location/location.wxss create mode 100644 project.config.json create mode 100644 sitemap.json create mode 100644 utils/HttpBasics.js create mode 100644 utils/util.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..a2655fc --- /dev/null +++ b/app.js @@ -0,0 +1,147 @@ +//app.js +const config = require("./config/config.js"); +const Http = require("./utils/HttpBasics"); +App({ + onLaunch: function (options) { + var that = this; + // 展示本地存储能力 + var logs = wx.getStorageSync('logs') || [] + logs.unshift(Date.now()) + wx.setStorageSync('logs', logs) + + /** + * 小程序版本更新 + */ + that.autoUpdate(); + + /** + * 用户登录 + */ + that.userLogin(options.scene); + + + + }, + //登陆 + userLogin(sceneAddress) { + let that = this; + // 登录 + wx.login({ + success: ({ + code + }) => { + let usrdata = { + appId: config.weapp.AppId, + code: code, + sceneAddress: sceneAddress + } + Http.post({ + url: config.api.login, + data: usrdata + }) + .then(res => { + wx.setStorageSync('openId',res.data.openId) + if (res.data && res.data.score) { + if (res.data.score != 0) { + that.globalData.score = res.data.score; + } + } + Http.setToken(res.data.token); + that.globalData.token = res.data.token; + console.log(that.globalData.token) + + if (that.tokenCallback) { + that.tokenCallback(res.data.token); + } + }) + .catch(err => { + console.log(err) + wx.showModal({ + title: '提示', + showCancel: false, + content: '登录失败,请重新尝试', + success: function(res) { + if (res.cancel) { + //点击取消,默认隐藏弹框 + } else { + //点击确定 + wx.reLaunch({ + url: '/pages/index/index', + }) + } + } + }) + }) + } + }) + }, + autoUpdate: function() { + let that = this; + if (wx.canIUse('getUpdateManager')) { + const updateManager = wx.getUpdateManager() + // 1. 检查小程序是否有新版本发布 + updateManager.onCheckForUpdate(function(res) { + // 请求完新版本信息的回调 + if (res.hasUpdate) { + // 检测到新版本,需要更新,给出提示 + wx.showModal({ + title: '更新提示', + content: '检测到新版本,是否下载新版本并重启小程序?', + success: function (res) { + if (res.confirm) { + //2. 用户确定下载更新小程序,小程序下载及更新静默进行 + that.downLoadAndUpdate(updateManager) + } else if (res.cancel) { + //用户点击取消按钮的处理,如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了 + wx.showModal({ + title: '温馨提示~', + content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问的哦~', + showCancel: false,//隐藏取消按钮 + confirmText: "确定更新",//只保留确定更新按钮 + success: function (res) { + if (res.confirm) { + //下载新版本,并重新应用 + that.downLoadAndUpdate(updateManager) + } + } + }) + } + } + }) + } + }) + } else { + // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示 + wx.showModal({ + title: '提示', + content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。' + }) + } + }, + /** + * 下载小程序新版本并重启应用 + */ + downLoadAndUpdate: function(updateManager) { + let that = this + wx.showLoading(); + //静默下载更新小程序新版本 + updateManager.onUpdateReady(function() { + wx.hideLoading() + //新的版本已经下载好,调用 applyUpdate 应用新版本并重启 + updateManager.applyUpdate() + }) + updateManager.onUpdateFailed(function() { + // 新的版本下载失败 + wx.showModal({ + title: '已经有新版本了哟~', + content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~', + }) + }) + }, + globalData: { + userInfo: null, + score: 0, + token: 0, + + } +}) \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..9af6c62 --- /dev/null +++ b/app.json @@ -0,0 +1,16 @@ +{ + "pages": [ + "pages/index/index", + "pages/location/location", + "pages/ces", + "pages/ces/ces" + ], + "window": { + "backgroundTextStyle": "light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "集团版", + "navigationBarTextStyle": "black" + }, + "style": "v2", + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..e69de29 diff --git a/config/config.js b/config/config.js new file mode 100644 index 0000000..154a41c --- /dev/null +++ b/config/config.js @@ -0,0 +1,16 @@ +var config = { + weapp: { + AppId: "wx649b3be73c1afe47", + }, + + url: 'https://ctest.malls.iformall.com/C/api', + // url: 'https://ctest.malls.iformall.com/C/api', + api: { + /** + * 接口用途:login + */ + login: "/user/login", + }, +}; + +module.exports = config; \ No newline at end of file diff --git a/pages/ces.js b/pages/ces.js new file mode 100644 index 0000000..5f62c13 --- /dev/null +++ b/pages/ces.js @@ -0,0 +1,66 @@ +// pages/ces.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/ces.json b/pages/ces.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/ces.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/ces.wxml b/pages/ces.wxml new file mode 100644 index 0000000..e69de29 diff --git a/pages/ces.wxss b/pages/ces.wxss new file mode 100644 index 0000000..0ea3e18 --- /dev/null +++ b/pages/ces.wxss @@ -0,0 +1 @@ +/* pages/ces.wxss */ \ No newline at end of file diff --git a/pages/ces/ces.js b/pages/ces/ces.js new file mode 100644 index 0000000..02a2c6b --- /dev/null +++ b/pages/ces/ces.js @@ -0,0 +1,66 @@ +// pages/ces/ces.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/ces/ces.json b/pages/ces/ces.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/ces/ces.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/ces/ces.wxml b/pages/ces/ces.wxml new file mode 100644 index 0000000..f274d26 --- /dev/null +++ b/pages/ces/ces.wxml @@ -0,0 +1,2 @@ + +pages/ces/ces.wxml diff --git a/pages/ces/ces.wxss b/pages/ces/ces.wxss new file mode 100644 index 0000000..1af376b --- /dev/null +++ b/pages/ces/ces.wxss @@ -0,0 +1 @@ +/* pages/ces/ces.wxss */ \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..3d90968 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,97 @@ +// pages/index/index.js +const Http = require("../../utils/HttpBasics"); +const config = require("../../config/config.js"); + +Page({ + + /** + * 跳转到其他小程序 + * 接受唯一参数 appId + * */ + goPlaza(event) { + let appid = event.currentTarget.dataset.appid + wx.navigateToMiniProgram({ + appId: appid, + success(res) { + // 打开成功 + } + }) + }, + + + /** + * 页面的初始数据 + */ + data: { + plazaAppid: 'wx8e5cab05e850bc91' + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + //测试发送请求 + // this.getInfo(); + + }, + //获取用户信息 + getInfo() { + Http.post({ + url: config.api.login, + data: { + + } + }).then(res => { + console.log(res) + }) + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..0c9f788 --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1,33 @@ + + + + + + 用户昵称 + 用户等级 + + + {{'我的成长值'}}| + {{"更多成长值"}} + + + + + + + 123 + 456 + + + + + + 欢乐国际购物城 + 广场地址:嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻 + 总面积:6000M² + 车位数:123 + 距您:233M + + + + \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..6b360eb --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,87 @@ +/* pages/index/index.wxss */ + +.Box { + width: 90%; + margin: 0 5%; +} + +.userinfo { + height: 200rpx; + border: 1rpx solid saddlebrown; + position: relative; + margin-top: 60rpx; + border-radius: 10rpx; + margin-bottom: 30rpx; +} + +.userPortrait { + position: absolute; + width: 120rpx; + height: 120rpx; + background-color: darkgoldenrod; + border-radius: 50%; + top: 0; + left: 42%; +} + +.textBox { + margin: 65rpx 20% 0 20%; + width: 60%; + overflow: hidden; +} + +.nameBox{ + overflow: hidden; + display: flex; + justify-content: center; + align-items: center; +} +.name { + float: left; +} +.grade { + margin-left: 10rpx; + float: left; + background-color: rgb(255, 102, 0); + color: #fff; + border-radius: 10rpx; + border: 1rpx solid #000; + padding: 0 10rpx; +} +.grow{ + color: rgb(255, 130, 0); +} +.swiperItem{ + background-color: red; +} +.plazaList{ + margin-top: 30rpx; + height: 320rpx; + border: 1rpx solid #000; + border-radius: 10rpx; +} +.EntranceBox{ + margin: 20rpx; + overflow: hidden +} +.plazaImg{ + float: left; + width: 300rpx; + height: 270rpx; + background-color: aqua; +} +.plazaMessage{ + float: left; + margin-left: 20rpx; +} +.site{ + width: 300rpx; + font-size: 24rpx; + margin-top: 10rpx ; + height: 40prx; + overflow: hidden +} +.area{ + margin-top: 10rpx ; + font-size: 24rpx; +} \ No newline at end of file diff --git a/pages/location/location.js b/pages/location/location.js new file mode 100644 index 0000000..83320af --- /dev/null +++ b/pages/location/location.js @@ -0,0 +1,66 @@ +// pages/location/location.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/location/location.json b/pages/location/location.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/location/location.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/location/location.wxml b/pages/location/location.wxml new file mode 100644 index 0000000..0eaea3d --- /dev/null +++ b/pages/location/location.wxml @@ -0,0 +1,21 @@ + + + + 当前位置 + + 北京市 + GPS定位 + + + + + 城市广场 + + + 欢乐国际城 + 武汉市江夏区佩尔中心 + 1.23Km + + + + \ No newline at end of file diff --git a/pages/location/location.wxss b/pages/location/location.wxss new file mode 100644 index 0000000..65533c5 --- /dev/null +++ b/pages/location/location.wxss @@ -0,0 +1,58 @@ +/* pages/location/location.wxss */ +.Box{ + width: 90%; + margin: 0 5%; +} +.presentSiteBox{ + overflow: hidden; + margin-bottom: 70rpx; +} +.presentText{ + font-size: 24rpx; + color: rgb(153, 153, 153); + overflow: hidden +} +.gpsBox{ + margin-top: 54rpx; + overflow: hidden; + margin-bottom: 20rpx; +} +.city{ + font-size: 40rpx; + float: left +} +.gps{ + float: left; + font-size: 24rpx; + line-height: 60rpx; + color: rgb(153, 153, 153); + margin-left: 40rpx; +} +.siteText{ + font-size: 24rpx; + color: rgb(153, 153, 153); + margin-top: 2rpx; +} +.plazaName{ + margin-top: 60rpx; + font-size: 34rpx; +} +.siteBox{ + margin-bottom: 30rpx; + overflow: hidden +} +.site{ + margin-top: 30rpx; + font-size: 24rpx; + color: rgb(153, 153, 153); + float: left; +} +.distance{ + margin-top: 30rpx; + font-size: 24rpx; + color: rgb(153, 153, 153); + float: right +} +.wire{ + border: 2rpx solid rgb(204, 204, 204) +} \ No newline at end of file diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..848a6b2 --- /dev/null +++ b/project.config.json @@ -0,0 +1,45 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "postcss": true, + "minified": true, + "newFeature": true, + "autoAudits": false, + "coverView": true, + "showShadowRootInWxmlPanel": true, + "scopeDataCheck": false + }, + "compileType": "miniprogram", + "libVersion": "2.12.0", + "appid": "wx649b3be73c1afe47", + "projectname": "C%E7%AB%AF%E9%9B%86%E5%9B%A2%E7%89%88", + "debugOptions": { + "hidedInDevtools": [] + }, + "isGameTourist": false, + "simulatorType": "wechat", + "simulatorPluginLibVersion": {}, + "condition": { + "search": { + "current": -1, + "list": [] + }, + "conversation": { + "current": -1, + "list": [] + }, + "game": { + "currentL": -1, + "list": [] + }, + "miniprogram": { + "current": -1, + "list": [] + } + } +} \ No newline at end of file diff --git a/sitemap.json b/sitemap.json new file mode 100644 index 0000000..ca02add --- /dev/null +++ b/sitemap.json @@ -0,0 +1,7 @@ +{ + "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", + "rules": [{ + "action": "allow", + "page": "*" + }] +} \ No newline at end of file diff --git a/utils/HttpBasics.js b/utils/HttpBasics.js new file mode 100644 index 0000000..6ca5c9f --- /dev/null +++ b/utils/HttpBasics.js @@ -0,0 +1,117 @@ +const config = require("../config/config.js"); +class HttpBasics { + constructor(address) { + if (address) { + this.address = address; + } + } + /** + * 配置 + */ + config = config; + /** + * 请求路径前缀 + */ + address = config.url; + /** + * 请求头 + */ + headers = { + "Content-Type": "application/json;charset=UTF-8", + token: "" + }; + /** + * 设置token + * @param {*} token + */ + setToken(token) { + this.headers.token = token; + } + /** + * 获取数据 + * @param {url,data,headers} param0 + */ + get({ url, data, headers }) { + headers = { ...this.headers, ...headers }; + url = `${this.address}${url}`; + return new Promise((resolve, reject) => { + wx.request({ + url: url, + header: headers, + data: data, + method: "Get", + success: res => { + this.responseMap(res, resolve, reject); + }, + fail: err => { + console.log(err) + if (err.errMsg == 'request:fail timeout') { + err.errMsg = '请求超时,请检查您的网络设置!' + } else if (err.errMsg == 'request:fail'){ + err.errMsg = '未检查到您的网络,请检查您的网络设置!' + } else if (err.errMsg == 'request:fail request connect error') { + err.errMsg = '连接失败' + } + reject(err); + } + }); + }); + } + /** + * 提交数据 + * @param {url,data,headers} param0 + */ + post({ url, data, headers }) { + headers = { ...this.headers, ...headers }; + url = `${this.address}${url}`; + return new Promise((resolve, reject) => { + wx.request({ + url: url, + header: headers, + data: data, + method: "POST", + success: res => { + this.responseMap(res, resolve, reject); + }, + fail: err => { + if (err.errMsg == 'request:fail timeout') { + err.errMsg = '请求超时,请检查您的网络设置!' + } else if (err.errMsg == 'request:fail') { + err.errMsg = '未检查到您的网络,请检查您的网络设置!' + } else if (err.errMsg == 'request:fail request connect error') { + err.errMsg = '连接失败' + } + reject(err); + }, + complete: res => {} + }); + }); + } + /** + * 过滤 请求信息 + * @param {*} res + * @param {*} resolve + * @param {*} reject + */ + responseMap = (res, resolve, reject) => { + // 网络状态码200 + if (res.statusCode == 200) { + // 服务器code 200 成功 + if (res.data.code == 200) { + resolve(res.data); + } else if (res.data.code == 1052) { + wx.reLaunch({ + url: '/pages/index/index' + }) + } else { + reject(res.data); + } + } else { + console.log("请求出错:", res); + reject(res.data); + } + }; + /** 日志 */ + log(url, body, headers) {} +} +module.exports = new HttpBasics(); diff --git a/utils/util.js b/utils/util.js new file mode 100644 index 0000000..1cd01d4 --- /dev/null +++ b/utils/util.js @@ -0,0 +1,206 @@ +var barcode = require("./barcode"); +var qrcode = require("./qrcode"); + +const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} +let imgProxy = extConfig.attr.imgProxy; + +function convertUTCTimeToLocalTime(UTCDateString) { + if (!UTCDateString) { + return '-'; + } + function formatFunc(str) { //格式化显示 + return str > 9 ? str : '0' + str + } + var date2 = new Date(UTCDateString); //这步是关键 + var year = date2.getFullYear(); + var mon = formatFunc(date2.getMonth() + 1); + var day = formatFunc(date2.getDate()); + var hour = date2.getHours(); + var noon = hour >= 12 ? 'PM' : 'AM'; + hour = hour >= 24 ? hour - 24 : hour; + hour = formatFunc(hour); + var min = formatFunc(date2.getMinutes()); + var dateStr = ' ' + hour + ':' + min ; + return dateStr; +} + +function fmtDate(date) { + var dateee = new Date(date).toJSON(); + return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''); +} + + +const formatTime = (date, fmt) => { + try { + if (!date) { + return date; + } + if (typeof date === 'string' && date.length === 13) { + date = Number(date); + } + if (typeof date == "number") { + date = new Date(date); + } + var o = { + "M+": date.getMonth() + 1, //月份 + "d+": date.getDate(), //日 + "h+": date.getHours(), //小时 + "m+": date.getMinutes(), //分 + "s+": date.getSeconds(), //秒 + "q+": Math.floor((date.getMonth() + 3) / 3), //季度 + S: date.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(fmt)) + fmt = fmt.replace( + RegExp.$1, + (date.getFullYear() + "").substr(4 - RegExp.$1.length) + ); + for (var k in o) + if (new RegExp("(" + k + ")").test(fmt)) + fmt = fmt.replace( + RegExp.$1, + RegExp.$1.length == 1 + ? o[k] + : ("00" + o[k]).substr(("" + o[k]).length) + ); + return fmt; + } catch (error) { + return date; + } +}; + +const formatNumber = n => { + n = n.toString(); + return n[1] ? n : "0" + n; +}; + +function convert_length(length) { + return Math.round((wx.getSystemInfoSync().windowWidth * length) / 750); +} + +function barc(id, code, width, height) { + barcode.code128( + wx.createCanvasContext(id), + code, + convert_length(width), + convert_length(height) + ); +} + +function qrc(id, code, width, height) { + qrcode.api.draw(code, { + ctx: wx.createCanvasContext(id), + width: convert_length(width), + height: convert_length(height) + }); +} +function fmtDate(obj) { + if (typeof obj === 'string' && obj.length === 13) { + obj = Number(obj); + } + var date = new Date(obj); + var y = 1900 + date.getYear(); + var m = "0" + (date.getMonth() + 1); + var d = "0" + date.getDate(); + return ( + y + + "-" + + m.substring(m.length - 2, m.length) + + "-" + + d.substring(d.length - 2, d.length) + ); +} + +//计算下单的时间与现在的时间的 +function timechuo(startTime) { + var s1 = new Date(startTime.replace(/-/g, "/")); + var s2 = new Date(); + var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000); + var year = Math.floor(runTime / 86400 / 365); + var runTime = runTime % (86400 * 365); + var month = Math.floor(runTime / 86400 / 30); + var runTime = runTime % (86400 * 30); + var day = Math.floor(runTime / 86400); + var runTime = runTime % 86400; + var hour = Math.floor(runTime / 3600); + var runTime = runTime % 3600; + var minute = Math.floor(runTime / 60); + var runTime = runTime % 60; + var second = runTime; + if (day && !year && !month){ + return (day + '天' + hour + "小时" + minute + "分钟") + } else if (month && !year){ + return ((month*30+day) +'天' + hour + "小时" + minute + "分钟") + } else if (year) { + return ((year*365 + month*30+ day) + '天' + hour + "小时" + minute + "分钟") + }else{ + return (hour + "小时" + minute + "分钟") + } +} + + +//计算时间差 +function timecha(endTime,startTime) { + var s1 = new Date(endTime.replace(/-/g, "/")); + var s2 = new Date(startTime.replace(/-/g, "/")); + var runTime = parseInt((s1.getTime() - s2.getTime()) / 1000); + var year = Math.floor(runTime / 86400 / 365); + var runTime = runTime % (86400 * 365); + var month = Math.floor(runTime / 86400 / 30); + var runTime = runTime % (86400 * 30); + var day = Math.floor(runTime / 86400); + var runTime = runTime % 86400; + var hour = Math.floor(runTime / 3600); + var runTime = runTime % 3600; + var minute = Math.floor(runTime / 60); + var runTime = runTime % 60; + var second = runTime; + return (month+"月"+day+"天"+hour+"小时"+minute+"分钟") +} +function isJSON(str) { + if (typeof str == 'string') { + console.log("string") + try { + var obj = JSON.parse(str); + if (typeof obj == 'object' && obj) { + return true; + } else { + return false; + } + } catch (e) { + console.log(e); + wx.showToast({ + title: '请扫描正确的二维码', + icon: 'none', + duration: 1300 + }) + } + } else { + wx.showToast({ + title: '请扫描正确的二维码', + icon: 'none', + duration: 1300 + }) + } +} +function getProxyImgUrl(str) { + let str1 = str; + imgProxy.map(file=>{ + if (str.indexOf(file.orgUrl) == 0) { + str1 = str.replace(file.orgUrl, file.newUrl) + return + } + }) + return str1 +} +module.exports = { + formatTime: formatTime, + barcode: barc, + qrcode: qrc, + isJSON: isJSON, + fmtDate: fmtDate, + timechuo: timechuo, + timecha: timecha, + getProxyImgUrl: getProxyImgUrl, + convertUTCTimeToLocalTime: convertUTCTimeToLocalTime +};