spring
4 天以前 435881d494e2be4ba5ce8bfccb02d6ef49e07314
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<template>
    <view class="wrap">
        <view class="login-back-img"></view>
        <!--国际化-->
        <js-lang title="login.title" :showBtn="false"></js-lang>
        <view
            style="background-color: #fff;z-index:20;width:750rpx;margin-top:514rpx;padding-bottom: 70rpx;border-radius: 20rpx;">
            <view class="logo">欢迎登录</view>
 
            <!--用户名密码登录-->
            <user-password />
 
 
            <view class="chooseServer" @click="chooseServer.visible = true" v-if="env == 'production'">
                服务器地址选择
            </view>
        </view>
        <u-popup v-model="chooseServer.visible" mode="bottom">
            <view class="chooseServer__content">
                <u-radio-group v-model="chooseServer.type" :wrap="true">
                    <u-radio v-for="(item, index) in serverList" :key="item.type" :name="item.type">
                        <view v-if="index < 2">
                            <u-field v-model="item.url" :label="item.name" label-width="70" disabled />
                        </view>
                        <view v-else>
                            <u-field v-model="chooseServer.url" label-width="70" :label="item.name" />
                        </view>
                    </u-radio>
                </u-radio-group>
                <view class="button" hover-class="button-hover" @click="serverSure()">
                    <text>确认</text>
                </view>
            </view>
        </u-popup>
 
        <!-- #ifdef MP -->
        <button class="button" @click.stop="getUserProfile" :disabled="btnLoading" :loading="btnLoading">
            <text>{{ $t("login.vxLoginButton") }}</text>
        </button>
        <!-- #endif -->
        <!-- <view class="login-bottom-box">
            <view class="copyright">
                江苏中天互联科技有限公司版权所有</br>Copyright ©2024.All Rights Reserved.
            </view>
        </view> -->
    </view>
</template>
<script>
import userPassword from "./userPassword";
import config from '@/common/config.js';
 
export default {
    components: {
        userPassword
    },
    data() {
        return {
            env: config.env,
            btnLoading: false,
            chooseServer: {
                visible: false,
                type: 2,
                url: ''
            }
        };
    },
    computed: {
        serverList() {
            return [{
                type: 0,
                name: '内网',
                url: 'http://rfcable.chinaztt.cn'
            }, {
                type: 1,
                name: '外网',
                url: 'http://rfcable.chinaztt.cn:8200'
            }, {
                type: 2,
                name: '其他',
                url: ''
            }]
        }
    },
    onLoad() {
        //已经登录 跳转到首页
        if (this.vuex_token) {
            uni.reLaunch({
                url: "/pages/sys/home/index",
            });
        }
    },
    onShow() {
        if (this.vuex_config.baseUrl === 'http://rfcable.chinaztt.cn') {
            this.chooseServer.type = 0
        } else if (this.vuex_config.baseUrl === 'http://rfcable.chinaztt.cn:8200') {
            this.chooseServer.type = 1
        } else {
            this.chooseServer.type = 2
            this.chooseServer.url = this.vuex_config.baseUrl
        }
    },
    methods: {
        serverSure() {
            let baseUrl = ''
            if (this.chooseServer.type == 0) {
                baseUrl = 'http://rfcable.chinaztt.cn'
            } else if (this.chooseServer.type == 1) {
                baseUrl = 'http://rfcable.chinaztt.cn:8200'
            } else {
                if (this.IsURL(this.chooseServer.url)) {
                    baseUrl = this.chooseServer.url
                } else {
                    this.$u.toast("地址输入不正确");
                    return
                }
            }
            let config = this.vuex_config
            config.baseUrl = baseUrl
            this.$u.vuex("vuex_config", config);
            this.$u.http.setConfig({
                baseUrl
            });
            this.$u.toast("设置成功");
            this.chooseServer.visible = false
        },
        IsURL(str_url) {
            var strRegex = "^((https|http|ftp|rtsp|mms)?://)" +
                "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ 
                +
                "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 
                +
                "|" // 允许IP和DOMAIN(域名)
                +
                "([0-9a-z_!~*'()-]+\.)*" // 域名- www. 
                +
                "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 
                +
                "[a-z]{2,6})" // first level domain- .com or .museum 
                +
                "(:[0-9]{1,4})?" // 端口- :80 
                +
                "((/?)|" // a slash isn't required if there is no file name 
                +
                "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
            var re = new RegExp(strRegex);
            //re.test()
            if (re.test(str_url)) {
                return (true);
            } else {
                return (false);
            }
        },
        getUserProfile() {
            this.btnLoading = true;
            //获取code,然后调用微信登录接口判断是否登录 401则跳转到绑定页面
            var tmp = this;
            uni.login({
                provider: "weixin",
                success: function (res) {
                    console.log("code", res.code);
 
                    let grant_type = "mobile";
                    let code = res.code;
 
                    tmp.$u.api
                        .vxLogin({
                            grant_type,
                            code,
                        }, {
                            Authorization: "Basic c29jaWFsOnNvY2lhbA==",
                        })
                        .then((res) => {
                            tmp.btnLoading = false;
                            //提示
                            tmp.$u.toast("恭喜您,登录成功!");
 
                            // 登陆成功,存储相关信息
                            tmp.$u.vuex("vuex_token", res.access_token);
                            tmp.$u.vuex("vuex_refresh_token", res.refresh_token);
                            tmp.$u.vuex("vuex_username", res.username);
                            tmp.$u.vuex("vuex_userId", res.user_id);
                            tmp.$u.vuex("vuex_client_id", res.client_id);
 
                            //查询用户详细信息并储存
                            tmp.$u.api.user.getUserInfo().then((res) => {
                                console.log("获取用户信息:", res);
                                tmp.$u.vuex("vuex_user", res.data.sysUser);
                            });
 
                            //跳转页面
                            setTimeout(() => {
                                uni.reLaunch({
                                    url: "/pages/sys/home/index",
                                });
                            }, 500);
                        })
                        .catch((e) => {
                            tmp.btnLoading = false;
                            if (e.statusCode === 401 || e.message === "用户不存在") {
                                console.log(
                                    "用户未绑定,请使用 sys_user 表存在的手机号进行绑定"
                                );
                                tmp.$u.toast(
                                    "用户未绑定,请使用 sys_user 表存在的手机号进行绑定"
                                );
                                uni.reLaunch({
                                    url: "/pages/sys/login/bindUser",
                                });
                                console.log("页面跳转...");
                            }
                        });
                },
            });
        },
    },
};
</script>
<style lang="scss">
@import "index.scss";
 
.login-back-img {
    background-image: url('~@/static/custom/login/img_bg.png');
    background-size: 100% auto;
    background-repeat: no-repeat;
    position: absolute;
    left: 0;
    top: 0;
    width: 750rpx;
    height: 540rpx;
}
 
 
.logo {
    width: 90%;
    font-size: 48rpx;
    color: #333333;
    margin: 50rpx auto 0;
    margin-left: 80rpx;
    text-align: left;
    font-weight: bold;
}
 
.list-call-icon {
    color: #ff0000;
}
 
.currentPhone-box {
    text-align: center;
    padding: 40rpx 80rpx;
 
    .number-text {
        color: #000000;
        font-size: 60rpx;
    }
 
    .other-text {
        color: #999999;
        font-size: 26rpx;
        padding: 20rpx 0;
    }
 
    .u-btn {
        margin: 30rpx auto;
    }
 
    .u-hairline-border {
        border: 1px solid #fff;
    }
}
 
 
 
.register {
    display: inline-block;
    color: #497bff;
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    float: right;
    margin-top: 6rpx;
}
 
.register-link {
    float: right;
    padding: 0 16rpx;
}
 
.reg-link {
    display: inline-block;
    color: #497bff;
}
 
.oauth2 {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    margin: 0rpx 100rpx 30rpx;
 
    image {
        height: 80rpx;
        width: 80rpx;
    }
}
 
.u-tabs {
    padding: 0 70rpx;
}
 
.chooseServer {
    margin: 20px 35px 20px 35px;
    text-align: right;
    text-decoration: underline;
}
 
.chooseServer__content {
    padding: 20rpx 40rpx;
 
    ::v-deep .u-radio__label {
        flex: 1;
    }
}
</style>