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-icon.png new file mode 100644 index 0000000..d8e6d6c Binary files /dev/null and b/static/icon/checked-icon.png differ diff --git a/static/icon/unchecked-icon.png b/static/icon/unchecked-icon.png new file mode 100644 index 0000000..d1016bc Binary files /dev/null and b/static/icon/unchecked-icon.png differ