backend-moke 模拟弱网环境;一些小修改
This commit is contained in:
		@@ -100,7 +100,6 @@
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import Taro from '@tarojs/taro'
 | 
			
		||||
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
 | 
			
		||||
import ENUM from '../../utils/const.js'
 | 
			
		||||
import DebugComp from '../../components/DebugComp.vue'
 | 
			
		||||
 | 
			
		||||
@@ -120,39 +119,37 @@ export default {
 | 
			
		||||
  components: {
 | 
			
		||||
    DebugComp
 | 
			
		||||
  },
 | 
			
		||||
  mounted() {
 | 
			
		||||
    eventCenter.once(getCurrentInstance().router.onShow, () => {
 | 
			
		||||
      console.log('onShow')
 | 
			
		||||
      console.log("ENUM", ENUM)
 | 
			
		||||
 | 
			
		||||
      this.userInfo = Taro.getStorageSync("userInfo");
 | 
			
		||||
      this.displayUsername = this.userInfo?.username ?? "请登录";
 | 
			
		||||
      if (!this.userInfo) {
 | 
			
		||||
        console.log("用户未登录")
 | 
			
		||||
        Taro.redirectTo({
 | 
			
		||||
          url: '/pages/index/login'
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        const role = ENUM.user.role;
 | 
			
		||||
        this.isVisitor = [
 | 
			
		||||
          role.VISITOR,
 | 
			
		||||
        ].includes(this.userInfo.role);
 | 
			
		||||
        this.isUser = [
 | 
			
		||||
          role.RESIDENTS_OWNER,
 | 
			
		||||
          role.RESIDENTS_MEMBER,
 | 
			
		||||
          role.RESIDENTS_TENENT,
 | 
			
		||||
        ].includes(this.userInfo.role);
 | 
			
		||||
        this.isAdmin = [
 | 
			
		||||
          role.ADMIN,
 | 
			
		||||
          role.STAFF,
 | 
			
		||||
        ].includes(this.userInfo.role);
 | 
			
		||||
        console.log(
 | 
			
		||||
          "isVisitor", this.isVisitor,
 | 
			
		||||
          "isUser", this.isUser,
 | 
			
		||||
          "isAdmin", this.isAdmin
 | 
			
		||||
        )
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
  onShow() {
 | 
			
		||||
    console.log('onShow')
 | 
			
		||||
    console.log("ENUM", ENUM)
 | 
			
		||||
    this.userInfo = Taro.getStorageSync("userInfo");
 | 
			
		||||
    this.displayUsername = this.userInfo?.username ?? "请登录";
 | 
			
		||||
    if (!this.userInfo) {
 | 
			
		||||
      console.log("用户未登录")
 | 
			
		||||
      Taro.redirectTo({
 | 
			
		||||
        url: '/pages/index/login'
 | 
			
		||||
      })
 | 
			
		||||
    } else {
 | 
			
		||||
      const role = ENUM.user.role;
 | 
			
		||||
      this.isVisitor = [
 | 
			
		||||
        role.VISITOR,
 | 
			
		||||
      ].includes(this.userInfo.role);
 | 
			
		||||
      this.isUser = [
 | 
			
		||||
        role.RESIDENTS_OWNER,
 | 
			
		||||
        role.RESIDENTS_MEMBER,
 | 
			
		||||
        role.RESIDENTS_TENENT,
 | 
			
		||||
      ].includes(this.userInfo.role);
 | 
			
		||||
      this.isAdmin = [
 | 
			
		||||
        role.ADMIN,
 | 
			
		||||
        role.STAFF,
 | 
			
		||||
      ].includes(this.userInfo.role);
 | 
			
		||||
      console.log(
 | 
			
		||||
        "isVisitor", this.isVisitor,
 | 
			
		||||
        "isUser", this.isUser,
 | 
			
		||||
        "isAdmin", this.isAdmin
 | 
			
		||||
      )
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  methods: {
 | 
			
		||||
    goCode() {
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,7 @@ export default {
 | 
			
		||||
        })
 | 
			
		||||
      } else {
 | 
			
		||||
        let passwordHash = md5(this.password);
 | 
			
		||||
        Taro.showLoading({ title: '加载中' })
 | 
			
		||||
        Taro.request({
 | 
			
		||||
          url: `${this.baseUrl}/user/login`,
 | 
			
		||||
          method: "POST",
 | 
			
		||||
@@ -54,18 +55,14 @@ export default {
 | 
			
		||||
            password: passwordHash,
 | 
			
		||||
          },
 | 
			
		||||
          success: function (d) {
 | 
			
		||||
            Taro.hideLoading()
 | 
			
		||||
            let result = d.data;
 | 
			
		||||
            if (result.success) {
 | 
			
		||||
              // 登录成功
 | 
			
		||||
              Taro.setStorageSync("userInfo", result.data.userInfo);
 | 
			
		||||
              console.log("userInfo", Taro.getStorageSync("userInfo"))
 | 
			
		||||
              Taro.showToast({
 | 
			
		||||
                title: "登录成功",
 | 
			
		||||
                icon: 'success',
 | 
			
		||||
                success: function () {
 | 
			
		||||
                  Taro.switchTab({
 | 
			
		||||
                    url: '/pages/index/index'
 | 
			
		||||
                  })
 | 
			
		||||
                }
 | 
			
		||||
              Taro.switchTab({
 | 
			
		||||
                url: '/pages/index/index'
 | 
			
		||||
              })
 | 
			
		||||
            } else {
 | 
			
		||||
              Taro.showToast({
 | 
			
		||||
@@ -76,6 +73,7 @@ export default {
 | 
			
		||||
            }
 | 
			
		||||
          },
 | 
			
		||||
          fail: function () {
 | 
			
		||||
            Taro.hideLoading()
 | 
			
		||||
            Taro.showToast({
 | 
			
		||||
              title: "请求失败",
 | 
			
		||||
              icon: 'error',
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@
 | 
			
		||||
 | 
			
		||||
<script>
 | 
			
		||||
import Taro from '@tarojs/taro'
 | 
			
		||||
import { eventCenter, getCurrentInstance } from '@tarojs/taro'
 | 
			
		||||
import drawQrcode from '../../utils/qrcode/index'
 | 
			
		||||
import utils from '../../utils/utils'
 | 
			
		||||
 | 
			
		||||
@@ -84,8 +83,8 @@ export default {
 | 
			
		||||
            text: text,
 | 
			
		||||
          })
 | 
			
		||||
 | 
			
		||||
          this.timeInterval = setInterval(this.updateTime, 1000);
 | 
			
		||||
          this.updateTime();
 | 
			
		||||
          this.timeInterval = setInterval(this.updateTime, 1000);
 | 
			
		||||
        })
 | 
			
		||||
    },
 | 
			
		||||
    updateTime() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user