liuyuqi-dellpc 7 years ago
commit
2f187e7616
100 changed files with 1700 additions and 0 deletions
  1. 103 0
      app.acss
  2. 16 0
      app.js
  3. 115 0
      app.json
  4. BIN
      image/api.png
  5. BIN
      image/api_active.png
  6. BIN
      image/api_bluetooth.png
  7. BIN
      image/api_data.png
  8. BIN
      image/api_device.png
  9. BIN
      image/api_map.png
  10. BIN
      image/api_media.png
  11. BIN
      image/api_network.png
  12. BIN
      image/api_open.png
  13. BIN
      image/api_rsa.png
  14. BIN
      image/api_share.png
  15. BIN
      image/api_view.png
  16. BIN
      image/api_websocket.png
  17. BIN
      image/arrowright.png
  18. BIN
      image/basic.png
  19. BIN
      image/biz_collapse.png
  20. BIN
      image/biz_dropdown.png
  21. BIN
      image/biz_errorview.png
  22. BIN
      image/biz_grid.png
  23. BIN
      image/biz_list.png
  24. BIN
      image/biz_tag.png
  25. BIN
      image/canvas.png
  26. BIN
      image/components.png
  27. BIN
      image/error-view/empty.png
  28. BIN
      image/error-view/error.png
  29. BIN
      image/error-view/limit.png
  30. BIN
      image/feedback.png
  31. BIN
      image/form.png
  32. BIN
      image/icon_API.png
  33. BIN
      image/icon_API_HL.png
  34. BIN
      image/icon_biz.png
  35. BIN
      image/icon_biz_HL.png
  36. BIN
      image/icon_component.png
  37. BIN
      image/icon_component_HL.png
  38. BIN
      image/logo.png
  39. BIN
      image/map.png
  40. BIN
      image/media.png
  41. BIN
      image/navigator.png
  42. BIN
      image/view.png
  43. 9 0
      page/API/action-sheet/action-sheet.axml
  44. 15 0
      page/API/action-sheet/action-sheet.js
  45. 3 0
      page/API/action-sheet/action-sheet.json
  46. 9 0
      page/API/alert/alert.axml
  47. 14 0
      page/API/alert/alert.js
  48. 3 0
      page/API/alert/alert.json
  49. 6 0
      page/API/animation/animation.acss
  50. 24 0
      page/API/animation/animation.axml
  51. 55 0
      page/API/animation/animation.js
  52. 3 0
      page/API/animation/animation.json
  53. 9 0
      page/API/bluetooth/bluetooth.acss
  54. 46 0
      page/API/bluetooth/bluetooth.axml
  55. 329 0
      page/API/bluetooth/bluetooth.js
  56. 3 0
      page/API/bluetooth/bluetooth.json
  57. 29 0
      page/API/canvas/canvas.acss
  58. 16 0
      page/API/canvas/canvas.axml
  59. 38 0
      page/API/canvas/canvas.js
  60. 3 0
      page/API/canvas/canvas.json
  61. 11 0
      page/API/canvas/example.axml
  62. 303 0
      page/API/canvas/example.js
  63. 9 0
      page/API/choose-city/choose-city.axml
  64. 13 0
      page/API/choose-city/choose-city.js
  65. 3 0
      page/API/choose-city/choose-city.json
  66. 3 0
      page/API/clipboard/clipboard.acss
  67. 16 0
      page/API/clipboard/clipboard.axml
  68. 26 0
      page/API/clipboard/clipboard.js
  69. 3 0
      page/API/clipboard/clipboard.json
  70. 9 0
      page/API/confirm/confirm.axml
  71. 15 0
      page/API/confirm/confirm.js
  72. 3 0
      page/API/confirm/confirm.json
  73. 0 0
      page/API/contact/contact.acss
  74. 17 0
      page/API/contact/contact.axml
  75. 31 0
      page/API/contact/contact.js
  76. 3 0
      page/API/contact/contact.json
  77. 3 0
      page/API/date-picker/date-picker.acss
  78. 11 0
      page/API/date-picker/date-picker.axml
  79. 40 0
      page/API/date-picker/date-picker.js
  80. 3 0
      page/API/date-picker/date-picker.json
  81. 0 0
      page/API/download-file/download-file.acss
  82. 3 0
      page/API/download-file/download-file.axml
  83. 17 0
      page/API/download-file/download-file.js
  84. 3 0
      page/API/download-file/download-file.json
  85. 30 0
      page/API/file/file.acss
  86. 26 0
      page/API/file/file.axml
  87. 70 0
      page/API/file/file.js
  88. 3 0
      page/API/file/file.json
  89. 13 0
      page/API/get-auth-code/get-auth-code.acss
  90. 7 0
      page/API/get-auth-code/get-auth-code.axml
  91. 14 0
      page/API/get-auth-code/get-auth-code.js
  92. 3 0
      page/API/get-auth-code/get-auth-code.json
  93. 11 0
      page/API/get-location/format-location.js
  94. 15 0
      page/API/get-location/get-location.acss
  95. 21 0
      page/API/get-location/get-location.axml
  96. 30 0
      page/API/get-location/get-location.js
  97. 3 0
      page/API/get-location/get-location.json
  98. 7 0
      page/API/get-network-type/get-network-type.acss
  99. 19 0
      page/API/get-network-type/get-network-type.axml
  100. 35 0
      page/API/get-network-type/get-network-type.js

+ 103 - 0
app.acss

@@ -0,0 +1,103 @@
+page {
+  background-color: #F7F7F7;
+}
+
+.page {
+  font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
+  font-size: 24rpx;
+  padding: 32rpx;
+  flex: 1;
+}
+
+.page-description {
+  margin-bottom: 32rpx;
+}
+
+.page-section {
+  background: #fff;
+  margin-bottom: 32rpx;
+}
+
+.page-section-title {
+  padding: 16rpx 32rpx;
+}
+
+.page-section-demo {
+  padding: 32rpx;
+}
+
+.page-section-btns {
+  border-top: 1px solid #ddd;
+  display: flex;
+  justify-content: space-around;
+  align-items: center;
+}
+
+.page-section-btns > view {
+  flex: 1;
+  height: 84rpx;
+  display: flex;
+  align-items: center;
+  justify-content: space-around;
+  color: #49a9ee;
+}
+.page-section-btns > view + view {
+  border-left: 1px solid #ddd;
+}
+
+button {
+  margin-top:20rpx;
+  margin-bottom:20rpx;
+}
+
+.bc_blue {
+  background-color: #49A9EE;
+}
+
+.bc_red {
+  background-color: #F04134;
+}
+
+.bc_yellow {
+  background-color: #FFBF00;
+}
+
+.bc_green {
+  background-color: #00A854;
+}
+
+.form-row {
+  display: flex;
+  align-items: center;
+  padding: 0 30rpx;
+  height: 88rpx;
+  align-items: center;
+}
+
+.form-row-label {
+  width: 180rpx;
+  font-size: 34rpx;
+  margin-right: 10rpx;
+  text-align: left;
+  color: #000;
+}
+
+.form-row-content {
+  flex: 1;
+  font-size: 34rpx;
+}
+
+.form-line {
+  height: 1px;
+  background-color: #ddd;
+  margin-left: 30rpx;
+}
+
+.input {
+  color: #000;
+  font-size: 34rpx;
+  width: 100%;
+  padding: 4rpx 0;
+  border: 0;
+  line-height: 1;
+}

+ 16 - 0
app.js

@@ -0,0 +1,16 @@
+App({
+  onLaunch(options) {
+    console.log('App Launch', options);
+    console.log('getSystemInfoSync', my.getSystemInfoSync());
+    console.log('SDKVersion', my.SDKVersion);
+  },
+  onShow() {
+    console.log('App Show');
+  },
+  onHide() {
+    console.log('App Hide');
+  },
+  globalData: {
+    hasLogin: false,
+  },
+});

+ 115 - 0
app.json

@@ -0,0 +1,115 @@
+{
+  "pages": [
+    "page/component/index",
+    "page/component/component-pages/action-sheet/action-sheet",
+    "page/component/component-pages/button/button",
+    "page/component/component-pages/canvas/canvas",
+    "page/component/component-pages/checkbox/checkbox",
+    "page/component/component-pages/form/form",
+    "page/component/component-pages/icon/icon",
+    "page/component/component-pages/image/image",
+    "page/component/component-pages/input/input",
+    "page/component/component-pages/label/label",
+    "page/component/component-pages/loading/loading",
+    "page/component/component-pages/map/map",
+    "page/component/component-pages/modal/modal",
+    "page/component/component-pages/navigator/navigate",
+    "page/component/component-pages/navigator/redirect",
+    "page/component/component-pages/navigator/reLaunch",
+    "page/component/component-pages/navigator/navigator",
+    "page/component/component-pages/picker/picker",
+    "page/component/component-pages/picker-view/picker-view",
+    "page/component/component-pages/progress/progress",
+    "page/component/component-pages/radio/radio",
+    "page/component/component-pages/scroll-view/scroll-view",
+    "page/component/component-pages/slide-tab/slide-tab",
+    "page/component/component-pages/slider/slider",
+    "page/component/component-pages/swiper/swiper",
+    "page/component/component-pages/switch/switch",
+    "page/component/component-pages/text/text",
+    "page/component/component-pages/textarea/textarea",
+    "page/component/component-pages/toast/toast",
+    "page/component/component-pages/view/view",
+    "page/API/index/index",
+    "page/API/share/share",
+    "page/API/action-sheet/action-sheet",
+    "page/API/alert/alert",
+    "page/API/animation/animation",
+    "page/API/canvas/canvas",
+    "page/API/choose-city/choose-city",
+    "page/API/confirm/confirm",
+    "page/API/contact/contact",
+    "page/API/date-picker/date-picker",
+    "page/API/download-file/download-file",
+    "page/API/file/file",
+    "page/API/get-auth-code/get-auth-code",
+    "page/API/get-location/get-location",
+    "page/API/get-network-type/get-network-type",
+    "page/API/get-system-info/get-system-info",
+    "page/API/get-server-time/get-server-time",
+    "page/API/get-user-info/get-user-info",
+    "page/API/image/image",
+    "page/API/keyboard/keyboard",
+    "page/API/loading/loading",
+    "page/API/make-phone-call/make-phone-call",
+    "page/API/navigation-bar-loading/navigation-bar-loading",
+    "page/API/navigator/navigator",
+    "page/API/open-location/open-location",
+    "page/API/pull-down-refresh/pull-down-refresh",
+    "page/API/request/request",
+    "page/API/request-payment/request-payment",
+    "page/API/scan-code/scan-code",
+    "page/API/set-navigation-bar/set-navigation-bar",
+    "page/API/storage/storage",
+    "page/API/toast/toast",
+    "page/API/upload-file/upload-file",
+    "page/API/vibrate/vibrate",
+    "page/API/watch-shake/watch-shake",
+    "page/API/clipboard/clipboard",
+    "page/API/bluetooth/bluetooth",
+    "page/API/rsa/rsa",
+    "page/API/page-scroll-to/page-scroll-to",
+    "page/API/websocket/websocket",
+    "page/biz/index",
+    "page/biz/pages/collapse/index",
+    "page/biz/pages/dropdown/index",
+    "page/biz/pages/error-view/index",
+    "page/biz/pages/grid/index",
+    "page/biz/pages/list/index",
+    "page/biz/pages/tag/index"
+  ],
+  "window": {
+    "enableWK": "YES",
+    "enableDSL": true,
+    "defaultTitle": "小程序",
+    "backgroundColor": "#F5F5F9",
+    "pullRefresh": false,
+    "allowsBounceVertical": true
+  },
+  "tabBar": {
+    "textColor": "#404040",
+    "selectedColor": "#108ee9",
+    "backgroundColor": "#F5F5F9",
+    "items": [
+      {
+        "pagePath": "page/component/index",
+        "icon": "image/icon_component.png",
+        "activeIcon": "image/icon_component_HL.png",
+        "name": "基础组件"
+      },
+      {
+        "pagePath": "page/API/index/index",
+        "icon": "image/icon_API.png",
+        "activeIcon": "image/icon_API_HL.png",
+        "name": "API"
+      },
+      {
+        "pagePath": "page/biz/index",
+        "icon": "image/icon_biz.png",
+        "activeIcon": "image/icon_biz_HL.png",
+        "name": "业务组件"
+      }
+    ]
+  },
+  "debug": true
+}

BIN
image/api.png


BIN
image/api_active.png


BIN
image/api_bluetooth.png


BIN
image/api_data.png


BIN
image/api_device.png


BIN
image/api_map.png


BIN
image/api_media.png


BIN
image/api_network.png


BIN
image/api_open.png


BIN
image/api_rsa.png


BIN
image/api_share.png


BIN
image/api_view.png


BIN
image/api_websocket.png


BIN
image/arrowright.png


BIN
image/basic.png


BIN
image/biz_collapse.png


BIN
image/biz_dropdown.png


BIN
image/biz_errorview.png


BIN
image/biz_grid.png


BIN
image/biz_list.png


BIN
image/biz_tag.png


BIN
image/canvas.png


BIN
image/components.png


BIN
image/error-view/empty.png


BIN
image/error-view/error.png


BIN
image/error-view/limit.png


BIN
image/feedback.png


BIN
image/form.png


BIN
image/icon_API.png


BIN
image/icon_API_HL.png


BIN
image/icon_biz.png


BIN
image/icon_biz_HL.png


BIN
image/icon_component.png


BIN
image/icon_component_HL.png


BIN
image/logo.png


BIN
image/map.png


BIN
image/media.png


BIN
image/navigator.png


BIN
image/view.png


+ 9 - 0
page/API/action-sheet/action-sheet.axml

@@ -0,0 +1,9 @@
+<view class="page">
+  <view class="page-description">操作菜单 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.showActionSheet</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="showActionSheet">显示操作菜单</button>
+    </view>
+  </view>
+</view>

+ 15 - 0
page/API/action-sheet/action-sheet.js

@@ -0,0 +1,15 @@
+Page({
+  showActionSheet() {
+    my.showActionSheet({
+      title: '支付宝-ActionSheet',
+      items: ['菜单一', '菜单二', '菜单三'],
+      cancelButtonText: '取消好了',
+      success: (res) => {
+        const btn = res.index === -1 ? '取消' : '第' + res.index + '个';
+        my.alert({
+          title: `你点了${btn}按钮`
+        });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/action-sheet/action-sheet.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Action Sheet"
+}

+ 9 - 0
page/API/alert/alert.axml

@@ -0,0 +1,9 @@
+<view class="page">
+  <view class="page-description">警告框 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.alert</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="alert">显示警告框</button>
+    </view>
+  </view>
+</view>

+ 14 - 0
page/API/alert/alert.js

@@ -0,0 +1,14 @@
+Page({
+  alert() {
+    my.alert({
+      title: '亲',
+      content: '您本月的账单已出',
+      buttonText: '我知道了',
+      success: () => {
+        my.alert({
+          title: '用户点击了「我知道了」',
+        });
+      }
+    });
+  },
+})

+ 3 - 0
page/API/alert/alert.json

@@ -0,0 +1,3 @@
+{
+  "defaultTitle": "Alert"
+}

+ 6 - 0
page/API/animation/animation.acss

@@ -0,0 +1,6 @@
+.animation-element {
+  width: 200rpx;
+  height: 200rpx;
+  background-color: #108ee9;
+  transform: scaleX(1) scaleY(1);
+}

+ 24 - 0
page/API/animation/animation.axml

@@ -0,0 +1,24 @@
+<view class="page">
+  <view class="page-description">动画 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.createAnimation</view>
+    <view class="page-section-demo">
+      <view class="animation-element" animation="{{animation}}"></view>
+    </view>
+    <view class="page-section-btns">
+      <view type="primary" onTap="rotate">旋转</view>
+      <view type="primary" onTap="scale"> 缩放</view>
+      <view type="primary" onTap="translate">移动</view>
+    </view>
+    <view class="page-section-btns">
+      <view type="primary" onTap="skew">倾斜</view>
+      <view type="primary" onTap="rotateAndScale">旋转并缩放</view>
+      <view type="primary" onTap="rotateThenScale">旋转后缩放</view>
+    </view>
+    <view class="page-section-btns">
+      <view type="primary" onTap="all">同时展示全部</view>
+      <view type="primary" onTap="allInQueue">顺序展示全部</view>
+      <view type="primary" onTap="reset">还原</view>
+    </view>
+  </view>
+</view>

+ 55 - 0
page/API/animation/animation.js

@@ -0,0 +1,55 @@
+Page({
+  onReady() {
+    this.animation = my.createAnimation()
+  },
+  rotate() {
+    this.animation.rotate(Math.random() * 720 - 360).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  scale() {
+    this.animation.scale(Math.random() * 2).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  translate() {
+    this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  skew() {
+    this.animation.skew(Math.random() * 90, Math.random() * 90).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  rotateAndScale() {
+    this.animation.rotate(Math.random() * 720 - 360)
+      .scale(Math.random() * 2)
+      .step()
+    this.setData({ animation: this.animation.export() })
+  },
+  rotateThenScale() {
+    this.animation.rotate(Math.random() * 720 - 360).step()
+      .scale(Math.random() * 2).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  all() {
+    this.animation.rotate(Math.random() * 720 - 360)
+      .scale(Math.random() * 2)
+      .translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
+      .skew(Math.random() * 90, Math.random() * 90)
+      .step()
+    this.setData({ animation: this.animation.export() })
+  },
+  allInQueue() {
+    this.animation.rotate(Math.random() * 720 - 360).step()
+      .scale(Math.random() * 2).step()
+      .translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
+      .skew(Math.random() * 90, Math.random() * 90).step()
+    this.setData({ animation: this.animation.export() })
+  },
+  reset() {
+    this.animation.rotate3d(0, 0, 0)
+      .scale(1)
+      .translate(0, 0)
+      .skew(0, 0)
+      .step({ duration: 0 })
+    this.setData({ animation: this.animation.export() })
+  }
+})

+ 3 - 0
page/API/animation/animation.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Animation"
+}

+ 9 - 0
page/API/bluetooth/bluetooth.acss

@@ -0,0 +1,9 @@
+.help-info {
+  padding:10px;
+  color:#000000;
+}
+
+.help-title {
+  padding:10px;
+  color:#FC0D1B;
+}

+ 46 - 0
page/API/bluetooth/bluetooth.axml

@@ -0,0 +1,46 @@
+<view class="page">
+  <view class="page-description">蓝牙 API</view>
+  <view class="page-section">
+    <view class="page-section-title">本机蓝牙开关状态</view>
+    <view class="page-section-demo">
+       <button type="primary" onTap="openBluetoothAdapter">初始化蓝牙</button>
+       <button type="primary" onTap="closeBluetoothAdapter">关闭本机蓝牙</button>
+       <button type="primary" onTap="getBluetoothAdapterState">获取蓝牙状态</button>
+    </view>
+
+    <view class="page-section-title">扫描蓝牙设备</view>
+    <view class="page-section-demo">
+       <button type="primary" onTap="startBluetoothDevicesDiscovery">开始搜索</button>
+       <button type="primary" onTap="getBluetoothDevices">所有搜索到的设备</button>
+       <button type="primary" onTap="getConnectedBluetoothDevices">所有已连接的设备</button>
+       <button type="primary" onTap="stopBluetoothDevicesDiscovery">停止搜索</button>
+    </view>
+
+    <view class="page-section-title">连接设备</view>
+    <view class="page-section-demo">
+       <input class="input" onInput="bindKeyInput" type="{{text}}" placeholder="输入要连接的设备的deviceId"></input>
+       <button type="primary" onTap="connectBLEDevice">连接设备</button>
+       <button type="primary" onTap="getBLEDeviceServices">获取设备服务</button>
+       <button type="primary" onTap="getBLEDeviceCharacteristics">获取读写特征</button>
+       <button type="primary" onTap="disconnectBLEDevice">断开设备连接</button>
+    </view>
+
+     <view class="page-section-title">读写数据</view>
+     <view class="page-section-demo">
+       <button type="primary" onTap="notifyBLECharacteristicValueChange">监听特征值数据变化</button>
+       <button type="primary" onTap="readBLECharacteristicValue">读取数据</button>
+       <button type="primary" onTap="writeBLECharacteristicValue">写入数据</button>
+       <button type="primary" onTap="offBLECharacteristicValueChange">取消特征值监听</button>
+    </view>
+
+     <view class="page-section-title">其他事件</view>
+     <view class="page-section-demo">
+       <button type="primary" onTap="bluetoothAdapterStateChange">本机蓝牙状态变化</button>
+       <button type="primary" onTap="offBluetoothAdapterStateChange">取消本机蓝牙状态监听</button>
+       <button type="primary" onTap="BLEConnectionStateChanged">蓝牙连接状态变化</button>
+       <button type="primary" onTap="offBLEConnectionStateChanged">取消蓝牙连接状态监听</button>
+       
+    </view>
+
+  </view>
+</view>

+ 329 - 0
page/API/bluetooth/bluetooth.js

@@ -0,0 +1,329 @@
+Page({
+  data: {
+    devid: '0D9C82AD-1CC0-414D-9526-119E08D28124',
+    serid: 'FEE7',
+    notifyId: '36F6',
+    writeId: '36F5',
+    charid: '',
+    alldev: [{ deviceId: '' }],
+  },
+  //获取本机蓝牙开关状态
+  openBluetoothAdapter() {
+    my.openBluetoothAdapter({
+      success: res => {
+        if (!res.isSupportBLE) {
+          my.alert({ content: '抱歉,您的手机蓝牙暂不可用' });
+          return;
+        }
+        my.alert({ content: '初始化成功!' });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  closeBluetoothAdapter() {
+    my.closeBluetoothAdapter({
+      success: () => {
+        my.alert({ content: '关闭蓝牙成功!' });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  getBluetoothAdapterState() {
+    my.getBluetoothAdapterState({
+      success: res => {
+        if (!res.available) {
+          my.alert({ content: '抱歉,您的手机蓝牙暂不可用' });
+          return;
+        }
+        my.alert({ content: JSON.stringify(res) });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  //扫描蓝牙设备
+  startBluetoothDevicesDiscovery() {
+    my.startBluetoothDevicesDiscovery({
+      allowDuplicatesKey: false,
+      success: () => {
+        my.onBluetoothDeviceFound({
+          success: res => {
+            // my.alert({content:'监听新设备'+JSON.stringify(res)});
+            var deviceArray = res.devices;
+            for (var i = deviceArray.length - 1; i >= 0; i--) {
+              var deviceObj = deviceArray[i];
+              //通过设备名称或者广播数据匹配目标设备,然后记录deviceID后面使用
+              if (deviceObj.name == this.data.name) {
+                my.alert({ content: '目标设备被找到' });
+                my.offBluetoothDeviceFound();
+                this.setData({
+                  deviceId: deviceObj.deviceId,
+                });
+                break;
+              }
+            }
+          },
+          fail: error => {
+            my.alert({ content: '监听新设备失败' + JSON.stringify(error) });
+          },
+        });
+      },
+      fail: error => {
+        my.alert({ content: '启动扫描失败' + JSON.stringify(error) });
+      },
+    });
+  },
+  //停止扫描
+  stopBluetoothDevicesDiscovery() {
+    my.stopBluetoothDevicesDiscovery({
+      success: res => {
+        my.offBluetoothDeviceFound();
+        my.alert({ content: '操作成功!' });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  //获取正在连接中的设备
+  getConnectedBluetoothDevices() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有在连接中的设备!' });
+          return;
+        }
+        my.alert({ content: JSON.stringify(res) });
+        devid = res.devices[0].deviceId;
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+
+  //获取所有搜索到的设备
+  getBluetoothDevices() {
+    my.getBluetoothDevices({
+      success: res => {
+        my.alert({ content: JSON.stringify(res) });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+
+  bindKeyInput(e) {
+    this.setData({
+      devid: e.detail.value,
+    });
+  },
+
+  //连接设备
+  connectBLEDevice() {
+    my.connectBLEDevice({
+      deviceId: this.data.devid,
+      success: res => {
+        my.alert({ content: '连接成功' });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  //断开连接
+  disconnectBLEDevice() {
+    my.disconnectBLEDevice({
+      deviceId: this.data.devid,
+      success: () => {
+        my.alert({ content: '断开连接成功!' });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  //获取连接设备的server,必须要再连接状态状态之下才能获取
+  getBLEDeviceServices() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有已连接的设备' });
+          return;
+        }
+        my.getBLEDeviceServices({
+          deviceId: this.data.devid,
+          success: res => {
+            my.alert({ content: JSON.stringify(res) });
+            this.setData({
+              serid: res.services[0].serviceId,
+            });
+          },
+          fail: error => {
+            my.alert({ content: JSON.stringify(error) });
+          },
+        });
+      },
+    });
+  },
+  //获取连接设备的charid,必须要再连接状态状态之下才能获取(这里分别筛选出读写特征字)
+  getBLEDeviceCharacteristics() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有已连接的设备' });
+          return;
+        }
+        this.setData({
+          devid: res.devices[0].deviceId,
+        });
+        my.getBLEDeviceCharacteristics({
+          deviceId: this.data.devid,
+          serviceId: this.data.serid,
+          success: res => {
+            my.alert({ content: JSON.stringify(res) });
+            //特征字对象属性见文档,根据属性匹配读写特征字并记录,然后后面读写使用
+            this.setData({
+              charid: res.characteristics[0].characteristicId,
+            });
+          },
+          fail: error => {
+            my.alert({ content: JSON.stringify(error) });
+          },
+        });
+      },
+    });
+  },
+  //读写数据
+  readBLECharacteristicValue() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有已连接的设备' });
+          return;
+        }
+        this.setData({
+          devid: res.devices[0].deviceId,
+        });
+        my.readBLECharacteristicValue({
+          deviceId: this.data.devid,
+          serviceId: this.data.serid,
+          characteristicId: this.data.notifyId,
+          //1、安卓读取服务
+          // serviceId:'0000180d-0000-1000-8000-00805f9b34fb',
+          // characteristicId:'00002a38-0000-1000-8000-00805f9b34fb',
+          success: res => {
+            my.alert({ content: JSON.stringify(res) });
+          },
+          fail: error => {
+            my.alert({ content: '读取失败' + JSON.stringify(error) });
+          },
+        });
+      },
+    });
+  },
+
+  writeBLECharacteristicValue() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有已连接的设备' });
+          return;
+        }
+        this.setData({
+          devid: res.devices[0].deviceId,
+        });
+
+        my.writeBLECharacteristicValue({
+          deviceId: this.data.devid,
+          serviceId: this.data.serid,
+          characteristicId: this.data.charid,
+          //安卓写入服务
+          //serviceId:'0000180d-0000-1000-8000-00805f9b34fb',
+          //characteristicId:'00002a39-0000-1000-8000-00805f9b34fb',
+          value: 'ABCD',
+          success: res => {
+            my.alert({ content: '写入数据成功!' });
+          },
+          fail: error => {
+            my.alert({ content: JSON.stringify(error) });
+          },
+        });
+      },
+    });
+  },
+  notifyBLECharacteristicValueChange() {
+    my.getConnectedBluetoothDevices({
+      success: res => {
+        if (res.devices.length === 0) {
+          my.alert({ content: '没有已连接的设备' });
+          return;
+        }
+        this.setData({
+          devid: res.devices[0].deviceId,
+        });
+
+        my.notifyBLECharacteristicValueChange({
+          state: true,
+          deviceId: this.data.devid,
+          serviceId: this.data.serid,
+          characteristicId: this.data.notifyId,
+          success: () => {
+            //监听特征值变化的事件
+            my.onBLECharacteristicValueChange({
+              success: res => {
+                //  my.alert({content: '特征值变化:'+JSON.stringify(res)});
+                my.alert({ content: '得到响应数据 = ' + res.value });
+              },
+            });
+            my.alert({ content: '监听成功' });
+          },
+          fail: error => {
+            my.alert({ content: '监听失败' + JSON.stringify(error) });
+          },
+        });
+      },
+    });
+  },
+  offBLECharacteristicValueChange() {
+    my.offBLECharacteristicValueChange();
+  },
+  //其他事件
+  bluetoothAdapterStateChange() {
+    my.onBluetoothAdapterStateChange({
+      success: res => {
+        my.alert({ content: '本机蓝牙状态变化:' + JSON.stringify(res) });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  offBluetoothAdapterStateChange() {
+    my.offBluetoothAdapterStateChange();
+  },
+
+  BLEConnectionStateChanged() {
+    my.onBLEConnectionStateChanged({
+      success: res => {
+        my.alert({ content: '连接状态变化:' + JSON.stringify(res) });
+      },
+      fail: error => {
+        my.alert({ content: JSON.stringify(error) });
+      },
+    });
+  },
+  offBLEConnectionStateChanged() {
+    my.offBLEConnectionStateChanged({
+      success: res => {
+        my.alert({ content: '取消监听成功!' });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/bluetooth/bluetooth.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Bluetooth"
+}

+ 29 - 0
page/API/canvas/canvas.acss

@@ -0,0 +1,29 @@
+.canvas-element {
+  width: auto;
+  align-self: stretch;
+  height: 400rpx;
+}
+
+.canvas-buttons {
+  padding: 50rpx 50rpx 10rpx;
+  border-top: 1px solid #ccc;
+  display: flex;
+  flex-grow: 1;
+  overflow-y: scroll;
+  flex-direction: row;
+  flex-wrap: wrap;
+  align-self: stretch;
+  height: 400rpx;
+  box-sizing: border-box;
+}
+
+.canvas-button {
+  font-size: 28rpx;
+  width: 290rpx;
+  margin: 20rpx auto;
+}
+
+.canvas-button-reset {
+  width: 610rpx;
+  margin: 20rpx auto;
+}

+ 16 - 0
page/API/canvas/canvas.axml

@@ -0,0 +1,16 @@
+<view class="page">
+  <view class="page-description">画布 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.createCanvasContext</view>
+    <view class="page-section-demo">
+      <canvas class="canvas-element" id="canvas" onTap="log" onTouchStart="log"></canvas>
+    </view>
+    <scroll-view class="canvas-buttons" scroll-y="true">
+      <block a:for="{{methods}}" a:for-item="method">
+        <button class="canvas-button" type="primary" onTap="{{method}}">{{method}}</button>
+      </block>
+    </scroll-view>
+    <button class="canvas-button" type="primary" onTap="toTempFilePath">toTempFilePath</button>
+  </view>
+</view>
+

+ 38 - 0
page/API/canvas/canvas.js

@@ -0,0 +1,38 @@
+import example from './example.js';
+
+Page({
+  onLoad() {
+    this.context = my.createCanvasContext('canvas')
+
+    var methods = Object.keys(example)
+    this.setData({
+      methods: methods
+    })
+
+    var that = this
+    methods.forEach(function (method) {
+      that[method] = function () {
+        example[method](that.context)
+        that.context.draw();
+      }
+    })
+  },
+  log(e) {
+    console.log('canvas', e);
+  },
+  toTempFilePath() {
+    this.context.toTempFilePath({
+      success(res) {
+        my.previewImage({
+          urls: [res.apFilePath],
+        });
+      },
+      fail(res) {
+        my.alert({
+          title: 'toTempFilePath',
+          content: `error: ${res.error}`,
+        })
+      }
+    })
+  }
+})

+ 3 - 0
page/API/canvas/canvas.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Canvas"
+}

+ 11 - 0
page/API/canvas/example.axml

@@ -0,0 +1,11 @@
+<view class="page">
+  <view class="page__hd">
+    <text class="page__title">{{method}}</text>
+    <text class="page__desc">{{introduction}}</text>
+  </view>
+  <view class="page__bd">
+    <view class="section section_gap">
+      <canvas style="width: 100%; height: 300px;" id="mycanvas"></canvas>
+    </view>
+  </view>
+</view>

+ 303 - 0
page/API/canvas/example.js

@@ -0,0 +1,303 @@
+var example = {};
+
+example.rotate = function (context) {
+  context.beginPath();
+  context.rotate(10*Math.PI/180);
+  context.rect(225, 75, 20, 10);
+  context.setFillStyle('#108ee9');
+  context.fill(); 
+};
+
+example.scale = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.rect(25, 25, 50, 50);
+  context.stroke();
+
+  context.scale(2,2);
+
+  context.beginPath();
+  context.rect(25, 25, 50, 50);
+  context.stroke();
+};
+
+
+example.reset = function (context) {
+  context.beginPath();
+
+  context.setFillStyle('#108ee9');
+  context.setStrokeStyle('#108ee9');
+  context.setFontSize(10);
+
+  context.setShadow(0, 0, 0, 'rgba(0, 0, 0, 0)');
+
+  context.setLineCap('butt');
+  context.setLineJoin('miter');
+  context.setLineWidth(1);
+  context.setMiterLimit(10);
+};
+
+example.translate = function (context) {
+  context.beginPath();
+  context.setFillStyle('#108ee9');
+  context.rect(10, 10, 100, 50);
+  context.fill();
+
+  context.translate(70, 70);
+
+  context.beginPath();
+  context.fill();
+};
+
+example.save = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.save();
+
+  context.scale(2, 2);
+  context.setStrokeStyle('#108ee9');
+  context.rect(0, 0, 100, 100);
+  context.stroke();
+  context.restore();
+
+  context.rect(0, 0, 50, 50);
+  context.stroke();
+};
+
+example.restore = function (context) {
+  [3, 2, 1].forEach(function (item) {
+    context.beginPath();
+    context.setStrokeStyle('#108ee9');
+    context.save();
+    context.scale(item, item);
+    context.rect(10, 10, 100, 100);
+    context.stroke();
+    context.restore();
+  });
+
+};
+
+example.drawImage = function (context) {
+  context.drawImage('/image/api.png', 0, 0);
+};
+
+example.fillText = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(0, 10);
+  context.lineTo(300, 10);
+  context.stroke();
+
+  // context.save();
+  // context.scale(1.5, 1.5);
+  // context.translate(20, 20);
+  context.setFontSize(10);
+  context.fillText('Hello Alipay', 0, 30);
+  context.setFontSize(20);
+  context.fillText('Hello Alipay', 200, 30);
+
+  // context.restore();
+
+  context.beginPath();
+  context.moveTo(0, 30);
+  context.lineTo(300, 30);
+  context.stroke();
+};
+
+example.fill = function (context) {
+  context.beginPath();
+  context.setFillStyle('#108ee9');
+  context.rect(20, 20, 150, 100);
+  context.fill();
+};
+
+example.stroke = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(20, 20);
+  context.lineTo(20, 100);
+  context.lineTo(70, 100);
+
+  context.stroke();
+};
+
+example.clearRect = function (context) {
+  context.beginPath();
+  context.setFillStyle('#108ee9');
+  context.rect(0, 0, 300, 150);
+  context.fill();
+  context.clearRect(20, 20, 100, 50);
+};
+
+example.beginPath = function (context) {
+  context.beginPath();
+  context.setLineWidth(5);
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(0, 75);
+  context.lineTo(250, 75);
+  context.stroke();
+
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(50, 0);
+  context.lineTo(150, 130);
+  context.stroke();
+};
+
+example.closePath = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(20, 20);
+  context.lineTo(20, 100);
+  context.lineTo(70, 100);
+  context.closePath();
+  context.stroke();
+};
+
+example.moveTo = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(0, 0);
+  context.lineTo(300, 150);
+  context.stroke();
+};
+
+example.lineTo = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(20,20);
+  context.lineTo(20,100);
+  context.lineTo(70,100);
+  context.stroke();
+};
+
+example.rect = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.rect(20, 20, 150, 100);
+  context.stroke();
+};
+
+example.arc = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.arc(75,75,50,0,Math.PI*2,true);
+  context.moveTo(110,75);
+  context.arc(75,75,35,0,Math.PI,false);
+  context.moveTo(65,65);
+  context.arc(60,65,5,0,Math.PI*2,true);
+  context.moveTo(95,65);
+  context.arc(90,65,5,0,Math.PI*2,true);
+  context.stroke();
+};
+
+example.quadraticCurveTo = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(20, 20);
+  context.quadraticCurveTo(20, 100, 200, 20);
+  context.stroke();
+};
+
+example.bezierCurveTo = function (context) {
+  context.beginPath();
+  context.setStrokeStyle('#108ee9');
+  context.moveTo(20, 20);
+  context.bezierCurveTo(20, 100, 200, 100, 200, 20);
+  context.stroke();
+};
+
+example.setFillStyle = function (context) {
+   ['rgb(183, 218, 243)', 'rgb(39, 156, 240)', 'rgb(67, 168, 240)', 'rgb(119, 194, 247)'].forEach(function (item, index) {
+    context.setFillStyle(item);
+    context.beginPath();
+    context.rect(0 + 75*index, 0, 50, 50);
+    context.fill();
+  });
+};
+
+example.setStrokeStyle = function (context) {
+  ['rgb(183, 218, 243)', 'rgb(39, 156, 240)', 'rgb(67, 168, 240)', 'rgb(119, 194, 247)'].forEach(function (item, index) {
+    context.setStrokeStyle(item);
+    context.beginPath();
+    context.rect(0 + 75*index, 0, 50, 50);
+    context.stroke();
+  });
+};
+
+example.setGlobalAlpha = function (context) {
+  context.setFillStyle('#108ee9');
+  [1, 0.5, 0.1].forEach(function (item, index) {
+    context.setGlobalAlpha(item)
+    context.beginPath();
+    context.rect(0 + 75*index, 0, 50, 50);
+    context.fill();
+  });
+}
+
+example.setShadow = function (context) {
+  context.beginPath();
+  context.setFillStyle('#108ee9');
+  context.setShadow(10, 10, 10, 'rgb(183, 218, 243)');
+  context.rect(10, 10, 100, 100);
+  context.fill();
+};
+
+example.setFontSize = function (context) {
+  [10, 20, 30, 40].forEach(function (item, index) {
+    context.setFontSize(item);
+    context.fillText('Hello, world', 20, 20 + 40*index);
+  })
+};
+
+example.setLineCap = function (context) {
+  context.setLineWidth(10);
+  ['butt', 'round', 'square'].forEach(function (item, index) {
+    context.beginPath();
+    context.setStrokeStyle('#108ee9');
+    context.setLineCap(item);
+    context.moveTo(20, 20 + 20*index);
+    context.lineTo(100, 20 + 20*index);
+    context.stroke(); 
+  });
+};
+
+example.setLineJoin = function (context) {
+  context.setLineWidth(10);
+  ['bevel', 'round', 'miter'].forEach(function (item, index) {
+    context.beginPath();
+    context.setStrokeStyle('#108ee9');
+    context.setLineJoin(item);
+    context.moveTo(20 + 80*index, 20);
+    context.lineTo(100 + 80*index, 50);
+    context.lineTo(20 + 80*index, 100);
+    context.stroke();
+  });
+};
+
+example.setLineWidth = function (context) {
+  [2, 4, 6, 8, 10].forEach(function (item, index) {
+    context.beginPath();
+    context.setStrokeStyle('#108ee9');
+    context.setLineWidth(item);
+    context.moveTo(20, 20 + 20*index);
+    context.lineTo(100, 20 + 20*index);
+    context.stroke();          
+  });
+};
+
+example.setMiterLimit = function (context) {
+  context.setLineWidth(4);
+
+  [2, 4, 6, 8, 10].forEach(function (item, index) {
+    context.beginPath();
+    context.setStrokeStyle('#108ee9');
+    context.setMiterLimit(item);
+    context.moveTo(20 + 80*index, 20);
+    context.lineTo(100 + 80*index, 50);
+    context.lineTo(20 + 80*index, 100);
+    context.stroke();          
+  });        
+};
+
+export default example

+ 9 - 0
page/API/choose-city/choose-city.axml

@@ -0,0 +1,9 @@
+<view class="page">
+  <view class="page-description">选择城市 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.chooseCity</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="chooseCity">选择城市</button>
+    </view>
+  </view>
+</view>

+ 13 - 0
page/API/choose-city/choose-city.js

@@ -0,0 +1,13 @@
+Page({
+  chooseCity() {
+    my.chooseCity({
+      showLocatedCity: true,
+      showHotCities: true,
+      success: (res) => {
+        my.alert({
+          title: 'chooseAlipayContact response: ' + JSON.stringify(res),
+        });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/choose-city/choose-city.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "City"
+}

+ 3 - 0
page/API/clipboard/clipboard.acss

@@ -0,0 +1,3 @@
+.clipboard-button {
+  margin-left: 5px;
+}

+ 16 - 0
page/API/clipboard/clipboard.axml

@@ -0,0 +1,16 @@
+<view class="page">
+  <view class="page-section">
+    <view class="page-section-title">setClipboard</view>
+    <view class="page-section-demo">
+      <input onInput="handleInput" value="{{text}}" />
+      <button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">复制</button>
+    </view>
+  </view>
+  <view class="page-section">
+    <view class="page-section-title">getClipboard</view>
+    <view class="page-section-demo">
+      <input onInput="bindInput" value="{{copy}}" disabled />
+      <button class="clipboard-button" type="default" size="mini" onTap="handlePaste">粘贴</button>
+    </view>
+  </view>
+</view>

+ 26 - 0
page/API/clipboard/clipboard.js

@@ -0,0 +1,26 @@
+Page({
+  data: {
+    text: '3.1415926',
+    copy: '',
+  },
+
+  handleInput(e) {
+    this.setData({
+      text: e.detail.value,
+    });
+  },
+
+  handleCopy() {
+    my.setClipboard({
+      text: this.data.text,
+    });
+  },
+
+  handlePaste() {
+    my.getClipboard({
+      success: ({ text }) => {
+        this.setData({ copy: text });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/clipboard/clipboard.json

@@ -0,0 +1,3 @@
+{
+  "defaultTitle": "Clipboard"
+}

+ 9 - 0
page/API/confirm/confirm.axml

@@ -0,0 +1,9 @@
+<view class="page">
+  <view class="page-description">确认框 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.confirm</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="comfirm">显示确认框</button>
+    </view>
+  </view>
+</view>

+ 15 - 0
page/API/confirm/confirm.js

@@ -0,0 +1,15 @@
+Page({
+  comfirm() {
+    my.confirm({
+      title: '温馨提示',
+      content: '您是否想查询快递单号:\n1234567890',
+      confirmButtonText: '马上查询',
+      cancelButtonText: '暂不需要',
+      success: (result) => {
+        my.alert({
+          title: `${result.confirm}`,
+        });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/confirm/confirm.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Confirm"
+}

+ 0 - 0
page/API/contact/contact.acss


+ 17 - 0
page/API/contact/contact.axml

@@ -0,0 +1,17 @@
+<view class="page">
+  <view class="page-description">联系人 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.choosePhoneContact</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="choosePhoneContact">唤起本地通讯录</button>
+    </view>
+  </view>
+  <view class="page-section">
+    <view class="page-section-title">my.chooseAlipayContact</view>
+    <view class="page-section-demo">
+      <button type="primary" onTap="chooseAlipayContact">唤起支付宝通讯录</button>
+    </view>
+  </view>
+</view>
+
+

+ 31 - 0
page/API/contact/contact.js

@@ -0,0 +1,31 @@
+Page({
+  choosePhoneContact() {
+    my.choosePhoneContact({
+      success: (res) => {
+        my.alert({
+          content: 'choosePhoneContact response: ' + JSON.stringify(res)
+        });
+      },
+      fail: (res) => {
+        my.alert({
+          content: 'choosePhoneContact response: ' + JSON.stringify(res)
+        });
+      }
+    });
+  },
+  chooseAlipayContact() {
+    my.chooseAlipayContact({
+      count: 2,
+      success: (res) => {
+        my.alert({
+          content: 'chooseAlipayContact response: ' + JSON.stringify(res)
+        });
+      },
+      fail: (res) => {
+        my.alert({
+          content: 'chooseAlipayContact response: ' + JSON.stringify(res)
+        });
+      }
+    });
+  },
+});

+ 3 - 0
page/API/contact/contact.json

@@ -0,0 +1,3 @@
+{
+   "defaultTitle": "Contact"
+}

+ 3 - 0
page/API/date-picker/date-picker.acss

@@ -0,0 +1,3 @@
+button + button {
+  margin-top: 20rpx;
+}

+ 11 - 0
page/API/date-picker/date-picker.axml

@@ -0,0 +1,11 @@
+<view class="page">
+  <view class="page-description">选择日期 API</view>
+  <view class="page-section">
+    <view class="page-section-title">my.datePicker</view>
+    <view class="page-section-demo">
+      <button class="page-body-button" type="primary" onTap="datePicker">选择日期-1</button>
+      <button class="page-body-button" type="primary" onTap="datePickerHMS">选择日期-2</button>
+      <button class="page-body-button" type="primary" onTap="datePickerYMDHMS">选择日期-3</button>
+    </view>
+  </view>
+</view>

+ 40 - 0
page/API/date-picker/date-picker.js

@@ -0,0 +1,40 @@
+Page({
+  datePicker() {
+    my.datePicker({
+      currentDate: '2016-10-10',
+      startDate: '2016-10-9',
+      endDate: '2017-10-9',
+      success: (res) => {
+        my.alert({
+          title: 'datePicker response: ' + JSON.stringify(res)
+        });
+      },
+    });
+  },
+  datePickerHMS() {
+    my.datePicker({
+      format: 'HH:mm:ss',
+      currentDate: '12:12:12',
+      startDate: '11:11:11',
+      endDate: '13:13:13',
+      success: (res) => {
+        my.alert({
+          title: 'datePicker response: ' + JSON.stringify(res)
+        });
+      },
+    });
+  },
+  datePickerYMDHMS() {
+    my.datePicker({
+      format: 'yyyy-MM-dd HH:mm:ss',
+      currentDate: '2012-01-09 11:11:11',
+      startDate: '2012-01-01 11:11:11',
+      endDate: '2012-01-10 11:11:11',
+      success: (res) => {
+        my.alert({
+          title: 'datePicker response: ' + JSON.stringify(res)
+        });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/date-picker/date-picker.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "Date Picker"
+}

+ 0 - 0
page/API/download-file/download-file.acss


+ 3 - 0
page/API/download-file/download-file.axml

@@ -0,0 +1,3 @@
+<view class="container">
+  <button onTap="download">下载图片并显示</button>
+</view>

+ 17 - 0
page/API/download-file/download-file.js

@@ -0,0 +1,17 @@
+Page({
+  download() {
+    my.downloadFile({
+      url: 'http://img.alicdn.com/tfs/TB1x669SXXXXXbdaFXXXXXXXXXX-520-280.jpg',
+      success({ apFilePath }) {
+        my.previewImage({
+          urls: [apFilePath],
+        });
+      },
+      fail(res) {
+        my.alert({
+          content: res.errorMessage || res.error,
+        });
+      },
+    });
+  },
+})

+ 3 - 0
page/API/download-file/download-file.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "下载文件"
+}

+ 30 - 0
page/API/file/file.acss

@@ -0,0 +1,30 @@
+.image {
+  width: 300rpx;
+  height: 300rpx;
+}
+.image-plus {
+  width: 150rpx;
+  height: 150rpx;
+  margin: 10rpx;
+  border: 1px solid #999;
+  position: relative;
+  justify-content: center;
+}
+.image-plus-horizontal {
+  align-self: center;
+  background-color: #d9d9d9;
+  width: 4rpx;
+  height: 80rpx;
+  justify-content: center;
+}
+.image-plus-vertical {
+  align-self: center;
+  background-color: #d9d9d9;
+  width: 80rpx;
+  height: 4rpx;
+}
+
+.page-body-info {
+  height: 400rpx;
+  padding-bottom: 50rpx; 
+}

+ 26 - 0
page/API/file/file.axml

@@ -0,0 +1,26 @@
+<view class="container">
+  <view class="page-body">
+    <view class="page-body-wrapper">
+      <view class="page-body-info">
+        <text class="page-body-text-small">请选择图片</text>
+        <block a:if="{{tempFilePath != ''}}">
+          <image src="{{tempFilePath}}" class="image"></image>
+        </block>
+        <block a:if="{{tempFilePath === '' && savedFilePath != ''}}">
+          <image src="{{savedFilePath}}" class="image"></image>
+        </block>
+        <block a:if="{{tempFilePath === '' && savedFilePath === ''}}">
+          <view class="image-plus" onTap="chooseImage">
+            <view class="image-plus-horizontal">
+              <view class="image-plus-vertical"></view>
+            </view>
+          </view>
+        </block>
+      </view>
+      <view class="page-body-buttons">
+        <button class="page-body-button" type="primary" onTap="saveFile">保存文件</button>
+        <button class="page-body-button" onTap="clear">删除文件</button>
+      </view>
+    </view>
+  </view>
+</view>

+ 70 - 0
page/API/file/file.js

@@ -0,0 +1,70 @@
+Page({
+  data: {
+    tempFilePath: '',
+    savedFilePath: '',
+    dialog: {
+      hidden: true
+    }
+  },
+  onLoad() {
+    my.getStorage({
+      success: (savedFilePath) => {
+        this.setData({
+          savedFilePath,
+        });
+      },
+    });
+  },
+  chooseImage() {
+    my.chooseImage({
+      count: 1,
+      success: (res) => {
+        this.setData({
+          tempFilePath: res.tempFilePaths[0]
+        })
+      }
+    })
+  },
+  saveFile() {
+    if (this.data.tempFilePath.length > 0) {
+      var that = this
+      my.saveFile({
+        tempFilePath: this.data.tempFilePath,
+        success(res) {
+          that.setData({
+            savedFilePath: res.savedFilePath
+          })
+          my.setStorage({ key: 'savedFilePath', data: res.savedFilePath })
+          that.setData({
+            dialog: {
+              title: '保存成功',
+              content: '下次进入应用时,此文件仍可用',
+              hidden: false
+            }
+          })
+        },
+        fail(res) {
+          that.setData({
+            dialog: {
+              title: '保存失败',
+              content: '应该是有 bug 吧',
+              hidden: false
+            }
+          })
+        }
+      })
+    }
+  },
+  clear() {
+    my.setStorage({ key: 'savedFilePath', data: '' })
+    this.setData({
+      tempFilePath: '',
+      savedFilePath: ''
+    })
+  },
+  confirm() {
+    this.setData({
+      'dialog.hidden': true
+    })
+  }
+})

+ 3 - 0
page/API/file/file.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "文件"
+}

+ 13 - 0
page/API/get-auth-code/get-auth-code.acss

@@ -0,0 +1,13 @@
+.page-body-wrapper {
+  margin-top: 200rpx;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  align-self: stretch;
+  padding: 0 50rpx;
+  box-sizing: border-box;
+}
+.page-body-button {
+  align-self: stretch;
+}

+ 7 - 0
page/API/get-auth-code/get-auth-code.axml

@@ -0,0 +1,7 @@
+<view class="page">
+  <view class="page-section">
+    <button type="primary" onTap="getAuthCode">
+      获取授权码
+    </button>
+  </view>
+</view>

+ 14 - 0
page/API/get-auth-code/get-auth-code.js

@@ -0,0 +1,14 @@
+Page({
+  onLoad() {},
+  data: {},
+  getAuthCode: () => {
+    my.getAuthCode({
+      scopes: 'auth_user',
+      success: ({ authCode }) => {
+        my.alert({
+          content: authCode,
+        });
+      },
+    });
+  },
+});

+ 3 - 0
page/API/get-auth-code/get-auth-code.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "获取授权码"
+}

+ 11 - 0
page/API/get-location/format-location.js

@@ -0,0 +1,11 @@
+function formatLocation(longitude, latitude) {
+  longitude = Number(longitude).toFixed(2)
+  latitude = Number(latitude).toFixed(2)
+
+  return {
+    longitude: longitude.toString().split('.'),
+    latitude: latitude.toString().split('.')
+  }
+}
+
+export default formatLocation

+ 15 - 0
page/API/get-location/get-location.acss

@@ -0,0 +1,15 @@
+.page-body-info {
+  height: 250rpx;
+}
+.page-body-text-small {
+  font-size: 24rpx;
+  color: #000;
+  margin-bottom: 100rpx;
+}
+.page-body-text-location {
+  display: flex;
+  font-size: 50rpx;
+}
+.page-body-text-location text {
+  margin: 10rpx;
+}

+ 21 - 0
page/API/get-location/get-location.axml

@@ -0,0 +1,21 @@
+<view class="page">
+  <view class="page-section">
+    <view class="page-section-demo">
+      <view>当前位置经纬度</view>
+      <block a:if="{{hasLocation === false}}">
+        <text>未获取</text>
+      </block>
+      <block a:if="{{hasLocation === true}}">
+        <view class="page-body-text-location">
+          <text>E{{location.longitude[0]}}°{{location.longitude[1]}}′</text>
+          <text>N{{location.latitude[0]}}°{{location.latitude[1]}}′</text>
+        </view>
+      </block>
+    </view>
+
+    <view class="page-section-btns">
+      <view onTap="getLocation">获取位置</view>
+      <view onTap="clear">清空</view>
+    </view>
+  </view>
+</view>

+ 30 - 0
page/API/get-location/get-location.js

@@ -0,0 +1,30 @@
+import formatLocation from './format-location.js';
+
+Page({
+  data: {
+    hasLocation: false,
+  },
+  getLocation() {
+    var that = this;
+    my.showLoading();
+    my.getLocation({
+      success(res) {
+        my.hideLoading();
+        console.log(res)
+        that.setData({
+          hasLocation: true,
+          location: formatLocation(res.longitude, res.latitude)
+        })
+      },
+      fail() {
+        my.hideLoading();
+        my.alert({ title: '定位失败' });
+      },
+    })
+  },
+  clear() {
+    this.setData({
+      hasLocation: false
+    })
+  }
+})

+ 3 - 0
page/API/get-location/get-location.json

@@ -0,0 +1,3 @@
+{
+    "defaultTitle": "获取位置"
+}

+ 7 - 0
page/API/get-network-type/get-network-type.acss

@@ -0,0 +1,7 @@
+.page-body-info {
+  height: 200rpx;
+}
+.page-body-text-network-type {
+  font-size: 80rpx;
+  font-family: Helvetica;
+}

+ 19 - 0
page/API/get-network-type/get-network-type.axml

@@ -0,0 +1,19 @@
+<view class="page">
+  <view class="page-section">
+    <view class="page-section-demo">
+      <view class="page-body-title">网络状态</view>
+      <block a:if="{{hasNetworkType === false}}">
+        <text class="page-body-text">未获取</text>
+        <text class="page-body-text">点击按钮可获取网络状态</text>
+      </block>
+      <block a:if="{{hasNetworkType === true}}">
+        <text class="page-body-text-network-type">{{networkType}}</text>
+      </block>
+    </view>
+
+    <view class="page-section-btns">
+      <view onTap="getNetworkType">获取手机网络状态</view>
+      <view onTap="clear">清空</view>
+    </view>
+  </view>
+</view>

+ 35 - 0
page/API/get-network-type/get-network-type.js

@@ -0,0 +1,35 @@
+Page({
+  data: {
+    hasNetworkType: false
+  },
+  onLoad() {
+    this.onChange = this.onChange.bind(this);
+    // my.onNetworkChange(this.onChange);
+  },
+  onChange(res){
+    console.log('onNetworkChange', res);
+    this.setData({
+      hasNetworkType: true,
+      networkType: res.networkType
+    });
+  },
+  onUnload() {
+    // my.offNetworkChange(this.onChange);
+  },
+  getNetworkType() {
+    my.getNetworkType({
+      success: (res) => {
+        this.setData({
+          hasNetworkType: true,
+          networkType: res.networkType
+        })
+      }
+    })
+  },
+  clear() {
+    this.setData({
+      hasNetworkType: false,
+      networkType: ''
+    })
+  },
+});

Some files were not shown because too many files changed in this diff