Commit fd5a72c5b81a9d7fb4b98dfd4486ebcc84ca14a1

Authored by xp.Huang
2 parents 44150a03 1a3c1b2e

Merge branch 'ft_local_dev' into 'main'

fix:修改绑定账号退出回到登录页

See merge request huang/thingskit-app!83
1 -import store from '@/store';  
2 -import {  
3 - h5Login  
4 -} from '@/config/h5Utils'; 1 +import store from "@/store";
  2 +import { h5Login } from "@/config/h5Utils";
5 // APP--授权登录 3 // APP--授权登录
6 // type授权登录平台 'qq'、'weixin'、'apple' 4 // type授权登录平台 'qq'、'weixin'、'apple'
7 export const loginApp = (type, successCallback, errorCallback) => { 5 export const loginApp = (type, successCallback, errorCallback) => {
8 - uni.login({  
9 - provider: type,  
10 - success: function(loginRes) {  
11 - // 获取用户信息  
12 - uni.getUserInfo({  
13 - provider: type,  
14 - success: function(infoRes) {  
15 - let data = {}  
16 - if (type == 'qq') {  
17 - data = {  
18 - 'openid': loginRes.authResult.openid,  
19 - 'nickname': infoRes.userInfo.nickname,  
20 - 'gender': infoRes.userInfo.gender,  
21 - 'province': infoRes.userInfo.province,  
22 - 'city': infoRes.userInfo.city,  
23 - 'figureurl': infoRes.userInfo.figureurl_qq  
24 - }  
25 - } else if (type == 'weixin') {  
26 - data = {  
27 - 'openid': loginRes.authResult.openid,  
28 - 'nickname': infoRes.userInfo.nickName,  
29 - 'sex': infoRes.userInfo.gender,  
30 - 'province': infoRes.userInfo.province,  
31 - 'city': infoRes.userInfo.city,  
32 - 'country': infoRes.userInfo.country,  
33 - 'headimgurl': infoRes.userInfo.avatarUrl,  
34 - 'unionid': loginRes.authResult.unionid  
35 - }  
36 - } else if (type == 'apple') {  
37 - data = {  
38 - verifyType: 'password',  
39 - personalPhone: '13888888888',  
40 - personalPhoneCountryCode: '86',  
41 - password: '123456'  
42 - }  
43 - }  
44 - successCallback && successCallback(data)  
45 - }  
46 - });  
47 - },  
48 - fail: function(err) {  
49 - console.log(res, "失败")  
50 - errorCallback && errorCallback(res)  
51 - }  
52 - });  
53 -} 6 + uni.login({
  7 + provider: type,
  8 + success: function (loginRes) {
  9 + // 获取用户信息
  10 + uni.getUserInfo({
  11 + provider: type,
  12 + success: function (infoRes) {
  13 + let data = {};
  14 + if (type == "qq") {
  15 + data = {
  16 + openid: loginRes.authResult.openid,
  17 + nickname: infoRes.userInfo.nickname,
  18 + gender: infoRes.userInfo.gender,
  19 + province: infoRes.userInfo.province,
  20 + city: infoRes.userInfo.city,
  21 + figureurl: infoRes.userInfo.figureurl_qq,
  22 + };
  23 + } else if (type == "weixin") {
  24 + data = {
  25 + openid: loginRes.authResult.openid,
  26 + nickname: infoRes.userInfo.nickName,
  27 + sex: infoRes.userInfo.gender,
  28 + province: infoRes.userInfo.province,
  29 + city: infoRes.userInfo.city,
  30 + country: infoRes.userInfo.country,
  31 + headimgurl: infoRes.userInfo.avatarUrl,
  32 + unionid: loginRes.authResult.unionid,
  33 + };
  34 + } else if (type == "apple") {
  35 + data = {
  36 + verifyType: "password",
  37 + personalPhone: "13888888888",
  38 + personalPhoneCountryCode: "86",
  39 + password: "123456",
  40 + };
  41 + }
  42 + successCallback && successCallback(data);
  43 + },
  44 + });
  45 + },
  46 + fail: function (err) {
  47 + console.log(res, "失败");
  48 + errorCallback && errorCallback(res);
  49 + },
  50 + });
  51 +};
54 // 微信/支付宝小程序---手机号授权登录时使用 52 // 微信/支付宝小程序---手机号授权登录时使用
55 // info: uni.login获取的参数 53 // info: uni.login获取的参数
56 export const getPhoneInfo = (info, successCallback, errCallback) => { 54 export const getPhoneInfo = (info, successCallback, errCallback) => {
57 - let httpData = {}  
58 - // #ifdef MP-WEIXIN  
59 - httpData = {  
60 - code: info.code, //小程序code  
61 - iv: info.iv, //小程序加密算法的初始向量  
62 - encryptedData: info.encryptedData, //包括敏感数据在内的完整用户信息的加密数据  
63 - };  
64 - // #endif  
65 - // #ifdef MP-ALIPAY  
66 - httpData = {  
67 - code: '', //小程序code  
68 - iv: '', //小程序加密算法的初始向量  
69 - encryptedData: info, //包括敏感数据在内的完整用户信息的加密数据  
70 - };  
71 - // #endif 55 + let httpData = {};
  56 + // #ifdef MP-WEIXIN
  57 + httpData = {
  58 + code: info.code, //小程序code
  59 + iv: info.iv, //小程序加密算法的初始向量
  60 + encryptedData: info.encryptedData, //包括敏感数据在内的完整用户信息的加密数据
  61 + };
  62 + // #endif
  63 + // #ifdef MP-ALIPAY
  64 + httpData = {
  65 + code: "", //小程序code
  66 + iv: "", //小程序加密算法的初始向量
  67 + encryptedData: info, //包括敏感数据在内的完整用户信息的加密数据
  68 + };
  69 + // #endif
72 70
73 - // 此时需要您的接口返回个人信息  
74 - // uni.$u.http.post('您的接口', httpData).then(res => {  
75 - var loginInfo = {  
76 - // userId: res.id,  
77 - // sessionId: res.sessionId,  
78 - // phoneNum: res.phoneNum,  
79 - // userName: res.userName,  
80 - // openId: res.openId,  
81 - };  
82 - successCallback && successCallback(loginInfo)  
83 - // }, err => {  
84 - // errCallback && errCallback(err)  
85 - // });  
86 -} 71 + // 此时需要您的接口返回个人信息
  72 + // uni.$u.http.post('您的接口', httpData).then(res => {
  73 + var loginInfo = {
  74 + // userId: res.id,
  75 + // sessionId: res.sessionId,
  76 + // phoneNum: res.phoneNum,
  77 + // userName: res.userName,
  78 + // openId: res.openId,
  79 + };
  80 + successCallback && successCallback(loginInfo);
  81 + // }, err => {
  82 + // errCallback && errCallback(err)
  83 + // });
  84 +};
87 // 微信/支付宝小程序---通用授权个人信息登录 85 // 微信/支付宝小程序---通用授权个人信息登录
88 export const getUserInfo = (successCallback, errorCallback) => { 86 export const getUserInfo = (successCallback, errorCallback) => {
89 - uni.showLoading({  
90 - title: '正在申请授权',  
91 - });  
92 - // #ifdef MP-WEIXIN  
93 - uni.getUserProfile({  
94 - desc: '用于完善会员资料',  
95 - success: function(res) {  
96 - uni.hideLoading()  
97 - var offUserInfo = res.userInfo  
98 - successCallback && successCallback(offUserInfo)  
99 - },  
100 - fail: (res) => {  
101 - uni.hideLoading()  
102 - errorCallback && errorCallback(res)  
103 - }  
104 - })  
105 - // #endif  
106 - // #ifdef MP-ALIPAY  
107 - uni.getOpenUserInfo({  
108 - success: (res) => {  
109 - uni.hideLoading()  
110 - var offUserInfo = JSON.parse(res.response).response // 以下方的报文格式解析两层 response  
111 - offUserInfo.avatarUrl = offUserInfo.avatar  
112 - successCallback && successCallback(offUserInfo)  
113 - },  
114 - fail: (res) => {  
115 - uni.hideLoading()  
116 - console.log(res, "失败")  
117 - errorCallback && errorCallback(res)  
118 - }  
119 - })  
120 - // #endif  
121 -} 87 + uni.showLoading({
  88 + title: "正在申请授权",
  89 + });
  90 + // #ifdef MP-WEIXIN
  91 + uni.getUserProfile({
  92 + desc: "用于完善会员资料",
  93 + success: function (res) {
  94 + uni.hideLoading();
  95 + var offUserInfo = res.userInfo;
  96 + successCallback && successCallback(offUserInfo);
  97 + },
  98 + fail: (res) => {
  99 + uni.hideLoading();
  100 + errorCallback && errorCallback(res);
  101 + },
  102 + });
  103 + // #endif
  104 + // #ifdef MP-ALIPAY
  105 + uni.getOpenUserInfo({
  106 + success: (res) => {
  107 + uni.hideLoading();
  108 + var offUserInfo = JSON.parse(res.response).response; // 以下方的报文格式解析两层 response
  109 + offUserInfo.avatarUrl = offUserInfo.avatar;
  110 + successCallback && successCallback(offUserInfo);
  111 + },
  112 + fail: (res) => {
  113 + uni.hideLoading();
  114 + console.log(res, "失败");
  115 + errorCallback && errorCallback(res);
  116 + },
  117 + });
  118 + // #endif
  119 +};
122 120
123 //判断是否登录(所有端) 121 //判断是否登录(所有端)
124 export const judgeLogin = (callback) => { 122 export const judgeLogin = (callback) => {
125 - let storeUserInfo = store.state.userInfo;  
126 - if (!storeUserInfo.userId) { // nvue页面读取不到vuex里面数据,将取缓存  
127 - storeUserInfo = uni.getStorageSync('userInfo')  
128 - }  
129 - if (!storeUserInfo.isToken) {  
130 - // #ifdef MP  
131 - return  
132 - // #endif  
133 - // #ifdef H5  
134 - h5Login();  
135 - // #endif  
136 - } else {  
137 - callback()  
138 - }  
139 -} 123 + let storeUserInfo = store.state.userInfo;
  124 + if (!storeUserInfo.userId) {
  125 + // nvue页面读取不到vuex里面数据,将取缓存
  126 + storeUserInfo = uni.getStorageSync("userInfo");
  127 + }
  128 + if (!storeUserInfo.isToken) {
  129 + // #ifdef MP
  130 + return uni.$u.toast("请进行账号绑定");
  131 + // #endif
  132 + // #ifdef H5
  133 + h5Login();
  134 + // #endif
  135 + } else {
  136 + callback();
  137 + }
  138 +};
@@ -196,7 +196,7 @@ export default { @@ -196,7 +196,7 @@ export default {
196 ...mapMutations(['emptyUserInfo', 'setUserInfo', 'setPlateInfo']), 196 ...mapMutations(['emptyUserInfo', 'setUserInfo', 'setPlateInfo']),
197 // 跳转前判断登录 197 // 跳转前判断登录
198 onTokenJump(url) { 198 onTokenJump(url) {
199 - this.judgeLogin(() => { 199 + this.judgeLogin(r => {
200 uni.navigateTo({ 200 uni.navigateTo({
201 url: url 201 url: url
202 }); 202 });
@@ -284,7 +284,7 @@ export default { @@ -284,7 +284,7 @@ export default {
284 } 284 }
285 }) 285 })
286 .catch(e => { 286 .catch(e => {
287 - let msg = e.data?.msg; 287 + let msg = e.data?.message;
288 if (msg == undefined) { 288 if (msg == undefined) {
289 msg = ''; 289 msg = '';
290 } 290 }
@@ -3,12 +3,8 @@ @@ -3,12 +3,8 @@
3 <!-- 公共组件-每个页面必须引入 --> 3 <!-- 公共组件-每个页面必须引入 -->
4 <public-module></public-module> 4 <public-module></public-module>
5 <view @click="upAvatar" class="u-flex set-main"> 5 <view @click="upAvatar" class="u-flex set-main">
6 - <view class="main-image">  
7 - <image class="image" :src="avatar || '../../static/logo.png'"></image>  
8 - </view>  
9 - <view class="main-right-image">  
10 - <image class="image" src="../../static/arrow-right.png"></image>  
11 - </view> 6 + <view class="main-image"><image class="image" :src="avatar || '../../static/logo.png'"></image></view>
  7 + <view class="main-right-image"><image class="image" src="../../static/arrow-right.png"></image></view>
12 </view> 8 </view>
13 <view class="u-m-t-20 basic-text"><text class="text">基本资料</text></view> 9 <view class="u-m-t-20 basic-text"><text class="text">基本资料</text></view>
14 <view class="basic-main"> 10 <view class="basic-main">
@@ -20,35 +16,48 @@ @@ -20,35 +16,48 @@
20 <u--input placeholder="请输入手机号码" v-model="myInfoModel.phoneNumber" border="none"></u--input> 16 <u--input placeholder="请输入手机号码" v-model="myInfoModel.phoneNumber" border="none"></u--input>
21 </u-form-item> 17 </u-form-item>
22 <u-form-item labelWidth="80px" label="用户账号" prop="username" borderBottom ref="item1"> 18 <u-form-item labelWidth="80px" label="用户账号" prop="username" borderBottom ref="item1">
23 - <u--input disabled placeholder="请输入用户账号 " v-model="myInfoModel.username" border="none">  
24 - </u--input> 19 + <u--input disabled placeholder="请输入用户账号 " v-model="myInfoModel.username" border="none"></u--input>
25 </u-form-item> 20 </u-form-item>
26 <u-form-item labelWidth="80px" label="邮箱地址" prop="email" borderBottom ref="item1"> 21 <u-form-item labelWidth="80px" label="邮箱地址" prop="email" borderBottom ref="item1">
27 <u--input placeholder="请输入邮箱地址" v-model="myInfoModel.email" border="none"></u--input> 22 <u--input placeholder="请输入邮箱地址" v-model="myInfoModel.email" border="none"></u--input>
28 </u-form-item> 23 </u-form-item>
29 - <u-form-item @click=" 24 + <u-form-item
  25 + @click="
30 showDate = true; 26 showDate = true;
31 hideKeyboard(); 27 hideKeyboard();
32 - " labelWidth="80px" label="有效期" prop="accountExpireTime" ref="item1">  
33 - <u--input v-model="myInfoModel.accountExpireTime" placeholder="请选择有效期" border="none">  
34 - </u--input>  
35 - <u-datetime-picker :formatter="formatter" :show="showDate" :value="datetime" mode="dateTime"  
36 - closeOnClickOverlay @confirm="dateConfirm" @cancel="dateClose" @close="dateClose">  
37 - </u-datetime-picker> 28 + "
  29 + labelWidth="80px"
  30 + label="有效期"
  31 + prop="accountExpireTime"
  32 + ref="item1"
  33 + >
  34 + <u--input v-model="myInfoModel.accountExpireTime" placeholder="请选择有效期" border="none"></u--input>
  35 + <u-datetime-picker
  36 + :formatter="formatter"
  37 + :show="showDate"
  38 + :value="datetime"
  39 + mode="dateTime"
  40 + closeOnClickOverlay
  41 + @confirm="dateConfirm"
  42 + @cancel="dateClose"
  43 + @close="dateClose"
  44 + ></u-datetime-picker>
38 </u-form-item> 45 </u-form-item>
39 </u--form> 46 </u--form>
40 </view> 47 </view>
41 <view class="basic-bottom u-flex"> 48 <view class="basic-bottom u-flex">
42 <view class="item" v-if="info.data.isThirdLoginAndNoDind && isJudgeBindBtn"> 49 <view class="item" v-if="info.data.isThirdLoginAndNoDind && isJudgeBindBtn">
43 - <button class="submit" size="default" @click="clearAccountFunc" :style="{ background: InfoColor }"><text  
44 - class="un-bind-text">解绑</text></button> 50 + <button class="submit" size="default" @click="clearAccountFunc" :style="{ background: InfoColor }"><text class="un-bind-text">解绑</text></button>
45 </view> 51 </view>
46 - <view class="item" style="margin-right: 60rpx;" :style="[ 52 + <view
  53 + class="item"
  54 + style="margin-right: 60rpx;"
  55 + :style="[
47 { position: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : 'relative' }, 56 { position: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : 'relative' },
48 { right: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : '-190rpx' } 57 { right: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : '-190rpx' }
49 - ]">  
50 - <button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }"><text  
51 - class="un-bind-text">确认</text></button> 58 + ]"
  59 + >
  60 + <button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }"><text class="un-bind-text">确认</text></button>
52 </view> 61 </view>
53 </view> 62 </view>
54 <!-- #ifdef MP --> 63 <!-- #ifdef MP -->
@@ -69,182 +78,182 @@ @@ -69,182 +78,182 @@
69 </template> 78 </template>
70 79
71 <script> 80 <script>
72 - import {  
73 - mapMutations  
74 - } from 'vuex';  
75 - import baseUrl from '@/config/baseUrl.js';  
76 - import {  
77 - mapState  
78 - } from 'vuex';  
79 -  
80 - export default {  
81 -  
82 - data() {  
83 - return {  
84 - showBind: false,  
85 - PrimaryColor: '#377DFF', //主题色  
86 - InfoColor: '#00C9A7', //主题色  
87 - myInfoModel: {  
88 -  
89 - realName: '',  
90 - phoneNumber: '',  
91 - username: '',  
92 - email: '',  
93 - accountExpireTime: ''  
94 -  
95 - },  
96 -  
97 - rules: {  
98 - phoneNumber: [{  
99 - required: true,  
100 - message: "请输入正确的手机号码",  
101 - trigger: "change",  
102 - }, {  
103 - pattern: /^1[3-9][0-9]{9}$/,  
104 - message: "请输入正确的手机号码"  
105 - }  
106 -  
107 - ],  
108 - email: [{  
109 - required: true,  
110 - message: "请输入正确的邮箱号",  
111 - trigger: "change",  
112 - }, {  
113 - pattern: /^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{3}$/,  
114 - message: "请输入正确的邮箱号"  
115 - } 81 +import { mapMutations } from 'vuex';
  82 +import baseUrl from '@/config/baseUrl.js';
  83 +import { mapState } from 'vuex';
116 84
117 - ], 85 +export default {
  86 + data() {
  87 + return {
  88 + showBind: false,
  89 + PrimaryColor: '#377DFF', //主题色
  90 + InfoColor: '#00C9A7', //主题色
  91 + myInfoModel: {
  92 + realName: '',
  93 + phoneNumber: '',
  94 + username: '',
  95 + email: '',
  96 + accountExpireTime: ''
  97 + },
118 98
119 - },  
120 - showDate: false,  
121 - dateTime: Number(new Date()),  
122 - avatar: '',  
123 - id: '',  
124 - info: {},  
125 - openIds: '',  
126 - isUpdatePersonOrLoginInfo: false,  
127 - isJudgeBindBtn: true  
128 - };  
129 - },  
130 - onReady() {  
131 - this.$refs.myForm.setRules(this.rules)  
132 - },  
133 - onLoad(e) {  
134 - console.log(e);  
135 - if (e.data !== null) {  
136 - let params = JSON.parse(e.data);  
137 - this.info = params;  
138 - this.myInfoModel.realName = params.data.realName;  
139 - this.myInfoModel.phoneNumber = params.data.phoneNumber;  
140 - this.myInfoModel.username = params.data.username;  
141 - this.myInfoModel.email = params.data.email;  
142 - this.myInfoModel.accountExpireTime = params.data.accountExpireTime;  
143 - this.avatar = params.data.avatar == undefined ? '../../static/logo.png' : params.data.avatar;  
144 - this.id = params.data.userId;  
145 - }  
146 - },  
147 - onShow() {  
148 - let getOpenId = getApp().globalData.openId;  
149 - if (getOpenId) {  
150 - this.openIds = getOpenId;  
151 - console.log('OPenid', this.openIds); 99 + rules: {
  100 + phoneNumber: [
  101 + {
  102 + required: true,
  103 + message: '请输入正确的手机号码',
  104 + trigger: 'change'
  105 + },
  106 + {
  107 + pattern: /^1[3-9][0-9]{9}$/,
  108 + message: '请输入正确的手机号码'
  109 + }
  110 + ],
  111 + email: [
  112 + {
  113 + required: true,
  114 + message: '请输入正确的邮箱号',
  115 + trigger: 'change'
  116 + },
  117 + {
  118 + pattern: /^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{3}$/,
  119 + message: '请输入正确的邮箱号'
  120 + }
  121 + ]
  122 + },
  123 + showDate: false,
  124 + dateTime: Number(new Date()),
  125 + avatar: '',
  126 + id: '',
  127 + info: {},
  128 + openIds: '',
  129 + isUpdatePersonOrLoginInfo: false,
  130 + isJudgeBindBtn: true
  131 + };
  132 + },
  133 + onReady() {
  134 + this.$refs.myForm.setRules(this.rules);
  135 + },
  136 + onLoad(e) {
  137 + console.log(e);
  138 + if (e.data !== null) {
  139 + let params = JSON.parse(e.data);
  140 + this.info = params;
  141 + this.myInfoModel.realName = params.data.realName;
  142 + this.myInfoModel.phoneNumber = params.data.phoneNumber;
  143 + this.myInfoModel.username = params.data.username;
  144 + this.myInfoModel.email = params.data.email;
  145 + this.myInfoModel.accountExpireTime = params.data.accountExpireTime;
  146 + this.avatar = params.data.avatar == undefined ? '../../static/logo.png' : params.data.avatar;
  147 + this.id = params.data.userId;
  148 + }
  149 + },
  150 + onShow() {
  151 + let getOpenId = getApp().globalData.openId;
  152 + if (getOpenId) {
  153 + this.openIds = getOpenId;
  154 + console.log('OPenid', this.openIds);
  155 + }
  156 + },
  157 + computed: {
  158 + ...mapState(['userInfo'])
  159 + },
  160 + methods: {
  161 + ...mapMutations(['setUserInfo', 'emptyUserInfo']),
  162 + confrimBind(e) {
  163 + if (e) {
  164 + //解绑
  165 + let httpData = {
  166 + appUserId: e.data?.userId,
  167 + thirdUserId: e.data?.thirdUserId == null ? this.openIds : e.data?.thirdUserId
  168 + };
  169 + uni.$u.http.delete('/yt/third', httpData).then(res => {
  170 + if (res) {
  171 + uni.showToast({
  172 + title: '解绑成功'
  173 + });
  174 + this.showBind = false;
  175 + this.isJudgeBindBtn = false;
  176 + uni.reLaunch({
  177 + url: '/publicLoginSubPage/public/login'
  178 + });
  179 + this.emptyUserInfo();
  180 + } else {
  181 + uni.showToast({
  182 + title: '解绑失败'
  183 + });
  184 + this.showBind = false;
  185 + }
  186 + });
152 } 187 }
153 }, 188 },
154 - computed: {  
155 - ...mapState(['userInfo']) 189 + clearAccountFunc() {
  190 + this.showBind = true;
156 }, 191 },
157 - methods: {  
158 - ...mapMutations(['setUserInfo']),  
159 - confrimBind(e) {  
160 - if (e) {  
161 - //解绑  
162 - let httpData = {  
163 - appUserId: e.data?.userId,  
164 - thirdUserId: e.data?.thirdUserId == null ? this.openIds : e.data?.thirdUserId  
165 - };  
166 - uni.$u.http.delete('/yt/third', httpData).then(res => {  
167 - if (res) {  
168 - uni.showToast({  
169 - title: '解绑成功'  
170 - });  
171 - this.showBind = false;  
172 - this.isJudgeBindBtn = false;  
173 - } else {  
174 - uni.showToast({  
175 - title: '解绑失败'  
176 - });  
177 - this.showBind = false; 192 + // 修改头像
  193 + async upAvatar() {
  194 + let token;
  195 + token = this.userInfo.isToken || uni.getStorageSync('userInfo').isToken || undefined;
  196 + // #ifdef H5
  197 + token = window.sessionStorage.getItem('userInfo').isToken;
  198 + // #endif
  199 + if (!token) return uni.$u.toast('请登录后上传图片');
  200 + uni.chooseImage({
  201 + count: 1,
  202 + sourceType: ['camera', 'album'],
  203 + success: res => {
  204 + const tempFilePaths = res.tempFilePaths;
  205 + //限制上传的图片大小不超过5M
  206 + let resSize = res.tempFiles[0].size;
  207 + if (resSize > 5242880) {
  208 + uni.showToast({
  209 + title: '上传的图片大小不能超过5M',
  210 + icon: 'none',
  211 + duration: 2000,
  212 + mask: true
  213 + });
  214 + return;
  215 + }
  216 + //获取图片扩展名
  217 + const fileTxt = res.tempFilePaths[0].split('.').pop();
  218 + const judgeType = fileTxt == 'jpg' || fileTxt == 'jpeg' || fileTxt == 'png';
  219 + if (!judgeType) {
  220 + uni.showToast({
  221 + title: '请上传指定图片类型(jpg、jpeg、png)',
  222 + icon: 'none',
  223 + duration: 2000,
  224 + mask: true
  225 + });
  226 + return;
  227 + }
  228 + uni.uploadFile({
  229 + url: `${baseUrl.baseUrl}/yt/oss/upload`,
  230 + filePath: tempFilePaths[0],
  231 + name: 'file',
  232 + header: {
  233 + 'content-type': 'multipart/form-data',
  234 + Authorization: 'Bearer ' + token
  235 + },
  236 + formData: {},
  237 + success: res => {
  238 + let objImage = JSON.parse(res.data);
  239 + this.avatar = objImage.fileStaticUri;
  240 + uni.$u.toast('头像上传成功');
178 } 241 }
179 }); 242 });
180 } 243 }
181 - },  
182 - clearAccountFunc() {  
183 - this.showBind = true;  
184 - },  
185 - // 修改头像  
186 - async upAvatar() {  
187 - let token;  
188 - token = this.userInfo.isToken || uni.getStorageSync('userInfo').isToken || undefined;  
189 - // #ifdef H5  
190 - token = window.sessionStorage.getItem('userInfo').isToken;  
191 - // #endif  
192 - if (!token) return uni.$u.toast('请登录后上传图片');  
193 - uni.chooseImage({  
194 - count: 1,  
195 - sourceType: ['camera', 'album'],  
196 - success: res => {  
197 - const tempFilePaths = res.tempFilePaths;  
198 - //限制上传的图片大小不超过5M  
199 - let resSize = res.tempFiles[0].size;  
200 - if (resSize > 5242880) {  
201 - uni.showToast({  
202 - title: '上传的图片大小不能超过5M',  
203 - icon: 'none',  
204 - duration: 2000,  
205 - mask: true  
206 - });  
207 - return;  
208 - }  
209 - //获取图片扩展名  
210 - const fileTxt = res.tempFilePaths[0].split('.').pop();  
211 - const judgeType = fileTxt == 'jpg' || fileTxt == 'jpeg' || fileTxt == 'png';  
212 - if (!judgeType) {  
213 - uni.showToast({  
214 - title: '请上传指定图片类型(jpg、jpeg、png)',  
215 - icon: 'none',  
216 - duration: 2000,  
217 - mask: true  
218 - });  
219 - return;  
220 - }  
221 - uni.uploadFile({  
222 - url: `${baseUrl.baseUrl}/yt/oss/upload`,  
223 - filePath: tempFilePaths[0],  
224 - name: 'file',  
225 - header: {  
226 - 'content-type': 'multipart/form-data',  
227 - Authorization: 'Bearer ' + token  
228 - },  
229 - formData: {},  
230 - success: res => {  
231 - let objImage = JSON.parse(res.data);  
232 - this.avatar = objImage.fileStaticUri;  
233 - uni.$u.toast('头像上传成功');  
234 - }  
235 - });  
236 - }  
237 - });  
238 - },  
239 - onSubmitFunc() {  
240 - let httpData = {  
241 - avatar: this.avatar,  
242 - email: this.myInfoModel.email,  
243 - id: this.id,  
244 - phoneNumber: this.myInfoModel.phoneNumber,  
245 - realName: this.myInfoModel.realName  
246 - };  
247 - this.$refs.myForm.validate().then(res => { 244 + });
  245 + },
  246 + onSubmitFunc() {
  247 + let httpData = {
  248 + avatar: this.avatar,
  249 + email: this.myInfoModel.email,
  250 + id: this.id,
  251 + phoneNumber: this.myInfoModel.phoneNumber,
  252 + realName: this.myInfoModel.realName
  253 + };
  254 + this.$refs.myForm
  255 + .validate()
  256 + .then(res => {
248 uni.$u.http 257 uni.$u.http
249 .put('/yt/user/center', httpData) 258 .put('/yt/user/center', httpData)
250 .then(res => { 259 .then(res => {
@@ -260,66 +269,67 @@ @@ -260,66 +269,67 @@
260 }); 269 });
261 }, 500); 270 }, 500);
262 } 271 }
263 - }).catch(e => {  
264 - uni.$u.toast(e.data.message);  
265 - });  
266 - }).catch(errors => {  
267 - uni.$u.toast('校验失败') 272 + })
  273 + .catch(e => {
  274 + uni.$u.toast(e.data.message);
  275 + });
268 }) 276 })
269 -  
270 - },  
271 - dateClose() {  
272 - this.showDate = false;  
273 - },  
274 - dateConfirm(e) {  
275 - this.showDate = false;  
276 - this.myInfoModel.userInfo.accountExpireTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');  
277 - },  
278 - //格式化日期  
279 - formatter(type, value) {  
280 - if (type === 'year') {  
281 - return `${value}年`;  
282 - }  
283 - if (type === 'month') {  
284 - return `${value}月`;  
285 - }  
286 - if (type === 'day') {  
287 - return `${value}日`;  
288 - }  
289 - if (type === 'hour') {  
290 - return `${value}时`;  
291 - }  
292 - if (type === 'minute') {  
293 - return `${value}分`;  
294 - }  
295 - return value;  
296 - },  
297 - //隐藏输入框  
298 - hideKeyboard() {  
299 - uni.hideKeyboard(); 277 + .catch(errors => {
  278 + uni.$u.toast('校验失败');
  279 + });
  280 + },
  281 + dateClose() {
  282 + this.showDate = false;
  283 + },
  284 + dateConfirm(e) {
  285 + this.showDate = false;
  286 + this.myInfoModel.userInfo.accountExpireTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
  287 + },
  288 + //格式化日期
  289 + formatter(type, value) {
  290 + if (type === 'year') {
  291 + return `${value}年`;
  292 + }
  293 + if (type === 'month') {
  294 + return `${value}月`;
  295 + }
  296 + if (type === 'day') {
  297 + return `${value}日`;
300 } 298 }
  299 + if (type === 'hour') {
  300 + return `${value}时`;
  301 + }
  302 + if (type === 'minute') {
  303 + return `${value}分`;
  304 + }
  305 + return value;
  306 + },
  307 + //隐藏输入框
  308 + hideKeyboard() {
  309 + uni.hideKeyboard();
301 } 310 }
302 - }; 311 + }
  312 +};
303 </script> 313 </script>
304 314
305 <style lang="scss" scoped> 315 <style lang="scss" scoped>
306 - .userName{  
307 - background-color: green;  
308 - }  
309 - @import './static/set.scss'; 316 +.userName {
  317 + background-color: green;
  318 +}
  319 +@import './static/set.scss';
310 320
311 - /deep/ .u-line {  
312 - width: 662rpx !important;  
313 - } 321 +/deep/ .u-line {
  322 + width: 662rpx !important;
  323 +}
314 324
315 - /deep/ .u-form-item {  
316 - height: 100rpx !important;  
317 - } 325 +/deep/ .u-form-item {
  326 + height: 100rpx !important;
  327 +}
318 328
319 - /deep/ .u-form-item:nth-child(3) {  
320 - .u-form-item__body {  
321 - background: #f5f7fa !important;  
322 - width: 663rpx !important;  
323 - } 329 +/deep/ .u-form-item:nth-child(3) {
  330 + .u-form-item__body {
  331 + background: #f5f7fa !important;
  332 + width: 663rpx !important;
324 } 333 }
  334 +}
325 </style> 335 </style>