杨豪
3 years ago
23 changed files with 989 additions and 478 deletions
@ -0,0 +1,66 @@
|
||||
<template> |
||||
<swiper class="swiper-block" autoplay="true" circular="true" previous-margin="90rpx" next-margin="90rpx" current="0" @change="swiperChange"> |
||||
<block v-for="(item, index) in imgs" :key="index"> |
||||
<swiper-item class="swiper-item" :class="(swiperIndex == index ? 'active' : '')" @tap="previewImg"> |
||||
<image mode="aspectFill" :src="item" :class="'slide-image ' + (swiperIndex == index ? 'active' : '')"></image> |
||||
</swiper-item> |
||||
</block> |
||||
</swiper> |
||||
</template> |
||||
|
||||
<script> |
||||
export default{ |
||||
props: { |
||||
imgs: { |
||||
type: Array, |
||||
default: [] |
||||
} |
||||
}, |
||||
data(){ |
||||
return { |
||||
swiperIndex: 0 |
||||
} |
||||
}, |
||||
methods: { |
||||
swiperChange(e) { |
||||
const that = this; |
||||
that.setData({ |
||||
swiperIndex: e.detail.current |
||||
}); |
||||
}, |
||||
|
||||
previewImg() { |
||||
uni.previewImage({ |
||||
urls: this.imgs |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style lang="less"> |
||||
.swiper-block { |
||||
height: 300rpx; |
||||
width: 100%; |
||||
} |
||||
|
||||
.swiper-item { |
||||
display: flex; |
||||
flex-direction: column; |
||||
justify-content: center; |
||||
align-items: flex-start; |
||||
overflow: unset; |
||||
} |
||||
.slide-image { |
||||
height: 250rpx; |
||||
width: 520rpx; |
||||
border-radius: 9rpx; |
||||
margin: 0rpx 30rpx; |
||||
z-index: 1; |
||||
} |
||||
.active { |
||||
transform: scale(1.14); |
||||
transition: all 0.2s ease-in 0s; |
||||
z-index: 20; |
||||
} |
||||
</style> |
@ -0,0 +1,99 @@
|
||||
<template> |
||||
<swiper class="swiper-block" vertical="true" circular="true" previous-margin="90rpx" next-margin="90rpx" current="0" @change="swiperChange"> |
||||
<block v-for="(item, index) in imgs" :key="index"> |
||||
<swiper-item class="swiper-item" :class="(swiperIndex == index ? 'active' : '')" @tap="previewImg"> |
||||
<view class="item-box" :class="(swiperIndex == index ? 'active' : '')"> |
||||
<image mode="aspectFill" :src="item" class="slide-image"></image> |
||||
<view class="content-box"> |
||||
<view class="title-box">标题标题标题标题标题</view> |
||||
<view class="content acea-row"> |
||||
<view>云快讯</view> |
||||
<view>3小时钱</view> |
||||
<view>300阅读</view> |
||||
</view> |
||||
</view> |
||||
</view> |
||||
</swiper-item> |
||||
</block> |
||||
</swiper> |
||||
</template> |
||||
|
||||
<script> |
||||
export default{ |
||||
props: { |
||||
imgs: { |
||||
type: Array, |
||||
default: [] |
||||
} |
||||
}, |
||||
data(){ |
||||
return { |
||||
swiperIndex: 0 |
||||
} |
||||
}, |
||||
methods: { |
||||
swiperChange(e) { |
||||
const that = this; |
||||
that.setData({ |
||||
swiperIndex: e.detail.current |
||||
}); |
||||
}, |
||||
|
||||
previewImg() { |
||||
uni.previewImage({ |
||||
urls: this.imgs |
||||
}); |
||||
} |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<style lang="less"> |
||||
.swiper-block { |
||||
width: 670rpx; |
||||
height: 300rpx; |
||||
margin: 60rpx auto; |
||||
} |
||||
|
||||
.swiper-item { |
||||
display: flex; |
||||
flex-direction: column; |
||||
justify-content: center; |
||||
align-items: center; |
||||
overflow: unset; |
||||
} |
||||
.item-box{ |
||||
width: 622rpx; |
||||
height: 200rpx; |
||||
position: relative; |
||||
border-radius: 20rpx; |
||||
} |
||||
.slide-image { |
||||
width: 100%; |
||||
height: 100%; |
||||
z-index: 1; |
||||
border-radius: 20rpx; |
||||
} |
||||
.content-box{ |
||||
position: absolute; |
||||
bottom: 20rpx; |
||||
left: 20rpx; |
||||
color: #0081FF; |
||||
z-index: 5; |
||||
} |
||||
.title-box{ |
||||
font-size: 32rpx; |
||||
font-weight: 500; |
||||
color: #fff; |
||||
} |
||||
.content{ |
||||
color: #fff; |
||||
font-size: 26rpx; |
||||
} |
||||
.active { |
||||
transform: scale(1.02); |
||||
transition: all 0.2s ease-in 0s; |
||||
border-radius: 20rpx; |
||||
z-index: 20; |
||||
} |
||||
</style> |
After Width: | Height: | Size: 646 B |
@ -0,0 +1,22 @@
|
||||
## 1.1.6(2021-09-22) |
||||
- 修复 在字节小程序上样式不生效的 bug |
||||
## 1.1.5(2021-07-30) |
||||
- 组件兼容 vue3,如何创建vue3项目,详见 [uni-app 项目支持 vue3 介绍](https://ask.dcloud.net.cn/article/37834) |
||||
## 1.1.4(2021-07-29) |
||||
- 修复 去掉 nvue 不支持css 的 align-self 属性,nvue 下不暂支持 absolute 属性 |
||||
## 1.1.3(2021-06-24) |
||||
- 优化 示例项目 |
||||
## 1.1.1(2021-05-12) |
||||
- 新增 组件示例地址 |
||||
## 1.1.0(2021-05-12) |
||||
- 新增 uni-badge 的 absolute 属性,支持定位 |
||||
- 新增 uni-badge 的 offset 属性,支持定位偏移 |
||||
- 新增 uni-badge 的 is-dot 属性,支持仅显示有一个小点 |
||||
- 新增 uni-badge 的 max-num 属性,支持自定义封顶的数字值,超过 99 显示99+ |
||||
- 优化 uni-badge 属性 custom-style, 支持以对象形式自定义样式 |
||||
## 1.0.7(2021-05-07) |
||||
- 修复 uni-badge 在 App 端,数字小于10时不是圆形的bug |
||||
- 修复 uni-badge 在父元素不是 flex 布局时,宽度缩小的bug |
||||
- 新增 uni-badge 属性 custom-style, 支持自定义样式 |
||||
## 1.0.6(2021-02-04) |
||||
- 调整为uni_modules目录规范 |
@ -0,0 +1,253 @@
|
||||
<template> |
||||
<view class="uni-badge--x"> |
||||
<slot /> |
||||
<text v-if="text" :class="classNames" :style="[badgeWidth, positionStyle, customStyle, dotStyle]" |
||||
class="uni-badge" |
||||
@click="onClick()">{{displayValue}}</text> |
||||
</view> |
||||
</template> |
||||
|
||||
<script> |
||||
/** |
||||
* Badge 数字角标 |
||||
* @description 数字角标一般和其它控件(列表、9宫格等)配合使用,用于进行数量提示,默认为实心灰色背景 |
||||
* @tutorial https://ext.dcloud.net.cn/plugin?id=21 |
||||
* @property {String} text 角标内容 |
||||
* @property {String} type = [default|primary|success|warning|error] 颜色类型 |
||||
* @value default 灰色 |
||||
* @value primary 蓝色 |
||||
* @value success 绿色 |
||||
* @value warning 黄色 |
||||
* @value error 红色 |
||||
* @property {String} size = [normal|small] Badge 大小 |
||||
* @value normal 一般尺寸 |
||||
* @value small 小尺寸 |
||||
* @property {String} inverted = [true|false] 是否无需背景颜色 |
||||
* @event {Function} click 点击 Badge 触发事件 |
||||
* @example <uni-badge text="1"></uni-badge> |
||||
*/ |
||||
export default { |
||||
name: 'UniBadge', |
||||
emits:['click'], |
||||
props: { |
||||
type: { |
||||
type: String, |
||||
default: 'default' |
||||
}, |
||||
inverted: { |
||||
type: Boolean, |
||||
default: false |
||||
}, |
||||
isDot: { |
||||
type: Boolean, |
||||
default: false |
||||
}, |
||||
maxNum: { |
||||
type: Number, |
||||
default: 99 |
||||
}, |
||||
absolute: { |
||||
type: String, |
||||
default: '' |
||||
}, |
||||
offset: { |
||||
type: Array, |
||||
default () { |
||||
return [0, 0] |
||||
} |
||||
}, |
||||
text: { |
||||
type: [String, Number], |
||||
default: '' |
||||
}, |
||||
size: { |
||||
type: String, |
||||
default: 'normal' |
||||
}, |
||||
customStyle: { |
||||
type: Object, |
||||
default () { |
||||
return {} |
||||
} |
||||
} |
||||
}, |
||||
data() { |
||||
return {}; |
||||
}, |
||||
computed: { |
||||
width() { |
||||
return String(this.text).length * 8 + 12 |
||||
}, |
||||
classNames() { |
||||
const { |
||||
inverted, |
||||
type, |
||||
size, |
||||
absolute |
||||
} = this |
||||
return [ |
||||
inverted ? 'uni-badge--' + type + '-inverted' : '', |
||||
'uni-badge--' + type, |
||||
'uni-badge--' + size, |
||||
absolute ? 'uni-badge--absolute' : '' |
||||
].join(' ') |
||||
}, |
||||
positionStyle() { |
||||
if (!this.absolute) return {} |
||||
let w = this.width / 2, |
||||
h = 10 |
||||
if (this.isDot) { |
||||
w = 5 |
||||
h = 5 |
||||
} |
||||
const x = `${- w + this.offset[0]}px` |
||||
const y = `${- h + this.offset[1]}px` |
||||
|
||||
const whiteList = { |
||||
rightTop: { |
||||
right: x, |
||||
top: y |
||||
}, |
||||
rightBottom: { |
||||
right: x, |
||||
bottom: y |
||||
}, |
||||
leftBottom: { |
||||
left: x, |
||||
bottom: y |
||||
}, |
||||
leftTop: { |
||||
left: x, |
||||
top: y |
||||
} |
||||
} |
||||
const match = whiteList[this.absolute] |
||||
return match ? match : whiteList['rightTop'] |
||||
}, |
||||
badgeWidth() { |
||||
return { |
||||
width: `${this.width}px` |
||||
} |
||||
}, |
||||
dotStyle() { |
||||
if (!this.isDot) return {} |
||||
return { |
||||
width: '10px', |
||||
height: '10px', |
||||
borderRadius: '10px' |
||||
} |
||||
}, |
||||
displayValue() { |
||||
const { isDot, text, maxNum } = this |
||||
return isDot ? '' : (Number(text) > maxNum ? `${maxNum}+` : text) |
||||
} |
||||
}, |
||||
methods: { |
||||
onClick() { |
||||
this.$emit('click'); |
||||
} |
||||
} |
||||
}; |
||||
</script> |
||||
|
||||
<style lang="scss" scoped> |
||||
$bage-size: 12px; |
||||
$bage-small: scale(0.8); |
||||
$bage-height: 20px; |
||||
|
||||
.uni-badge--x { |
||||
/* #ifdef APP-NVUE */ |
||||
// align-self: flex-start; |
||||
/* #endif */ |
||||
/* #ifndef APP-NVUE */ |
||||
display: inline-block; |
||||
/* #endif */ |
||||
position: relative; |
||||
} |
||||
|
||||
.uni-badge--absolute { |
||||
position: absolute; |
||||
} |
||||
|
||||
.uni-badge { |
||||
/* #ifndef APP-NVUE */ |
||||
display: flex; |
||||
overflow: hidden; |
||||
box-sizing: border-box; |
||||
/* #endif */ |
||||
justify-content: center; |
||||
flex-direction: row; |
||||
height: $bage-height; |
||||
line-height: $bage-height; |
||||
color: $uni-text-color; |
||||
border-radius: 100px; |
||||
background-color: $uni-bg-color-hover; |
||||
background-color: transparent; |
||||
text-align: center; |
||||
font-family: 'Helvetica Neue', Helvetica, sans-serif; |
||||
font-size: $bage-size; |
||||
/* #ifdef H5 */ |
||||
cursor: pointer; |
||||
/* #endif */ |
||||
} |
||||
|
||||
.uni-badge--inverted { |
||||
padding: 0 5px 0 0; |
||||
color: $uni-bg-color-hover; |
||||
} |
||||
|
||||
.uni-badge--default { |
||||
color: $uni-text-color; |
||||
background-color: $uni-bg-color-hover; |
||||
} |
||||
|
||||
.uni-badge--default-inverted { |
||||
color: $uni-text-color-grey; |
||||
background-color: transparent; |
||||
} |
||||
|
||||
.uni-badge--primary { |
||||
color: $uni-text-color-inverse; |
||||
background-color: $uni-color-primary; |
||||
} |
||||
|
||||
.uni-badge--primary-inverted { |
||||
color: $uni-color-primary; |
||||
background-color: transparent; |
||||
} |
||||
|
||||
.uni-badge--success { |
||||
color: $uni-text-color-inverse; |
||||
background-color: $uni-color-success; |
||||
} |
||||
|
||||
.uni-badge--success-inverted { |
||||
color: $uni-color-success; |
||||
background-color: transparent; |
||||
} |
||||
|
||||
.uni-badge--warning { |
||||
color: $uni-text-color-inverse; |
||||
background-color: $uni-color-warning; |
||||
} |
||||
|
||||
.uni-badge--warning-inverted { |
||||
color: $uni-color-warning; |
||||
background-color: transparent; |
||||
} |
||||
|
||||
.uni-badge--error { |
||||
color: $uni-text-color-inverse; |
||||
background-color: $uni-color-error; |
||||
} |
||||
|
||||
.uni-badge--error-inverted { |
||||
color: $uni-color-error; |
||||
background-color: transparent; |
||||
} |
||||
|
||||
.uni-badge--small { |
||||
transform: $bage-small; |
||||
transform-origin: center center; |
||||
} |
||||
</style> |
@ -0,0 +1,88 @@
|
||||
{ |
||||
"id": "uni-badge", |
||||
"displayName": "uni-badge 数字角标", |
||||
"version": "1.1.6", |
||||
"description": "数字角标(徽章)组件,在元素周围展示消息提醒,一般用于列表、九宫格、按钮等地方。", |
||||
"keywords": [ |
||||
"", |
||||
"badge", |
||||
"uni-ui", |
||||
"uniui", |
||||
"数字角标", |
||||
"徽章" |
||||
], |
||||
"repository": "https://github.com/dcloudio/uni-ui", |
||||
"engines": { |
||||
"HBuilderX": "" |
||||
}, |
||||
"directories": { |
||||
"example": "../../temps/example_temps" |
||||
}, |
||||
"dcloudext": { |
||||
"category": [ |
||||
"前端组件", |
||||
"通用组件" |
||||
], |
||||
"sale": { |
||||
"regular": { |
||||
"price": "0.00" |
||||
}, |
||||
"sourcecode": { |
||||
"price": "0.00" |
||||
} |
||||
}, |
||||
"contact": { |
||||
"qq": "" |
||||
}, |
||||
"declaration": { |
||||
"ads": "无", |
||||
"data": "无", |
||||
"permissions": "无" |
||||
}, |
||||
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui" |
||||
}, |
||||
"uni_modules": { |
||||
"dependencies": [], |
||||
"encrypt": [], |
||||
"platforms": { |
||||
"cloud": { |
||||
"tcb": "y", |
||||
"aliyun": "y" |
||||
}, |
||||
"client": { |
||||
"App": { |
||||
"app-vue": "y", |
||||
"app-nvue": "y" |
||||
}, |
||||
"H5-mobile": { |
||||
"Safari": "y", |
||||
"Android Browser": "y", |
||||
"微信浏览器(Android)": "y", |
||||
"QQ浏览器(Android)": "y" |
||||
}, |
||||
"H5-pc": { |
||||
"Chrome": "y", |
||||
"IE": "y", |
||||
"Edge": "y", |
||||
"Firefox": "y", |
||||
"Safari": "y" |
||||
}, |
||||
"小程序": { |
||||
"微信": "y", |
||||
"阿里": "y", |
||||
"百度": "y", |
||||
"字节跳动": "y", |
||||
"QQ": "y" |
||||
}, |
||||
"快应用": { |
||||
"华为": "y", |
||||
"联盟": "y" |
||||
}, |
||||
"Vue": { |
||||
"vue2": "y", |
||||
"vue3": "y" |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,58 @@
|
||||
|
||||
|
||||
## Badge 数字角标 |
||||
> **组件名:uni-badge** |
||||
> 代码块: `uBadge` |
||||
|
||||
|
||||
数字角标一般和其它控件(列表、9宫格等)配合使用,用于进行数量提示,默认为实心灰色背景, |
||||
|
||||
### 安装方式 |
||||
|
||||
本组件符合[easycom](https://uniapp.dcloud.io/collocation/pages?id=easycom)规范,`HBuilderX 2.5.5`起,只需将本组件导入项目,在页面`template`中即可直接使用,无需在页面中`import`和注册`components`。 |
||||
|
||||
如需通过`npm`方式使用`uni-ui`组件,另见文档:[https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55) |
||||
|
||||
### 基本用法 |
||||
|
||||
在 ``template`` 中使用组件 |
||||
|
||||
```html |
||||
<uni-badge size="small" :text="100" absolute="rightBottom" type="primary"> |
||||
<button type="default">右上</button> |
||||
</uni-badge> |
||||
<uni-badge text="1"></uni-badge> |
||||
<uni-badge text="2" type="purple" @click="bindClick"></uni-badge> |
||||
<uni-badge text="3" type="primary" :inverted="true"></uni-badge> |
||||
|
||||
``` |
||||
|
||||
|
||||
## API |
||||
|
||||
### Badge Props |
||||
|
||||
|属性名 |类型 |默认值 |说明 | |
||||
|:-: |:-: |:-: |:-: | |
||||
|text |String |- |角标内容 | |
||||
|type |String |default|颜色类型,可选值:default(灰色)、primary(蓝色)、success(绿色)、warning(黄色)、error(红色)| |
||||
|size |String |normal |Badge 大小,可取值:normal、small | |
||||
|is-dot |Boolean|false |不展示数字,只有一个小点 | |
||||
|max-num |String/Numbuer|99 |展示封顶的数字值,超过 99 显示99+ | |
||||
|custom-style |Object | {} |自定义 Badge 样式, 样式对象语法 | |
||||
|inverted |Boolean|false |是否无需背景颜色,为 true 时,背景颜色将变为文字的字体颜色 | |
||||
|absolute (不支持 nvue) |String| rightTop|开启绝对定位, 角标将定位到其包裹的标签的四个角上,可选值: rightTop(右上角)、rightBottom(右下角)、leftBottom(左下角) 、leftTop(左上角) | |
||||
|offset |Array[number]| [0, 0]|距定位角中心点的偏移量,[-10, -10] 表示向 absolute 指定的方向偏移 10px,[10, 10] 表示向 absolute 指定的反方向偏移 10px,只有存在 absolute 属性时有效,与absolute 的值一一对应(例如:值为rightTop, 对应 offset 为 [right, Top])| |
||||
|
||||
### Badge Events |
||||
|
||||
|事件名 |事件说明 |返回参数 | |
||||
|:-: |:-: |:-: | |
||||
|@click |点击 Badge 触发事件| - | |
||||
|
||||
|
||||
|
||||
|
||||
## 组件示例 |
||||
|
||||
点击查看:[https://hellouniapp.dcloud.net.cn/pages/extUI/badge/badge](https://hellouniapp.dcloud.net.cn/pages/extUI/badge/badge) |
Loading…
Reference in new issue