瀏覽代碼

feat: 添加入库功能

黎海 2 年之前
當前提交
ab1024b984
共有 97 個文件被更改,包括 11077 次插入0 次删除
  1. 16 0
      .gitignore
  2. 0 0
      README.md
  3. 19 0
      app.js
  4. 60 0
      app.json
  5. 27 0
      app.wxss
  6. 二進制
      audio/scanCode.mp3
  7. 37 0
      components/cloudTipModal/index.js
  8. 4 0
      components/cloudTipModal/index.json
  9. 13 0
      components/cloudTipModal/index.wxml
  10. 57 0
      components/cloudTipModal/index.wxss
  11. 66 0
      components/mineList.js
  12. 3 0
      components/mineList.json
  13. 2 0
      components/mineList.wxml
  14. 1 0
      components/mineList.wxss
  15. 34 0
      components/mineList/index.js
  16. 4 0
      components/mineList/index.json
  17. 11 0
      components/mineList/index.wxml
  18. 35 0
      components/mineList/index.wxss
  19. 6 0
      envList.js
  20. 二進制
      images/home.png
  21. 二進制
      images/mine.png
  22. 二進制
      images/order.png
  23. 二進制
      images/quality.png
  24. 二進制
      images/un_home.png
  25. 二進制
      images/un_mine.png
  26. 二進制
      images/un_order.png
  27. 二進制
      images/un_quality.png
  28. 18 0
      package-lock.json
  29. 16 0
      package.json
  30. 339 0
      pages/bleConnect/bleConnect.js
  31. 4 0
      pages/bleConnect/bleConnect.json
  32. 18 0
      pages/bleConnect/bleConnect.wxml
  33. 58 0
      pages/bleConnect/bleConnect.wxss
  34. 95 0
      pages/codeInput/codeInput.js
  35. 11 0
      pages/codeInput/codeInput.json
  36. 28 0
      pages/codeInput/codeInput.wxml
  37. 66 0
      pages/codeInput/codeInput.wxss
  38. 109 0
      pages/home/home.js
  39. 6 0
      pages/home/home.json
  40. 14 0
      pages/home/home.wxml
  41. 23 0
      pages/home/home.wxss
  42. 138 0
      pages/homePage/homePage.js
  43. 7 0
      pages/homePage/homePage.json
  44. 18 0
      pages/homePage/homePage.wxml
  45. 63 0
      pages/homePage/homePage.wxss
  46. 575 0
      pages/label/label.js
  47. 3 0
      pages/label/label.json
  48. 15 0
      pages/label/label.wxml
  49. 13 0
      pages/label/label.wxss
  50. 66 0
      pages/mine/mine.js
  51. 8 0
      pages/mine/mine.json
  52. 2 0
      pages/mine/mine.wxml
  53. 1 0
      pages/mine/mine.wxss
  54. 340 0
      pages/net/net.js
  55. 3 0
      pages/net/net.json
  56. 29 0
      pages/net/net.wxml
  57. 123 0
      pages/net/net.wxss
  58. 59 0
      pages/order/order.js
  59. 8 0
      pages/order/order.json
  60. 37 0
      pages/order/order.wxml
  61. 84 0
      pages/order/order.wxss
  62. 73 0
      pages/orderDetails/orderDetails.js
  63. 8 0
      pages/orderDetails/orderDetails.json
  64. 35 0
      pages/orderDetails/orderDetails.wxml
  65. 79 0
      pages/orderDetails/orderDetails.wxss
  66. 51 0
      pages/qualityTesting/qualityTesting.js
  67. 9 0
      pages/qualityTesting/qualityTesting.json
  68. 32 0
      pages/qualityTesting/qualityTesting.wxml
  69. 136 0
      pages/qualityTesting/qualityTesting.wxss
  70. 578 0
      pages/receipt/receipt.js
  71. 3 0
      pages/receipt/receipt.json
  72. 15 0
      pages/receipt/receipt.wxml
  73. 21 0
      pages/receipt/receipt.wxss
  74. 228 0
      pages/scanCode/scanCode.js
  75. 12 0
      pages/scanCode/scanCode.json
  76. 78 0
      pages/scanCode/scanCode.wxml
  77. 203 0
      pages/scanCode/scanCode.wxss
  78. 509 0
      pages/sendCommand/sendCommand.js
  79. 3 0
      pages/sendCommand/sendCommand.json
  80. 42 0
      pages/sendCommand/sendCommand.wxml
  81. 74 0
      pages/sendCommand/sendCommand.wxss
  82. 549 0
      pages/ticket/ticket.js
  83. 4 0
      pages/ticket/ticket.json
  84. 19 0
      pages/ticket/ticket.wxml
  85. 15 0
      pages/ticket/ticket.wxss
  86. 57 0
      project.config.json
  87. 57 0
      project.private.config.json
  88. 7 0
      sitemap.json
  89. 220 0
      utils/base64.js
  90. 47 0
      utils/encoding-indexes.js
  91. 3313 0
      utils/encoding.js
  92. 953 0
      utils/esc.js
  93. 90 0
      utils/gbk.js
  94. 88 0
      utils/http.js
  95. 30 0
      utils/tool.js
  96. 506 0
      utils/tsc.js
  97. 141 0
      utils/util.js

+ 16 - 0
.gitignore

@@ -0,0 +1,16 @@
1
+# Windows
2
+[Dd]esktop.ini
3
+Thumbs.db
4
+$RECYCLE.BIN/
5
+
6
+# macOS
7
+.DS_Store
8
+.fseventsd
9
+.Spotlight-V100
10
+.TemporaryItems
11
+.Trashes
12
+.idea
13
+
14
+# Node.js
15
+miniprogram_npm
16
+node_modules/

+ 0 - 0
README.md


+ 19 - 0
app.js

@@ -0,0 +1,19 @@
1
+// app.js
2
+App({
3
+  onLaunch: function () {
4
+    if (!wx.cloud) {
5
+      console.error('请使用 2.2.3 或以上的基础库以使用云能力');
6
+    } else {
7
+      wx.cloud.init({
8
+        // env 参数说明:
9
+        //   env 参数决定接下来小程序发起的云开发调用(wx.cloud.xxx)会默认请求到哪个云环境的资源
10
+        //   此处请填入环境 ID, 环境 ID 可打开云控制台查看
11
+        //   如不填则使用默认环境(第一个创建的环境)
12
+        // env: 'my-env-id',
13
+        traceUser: true,
14
+      });
15
+    }
16
+
17
+    this.globalData = {};
18
+  }
19
+});

+ 60 - 0
app.json

@@ -0,0 +1,60 @@
1
+{
2
+  "pages": [
3
+    "pages/homePage/homePage",
4
+    "pages/order/order",
5
+    "pages/orderDetails/orderDetails",
6
+    "pages/qualityTesting/qualityTesting",
7
+    "pages/mine/mine",
8
+    "pages/scanCode/scanCode",
9
+    "pages/home/home",
10
+    "pages/bleConnect/bleConnect",
11
+    "pages/sendCommand/sendCommand",
12
+    "pages/net/net",
13
+    "pages/ticket/ticket",
14
+    "pages/receipt/receipt",
15
+    "pages/label/label",
16
+    "pages/codeInput/codeInput",
17
+    "components/mineList",
18
+    "components/mineList/index"
19
+  ],
20
+  "window": {
21
+    "backgroundColor": "#F6F6F6",
22
+    "backgroundTextStyle": "light",
23
+    "navigationBarBackgroundColor": "#F6F6F6",
24
+    "navigationBarTitleText": "云开发 QuickStart",
25
+    "navigationBarTextStyle": "black"
26
+  },
27
+  "tabBar": {
28
+    "color": "#666666",
29
+    "selectedColor": "#333333",
30
+    "borderStyle": "white",
31
+    "backgroundColor": "#fff",
32
+    "list": [
33
+      {
34
+        "iconPath": "images/un_home.png",
35
+        "selectedIconPath": "images/home.png",
36
+        "pagePath": "pages/homePage/homePage",
37
+        "text": "首页"
38
+      },
39
+      {
40
+        "iconPath": "images/un_order.png",
41
+        "selectedIconPath": "images/order.png",
42
+        "pagePath": "pages/order/order",
43
+        "text": "订单"
44
+      },
45
+      {
46
+        "iconPath": "images/un_quality.png",
47
+        "selectedIconPath": "images/quality.png",
48
+        "pagePath": "pages/qualityTesting/qualityTesting",
49
+        "text": "质检"
50
+      },
51
+      {
52
+        "iconPath": "images/un_mine.png",
53
+        "selectedIconPath": "images/mine.png",
54
+        "pagePath": "pages/mine/mine",
55
+        "text": "我的"
56
+      }
57
+    ]
58
+  },
59
+  "sitemapLocation": "sitemap.json"
60
+}

+ 27 - 0
app.wxss

@@ -0,0 +1,27 @@
1
+/**app.wxss**/
2
+.container {
3
+  display: flex;
4
+  flex-direction: column;
5
+  align-items: center;
6
+  box-sizing: border-box;
7
+} 
8
+
9
+button {
10
+  background: initial;
11
+}
12
+
13
+button:focus{
14
+  outline: 0;
15
+}
16
+
17
+button::after{
18
+  border: none;
19
+}
20
+
21
+
22
+page {
23
+  background: #f6f6f6;
24
+  display: flex;
25
+  flex-direction: column;
26
+  justify-content: flex-start;
27
+}

二進制
audio/scanCode.mp3


+ 37 - 0
components/cloudTipModal/index.js

@@ -0,0 +1,37 @@
1
+// miniprogram/components/cloudTipModal/index.js
2
+const { isMac } = require('../../envList.js');
3
+
4
+Component({
5
+
6
+  /**
7
+   * 页面的初始数据
8
+   */
9
+  data: {
10
+    showUploadTip: false,
11
+    tipText: isMac ? 'sh ./uploadCloudFunction.sh' : './uploadCloudFunction.bat'
12
+  },
13
+  properties: {
14
+    showUploadTipProps: Boolean
15
+  },
16
+  observers: {
17
+    showUploadTipProps: function(showUploadTipProps) {
18
+      this.setData({
19
+        showUploadTip: showUploadTipProps
20
+      });
21
+    }
22
+  },
23
+  methods: {
24
+    onChangeShowUploadTip() {
25
+      this.setData({
26
+        showUploadTip: !this.data.showUploadTip
27
+      });
28
+    },
29
+
30
+    copyShell() {
31
+      wx.setClipboardData({
32
+        data: this.data.tipText,
33
+      });
34
+    },
35
+  }
36
+
37
+});

+ 4 - 0
components/cloudTipModal/index.json

@@ -0,0 +1,4 @@
1
+{
2
+  "usingComponents": {},
3
+  "component": true
4
+}

+ 13 - 0
components/cloudTipModal/index.wxml

@@ -0,0 +1,13 @@
1
+<!--miniprogram/components/cloudTipModal/index.wxml-->
2
+<view class="install_tip" wx:if="{{showUploadTip}}">
3
+  <view class="install_tip_back"></view>
4
+  <view class="install_tip_detail">
5
+    <view class="install_tip_detail_title">体验前需部署云资源</view>
6
+    <view class="install_tip_detail_tip">请开启调试器进入终端窗口,复制并运行以下命令</view>
7
+    <view class="install_tip_detail_shell">
8
+      {{tipText}}
9
+      <view bindtap="copyShell" class="install_tip_detail_copy">复制</view>
10
+    </view>
11
+    <view bindtap="onChangeShowUploadTip" class="install_tip_detail_button">已执行命令</view>
12
+  </view>
13
+</view>

+ 57 - 0
components/cloudTipModal/index.wxss

@@ -0,0 +1,57 @@
1
+.install_tip_back {
2
+  position: fixed;
3
+  top: 0;
4
+  right: 0;
5
+  bottom: 0;
6
+  left: 0;
7
+  background-color: rgba(0,0,0,0.4);
8
+  z-index: 1;
9
+}
10
+
11
+.install_tip_detail {
12
+  position: fixed;
13
+  background-color: white;
14
+  right: 0;
15
+  bottom: 0;
16
+  left: 0;
17
+  top: 60%;
18
+  border-radius: 40rpx 40rpx 0 0;
19
+  padding: 50rpx;
20
+  z-index: 9;
21
+}
22
+
23
+.install_tip_detail_title {
24
+  font-weight: 400;
25
+  font-size: 40rpx;
26
+  text-align: center;
27
+}
28
+
29
+.install_tip_detail_tip {
30
+  font-size: 25rpx;
31
+  color: rgba(0,0,0,0.4);
32
+  margin-top: 20rpx;
33
+  text-align: center;
34
+}
35
+
36
+.install_tip_detail_shell {
37
+  margin: 70rpx 0;
38
+  display: flex;
39
+  justify-content: center;
40
+}
41
+
42
+.install_tip_detail_copy {
43
+  color: #546488;
44
+  margin-left: 10rpx;
45
+}
46
+
47
+.install_tip_detail_button {
48
+  color: #07C160;
49
+  font-weight: 500;
50
+  background-color: rgba(0,0,0,0.1);
51
+  width: 60%;
52
+  text-align: center;
53
+  height: 90rpx;
54
+  line-height: 90rpx;
55
+  border-radius: 10rpx;
56
+  margin: 0 auto;
57
+}

+ 66 - 0
components/mineList.js

@@ -0,0 +1,66 @@
1
+// components/mineList.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+
9
+  },
10
+
11
+  /**
12
+   * 生命周期函数--监听页面加载
13
+   */
14
+  onLoad: function (options) {
15
+
16
+  },
17
+
18
+  /**
19
+   * 生命周期函数--监听页面初次渲染完成
20
+   */
21
+  onReady: function () {
22
+
23
+  },
24
+
25
+  /**
26
+   * 生命周期函数--监听页面显示
27
+   */
28
+  onShow: function () {
29
+
30
+  },
31
+
32
+  /**
33
+   * 生命周期函数--监听页面隐藏
34
+   */
35
+  onHide: function () {
36
+
37
+  },
38
+
39
+  /**
40
+   * 生命周期函数--监听页面卸载
41
+   */
42
+  onUnload: function () {
43
+
44
+  },
45
+
46
+  /**
47
+   * 页面相关事件处理函数--监听用户下拉动作
48
+   */
49
+  onPullDownRefresh: function () {
50
+
51
+  },
52
+
53
+  /**
54
+   * 页面上拉触底事件的处理函数
55
+   */
56
+  onReachBottom: function () {
57
+
58
+  },
59
+
60
+  /**
61
+   * 用户点击右上角分享
62
+   */
63
+  onShareAppMessage: function () {
64
+
65
+  }
66
+})

+ 3 - 0
components/mineList.json

@@ -0,0 +1,3 @@
1
+{
2
+  "usingComponents": {}
3
+}

+ 2 - 0
components/mineList.wxml

@@ -0,0 +1,2 @@
1
+<!--components/mineList.wxml-->
2
+<text>components/mineList.wxml</text>

+ 1 - 0
components/mineList.wxss

@@ -0,0 +1 @@
1
+/* components/mineList.wxss */

+ 34 - 0
components/mineList/index.js

@@ -0,0 +1,34 @@
1
+// components/mineList/index.js
2
+Component({
3
+  /**
4
+   * 组件的属性列表
5
+   */
6
+  properties: {
7
+    name: {
8
+      type: String,
9
+      value: ''
10
+    },
11
+    item: {
12
+      type: String,
13
+      value: ''
14
+    },
15
+    disabled: {
16
+      type: Boolean,
17
+      value: false
18
+    }
19
+  },
20
+
21
+  /**
22
+   * 组件的初始数据
23
+   */
24
+  data: {
25
+
26
+  },
27
+
28
+  /**
29
+   * 组件的方法列表
30
+   */
31
+  methods: {
32
+
33
+  }
34
+})

+ 4 - 0
components/mineList/index.json

@@ -0,0 +1,4 @@
1
+{
2
+  "component": true,
3
+  "usingComponents": {}
4
+}

+ 11 - 0
components/mineList/index.wxml

@@ -0,0 +1,11 @@
1
+<view class="list">
2
+  <view class="left">
3
+    {{name}}
4
+  </view>
5
+  <view class="right">
6
+    <text>{{item}}</text>
7
+    <view class="icon" hidden="{{!disabled}}">
8
+      <image src="https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/next.png"></image>
9
+    </view>
10
+  </view>
11
+</view>

+ 35 - 0
components/mineList/index.wxss

@@ -0,0 +1,35 @@
1
+/* components/mineList/index.wxss */
2
+.list {
3
+  height: 112rpx;
4
+  display: flex;
5
+  justify-content: space-between;
6
+  align-items: center;
7
+  padding: 0 28rpx;
8
+}
9
+
10
+.list .left {
11
+  font-family: PingFangSC-Regular;
12
+  font-size: 16px;
13
+  color: #333333;
14
+  letter-spacing: 0;
15
+}
16
+
17
+.list .right {
18
+  display: flex;
19
+  justify-content: space-between;
20
+}
21
+.list .right .icon{
22
+  margin-left: 20rpx;
23
+
24
+}
25
+
26
+.list .right text {
27
+  font-family: PingFangSC-Regular;
28
+  font-size: 28rpx;
29
+  color: #333333;
30
+  letter-spacing: 0;
31
+}
32
+.list .right image{
33
+  width: 12rpx;
34
+  height: 24rpx;
35
+}

+ 6 - 0
envList.js

@@ -0,0 +1,6 @@
1
+const envList = [{"envId":"cloud1-9g8zu4s7d2df7bd7","alias":"cloud1"}]
2
+const isMac = true
3
+module.exports = {
4
+    envList,
5
+    isMac
6
+}

二進制
images/home.png


二進制
images/mine.png


二進制
images/order.png


二進制
images/quality.png


二進制
images/un_home.png


二進制
images/un_mine.png


二進制
images/un_order.png


二進制
images/un_quality.png


+ 18 - 0
package-lock.json

@@ -0,0 +1,18 @@
1
+{
2
+  "name": "erp_phone_demo",
3
+  "version": "1.0.0",
4
+  "lockfileVersion": 1,
5
+  "requires": true,
6
+  "dependencies": {
7
+    "@vant/weapp": {
8
+      "version": "1.10.2",
9
+      "resolved": "https://registry.npmjs.org/@vant/weapp/-/weapp-1.10.2.tgz",
10
+      "integrity": "sha512-caqA0xQxM4lMRncFsRPPVMDdEzUBCJ4xdFXuKReXpEU3qwnVIP/WIjVDIi7mWyS7xqz8C9WfSW5JL4PrlSq31w=="
11
+    },
12
+    "vant-weapp": {
13
+      "version": "0.5.29",
14
+      "resolved": "https://registry.npmjs.org/vant-weapp/-/vant-weapp-0.5.29.tgz",
15
+      "integrity": "sha512-RMc0Ga914XFwspw2WuOMU8bOHlIkua8X1DoQ/KPnGQzjwT1uEL4S7W186EmaHF1wN2krB9BVd0LdRRt39dGh6Q=="
16
+    }
17
+  }
18
+}

+ 16 - 0
package.json

@@ -0,0 +1,16 @@
1
+{
2
+  "name": "erp_phone",
3
+  "version": "1.0.0",
4
+  "description": "lihai",
5
+  "main": "app.js",
6
+  "dependencies": {
7
+    "@vant/weapp": "^1.10.2",
8
+    "vant-weapp": "^0.5.29"
9
+  },
10
+  "devDependencies": {},
11
+  "scripts": {
12
+    "test": "echo \"Error: no test specified\" && exit 1"
13
+  },
14
+  "author": "lihai",
15
+  "license": "ISC"
16
+}

+ 339 - 0
pages/bleConnect/bleConnect.js

@@ -0,0 +1,339 @@
1
+// pages/blueconn/blueconn.js
2
+var app = getApp()
3
+Page({
4
+
5
+  /**
6
+   * 页面的初始数据
7
+   */
8
+  data: {
9
+    list: [],
10
+    services: [],
11
+    serviceId: 0,
12
+    writeCharacter: false,
13
+    readCharacter: false,
14
+    notifyCharacter: false,
15
+    isScanning:false
16
+  },
17
+  //搜索设备
18
+  startSearch: function () {
19
+    var that = this
20
+    wx.openBluetoothAdapter({
21
+      success: function (res) {
22
+        wx.getBluetoothAdapterState({
23
+          success: function (res) {
24
+            console.log('openBluetoothAdapter success', res)
25
+            if (res.available) {
26
+              if (res.discovering) {
27
+                wx.stopBluetoothDevicesDiscovery({
28
+                  success: function (res) {
29
+                    console.log(res)
30
+                  }
31
+                })
32
+              }else{
33
+                // that.startBluetoothDevicesDiscovery()
34
+                that.getBluetoothDevices()
35
+              }
36
+              // that.checkPemission()
37
+            } else {
38
+              wx.showModal({
39
+                title: '提示',
40
+                content: '本机蓝牙不可用',
41
+                showCancel: false
42
+              })
43
+            }
44
+          },
45
+        })
46
+      }, fail: function () {
47
+
48
+        // if (res.errCode === 10001) {
49
+        //   wx.onBluetoothAdapterStateChange(function (res) {
50
+        //     console.log('onBluetoothAdapterStateChange', res)
51
+        //     if (res.available) {
52
+        //       this.startBluetoothDevicesDiscovery()
53
+        //     }
54
+        //   })
55
+        // }
56
+
57
+        wx.showModal({
58
+          title: '提示',
59
+          content: '蓝牙初始化失败,请到设置打开蓝牙',
60
+          showCancel: false
61
+        })
62
+      }
63
+    })
64
+  },
65
+  checkPemission: function () {  //android 6.0以上需授权地理位置权限
66
+    var that = this
67
+    var platform = app.BLEInformation.platform
68
+    if (platform == "ios") {
69
+      app.globalData.platform = "ios"
70
+      that.getBluetoothDevices()
71
+    } else if (platform == "android") {
72
+      app.globalData.platform = "android"
73
+      console.log(app.getSystem().substring(app.getSystem().length - (app.getSystem().length - 8), app.getSystem().length - (app.getSystem().length - 8) + 1))
74
+      if (app.getSystem().substring(app.getSystem().length - (app.getSystem().length - 8), app.getSystem().length - (app.getSystem().length - 8) + 1) > 5) {
75
+        wx.getSetting({
76
+          success: function (res) {
77
+            console.log(res)
78
+            if (!res.authSetting['scope.userLocation']) {
79
+              wx.authorize({
80
+                scope: 'scope.userLocation',
81
+                complete: function (res) {
82
+                  that.getBluetoothDevices()
83
+                }
84
+              })
85
+            } else {
86
+              that.getBluetoothDevices()
87
+            }
88
+          }
89
+        })
90
+      }
91
+    }
92
+  },
93
+  getBluetoothDevices: function () {  //获取蓝牙设备信息
94
+    var that = this
95
+    console.log("start search")
96
+    wx.showLoading({
97
+      title: '正在加载',
98
+      icon: 'loading',
99
+    })
100
+    that.setData({
101
+      isScanning:true
102
+    })
103
+    wx.startBluetoothDevicesDiscovery({
104
+      success: function (res) {
105
+        console.log(res)
106
+        setTimeout(function () {
107
+          wx.getBluetoothDevices({
108
+            success: function (res) {
109
+              var devices = []
110
+              var num = 0
111
+              for (var i = 0; i < res.devices.length; ++i) {
112
+                if (res.devices[i].name != "未知设备") {
113
+                  devices[num] = res.devices[i]
114
+                  num++
115
+                }
116
+              }
117
+              that.setData({
118
+                list: devices,
119
+                isScanning:false
120
+              })
121
+              wx.hideLoading()
122
+              wx.stopPullDownRefresh()
123
+              wx.stopBluetoothDevicesDiscovery({
124
+                success: function (res) {
125
+                  console.log("停止搜索蓝牙")
126
+                }
127
+              })
128
+            },
129
+          })
130
+        }, 5000)
131
+      },
132
+    })
133
+  },
134
+  bindViewTap: function (e) {
135
+    var that = this
136
+    wx.stopBluetoothDevicesDiscovery({
137
+      success: function (res) { console.log(res) },
138
+    })
139
+    that.setData({
140
+      serviceId: 0,
141
+      writeCharacter: false,
142
+      readCharacter: false,
143
+      notifyCharacter: false
144
+    })
145
+    console.log(e.currentTarget.dataset.title)
146
+    wx.showLoading({
147
+      title: '正在连接',
148
+      
149
+    })
150
+    wx.createBLEConnection({
151
+      deviceId: e.currentTarget.dataset.title,
152
+      success: function (res) {
153
+        console.log(res)
154
+        app.BLEInformation.deviceId = e.currentTarget.dataset.title
155
+        that.getSeviceId()
156
+      }, fail: function (e) {
157
+        wx.showModal({
158
+          title: '提示',
159
+          content: '连接失败',
160
+          showCancel: false
161
+        })
162
+        console.log(e)
163
+        wx.hideLoading()
164
+      }, complete: function (e) {
165
+        console.log(e)
166
+      }
167
+    })
168
+  },
169
+  getSeviceId: function () {
170
+    var that = this
171
+    var platform = app.BLEInformation.platform
172
+    console.log(app.BLEInformation.deviceId)
173
+    wx.getBLEDeviceServices({
174
+      deviceId: app.BLEInformation.deviceId,
175
+      success: function (res) {
176
+        console.log(res)
177
+        // var realId = ''
178
+        // if (platform == 'android') {
179
+        //   // for(var i=0;i<res.services.length;++i){
180
+        //   // var item = res.services[i].uuid
181
+        //   // if (item == "0000FEE7-0000-1000-8000-00805F9B34FB"){
182
+        //   realId = "0000FEE7-0000-1000-8000-00805F9B34FB"
183
+        //   //       break;
184
+        //   //     }
185
+        //   // }
186
+        // } else if (platform == 'ios') {
187
+        //   // for(var i=0;i<res.services.length;++i){
188
+        //   // var item = res.services[i].uuid
189
+        //   // if (item == "49535343-FE7D-4AE5-8FA9-9FAFD205E455"){
190
+        //   realId = "49535343-FE7D-4AE5-8FA9-9FAFD205E455"
191
+        //   // break
192
+        //   // }
193
+        //   // }
194
+        // }
195
+        // app.BLEInformation.serviceId = realId
196
+        that.setData({
197
+          services: res.services
198
+        })
199
+        that.getCharacteristics()
200
+      }, fail: function (e) {
201
+        console.log(e)
202
+      }, complete: function (e) {
203
+        console.log(e)
204
+      }
205
+    })
206
+  },
207
+  getCharacteristics: function () {
208
+    var that = this
209
+    var list = that.data.services
210
+    var num = that.data.serviceId
211
+    var write = that.data.writeCharacter
212
+    var read = that.data.readCharacter
213
+    var notify = that.data.notifyCharacter
214
+    wx.getBLEDeviceCharacteristics({
215
+      deviceId: app.BLEInformation.deviceId,
216
+      serviceId: list[num].uuid,
217
+      success: function (res) {
218
+        console.log(res)
219
+        for (var i = 0; i < res.characteristics.length; ++i) {
220
+          var properties = res.characteristics[i].properties
221
+          var item = res.characteristics[i].uuid
222
+          if (!notify) {
223
+            if (properties.notify) {
224
+              app.BLEInformation.notifyCharaterId = item
225
+              app.BLEInformation.notifyServiceId = list[num].uuid
226
+              notify = true
227
+            }
228
+          }
229
+          if (!write) {
230
+            if (properties.write) {
231
+              app.BLEInformation.writeCharaterId = item
232
+              app.BLEInformation.writeServiceId = list[num].uuid
233
+              write = true
234
+            }
235
+          }
236
+          if (!read) {
237
+            if (properties.read) {
238
+              app.BLEInformation.readCharaterId = item
239
+              app.BLEInformation.readServiceId = list[num].uuid
240
+              read = true
241
+            }
242
+          }
243
+        }
244
+        if (!write || !notify || !read) {
245
+          num++
246
+          that.setData({
247
+            writeCharacter: write,
248
+            readCharacter: read,
249
+            notifyCharacter: notify,
250
+            serviceId: num
251
+          })
252
+          if (num == list.length) {
253
+            wx.showModal({
254
+              title: '提示',
255
+              content: '找不到该读写的特征值',
256
+              showCancel: false
257
+            })
258
+          } else {
259
+            that.getCharacteristics()
260
+          }
261
+        } else {
262
+          wx.showToast({
263
+            title: '连接成功',
264
+          })
265
+          that.openControl()
266
+        }
267
+      }, fail: function (e) {
268
+        console.log(e)
269
+      }, complete: function (e) {
270
+        console.log("write:" + app.BLEInformation.writeCharaterId)
271
+        console.log("read:" + app.BLEInformation.readCharaterId)
272
+        console.log("notify:" + app.BLEInformation.notifyCharaterId)
273
+      }
274
+    })
275
+  },
276
+   openControl: function () {//连接成功返回主页
277
+    wx.navigateTo({
278
+      url: '../home/home',
279
+    })
280
+
281
+  },
282
+  /**
283
+   * 生命周期函数--监听页面加载
284
+   */
285
+  onLoad: function (options) {
286
+    app.BLEInformation.platform = app.getPlatform()
287
+  },
288
+
289
+  /**
290
+   * 生命周期函数--监听页面初次渲染完成
291
+   */
292
+  onReady: function () {
293
+
294
+  },
295
+
296
+  /**
297
+   * 生命周期函数--监听页面显示
298
+   */
299
+  onShow: function () {
300
+
301
+  },
302
+
303
+  /**
304
+   * 生命周期函数--监听页面隐藏
305
+   */
306
+  onHide: function () {
307
+
308
+  },
309
+
310
+  /**
311
+   * 生命周期函数--监听页面卸载
312
+   */
313
+  onUnload: function () {
314
+
315
+  },
316
+
317
+  // /**
318
+  //  * 页面相关事件处理函数--监听用户下拉动作
319
+  //  */
320
+  // onPullDownRefresh: function () {
321
+  //     // var that = this
322
+  //     // wx.startPullDownRefresh({})
323
+  //     // that.startSearch()
324
+  // },
325
+
326
+  /**
327
+   * 页面上拉触底事件的处理函数
328
+   */
329
+  onReachBottom: function () {
330
+
331
+  },
332
+
333
+  /**
334
+   * 用户点击右上角分享
335
+   */
336
+  onShareAppMessage: function () {
337
+
338
+  }
339
+})

+ 4 - 0
pages/bleConnect/bleConnect.json

@@ -0,0 +1,4 @@
1
+{
2
+  "navigationBarTitleText": "蓝牙",
3
+  "enablePullDownRefresh" : true
4
+}

+ 18 - 0
pages/bleConnect/bleConnect.wxml

@@ -0,0 +1,18 @@
1
+<button class='button'  hover-class="hover" bindtap="startSearch" loading='{{isScanning}}'> 搜索蓝牙设备 </button>
2
+<text class=".td">(Android8.0+系统需开启定位)</text> 
3
+<scroll-view class="device_list" scroll-y scroll-with-animation >
4
+  <view  wx:for="{{list}}" wx:for-item="item" 
5
+         data-title="{{item.deviceId}}" 
6
+         data-name="{{item.name}}" 
7
+         data-advertisData="{{item.advertisServiceUUIDs}}" 
8
+         wx:key="{{item.deviceId}}"
9
+         bindtap="bindViewTap"
10
+         class="item" hover-class="item_hover">
11
+     <view  style="font-size: 16px; color: #333;">{{item.name}}</view>
12
+     <view  style="font-size: 16px; color: #333;" >{{item.deviceId}}</view>  
13
+     <view style="font-size: 10px">信号强度: {{item.RSSI}}dBm 
14
+		 <!-- ({{utils.max(0, item.RSSI + 100)}}%) -->
15
+		 </view>  
16
+</view>  
17
+</scroll-view>
18
+ 

+ 58 - 0
pages/bleConnect/bleConnect.wxss

@@ -0,0 +1,58 @@
1
+.button {
2
+  margin-top: 20px;
3
+  width: 90%;
4
+  background-color: #54bec2;
5
+  color: white;
6
+  border-radius: 98rpx;
7
+  background: bg_red;
8
+}
9
+ 
10
+/* 按下变颜色 */
11
+.hover {
12
+  background:  #DCDCDC;
13
+}
14
+
15
+.device_list {
16
+  height: auto;
17
+  margin-left: 20px;
18
+  margin-right: 20px;
19
+  margin-top: 10px;
20
+  margin-bottom: 20px;
21
+  border: 1px solid #EEE;
22
+  border-radius: 5px;
23
+  width: auto;
24
+}
25
+.td {
26
+  display: flex;
27
+  align-items: center;
28
+  justify-content: center;
29
+   margin-top: 10px;
30
+}
31
+/* .item {
32
+    padding-top: 10px;
33
+    padding-bottom: 10px;
34
+     height: 130rpx;
35
+     width: 100%;
36
+} */
37
+.item{
38
+ display: block;
39
+  /* font-family:  Arial, Helvetica, sans-serif;
40
+  font-size:14px;
41
+  margin: 0 10px;
42
+  margin-top:10px;
43
+  margin-bottom: 10px;
44
+  background-color:#FFA850; 
45
+  border-radius: 5px;
46
+  border-bottom: 2px solid #68BAEA; */
47
+  border-bottom: 1px solid #EEE;
48
+  padding: 4px;
49
+  color: #666;
50
+}
51
+.item_hover {
52
+  background-color: rgba(0, 0, 0, .1);
53
+}
54
+.block{
55
+    display: block;
56
+    color:#ffffff;
57
+    padding: 5px;
58
+}/* pages/bleConnect/bleConnect.wxss */

+ 95 - 0
pages/codeInput/codeInput.js

@@ -0,0 +1,95 @@
1
+// pages/codeInput/codeInput.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+    isSupplier: false, //供应商选择器
9
+    isProductType: false, //产品类型选择器
10
+    isAfterSale: false, //售后类型选择
11
+    supplierList: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
12
+    wareInfo: {
13
+      supplier: "",
14
+      product: "",
15
+      num: "",
16
+      price: '',
17
+      afterSale: "",
18
+      message: ""
19
+    }
20
+  },
21
+
22
+  /**
23
+   * 生命周期函数--监听页面加载
24
+   */
25
+  onLoad: function (options) {
26
+
27
+  },
28
+
29
+  /**
30
+   * 生命周期函数--监听页面初次渲染完成
31
+   */
32
+  onReady: function () {
33
+
34
+  },
35
+
36
+  /**
37
+   * 生命周期函数--监听页面显示
38
+   */
39
+  onShow: function () {
40
+
41
+  },
42
+  onOpenSupplier() {
43
+    this.setData({
44
+      isSupplier: true
45
+    })
46
+  },
47
+  onCancel() {
48
+    this.setData({
49
+      isSupplier: false
50
+    })
51
+  },
52
+  onConfirm(e) {
53
+    console.log(e);
54
+    this.setData({
55
+      isSupplier: false,
56
+      'wareInfo.supplier': e.detail.value
57
+    })
58
+  },
59
+  onProduct() {
60
+    this.setData({
61
+      isProductType: true
62
+    })
63
+  },
64
+  onCancelProduct() {
65
+    this.setData({
66
+      isProductType: false
67
+    })
68
+  },
69
+  onConfirmProduct(e) {
70
+    console.log(e);
71
+    this.setData({
72
+      isProductType: false,
73
+      'wareInfo.product': e.detail.value
74
+    })
75
+  },
76
+  onAfterSale() {
77
+    this.setData({
78
+      isAfterSale: true,
79
+    })
80
+  },
81
+  onCancelAfterSale() {
82
+    this.setData({
83
+      isAfterSale: false,
84
+    })
85
+  },
86
+  onConfirmAfterSale(e) {
87
+    this.setData({
88
+      isAfterSale: false,
89
+      'wareInfo.afterSale': e.detail.value
90
+    })
91
+  },
92
+  submit() {
93
+
94
+  }
95
+})

+ 11 - 0
pages/codeInput/codeInput.json

@@ -0,0 +1,11 @@
1
+{ 
2
+  "navigationBarTitleText": "入库信息录入",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "mine-list":"../../components/mineList/index",
7
+    "van-field": "@vant/weapp/field/index",
8
+    "van-popup": "@vant/weapp/popup/index",
9
+    "van-picker": "@vant/weapp/picker/index"
10
+  }
11
+}

+ 28 - 0
pages/codeInput/codeInput.wxml

@@ -0,0 +1,28 @@
1
+<view class="mine">
2
+  <view class="tab-content">
3
+    <mine-list style="" name="批次序号" item="367874974"></mine-list>
4
+    <mine-list name="供应商选择" bindtap="onOpenSupplier" item="{{wareInfo.supplier}}" disabled="{{true}}"></mine-list>
5
+    <mine-list name="产品类型选择"  bindtap="onProduct"  item="{{wareInfo.product}}" disabled="{{true}}"></mine-list>
6
+    <van-field value="{{wareInfo.num}}" input-align="right" placeholder="输入数量" label="入库数量" border="{{ false }}" />
7
+  </view>
8
+  <view class="price">
9
+    <van-field value="{{wareInfo.price}}" placeholder="输入价格" border="{{ false }}" />
10
+  </view>
11
+  <view class="cloise">
12
+    <mine-list name="售后类型选择" bindtap="onAfterSale" item="{{wareInfo.afterSale}}" disabled="{{true}}"></mine-list>
13
+  </view>
14
+  <view class="remarks">
15
+    <van-field value="{{ wareInfo.message }}" type="textarea" placeholder="输入备注" autosize border="{{ false }}" />
16
+  </view>
17
+  <van-popup show="{{ isSupplier }}" round position="bottom">
18
+    <van-picker columns="{{ supplierList }}" bind:cancel="onCancel" bind:confirm="onConfirm" title="供应商选择" show-toolbar />
19
+  </van-popup>
20
+  <van-popup show="{{ isProductType }}" round position="bottom">
21
+    <van-picker columns="{{ supplierList }}" bind:cancel="onCancelProduct" bind:confirm="onConfirmProduct" title="产品类型选择" show-toolbar />
22
+  </van-popup>
23
+  <van-popup show="{{ isAfterSale }}" round position="bottom">
24
+    <van-picker columns="{{ supplierList }}" bind:cancel="onCancelAfterSale" bind:confirm="onConfirmAfterSale" title="售后类型选择" show-toolbar />
25
+  </van-popup>
26
+
27
+  <view class="bottom-confirm" bindtap="submit">确定</view>
28
+</view>

+ 66 - 0
pages/codeInput/codeInput.wxss

@@ -0,0 +1,66 @@
1
+/* pages/codeInput/codeInput.wxss */
2
+.mine {
3
+  padding: 26rpx 30rpx 104rpx 30rpx;
4
+  position: relative;
5
+}
6
+
7
+.tab-content {
8
+  background: #FFFFFF;
9
+  border-radius: 8px;
10
+  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
11
+}
12
+
13
+.price {
14
+  margin-top: 20rpx;
15
+  background: #FFFFFF;
16
+  border-radius: 8px;
17
+  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
18
+}
19
+
20
+.van-cell {
21
+  border-radius: 8px;
22
+  padding-top: 34rpx !important;
23
+  padding-bottom: 34rpx !important;
24
+}
25
+
26
+.van-field__label {
27
+  font-size: 16px !important;
28
+  font-family: PingFangSC-Regular !important;
29
+  color: #333333 !important;
30
+}
31
+
32
+.van-field__control {
33
+  font-size: 16px !important;
34
+  font-family: PingFangSC-Regular !important;
35
+  color: #333333 !important;
36
+}
37
+
38
+.cloise {
39
+  margin-top: 20rpx;
40
+  background: #FFFFFF;
41
+  border-radius: 8px;
42
+}
43
+
44
+.remarks {
45
+  margin-top: 20rpx;
46
+  background: #FFFFFF;
47
+  border-radius: 8px;
48
+  height: 412rpx;
49
+}
50
+
51
+.bottom-confirm {
52
+  width: 626rpx;
53
+  height: 96rpx;
54
+  line-height: 96rpx;
55
+  background: #0271E3;
56
+  border-radius: 52rpx;
57
+  text-align: center;
58
+  font-family: PingFangSC-Regular;
59
+  font-size: 36rpx;
60
+  color: #FFFFFF;
61
+  letter-spacing: 0;
62
+  margin-top: 72rpx;
63
+  position: relative;
64
+  left: 50%;
65
+  transform: translateX(-50%);
66
+}

+ 109 - 0
pages/home/home.js

@@ -0,0 +1,109 @@
1
+// pages/blueconn/blueconn.js
2
+var app = getApp()
3
+Page({
4
+
5
+  /**
6
+   * 页面的初始数据
7
+   */
8
+  data: {
9
+    list: [],
10
+  },
11
+  blueTooth:function(){
12
+    wx.navigateTo({
13
+      url: '../bleConnect/bleConnect',
14
+    })
15
+  },
16
+  //打印指令页面
17
+  printTest: function () {
18
+    wx.navigateTo({
19
+      url: '../sendCommand/sendCommand',
20
+    })
21
+  },
22
+  //小票案例
23
+  recipt: function () {
24
+    wx.navigateTo({
25
+      url: '../receipt/receipt',
26
+    })
27
+  },
28
+  //标签案例
29
+  label: function () {
30
+    wx.navigateTo({
31
+      url: '../label/label',
32
+    })
33
+  },
34
+  //蓝牙配网页面
35
+  blueToothNet: function () {
36
+    wx.navigateTo({
37
+      url: '../net/net',
38
+    })
39
+  },
40
+  //打印彩票
41
+  lotteryTicket: function () {
42
+    wx.navigateTo({
43
+      url: '../ticket/ticket',
44
+    })
45
+  },
46
+
47
+  /**
48
+   * 生命周期函数--监听页面加载
49
+   */
50
+  onLoad: function (options) {
51
+    app.BLEInformation.platform = app.getPlatform()
52
+  },
53
+
54
+  /**
55
+   * 生命周期函数--监听页面初次渲染完成
56
+   */
57
+  onReady: function () {
58
+
59
+  },
60
+
61
+  /**
62
+   * 生命周期函数--监听页面显示
63
+   */
64
+  onShow: function () {
65
+
66
+  },
67
+
68
+  /**
69
+   * 生命周期函数--监听页面隐藏
70
+   */
71
+  onHide: function () {
72
+
73
+  },
74
+
75
+  /**
76
+   * 生命周期函数--监听页面卸载
77
+   */
78
+  onUnload: function () {
79
+  wx.closeBLEConnection({
80
+      deviceId: app.BLEInformation.deviceId,
81
+      success: function(res) {
82
+        console.log("关闭蓝牙成功")
83
+      },
84
+    })
85
+  },
86
+
87
+  // /**
88
+  //  * 页面相关事件处理函数--监听用户下拉动作
89
+  //  */
90
+  // onPullDownRefresh: function () {
91
+  //   var that = this
92
+  //   wx.startPullDownRefresh({})
93
+  //   that.startSearch()
94
+  // },
95
+
96
+  /**
97
+   * 页面上拉触底事件的处理函数
98
+   */
99
+  onReachBottom: function () {
100
+
101
+  },
102
+
103
+  /**
104
+   * 用户点击右上角分享
105
+   */
106
+  onShareAppMessage: function () {
107
+
108
+  }
109
+})

+ 6 - 0
pages/home/home.json

@@ -0,0 +1,6 @@
1
+{
2
+  "navigationBarTitleText": "主页",
3
+  "enablePullDownRefresh": true,
4
+  "navigationBarBackgroundColor": "#54bec2",
5
+  "navigationBarTextStyle": "white"
6
+}

+ 14 - 0
pages/home/home.wxml

@@ -0,0 +1,14 @@
1
+<view class="mine">
2
+  <view class="tab">
3
+    <view class="tab-title">HI,个人昵称</view>
4
+    <view class="tab-tips">欢迎来到XXXXXXXXXXXXXX有限公司</view>
5
+  </view>
6
+</view>
7
+
8
+
9
+<button class='button' hover-class="hover" bindtap="blueTooth"> 蓝牙设备 </button>
10
+<button class='button' hover-class="hover" hidden="true" bindtap="printTest"> 发送命令</button>
11
+<button class='button' hover-class="hover" bindtap="recipt"> 小票案例</button>
12
+<button class='button' hover-class="hover" bindtap="label"> 标签案例</button>
13
+<button class='button' hover-class="hover" bindtap="blueToothNet"> 蓝牙配网</button>
14
+<button class='button' hover-class="hover" hidden="true" bindtap="lotteryTicket"> 打印彩票</button>

+ 23 - 0
pages/home/home.wxss

@@ -0,0 +1,23 @@
1
+
2
+.mine{
3
+
4
+}
5
+.mine .tab{
6
+  padding: 48rpx 40rpx 0 40rpx;
7
+  height: 324rpx;
8
+  width: 100%;
9
+}
10
+
11
+.button {
12
+  margin-top: 20px;
13
+  width: 90%;
14
+  background-color: #54bec2;
15
+  color: white;
16
+  border-radius: 98rpx;
17
+  background: bg_red;
18
+}
19
+ 
20
+/* 按下变颜色 */
21
+.hover {
22
+  background:  #DCDCDC;
23
+}

+ 138 - 0
pages/homePage/homePage.js

@@ -0,0 +1,138 @@
1
+// pages/homePage/homePage.js
2
+import {
3
+  get,
4
+  post
5
+} from '../../utils/http.js'
6
+Page({
7
+
8
+  /**
9
+   * 页面的初始数据
10
+   */
11
+  data: {
12
+    list: [{
13
+      id: 0,
14
+      name: '入库',
15
+      icon: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/warehousing.png',
16
+    },
17
+    {
18
+      id: 1,
19
+      name: '出库',
20
+      icon: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/exWarehouse.png',
21
+    },
22
+    {
23
+      id: 2,
24
+      name: '供应商退货',
25
+      icon: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/supplier.png',
26
+    },
27
+    {
28
+      id: 3,
29
+      name: '客户退货',
30
+      icon: 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/customer.png',
31
+    },
32
+  ]
33
+
34
+  },
35
+
36
+  /**
37
+   * 生命周期函数--监听页面加载
38
+   */
39
+  onLoad(options) {
40
+    this.getPhoneInfo()
41
+    wx.getUserProfile({
42
+      desc: '用于展示', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
43
+      success: (res) => {
44
+        console.log(res);
45
+        this.setData({
46
+          userInfo: res.userInfo,
47
+          hasUserInfo: true
48
+        })
49
+      }
50
+    })
51
+  },
52
+
53
+  /**
54
+   * 生命周期函数--监听页面初次渲染完成
55
+   */
56
+  onReady() {
57
+
58
+  },
59
+
60
+  /**
61
+   * 生命周期函数--监听页面显示
62
+   */
63
+  onShow() {
64
+
65
+  },
66
+
67
+  /**
68
+   * 生命周期函数--监听页面隐藏
69
+   */
70
+  onHide() {
71
+
72
+  },
73
+
74
+  /**
75
+   * 生命周期函数--监听页面卸载
76
+   */
77
+  onUnload() {
78
+
79
+  },
80
+
81
+  /**
82
+   * 页面相关事件处理函数--监听用户下拉动作
83
+   */
84
+  onPullDownRefresh() {
85
+
86
+  },
87
+
88
+  /**
89
+   * 页面上拉触底事件的处理函数
90
+   */
91
+  onReachBottom() {
92
+
93
+  },
94
+
95
+  /**
96
+   * 用户点击右上角分享
97
+   */
98
+  onShareAppMessage() {
99
+
100
+  },
101
+
102
+  getPhoneInfo(){
103
+    post('get_phone_info', {imei:"356727085900775"}, res => {
104
+     console.log(res);
105
+    })
106
+  },
107
+
108
+  onDetails(e){
109
+    let item = e.currentTarget.dataset.item
110
+    if (item!=0) {
111
+      wx.showToast({
112
+        title: '敬请期待!',
113
+        icon: 'none'
114
+      })
115
+    }
116
+    let urls = "/pages/scanCode/scanCode"
117
+    if (item.id==1) {
118
+      urls = ''
119
+    }else if (item.id==2) {
120
+      urls = ''
121
+    }else if (item.id==3) {
122
+      urls = ''
123
+    }
124
+    console.log(item,'eee',urls);
125
+    wx.navigateTo({
126
+      url: urls,
127
+    })
128
+  },
129
+  /**
130
+   * 去入库
131
+   */
132
+  onWarehousing() {
133
+    wx.navigateTo({
134
+      url: '/pages/warehousing/warehousing',
135
+    })
136
+  },
137
+  
138
+})

+ 7 - 0
pages/homePage/homePage.json

@@ -0,0 +1,7 @@
1
+{
2
+  "navigationBarTitleText": "首页",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+  }
7
+}

+ 18 - 0
pages/homePage/homePage.wxml

@@ -0,0 +1,18 @@
1
+<view class="mine">
2
+  <view class="tab">
3
+    <!-- <view class="tab-title">HI,个人昵称</view>
4
+    <view class="tab-tips">欢迎来到XXXXXXXXXXXXXX有限公司</view> -->
5
+    <view class="tab-title">欢迎来到进销存系统</view>
6
+  </view>
7
+  <view class="func">
8
+    <view class="list" wx:for="{{list}}" bindtap="onDetails" data-item="{{item}}">
9
+      <view class="left">
10
+        <image class="list-icon" src="{{item.icon}}"></image>
11
+        <text class="list-title">{{item.name}}</text>
12
+      </view>
13
+      <view class="right">
14
+        <!-- <image class="onDetails" src="https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/onDetails.png"></image> -->
15
+      </view>
16
+    </view>
17
+  </view>
18
+</view>

+ 63 - 0
pages/homePage/homePage.wxss

@@ -0,0 +1,63 @@
1
+/* pages/homePage/homePage.wxss */
2
+.mine {}
3
+
4
+.mine .tab {
5
+  padding: 48rpx 40rpx 0 40rpx;
6
+  height: 324rpx;
7
+  width: 100%;
8
+  color: #333333;
9
+  letter-spacing: 0;
10
+  background-image: linear-gradient(180deg, #E5F2FF 0%, rgba(220, 237, 255, 0.00) 100%);
11
+}
12
+
13
+.func {
14
+  padding: 48rpx 40rpx;
15
+  margin-top: -240rpx;
16
+
17
+}
18
+
19
+.func .list {
20
+  margin-top: 24rpx;
21
+  box-shadow: 0px 0px 3px 0px rgba(0,0,0,0.5);
22
+  background: #FFFFFF;
23
+  border-radius: 12px;
24
+  padding: 40rpx 48rpx 40rpx 40rpx;
25
+  display: flex;
26
+  justify-content: space-between;
27
+  align-items: center;
28
+}
29
+
30
+.func .list .left {
31
+  display: flex;
32
+  align-items: center;
33
+}
34
+
35
+.func .list .list-icon {
36
+  width: 120rpx;
37
+  height: 120rpx;
38
+}
39
+
40
+.func .list .list-title {
41
+  margin-left: 40rpx;
42
+  font-family: PingFangSC-Regular;
43
+  font-size: 40rpx;
44
+  color: #333333;
45
+  letter-spacing: 0;
46
+  vertical-align: middle;
47
+}
48
+
49
+.func .list .onDetails {
50
+  width: 60rpx;
51
+  height: 26rpx;
52
+
53
+}
54
+
55
+.tab .tab-title {
56
+  font-family: PingFangSC-Medium;
57
+  font-size: 40rpx;
58
+}
59
+
60
+.tab .tab-tips {
61
+  font-family: PingFangSC-Regular;
62
+  font-size: 32rpx;
63
+}

+ 575 - 0
pages/label/label.js

@@ -0,0 +1,575 @@
1
+
2
+var app = getApp();
3
+var tsc = require("../../utils/tsc.js");
4
+var encode = require("../../utils/encoding.js");
5
+
6
+function convertToGrayscale(data) {
7
+  let g = 0
8
+  for (let i = 0; i < data.length; i += 4) {
9
+    g = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11)
10
+    data[i] = g
11
+    data[i + 1] = g
12
+    data[i + 2] = g
13
+  }
14
+  return data
15
+}
16
+
17
+function inArray(arr, key, val) {
18
+  for (let i = 0; i < arr.length; i++) {
19
+    if (arr[i][key] === val) {
20
+      return i;
21
+    }
22
+  }
23
+  return -1;
24
+}
25
+
26
+// ArrayBuffer转16进度字符串示例
27
+function ab2hex(buffer) {
28
+  var hexArr = Array.prototype.map.call(
29
+    new Uint8Array(buffer),
30
+    function (bit) {
31
+      return ('00' + bit.toString(16)).slice(-2)
32
+    }
33
+  )
34
+  return hexArr.join('');
35
+}
36
+
37
+// function convertToGrayscale(data) {
38
+//   let g = 0
39
+//   for (let i = 0; i < data.length; i += 4) {
40
+//     g = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11)
41
+//     data[i] = g
42
+//     data[i + 1] = g
43
+//     data[i + 2] = g
44
+//   }
45
+//   return data
46
+// }
47
+
48
+function setPixel(data, offset, value) {
49
+  data[offset] = value;
50
+  data[offset + 1] = value;
51
+  data[offset + 2] = value;
52
+}
53
+
54
+function adjustPixel(data, offset, value) {
55
+  data[offset] += value;
56
+}
57
+
58
+// 彩色图转成单色图
59
+function convertToMonoImage(width, height, data, shake) {
60
+  let g = 0
61
+  let e = 0
62
+
63
+  for (let i = 0; i < data.length; i += 4) {
64
+    data[i] = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11);
65
+  }
66
+
67
+  for (let y = 0; y < height; y++) {
68
+    for (let x = 0; x < width; x++) {
69
+      let dataOffset = (width * y + x) * 4;
70
+      g = data[dataOffset];
71
+      if (g >= 150) {  // 灰色转黑白的阈值, 可以调整打印效果
72
+        e = g - 255;
73
+        setPixel(data, dataOffset, 255);
74
+      } else {
75
+        e = g;
76
+        setPixel(data, dataOffset, 0);
77
+      }
78
+
79
+      if (!shake)
80
+        continue;
81
+
82
+      if (x < width - 1 && y < height - 1) {
83
+        //右边像素处理
84
+        data[(width * y + x + 1) * 4] += 7 * e / 16;
85
+        //下
86
+        data[(width * (y + 1) + x) * 4] += 5 * e / 16;
87
+        //右下
88
+        data[(width * (y + 1) + x + 1) * 4] += e / 16;
89
+        //左下
90
+        if (x > 0) {
91
+          data[(width * (y + 1) + x - 1) * 4] += 3 * e / 16;
92
+        }
93
+      } else if (x == width - 1 && y < height - 1) {
94
+        //下方像素处理
95
+        data[(width * (y + 1) + x) * 4] += 5 * e / 16;
96
+      } else if (x < width - 1 && y == height - 1) {
97
+        //右边像素处理
98
+        data[(width * y + x + 1) * 4] += 7 * e / 16;
99
+      }
100
+    }
101
+  }
102
+  return data
103
+}
104
+Page({
105
+
106
+  /**
107
+   * 页面的初始数据
108
+   */
109
+  data: {
110
+    looptime: 0,
111
+    currentTime: 1,
112
+    lastData: 0,
113
+    oneTimeData: 0,
114
+    buffSize: [],
115
+    buffIndex: 0,//发送字节数下标
116
+    printNum: [],
117
+    printNumIndex: 0,
118
+    printerNum: 1,
119
+    currentPrint: 1,
120
+    isLabelSend: false,
121
+    isQuery: false,
122
+    imageSrc: '../../imags/wechat.jpg',
123
+    jpgSrc: '../../imags/flower2.jpg',
124
+    canvasWidth: 100,
125
+    canvasHeight: 100,
126
+    jpgWidth: 200,
127
+    jpgHeight: 200,
128
+  },
129
+
130
+  /**
131
+   * 生命周期函数--监听页面加载
132
+   */
133
+  onLoad: function (options) {
134
+
135
+  }, initPhoto: function () {//初始化画布数据
136
+    //创建一个png格式
137
+    var that = this
138
+    const ctx_out = wx.createCanvasContext('canvasOut', this);
139
+    var png = that.data.imageSrc;
140
+    wx.getImageInfo({
141
+      src: png,
142
+      success(res) {
143
+        that.setData({
144
+          canvasWidth: res.width,
145
+          canvasHeight: res.height,
146
+        });
147
+        console.log("画布宽度" + res.width, "画布高度" + res.height);
148
+        // ctx_out.setFillStyle('#ffffff')
149
+        // ctx_out.setStrokeStyle('rgba(1,1,1,0)')
150
+        // ctx_out.fill()
151
+        //ctx_out.drawImage(png, 0, 0, res.width, res.height);
152
+        ctx_out.drawImage(png, 0, 0);
153
+        ctx_out.draw();
154
+      }
155
+    })
156
+    //创建一个jpg格式图片
157
+    const ctx_jpg = wx.createCanvasContext('canvasJPG', this);
158
+    var jpg_width = that.data.jpgWidth;
159
+    var jpg_height = that.data.jpgHeight;
160
+    var img = that.data.jpgSrc;
161
+    wx.getImageInfo({
162
+      src: img,
163
+      success(res) {
164
+        that.setData({
165
+          jpgWidth: res.width,
166
+          jpgHeight: res.height,
167
+        });
168
+        console.log("JPG画布宽度" + res.width, "JPG画布高度" + res.height);
169
+        ctx_jpg.drawImage(img, 0, 0, res.width, res.height);
170
+        ctx_jpg.draw();
171
+      }
172
+    })
173
+  },
174
+  labelTest: function () { //标签测试
175
+    var that = this;
176
+    var canvasWidth = that.data.canvasWidth
177
+    var canvasHeight = that.data.canvasHeight
178
+    var command = tsc.jpPrinter.createNew()
179
+    command.setCls()//清除缓冲区,防止下一个没生效
180
+    command.setSize(58, 30)//设置标签大小,单位mm.具体参数请用尺子量一下
181
+    command.setGap(0)//设置两个标签之间的间隙,单位mm.具体参数请用尺子量一下
182
+    command.setCls()//清除缓冲区
183
+    command.setBox(10, 10, 464, 230, 5)//绘制一个边框
184
+    command.setBar(10, 75, 455, 5);//绘制一条黑线
185
+    command.setText(150, 20, "TSS24.BF2", 0, 2, 2, "棒棒糖")//绘制文字
186
+    command.setText(340, 20, "TSS24.BF2", 0, 2, 2, "8 元")//绘制文字
187
+    command.setText(360, 40, "TSS24.BF2", 0, 1, 1, ".8")//绘制文字
188
+    command.setText(50, 100, "TSS24.BF2", 0, 1, 1, "单位:______")//绘制文字
189
+    command.setText(140, 90, "TSS24.BF2", 0, 1, 1, "包")//绘制文字
190
+    command.setText(50, 140, "TSS24.BF2", 0, 1, 1, "重量:______")//绘制文字
191
+    command.setText(140, 130, "TSS24.BF2", 0, 1, 1, "500g")//绘制文字
192
+    command.setText(50, 170, "TSS24.BF2", 0, 1, 1, "条码:")//绘制文字
193
+    command.setBarCode(120, 170, "128", 48, 0, 0, 2, 2, "12345678")//绘制code128条码
194
+    command.setBar(300, 80, 5, 150);//绘制一条黑线
195
+    command.setQrcode(320, 90, "L", 5, "A", "http://www.howbest.cn/cn/")//绘制一个二维码
196
+    command.setPagePrint()//执行打印指令
197
+    that.setData({
198
+      isLabelSend: true
199
+    })
200
+    that.prepareSend(command.getData())
201
+  },
202
+  printPhoto: function () {//打印bitmap,图片内容不建议太大,小程序限制传输的字节数为20byte
203
+    var that = this;
204
+    var canvasWidth = that.data.canvasWidth
205
+    var canvasHeight = that.data.canvasHeight
206
+    var command = tsc.jpPrinter.createNew()
207
+    command.setCls()
208
+    command.setSize(30, 30)
209
+    command.setGap(0)
210
+    command.setCls()
211
+    wx.canvasGetImageData({
212
+      canvasId: 'canvasOut',
213
+      x: 0,
214
+      y: 0,
215
+      width: canvasWidth,
216
+      height: canvasHeight,
217
+      success: function (res) {
218
+        console.log("获取画布数据成功")
219
+        command.setBitmap(0, 0, 0, res)
220
+        command.setPrint(1)
221
+        that.prepareSend(command.getData())//发送数据
222
+      },
223
+      complete: function (res) {
224
+        console.log("finish")
225
+      },
226
+      fail: function (res) {
227
+        console.log(res)
228
+        wx.showToast({
229
+          title: '获取画布数据失败',
230
+          icon: 'none',
231
+        })
232
+      }
233
+    })
234
+  },
235
+  printJPGPhoto: function () {
236
+    var that = this;
237
+    var canvasWidth = that.data.jpgWidth
238
+    var canvasHeight = that.data.jpgHeight
239
+
240
+    //抖动处理JPG图片
241
+    const cfg = {
242
+      x: 0,
243
+      y: 0,
244
+      width: canvasWidth,
245
+      height: canvasHeight,
246
+    }
247
+    wx.canvasGetImageData({
248
+      canvasId: 'canvasJPG',
249
+      ...cfg,
250
+      success: (res) => {
251
+        //const data = convertToGrayscale(res.data)
252
+        const data = convertToMonoImage(res.width, res.height, res.data, true);
253
+        wx.canvasPutImageData({
254
+          canvasId: 'canvasJPG',
255
+          data,
256
+          ...cfg,
257
+          success: (res) => {
258
+            console.log(res)
259
+            console.log('deal graphic width: ' + cfg.width)
260
+            console.log('deal graphic width: ' + cfg.height)
261
+            that.printerJPG();
262
+          },
263
+          fail: (err) => {
264
+            console.error(err)
265
+          }
266
+        })
267
+      },
268
+      fail: (err) => {
269
+        console.error(err)
270
+      }
271
+    })
272
+  },
273
+  printerJPG: function () {
274
+    var that = this;
275
+    var canvasWidth = that.data.jpgWidth
276
+    var canvasHeight = that.data.jpgHeight
277
+    var command = tsc.jpPrinter.createNew()
278
+    command.setCls()
279
+    command.setSize(30, 30)
280
+    command.setGap(0)
281
+    command.setCls()
282
+    wx.canvasGetImageData({
283
+      canvasId: 'canvasJPG',
284
+      x: 0,
285
+      y: 0,
286
+      width: canvasWidth,
287
+      height: canvasHeight,
288
+      success: function (res) {
289
+        console.log("获取画布数据成功")
290
+        command.setBitmap(60, 0, 1, res)
291
+        command.setPrint(1)
292
+        that.prepareSend(command.getData())//发送数据
293
+      },
294
+      complete: function (res) {
295
+        console.log("finish")
296
+      },
297
+      fail: function (res) {
298
+        console.log(res)
299
+        wx.showToast({
300
+          title: '获取画布数据失败',
301
+          icon: 'none',
302
+        })
303
+      }
304
+    })
305
+  },
306
+
307
+  prepareSend: function (buff) { //准备发送,根据每次发送字节数来处理分包数量
308
+    //console.log(buff)
309
+    var that = this
310
+    var time = that.data.oneTimeData
311
+    var looptime = parseInt(buff.length / time);
312
+    var lastData = parseInt(buff.length % time);
313
+    //console.log(looptime + "---" + lastData)
314
+    that.setData({
315
+      looptime: looptime + 1,
316
+      lastData: lastData,
317
+      currentTime: 1,
318
+    })
319
+    that.Send(buff)
320
+  },
321
+  queryStatus: function () {//查询打印机状态
322
+    var that = this
323
+    var buf;
324
+    var dateView;
325
+    /*
326
+    n = 1:传送打印机状态
327
+    n = 2:传送脱机状态
328
+    n = 3:传送错误状态
329
+    n = 4:传送纸传感器状态
330
+    */
331
+    buf = new ArrayBuffer(5)
332
+    dateView = new DataView(buf)
333
+    dateView.setUint8(0, 27)
334
+    dateView.setUint8(1, 33)
335
+    dateView.setUint8(2, 63)
336
+    dateView.setUint8(3, 13)
337
+    dateView.setUint8(4, 10)
338
+    wx.writeBLECharacteristicValue({
339
+      deviceId: app.BLEInformation.deviceId,
340
+      serviceId: app.BLEInformation.writeServiceId,
341
+      characteristicId: app.BLEInformation.writeCharaterId,
342
+      value: buf,
343
+      success: function (res) {
344
+        console.log("发送成功")
345
+        that.setData({
346
+          isQuery: true
347
+        })
348
+      },
349
+      fail: function (e) {
350
+        wx.showToast({
351
+          title: '发送失败',
352
+          icon: 'none',
353
+        })
354
+        //console.log(e)
355
+        return;
356
+      },
357
+      complete: function () {
358
+
359
+      }
360
+    })
361
+
362
+    wx.notifyBLECharacteristicValueChange({
363
+      deviceId: app.BLEInformation.deviceId,
364
+      serviceId: app.BLEInformation.notifyServiceId,
365
+      characteristicId: app.BLEInformation.notifyCharaterId,
366
+      state: true,
367
+      success: function (res) {
368
+        wx.onBLECharacteristicValueChange(function (r) {
369
+          console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
370
+          var result = ab2hex(r.value)
371
+          console.log("返回" + result)
372
+          var tip = ''
373
+          if (result == 0) {//正常
374
+            tip = "正常"
375
+          } else if (result == 4) {//缺纸
376
+            tip = "缺纸"
377
+          } else if (result == 5) {//开盖、缺纸
378
+            tip = "开盖、缺纸"
379
+          } else if (result == 41) {
380
+            tip = "开盖"
381
+          }else if (result == 40) {//其他错误
382
+            tip = "其他错误"
383
+          } else {//未处理错误
384
+            tip = "未知错误"
385
+          }
386
+          wx.showModal({
387
+            title: '打印机状态',
388
+            content: tip,
389
+            showCancel: false
390
+          })
391
+
392
+        })
393
+      },
394
+      fail: function (e) {
395
+        wx.showModal({
396
+          title: '打印机状态',
397
+          content: '获取失败',
398
+          showCancel: false
399
+        })
400
+        console.log(e)
401
+      },
402
+      complete: function (e) {
403
+        that.setData({
404
+          isQuery: false
405
+        })
406
+        console.log("执行完成")
407
+      }
408
+    })
409
+  },
410
+  Send: function (buff) { //分包发送
411
+    var that = this
412
+    var currentTime = that.data.currentTime
413
+    var loopTime = that.data.looptime
414
+    var lastData = that.data.lastData
415
+    var onTimeData = that.data.oneTimeData
416
+    var printNum = that.data.printerNum
417
+    var currentPrint = that.data.currentPrint
418
+    var buf
419
+    var dataView
420
+    if (currentTime < loopTime) {
421
+      buf = new ArrayBuffer(onTimeData)
422
+      dataView = new DataView(buf)
423
+      for (var i = 0; i < onTimeData; ++i) {
424
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
425
+      }
426
+    } else {
427
+      buf = new ArrayBuffer(lastData)
428
+      dataView = new DataView(buf)
429
+      for (var i = 0; i < lastData; ++i) {
430
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
431
+      }
432
+    }
433
+    //console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
434
+    wx.writeBLECharacteristicValue({
435
+      deviceId: app.BLEInformation.deviceId,
436
+      serviceId: app.BLEInformation.writeServiceId,
437
+      characteristicId: app.BLEInformation.writeCharaterId,
438
+      value: buf,
439
+      success: function (res) {
440
+        if (currentPrint == printNum) {
441
+          wx.showToast({
442
+            title: '已打印第' + currentPrint + '张成功',
443
+          })
444
+        }
445
+        //console.log(res)
446
+      },
447
+      fail: function (e) {
448
+        wx.showToast({
449
+          title: '打印第' + currentPrint + '张失败',
450
+          icon: 'none',
451
+        })
452
+
453
+        //console.log(e)
454
+      },
455
+      complete: function () {
456
+        currentTime++
457
+        if (currentTime <= loopTime) {
458
+          that.setData({
459
+            currentTime: currentTime
460
+          })
461
+          that.Send(buff)
462
+        } else {
463
+          // wx.showToast({
464
+          //   title: '已打印第' + currentPrint + '张',
465
+          // })`
466
+          if (currentPrint == printNum) {
467
+            that.setData({
468
+              looptime: 0,
469
+              lastData: 0,
470
+              currentTime: 1,
471
+              isLabelSend: false,
472
+              currentPrint: 1
473
+            })
474
+          } else {
475
+            currentPrint++
476
+            that.setData({
477
+              currentPrint: currentPrint,
478
+              currentTime: 1,
479
+            })
480
+            that.Send(buff)
481
+          }
482
+        }
483
+      }
484
+    })
485
+  },
486
+
487
+  /**
488
+   * 生命周期函数--监听页面初次渲染完成
489
+   */
490
+  onReady: function () {
491
+    var list = []
492
+    var numList = []
493
+    var j = 0
494
+    for (var i = 20; i < 200; i += 10) {
495
+      list[j] = i;
496
+      j++
497
+    }
498
+    for (var i = 1; i < 10; i++) {
499
+      numList[i - 1] = i
500
+    }
501
+    this.setData({
502
+      buffSize: list,
503
+      oneTimeData: list[0],
504
+      printNum: numList,
505
+      printerNum: numList[0]
506
+    })
507
+    this.initPhoto();
508
+  },
509
+
510
+  /**
511
+   * 生命周期函数--监听页面显示
512
+   */
513
+  onShow: function () {
514
+
515
+  },
516
+
517
+
518
+  buffBindChange: function (res) { //更改打印字节数
519
+    var index = res.detail.value
520
+    var time = this.data.buffSize[index]
521
+    this.setData({
522
+      buffIndex: index,
523
+      oneTimeData: time
524
+    })
525
+  },
526
+  printNumBindChange: function (res) { //更改打印份数
527
+    var index = res.detail.value
528
+    var num = this.data.printNum[index]
529
+    this.setData({
530
+      printNumIndex: index,
531
+      printerNum: num
532
+    })
533
+  },
534
+
535
+  /**
536
+   * 生命周期函数--监听页面隐藏
537
+   */
538
+  onHide: function () {
539
+
540
+  },
541
+
542
+  /**
543
+   * 生命周期函数--监听页面卸载
544
+   */
545
+  onUnload: function () {
546
+    //关闭蓝牙连接
547
+    // wx.closeBLEConnection({
548
+    //   deviceId: app.BLEInformation.deviceId,
549
+    //   success: function(res) {
550
+    //     console.log("关闭蓝牙成功")
551
+    //   },
552
+    // })
553
+  },
554
+
555
+  /**
556
+   * 页面相关事件处理函数--监听用户下拉动作
557
+   */
558
+  onPullDownRefresh: function () {
559
+
560
+  },
561
+
562
+  /**
563
+   * 页面上拉触底事件的处理函数
564
+   */
565
+  onReachBottom: function () {
566
+
567
+  },
568
+
569
+  /**
570
+   * 用户点击右上角分享
571
+   */
572
+  onShareAppMessage: function () {
573
+
574
+  }
575
+})

+ 3 - 0
pages/label/label.json

@@ -0,0 +1,3 @@
1
+{
2
+  "navigationBarTitleText": "标签"
3
+}

+ 15 - 0
pages/label/label.wxml

@@ -0,0 +1,15 @@
1
+<view class="body">
2
+  		<button class='button'  hover-class="hover" bindtap='labelTest' loading='{{isLabelSend}}' disabled='{{isLabelSend}}'>标签案例</button>
3
+        	<button  class='button'  hover-class="hover" bindtap='queryStatus' loading='{{isQuery}}' disabled='{{isQuery}}'>查询状态</button>
4
+         <button class='button'  hover-class="hover" bindtap='printPhoto' >打印图片</button>
5
+          		<canvas canvas-id="canvasOut" class="canvas"  style='border:0px solid; width:{{canvasWidth}}px; height:{{canvasHeight}}px'></canvas>
6
+
7
+           <button class='button'  hover-class="hover" bindtap='printJPGPhoto' >打印彩图</button>
8
+           <canvas canvas-id="canvasJPG" class="canvas" style='border:0px solid; width:{{jpgWidth}}px; height:{{jpgHeight}}px'></canvas>  
9
+	<picker style='margin:20px' mode='selector' range='{{buffSize}}' value='{{buffIndex}}' bindchange='buffBindChange'>当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
10
+	</picker>
11
+
12
+	<picker style='margin:20px' mode='selector' range='{{printNum}}' value='{{printNumIndex}}' bindchange='printNumBindChange'>当前打印份数(点击可更换):{{printNum[printNumIndex]}}
13
+	</picker>
14
+
15
+</view>

+ 13 - 0
pages/label/label.wxss

@@ -0,0 +1,13 @@
1
+.button {
2
+  margin-top: 20px;
3
+  width: 90%;
4
+  background-color: #54bec2;
5
+  color: white;
6
+  border-radius: 98rpx;
7
+  background: bg_red;
8
+}
9
+ 
10
+/* 按下变颜色 */
11
+.hover {
12
+  background:  #DCDCDC;
13
+}

+ 66 - 0
pages/mine/mine.js

@@ -0,0 +1,66 @@
1
+// pages/mine/mine.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+
9
+  },
10
+
11
+  /**
12
+   * 生命周期函数--监听页面加载
13
+   */
14
+  onLoad: function (options) {
15
+
16
+  },
17
+
18
+  /**
19
+   * 生命周期函数--监听页面初次渲染完成
20
+   */
21
+  onReady: function () {
22
+
23
+  },
24
+
25
+  /**
26
+   * 生命周期函数--监听页面显示
27
+   */
28
+  onShow: function () {
29
+
30
+  },
31
+
32
+  /**
33
+   * 生命周期函数--监听页面隐藏
34
+   */
35
+  onHide: function () {
36
+
37
+  },
38
+
39
+  /**
40
+   * 生命周期函数--监听页面卸载
41
+   */
42
+  onUnload: function () {
43
+
44
+  },
45
+
46
+  /**
47
+   * 页面相关事件处理函数--监听用户下拉动作
48
+   */
49
+  onPullDownRefresh: function () {
50
+
51
+  },
52
+
53
+  /**
54
+   * 页面上拉触底事件的处理函数
55
+   */
56
+  onReachBottom: function () {
57
+
58
+  },
59
+
60
+  /**
61
+   * 用户点击右上角分享
62
+   */
63
+  onShareAppMessage: function () {
64
+
65
+  }
66
+})

+ 8 - 0
pages/mine/mine.json

@@ -0,0 +1,8 @@
1
+{
2
+  "navigationBarTitleText": "我的",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "van-empty": "@vant/weapp/empty/index"
7
+  }
8
+}

+ 2 - 0
pages/mine/mine.wxml

@@ -0,0 +1,2 @@
1
+<!--pages/mine/mine.wxml-->
2
+<van-empty description="敬请期待!" />

+ 1 - 0
pages/mine/mine.wxss

@@ -0,0 +1 @@
1
+/* pages/mine/mine.wxss */

+ 340 - 0
pages/net/net.js

@@ -0,0 +1,340 @@
1
+// pages/sendCommand/sendCommand.js
2
+
3
+/**
4
+ * 此Demo仅供参考,可打印数字,英文,符号,中文,
5
+ * 小程序支持的蓝牙为低功耗蓝牙(BLE),数据量大需分包发送
6
+ */
7
+
8
+var app = getApp();
9
+var tsc = require("../../utils/tsc.js");
10
+var esc = require("../../utils/esc.js");
11
+var encode = require("../../utils/encoding.js");//GB18030
12
+
13
+Page({
14
+
15
+  /**
16
+   * 页面的初始数据
17
+   */
18
+  data: {
19
+    ssid:"",
20
+    password:"",
21
+    looptime: 0,
22
+    currentTime: 1,
23
+    lastData: 0,
24
+    oneTimeData: 60,
25
+    returnResult: "",
26
+    buffSize: [],
27
+    buffIndex: 0,
28
+    printNum: [],
29
+    printerNum: 1,
30
+    currentPrint: 1,
31
+    netCommand: [31, 27,31, 27, 0, 17, 34, 80],
32
+    selfCommand: [126, 87, 67],//斑马指令自检页
33
+    end:[0],
34
+    isNet:false,//标记是否为配网
35
+    defaultType: true,
36
+    passwordType: true
37
+  },
38
+
39
+  /**
40
+   * 生命周期函数--监听页面加载
41
+   */
42
+  onLoad: function (options) {
43
+    var that = this;
44
+    wx.notifyBLECharacteristicValueChange({
45
+      deviceId: app.BLEInformation.deviceId,
46
+      serviceId: app.BLEInformation.notifyServiceId,
47
+      characteristicId: app.BLEInformation.notifyCharaterId,
48
+      state: true,
49
+      success: function (res) {
50
+        wx.onBLECharacteristicValueChange(function (r) {
51
+          console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
52
+        })
53
+      },
54
+      fail: function (e) {
55
+        console.log(e)
56
+      },
57
+      complete: function (e) {
58
+        console.log(e)
59
+      }
60
+    })
61
+  },
62
+
63
+   ssid: function (e) { //获取输入SSID
64
+    this.setData({
65
+      ssid: e.detail.value
66
+    })
67
+    //  console.log("字符长度:" + data.name.length)
68
+  },
69
+  clear:function(){//清空输入
70
+    this.setData({
71
+      ssid: ""
72
+    })
73
+  },
74
+  password: function (e) { //获取输入password
75
+    this.setData({
76
+      password: e.detail.value
77
+    })
78
+  },
79
+  //defaultType:眼睛状态   passwordType:密码可见与否状态
80
+  eyeStatus: function () {
81
+    if (this.data.defaultType) {
82
+      this.setData({
83
+        passwordType: false,
84
+        defaultType: false,
85
+      })
86
+    } else {
87
+      this.setData({
88
+        passwordType: true,
89
+        defaultType: true,
90
+      })
91
+    }
92
+  },
93
+
94
+  settiing: function () { //设置
95
+    console.log("SSID长度:" + this.data.ssid.length)
96
+    if (this.data.ssid.length == 0 ) {
97
+      wx.showModal({
98
+        title: '提示',
99
+        content: '名称SSID不能为空!',
100
+        showCancel: false,
101
+      })
102
+    }else {
103
+    wx.setStorageSync("ssid", this.data.ssid)
104
+    wx.setStorageSync("password", this.data.password)
105
+    var t_ssid = "\"" + this.data.ssid +"\""
106
+    var t_password = "\""+this.data.password + "\""
107
+    this.setData({
108
+      looptime: 0,
109
+      isNet:true,
110
+    })
111
+    var SSID = new encode.TextEncoder(
112
+      'utf-8', {
113
+        NONSTANDARD_allowLegacyEncoding: true
114
+      }).encode(t_ssid);
115
+    var PASSWORD = new encode.TextEncoder(
116
+      'utf-8', {
117
+        NONSTANDARD_allowLegacyEncoding: true
118
+      }).encode(t_password);
119
+      var data = [];
120
+      for (var i = 0; i < this.data.netCommand.length;i++){
121
+        data.push(this.data.netCommand[i]);
122
+     }
123
+      for (var i = 0; i < SSID.length; i++) {
124
+        data.push(SSID[i]);
125
+      }
126
+      data.push(0);
127
+      for (var i = 0; i < PASSWORD.length; i++) {
128
+        data.push(PASSWORD[i]);
129
+      }
130
+      data.push(0);
131
+      this.prepareSend(data)
132
+    }
133
+  },
134
+  receiptTest: function () { //打印自检页
135
+    this.prepareSend(this.data.selfCommand)
136
+  },
137
+
138
+  prepareSend: function (buff) { //准备发送,根据每次发送字节数来处理分包数量
139
+    console.log(buff)
140
+    var that = this
141
+    var time = that.data.oneTimeData
142
+    var looptime = parseInt(buff.length / time);
143
+    var lastData = parseInt(buff.length % time);
144
+    console.log(looptime + "---" + lastData)
145
+    that.setData({
146
+      looptime: looptime + 1,
147
+      lastData: lastData,
148
+      currentTime: 1,
149
+    })
150
+    that.Send(buff)
151
+  },
152
+
153
+  Send: function (buff) { //分包发送
154
+    var that = this
155
+    var currentTime = that.data.currentTime
156
+    var loopTime = that.data.looptime
157
+    var lastData = that.data.lastData
158
+    var onTimeData = that.data.oneTimeData
159
+    var printNum = that.data.printerNum
160
+    var currentPrint = that.data.currentPrint
161
+    var buf
162
+    var dataView
163
+    if (currentTime < loopTime) {
164
+      buf = new ArrayBuffer(onTimeData)
165
+      dataView = new DataView(buf)
166
+      for (var i = 0; i < onTimeData; ++i) {
167
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
168
+      }
169
+    } else {
170
+      buf = new ArrayBuffer(lastData)
171
+      dataView = new DataView(buf)
172
+      for (var i = 0; i < lastData; ++i) {
173
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
174
+      }
175
+    }
176
+    console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
177
+    wx.writeBLECharacteristicValue({
178
+      deviceId: app.BLEInformation.deviceId,
179
+      serviceId: app.BLEInformation.writeServiceId,
180
+      characteristicId: app.BLEInformation.writeCharaterId,
181
+      value: buf,
182
+      success: function (res) {
183
+        if(that.data.isNet){ 
184
+          wx.showModal({
185
+            title: '发送成功',
186
+            content: '请耐心等待配网...\r\n配网成功打印:Config SUCCESS!\r\n配网失败打印:Config Fail!!!',
187
+            showCancel: false,
188
+            confirmText: '知道啦',
189
+            success: function (res) {
190
+              if (res.confirm) {
191
+                that.setData({
192
+                  isNet: false,
193
+                })
194
+                that.onShow();
195
+              } else if (res.cancel) {
196
+                console.log('用户点击关闭')
197
+              }
198
+            }
199
+          })
200
+          console.log("配网")
201
+        }else{
202
+          console.log("不配网")
203
+        }
204
+        console.log("发送成功")
205
+        console.log(res)
206
+      },
207
+      fail: function (e) {
208
+        console.log("发送失败")
209
+        wx.showModal({
210
+          title: '提示',
211
+          content: '发送失败',
212
+          showCancel: false
213
+        })
214
+        console.log(e)
215
+        return;
216
+      },
217
+      complete: function () {
218
+        currentTime++
219
+        if (currentTime <= loopTime) {
220
+          that.setData({
221
+            currentTime: currentTime
222
+          })
223
+          that.Send(buff)
224
+        } else {
225
+         
226
+          if (currentPrint == printNum) {
227
+            that.setData({
228
+              looptime: 0,
229
+              lastData: 0,
230
+              currentTime: 1,
231
+              currentPrint: 1
232
+            })
233
+          } else {
234
+            currentPrint++
235
+            that.setData({
236
+              currentPrint: currentPrint,
237
+              currentTime: 1,
238
+            })
239
+            that.Send(buff)
240
+          }
241
+        }
242
+      }
243
+    })
244
+
245
+  },
246
+
247
+  /**
248
+   * 生命周期函数--监听页面初次渲染完成
249
+   */
250
+  onReady: function () {
251
+    var list = []
252
+    var numList = []
253
+    var j = 0
254
+    for (var i = 60; i < 200; i += 10) {
255
+      list[j] = i;
256
+      j++
257
+    }
258
+    for (var i = 1; i < 10; i++) {
259
+      numList[i - 1] = i
260
+    }
261
+    this.setData({
262
+      buffSize: list,
263
+      oneTimeData: list[0],
264
+      printNum: numList,
265
+      printerNum: numList[0]
266
+    })
267
+  },
268
+
269
+  /**
270
+   * 生命周期函数--监听页面显示
271
+   */
272
+  onShow: function () {
273
+    var that = this
274
+    //获取本地数据
275
+    var ssid = wx.getStorageSync('ssid');
276
+    var password = wx.getStorageSync('password');
277
+    console.log("已保存"+ssid);
278
+    console.log("已保存" + password);
279
+    if (ssid) {
280
+      this.setData({
281
+         ssid: ssid 
282
+         });
283
+    }
284
+    if (password) {
285
+      this.setData({ 
286
+        password: password
287
+         });
288
+    }
289
+  },
290
+
291
+  buffBindChange: function (res) { //更改打印字节数
292
+    var index = res.detail.value
293
+    var time = this.data.buffSize[index]
294
+    console.log("index" + index);
295
+    console.log("time" + time);
296
+    this.setData({
297
+      buffIndex: index,
298
+      oneTimeData: time
299
+    })
300
+  },
301
+  /**
302
+   * 生命周期函数--监听页面隐藏
303
+   */
304
+  onHide: function () {
305
+
306
+  },
307
+
308
+  /**
309
+   * 生命周期函数--监听页面卸载
310
+   */
311
+  onUnload: function () {
312
+    // wx.closeBLEConnection({
313
+    //   deviceId: app.BLEInformation.deviceId,
314
+    //   success: function (res) {
315
+    //     console.log("关闭蓝牙成功")
316
+    //   },
317
+    // })
318
+  },
319
+
320
+  /**
321
+   * 页面相关事件处理函数--监听用户下拉动作
322
+   */
323
+  onPullDownRefresh: function () {
324
+
325
+  },
326
+
327
+  /**
328
+   * 页面上拉触底事件的处理函数
329
+   */
330
+  onReachBottom: function () {
331
+
332
+  },
333
+
334
+  /**
335
+   * 用户点击右上角分享
336
+   */
337
+  onShareAppMessage: function () {
338
+
339
+  }
340
+})

+ 3 - 0
pages/net/net.json

@@ -0,0 +1,3 @@
1
+{
2
+  "navigationBarTitleText": "配网"
3
+}

+ 29 - 0
pages/net/net.wxml

@@ -0,0 +1,29 @@
1
+<!--blecontrol.wxml-->
2
+<view class="body">
3
+
4
+
5
+  <view style='margin:4%;display: flex;flex-direction: row;'>
6
+    <text class="text">名称:</text>
7
+    <view class="pwd" style='margin:4%;display: flex;flex-direction: row;'>
8
+      <input class="pwdinput" bindinput="ssid" value="{{ssid}}" placeholder="请输入SSID" />
9
+      <image bindtap="clear" src='../../imags/ic_close.png' class='imageStyle'></image>
10
+    </view>
11
+  </view>
12
+
13
+  <view style='margin:4%;display: flex;flex-direction: row;'>
14
+    <text class="text">密码:</text>
15
+    <view class="pwd" style='margin:4%;display: flex;flex-direction: row;'>
16
+      <input class="pwdinput" password='{{passwordType}}' bindinput="password" value="{{password}}" />
17
+      <image src='{{defaultType? "../../imags/ic_unvisiable.png": "../../imags/ic_visiable.png"}}' class='imageStyle' bindtap='eyeStatus'></image>
18
+    </view>
19
+  </view>
20
+
21
+  <button class='button'  hover-class="hover" bindtap="settiing">设置</button>
22
+
23
+  <view style='margin-top:4%;display: flex;flex-direction: row;'>
24
+
25
+    <button hidden="true" type='primary' bindtap='receiptTest' loading='{{isReceiptSend}}' disabled='{{isReceiptSend}}'>打印自检页</button>
26
+
27
+  </view>
28
+
29
+</view>

+ 123 - 0
pages/net/net.wxss

@@ -0,0 +1,123 @@
1
+/* blecontrol.wxss */
2
+
3
+page{
4
+  width: 100%;
5
+  min-height: 100%;
6
+  background: blanchedalmond;
7
+}
8
+.parentstyle {
9
+  margin-left: 38rpx;
10
+  margin-top: 30rpx;
11
+  margin-right: 38rpx;
12
+}
13
+.centerStyle {
14
+  display: flex;
15
+  align-items: center;
16
+  justify-content: space-between;
17
+}
18
+.input{
19
+ align-items: center;
20
+ margin-left: 4px;
21
+ padding: 4px;
22
+ width: 80%;
23
+ height: 30px; 
24
+ color: green;
25
+ border: 1px solid slategray;
26
+ border-radius: 8px;
27
+}
28
+.pwd{
29
+ align-items: center;
30
+ padding: 4px;
31
+ width: 75%;
32
+ height: 30px; 
33
+ color: green;
34
+ border: 1px solid slategray;
35
+ border-radius: 8px;
36
+}
37
+.pwdinput{
38
+ align-items: center;
39
+ padding: 4px;
40
+ width: 90%;
41
+ height: 30px; 
42
+ color: #54bec2;
43
+}
44
+.imageStyle{
45
+  width: 25px;
46
+  height: 25px;
47
+}
48
+.text{
49
+ font-size: 30rpx;
50
+ color: #54bec2;
51
+ display: flex;
52
+ align-items: center;
53
+ justify-content: center;
54
+}
55
+
56
+.receiver_info_scroll_view{
57
+  width: 90%;
58
+  height: 200px;
59
+  margin-left: 4%;
60
+  margin-right: 4%;
61
+  margin-top: 10px;
62
+  margin-bottom: 25px;
63
+  border: 1px solid black;
64
+}
65
+
66
+.result{
67
+  width: 90%;
68
+  height: 150px;
69
+  border: 1px solid black;
70
+  margin-left: 4%;
71
+  margin-bottom: 4%;
72
+  margin-top: 5%
73
+}
74
+
75
+button{
76
+  width: 90%;
77
+  margin-left: 5%;
78
+  margin-right: 5%;
79
+}
80
+
81
+.switch{
82
+  float: right;
83
+  margin-right: 20px;
84
+  margin-bottom: 16px;
85
+}
86
+
87
+text{
88
+  color: #fff;
89
+  display: block;
90
+}
91
+
92
+input{
93
+  color: gainsboro;
94
+  float: left;
95
+}
96
+
97
+.v_net_ssid{
98
+  width: 100%;
99
+  background:  #fff;
100
+}
101
+
102
+.v_net_passw{
103
+  width: 100%;
104
+  background: antiquewhite;
105
+}
106
+
107
+.swiper{
108
+  width: 100%;
109
+  height: 100%;
110
+}
111
+.button {
112
+  margin-top: 20px;
113
+  width: 90%;
114
+  background-color: #54bec2;
115
+  color: white;
116
+  border-radius: 98rpx;
117
+  background: bg_red;
118
+}
119
+ 
120
+/* 按下变颜色 */
121
+.hover {
122
+  background:  rgb(247, 176, 176);
123
+}

+ 59 - 0
pages/order/order.js

@@ -0,0 +1,59 @@
1
+// pages/order/order.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+    tabList: [
9
+      "入库单",
10
+      "出库单",
11
+      "供应商退货",
12
+      "客户退货",
13
+    ],
14
+    orderList:[
15
+      {
16
+        _index:"43644482767687HGF",
17
+        type:"Airpods第三代",
18
+        supplier:"华强北",
19
+        onNum:100,
20
+        price:88888,
21
+        ps:'一等'
22
+      }
23
+    ],
24
+    tabIndex: 0,
25
+    tabTitle:"入库单",
26
+  },
27
+
28
+  /**
29
+   * 生命周期函数--监听页面加载
30
+   */
31
+  onLoad(options) {
32
+
33
+  },
34
+
35
+  /**
36
+   * 生命周期函数--监听页面初次渲染完成
37
+   */
38
+  onReady() {
39
+
40
+  },
41
+
42
+  /**
43
+   * 生命周期函数--监听页面显示
44
+   */
45
+  onShow() {
46
+
47
+  },
48
+  onChangeTab(e) {
49
+    this.setData({
50
+      tabIndex: e.currentTarget.dataset.index,
51
+      tabTitle:e.currentTarget.dataset.item
52
+    })
53
+  },
54
+  onDetails(e){
55
+    wx.navigateTo({
56
+      url: '/pages/orderDetails/orderDetails',
57
+    })
58
+  }
59
+})

+ 8 - 0
pages/order/order.json

@@ -0,0 +1,8 @@
1
+{
2
+  "navigationBarTitleText": "订单",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "van-empty": "@vant/weapp/empty/index"
7
+  }
8
+}

+ 37 - 0
pages/order/order.wxml

@@ -0,0 +1,37 @@
1
+<!-- <view class="mine">
2
+  <view class="navbar">
3
+    <view wx:for="{{tabList}}" class="list {{index==tabIndex?'active':''}}" bindtap="onChangeTab" data-item="{{item}}" data-index="{{index}}">{{item}}</view>
4
+  </view>
5
+  <view class="details-list" wx:for="{{orderList}}">
6
+    <view class="list-info">
7
+      <view class="header">{{tabTitle}}</view>
8
+      <view class="info-text">
9
+        <text>批次编号:</text>
10
+        <text>{{item._index}}</text>
11
+      </view>
12
+      <view class="info-text">
13
+        <text decode="{{true}}" space="{{true}}">品&emsp;&emsp;类:</text>
14
+        <text>{{item._index}}</text>
15
+      </view>
16
+      <view class="info-text">
17
+        <text decode="{{true}}" space="{{true}}">供&ensp;应&ensp;商:</text>
18
+        <text>{{item._index}}</text>
19
+      </view>
20
+      <view class="info-text">
21
+        <text>入库数量:</text>
22
+        <text>{{item._index}}</text>
23
+      </view>
24
+      <view class="info-text">
25
+        <text decode="{{true}}" space="{{true}}">价&emsp;&emsp;格:</text>
26
+        <text>{{item._index}}</text>
27
+      </view>
28
+      <view class="info-text">
29
+        <text decode="{{true}}" space="{{true}}">备&emsp;&emsp;注:</text>
30
+        <text>{{item._index}}</text>
31
+      </view>
32
+      <view class="more-see" data-item="{{item}}" data-index="{{index}}" bindtap="onDetails">查看更多 <image src="https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/toDetails.png"></image>
33
+      </view>
34
+    </view>
35
+  </view>
36
+</view> -->
37
+<van-empty description="敬请期待!" />

+ 84 - 0
pages/order/order.wxss

@@ -0,0 +1,84 @@
1
+/* pages/order/order.wxss */
2
+.navbar {
3
+  width: 100%;
4
+  height: 128rpx;
5
+  display: flex;
6
+  background: #FFFFFF;
7
+  justify-content: space-around;
8
+
9
+}
10
+
11
+.navbar .list {
12
+  height: 128rpx;
13
+  line-height: 128rpx;
14
+  font-family: PingFangSC-Regular;
15
+  font-size: 16px;
16
+  color: #999999;
17
+  letter-spacing: 0;
18
+  text-align: center;
19
+}
20
+
21
+.navbar .active {
22
+  border-bottom: 6rpx solid #0271E3;
23
+  color: #333333;
24
+}
25
+
26
+.details-list {
27
+  padding: 12rpx 30rpx;
28
+
29
+}
30
+
31
+.details-list .list-info {
32
+  margin-top: 56rpx;
33
+  position: relative;
34
+  padding: 90rpx 28rpx 0 28rpx;
35
+  background: #FFFFFF;
36
+  box-shadow: 0 -1px 8px 0 rgba(0, 0, 0, 0.04);
37
+  border-radius: 12px;
38
+}
39
+
40
+.details-list .list-info .header {
41
+  position: absolute;
42
+  left: 0;
43
+  top: -24rpx;
44
+  width: 178rpx;
45
+  height: 96rpx;
46
+  background: url(https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/tabBag.png) no-repeat;
47
+  background-size: 100% 100%;
48
+  font-family: PingFangSC-Semibold;
49
+  font-size: 32rpx;
50
+  color: #FFFFFF;
51
+  letter-spacing: 0;
52
+  text-align: center;
53
+  line-height: 70rpx;
54
+}
55
+
56
+.details-list .list-info .info-text {
57
+  margin-bottom: 30rpx;
58
+}
59
+
60
+.details-list .list-info .info-text text {
61
+  font-family: PingFangSC-Regular;
62
+  font-size: 32rpx;
63
+  color: #333333;
64
+  letter-spacing: 0;
65
+
66
+}
67
+
68
+.details-list .more-see {
69
+  height: 100rpx;
70
+  line-height: 100rpx;
71
+  border-top: 1px solid #E4E4E4;
72
+  display: flex;
73
+  justify-content: center;
74
+  align-items: center;
75
+  font-family: PingFangSC-Regular;
76
+  font-size: 28rpx;
77
+  color: #333333;
78
+  text-align: center;
79
+}
80
+
81
+.details-list .more-see image {
82
+  width: 48rpx;
83
+  height: 48rpx;
84
+}

+ 73 - 0
pages/orderDetails/orderDetails.js

@@ -0,0 +1,73 @@
1
+// pages/orderDetails/orderDetails.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+      info:{
9
+        _index:"43644482767687HGF",
10
+        type:"Airpods第三代",
11
+        supplier:"华强北",
12
+        onNum:100,
13
+        price:88888,
14
+        ps:'一等'
15
+      }
16
+  },
17
+
18
+  /**
19
+   * 生命周期函数--监听页面加载
20
+   */
21
+  onLoad: function (options) {
22
+
23
+  },
24
+
25
+  /**
26
+   * 生命周期函数--监听页面初次渲染完成
27
+   */
28
+  onReady: function () {
29
+
30
+  },
31
+
32
+  /**
33
+   * 生命周期函数--监听页面显示
34
+   */
35
+  onShow: function () {
36
+
37
+  },
38
+
39
+  /**
40
+   * 生命周期函数--监听页面隐藏
41
+   */
42
+  onHide: function () {
43
+
44
+  },
45
+
46
+  /**
47
+   * 生命周期函数--监听页面卸载
48
+   */
49
+  onUnload: function () {
50
+
51
+  },
52
+
53
+  /**
54
+   * 页面相关事件处理函数--监听用户下拉动作
55
+   */
56
+  onPullDownRefresh: function () {
57
+
58
+  },
59
+
60
+  /**
61
+   * 页面上拉触底事件的处理函数
62
+   */
63
+  onReachBottom: function () {
64
+
65
+  },
66
+
67
+  /**
68
+   * 用户点击右上角分享
69
+   */
70
+  onShareAppMessage: function () {
71
+
72
+  }
73
+})

+ 8 - 0
pages/orderDetails/orderDetails.json

@@ -0,0 +1,8 @@
1
+{
2
+  "navigationBarTitleText": "详情",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "van-field": "@vant/weapp/field/index"
7
+  }
8
+}

+ 35 - 0
pages/orderDetails/orderDetails.wxml

@@ -0,0 +1,35 @@
1
+<view class="mine">
2
+  <view class="info-text">
3
+    <text>批次编号:</text>
4
+    <text>{{info._index}}</text>
5
+  </view>
6
+  <view class="info-text info-type">
7
+    <text decode="{{true}}" space="{{true}}">品&emsp;&emsp;类:</text>
8
+    <text>{{info.type}}</text>
9
+  </view>
10
+  <view class="info-text info-supplier">
11
+    <text decode="{{true}}" space="{{true}}">供&ensp;应&ensp;商:</text>
12
+    <van-field value="{{info.supplier}}" border="{{ false }}" />
13
+  </view>
14
+  <view class="info-text info-num">
15
+    <text>入库数量:</text>
16
+    <van-field value="{{info.onNum}}" border="{{ false }}"> <text slot="button" size="small">
17
+        个
18
+      </text></van-field>
19
+  </view>
20
+  <view class="info-text info-price">
21
+    <text>价格:</text>
22
+    <van-field value="{{info.price}}" border="{{ false }}"> <text slot="button" size="small">
23
+        元
24
+      </text></van-field>
25
+  </view>
26
+  <view class="info-text info-ps">
27
+    <text>备注:</text>
28
+    <view class="remarks">
29
+      <van-field value="{{ info.ps }}" type="textarea" placeholder="输入备注" autosize border="{{ false }}" />
30
+    </view>
31
+  </view>
32
+  <view class="operation">
33
+    更新
34
+  </view>
35
+</view>

+ 79 - 0
pages/orderDetails/orderDetails.wxss

@@ -0,0 +1,79 @@
1
+/* pages/orderDetails/orderDetails.wxss */
2
+.mine {
3
+  padding: 64rpx 28rpx 120rpx 28rpx;
4
+  position: relative;
5
+
6
+}
7
+
8
+.mine .info-text {
9
+  font-family: PingFangSC-Regular;
10
+  font-size: 32rpx;
11
+  color: #333333;
12
+  letter-spacing: 0;
13
+}
14
+
15
+.mine .info-type {
16
+  margin-top: 24rpx;
17
+}
18
+
19
+.mine .info-supplier {
20
+  margin-top: 40rpx;
21
+}
22
+
23
+.van-cell {
24
+  margin-top: 18rpx;
25
+  border-radius: 8px;
26
+  padding-top: 34rpx !important;
27
+  padding-bottom: 34rpx !important;
28
+}
29
+
30
+.van-field__label {
31
+  font-size: 32rpx !important;
32
+  font-family: PingFangSC-Regular !important;
33
+  color: #333333 !important;
34
+}
35
+
36
+.van-field__control {
37
+  font-size: 32rpx !important;
38
+  font-family: PingFangSC-Regular !important;
39
+  color: #333333 !important;
40
+}
41
+
42
+.van-field__button {
43
+  height: 32rpx;
44
+  line-height: 10rpx;
45
+}
46
+
47
+.mine .info-num {
48
+  margin-top: 40rpx;
49
+}
50
+
51
+.mine .info-price {
52
+  margin-top: 40rpx;
53
+}
54
+
55
+.mine .info-ps {
56
+  margin-top: 40rpx;
57
+}
58
+
59
+.mine .info-ps .remarks {
60
+  background: #FFFFFF;
61
+  height: 224rpx;
62
+}
63
+
64
+.operation {
65
+  margin-top: 88rpx;
66
+  width: 626rpx;
67
+  height: 96rpx;
68
+  line-height: 96rpx;
69
+  background: #0271E3;
70
+  border-radius: 48rpx;
71
+  font-family: PingFangSC-Regular;
72
+  font-size: 36rpx;
73
+  color: #FFFFFF;
74
+  letter-spacing: 0;
75
+  text-align: center;
76
+  position: relative;
77
+  left: 50%;
78
+  transform: translateX(-50%);
79
+}

+ 51 - 0
pages/qualityTesting/qualityTesting.js

@@ -0,0 +1,51 @@
1
+// pages/qualityTesting/qualityTesting.js
2
+Page({
3
+
4
+  /**
5
+   * 页面的初始数据
6
+   */
7
+  data: {
8
+    tabList: [{
9
+        id: 0,
10
+        title: "手机质检"
11
+      },
12
+      {
13
+        id: 1,
14
+        title: "耳机质检"
15
+      }
16
+    ],
17
+    equiInfo:{
18
+      onlyIndex:'djikdjuodjojd',
19
+      model:'iPhone 11pro',
20
+      color:'黑色',
21
+      memory:'64G',
22
+    },
23
+    nowIndex: 0,
24
+    status:1,
25
+  },
26
+
27
+  /**
28
+   * 生命周期函数--监听页面加载
29
+   */
30
+  onLoad(options) {
31
+
32
+  },
33
+
34
+  /**
35
+   * 生命周期函数--监听页面初次渲染完成
36
+   */
37
+  onReady() {
38
+
39
+  },
40
+
41
+  onChangeTab(e) {
42
+    this.setData({
43
+      nowIndex: e.currentTarget.dataset.index
44
+    })
45
+  },
46
+  onceshi() {
47
+    wx.navigateTo({
48
+      url: '/pages/home/home',
49
+    })
50
+  }
51
+})

+ 9 - 0
pages/qualityTesting/qualityTesting.json

@@ -0,0 +1,9 @@
1
+{
2
+  "navigationBarTitleText": "质检",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "van-field": "@vant/weapp/field/index",
7
+    "van-empty": "@vant/weapp/empty/index"
8
+  }
9
+}

+ 32 - 0
pages/qualityTesting/qualityTesting.wxml

@@ -0,0 +1,32 @@
1
+<!-- <view class="mine">
2
+  <view class="navbar">
3
+    <view class="nav-info {{nowIndex==index?'active':''}}" wx:for="{{tabList}}" data-index="{{index}}" bindtap="onChangeTab">{{item.title}}</view>
4
+  </view>
5
+  <view class="qua-status {{status==2?'status-active':''}}">
6
+    <view class="status-tips">您的手机项目检测状态:</view>
7
+    <view class="status-text {{status==2?'text-active':''}}">{{status==1?'未开始':'已完成'}}</view>
8
+  </view>
9
+  <view class="content">
10
+    <view class="code-info">
11
+      <view class="code-title">Airpods唯一标识</view>
12
+      <view class="code-info-modul">
13
+        <van-field value="{{ equiInfo.onlyIndex }}" />
14
+        <view class="scan-code"><image src=""></image></view>
15
+      </view>
16
+      <view class="equi-info">
17
+        <view>型号:{{equiInfo.model}}</view>
18
+        <view>颜色:{{equiInfo.color}}</view>
19
+        <view>内存:{{equiInfo.memory}}</view>
20
+      </view>
21
+      <view class="print-code" bindtap="onceshi">
22
+            打印条码
23
+      </view>
24
+    </view>
25
+    <view class="appe">
26
+      <view class="appe-title">
27
+
28
+      </view>
29
+    </view>
30
+  </view>
31
+</view> -->
32
+<van-empty description="敬请期待!" />

+ 136 - 0
pages/qualityTesting/qualityTesting.wxss

@@ -0,0 +1,136 @@
1
+/* pages/qualityTesting/qualityTesting.wxss */
2
+.mine {
3
+  padding-top: 4rpx;
4
+}
5
+
6
+.navbar {
7
+  padding: 28rpx 38rpx;
8
+  display: flex;
9
+}
10
+
11
+.navbar .nav-info {
12
+  flex: 1;
13
+  height: 80rpx;
14
+  text-align: center;
15
+  line-height: 80rpx;
16
+  background: #EEEEEE;
17
+  font-family: PingFangSC-Regular;
18
+  font-size: 32rpx;
19
+  color: #666666;
20
+  letter-spacing: 0;
21
+  text-align: center;
22
+}
23
+
24
+.navbar .nav-info:nth-child(1) {
25
+  border-radius: 24px 0 0 24px;
26
+}
27
+
28
+.navbar .nav-info:nth-child(2) {
29
+  border-radius: 0 24px 24px 0;
30
+}
31
+
32
+.navbar .active {
33
+  background: #0271E3;
34
+  color: #FFFFFF;
35
+}
36
+
37
+.qua-status {
38
+  height: 106rpx;
39
+  padding: 0 38rpx;
40
+  display: flex;
41
+  justify-content: space-between;
42
+  background: #DEDEDE;
43
+  align-items: center;
44
+  border-radius: 0 0 24rpx 24rpx;
45
+  font-family: PingFangSC-Regular;
46
+  font-size: 32rpx;
47
+  color: #333333;
48
+  letter-spacing: 0;
49
+}
50
+
51
+.qua-status .status-tips {
52
+  padding-left: 40rpx;
53
+}
54
+
55
+.qua-status .status-text {
56
+  font-family: PingFangSC-Medium;
57
+  font-size: 36rpx;
58
+  color: #999999;
59
+}
60
+
61
+.status-active {
62
+  background: #0DB853;
63
+  color: #FFFFFF;
64
+}
65
+
66
+.qua-status .text-active {
67
+  color: #FFFFFF;
68
+}
69
+
70
+.content {
71
+  padding: 28rpx;
72
+}
73
+
74
+.content .code-info {
75
+  padding: 32rpx 30rpx 42rpx 30rpx;
76
+  background: #FFFFFF;
77
+  border-radius: 12px;
78
+  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
79
+  position: relative;
80
+}
81
+
82
+.content .code-title {
83
+  font-family: PingFangSC-Medium;
84
+  font-size: 32rpx;
85
+  color: #333333;
86
+  letter-spacing: 0;
87
+}
88
+
89
+.content .code-info .code-info-modul .van-cell {
90
+  left: -30rpx;
91
+  /* width: 400rpx; */
92
+}
93
+
94
+.content .code-info .code-info-modul text {
95
+  font-family: PingFangSC-Regular;
96
+  font-size: 24rpx;
97
+  color: #999999;
98
+  letter-spacing: 0;
99
+}
100
+
101
+.content .code-info .code-info-modul image {
102
+  width: 48rpx;
103
+  height: 48rpx;
104
+}
105
+
106
+.equi-info {
107
+  margin-top: 24rpx;
108
+  font-size: 24rpx;
109
+  font-family: PingFangSC-Regular, PingFang SC;
110
+  font-weight: 400;
111
+  color: #333333;
112
+  line-height: 34px;
113
+  text-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
114
+  display: flex;
115
+  justify-content: space-between;
116
+}
117
+
118
+.print-code {
119
+  margin-top: 60rpx;
120
+  height: 96rpx;
121
+  line-height: 96rpx;
122
+  text-align: center;
123
+  background: #0271E3;
124
+  box-shadow: 0px 2px 10px 0px rgba(0, 0, 0, 0.1);
125
+  border-radius: 48rpx;
126
+  font-size: 36rpx;
127
+  font-family: PingFangSC-Regular, PingFang SC;
128
+  font-weight: 400;
129
+  color: #FFFFFF;
130
+}
131
+
132
+.appe {
133
+  opacity: 0.71;
134
+  background: #FFFFFF;
135
+
136
+}

+ 578 - 0
pages/receipt/receipt.js

@@ -0,0 +1,578 @@
1
+var app = getApp();
2
+var esc = require("../../utils/esc.js");
3
+var encode = require("../../utils/encoding.js");
4
+
5
+function inArray(arr, key, val) {
6
+	for (let i = 0; i < arr.length; i++) {
7
+		if (arr[i][key] === val) {
8
+			return i;
9
+		}
10
+	}
11
+	return -1;
12
+}
13
+
14
+// ArrayBuffer转16进度字符串示例
15
+function ab2hex(buffer) {
16
+	var hexArr = Array.prototype.map.call(
17
+		new Uint8Array(buffer),
18
+		function(bit) {
19
+			return ('00' + bit.toString(16)).slice(-2)
20
+		}
21
+	)
22
+	return hexArr.join('');
23
+}
24
+
25
+function convertToGrayscale(data) {
26
+	let g = 0
27
+	for (let i = 0; i < data.length; i += 4) {
28
+		g = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11)
29
+		data[i] = g
30
+		data[i + 1] = g
31
+		data[i + 2] = g
32
+	}
33
+	return data
34
+}
35
+
36
+function setPixel(data, offset, value) {
37
+	data[offset] = value;
38
+	data[offset + 1] = value;
39
+	data[offset + 2] = value;
40
+}
41
+
42
+function adjustPixel(data, offset, value) {
43
+	data[offset] += value;
44
+}
45
+
46
+// 彩色图转成单色图
47
+function convertToMonoImage(width, height, data, shake) {
48
+	let g = 0
49
+	let e = 0
50
+
51
+	for (let i = 0; i < data.length; i += 4) {
52
+		data[i] = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11);
53
+	}
54
+
55
+	for (let y = 0; y < height; y++) {
56
+		for (let x = 0; x < width; x++) {
57
+			let dataOffset = (width * y + x) * 4;
58
+			g = data[dataOffset];
59
+			if (g >= 150) { // 灰色转黑白的阈值, 可以调整打印效果
60
+				e = g - 255;
61
+				setPixel(data, dataOffset, 255);
62
+			} else {
63
+				e = g;
64
+				setPixel(data, dataOffset, 0);
65
+			}
66
+
67
+			if (!shake)
68
+				continue;
69
+
70
+			if (x < width - 1 && y < height - 1) {
71
+				//右边像素处理
72
+				data[(width * y + x + 1) * 4] += 7 * e / 16;
73
+				//下
74
+				data[(width * (y + 1) + x) * 4] += 5 * e / 16;
75
+				//右下
76
+				data[(width * (y + 1) + x + 1) * 4] += e / 16;
77
+				//左下
78
+				if (x > 0) {
79
+					data[(width * (y + 1) + x - 1) * 4] += 3 * e / 16;
80
+				}
81
+			} else if (x == width - 1 && y < height - 1) {
82
+				//下方像素处理
83
+				data[(width * (y + 1) + x) * 4] += 5 * e / 16;
84
+			} else if (x < width - 1 && y == height - 1) {
85
+				//右边像素处理
86
+				data[(width * y + x + 1) * 4] += 7 * e / 16;
87
+			}
88
+		}
89
+	}
90
+	return data
91
+}
92
+Page({
93
+
94
+	/**
95
+	 * 页面的初始数据
96
+	 */
97
+	data: {
98
+		looptime: 0,
99
+		currentTime: 1,
100
+		lastData: 0,
101
+		oneTimeData: 0,
102
+		buffSize: [],
103
+		buffIndex: 0, //发送字节数下标
104
+		printNum: [],
105
+		printNumIndex: 0,
106
+		printerNum: 1,
107
+		currentPrint: 1,
108
+		isReceiptSend: false,
109
+		isQuery: false,
110
+		imageSrc: '../../imags/wechat.png',
111
+		jpgSrc: '../../imags/flower2.jpg',
112
+		canvasWidth: 100,
113
+		canvasHeight: 100,
114
+		jpgWidth: 200,
115
+		jpgHeight: 200,
116
+	},
117
+
118
+	/**
119
+	 * 生命周期函数--监听页面加载
120
+	 */
121
+	onLoad: function(options) {
122
+		// this.canvas();
123
+	},
124
+	initPhoto: function() { //初始化画布数据
125
+		//创建一个png格式
126
+		var that = this
127
+		const ctx_out = wx.createCanvasContext('canvasOut', this);
128
+		var png = that.data.imageSrc;
129
+		wx.getImageInfo({
130
+			src: png,
131
+			success(res) {
132
+				that.setData({
133
+					canvasWidth: res.width,
134
+					canvasHeight: res.height,
135
+				});
136
+				console.log("画布宽度" + res.width, "画布高度" + res.height);
137
+				ctx_out.drawImage(png, 0, 0, res.width, res.height);
138
+				ctx_out.draw();
139
+			}
140
+		})
141
+		//创建一个jpg格式图片
142
+		const ctx_jpg = wx.createCanvasContext('canvasJPG', this);
143
+		var jpg_width = that.data.jpgWidth;
144
+		var jpg_height = that.data.jpgHeight;
145
+		var img = that.data.jpgSrc;
146
+		wx.getImageInfo({
147
+			src: img,
148
+			success(res) {
149
+				that.setData({
150
+					jpgWidth: res.width,
151
+					jpgHeight: res.height,
152
+				});
153
+				console.log("JPG画布宽度" + res.width, "JPG画布高度" + res.height);
154
+				ctx_jpg.drawImage(img, 0, 0, res.width, res.height);
155
+				ctx_jpg.draw();
156
+			}
157
+		})
158
+	},
159
+	receiptTest: function() { //票据测试
160
+		var that = this;
161
+		var canvasWidth = that.data.canvasWidth
162
+		var canvasHeight = that.data.canvasHeight
163
+		var command = esc.jpPrinter.createNew()
164
+		command.init() //初始化打印机
165
+		command.setSelectJustification(1) //居中
166
+		command.setCharacterSize(17); //设置倍高倍宽
167
+		command.setText("票据测试");
168
+		command.setPrint(); //打印并换行
169
+		command.setCharacterSize(0); //设置正常大小
170
+		command.setSelectJustification(0) //设置居左
171
+		command.setText("打印对齐方式测试:")
172
+		command.setPrint() //打印并换行
173
+		command.setSelectJustification(0) //设置居左
174
+		command.setText("居左")
175
+		command.setPrint() //打印并换行
176
+		command.setSelectJustification(1) //设置居中
177
+		command.setText("居中")
178
+		command.setPrint()
179
+		command.setSelectJustification(2)
180
+		command.setText("居右");
181
+		command.setPrint()
182
+		command.setSelectJustification(0)
183
+		command.setText("同行打印位置测试:");
184
+		command.setPrint()
185
+		command.setText("居左");
186
+		command.setAbsolutePrintPosition(168)
187
+		command.setText("居中");
188
+		command.setAbsolutePrintPosition(336)
189
+		command.setText("居右");
190
+		command.setPrint()
191
+		command.init() //初始化打印机
192
+		command.setPrint()
193
+		command.setText("条码打印");
194
+		command.setPrint()
195
+		command.setHRIPosition(2) //设置HRI位置
196
+		command.setHRIFont(0) //HRI字体大小
197
+		command.setBarcodeHeight(60) //条码高度
198
+		command.setBarcodeWidth(2) //设置条码宽度
199
+		command.setAbsolutePrintPosition(24)
200
+		command.setCode128("{A12345678"); //code128  A类型
201
+		command.setPrint()
202
+		command.setText("二维码测试:")
203
+		command.setPrint()
204
+		command.setSelectSizeOfModuleForQRCode(5)
205
+		command.setSelectErrorCorrectionLevelForQRCode(49)
206
+		command.setStoreQRCodeData("http://www.howbest.cn/cn/")
207
+		command.setPrintQRCode()
208
+		command.setPrint()
209
+		command.setPrint()
210
+		command.setPrint()
211
+		command.setPrint()
212
+		that.prepareSend(command.getData()) //准备发送数据
213
+
214
+	},
215
+	printPhoto: function() { //打印bitmap,图片内容不建议太大,小程序限制传输的字节数为20byte
216
+		var that = this;
217
+		var canvasWidth = that.data.canvasWidth
218
+		var canvasHeight = that.data.canvasHeight
219
+		var command = esc.jpPrinter.createNew()
220
+		command.init() //初始化打印机
221
+		wx.canvasGetImageData({
222
+			canvasId: 'canvasOut',
223
+			x: 0,
224
+			y: 0,
225
+			width: canvasWidth,
226
+			height: canvasHeight,
227
+			success: function(res) {
228
+				console.log("获取画布数据成功")
229
+				command.setBitmap(res)
230
+				command.setPrint()
231
+				that.prepareSend(command.getData()) //发送数据
232
+			},
233
+			complete: function(res) {
234
+				console.log("finish")
235
+			},
236
+			fail: function(res) {
237
+				console.log(res)
238
+				wx.showToast({
239
+					title: '获取画布数据失败',
240
+					icon: 'none',
241
+				})
242
+			}
243
+		})
244
+	},
245
+	printJPGPhoto: function() {
246
+		var that = this;
247
+		var canvasWidth = that.data.jpgWidth
248
+		var canvasHeight = that.data.jpgHeight
249
+
250
+		//抖动处理JPG图片
251
+		const cfg = {
252
+			x: 0,
253
+			y: 0,
254
+			width: canvasWidth,
255
+			height: canvasHeight,
256
+		}
257
+		wx.canvasGetImageData({
258
+			canvasId: 'canvasJPG',
259
+			...cfg,
260
+			success: (res) => {
261
+				//const data = convertToGrayscale(res.data)
262
+				const data = convertToMonoImage(res.width, res.height, res.data, true);
263
+				wx.canvasPutImageData({
264
+					canvasId: 'canvasJPG',
265
+					data,
266
+					...cfg,
267
+					success: (res) => {
268
+						console.log(res)
269
+						console.log('deal graphic width: ' + cfg.width)
270
+						console.log('deal graphic width: ' + cfg.height)
271
+						that.printerJPG();
272
+					},
273
+					fail: (err) => {
274
+						console.error(err)
275
+					}
276
+				})
277
+			},
278
+			fail: (err) => {
279
+				console.error(err)
280
+			}
281
+		})
282
+	},
283
+	printerJPG: function() {
284
+		var that = this;
285
+		var canvasWidth = that.data.jpgWidth
286
+		var canvasHeight = that.data.jpgHeight
287
+		var command = esc.jpPrinter.createNew()
288
+		command.init() //初始化打印机
289
+		wx.canvasGetImageData({
290
+			canvasId: 'canvasJPG',
291
+			x: 0,
292
+			y: 0,
293
+			width: canvasWidth,
294
+			height: canvasHeight,
295
+			success: function(res) {
296
+				console.log("获取画布数据成功")
297
+				command.setBitmap(res)
298
+				command.setPrint()
299
+				that.prepareSend(command.getData()) //发送数据
300
+			},
301
+			complete: function(res) {
302
+				console.log("finish")
303
+			},
304
+			fail: function(res) {
305
+				console.log(res)
306
+				wx.showToast({
307
+					title: '获取画布数据失败',
308
+					icon: 'none',
309
+				})
310
+			}
311
+		})
312
+	},
313
+	prepareSend: function(buff) { //准备发送,根据每次发送字节数来处理分包数量
314
+		//console.log(buff)
315
+		var that = this
316
+		var time = that.data.oneTimeData
317
+		var looptime = parseInt(buff.length / time);
318
+		var lastData = parseInt(buff.length % time);
319
+		//console.log(looptime + "---" + lastData)
320
+		that.setData({
321
+			looptime: looptime + 1,
322
+			lastData: lastData,
323
+			currentTime: 1,
324
+		})
325
+		that.Send(buff)
326
+	},
327
+	queryStatus: function() { //查询打印机状态
328
+		var that = this
329
+		var buf;
330
+		var dateView;
331
+		/*
332
+		n = 1:传送打印机状态
333
+		n = 2:传送脱机状态
334
+		n = 3:传送错误状态
335
+		n = 4:传送纸传感器状态
336
+		*/
337
+		buf = new ArrayBuffer(3)
338
+		dateView = new DataView(buf)
339
+		dateView.setUint8(0, 16)
340
+		dateView.setUint8(1, 4)
341
+		dateView.setUint8(2, 2)
342
+		wx.writeBLECharacteristicValue({
343
+			deviceId: app.BLEInformation.deviceId,
344
+			serviceId: app.BLEInformation.writeServiceId,
345
+			characteristicId: app.BLEInformation.writeCharaterId,
346
+			value: buf,
347
+			success: function(res) {
348
+				console.log("发送成功")
349
+				that.setData({
350
+					isQuery: true
351
+				})
352
+			},
353
+			fail: function(e) {
354
+				wx.showToast({
355
+					title: '发送失败',
356
+					icon: 'none',
357
+				})
358
+				//console.log(e)
359
+				return;
360
+			},
361
+			complete: function() {
362
+
363
+			}
364
+		})
365
+
366
+		wx.notifyBLECharacteristicValueChange({
367
+			deviceId: app.BLEInformation.deviceId,
368
+			serviceId: app.BLEInformation.notifyServiceId,
369
+			characteristicId: app.BLEInformation.notifyCharaterId,
370
+			state: true,
371
+			success: function(res) {
372
+				wx.onBLECharacteristicValueChange(function(r) {
373
+					console.log(
374
+						`characteristic ${r.characteristicId} has changed, now is ${r}`
375
+						)
376
+					var result = ab2hex(r.value)
377
+					console.log("返回" + result)
378
+					var tip = ''
379
+					if (result == 12) { //正常
380
+						tip = "正常"
381
+					} else if (result == 32) { //缺纸
382
+						tip = "缺纸"
383
+					} else if (result == 36) { //开盖、缺纸
384
+						tip = "开盖、缺纸"
385
+					} else if (result == 16) {
386
+						tip = "开盖"
387
+					} else if (result == 40) { //其他错误
388
+						tip = "其他错误"
389
+					} else { //未处理错误
390
+						tip = "未知错误"
391
+					}
392
+					wx.showModal({
393
+						title: '打印机状态',
394
+						content: tip,
395
+						showCancel: false
396
+					})
397
+
398
+				})
399
+			},
400
+			fail: function(e) {
401
+				wx.showModal({
402
+					title: '打印机状态',
403
+					content: '获取失败',
404
+					showCancel: false
405
+				})
406
+				console.log(e)
407
+			},
408
+			complete: function(e) {
409
+				that.setData({
410
+					isQuery: false
411
+				})
412
+				console.log("执行完成")
413
+			}
414
+		})
415
+	},
416
+	Send: function(buff) { //分包发送
417
+		var that = this
418
+		var currentTime = that.data.currentTime
419
+		var loopTime = that.data.looptime
420
+		var lastData = that.data.lastData
421
+		var onTimeData = that.data.oneTimeData
422
+		var printNum = that.data.printerNum
423
+		var currentPrint = that.data.currentPrint
424
+		var buf
425
+		var dataView
426
+		if (currentTime < loopTime) {
427
+			buf = new ArrayBuffer(onTimeData)
428
+			dataView = new DataView(buf)
429
+			for (var i = 0; i < onTimeData; ++i) {
430
+				dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
431
+			}
432
+		} else {
433
+			buf = new ArrayBuffer(lastData)
434
+			dataView = new DataView(buf)
435
+			for (var i = 0; i < lastData; ++i) {
436
+				dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
437
+			}
438
+		}
439
+		//console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
440
+		wx.writeBLECharacteristicValue({
441
+			deviceId: app.BLEInformation.deviceId,
442
+			serviceId: app.BLEInformation.writeServiceId,
443
+			characteristicId: app.BLEInformation.writeCharaterId,
444
+			value: buf,
445
+			success: function(res) {
446
+				if (currentTime <= loopTime) {
447
+					// wx.showLoading({
448
+					//   title: '传输中...',
449
+					// })
450
+				} else {
451
+					wx.showToast({
452
+						title: '已打印第' + currentPrint + '张成功',
453
+					})
454
+				}
455
+				//console.log(res)
456
+			},
457
+			fail: function(e) {
458
+				wx.showToast({
459
+					title: '打印第' + currentPrint + '张失败',
460
+					icon: 'none',
461
+				})
462
+				//console.log(e)
463
+			},
464
+			complete: function() {
465
+				currentTime++
466
+				if (currentTime <= loopTime) {
467
+					that.setData({
468
+						currentTime: currentTime
469
+					})
470
+					that.Send(buff)
471
+				} else {
472
+					if (currentPrint == printNum) {
473
+						that.setData({
474
+							looptime: 0,
475
+							lastData: 0,
476
+							currentTime: 1,
477
+							isReceiptSend: false,
478
+							currentPrint: 1
479
+						})
480
+					} else {
481
+						currentPrint++
482
+						that.setData({
483
+							currentPrint: currentPrint,
484
+							currentTime: 1,
485
+						})
486
+						that.Send(buff)
487
+					}
488
+				}
489
+			}
490
+		})
491
+	},
492
+
493
+	/**
494
+	 * 生命周期函数--监听页面初次渲染完成
495
+	 */
496
+	onReady: function() {
497
+		var list = []
498
+		var numList = []
499
+		var j = 0
500
+		for (var i = 20; i < 200; i += 10) {
501
+			list[j] = i;
502
+			j++
503
+		}
504
+		for (var i = 1; i < 10; i++) {
505
+			numList[i - 1] = i
506
+		}
507
+		this.setData({
508
+			buffSize: list,
509
+			oneTimeData: list[0],
510
+			printNum: numList,
511
+			printerNum: numList[0]
512
+		})
513
+		this.initPhoto();
514
+	},
515
+	buffBindChange: function(res) { //更改打印字节数
516
+		var index = res.detail.value
517
+		var time = this.data.buffSize[index]
518
+		this.setData({
519
+			buffIndex: index,
520
+			oneTimeData: time
521
+		})
522
+	},
523
+	printNumBindChange: function(res) { //更改打印份数
524
+		var index = res.detail.value
525
+		var num = this.data.printNum[index]
526
+		this.setData({
527
+			printNumIndex: index,
528
+			printerNum: num
529
+		})
530
+	},
531
+
532
+	/**
533
+	 * 生命周期函数--监听页面显示
534
+	 */
535
+	onShow: function() {
536
+
537
+	},
538
+	/**
539
+	 * 生命周期函数--监听页面隐藏
540
+	 */
541
+	onHide: function() {
542
+
543
+	},
544
+
545
+	/**
546
+	 * 生命周期函数--监听页面卸载
547
+	 */
548
+	onUnload: function() {
549
+		//关闭蓝牙连接
550
+		// wx.closeBLEConnection({
551
+		//   deviceId: app.BLEInformation.deviceId,
552
+		//   success: function(res) {
553
+		//     console.log("关闭蓝牙成功")
554
+		//   },
555
+		// })
556
+	},
557
+
558
+	/**
559
+	 * 页面相关事件处理函数--监听用户下拉动作
560
+	 */
561
+	onPullDownRefresh: function() {
562
+
563
+	},
564
+
565
+	/**
566
+	 * 页面上拉触底事件的处理函数
567
+	 */
568
+	onReachBottom: function() {
569
+
570
+	},
571
+
572
+	/**
573
+	 * 用户点击右上角分享
574
+	 */
575
+	onShareAppMessage: function() {
576
+
577
+	}
578
+})

+ 3 - 0
pages/receipt/receipt.json

@@ -0,0 +1,3 @@
1
+{
2
+  "navigationBarTitleText": "小票"
3
+}

+ 15 - 0
pages/receipt/receipt.wxml

@@ -0,0 +1,15 @@
1
+<view class="body">
2
+  		<button  class='button'  hover-class="hover" bindtap='receiptTest' loading='{{isReceiptSend}}' disabled='{{isReceiptSend}}'>小票案例</button>
3
+        	<button class='button'  hover-class="hover" bindtap='queryStatus' loading='{{isQuery}}' disabled='{{isQuery}}'>查询状态</button>
4
+          <button class='button'  hover-class="hover" bindtap='printPhoto' >打印图片</button>
5
+          		<canvas canvas-id="canvasOut" class="canvas"  style='border:0px solid; width:{{canvasWidth}}px; height:{{canvasHeight}}px'></canvas>
6
+
7
+           <button class='button'  hover-class="hover" bindtap='printJPGPhoto' >打印彩图</button>
8
+           <canvas canvas-id="canvasJPG" class="canvas" style='border:0px solid; width:{{jpgWidth}}px; height:{{jpgHeight}}px'></canvas>
9
+	<picker style='margin:20px' mode='selector' range='{{buffSize}}' value='{{buffIndex}}' bindchange='buffBindChange'>当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
10
+	</picker>
11
+
12
+	<picker style='margin:20px' mode='selector' range='{{printNum}}' value='{{printNumIndex}}' bindchange='printNumBindChange'>当前打印份数(点击可更换):{{printNum[printNumIndex]}}
13
+	</picker>
14
+
15
+</view>

+ 21 - 0
pages/receipt/receipt.wxss

@@ -0,0 +1,21 @@
1
+/* pages/receipt/receipt.wxss */
2
+.button {
3
+  margin-top: 20px;
4
+  width: 90%;
5
+  background-color: #54bec2;
6
+  color: white;
7
+  border-radius: 98rpx;
8
+  background: bg_red;
9
+}
10
+ 
11
+/* 按下变颜色 */
12
+.hover {
13
+  background:  #DCDCDC;
14
+}
15
+.canvas {
16
+ display:flex;
17
+ margin-top: 15px;
18
+ height: 100%;               
19
+ justify-content: center;
20
+ align-items: center;
21
+}

+ 228 - 0
pages/scanCode/scanCode.js

@@ -0,0 +1,228 @@
1
+import tool from "../../utils/tool"
2
+import {
3
+  get,
4
+  post
5
+} from '../../utils/http.js'
6
+// 移动动画
7
+let animation = wx.createAnimation({});
8
+
9
+Page({
10
+  data: {
11
+    codeList: [], //手机
12
+    qrCodeList: [], //耳机
13
+    userName: '',
14
+    remarks: '',
15
+    nowCode: '',
16
+    type: '',
17
+    popupShow: false,
18
+    againDelete: false,
19
+    deleteOverData: false
20
+  },
21
+  onLoad: function () {
22
+
23
+  },
24
+  onShow() {
25
+    this.donghua()
26
+  },
27
+  donghua() {
28
+    var that = this;
29
+    // 控制向上还是向下移动
30
+    let m = true
31
+    setInterval(function () {
32
+      if (m) {
33
+        animation.translateY(230).step({
34
+          duration: 3000
35
+        })
36
+        m = !m;
37
+      } else {
38
+        animation.translateY(0).step({
39
+          duration: 3000
40
+        })
41
+        m = !m;
42
+      }
43
+
44
+      that.setData({
45
+        animation: animation.export()
46
+      })
47
+    }.bind(this), 3000)
48
+  },
49
+  /**
50
+   * 扫码,延时器
51
+   */
52
+  scancode: tool.debounce(function (e) {
53
+    // 校验扫描结果,并处理
54
+    let code = e[0].detail.result
55
+    // 提示音
56
+    let innerAudioContext = wx.createInnerAudioContext()
57
+    innerAudioContext.src = '/audio/scanCode.mp3'
58
+    innerAudioContext.play()
59
+    console.log(e[0].detail);
60
+    if (this.data.codeList.length == 0 && this.data.qrCodeList.length == 0) {
61
+      this.setData({
62
+        type: e[0].detail.type
63
+      })
64
+    } else {
65
+      if (e[0].detail.type != this.data.type) {
66
+        wx.showToast({
67
+          title: '同一批次只能入库相同的设备',
68
+          icon: 'none'
69
+        })
70
+        return
71
+      }
72
+    }
73
+    console.log('code',code);
74
+    if (e[0].detail.type == "barcode") {
75
+    console.log('code2',code);
76
+      var result = this.data.codeList.some(item => item.imei == code)
77
+      if (!result) {
78
+    console.log('code1',code);
79
+        post('get_phone_info', {
80
+          imei: code
81
+        }, res => {
82
+          console.log(res,'resres');
83
+          if (res.code == 200) {
84
+            let arr = this.data.codeList
85
+            arr.unshift(res.data)
86
+            this.setData({
87
+              codeList: arr
88
+            })
89
+          }else{
90
+            console.log('tanchuang ');
91
+            wx.showToast({
92
+              title: '没有找到该设备',
93
+              icon: 'none'
94
+            })
95
+          }
96
+        })
97
+      } else {
98
+        wx.showToast({
99
+          title: '重复扫码。',
100
+          icon: 'error'
101
+        })
102
+      }
103
+    } else {
104
+      if (JSON.stringify(this.data.qrCodeList).indexOf(code) == -1) {
105
+        let arr = this.data.qrCodeList
106
+        arr.unshift(code)
107
+        this.setData({
108
+          qrCodeList: arr
109
+        })
110
+      } else {
111
+        wx.showToast({
112
+          title: '重复扫码。',
113
+          icon: 'error'
114
+        })
115
+      }
116
+    }
117
+  }, 500),
118
+  warehousing() {
119
+    this.setData({
120
+      popupShow: true
121
+    })
122
+  },
123
+  onOpenShow() {
124
+    this.setData({
125
+      popupShow: true
126
+    })
127
+  },
128
+  /**
129
+   * 入库
130
+   */
131
+  onAddCode() {
132
+    if (this.data.userName.length == 0) {
133
+      wx.showToast({
134
+        title: '请输入客户名',
135
+        icon: 'error'
136
+      })
137
+      return
138
+    }
139
+    let imeiList = []
140
+    this.data.codeList.forEach(item => {
141
+      imeiList.push(item.imei)
142
+    })
143
+    wx.showLoading({
144
+      title: '入库中...',
145
+    })
146
+    let that = this
147
+    post('save_box_info', {
148
+      ids: this.data.type == 'barcode' ? imeiList : this.data.qrCodeList,
149
+      name: this.data.userName,
150
+      comment: this.data.remarks,
151
+      type:this.data.type
152
+    }, res => {
153
+      if (res.code == 200) {
154
+        setTimeout(function () {
155
+          wx.hideLoading()
156
+          wx.showToast({
157
+            title: `成功入库${res.cnt}台设备`,
158
+            icon: 'error'
159
+          })
160
+          that.setData({
161
+            popupShow:false
162
+          })
163
+          that.clearData()
164
+        }, 2000)
165
+      }
166
+    })
167
+  },
168
+  onCloseShow() {
169
+    this.setData({
170
+      popupShow: false,
171
+      codeInfo: ''
172
+    })
173
+  },
174
+  onDelete(e) {
175
+    this.setData({
176
+      nowCode: e.currentTarget.dataset.index,
177
+      againDelete: true
178
+    })
179
+
180
+  },
181
+  /**
182
+   * 删除单条录入数据
183
+   * @param {} e 
184
+   */
185
+  onDeleteCode(e) {
186
+    let index, _codeList
187
+    index = this.data.nowCode
188
+    if (this.data.type == 'barcode') {
189
+      _codeList = this.data.codeList
190
+      _codeList.splice(index, 1)
191
+      this.setData({
192
+        codeList: _codeList,
193
+        againDelete: false
194
+      })
195
+    } else {
196
+      _codeList = this.data.qrCodeList
197
+      _codeList.splice(index, 1)
198
+      this.setData({
199
+        qrCodeList: _codeList,
200
+        againDelete: false
201
+      })
202
+    }
203
+  },
204
+  clearData() {
205
+    this.setData({
206
+      codeList: [], //手机
207
+      qrCodeList: [], //耳机
208
+      userName: '',
209
+      remarks: '',
210
+      nowCode: '',
211
+      type: '',
212
+    })
213
+  },
214
+  /**
215
+   * 清空数据
216
+   */
217
+  onCodeInput() {
218
+    this.setData({
219
+      deleteOverData: true
220
+    })
221
+  },
222
+  onDeleteOverData() {
223
+    this.clearData()
224
+    this.setData({
225
+      deleteOverData: false
226
+    })
227
+  }
228
+})

+ 12 - 0
pages/scanCode/scanCode.json

@@ -0,0 +1,12 @@
1
+{
2
+  "navigationBarTitleText": "质检",
3
+  "navigationBarBackgroundColor": "#313132",
4
+  "navigationBarTextStyle": "white",
5
+  "usingComponents": {
6
+    "van-popup": "@vant/weapp/popup/index",
7
+    "van-field": "@vant/weapp/field/index",
8
+    "van-cell-group": "@vant/weapp/cell-group/index",
9
+    "van-dialog": "@vant/weapp/dialog/index",
10
+    "van-toast": "@vant/weapp/toast/index"
11
+  }
12
+}

+ 78 - 0
pages/scanCode/scanCode.wxml

@@ -0,0 +1,78 @@
1
+<view class="mine">
2
+  <view class="content">
3
+    <view class="camera-content">
4
+      <camera class='scan-camera' mode="scanCode" binderror="cameraError" bindscancode='scancode' frame-size='large'>
5
+              <cover-view class='scan-animation' animation="{{animation}}"></cover-view>
6
+      </camera>
7
+      <view class='cover-corner cover-left-top' src='/images/left-top.png'></view>
8
+      <view class='cover-corner cover-right-top' src='/images/right-top.png'></view>
9
+      <view class='cover-corner cover-left-bottom' src='/images/left-bottom.png'></view>
10
+      <view class='cover-corner cover-right-bottom' src='/images/right-bottom.png'></view>
11
+    </view>
12
+    <view class="cover-tips">
13
+      请扫描相应的条形码
14
+    </view>
15
+    <view class="total">入库数:{{type=='barcode'?codeList.length+'台':qrCodeList.length+'个'}}</view>
16
+    <view class="code-list">
17
+      <view class="list-info">
18
+        <view class="phone-list">
19
+          <view class="serial">序号</view>
20
+          <text> 机型信息</text>
21
+          <text>设备码</text>
22
+        </view>
23
+        <view class="delete-button"></view>
24
+      </view>
25
+      <!-- 手机 -->
26
+      <view wx:if="{{type=='barcode'}}">
27
+        <view class="list-info" wx:for="{{codeList}}">
28
+          <view class="phone-list">
29
+            <view class="serial">{{index+1}}</view>
30
+            <text>{{item.title}}</text>
31
+            <text>{{item.imei}}</text>
32
+          </view>
33
+          <view class="delete-button" bindtap="onDelete" data-item="{{item}}" data-index="{{index}}">
34
+            <image src="https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/delete.png"></image>
35
+          </view>
36
+        </view>
37
+      </view>
38
+      <!-- 耳机 -->
39
+      <view wx:else="">
40
+        <view class="list-info" wx:for="{{qrCodeList}}">
41
+          <view class="phone-list">
42
+            <view class="serial">{{index+1}}</view>
43
+            <text>耳机</text>
44
+            <text>{{item}}</text>
45
+          </view>
46
+          <view class="delete-button" bindtap="onDelete" data-item="{{item}}" data-index="{{index}}">
47
+            <image src="https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxrep/delete.png"></image>
48
+          </view>
49
+        </view>
50
+      </view>
51
+    </view>
52
+    <view class="bottom-btn">
53
+      <!-- <view class="btn" bindtap="onOpenShow">填写条码入库</view>
54
+      <view class="btn" bindtap="onCodeInput">编辑更多信息</view> -->
55
+      <view class="btn" bindtap="onCodeInput">清空</view>
56
+      <view class="btn" bindtap="warehousing">入库</view>
57
+    </view>
58
+  </view>
59
+  <van-popup class="code-popup" show="{{ popupShow }}" round bind:close="onClose">
60
+    <view class="vr-code">
61
+    <view class="code-popup-title">箱号数据</view>
62
+      <van-cell-group>
63
+        <van-field model:value="{{ userName }}" type="textarea" placeholder="请输入客户名" autosize />
64
+        <view>
65
+          <van-field model:value="{{ remarks }}" type="textarea"  border="{{ false }}" placeholder="备注" autosize />
66
+        </view>
67
+      </van-cell-group>
68
+      <view class="popup-botton">
69
+        <view class="btn close-btn" bindtap="onCloseShow">取消</view>
70
+        <view class="btn add-btn" bindtap="onAddCode">添加</view>
71
+      </view>
72
+    </view>
73
+  </van-popup>
74
+  <van-dialog use-slot title="您将删除该型号" show="{{ againDelete }}" show-cancel-button bind:close="onClose" bind:confirm="onDeleteCode">
75
+  </van-dialog>
76
+  <van-dialog use-slot title="您将清空所有记录" show="{{ deleteOverData }}" show-cancel-button bind:close="onClose" bind:confirm="onDeleteOverData">
77
+  </van-dialog>
78
+</view>

+ 203 - 0
pages/scanCode/scanCode.wxss

@@ -0,0 +1,203 @@
1
+/**scan.wxss**/
2
+.mine {
3
+  padding-top: 40rpx;
4
+  width: 100%;
5
+  min-height: 100%;
6
+  display: flex;
7
+  align-items: center;
8
+  justify-content: center;
9
+}
10
+
11
+.content {
12
+  width: 94%;
13
+  border-radius: 10rpx;
14
+  display: flex;
15
+  flex-direction: column;
16
+  align-items: center;
17
+}
18
+
19
+.scan-camera {
20
+  width: 100%;
21
+  height: 100%;
22
+  /* border-radius: 6rpx; */
23
+}
24
+
25
+.camera-content {
26
+  position: relative;
27
+  border: 1px solid #0271E3;
28
+  width: 500rpx;
29
+  height: 500rpx;
30
+}
31
+
32
+.cover-corner {
33
+  width: 80rpx;
34
+  height: 80rpx;
35
+  position: absolute;
36
+}
37
+
38
+.cover-left-top {
39
+  border-top: 6rpx solid #0271E3;
40
+  border-left: 6rpx solid #0271E3;
41
+  left: -6rpx;
42
+  top: -6rpx;
43
+}
44
+
45
+.cover-right-top {
46
+  border-top: 6rpx solid #0271E3;
47
+  border-right: 6rpx solid #0271E3;
48
+  right: -6rpx;
49
+  top: -6rpx;
50
+}
51
+
52
+.cover-left-bottom {
53
+  border-left: 6rpx solid #0271E3;
54
+  border-bottom: 6rpx solid #0271E3;
55
+  left: -6rpx;
56
+  bottom: -6rpx;
57
+}
58
+
59
+.cover-right-bottom {
60
+  border-right: 6rpx solid #0271E3;
61
+  border-bottom: 6rpx solid #0271E3;
62
+  right: -6rpx;
63
+  bottom: -6rpx;
64
+}
65
+
66
+.scan-animation {
67
+  position: absolute;
68
+  top: 10rpx;
69
+  left: 10rpx;
70
+  width: 480rpx;
71
+  height: 8rpx;
72
+  background-color: #08FDFE;
73
+  border-radius: 50%;
74
+}
75
+
76
+.cover-tips {
77
+  width: 100%;
78
+  text-align: center;
79
+  height: 110rpx;
80
+  line-height: 110rpx;
81
+  font-family: PingFangSC-Regular;
82
+  font-size: 32rpx;
83
+  color: #333333;
84
+  letter-spacing: 0;
85
+  border-bottom: 1px solid #F3F3F3;
86
+}
87
+
88
+.code-list {
89
+  width: 100%;
90
+  height: 500rpx;
91
+  overflow-y: scroll;
92
+  padding: 0 10rpx;
93
+}
94
+.total{
95
+  width: 100%;
96
+  text-align: right;
97
+}
98
+
99
+.list-info {
100
+  padding: 20rpx 0;
101
+  border-bottom: 1px solid #cac9c9;
102
+  font-family: PingFangSC-Regular;
103
+  font-size: 28rpx;
104
+  color: #333333;
105
+  letter-spacing: 0;
106
+  display: flex;
107
+  justify-content: space-between;
108
+  align-items: center;
109
+}
110
+.serial{
111
+  width: 70rpx;
112
+  text-align: center;
113
+  margin-right: 20rpx;
114
+}
115
+.code-popup-title{
116
+  text-align: center;
117
+  margin-bottom: 30rpx;
118
+}
119
+.phone-list{
120
+  flex: 1;
121
+  display: flex;
122
+}
123
+.phone-list text{
124
+  flex: 1;
125
+}
126
+.delete-button{
127
+  width: 80rpx;
128
+  text-align: center;
129
+}
130
+
131
+.list-info text {
132
+  word-break: break-all;
133
+}
134
+
135
+.list-info image {
136
+  vertical-align: middle;
137
+  width: 40rpx;
138
+  height: 40rpx;
139
+}
140
+
141
+.bottom-btn {
142
+  width: 100%;
143
+  display: flex;
144
+  justify-content: space-between;
145
+  align-items: center;
146
+  padding: 66rpx 0 58rpx 0;
147
+}
148
+
149
+.bottom-btn .btn {
150
+  width: 40%;
151
+  height: 96rpx;
152
+  line-height: 96rpx;
153
+  text-align: center;
154
+  font-family: PingFangSC-Regular;
155
+  font-size: 32rpx;
156
+  color: #979797;
157
+  letter-spacing: 0;
158
+  border: 1px solid #979797;
159
+  border-radius: 52rpx;
160
+}
161
+
162
+.bottom-btn .btn:nth-child(2) {
163
+  background: #0271E3;
164
+  color: #FFFFFF;
165
+}
166
+.code-popup{
167
+  /* border-radius: 50%; */
168
+}
169
+
170
+.vr-code {
171
+  width: 600rpx;
172
+  min-height: 200rpx;
173
+  padding: 40rpx;
174
+  background: #FFFFFF;
175
+  box-shadow: 0 -1px 8px 0 rgba(0, 0, 0, 0.04);
176
+  border-radius: 12px;
177
+  position: relative;
178
+  padding-bottom: 160rpx;
179
+}
180
+.popup-botton{
181
+  width: 100%;
182
+  position: absolute;
183
+  bottom: 40rpx;
184
+  left: 0;
185
+  display: flex;
186
+  justify-content: space-around;
187
+}
188
+.popup-botton .btn{
189
+  width: 216rpx;
190
+  height: 96rpx;
191
+  line-height: 96rpx;
192
+  text-align: center;
193
+  font-family: PingFangSC-Regular;
194
+  font-size: 32rpx;
195
+  color: #666666;
196
+  letter-spacing: 0;
197
+  border: 1px solid #979797;
198
+  border-radius: 52rpx;
199
+}
200
+.popup-botton .add-btn{
201
+  background: #0271E3;
202
+  color: #FFFFFF;
203
+}

+ 509 - 0
pages/sendCommand/sendCommand.js

@@ -0,0 +1,509 @@
1
+// pages/sendCommand/sendCommand.js
2
+
3
+/**
4
+ * 此Demo仅供参考,可打印数字,英文,符号,中文,
5
+ * 小程序支持的蓝牙为低功耗蓝牙(BLE),数据量大需分包发送
6
+ */
7
+
8
+var app = getApp();
9
+var tsc = require("../../utils/tsc.js");
10
+var esc = require("../../utils/esc.js");
11
+var encode = require("../../utils/encoding.js");
12
+
13
+function convertToGrayscale(data) {
14
+  let g = 0
15
+  for (let i = 0; i < data.length; i += 4) {
16
+    g = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11)
17
+    data[i] = g
18
+    data[i + 1] = g
19
+    data[i + 2] = g
20
+  }
21
+  return data
22
+}
23
+
24
+function setPixel(data, offset, value) {
25
+  data[offset] = value;
26
+  data[offset+1] = value;
27
+  data[offset+2] = value;
28
+}
29
+
30
+function adjustPixel(data, offset, value) {
31
+  data[offset] += value;
32
+}
33
+
34
+// 彩色图转成单色图
35
+function convertToMonoImage(width, height, data, shake) {
36
+  let g = 0
37
+  let e = 0
38
+
39
+  for(let i=0; i<data.length; i+=4) {
40
+    data[i] = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11);
41
+  }
42
+
43
+  for(let y=0; y<height; y++) {
44
+    for(let x=0; x<width; x++) {
45
+      let dataOffset = (width * y + x) * 4;
46
+      g = data[dataOffset];
47
+      if(g >= 150) {  // 灰色转黑白的阈值, 可以调整打印效果
48
+        e = g - 255;
49
+        setPixel(data, dataOffset, 255);
50
+      } else {
51
+        e = g;
52
+        setPixel(data, dataOffset, 0);
53
+      }
54
+
55
+      if(!shake)
56
+        continue;
57
+
58
+      if (x < width - 1 && y < height - 1) {
59
+        //右边像素处理
60
+        data[(width * y + x + 1)*4] += 7 * e / 16;
61
+        //下
62
+        data[(width * (y + 1) + x)*4] += 5 * e / 16;
63
+        //右下
64
+        data[(width * (y + 1) + x + 1)*4] += e / 16;
65
+        //左下
66
+        if (x > 0) {
67
+          data[(width * (y + 1) + x - 1)*4] += 3 * e / 16;
68
+        }
69
+      } else if (x == width - 1 && y < height - 1) {
70
+        //下方像素处理
71
+        data[(width * (y + 1) + x)*4] += 5 * e / 16;
72
+      } else if (x < width - 1 && y == height - 1) {
73
+        //右边像素处理
74
+        data[(width * y + x + 1)*4] += 7 * e / 16;
75
+      }
76
+    }
77
+  }
78
+  return data
79
+}
80
+
81
+Page({
82
+
83
+  /**
84
+   * 页面的初始数据
85
+   */
86
+  data: {
87
+    sendContent: "",
88
+    looptime: 0,
89
+    currentTime: 1,
90
+    lastData: 0,
91
+    oneTimeData: 0,
92
+    returnResult: "",
93
+    canvasWidth: 180,
94
+    canvasHeight: 180,
95
+    imageSrc: '../../imags/abc_ic_star_black_16dp.png',
96
+    buffSize: [],
97
+    buffIndex: 0,
98
+    printNum: [],
99
+    printNumIndex: 0,
100
+    printerNum: 1,
101
+    currentPrint: 1,
102
+    isReceiptSend: false,
103
+    isLabelSend: false
104
+  },
105
+
106
+  /**
107
+   * 生命周期函数--监听页面加载
108
+   */
109
+  onLoad: function (options) {
110
+    var that = this;
111
+    wx.notifyBLECharacteristicValueChange({
112
+      deviceId: app.BLEInformation.deviceId,
113
+      serviceId: app.BLEInformation.notifyServiceId,
114
+      characteristicId: app.BLEInformation.notifyCharaterId,
115
+      state: true,
116
+      success: function (res) {
117
+        wx.onBLECharacteristicValueChange(function (r) {
118
+          console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
119
+        })
120
+      },
121
+      fail: function (e) {
122
+        console.log(e)
123
+      },
124
+      complete: function (e) {
125
+        console.log(e)
126
+      }
127
+    })
128
+  },
129
+
130
+  inputEvent: function (e) { //获取输入内容
131
+    this.setData({
132
+      sendContent: e.detail.value
133
+    })
134
+  },
135
+
136
+  sendData: function () { //输入框点击发送
137
+    var data = this.data.sendContent + "\n"
138
+
139
+    this.setData({
140
+      looptime: 0
141
+    })
142
+    var content = new encode.TextEncoder(
143
+      'gb18030', {
144
+        NONSTANDARD_allowLegacyEncoding: true
145
+      }).encode(data);
146
+
147
+    this.prepareSend(content)
148
+  },
149
+
150
+  labelTest: function () { //标签测试
151
+    var that = this;
152
+    var canvasWidth = that.data.canvasWidth
153
+    var canvasHeight = that.data.canvasHeight
154
+    var command = tsc.jpPrinter.createNew()
155
+    command.setSize(48, 40)
156
+    command.setGap(0)
157
+    command.setCls()
158
+    // command.setText(0, 30, "TSS24.BF2", 1, 1, "图片")
159
+    // command.setQrcode(40, 120, "L", 4, "A", "www.gainscha.com佳博浩盛")
160
+    // command.setText(60, 90, "TSS24.BF2", 1, 1, "佳博浩盛")
161
+    // command.setText(170, 50, "TSS24.BF2", 1, 1, "小程序测试")
162
+    // command.setText(170, 90, "TSS24.BF2", 1, 1, "测试数字12345678")
163
+    // command.setText(170, 120, "TSS24.BF2", 1, 1, "测试英文abcdefg")
164
+    // command.setText(170, 150, "TSS24.BF2", 1, 1, "测试符号/*-+!@#$")
165
+    // command.setBarCode(170, 180, "EAN8", 64, 1, 0,3, 3, "1234567")
166
+
167
+    wx.canvasGetImageData({
168
+      canvasId: 'canvasOut',
169
+      x: 0,
170
+      y: 0,
171
+      width: canvasWidth,
172
+      height: canvasHeight,
173
+      success: function (res) {
174
+        console.log('res len= ' + res.data.length)
175
+        command.setBitmap(60, 0, 1, res)
176
+        command.setPrint(1)
177
+        that.prepareSend(command.getData())
178
+      },
179
+      complete: function () {
180
+        command.setPagePrint()
181
+        that.setData({
182
+          isLabelSend: true
183
+        })
184
+      }
185
+    })
186
+
187
+  },
188
+
189
+  receiptTest: function () { //票据测试
190
+    var that = this;
191
+    var canvasWidth = that.data.canvasWidth
192
+    var canvasHeight = that.data.canvasHeight
193
+    var command = esc.jpPrinter.createNew()
194
+    command.init()
195
+    command.setText("票据测试!");
196
+    command.setPrint()
197
+    command.setText("This is a receipt test!!!")
198
+    command.setPrint()
199
+    command.setText("二维码测试:")
200
+    command.setPrint()
201
+    command.setSelectSizeOfModuleForQRCode(5)
202
+    command.setSelectErrorCorrectionLevelForQRCode(49)
203
+    command.setStoreQRCodeData("佳博浩盛打印机")
204
+    command.setPrintQRCode()
205
+    command.setPrint()
206
+    command.setSelectJustification(0)
207
+    command.setText("向左对齐")
208
+    command.setPrint()
209
+    command.setSelectJustification(1)
210
+    command.setText("居中对齐")
211
+    command.setPrint()
212
+    command.setSelectJustification(2)
213
+    command.setText("向右对齐")
214
+    command.setPrint()
215
+    command.setSelectJustification(0)
216
+    command.setText("图片测试")
217
+    command.setPrint()
218
+
219
+    wx.canvasGetImageData({
220
+      canvasId: 'canvasOut',
221
+      x: 0,
222
+      y: 0,
223
+      width: canvasWidth,
224
+      height: canvasHeight,
225
+      success: function (res) {
226
+        command.setBitmap(res)
227
+        that.prepareSend(command.getData())
228
+      },
229
+      complete: function (res) {
230
+        console.log("finish")
231
+        command.setPrint()
232
+        that.setData({
233
+          isReceiptSend: true
234
+        })
235
+        //that.prepareSend(command.getData())
236
+      }
237
+    })
238
+
239
+    // this.send(buff)
240
+  },
241
+
242
+  openAndDraw() {
243
+    var that = this
244
+    const MAX_WIDTH = 384;  // 58打印宽度
245
+    //const MAX_WIDTH = 576;  // 80打印宽度
246
+    const MAX_HEIGHT = 256;
247
+    wx.chooseImage({
248
+      success: (res) => {
249
+        const ctx_in = wx.createCanvasContext('canvasIn', this);
250
+        const ctx_out = wx.createCanvasContext('canvasOut', this);
251
+        wx.getImageInfo({
252
+          src: res.tempFilePaths[0],
253
+          success(info) {
254
+            console.log('origin width: ' + info.width)
255
+            console.log('origin height: ' + info.height)
256
+            var imgWidth = info.width;
257
+            var imgHeight = info.height;
258
+            var canWidth = imgWidth;
259
+            var canHeight = imgHeight;
260
+            var canScale = 1.0;
261
+
262
+            // 按 MAX_WIDTH 调整图片宽度
263
+            if(imgWidth > MAX_WIDTH) {
264
+              canWidth = MAX_WIDTH;
265
+              canScale = canWidth / imgWidth;
266
+              canHeight = parseInt(canScale * imgHeight);
267
+              console.log("scale = "+canScale);
268
+              console.log('scale canvas width: ' + canWidth);
269
+              console.log('scale canvas height: ' + canHeight);
270
+            }
271
+
272
+            // 按 MAX_HEIGHT 截取高度 (过多的部分会被裁剪掉)
273
+            if(canHeight > MAX_HEIGHT) {
274
+              canHeight = MAX_HEIGHT;
275
+              imgHeight = parseInt(canHeight / canScale);
276
+            }
277
+
278
+            that.setData({
279
+              canvasWidth: canWidth,
280
+              canvasHeight: canHeight,
281
+            });
282
+            ctx_in.drawImage(res.tempFilePaths[0], 0, 0, imgWidth, imgHeight, 0, 0, canWidth, canHeight)
283
+            ctx_in.draw()
284
+            ctx_out.clearRect(0, 0, imgWidth, imgHeight)
285
+            ctx_out.draw()
286
+          }
287
+        })
288
+      }
289
+    })
290
+  },
291
+
292
+  process() {
293
+    var that = this
294
+
295
+    const cfg = {
296
+      x: 0,
297
+      y: 0,
298
+      width: that.data.canvasWidth,
299
+      height: that.data.canvasHeight,
300
+    }
301
+    wx.canvasGetImageData({
302
+      canvasId: 'canvasIn',
303
+      ...cfg,
304
+      success: (res) => {
305
+        //const data = convertToGrayscale(res.data)
306
+        const data = convertToMonoImage(res.width, res.height, res.data, true);
307
+        wx.canvasPutImageData({
308
+          canvasId: 'canvasOut',
309
+          data,
310
+          ...cfg,
311
+          success: (res) => {
312
+            console.log(res)
313
+            console.log('deal graphic width: ' + cfg.width)
314
+            console.log('deal graphic width: ' + cfg.height)
315
+          },
316
+          fail: (err) => {
317
+            console.error(err)
318
+          }
319
+        })
320
+      },
321
+      fail: (err) => {
322
+        console.error(err)
323
+      }
324
+    })
325
+  },
326
+
327
+  prepareSend: function (buff) { //准备发送,根据每次发送字节数来处理分包数量
328
+    //console.log(buff)
329
+    var that = this
330
+    var time = that.data.oneTimeData
331
+    var looptime = parseInt(buff.length / time);
332
+    var lastData = parseInt(buff.length % time);
333
+    //console.log(looptime + "---" + lastData)
334
+    that.setData({
335
+      looptime: looptime + 1,
336
+      lastData: lastData,
337
+      currentTime: 1,
338
+    })
339
+    that.Send(buff)
340
+  },
341
+
342
+  queryStatus: function () { //查询打印机状态
343
+    var command = esc.jpPrinter.Query();
344
+    command.getRealtimeStatusTransmission(1);
345
+  },
346
+
347
+  Send: function (buff) { //分包发送
348
+    var that = this
349
+    var currentTime = that.data.currentTime
350
+    var loopTime = that.data.looptime
351
+    var lastData = that.data.lastData
352
+    var onTimeData = that.data.oneTimeData
353
+    var printNum = that.data.printerNum
354
+    var currentPrint = that.data.currentPrint
355
+    var buf
356
+    var dataView
357
+    if (currentTime < loopTime) {
358
+      buf = new ArrayBuffer(onTimeData)
359
+      dataView = new DataView(buf)
360
+      for (var i = 0; i < onTimeData; ++i) {
361
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
362
+      }
363
+    } else {
364
+      buf = new ArrayBuffer(lastData)
365
+      dataView = new DataView(buf)
366
+      for (var i = 0; i < lastData; ++i) {
367
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
368
+      }
369
+    }
370
+    //console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
371
+    wx.writeBLECharacteristicValue({
372
+      deviceId: app.BLEInformation.deviceId,
373
+      serviceId: app.BLEInformation.writeServiceId,
374
+      characteristicId: app.BLEInformation.writeCharaterId,
375
+      value: buf,
376
+      success: function (res) {
377
+        wx.showToast({
378
+          title: '已打印第' + currentPrint + '张成功',
379
+        })
380
+        //console.log(res)
381
+      },
382
+      fail: function (e) {
383
+        wx.showToast({
384
+          title: '打印第' + currentPrint + '张失败',
385
+          icon: 'none',
386
+        })
387
+        //console.log(e)
388
+      },
389
+      complete: function () {
390
+        currentTime++
391
+        if (currentTime <= loopTime) {
392
+          that.setData({
393
+            currentTime: currentTime
394
+          })
395
+          that.Send(buff)
396
+        } else {
397
+          // wx.showToast({
398
+          //   title: '已打印第' + currentPrint + '张',
399
+          // })
400
+          if (currentPrint == printNum) {
401
+            that.setData({
402
+              looptime: 0,
403
+              lastData: 0,
404
+              currentTime: 1,
405
+              isReceiptSend: false,
406
+              isLabelSend: false,
407
+              currentPrint: 1
408
+            })
409
+          } else {
410
+            currentPrint++
411
+            that.setData({
412
+              currentPrint: currentPrint,
413
+              currentTime: 1,
414
+            })
415
+            that.Send(buff)
416
+          }
417
+        }
418
+      }
419
+    })
420
+
421
+  },
422
+
423
+  /**
424
+   * 生命周期函数--监听页面初次渲染完成
425
+   */
426
+  onReady: function () {
427
+    var list = []
428
+    var numList = []
429
+    var j = 0
430
+    for (var i = 20; i < 200; i += 10) {
431
+      list[j] = i;
432
+      j++
433
+    }
434
+    for (var i = 1; i < 10; i++) {
435
+      numList[i - 1] = i
436
+    }
437
+    this.setData({
438
+      buffSize: list,
439
+      oneTimeData: list[0],
440
+      printNum: numList,
441
+      printerNum: numList[0]
442
+    })
443
+  },
444
+
445
+  /**
446
+   * 生命周期函数--监听页面显示
447
+   */
448
+  onShow: function () {
449
+
450
+  },
451
+
452
+
453
+  buffBindChange: function (res) { //更改打印字节数
454
+    var index = res.detail.value
455
+    var time = this.data.buffSize[index]
456
+    this.setData({
457
+      buffIndex: index,
458
+      oneTimeData: time
459
+    })
460
+  },
461
+  printNumBindChange: function (res) { //更改打印份数
462
+    var index = res.detail.value
463
+    var num = this.data.printNum[index]
464
+    this.setData({
465
+      printNumIndex: index,
466
+      printerNum: num
467
+    })
468
+  },
469
+
470
+  /**
471
+   * 生命周期函数--监听页面隐藏
472
+   */
473
+  onHide: function () {
474
+
475
+  },
476
+
477
+  /**
478
+   * 生命周期函数--监听页面卸载
479
+   */
480
+  onUnload: function () {
481
+    // wx.closeBLEConnection({
482
+    //   deviceId: app.BLEInformation.deviceId,
483
+    //   success: function(res) {
484
+    //     console.log("关闭蓝牙成功")
485
+    //   },
486
+    // })
487
+  },
488
+
489
+  /**
490
+   * 页面相关事件处理函数--监听用户下拉动作
491
+   */
492
+  onPullDownRefresh: function () {
493
+
494
+  },
495
+
496
+  /**
497
+   * 页面上拉触底事件的处理函数
498
+   */
499
+  onReachBottom: function () {
500
+
501
+  },
502
+
503
+  /**
504
+   * 用户点击右上角分享
505
+   */
506
+  onShareAppMessage: function () {
507
+
508
+  }
509
+})

+ 3 - 0
pages/sendCommand/sendCommand.json

@@ -0,0 +1,3 @@
1
+{
2
+  "navigationBarTitleText": "发送测试"
3
+}

+ 42 - 0
pages/sendCommand/sendCommand.wxml

@@ -0,0 +1,42 @@
1
+<!--blecontrol.wxml-->
2
+<view class="body">
3
+
4
+	<view>
5
+		<textarea class="result">{{returnResult}}</textarea>
6
+	</view>
7
+	<textarea class="input" bindinput="inputEvent"></textarea>
8
+
9
+	<button type="primary" bindtap="sendData">发送(票据可使用)</button>
10
+
11
+
12
+
13
+
14
+
15
+	<view style='margin-top:4%;display: flex;flex-direction: row;'>
16
+
17
+		<button type='primary' bindtap='receiptTest' loading='{{isReceiptSend}}' disabled='{{isReceiptSend}}'>票据测试</button>
18
+
19
+		<button type='primary' bindtap='labelTest' loading='{{isLabelSend}}' disabled='{{isLabelSend}}'>标签测试</button>
20
+
21
+	</view>
22
+	<view style='margin-top:4%;display: flex;flex-direction: row;'>
23
+		<button type="primary" bindtap="openAndDraw">打开本地图片</button>
24
+    <button type="primary" bindtap="process">处理图片</button>
25
+	</view>
26
+	<!-- <button style='margin-top:4%' type='primary' bindtap='queryStatus'>查询打印机状态</button> -->
27
+
28
+	<!-- <view style='margin-top:4%;display: flex;flex-direction: row;'>
29
+    <canvas hidden='false' canvas-id='edit_area_canvas' style='width:{{canvasWidth}}px;height:{{canvasHeight}}px'></canvas>
30
+  </view> -->
31
+	<view style='margin-top:4%;display: flex;flex-direction: column;'>
32
+		<canvas canvas-id="canvasIn" class="canvas" style='border:1px solid; width:{{canvasWidth}}px; height:{{canvasHeight}}px'></canvas>
33
+		<canvas canvas-id="canvasOut" class="canvas" style='border:1px solid; width:{{canvasWidth}}px; height:{{canvasHeight}}px'></canvas>
34
+	</view>
35
+
36
+	<picker style='margin:20px' mode='selector' range='{{buffSize}}' value='{{buffIndex}}' bindchange='buffBindChange'>当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
37
+	</picker>
38
+
39
+	<picker style='margin:20px' mode='selector' range='{{printNum}}' value='{{printNumIndex}}' bindchange='printNumBindChange'>当前打印份数(点击可更换):{{printNum[printNumIndex]}}
40
+	</picker>
41
+
42
+</view>

+ 74 - 0
pages/sendCommand/sendCommand.wxss

@@ -0,0 +1,74 @@
1
+/* blecontrol.wxss */
2
+
3
+page{
4
+  width: 100%;
5
+  min-height: 100%;
6
+  background: blanchedalmond;
7
+}
8
+
9
+.input{
10
+  text-align: top;
11
+  width: 90%;
12
+  height: 150px;
13
+  margin-left: 4%;
14
+  margin-right: 4%;
15
+  margin-top: 10px;
16
+  margin-bottom: 12px;
17
+  border: 1px solid slategray;
18
+}
19
+
20
+.receiver_info_scroll_view{
21
+  width: 90%;
22
+  height: 200px;
23
+  margin-left: 4%;
24
+  margin-right: 4%;
25
+  margin-top: 10px;
26
+  margin-bottom: 25px;
27
+  border: 1px solid black;
28
+}
29
+
30
+.result{
31
+  width: 90%;
32
+  height: 150px;
33
+  border: 1px solid black;
34
+  margin-left: 4%;
35
+  margin-bottom: 4%;
36
+  margin-top: 5%
37
+}
38
+
39
+button{
40
+  width: 90%;
41
+  margin-left: 5%;
42
+  margin-right: 5%;
43
+}
44
+
45
+.switch{
46
+  float: right;
47
+  margin-right: 20px;
48
+  margin-bottom: 16px;
49
+}
50
+
51
+text{
52
+  color: #fff;
53
+  display: block;
54
+}
55
+
56
+input{
57
+  color: gainsboro;
58
+  float: left;
59
+}
60
+
61
+.v_net_ssid{
62
+  width: 100%;
63
+  background:  #fff;
64
+}
65
+
66
+.v_net_passw{
67
+  width: 100%;
68
+  background: antiquewhite;
69
+}
70
+
71
+.swiper{
72
+  width: 100%;
73
+  height: 100%;
74
+}

+ 549 - 0
pages/ticket/ticket.js

@@ -0,0 +1,549 @@
1
+
2
+var app = getApp();
3
+var esc = require("../../utils/esc.js");
4
+var encode = require("../../utils/encoding.js");
5
+
6
+function convertToGrayscale(data) {
7
+  let g = 0
8
+  for (let i = 0; i < data.length; i += 4) {
9
+    g = (data[i] * 0.3 + data[i + 1] * 0.59 + data[i + 2] * 0.11)
10
+    data[i] = g
11
+    data[i + 1] = g
12
+    data[i + 2] = g
13
+  }
14
+  return data
15
+}
16
+
17
+function inArray(arr, key, val) {
18
+  for (let i = 0; i < arr.length; i++) {
19
+    if (arr[i][key] === val) {
20
+      return i;
21
+    }
22
+  }
23
+  return -1;
24
+}
25
+
26
+// ArrayBuffer转16进度字符串示例
27
+function ab2hex(buffer) {
28
+  var hexArr = Array.prototype.map.call(
29
+    new Uint8Array(buffer),
30
+    function (bit) {
31
+      return ('00' + bit.toString(16)).slice(-2)
32
+    }
33
+  )
34
+  return hexArr.join('');
35
+}
36
+
37
+Page({
38
+
39
+  /**
40
+   * 页面的初始数据
41
+   */
42
+  data: {
43
+    looptime: 0,
44
+    currentTime: 1,
45
+    lastData: 0,
46
+    oneTimeData: 0,
47
+    returnResult: "",
48
+    buffSize: [],
49
+    buffIndex: 0,//发送字节数下标
50
+    printNum: [],
51
+    printNumIndex: 0,
52
+    printerNum: 1,
53
+    currentPrint: 1,
54
+    isReceiptSend: false,
55
+    isCheckTake:false,
56
+    isQuery:false,
57
+    chs: [],
58
+  },
59
+
60
+  /**
61
+   * 生命周期函数--监听页面加载
62
+   */
63
+  onLoad: function (options) {
64
+    // var that = this;
65
+    // wx.notifyBLECharacteristicValueChange({
66
+    //   deviceId: app.BLEInformation.deviceId,
67
+    //   serviceId: app.BLEInformation.notifyServiceId,
68
+    //   characteristicId: app.BLEInformation.notifyCharaterId,
69
+    //   state: true,
70
+    //   success: function (res) {
71
+    //     wx.onBLECharacteristicValueChange(function (r) {
72
+    //       console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
73
+    //     })
74
+    //   },
75
+    //   fail: function (e) {
76
+    //     console.log(e)
77
+    //   },
78
+    //   complete: function (e) {
79
+    //     console.log(e)
80
+    //   }
81
+    // })
82
+  },
83
+  receiptTest: function () { //票据测试
84
+    var that = this;
85
+    var command = esc.jpPrinter.createNew()
86
+    command.init()//初始化打印机
87
+    command.setLeftMargin(0)//设置左边距
88
+    command.setPrint()
89
+    command.setPrintMode(41)
90
+    command.setText("    71106 29079 81101 66268")
91
+    command.setPrint()
92
+    command.setPrintMode(0)
93
+    command.setText("测试票,机号:44010660 2007.09.07-10:43:32")
94
+    command.setPrint()
95
+    command.setPrintMode(0)
96
+    command.setText("双色球(B001)/2007105(0623)期 序号:00067:单式")
97
+    command.setPrint()
98
+    command.setPrint()
99
+    command.setPrintMode(0)
100
+    command.setText("1> ")
101
+    command.setPrintMode(41)
102
+    command.setText("03 04 13 18 19 27 - 13* 001")
103
+    command.setPrint()
104
+    command.setPrintMode(0)
105
+    command.setText("2> ")
106
+    command.setPrintMode(41)
107
+    command.setText("01 04 17 18 19 28 - 01* 001")
108
+    command.setPrint()
109
+    command.setPrintMode(0)
110
+    command.setText("3> ")
111
+    command.setPrintMode(41)
112
+    command.setText("01 04 17 18 19 28 - 01* 001")
113
+    command.setPrint()
114
+    command.setPrintMode(41)
115
+    command.setText("    CD33 7B07 5F 8D D2C2")
116
+    command.setPrint()
117
+    command.setPrintMode(0)
118
+    command.setText("开奖日:2007-09-09       金额20元")
119
+    command.setPrint()
120
+    command.setText("站地址:好易内部测试")
121
+    command.setPrint()
122
+    command.setText("查询电话:16880345 客服电话:020-88320568")
123
+    command.setPrint()
124
+    command.setText("兑奖通知:中奖10000元以内(含10000元)由银行自动返奖;10000元以上持本票到广州市福利彩票发行中心领奖。(此票不能在电脑福利彩票投注站兑奖)")
125
+    // command.setAbsolutePrintPosition(18)
126
+    command.setPrint()
127
+    command.setHRIPosition(0)//设置HRI位置
128
+    command.setHRIFont(0)//HRI字体大小
129
+    command.setBarcodeHeight(60)//条码高度
130
+    command.setBarcodeWidth(2)//设置条码宽度
131
+    command.setAbsolutePrintPosition(24)
132
+    command.setCode128("{A71106290798110166238");//code128  A类型
133
+    command.setText("                                 888888888888")
134
+    command.setPrint()
135
+    command.setPrint()
136
+    command.setPrint()
137
+    command.setPrint()
138
+    command.setPrint()
139
+    command.setPrint()
140
+    command.setPrint()
141
+    command.setPrint()
142
+    command.setPrint()
143
+    command.setBlackMarkStart()
144
+    command.setCut()
145
+    that.prepareSend(command.getData())//准备发送数据
146
+  },
147
+
148
+  prepareSend: function (buff) { //准备发送,根据每次发送字节数来处理分包数量
149
+    //console.log(buff)
150
+    var that = this
151
+    var time = that.data.oneTimeData
152
+    var looptime = parseInt(buff.length / time);
153
+    var lastData = parseInt(buff.length % time);
154
+    //console.log(looptime + "---" + lastData)
155
+    that.setData({
156
+      looptime: looptime + 1,
157
+      lastData: lastData,
158
+      currentTime: 1,
159
+    })
160
+    that.Send(buff)
161
+  },
162
+  queryStatus:function(){//查询打印机状态
163
+    var that = this
164
+    var buf;
165
+    var dateView;
166
+    /*
167
+    n = 1:传送打印机状态
168
+    n = 2:传送脱机状态
169
+    n = 3:传送错误状态
170
+    n = 4:传送纸传感器状态
171
+    */
172
+    buf = new ArrayBuffer(3)
173
+    dateView = new DataView(buf)
174
+    dateView.setUint8(0, 16)
175
+    dateView.setUint8(1, 4)
176
+    dateView.setUint8(2, 2)
177
+    wx.writeBLECharacteristicValue({
178
+      deviceId: app.BLEInformation.deviceId,
179
+      serviceId: app.BLEInformation.writeServiceId,
180
+      characteristicId: app.BLEInformation.writeCharaterId,
181
+      value: buf,
182
+      success: function (res) {
183
+        console.log("发送成功")
184
+        that.setData({
185
+          isQuery: true
186
+        })
187
+      },
188
+      fail: function (e) {
189
+        wx.showToast({
190
+          title: '发送失败',
191
+          icon: 'none',
192
+        })
193
+        //console.log(e)
194
+        return;
195
+      },
196
+      complete: function () {
197
+
198
+      }
199
+    })
200
+
201
+    wx.notifyBLECharacteristicValueChange({
202
+      deviceId: app.BLEInformation.deviceId,
203
+      serviceId: app.BLEInformation.notifyServiceId,
204
+      characteristicId: app.BLEInformation.notifyCharaterId,
205
+      state: true,
206
+      success: function (res) {
207
+        wx.onBLECharacteristicValueChange(function (r) {
208
+          console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
209
+          var result = ab2hex(r.value)
210
+          console.log("返回" + result)
211
+          var tip = ''
212
+          if (result == 12) {//正常
213
+            tip = "正常"
214
+          } else if (result == 32) {//缺纸
215
+            tip = "缺纸"
216
+          } else if (result == 36) {//开盖、缺纸
217
+            tip = "开盖、缺纸"
218
+          } else if (result == 16) {
219
+            tip = "开盖"
220
+          } else if (result == 40) {//其他错误
221
+            tip = "其他错误"
222
+          } else {//未处理错误
223
+            tip = "未知错误"
224
+          }
225
+          wx.showModal({
226
+            title: '打印机状态',
227
+            content: tip,
228
+            showCancel: false
229
+          })
230
+
231
+        })
232
+      },
233
+      fail: function (e) {
234
+        wx.showModal({
235
+          title: '打印机状态',
236
+          content: '获取失败',
237
+          showCancel: false
238
+        })
239
+        console.log(e)
240
+      },
241
+      complete: function (e) {
242
+        that.setData({
243
+          isQuery: false
244
+        })
245
+        console.log("执行完成")
246
+      }
247
+    })
248
+  },
249
+  checkTake: function () { //查询纸张状态
250
+    var that = this
251
+    var buf;
252
+    var dateView;
253
+      /*
254
+      n = 1:传送打印机状态
255
+      n = 2:传送脱机状态
256
+      n = 3:传送错误状态
257
+      n = 4:传送纸传感器状态
258
+      */
259
+      buf = new ArrayBuffer(3)
260
+      dateView = new DataView(buf)
261
+      dateView.setUint8(0, 16)
262
+      dateView.setUint8(1, 4)
263
+      dateView.setUint8(2, 4)
264
+      wx.writeBLECharacteristicValue({
265
+      deviceId: app.BLEInformation.deviceId,
266
+      serviceId: app.BLEInformation.writeServiceId,
267
+      characteristicId: app.BLEInformation.writeCharaterId,
268
+      value: buf,
269
+      success: function (res) {
270
+        console.log("发送成功")
271
+        that.setData({
272
+          isCheckTake: true
273
+        })
274
+      },
275
+      fail: function (e) {
276
+        wx.showToast({
277
+          title: '发送失败',
278
+          icon: 'none',
279
+        })
280
+        //console.log(e)
281
+        return;
282
+      },
283
+      complete: function () {
284
+     
285
+      }
286
+    })
287
+
288
+    wx.notifyBLECharacteristicValueChange({
289
+      deviceId: app.BLEInformation.deviceId,
290
+      serviceId: app.BLEInformation.notifyServiceId,
291
+      characteristicId: app.BLEInformation.notifyCharaterId,
292
+      state: true,
293
+      success: function (res) {
294
+        wx.onBLECharacteristicValueChange(function (r) {
295
+          console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`)
296
+          var result = ab2hex(r.value)
297
+          console.log("返回"+result)
298
+          var tip = ''
299
+        if (result == 12) {//纸张已取走
300
+          tip = "已取走"
301
+        } else if (result == 10) {//纸张未取走
302
+          tip = "未取走"
303
+        }else{//未处理错误
304
+          tip = "未知"
305
+        }
306
+        wx.showModal({
307
+          title: '彩票是否取走?',
308
+          content: tip,
309
+          showCancel: false
310
+        })
311
+    
312
+        })
313
+      },
314
+      fail: function (e) {
315
+        wx.showModal({
316
+          title: '彩票是否取走?',
317
+          content: '获取失败',
318
+          showCancel: false
319
+        })
320
+        console.log(e)
321
+      },
322
+      complete: function (e) {
323
+        that.setData({
324
+          isCheckTake: false
325
+        })
326
+        console.log("执行完成")
327
+      }
328
+    })
329
+
330
+
331
+    // 操作之前先监听,保证第一时间获取数据
332
+    // wx.onBLECharacteristicValueChange((characteristic) => {
333
+    //   const idx = inArray(this.data.chs, 'uuid', characteristic.characteristicId)
334
+    //   const data = {}
335
+    //   if (idx === -1) {
336
+    //     var result = ab2hex(characteristic.value)
337
+    //     data[`chs[${this.data.chs.length}]`] = {
338
+    //       uuid: characteristic.characteristicId,
339
+    //       // value: ab2hex(characteristic.value)
340
+    //       value: result
341
+    //     }
342
+    //     console.log("获取失败")
343
+    //     wx.showModal({
344
+    //       title: '提示',
345
+    //       content: '获取状态失败',
346
+    //       showCancel: false
347
+    //     })
348
+    //     that.setData({
349
+    //       isQuery: false
350
+    //     })
351
+    //   } else {
352
+    //     var result = ab2hex(characteristic.value)
353
+    //     data[`chs[${idx}]`] = {
354
+    //       uuid: characteristic.characteristicId,
355
+    //       value: ab2hex(characteristic.value)
356
+    //     }
357
+    //     var tip = ''
358
+    //     if (result == 12) {//正常
359
+    //       tip = "正常"
360
+    //     } else if (result == 36) {//缺纸
361
+    //       tip = "缺纸"
362
+    //     } else if (result == 16) {//开盖
363
+    //       tip = "开盖"
364
+    //     } else if (result == 40) {//其他错误
365
+    //       tip = "其他错误"
366
+    //     }else{//未处理错误
367
+    //       tip = "未知错误"
368
+    //     }
369
+    //     wx.showModal({
370
+    //       title: '提示',
371
+    //       content: tip,
372
+    //       showCancel: false
373
+    //     })
374
+    //     that.setData({
375
+    //       isQuery: false
376
+    //     })
377
+    //   }
378
+      // data[`chs[${this.data.chs.length}]`] = {
379
+      //   uuid: characteristic.characteristicId,
380
+      //   value: ab2hex(characteristic.value)
381
+      // }
382
+    //   this.setData(data)
383
+    // })
384
+   
385
+  },
386
+
387
+  Send: function (buff) { //分包发送
388
+    var that = this
389
+    var currentTime = that.data.currentTime
390
+    var loopTime = that.data.looptime
391
+    var lastData = that.data.lastData
392
+    var onTimeData = that.data.oneTimeData
393
+    var printNum = that.data.printerNum
394
+    var currentPrint = that.data.currentPrint
395
+    var buf
396
+    var dataView
397
+    if (currentTime < loopTime) {
398
+      buf = new ArrayBuffer(onTimeData)
399
+      dataView = new DataView(buf)
400
+      for (var i = 0; i < onTimeData; ++i) {
401
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
402
+      }
403
+    } else {
404
+      buf = new ArrayBuffer(lastData)
405
+      dataView = new DataView(buf)
406
+      for (var i = 0; i < lastData; ++i) {
407
+        dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i])
408
+      }
409
+    }
410
+    //console.log("第" + currentTime + "次发送数据大小为:" + buf.byteLength)
411
+    wx.writeBLECharacteristicValue({
412
+      deviceId: app.BLEInformation.deviceId,
413
+      serviceId: app.BLEInformation.writeServiceId,
414
+      characteristicId: app.BLEInformation.writeCharaterId,
415
+      value: buf,
416
+      success: function (res) {
417
+        if (currentPrint == printNum) {
418
+        wx.showToast({
419
+          title: '已打印第' + currentPrint + '张成功',
420
+        })
421
+        }
422
+        //console.log(res)
423
+      },
424
+      fail: function (e) {
425
+        wx.showToast({
426
+          title: '打印第' + currentPrint + '张失败',
427
+          icon: 'none',
428
+        })
429
+        //console.log(e)
430
+      },
431
+      complete: function () {
432
+        currentTime++
433
+        if (currentTime <= loopTime) {
434
+          that.setData({
435
+            currentTime: currentTime
436
+          })
437
+          that.Send(buff)
438
+        } else {
439
+          // wx.showToast({
440
+          //   title: '已打印第' + currentPrint + '张',
441
+          // })
442
+          if (currentPrint == printNum) {
443
+            that.setData({
444
+              looptime: 0,
445
+              lastData: 0,
446
+              currentTime: 1,
447
+              isReceiptSend: false,
448
+              currentPrint: 1
449
+            })
450
+          } else {
451
+            currentPrint++
452
+            that.setData({
453
+              currentPrint: currentPrint,
454
+              currentTime: 1,
455
+            })
456
+            that.Send(buff)
457
+          }
458
+        }
459
+      }
460
+    })
461
+  },
462
+
463
+  /**
464
+   * 生命周期函数--监听页面初次渲染完成
465
+   */
466
+  onReady: function () {
467
+    var list = []
468
+    var numList = []
469
+    var j = 0
470
+    for (var i = 20; i < 200; i += 10) {
471
+      list[j] = i;
472
+      j++
473
+    }
474
+    for (var i = 1; i < 10; i++) {
475
+      numList[i - 1] = i
476
+    }
477
+    this.setData({
478
+      buffSize: list,
479
+      oneTimeData: list[0],
480
+      printNum: numList,
481
+      printerNum: numList[0]
482
+    })
483
+  },
484
+
485
+  /**
486
+   * 生命周期函数--监听页面显示
487
+   */
488
+  onShow: function () {
489
+
490
+  },
491
+
492
+
493
+  buffBindChange: function (res) { //更改打印字节数
494
+    var index = res.detail.value
495
+    var time = this.data.buffSize[index]
496
+    this.setData({
497
+      buffIndex: index,
498
+      oneTimeData: time
499
+    })
500
+  },
501
+  printNumBindChange: function (res) { //更改打印份数
502
+    var index = res.detail.value
503
+    var num = this.data.printNum[index]
504
+    this.setData({
505
+      printNumIndex: index,
506
+      printerNum: num
507
+    })
508
+  },
509
+
510
+  /**
511
+   * 生命周期函数--监听页面隐藏
512
+   */
513
+  onHide: function () {
514
+
515
+  },
516
+
517
+  /**
518
+   * 生命周期函数--监听页面卸载
519
+   */
520
+  onUnload: function () {
521
+    // wx.closeBLEConnection({
522
+    //   deviceId: app.BLEInformation.deviceId,
523
+    //   success: function(res) {
524
+    //     console.log("关闭蓝牙成功")
525
+    //   },
526
+    // })
527
+  },
528
+
529
+  /**
530
+   * 页面相关事件处理函数--监听用户下拉动作
531
+   */
532
+  onPullDownRefresh: function () {
533
+
534
+  },
535
+
536
+  /**
537
+   * 页面上拉触底事件的处理函数
538
+   */
539
+  onReachBottom: function () {
540
+
541
+  },
542
+
543
+  /**
544
+   * 用户点击右上角分享
545
+   */
546
+  onShareAppMessage: function () {
547
+
548
+  }
549
+})

+ 4 - 0
pages/ticket/ticket.json

@@ -0,0 +1,4 @@
1
+{
2
+  "navigationBarTitleText": "彩票",
3
+  "usingComponents": {}
4
+}

+ 19 - 0
pages/ticket/ticket.wxml

@@ -0,0 +1,19 @@
1
+<!--blecontrol.wxml-->
2
+<view class="body">
3
+
4
+
5
+	<button class='button' hover-class="hover" bindtap='receiptTest' loading='{{isReceiptSend}}'
6
+		disabled='{{isReceiptSend}}'>彩票单据</button>
7
+	<button class='button' hover-class="hover" bindtap='checkTake' loading='{{isCheckTake}}'
8
+		disabled='{{isCheck}}'>纸张取走</button>
9
+	<button class='button' hover-class="hover" bindtap='queryStatus' loading='{{isQuery}}'
10
+		disabled='{{isQuery}}'>查询状态</button>
11
+	<picker style='margin:20px' mode='selector' range='{{buffSize}}' value='{{buffIndex}}' bindchange='buffBindChange'>
12
+		当前每次发送字节数为(点击可更换):{{buffSize[buffIndex]}}
13
+	</picker>
14
+
15
+	<picker style='margin:20px' mode='selector' range='{{printNum}}' value='{{printNumIndex}}'
16
+		bindchange='printNumBindChange'>当前打印份数(点击可更换):{{printNum[printNumIndex]}}
17
+	</picker>
18
+
19
+</view>

+ 15 - 0
pages/ticket/ticket.wxss

@@ -0,0 +1,15 @@
1
+/* pages/ticket/ticket.wxss */
2
+
3
+.button {
4
+  margin-top: 20px;
5
+  width: 90%;
6
+  background-color: #54bec2;
7
+  color: white;
8
+  border-radius: 98rpx;
9
+  background: bg_red;
10
+}
11
+ 
12
+/* 按下变颜色 */
13
+.hover {
14
+  background:  #DCDCDC;
15
+}

+ 57 - 0
project.config.json

@@ -0,0 +1,57 @@
1
+{
2
+  "appid": "wx389729dafe02559a",
3
+  "compileType": "miniprogram",
4
+  "libVersion": "2.23.4",
5
+  "packOptions": {
6
+    "ignore": [],
7
+    "include": []
8
+  },
9
+  "setting": {
10
+    "urlCheck": true,
11
+    "es6": true,
12
+    "enhance": true,
13
+    "postcss": true,
14
+    "preloadBackgroundData": false,
15
+    "minified": true,
16
+    "coverView": true,
17
+    "autoAudits": false,
18
+    "showShadowRootInWxmlPanel": true,
19
+    "uglifyFileName": false,
20
+    "checkInvalidKey": true,
21
+    "checkSiteMap": true,
22
+    "uploadWithSourceMap": true,
23
+    "compileHotReLoad": true,
24
+    "lazyloadPlaceholderEnable": false,
25
+    "useMultiFrameRuntime": true,
26
+    "useApiHook": true,
27
+    "useApiHostProcess": true,
28
+    "babelSetting": {
29
+      "ignore": [],
30
+      "disablePlugins": [],
31
+      "outputPath": ""
32
+    },
33
+    "useIsolateContext": true,
34
+    "userConfirmedBundleSwitch": false,
35
+    "packNpmManually": true,
36
+    "packNpmRelationList": [
37
+      {
38
+        "packageJsonPath": "./package.json",
39
+        "miniprogramNpmDistDir": "./../erp_phone_demo"
40
+      }
41
+    ],
42
+    "minifyWXSS": true,
43
+    "disableUseStrict": false,
44
+    "minifyWXML": true,
45
+    "showES6CompileOption": false,
46
+    "useCompilerPlugins": false,
47
+    "ignoreUploadUnusedFiles": true,
48
+    "scopeDataCheck": false
49
+  },
50
+  "editorSetting": {
51
+    "tabIndent": "insertSpaces",
52
+    "tabSize": 2
53
+  },
54
+  "description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
55
+  "projectname": "erp_phone",
56
+  "condition": {}
57
+}

+ 57 - 0
project.private.config.json

@@ -0,0 +1,57 @@
1
+{
2
+  "projectname": "erp_phone_demo",
3
+  "setting": {
4
+    "compileHotReLoad": true
5
+  },
6
+  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
7
+  "condition": {
8
+    "plugin": {
9
+      "list": []
10
+    },
11
+    "game": {
12
+      "list": []
13
+    },
14
+    "gamePlugin": {
15
+      "list": []
16
+    },
17
+    "miniprogram": {
18
+      "list": [
19
+        {
20
+          "name": "扫码",
21
+          "pathName": "pages/scanCode/scanCode",
22
+          "query": "",
23
+          "launchMode": "default",
24
+          "scene": null
25
+        },
26
+        {
27
+          "name": "编辑录入",
28
+          "pathName": "pages/codeInput/codeInput",
29
+          "query": "",
30
+          "launchMode": "default",
31
+          "scene": null
32
+        },
33
+        {
34
+          "name": "订单",
35
+          "pathName": "pages/order/order",
36
+          "query": "",
37
+          "launchMode": "default",
38
+          "scene": null
39
+        },
40
+        {
41
+          "name": "订单详情",
42
+          "pathName": "pages/orderDetails/orderDetails",
43
+          "query": "",
44
+          "launchMode": "default",
45
+          "scene": null
46
+        },
47
+        {
48
+          "name": "质检",
49
+          "pathName": "pages/qualityTesting/qualityTesting",
50
+          "query": "",
51
+          "scene": null,
52
+          "launchMode": "default"
53
+        }
54
+      ]
55
+    }
56
+  }
57
+}

+ 7 - 0
sitemap.json

@@ -0,0 +1,7 @@
1
+{
2
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
3
+  "rules": [{
4
+    "action": "allow",
5
+    "page": "*"
6
+  }]
7
+}

+ 220 - 0
utils/base64.js

@@ -0,0 +1,220 @@
1
+
2
+(function () {
3
+  var BASE64_MAPPING = [
4
+    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
5
+    'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
6
+    'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
7
+    'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
8
+    'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
9
+    'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
10
+    'w', 'x', 'y', 'z', '0', '1', '2', '3',
11
+    '4', '5', '6', '7', '8', '9', '+', '/'
12
+  ];
13
+
14
+	/**
15
+	 *ascii convert to binary
16
+	 */
17
+  var _toBinary = function (ascii) {
18
+    var binary = new Array();
19
+    while (ascii > 0) {
20
+      var b = ascii % 2;
21
+      ascii = Math.floor(ascii / 2);
22
+      binary.push(b);
23
+    }
24
+		/*
25
+		var len = binary.length;
26
+		if(6-len > 0){
27
+			for(var i = 6-len ; i > 0 ; --i){
28
+				binary.push(0);
29
+			}
30
+		}*/
31
+    binary.reverse();
32
+    return binary;
33
+  };
34
+
35
+	/**
36
+	 *binary convert to decimal
37
+	 */
38
+  var _toDecimal = function (binary) {
39
+    var dec = 0;
40
+    var p = 0;
41
+    for (var i = binary.length - 1; i >= 0; --i) {
42
+      var b = binary[i];
43
+      if (b == 1) {
44
+        dec += Math.pow(2, p);
45
+      }
46
+      ++p;
47
+    }
48
+    return dec;
49
+  };
50
+
51
+	/**
52
+	 *unicode convert to utf-8
53
+	 */
54
+  var _toUTF8Binary = function (c, binaryArray) {
55
+    var mustLen = (8 - (c + 1)) + ((c - 1) * 6);
56
+    var fatLen = binaryArray.length;
57
+    var diff = mustLen - fatLen;
58
+    while (--diff >= 0) {
59
+      binaryArray.unshift(0);
60
+    }
61
+    var binary = [];
62
+    var _c = c;
63
+    while (--_c >= 0) {
64
+      binary.push(1);
65
+    }
66
+    binary.push(0);
67
+    var i = 0, len = 8 - (c + 1);
68
+    for (; i < len; ++i) {
69
+      binary.push(binaryArray[i]);
70
+    }
71
+
72
+    for (var j = 0; j < c - 1; ++j) {
73
+      binary.push(1);
74
+      binary.push(0);
75
+      var sum = 6;
76
+      while (--sum >= 0) {
77
+        binary.push(binaryArray[i++]);
78
+      }
79
+    }
80
+    return binary;
81
+  };
82
+
83
+  var __BASE64 = {
84
+    /**
85
+     *BASE64 Encode
86
+     */
87
+    encoder: function (str) {
88
+      var base64_Index = [];
89
+      var binaryArray = [];
90
+      for (var i = 0, len = str.length; i < len; ++i) {
91
+        var unicode = str.charCodeAt(i);
92
+        var _tmpBinary = _toBinary(unicode);
93
+        if (unicode < 0x80) {
94
+          var _tmpdiff = 8 - _tmpBinary.length;
95
+          while (--_tmpdiff >= 0) {
96
+            _tmpBinary.unshift(0);
97
+          }
98
+          binaryArray = binaryArray.concat(_tmpBinary);
99
+        } else if (unicode >= 0x80 && unicode <= 0x7FF) {
100
+          binaryArray = binaryArray.concat(_toUTF8Binary(2, _tmpBinary));
101
+        } else if (unicode >= 0x800 && unicode <= 0xFFFF) {//UTF-8 3byte
102
+          binaryArray = binaryArray.concat(_toUTF8Binary(3, _tmpBinary));
103
+        } else if (unicode >= 0x10000 && unicode <= 0x1FFFFF) {//UTF-8 4byte
104
+          binaryArray = binaryArray.concat(_toUTF8Binary(4, _tmpBinary));
105
+        } else if (unicode >= 0x200000 && unicode <= 0x3FFFFFF) {//UTF-8 5byte
106
+          binaryArray = binaryArray.concat(_toUTF8Binary(5, _tmpBinary));
107
+        } else if (unicode >= 4000000 && unicode <= 0x7FFFFFFF) {//UTF-8 6byte
108
+          binaryArray = binaryArray.concat(_toUTF8Binary(6, _tmpBinary));
109
+        }
110
+      }
111
+
112
+      var extra_Zero_Count = 0;
113
+      for (var i = 0, len = binaryArray.length; i < len; i += 6) {
114
+        var diff = (i + 6) - len;
115
+        if (diff == 2) {
116
+          extra_Zero_Count = 2;
117
+        } else if (diff == 4) {
118
+          extra_Zero_Count = 4;
119
+        }
120
+        //if(extra_Zero_Count > 0){
121
+        //	len += extra_Zero_Count+1;
122
+        //}
123
+        var _tmpExtra_Zero_Count = extra_Zero_Count;
124
+        while (--_tmpExtra_Zero_Count >= 0) {
125
+          binaryArray.push(0);
126
+        }
127
+        base64_Index.push(_toDecimal(binaryArray.slice(i, i + 6)));
128
+      }
129
+
130
+      var base64 = '';
131
+      for (var i = 0, len = base64_Index.length; i < len; ++i) {
132
+        base64 += BASE64_MAPPING[base64_Index[i]];
133
+      }
134
+
135
+      for (var i = 0, len = extra_Zero_Count / 2; i < len; ++i) {
136
+        base64 += '=';
137
+      }
138
+      return base64;
139
+    },
140
+    /**
141
+     *BASE64  Decode for UTF-8 
142
+     */
143
+    decoder: function (_base64Str) {
144
+      var _len = _base64Str.length;
145
+      var extra_Zero_Count = 0;
146
+      /**
147
+       *计算在进行BASE64编码的时候,补了几个0
148
+       */
149
+      if (_base64Str.charAt(_len - 1) == '=') {
150
+        //alert(_base64Str.charAt(_len-1));
151
+        //alert(_base64Str.charAt(_len-2));
152
+        if (_base64Str.charAt(_len - 2) == '=') {//两个等号说明补了4个0
153
+          extra_Zero_Count = 4;
154
+          _base64Str = _base64Str.substring(0, _len - 2);
155
+        } else {//一个等号说明补了2个0
156
+          extra_Zero_Count = 2;
157
+          _base64Str = _base64Str.substring(0, _len - 1);
158
+        }
159
+      }
160
+
161
+      var binaryArray = [];
162
+      for (var i = 0, len = _base64Str.length; i < len; ++i) {
163
+        var c = _base64Str.charAt(i);
164
+        for (var j = 0, size = BASE64_MAPPING.length; j < size; ++j) {
165
+          if (c == BASE64_MAPPING[j]) {
166
+            var _tmp = _toBinary(j);
167
+            /*不足6位的补0*/
168
+            var _tmpLen = _tmp.length;
169
+            if (6 - _tmpLen > 0) {
170
+              for (var k = 6 - _tmpLen; k > 0; --k) {
171
+                _tmp.unshift(0);
172
+              }
173
+            }
174
+            binaryArray = binaryArray.concat(_tmp);
175
+            break;
176
+          }
177
+        }
178
+      }
179
+
180
+      if (extra_Zero_Count > 0) {
181
+        binaryArray = binaryArray.slice(0, binaryArray.length - extra_Zero_Count);
182
+      }
183
+
184
+      var unicode = [];
185
+      var unicodeBinary = [];
186
+      for (var i = 0, len = binaryArray.length; i < len;) {
187
+        if (binaryArray[i] == 0) {
188
+          unicode = unicode.concat(_toDecimal(binaryArray.slice(i, i + 8)));
189
+          i += 8;
190
+        } else {
191
+          var sum = 0;
192
+          while (i < len) {
193
+            if (binaryArray[i] == 1) {
194
+              ++sum;
195
+            } else {
196
+              break;
197
+            }
198
+            ++i;
199
+          }
200
+          unicodeBinary = unicodeBinary.concat(binaryArray.slice(i + 1, i + 8 - sum));
201
+          i += 8 - sum;
202
+          while (sum > 1) {
203
+            unicodeBinary = unicodeBinary.concat(binaryArray.slice(i + 2, i + 8));
204
+            i += 8;
205
+            --sum;
206
+          }
207
+          unicode = unicode.concat(_toDecimal(unicodeBinary));
208
+          unicodeBinary = [];
209
+        }
210
+      }
211
+      return unicode;
212
+    }
213
+  };
214
+
215
+  //window.BASE64 = __BASE64;
216
+  module.exports = {
217
+    CusBASE64: __BASE64
218
+  }
219
+})();
220
+

File diff suppressed because it is too large
+ 47 - 0
utils/encoding-indexes.js


File diff suppressed because it is too large
+ 3313 - 0
utils/encoding.js


+ 953 - 0
utils/esc.js

@@ -0,0 +1,953 @@
1
+var encode = require("./encoding.js")
2
+var app = getApp();
3
+var jpPrinter = {    
4
+  createNew: function() {      
5
+    var jpPrinter = {};
6
+    var data = [];
7
+    var bar = ["UPC-A", "UPC-E", "EAN13", "EAN8", "CODE39", "ITF", "CODABAR", "CODE93", "CODE128"];
8
+    jpPrinter.name = "蓝牙打印机";
9
+    /**
10
+     * ESC @ 初始化打印机
11
+     * 清除打印缓冲区数据,打印模式被设为上电时的默认值模式
12
+     */
13
+    jpPrinter.init = function() { 
14
+      data.push(27)
15
+      data.push(64)
16
+    };
17
+    /**
18
+    *LF 打印并换行
19
+    *将打印缓冲区中的数据打印出来,并且按照当前行间距,把打印纸向前推进一行。
20
+    */
21
+    jpPrinter.setPrint = function () { 
22
+      data.push(10)
23
+    };
24
+    /**
25
+     * ESC J 打印并走纸n 个单位
26
+     * 打印缓冲区数据并走纸[n × 纵向或横向移动单位]英寸。
27
+     */
28
+    jpPrinter.setPrintAndFeed = function (n) { 
29
+      data.push(27)
30
+      data.push(74)
31
+      data.push(n)
32
+    };
33
+    /**
34
+     * ESC d 打印并走纸n 行
35
+     * 打印缓冲区里的数据并向前走纸n 行(字符行)
36
+     */
37
+    jpPrinter.setPrintAndFeedRow = function (n) {
38
+      data.push(27)
39
+      data.push(100)
40
+      data.push(n)
41
+    };
42
+     /**
43
+      * HT 水平定位
44
+      *移动打印位置到下一个水平定位点的位置
45
+      */
46
+    jpPrinter.setHorTab = function () {
47
+      data.push(9)
48
+    };
49
+    /**
50
+     * ESC $ 设置绝对打印位置
51
+     * 将当前位置设置到距离行首(nL + nH × 256)×(横向或纵向移动单位)处。
52
+     * 传入参数为点数
53
+     * 1mm=8dot
54
+     */
55
+    jpPrinter.setAbsolutePrintPosition = function (where) {
56
+      data.push(27)
57
+      data.push(36)
58
+      data.push(parseInt(where % 256))
59
+      data.push(parseInt(where / 256))
60
+    };
61
+    /**
62
+     * ESC \ 设置相对横向打印位置
63
+     * 以横向或纵向移动单位设置横向相对位移
64
+     * 传入参数为点数
65
+     * 1mm=8dot
66
+     */
67
+    jpPrinter.setRelativePrintPositon = function (where) { //设置相对横向打印位置
68
+      data.push(27)
69
+      data.push(92)
70
+      data.push(parseInt(where % 256))
71
+      data.push(parseInt(where / 256))
72
+    };
73
+    /**
74
+     * ESC a 选择对齐方式
75
+     * 使所有的打印数据按某一指定对齐方式排列。
76
+     * n 的取值与对齐方式对应关系如下
77
+     * • 当n 为0 时 : 左对齐
78
+     * • 当n 为1 时 : 中间对齐
79
+     * • 当n 为2 时  右对齐
80
+     */
81
+    jpPrinter.setSelectJustification = function (which) {
82
+      data.push(27)
83
+      data.push(97)
84
+      data.push(which)
85
+    };
86
+    /**
87
+     * GS L 设置左边距
88
+     * 传入参数为点数  
89
+     * 1mm=8dot
90
+     */
91
+    jpPrinter.setLeftMargin = function (n) {
92
+      data.push(29)
93
+      data.push(76)
94
+      data.push(parseInt(n % 256))
95
+      data.push(parseInt(n / 256))
96
+    };
97
+    /**
98
+     * GS W 设置打印区域宽度
99
+    * 传入参数为点数
100
+     * 1mm=8dot
101
+     */
102
+    jpPrinter.setPrintingAreaWidth = function (width) {
103
+      data.push(29)
104
+      data.push(87)
105
+      data.push(parseInt(width % 256))
106
+      data.push(parseInt(width / 256))
107
+    };
108
+    /**
109
+     * GS P 设置横向和纵向移动单位
110
+     * 传入参数为点数
111
+     * 1mm=8dot
112
+     */
113
+    jpPrinter.setHorizontalAndVertical=function(x,y){
114
+      data.push(29)
115
+      data.push(80)
116
+      data.push(x)
117
+      data.push(y)
118
+    };
119
+    /**
120
+     * DLE DC4 实时产生钱箱开启脉冲
121
+     * 在指定的钱箱插座引脚产生设定的开启脉冲,引脚由m 指定:
122
+       m 连接引脚
123
+       0 钱箱插座引脚2
124
+       1 钱箱插座引脚5
125
+     * 脉冲高电平时间为[t × 100 ms],低电平的时间为[t × 100 ms]
126
+     */
127
+    jpPrinter.setCashboxPulse=function(n,m,t){
128
+      data.push(16)
129
+      data.push(20)
130
+      data.push(n)
131
+      data.push(m)
132
+      data.push(t)
133
+    };
134
+    /**
135
+     * ESC c 3 选择打印纸传感器以输出缺纸信号
136
+     * 传入参数说明
137
+     * • 当n 为0 时:关闭纸将尽传感器
138
+     * • 当n 为1 时:开启纸将尽传感器
139
+     * • 当n 为2 时:开启纸将尽传感器
140
+     * • 当n 为3 时:开启纸尽传感器
141
+     * • 当n 为4 时:开启纸尽传感器
142
+     */
143
+    jpPrinter.setPrintPageSignal=function(n){
144
+      data.push(27)
145
+      data.push(99)
146
+      data.push(51)
147
+      data.push(n)
148
+    };
149
+    /**
150
+     * ESC c 4 选择打印纸传感器以停止打印
151
+    * 传入参数说明
152
+     * • 当n 为0 时:禁止纸将尽传感器
153
+     * • 当n 为1 时:允许纸将尽传感器
154
+     * • 当n 为2 时:允许纸将尽传感器
155
+     */
156
+    jpPrinter.setSensorToStopPrint = function (n) {
157
+      data.push(27)
158
+      data.push(99)
159
+      data.push(52)
160
+      data.push(n)
161
+    };
162
+    /**
163
+     * ESC c 5 允许/禁止按键
164
+     * 允许/禁止按键
165
+     * 传入参数说明
166
+     * • 当n 为0 时,按键起作用。
167
+     * • 当n 为1 时,按键被禁止。
168
+     */
169
+    jpPrinter.setSelectKey = function (n) {
170
+      data.push(27)
171
+      data.push(99)
172
+      data.push(53)
173
+      data.push(n)
174
+    };
175
+    /**
176
+     * ESC p 产生钱箱控制脉冲
177
+     * 输出由t1 和t2 设定的钱箱开启脉冲到由m 指定的引脚:
178
+     * 传入参数说明
179
+     * • 当m 为0 时,钱箱插座的引脚2
180
+     * • 当m 为1 时,钱箱插座的引脚5
181
+     */
182
+    jpPrinter.setCashCashboxPulse=function(m,t1,t2){
183
+      data.push(27)
184
+      data.push(112)
185
+      data.push(m)
186
+      data.push(t1)
187
+      data.push(t2)
188
+    };
189
+    /**
190
+     * ESC = 选择打印机
191
+     * 选择打印机,被选择的打印机可以接收主计算机发送的数据
192
+     * 传入参数说明
193
+     * • 当n 为0 时,打印机禁止
194
+     * • 当n 为1 时,打印机允许。
195
+     */
196
+    jpPrinter.setSelectPrinter=function(n){
197
+      data.push(27)
198
+      data.push(112)
199
+      data.push(n)
200
+    };
201
+    /**
202
+     * ESC 2 设置默认行间距
203
+     *选择默认行间距
204
+     */
205
+    jpPrinter.setDefaultLineSpace=function(){
206
+      data.push(27)
207
+      data.push(50)
208
+    };
209
+    /**
210
+     * ESC 3 设置行间距
211
+     * 传入参数为点数
212
+     * 1mm=8dot
213
+     */
214
+    jpPrinter.setLineSpace = function (n) {
215
+      data.push(27)
216
+      data.push(51)
217
+      data.push(n)
218
+    };
219
+    /**
220
+     * ESC SP 设置字符右间距
221
+     * 传入参数为点数
222
+     * 1mm=8dot
223
+     */
224
+    jpPrinter.setCharacterRightSpace=function(n){
225
+      data.push(27)
226
+      data.push(32)
227
+      data.push(n)
228
+    };
229
+    /**
230
+     * ESC ! 选择打印模式
231
+     * 传入参数说明
232
+     * 根据n 的值设置字符打印模式
233
+     */
234
+    jpPrinter.setPrintMode = function (mode) { //设置打印模式
235
+      data.push(27)
236
+      data.push(33)
237
+      data.push(mode)
238
+    }
239
+    /**
240
+     * ESC % 选择/取消用户自定义字符
241
+     * • 当n 为0 时,不使用用户自定义字符。
242
+     * • 当n 为1 时,使用用户自定义字符。
243
+     */
244
+    jpPrinter.setUserDefinitionCharacter=function(n){
245
+      data.push(27)
246
+      data.push(37)
247
+      data.push(n)
248
+    };
249
+    /**
250
+     * ESC – 选择/取消下划线模式
251
+     * 传入参数说明
252
+     * • 当n 为0 时:取消下划线模式
253
+     * • 当n 为1 时:选择下划线模式(1 点宽)
254
+     * • 当n 为2 时:选择下划线模式(2 点宽)
255
+     */
256
+    jpPrinter.setUnderlineMode=function(n){
257
+      data.push(27)
258
+      data.push(45)
259
+      data.push(n)
260
+    };
261
+    /**
262
+     * ESC ? 取消用户自定义字符
263
+     * 传入参数说明
264
+     * 取消用户自定义字符中代码为n 的字符。取消后,此字符使用内部字库
265
+     */
266
+    jpPrinter.setCancleUserDefinitionCharacter = function(n){
267
+      data.push(27)
268
+      data.push(63)
269
+      data.push(n)
270
+    };
271
+    /**
272
+     * ESC E 选择/取消加粗模式
273
+     * 传入参数说明
274
+     * 当n 为0 时,取消加粗模式。
275
+     * 当n 为1 时,选择加粗模式。
276
+     */
277
+    jpPrinter.setBoldMode=function(n){
278
+      data.push(27)
279
+      data.push(69)
280
+      data.push(n)
281
+    };
282
+    /**
283
+     * ESC G 选择/取消双重打印模式
284
+     *传入参数说明
285
+     *• 当n 位为0 时,取消双重打印模式。
286
+     *• 当n 位为1 时,选择双重打印模式。
287
+     */
288
+    jpPrinter.setDoublePrintMode=function(n){
289
+      data.push(27)
290
+      data.push(71)
291
+      data.push(n)
292
+    };
293
+    /**
294
+     * ESC M 选择字体
295
+     * 传入参数说明
296
+     * • 当n 位为0 时, 选择标准ASCII 码字体(12 × 24)
297
+     * • 当n 位为1 时, 选择压缩ASCII 码字体(9 × 17))
298
+     */
299
+    jpPrinter.setSelectFont=function(n){
300
+      data.push(27)
301
+      data.push(77)
302
+      data.push(n)
303
+    };
304
+    /**
305
+     * ESC R 选择国际字符集
306
+     * 传入参数说明
307
+     * • 当n 位为0 时, 选择美国(默认)
308
+     * • 当n 位为1 时, 选择法国
309
+     * • 当n 位为2 时, 选择德国
310
+     * • 当n 位为3 时, 选择英国
311
+     * • 当n 位为4 时, 选择丹麦I
312
+     * • 当n 位为5 时, 选择瑞典
313
+     * • 当n 位为6 时, 选择意大利
314
+     * • 当n 位为7 时, 选择西班牙I
315
+     * • 当n 位为8 时, 选择日本
316
+     * • 当n 位为9 时, 选择挪威
317
+     * • 当n 位为10 时, 选择丹麦II
318
+     * • 当n 位为11 时, 选择西班牙II
319
+     * • 当n 位为12 时, 选择拉丁美洲
320
+     * • 当n 位为13 时, 选择韩国
321
+     * • 当n 位为14 时, 选择斯洛维尼亚/克罗帝亚
322
+     * • 当n 位为15 时, 选择中国
323
+     */
324
+    jpPrinter.setInternationalCharacters=function(n){
325
+      data.push(27)
326
+      data.push(82)
327
+      data.push(n)
328
+    };
329
+    /**
330
+     * ESC V 选择/取消顺时针旋转90 度
331
+     * 传入参数说明
332
+     * • 当n 位为0 时, 取消顺时针旋转90 度模式
333
+     * • 当n 位为1 时,选择顺时针旋转90 度模式
334
+     */
335
+    jpPrinter.setRotate90=function(n){
336
+      data.push(27)
337
+      data.push(86)
338
+      data.push(n)
339
+    };
340
+    /**
341
+     * ESC t 选择字符代码页
342
+     * 传入参数说明
343
+     * • 当n 位为0 时, 选择PC437 [美国,欧洲标准](默认)
344
+     * • 当n 位为1 时, 选择日文片假名
345
+     * • 当n 位为2 时, 选择PC850 [多语言]
346
+     * • 当n 位为3 时, 选择PC860 [葡萄牙语]
347
+     * • 当n 位为4 时, 选择PC863 [加拿大-法语]
348
+     * • 当n 位为5 时, 选择PC865 [北欧]
349
+     * • 当n 位为6 时, 选择West Europe
350
+     * • 当n 位为7 时, 选择Greek
351
+     * • 当n 位为8 时, 选择Hebrew
352
+     * • 当n 位为9 时, 选择PC755:East Europe
353
+     * • 当n 位为10 时, 选择Iran   
354
+     *   
355
+     * • 当n 位为16 时, 选择WPC1252
356
+     * • 当n 位为17 时, 选择PC866:Cyrillice*2
357
+     * • 当n 位为18 时, 选择PC852:Latin2
358
+     * • 当n 位为19 时, 选择PC858
359
+     * • 当n 位为20 时, 选择Inrall
360
+     * • 当n 位为21 时, 选择Latvian
361
+     * • 当n 位为22 时, 选择Arabic
362
+     * • 当n 位为23 时, 选择PT151,1251
363
+     * • 当n 位为24 时, 选择PC747
364
+     * • 当n 位为25 时, 选择WPC1257
365
+     * 
366
+     * • 当n 位为27 时, 选择Vietnam
367
+     * • 当n 位为28 时, 选择PC864
368
+     * • 当n 位为29 时, 选择PC1001
369
+     * • 当n 位为30 时, 选择Uygur
370
+     * 
371
+     * • 当n 位为255 时, 选择Uygur
372
+     * 打印机支持代码页请以打印机自检测试页为准
373
+     */
374
+    jpPrinter.setCodePage=function(n){
375
+      data.push(27)
376
+      data.push(116)
377
+      data.push(n)
378
+    };
379
+    /**
380
+     * ESC { 选择/取消倒置打印模式
381
+     * 传入参数说明
382
+     * • 当n 位为0 时, 选择PC437 [美国,欧洲标准](默认)
383
+     * • 当n 位为1 时, 选择日文片假名
384
+     */
385
+    jpPrinter.setInvertPrintMode = function (n) {
386
+      data.push(27)
387
+      data.push(123)
388
+      data.push(n)
389
+    };
390
+    /**
391
+     * GS ! 选择字符大小
392
+     * 传入参数说明
393
+     *(1 ≤ 纵向放大倍数≤ 8,1 ≤ 横向放大倍数≤ 8)
394
+     *一个byte 有8 位,用0 到2 位选择字符高度,4 到6 位选择字符宽度
395
+     * • 当n 位为0 时, 正常
396
+     * • 当n 位为16 时,2(倍宽)
397
+     * • 当n 位为32 时,3(倍宽)
398
+     * • 当n 位为48 时,4(倍宽)
399
+     * • 当n 位为64 时,5(倍宽)
400
+     * • 当n 位为80 时,6(倍宽)
401
+     * • 当n 位为96 时,7(倍宽)
402
+     * • 当n 位为112 时,8(倍宽)
403
+     * 
404
+     * • 当n 位为16 时,2(倍高)
405
+     * • 当n 位为32 时,3(倍高)
406
+     * • 当n 位为48 时,4(倍高)
407
+     * • 当n 位为64 时,5(倍高)
408
+     * • 当n 位为80 时,6(倍高)
409
+     * • 当n 位为96 时,7(倍高)
410
+     * • 当n 位为112 时,8(倍高)
411
+     * 若需要倍宽倍高,请在同等倍数下相加 如17为倍宽倍高
412
+     */
413
+    jpPrinter.setCharacterSize=function(n){
414
+      data.push(29)
415
+      data.push(33)
416
+      data.push(n)
417
+    };
418
+    /**
419
+     * GS B 选择/取消黑白反显打印模式
420
+     * 传入参数说明
421
+     * • 当n 位为0 时,取消反显打印
422
+     * • 当n 位为1 时,选择反显打印
423
+     */
424
+    jpPrinter.setReverseMode=function(n){
425
+      data.push(29)
426
+      data.push(66)
427
+      data.push(n)
428
+    };
429
+
430
+
431
+  
432
+    function convertPartialToBitmap(w, start_y, bith, pitch, res) {
433
+      console.log('convert bitmap: ' + w + ', ' + start_y + ', ' + bith + ', ' + pitch);
434
+      var bits = new Uint8Array(bith*pitch);
435
+      data.push(29) // 0x1D
436
+      data.push(118) // 0x76
437
+      data.push(48) // 0x30
438
+      data.push(0) // 0x00
439
+      data.push(parseInt(pitch % 256));
440
+      data.push(parseInt(pitch / 256));
441
+      data.push(parseInt(bith % 256));
442
+      data.push(parseInt(bith / 256));
443
+      for (var y = 0; y < bith; y++) {
444
+        for (var x = 0; x < w; x++) {
445
+          var color = res.data[((y + start_y) * w + x) * 4];
446
+          if (color < 128) {
447
+              bits[parseInt(y * pitch + x/8)] |= (0x80 >> (x%8));
448
+          }
449
+        }
450
+      }
451
+      for(var i=0; i<bits.length; i++) {
452
+        data.push(bits[i]);
453
+      }
454
+    }
455
+
456
+    /*
457
+    单色图片转成多张bitmap, 高度按BLOCK_SIZE拆分图片
458
+    */
459
+    function convertToMultiBitmap(res) {
460
+      var w = res.width;
461
+      var h = res.height;
462
+      const BLOCK_SIZE = 128;
463
+      var pitch = parseInt((w+7)/8);
464
+      var block = parseInt((h + BLOCK_SIZE - 1) / BLOCK_SIZE);
465
+
466
+      console.log(w + "--" + h);
467
+
468
+      for(var i=0; i<block; i++) {
469
+        var bith = BLOCK_SIZE;
470
+        if(i * BLOCK_SIZE + bith > h) {
471
+          bith = h - i * BLOCK_SIZE;
472
+        }
473
+        convertPartialToBitmap(w, i*BLOCK_SIZE, bith, pitch, res);
474
+      }
475
+      console.log(data);
476
+    }
477
+
478
+    /*
479
+    单色图片整图转成一张bitmap
480
+    */
481
+    function convertToSingleBitmap(res) {
482
+      console.log(res)
483
+      var w = res.width;
484
+      var h = res.height;
485
+      var bitw = parseInt((w+7)/8)*8;
486
+      var bith = h;
487
+      var pitch = parseInt(bitw / 8);
488
+      var bits = new Uint8Array(bith*pitch);
489
+      console.log(w + "--" + h);
490
+      console.log("bitw="+bitw+", bith="+bith+", pitch="+pitch);
491
+      data.push(29) // 0x1D
492
+      data.push(118) // 0x76
493
+      data.push(48) // 0x30
494
+      data.push(0) // 0x00
495
+      data.push(parseInt(pitch % 256));
496
+      data.push(parseInt(pitch / 256));
497
+      data.push(parseInt(bith % 256));
498
+      data.push(parseInt(bith / 256));
499
+      console.log(res.data.length)
500
+      for (var y = 0; y < h; y++) {
501
+        for (var x = 0; x < w; x++) {
502
+          var color = res.data[(y * w + x) * 4];
503
+          if (color < 128) {
504
+              bits[parseInt(y * pitch + x/8)] |= (0x80 >> (x%8));
505
+          }
506
+        }
507
+      }
508
+      for(var i=0; i<bits.length; i++) {
509
+        data.push(bits[i]);
510
+      }
511
+    }
512
+
513
+    /**
514
+     * GS v 0 打印光栅位图
515
+     *
516
+     */
517
+    jpPrinter.setBitmap = function (res) { //参数,画布的参数
518
+      console.log(res)
519
+      convertToSingleBitmap(res) // 转成单张位图
520
+      //convertToMultiBitmap(res) // 转成多张位图
521
+      console.log(data);
522
+    };
523
+
524
+    /**
525
+     * GS H 选择HRI 字符的打印位置
526
+     * 传入参数说明
527
+     * • 当n 位为0 时,不打印
528
+     * • 当n 位为1 时,条码上方
529
+     * • 当n 位为2 时,条码下方
530
+     * • 当n 位为3 时,条码上、下方
531
+     */
532
+    jpPrinter.setHRIPosition = function (position) { 
533
+      data.push(29)
534
+      data.push(72)
535
+      data.push(position)
536
+    };
537
+    /**
538
+     * GS f 选择HRI 使用字体
539
+     * 传入参数说明
540
+     * • 当n 位为0 时,标准ASCII 码字符(12 × 24)
541
+     * • 当n 位为1 时,压缩ASCII 码字符(9 × 17)
542
+     */
543
+    jpPrinter.setHRIFont = function (font) {
544
+      data.push(29)
545
+      data.push(102)
546
+      data.push(font)
547
+    };
548
+    /**
549
+     * GS h 选择条码高度
550
+     * 传入参数说明
551
+     * 2 ≤ n ≤ 6
552
+     */
553
+    jpPrinter.setBarcodeWidth = function (width) {
554
+      data.push(29)
555
+      data.push(119)
556
+      if (width > 6) {
557
+        width = 6;
558
+      }
559
+      if (width < 2) {
560
+        width = 1;
561
+      }
562
+      data.push(width)
563
+    };
564
+    /**
565
+     * GS h 选择条码高度
566
+     * 传入参数说明
567
+     * 1 ≤ n ≤ 255
568
+     */
569
+    jpPrinter.setBarcodeHeight = function (height) {
570
+      data.push(29)
571
+      data.push(104)
572
+      data.push(height)
573
+    };
574
+    /**
575
+     * 打印条码128类型
576
+     */
577
+    jpPrinter.setCode128 = function (content) {
578
+      data.push(29)
579
+      data.push(107)
580
+      data.push(73)
581
+      var code = new encode.TextEncoder(
582
+        'gb18030', {
583
+          NONSTANDARD_allowLegacyEncoding: true
584
+        }).encode(content)
585
+      data.push(code.length)
586
+      for (var i = 0; i < code.length; ++i) {
587
+        data.push(code[i])
588
+      }
589
+    };
590
+    /**
591
+     * 打印条码
592
+     * 传入参数说明
593
+     * t:条码类型
594
+     * content:内容
595
+     */
596
+    jpPrinter.setBarcodeContent = function (t, content) {
597
+      var ty = 73;
598
+      data.push(29)
599
+      data.push(107)
600
+      switch (t) {
601
+        case bar[0]:
602
+          ty = 65;
603
+          break;
604
+        case bar[1]:
605
+          ty = 66;
606
+          break;
607
+        case bar[2]:
608
+          ty = 67;
609
+          break;
610
+        case bar[3]:
611
+          ty = 68;
612
+          break;
613
+        case bar[4]:
614
+          ty = 69;
615
+          break;
616
+        case bar[5]:
617
+          ty = 70;
618
+          break;
619
+        case bar[6]:
620
+          ty = 71;
621
+          break;
622
+        case bar[7]:
623
+          ty = 72;
624
+          break;
625
+        case bar[8]:
626
+          ty = 73;
627
+          break;
628
+      }
629
+      data.push(ty)
630
+      data.push(content)
631
+    };
632
+    /**
633
+     * FS ! 设置汉字字符模式
634
+     * 传入参数说明
635
+     * • 当n 位为0 时,取消倍宽、倍高、取消下划线
636
+     * • 当n 位为4 时,选择倍宽
637
+     * • 当n 位为8 时,选择倍高
638
+     * • 当n 位为128 时,选择下划线
639
+     */
640
+    jpPrinter.setChineseCharacterMode=function(n){
641
+      data.push(28)
642
+      data.push(33)
643
+      data.push(n)
644
+    };
645
+    /**
646
+     * FS & 选择汉字模式
647
+     */
648
+    jpPrinter.setSelectChineseCharacter=function(){
649
+      data.push(28)
650
+      data.push(38)
651
+    };
652
+    /**
653
+    * FS . 取消汉字模式
654
+    */
655
+    jpPrinter.setCancelChineseCharacter = function () {
656
+      data.push(28)
657
+      data.push(46)
658
+    };
659
+    /**
660
+     * FS - 选择/取消汉字下划线模式
661
+     * 传入参数说明
662
+     * • 当n 位为0 时,取消汉字下划线
663
+     * • 当n 位为1 时,选择汉字下划线(1 点宽)
664
+     * • 当n 位为2 时,选择汉字下划线(2 点宽)
665
+     */
666
+    jpPrinter.setCancelUnderLine=function(n){
667
+      data.push(28)
668
+      data.push(45)
669
+      data.push(n)
670
+    };
671
+    /**
672
+     * FS S 设置汉字字符左右间距
673
+     * 传入参数说明
674
+     * 分别将汉字的左间距和右间距设置为n1 和n2
675
+     * 传入点数,1mm=8dot
676
+     */
677
+    jpPrinter.setChineseCharacterSpace=function(n1,n2){
678
+      data.push(28)
679
+      data.push(83)
680
+      data.push(n1)
681
+      data.push(n2)
682
+    };
683
+    /**
684
+     * FS W 选择/取消汉字倍高倍宽
685
+     * • 当n 的最低位为0,取消汉字倍高倍宽模式。
686
+     * • 当n 的最低位为1,选择汉字倍高倍宽模式。
687
+     */
688
+    jpPrinter.setChineseCharacteHeightWidth=function(n){
689
+      data.push(28)
690
+      data.push(87)
691
+      data.push(n)
692
+    };
693
+    /**
694
+     * GS ( F 设置黑标定位偏移量
695
+     * 该命令用于选择黑标定位控制允许,且设置切/撕纸位置或起始打印位置相对于黑标检测的偏移值。该值以点数计算。
696
+     * p
697
+     * 传入点数
698
+     * 
699
+     * a = 1, 2; 
700
+     * a=1:设置起始打印位置相对于黑标检测位置的偏移量
701
+     * a=2:设置切/撕纸位置相对于黑标检测位置的偏移量
702
+     * 
703
+     * m = 0, 48
704
+     * m=0 或48,选择偏移量为前进纸方向计算;
705
+     * 
706
+     * 0 ≤ n ≤ 1700
707
+     */
708
+    jpPrinter.setBlackMaskOffset = function (p,a,m,n) {
709
+      data.push(29)
710
+      data.push(40)
711
+      data.push(70)
712
+      data.push(p%256)
713
+      data.push(p/256)
714
+      data.push(a)
715
+      data.push(m)
716
+      data.push(n%256)
717
+      data.push(n/256)
718
+    };
719
+    /**
720
+     * GS FF 设置黑标至打印起始位置
721
+     */
722
+    jpPrinter.setBlackMarkStart = function () {//黑标至打印起始位置
723
+      data.push(29)
724
+      data.push(12)
725
+    };
726
+    /**
727
+     * GS V 选择切纸模式并切纸
728
+     * 半切
729
+     */
730
+    jpPrinter.setCutter= function () {
731
+      data.push(29)
732
+      data.push(86)
733
+      data.push(1)
734
+    } ;
735
+    
736
+     /**
737
+     * GS V 选择切纸模式并切纸
738
+     * 传入参数说明
739
+     * 传入点数,1mm=8dot
740
+     * 进纸n 并且半切纸
741
+     */
742
+    jpPrinter.setCut = function (n) {
743
+      data.push(29)
744
+      data.push(86)
745
+      data.push(101)
746
+      data.push(n)
747
+    };
748
+    /**
749
+     * ESC B 打印机来单打印蜂鸣提示
750
+     * 传入参数说明
751
+     * 1 ≤ n ≤ 9
752
+     * 1 ≤ t ≤ 9
753
+     * n 是指蜂鸣器鸣叫次数。
754
+     * t 是指蜂鸣器鸣每次数鸣叫时间为(t × 50) ms
755
+     */
756
+    jpPrinter.setSound = function (n, t) { //设置蜂鸣器
757
+      data.push(27)
758
+      data.push(66)
759
+      if (n < 0) {
760
+        n = 1;
761
+      } else if (n > 9) {
762
+        n = 9;
763
+      }
764
+      if (t < 0) {
765
+        t = 1;
766
+      } else if (t > 9) {
767
+        t = 9;
768
+      }
769
+      data.push(n)
770
+      data.push(t)
771
+    };
772
+    /**
773
+     * ESC C 打印机来单打印蜂鸣提示及报警灯闪烁
774
+     * 传入参数说明
775
+     * 1 ≤ m ≤ 20,1 ≤ t ≤ 20,0 ≤ n ≤ 3
776
+     * 
777
+     * m:指报警灯闪烁次数或蜂鸣器鸣叫次数
778
+     * 
779
+     * t:指报警灯闪烁间隔时间为(t × 50) ms 或蜂鸣器鸣叫间隔时间为(t × 50) ms
780
+     * 
781
+     * 当n = 0 时,蜂鸣器不鸣叫,同时报警灯不闪烁
782
+     * 当n = 1 时,蜂鸣器鸣叫
783
+     * 当n = 2 时,报警灯闪烁
784
+     * 当n = 3 时,蜂鸣器鸣叫,同时报警灯闪烁
785
+     */
786
+    jpPrinter.setOrderTip=function(m,t,n){
787
+      data.push(27)
788
+      data.push(67)
789
+      if (m < 0) {
790
+        m = 1;
791
+      } else if (m > 20) {
792
+        n = 20;
793
+      }
794
+      if (t < 0) {
795
+        t = 1;
796
+      } else if (t > 20) {
797
+        t = 20;
798
+      }
799
+      if (n < 0) {
800
+        n = 1;
801
+      } else if (n > 3) {
802
+        n = 3;
803
+      }
804
+      data.push(m)
805
+      data.push(t)
806
+      data.push(n)
807
+    };
808
+    /**
809
+     * 设置QRCode 模块大小为n dot
810
+     * 传入参数说明
811
+     * 1 ≤ n ≤ 15
812
+     * [默认值] n = 3
813
+     */
814
+    jpPrinter.setSelectSizeOfModuleForQRCode = function(n) { //设置二维码大小
815
+      data.push(29)
816
+      data.push(40)
817
+      data.push(107)
818
+      data.push(3)
819
+      data.push(0)
820
+      data.push(49)
821
+      data.push(67)
822
+      if (n > 15) {
823
+        n = 15
824
+      }
825
+      if (n < 1) {
826
+        n = 1
827
+      }
828
+      data.push(n)
829
+    };
830
+    /**
831
+     * 选择QRCode 纠错等级
832
+     * 传入参数说明
833
+     * n      功能        纠错能力
834
+     * 48    选择纠错等级  L 7
835
+     * 49    选择纠错等级  M 15
836
+     * 50    选择纠错等级  Q 25
837
+     * 51    选择纠错等级  H 30
838
+     */
839
+    jpPrinter.setSelectErrorCorrectionLevelForQRCode = function(n) { 
840
+      data.push(29)
841
+      data.push(40)
842
+      data.push(107)
843
+      data.push(3)
844
+      data.push(0)
845
+      data.push(49)
846
+      data.push(69)
847
+      data.push(n)
848
+    };
849
+    /**
850
+     * 存储QRCode 数据(d1...dk)到符号存储区
851
+     */
852
+    jpPrinter.setStoreQRCodeData = function(content) {
853
+      var code = new encode.TextEncoder(
854
+        'gb18030', {
855
+          NONSTANDARD_allowLegacyEncoding: true
856
+        }).encode(content)
857
+      data.push(29)
858
+      data.push(40)
859
+      data.push(107)
860
+      data.push(parseInt((code.length + 3) % 256))
861
+      data.push(parseInt((code.length + 3) / 256))
862
+      data.push(49)
863
+      data.push(80)
864
+      data.push(48)
865
+      for (var i = 0; i < code.length; ++i) {
866
+        data.push(code[i])
867
+      }
868
+    };
869
+    /**
870
+     * 打印QRCode 条码
871
+     */
872
+    jpPrinter.setPrintQRCode = function() { 
873
+      data.push(29)
874
+      data.push(40)
875
+      data.push(107)
876
+      data.push(3)
877
+      data.push(0)
878
+      data.push(49)
879
+      data.push(81)
880
+      data.push(48)
881
+    };
882
+    /**
883
+     * 设置GB18030编码格式文字
884
+     */
885
+    jpPrinter.setText = function (content) { 
886
+      var code = new encode.TextEncoder(
887
+        'gb18030', {
888
+          NONSTANDARD_allowLegacyEncoding: true
889
+        }).encode(content)
890
+      for (var i = 0; i < code.length; ++i) {
891
+        data.push(code[i])
892
+      }
893
+    };
894
+    /**
895
+     * 添加用户自定义指令
896
+     */
897
+    jpPrinter.setUserCommand = function (content) { //添加用户指令
898
+      data.push(content)
899
+    };
900
+    
901
+   
902
+    jpPrinter.getData = function() { //获取打印数据
903
+      return data;
904
+    };
905
+    jpPrinter.clearData = function () { //获取打印数据
906
+      if(data.length>0){
907
+        data.clearData
908
+      }
909
+    };
910
+    return jpPrinter; 
911
+  },
912
+
913
+  Query: function() {
914
+    var queryStatus = {};
915
+    var buf;
916
+    var dateView;
917
+    queryStatus.getRealtimeStatusTransmission = function(n) { //查询打印机实时状态
918
+      /*
919
+      n = 1:传送打印机状态
920
+      n = 2:传送脱机状态
921
+      n = 3:传送错误状态
922
+      n = 4:传送纸传感器状态
923
+      */
924
+      buf = new ArrayBuffer(3)
925
+      dateView = new DataView(buf)
926
+      dateView.setUint8(0, 16)
927
+      dateView.setUint8(1, 4)
928
+      dateView.setUint8(2, n)
929
+      queryStatus.query(buf)
930
+    }
931
+
932
+    queryStatus.query = function(buf) {
933
+      wx.writeBLECharacteristicValue({
934
+        deviceId: app.BLEInformation.deviceId,
935
+        serviceId: app.BLEInformation.writeServiceId,
936
+        characteristicId: app.BLEInformation.writeCharaterId,
937
+        value: buf,
938
+        success: function(res) {
939
+
940
+        },
941
+        complete: function(res) {
942
+          console.log(res)
943
+          buf = null
944
+          dateView = null;
945
+        }
946
+      })
947
+    }
948
+    return queryStatus;
949
+  }
950
+
951
+};
952
+
953
+module.exports.jpPrinter = jpPrinter;

File diff suppressed because it is too large
+ 90 - 0
utils/gbk.js


+ 88 - 0
utils/http.js

@@ -0,0 +1,88 @@
1
+export let api_url = null
2
+
3
+export function get(url, params, success = noop, fail = noop) {
4
+  return http(url, 'GET', params, success, fail)
5
+}
6
+
7
+export function post(url, params, success = noop, fail = noop) {
8
+  return http(url, 'POST', params, success, fail)
9
+}
10
+
11
+function noop() {}
12
+
13
+function http(url, method, params, success, fail) {
14
+  // const type = wx.getStorageSync('env') || 'dev' // 测试环境
15
+  const type = wx.getStorageSync('env') || 'ijolijoli' // 正式环境
16
+  switch (type) {
17
+    case 'dev':
18
+      api_url = 'https://test-api-ads.tiantianqutao.com/'
19
+      break
20
+    default:
21
+      api_url = 'https://test-api-ads.tiantianqutao.com/'
22
+      break
23
+  }
24
+  return wx.request({
25
+    url: `${api_url}${url}`,
26
+    method: method,
27
+    data: params,
28
+    header: {
29
+      token: wx.getStorageSync('token') || ''
30
+    },
31
+    success: ({ data, statusCode, header }) => {
32
+      console.log(`==============${url}`, data)
33
+      if (data.code == 200) {
34
+        success(data, header)
35
+      } else if (data.code == 201) {
36
+        wx.showToast({
37
+          title: data.msg,
38
+          icon: 'none'
39
+        })
40
+        fail(data, header)
41
+      } else if (data.code == 400) {
42
+        console.log('登录失败')
43
+        wx.showToast({
44
+          title: data.msg,
45
+          icon: 'none'
46
+        })
47
+        let pages = getCurrentPages()
48
+        if (pages.length == 0) {
49
+          wx.reLaunch({
50
+            url: '/pages/login/login'
51
+          })
52
+          return
53
+        }
54
+        // if (pages[pages.length - 1].route == 'pages/deviceLogin/deviceLogin') {
55
+        //   wx.navigateTo({
56
+        //     url: '/pages/login/login?prePage=1'
57
+        //   })
58
+        // } else {
59
+        //   wx.reLaunch({
60
+        //     url: '/pages/login/login'
61
+        //   })
62
+        // }
63
+        // wx.reLaunch({
64
+        //   url: '/pages/login/login',
65
+        // })
66
+        // login()
67
+      }else{
68
+        success(data, header)
69
+      }
70
+    },
71
+    fail() {
72
+      wx.showToast({
73
+        title: '服务器异常 请稍后再试',
74
+        icon: 'none'
75
+      })
76
+    }
77
+  })
78
+}
79
+
80
+
81
+
82
+// 清理code
83
+export function clearWxLoginCode() {
84
+  getApp().loginConfig = {
85
+    code: '',
86
+    codeTime: ''
87
+  }
88
+}

+ 30 - 0
utils/tool.js

@@ -0,0 +1,30 @@
1
+/*函数节流*/
2
+function throttle(fn, interval) {
3
+  var enterTime = 0;//触发的时间
4
+  var gapTime = interval || 300 ;//间隔时间,如果interval不传,则默认300ms
5
+  return function() {
6
+    var context = this;
7
+    var backTime = new Date();//第一次函数return即触发的时间
8
+    if (backTime - enterTime > gapTime) {
9
+      fn.call(context,arguments);
10
+      enterTime = backTime;//赋值给第一次触发的时间,这样就保存了第二次触发的时间
11
+    }
12
+  };
13
+}
14
+/*函数防抖*/
15
+function debounce(fn, interval) {
16
+  var timer;
17
+  var gapTime = interval || 1000;//间隔时间,如果interval不传,则默认1000ms
18
+  return function() {
19
+    clearTimeout(timer);
20
+    var context = this;
21
+    var args = arguments;//保存此处的arguments,因为setTimeout是全局的,arguments不是防抖函数需要的。
22
+    timer = setTimeout(function() {
23
+      fn.call(context,args);
24
+    }, gapTime);
25
+  };
26
+}
27
+export default {
28
+  throttle,
29
+  debounce
30
+};

+ 506 - 0
utils/tsc.js

@@ -0,0 +1,506 @@
1
+var app = getApp();
2
+var encode = require("./encoding.js");
3
+var jpPrinter = {    
4
+  createNew: function() {      
5
+    var jpPrinter = {};
6
+    var data = "";
7
+    var command = []
8
+
9
+    jpPrinter.name = "蓝牙打印机";
10
+
11
+    jpPrinter.init = function() {};
12
+
13
+    jpPrinter.addCommand = function(content) { //将指令转成数组装起
14
+      var code = new encode.TextEncoder(
15
+        'gb18030', {
16
+          NONSTANDARD_allowLegacyEncoding: true
17
+        }).encode(content)
18
+      for (var i = 0; i < code.length; ++i) {
19
+        command.push(code[i])
20
+      }
21
+    };
22
+    /**
23
+     * 该指令用于设定卷标纸的宽度和长度
24
+     * 传入参数说明
25
+     * pageWidght:标签宽度 单位mm
26
+     * pageHeight:标签高度 单位mm
27
+     */
28
+    jpPrinter.setSize = function(pageWidght, pageHeight) { 
29
+      data = "SIZE " + pageWidght.toString() + " mm" + "," + pageHeight.toString() + " mm" + "\r\n";
30
+      jpPrinter.addCommand(data)
31
+    };
32
+    /**
33
+     * 该指令用于定义两张卷标纸间的垂直间距距离
34
+     * 传入参数说明
35
+     * 标签间隙 单位mm
36
+     */
37
+    jpPrinter.setGap = function (printGap) {
38
+      data = "GAP " + printGap.toString() + " mm,0 mm\r\n";
39
+      jpPrinter.addCommand(data)
40
+    };
41
+    /**
42
+     * 该指令用于设定黑标高度及定义标签印完后标签额外送出的长度
43
+     * 传入参数说明
44
+     * 黑标高度 单位mm
45
+     */
46
+    jpPrinter.setBline = function (printBline) { 
47
+      data = "BLINE " + printBline.toString() + " mm,0 mm\r\n";
48
+      jpPrinter.addCommand(data)
49
+    };
50
+    /**
51
+     * 该指令用于控制在剥离模式时(peel-off mode)每张卷标停止的位置,在打印
52
+     * 下一张时打印机会将原先多推出或少推出的部分以回拉方式补偿回来。该指令仅
53
+     * 适用于剥离模式。
54
+     * 传入参数说明
55
+     * 纸张停止的距离 单位mm 
56
+     */
57
+    jpPrinter.setOffset = function (offset) { 
58
+      data = "OFFSET " + offset.toString() + " mm,0 mm\r\n";
59
+      jpPrinter.addCommand(data)
60
+    };
61
+    /**
62
+     * 该指令用于控制打印速度
63
+     *  传入参数说明
64
+     * 1<=printSpeed<=6
65
+     * 实际支持速度以自检页为准
66
+     */
67
+    jpPrinter.setSpeed = function(printSpeed) {
68
+      data = "SPEED " + printSpeed.toString() + "\r\n";
69
+      jpPrinter.addCommand(data)
70
+    };
71
+    /**
72
+     * 该指令用于控制打印时的浓度
73
+      传入参数说明
74
+     * 1<=printDensity<=15
75
+     */
76
+    jpPrinter.setDensity = function(printDensity) {
77
+      data = "DENSITY " + printDensity.toString() + "\r\n";
78
+      jpPrinter.addCommand(data)
79
+    }
80
+
81
+    /**
82
+     * 该指令用于定义打印时出纸和打印字体的方向
83
+     * 传入参数说明
84
+     * direction=0或direction=1
85
+     */
86
+    jpPrinter.setDirection = function (direction) {
87
+      data = "DIRECTION " + direction + "\r\n";
88
+      jpPrinter.addCommand(data)
89
+    };
90
+    /**
91
+     * 该指令用于定义卷标的参考坐标原点。坐标原点位置和打印方向有关
92
+     * 传入参数说明
93
+     * x 水平方向的坐标位置,单位dots
94
+     * y 垂直方向的坐标位置,单位dots
95
+     * 打印机分辨率200 DPI:  1 mm = 8  dots
96
+     * 打印机分辨率300 DPI:  1 mm = 12 dots
97
+     */
98
+    jpPrinter.setReference = function (x, y) {
99
+      data = "REFERENCE " + x + "," + y + "\r\n";
100
+      jpPrinter.addCommand(data)
101
+    };
102
+    /**
103
+     * 该指令表示标签打印偏移量多少设置
104
+     * 传入参数说明  点数dot
105
+     * n 偏移量 ,单位dot 1mm=8 dots
106
+     * 打印机分辨率200 DPI:  1 mm = 8  dots
107
+     * 打印机分辨率300 DPI:  1 mm = 12 dots
108
+     */
109
+    jpPrinter.setShift = function (n) {
110
+      data = "SHIFT " + n +"\r\n";
111
+      jpPrinter.addCommand(data)
112
+    };
113
+   /**
114
+    * 该指令用于选择对应的国际字符集
115
+    * 传入参数说明
116
+    *  001:USA
117
+    *  002:French
118
+    *  003:Latin America
119
+    *  034:Spanish
120
+    *  039:Italian
121
+    *  044:United Kingdom
122
+    *  046:Swedish
123
+    *  047:Norwegian
124
+    *  049:German
125
+    */
126
+    jpPrinter.setCountry = function(country) {
127
+      data = "COUNTRY " + country + "\r\n";
128
+      jpPrinter.addCommand(data)
129
+    };
130
+    /**
131
+     * 该指令用于选择对应的国际代码页
132
+     * 传入参数说明
133
+     * 8-bit codepage 字符集代表
134
+     * 437:United States
135
+     * 850:Multilingual
136
+     * 852:Slavic
137
+     * 860:Portuguese
138
+     * 863:Canadian/French
139
+     * 865:Nordic
140
+     * 
141
+     * Windows code page
142
+     * 1250:Central Europe
143
+     * 1252:Latin I
144
+     * 1253:Greek
145
+     * 1254:Turkish
146
+     * 
147
+     * 以下代码页仅限于12×24 dot 英数字体
148
+     * WestEurope:WestEurope
149
+     * Greek:Greek
150
+     * Hebrew:Hebrew
151
+     * EastEurope:EastEurope
152
+     * Iran:Iran
153
+     * IranII:IranII
154
+     * Latvian:Latvian
155
+     * Arabic:Arabic
156
+     * Vietnam:Vietnam
157
+     * Uygur:Uygur
158
+     * Thai:Thai
159
+     * 1252:Latin I
160
+     * 1257:WPC1257
161
+     * 1251:WPC1251
162
+     * 866:Cyrillic
163
+     * 858:PC858
164
+     * 747:PC747
165
+     * 864:PC864
166
+     * 1001:PC1001
167
+     */
168
+    jpPrinter.setCodepage = function(codepage) {
169
+      data = "CODEPAGE " + codepage + "\r\n";
170
+      jpPrinter.addCommand(data)
171
+    }
172
+    /**
173
+     * 该指令用于清除图像缓冲区(image buffer)的数据
174
+     */
175
+    jpPrinter.setCls = function() {
176
+      data = "CLS\r\n";
177
+      jpPrinter.addCommand(data)
178
+    };
179
+    /**
180
+     * 该指令用于将标签纸向前推送指定的长度
181
+     * 传入参数说明  点数dots
182
+     * 打印机分辨率200 DPI:1 mm = 8  dots
183
+     * 打印机分辨率300 DPI:1 mm = 12 dots
184
+     */
185
+    jpPrinter.setFeed = function(feed) {
186
+      data = "FEED " + feed + "\r\n";
187
+      jpPrinter.addCommand(data)
188
+    };
189
+    /**
190
+     * 该指令用于将标签纸向后回拉指定的长度
191
+     * 传入参数说明  点数dots
192
+     * 打印机分辨率200 DPI:1 mm = 8  dots 
193
+     * 打印机分辨率300 DPI:1 mm = 12 dots
194
+     */
195
+    jpPrinter.setBackFeed = function(backup) {
196
+      data = "BACKFEED " + backup + "\r\n";
197
+      jpPrinter.addCommand(data)
198
+    }
199
+    /**
200
+     * 该指令用于控制打印机进一张标签纸
201
+     */
202
+    jpPrinter.setFromfeed = function() {
203
+      data = "FORMFEED\r\n";
204
+      jpPrinter.addCommand(data)
205
+    };
206
+    /**
207
+     * 在使用含有间隙或黑标的标签纸时,若不能确定第一张标签纸是否在正确打印位
208
+     * 置时,此指令可将标签纸向前推送至下一张标签纸的起点开始打印。标签尺寸和
209
+     * 间隙需要在本条指令前设置
210
+     * 注:使用该指令时,纸张高度大于或等于30 mm
211
+     */
212
+    jpPrinter.setHome = function() { //根据Size找到下一张标签纸的位置
213
+      data = "HOME\r\n";
214
+      jpPrinter.addCommand(data)
215
+    };
216
+    /**
217
+     * 该指令用于打印出存储于影像缓冲区内的数据
218
+     */
219
+    jpPrinter.setPagePrint = function() { 
220
+      data = "PRINT 1,1\r\n"
221
+      jpPrinter.addCommand(data)
222
+    };
223
+    /**
224
+     * 该指令用于打印出存储于影像缓冲区内的数据
225
+     * 传入参数说明  打印份数
226
+     * 1≤n≤65535
227
+     */
228
+    jpPrinter.setPrint = function (n) {
229
+      data = "PRINT "+n+",1\r\n"
230
+      jpPrinter.addCommand(data)
231
+    };
232
+    /**
233
+     * 该指令用于控制蜂鸣器的频率,可设定10 阶的声音,每阶声音的长短由第二个参数控制
234
+     * 传入参数说明
235
+     * level        音阶:0-9
236
+     * interval 间隔时间:1-4095
237
+     */
238
+    jpPrinter.setSound = function(level, interval) { //控制蜂鸣器
239
+      data = "SOUND " + level + "," + interval + "\r\n";
240
+      jpPrinter.addCommand(data)
241
+    };
242
+    /**
243
+     * 该指令用于设定打印机进纸时,若经过所设定的长度仍无法侦测到垂直间距,则打印机在连续纸模式工作
244
+     * 传入参数说明  点数dots
245
+     */
246
+    jpPrinter.setLimitfeed = function(limit) { // 检测垂直间距
247
+      data = "LIMITFEED " + limit + "mm\r\n";
248
+      jpPrinter.addCommand(data)
249
+    };
250
+    /**
251
+     * 打印自检页
252
+     */
253
+    jpPrinter.setSelfTest=function(){
254
+      data = "SELFTEST\r\n";
255
+      jpPrinter.addCommand(data)
256
+    }
257
+    /**
258
+     * 该指令用于在标签上画线
259
+     * 传入参数说明
260
+     * x 线条左上角X 坐标,单位dots
261
+     * y 线条左上角Y 坐标,单位dots
262
+     * width  线宽,单位dots
263
+     * height 线高,单位dots
264
+     */
265
+    jpPrinter.setBar = function(x, y, width, height) { //绘制线条
266
+      data = "BAR " + x + "," + y + "," + width + "," + height + "\r\n"
267
+      jpPrinter.addCommand(data)
268
+    };
269
+    /**
270
+     * 该指令用于在卷标上绘制矩形方框
271
+     * x_start 方框左上角X 坐标,单位dots
272
+     * y_start 方框左上角Y 坐标,单位dots
273
+     * x_end 方框右下角X 坐标,单位dots
274
+     * y_end 方框右下角Y 坐标,单位dots
275
+     * thickness 方框线宽,单位dots
276
+     */
277
+    jpPrinter.setBox = function (x_start, y_start, x_end, y_end, thickness) {
278
+      data = "BOX " + x_start + "," + y_start + "," + x_end + "," + y_end + "," + thickness + "\r\n";
279
+      jpPrinter.addCommand(data)
280
+    };
281
+    /**
282
+    * 该指令用来画一维条码
283
+    * 传入参数说明
284
+    * x 左上角水平坐标起点,以点(dot)表示
285
+    * y 左上角垂直坐标起点,以点(dot)表示
286
+    * height 条形码高度,以点(dot)表示
287
+    *readable 0 表示人眼不可识,1 表示人眼可识
288
+    *rotation 条形码旋转角度,顺时针方向 0,90,180,270
289
+    * narrow 窄bar 宽度,以点(dots)表示
290
+    * wide 宽bar 宽度,以点(dot)表示
291
+    * content 打印内容
292
+    */
293
+    jpPrinter.setBarCode = function (x, y, codetype, height, readable, rotation, narrow, wide, content) {
294
+      data = "BARCODE " + x + "," + y + ",\"" + codetype + "\"," + height + "," + readable + "," + rotation + "," + narrow + "," + wide + ",\"" + content + "\"\r\n"
295
+      jpPrinter.addCommand(data)
296
+    };
297
+
298
+    /**
299
+     * 打印图片(单色图片)
300
+     * res为画布参数
301
+     */
302
+    jpPrinter.setBitmap = function (x, y, mode, res) {
303
+      console.log(res)
304
+      var w = res.width;
305
+      var h = res.height;
306
+      var bitw = parseInt((w + 7) / 8) * 8;
307
+      // var bitw = (parseInt(w) % 8) == 0 ? (parseInt(w) / 8) :( parseInt(w) / 8+1);
308
+      var pitch = parseInt(bitw / 8);
309
+      var bits = new Uint8Array(h * pitch);
310
+      console.log("w=" + w + ", h=" + h + ", bitw=" + bitw + ", pitch=" + pitch + ", bits=" + bits.length);
311
+      var cmd = "BITMAP " + x + "," + y + "," + pitch + "," + h + "," + mode + ",";
312
+      console.log("add cmd: " + cmd);
313
+      jpPrinter.addCommand(cmd);
314
+      // for (var i=0; i<bits.length; i++) {
315
+      //   bits[i] = 0;
316
+      // }
317
+      for (y = 0; y < h; y++) {
318
+        for (x = 0; x < w; x++) {
319
+          var color = res.data[(y * w + x) * 4 + 1];
320
+          if (color <= 128) {
321
+            bits[parseInt(y * pitch + x / 8)] |= (0x80 >> (x % 8));
322
+          }
323
+        }
324
+      }
325
+      for (var i = 0; i < bits.length; i++) {
326
+        command.push((~bits[i]) & 0xFF);
327
+      }
328
+      console.log(command);
329
+    };
330
+  
331
+    /**
332
+     * 将指定的区域反相打印
333
+     * 传入参数说明
334
+     * x_start 反相区域左上角X 坐标,单位dot
335
+     * y_start 反相区域左上角Y 坐标,单位dot
336
+     * x_width 反相区域宽度,单位dot
337
+     * y_height 反相区域高度,单位dot
338
+     */
339
+    jpPrinter.setErase = function(x_start, y_start, x_width, y_height) {
340
+      data = "ERASE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
341
+      jpPrinter.addCommand(data)
342
+    };
343
+    /**
344
+     * 将指定的区域反相打印
345
+     * 传入参数说明
346
+     * x_start 反相区域左上角X 坐标,单位dot
347
+     * y_start 反相区域左上角Y 坐标,单位dot
348
+     * x_width 反相区域宽度,单位dot
349
+     * y_height 反相区域高度,单位dot
350
+     */
351
+    jpPrinter.setReverse = function(x_start, y_start, x_width, y_height) {
352
+      data = "REVERSE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
353
+      jpPrinter.addCommand(data)
354
+    };
355
+    /**
356
+     * 该指令用于打印字符串
357
+     * 传入参数说明
358
+     * x 文字X 方向起始点坐标
359
+     *  y 文字Y 方向起始点坐标
360
+     *  font 字体名称
361
+     *  1 8×12 dot 英数字体
362
+     *  2 12×20 dot 英数字体
363
+     *  3 16×24 dot 英数字体
364
+     *  4 24×32 dot 英数字体
365
+     *  5 32×48 dot 英数字体
366
+     *  6 14×19 dot 英数字体OCR-B
367
+     *  7 21×27 dot 英数字体OCR-B
368
+     *  8 14×25 dot 英数字体OCR-A
369
+     *  9 9×17 dot 英数字体
370
+     *  10 12×24 dot 英数字体
371
+     *  TSS16.BF2 简体中文16×16(GB 码)
372
+     *  TSS20.BF2 简体中文20×20(GB 码)
373
+     *  TST24.BF2 繁体中文24×24(大五码)
374
+     *  TSS24.BF2 简体中文24×24(GB 码)
375
+     *  K 韩文24×24Font(KS 码)
376
+     * TSS32.BF2 简体中文32×32(GB 码)
377
+     * rotation 文字旋转角度(顺时针方向) 0, 90, 180, 270
378
+     */
379
+    jpPrinter.setText = function(x, y, font, rotation,x_, y_, str) { 
380
+      data = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + x_ + "," + y_ + "," + "\"" + str + "\"\r\n"
381
+      jpPrinter.addCommand(data)
382
+    };
383
+    /**
384
+     * 该指令用来打印二维码
385
+     * x 二维码水平方向起始点坐标
386
+     * y 二维码垂直方向起始点坐标
387
+     * ECC level 选择QRCODE 纠错等级
388
+     *   L 7%
389
+     *   M 15%
390
+     *   Q 25%
391
+     *   H 30%
392
+     * cell width 二维码宽度1-10
393
+     * mode 手动/自动编码
394
+     *   A Auto
395
+     *   M Manual
396
+     * rotation 旋转角度(顺时针方向) 0,90,180,270
397
+     * content  内容
398
+     */
399
+    jpPrinter.setQrcode = function(x, y, level, width, mode, content) {
400
+      data = "QRCODE " + x + "," + y + "," + level + "," + width + "," + mode + "," + 0 + ",\"" + content +"\"\r\n"
401
+      jpPrinter.addCommand(data)
402
+    };
403
+    /**
404
+     * 该指令用来起动Key1 的预设功能
405
+     * 传入参数说明
406
+     * ON 开启按键
407
+     * OFF 关闭按键
408
+     */
409
+    jpPrinter.setKey1=function(n){
410
+      data = "SET KYE1 "+n.toString+"\r\n"
411
+      jpPrinter.addCommand(data)
412
+    };
413
+    /**
414
+   * 该指令用来起动Key2 的预设功能
415
+   * 传入参数说明
416
+   * ON 开启按键
417
+   * OFF 关闭按键
418
+   */
419
+    jpPrinter.setKey2 = function (n) {
420
+      data = "SET KYE2 " + n.toString + "\r\n"
421
+      jpPrinter.addCommand(data)
422
+    };
423
+    /**
424
+     * 该指令用来启动/关闭剥离模式,默认值为关闭
425
+     * 传入参数说明
426
+     * ON  起动剥离模式
427
+     * OFF 关闭剥离模式
428
+     */
429
+    jpPrinter.setPeel = function (n) {
430
+      data = "SET PEEL " + n.toString + "\r\n"
431
+      jpPrinter.addCommand(data)
432
+    };
433
+    /**
434
+     * 此命令是用来启用/禁用撕纸位置走到撕纸处,此设置关掉电源后将保存在打印机内
435
+     * 传入参数说明
436
+     * ON 启用撕纸位置走到撕纸处
437
+     * OFF 禁用撕纸位置走到撕纸处,命令在起始位置有效
438
+     */
439
+    jpPrinter.setTear = function (n) {
440
+      data = "SET TEAR " + n.toString + "\r\n"
441
+      jpPrinter.addCommand(data)
442
+    };
443
+    /**
444
+   * 此命令是用来启用/禁用撕纸位置走到撕纸处,此设置关掉电源后将保存在打印机内
445
+     * 传入参数说明
446
+   * ON 启用撕纸位置走到撕纸处
447
+   * OFF 禁用撕纸位置走到撕纸处,命令在起始位置有效
448
+   */
449
+    jpPrinter.setStripper = function (n) {
450
+      data = "SET STRIPPER " + n.toString + "\r\n"
451
+      jpPrinter.addCommand(data)
452
+    };
453
+    /**
454
+     * 此设置用于启用/禁用打印头合盖传感器。如果禁用合盖传感器,打印机头被打开时,将不会传回错误信息。
455
+     * 此设置将保存在打印机内存。
456
+     * 传入参数说明
457
+     * ON  启用打印头合盖传感器
458
+     * OFF 禁用打印头合盖传感器
459
+     */
460
+    jpPrinter.setHead = function (n) {
461
+      data = "SET HEAD " + n.toString + "\r\n"
462
+      jpPrinter.addCommand(data)
463
+    };
464
+    /**
465
+     * 此命令将禁用/启用标签机在无纸或开盖错误发生后,上纸或合盖后重新打印一次标签内容
466
+     * 传入参数说明
467
+     * OFF 禁止此功能
468
+     * ON 启用此功能
469
+     */
470
+    jpPrinter.setReprint = function (n) {
471
+      data = "SET REPRINT " + n.toString + "\r\n"
472
+      jpPrinter.addCommand(data)
473
+    };
474
+
475
+    /**
476
+     * 设定开启/关闭碳带感应器,即切换热转式/热感印式打印。通常打印机于开启电
477
+     *源时,碳带感应器即会自动检测打印机是否已装上碳带,并藉此决定使用热感式
478
+     *或热转式打印。此项设定并不会存于打印机中。此方法仅适用于热转式机器。
479
+     * 传入参数说明
480
+     * OFF 禁止此功能
481
+     * ON 启用此功能
482
+     */
483
+    jpPrinter.setRibbon = function (n) {
484
+      data = "SET RIBBON " + n.toString + "\r\n"
485
+      jpPrinter.addCommand(data)
486
+    };
487
+    /**
488
+     * 此命令用于设置切刀状态,关闭打印机电源后,该设置将会被存储在打印机内存中。
489
+     * 传入参数说明
490
+     * OFF 关闭切刀功能
491
+     * BATCH 在PRINT 命令结束后切纸
492
+     * pieces 0-65535,用于设置每几个标签进行切纸
493
+     */
494
+    jpPrinter.setCut = function (n) {
495
+      data = "SET CUTTER " + n.toString + "\r\n"
496
+      jpPrinter.addCommand(data)
497
+    };
498
+    //获取打印数据
499
+    jpPrinter.getData = function() {
500
+      return command;
501
+    };  
502
+    return jpPrinter; 
503
+  }
504
+};
505
+
506
+module.exports.jpPrinter = jpPrinter;

+ 141 - 0
utils/util.js

@@ -0,0 +1,141 @@
1
+const gbk = require('./gbk.js');
2
+console.log("sasas" + gbk);
3
+const formatTime = date => {
4
+  const year = date.getFullYear()
5
+  const month = date.getMonth() + 1
6
+  const day = date.getDate()
7
+  const hour = date.getHours()
8
+  const minute = date.getMinutes()
9
+  const second = date.getSeconds()
10
+
11
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
12
+}
13
+
14
+const formatNumber = n => {
15
+  n = n.toString()
16
+  return n[1] ? n : '0' + n
17
+}
18
+
19
+
20
+const hexStringToBuff = str => { //str='中国:WXHSH'
21
+  const buffer = new ArrayBuffer((sumStrLength(str)) * 4)
22
+  const dataView = new DataView(buffer)
23
+  var data = str.toString();
24
+  var p = 0; //ArrayBuffer 偏移量
25
+  for (var i = 0; i < data.length; i++) {
26
+    if (isCN(data[i])) { //是中文
27
+      //调用GBK 转码
28
+      var t = gbk.encode(data[i]);
29
+      for (var j = 0; j < 2; j++) {
30
+        //var code = t[j * 2] + t[j * 2 + 1];
31
+        var code = t[j * 3 + 1] + t[j * 3 + 2];
32
+         var temp = parseInt(code, 16)
33
+        //var temp = strToHexCharCode(code);
34
+        dataView.setUint8(p++, temp)
35
+      }
36
+    } else {
37
+      var temp = data.charCodeAt(i);
38
+      dataView.setUint8(p++, temp)
39
+    }
40
+  }
41
+  return buffer;
42
+}
43
+
44
+function toUnicode(s) {
45
+  var str = "";
46
+  for (var i = 0; i < s.length; i++) {
47
+    str += "\\u" + s.charCodeAt(i).toString(16) + "\t";
48
+  }
49
+  return str;
50
+}
51
+
52
+function strToHexCharCode(str) {
53
+  if (str === "")
54
+    return "";
55
+  var hexCharCode = [];
56
+  hexCharCode.push("0x");
57
+  for (var i = 0; i < str.length; i++) {
58
+    hexCharCode.push((str.charCodeAt(i)).toString(16));
59
+  }
60
+  return hexCharCode.join("");
61
+}
62
+
63
+function sumStrLength(str) {
64
+  var length = 0;
65
+  var data = str.toString();
66
+  for (var i = 0; i < data.length; i++) {
67
+    if (isCN(data[i])) { //是中文
68
+      length += 2;
69
+    } else {
70
+      length += 1;
71
+    }
72
+  }
73
+  return length;
74
+}
75
+
76
+function isCN(str) {
77
+  if (/^[\u3220-\uFA29]+$/.test(str)) {
78
+    return true;
79
+  } else {
80
+    return false;
81
+  }
82
+}
83
+
84
+//汉字转码
85
+function hexStringToArrayBuffer(str) {
86
+  const buffer = new ArrayBuffer((str.length / 2) + 1)
87
+  const dataView = new DataView(buffer)
88
+  for (var i = 0; i < str.length / 2; i++) {
89
+    var temp = parseInt(str[i * 2] + str[i * 2 + 1], 16)
90
+    dataView.setUint8(i, temp)
91
+  }
92
+  dataView.setUint8((str.length / 2), 0x0a)
93
+  return buffer;
94
+}
95
+
96
+//返回八位数组
97
+function subString(str) {
98
+  var arr = [];
99
+  if (str.length > 8) { //大于8
100
+    for (var i = 0;
101
+      (i * 8) < str.length; i++) {
102
+      var temp = str.substring(i * 8, 8 * i + 8);
103
+      arr.push(temp)
104
+    }
105
+    return arr;
106
+  } else {
107
+    return str
108
+  }
109
+}
110
+
111
+//不带有汉字
112
+function hexStringToArrayBufferstr(str) {
113
+  let val = ""
114
+  for (let i = 0; i < str.length; i++) {
115
+    if (val === '') {
116
+      val = str.charCodeAt(i).toString(16)
117
+    } else {
118
+      val += ',' + str.charCodeAt(i).toString(16)
119
+    }
120
+  }
121
+  val += "," + "0x0a";
122
+  console.log(val)
123
+  // 将16进制转化为ArrayBuffer
124
+  return new Uint8Array(val.match(/[\da-f]{2}/gi).map(function(h) {
125
+    return parseInt(h, 16)
126
+  })).buffer
127
+}
128
+
129
+function send0X0A() {
130
+  const buffer = new ArrayBuffer(1)
131
+  const dataView = new DataView(buffer)
132
+  dataView.setUint8(0, 0x0a)
133
+  return buffer;
134
+}
135
+
136
+
137
+module.exports = {
138
+  hexStringToArrayBuffer: hexStringToArrayBuffer,
139
+  hexStringToBuff: hexStringToBuff,
140
+  send0X0A: send0X0A
141
+}