创建新的小程序,进出码,体温上报功能迁移基本完成
This commit is contained in:
		
							
								
								
									
										111
									
								
								weixin-miniprogram/pages/index/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								weixin-miniprogram/pages/index/index.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,111 @@
 | 
			
		||||
// pages/index/index.js
 | 
			
		||||
const menuItemDict = require('../../utils/menuList.js')
 | 
			
		||||
const getUserGroupByRole = require('../../utils/getUserGroupByRole.js')
 | 
			
		||||
 | 
			
		||||
const app = getApp()
 | 
			
		||||
 | 
			
		||||
Page({
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面的初始数据
 | 
			
		||||
   */
 | 
			
		||||
  data: {
 | 
			
		||||
    debugText: "调试",
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面加载
 | 
			
		||||
   */
 | 
			
		||||
  onLoad(options) {
 | 
			
		||||
    console.log("index/index onLoad", options)
 | 
			
		||||
    // console.log("wx.getLaunchOptionsSync()", wx.getLaunchOptionsSync())
 | 
			
		||||
    this.setData({
 | 
			
		||||
      debugText: JSON.stringify(options, null, 4),
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    console.log("menuItemDict", menuItemDict)
 | 
			
		||||
    this.userInfo = wx.getStorageSync("userInfo")
 | 
			
		||||
    this.displayUsername = this.userInfo?.username ?? "请登录"
 | 
			
		||||
    if (!this.userInfo) {
 | 
			
		||||
      console.log("用户未登录")
 | 
			
		||||
      wx.redirectTo({
 | 
			
		||||
        url: '/pages/index/login'
 | 
			
		||||
      })
 | 
			
		||||
    } else {
 | 
			
		||||
      // 用户已登录
 | 
			
		||||
      this.userGroup = getUserGroupByRole(this.userInfo.role)
 | 
			
		||||
      this.debugObject = {
 | 
			
		||||
        userGroup: this.userGroup
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      //判断用户是否是通过扫小程序码进来的
 | 
			
		||||
      if (options.scene) {
 | 
			
		||||
        // 扫门禁的小程序码
 | 
			
		||||
        if (options.scene.split('%')[0] == "guard") {
 | 
			
		||||
          options.scene = null
 | 
			
		||||
          wx.navigateTo({
 | 
			
		||||
            url: "/pages/scan/entrance"
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 开发模式下自动跳转到指定页面,节省开发时间
 | 
			
		||||
    console.log("app.globalData", app.globalData)
 | 
			
		||||
    if (app.globalData.debugMode) {
 | 
			
		||||
      wx.switchTab({
 | 
			
		||||
        url: '/pages/residents/report'
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面初次渲染完成
 | 
			
		||||
   */
 | 
			
		||||
  onReady() {
 | 
			
		||||
    console.log("index/index onReady")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面显示
 | 
			
		||||
   */
 | 
			
		||||
  onShow() {
 | 
			
		||||
    console.log("index/index onShow")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面隐藏
 | 
			
		||||
   */
 | 
			
		||||
  onHide() {
 | 
			
		||||
    console.log("index/index onHide")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面卸载
 | 
			
		||||
   */
 | 
			
		||||
  onUnload() {
 | 
			
		||||
    console.log("index/index onUnload")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面相关事件处理函数--监听用户下拉动作
 | 
			
		||||
   */
 | 
			
		||||
  onPullDownRefresh() {
 | 
			
		||||
    console.log("index/index onPullDownRefresh")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面上拉触底事件的处理函数
 | 
			
		||||
   */
 | 
			
		||||
  onReachBottom() {
 | 
			
		||||
    console.log("index/index onReachBottom")
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 用户点击右上角分享
 | 
			
		||||
   */
 | 
			
		||||
  onShareAppMessage() {
 | 
			
		||||
    console.log("index/index onShareAppMessage")
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										5
									
								
								weixin-miniprogram/pages/index/index.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								weixin-miniprogram/pages/index/index.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
{
 | 
			
		||||
  "usingComponents": {},
 | 
			
		||||
  "navigationBarTitleText": "首页",
 | 
			
		||||
  "navigationStyle": "custom"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										21
									
								
								weixin-miniprogram/pages/index/index.wxml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								weixin-miniprogram/pages/index/index.wxml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
<!--pages/index/index.wxml-->
 | 
			
		||||
<view>
 | 
			
		||||
  <image src="../../image/home.jpg" style="width: 100vw; height: 41.5vw;"></image>
 | 
			
		||||
  <view style="display: block; padding-left: 30px; padding-top: 12px;">
 | 
			
		||||
    <text>欢迎你,{{ displayUsername }}!</text>
 | 
			
		||||
  </view>
 | 
			
		||||
  <view>
 | 
			
		||||
  <text>调试信息:{{ debugText }}</text>
 | 
			
		||||
  </view>
 | 
			
		||||
  <view id="menu-view">
 | 
			
		||||
    <view class="menu-item" v-for="menuItem in filterMenuItems" :key="menuItem.id">
 | 
			
		||||
      <view :class="{ 'add-dot': menuItem.addDot }" style="display: inline-block;">
 | 
			
		||||
        <image :src="'../../image/icon/' + menuItem.image" class="item-image" bindtap='switchTo(menuItem.switchFunc, menuItem.url)'></image>
 | 
			
		||||
      </view>
 | 
			
		||||
      <view>{{ menuItem.title }}</view>
 | 
			
		||||
    </view>
 | 
			
		||||
  </view>
 | 
			
		||||
  <button type="primary" size="mini" bindtap="toggleDot('code', true)">显示小红点</button>
 | 
			
		||||
  <button type="primary" size="mini" bindtap="toggleDot('code', false)">隐藏小红点</button>
 | 
			
		||||
  <button type="warn" size="mini" bindtap="magicButton">魔法按钮</button>
 | 
			
		||||
</view>
 | 
			
		||||
							
								
								
									
										1
									
								
								weixin-miniprogram/pages/index/index.wxss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								weixin-miniprogram/pages/index/index.wxss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
/* pages/index/index.wxss */
 | 
			
		||||
							
								
								
									
										129
									
								
								weixin-miniprogram/pages/index/login.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								weixin-miniprogram/pages/index/login.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
			
		||||
// pages/index/login.js
 | 
			
		||||
const app = getApp();
 | 
			
		||||
 | 
			
		||||
Page({
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面的初始数据
 | 
			
		||||
   */
 | 
			
		||||
  data: {
 | 
			
		||||
    username: '',
 | 
			
		||||
    password: '',
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面加载
 | 
			
		||||
   */
 | 
			
		||||
  onLoad(options) {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面初次渲染完成
 | 
			
		||||
   */
 | 
			
		||||
  onReady() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面显示
 | 
			
		||||
   */
 | 
			
		||||
  onShow() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面隐藏
 | 
			
		||||
   */
 | 
			
		||||
  onHide() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 生命周期函数--监听页面卸载
 | 
			
		||||
   */
 | 
			
		||||
  onUnload() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面相关事件处理函数--监听用户下拉动作
 | 
			
		||||
   */
 | 
			
		||||
  onPullDownRefresh() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 页面上拉触底事件的处理函数
 | 
			
		||||
   */
 | 
			
		||||
  onReachBottom() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * 用户点击右上角分享
 | 
			
		||||
   */
 | 
			
		||||
  onShareAppMessage() {
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  bindKeyInput: function (e) {
 | 
			
		||||
    // console.log('e', e)
 | 
			
		||||
    let newData = {}
 | 
			
		||||
    newData[e.target.id] = e.detail.value
 | 
			
		||||
    this.setData(newData)
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  login() {
 | 
			
		||||
    console.log("login userInput", this.data.username, this.data.password)
 | 
			
		||||
    if (!this.data.username || !this.data.password) {
 | 
			
		||||
      wx.showToast({
 | 
			
		||||
        title: "请完善登录信息",
 | 
			
		||||
        icon: 'error',
 | 
			
		||||
        duration: 2000
 | 
			
		||||
      })
 | 
			
		||||
    } else {
 | 
			
		||||
      wx.showLoading({
 | 
			
		||||
        title: '加载中'
 | 
			
		||||
      })
 | 
			
		||||
      wx.request({
 | 
			
		||||
        url: `${app.globalData.baseUrl}/user/login`,
 | 
			
		||||
        method: "POST",
 | 
			
		||||
        header: {
 | 
			
		||||
          "Content-Type": "application/x-www-form-urlencoded" //用于post
 | 
			
		||||
        },
 | 
			
		||||
        data: {
 | 
			
		||||
          username: this.data.username,
 | 
			
		||||
          password: this.data.password,
 | 
			
		||||
        },
 | 
			
		||||
        success: function (d) {
 | 
			
		||||
          wx.hideLoading()
 | 
			
		||||
          let result = d.data;
 | 
			
		||||
          if (result.success) {
 | 
			
		||||
            // 登录成功
 | 
			
		||||
            wx.setStorageSync("userInfo", result.data.userInfo);
 | 
			
		||||
            console.log("userInfo", wx.getStorageSync("userInfo"))
 | 
			
		||||
            wx.switchTab({
 | 
			
		||||
              url: '/pages/index/index'
 | 
			
		||||
            })
 | 
			
		||||
          } else {
 | 
			
		||||
            wx.showToast({
 | 
			
		||||
              title: result.msg,
 | 
			
		||||
              icon: 'error',
 | 
			
		||||
              duration: 2000
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        fail: function () {
 | 
			
		||||
          wx.hideLoading()
 | 
			
		||||
          wx.showToast({
 | 
			
		||||
            title: "请求失败",
 | 
			
		||||
            icon: 'error',
 | 
			
		||||
            duration: 2000
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										4
									
								
								weixin-miniprogram/pages/index/login.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								weixin-miniprogram/pages/index/login.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
{
 | 
			
		||||
  "usingComponents": {},
 | 
			
		||||
  "navigationBarTitleText": "登录"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								weixin-miniprogram/pages/index/login.wxml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								weixin-miniprogram/pages/index/login.wxml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
<!--pages/index/login.wxml-->
 | 
			
		||||
<view class="container">
 | 
			
		||||
  <view class="login-icon">
 | 
			
		||||
    <image class="login-img" src="../../image/icon/login-background.svg"></image>
 | 
			
		||||
  </view>
 | 
			
		||||
  <view class="login-from">
 | 
			
		||||
    <view class="inputView">
 | 
			
		||||
      <!--账号-->
 | 
			
		||||
      <input class="inputText" placeholder="账号" id="username" bindinput="bindKeyInput" />
 | 
			
		||||
      <!--密码-->
 | 
			
		||||
      <input class="inputText" placeholder="密码" id="password" bindinput="bindKeyInput" password="true" />
 | 
			
		||||
    </view>
 | 
			
		||||
    <view class="loginBtnView">
 | 
			
		||||
      <!--按钮-->
 | 
			
		||||
      <button class="loginBtn" type="primary" bindtap="login">登录</button>
 | 
			
		||||
      <button class="loginBtn" type="secondary" bindtap="visitor">访客申请</button>
 | 
			
		||||
    </view>
 | 
			
		||||
  </view>
 | 
			
		||||
</view>
 | 
			
		||||
							
								
								
									
										31
									
								
								weixin-miniprogram/pages/index/login.wxss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								weixin-miniprogram/pages/index/login.wxss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
/* pages/index/login.wxss */
 | 
			
		||||
.container {
 | 
			
		||||
  line-height: 1.5em;
 | 
			
		||||
  padding: 30px 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.login-icon {
 | 
			
		||||
  text-align: center;
 | 
			
		||||
  height: 35vh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.login-img {
 | 
			
		||||
  width: 50vw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.login-from {
 | 
			
		||||
  padding: 0 20vw;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.inputText {
 | 
			
		||||
  width: 95%;
 | 
			
		||||
  border-bottom: solid 1px;
 | 
			
		||||
  margin-bottom: 50px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.loginBtnView {
 | 
			
		||||
  margin-top: 70px;
 | 
			
		||||
}
 | 
			
		||||
.loginBtn {
 | 
			
		||||
  margin-bottom: 25px;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user