【升级】升级小程序简短UI框架UView至2.0.35版本。

This commit is contained in:
大灰灰
2022-10-31 16:35:14 +08:00
parent 75567e482f
commit 94181c5789
4 changed files with 117 additions and 114 deletions

View File

@@ -1,4 +1,4 @@
## 2.0.342022-09-25 ## 2.0.342022-09-24
# uView2.0重磅发布,利剑出鞘,一统江湖 # uView2.0重磅发布,利剑出鞘,一统江湖
1. `u-input``u-textarea`增加`ignoreCompositionEvent`属性 1. `u-input``u-textarea`增加`ignoreCompositionEvent`属性

View File

@@ -146,7 +146,7 @@
}, },
// 点击遮罩 // 点击遮罩
// 从原理上来说modal的遮罩点击并不是真的点击到了遮罩 // 从原理上来说modal的遮罩点击并不是真的点击到了遮罩
// 因为modal依赖于popup的中部弹窗类型中部弹窗比较特殊然遮罩但是为了让弹窗内容能flex居中 // 因为modal依赖于popup的中部弹窗类型中部弹窗比较特殊虽然遮罩但是为了让弹窗内容能flex居中
// 多了一个透明的遮罩此透明的遮罩会覆盖在灰色的遮罩上所以实际上是点击不到灰色遮罩的popup内部在 // 多了一个透明的遮罩此透明的遮罩会覆盖在灰色的遮罩上所以实际上是点击不到灰色遮罩的popup内部在
// 透明遮罩的子元素做了.stop处理所以点击内容区也不会导致误触发 // 透明遮罩的子元素做了.stop处理所以点击内容区也不会导致误触发
clickHandler() { clickHandler() {

View File

@@ -4,121 +4,121 @@
*/ */
class Router { class Router {
constructor() { constructor() {
// 原始属性定义 // 原始属性定义
this.config = { this.config = {
type: 'navigateTo', type: 'navigateTo',
url: '', url: '',
delta: 1, // navigateBack页面后退时,回退的层数 delta: 1, // navigateBack页面后退时,回退的层数
params: {}, // 传递的参数 params: {}, // 传递的参数
animationType: 'pop-in', // 窗口动画,只在APP有效 animationType: 'pop-in', // 窗口动画,只在APP有效
animationDuration: 300, // 窗口动画持续时间,单位毫秒,只在APP有效 animationDuration: 300, // 窗口动画持续时间,单位毫秒,只在APP有效
intercept: false // 是否需要拦截 intercept: false // 是否需要拦截
} }
// 因为route方法是需要对外赋值给另外的对象使用同时route内部有使用this会导致route失去上下文 // 因为route方法是需要对外赋值给另外的对象使用同时route内部有使用this会导致route失去上下文
// 这里在构造函数中进行this绑定 // 这里在构造函数中进行this绑定
this.route = this.route.bind(this) this.route = this.route.bind(this)
} }
// 判断url前面是否有"/",如果没有则加上,否则无法跳转 // 判断url前面是否有"/",如果没有则加上,否则无法跳转
addRootPath(url) { addRootPath(url) {
return url[0] === '/' ? url : `/${url}` return url[0] === '/' ? url : `/${url}`
} }
// 整合路由参数 // 整合路由参数
mixinParam(url, params) { mixinParam(url, params) {
url = url && this.addRootPath(url) url = url && this.addRootPath(url)
// 使用正则匹配,主要依据是判断是否有"/","?","="等,如“/page/index/index?name=mary" // 使用正则匹配,主要依据是判断是否有"/","?","="等,如“/page/index/index?name=mary"
// 如果有url中有get参数转换后无需带上"?" // 如果有url中有get参数转换后无需带上"?"
let query = '' let query = ''
if (/.*\/.*\?.*=.*/.test(url)) { if (/.*\/.*\?.*=.*/.test(url)) {
// object对象转为get类型的参数 // object对象转为get类型的参数
query = uni.$u.queryParams(params, false) query = uni.$u.queryParams(params, false)
// 因为已有get参数,所以后面拼接的参数需要带上"&"隔开 // 因为已有get参数,所以后面拼接的参数需要带上"&"隔开
return url += `&${query}` return url += `&${query}`
} }
// 直接拼接参数因为此处url中没有后面的query参数也就没有"?/&"之类的符号 // 直接拼接参数因为此处url中没有后面的query参数也就没有"?/&"之类的符号
query = uni.$u.queryParams(params) query = uni.$u.queryParams(params)
return url += query return url += query
} }
// 对外的方法名称 // 对外的方法名称
async route(options = {}, params = {}) { async route(options = {}, params = {}) {
// 合并用户的配置和内部的默认配置 // 合并用户的配置和内部的默认配置
let mergeConfig = {} let mergeConfig = {}
if (typeof options === 'string') { if (typeof options === 'string') {
// 如果options为字符串则为route(url, params)的形式 // 如果options为字符串则为route(url, params)的形式
mergeConfig.url = this.mixinParam(options, params) mergeConfig.url = this.mixinParam(options, params)
mergeConfig.type = 'navigateTo' mergeConfig.type = 'navigateTo'
} else { } else {
mergeConfig = uni.$u.deepMerge(options, this.config) mergeConfig = uni.$u.deepMerge(this.config, options)
// 否则正常使用mergeConfig中的url和params进行拼接 // 否则正常使用mergeConfig中的url和params进行拼接
mergeConfig.url = this.mixinParam(options.url, options.params) mergeConfig.url = this.mixinParam(options.url, options.params)
} }
// 如果本次跳转的路径和本页面路径一致,不执行跳转,防止用户快速点击跳转按钮,造成多次跳转同一个页面的问题 // 如果本次跳转的路径和本页面路径一致,不执行跳转,防止用户快速点击跳转按钮,造成多次跳转同一个页面的问题
if (mergeConfig.url === uni.$u.page()) return if (mergeConfig.url === uni.$u.page()) return
if (params.intercept) { if (params.intercept) {
this.config.intercept = params.intercept this.config.intercept = params.intercept
} }
// params参数也带给拦截器 // params参数也带给拦截器
mergeConfig.params = params mergeConfig.params = params
// 合并内外部参数 // 合并内外部参数
mergeConfig = uni.$u.deepMerge(this.config, mergeConfig) mergeConfig = uni.$u.deepMerge(this.config, mergeConfig)
// 判断用户是否定义了拦截器 // 判断用户是否定义了拦截器
if (typeof uni.$u.routeIntercept === 'function') { if (typeof uni.$u.routeIntercept === 'function') {
// 定一个promise根据用户执行resolve(true)或者resolve(false)来决定是否进行路由跳转 // 定一个promise根据用户执行resolve(true)或者resolve(false)来决定是否进行路由跳转
const isNext = await new Promise((resolve, reject) => { const isNext = await new Promise((resolve, reject) => {
uni.$u.routeIntercept(mergeConfig, resolve) uni.$u.routeIntercept(mergeConfig, resolve)
}) })
// 如果isNext为true则执行路由跳转 // 如果isNext为true则执行路由跳转
isNext && this.openPage(mergeConfig) isNext && this.openPage(mergeConfig)
} else { } else {
this.openPage(mergeConfig) this.openPage(mergeConfig)
} }
} }
// 执行路由跳转 // 执行路由跳转
openPage(config) { openPage(config) {
// 解构参数 // 解构参数
const { const {
url, url,
type, type,
delta, delta,
animationType, animationType,
animationDuration animationDuration
} = config } = config
if (config.type == 'navigateTo' || config.type == 'to') { if (config.type == 'navigateTo' || config.type == 'to') {
uni.navigateTo({ uni.navigateTo({
url, url,
animationType, animationType,
animationDuration animationDuration
}) })
} }
if (config.type == 'redirectTo' || config.type == 'redirect') { if (config.type == 'redirectTo' || config.type == 'redirect') {
uni.redirectTo({ uni.redirectTo({
url url
}) })
} }
if (config.type == 'switchTab' || config.type == 'tab') { if (config.type == 'switchTab' || config.type == 'tab') {
uni.switchTab({ uni.switchTab({
url url
}) })
} }
if (config.type == 'reLaunch' || config.type == 'launch') { if (config.type == 'reLaunch' || config.type == 'launch') {
uni.reLaunch({ uni.reLaunch({
url url
}) })
} }
if (config.type == 'navigateBack' || config.type == 'back') { if (config.type == 'navigateBack' || config.type == 'back') {
uni.navigateBack({ uni.navigateBack({
delta delta
}) })
} }
} }
} }
export default (new Router()).route export default (new Router()).route

View File

@@ -2,7 +2,7 @@
"id": "uview-ui", "id": "uview-ui",
"name": "uview-ui", "name": "uview-ui",
"displayName": "uView2.0重磅发布,利剑出鞘,一统江湖", "displayName": "uView2.0重磅发布,利剑出鞘,一统江湖",
"version": "2.0.34", "version": "2.0.35",
"description": "uView UI已完美兼容nvue全面的组件和便捷的工具会让您信手拈来如鱼得水", "description": "uView UI已完美兼容nvue全面的组件和便捷的工具会让您信手拈来如鱼得水",
"keywords": [ "keywords": [
"uview", "uview",
@@ -17,8 +17,12 @@
"engines": { "engines": {
"HBuilderX": "^3.1.0" "HBuilderX": "^3.1.0"
}, },
"dcloudext": { "dcloudext": {
"sale": { "category": [
"前端组件",
"通用组件"
],
"sale": {
"regular": { "regular": {
"price": "0.00" "price": "0.00"
}, },
@@ -34,8 +38,7 @@
"data": "无", "data": "无",
"permissions": "无" "permissions": "无"
}, },
"npmurl": "https://www.npmjs.com/package/uview-ui", "npmurl": "https://www.npmjs.com/package/uview-ui"
"type": "component-vue"
}, },
"uni_modules": { "uni_modules": {
"dependencies": [], "dependencies": [],