Commit 3735afaa by 高淑倩

init

parent 4c7d6f7f
// app.js
import { cEvent } from './utils/event.js'
const Promise = require('lib/bluebird')
var utils = require('utils/util.js')
var wxService = require('utils/wxService')
const envInfo = require('config/index').envInfo
App({
onLaunch: function (e) {
},
onShow: function (options = {}) {
// 是不是第一次进入小程序
const baseUserInfo = wx.getStorageSync('_baseUserInfo')
if (baseUserInfo) {
// wxService.getUserInfo()
}
},
onHide: function () {
this.globalData.loginFirst = false
},
getUserInfo() {
return new Promise((resolve, reject) => {
const _baseUserInfo = wx.getStorageSync('_baseUserInfo')
if (_baseUserInfo) {
resolve(_baseUserInfo)
} else {
reject('_baseUserInfo is null')
}
})
},
globalData: {
userInfo: null,
userBaseInfo: null, // openid
systemInfo: wx.getSystemInfoSync(),
ctx: envInfo.ctx,
openCard: false,
userNo: null,
storeId: '',
storeName: '',
loginFirst: false
}
})
{
"pages": [
"pages/welcome/welcome",
"pages/userCenter/userCenter",
"pages/mySpend/mySpend",
"pages/memberRules/memberRules",
"pages/memberOfOwn/memberOfOwn",
"pages/integralWater/integralWater",
"pages/deliveryService/deliveryService",
"pages/coupons/coupons",
"pages/couponDetail/couponDetail",
"pages/consumptionDetails/consumptionDetails",
"pages/IntegralMall/IntegralMall"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
}
}
\ No newline at end of file
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
@charset "UTF-8";
.df {
display: flex;
align-items: center;
justify-content: center; }
.df-j--bt {
justify-content: space-between; }
.df-j--ba {
justify-content: space-around;
}
.df-1 {
flex: 1; }
.df-2 {
flex: 2; }
.df-3 {
flex: 3; }
.df-j--fs {
justify-content: flex-start; }
.fd-c {
flex-direction: column; }
.fd-r {
flex-direction: row; }
.fd-wrap {
flex-flow: wrap; }
.ai-fs {
align-items: flex-start; }
.ai-fe {
align-items: flex-end; }
.df-j--fe {
justify-content: flex-end; }
/*不换行加...*/
.t-ellipsis, .t-ellipsis-2 {
overflow: hidden;
text-overflow: ellipsis; }
.t-ellipsis {
white-space: nowrap; }
.t-ellipsis-2 {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical; }
/*文字左*/
.tl {
text-align: left; }
/*文字居中*/
.tc {
text-align: center; }
/*文字右*/
.tr {
text-align: right; }
/*两端对齐*/
.tj {
text-align: justify; }
/*浮动*/
/*左浮*/
.pl {
float: left; }
/*右浮*/
.pr {
float: right; }
/*清除浮动*/
.clear:before,
.clear:after {
display: table;
content: ' '; }
.clear:after {
clear: both; }
/*字体*/
.fs-10 {
font-size: 10px; }
.fs-12 {
font-size: 12px; }
.fs-14 {
font-size: 14px; }
.fs-16 {
font-size: 16px; }
.fs-18 {
font-size: 18px; }
.fs-20 {
font-size: 20px; }
.fs-22 {
font-size: 22rpx; }
.fs-24 {
font-size: 24rpx; }
.fs-25 {
font-size: 25rpx; }
.fs-30 {
font-size: 30rpx; }
.fs-28 {
font-size: 28rpx; }
.fs-33 {
font-size: 33rpx; }
.fs-34 {
font-size: 34rpx; }
.fs-36 {
font-size: 36rpx; }
.fs-40 {
font-size: 40rpx; }
.box-s {
box-sizing: border-box; }
.bg-fff {
background-color: #fff; }
page {
width: 100%;
box-sizing: border-box;
background-color: #f2f4f7;
font: 14px/1.5 "Microsoft Yahei", Helvetica Neue, Helvetica, STHeiTi, sans-serif; }
.nowrap {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden; }
.cleanFix::after {
visibility: hidden;
display: block;
clear: both;
height: 0;
content: ""; }
/* 重置样式 start */
body, dl, dd, h1, h2, h3, h4, h5, h6, p, hr, form {
margin: 0; }
h1, h2, h3, h4, h5, h6 {
font-weight: normal; }
ol, ul {
margin: 0;
padding: 0;
list-style: none; }
a {
text-decoration: none; }
button, input {
padding: 0; }
i {
font-style: normal; }
/* 重置样式 end */
/* 0.5px border start*/
.border_top05, .border_bottom05, .border_top_bottom05 {
position: relative; }
.border_top05:before, .border_bottom05:after, .border_top_bottom05:before,
.border_top_bottom05:after {
display: block;
content: "";
width: calc(200%);
height: 1px;
position: absolute;
left: -50%;
background-color: #e7e8eb;
-webkit-transform: scale(0.5);
-moz-transform: scale(0.5);
-ms-transform: scale(0.5);
-o-transform: scale(0.5);
transform: scale(0.5);
z-index: 1; }
.border_top05:before, .border_top_bottom05:before {
top: 0; }
.border_bottom05:after, .border_top_bottom05:after {
bottom: 0; }
/* border-box start */
.border_box {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
/* border-box start */
/* 清除浮动 start */
.clear_both::after {
visibility: hidden;
display: block;
clear: both;
content: "";
height: 0; }
/* 清除浮动 end */
/* 文字下划线 start */
.text_underline {
text-decoration: underline; }
/*超出部分点点点*/
.nowrap {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden; }
.none {
display: none; }
.activeRed:active {
background-color: #d9453d; }
.color666 {
color: #666 !important; }
.color333 {
color: #333 !important; }
// component/imageSwiper/imageSwiper.js
var app = getApp()
const wxService = require('../../utils/wxService')
const envInfo = require('../../config/index').envInfo
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {
imgUrls: [
'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
],
indicatorDots: true,
autoplay: true,
interval: 5000,
duration: 1000
},
/**
* 组件的方法列表
*/
methods: {
preview() {
wx.previewImage({
current: 'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640', // 当前显示图片的http链接
urls: ['https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'] // 需要预览的图片http链接列表
})
}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<!--component/imageSwiper/imageSwiper.wxml-->
<swiper
indicator-dots="{{indicatorDots}}"
autoplay="{{autoplay}}"
interval="{{interval}}"
duration="{{duration}}"
>
<block wx:for="{{imgUrls}}" wx:key="{{item}}">
<swiper-item>
<image src="{{item}}" bindtap='preview' class="slide-image" width="355" height="150" />
</swiper-item>
</block>
</swiper>
/* component/imageSwiper/imageSwiper.wxss */
swiper image{
width: 100%
}
\ No newline at end of file
const PROJECT_ENV = 'dev' // 生产 prod, 测试 dev
const needMock = '' //
// appid_dev wxc3b64b09b1d3dfc2
// appid_prod
const devCtx = 'https://srtest.ihotwind.cn/wxMiniProgram/'
const prodCtx = 'https://wxapp.ihotwind.cn/wxMiniProgram/' // 发生产时解开此注释
const config = {
dev: devCtx,
prod: prodCtx
}
const envInfo = (() => {
return {
ctx: config[PROJECT_ENV],
env: PROJECT_ENV
}
})()
module.exports = {
envInfo
}
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "积分商城",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.积分商城wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/consumptionDetails.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "消费详情",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/consumptionDetails.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/coupons.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "券码详情页",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/couponDetail/couponDetail.wxss */
\ No newline at end of file
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/coupons.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "我的卡券",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "外卖服务",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "积分流水",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "我的会员",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "会员规则",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "我的消费",
"usingComponents": {}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<text>pages/userCenter.wxml</text>
/* pages/userCenter.wxss */
\ No newline at end of file
// pages/userCenter.js
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.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
{
"navigationBarTitleText": "广东7-Eleven会员专区",
"usingComponents": {
"image-swiper": "./../../component/imageSwiper/imageSwiper"
}
}
\ No newline at end of file
<!--pages/userCenter.wxml-->
<view class='user-center'>
<image-swiper />
</view>
\ No newline at end of file
/* pages/userCenter.wxss */
@import './../../base/base.wxss'
.user-center{
padding: 15rpx
}
\ No newline at end of file
//index.js
//获取应用实例
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
env: envInfo.env
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
_getUserInfo(ev = {}) {
const userInfo = ev.detail || {}
utils.getUserInfoByBtn(userInfo).then(({ token = '', data = {} }) => {
wx.setStorageSync('_accreditUserInfo', userInfo)
wx.hideNavigationBarLoading()
if (token) {
app.globalData.userNo = token.split('###')[0]
wx.setStorageSync('token', token)
} else {
wx.setStorageSync('token', '')
}
if (data && data.isMember === '1') {
app.globalData.openCard = true
app.globalData.userInfo = wx.getStorageSync('_userInfo')
cEvent.notify('openCardSuccess', data)
}
wx.setStorageSync('_baseUserInfo', data)
this.setUserInfo()
}).catch(err => {
if (err && err.rspCode === -1) {
wx.showToast({
title: `会员系统异常请稍后重试!`,
icon: 'none'
})
}
})
},
setUserInfo: function (e) {
console.log('开卡')
wxService.router(`/pages/userCenter/userCenter`)
// if (!app.globalData.openCard) { // 没有开卡并且需要开卡
// wxService.openCard()
// return false
// }
// const urls = getCurrentPages()
// setTimeout(() => {
// const item = urls[0].options
// if (item.route) {
// try {
// const options = JSON.parse(item.options)
// wxService.router(`/${item.route}`).search(options).replace()
// } catch (e) {
// wx.switchTab({
// url: '/pages/userCenter/userCenter'
// })
// }
// } else {
// wx.switchTab({
// url: '/pages/userCenter/userCenter'
// })
// }
// }, 200)
}
})
{
"usingComponents": {}
}
\ No newline at end of file
<!--index.wxml-->
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<view class="userinfo-avatar">
<open-data type="userAvatarUrl"></open-data>
</view>
<open-data type="userNickName" class="userinfo-nickname" lang="zh_CN"></open-data>
</view>
<view class="usermotto">
<button bindgetuserinfo="_getUserInfo" open-type='getUserInfo' class="user-motto">{{motto}}</button>
</view>
</view>
/**index.wxss**/
page {
height: 100%; }
.userinfo {
display: flex;
flex-direction: column;
align-items: center; }
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
overflow:hidden;
border-radius: 50%; }
.userinfo-nickname {
color: #aaa; }
.user-motto {
margin-top: 200px;
padding: 0 28rpx;
color: #00843e;
font-size: 32rpx; }
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"autoAudits": false
},
"compileType": "miniprogram",
"libVersion": "2.6.6",
"appid": "wxc3b64b09b1d3dfc2",
"projectname": "7-Eleven",
"debugOptions": {
"hidedInDevtools": []
},
"isGameTourist": false,
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"plugin": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": 0,
"list": [
{
"id": -1,
"name": "会员中心",
"pathName": "pages/userCenter/userCenter"
}
]
}
}
}
\ No newline at end of file
const Promise = require('../lib/bluebird')
const envInfo = require('../config/index').envInfo
class Http {
constructor () {
this.state = 'loaded'
this.token = ''
this.app = null
}
request ({
url,
data,
header,
method,
dataType,
responseType,
channel,
success,
fail,
complete
}) {
let path = ''
if (channel) {
path = channel + url
} else {
path = envInfo.ctx + url
}
if (/^http/gi.test(url)) {
path = url
}
const that = this
this.state = 'loading'
return new Promise(function (resolve, reject) {
wx.request({
url: path,
data,
header,
method,
dataType,
responseType,
success: function (data, statusCode, header) {
if (success) {
resolve(data)
} else {
resolve(data)
}
},
fail: function (data, statusCode, header) {
if (fail) {
reject(data)
} else {
reject(data)
}
},
complete: function (data) {
that.state = 'loaded'
if (complete) {
reject(data)
} else {
reject(data)
}
// complete ? complete.apply(this, arguments) : reject(data)
}
})
})
.then(this.checkStatus)
.then(this.intercept)
.then((data) => {
if (success) {
success(data)
}
return Promise.resolve(data)
}, (data) => {
if (fail) {
fail(data)
}
return Promise.reject(data)
})
.catch(this.fail)
}
get (url, parmas) {
return this.request({
url,
method: 'GET',
header: {
token: this.getToken()
},
data: parmas
})
}
post (url, parmas, channel) {
return this.request({
url,
method: 'POST',
header: {
token: wx.getStorageSync('token')
},
data: parmas,
channel: channel
})
}
checkStatus (resp) {
let status = resp.statusCode
if (status >= 200 && status < 300) {
// return resp;
return Promise.resolve(resp)
} else {
var error = new Error(`status: ${resp.statusCode}`)
error.response = resp
return Promise.reject(error)
}
}
intercept (res) {
if (res.data && res.data.code === 401) {
let baseUserInfo = wx.getStorageSync('_baseUserInfo')
if (!baseUserInfo || baseUserInfo.isMember !== '1') {
return Promise.reject({
state: 401,
msg: '没有领取会员卡'
})
} else {
return Promise.reject({
state: 402,
msg: 'token失效'
})
}
} else {
return Promise.resolve(res)
}
}
fail (error) {
if (/timeout/.test(error.errMsg)) {
wx.showModal({
title: '网络不给力',
content: '请求数据超时'
})
}
console.log(JSON.stringify(error))
return Promise.reject(error)
}
getApp () {
if (!this.app) {
this.app = getApp()
}
return this.app
}
getToken () {
// if (!this.token) {
// const token = wx.getStorageSync('token')
// this.token = token
// }
return wx.getStorageSync('token')
}
}
export default Http
class CEvent {
constructor () {
this.events = {}
}
// 消息订阅
on (type, fn) {
const fns = this.events[type]
if (fns) {
fns.push(fn)
} else {
this.events[type] = []
this.events[type].push(fn)
}
return this
}
// 消息发布
notify (type, data) {
const fns = this.events[type]
if (fns) {
fns.forEach(fn => {
fn(data)
})
}
}
// 移除订阅
remove (type, fn) {
if (this.events[type] && this.events[type].length) {
this.events[type] = this.events[type].filter(item => {
return item !== fn
})
}
}
}
export const cEvent = new CEvent()
export default CEvent
const Promise = require('../lib/bluebird')
let c1C2Map = {}
let c2C3Map = {}
export function handler2citys ({
city,
result,
list
}) {
const len = Object.keys(city).length
let res = {
name: [...result.name],
code: [...result.code]
}
let name = city.name
let arginName = res.name.join('') // 原城市名
res.name.push(name)
res.code.push(city.code)
if (res.code.length === 2) {
const pName = res.name.join('###')
const code = res.code.join('')
list[`${pName}`] = `${code}`
if (!c1C2Map[arginName]) {
c1C2Map[arginName] = new Set()
}
c1C2Map[arginName].add(name)
}
if (len > 2) {
for (const key in city) {
if (city.hasOwnProperty(key) && key !== 'name' && key !== 'code') {
const element = city[key]
handler2citys({
city: element,
result: res,
list
})
}
}
} else {
const pName = res.name.join('###')
const code = res.code.join('')
list[`${pName}`] = `${code}`
if (!c2C3Map[arginName]) {
c2C3Map[arginName] = new Set()
}
c2C3Map[arginName].add(name)
}
}
export function getC1 () {
return new Promise((resolve, reject) => {
let keys = Object.keys(c1C2Map)
if (keys.length) {
resolve(keys)
} else {
reject('c1C2Map is empty object')
}
})
}
export function getC2 (c1Name) {
return new Promise((resolve, reject) => {
let keys = c1C2Map[c1Name]
if (keys) {
resolve(keys)
} else {
reject('c1C2Map is empty object')
}
})
}
export function getC3 (c2Name) {
return new Promise((resolve, reject) => {
let keys = c2C3Map[c2Name]
if (keys) {
resolve(keys)
} else {
reject('c2C3Map is empty object')
}
})
}
export function getAppUserInfo () {
const userInfo = wx.getStorageSync('_userInfo')
if (userInfo) {
return Promise.resolve({ userInfo })
} else {
return Promise.reject(new Error('userinfo is null'))
}
}
export default {
c1C2Map,
c2C3Map
}
export function checkOpenCard () {
const baseUserInfo = wx.getStorageSync('_baseUserInfo')
let isMember = '0'
if (baseUserInfo && baseUserInfo.isMember === '1') {
isMember = '1'
}
const pass = isMember === '1'
return pass
}
import Http from './Http'
const Promise = require('../lib/bluebird')
// 时间管理对象
class ManageDate {
constructor () {
this.recordTime = 0 // 上一次刷新的时间戳
this.curTime = 0 // 当前的时间戳
this.updateTime = 3000 // n毫秒刷新时间
}
setNow (now) {
this.now = now
}
/**
* 从服务器端获取时间
*/
hanleRequest (resolve, now) {
this.curTime = new Date().getTime()
// 当前时间与上一次更新时间差比配置更新时间大,则调用接口获取服务器最新时间;
if (!now || ((this.curTime - this.recordTime) > this.updateTime)) {
new Http().get('hs/getNowTime').then(res => {
now = res.data.data.now
this.recordTime = new Date().getTime()
this.setNow(now)
resolve(now)
})
} else {
this.setNow(now)
resolve(now)
}
}
// 获取当前时间
getNow () {
let now = this.now
return new Promise((resolve, reject) => {
this.hanleRequest(resolve, now)
})
}
}
export default ManageDate
class Router {
constructor (url, switchTab) {
const switchPages = [
// '/pages/page/page',
// '/pages/nav/nav',
// '/pages/cart/cart',
// '/pages/userCenter/userCenter'
]
this.router = url || ''
this.navigateType = switchTab ? 'switchTab' : 'navigate'
function getRouter (router) {
return router.split('?')[0]
}
this.navigateManage = {
navigate: () => {
if (switchPages.indexOf(getRouter(this.router)) === -1) {
wx.navigateTo({
url: this.router
})
} else {
wx.switchTab({
url: getRouter(this.router)
})
}
},
switchTab: () => {
wx.switchTab({
url: getRouter(this.router)
})
},
back: () => {
wx.navigateBack({
delta: 1
})
},
redirect: () => {
if (switchPages.indexOf(getRouter(this.router)) === -1) {
wx.redirectTo({
url: this.router
})
} else {
wx.switchTab({
url: getRouter(this.router)
})
}
}
}
setTimeout(() => {
const navigateType = this.navigateType
this.navigateManage[navigateType]()
}, 0)
}
search (parmas) {
var temp = []
for (let p in parmas) {
temp.push(`${p}=${parmas[p]}`)
}
this.router += `?${temp.join('&')}`
return this
}
replace () {
this.navigateType = 'redirect'
return this
}
switchTab () {
this.navigateType = 'switchTab'
return this
}
back (dintance) {
this.navigateType = 'back'
return this
}
}
export default Router
const wxService = require('./wxService')
const moment = require('../lib/moment.min')
const Promise = require('../lib/bluebird')
const _ = require('../lib/underscore.min')
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(':')
}
/* 获取当前页url */
function getCurrentPageUrl() {
var pages = getCurrentPages() // 获取加载的页面
var currentPage = pages[pages.length - 1] // 获取当前页面的对象
var url = currentPage.route // 当前页面url
return url
}
/* 获取当前页带参数的url */
function getCurrentPageUrlWithArgs() {
var pages = getCurrentPages() // 获取加载的页面
var currentPage = pages[pages.length - 1] // 获取当前页面的对象
var url = currentPage.route // 当前页面url
var options = currentPage.options // 如果要获取url中所带的参数可以查看options
// 拼接url的参数
var urlWithArgs = url + '?'
for (var key in options) {
var value = options[key]
urlWithArgs += key + '=' + value + '&'
}
urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1)
return urlWithArgs
}
function getCurrentRouter() {
var pages = getCurrentPages() // 获取加载的页面
var currentPage = pages[pages.length - 1] // 获取当前页面的对象
return currentPage
}
function getNowTime() {
return wxService.getManageDate().getNow()
}
function getAppUserInfo() {
const app = getApp()
if (app.globalData.userInfo) {
return Promise.resolve({ userInfo: app.globalData.userInfo })
} else {
return Promise.reject('userinfo is null')
}
}
/**
* 处理分页数据安全加载,渲染
* 小程序1M的限制
*/
class HandlerDataOnPage {
init(target, originArrName) {
if (target && target.data && originArrName) {
this.target = target.data
this.OriginArrayName = originArrName
}
}
handlerArray(dataArray = []) {
const target = this.target
const arrayName = this.OriginArrayName
dataArray = dataArray || []
this.validate()
if (toString.call(dataArray) !== '[object Array]') {
throw new Error('dataArray invaild')
}
let len = target[arrayName].length
target[arrayName] = target[arrayName].concat(dataArray)
return this.trunObject(dataArray, len)
}
editArray(dataArray = [], startIndex = -1) {
if (startIndex < 0) {
throw new Error('editArray startIndex must > -1')
}
return this.trunObject(dataArray, startIndex)
}
trunObject(dataArray = [], len) {
const arrayName = this.OriginArrayName
function RenderArray2Object() { };
RenderArray2Object.prototype.keysNum = function () {
return Object.keys(this).length
}
let renderArray2Object = new RenderArray2Object()
for (let i = 0, s = dataArray.length; i < s; i++) {
renderArray2Object[`${arrayName}[${len + i}]`] = dataArray[i]
}
return renderArray2Object
}
validate() {
const target = this.target; const arrayName = this.OriginArrayName
target[arrayName] = target[arrayName] || []
if (!target) {
throw new Error('target invaild')
}
if (!(target[arrayName] && toString.call(target[arrayName]) === '[object Array]')) {
target[arrayName] = []
}
}
clearOriginArr() {
const target = this.target; const arrayName = this.OriginArrayName
this.validate()
target[arrayName] = []
}
}
class Logger {
log() {
// if (envInfo.env === 'prod') {
// return
// }
let args = Array.prototype.slice.apply(arguments)
let params = Array.prototype.slice.apply(arguments)
const desc = args.shift()
let tip = `======= ${desc} =======`
args.forEach(() => {
tip += ',%o'
})
params[0] = tip
console.log.apply(console, params)
}
}
// 通过点击按钮 获取用户信息并登陆注册到crm系统中
function getUserInfoByBtn(userInfo) {
const logger = new Logger()
if (Object.keys(userInfo).length === 1) {
return wxService.Promise.reject(userInfo.errMsg)
}
return wxService.login().then((res) => {
logger.log(' wx getUserInfoByBtn success res --->', res)
return Promise.all([Promise.resolve(userInfo), Promise.resolve(res)])
}).then((res) => {
logger.log(' wx _userInfo success res --->', res)
wx.setStorageSync('_userInfo', res[0].userInfo)
wx.showLoading({
title: '正在加载...',
icon: 'none',
mask: true
})
return wxService.get(`memberCard/getCrmUserInfo`, {
code: res[1].code,
wechatInfo: JSON.stringify(res[0])
})
}, (err) => {
return Promise.reject(err)
}).then(response => {
console.log(JSON.stringify(response))
logger.log('getCrmUserInfo response', response)
if (response.data.data.rspCode === -1) {
return Promise.reject(response.data.data)
}
return Promise.resolve(response.data.data)
}).finally(() => {
wx.hideLoading()
})
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = {
formatTime,
getCurrentPageUrl,
getCurrentRouter,
getCurrentPageUrlWithArgs,
getNowTime,
getUserInfoByBtn,
moment,
_,
// _: underscore,
HandlerDataOnPage,
formatTime: formatTime,
getAppUserInfo,
formatNumber: formatNumber,
logger: new Logger()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment