From 53a6f0b149058d500c952444a19fdde440ec3ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=90=E6=98=8E=E6=98=8E?= <970899069@qq.com> Date: Thu, 6 Jan 2022 14:54:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 10 ++- pages.json | 5 +- pages/auth/auth.vue | 49 +++------------ pages/index/index.vue | 6 +- pages/user/index.vue | 46 ++++++++++---- public/date.js | 31 ++++++++++ public/userAuth.js | 110 +++++++++++++++++++++++++++++++++ router/index.js | 5 +- static/icon/checked-icon.png | Bin 0 -> 2083 bytes static/icon/unchecked-icon.png | Bin 0 -> 2077 bytes 10 files changed, 202 insertions(+), 60 deletions(-) create mode 100644 public/date.js create mode 100644 public/userAuth.js create mode 100644 static/icon/checked-icon.png create mode 100644 static/icon/unchecked-icon.png diff --git a/manifest.json b/manifest.json index e972d67..fbfbb3f 100644 --- a/manifest.json +++ b/manifest.json @@ -17,7 +17,9 @@ "delay" : 0 }, /* 模块配置 */ - "modules" : {}, + "modules" : { + "OAuth" : {} + }, /* 应用发布信息 */ "distribute" : { /* android打包配置 */ @@ -43,7 +45,11 @@ /* ios打包配置 */ "ios" : {}, /* SDK配置 */ - "sdkConfigs" : {} + "sdkConfigs" : { + "oauth" : { + "univerify" : {} + } + } } }, /* 快应用特有相关 */ diff --git a/pages.json b/pages.json index 55b8a11..3e5cc54 100644 --- a/pages.json +++ b/pages.json @@ -51,7 +51,10 @@ "name": "Auth", "style": { "navigationBarTitleText": "登录", - "navigationStyle":"custom" + "navigationStyle":"custom", + "app-plus":{ + "animationType":"slide-in-bottom" + } } }, { "path": "pages/store/goods", diff --git a/pages/auth/auth.vue b/pages/auth/auth.vue index 5b7f192..db57790 100644 --- a/pages/auth/auth.vue +++ b/pages/auth/auth.vue @@ -2,8 +2,10 @@ - 关闭 - 一键登录 + + + + 一键登录 @@ -32,7 +34,7 @@ @@ -142,28 +162,28 @@ .user-flex{ position: relative; padding: $padding*2 $padding ($padding*2 + 60); - height: 108rpx; + height: 128rpx; .cover{ position: absolute; - width: 108rpx; - height: 108rpx; + width: 128rpx; + height: 128rpx; border-radius: 50%; border:solid 6rpx white; box-sizing: border-box; } .user-content{ - padding-left: 128rpx; - height: 108rpx; + padding-left: 158rpx; + height: 128rpx; display: flex; flex-direction: column; justify-content: center; .name{ line-height: 40rpx; font-weight: bold; - font-size: $title-size + 4; + font-size: $title-size + 8; } .tabs{ - padding-top: 5rpx; + padding-top: 10rpx; &-item{ background: rgba($color: #000000, $alpha: .3); font-size: $title-size-sm - 4; diff --git a/public/date.js b/public/date.js new file mode 100644 index 0000000..71410bd --- /dev/null +++ b/public/date.js @@ -0,0 +1,31 @@ + +/** + * Web唐明明 + * 匆匆数载恍如梦,岁月迢迢华发增。 + * 碌碌无为枉半生,一朝惊醒万事空。 + * moduleName: 日期 + */ + +export default getDate = (type) =>{ + return new Promise((resolve, reject) => { + const date = new Date() + const year = date.getFullYear() + + const month = (date.getMonth() + 1) <= 9 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1) + const day = date.getDate() + + switch(type){ + case 'day': + resolve(year + '-' + month + '-' + day) + break + case 'month': + resolve(year + '-' + month) + break + case 'year': + resolve(year) + break + default: + resolve(year + '-' + month + '-' + day) + } + }) +} diff --git a/public/userAuth.js b/public/userAuth.js new file mode 100644 index 0000000..caf3074 --- /dev/null +++ b/public/userAuth.js @@ -0,0 +1,110 @@ +/** + * Web唐明明 + * 匆匆数载恍如梦,岁月迢迢华发增。 + * 碌碌无为枉半生,一朝惊醒万事空。 + * moduleName: 登录 + */ + +import { router } from '../router' +import { keyAuth } from '../apis/interfaces/auth' +import store from '../store' + +class userAuth { + constructor() { + this.univerfyConfig = { + fullScreen: true, + authButton: { + 'title': '一键登录', + 'normalColor': '#34CE98', + 'highlightColor': '#16b17a', + 'disabledColor': '#aae4cc', + }, + otherLoginButton: { + 'title': '其他手机号码', + 'borderColor': '#34CE98', + 'textColor': '#34CE98' + }, + privacyTerms: { + 'checkedImage': '/static/icon/checked-icon.png', + 'uncheckedImage': '/static/icon/unchecked-icon.png', + 'textColor': '#999', + 'termsColor': '#34CE98', + 'suffix': '并使用本机号码登录/注册', + 'privacyItems': [{ + 'url': 'https://www.baidu.com', + 'title': '隐私协议' + }, { + 'url': 'https://www.baidu.com', + 'title': '服务协议' + }] + }, + buttons: { + 'iconWidth': '45px', + 'list': [{ + "provider": '微信登录', + "iconPath": '/static/icons/wechat.png', + }] + } + } + } + // 预登录 + Login() { + return new Promise((resolve, reject) => { + uni.showLoading({ + title: '加载中', + mask: true + }) + uni.preLogin({ + provider: 'univerify', + success: res => { + this.keyLogin().then(() => { + resolve({ + auth: true + }) + }).catch(errMsg => { + reject(errMsg) + }) + }, + fail: err => { + router.push({ name: 'Auth' }) + }, + complete() { + uni.hideLoading() + } + }) + }) + } + // 一键登录 + keyLogin() { + return new Promise((resolve, reject) => { + uni.login({ + provider: 'univerify', + univerifyStyle: { + ...this.univerfyConfig + }, + success: authResult => { + keyAuth({ + access_token: authResult.authResult.access_token, + openid: authResult.authResult.openid + }).then(res => { + uni.closeAuthView() + store.commit('setToken', res.token_type + ' ' + res.access_token) + resolve() + }).catch(err => { + reject(err) + }) + }, + fail: err => { + uni.closeAuthView() + switch (err.code) { + case 30002: + router.push({ name: 'Auth', params: { keyPhone: 1 }}) + break + } + } + }) + }) + } +} + +export default userAuth diff --git a/router/index.js b/router/index.js index 3fa9ec7..874a5d7 100644 --- a/router/index.js +++ b/router/index.js @@ -11,11 +11,12 @@ const router = createRouter({ //全局路由前置守卫 router.beforeEach((to, from, next) => { next(); -}); +}); + // 全局路由后置守卫 router.afterEach((to, from) => { console.log('跳转结束') -}) +}) export { router, diff --git a/static/icon/checked-icon.png b/static/icon/checked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