Explorar el Código

Initial Commit

panxingxin hace 5 años
commit
272d7554f7
Se han modificado 15 ficheros con 357 adiciones y 0 borrados
  1. 14 0
      .gitignore
  2. 39 0
      app.js
  3. 14 0
      app.json
  4. 10 0
      app.wxss
  5. 63 0
      pages/bind/bind.js
  6. 4 0
      pages/bind/bind.json
  7. 17 0
      pages/bind/bind.wxml
  8. 8 0
      pages/bind/bind.wxss
  9. 71 0
      pages/index/index.js
  10. 3 0
      pages/index/index.json
  11. 13 0
      pages/index/index.wxml
  12. 21 0
      pages/index/index.wxss
  13. 54 0
      project.config.json
  14. 7 0
      sitemap.json
  15. 19 0
      utils/util.js

+ 14 - 0
.gitignore

@@ -0,0 +1,14 @@
+# Windows
+[Dd]esktop.ini
+Thumbs.db
+$RECYCLE.BIN/
+
+# macOS
+.DS_Store
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+
+# Node.js
+node_modules/

+ 39 - 0
app.js

@@ -0,0 +1,39 @@
+//app.js
+App({
+  onLaunch: function () {
+    // 展示本地存储能力
+    var logs = wx.getStorageSync('logs') || []
+    logs.unshift(Date.now())
+    wx.setStorageSync('logs', logs)
+
+    // 登录
+    wx.login({
+      success: res => {
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+      }
+    })
+    // 获取用户信息
+    wx.getSetting({
+      success: res => {
+        if (res.authSetting['scope.userInfo']) {
+          // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
+          wx.getUserInfo({
+            success: res => {
+              // 可以将 res 发送给后台解码出 unionId
+              this.globalData.userInfo = res.userInfo
+
+              // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
+              // 所以此处加入 callback 以防止这种情况
+              if (this.userInfoReadyCallback) {
+                this.userInfoReadyCallback(res)
+              }
+            }
+          })
+        }
+      }
+    })
+  },
+  globalData: {
+    userInfo: null
+  }
+})

+ 14 - 0
app.json

@@ -0,0 +1,14 @@
+{
+  "pages": [
+    "pages/index/index",
+    "pages/bind/bind"
+  ],
+  "window": {
+    "backgroundTextStyle": "light",
+    "navigationBarBackgroundColor": "#fff",
+    "navigationBarTitleText": "WeChat",
+    "navigationBarTextStyle": "black"
+  },
+  "style": "v2",
+  "sitemapLocation": "sitemap.json"
+}

+ 10 - 0
app.wxss

@@ -0,0 +1,10 @@
+/**app.wxss**/
+.container {
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: space-between;
+  padding: 200rpx 0;
+  box-sizing: border-box;
+} 

+ 63 - 0
pages/bind/bind.js

@@ -0,0 +1,63 @@
+//logs.js
+const util = require('../../utils/util.js')
+
+Page({
+  data: {
+    mobile:'',
+    code:''
+  },
+  getMobileInput:function(e){
+     this.setData({
+      mobile:e.detail.value
+     })
+  },
+  getCodeInput:function(e){
+    this.setData({
+      code:e.detail.value
+    })
+ },
+ getSmsCode:function(){
+  wx.request({
+    url: 'http://192.168.20.53:9999/admin/mobile/' + this.data.mobile,
+    method: 'get',
+    header: {
+      'Authorization': 'Basic dGVzdDp0ZXN0'
+    },
+    success(res) {
+      //测试环境报文直接返回了短信验证码,生产环境服务端要接短信通道下发
+      console.log(res)
+    }
+  })
+},
+bind:function(e){
+  wx.request({
+    url: 'http://192.168.20.53:9999/auth/mobile/token/sms?mobile=SMS@'+this.data.mobile+'&code='+this.data.code+'&grant_type=mobile',
+    method: 'post',
+    header: {
+      'Authorization': 'Basic dGVzdDp0ZXN0'
+    },
+    success(res) {
+      var token = res.data.access_token
+     
+      wx.login({
+        success(res){
+          wx.request({
+            url: 'http://192.168.20.53:9999/admin/social/bind?state=MINI&code=' + res.code,
+            method: 'post',
+            header: {
+              'Authorization': 'Bearer '+token
+            },
+            success(r) {
+              console.log(r)
+            }
+          })
+        }
+      })
+
+
+
+    }
+  })
+},
+
+})

+ 4 - 0
pages/bind/bind.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "用户绑定",
+  "usingComponents": {}
+}

+ 17 - 0
pages/bind/bind.wxml

@@ -0,0 +1,17 @@
+<!--logs.wxml-->
+<view class="container log-list">
+<view class="cell">
+    手机号:<input bindinput="getMobileInput"></input>
+</view>
+<view class="cell">
+
+</view>
+<view class="cell">
+   <button bindtap="getSmsCode">获取验证码</button>
+   <input bindinput="getCodeInput"></input>
+
+</view>
+<view class="cell">
+   <button bindtap="bind">绑定</button>
+</view>
+</view>

+ 8 - 0
pages/bind/bind.wxss

@@ -0,0 +1,8 @@
+.log-list {
+  display: flex;
+  flex-direction: column;
+  padding: 40rpx;
+}
+.log-item {
+  margin: 10rpx;
+}

+ 71 - 0
pages/index/index.js

@@ -0,0 +1,71 @@
+//index.js
+//获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+    username:'未登录'
+  },
+  getPhoneNumber (e) {
+    console.log(e.detail.errMsg)
+    console.log(e.detail.iv)
+    console.log(e.detail.encryptedData)
+  },
+  //事件处理函数
+  bindViewTap: function() {
+    wx.navigateTo({
+      url: '../logs/logs'
+    })
+  },
+
+
+  getmenu:function(){
+
+        wx.request({
+          url: 'http://192.168.20.53:9999/admin/menu/tree',
+          method: 'get',
+          header: {
+            'Authorization': 'Bearer '+wx.getStorageSync('token')
+          },
+          success(r) {
+            console.log(r)
+            console.log(r)
+          }
+        })
+  
+
+  },
+
+
+
+  login:function(){
+    // var self = this
+    // wx.login({
+    //   success(res){
+    //     wx.request({
+    //       url: 'http://192.168.20.53:9999/auth/mobile/token/social?grant_type=mobil&mobile=MINI@'+res.code,
+    //       method: 'post',
+    //       header: {
+    //         'Authorization': 'Basic dGVzdDp0ZXN0'
+    //       },
+    //       success(res){
+    //         console.log(res)
+    //         wx.setStorageSync('token', res.data.access_token);
+    //         if (res.statusCode === 401){
+    //            console.log(res.data)
+    //            wx.navigateTo({
+    //              url: '../bind/bind',
+    //            })
+    //         }else{
+    //           self.setData({
+    //             username: res.data.username
+    //           })
+    //         }
+    //       }
+    //     })
+    //   }
+    // })
+
+  }
+
+})

+ 3 - 0
pages/index/index.json

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

+ 13 - 0
pages/index/index.wxml

@@ -0,0 +1,13 @@
+<!--index.wxml-->
+<view class="container">
+  <view class="userinfo">
+<button bindgetphonenumber="getPhoneNumber" open-type="getPhoneNumber" type="primary">登录</button>
+
+<!-- <button bindtap="getmenu">获取菜单</button> -->
+
+
+  </view>
+  <view class="usermotto">
+    <text class="user-motto">{{username}}</text>
+  </view>
+</view>

+ 21 - 0
pages/index/index.wxss

@@ -0,0 +1,21 @@
+/**index.wxss**/
+.userinfo {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+.userinfo-avatar {
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+}
+
+.userinfo-nickname {
+  color: #aaa;
+}
+
+.usermotto {
+  margin-top: 200px;
+}

+ 54 - 0
project.config.json

@@ -0,0 +1,54 @@
+{
+	"description": "项目配置文件",
+	"packOptions": {
+		"ignore": []
+	},
+	"setting": {
+		"urlCheck": false,
+		"es6": true,
+		"postcss": true,
+		"preloadBackgroundData": false,
+		"minified": true,
+		"newFeature": true,
+		"coverView": true,
+		"autoAudits": false,
+		"showShadowRootInWxmlPanel": true,
+		"scopeDataCheck": false,
+		"checkInvalidKey": true,
+		"checkSiteMap": true,
+		"uploadWithSourceMap": true,
+		"babelSetting": {
+			"ignore": [],
+			"disablePlugins": [],
+			"outputPath": ""
+		}
+	},
+	"compileType": "miniprogram",
+	"libVersion": "2.10.4",
+	"appid": "wx2b8ec05ea3a797a2",
+	"projectname": "pigx-mini-app-sample",
+	"debugOptions": {
+		"hidedInDevtools": []
+	},
+	"isGameTourist": false,
+	"simulatorType": "wechat",
+	"simulatorPluginLibVersion": {},
+	"condition": {
+		"search": {
+			"current": -1,
+			"list": []
+		},
+		"conversation": {
+			"current": -1,
+			"list": []
+		},
+		"game": {
+			"currentL": -1,
+			"list": []
+		},
+		"miniprogram": {
+			"current": -1,
+			"list": []
+		}
+	}
+}

+ 7 - 0
sitemap.json

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

+ 19 - 0
utils/util.js

@@ -0,0 +1,19 @@
+const formatTime = date => {
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+  const second = date.getSeconds()
+
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
+}
+
+const formatNumber = n => {
+  n = n.toString()
+  return n[1] ? n : '0' + n
+}
+
+module.exports = {
+  formatTime: formatTime
+}