yangan
2024-09-02 c311ab706cfc3934e03c875211a41082acff575a
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
<template>
    <view class="main">
        <view class="list">
            <view class="list-call">
                <u--input v-model="username"
                    clearable
                    maxlength="32"
                    type="text"
                    placeholder="请输入手机号"
                    prefixIcon="account"
                    prefixIconStyle="font-size: 22px;color: #909399"></u--input>
            </view>
            <view class="list-call">
                <u--input v-model="password"
                    clearable
                    maxlength="32"
                    type="password"
                    placeholder="请输入密码"
                    prefixIcon="lock"
                    prefixIconStyle="font-size: 22px;color: #909399"></u--input>
            </view>
        </view>
        <view class="loginBtn"><u-button type="primary"
                text="确认"
                @click="submit()"
                :loading="submitLoading"></u-button></view>
    </view>
</template>
 
<script>
    import { BaseUrl } from '@/api/publicInterface.js'
    export default {
        data() {
            return {
                username: '',
                password: '',
                code: '',
                submitLoading: false
            };
        },
        methods: {
            submit() {
                if (this.username.length === 0) {
                    return this.$u.toast('请输入手机号')
                }
                if (this.password.length === 0) {
                    return this.$u.toast('请输入密码')
                }
                this.setUpWxOpenid(this.username, this.password, uni.getStorageSync('bindCode'))
            },
            getUserAuth() {
                wx.getSetting({
                    withSubscriptions: true,
                    success(res) {
                        if (res.subscriptionsSetting == null || res.subscriptionsSetting == undefined ||
                            res.subscriptionsSetting.itemSettings == null || res.subscriptionsSetting
                            .itemSettings == undefined || res.subscriptionsSetting[
                                "bvDqcHRRKEewTz7XVrdwUbrF6ZewSRmiUIB1V_IBJq4"] != 'accept') {
                            wx.requestSubscribeMessage({
                                tmplIds: ['bvDqcHRRKEewTz7XVrdwUbrF6ZewSRmiUIB1V_IBJq4'],
                                success(res) {
                                    console.log(res, '获取订阅消息');
                                },
                                fail(e) {
                                    console.log(e, '订阅消息失败');
                                }
                            })
                        }
                    }
                })
            },
            setUpWxOpenid(userName, passWord, code) {
                this.submitLoading = true
                uni.request({
                    url: `${BaseUrl}/admin/user/setUpWxOpenid`,
                    data: {
                        userName,
                        passWord,
                        code
                    },
                    method: 'POST',
                    header: {
                        'content-type': 'application/x-www-form-urlencoded'
                    },
                    success: (res) => {
                        console.log(res, '绑定结果');
                        if (res.data.code === 1) {
                            this.$u.toast(res.data.msg ? res.data.msg : '绑定失败')
                            this.submitLoading = false
                        } else {
                            this.$u.toast('操作成功')
                            this.submitLoading = false
                        }
                    }
                })
            },
            onShow() {
                uni.login({
                    success(res) {
                        if (res.code) {
                            console.log(res.code, '获取code');
                            this.code = res.code
                            uni.setStorageSync('bindCode', this.code)
                        } else {
                            uni.showToast({
                                title: '出现错误',
                                duration: 2000
                            });
                        }
                    }
                })
            },
        }
    }
</script>
 
<style lang="scss"
    scoped>
    @import 'index.scss';
 
    .main {
        width: 100%;
        height: 100%;
        margin: 0 auto;
    }
 
    .loginBtn {
        width: 80%;
        margin: 0 auto;
    }
</style>