Commit 40e6e54906adf02ba34e353a3cea12d2342a5788

Authored by sqy
1 parent 061a9133

fix:微信登录可以退出

Showing 1 changed file with 425 additions and 425 deletions
1   -<template>
2   - <view class="personal">
3   - <!-- 公共组件-每个页面必须引入 -->
4   - <public-module></public-module>
5   - <view class="headBox">
6   - <!-- #ifdef MP || APP-PLUS -->
7   - <!-- 登录 -->
8   - <view class="u-flex u-p-l-30 u-p-r-20 u-p-t-75 u-p-b-30">
9   - <block v-if="userInfo.isToken || userInfo.isThirdLogin">
10   - <view @click.top="openPersonalInfo" class="u-m-r-20">
11   - <image class="avatar" mode="aspectFill" :src="!userInfo.avatar ? '../../static/logo.png' : userInfo.avatar || thirdObj.avatarUrl"></image>
12   - </view>
13   - <view class="u-flex-1" @click.top="openPersonalInfo">
14   - <view class="nickName u-flex">
15   - <view class="name u-m-r-10" v-if="userInfo.realName || userInfo.nickName">
16   - <text style="#FFFFFF;font-size: 18px;">{{ userInfo.realName || userInfo.nickName }}</text>
17   - </view>
18   - <view v-if="userInfo.isThirdLogin" @click.stop="clickAccountFunc" class="detail"><text class="text">绑定账号</text></view>
19   - </view>
20   - <view style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
21   - </view>
22   - </block>
23   - <block v-else>
24   - <view class="u-m-r-20" @click="openLoginFunc">
25   - <view class="avatar u-flex"><image class="avatar" mode="aspectFill" src="../../static/logo.png"></image></view>
26   - </view>
27   - <view class="u-flex-1"><view @click="openLoginFunc" class="u-font-lg click-login login-btn ">请点击登录</view></view>
28   - </block>
29   - <view v-if="userInfo.isToken" @click="openPersonalInfo"><u-icon name="arrow-right" color="white" size="13"></u-icon></view>
30   - </view>
31   - <!-- 登录 -->
32   - <!-- #endif -->
33   - </view>
34   - <view class="u-flex my-nav">
35   - <view class="nav-main">
36   - <view @click="onTokenJump('/sysNotifySubPage/sysNotifyPage/systemNotify')" class="u-flex nav-link">
37   - <view class="nav-image"><image class="image" src="../../static/sys-not.png"></image></view>
38   - <view class="nav-center"><text class="text">系统通知</text></view>
39   - <view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
40   - </view>
41   - <view @click="onTokenJump('/feedBackSubPage/feedback/feedback')" class="u-flex nav-link">
42   - <view class="nav-image"><image class="image" src="../../static/find-sugg.png"></image></view>
43   - <view class="nav-center"><text class="text">意见反馈</text></view>
44   - <view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
45   - </view>
46   - </view>
47   - <view @click="onLoginoutFunc" v-if="userInfo.isToken" class="u-flex" style="justify-content: center; width: 600rpx">
48   - <button class="submit" size="default" @click="onLoginoutFunc"><text class="text">退出账号</text></button>
49   - </view>
50   - </view>
51   - <!-- 绑定账号 -->
52   - <view>
53   - <u-modal :showConfirmButton="false" :show="show" :title="title">
54   - <view v-if="!bindPhone" class="loginPhone">
55   - <view class="form-row">
56   - <u--input shape="circle" class="input" prefixIcon="account-fill" type="text" placeholder="登录账号" v-model="bindAccountObj.appUserKey"></u--input>
57   - </view>
58   - <view class="form-row item-bind">
59   - <u--input
60   - class="input"
61   - shape="circle"
62   - prefixIcon="lock-fill"
63   - suffixIconStyle="color: #909399"
64   - type="password"
65   - placeholder="登录密码"
66   - v-model="bindAccountObj.appUserSecret"
67   - ></u--input>
68   - </view>
69   - <view class="u-flex item-phone">
70   - <view class="phone-hide">手机验证码登录</view>
71   - <view class="bind-phone-text" @click="bindPhoneFunc">手机绑定</view>
72   - </view>
73   - </view>
74   - <view v-else class="loginPhone">
75   - <view class="form-row">
76   - <u--input
77   - shape="circle"
78   - class="input"
79   - type="text"
80   - v-model="bindPhoneObj.appUserKey"
81   - placeholder="请输入手机号码"
82   - placeholder-style="font-weight:normal;color:#bbbbbb;"
83   - ></u--input>
84   - </view>
85   - <view class="form-row row-top">
86   - <u--input
87   - shape="circle"
88   - class="input"
89   - type="text"
90   - v-model="bindPhoneObj.appUserSecret"
91   - placeholder="请输入验证码"
92   - placeholder-style="font-weight:normal;color:#bbbbbb;"
93   - ></u--input>
94   - <view style="color: #377dff" class="getvcode" :class="{ forhidden: readonly }" @click="getVcode">{{ codeText }}</view>
95   - </view>
96   - <view class="u-flex item-phone">
97   - <view class="phone-hide">手机验证码登录</view>
98   - <view class="bind-phone-text" @click="bindAccountFunc">账号绑定</view>
99   - </view>
100   - </view>
101   - <view class="bottom-content">
102   - <view class="u-flex content">
103   - <view class="cancel"><u-button @click="show = false" type="info" shape="circle" text="取消"></u-button></view>
104   - <view class="confrim"><u-button @click="bindConfirm" type="primary" shape="circle" text="确认"></u-button></view>
105   - </view>
106   - </view>
107   - </u-modal>
108   - </view>
109   - <!-- 退出登录 -->
110   - <view>
111   - <u-popup bgColor="transparent" :overlay="true" :show="showLogout" mode="bottom">
112   - <view class="u-flex logout-main">
113   - <view class="main"><text style="color: #999999">确定要退出当前账号?</text></view>
114   - <view @click.top="logoutBtn" class="main"><text style="color: #f95e5a">退出登录</text></view>
115   - <view class="main1"><text @click.top="closeLogout" style="color: #3478f7">取消</text></view>
116   - </view>
117   - </u-popup>
118   - </view>
119   - <!-- 退出登录 -->
120   - <f-tabbar></f-tabbar>
121   - </view>
122   -</template>
123   -
124   -<script>
125   -var clear;
126   -import base from '@/config/baseUrl';
127   -import fTabbar from '@/components/module/f-tabbar/f-tabbar';
128   -import fNavbar from '@/components/module/f-navbar/f-navbar';
129   -import { mapState, mapMutations } from 'vuex';
130   -import { appId } from '@/config/constant.js';
131   -
132   -export default {
133   - components: {
134   - fTabbar,
135   - fNavbar
136   - },
137   - data() {
138   - return {
139   - PrimaryColor: '#0079fe', //主题色
140   - showLogout: false,
141   - readonly: false,
142   - codeText: '获取验证码',
143   - tips: '验证码',
144   - bindPhone: false,
145   - show: false,
146   - title: '绑定账号',
147   - systemInfo: base.systemInfo,
148   - PrimaryButtonColor: '#0079fe', //主题色
149   - bindAccountObj: {
150   - appUserKey: '',
151   - appUserSecret: ''
152   - },
153   - bindPhoneObj: {
154   - appUserKey: '',
155   - appUserSecret: ''
156   - },
157   - thirdObj: {},
158   - getOpenId: ''
159   - };
160   - },
161   - onLoad(e) {
162   - // 隐藏原生的tabbar
163   - uni.hideTabBar();
164   - // if (e.obj != null) {
165   - // const params = JSON.parse(decodeURIComponent(e.obj));
166   - // // uni.$u.toast('eee', params.avatarUrl);
167   - // this.thirdObj = params;
168   - // }
169   - this.getOpenId = getApp().globalData.openId;
170   - },
171   - computed: {
172   - ...mapState(['userInfo'])
173   - },
174   - methods: {
175   - ...mapMutations(['emptyUserInfo', 'setUserInfo']),
176   - // 跳转前判断登录
177   - onTokenJump(url) {
178   - this.judgeLogin(() => {
179   - uni.navigateTo({
180   - url: url
181   - });
182   - });
183   - },
184   - onJump(url) {
185   - uni.navigateTo({
186   - url: url
187   - });
188   - },
189   - openLoginFunc() {
190   - uni.navigateTo({
191   - url: '/publicLoginSubPage/public/login'
192   - });
193   - },
194   - openPersonalInfo() {
195   - let obj = {
196   - data: this.userInfo,
197   - third: this.thirdObj
198   - };
199   - uni.navigateTo({
200   - url: '/publicLoginSubPage/other/set?data=' + JSON.stringify(obj)
201   - });
202   - },
203   - clickAccountFunc() {
204   - this.show = true;
205   - this.resetFunc();
206   - },
207   - resetFunc() {
208   - this.bindPhone = false;
209   - this.bindAccountObj = {};
210   - this.bindPhoneObj = {};
211   - },
212   - bindConfirm() {
213   - //需要绑定
214   - if (!this.bindPhone) {
215   - if (this.bindAccountObj.appUserKey == '') {
216   - return uni.$u.toast('请输入登录账号~');
217   - }
218   - const passReg = /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$/;
219   - if (this.bindAccountObj.appUserSecret == '') {
220   - uni.showToast({
221   - title: '请输入登录密码~',
222   - icon: 'none'
223   - });
224   - return;
225   - } else if (!passReg.test(this.bindAccountObj.appUserSecret)) {
226   - uni.showToast({
227   - title: '密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~',
228   - icon: 'none',
229   - duration: 3000
230   - });
231   - return;
232   - }
233   - const postData = {
234   - loginMethod: 'ACCOUNT',
235   - ...this.bindAccountObj,
236   - platformName: 'WECHAT',
237   - thirdUserId: this.getOpenId
238   - };
239   - uni.$u.http
240   - .post('/yt/third/bind', postData)
241   - .then(res => {
242   - if (res) {
243   - this.show = false;
244   - // 储存登录信息
245   - let resObj = {
246   - refreshToken: res.refreshToken,
247   - isToken: res.token
248   - };
249   - let userInfo = {
250   - ...resObj,
251   - token: true, //token用于判断是否登录
252   - isThirdLogin: false,
253   - isThirdLoginAndNoDind: true
254   - };
255   - if (userInfo.token) {
256   - this.setUserInfo(userInfo);
257   - }
258   - uni.showToast({
259   - title: '账号绑定成功~',
260   - icon: 'none'
261   - });
262   - this.saveUserInfo();
263   - }
264   - })
265   - .catch(e => {
266   - uni.$u.toast(e.data?.msg);
267   - this.show = true;
268   - });
269   - } else {
270   - const phoneRegular = /^1\d{10}$/;
271   - if (this.bindPhoneObj.appUserKey == '') {
272   - uni.showToast({
273   - title: '请输入手机号码~',
274   - icon: 'none'
275   - });
276   - return;
277   - } else if (!phoneRegular.test(this.bindPhoneObj.appUserKey)) {
278   - uni.showToast({
279   - title: '手机号格式不正确~',
280   - icon: 'none'
281   - });
282   - return;
283   - }
284   - if (this.bindPhoneObj.appUserSecret == '') {
285   - uni.showToast({
286   - title: '请输入验证码~',
287   - icon: 'none'
288   - });
289   - return;
290   - } else if (!/^\d{6}$/.test(this.bindPhoneObj.appUserSecret)) {
291   - uni.showToast({
292   - title: '验证码格式不正确~',
293   - icon: 'none'
294   - });
295   - return;
296   - }
297   - const postData = {
298   - loginMethod: 'PHONE',
299   - ...this.bindPhoneObj,
300   - platformName: 'WECHAT',
301   - thirdUserId: this.getOpenId
302   - };
303   - uni.$u.http
304   - .post('/yt/third/bind', postData)
305   - .then(res => {
306   - this.show = false;
307   - // 储存登录信息
308   - let resObj = {
309   - refreshToken: res.refreshToken,
310   - isToken: res.token
311   - };
312   - let userInfo = {
313   - ...resObj,
314   - token: true, //token用于判断是否登录
315   - isThirdLogin: false,
316   - isThirdLoginAndNoDind: true
317   - };
318   - if (userInfo.token) {
319   - this.setUserInfo(userInfo);
320   - }
321   - uni.showToast({
322   - title: '手机绑定成功~',
323   - icon: 'none'
324   - });
325   - this.saveUserInfo();
326   - })
327   - .catch(e => {
328   - uni.$u.toast(e.data?.msg);
329   - this.show = true;
330   - });
331   - }
332   - },
333   - saveUserInfo() {
334   - //储存个人信息
335   - uni.$u.http.get('/yt/user/me/info').then(res => {
336   - if (res) {
337   - this.setUserInfo(res);
338   - }
339   - });
340   - },
341   - bindPhoneFunc() {
342   - this.bindPhone = true;
343   - },
344   - bindAccountFunc() {
345   - this.bindPhone = false;
346   - },
347   - //验证码按钮文字状态
348   - getCodeState() {
349   - const _this = this;
350   - this.readonly = true;
351   - this.codeText = '60S后重新获取';
352   - var s = 60;
353   - clear = setInterval(() => {
354   - s--;
355   - _this.codeText = s + 'S后重新获取';
356   - if (s <= 0) {
357   - clearInterval(clear);
358   - _this.codeText = '获取验证码';
359   - _this.readonly = false;
360   - }
361   - }, 1000);
362   - },
363   - //获取验证码
364   - getVcode() {
365   - if (this.readonly) {
366   - uni.showToast({
367   - title: '验证码已发送~',
368   - icon: 'none'
369   - });
370   - return;
371   - }
372   - if (this.bindPhoneObj.appUserKey == '') {
373   - uni.showToast({
374   - title: '请输入手机号~',
375   - icon: 'none'
376   - });
377   - return;
378   - }
379   - const phoneRegular = /^1\d{10}$/;
380   - if (!phoneRegular.test(this.bindPhoneObj.appUserKey)) {
381   - uni.showToast({
382   - title: '手机号格式不正确~',
383   - icon: 'none'
384   - });
385   - return;
386   - }
387   - let httpData = {};
388   - // 获取验证码接口
389   - uni.$u.http.post(`/yt/noauth/sendLoginSmsCode/${this.bindPhoneObj.appUserKey}`).then(res => {
390   - if (res) {
391   - this.getCodeState(); //开始倒计时
392   - }
393   - });
394   - },
395   - onLoginoutFunc() {
396   - this.showLogout = true;
397   - },
398   - closeLogout() {
399   - this.showLogout = false;
400   - },
401   - logoutBtn() {
402   - let that = this;
403   - uni.showModal({
404   - title: '退出登录',
405   - content: '你确定退出登录吗?',
406   - success(res) {
407   - if (res.confirm) {
408   - that.emptyUserInfo();
409   - that.showLogout = false;
410   - setTimeout(() => {
411   - uni.navigateTo({
412   - url: '/publicLoginSubPage/public/login'
413   - });
414   - }, 500);
415   - } else if (res.cancel) {
416   - }
417   - }
418   - });
419   - }
420   - }
421   -};
422   -</script>
423   -
424   -<style lang="scss" scoped>
425   -@import './static/personal.scss';
  1 +<template>
  2 + <view class="personal">
  3 + <!-- 公共组件-每个页面必须引入 -->
  4 + <public-module></public-module>
  5 + <view class="headBox">
  6 + <!-- #ifdef MP || APP-PLUS -->
  7 + <!-- 登录 -->
  8 + <view class="u-flex u-p-l-30 u-p-r-20 u-p-t-75 u-p-b-30">
  9 + <block v-if="userInfo.isToken || userInfo.isThirdLogin">
  10 + <view @click.top="openPersonalInfo" class="u-m-r-20">
  11 + <image class="avatar" mode="aspectFill" :src="!userInfo.avatar ? '../../static/logo.png' : userInfo.avatar || thirdObj.avatarUrl"></image>
  12 + </view>
  13 + <view class="u-flex-1" @click.top="openPersonalInfo">
  14 + <view class="nickName u-flex">
  15 + <view class="name u-m-r-10" v-if="userInfo.realName || userInfo.nickName">
  16 + <text style="#FFFFFF;font-size: 18px;">{{ userInfo.realName || userInfo.nickName }}</text>
  17 + </view>
  18 + <view v-if="userInfo.isThirdLogin" @click.stop="clickAccountFunc" class="detail"><text class="text">绑定账号</text></view>
  19 + </view>
  20 + <view style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
  21 + </view>
  22 + </block>
  23 + <block v-else>
  24 + <view class="u-m-r-20" @click="openLoginFunc">
  25 + <view class="avatar u-flex"><image class="avatar" mode="aspectFill" src="../../static/logo.png"></image></view>
  26 + </view>
  27 + <view class="u-flex-1"><view @click="openLoginFunc" class="u-font-lg click-login login-btn ">请点击登录</view></view>
  28 + </block>
  29 + <view v-if="userInfo.isToken" @click="openPersonalInfo"><u-icon name="arrow-right" color="white" size="13"></u-icon></view>
  30 + </view>
  31 + <!-- 登录 -->
  32 + <!-- #endif -->
  33 + </view>
  34 + <view class="u-flex my-nav">
  35 + <view class="nav-main">
  36 + <view @click="onTokenJump('/sysNotifySubPage/sysNotifyPage/systemNotify')" class="u-flex nav-link">
  37 + <view class="nav-image"><image class="image" src="../../static/sys-not.png"></image></view>
  38 + <view class="nav-center"><text class="text">系统通知</text></view>
  39 + <view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
  40 + </view>
  41 + <view @click="onTokenJump('/feedBackSubPage/feedback/feedback')" class="u-flex nav-link">
  42 + <view class="nav-image"><image class="image" src="../../static/find-sugg.png"></image></view>
  43 + <view class="nav-center"><text class="text">意见反馈</text></view>
  44 + <view class="nav-right"><image class="image" src="../../static/arrow-right.png"></image></view>
  45 + </view>
  46 + </view>
  47 + <view @click="onLoginoutFunc" class="u-flex" style="justify-content: center; width: 600rpx">
  48 + <button class="submit" size="default" @click="onLoginoutFunc"><text class="text">退出账号</text></button>
  49 + </view>
  50 + </view>
  51 + <!-- 绑定账号 -->
  52 + <view>
  53 + <u-modal :showConfirmButton="false" :show="show" :title="title">
  54 + <view v-if="!bindPhone" class="loginPhone">
  55 + <view class="form-row">
  56 + <u--input shape="circle" class="input" prefixIcon="account-fill" type="text" placeholder="登录账号" v-model="bindAccountObj.appUserKey"></u--input>
  57 + </view>
  58 + <view class="form-row item-bind">
  59 + <u--input
  60 + class="input"
  61 + shape="circle"
  62 + prefixIcon="lock-fill"
  63 + suffixIconStyle="color: #909399"
  64 + type="password"
  65 + placeholder="登录密码"
  66 + v-model="bindAccountObj.appUserSecret"
  67 + ></u--input>
  68 + </view>
  69 + <view class="u-flex item-phone">
  70 + <view class="phone-hide">手机验证码登录</view>
  71 + <view class="bind-phone-text" @click="bindPhoneFunc">手机绑定</view>
  72 + </view>
  73 + </view>
  74 + <view v-else class="loginPhone">
  75 + <view class="form-row">
  76 + <u--input
  77 + shape="circle"
  78 + class="input"
  79 + type="text"
  80 + v-model="bindPhoneObj.appUserKey"
  81 + placeholder="请输入手机号码"
  82 + placeholder-style="font-weight:normal;color:#bbbbbb;"
  83 + ></u--input>
  84 + </view>
  85 + <view class="form-row row-top">
  86 + <u--input
  87 + shape="circle"
  88 + class="input"
  89 + type="text"
  90 + v-model="bindPhoneObj.appUserSecret"
  91 + placeholder="请输入验证码"
  92 + placeholder-style="font-weight:normal;color:#bbbbbb;"
  93 + ></u--input>
  94 + <view style="color: #377dff" class="getvcode" :class="{ forhidden: readonly }" @click="getVcode">{{ codeText }}</view>
  95 + </view>
  96 + <view class="u-flex item-phone">
  97 + <view class="phone-hide">手机验证码登录</view>
  98 + <view class="bind-phone-text" @click="bindAccountFunc">账号绑定</view>
  99 + </view>
  100 + </view>
  101 + <view class="bottom-content">
  102 + <view class="u-flex content">
  103 + <view class="cancel"><u-button @click="show = false" type="info" shape="circle" text="取消"></u-button></view>
  104 + <view class="confrim"><u-button @click="bindConfirm" type="primary" shape="circle" text="确认"></u-button></view>
  105 + </view>
  106 + </view>
  107 + </u-modal>
  108 + </view>
  109 + <!-- 退出登录 -->
  110 + <view>
  111 + <u-popup bgColor="transparent" :overlay="true" :show="showLogout" mode="bottom">
  112 + <view class="u-flex logout-main">
  113 + <view class="main"><text style="color: #999999">确定要退出当前账号?</text></view>
  114 + <view @click.top="logoutBtn" class="main"><text style="color: #f95e5a">退出登录</text></view>
  115 + <view class="main1"><text @click.top="closeLogout" style="color: #3478f7">取消</text></view>
  116 + </view>
  117 + </u-popup>
  118 + </view>
  119 + <!-- 退出登录 -->
  120 + <f-tabbar></f-tabbar>
  121 + </view>
  122 +</template>
  123 +
  124 +<script>
  125 +var clear;
  126 +import base from '@/config/baseUrl';
  127 +import fTabbar from '@/components/module/f-tabbar/f-tabbar';
  128 +import fNavbar from '@/components/module/f-navbar/f-navbar';
  129 +import { mapState, mapMutations } from 'vuex';
  130 +import { appId } from '@/config/constant.js';
  131 +
  132 +export default {
  133 + components: {
  134 + fTabbar,
  135 + fNavbar
  136 + },
  137 + data() {
  138 + return {
  139 + PrimaryColor: '#0079fe', //主题色
  140 + showLogout: false,
  141 + readonly: false,
  142 + codeText: '获取验证码',
  143 + tips: '验证码',
  144 + bindPhone: false,
  145 + show: false,
  146 + title: '绑定账号',
  147 + systemInfo: base.systemInfo,
  148 + PrimaryButtonColor: '#0079fe', //主题色
  149 + bindAccountObj: {
  150 + appUserKey: '',
  151 + appUserSecret: ''
  152 + },
  153 + bindPhoneObj: {
  154 + appUserKey: '',
  155 + appUserSecret: ''
  156 + },
  157 + thirdObj: {},
  158 + getOpenId: ''
  159 + };
  160 + },
  161 + onLoad(e) {
  162 + // 隐藏原生的tabbar
  163 + uni.hideTabBar();
  164 + // if (e.obj != null) {
  165 + // const params = JSON.parse(decodeURIComponent(e.obj));
  166 + // // uni.$u.toast('eee', params.avatarUrl);
  167 + // this.thirdObj = params;
  168 + // }
  169 + this.getOpenId = getApp().globalData.openId;
  170 + },
  171 + computed: {
  172 + ...mapState(['userInfo'])
  173 + },
  174 + methods: {
  175 + ...mapMutations(['emptyUserInfo', 'setUserInfo']),
  176 + // 跳转前判断登录
  177 + onTokenJump(url) {
  178 + this.judgeLogin(() => {
  179 + uni.navigateTo({
  180 + url: url
  181 + });
  182 + });
  183 + },
  184 + onJump(url) {
  185 + uni.navigateTo({
  186 + url: url
  187 + });
  188 + },
  189 + openLoginFunc() {
  190 + uni.navigateTo({
  191 + url: '/publicLoginSubPage/public/login'
  192 + });
  193 + },
  194 + openPersonalInfo() {
  195 + let obj = {
  196 + data: this.userInfo,
  197 + third: this.thirdObj
  198 + };
  199 + uni.navigateTo({
  200 + url: '/publicLoginSubPage/other/set?data=' + JSON.stringify(obj)
  201 + });
  202 + },
  203 + clickAccountFunc() {
  204 + this.show = true;
  205 + this.resetFunc();
  206 + },
  207 + resetFunc() {
  208 + this.bindPhone = false;
  209 + this.bindAccountObj = {};
  210 + this.bindPhoneObj = {};
  211 + },
  212 + bindConfirm() {
  213 + //需要绑定
  214 + if (!this.bindPhone) {
  215 + if (this.bindAccountObj.appUserKey == '') {
  216 + return uni.$u.toast('请输入登录账号~');
  217 + }
  218 + const passReg = /^(?=.*?[A-Z])(?=(.*[a-z]){1,})(?=(.*[\d]){1,})(?=(.*[\W]){1,})(?!.*\s).{8,}$/;
  219 + if (this.bindAccountObj.appUserSecret == '') {
  220 + uni.showToast({
  221 + title: '请输入登录密码~',
  222 + icon: 'none'
  223 + });
  224 + return;
  225 + } else if (!passReg.test(this.bindAccountObj.appUserSecret)) {
  226 + uni.showToast({
  227 + title: '密码格式不正确(至少一个大写英文字母、至少一个小写英文字母、至少一位数字、至少一个特殊字符、最少八个字符)~',
  228 + icon: 'none',
  229 + duration: 3000
  230 + });
  231 + return;
  232 + }
  233 + const postData = {
  234 + loginMethod: 'ACCOUNT',
  235 + ...this.bindAccountObj,
  236 + platformName: 'WECHAT',
  237 + thirdUserId: this.getOpenId
  238 + };
  239 + uni.$u.http
  240 + .post('/yt/third/bind', postData)
  241 + .then(res => {
  242 + if (res) {
  243 + this.show = false;
  244 + // 储存登录信息
  245 + let resObj = {
  246 + refreshToken: res.refreshToken,
  247 + isToken: res.token
  248 + };
  249 + let userInfo = {
  250 + ...resObj,
  251 + token: true, //token用于判断是否登录
  252 + isThirdLogin: false,
  253 + isThirdLoginAndNoDind: true
  254 + };
  255 + if (userInfo.token) {
  256 + this.setUserInfo(userInfo);
  257 + }
  258 + uni.showToast({
  259 + title: '账号绑定成功~',
  260 + icon: 'none'
  261 + });
  262 + this.saveUserInfo();
  263 + }
  264 + })
  265 + .catch(e => {
  266 + uni.$u.toast(e.data?.msg);
  267 + this.show = true;
  268 + });
  269 + } else {
  270 + const phoneRegular = /^1\d{10}$/;
  271 + if (this.bindPhoneObj.appUserKey == '') {
  272 + uni.showToast({
  273 + title: '请输入手机号码~',
  274 + icon: 'none'
  275 + });
  276 + return;
  277 + } else if (!phoneRegular.test(this.bindPhoneObj.appUserKey)) {
  278 + uni.showToast({
  279 + title: '手机号格式不正确~',
  280 + icon: 'none'
  281 + });
  282 + return;
  283 + }
  284 + if (this.bindPhoneObj.appUserSecret == '') {
  285 + uni.showToast({
  286 + title: '请输入验证码~',
  287 + icon: 'none'
  288 + });
  289 + return;
  290 + } else if (!/^\d{6}$/.test(this.bindPhoneObj.appUserSecret)) {
  291 + uni.showToast({
  292 + title: '验证码格式不正确~',
  293 + icon: 'none'
  294 + });
  295 + return;
  296 + }
  297 + const postData = {
  298 + loginMethod: 'PHONE',
  299 + ...this.bindPhoneObj,
  300 + platformName: 'WECHAT',
  301 + thirdUserId: this.getOpenId
  302 + };
  303 + uni.$u.http
  304 + .post('/yt/third/bind', postData)
  305 + .then(res => {
  306 + this.show = false;
  307 + // 储存登录信息
  308 + let resObj = {
  309 + refreshToken: res.refreshToken,
  310 + isToken: res.token
  311 + };
  312 + let userInfo = {
  313 + ...resObj,
  314 + token: true, //token用于判断是否登录
  315 + isThirdLogin: false,
  316 + isThirdLoginAndNoDind: true
  317 + };
  318 + if (userInfo.token) {
  319 + this.setUserInfo(userInfo);
  320 + }
  321 + uni.showToast({
  322 + title: '手机绑定成功~',
  323 + icon: 'none'
  324 + });
  325 + this.saveUserInfo();
  326 + })
  327 + .catch(e => {
  328 + uni.$u.toast(e.data?.msg);
  329 + this.show = true;
  330 + });
  331 + }
  332 + },
  333 + saveUserInfo() {
  334 + //储存个人信息
  335 + uni.$u.http.get('/yt/user/me/info').then(res => {
  336 + if (res) {
  337 + this.setUserInfo(res);
  338 + }
  339 + });
  340 + },
  341 + bindPhoneFunc() {
  342 + this.bindPhone = true;
  343 + },
  344 + bindAccountFunc() {
  345 + this.bindPhone = false;
  346 + },
  347 + //验证码按钮文字状态
  348 + getCodeState() {
  349 + const _this = this;
  350 + this.readonly = true;
  351 + this.codeText = '60S后重新获取';
  352 + var s = 60;
  353 + clear = setInterval(() => {
  354 + s--;
  355 + _this.codeText = s + 'S后重新获取';
  356 + if (s <= 0) {
  357 + clearInterval(clear);
  358 + _this.codeText = '获取验证码';
  359 + _this.readonly = false;
  360 + }
  361 + }, 1000);
  362 + },
  363 + //获取验证码
  364 + getVcode() {
  365 + if (this.readonly) {
  366 + uni.showToast({
  367 + title: '验证码已发送~',
  368 + icon: 'none'
  369 + });
  370 + return;
  371 + }
  372 + if (this.bindPhoneObj.appUserKey == '') {
  373 + uni.showToast({
  374 + title: '请输入手机号~',
  375 + icon: 'none'
  376 + });
  377 + return;
  378 + }
  379 + const phoneRegular = /^1\d{10}$/;
  380 + if (!phoneRegular.test(this.bindPhoneObj.appUserKey)) {
  381 + uni.showToast({
  382 + title: '手机号格式不正确~',
  383 + icon: 'none'
  384 + });
  385 + return;
  386 + }
  387 + let httpData = {};
  388 + // 获取验证码接口
  389 + uni.$u.http.post(`/yt/noauth/sendLoginSmsCode/${this.bindPhoneObj.appUserKey}`).then(res => {
  390 + if (res) {
  391 + this.getCodeState(); //开始倒计时
  392 + }
  393 + });
  394 + },
  395 + onLoginoutFunc() {
  396 + this.showLogout = true;
  397 + },
  398 + closeLogout() {
  399 + this.showLogout = false;
  400 + },
  401 + logoutBtn() {
  402 + let that = this;
  403 + uni.showModal({
  404 + title: '退出登录',
  405 + content: '你确定退出登录吗?',
  406 + success(res) {
  407 + if (res.confirm) {
  408 + that.emptyUserInfo();
  409 + that.showLogout = false;
  410 + setTimeout(() => {
  411 + uni.navigateTo({
  412 + url: '/publicLoginSubPage/public/login'
  413 + });
  414 + }, 500);
  415 + } else if (res.cancel) {
  416 + }
  417 + }
  418 + });
  419 + }
  420 + }
  421 +};
  422 +</script>
  423 +
  424 +<style lang="scss" scoped>
  425 +@import './static/personal.scss';
426 426 </style>
... ...