提交 afee7ca2 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新依赖的modules版本

上级 5c122dae
## 1.1.11(2023-03-24) ## 1.1.14(2023-05-19)
- 修复 tabbar页面因为token无效而强制跳转至登录页面(url参数包含`uniIdRedirectUrl`)后无法返回的问题 - 修复 退出登录不会跳转至登录页的问题
## 1.1.10(2023-03-24) ## 1.1.13(2023-05-10)
- 修复 PC微信扫码登录跳转地址错误 - 修复 启用摇树优化 报错的问题
- uni-id-co 新增 请求鉴权支持 uni-cloud-s2s 模块验证签名 [uni-cloud-s2s文档](https://uniapp.dcloud.net.cn/uniCloud/uni-cloud-s2s.html) ## 1.1.12(2023-05-05)
- uni-id-co 新增 调用 add-user 接口创建用户时允许触发 beforeRegister 钩子方法,beforeRegister 钩子[详见](https://uniapp.dcloud.net.cn/uniCloud/uni-id-summary.html#before-register)
- uni-id-co 新增 自无 unionid 到有 unionid 状态进行登录时为用户补充 unionid 字段
- uni-id-co 修复 i18n 在特定场景下报错的 bug
- uni-id-co 修复 跨平台解绑微信/QQ时无法解绑的 bug
- uni-id-co 修复 微信小程序等平台创建验证码时无法展示的 bug
- uni-id-co 修复 更新 push_clientid 时因 device_id 没有变化导致无法更新
## 1.1.11(2023-03-24)
- 修复 tabbar页面因为token无效而强制跳转至登录页面(url参数包含`uniIdRedirectUrl`)后无法返回的问题
## 1.1.10(2023-03-24)
- 修复 PC微信扫码登录跳转地址错误
- uni-id-co 新增 请求鉴权支持 uni-cloud-s2s 模块验证签名 [uni-cloud-s2s文档](https://uniapp.dcloud.net.cn/uniCloud/uni-cloud-s2s.html)
## 1.1.9(2023-03-24) ## 1.1.9(2023-03-24)
- 修复 跳转至登录页面的url参数包含`uniIdRedirectUrl`后无法返回的问题 - 修复 跳转至登录页面的url参数包含`uniIdRedirectUrl`后无法返回的问题
## 1.1.8(2023-03-02) ## 1.1.8(2023-03-02)
......
export default function checkIdCard (idCardNumber) { function checkIdCard (idCardNumber) {
if (!idCardNumber || typeof idCardNumber !== 'string' || idCardNumber.length !== 18) return false if (!idCardNumber || typeof idCardNumber !== 'string' || idCardNumber.length !== 18) return false
const coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] const coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
...@@ -12,3 +12,5 @@ export default function checkIdCard (idCardNumber) { ...@@ -12,3 +12,5 @@ export default function checkIdCard (idCardNumber) {
return checkCode[sum % 11].toString() === code.toLowerCase() return checkCode[sum % 11].toString() === code.toLowerCase()
} }
export default checkIdCard
...@@ -79,7 +79,7 @@ export const mutations = { ...@@ -79,7 +79,7 @@ export const mutations = {
uni.removeStorageSync('uni_id_token'); uni.removeStorageSync('uni_id_token');
uni.setStorageSync('uni_id_token_expired', 0) uni.setStorageSync('uni_id_token_expired', 0)
uni.redirectTo({ uni.redirectTo({
url: `/${pagesJson.uniIdRouter && pagesJson.uniIdRouter.loginPage ? 'uni_modules/uni-id-pages/pages/login/login-withoutpwd': ''}`, url: `/${pagesJson.uniIdRouter && pagesJson.uniIdRouter.loginPage ? pagesJson.uniIdRouter.loginPage: 'uni_modules/uni-id-pages/pages/login/login-withoutpwd'}`,
}); });
uni.$emit('uni-id-pages-logout') uni.$emit('uni-id-pages-logout')
this.setUserInfo({},{cover:true}) this.setUserInfo({},{cover:true})
...@@ -98,14 +98,14 @@ export const mutations = { ...@@ -98,14 +98,14 @@ export const mutations = {
// console.log('判断需要返回几层:', delta); // console.log('判断需要返回几层:', delta);
if (uniIdRedirectUrl) { if (uniIdRedirectUrl) {
return uni.redirectTo({ return uni.redirectTo({
url: uniIdRedirectUrl, url: uniIdRedirectUrl,
fail: (err1) => { fail: (err1) => {
uni.switchTab({ uni.switchTab({
url:uniIdRedirectUrl, url:uniIdRedirectUrl,
fail: (err2) => { fail: (err2) => {
console.log(err1,err2) console.log(err1,err2)
} }
}) })
} }
}) })
} }
......
...@@ -202,7 +202,6 @@ ...@@ -202,7 +202,6 @@
return '/' + pages[pages.length - n].route return '/' + pages[pages.length - n].route
}, },
toPage(path,index = 0) { toPage(path,index = 0) {
let type = ['navigateTo','redirectTo'][index]
//console.log('比较', this.getRoute(1),this.getRoute(2), path) //console.log('比较', this.getRoute(1),this.getRoute(2), path)
if (this.getRoute(1) == path.split('?')[0] && this.getRoute(1) == if (this.getRoute(1) == path.split('?')[0] && this.getRoute(1) ==
'/uni_modules/uni-id-pages/pages/login/login-withoutpwd') { '/uni_modules/uni-id-pages/pages/login/login-withoutpwd') {
...@@ -212,13 +211,23 @@ ...@@ -212,13 +211,23 @@
} else if (this.getRoute(2) == path) { // 如果上一个页面就是,马上要打开的页面,直接返回。防止重复开启 } else if (this.getRoute(2) == path) { // 如果上一个页面就是,马上要打开的页面,直接返回。防止重复开启
uni.navigateBack(); uni.navigateBack();
} else if (this.getRoute(1) != path) { } else if (this.getRoute(1) != path) {
uni[type]({ if(index === 0){
url: path, uni.navigateTo({
animationType: 'slide-in-left', url: path,
complete(e) { animationType: 'slide-in-left',
// console.log(e); complete(e) {
} // console.log(e);
}) }
})
}else{
uni.redirectTo({
url: path,
animationType: 'slide-in-left',
complete(e) {
// console.log(e);
}
})
}
} else { } else {
console.log('出乎意料的情况,path:' + path); console.log('出乎意料的情况,path:' + path);
} }
......
...@@ -17,24 +17,14 @@ export default { ...@@ -17,24 +17,14 @@ export default {
// "douyin", // "douyin",
// #ifdef APP // #ifdef APP
// 'univerify', 'univerify',
// #endif // #endif
'weixin',
// #ifdef MP-WEIXIN 'username',
'weixin',
// #endif
// #ifndef MP-WEIXIN
'username',
// #endif
// #ifdef APP // #ifdef APP
'apple', 'apple',
// #endif // #endif
'smsCode'
// #ifndef MP-WEIXIN
'smsCode',
// #endif
], ],
// 政策协议 // 政策协议
agreements: { agreements: {
...@@ -62,7 +52,7 @@ export default { ...@@ -62,7 +52,7 @@ export default {
* weak(弱:密码必须包含字母和数字,长度范围:6-16位之间) * weak(弱:密码必须包含字母和数字,长度范围:6-16位之间)
* 为空或false则不验证密码强度 * 为空或false则不验证密码强度
*/ */
// passwordStrength: 'medium', passwordStrength: 'medium',
/** /**
* 登录后允许用户设置密码(只针对未设置密码得用户) * 登录后允许用户设置密码(只针对未设置密码得用户)
* 开启此功能将 setPasswordAfterLogin 设置为 true 即可 * 开启此功能将 setPasswordAfterLogin 设置为 true 即可
......
{ {
"id": "uni-id-pages", "id": "uni-id-pages",
"displayName": "uni-id-pages", "displayName": "uni-id-pages",
"version": "1.1.11", "version": "1.1.14",
"description": "云端一体简单、统一、可扩展的用户中心页面模版", "description": "云端一体简单、统一、可扩展的用户中心页面模版",
"keywords": [ "keywords": [
"用户管理", "用户管理",
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
"uni-popup", "uni-popup",
"uni-scss", "uni-scss",
"uni-transition", "uni-transition",
"uni-open-bridge-common", "uni-open-bridge-common",
"uni-cloud-s2s" "uni-cloud-s2s"
], ],
"encrypt": [], "encrypt": [],
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
this.focusPassword = true this.focusPassword = true
return uni.showToast({ return uni.showToast({
title: '请输入密码', title: '请输入密码',
icon: 'none', icon: 'none',
duration: 3000 duration: 3000
}); });
} }
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
this.focusUsername = true this.focusUsername = true
return uni.showToast({ return uni.showToast({
title: '请输入手机号/用户名/邮箱', title: '请输入手机号/用户名/邮箱',
icon: 'none', icon: 'none',
duration: 3000 duration: 3000
}); });
} }
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
this.$refs.captcha.getImageCaptcha() this.$refs.captcha.getImageCaptcha()
return uni.showToast({ return uni.showToast({
title: '请输入验证码', title: '请输入验证码',
icon: 'none', icon: 'none',
duration: 3000 duration: 3000
}); });
} }
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content { .uni-content {
height: 600px; height: auto;
} }
} }
...@@ -173,4 +173,4 @@ ...@@ -173,4 +173,4 @@
.link { .link {
font-size: 12px; font-size: 12px;
} }
</style> </style>
...@@ -40,8 +40,9 @@ ...@@ -40,8 +40,9 @@
</template> </template>
<script> <script>
import checkIdCard from '@/uni_modules/uni-id-pages/common/check-id-card.js' import checkIdCard from '@/uni_modules/uni-id-pages/common/check-id-card.js';
import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js'; import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
import { import {
store, store,
mutations mutations
......
const ERROR = { const ERROR = {
ACCOUNT_EXISTS: 'uni-id-account-exists', ACCOUNT_EXISTS: 'uni-id-account-exists',
ACCOUNT_NOT_EXISTS: 'uni-id-account-not-exists', ACCOUNT_NOT_EXISTS: 'uni-id-account-not-exists',
ACCOUNT_NOT_EXISTS_IN_CURRENT_APP: 'uni-id-account-not-exists-in-current-app', ACCOUNT_NOT_EXISTS_IN_CURRENT_APP: 'uni-id-account-not-exists-in-current-app',
ACCOUNT_CONFLICT: 'uni-id-account-conflict', ACCOUNT_CONFLICT: 'uni-id-account-conflict',
ACCOUNT_BANNED: 'uni-id-account-banned', ACCOUNT_BANNED: 'uni-id-account-banned',
ACCOUNT_AUDITING: 'uni-id-account-auditing', ACCOUNT_AUDITING: 'uni-id-account-auditing',
ACCOUNT_AUDIT_FAILED: 'uni-id-account-audit-failed', ACCOUNT_AUDIT_FAILED: 'uni-id-account-audit-failed',
ACCOUNT_CLOSED: 'uni-id-account-closed', ACCOUNT_CLOSED: 'uni-id-account-closed',
CAPTCHA_REQUIRED: 'uni-id-captcha-required', CAPTCHA_REQUIRED: 'uni-id-captcha-required',
PASSWORD_ERROR: 'uni-id-password-error', PASSWORD_ERROR: 'uni-id-password-error',
PASSWORD_ERROR_EXCEED_LIMIT: 'uni-id-password-error-exceed-limit', PASSWORD_ERROR_EXCEED_LIMIT: 'uni-id-password-error-exceed-limit',
INVALID_USERNAME: 'uni-id-invalid-username', INVALID_USERNAME: 'uni-id-invalid-username',
INVALID_PASSWORD: 'uni-id-invalid-password', INVALID_PASSWORD: 'uni-id-invalid-password',
INVALID_PASSWORD_SUPER: 'uni-id-invalid-password-super', INVALID_PASSWORD_SUPER: 'uni-id-invalid-password-super',
INVALID_PASSWORD_STRONG: 'uni-id-invalid-password-strong', INVALID_PASSWORD_STRONG: 'uni-id-invalid-password-strong',
INVALID_PASSWORD_MEDIUM: 'uni-id-invalid-password-medium', INVALID_PASSWORD_MEDIUM: 'uni-id-invalid-password-medium',
INVALID_PASSWORD_WEAK: 'uni-id-invalid-password-weak', INVALID_PASSWORD_WEAK: 'uni-id-invalid-password-weak',
INVALID_MOBILE: 'uni-id-invalid-mobile', INVALID_MOBILE: 'uni-id-invalid-mobile',
INVALID_EMAIL: 'uni-id-invalid-email', INVALID_EMAIL: 'uni-id-invalid-email',
INVALID_NICKNAME: 'uni-id-invalid-nickname', INVALID_NICKNAME: 'uni-id-invalid-nickname',
INVALID_PARAM: 'uni-id-invalid-param', INVALID_PARAM: 'uni-id-invalid-param',
PARAM_REQUIRED: 'uni-id-param-required', PARAM_REQUIRED: 'uni-id-param-required',
GET_THIRD_PARTY_ACCOUNT_FAILED: 'uni-id-get-third-party-account-failed', GET_THIRD_PARTY_ACCOUNT_FAILED: 'uni-id-get-third-party-account-failed',
GET_THIRD_PARTY_USER_INFO_FAILED: 'uni-id-get-third-party-user-info-failed', GET_THIRD_PARTY_USER_INFO_FAILED: 'uni-id-get-third-party-user-info-failed',
MOBILE_VERIFY_CODE_ERROR: 'uni-id-mobile-verify-code-error', MOBILE_VERIFY_CODE_ERROR: 'uni-id-mobile-verify-code-error',
EMAIL_VERIFY_CODE_ERROR: 'uni-id-email-verify-code-error', EMAIL_VERIFY_CODE_ERROR: 'uni-id-email-verify-code-error',
ADMIN_EXISTS: 'uni-id-admin-exists', ADMIN_EXISTS: 'uni-id-admin-exists',
PERMISSION_ERROR: 'uni-id-permission-error', PERMISSION_ERROR: 'uni-id-permission-error',
SYSTEM_ERROR: 'uni-id-system-error', SYSTEM_ERROR: 'uni-id-system-error',
SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed', SET_INVITE_CODE_FAILED: 'uni-id-set-invite-code-failed',
INVALID_INVITE_CODE: 'uni-id-invalid-invite-code', INVALID_INVITE_CODE: 'uni-id-invalid-invite-code',
CHANGE_INVITER_FORBIDDEN: 'uni-id-change-inviter-forbidden', CHANGE_INVITER_FORBIDDEN: 'uni-id-change-inviter-forbidden',
BIND_CONFLICT: 'uni-id-bind-conflict', BIND_CONFLICT: 'uni-id-bind-conflict',
UNBIND_FAIL: 'uni-id-unbind-failed', UNBIND_FAIL: 'uni-id-unbind-failed',
UNBIND_NOT_SUPPORTED: 'uni-id-unbind-not-supported', UNBIND_NOT_SUPPORTED: 'uni-id-unbind-not-supported',
UNBIND_UNIQUE_LOGIN: 'uni-id-unbind-unique-login', UNBIND_UNIQUE_LOGIN: 'uni-id-unbind-unique-login',
UNBIND_PASSWORD_NOT_EXISTS: 'uni-id-unbind-password-not-exists', UNBIND_PASSWORD_NOT_EXISTS: 'uni-id-unbind-password-not-exists',
UNBIND_MOBILE_NOT_EXISTS: 'uni-id-unbind-mobile-not-exists', UNBIND_MOBILE_NOT_EXISTS: 'uni-id-unbind-mobile-not-exists',
UNSUPPORTED_REQUEST: 'uni-id-unsupported-request', UNSUPPORTED_REQUEST: 'uni-id-unsupported-request',
ILLEGAL_REQUEST: 'uni-id-illegal-request', ILLEGAL_REQUEST: 'uni-id-illegal-request',
CONFIG_FIELD_REQUIRED: 'uni-id-config-field-required', CONFIG_FIELD_REQUIRED: 'uni-id-config-field-required',
CONFIG_FIELD_INVALID: 'uni-id-config-field-invalid', CONFIG_FIELD_INVALID: 'uni-id-config-field-invalid',
FRV_FAIL: 'uni-id-frv-fail', FRV_FAIL: 'uni-id-frv-fail',
FRV_PROCESSING: 'uni-id-frv-processing', FRV_PROCESSING: 'uni-id-frv-processing',
REAL_NAME_VERIFIED: 'uni-id-realname-verified', REAL_NAME_VERIFIED: 'uni-id-realname-verified',
ID_CARD_EXISTS: 'uni-id-idcard-exists', ID_CARD_EXISTS: 'uni-id-idcard-exists',
INVALID_ID_CARD: 'uni-id-invalid-idcard', INVALID_ID_CARD: 'uni-id-invalid-idcard',
INVALID_REAL_NAME: 'uni-id-invalid-realname', INVALID_REAL_NAME: 'uni-id-invalid-realname',
UNKNOWN_ERROR: 'uni-id-unknown-error', UNKNOWN_ERROR: 'uni-id-unknown-error',
REAL_NAME_VERIFY_UPPER_LIMIT: 'uni-id-realname-verify-upper-limit' REAL_NAME_VERIFY_UPPER_LIMIT: 'uni-id-realname-verify-upper-limit'
} }
function isUniIdError (errCode) { function isUniIdError (errCode) {
return Object.values(ERROR).includes(errCode) return Object.values(ERROR).includes(errCode)
} }
class UniCloudError extends Error { class UniCloudError extends Error {
constructor (options) { constructor (options) {
super(options.message) super(options.message)
this.errMsg = options.message || '' this.errMsg = options.message || ''
this.errCode = options.code this.errCode = options.code
} }
} }
module.exports = { module.exports = {
ERROR, ERROR,
isUniIdError, isUniIdError,
UniCloudError UniCloudError
} }
...@@ -212,11 +212,16 @@ module.exports = { ...@@ -212,11 +212,16 @@ module.exports = {
} }
// 国际化 // 国际化
const messages = require('./lang/index')
const fallbackLocale = 'zh-Hans'
const i18n = uniCloud.initI18n({ const i18n = uniCloud.initI18n({
locale: clientInfo.locale, locale: clientInfo.locale,
fallbackLocale: 'zh-Hans', fallbackLocale,
messages: require('./lang/index') messages: JSON.parse(JSON.stringify(messages))
}) })
if (!messages[i18n.locale]) {
i18n.setLocale(fallbackLocale)
}
this.t = i18n.t.bind(i18n) this.t = i18n.t.bind(i18n)
this.response = {} this.response = {}
......
...@@ -173,8 +173,8 @@ async function thirdPartyLogin (params = {}) { ...@@ -173,8 +173,8 @@ async function thirdPartyLogin (params = {}) {
user user
} = params } = params
return { return {
mobileComfirmd: user.mobile_comfirmd, mobileConfirmed: !!user.mobile_confirmed,
emailComfirmd: user.email_comfirmd emailConfirmed: !!user.email_confirmed
} }
} }
...@@ -194,7 +194,7 @@ async function postLogin (params = {}) { ...@@ -194,7 +194,7 @@ async function postLogin (params = {}) {
last_login_ip: clientIP, last_login_ip: clientIP,
...extraData ...extraData
} }
const createTokenRes = await this.uniIdCommon.createToken({ const createTokenRes = await this.uniIdCommon.createToken({
uid uid
}) })
......
const crypto = require('crypto') const crypto = require('crypto')
const createConfig = require('uni-config-center') const createConfig = require('uni-config-center')
const { verifyHttpInfo } = require('uni-cloud-s2s') const { verifyHttpInfo } = require('uni-cloud-s2s')
const { ERROR } = require('../common/error') const { ERROR } = require('../common/error')
const s2sConfig = createConfig({ const s2sConfig = createConfig({
pluginId: 'uni-cloud-s2s' pluginId: 'uni-cloud-s2s'
}) })
const needSignFunctions = new Set([ const needSignFunctions = new Set([
'externalRegister', 'externalRegister',
'externalLogin', 'externalLogin',
'updateUserInfoByExternal' 'updateUserInfoByExternal'
]) ])
module.exports = function () { module.exports = function () {
const methodName = this.getMethodName() const methodName = this.getMethodName()
const { source } = this.getUniversalClientInfo() const { source } = this.getUniversalClientInfo()
// 指定接口需要鉴权 // 指定接口需要鉴权
if (!needSignFunctions.has(methodName)) return if (!needSignFunctions.has(methodName)) return
// 非 HTTP 方式请求拒绝访问 // 非 HTTP 方式请求拒绝访问
if (source !== 'http') { if (source !== 'http') {
throw { throw {
errCode: ERROR.ILLEGAL_REQUEST errCode: ERROR.ILLEGAL_REQUEST
} }
} }
// 支持 uni-cloud-s2s 验证请求 // 支持 uni-cloud-s2s 验证请求
if (s2sConfig.hasFile('config.json')) { if (s2sConfig.hasFile('config.json')) {
try { try {
if (!verifyHttpInfo(this.getHttpInfo())) { if (!verifyHttpInfo(this.getHttpInfo())) {
throw { throw {
errCode: ERROR.ILLEGAL_REQUEST errCode: ERROR.ILLEGAL_REQUEST
} }
} }
} catch (e) { } catch (e) {
if (e.errSubject === 'uni-cloud-s2s') { if (e.errSubject === 'uni-cloud-s2s') {
throw { throw {
errCode: ERROR.ILLEGAL_REQUEST, errCode: ERROR.ILLEGAL_REQUEST,
errMsg: e.errMsg errMsg: e.errMsg
} }
} }
throw e throw e
} }
return return
} }
if (!this.config.requestAuthSecret || typeof this.config.requestAuthSecret !== 'string') { if (!this.config.requestAuthSecret || typeof this.config.requestAuthSecret !== 'string') {
throw { throw {
errCode: ERROR.CONFIG_FIELD_REQUIRED, errCode: ERROR.CONFIG_FIELD_REQUIRED,
errMsgValue: { errMsgValue: {
field: 'requestAuthSecret' field: 'requestAuthSecret'
} }
} }
} }
const timeout = 20 * 1000 // 请求超过20秒不能再请求,防止重放攻击 const timeout = 20 * 1000 // 请求超过20秒不能再请求,防止重放攻击
const { headers, body: _body } = this.getHttpInfo() const { headers, body: _body } = this.getHttpInfo()
const { 'uni-id-nonce': nonce, 'uni-id-timestamp': timestamp, 'uni-id-signature': signature } = headers const { 'uni-id-nonce': nonce, 'uni-id-timestamp': timestamp, 'uni-id-signature': signature } = headers
const body = JSON.parse(_body).params || {} const body = JSON.parse(_body).params || {}
const bodyStr = Object.keys(body) const bodyStr = Object.keys(body)
.sort() .sort()
.filter(item => typeof body[item] !== 'object') .filter(item => typeof body[item] !== 'object')
.map(item => `${item}=${body[item]}`) .map(item => `${item}=${body[item]}`)
.join('&') .join('&')
if (isNaN(Number(timestamp)) || (Number(timestamp) + timeout) < Date.now()) { if (isNaN(Number(timestamp)) || (Number(timestamp) + timeout) < Date.now()) {
throw { throw {
errCode: ERROR.ILLEGAL_REQUEST errCode: ERROR.ILLEGAL_REQUEST
} }
} }
const reSignature = crypto.createHmac('sha256', `${this.config.requestAuthSecret + nonce}`).update(`${timestamp}${bodyStr}`).digest('hex') const reSignature = crypto.createHmac('sha256', `${this.config.requestAuthSecret + nonce}`).update(`${timestamp}${bodyStr}`).digest('hex')
if (signature !== reSignature.toUpperCase()) { if (signature !== reSignature.toUpperCase()) {
throw { throw {
errCode: ERROR.ILLEGAL_REQUEST errCode: ERROR.ILLEGAL_REQUEST
} }
} }
} }
...@@ -113,7 +113,17 @@ module.exports = async function (params = {}) { ...@@ -113,7 +113,17 @@ module.exports = async function (params = {}) {
data.mobile_confirmed = 1 data.mobile_confirmed = 1
} }
await userCollection.add(data) // 触发 beforeRegister 钩子
const beforeRegister = this.hooks.beforeRegister
let userRecord = data
if (beforeRegister) {
userRecord = await beforeRegister({
userRecord,
clientInfo: this.getUniversalClientInfo()
})
}
await userCollection.add(userRecord)
return { return {
errCode: 0, errCode: 0,
errMsg: '' errMsg: ''
......
...@@ -70,6 +70,7 @@ module.exports = async function (params) { ...@@ -70,6 +70,7 @@ module.exports = async function (params) {
status: REAL_NAME_STATUS.CERTIFY_FAILED status: REAL_NAME_STATUS.CERTIFY_FAILED
}) })
console.log(ERROR.FRV_FAIL, 'error: ', res)
throw { throw {
errCode: ERROR.FRV_FAIL errCode: ERROR.FRV_FAIL
} }
......
...@@ -108,7 +108,8 @@ module.exports = async function (params = {}) { ...@@ -108,7 +108,8 @@ module.exports = async function (params = {}) {
const extraData = { const extraData = {
qq_openid: { qq_openid: {
[`${qqPlatform}_${appId}`]: openid [`${qqPlatform}_${appId}`]: openid
} },
qq_unionid: unionid
} }
if (type === 'register' && qqPlatform !== 'mp') { if (type === 'register' && qqPlatform !== 'mp') {
const { const {
......
...@@ -110,7 +110,8 @@ module.exports = async function (params = {}) { ...@@ -110,7 +110,8 @@ module.exports = async function (params = {}) {
const extraData = { const extraData = {
wx_openid: { wx_openid: {
[`${weixinPlatform}_${appId}`]: openid [`${weixinPlatform}_${appId}`]: openid
} },
wx_unionid: unionid
} }
if (type === 'register' && weixinPlatform !== 'mp') { if (type === 'register' && weixinPlatform !== 'mp') {
const { const {
......
...@@ -5,10 +5,6 @@ const { ...@@ -5,10 +5,6 @@ const {
const { const {
LOG_TYPE, dbCmd LOG_TYPE, dbCmd
} = require('../../common/constants') } = require('../../common/constants')
const {
getQQPlatform
} = require('../../lib/utils/qq')
/** /**
* 解绑QQ * 解绑QQ
* @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-qq * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#unbind-qq
...@@ -16,20 +12,11 @@ const { ...@@ -16,20 +12,11 @@ const {
*/ */
module.exports = async function () { module.exports = async function () {
const { uid } = this.authInfo const { uid } = this.authInfo
const { appId } = this.getUniversalClientInfo()
const qqPlatform = getQQPlatform.call(this)
await preUnBind.call(this, { await preUnBind.call(this, {
uid, uid,
unBindAccount: { unBindAccount: {
qq_openid: dbCmd.or([ qq_openid: dbCmd.exists(true),
{
[qqPlatform]: dbCmd.exists(true)
},
{
[`${qqPlatform}_${appId}`]: dbCmd.exists(true)
}
]),
qq_unionid: dbCmd.exists(true) qq_unionid: dbCmd.exists(true)
}, },
logType: LOG_TYPE.UNBIND_QQ logType: LOG_TYPE.UNBIND_QQ
......
...@@ -16,14 +16,12 @@ const { ...@@ -16,14 +16,12 @@ const {
*/ */
module.exports = async function () { module.exports = async function () {
const { uid } = this.authInfo const { uid } = this.authInfo
const weixinPlatform = getWeixinPlatform.call(this) // const weixinPlatform = getWeixinPlatform.call(this)
await preUnBind.call(this, { await preUnBind.call(this, {
uid, uid,
unBindAccount: { unBindAccount: {
wx_openid: { wx_openid: dbCmd.exists(true),
[weixinPlatform]: dbCmd.exists(true)
},
wx_unionid: dbCmd.exists(true) wx_unionid: dbCmd.exists(true)
}, },
logType: LOG_TYPE.UNBIND_WEIXIN logType: LOG_TYPE.UNBIND_WEIXIN
......
...@@ -117,25 +117,16 @@ module.exports = async function (params = {}) { ...@@ -117,25 +117,16 @@ module.exports = async function (params = {}) {
errCode: 0 errCode: 0
} }
} }
// 同一用户允许更新token_expired,不同用户在token_expired小于Date.now()时允许更新。搭配逻辑:用户退出登录时将token_expired置0
if (
deviceRecord.user_id === uid ||
(deviceRecord.token_expired < Date.now())
) {
await deviceCollection.where({
device_id: deviceId
}).update({
user_id: uid,
token_expired: tokenExpired,
push_clientid: pushClientId,
appid: appId
})
return {
errCode: 0
}
}
await deviceCollection.where({
device_id: deviceId
}).update({
user_id: uid,
token_expired: tokenExpired,
push_clientid: pushClientId,
appid: appId
})
return { return {
errCode: ERROR.SYSTEM_ERROR errCode: 0
} }
} }
...@@ -18,7 +18,7 @@ module.exports = async function (params = {}) { ...@@ -18,7 +18,7 @@ module.exports = async function (params = {}) {
} }
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const deviceId = this.getUniversalClientInfo().deviceId const { deviceId, platform } = this.getUniversalClientInfo()
const { const {
scene scene
} = params } = params
...@@ -29,6 +29,7 @@ module.exports = async function (params = {}) { ...@@ -29,6 +29,7 @@ module.exports = async function (params = {}) {
} }
return this.uniCaptcha.create({ return this.uniCaptcha.create({
deviceId, deviceId,
scene scene,
uniPlatform: platform
}) })
} }
...@@ -18,7 +18,8 @@ module.exports = async function (params = {}) { ...@@ -18,7 +18,8 @@ module.exports = async function (params = {}) {
} }
this.middleware.validate(params, schema) this.middleware.validate(params, schema)
const deviceId = this.getUniversalClientInfo().deviceId const { deviceId, platform } = this.getUniversalClientInfo()
const { const {
scene scene
} = params } = params
...@@ -29,6 +30,7 @@ module.exports = async function (params = {}) { ...@@ -29,6 +30,7 @@ module.exports = async function (params = {}) {
} }
return this.uniCaptcha.refresh({ return this.uniCaptcha.refresh({
deviceId, deviceId,
scene scene,
uniPlatform: platform
}) })
} }
{ {
"name": "uni-id-co", "name": "uni-id-co",
"version": "1.1.10", "version": "1.1.14",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"keywords": [], "keywords": [],
......
## 1.2.0(2023-04-27)
- 优化 微信小程序平台 使用微信新增 API getStableAccessToken 获取 access_token, access_token 有效期内重复调用该接口不会更新 access_token, [详情](https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html)
## 1.1.5(2023-03-27) ## 1.1.5(2023-03-27)
- 修复 微信小程序平台 某些情况下 encrypt_key 插入错误的问题 - 修复 微信小程序平台 某些情况下 encrypt_key 插入错误的问题
## 1.1.4(2023-03-13) ## 1.1.4(2023-03-13)
......
{ {
"id": "uni-open-bridge-common", "id": "uni-open-bridge-common",
"displayName": "uni-open-bridge-common", "displayName": "uni-open-bridge-common",
"version": "1.1.5", "version": "1.2.0",
"description": "统一接管微信等三方平台认证凭据", "description": "统一接管微信等三方平台认证凭据",
"keywords": [ "keywords": [
"uni-open-bridge-common", "uni-open-bridge-common",
......
...@@ -20,8 +20,8 @@ class WeixinServer { ...@@ -20,8 +20,8 @@ class WeixinServer {
getAccessToken() { getAccessToken() {
return uniCloud.httpclient.request(WeixinServer.AccessToken_Url, { return uniCloud.httpclient.request(WeixinServer.AccessToken_Url, {
dataType: 'json', dataType: 'json',
method: 'GET', method: 'POST',
dataAsQueryString: true, contentType: 'json',
data: { data: {
appid: this._appid, appid: this._appid,
secret: this._secret, secret: this._secret,
...@@ -106,7 +106,7 @@ class WeixinServer { ...@@ -106,7 +106,7 @@ class WeixinServer {
} }
} }
WeixinServer.AccessToken_Url = 'https://api.weixin.qq.com/cgi-bin/token' WeixinServer.AccessToken_Url = 'https://api.weixin.qq.com/cgi-bin/stable_token'
WeixinServer.Code2Session_Url = 'https://api.weixin.qq.com/sns/jscode2session' WeixinServer.Code2Session_Url = 'https://api.weixin.qq.com/sns/jscode2session'
WeixinServer.User_Encrypt_Key_Url = 'https://api.weixin.qq.com/wxa/business/getuserencryptkey' WeixinServer.User_Encrypt_Key_Url = 'https://api.weixin.qq.com/wxa/business/getuserencryptkey'
WeixinServer.AccessToken_H5_Url = 'https://api.weixin.qq.com/cgi-bin/token' WeixinServer.AccessToken_H5_Url = 'https://api.weixin.qq.com/cgi-bin/token'
......
## 1.3.2(2023-05-04)
- 修复 NVUE 平台报错的问题
## 1.3.1(2021-11-23) ## 1.3.1(2021-11-23)
- 修复 init 方法初始化问题 - 修复 init 方法初始化问题
## 1.3.0(2021-11-19) ## 1.3.0(2021-11-19)
- 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource) - 优化 组件UI,并提供设计资源,详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-transition](https://uniapp.dcloud.io/component/uniui/uni-transition) - 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-transition](https://uniapp.dcloud.io/component/uniui/uni-transition)
## 1.2.1(2021-09-27) ## 1.2.1(2021-09-27)
- 修复 init 方法不生效的 Bug - 修复 init 方法不生效的 Bug
## 1.2.0(2021-07-30) ## 1.2.0(2021-07-30)
- 组件兼容 vue3,如何创建 vue3 项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) - 组件兼容 vue3,如何创建 vue3 项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834)
## 1.1.1(2021-05-12) ## 1.1.1(2021-05-12)
- 新增 示例地址 - 新增 示例地址
- 修复 示例项目缺少组件的 Bug - 修复 示例项目缺少组件的 Bug
## 1.1.0(2021-04-22) ## 1.1.0(2021-04-22)
- 新增 通过方法自定义动画 - 新增 通过方法自定义动画
- 新增 custom-class 非 NVUE 平台支持自定义 class 定制样式 - 新增 custom-class 非 NVUE 平台支持自定义 class 定制样式
- 优化 动画触发逻辑,使动画更流畅 - 优化 动画触发逻辑,使动画更流畅
- 优化 支持单独的动画类型 - 优化 支持单独的动画类型
- 优化 文档示例 - 优化 文档示例
## 1.0.2(2021-02-05) ## 1.0.2(2021-02-05)
- 调整为 uni_modules 目录规范 - 调整为 uni_modules 目录规范
// const defaultOption = { // const defaultOption = {
// duration: 300, // duration: 300,
// timingFunction: 'linear', // timingFunction: 'linear',
// delay: 0, // delay: 0,
// transformOrigin: '50% 50% 0' // transformOrigin: '50% 50% 0'
// } // }
// #ifdef APP-NVUE // #ifdef APP-NVUE
const nvueAnimation = uni.requireNativePlugin('animation') const nvueAnimation = uni.requireNativePlugin('animation')
// #endif // #endif
class MPAnimation { class MPAnimation {
constructor(options, _this) { constructor(options, _this) {
this.options = options this.options = options
this.animation = uni.createAnimation(options) // 在iOS10+QQ小程序平台下,传给原生的对象一定是个普通对象而不是Proxy对象,否则会报parameter should be Object instead of ProxyObject的错误
this.currentStepAnimates = {} this.animation = uni.createAnimation({
this.next = 0 ...options
this.$ = _this })
this.currentStepAnimates = {}
} this.next = 0
this.$ = _this
_nvuePushAnimates(type, args) {
let aniObj = this.currentStepAnimates[this.next] }
let styles = {}
if (!aniObj) { _nvuePushAnimates(type, args) {
styles = { let aniObj = this.currentStepAnimates[this.next]
styles: {}, let styles = {}
config: {} if (!aniObj) {
} styles = {
} else { styles: {},
styles = aniObj config: {}
} }
if (animateTypes1.includes(type)) { } else {
if (!styles.styles.transform) { styles = aniObj
styles.styles.transform = '' }
if (animateTypes1.includes(type)) {
if (!styles.styles.transform) {
styles.styles.transform = ''
} }
let unit = '' let unit = ''
if(type === 'rotate'){ if(type === 'rotate'){
unit = 'deg' unit = 'deg'
} }
styles.styles.transform += `${type}(${args+unit}) ` styles.styles.transform += `${type}(${args+unit}) `
} else { } else {
styles.styles[type] = `${args}` styles.styles[type] = `${args}`
} }
this.currentStepAnimates[this.next] = styles this.currentStepAnimates[this.next] = styles
} }
_animateRun(styles = {}, config = {}) { _animateRun(styles = {}, config = {}) {
let ref = this.$.$refs['ani'].ref let ref = this.$.$refs['ani'].ref
if (!ref) return if (!ref) return
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
nvueAnimation.transition(ref, { nvueAnimation.transition(ref, {
styles, styles,
...config ...config
}, res => { }, res => {
resolve() resolve()
}) })
}) })
} }
_nvueNextAnimate(animates, step = 0, fn) { _nvueNextAnimate(animates, step = 0, fn) {
let obj = animates[step] let obj = animates[step]
if (obj) { if (obj) {
let { let {
styles, styles,
config config
} = obj } = obj
this._animateRun(styles, config).then(() => { this._animateRun(styles, config).then(() => {
step += 1 step += 1
this._nvueNextAnimate(animates, step, fn) this._nvueNextAnimate(animates, step, fn)
}) })
} else { } else {
this.currentStepAnimates = {} this.currentStepAnimates = {}
typeof fn === 'function' && fn() typeof fn === 'function' && fn()
this.isEnd = true this.isEnd = true
} }
} }
step(config = {}) { step(config = {}) {
// #ifndef APP-NVUE // #ifndef APP-NVUE
this.animation.step(config) this.animation.step(config)
// #endif // #endif
// #ifdef APP-NVUE // #ifdef APP-NVUE
this.currentStepAnimates[this.next].config = Object.assign({}, this.options, config) this.currentStepAnimates[this.next].config = Object.assign({}, this.options, config)
this.currentStepAnimates[this.next].styles.transformOrigin = this.currentStepAnimates[this.next].config.transformOrigin this.currentStepAnimates[this.next].styles.transformOrigin = this.currentStepAnimates[this.next].config.transformOrigin
this.next++ this.next++
// #endif // #endif
return this return this
} }
run(fn) { run(fn) {
// #ifndef APP-NVUE // #ifndef APP-NVUE
this.$.animationData = this.animation.export() this.$.animationData = this.animation.export()
this.$.timer = setTimeout(() => { this.$.timer = setTimeout(() => {
typeof fn === 'function' && fn() typeof fn === 'function' && fn()
}, this.$.durationTime) }, this.$.durationTime)
// #endif // #endif
// #ifdef APP-NVUE // #ifdef APP-NVUE
this.isEnd = false this.isEnd = false
let ref = this.$.$refs['ani'] && this.$.$refs['ani'].ref let ref = this.$.$refs['ani'] && this.$.$refs['ani'].ref
if(!ref) return if(!ref) return
this._nvueNextAnimate(this.currentStepAnimates, 0, fn) this._nvueNextAnimate(this.currentStepAnimates, 0, fn)
this.next = 0 this.next = 0
// #endif // #endif
} }
} }
const animateTypes1 = ['matrix', 'matrix3d', 'rotate', 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scale3d', const animateTypes1 = ['matrix', 'matrix3d', 'rotate', 'rotate3d', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scale3d',
'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'translate', 'translate3d', 'translateX', 'translateY', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'translate', 'translate3d', 'translateX', 'translateY',
'translateZ' 'translateZ'
] ]
const animateTypes2 = ['opacity', 'backgroundColor'] const animateTypes2 = ['opacity', 'backgroundColor']
const animateTypes3 = ['width', 'height', 'left', 'right', 'top', 'bottom'] const animateTypes3 = ['width', 'height', 'left', 'right', 'top', 'bottom']
animateTypes1.concat(animateTypes2, animateTypes3).forEach(type => { animateTypes1.concat(animateTypes2, animateTypes3).forEach(type => {
MPAnimation.prototype[type] = function(...args) { MPAnimation.prototype[type] = function(...args) {
// #ifndef APP-NVUE // #ifndef APP-NVUE
this.animation[type](...args) this.animation[type](...args)
// #endif // #endif
// #ifdef APP-NVUE // #ifdef APP-NVUE
this._nvuePushAnimates(type, args) this._nvuePushAnimates(type, args)
// #endif // #endif
return this return this
} }
}) })
export function createAnimation(option, _this) { export function createAnimation(option, _this) {
if(!_this) return if(!_this) return
clearTimeout(_this.timer) clearTimeout(_this.timer)
return new MPAnimation(option, _this) return new MPAnimation(option, _this)
} }
<template> <template>
<view v-if="isShow" ref="ani" :animation="animationData" :class="customClass" :style="transformStyles" @click="onClick"><slot></slot></view> <!-- #ifndef APP-NVUE -->
</template> <view v-show="isShow" ref="ani" :animation="animationData" :class="customClass" :style="transformStyles" @click="onClick"><slot></slot></view>
<!-- #endif -->
<script> <!-- #ifdef APP-NVUE -->
import { createAnimation } from './createAnimation' <view v-if="isShow" ref="ani" :animation="animationData" :class="customClass" :style="transformStyles" @click="onClick"><slot></slot></view>
<!-- #endif -->
/** </template>
* Transition 过渡动画
* @description 简单过渡动画组件 <script>
* @tutorial https://ext.dcloud.net.cn/plugin?id=985 import { createAnimation } from './createAnimation'
* @property {Boolean} show = [false|true] 控制组件显示或隐藏
* @property {Array|String} modeClass = [fade|slide-top|slide-right|slide-bottom|slide-left|zoom-in|zoom-out] 过渡动画类型 /**
* @value fade 渐隐渐出过渡 * Transition 过渡动画
* @value slide-top 由上至下过渡 * @description 简单过渡动画组件
* @value slide-right 由右至左过渡 * @tutorial https://ext.dcloud.net.cn/plugin?id=985
* @value slide-bottom 由下至上过渡 * @property {Boolean} show = [false|true] 控制组件显示或隐藏
* @value slide-left 由左至右过渡 * @property {Array|String} modeClass = [fade|slide-top|slide-right|slide-bottom|slide-left|zoom-in|zoom-out] 过渡动画类型
* @value zoom-in 由小到大过渡 * @value fade 渐隐渐出过渡
* @value zoom-out 由大到小过渡 * @value slide-top 由上至下过渡
* @property {Number} duration 过渡动画持续时间 * @value slide-right 由右至左过渡
* @property {Object} styles 组件样式,同 css 样式,注意带’-‘连接符的属性需要使用小驼峰写法如:`backgroundColor:red` * @value slide-bottom 由下至上过渡
*/ * @value slide-left 由左至右过渡
export default { * @value zoom-in 由小到大过渡
name: 'uniTransition', * @value zoom-out 由大到小过渡
emits:['click','change'], * @property {Number} duration 过渡动画持续时间
props: { * @property {Object} styles 组件样式,同 css 样式,注意带’-‘连接符的属性需要使用小驼峰写法如:`backgroundColor:red`
show: { */
type: Boolean, export default {
default: false name: 'uniTransition',
}, emits:['click','change'],
modeClass: { props: {
type: [Array, String], show: {
default() { type: Boolean,
return 'fade' default: false
} },
}, modeClass: {
duration: { type: [Array, String],
type: Number, default() {
default: 300 return 'fade'
}, }
styles: { },
type: Object, duration: {
default() { type: Number,
return {} default: 300
} },
styles: {
type: Object,
default() {
return {}
}
}, },
customClass:{ customClass:{
type: String, type: String,
default: '' default: ''
} },
}, onceRender:{
data() { type:Boolean,
return { default:false
isShow: false, },
transform: '', },
opacity: 1, data() {
animationData: {}, return {
durationTime: 300, isShow: false,
config: {} transform: '',
} opacity: 1,
}, animationData: {},
watch: { durationTime: 300,
show: { config: {}
handler(newVal) { }
if (newVal) { },
this.open() watch: {
} else { show: {
// 避免上来就执行 close,导致动画错乱 handler(newVal) {
if (this.isShow) { if (newVal) {
this.close() this.open()
} } else {
} // 避免上来就执行 close,导致动画错乱
}, if (this.isShow) {
immediate: true this.close()
} }
}, }
computed: { },
// 生成样式数据 immediate: true
stylesObject() { }
let styles = { },
...this.styles, computed: {
'transition-duration': this.duration / 1000 + 's' // 生成样式数据
} stylesObject() {
let transform = '' let styles = {
for (let i in styles) { ...this.styles,
let line = this.toLine(i) 'transition-duration': this.duration / 1000 + 's'
transform += line + ':' + styles[i] + ';' }
} let transform = ''
return transform for (let i in styles) {
}, let line = this.toLine(i)
// 初始化动画条件 transform += line + ':' + styles[i] + ';'
transformStyles() { }
return 'transform:' + this.transform + ';' + 'opacity:' + this.opacity + ';' + this.stylesObject return transform
} },
}, // 初始化动画条件
created() { transformStyles() {
// 动画默认配置 return 'transform:' + this.transform + ';' + 'opacity:' + this.opacity + ';' + this.stylesObject
this.config = { }
duration: this.duration, },
timingFunction: 'ease', created() {
transformOrigin: '50% 50%', // 动画默认配置
delay: 0 this.config = {
} duration: this.duration,
this.durationTime = this.duration timingFunction: 'ease',
}, transformOrigin: '50% 50%',
methods: { delay: 0
/** }
* ref 触发 初始化动画 this.durationTime = this.duration
*/ },
init(obj = {}) { methods: {
if (obj.duration) { /**
this.durationTime = obj.duration * ref 触发 初始化动画
} */
this.animation = createAnimation(Object.assign(this.config, obj),this) init(obj = {}) {
}, if (obj.duration) {
/** this.durationTime = obj.duration
* 点击组件触发回调 }
*/ this.animation = createAnimation(Object.assign(this.config, obj),this)
onClick() { },
this.$emit('click', { /**
detail: this.isShow * 点击组件触发回调
}) */
}, onClick() {
/** this.$emit('click', {
* ref 触发 动画分组 detail: this.isShow
* @param {Object} obj })
*/ },
step(obj, config = {}) { /**
* ref 触发 动画分组
* @param {Object} obj
*/
step(obj, config = {}) {
if (!this.animation) return if (!this.animation) return
for (let i in obj) { for (let i in obj) {
try { try {
if(typeof obj[i] === 'object'){ if(typeof obj[i] === 'object'){
this.animation[i](...obj[i]) this.animation[i](...obj[i])
}else{ }else{
this.animation[i](obj[i]) this.animation[i](obj[i])
} }
} catch (e) { } catch (e) {
console.error(`方法 ${i} 不存在`) console.error(`方法 ${i} 不存在`)
} }
} }
this.animation.step(config) this.animation.step(config)
return this return this
}, },
/** /**
* ref 触发 执行动画 * ref 触发 执行动画
*/ */
run(fn) { run(fn) {
if (!this.animation) return if (!this.animation) return
this.animation.run(fn) this.animation.run(fn)
}, },
// 开始过度动画 // 开始过度动画
open() { open() {
clearTimeout(this.timer) clearTimeout(this.timer)
this.transform = '' this.transform = ''
this.isShow = true this.isShow = true
let { opacity, transform } = this.styleInit(false) let { opacity, transform } = this.styleInit(false)
if (typeof opacity !== 'undefined') { if (typeof opacity !== 'undefined') {
this.opacity = opacity this.opacity = opacity
} }
this.transform = transform this.transform = transform
// 确保动态样式已经生效后,执行动画,如果不加 nextTick ,会导致 wx 动画执行异常 // 确保动态样式已经生效后,执行动画,如果不加 nextTick ,会导致 wx 动画执行异常
this.$nextTick(() => { this.$nextTick(() => {
// TODO 定时器保证动画完全执行,目前有些问题,后面会取消定时器 // TODO 定时器保证动画完全执行,目前有些问题,后面会取消定时器
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.animation = createAnimation(this.config, this) this.animation = createAnimation(this.config, this)
this.tranfromInit(false).step() this.tranfromInit(false).step()
this.animation.run() this.animation.run()
this.$emit('change', { this.$emit('change', {
detail: this.isShow detail: this.isShow
}) })
}, 20) }, 20)
}) })
}, },
// 关闭过度动画 // 关闭过度动画
close(type) { close(type) {
if (!this.animation) return if (!this.animation) return
this.tranfromInit(true) this.tranfromInit(true)
.step() .step()
.run(() => { .run(() => {
this.isShow = false this.isShow = false
this.animationData = null this.animationData = null
this.animation = null this.animation = null
let { opacity, transform } = this.styleInit(false) let { opacity, transform } = this.styleInit(false)
this.opacity = opacity || 1 this.opacity = opacity || 1
this.transform = transform this.transform = transform
this.$emit('change', { this.$emit('change', {
detail: this.isShow detail: this.isShow
}) })
}) })
}, },
// 处理动画开始前的默认样式 // 处理动画开始前的默认样式
styleInit(type) { styleInit(type) {
let styles = { let styles = {
transform: '' transform: ''
} }
let buildStyle = (type, mode) => { let buildStyle = (type, mode) => {
if (mode === 'fade') { if (mode === 'fade') {
styles.opacity = this.animationType(type)[mode] styles.opacity = this.animationType(type)[mode]
} else { } else {
styles.transform += this.animationType(type)[mode] + ' ' styles.transform += this.animationType(type)[mode] + ' '
} }
} }
if (typeof this.modeClass === 'string') { if (typeof this.modeClass === 'string') {
buildStyle(type, this.modeClass) buildStyle(type, this.modeClass)
} else { } else {
this.modeClass.forEach(mode => { this.modeClass.forEach(mode => {
buildStyle(type, mode) buildStyle(type, mode)
}) })
} }
return styles return styles
}, },
// 处理内置组合动画 // 处理内置组合动画
tranfromInit(type) { tranfromInit(type) {
let buildTranfrom = (type, mode) => { let buildTranfrom = (type, mode) => {
let aniNum = null let aniNum = null
if (mode === 'fade') { if (mode === 'fade') {
aniNum = type ? 0 : 1 aniNum = type ? 0 : 1
} else { } else {
aniNum = type ? '-100%' : '0' aniNum = type ? '-100%' : '0'
if (mode === 'zoom-in') { if (mode === 'zoom-in') {
aniNum = type ? 0.8 : 1 aniNum = type ? 0.8 : 1
} }
if (mode === 'zoom-out') { if (mode === 'zoom-out') {
aniNum = type ? 1.2 : 1 aniNum = type ? 1.2 : 1
} }
if (mode === 'slide-right') { if (mode === 'slide-right') {
aniNum = type ? '100%' : '0' aniNum = type ? '100%' : '0'
} }
if (mode === 'slide-bottom') { if (mode === 'slide-bottom') {
aniNum = type ? '100%' : '0' aniNum = type ? '100%' : '0'
} }
} }
this.animation[this.animationMode()[mode]](aniNum) this.animation[this.animationMode()[mode]](aniNum)
} }
if (typeof this.modeClass === 'string') { if (typeof this.modeClass === 'string') {
buildTranfrom(type, this.modeClass) buildTranfrom(type, this.modeClass)
} else { } else {
this.modeClass.forEach(mode => { this.modeClass.forEach(mode => {
buildTranfrom(type, mode) buildTranfrom(type, mode)
}) })
} }
return this.animation return this.animation
}, },
animationType(type) { animationType(type) {
return { return {
fade: type ? 1 : 0, fade: type ? 1 : 0,
'slide-top': `translateY(${type ? '0' : '-100%'})`, 'slide-top': `translateY(${type ? '0' : '-100%'})`,
'slide-right': `translateX(${type ? '0' : '100%'})`, 'slide-right': `translateX(${type ? '0' : '100%'})`,
'slide-bottom': `translateY(${type ? '0' : '100%'})`, 'slide-bottom': `translateY(${type ? '0' : '100%'})`,
'slide-left': `translateX(${type ? '0' : '-100%'})`, 'slide-left': `translateX(${type ? '0' : '-100%'})`,
'zoom-in': `scaleX(${type ? 1 : 0.8}) scaleY(${type ? 1 : 0.8})`, 'zoom-in': `scaleX(${type ? 1 : 0.8}) scaleY(${type ? 1 : 0.8})`,
'zoom-out': `scaleX(${type ? 1 : 1.2}) scaleY(${type ? 1 : 1.2})` 'zoom-out': `scaleX(${type ? 1 : 1.2}) scaleY(${type ? 1 : 1.2})`
} }
}, },
// 内置动画类型与实际动画对应字典 // 内置动画类型与实际动画对应字典
animationMode() { animationMode() {
return { return {
fade: 'opacity', fade: 'opacity',
'slide-top': 'translateY', 'slide-top': 'translateY',
'slide-right': 'translateX', 'slide-right': 'translateX',
'slide-bottom': 'translateY', 'slide-bottom': 'translateY',
'slide-left': 'translateX', 'slide-left': 'translateX',
'zoom-in': 'scale', 'zoom-in': 'scale',
'zoom-out': 'scale' 'zoom-out': 'scale'
} }
}, },
// 驼峰转中横线 // 驼峰转中横线
toLine(name) { toLine(name) {
return name.replace(/([A-Z])/g, '-$1').toLowerCase() return name.replace(/([A-Z])/g, '-$1').toLowerCase()
} }
} }
} }
</script> </script>
<style></style> <style></style>
{ {
"id": "uni-transition", "id": "uni-transition",
"displayName": "uni-transition 过渡动画", "displayName": "uni-transition 过渡动画",
"version": "1.3.1", "version": "1.3.2",
"description": "元素的简单过渡动画", "description": "元素的简单过渡动画",
"keywords": [ "keywords": [
"uni-ui", "uni-ui",
"uniui", "uniui",
"动画", "动画",
"过渡", "过渡",
"过渡动画" "过渡动画"
], ],
"repository": "https://github.com/dcloudio/uni-ui", "repository": "https://github.com/dcloudio/uni-ui",
"engines": { "engines": {
"HBuilderX": "" "HBuilderX": ""
}, },
"directories": { "directories": {
"example": "../../temps/example_temps" "example": "../../temps/example_temps"
}, },
"dcloudext": { "dcloudext": {
"category": [ "sale": {
"前端组件", "regular": {
"通用组件" "price": "0.00"
], },
"sale": { "sourcecode": {
"regular": { "price": "0.00"
"price": "0.00" }
}, },
"sourcecode": { "contact": {
"price": "0.00" "qq": ""
} },
}, "declaration": {
"contact": { "ads": "无",
"qq": "" "data": "无",
}, "permissions": "无"
"declaration": { },
"ads": "无", "npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui",
"data": "无", "type": "component-vue"
"permissions": "无" },
}, "uni_modules": {
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui" "dependencies": ["uni-scss"],
}, "encrypt": [],
"uni_modules": { "platforms": {
"dependencies": ["uni-scss"], "cloud": {
"encrypt": [], "tcb": "y",
"platforms": { "aliyun": "y"
"cloud": { },
"tcb": "y", "client": {
"aliyun": "y" "App": {
}, "app-vue": "y",
"client": { "app-nvue": "y"
"App": { },
"app-vue": "y", "H5-mobile": {
"app-nvue": "y" "Safari": "y",
}, "Android Browser": "y",
"H5-mobile": { "微信浏览器(Android)": "y",
"Safari": "y", "QQ浏览器(Android)": "y"
"Android Browser": "y", },
"微信浏览器(Android)": "y", "H5-pc": {
"QQ浏览器(Android)": "y" "Chrome": "y",
}, "IE": "y",
"H5-pc": { "Edge": "y",
"Chrome": "y", "Firefox": "y",
"IE": "y", "Safari": "y"
"Edge": "y", },
"Firefox": "y", "小程序": {
"Safari": "y" "微信": "y",
}, "阿里": "y",
"小程序": { "百度": "y",
"微信": "y", "字节跳动": "y",
"阿里": "y", "QQ": "y"
"百度": "y", },
"字节跳动": "y", "快应用": {
"QQ": "y" "华为": "u",
}, "联盟": "u"
"快应用": { },
"华为": "u", "Vue": {
"联盟": "u" "vue2": "y",
}, "vue3": "y"
"Vue": { }
"vue2": "y", }
"vue3": "y" }
} }
}
}
}
} }
\ No newline at end of file
## Transition 过渡动画 ## Transition 过渡动画
> **组件名:uni-transition** > **组件名:uni-transition**
> 代码块: `uTransition` > 代码块: `uTransition`
元素过渡动画 元素过渡动画
### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-transition) ### [查看文档](https://uniapp.dcloud.io/component/uniui/uni-transition)
#### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839 #### 如使用过程中有任何问题,或者您对uni-ui有一些好的建议,欢迎加入 uni-ui 交流群:871950839
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册