zhangzengfei
2023-09-06 c0c034b3ef0fdf0fd9c802d5984dbd717db6817a
src/pages/index/App.vue
@@ -39,7 +39,8 @@
import formAccount from "@/pages/index/components/formAccount"
import formNet from "@/pages/index/components/formNet"
import formInfo from "@/pages/index/components/formInfo"
import { getInitInfo, savePassword, initNetwork, saveRegInfo, getRegInfo, isOnNet } from "./api"
import { tologin, getLoginUserData, getServerName } from "./api.ts"
import { getMenuListData } from "@/api/utils"
export default {
  name: "smartai init",
@@ -60,107 +61,45 @@
    }
  },
  mounted() {
    location.assign("/view/desktop/")
    return
    this.getInitInfo()
    let message = "网络正常"
    function onLine(callback) {
      var img = new Image()
      //临时判断网络是否通畅
      img.src = "http://apps.smartai.com/img/icons/favicon-32x32.png"
      img.onload = function() {
        if (callback) callback(true)
      }
      img.onerror = function() {
        if (callback) callback(false)
      }
    }
    onLine((flag) => {
      let message = ""
      if (flag) {
        this.isOnline = true
        message = "已有网络"
      } else {
        //网络断网效果图出来后,将此地改为跳转路径到效果图上
        message = "无法连接互联网"
        this.$notify({
          message: message
        })
      }
    })
    this.testLogin()
  },
  methods: {
    preForm() {
      if (this.active == this.createUser) {
        return
      }
      this.active--
    async testLogin() {
      // location.assign("/view/desktop/")
      tologin({ username: "basic", password: "basic2019" })
        .then((json) => {
          const loginedInfo = {
            access_token: json.token_type + " " + json.access_token,
            refresh_token: json.refresh_token
          }
          sessionStorage.setItem("expires_in", json.expires_in)
          sessionStorage.setItem("loginedInfo", JSON.stringify(loginedInfo))
          sessionStorage.setItem("userInfo", JSON.stringify(json.userInfo))
      // 如果网络正常, 直接跳过
      if (this.active == this.configNet && this.isOnline) {
        this.active--
      }
      this.$refs["carousel"].setActiveItem(this.active)
          location.assign("/view/desktop/")
        })
        .catch()
    },
    async nextForm() {
      // 提交注册信息
      if (this.active == this.registerInfo) {
        const data = this.$refs[`form${this.active}`].getFormData()
        await saveRegInfo(data)
        location.assign("/view/login/")
        return
    async getLoginUserData() {
      let res = await getLoginUserData()
      if (res.success) {
        sessionStorage.setItem("userInfo", JSON.stringify(res.data))
        // 获取权限
        // await this.getMenuList()
        return res.data
      } else {
      }
      // 配置网络
      if (this.active == this.configNet) {
        const data = this.$refs[`form${this.active}`].getFormData()
        initNetwork(data)
      }
      // 创建用户
      if (this.active == this.createUser) {
        const data = this.$refs[`form${this.active}`].getFormData()
        if (!data) {
          return false
        }
        await savePassword(data)
        // 如果网络正常, 直接跳到第三部
        if (this.isOnline) {
          this.active++
        }
      }
      this.active++
      this.$refs["carousel"].setActiveItem(this.active)
    },
    async nextFormNot() {
      await this.getInitInfo()
      this.active++
      this.$refs["carousel"].next()
    },
    async getInitInfo() {
      const res = await getInitInfo().catch((err) => {
        this.isWhite = false
      })
      if (res.data && res.data.initPwd && !res.data.initRegInfo) {
        this.active = this.isOnline ? this.registerInfo : this.configNet
    async getMenuList() {
      let results = await getMenuListData({})
      if (results && results.success) {
        /* 存储权限 */
        let buttonAuthoritys = results.data
        sessionStorage.setItem("buttonAuthoritys", "," + buttonAuthoritys + ",")
        sessionStorage.setItem("menuInfo", JSON.stringify(results))
      }
      if (res.data && res.data.initPwd && res.data.initRegInfo) {
        location.assign("/view/login/")
        return
      }
      this.isWhite = false
    }
  }
}