Commit 7dce30c3bdbc6fae7f61945f217b8fe197b4a02f

Authored by vking
1 parent 437b8693

filter 人均

1 /* components/reserve/caixi.wxss */ 1 /* components/reserve/caixi.wxss */
2 @import "../../app.wxss"; 2 @import "../../app.wxss";
  3 +.mask{
  4 + z-index:99999;
  5 +}
3 .caixi{ 6 .caixi{
4 background-color: #fefefe; 7 background-color: #fefefe;
5 position: fixed; 8 position: fixed;
  1 +// components/reserve/search/filter.js
  2 +import util from '../../../utils/util'
  3 +Component({
  4 + /**
  5 + * 组件的属性列表
  6 + */
  7 + properties: {
  8 +
  9 + },
  10 +
  11 + /**
  12 + * 组件的初始数据
  13 + */
  14 + data: {
  15 + consumeStr:'',
  16 + hasDisplay:false,
  17 + },
  18 + attached(){
  19 + this.min=0
  20 + this.max=300
  21 + },
  22 + /**
  23 + * 组件的方法列表
  24 + */
  25 + methods: {
  26 + consumeEvent(e){
  27 + console.log('consumeEvent',e)
  28 + let data={
  29 + hasChange:true,
  30 + }
  31 + if(e.detail.type=='once'){
  32 + this.min=e.detail.min
  33 + this.max=e.detail.max
  34 + }else{
  35 + this[e.detail.type]=e.detail.value
  36 + }
  37 + let consumeStr=''
  38 + if(this.min==0){
  39 + if(this.max>this.min){
  40 + consumeStr='¥'+this.max+'以下'
  41 + }
  42 + }else{
  43 + if(this.min<300){
  44 + consumeStr='¥'+this.min+'-'+this.max
  45 + }else{
  46 + consumeStr='¥'+this.min+'以上'
  47 + }
  48 + }
  49 + let obj={
  50 + consumeStr:consumeStr,
  51 + }
  52 + if(e.detail.type!='once'){
  53 + obj.active=''
  54 + }
  55 + this.setData(obj)
  56 + },
  57 + changeVal(e){
  58 + let active=util.attr(e,'val')
  59 + let val=active.split(',')
  60 + this.min=val[0]
  61 + this.max=val[1]
  62 + this.setData({
  63 + active:active,
  64 + })
  65 + this.selectComponent('#consume').changeVal(this.min,this.max);
  66 + },
  67 + close(){
  68 + this.setData({
  69 + hasDisplay:false,
  70 + })
  71 + },
  72 + show(){
  73 + this.setData({
  74 + hasDisplay:true,
  75 + })
  76 + },
  77 + submit(){
  78 + this.triggerEvent('event',{
  79 + type:'set',
  80 + data:{
  81 + consumeStr:this.data.consumeStr||'',
  82 + min:this.min,
  83 + max:this.max,
  84 + active:this.data.active||'',
  85 + },
  86 + })
  87 + this.close()
  88 + },
  89 + reset(){
  90 + this.selectComponent('#consume').changeVal(0,300);
  91 + this.setData({
  92 + active:'',
  93 + consumeStr:'',
  94 + })
  95 + this.triggerEvent('event',{type:'clean'})
  96 + this.close()
  97 + },
  98 + }
  99 +})
  1 +{
  2 + "component": true,
  3 + "usingComponents": {
  4 + "consume":"/components/stat/zyslider"
  5 + }
  6 +}
  1 +<!--components/reserve/search/filter.wxml-->
  2 +<view class="mask" wx:if="{{hasDisplay}}" bindtap="close">
  3 + <view class="filter" catchtap="catchtap">
  4 + <view class="header flex-lr">
  5 + <view></view>
  6 + <view class="title">更多筛选</view>
  7 + <view class="close" bindtap="close"></view>
  8 + </view>
  9 + <view class="part flex-ll">
  10 + 人均消费
  11 + <view class="txt" wx:if="{{consumeStr}}">{{consumeStr}}</view>
  12 + </view>
  13 + <view class="flex-lr tips">
  14 + <view class="content">¥0</view>
  15 + <view class="content">¥300以上</view>
  16 + </view>
  17 + <view class="consume flex-vc">
  18 + <consume style="width:99%;" id="consume"
  19 + minValue="0" maxValue="300" min="0" max="300"
  20 + blockColor="#fefefe"
  21 + backgroundColor="#D8D8D8"
  22 + selectedColor="#E9BE94"
  23 + bindevent="consumeEvent">
  24 + </consume>
  25 + </view>
  26 + <view class="flex-lr split">
  27 + <view class="item {{active=='0,100'?'active':''}}" bindtap="changeVal" data-val="0,100">¥100以下</view>
  28 + <view class="item {{active=='100,200'?'active':''}}" bindtap="changeVal" data-val="100,200">¥100-200</view>
  29 + <view class="item {{active=='200,300'?'active':''}}" bindtap="changeVal" data-val="200,300">¥200-300</view>
  30 + <view class="item {{active=='300,300'?'active':''}}" bindtap="changeVal" data-val="300,300">¥300以上</view>
  31 + </view>
  32 + <view class="flex-lr buttons">
  33 + <view class="reset" bindtap="reset">重置</view>
  34 + <view class="submit" bindtap="submit">完成</view>
  35 + </view>
  36 + </view>
  37 +</view>
  38 +
  1 +/* components/reserve/search/filter.wxss */
  2 +@import "../../../app.wxss";
  3 +.mask{
  4 + z-index: 99999;
  5 +}
  6 +.filter{
  7 + position: fixed;
  8 + bottom: env(safe-area-inset-bottom);
  9 + width: 100%;
  10 + background-color: #fefefe;
  11 + z-index: 9999;
  12 + padding: 40rpx 30rpx;
  13 + box-sizing: border-box;
  14 + border-radius: 20rpx 20rpx 0px 0px;
  15 +}
  16 +.header{
  17 + height: 42rpx;
  18 + font-size: 30rpx;
  19 + font-family: PingFangSC-Semibold, PingFang SC;
  20 + font-weight: 600;
  21 + color: #353535;
  22 + line-height: 42rpx;
  23 +}
  24 +.header .close{
  25 + background-image: url("http://nosqn.colorcun.com/reserve/images/close.png");
  26 + background-size: 100% 100%;
  27 + width:32rpx;
  28 + height:32rpx;
  29 + position: relative;
  30 +}
  31 +.close:after{
  32 + width:100rpx;
  33 + height:100rpx;
  34 + position: absolute;
  35 + content: "";
  36 + top:-50rpx;
  37 + left:-50rpx;
  38 +}
  39 +.part{
  40 + height: 48rpx;
  41 + font-size: 34rpx;
  42 + font-family: PingFangSC-Semibold, PingFang SC;
  43 + font-weight: 600;
  44 + color: #353535;
  45 + line-height: 48rpx;
  46 + margin-top: 60rpx;
  47 +}
  48 +.part .txt{
  49 + height: 48rpx;
  50 + font-size: 34rpx;
  51 + font-family: PingFangSC-Medium, PingFang SC;
  52 + font-weight: 500;
  53 + color: #E9BE94;
  54 + line-height: 48rpx;
  55 + margin-left: 30rpx;
  56 +}
  57 +.tips{
  58 + height: 40rpx;
  59 + font-size: 28rpx;
  60 + font-family: PingFangSC-Regular, PingFang SC;
  61 + font-weight: 400;
  62 + color: #353535;
  63 + line-height: 40rpx;
  64 + margin-top: 40rpx;
  65 +}
  66 +.tips .content{
  67 + width: 130rpx;
  68 + text-align: center;
  69 +}
  70 +.consume{
  71 + margin: 0rpx auto;
  72 + width: calc(100% - 60rpx);
  73 + height: 80rpx;
  74 + overflow: hidden;
  75 +}
  76 +.split{
  77 + margin-top: 60rpx;
  78 +}
  79 +.split .item{
  80 + width: calc(calc(100% - 66rpx) / 4);
  81 + margin-right: 22rpx;
  82 + height: 84rpx;
  83 + background: #F0F0F9;
  84 + border-radius: 6rpx;
  85 +
  86 + font-size: 28rpx;
  87 + font-family: PingFangSC-Regular, PingFang SC;
  88 + font-weight: 400;
  89 + color: #353535;
  90 + line-height: 84rpx;
  91 + text-align: center;
  92 +}
  93 +.split .item:last-child{
  94 + margin-right: 0;
  95 +}
  96 +.split .item.active{
  97 + background: #F4DAB9;
  98 + color: #8B5318;
  99 +}
  100 +.buttons{
  101 + margin-top: 100rpx;
  102 +}
  103 +.buttons .reset,.buttons .submit{
  104 + width: calc(50% - 21rpx);
  105 + height: 84rpx;
  106 + background: #FFFFFF;
  107 + border-radius: 12rpx;
  108 + border: 2rpx solid #C0C0C0;
  109 + margin-right: 21rpx;
  110 +
  111 + font-size: 34rpx;
  112 + font-family: PingFangSC-Medium, PingFang SC;
  113 + font-weight: 500;
  114 + color: #5E5E5E;
  115 + line-height: 84rpx;
  116 + text-align: center;
  117 + box-sizing: border-box;
  118 +}
  119 +.buttons .submit{
  120 + margin-right: 0;
  121 + margin-left: 21rpx;
  122 + background: linear-gradient(180deg, #F4DAB9 0%, #E9BE94 100%);
  123 + color: #8B5318;
  124 + border-width: 0;
  125 +}
  1 +// component/zyslider/zyslider.js
  2 +var util = require('../../utils/util')
  3 +Component({
  4 + /**
  5 + * 组件的属性列表
  6 + */
  7 + properties: {
  8 + /** slider 最小值 */
  9 + min: {
  10 + type: Number
  11 + },
  12 + /** slider 最大值 */
  13 + max: {
  14 + type: Number
  15 + },
  16 + /** 步进 (没做,有时间再说,项目里没用到撒) */
  17 + step: {
  18 + type: Number
  19 + },
  20 + /** 预选选择的小值*/
  21 + minValue: {
  22 + type: Number
  23 + },
  24 + /** 预选选择的大值 */
  25 + maxValue: {
  26 + type: Number
  27 + },
  28 + /** 滑块颜色 */
  29 + blockColor:{
  30 + type: String
  31 + },
  32 + /** 未选择进度条颜色 */
  33 + backgroundColor:{
  34 + type: String
  35 + },
  36 + /** 已选择进度条颜色 */
  37 + selectedColor:{
  38 + type: String
  39 + }
  40 + },
  41 +
  42 +
  43 + /**
  44 + * 组件的初始数据
  45 + */
  46 + data: {
  47 + min: 0,
  48 + max: 300,
  49 + leftValue: 0,
  50 + rightValue: 300,
  51 + totalLength: 0,
  52 + bigLength: 0,
  53 + ratio: 0.5,
  54 + sliderLength: 30,
  55 + containerLeft: 0, //标识整个组件,距离屏幕左边的距离
  56 + hideOption: '', //初始状态为显示组件
  57 + },
  58 +
  59 + /**
  60 + * 组件的方法列表
  61 + */
  62 + methods: {
  63 +
  64 + /**
  65 + * 设置左边滑块的值
  66 + */
  67 + _propertyLeftValueChange: function () {
  68 +
  69 + let minValue = this.data.minValue / this.data.max * this.data.bigLength
  70 + let min = this.data.min / this.data.max * this.data.bigLength
  71 + this.setData({
  72 + leftValue: minValue - min
  73 + })
  74 + },
  75 +
  76 + /**
  77 + * 设置右边滑块的值
  78 + */
  79 + _propertyRightValueChange: function () {
  80 + let right = this.data.maxValue / this.data.max * this.data.bigLength + this.data.sliderLength
  81 + this.setData({
  82 + rightValue: right
  83 + })
  84 + },
  85 +
  86 + /**
  87 + * 滑块滑动
  88 + * @param e
  89 + */
  90 + sliderMove(e){
  91 + this.sliderEvent=e
  92 + //console.log('sliderMove.changing',this.sliderMoving)
  93 + if(this.sliderMoving) return;//移动中
  94 + setTimeout(()=>{
  95 + //console.log('changing',this.sliderEvent);
  96 + let pagex = this.sliderEvent.changedTouches[0].pageX / this.data.ratio - this.data.containerLeft - this.data.sliderLength / 2
  97 + let myEventDetail={}
  98 + if(util.attr(this.sliderEvent,'type')=='max'){
  99 + if (pagex <= this.data.leftValue + this.data.sliderLength) {
  100 + pagex = this.data.leftValue + this.data.sliderLength
  101 + } else if (pagex >= this.data.totalLength - this.data.sliderLength) {
  102 + pagex = this.data.totalLength - this.data.sliderLength
  103 + }
  104 + this.setData({
  105 + rightValue: pagex
  106 + })
  107 + pagex = pagex - this.data.sliderLength
  108 + let heighValue = parseInt(pagex / this.data.bigLength * (this.data.max - this.data.min) + this.data.min)
  109 +
  110 + myEventDetail = { type:'max',value: heighValue }
  111 + }else{
  112 + if (pagex + this.data.sliderLength >= this.data.rightValue) {
  113 + pagex = this.data.rightValue - this.data.sliderLength
  114 + } else if (pagex <= 0) {
  115 + pagex = 0
  116 + }
  117 + this.setData({
  118 + leftValue: pagex
  119 + })
  120 + let lowValue = parseInt(pagex / this.data.bigLength * parseInt(this.data.max - this.data.min) + this.data.min)
  121 + myEventDetail = { type:'min',value: lowValue }
  122 + }
  123 + //console.log('event',myEventDetail);
  124 + this.triggerEvent('event', myEventDetail)
  125 + this.sliderMoving=false
  126 + },0)
  127 + this.sliderMoving=true
  128 + },
  129 + /**
  130 + * 隐藏组件
  131 + */
  132 + hide: function () {
  133 + this.setData({
  134 + hideOption: 'hide',
  135 + })
  136 + },
  137 + /**
  138 + * 显示组件
  139 + */
  140 + show: function () {
  141 + this.setData({
  142 + hideOption: '',
  143 + })
  144 + },
  145 + /**
  146 + * 重置
  147 + */
  148 + reset: function () {
  149 + this.setData({
  150 + rightValue: this.data.totalLength,
  151 + leftValue: 0,
  152 + })
  153 + },
  154 + changeVal(min,max) {
  155 + this.setData({
  156 + minValue: parseInt(min),
  157 + maxValue: parseInt(max),
  158 + })
  159 + this._propertyLeftValueChange()
  160 + this._propertyRightValueChange()
  161 + this.triggerEvent('event', { type:'once',min:min,max:max})
  162 + },
  163 + },
  164 +
  165 + ready: function () {
  166 + let that = this;
  167 + const getSystemInfo = util.wxPromisify(wx.getSystemInfo)
  168 + const queryContainer = util.wxPromisify(wx.createSelectorQuery().in(this).select(".container").boundingClientRect)
  169 + util.wxPromisify(wx.getSystemInfo)()
  170 + .then(res => {
  171 + let ratio = res.windowWidth / 750
  172 + that.setData({
  173 + ratio: ratio,
  174 + })
  175 + })
  176 + .then(() => {
  177 + var query = wx.createSelectorQuery().in(this)
  178 + query.select(".container").boundingClientRect(function (res) {
  179 + that.setData({
  180 + totalLength: res.width / that.data.ratio - that.data.sliderLength,
  181 + bigLength: res.width / that.data.ratio - that.data.sliderLength * 3,
  182 + rightValue: res.width / that.data.ratio - that.data.sliderLength,
  183 + containerLeft: res.left / that.data.ratio
  184 + })
  185 +
  186 + /**
  187 + * 设置初始滑块位置
  188 + */
  189 + that._propertyLeftValueChange()
  190 + that._propertyRightValueChange()
  191 + }).exec()
  192 + })
  193 + }
  194 +})
  1 +{
  2 + "component": true,
  3 + "usingComponents": {}
  4 +}
  1 +<!--component/zyslider.wxml-->
  2 +<slot></slot>
  3 +<view class="container {{hideOption}}">
  4 + <view class="slider-item min" style="left:{{leftValue}}rpx;background-color:{{blockColor}};" catchtouchmove="sliderMove" data-type="min"></view>
  5 + <view class="slider-item max" style="left:{{rightValue}}rpx;background-color:{{blockColor}};" catchtouchmove="sliderMove" data-type="max"></view>
  6 +
  7 + <view class="slider-body left" style="left:{{sliderLength}}rpx; width:{{leftValue}}rpx;background-color:{{backgroundColor}};"></view>
  8 + <view class="slider-body body" style="left:{{leftValue}}rpx; width:{{rightValue-leftValue}}rpx;background-color:{{selectedColor}};"></view>
  9 + <view class="slider-body right" style="left:{{rightValue}}rpx; width:{{totalLength - rightValue}}rpx;background-color:{{backgroundColor}};"></view>
  10 +</view>
  1 +/* component/zyslider.wxss */
  2 +.container {
  3 + /*height: 100%;*/
  4 + width: 100%;
  5 + position: relative;
  6 +}
  7 +
  8 +.slider-body {
  9 + height: 6rpx;
  10 + background: #D8D8D8;
  11 + border-radius: 3rpx;
  12 + position: relative;
  13 +}
  14 +
  15 +.body {
  16 + bottom: 60rpx;
  17 + height: 6rpx;
  18 + background: #E9BE94;
  19 + border-radius: 3rpx;
  20 + z-index: 0.3;
  21 +}
  22 +
  23 +.left {
  24 + bottom: 60rpx;
  25 + z-index: 0.1;
  26 +}
  27 +
  28 +.right {
  29 + z-index: 0.2;
  30 + bottom: 64rpx;
  31 +}
  32 +
  33 +.slider-item {
  34 + width: 60rpx;
  35 + height: 60rpx;
  36 + background: #FFFFFF;
  37 + box-shadow: 0px 4rpx 8rpx 0rpx #F4DAB9;
  38 + border: 2rpx solid #E9BE94;
  39 + border-radius: 50%;
  40 + z-index: 2;
  41 +}
  42 +
  43 +.min {
  44 + position: relative;
  45 + top: 40rpx;
  46 + /*left: 100rpx;*/
  47 +}
  48 +
  49 +.max {
  50 + position: relative;
  51 + bottom: 22rpx;
  52 + /*left: 600rpx;*/
  53 +}
  54 +.hide{
  55 + display: none;
  56 +}
@@ -506,6 +506,13 @@ Page({ @@ -506,6 +506,13 @@ Page({
506 if(this.findSellerData){ 506 if(this.findSellerData){
507 param=Object.assign(param,this.findSellerData.paramObj) 507 param=Object.assign(param,this.findSellerData.paramObj)
508 } 508 }
  509 + if(this.filterParams){//人均过滤
  510 + let filterParams=this.filterParams.min+','+this.filterParams.max
  511 + if(this.filterParams.min==this.filterParams.max && this.filterParams.min==300){
  512 + filterParams=this.filterParams.min+','+parseInt(new Date()/1000)
  513 + }
  514 + param.filterParams=filterParams
  515 + }
509 //this.selectComponent('#list').getList(param); 516 //this.selectComponent('#list').getList(param);
510 this.param=param; 517 this.param=param;
511 let now_sid=[]; 518 let now_sid=[];
@@ -982,4 +989,17 @@ Page({ @@ -982,4 +989,17 @@ Page({
982 } 989 }
983 } 990 }
984 }, 991 },
  992 + filterShow(){
  993 + this.selectComponent('#filter').show();
  994 + },
  995 + filterParams:null,
  996 + filterEvent(e){
  997 + console.log('filterEvent',e)
  998 + if(e.detail.type=='clean'){
  999 + this.filterParams=null
  1000 + }else{
  1001 + this.filterParams=e.detail.data
  1002 + }
  1003 + setTimeout(()=>{this.getMarkers();},0)
  1004 + },
985 }) 1005 })
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 "caixi":"/components/reserve/caixi", 12 "caixi":"/components/reserve/caixi",
13 "activity-enter":"/components/activity/enter", 13 "activity-enter":"/components/activity/enter",
14 "as-phone":"/components/actionSheet/phone", 14 "as-phone":"/components/actionSheet/phone",
15 - "activity-tips":"/components/tips/discount" 15 + "activity-tips":"/components/tips/discount",
  16 + "filter":"/components/reserve/search/filter"
16 } 17 }
17 } 18 }
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 </view> 35 </view>
36 </view> 36 </view>
37 </navigator> 37 </navigator>
38 - <view class="transverse-search flex-ll"> 38 + <view class="transverse-search">
39 <view 39 <view
40 bindtap="caixiShow" 40 bindtap="caixiShow"
41 class="tags {{multiIndex[0]>0?'active':''}}" 41 class="tags {{multiIndex[0]>0?'active':''}}"
@@ -53,6 +53,18 @@ @@ -53,6 +53,18 @@
53 bindtap="tagsChange" 53 bindtap="tagsChange"
54 data-id="{{item.id}}">{{item.name}}</view> 54 data-id="{{item.id}}">{{item.name}}</view>
55 </block> 55 </block>
  56 + <view
  57 + bindtap="filterShow"
  58 + class="tags {{multiIndex[0]>0?'active':''}}"
  59 + >
  60 + <view class="picker flex-lr">
  61 + <view class="input">
  62 + <block wx:if="{{multiIndex[0]==0}}">筛选</block>
  63 + <block wx:else="">{{multiArray[0][multiIndex[0]]}}</block>
  64 + </view>
  65 + <view class="more"></view>
  66 + </view>
  67 + </view>
56 <!-- 68 <!--
57 <view class="fingSeller flex-ll" bindtap="findSeller"> 69 <view class="fingSeller flex-ll" bindtap="findSeller">
58 <view class="icon"></view> 70 <view class="icon"></view>
@@ -161,4 +173,5 @@ @@ -161,4 +173,5 @@
161 <activity-enter hasInHome wx:if="{{hasGetPos}}"></activity-enter> 173 <activity-enter hasInHome wx:if="{{hasGetPos}}"></activity-enter>
162 <boost bindevent="boostEvent" wx:if="{{hasBoost}}"></boost> 174 <boost bindevent="boostEvent" wx:if="{{hasBoost}}"></boost>
163 <activity-tips wx:if="{{hasSetActivity}}" map="{{map}}"></activity-tips> 175 <activity-tips wx:if="{{hasSetActivity}}" map="{{map}}"></activity-tips>
164 -<as-phone id="as"></as-phone>  
  176 +<as-phone id="as"></as-phone>
  177 +<filter id="filter" bindevent="filterEvent"></filter>
@@ -43,6 +43,7 @@ page{ @@ -43,6 +43,7 @@ page{
43 background-color: #fefefe; 43 background-color: #fefefe;
44 /*height: 264rpx;*/ 44 /*height: 264rpx;*/
45 width: 100%; 45 width: 100%;
  46 + margin-top: -360rpx;
46 } 47 }
47 .transverse-list .seller{ 48 .transverse-list .seller{
48 width: 98%; 49 width: 98%;
@@ -101,6 +102,8 @@ page{ @@ -101,6 +102,8 @@ page{
101 .picker{ 102 .picker{
102 height: 50rpx; 103 height: 50rpx;
103 line-height: 50rpx; 104 line-height: 50rpx;
  105 + padding-left: 8rpx;
  106 + padding-right: 10rpx;
104 } 107 }
105 .picker .input{ 108 .picker .input{
106 height: 50rpx; 109 height: 50rpx;
@@ -331,11 +334,20 @@ page{ @@ -331,11 +334,20 @@ page{
331 } 334 }
332 .transverse-search{ 335 .transverse-search{
333 background-color: #fefefe; 336 background-color: #fefefe;
334 - height: 90rpx; 337 + /*height: 90rpx;*/
  338 + height: 450rpx;
335 font-size: 24rpx; 339 font-size: 24rpx;
336 - padding-left: 40rpx; 340 + padding-left: 16rpx;
337 line-height: 90rpx; 341 line-height: 90rpx;
  342 + width: calc(100% - 16rpx);
  343 + overflow-x: auto;
  344 + white-space:nowrap;
338 } 345 }
  346 +.transverse-search view{
  347 + display: inline-block;
  348 +}
  349 +
  350 +
339 .disabled .transverse-search{ 351 .disabled .transverse-search{
340 padding-top: 0; 352 padding-top: 0;
341 } 353 }
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 "packNpmRelationList": [] 30 "packNpmRelationList": []
31 }, 31 },
32 "compileType": "miniprogram", 32 "compileType": "miniprogram",
33 - "libVersion": "2.10.1", 33 + "libVersion": "2.11.1",
34 "appid": "wxd3dc4206c76f14fc", 34 "appid": "wxd3dc4206c76f14fc",
35 "projectname": "c%E7%AB%AF%E9%A2%84%E5%AE%9A", 35 "projectname": "c%E7%AB%AF%E9%A2%84%E5%AE%9A",
36 "isGameTourist": false, 36 "isGameTourist": false,
@@ -110,7 +110,25 @@ function timetouUnix(dasr, connect) { @@ -110,7 +110,25 @@ function timetouUnix(dasr, connect) {
110 var time_str = date.getTime().toString(); 110 var time_str = date.getTime().toString();
111 return time_str.substr(0, 10); 111 return time_str.substr(0, 10);
112 } 112 }
  113 +/**
  114 + * 将小程序的API封装成支持Promise的API
  115 + * @params fn {Function} 小程序原始API,如wx.login
  116 + */
  117 +const wxPromisify = fn => {
  118 + return function (obj = {}) {
  119 + return new Promise((resolve, reject) => {
  120 + obj.success = function (res) {
  121 + resolve(res)
  122 + }
  123 +
  124 + obj.fail = function (res) {
  125 + reject(res)
  126 + }
113 127
  128 + fn(obj)
  129 + })
  130 + }
  131 +}
114 module.exports = { 132 module.exports = {
115 formatTime: formatTime, 133 formatTime: formatTime,
116 unixtoTime: unixtoTime, 134 unixtoTime: unixtoTime,
@@ -343,6 +361,7 @@ module.exports = { @@ -343,6 +361,7 @@ module.exports = {
343 }, 361 },
344 }) 362 })
345 }, 363 },
  364 + wxPromisify:wxPromisify,
346 } 365 }
347 366
348 367