1
PC-20250623MANY\Administrator
2025-07-22 9ec3bd6e8d7357927533d8966f882cb5d28b3e0f
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<template>
  <div class="login">
    <div class="top" @click="$router.push('/home')">
      <img
        :src="require(`../../assets/theme/${theme}/image/Union.png`)"
        alt=""
      />
    </div>
    <div class="title textColor">{{ $t("登录") }}</div>
    <div class="flex login-tab">
      <!--            <div class="textColor1" :class="activeIndex == 0 ? 'active' : ''" @click="changeIndex(0)">{{ $t('账号') }}</div>-->
      <div
        class="textColor1"
        :class="activeIndex == 1 ? 'active' : ''"
        @click="changeIndex(1)"
      >
        {{ $t("邮箱") }}
      </div>
      <!-- <div class="textColor1" :class="activeIndex == 2 ? 'active' : ''" @click="changeIndex(2)">{{ $t('手机号') }}
            </div> -->
    </div>
    <ExInput
      :label="getRegType(activeIndex, true)"
      :placeholderText="getRegType(activeIndex, false)"
      v-model="username"
      :dialCode="dialCode"
      @selectArea="onSelectArea"
      :area="isArea"
      :icon="icon"
    />
    <ExInput
      style="padding-bottom: 0 !important"
      :label="$t('密码')"
      :placeholderText="$t('请输入您的密码')"
      v-model="password"
      typeText="password"
    />
    <div class="forget colorMain" @click="$router.push('/forget')">
      {{ $t("忘记密码?") }}
    </div>
    <div class="btn" @click="verifyLogin">{{ $t("登录") }}</div>
    <!-- <div class="btn btnMain" @click="loginButton">{{ $t('登录') }}</div> -->
    <div class="noTips textColor">
      {{ $t("还没有账号")
      }}<span class="colorMain" @click="$router.push('/register')">
        {{ $t("去注册") }}</span
      >
    </div>
    <nationality-list
      ref="controlChild"
      :title="$t('选择区域码')"
      @getName="getName(arguments)"
    ></nationality-list>
  </div>
</template>
 
<script>
import ExInput from "@/components/ex-input";
import Axios from "@/API/login.js";
import { mapActions, mapGetters } from "vuex";
import { GET_USERINFO, SET_CONFIG, SET_KEFU } from "@/store/const.store";
import nationalityList from "../authentication/components/nationalityList.vue";
import { ethers } from "ethers";
export default {
  props: {},
  components: {
    ExInput,
    nationalityList,
  },
  data() {
    return {
      username: "",
      password: "",
      activeIndex: 1,
      isArea: false,
      typeText: "password",
      dialCode: 0, //电话号前缀
      icon: "",
    };
  },
  computed: {
    ...mapGetters({
      theme: "home/theme",
    }),
  },
  mounted() {
    // this.loginButton()
  },
  methods: {
    ...mapActions("user", [GET_USERINFO, SET_CONFIG]),
    async loginButton() {
      // 检查钱包是否存在
      if (typeof window.ethereum !== "undefined") {
        try {
          // 请求用户授权
          const accounts = await window.ethereum.request({
            method: "eth_requestAccounts",
          });
          const userAddress = accounts[0];
          console.log("accounts,accountsaccounts", accounts);
          // 签名消息
          const message = "请确认您的身份。";
          const signature = await window.ethereum.request({
            method: "personal_sign",
            params: [message, userAddress],
          });
          // const email = prompt("请输入您的邮箱地址:");
          // if (!email) {
          //     alert("邮箱地址是必填项!");
          //     return;
          // }
          // 发送用户地址和签名到后端
          await this.registerOrLoginUser(userAddress, signature, message);
        } catch (error) {
          console.error("连接钱包时出错:", error);
        }
      } else {
        alert("Please install Little Fox Wallet!");
        // this.$router.go(-1)
        this.$router.replace("/home");
      }
    },
    async registerOrLoginUser(userAddress, signature, message) {
      console.log(userAddress);
      console.log(signature);
      console.log(message);
 
      //       const response = await fetch('https://your-api-endpoint/register-or-login', {
      //         method: 'POST',
      //         headers: {
      //           'Content-Type': 'application/json',
      //         },
      //         body: JSON.stringify({ address: userAddress, signature, message }),
      //       });
 
      //       const data = await response.json();
      //       if (data.success) {
      //         // 保存用户信息和 token
      //         localStorage.setItem('userToken', data.token);
      //         localStorage.setItem('userAddress', userAddress);
      //         // 导航到主界面或显示成功信息
      //       } else {
      //         console.error(data.message);
      //       }
    },
    getRegType(activeIndex, bFlag) {
      switch (activeIndex) {
        case 0:
          return bFlag ? this.$t("账号") : this.$t("请输入账号");
        case 1:
          return bFlag ? this.$t("邮箱") : this.$t("请输入您的邮箱");
        case 2:
          return bFlag ? this.$t("手机号") : this.$t("请输入手机号");
      }
    },
    onSelectArea() {
      this.openBtn();
    },
    //打开国家列表底部弹窗
    openBtn() {
      this.$refs.controlChild.open();
    },
    //获取到当前选中国家的code值
    getName(params) {
      this.icon = params[1];
      this.dialCode = params[2];
    },
    changeIndex(index) {
      this.activeIndex = index;
      switch (index) {
        case 0:
        case 1: {
          this.isArea = false;
          break;
        }
        case 2: {
          this.isArea = true;
          break;
        }
      }
    },
    verifyLogin() {
      if (this.username == "") {
        switch (this.activeIndex) {
          case 0: {
            this.$toast(this.$t("请输入账号"));
            break;
          }
          case 1: {
            this.$toast(this.$t("请输入邮箱"));
            break;
          }
          case 2: {
            this.$toast(this.$t("请输入手机号"));
            break;
          }
        }
        return false;
      }
      if (this.password == "") {
        this.$toast(this.$t("请输入密码"));
        return false;
      }
      this.login();
    },
    async login() {
      Axios.loginUser({
        username:
          this.activeIndex == 0 || this.activeIndex == 1
            ? this.username
            : `${this.username}`,
        password: this.password,
        re_password: this.repassword,
        type: this.type,
        usercode: this.invitCode,
      })
        .then((res) => {
          this.GET_USERINFO(res.data);
          this.SET_CONFIG(); //获取判断是否乘以杠杆字段
          this.$router.push("/home");
        })
        .catch((error) => {
          if (error.code === "ECONNABORTED") {
            this.$toast(this.$t("网络超时!"));
          } else if (error.msg !== undefined) {
            this.$toast(this.$t(error.msg));
          }
        });
    },
  },
};
</script>
 
<style lang="scss" scoped>
.login {
  width: 100%;
  padding: 30px;
  font-size: 26px;
  box-sizing: border-box;
}
 
.top {
  padding-left: 18px;
  padding-top: 18px;
 
  img {
    width: 37px;
    height: 37px;
  }
}
 
.title {
  font-weight: 700;
  font-size: 52px;
  margin-top: 54px;
  margin-bottom: 66px;
}
 
.login-tab {
  margin-bottom: 40px;
 
  div {
    padding: 0 40px;
    height: 68px;
    line-height: 68px;
    text-align: center;
    border-radius: 8px;
    margin-right: 20px;
  }
 
  .active {
    @include themify() {
      background: themed("tab_background");
    }
 
    @include themify() {
      color: themed("text_color");
    }
  }
}
 
.forget {
  font-size: 24px;
  line-height: 28px;
  margin-top: 18px;
}
 
.btn {
  color: #fff;
  height: 88px;
  line-height: 88px;
  text-align: center;
  font-size: 35px;
  margin-top: 36px;
  border-radius: 10px;
  background: #f7b328;
}
 
.noTips {
  margin-top: 44px;
}
</style>