From 9737d0816d14513f0172e5b944200ed242d5fb60 Mon Sep 17 00:00:00 2001 From: linju Date: Wed, 21 Sep 2022 22:10:30 +0800 Subject: [PATCH] 1.0.20 --- manifest.json | 2 +- uni_modules/uni-id-pages/changelog.md | 2 + uni_modules/uni-id-pages/common/common.js | 13 - .../uni-id-pages/common/login-page.mixin.js | 7 +- .../uni-id-pages/common/login-page.scss | 11 +- .../uni-id-pages/common/loginSuccess.js | 51 --- uni_modules/uni-id-pages/common/store.js | 135 +++++++ .../uni-id-pages-agreements.vue | 2 +- .../uni-id-pages-avatar.vue | 100 ++--- .../uni-id-pages-fab-login.vue | 15 +- uni_modules/uni-id-pages/package.json | 2 +- .../pages/login/login-withoutpwd.vue | 7 +- .../pages/login/login-withpwd.vue | 338 +++++++++-------- .../pages/register/register-by-email.vue | 2 +- .../uni-id-pages/pages/register/register.vue | 355 +++++++++--------- .../pages/retrieve/retrieve-by-email.vue | 1 + .../uni-id-pages/pages/retrieve/retrieve.vue | 1 + .../userinfo/bind-mobile/bind-mobile.vue | 6 +- .../uni-id-pages/pages/userinfo/userinfo.vue | 81 ++-- 19 files changed, 593 insertions(+), 538 deletions(-) delete mode 100644 uni_modules/uni-id-pages/common/common.js delete mode 100644 uni_modules/uni-id-pages/common/loginSuccess.js create mode 100644 uni_modules/uni-id-pages/common/store.js diff --git a/manifest.json b/manifest.json index 82270bf..c1bda1a 100644 --- a/manifest.json +++ b/manifest.json @@ -128,7 +128,7 @@ "uniStatistics" : { "enable" : false }, - "vueVersion" : "2", + "vueVersion" : "3", "h5" : { "unipush" : { "enable" : false diff --git a/uni_modules/uni-id-pages/changelog.md b/uni_modules/uni-id-pages/changelog.md index d19b8ef..bd4d9ed 100644 --- a/uni_modules/uni-id-pages/changelog.md +++ b/uni_modules/uni-id-pages/changelog.md @@ -1,3 +1,5 @@ +## 1.0.20(2022-09-21) +- 新增 store 账号信息状态管理,详情:用户中心页面 路径:`/uni_modules/uni-id-pages/pages/userinfo/userinfo` ## 1.0.19(2022-09-20) - 修复 小程序端,使用将自定义节点设置成[虚拟节点](https://uniapp.dcloud.net.cn/tutorial/vue-api.html#%E5%85%B6%E4%BB%96%E9%85%8D%E7%BD%AE)的uni-ui组件,样式错乱的问题 ## 1.0.18(2022-09-20) diff --git a/uni_modules/uni-id-pages/common/common.js b/uni_modules/uni-id-pages/common/common.js deleted file mode 100644 index a672660..0000000 --- a/uni_modules/uni-id-pages/common/common.js +++ /dev/null @@ -1,13 +0,0 @@ -import pagesJson from '@/pages.json' -const uniIdCo = uniCloud.importObject("uni-id-co") -export default { - async logout() { - await uniIdCo.logout() - uni.removeStorageSync('uni_id_token'); - uni.setStorageSync('uni_id_token_expired', 0) - uni.redirectTo({ - url: `/${pagesJson.uniIdRouter?.loginPage ?? 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`, - }); - uni.$emit('uni-id-pages-logout') - }, -} diff --git a/uni_modules/uni-id-pages/common/login-page.mixin.js b/uni_modules/uni-id-pages/common/login-page.mixin.js index 130647f..b5164a3 100644 --- a/uni_modules/uni-id-pages/common/login-page.mixin.js +++ b/uni_modules/uni-id-pages/common/login-page.mixin.js @@ -1,4 +1,7 @@ -import loginSuccess from './loginSuccess.js'; +import { + store, + mutations + } from '@/uni_modules/uni-id-pages/common/store.js' import config from '@/uni_modules/uni-id-pages/config.js' let mixin = { data() { @@ -75,7 +78,7 @@ let mixin = { }, methods: { loginSuccess(e) { - loginSuccess({ + mutations.loginSuccess({ ...e, uniIdRedirectUrl: this.uniIdRedirectUrl }) diff --git a/uni_modules/uni-id-pages/common/login-page.scss b/uni_modules/uni-id-pages/common/login-page.scss index 9a2fc3b..3f55166 100644 --- a/uni_modules/uni-id-pages/common/login-page.scss +++ b/uni_modules/uni-id-pages/common/login-page.scss @@ -51,7 +51,12 @@ .register-back{ display: none; - } + } + + uni-button{ + padding-bottom: 1px; + } + /* #endif */ } @@ -81,13 +86,13 @@ } -/* #ifdef MP */ +/* #ifndef APP-NVUE */ // 解决小程序端开启虚拟节点virtualHost引起的 class = input-box丢失的问题 [详情参考](https://uniapp.dcloud.net.cn/matter.html#%E5%90%84%E5%AE%B6%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%AE%9E%E7%8E%B0%E6%9C%BA%E5%88%B6%E4%B8%8D%E5%90%8C-%E5%8F%AF%E8%83%BD%E5%AD%98%E5%9C%A8%E7%9A%84%E5%B9%B3%E5%8F%B0%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98) .uni-content ::v-deep .uni-easyinput__content, /* #endif */ .input-box { - padding: 4px; + height: 44px; background-color: #F8F8F8 !important; border-radius: 0; font-size: 14px; diff --git a/uni_modules/uni-id-pages/common/loginSuccess.js b/uni_modules/uni-id-pages/common/loginSuccess.js deleted file mode 100644 index 9f356cf..0000000 --- a/uni_modules/uni-id-pages/common/loginSuccess.js +++ /dev/null @@ -1,51 +0,0 @@ -import pagesJson from '@/pages.json' - -export default function(e = {}) { - const { - showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = '' - } = e - console.log({ - toastText, - autoBack - }); - if (showToast) { - uni.showToast({ - title: toastText, - icon: 'none' - }); - } - if (autoBack) { - let delta = 0; //判断需要返回几层 - let pages = getCurrentPages(); - uni.$emit('uni-id-pages-login-success',pages) - console.log(pages); - pages.forEach((page, index) => { - if (pages[pages.length - index - 1].route.split('/')[3] == 'login') { - delta++ - } - }) - console.log('判断需要返回几层:',pages, delta); - if (uniIdRedirectUrl) { - return uni.reLaunch({ - url: uniIdRedirectUrl - }) - } - // #ifdef H5 - if(e.loginType == 'weixin'){ - console.log('window.history',window.history); - return window.history.go(-3) - } - // #endif - - if (delta) { - const page = pagesJson.pages[0] - return uni.reLaunch({ - url: `/${page.path}` - }) - } - - uni.navigateBack({ - delta - }) - } -} diff --git a/uni_modules/uni-id-pages/common/store.js b/uni_modules/uni-id-pages/common/store.js new file mode 100644 index 0000000..f347a8c --- /dev/null +++ b/uni_modules/uni-id-pages/common/store.js @@ -0,0 +1,135 @@ +import pagesJson from '@/pages.json' +const uniIdCo = uniCloud.importObject("uni-id-co") +const db = uniCloud.database(); +const usersTable = db.collection('uni-id-users') + +console.log(uni.getStorageSync('uni-id-pages-userInfo') || {}); + +const data = { + userInfo: uni.getStorageSync('uni-id-pages-userInfo') || {}, + hasLogin: !!uni.getStorageSync('uni-id-pages-userInfo') +} + +console.log('data', data); +// 定义 mutations, 修改属性 +export const mutations = { + // data不为空,表示传递要更新的值(注意不是覆盖是合并),什么也不传时,直接查库获取更新 + async updateUserInfo(data = false) { + if (data) { + usersTable.where('_id==$env.uid').update(data).then(e => { + console.log(e); + if (e.result.updated) { + uni.showToast({ + title: "更新成功", + icon: 'none' + }); + this.setUserInfo(data) + } else { + uni.showToast({ + title: "没有改变", + icon: 'none' + }); + } + }) + + } else { + try { + let res = await usersTable.where("'_id' == $cloudEnv_uid") + .field('mobile,nickname,user_name,email,avatar_file') + .get() + console.log('fromDbData',res.result.data); + this.setUserInfo(res.result.data[0]) + } catch (e) { + this.setUserInfo({},{cover:true}) + console.error(e.message, e.errCode); + } + } + }, + async setUserInfo(data, {cover}={cover:false}) { + console.log('set-userInfo', data); + let userInfo = cover?data:Object.assign(store.userInfo,data) + store.userInfo = Object.assign({},userInfo) + store.hasLogin = Object.keys(store.userInfo).length != 0 + console.log('store.userInfo', store.userInfo); + uni.setStorage({ + key: "uni-id-pages-userInfo", + data:store.userInfo + }) + return data + }, + async logout() { + await uniIdCo.logout() + uni.removeStorageSync('uni_id_token'); + uni.setStorageSync('uni_id_token_expired', 0) + uni.redirectTo({ + url: `/${pagesJson.uniIdRouter?.loginPage ?? 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`, + }); + uni.$emit('uni-id-pages-logout') + this.setUserInfo({},{cover:true}) + }, + loginSuccess(e){ + const { + showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = '' + } = e + console.log({ + toastText, + autoBack + }); + if (showToast) { + uni.showToast({ + title: toastText, + icon: 'none' + }); + } + this.updateUserInfo() + uni.$emit('uni-id-pages-login-success') + if (autoBack) { + let delta = 0; //判断需要返回几层 + let pages = getCurrentPages(); + // console.log(pages); + pages.forEach((page, index) => { + if (pages[pages.length - index - 1].route.split('/')[3] == 'login') { + delta++ + } + }) + console.log('判断需要返回几层:', pages, delta); + if (uniIdRedirectUrl) { + return uni.reLaunch({ + url: uniIdRedirectUrl + }) + } + // #ifdef H5 + if (e.loginType == 'weixin') { + console.log('window.history', window.history); + return window.history.go(-3) + } + // #endif + + if (delta) { + const page = pagesJson.pages[0] + return uni.reLaunch({ + url: `/${page.path}` + }) + } + + uni.navigateBack({ + delta + }) + } + } + +} + +// #ifdef VUE2 +import Vue from 'vue' +// 通过Vue.observable创建一个可响应的对象 +export const store = Vue.observable(data) +// #endif + +// #ifdef VUE3 +import { + reactive +} from 'vue' +// 通过Vue.observable创建一个可响应的对象 +export const store = reactive(data) +// #endif diff --git a/uni_modules/uni-id-pages/components/uni-id-pages-agreements/uni-id-pages-agreements.vue b/uni_modules/uni-id-pages/components/uni-id-pages-agreements/uni-id-pages-agreements.vue index 2e1e0d3..d2660a9 100644 --- a/uni_modules/uni-id-pages/components/uni-id-pages-agreements/uni-id-pages-agreements.vue +++ b/uni_modules/uni-id-pages/components/uni-id-pages-agreements/uni-id-pages-agreements.vue @@ -67,7 +67,7 @@ }, methods: { popupConfirm(){ - console.log("popupConfirm"); + // console.log("popupConfirm"); this.isAgree = true retryFun() // this.$emit('popupConfirm') diff --git a/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue b/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue index 898bbaa..3f45238 100644 --- a/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue +++ b/uni_modules/uni-id-pages/components/uni-id-pages-avatar/uni-id-pages-avatar.vue @@ -1,5 +1,5 @@ - diff --git a/uni_modules/uni-id-pages/components/uni-id-pages-fab-login/uni-id-pages-fab-login.vue b/uni_modules/uni-id-pages/components/uni-id-pages-fab-login/uni-id-pages-fab-login.vue index b6ae82a..b0af426 100644 --- a/uni_modules/uni-id-pages/components/uni-id-pages-fab-login/uni-id-pages-fab-login.vue +++ b/uni_modules/uni-id-pages/components/uni-id-pages-fab-login/uni-id-pages-fab-login.vue @@ -14,8 +14,11 @@ - - diff --git a/uni_modules/uni-id-pages/pages/register/register-by-email.vue b/uni_modules/uni-id-pages/pages/register/register-by-email.vue index 1a34514..f45dc57 100644 --- a/uni_modules/uni-id-pages/pages/register/register-by-email.vue +++ b/uni_modules/uni-id-pages/pages/register/register-by-email.vue @@ -191,7 +191,7 @@ @media screen and (min-width: 690px) { .uni-content{ padding: 30px 40px; - max-height: 550px; + max-height: 650px; } .link-box { /* #ifndef APP-NVUE */ diff --git a/uni_modules/uni-id-pages/pages/register/register.vue b/uni_modules/uni-id-pages/pages/register/register.vue index abd1de1..28c5d12 100644 --- a/uni_modules/uni-id-pages/pages/register/register.vue +++ b/uni_modules/uni-id-pages/pages/register/register.vue @@ -1,175 +1,186 @@ - - - - - - diff --git a/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue b/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue index 8671463..71ca8fe 100644 --- a/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue +++ b/uni_modules/uni-id-pages/pages/retrieve/retrieve-by-email.vue @@ -204,6 +204,7 @@ @media screen and (min-width: 690px) { .uni-content{ padding: 30px 40px 40px; + max-height: 650px; } .link-box { diff --git a/uni_modules/uni-id-pages/pages/retrieve/retrieve.vue b/uni_modules/uni-id-pages/pages/retrieve/retrieve.vue index 20eea22..74ed220 100644 --- a/uni_modules/uni-id-pages/pages/retrieve/retrieve.vue +++ b/uni_modules/uni-id-pages/pages/retrieve/retrieve.vue @@ -228,6 +228,7 @@ @media screen and (min-width: 690px) { .uni-content{ padding: 30px 40px 40px; + max-height: 650px; } .link-box { /* #ifndef APP-NVUE */ diff --git a/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue index 22912d1..15d68eb 100644 --- a/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue +++ b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue @@ -19,6 +19,10 @@