From 1c64c10f8dd88018c0d30de79237f3128173f118 Mon Sep 17 00:00:00 2001 From: YM <479443481@qq.com> Date: 星期二, 26 三月 2024 17:36:51 +0800 Subject: [PATCH] 调整登录 --- app.json | 3 pages/home/home.js | 58 +------- pages/bindInfo/index.wxml | 21 +++ .vscode/settings.json | 2 pages/bindInfo/index.js | 150 +++++++++++++++++++++ pages/bindInfo/index.json | 3 assets/request/index.js | 12 - pages/bindInfo/index.wxss | 42 ++++++ assets/js/config.js | 17 + assets/js/login.js | 63 +++++++++ 10 files changed, 305 insertions(+), 66 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 22d6d96..8096c21 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -32,7 +32,7 @@ }, "editor.tabSize": 2, "[wxml]": { - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "wechat.miniprogram.wxml-language-features" }, "[css]": { "editor.defaultFormatter": "HookyQR.beautify" diff --git a/app.json b/app.json index f166636..f44c4a5 100644 --- a/app.json +++ b/app.json @@ -12,7 +12,8 @@ "pages/personalCenter/feedBackSubmit/index", "pages/personalCenter/certificate/index", "pages/testLogin/index", - "pages/bookServices/assort/index" + "pages/bookServices/assort/index", + "pages/bindInfo/index" ], "subPackages": [ { diff --git a/assets/js/config.js b/assets/js/config.js index a87241b..1cb605a 100644 --- a/assets/js/config.js +++ b/assets/js/config.js @@ -1,8 +1,18 @@ // export const requestCtx = "http://182.92.203.7:3001"; // 璇锋眰鍦板潃 +<<<<<<< Updated upstream export const appId = 27; // export const requestCtx = "http://jsysf.bnuic.com"; // 璇锋眰鍦板潃 export const requestCtx = "https://jsek.bnuic.com" // 璇锋眰鍦板潃 // export const appId = 3; +======= +// export const appId = 27; +export const requestCtx = "https://jsek.bnuic.com"; // 璇锋眰鍦板潃 +export const appId = 3; + +// export const epubUrl = "http://182.92.203.7:3007/epubReadMobile/"; +export const epubUrl = "http://jsysf.bnuic.com/epubReadMobile/#/"; + +>>>>>>> Stashed changes export const requestTimeOut = 300000; // 璇锋眰瓒呮椂鏃堕棿 export const tokenKey = "jsek-token"; export const userInfoKey = "website-front-userInfo"; // 鐢ㄦ埛淇℃伅key @@ -18,11 +28,7 @@ export const reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; // 鐢佃瘽鍙锋鍒� export const reg_telphone = /^0\d{2}-\d{8}$|^0\d{3}-\d{7}$/; //搴ф満鍙锋鍒� -export const fontUrl = "http://192.168.3.132:5173"; -// export const fontUrl = "http://182.92.203.7:3007/jsek/website"; -// export const fontUrl = "http://jsysf.bnuic.com/website"; -export const epubUrl = "http://182.92.203.7:3007/epubReadMobile/"; -// export const epubUrl = "http://jsysf.bnuic.com/epubReadMobile/#/"; + const config = { requestCtx, @@ -34,7 +40,6 @@ digitalCourses, digitalTextbooks, seminar, - fontUrl, reg_tel, reg_telphone, epubUrl diff --git a/assets/js/login.js b/assets/js/login.js new file mode 100644 index 0000000..bf70086 --- /dev/null +++ b/assets/js/login.js @@ -0,0 +1,63 @@ +import { setSessionGuid } from "./userAction" + + +export const checkLoginInfo = (app, callback) => { + const token = wx.getStorageSync(app.config.tokenKey) + if (!token) { + wx.login({ + success: (res) => { + wx.getUserInfo({ + success: (infoRes) => { + app.MG.identity.checkWeChatAppAccount({ + code: res.code, + appCode: app.config.appRefCode, + encryptedData: infoRes.encryptedData, + iv: infoRes.iv + }).then(loginRes => { + if (!loginRes) { + wx.navigateTo({ + url: "/pages/bindInfo/index?code=" + res.code, + }); + } else { + wx.login({ + success: (res) => { + app.MG.identity.loginByWeChatAppCode({ + code: res.code, + appRefCode: app.config.appRefCode, + platform: "weChatAppCustom", + encryptedData: infoRes.encryptedData, + iv: infoRes.iv + }).then(res => { + if (res && res.status == "Ok") { + wx.setStorageSync(app.config.tokenKey, res.token); + setSessionGuid() + callback(res.token) + } else { + console.log(res); + callback(false) + } + }) + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) + } + }) + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) + }, + fail: (err) => { + console.log(err); + callback(false) + } + }) + } else { + callback(token) + } +} \ No newline at end of file diff --git a/assets/request/index.js b/assets/request/index.js index f782c3a..798b3ab 100644 --- a/assets/request/index.js +++ b/assets/request/index.js @@ -37,9 +37,10 @@ backUrl: urlargs } currentUrl = JSON.stringify(currentUrl) - wx.reLaunch({ - url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home' - }) + // 涓嶅幓棣栭〉鐧诲綍锛岀洿鎺ヨ皟鐢ㄥ叕鍏辩櫥褰曟柟娉� + // wx.reLaunch({ + // url: urlargs ? '/pages/home/home?backUrl=' + encodeURIComponent(currentUrl) : '/pages/home/home' + // }) } } else { wx.showToast({ @@ -47,11 +48,6 @@ icon: 'none' }) reject(res.data.message) - wx.login({ - success: (res) => { - console.log(res) - }, - }) } }, fail: (res) => { diff --git a/pages/bindInfo/index.js b/pages/bindInfo/index.js new file mode 100644 index 0000000..7e317c7 --- /dev/null +++ b/pages/bindInfo/index.js @@ -0,0 +1,150 @@ +// pages/index/bindInfo/index.js +const app = getApp(); +Page({ + + /** + * 椤甸潰鐨勫垵濮嬫暟鎹� + */ + data: { + avatarUrl: "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0", + nickName: "", + wxCode: null, + }, + + onChooseAvatar(res) { + wx.compressImage({ + src: res.detail.avatarUrl, //聽鍥剧墖璺緞 + quality: 50, //聽鍘嬬缉璐ㄩ噺 + compressedWidth: 80, + compressedHeight: 80, + success: (compressRes) => { + wx.getFileSystemManager().readFile({ + filePath: compressRes.tempFilePath, //閫夋嫨鍥剧墖杩斿洖鐨勭浉瀵硅矾寰� + encoding: 'base64', //缂栫爜鏍煎紡 + success: base64Res => { //鎴愬姛鐨勫洖璋� + this.setData({ + avatarUrl: 'data:image/png;base64,' + base64Res.data, + }); + } + }) + } + }) + }, + + formSubmit() { + if (this.data.nickName == "") { + return wx.showToast({ + icon: "error", + title: "鏄电О涓嶈兘涓虹┖锛�", + }); + } + + wx.getUserInfo({ + success: (infoRes) => { + wx.login({ + success: (res) => { + app.MG.identity.loginByWeChatAppCode({ + code: res.code, + appRefCode: app.config.appRefCode, + platform: "weChatApp", + icon: this.data.avatarUrl, + encryptedData: infoRes.encryptedData, + iv: infoRes.iv, + name: this.data.nickName, + }).then(res => { + if (res && res.status == "Ok") { + wx.setStorageSync(app.config.tokenKey, res.token); + this.getUserInfo() + } + }) + }, + }) + } + }) + }, + // 鑾峰彇鐧诲綍鐢ㄦ埛韬唤 + getUserInfo() { + app.MG.identity.getCurrentAppUser().then(res => { + // console.log(res, "userInfo"); + // 鐢ㄦ埛淇℃伅浼樺厛绾э細鏁欏笀璁よ瘉 > 寰俊 > 瀛︾敓锛堟敞鍐屾椂榛樿锛� + if (res) { + let defaultUser = {}; + // let secretData = res.secretList.find(i => i.type == 'LoginNameAndPassword') + let WeChatInfo = res.infoList.find((item) => item.type === "WeChat"); + let phoneNumber = res.secretList.find(i => i.type == 'MobilePhone') + + if (WeChatInfo) { + defaultUser = { + nickName: WeChatInfo.name, + avatarUrl: WeChatInfo.icon, + weChatId: WeChatInfo.id + } + } + + if (phoneNumber) { + defaultUser.phoneNumber = phoneNumber.credential + } + this.setData({ + userInfo: defaultUser, + loading: false + }) + wx.setStorageSync(app.config.userInfoKey, JSON.stringify(this.data.userInfo)); + } + wx.switchTab({ + url: '/pages/index/index' + }) + }); + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 + */ + onLoad(options) { + console.log(options, "options"); + this.setData({ + wxCode: options.code + }) + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 + */ + onReady() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず + */ + onShow() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 + */ + onHide() { + + }, + + /** + * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 + */ + onUnload() { + + }, + + /** + * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 + */ + onPullDownRefresh() { + + }, + + /** + * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� + */ + onReachBottom() { + + }, +}) \ No newline at end of file diff --git a/pages/bindInfo/index.json b/pages/bindInfo/index.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/bindInfo/index.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/bindInfo/index.wxml b/pages/bindInfo/index.wxml new file mode 100644 index 0000000..d5fa5dc --- /dev/null +++ b/pages/bindInfo/index.wxml @@ -0,0 +1,21 @@ +<view> + <view class="avatar-wrap"> + <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar"> + <image class="avatar" src="{{avatarUrl}}"></image> + </button> + <view class="keynote"> + 鎻愮ず锛氭湭涓婁紶澶村儚锛屽皢浣跨敤榛樿鍥剧墖 + </view> + </view> + <form catchsubmit="formSubmit"> + <view class="fromItem"> + <view> + 鏄电О + </view> + <input type="nickname" class="nickNameInput" placeholder="璇疯緭鍏ユ樀绉�" model:value="{{nickName}}"/> + </view> + <view class="submit" > + <button type="primary" formType="submit" size="default">纭</button> + </view> + </form> +</view> \ No newline at end of file diff --git a/pages/bindInfo/index.wxss b/pages/bindInfo/index.wxss new file mode 100644 index 0000000..4f6d453 --- /dev/null +++ b/pages/bindInfo/index.wxss @@ -0,0 +1,42 @@ +/* pages/index/bindInfo/index.wxss *//* pages/fillInAvatarNickname/fillInAvatarNickname.wxss */ +.avatar-wrap { + padding-top: 40px; + padding-bottom: 40rpx; +} + +.avatar-wrapper { + padding: 0; + width: 56px; + margin-bottom: 0; +} +.avatar { + display: block; + width: 56px; + height: 56px; + margin: 0 auto; +} +.keynote { + font-size: 25rpx; + color: #333; + line-height: 50rpx; + margin: 0 auto; + margin-top: 20rpx; + text-align: center; +} +.container { + display: flex; +} +.fromItem { + display: flex; + align-items: center; + padding: 20rpx; + border: 1px solid #eee; +} +.nickNameInput { + padding-left: 100rpx; +} +.submit { + width: 400rpx; + margin: 0 auto; + margin-top: 200rpx; +} \ No newline at end of file diff --git a/pages/home/home.js b/pages/home/home.js index 60f3e8a..0a15970 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -1,6 +1,6 @@ import { fetchHome } from '../../services/home/home'; import moment from 'moment' -import { setSessionGuid } from "../../assets/js/userAction" +import { checkLoginInfo } from '../../assets/js/login'; const app = getApp() Page({ data: { @@ -58,7 +58,13 @@ backUrl: backUrl.backUrl }) } - this.getTestLoginInfo() + + // checkLoginInfo(app, (data) => { + // if (data) { + // this.getCurrentUserInfo(); + // } + // }) + this.init(); }, onReachBottom() { @@ -82,53 +88,6 @@ 'baseRefresh.value': false, }) }, 500); - }, - // 鑾峰彇娴嬭瘯鐧诲綍鏃剁殑token - getTestLoginInfo() { - const token = wx.getStorageSync(app.config.tokenKey) - if (!token) { - wx.login({ - success: (res) => { - wx.getUserInfo({ - success: (infoRes) => { - app.MG.identity.checkWeChatAppAccount({ - code: res.code, - appCode: app.config.appRefCode, - encryptedData: infoRes.encryptedData, - iv: infoRes.iv - }).then(loginRes => { - if (!loginRes) { - // wx.navigateTo({ - // url: "/pages/index/bindInfo/index?code=" + res.code, - // }); - } else { - wx.login({ - success: (res) => { - app.MG.identity.loginByWeChatAppCode({ - code: res.code, - appRefCode: app.config.appRefCode, - platform: "weChatApp", - encryptedData: infoRes.encryptedData, - iv: infoRes.iv - }).then(res => { - if (res && res.status == "Ok") { - wx.setStorageSync(app.config.tokenKey, res.token); - setSessionGuid() - this.getCurrentUserInfo() - } - }) - }, - }) - } - }) - } - }) - - }, - }) - } else { - this.getShoppingCartList(); - } }, getCurrentUserInfo() { @@ -163,7 +122,6 @@ url: '/pages/home/home' }) } - }); }, getBannerList() { -- Gitblit v1.9.1