Prechádzať zdrojové kódy

更新 登录;tabbar

wzh 3 rokov pred
rodič
commit
160e5480f5

+ 2 - 2
cloudfunctions/api/index.js

@@ -3,8 +3,8 @@ const cloud = require('wx-server-sdk')
 const TcbRouter = require("tcb-router")
 const got = require('got')
 const md5 = require("md5")
-const APPID = "wxf22759845920b6f3"
-const SECRET = "149873f78958781cd1693c1238deaebc"
+const APPID = "wxd8fe7909b3471a51"
+const SECRET = "c5aeac63ae791b76942d8d52261ef710"
 const WXBizDataCrypt = require('./WXBizDataCrypt')
 
 cloud.init()

+ 4 - 0
miniprogram/app.js

@@ -1,5 +1,9 @@
+import {
+  wxSetSessionKey
+} from "./utils/wxUtils"
 App({
   onLaunch: function () {
+    wxSetSessionKey()
     const updateManager = wx.getUpdateManager()
 
     updateManager.onCheckForUpdate(function (res) {

+ 10 - 5
miniprogram/app.json

@@ -14,18 +14,23 @@
     "navigationBarTextStyle": "black"
   },
   "tabBar": {
-    "list": [
-      {
+    "list": [{
         "pagePath": "pages/index/index",
-        "text": "首页"
+        "text": "首页",
+        "iconPath": "images/tabBar/index.png",
+        "selectedIconPath": "images/tabBar/index-c.png"
       },
       {
         "pagePath": "pages/voyages/voyages",
-        "text": "航次"
+        "text": "航次",
+        "iconPath": "images/tabBar/voyage.png",
+        "selectedIconPath": "images/tabBar/voyage-c.png"
       },
       {
         "pagePath": "pages/me/me",
-        "text": "我"
+        "text": "我",
+        "iconPath": "images/tabBar/user.png",
+        "selectedIconPath": "images/tabBar/user-c.png"
       }
     ]
   },

+ 54 - 0
miniprogram/components/getPhoneButton/getPhoneButton.js

@@ -0,0 +1,54 @@
+// components/getPhoneButton/getPhoneButton.js
+import {
+  postApi
+} from "../../apis/api"
+import cloudApi from "../../apis/cloudApi"
+Component({
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    style: String,
+    type: String
+  },
+  data: {
+
+  },
+  methods: {
+    async getPhoneNumber(e) {
+      let res = await postApi("/user/wx/openId/login", {
+        openId: wx.getStorageSync('openId')
+      })
+      let {
+        result
+      } = res.data
+      Object.keys(result).forEach(function (key) {
+        wx.setStorageSync(key, result[key])
+      })
+      wx.switchTab({
+        url: '/pages/index/index',
+      })
+      return
+      try {
+        if (e.detail.errMsg == "getPhoneNumber:ok") {
+          let session_key = wx.getStorageSync('session_key')
+          let {
+            result
+          } = await cloudApi("getWxPhoneNumber", {
+            ...e.detail,
+            session_key
+          })
+          let {
+            phone,
+          } = result
+        } else {
+          wx.showToast({
+            title: '请授权以登录',
+            icon: "error"
+          })
+        }
+      } catch (error) {}
+
+    }
+  }
+})

+ 4 - 0
miniprogram/components/getPhoneButton/getPhoneButton.json

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

+ 3 - 0
miniprogram/components/getPhoneButton/getPhoneButton.wxml

@@ -0,0 +1,3 @@
+<button type="{{type}}" style="{{style}}" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">
+  <slot></slot>
+</button>

+ 1 - 0
miniprogram/components/getPhoneButton/getPhoneButton.wxss

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

BIN
miniprogram/images/tabBar/index-c.png


BIN
miniprogram/images/tabBar/index.png


BIN
miniprogram/images/tabBar/user-c.png


BIN
miniprogram/images/tabBar/user.png


BIN
miniprogram/images/tabBar/voyage-c.png


BIN
miniprogram/images/tabBar/voyage.png


+ 12 - 3
miniprogram/pages/index/index.js

@@ -12,6 +12,7 @@ Page({
     let res = await postApi('/voyage/index', {
       cargoOwnerId: wx.getStorageSync('cargoOwnerId')
     })
+    console.log(res)
     this.setData({
       indexInfo: res.data.result
     })
@@ -20,8 +21,16 @@ Page({
 
   },
   onLoad() {
-    this.getIndexInfo()
-    const child = this.selectComponent('.voyages');
-    child.getVoyageList()
+    let cargoOwnerId = wx.getStorageSync('cargoOwnerId')
+    if (cargoOwnerId) {
+      this.getIndexInfo()
+      const child = this.selectComponent('.voyages');
+      child.getVoyageList()
+    } else {
+      wx.redirectTo({
+        url: '/pages/login/login',
+      })
+    }
+
   }
 })

+ 4 - 4
miniprogram/pages/index/index.wxss

@@ -6,19 +6,19 @@
 }
 
 .block-line:first-child>view:first-child {
-  background: rgb(131, 38, 131);
+  background: #27ae60;
 }
 
 .block-line:first-child>view:last-child {
-  background: rgb(170, 37, 37);
+  background: #e74c3c;
 }
 
 .block-line:last-child>view:first-child {
-  background: rgb(28, 28, 112);
+  background: #e67e22;
 }
 
 .block-line:last-child>view:last-child {
-  background: rgb(26, 95, 26);
+  background: #2980b9;
 }
 
 .block-line>view>view:first-child {

+ 3 - 1
miniprogram/pages/login/login.json

@@ -1,3 +1,5 @@
 {
-  "usingComponents": {}
+  "usingComponents": {
+    "PhoneButton": "/components/getPhoneButton/getPhoneButton"
+  }
 }

+ 1 - 1
miniprogram/pages/login/login.wxml

@@ -1 +1 @@
-<button bindtap="login">login</button>
+<PhoneButton type="primary">登录/注册</PhoneButton>

+ 5 - 1
miniprogram/pages/me/me.js

@@ -9,6 +9,10 @@ Page({
 
   },
   async getCargoOwnerInfo() {
-
+    let res = await cloudApi('getOpenId')
+    console.log(res)
+  },
+  onLoad() {
+    this.getCargoOwnerInfo()
   }
 })