yangys
2025-05-27 81060ec4cc3ead9080d4bdb3875920e257583de4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
  <el-dialog
    title="账号注册"
    append-to-body
    v-model="accountBox"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false"
    width="20%"
  >
    <el-form :model="form" ref="form" label-width="80px">
      <el-form-item v-if="tenantMode" label="租户编号">
        <el-input v-model="form.tenantId" placeholder="请输入租户编号"></el-input>
      </el-form-item>
      <el-form-item label="用户姓名">
        <el-input v-model="form.name" placeholder="请输入用户姓名"></el-input>
      </el-form-item>
      <el-form-item label="账号名称">
        <el-input v-model="form.account" placeholder="请输入账号名称"></el-input>
      </el-form-item>
      <el-form-item label="账号密码">
        <el-input v-model="form.password" placeholder="请输入账号密码"></el-input>
      </el-form-item>
      <el-form-item label="确认密码">
        <el-input v-model="form.password2" placeholder="请输入确认密码"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" :loading="loading" @click="handleRegister">确 定</el-button>
      </span>
    </template>
  </el-dialog>
</template>
 
<script>
import { mapGetters } from 'vuex';
import { validatenull } from 'utils/validate';
import { registerGuest } from '@/api/user';
import { getTopUrl } from 'utils/util';
import { info } from '@/api/system/tenant';
import { resetRouter } from '@/router/index';
 
export default {
  name: 'thirdRegister',
  data() {
    return {
      form: {
        tenantId: '',
        name: '',
        account: '',
        password: '',
        password2: '',
      },
      loading: false,
      tenantMode: true,
      accountBox: false,
    };
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  created() {
    this.getTenant();
  },
  mounted() {
    // 若未登录则弹出框进行绑定
    if (validatenull(this.userInfo.userId) || this.userInfo.userId < 0) {
      this.form.name = this.userInfo.userName;
      this.form.account = this.userInfo.account;
      this.accountBox = true;
    }
  },
  methods: {
    handleRegister() {
      if (this.form.tenantId === '') {
        this.$message.warning('请先输入租户编号');
        return;
      }
      if (this.form.account === '') {
        this.$message.warning('请先输入账号名称');
        return;
      }
      if (this.form.password === '' || this.form.password2 === '') {
        this.$message.warning('请先输入密码');
        return;
      }
      if (this.form.password !== this.form.password2) {
        this.$message.warning('两次密码输入不一致');
        return;
      }
      this.loading = true;
      registerGuest(this.form, this.userInfo.oauthId).then(
        res => {
          this.loading = false;
          const data = res.data;
          if (data.success) {
            this.accountBox = false;
            this.$alert('注册申请已提交,请耐心等待管理员通过!', '注册提示').then(() => {
              this.$store.dispatch('LogOut').then(() => {
                resetRouter();
                this.$router.push({ path: '/login' });
              });
            });
          } else {
            this.$message.error(data.msg || '提交失败');
          }
        },
        error => {
          window.console.log(error);
          this.loading = false;
        }
      );
    },
    getTenant() {
      let domain = getTopUrl();
      // 临时指定域名,方便测试
      //domain = "https://bladex.cn";
      info(domain).then(res => {
        const data = res.data;
        if (data.success && data.data.tenantId) {
          this.form.tenantId = data.data.tenantId;
          this.tenantMode = false;
        }
      });
    },
  },
};
</script>