Skip to content

Commit

Permalink
feat: up-row/up-col组件支持uni-app-x
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Aug 27, 2024
1 parent 01dee26 commit b3ff2ae
Show file tree
Hide file tree
Showing 15 changed files with 532 additions and 136 deletions.
14 changes: 7 additions & 7 deletions src/uni_modules/uview-plus/components/up-button/up-button.uvue
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ import { throttle } from '../../libs/function/throttle';
export default {
name: "up-button",
// #ifdef MP
mixins: [mpMixin, mixin, button, openType, propsButton],
mixins: [mpMixin, mixin, buttonMixin, openType, propsButton],
// #endif
// #ifndef MP
mixins: [mpMixin, mixin, propsButton],
Expand Down Expand Up @@ -153,7 +153,7 @@ export default {
? this.color
: config.getString(`color.up-${this.type}`) as String;
}
if (this.type === "info") {
if (this.type == "info") {
return "#c9c9c9";
}
return "rgb(200, 200, 200)";
Expand All @@ -168,13 +168,13 @@ export default {
return "";
}
},
baseColor(): any {
baseColor(): UTSJSONObject {
let style = {
color: ''
};
} as UTSJSONObject;
if (this.color != '') {
// 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
style.color = this.plain ? this.color : "white";
style['color'] = this.plain ? this.color : "white";
if (!this.plain) {
// 非镂空,背景色使用自定义的颜色
style["backgroundColor"] = this.color;
Expand All @@ -200,8 +200,8 @@ export default {
return style;
},
// nvue版本按钮的字体不会继承父组件的颜色,需要对每一个text组件进行单独的设置
nvueTextStyle(): any {
let style = {};
nvueTextStyle(): UTSJSONObject {
let style = {} as UTSJSONObject;
// 针对自定义了color颜色的情况,镂空状态下,就是用自定义的颜色
if (this.type === "info") {
style['color'] = "#323233";
Expand Down
19 changes: 19 additions & 0 deletions src/uni_modules/uview-plus/components/up-col/col.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* @Author : LQ,jry
* @Description :
* @version : 3.0
* @Date : 2021-08-20 16:44:21
* @LastAuthor : jry
* @lastTime : 2024-08-20 14:20:58
* @FilePath : /uview-plus/libs/config/props/col.js
*/
export default {
// col 组件
col: {
span: '12',
offset: '0',
justify: 'start',
align: 'stretch',
textAlign: 'left'
}
} as UTSJSONObject
3 changes: 2 additions & 1 deletion src/uni_modules/uview-plus/components/up-col/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineMixin } from '../../libs/vue.js'
import defProps from '../../libs/config/props.js'
export const props = defineMixin({

export const propsCol = defineMixin({
props: {
// 占父容器宽度的多少等分,总分为12份
span: {
Expand Down
33 changes: 33 additions & 0 deletions src/uni_modules/uview-plus/components/up-col/props.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineMixin } from '../../libs/vue'
import defProps from './col'
let crtProp = defProps['col'] as UTSJSONObject

export const propsCol = defineMixin({
props: {
// 占父容器宽度的多少等分,总分为12份
span: {
type: [String, Number],
default: crtProp['span']
},
// 指定栅格左侧的间隔数(总12栏)
offset: {
type: [String, Number],
default: crtProp['offset']
},
// 水平排列方式,可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`)
justify: {
type: String,
default: crtProp['justify']
},
// 垂直对齐方式,可选值为top、center、bottom、stretch
align: {
type: String,
default: crtProp['align']
},
// 文字对齐方式
textAlign: {
type: String,
default: crtProp['textAlign']
}
}
})
170 changes: 170 additions & 0 deletions src/uni_modules/uview-plus/components/up-col/up-col.uvue
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<template>
<view
class="up-col"
ref="up-col"
:class="[
'up-col-' + span
]"
:style="[colStyle]"
@tap="clickHandler"
>
<slot></slot>
</view>
</template>

<script>
import { propsCol } from './props';
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addStyle, addUnit, deepMerge, getPx, getParentData } from '../../libs/function/index';
/**
* CodeInput 栅格系统的列
* @description 该组件一般用于Layout 布局 通过基础的 12 分栏,迅速简便地创建布局
* @tutorial https://ijry.github.io/uview-plus/components/Layout.html
* @property {String | Number} span 栅格占据的列数,总12等份 (默认 12 )
* @property {String | Number} offset 分栏左边偏移,计算方式与span相同 (默认 0 )
* @property {String} justify 水平排列方式,可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`) (默认 'start' )
* @property {String} align 垂直对齐方式,可选值为top、center、bottom、stretch (默认 'stretch' )
* @property {String} textAlign 文字水平对齐方式 (默认 'left' )
* @property {Object} customStyle 定义需要用到的外部样式
* @event {Function} click col被点击,会阻止事件冒泡到row
* @example <up-col span="3" offset="3" > <view class="demo-layout bg-purple"></view> </up-col>
*/
export default {
name: 'up-col',
mixins: [mpMixin, mixin, propsCol],
data() {
return {
width: 0,
parent: null as ComponentPublicInstance|null,
parentData: {
gutter: 0
} as UTSJSONObject,
gridNum: 12
}
},
// 微信小程序中 options 选项
// #ifdef MP-WEIXIN
options: {
virtualHost: true // 将自定义节点设置成虚拟的,更加接近Vue组件的表现。我们不希望自定义组件的这个节点本身可以设置样式、响应 flex 布局等
},
// #endif
computed: {
uJustify(): string {
if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify
else if (this.justify == 'around' || this.justify == 'between') return 'space-' + this.justify
else return this.justify
},
uAlignItem(): string {
if (this.align == 'top') return 'flex-start'
if (this.align == 'bottom') return 'flex-end'
else return this.align
},
colStyle(): any {
let pct = 100 / this.gridNum * parseInt(this.span.toString());
const style = {
// 这里写成"padding: 0 10px"的形式是因为nvue的需要
paddingLeft: addUnit(parseInt(getPx(this.parentData['gutter'].toString()))/2),
paddingRight: addUnit(parseInt(getPx(this.parentData['gutter'].toString()))/2),
alignItems: this.uAlignItem,
justifyContent: this.uJustify,
textAlign: this.textAlign,
flex: `0 0 ${pct.toString()}%`,
marginLeft: (100 / 12 * parseInt(this.offset.toString())).toString() + '%'
}
return deepMerge(style, addStyle(this.customStyle))
}
},
mounted() {
this.init()
},
emits: ["click"],
methods: {
init(): void {
// 支付宝小程序不支持provide/inject,所以使用这个方法获取整个父组件,在created定义,避免循环引用
this.updateParentData()
console.log(this.parent)
// this?.parent?.getComponentWidth().then((width: number|null) => {
// // this.width = parseInt(width.toString())
// // // console.log(this.width)
// })
},
updateParentData(): void {
this.getParentData('up-row')
},
clickHandler(e: any): void {
this.$emit('click');
}
},
}
</script>

<style lang="scss" scoped>
@import "../../libs/css/components.scss";

.up-col {
padding: 0;
/* #ifndef APP-NVUE */
box-sizing:border-box;
/* #endif */
/* #ifdef MP */
display: block;
/* #endif */
}

// nvue下百分比无效
/* #ifndef APP-NVUE */
.up-col-0 {
width: 0;
}

.up-col-1 {
width: calc(100%/12);
}

.up-col-2 {
width: calc(100%/12 * 2);
}

.up-col-3 {
width: calc(100%/12 * 3);
}

.up-col-4 {
width: calc(100%/12 * 4);
}

.up-col-5 {
width: calc(100%/12 * 5);
}

.up-col-6 {
width: calc(100%/12 * 6);
}

.up-col-7 {
width: calc(100%/12 * 7);
}

.up-col-8 {
width: calc(100%/12 * 8);
}

.up-col-9 {
width: calc(100%/12 * 9);
}

.up-col-10 {
width: calc(100%/12 * 10);
}

.up-col-11 {
width: calc(100%/12 * 11);
}

.up-col-12 {
width: calc(100%/12 * 12);
}

/* #endif */
</style>
6 changes: 4 additions & 2 deletions src/uni_modules/uview-plus/components/up-col/up-col.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</template>

<script>
import { props } from './props.js';
import { propsCol } from './props.js';
import { mpMixin } from '../../libs/mixin/mpMixin.js';
import { mixin } from '../../libs/mixin/mixin.js';
import { addStyle, addUnit, deepMerge, getPx } from '../../libs/function/index.js';
Expand All @@ -32,7 +32,7 @@
*/
export default {
name: 'up-col',
mixins: [mpMixin, mixin, props],
mixins: [mpMixin, mixin, propsCol],
data() {
return {
width: 0,
Expand All @@ -43,9 +43,11 @@
}
},
// 微信小程序中 options 选项
// #ifdef MP-WEIXIN
options: {
virtualHost: true // 将自定义节点设置成虚拟的,更加接近Vue组件的表现。我们不希望自定义组件的这个节点本身可以设置样式、响应 flex 布局等
},
// #endif
computed: {
uJustify() {
if (this.justify == 'end' || this.justify == 'start') return 'flex-' + this.justify
Expand Down
3 changes: 2 additions & 1 deletion src/uni_modules/uview-plus/components/up-row/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineMixin } from '../../libs/vue.js'
import defProps from '../../libs/config/props.js'
export const props = defineMixin({

export const propsRow = defineMixin({
props: {
// 给col添加间距,左右边距各占一半
gutter: {
Expand Down
23 changes: 23 additions & 0 deletions src/uni_modules/uview-plus/components/up-row/props.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineMixin } from '../../libs/vue'
import defProps from './row'
let crtProp = defProps['row'] as UTSJSONObject

export const propsRow = defineMixin({
props: {
// 给col添加间距,左右边距各占一半
gutter: {
type: [String, Number],
default: crtProp['gutter']
},
// 水平排列方式,可选值为`start`(或`flex-start`)、`end`(或`flex-end`)、`center`、`around`(或`space-around`)、`between`(或`space-between`)
justify: {
type: String,
default: crtProp['justify']
},
// 垂直对齐方式,可选值为top、center、bottom
align: {
type: String,
default: crtProp['align']
}
}
})
17 changes: 17 additions & 0 deletions src/uni_modules/uview-plus/components/up-row/row.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* @Author : LQ,jry
* @Description :
* @version : 3.0
* @Date : 2021-08-20 16:44:21
* @LastAuthor : jry
* @lastTime : 2024-08-20 14:20:58
* @FilePath : /uview-plus/libs/config/props/row.js
*/
export default {
// row
row: {
gutter: 0,
justify: 'start',
align: 'center'
}
} as UTSJSONObject
Loading

0 comments on commit b3ff2ae

Please sign in to comment.