lin
2026-03-30 5f21d92871e0d48309b44549d4e09a8afd2b4980
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
<template>
    <view>
        <view class="login-title">
            <view class="login-title-1">手机号登录</view>
            <view class="login-title-2">未注册的手机号将自动注册</view>
        </view>
        <view class="login-type">
            <view class="login-type-v">
                <view :class="formData.loginType == 1 ? 'active' : ''" @tap="loginTypeClick(1)">账号密码登录</view>
                <view :class="formData.loginType == 2 ? 'active' : ''" @tap="loginTypeClick(2)">短信登录</view>
            </view>
        </view>
        <view class="login-list">
            <view class="login-item">
                <input type="tel" v-model="formData.phone" placeholder="请输入手机号" />
            </view>
            <view class="login-item" v-if="formData.loginType == 1">
                <input type="password" v-model="formData.pass" placeholder="请输入密码" />
            </view>
            <view class="login-item" v-if="formData.loginType == 2">
                <input type="tel" v-model="formData.code" maxlength="4" placeholder="请输入验证码" />
                <text class="code2" v-if="leftTime < 60">{{leftTime}}S后获取</text>
                <text class="code" @click="sendCode" v-else>获取验证码</text>
            </view>
        </view>
        <view class="loginBtn">
            <view class="loginBtn-desc">
                <image @click="agreeClick" class="loginBtn-icon" :src="!loginAct ? '/static/imgs/check.png' : '/static/imgs/checked.png'" ></image>
                <text>我已阅读并同意</text>
                <text class="blue" @tap="agreeDialog1">《注册协议》</text>
                <text class="blue" @tap="agreeDialog2">《隐私政策》</text>
            </view>
            <view :class="loginAct ? 'login-btn active' : 'login-btn'" @click="loginUser">登录</view>
            <view class="loginDesc">
                <view class="fl" @tap="$util.goPages('/pages/regist/regist')">注册账号</view>
                <view class="fr" @tap="$util.goPages('/pages/findpass/findpass')">忘记密码</view>
            </view>
        </view>
        <agreePup ref="agreePup1" :gp="1" title="注册协议"></agreePup>
        <agreePup ref="agreePup2" :gp="2" title="隐私政策"></agreePup>
    </view>
</template>
 
<script>
    import agreePup from "@/components/agreePup/agreePup";
    export default {
        components: {
            agreePup,
        },
        data() {
            return {
                loginAct: false,
                formData: {
                    phone: '',
                    code: '',
                    pass: '',
                    loginType: 1,
                },
                phoneReg: /^\d{11}$/,
                backUrl: '',
                leftTime: 60,
            }
        },
        onLoad(op) {
            this.backUrl = op.backUrl ? op.backUrl : ''
        },
        methods: {
            agreeDialog1 (e) {
                this.$refs.agreePup1.dialog = !this.$refs.agreePup1.dialog
            },
            agreeDialog2 (e) {
                this.$refs.agreePup2.dialog = !this.$refs.agreePup2.dialog
            },
            loginTypeClick (e) {
                this.formData.loginType = e
            },
            agreeClick () {
                this.loginAct = !this.loginAct
            },
      async loginUser() {
        let t = this
 
        if (!t.loginAct) {
          return uni.showToast({
            title: '请阅读并同意协议政策',
            icon: 'error'
          })
        }
 
        if (t.formData.phone == '' || !t.phoneReg.test(t.formData.phone)) {
          return uni.showToast({
            title: '手机号错误!',
            icon: 'error'
          })
        }
 
        if (t.formData.pass == '' && t.formData.loginType == 1) {
          return uni.showToast({
            title: '请输入密码!',
            icon: 'error'
          })
        }
 
        if (t.formData.code == '' && t.formData.loginType == 2) {
          return uni.showToast({
            title: '请输入验证码!',
            icon: 'error'
          })
        }
 
        try {
 
          // 登录接口
          const res = await t.$util.post('User/Login', this.formData)
 
          if (res.code == 1) {
 
            uni.setStorageSync('lzsc-token', res.data.userToken)
            uni.setStorageSync('user-info', JSON.stringify(res.data))
 
            let isSwitch = 0
            let goUrl = ''
 
            // qxgLogin接口
            const ygxRes = await new Promise((resolve, reject) => {
              uni.request({
                url: t.$webHost + '/api/v2/auth/qxgIosUnionLogin?phone=' + t.$util.getUserInfo().phone,
                success: resolve,
                fail: reject
              })
            })
            console.log(ygxRes);
            if(!ygxRes.data.data.boughtEquity){
              goUrl = '/pages/quanyi/index'
              t.$util.goPages(goUrl)
              return
            }
 
            t.qxgLogin = ygxRes.data.data
            uni.setStorageSync('qxgLogin', t.qxgLogin)
 
            if (this.backUrl == '') {
              isSwitch = 1
              goUrl = '/pages/index/index'
            } else {
              goUrl = this.backUrl
            }
 
            uni.showToast({
              title: res.msg || '登录成功'
            })
 
            setTimeout(() => {
              if (isSwitch == 1) {
                t.$util.goSwitch(goUrl)
              } else {
                t.$util.goPages(goUrl)
              }
            }, 1500)
 
          } else {
            uni.showToast({
              title: res.msg || '登录失败',
              icon: 'error'
            })
          }
 
        } catch (err) {
          console.error(err)
 
          uni.showToast({
            title: '请求失败',
            icon: 'error'
          })
        }
      },
            sendCode () {
                let t = this
                if(this.formData.phone == '' || !this.phoneReg.test(t.formData.phone)){
                    return uni.showToast({
                        title: '手机号错误!',
                        icon: 'error',
                    })
                }
                if (this.leftTime < 60) {
                    return false
                }
                this.$util.post('Sms/sendVerificationCode', {phone: this.formData.phone}).then(res => {
                    console.log(res)
                    if(res.code == 1){
                        t.countDown()
                        uni.showToast({
                            title:'发送成功',
                            icon:'none'
                        })
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none',
                        })
                    }
                })
            },
            countDown() {
                this.leftTime--
                if (this.leftTime > 0) {
                    setTimeout(this.countDown, 1000)
                } else {
                    this.leftTime = 60
                }
            },
        }
    }
</script>
 
<style>
    @import url(/static/css/login.css);
</style>