Commit c381700aa275b30b537c64ce1bdb885ce24072dc

Authored by fengtao
1 parent 11d82dba

feat:新增解绑换在个人资料位置

... ... @@ -3,7 +3,7 @@
3 3 <!-- 公共组件-每个页面必须引入 -->
4 4 <public-module></public-module>
5 5 <view class="headBox">
6   - <!-- #ifdef MP -->
  6 + <!-- #ifdef MP || APP-PLUS -->
7 7 <!-- 登录 -->
8 8 <view class="u-flex u-p-l-30 u-p-r-20 u-p-t-75 u-p-b-30">
9 9 <block v-if="userInfo.isToken">
... ... @@ -17,8 +17,6 @@
17 17 </view>
18 18 </view>
19 19 <view @click="openPersonalInfo" style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
20   - <view v-else><text style="color:#FFFFFF;font-size: 14px;">手机号:未绑定</text></view>
21   - <view v-if="userInfo.isToken" @click="clearAccountFunc(userInfo)" class="detail"><text class="text">解绑</text></view>
22 20 </view>
23 21 </block>
24 22 <block v-else>
... ... @@ -30,37 +28,9 @@
30 28 <view v-if="!userInfo.isToken" @click="clickAccountFunc" class="detail"><text class="text">绑定账号</text></view>
31 29 </view>
32 30 </block>
33   - <view v-if="userInfo.isToken"><u-icon name="arrow-right" color="white" size="13"></u-icon></view>
  31 + <view v-if="userInfo.isToken" @click="openPersonalInfo"><u-icon name="arrow-right" color="white" size="13"></u-icon></view>
34 32 </view>
35   - <!-- #endif -->
36   - <!-- #ifndef MP -->
37 33 <!-- 登录 -->
38   - <view class="u-flex u-p-l-30 u-p-r-20 u-p-t-75 u-p-b-30">
39   - <block v-if="userInfo.isToken">
40   - <view @click="openPersonalInfo" class="u-m-r-20">
41   - <image class="avatar" mode="aspectFill" :src="userInfo.avatar || userInfo.avatarUrl || '/static/default.png'"></image>
42   - </view>
43   - <view @click="openPersonalInfo" class="u-flex-1">
44   - <view class="nickName u-flex">
45   - <view class="name u-m-r-10" v-if="userInfo.realName || userInfo.nickName">
46   - <text style="#FFFFFF;font-size: 18px;">{{ userInfo.realName || userInfo.nickName }}</text>
47   - </view>
48   - </view>
49   - <view style="color:#FFFFFF;font-size: 14px;" v-if="userInfo.phoneNumber">{{ userInfo.phoneNumber | phone }}</view>
50   - <view v-else><text style="color:#FFFFFF;font-size: 14px;">手机号:未绑定</text></view>
51   - </view>
52   - </block>
53   - <block v-else>
54   - <view class="u-m-r-20" @click="openLoginFunc">
55   - <view class="avatar u-flex" style="justify-content: center"><u-icon name="account-fill" color="black" size="30"></u-icon></view>
56   - </view>
57   - <view class="u-flex-1">
58   - <view @click="openLoginFunc" class="u-font-lg login-btn">登录</view>
59   - <view v-if="userInfo.isToken == '' || userInfo.isToken == null" @click="clickAccountFunc" style="color: black" class="detail">绑定账号</view>
60   - </view>
61   - </block>
62   - <view><u-icon name="arrow-right" color="black" size="13"></u-icon></view>
63   - </view>
64 34 <!-- #endif -->
65 35 </view>
66 36 <view class="u-flex my-nav">
... ... @@ -195,7 +165,6 @@ export default {
195 165 if (e.obj != null) {
196 166 const params = JSON.parse(decodeURIComponent(e.obj));
197 167 this.thirdObj = params;
198   - console.log(this.thirdObj);
199 168 }
200 169 },
201 170 computed: {
... ... @@ -223,7 +192,8 @@ export default {
223 192 },
224 193 openPersonalInfo() {
225 194 let obj = {
226   - data: this.userInfo
  195 + data: this.userInfo,
  196 + third: this.thirdObj
227 197 };
228 198 uni.navigateTo({
229 199 url: '/publicLoginSubPage/other/set?data=' + JSON.stringify(obj)
... ... @@ -290,7 +260,8 @@ export default {
290 260 }
291 261 })
292 262 .catch(e => {
293   - uni.$u.toast(e.data?.message);
  263 + uni.$u.toast(e.data?.msg || e.data?.message);
  264 + this.show = false;
294 265 });
295 266 } else {
296 267 const phoneRegular = /^1\d{10}$/;
... ... @@ -349,7 +320,8 @@ export default {
349 320 this.saveUserInfo();
350 321 })
351 322 .catch(e => {
352   - uni.$u.toast(e.data?.message);
  323 + uni.$u.toast(e.data?.msg || e.data?.message);
  324 + this.show = false;
353 325 });
354 326 }
355 327 },
... ... @@ -439,18 +411,6 @@ export default {
439 411 }
440 412 }
441 413 });
442   - },
443   - clearAccountFunc(e) {
444   - //解绑
445   - let httpData = {
446   - appUserId: e.userId,
447   - thirdUserId: this.thirdObj.thirdUserId
448   - };
449   - uni.$u.http.delete('/yt/third', httpData).then(res => {
450   - if (res) {
451   - this.getCodeState(); //开始倒计时
452   - }
453   - });
454 414 }
455 415 }
456 416 };
... ...
... ... @@ -45,10 +45,24 @@
45 45 </u-form-item>
46 46 </u--form>
47 47 </view>
48   - <view class="basic-bottom"><button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }">确认</button></view>
  48 + <view class="basic-bottom u-flex">
  49 + <view class="item" v-if="info.data.isToken"><button class="submit" size="default" @click="clearAccountFunc" :style="{ background: InfoColor }">解绑</button></view>
  50 + <view class="item" style="margin-right: 60rpx;"><button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }">确认</button></view>
  51 + </view>
49 52 <!-- #ifdef MP -->
50 53 <view class="u-m-t-40"><text style="visibility: hidden;">#</text></view>
51 54 <!-- #endif -->
  55 + <!-- 解绑账号 -->
  56 + <view>
  57 + <u-popup bgColor="transparent" :overlay="true" :show="showBind" mode="bottom">
  58 + <view class="u-flex logout-main">
  59 + <view class="main"><text style="color: #999999">是否需要解绑?</text></view>
  60 + <view @click="confrimBind(info)" class="main"><text style="color: #f95e5a">是</text></view>
  61 + <view class="main1"><text @click="showBind = false" style="color: #3478f7">否</text></view>
  62 + </view>
  63 + </u-popup>
  64 + </view>
  65 + <!-- 解绑账号 -->
52 66 </view>
53 67 </template>
54 68
... ... @@ -56,7 +70,9 @@
56 70 export default {
57 71 data() {
58 72 return {
59   - PrimaryColor: '#0079fe', //主题色
  73 + showBind: false,
  74 + PrimaryColor: '#377DFF', //主题色
  75 + InfoColor: '#E3E4E5', //主题色
60 76 myInfoModel: {
61 77 userInfo: {
62 78 realName: '',
... ... @@ -117,12 +133,14 @@ export default {
117 133 trigger: ['change', 'blur']
118 134 }
119 135 ]
120   - }
  136 + },
  137 + info: {}
121 138 };
122 139 },
123 140 onLoad(e) {
124 141 if (e.data !== null) {
125 142 let params = JSON.parse(e.data);
  143 + this.info = params;
126 144 this.myInfoModel.userInfo.realName = params.data.realName;
127 145 this.myInfoModel.userInfo.phoneNumber = params.data.phoneNumber;
128 146 this.myInfoModel.userInfo.username = params.data.username;
... ... @@ -133,6 +151,31 @@ export default {
133 151 }
134 152 },
135 153 methods: {
  154 + confrimBind(e) {
  155 + if (e) {
  156 + //解绑
  157 + let httpData = {
  158 + appUserId: e.data?.userId,
  159 + thirdUserId: e.third?.thirdUserId
  160 + };
  161 + uni.$u.http.delete('/yt/third', httpData).then(res => {
  162 + if (res) {
  163 + uni.showToast({
  164 + title: '解绑成功'
  165 + });
  166 + this.showBind = false;
  167 + } else {
  168 + uni.showToast({
  169 + title: '解绑失败'
  170 + });
  171 + this.showBind = false;
  172 + }
  173 + });
  174 + }
  175 + },
  176 + clearAccountFunc() {
  177 + this.showBind = true;
  178 + },
136 179 // 修改头像
137 180 upAvatar() {
138 181 var that = this;
... ...
... ... @@ -46,6 +46,30 @@
46 46 padding-left: 15rpx;
47 47 }
48 48 .basic-bottom {
49   - width: 500rpx;
50   - margin-left: 86rpx;
  49 + width: 750rpx;
  50 + justify-content: space-between;
  51 + .item {
  52 + width: 318rpx;
  53 + }
  54 +}
  55 +
  56 +.logout-main {
  57 + flex-direction: column;
  58 + height: 300rpx;
  59 + margin: 30rpx 40rpx;
  60 + background: #f5f5f5;
  61 + border-radius: 20rpx;
  62 + .main {
  63 + width: 669rpx;
  64 + height: 100rpx;
  65 + border-bottom: 1rpx solid #d6d6d6;
  66 + text-align: center;
  67 + line-height: 86rpx;
  68 + }
  69 + .main1 {
  70 + width: 669rpx;
  71 + height: 100rpx;
  72 + text-align: center;
  73 + line-height: 86rpx;
  74 + }
51 75 }
... ...
... ... @@ -37,7 +37,7 @@
37 37 </template>
38 38
39 39 <script>
40   -import { mapMutations } from 'vuex';
  40 +import { mapMutations, mapActions } from 'vuex';
41 41 import { loginApp } from '@/config/login';
42 42 import baseUrl from '@/config/baseUrl.js';
43 43 import WXBizDataCrypt from '@/config/WXBizDataCrypt.js';
... ... @@ -70,6 +70,12 @@ export default {
70 70 this.openid = res.data.openid;
71 71 this.session_key = res.data.session_key;
72 72 }
  73 + },
  74 + complete: e => {
  75 + if (e.data.errcode != null) {
  76 + return;
  77 + // return uni.$u.toast('获取用户唯一id失败');
  78 + }
73 79 }
74 80 });
75 81 } else {
... ... @@ -80,14 +86,19 @@ export default {
80 86 },
81 87 methods: {
82 88 ...mapMutations(['setUserInfo']),
  89 + ...mapActions(['updateBadgeTotal']),
83 90 //微信授权登录
84 91 //#ifdef MP
85 92 onAuthorization(e) {
  93 + /**
  94 + * 注意:通过wx.getUserProfile并不能获取用户的openid,openid是唯一识别用户的标识,
  95 + * 所以最好在用户授权登录时就获取。调用wx.login()获取
  96 + */
86 97 wx.getUserProfile({
87   - desc: '获取用户信息',
  98 + desc: '获取用户授权信息',
88 99 success: res => {
89 100 if (res) {
90   - //微信官方自带解密(node)
  101 + //微信官方自带解密(node.js实现
91 102 let pc = new WXBizDataCrypt(appId, this.session_key);
92 103 let data = pc.decryptData(res.encryptedData, res.iv);
93 104 let obj = {
... ... @@ -100,11 +111,12 @@ export default {
100 111 .get(`/yt/third/login/${this.openid}`)
101 112 .then(res => {
102 113 if (res.token == '' || res.token == null) {
103   - //需要绑定,跳转我的页面
  114 + //需要绑定,跳转我的页面进行绑定,显示绑定按钮
104 115 uni.reLaunch({
105 116 url: '/pages/personal/personal'
106 117 });
107 118 } else {
  119 + // 不需要绑定
108 120 // 储存登录信息
109 121 let resObj = {
110 122 refreshToken: res.refreshToken,
... ... @@ -122,12 +134,17 @@ export default {
122 134 icon: 'none'
123 135 });
124 136 this.saveUserInfo();
  137 + this.getAlarmTotalData();
125 138 }
126 139 })
127 140 .catch(e => {
128 141 uni.$u.toast(e.data?.message);
129 142 });
130   - // #ifdef APP-PLUS||MP
  143 + /**
  144 + * 有些时候uni.navigatorBack({})没有返回到上级页面
  145 + * 才使用uni.reLaunch()进行跳转
  146 + */
  147 + // #ifdef MP
131 148 setTimeout(() => {
132 149 uni.reLaunch({
133 150 url: '/pages/personal/personal?obj=' + encodeURIComponent(JSON.stringify(obj))
... ... @@ -147,6 +164,14 @@ export default {
147 164 }
148 165 });
149 166 },
  167 + getAlarmTotalData() {
  168 + uni.$u.http.get('/yt/homepage/app').then(res => {
  169 + if (res) {
  170 + //异步实时更新告警徽标数
  171 + this.updateBadgeTotal(res.totalAlarm.activedAlarm);
  172 + }
  173 + });
  174 + },
150 175 onSubmitFunc() {
151 176 if (this.loginForm.username == '') {
152 177 return uni.$u.toast('请输入登录账号~');
... ... @@ -199,6 +224,7 @@ export default {
199 224 // #endif
200 225 });
201 226 this.saveUserInfo();
  227 + this.getAlarmTotalData();
202 228 }
203 229 })
204 230 .catch(e => {
... ...
... ... @@ -172,6 +172,19 @@ button {
172 172 font-weight: 400;
173 173 color: #2f384e;
174 174 }
  175 +//筛选字体颜色
  176 +.select-text {
  177 + font-size: 13px;
  178 + font-family: PingFangSC-Regular, PingFang SC;
  179 + font-weight: 400;
  180 + color: #377dff !important;
  181 +}
  182 +.un-select-text {
  183 + font-size: 13px;
  184 + font-family: PingFangSC-Regular, PingFang SC;
  185 + font-weight: 400;
  186 + color: #333333 !important;
  187 +}
175 188 // 定义flex等分
176 189 @for $i from 0 through 12 {
177 190 .u-flex-#{$i} {
... ...