微信小程序 文章加载占位样式 CSS Placeholder

类似豆瓣 APP 动画闪烁效果

WXML:

<view class="text-loading">
  <view class='pic-loading-line'></view>
  <view class='text-loading-line-first'>
    <view class='text-loading-line'></view>
    <view class='text-loading-line'></view>
    <view class='text-loading-line'></view>
  </view>
  <view class='text-loading-line-second'>
    <view class='text-loading-line'></view>
    <view class='text-loading-line'></view>
    <view class='text-loading-line'></view>
  </view>
</view>

WXSS:

.text-loading {
  width: 90%;
  margin:50rpx;
  /* border:1rpx solid #ccc; */
}

.text-loading .pic-loading-line {
  display: inline-block;
  width: 130rpx;
  height: 130rpx;
  margin-right: 20rpx;
  margin-bottom: 20rpx;
  animation: pulse 1s infinite ease-in-out;
}

.text-loading .text-loading-line-first {
  display: inline-block;
  width: 70%;
  height: 150rpx;
}

.text-loading .text-loading-line-second {
  display: inline-block;
  width: 100%;
  height: 150rpx;
}

.text-loading-line {
  height: 30rpx;
  margin-bottom: 20rpx;  
  width: 100%;
  animation: pulse 1s infinite ease-in-out;
}

.text-loading-line:nth-child(1) {
  width: 100%;
}

.text-loading-line:nth-child(2) {
  width: 90%;
}

.text-loading-line:nth-child(3) {
  width: 50%;
}

@keyframes pulse {
  0% {
    background-color: rgba(165, 165, 165, 0.1);
  }

  50% {
    background-color: rgba(165, 165, 165, 0.3);
  }

  100% {
    background-color: rgba(165, 165, 165, 0.1);
  }
}

 

微信小程序 重写 Radio CheckBox 样式 美化单选框复选框

单选按钮 Radio

wxss:

/*  重写 radio 样式  */
/* 未选中的 背景样式 */
radio .wx-radio-input{
   border-radius: 50%;/* 圆角 */
   width: 40rpx;
   height: 40rpx;
}
/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked{
   border: none;
   background: red;
}
/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
radio .wx-radio-input.wx-radio-input-checked::before{
   border-radius: 50%;/* 圆角 */
   width: 40rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
   height: 40rpx; /* 选中后对勾大小,不要超过背景的尺寸 */
   line-height: 40rpx;
   text-align: center;
   font-size:30rpx; /* 对勾大小 30rpx */
   color:#fff; /* 对勾颜色 白色 */
   background: transparent;
   transform:translate(-50%, -50%) scale(1);
   -webkit-transform:translate(-50%, -50%) scale(1);
}
复选按钮 Checkbox

wxss:

/*  重写 checkbox 样式  */
/* 未选中的 背景样式 */
checkbox .wx-checkbox-input{
   border-radius: 50%;/* 圆角 */
   width: 40rpx; /* 背景的宽 */
   height: 40rpx; /* 背景的高 */
}
/* 选中后的 背景样式 (红色背景 无边框 可根据UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked{
   border: none;
   background: red;
}
/* 选中后的 对勾样式 (白色对勾 可根据UI需求自己修改) */
checkbox .wx-checkbox-input.wx-checkbox-input-checked::before{
   border-radius: 50%;/* 圆角 */
   width: 40rpx;/* 选中后对勾大小,不要超过背景的尺寸 */
   height: 40rpx;/* 选中后对勾大小,不要超过背景的尺寸 */
   line-height: 40rpx;
   text-align: center;
   font-size:30rpx; /* 对勾大小 30rpx */
   color:#fff; /* 对勾颜色 白色 */
   background: transparent;
   transform:translate(-50%, -50%) scale(1);
   -webkit-transform:translate(-50%, -50%) scale(1);
}

 

PHP 实现无限极分类生成分类树的方法

<?php

$data = array (
  array (
    'id' => 4,
    'category_name' => '要闻',
    'pid' => 3,
    'created_at' => '2018-06-21 17:33:55',
    'updated_at' => '2018-06-21 17:33:55',
  ),
  array (
    'id' => 3,
    'category_name' => '新闻',
    'pid' => 0,
    'created_at' => '2018-06-21 17:33:45',
    'updated_at' => '2018-06-21 17:33:45',
  ),
  array (
    'id' => 5,
    'category_name' => '企业服务',
    'pid' => 3,
    'created_at' => '2018-06-21 17:34:12',
    'updated_at' => '2018-06-21 17:34:12',
  ),
  array (
    'id' => 6,
    'category_name' => '大新闻',
    'pid' => 0,
    'created_at' => '2018-06-26 14:41:28',
    'updated_at' => '2018-06-26 14:41:28',
  ),
  array (
    'id' => 7,
    'category_name' => '优惠',
    'pid' => 6,
    'created_at' => '2018-06-26 14:41:45',
    'updated_at' => '2018-06-26 14:41:45',
  ),
);
echo "<pre>";
//var_export($data);



function getTree($list,$pid=0,$level=0) {
  static $tree = array();
  foreach($list as $row) {
    if($row['parentID']==$pid) {
      $row['level'] = $level;
      $tree[] = $row;
      getTree($list, $row['id'], $level + 1);
    }
  }
  return $tree;
}

function makeTree($arr){
  $refer = array();
  $tree = array();
  foreach($arr as $k => $v){
    $refer[$v['id']] = & $arr[$k]; //创建主键的数组引用
  }
  foreach($arr as $k => $v){
    $pid = $v['pid'];  //获取当前分类的父级id
    if($pid == 0){
      $tree[] = & $arr[$k];  //顶级栏目
    }else{
      if(isset($refer[$pid])){
        $refer[$pid]['subcat'][] = & $arr[$k]; //如果存在父级栏目,则添加进父级栏目的子栏目数组中
      }
    }
  }
  return $tree;
}


$a = makeTree($data);
print_r($a);

$b = getTree($data);
print_r($b);

输出:

Array
(
    [0] => Array
        (
            [id] => 3
            [category_name] => 新闻
            [pid] => 0
            [created_at] => 2018-06-21 17:33:45
            [updated_at] => 2018-06-21 17:33:45
            [subcat] => Array
                (
                    [0] => Array
                        (
                            [id] => 4
                            [category_name] => 要闻
                            [pid] => 3
                            [created_at] => 2018-06-21 17:33:55
                            [updated_at] => 2018-06-21 17:33:55
                        )

                    [1] => Array
                        (
                            [id] => 5
                            [category_name] => 企业服务
                            [pid] => 3
                            [created_at] => 2018-06-21 17:34:12
                            [updated_at] => 2018-06-21 17:34:12
                        )

                )

        )

    [1] => Array
        (
            [id] => 6
            [category_name] => 大新闻
            [pid] => 0
            [created_at] => 2018-06-26 14:41:28
            [updated_at] => 2018-06-26 14:41:28
            [subcat] => Array
                (
                    [0] => Array
                        (
                            [id] => 7
                            [category_name] => 优惠
                            [pid] => 6
                            [created_at] => 2018-06-26 14:41:45
                            [updated_at] => 2018-06-26 14:41:45
                        )

                )

        )

)
Array
(
    [0] => Array
        (
            [id] => 4
            [category_name] => 要闻
            [pid] => 3
            [created_at] => 2018-06-21 17:33:55
            [updated_at] => 2018-06-21 17:33:55
            [level] => 0
        )

    [1] => Array
        (
            [id] => 3
            [category_name] => 新闻
            [pid] => 0
            [created_at] => 2018-06-21 17:33:45
            [updated_at] => 2018-06-21 17:33:45
            [level] => 0
        )

    [2] => Array
        (
            [id] => 5
            [category_name] => 企业服务
            [pid] => 3
            [created_at] => 2018-06-21 17:34:12
            [updated_at] => 2018-06-21 17:34:12
            [level] => 0
        )

    [3] => Array
        (
            [id] => 6
            [category_name] => 大新闻
            [pid] => 0
            [created_at] => 2018-06-26 14:41:28
            [updated_at] => 2018-06-26 14:41:28
            [level] => 0
        )

    [4] => Array
        (
            [id] => 7
            [category_name] => 优惠
            [pid] => 6
            [created_at] => 2018-06-26 14:41:45
            [updated_at] => 2018-06-26 14:41:45
            [level] => 0
        )

)

 

微信小程序地图服务使用 百度坐标系经纬度 方法 百度坐标系转 GCJ02

微信小程序使用 百度地图提供的坐标进行定位的时候会造成位置偏移,究其原因是百度地图未使用常规的国测局坐标(火星坐标,GCJ02)、或WGS84坐标系 而使用了自己的坐标系 百度坐标系

会造成经纬度上的一公里左右的偏移。

但百度只提供 WGS84、GCJ02 坐标系转百度坐标系的接口,而未提供百度坐标系转 WGS84、GCJ02坐标系

互联网在线地图使用的坐标系:

火星坐标系:

  • iOS 地图(其实是高德)
  • Gogole地图
  • 搜搜、阿里云、高德地图

百度坐标系:

  • 当然只有百度地图

WGS84坐标系:

  • 国际标准,谷歌国外地图、osm地图等国外的地图一般都是这个

微信小程序使用百度坐标系经纬度的解决方式:

腾讯位置服务提供了 微信小程序 JavaScript SDK,可进行其他坐标系的逆向解析,包含以下坐标系转换至腾讯坐标系:

  • GPS坐标
  • sogou经纬度
  • baidu经纬度
  • mapbar经纬度
  • [默认]腾讯、google、高德坐标
  • sogou墨卡托

接口文档: http://lbs.qq.com/qqmap_wx_jssdk/method-reverseGeocoder.html

PHP 自定义函数 记录错误 / LOG日志到文件

public function log($res){
    $err_date = date("Ym", time());
    $address = '/error';
    if (!is_dir($address)) {
        mkdir($address, 0700, true);
    }
    $address = $address.'/'.$err_date . '_error.log';
    $error_date = date("Y-m-d H:i:s", time());
    if(!empty($_SERVER['HTTP_REFERER'])) {
        $file = $_SERVER['HTTP_REFERER'];
    } else {
        $file = $_SERVER['REQUEST_URI'];
    }
    if(is_array($res)) {
        $res_real = "$error_date\t$file\n";
        error_log($res_real, 3, $address);
        $res = var_export($res,true);
        $res = $res."\n";
        error_log($res, 3, $address);
    } else {
        $res_real = "$error_date\t$file\t$res\n";
        error_log($res_real, 3, $address);
    }
}

 

微信小程序 JavaScript 时间比较函数 JS 日期比较

// 时间比较函数
compareDate:function (startDate, endDate) {
  var arrStart = startDate.split("-");
  var startTime = new Date(arrStart[0], arrStart[1], arrStart[2]);
  var startTimes = startTime.getTime();
  var arrEnd = endDate.split("-");
  var endTime = new Date(arrEnd[0], arrEnd[1], arrEnd[2]);
  var endTimes = endTime.getTime();
  if(endTimes<startTimes) {
    return false;
  }
return true;
},

 

微信小程序实现点击滑动展开效果动画

js

let animationShowHeight = 300;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    animation: ''
  },
  // 下来
  btnClick: function () {
    var animation = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(animationShowHeight).step()
    this.setData({
      animation: animation.export(),
    })
  },
  // 上去
  btnClickTo: function () {
    var animation = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(0).step()
    this.setData({
      animation: animation.export(),
    })
  }  
})

wxml

<button type="primary" bindtap="btnClick"> 点我下去 </button>
<button type="primary" bindtap="btnClickTo"> 点我回去 </button>
<view class="body-view" animation="{{animation}}">
  <view>我一会就出来吓死你</view>
  <view>我一会就出来吓死你</view>
  <view>我一会就出来吓死你</view>
</view>

微信小程序 picker 组件,当  range 为 Object Array 类型时示例代码

微信小程序 picker 组件,当  range 为 Object Array 类型时

wxml:

<picker bindchange="bindPickerChange" value="{{index}}" range-key="name" range="{{objectArray}}">
    <view class="picker">
      当前选择:{{objectArray[index].name}}
    </view>
</picker>

js:

Page({
  data: {
    objectArray: [
      {
        id: 0,
        name: '美国'
      },
      {
        id: 1,
        name: '中国'
      },
      {
        id: 2,
        name: '巴西'
      },
      {
        id: 3,
        name: '日本'
      }
    ]
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    var index = e.detail.value;
    var currentId = this.data.objectArray[index].id; 
    this.setData({
      index: e.detail.value
    })
  }
})

 

微信小程序支付完成后回调通知数据 记录

<xml><appid><![CDATA[wxf2e83f1160dfcxxx]]></appid><bank_type><![CDATA[ICBC_DEBIT]]></bank_type>/<cash_fee><![CDATA[1]]></cash_fee>/<fee_type><![CDATA[CNY]]></fee_type>/<is_subscribe><![CDATA[N]]></is_subscribe>/<mch_id><![CDATA[130xxx8601]]></mch_id>/<nonce_str><![CDATA[LhpVcEPpTNASOaQysNFNlYLrpMgyWDLa]]></nonce_str>/<openid><![CDATA[oC7xr5TZehbHbe__UUNPJzDapxxx]]></openid>/<out_trade_no><![CDATA[1528360591]]></out_trade_no>/<result_code><![CDATA[SUCCESS]]></result_code>/<return_code><![CDATA[SUCCESS]]></return_code>/<sign><![CDATA[766868113312ED3C141BF3D3487D1BDF]]></sign>/<time_end><![CDATA[20180607163654]]></time_end>/<total_fee>1</total_fee>/<trade_type><![CDATA[JSAPI]]></trade_type>/<transaction_id><![CDATA[4200000123201806075922186660]]></transaction_id>/</xml>

{"appid":"wxf2e83f1160dfcxxx","bank_type":"ICBC_DEBIT","cash_fee":"1","fee_type":"CNY","is_subscribe":"N","mch_id":"130xxx8601","nonce_str":"yHbHrfbyDnWvRuogoOLWffsuFEXhDBeT","openid":"oC7xr5TZehbHbe__UUNPJzDapxxx","out_trade_no":"1528361071","result_code":"SUCCESS","return_code":"SUCCESS","sign":"364C903E8668AE6B49A1EE2B7A217D97","time_end":"20180607164442","total_fee":"1","trade_type":"JSAPI","transaction_id":"4200000126201806078162413986"}

接收并处理

$data['postStr']=isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
$postdata = json_decode(json_encode(simplexml_load_string($data['postStr'], 'SimpleXMLElement', LIBXML_NOCDATA)), true);

JSON格式化

{
    "appid": "wxf2e83f1160dfcxxx",
    "bank_type": "ICBC_DEBIT",
    "cash_fee": "1",
    "fee_type": "CNY",
    "is_subscribe": "N",
    "mch_id": "130xxx8601",
    "nonce_str": "yHbHrfbyDnWvRuogoOLWffsuFEXhDBeT",
    "openid": "oC7xr5TZehbHbe__UUNPJzDapxxx",
    "out_trade_no": "1528361071",
    "result_code": "SUCCESS",
    "return_code": "SUCCESS",
    "sign": "364C903E8668AE6B49A1EE2B7A217D97",
    "time_end": "20180607164442",
    "total_fee": "1",
    "trade_type": "JSAPI",
    "transaction_id": "4200000126201806078162413986"
}

官方文档:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_7&index=8