spring
6 天以前 f26f29d84e0a68831a6af14dab3eec5500496d2e
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
<template>
  <view>
    <view class="list">
      <view class="list-call">
        <u-icon class="u-icon" size="40" name="account"></u-icon>
        <input
          class="u-input"
          type="text"
          v-model="userInfo.username"
          maxlength="32"
          :placeholder="$t('login.placeholderAccount')"
        />
      </view>
      <view class="list-call">
        <u-icon class="u-icon" size="40" name="lock"></u-icon>
        <input
          class="u-input"
          type="text"
          v-model="userInfo.password"
          maxlength="32"
          :placeholder="$t('login.placeholderPassword')"
          :password="!showPassword"
        />
        <image
          class="u-icon-right"
          :src="
            '/static/custom/login/eye_' +
            (showPassword ? 'open' : 'close') +
            '.png'
          "
          @click="showPass()"
        ></image>
      </view>
      <u-radio-group v-model="remember" style="margin-top: 30rpx;" @change="checkboxChange">
        <u-radio shape="square" name="1" :checked="1" >记住密码</u-radio>
      </u-radio-group>
    </view>
    <view class="button custom-botton" hover-class="button-hover" @click="submit()">
      <text>{{ $t("login.loginButton") }}</text>
    </view>
  </view>
</template>
 
<script>
import { encryption } from "@/utils";
 
export default {
    name: "userPassword",
    data() {
        return {
            userInfo: {
                username: "",
                password: ""
            },
            showPassword: false,
            remember: '',
            baseUrl: "",
        };
    },
    created() {
        if (process.env.NODE_ENV == 'development') {
            // this.userInfo = {
            //      username: "admin",
            //     password: "zttZTT123!"
            // }
        }
        this.remember = uni.getStorageSync('remember');
        // 检查本地存储中是否有记住的用户名和密码
        const savedUsername = uni.getStorageSync('username');
        const savedPassword = uni.getStorageSync('password');
        if (savedUsername && savedPassword) {
            this.userInfo.username = savedUsername;
            this.userInfo.password = savedPassword;
        }
    },
    methods: {
        showPass() {
            this.showPassword = !this.showPassword;
        },
        //登录
        submit() {
            //表单校验
            if (this.userInfo.username.length === 0) {
                this.$u.toast("请输入账号");
                return;
            }
            if (this.userInfo.password.length === 0) {
                this.$u.toast("请输入密码");
                return;
            }
 
            //构造登录参数
            const user = encryption({
                data: this.userInfo,
                key: "pigxpigxpigxpigx",
                param: ["password"],
            });
 
            let grant_type = "password";
            //登录接口
            this.$u.api
                    .login(
                            {
                                randomStr: 'blockPuzzle',
                                code: '',
                                grant_type
                            },
                            {
                                username: user.username,
                                password: user.password
                            },
                            {
                                Authorization: "Basic cGlnOnBpZw==",
                                "content-type": "application/x-www-form-urlencoded",
                                isToken: false,
                                "TENANT-ID": "1",
                            }
                    )
                    .then((res) => {
                        //提示
                        this.$u.toast("恭喜您,登录成功!");
                        if (this.remember == 1) {
                            uni.setStorageSync('username', this.userInfo.username);
                            uni.setStorageSync('password', this.userInfo.password);
                            uni.setStorageSync('remember', this.remember);
                        } else {
                            // 如果用户未勾选“记住我”,清除本地存储中的用户名和密码
                            uni.removeStorageSync('username');
                            uni.removeStorageSync('password');
                            uni.removeStorageSync('remember');
                        }
                        console.log('dadasd', res)
                        // 登陆成功,存储相关信息
                        this.$u.vuex("vuex_token", res.access_token);
                        this.$u.vuex("vuex_refresh_token", res.refresh_token);
                        this.$u.vuex("vuex_username", res.user_info.staffName);
                        this.$u.vuex("vuex_userId", res.user_info.id);
                        //this.$u.vuex("vuex_client_id", res.client_id);
                        this.$u.vuex("vuex_user", res.user_info);
 
                        //查询用户详细信息并储存
                        /*this.$u.api.user.getUserInfo().then((res) => {
            console.log("获取用户信息:", res);
            this.$u.vuex("vuex_user", res.data.sysUser);
          });*/
 
                        //跳转页面
                        setTimeout(() => {
                            uni.reLaunch({
                                url: "/pages/sys/home/index",
                            });
                        }, 500);
                    })
                    .catch((e) => {
                        this.$u.toast(e);
                    });
        },
        checkboxChange(e) {
            console.log('e---', e)
            this.remember = e
            console.log('this.remember222---', this.remember)
        }
    }
}
</script>
 
<style lang="scss">
@import "index.scss";
 
.custom-botton{
        height: 96rpx;
        background: #214DED;
        box-shadow: 0rpx 6rpx 8rpx 0rpx rgba(4,49,212,0.3);
        border-radius: 16rpx;
        line-height: 96rpx;
    }
</style>