@@ -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, | |||||
} | |||||
}) |
@@ -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" | |||||
} |
@@ -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; |
@@ -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 () { | |||||
} | |||||
}) |
@@ -0,0 +1,3 @@ | |||||
{ | |||||
"usingComponents": {} | |||||
} |
@@ -0,0 +1 @@ | |||||
/* pages/ces.wxss */ |
@@ -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 () { | |||||
} | |||||
}) |
@@ -0,0 +1,3 @@ | |||||
{ | |||||
"usingComponents": {} | |||||
} |
@@ -0,0 +1,2 @@ | |||||
<!--pages/ces/ces.wxml--> | |||||
<text>pages/ces/ces.wxml</text> |
@@ -0,0 +1 @@ | |||||
/* pages/ces/ces.wxss */ |
@@ -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 () { | |||||
} | |||||
}) |
@@ -0,0 +1,3 @@ | |||||
{ | |||||
"usingComponents": {} | |||||
} |
@@ -0,0 +1,33 @@ | |||||
<view class="Box"> | |||||
<view class=" top"> | |||||
<view class='userinfo'> | |||||
<view class="textBox"> | |||||
<view class="nameBox"> | |||||
<view class="name">用户昵称</view> | |||||
<view class="grade">用户等级</view> | |||||
</view> | |||||
<view class="myGrow nameBox"> | |||||
<view>{{'我的成长值'}}|</view> | |||||
<view class="grow">{{"更多成长值"}}</view> | |||||
</view> | |||||
</view> | |||||
</view> | |||||
<view class='userPortrait'></view> | |||||
</view> | |||||
<swiper autoplay='true' interval='1000' circular='true'> | |||||
<swiper-item class="swiperItem">123</swiper-item> | |||||
<swiper-item class="swiperItem">456</swiper-item> | |||||
</swiper> | |||||
<view class="plazaList" bindtap="goPlaza" data-appid="{{plazaAppid}}"> | |||||
<view class="EntranceBox"> | |||||
<view class="plazaImg"></view> | |||||
<view class="plazaMessage"> | |||||
<view class="plazaName">欢乐国际购物城 </view> | |||||
<view class="site">广场地址:嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻</view> | |||||
<view class="area">总面积:6000M²</view> | |||||
<view class="area stall"> 车位数:123</view> | |||||
<vide class="area distance">距您:233M</vide> | |||||
</view> | |||||
</view> | |||||
</view> | |||||
</view> |
@@ -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; | |||||
} |
@@ -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 () { | |||||
} | |||||
}) |
@@ -0,0 +1,3 @@ | |||||
{ | |||||
"usingComponents": {} | |||||
} |
@@ -0,0 +1,21 @@ | |||||
<!--pages/location/location.wxml--> | |||||
<view class="Box"> | |||||
<view class="presentSiteBox"> | |||||
<view class="presentText">当前位置 </view> | |||||
<view class="gpsBox"> | |||||
<view class="city"> 北京市</view> | |||||
<view class="gps">GPS定位 </view> | |||||
</view> | |||||
<view class="wire"> </view> | |||||
</view> | |||||
<view class="siteText" > 城市广场</view> | |||||
<view class="siteBox"> | |||||
<view class="plazaName">欢乐国际城</view> | |||||
<view class="site">武汉市江夏区佩尔中心 </view> | |||||
<view class="distance">1.23Km </view> | |||||
</view> | |||||
<view class="wire"> </view> | |||||
</view> |
@@ -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) | |||||
} |
@@ -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": [] | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,7 @@ | |||||
{ | |||||
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", | |||||
"rules": [{ | |||||
"action": "allow", | |||||
"page": "*" | |||||
}] | |||||
} |
@@ -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(); |
@@ -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 | |||||
}; |