From f47ce70afac05ce941b5eafb2d9114c7a017f774 Mon Sep 17 00:00:00 2001 From: 付延余 <f-yanyu@outlook.com> Date: 星期二, 06 九月 2022 20:01:27 +0800 Subject: [PATCH] 新增微信账号快捷登录、账号绑定、换绑功能,及页面更新。 --- pages/home/home.vue | 104 +++++++--- utils/request.js | 4 pages/login/login.vue | 171 ++++++++---------- utils/index.js | 3 pages/register/register.vue | 153 +++++++++++++++++ pages.json | 35 +++ utils/api.js | 6 main.js | 1 api/global.js | 42 ++++ utils/status.js | 2 10 files changed, 379 insertions(+), 142 deletions(-) diff --git a/api/global.js b/api/global.js index fddc019..4b4916e 100644 --- a/api/global.js +++ b/api/global.js @@ -27,9 +27,9 @@ }); } -// const baseUrl = 'http://192.168.0.159:9999' +// const baseUrl = 'http://192.168.3.159:9999' // const baseUrl = 'https://mx.jzeg.cn:443/app'; -const baseUrl = "https://mx.jzeg.cn:9998"; +const baseUrl = "https://mx.jzeg.cn:9998"; // 姝e紡鏈嶅姟 // POST璇锋眰 function apiLogin({ @@ -59,7 +59,38 @@ resolve(res); }, fail: (err) => { - console.log('閿欒',err); + console.log('閿欒', err); + uni.hideLoading(); + uni.showToast({ + icon: 'none', + title: '鏈嶅姟鍣ㄩ敊璇�' + }) + } + }) + }) +} + +function wxSmallLogin(code) { + uni.showLoading({ + title: '鐧诲綍涓�...', + }) + + return new Promise((resolve, reject) => { + uni.request({ + url: baseUrl + `/auth/mobile/token/social?grant_type=mobile&mobile=MINI@${code}`, + method: "POST", + header: { + "TENANT-ID": "5", + "Authorization": "Basic cGlnOnBpZw==", + 'Content-Type': 'application/x-www-form-urlencoded' + }, + success: (res) => { + uni.hideLoading(); + // console.log(res) + resolve(res); + }, + fail: (err) => { + console.log('閿欒', err); uni.hideLoading(); uni.showToast({ icon: 'none', @@ -71,6 +102,8 @@ } + + // 鑾峰彇娴佺▼鏁版嵁 // export const getProcessDataList = (params) => { // return getRequest('/oa/actProcess/getByCondition', params) @@ -78,5 +111,6 @@ export default { - apiLogin + apiLogin, + wxSmallLogin } diff --git a/main.js b/main.js index 06880df..5a527eb 100644 --- a/main.js +++ b/main.js @@ -16,7 +16,6 @@ Vue.prototype.$store = store - Vue.config.productionTip = false diff --git a/pages.json b/pages.json index f715b90..e27aa1f 100644 --- a/pages.json +++ b/pages.json @@ -3,7 +3,9 @@ { "path": "pages/login/login", "style": { - "navigationStyle": "custom" + // "navigationStyle": "custom" + "navigationBarTitleText": "璇风櫥褰�", + "enablePullDownRefresh": false } }, { @@ -82,8 +84,37 @@ "navigationBarTitleText": "淇敼", "enablePullDownRefresh": false } + }, { + "path": "pages/register/register", + "style": { + "navigationBarTitleText": "缁戝畾璐﹀彿", + "enablePullDownRefresh": false + // "navigationStyle": "custom" + } } - ], + ], + "tabBar": { + // "color": "#999794", + // "selectedColor": "#007AFF", + // "borderStyle": "white", + // "backgroundColor": "#F5F5F5", + "custom": true, + "list": [ + // 瀹㈡埛tabbar + { + "pagePath": "pages/home/home" + // "iconPath": "static/tabBar-icon/Gfayun.png", + // "selectedIconPath": "static/tabBar-icon/Bfayun1.png", + // "text": "鍙戣繍" + }, + { + "pagePath": "pages/login/login" + // "iconPath": "static/tabBar-icon/Gfayun.png", + // "selectedIconPath": "static/tabBar-icon/Bfayun1.png", + // "text": "鍙戣繍" + } + ] + }, "globalStyle": { "navigationBarTextStyle": "white", "navigationBarTitleText": "uni-app", diff --git a/pages/home/home.vue b/pages/home/home.vue index d370212..e3b171d 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -2,16 +2,12 @@ <view class="home"> <!-- 杞挱鍥� --> <view class="home_swipe"><u-swiper :list="list3" indicator indicatorMode="line" circular></u-swiper></view> + <!-- 鍥捐〃 --> <combined-title title="鐓や粨搴撳瓨鏄庣粏"></combined-title> <view class="charts-box"> <qiun-data-charts type="pie" :opts="opts" :chartData="chartData" v-if="uchartsData.length > 0" /> - <u-empty - mode="data" - icon="http://cdn.uviewui.com/uview/empty/data.png" - v-if="uchartsData.length == 0" - > - </u-empty> + <u-empty mode="data" iconSize="200" textSize="25" width="350" height="350" icon="http://cdn.uviewui.com/uview/empty/data.png" v-if="uchartsData.length == 0"></u-empty> </view> <!-- 鎴戠殑鐢宠 --> <combined-title title="鎴戠殑鐢宠" detailsPath="/pages/my-application/my-application" v-if="shenqingMenu"></combined-title> @@ -62,7 +58,7 @@ <image src="@/static/home/jindu.png" mode=""></image> <view>鏌ョ湅杩涘害</view> </view> - <view @click="theFormDataClick(item.tableId)" v-if="(item.status == 1 || item.status == 2) && (item.procDefId == 'WAY_BILL:4:87504')"> + <view @click="theFormDataClick(item.tableId)" v-if="(item.status == 1 || item.status == 2) && item.procDefId == 'WAY_BILL:4:87504'"> <image src="@/static/home/biaodan.png" mode=""></image> <view>琛ㄥ崟鏁版嵁</view> </view> @@ -218,7 +214,7 @@ <!-- 鏃ヨ鍒� --> <combined-title title="鏃ュ彂杩愯鍒�" detailsPath="/pages/jihua/jihua" v-if="rijihuaMenu"></combined-title> - <view class="card-group"> + <view class="card-group bottomChild" > <combination-card class="card" :showTop="false" v-for="(item, index) in fyData.slice(0, 2)" :key="item.id" v-if="rijihuaMenu"> <template v-slot:top></template> <template v-slot:center> @@ -306,6 +302,20 @@ <!-- 鑿滃崟鏍� --> <!-- <popup-menu @menuShow="menushow" ref="menuRef"></popup-menu> --> + <u-gap height="15" bgColor="#eeeeee"></u-gap> + <view class="utils"> + <view class="utils-container"> + <view class="utils-container-body" @click="redirectLogin"> + <view class="top"><u-icon name="backspace" color="#FF4233" size="70"></u-icon></view> + <view class="bottom-text"><text>閫�鍑�</text></view> + </view> + <view class="utils-container-body" @click="huanBang"> + <view class="top"><u-icon name="lock-open" color="#1987FF" size="70"></u-icon></view> + <view class="bottom-text"><text>鎹㈢粦</text></view> + </view> + </view> + </view> + <u-gap height="60" bgColor="#eeeeee"></u-gap> </view> </template> @@ -315,7 +325,7 @@ // import popupMenu from '@/components/common/popup-menu/popup-menu.vue'; import combinedTitle from '@/components/common/combined-title/combined-title.vue'; import combinationCard from '@/components/common/combination-card/combination-card.vue'; -import { setAccessToken } from '@/utils/status.js'; +import { setAccessToken, redirectLogin } from '@/utils/status.js'; export default { name: 'home', @@ -432,27 +442,31 @@ // }, // 鐐瑰嚮瀵艰埅鏍忚彍鍗曞悗 onNavigationBarButtonTap(e) { - console.log('閫�鍑哄鑸爮鎸夐挳浜嬩欢',e); + console.log('閫�鍑哄鑸爮鎸夐挳浜嬩欢', e); // this.$refs.menuRef.menuClick(); }, // 鐩戝惉宸︿笂瑙掔殑鍥為��浜嬩欢 - onUnload(event){ //澶氬眰绾ц烦杞箣鍚庯紝鐩戝惉宸︿笂瑙掕繑鍥炰簨浠讹紝鐩存帴閫�鍥炲埌index - console.log('鐩戝惉宸︿笂瑙�',event); - uni.request({ - url: `${BaseUrl}/auth/token/logout`, - method: 'DELETE', - header: { - 'TENANT-ID': 5, - Authorization: 'Bearer ' + uni.getStorageSync('access_token'), - VERSION: 'zzl' - } - }).then(res=>{ - console.log('缂撳瓨娓呯悊鎴愬姛'); - }).catch(err => { - uni.showToast({ - title: '缂撳瓨娓呯悊澶辫触锛�', - }) - }) + onUnload(event) { + //澶氬眰绾ц烦杞箣鍚庯紝鐩戝惉宸︿笂瑙掕繑鍥炰簨浠讹紝鐩存帴閫�鍥炲埌index + console.log('鐩戝惉宸︿笂瑙�', event); + uni + .request({ + url: `${BaseUrl}/auth/token/logout`, + method: 'DELETE', + header: { + 'TENANT-ID': 5, + Authorization: 'Bearer ' + uni.getStorageSync('access_token'), + VERSION: 'zzl' + } + }) + .then(res => { + console.log('缂撳瓨娓呯悊鎴愬姛'); + }) + .catch(err => { + uni.showToast({ + title: '缂撳瓨娓呯悊澶辫触锛�' + }); + }); }, onShow() { // 鑿滃崟娉ㄩ噴锛坅pp寰呯敤锛� @@ -486,7 +500,7 @@ }); }, getServerData() { - console.log('鍔犺浇鍥捐〃',this.uchartsData); + console.log('鍔犺浇鍥捐〃', this.uchartsData); //妯℃嫙浠庢湇鍔″櫒鑾峰彇鏁版嵁鏃剁殑寤舵椂 setTimeout(() => { //妯℃嫙鏈嶅姟鍣ㄨ繑鍥炴暟鎹紝濡傛灉鏁版嵁鏍煎紡鍜屾爣鍑嗘牸寮忎笉鍚岋紝闇�鑷鎸変笅闈㈢殑鏍煎紡鎷兼帴 @@ -783,6 +797,14 @@ this.deleteApplicationModalShow = true; this.procInstId = id; console.log(id); + }, + redirectLogin() { + redirectLogin(); + }, + huanBang() { + uni.navigateTo({ + url: '/pages/register/register' + }); } } }; @@ -793,7 +815,20 @@ width: 100%; display: flex; flex-direction: column; - padding-bottom: vww(20); + + // 妯悜鑿滃崟鏍� + .utils { + .utils-container { + display: flex; + justify-content: space-between; + width: 66%; + margin: 0 auto; + .utils-container-body { + display: flex; + align-items: center; + } + } + } .home_swipe { width: 100%; @@ -820,8 +855,8 @@ width: 91%; height: vww(330); margin: 0 auto; - .u-empty{ - height:100%; + .u-empty { + height: 100%; } } @@ -839,6 +874,9 @@ } } } + } + .bottomChild{ + margin-bottom: vww(20); } // 鍗$墖涓棿 @@ -925,7 +963,7 @@ // width:100%; // height:vww(244); .slot-content { - width:vww(330); + width: vww(330); .rejectMesaage { display: flex; padding: vww(3); @@ -1062,4 +1100,4 @@ } } } -</style> +</style> diff --git a/pages/login/login.vue b/pages/login/login.vue index 4956eb1..5654590 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -1,125 +1,100 @@ <template> <view class="login"> <image src="@/static/login/banner.png" class="background"></image> - <view class="inputBox"> - <view class="phone"> - <image src="@/static/login/phone.png" mode="鍔犺浇閿欒"></image> - <input type="text" placeholder="璇疯緭鍏ョ敤鎴峰悕/鎵嬫満鍙�" v-model="formData.username" /> - </view> - <view class="password"> - <image src="@/static/login/lock.png" mode="鍔犺浇閿欒" /> - <input type="password" placeholder="璇疯緭鍏ヨ处鍙峰瘑鐮�" v-model="formData.password" /> - </view> - <view class="loginBtn"><button type="default" @click="loginSubmit">鐧诲綍</button></view> - </view> + <view class="loginBtn"><u-button throttleTime="3000" text="寰俊璐﹀彿蹇嵎鐧诲綍" type="success" shape="circle" icon="weixin-fill" @click="wxLogin"></u-button></view> </view> </template> <script> -import { setAccessToken,setTokenType,setRefreshToken,setClientId,setScope,redirectHome,redirectLogin } from '@/utils/status.js' +import { setAccessToken, setTokenType, setRefreshToken, setClientId, setScope, redirectHome, redirectLogin } from '@/utils/status.js'; export default { - name: 'login', data() { return { - formData:{ - username:'', - password:'' - } + wxcode: '' }; }, - onShow(){ - // 娓呴櫎缂撳瓨 - if(uni.getStorageSync('userInfo')||uni.getStorageSync('access_token')||uni.getStorageSync('refresh_token')){ - this.$u.toast('鎴愬姛杩涘叆鐧诲綍椤�'); - uni.clearStorageSync(); - } - }, - methods:{ - loginSubmit(){ - console.log('鐐瑰嚮鐧诲綍'); - // console.log('login'); - uni.showLoading({ - title:'鐧诲綍涓�...' - }); - this.apiLogin(this.formData).then(this.saveUserInfo).catch(this.loginFail); - }, - saveUserInfo(response){ - uni.hideLoading(); - if(response.statusCode === 200){ - // console.log('res',response); - const { data } = response; - const { access_token,refresh_token,token_type,scope } = data; - try { - setAccessToken(access_token); - setTokenType(token_type); - setRefreshToken(refresh_token); - setScope(scope); - this.$store.dispatch('menus') - redirectHome(); - uni.hideLoading(); - } catch (e) { - // error - console.log(e); - } - } else{ - uni.showToast({ - title:response.data.msg, - icon:'error', - duration:2000 - }) - } + onShow() { + // 娓呴櫎缂撳瓨 + if (uni.getStorageSync('userInfo') || uni.getStorageSync('access_token') || uni.getStorageSync('refresh_token')) { + uni.clearStorageSync(); } - + }, + methods: { + wxLogin() { + uni.showLoading({ + title: '鍔犺浇涓�...' + }); + uni.login({ + success: res => { + console.log('鐧诲綍loginRes', res); + if (res.code) { + this.wxcode = res.code; + this.wxSmallLogin(this.wxcode) + .then(res => { + if (res.data.data == '鐢ㄦ埛涓嶅瓨鍦�') { + this.$u.toast('鏈粦瀹氱郴缁熻处鍙凤紝鍗冲皢璺宠浆缁戝畾椤甸潰锛�') + setTimeout(()=>{ + uni.navigateTo({ + url: '/pages/register/register' + }); + },1000) + } else if (res.data.active && res.data.active == true) { + const { access_token, refresh_token, token_type, scope } = res.data; + try { + setAccessToken(access_token); + setTokenType(token_type); + setRefreshToken(refresh_token); + setScope(scope); + this.$store.dispatch('menus'); + redirectHome(); + uni.hideLoading(); + } catch (e) { + // error + console.log(e); + } + } + console.log('寰俊鐧诲綍', res); + }) + .catch(err => { + console.log('閿欒', err); + }); + } else { + uni.showToast({ + title: '寰俊鐧诲綍澶辫触锛�', + duration: 2000 + }); + } + } + }); + } } }; </script> <style lang="scss" scoped> -.login { +::v-deep.login { + height: 100vh; + .background { width: 100%; - height: vww(289); + // height: vww(289); + height: vww(246); } - .inputBox { - width: vww(280); - margin: vww(40) auto; - input { - width: vww(240); - margin-left: vww(8); - } - .phone { - width: vww(280); - height: vww(36); - display: flex; - align-items: center; - border-bottom: vww(1) solid #cccccc; - image { - width: vww(20); - height: vww(20); - } - } - .password { - width: vww(280); - height: vww(36); - display: flex; - align-items: center; - margin-top: vww(40); - border-bottom: vww(1) solid #cccccc; - image { - width: vww(20); - height: vww(20); - } - } - .loginBtn { - margin-top: vww(80); - button { - background-color: #007aff; - color: #ffffff; - font-size: vww(16); - border-radius: vww(22); + .loginBtn { + margin: vww(60) auto; + width: 80%; + .u-button { + .u-icon { + .u-icon__icon { + font-size: vww(30) !important; + } } } + + .u-button--success { + border-style: none; + } } } </style> diff --git a/pages/register/register.vue b/pages/register/register.vue new file mode 100644 index 0000000..30c5849 --- /dev/null +++ b/pages/register/register.vue @@ -0,0 +1,153 @@ +<template> + <view class="login"> + <image src="@/static/login/banner.png" class="background"></image> + <view class="inputBox"> + <view class="phone"> + <image src="@/static/login/phone.png" mode="鍔犺浇閿欒"></image> + <input type="text" placeholder="璇疯緭鍏ョ敤鎴峰悕/鎵嬫満鍙�" v-model="formData.username" /> + </view> + <view class="password"> + <image src="@/static/login/lock.png" mode="鍔犺浇閿欒" /> + <input type="password" placeholder="璇疯緭鍏ヨ处鍙峰瘑鐮�" v-model="formData.password" /> + </view> + <view class="loginBtn"><button type="default" @click="loginSubmit">缁戝畾</button></view> + </view> + </view> +</template> + +<script> +import { setAccessToken, setTokenType, setRefreshToken, setClientId, setScope, redirectHome, redirectLogin } from '@/utils/status.js'; +export default { + name: 'login', + data() { + return { + formData: { + username: '', + password: '' + }, + bindData: { + state: 'MINI', + code: '' + } + }; + }, + methods: { + loginSubmit() { + console.log('鐐瑰嚮鐧诲綍'); + // console.log('login'); + uni.showLoading({ + title: '鐧诲綍涓�...' + }); + this.apiLogin(this.formData) + .then(this.saveUserInfo) + .catch(this.loginFail); + }, + saveUserInfo(response) { + uni.hideLoading(); + if (response.statusCode === 200) { + const { access_token, refresh_token, token_type, scope } = response.data; + try { + setAccessToken(access_token); + setTokenType(token_type); + setRefreshToken(refresh_token); + setScope(scope); + // this.$store.dispatch('menus'); + // redirectHome(); + uni.hideLoading(); + this.bindWx(); // 鐧诲綍鎴愬姛鍚庤幏鍙朿ode鐮侊紝杩旂粰鍚庣 + } catch (e) { + // error + console.log('妫�娴嬪埌閿欒',e); + } + } else { + uni.showToast({ + title: response.data.msg, + icon: 'error', + duration: 2000 + }); + } + }, + loginFail(err) { + console.log('鐧诲綍鎺ュ彛閿欒', err); + }, + bindWx() { + uni.login({ + success: res => { + this.bindData.code = res.code; + this.bindWxPost(); + }, + fail: err => { + console.log('寰俊鐧诲綍閿欒', err); + } + }); + }, + bindWxPost() { + this.$reqPost('bindWx', this.bindData) + .then(res => { + if (res.code == 0) { + this.$u.toast('缁戝畾鎴愬姛锛屽嵆灏嗚繑鍥炵櫥褰曢〉锛�'); + setTimeout(() => { + uni.reLaunch({ + url:"/pages/login/login" + }) + }, 1000); + } + }) + .catch(err => { + console.log('缁戝畾閿欒', err); + }); + } + } +}; +</script> + +<style lang="scss" scoped> +.login { + .background { + width: 100%; + // height: vww(289); + height: vww(246); + } + .inputBox { + width: vww(280); + margin: vww(40) auto; + input { + width: vww(240); + margin-left: vww(8); + } + .phone { + width: vww(280); + height: vww(36); + display: flex; + align-items: center; + border-bottom: vww(1) solid #cccccc; + image { + width: vww(20); + height: vww(20); + } + } + .password { + width: vww(280); + height: vww(36); + display: flex; + align-items: center; + margin-top: vww(40); + border-bottom: vww(1) solid #cccccc; + image { + width: vww(20); + height: vww(20); + } + } + .loginBtn { + margin-top: vww(80); + + button { + background-color: #007aff; + color: #ffffff; + font-size: vww(16); + border-radius: vww(22); + } + } + } +} +</style> diff --git a/utils/api.js b/utils/api.js index 74918e9..12c341e 100644 --- a/utils/api.js +++ b/utils/api.js @@ -1,4 +1,10 @@ export const api = { + // 寰俊缁戝畾瀹㈡埛 + bindWx:{ + url:'/admin/social/bind', + method:"POST" + }, + // 鑾峰彇鍗曚綅鏍� fetchCompTree:{ url:'/admin/dept/compTree', diff --git a/utils/index.js b/utils/index.js index f9f1910..1c6b914 100644 --- a/utils/index.js +++ b/utils/index.js @@ -28,7 +28,7 @@ } // post璇锋眰 -export const reqPost = (url, params, form, opt = {}) => { +export const reqPost = (url, params,form, opt = {}) => { if(form == 'form'){ opt.header = {'Content-Type': 'application/x-www-form-urlencoded'} } else { @@ -36,5 +36,6 @@ } opt.method = "POST"; opt.data = params; + opt.params = params; return fetch(url, opt) } diff --git a/utils/request.js b/utils/request.js index 451dd24..d9517b4 100644 --- a/utils/request.js +++ b/utils/request.js @@ -82,9 +82,9 @@ 500: responseError } -// let BaseUrl = 'http://192.168.0.159:9999'; +// let BaseUrl = 'http://192.168.3.159:9999'; // const BaseUrl = 'https://mx.jzeg.cn:443/app'; -const BaseUrl = "https://mx.jzeg.cn:9998"; +const BaseUrl = "https://mx.jzeg.cn:9998"; // 姝e紡鏈嶅姟 // 璇锋眰鎷︽埅 const fetch = (url, opt ,urlParam) => { diff --git a/utils/status.js b/utils/status.js index 0e2e7a6..eb9cf7b 100644 --- a/utils/status.js +++ b/utils/status.js @@ -16,7 +16,7 @@ export const setRefreshToken = SetStorage(refresh_token); export const setScope = SetStorage(scope) export const redirectHome = (path) => { - uni.reLaunch({ + uni.switchTab({ url: path || SuccessRedirect }) } -- Gitblit v1.9.1