Skip to content

Commit

Permalink
规范化及兼容性增强
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Apr 16, 2024
1 parent 6be3306 commit d979c9c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
16 changes: 7 additions & 9 deletions src/pages/example/components.nvue
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</template>
</up-cell>
</up-cell-group>
</view>
<up-gap height="30" bgColor="#fff"></up-gap>
</view>
<up-gap height="30" bgColor="#fff"></up-gap>
<up-alert description ='uview-plus 2022-2024'></up-alert>
<up-gap height="30" bgColor="#fff"></up-gap>
</view>
Expand All @@ -31,15 +31,13 @@
}
},
computed: {
getIcon() {
return (path: string) => {
return 'https://uview-plus.jiangruyi.com/h5/static/uview/demo/' + path + '.png';
}
},
},
onLoad() {
},
onLoad() {
},
methods: {
getIcon(path: string) {
return 'https://uview-plus.jiangruyi.com/h5/static/uview/demo/' + path + '.png';
},
openPage(detail: { name: string }) {
const path = detail.name
// #ifdef APP-NVUE
Expand Down
10 changes: 4 additions & 6 deletions src/pages/example/template.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</view>
</template>

<script>
<script lang="ts">
import list from "./template.config.js";
export default {
data() {
Expand All @@ -30,11 +30,6 @@
}
},
computed: {
getIcon() {
return path => {
return 'https://uview-plus.jiangruyi.com/h5/static/uview/demo/' + path + '.png';
}
},
desc() {
return this.$t('template.desc');
}
Expand All @@ -45,6 +40,9 @@
});
},
methods: {
getIcon(path) {
return 'https://uview-plus.jiangruyi.com/h5/static/uview/demo/' + path + '.png';
},
openPage(path) {
this.$u.route({
url: path.indexOf('/page') == 0 ? path : '/pages/template/' + path + '/index'
Expand Down
22 changes: 12 additions & 10 deletions src/uni_modules/uview-plus/libs/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function range(min = 0, max = 0, value = 0) {
}

/**
* @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.upx2px进行转换
* @description 用于获取用户传递值的px值 如果用户传递了"xxpx"或者"xxrpx",取出其数值部分,如果是"xxxrpx"还需要用过uni.rpx2px进行转换
* @param {number|string} value 用户传递值的px值
* @param {boolean} unit
* @returns {number|string}
Expand All @@ -27,7 +27,7 @@ export function getPx(value, unit = false) {
}
// 如果带有rpx,先取出其数值部分,再转为px值
if (/(rpx|upx)$/.test(value)) {
return unit ? `${uni.upx2px(parseInt(value))}px` : Number(uni.upx2px(parseInt(value)))
return unit ? `${uni.rpx2px(parseInt(value))}px` : Number(uni.rpx2px(parseInt(value)))

This comment has been minimized.

Copy link
@HEI-cloud

HEI-cloud May 12, 2024

rpx2px方法,是UTSAndroid的方法,仅在app-android平台专有的内置对象。
导致编译到小程序平台报错!
希望尽快修复!
uniapp原文档地址:https://doc.dcloud.net.cn/uni-app-x/uts/utsandroid.html#utsandroid

}
return unit ? `${parseInt(value)}px` : parseInt(value)
}
Expand Down Expand Up @@ -161,10 +161,12 @@ export function addStyle(customStyle, target = 'object') {
}
// 这里为对象转字符串形式
let string = ''
for (const i in customStyle) {
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
string += `${key}:${customStyle[i]};`
if (typeof customStyle === 'object') {
customStyle.forEach((val, i) => {
// 驼峰转为中划线的形式,否则css内联样式,无法识别驼峰样式属性名
const key = i.replace(/([A-Z])/g, '-$1').toLowerCase()
string += `${key}:${val};`
})
}
// 去除两端空格
return trim(string)
Expand Down Expand Up @@ -612,9 +614,9 @@ export function formValidate(instance, event) {
* @returns {*}
*/
export function getProperty(obj, key) {
if (!obj) {
return
}
if (typeof obj !== 'object' || null == obj) {
return ''
}
if (typeof key !== 'string' || key === '') {
return ''
}
Expand All @@ -639,7 +641,7 @@ export function getProperty(obj, key) {
* @param {string} value 设置的值
*/
export function setProperty(obj, key, value) {
if (!obj) {
if (typeof obj !== 'object' || null == obj) {
return
}
// 递归赋值
Expand Down

0 comments on commit d979c9c

Please sign in to comment.